Skip to content

Commit b3cfc7d

Browse files
authored
build: update workflow to support ts (#1119)
1 parent 28b3530 commit b3cfc7d

35 files changed

+3546
-7378
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# copy this file as .env for testing env
2+
3+
SERVER_ENDPOINT=""
4+
ACCESS_KEY=""
5+
SECRET_KEY=""

.eslintrc.js

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,35 @@ module.exports = {
44
mocha: true,
55
es6: true,
66
},
7-
ignorePatterns: ['src/test/*.*', 'examples/**/*'],
8-
overrides: [],
97
extends: [
108
'eslint:recommended',
119
'plugin:@typescript-eslint/recommended',
1210
'prettier', // This should be the last entry.
1311
],
1412
parser: '@typescript-eslint/parser',
15-
plugins: ['@typescript-eslint', 'simple-import-sort'],
13+
plugins: ['@typescript-eslint', 'simple-import-sort', 'unused-imports', 'import', 'unicorn'],
1614
parserOptions: {
1715
sourceType: 'module',
18-
ecmaVersion: 8,
16+
ecmaVersion: 'latest',
17+
},
18+
ignorePatterns: ['examples/**/*', 'dist/**/*'],
19+
settings: {
20+
'import/parsers': {
21+
'@typescript-eslint/parser': ['.ts'],
22+
},
23+
// we need to config this so import are fully specified
24+
// otherwise @babel/register can't handle TypeScript files
25+
'import/resolver': {
26+
typescript: {
27+
alwaysTryTypes: false,
28+
extensionAlias: {
29+
'.js': ['.js'],
30+
},
31+
extensions: ['.ts', '.js', '.mjs'],
32+
fullySpecified: true,
33+
enforceExtension: true,
34+
},
35+
},
1936
},
2037
rules: {
2138
'no-console': ['error'],
@@ -34,6 +51,9 @@ module.exports = {
3451
'rest-spread-spacing': 0, // ["error", "never"],
3552
'no-multi-spaces': 0, // ["warn", { ignoreEOLComments: false }],
3653

54+
// import node stdlib as `node:...`
55+
// don't worry, babel will remove these prefix.
56+
'unicorn/prefer-node-protocol': 'error',
3757
'simple-import-sort/imports': 'error',
3858
'simple-import-sort/exports': 'error',
3959
indent: 'off',
@@ -67,5 +87,42 @@ module.exports = {
6787

6888
'no-extra-parens': 0,
6989
'@typescript-eslint/no-extra-parens': 0,
90+
'import/namespace': 'error',
91+
'import/default': 'error',
92+
'import/named': 'error',
93+
// default export confuse esm/cjs interop
94+
'import/no-default-export': 'error',
95+
'import/extensions': ['error', 'always'],
96+
'@typescript-eslint/consistent-type-imports': [
97+
'error',
98+
{
99+
prefer: 'type-imports',
100+
fixStyle: 'separate-type-imports',
101+
},
102+
],
103+
'unused-imports/no-unused-imports': 'error',
104+
'import/no-amd': 'error',
70105
},
106+
overrides: [
107+
{
108+
files: ['./src/**/*', './tests/**/*'],
109+
rules: {
110+
'import/no-commonjs': 'error',
111+
},
112+
},
113+
{
114+
files: ['./tests/**/*'],
115+
rules: {
116+
'no-empty-function': 0,
117+
'@typescript-eslint/no-empty-function': 0,
118+
},
119+
},
120+
{
121+
files: ['./types/**/*'],
122+
rules: {
123+
'@typescript-eslint/no-unused-vars': 0,
124+
'@typescript-eslint/no-explicit-any': 0,
125+
},
126+
},
127+
],
71128
}

.github/workflows/lint.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ jobs:
3535

3636
- run: npm ci
3737

38-
- run: npm run compile
39-
- run: npm run browserify
38+
- run: npm run type-check
39+
40+
- run: npm run build

.github/workflows/nodejs-windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ on:
99
- master
1010

1111
jobs:
12-
build:
12+
test:
1313
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
1414
runs-on: ${{ matrix.os }}
1515
strategy:
1616
max-parallel: 3
1717
matrix:
18-
node_version: [12.x, 14.x, 16.x, 17.x, 18.x, 19.x]
18+
node_version: [12.x, 14.x, 16.x, 17.x, 18.x, 20.x]
1919
os: [windows-latest]
2020
steps:
2121
- uses: actions/checkout@v3

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
max-parallel: 3
1717
matrix:
18-
node_version: [12.x, 14.x, 16.x, 17.x, 18.x, 19.x]
18+
node_version: [12.x, 14.x, 16.x, 17.x, 18.x, 20.x]
1919
os: [ubuntu-latest]
2020
steps:
2121
- uses: actions/checkout@v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Logs
22
logs
33
*.log
4+
.vscode/
45
.idea/
56
.DS_Store
67
# Dependency directory
78
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
89
node_modules
910

11+
/.env
1012
/dist/
1113
yarn.lock
1214
.yarn/

.husky/pre-commit

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4+
npm run type-check
45
npm run lint-staged

.mocharc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
spec: 'tests/**/*.js',
3+
exit: true,
4+
reporter: 'spec',
5+
ui: 'bdd',
6+
require: ['dotenv/config', 'source-map-support/register', './babel-register.js'],
7+
}

.npmignore

Lines changed: 0 additions & 19 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
### Setup your minio-js Github Repository
22
Fork [minio-js upstream](https://github.com/minio/minio-js/fork) source repository to your own personal repository.
33

4-
MinIO Javascript library uses gulp for its dependency management http://gulpjs.com/
5-
64
```bash
75
$ git clone https://github.com/$USER_ID/minio-js
86
$ cd minio-js
97
$ npm install
10-
$ gulp
8+
$ npm test
9+
$ npm build
1110
...
1211
```
1312

@@ -21,3 +20,12 @@ $ gulp
2120
- Commit your changes (git commit -am 'Add some feature')
2221
- Push to the branch (git push origin my-new-feature)
2322
- Create new Pull Request
23+
24+
### Style Guide
25+
26+
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)**
27+
28+
That means only use nodejs `require` in js config file like `.eslintrc.js`
29+
30+
You should always fully specify your import path extension,
31+
which means you should write `import {} from "errors.ts"` for `errors.ts` file, do not write `import {} from "errors.js"`.

MAINTAINERS.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# For maintainers only
2-
MinIO JS SDK uses [npm4+](https://www.npmjs.org/) build system.
2+
Development of MinIO JS SDK require nodejs14+ and [npm7+](https://www.npmjs.org/).
33

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

14-
### Build and verify
15-
Run `install` gulp task to build and verify the SDK.
16-
```sh
14+
### Install deps
15+
```shell
1716
$ npm install
1817
```
1918

19+
### Testing
20+
```shell
21+
$ npm test
22+
```
23+
2024
## Publishing new release
2125
Edit `package.json` version and all other files to the latest version as shown below.
2226
```sh
@@ -34,6 +38,11 @@ $ npm login
3438
Logged in as minio on https://registry.npmjs.org/.
3539
```
3640

41+
Build for release
42+
```sh
43+
$ npm run build
44+
```
45+
3746
Publish the new release to npm repository.
3847
```
3948
$ npm publish

babel-register.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// fix babel register doesn't transform TypeScript
2+
//
3+
// https://github.com/babel/babel/issues/8962#issuecomment-443135379
4+
5+
// eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-commonjs
6+
const register = require('@babel/register')
7+
8+
register({
9+
extensions: ['.ts', '.js'],
10+
assumptions: {
11+
constantSuper: true,
12+
noIncompleteNsImportDetection: true,
13+
constantReexports: true,
14+
},
15+
plugins: [
16+
[
17+
'@babel/plugin-transform-modules-commonjs',
18+
{
19+
importInterop: 'node',
20+
},
21+
],
22+
'@upleveled/remove-node-prefix', // lower version of node (<14) doesn't support require('node:fs')
23+
],
24+
presets: [
25+
['@babel/preset-typescript', { allExtensions: true }],
26+
['@babel/preset-env', { targets: { node: 'current' }, modules: 'cjs' }],
27+
],
28+
})

0 commit comments

Comments
 (0)