Skip to content

Commit

Permalink
build: update workflow to support ts (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored May 5, 2023
1 parent 28b3530 commit b3cfc7d
Show file tree
Hide file tree
Showing 35 changed files with 3,546 additions and 7,378 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# copy this file as .env for testing env

SERVER_ENDPOINT=""
ACCESS_KEY=""
SECRET_KEY=""
65 changes: 61 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,35 @@ module.exports = {
mocha: true,
es6: true,
},
ignorePatterns: ['src/test/*.*', 'examples/**/*'],
overrides: [],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier', // This should be the last entry.
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'simple-import-sort'],
plugins: ['@typescript-eslint', 'simple-import-sort', 'unused-imports', 'import', 'unicorn'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 8,
ecmaVersion: 'latest',
},
ignorePatterns: ['examples/**/*', 'dist/**/*'],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts'],
},
// we need to config this so import are fully specified
// otherwise @babel/register can't handle TypeScript files
'import/resolver': {
typescript: {
alwaysTryTypes: false,
extensionAlias: {
'.js': ['.js'],
},
extensions: ['.ts', '.js', '.mjs'],
fullySpecified: true,
enforceExtension: true,
},
},
},
rules: {
'no-console': ['error'],
Expand All @@ -34,6 +51,9 @@ module.exports = {
'rest-spread-spacing': 0, // ["error", "never"],
'no-multi-spaces': 0, // ["warn", { ignoreEOLComments: false }],

// import node stdlib as `node:...`
// don't worry, babel will remove these prefix.
'unicorn/prefer-node-protocol': 'error',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
indent: 'off',
Expand Down Expand Up @@ -67,5 +87,42 @@ module.exports = {

'no-extra-parens': 0,
'@typescript-eslint/no-extra-parens': 0,
'import/namespace': 'error',
'import/default': 'error',
'import/named': 'error',
// default export confuse esm/cjs interop
'import/no-default-export': 'error',
'import/extensions': ['error', 'always'],
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'separate-type-imports',
},
],
'unused-imports/no-unused-imports': 'error',
'import/no-amd': 'error',
},
overrides: [
{
files: ['./src/**/*', './tests/**/*'],
rules: {
'import/no-commonjs': 'error',
},
},
{
files: ['./tests/**/*'],
rules: {
'no-empty-function': 0,
'@typescript-eslint/no-empty-function': 0,
},
},
{
files: ['./types/**/*'],
rules: {
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-explicit-any': 0,
},
},
],
}
5 changes: 3 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ jobs:

- run: npm ci

- run: npm run compile
- run: npm run browserify
- run: npm run type-check

- run: npm run build
4 changes: 2 additions & 2 deletions .github/workflows/nodejs-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ on:
- master

jobs:
build:
test:
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 3
matrix:
node_version: [12.x, 14.x, 16.x, 17.x, 18.x, 19.x]
node_version: [12.x, 14.x, 16.x, 17.x, 18.x, 20.x]
os: [windows-latest]
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
max-parallel: 3
matrix:
node_version: [12.x, 14.x, 16.x, 17.x, 18.x, 19.x]
node_version: [12.x, 14.x, 16.x, 17.x, 18.x, 20.x]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Logs
logs
*.log
.vscode/
.idea/
.DS_Store
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

/.env
/dist/
yarn.lock
.yarn/
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run type-check
npm run lint-staged
7 changes: 7 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
spec: 'tests/**/*.js',
exit: true,
reporter: 'spec',
ui: 'bdd',
require: ['dotenv/config', 'source-map-support/register', './babel-register.js'],
}
19 changes: 0 additions & 19 deletions .npmignore

This file was deleted.

14 changes: 11 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
### Setup your minio-js Github Repository
Fork [minio-js upstream](https://github.com/minio/minio-js/fork) source repository to your own personal repository.

MinIO Javascript library uses gulp for its dependency management http://gulpjs.com/

```bash
$ git clone https://github.com/$USER_ID/minio-js
$ cd minio-js
$ npm install
$ gulp
$ npm test
$ npm build
...
```

Expand All @@ -21,3 +20,12 @@ $ gulp
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request

### Style Guide

We are currently migrating from JavaScript to TypeScript, so **All Source should be written in [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)**

That means only use nodejs `require` in js config file like `.eslintrc.js`

You should always fully specify your import path extension,
which means you should write `import {} from "errors.ts"` for `errors.ts` file, do not write `import {} from "errors.js"`.
17 changes: 13 additions & 4 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# For maintainers only
MinIO JS SDK uses [npm4+](https://www.npmjs.org/) build system.
Development of MinIO JS SDK require nodejs14+ and [npm7+](https://www.npmjs.org/).

## Responsibilities
Go through [Maintainer Responsibility Guide](https://gist.github.com/abperiasamy/f4d9b31d3186bbd26522).
Expand All @@ -11,12 +11,16 @@ $ git clone [email protected]:minio/minio-js
$ cd minio-js
```

### Build and verify
Run `install` gulp task to build and verify the SDK.
```sh
### Install deps
```shell
$ npm install
```

### Testing
```shell
$ npm test
```

## Publishing new release
Edit `package.json` version and all other files to the latest version as shown below.
```sh
Expand All @@ -34,6 +38,11 @@ $ npm login
Logged in as minio on https://registry.npmjs.org/.
```

Build for release
```sh
$ npm run build
```

Publish the new release to npm repository.
```
$ npm publish
Expand Down
28 changes: 28 additions & 0 deletions babel-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// fix babel register doesn't transform TypeScript
//
// https://github.com/babel/babel/issues/8962#issuecomment-443135379

// eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-commonjs
const register = require('@babel/register')

register({
extensions: ['.ts', '.js'],
assumptions: {
constantSuper: true,
noIncompleteNsImportDetection: true,
constantReexports: true,
},
plugins: [
[
'@babel/plugin-transform-modules-commonjs',
{
importInterop: 'node',
},
],
'@upleveled/remove-node-prefix', // lower version of node (<14) doesn't support require('node:fs')
],
presets: [
['@babel/preset-typescript', { allExtensions: true }],
['@babel/preset-env', { targets: { node: 'current' }, modules: 'cjs' }],
],
})
Loading

0 comments on commit b3cfc7d

Please sign in to comment.