Skip to content

Commit

Permalink
ts
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Apr 30, 2023
1 parent 8c3b7fb commit d12cc45
Show file tree
Hide file tree
Showing 34 changed files with 3,509 additions and 7,375 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=""
147 changes: 98 additions & 49 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,117 @@ 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: 2022,
},
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'],
// "no-var": ["error"],
'comma-dangle': 0,
curly: ['error'],
'prefer-const': 0,
'no-template-curly-in-string': 'error',
// "quotes": ["error", "double"],
'comma-spacing': 0, // ["error", { before: false, after: true }],
'semi-spacing': 0, // ["warn", { before: false, after: true }],
'space-before-blocks': 0, // ["warn", "always"],
'switch-colon-spacing': ['warn', { after: true, before: false }],
'keyword-spacing': 0, // ["warn", { before: true, after: true }],
'template-curly-spacing': 0, // ["error", "never"],
'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',
'linebreak-style': ['error', 'unix'],
semi: ['error', 'never'],
'spaced-comment': [
'error',
'always',
{
line: {
markers: ['/'],
exceptions: ['-', '+'],
},
block: {
markers: ['!'],
exceptions: ['*'],
balanced: true,
},
},
],
'@typescript-eslint/no-explicit-any': ['warn'],
},
overrides: [
{
files: './src/**/*',
excludedFiles: ['tests/*.*'],
rules: {
'no-console': ['error'],
'prefer-const': 0,
'no-template-curly-in-string': 'error',
// "quotes": ["error", "double"],
'comma-spacing': 0, // ["error", { before: false, after: true }],
'semi-spacing': 0, // ["warn", { before: false, after: true }],
'space-before-blocks': 0, // ["warn", "always"],
'switch-colon-spacing': ['warn', { after: true, before: false }],
'keyword-spacing': 0, // ["warn", { before: true, after: true }],
'template-curly-spacing': 0, // ["error", "never"],
'rest-spread-spacing': 0, // ["error", "never"],
'no-multi-spaces': 0, // ["warn", { ignoreEOLComments: false }],
'simple-import-sort/exports': 'error',
indent: 'off',
'linebreak-style': ['error', 'unix'],
semi: ['error', 'never'],
'spaced-comment': [
'error',
'always',
{
line: {
markers: ['/'],
exceptions: ['-', '+'],
},
block: {
markers: ['!'],
exceptions: ['*'],
balanced: true,
},
},
],

'@typescript-eslint/prefer-optional-chain': 0, // ["warn"],
'no-empty-function': 0,
'@typescript-eslint/no-empty-function': 0, // ["warn"],
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/no-this-alias': 0,
'@typescript-eslint/no-empty-interface': ['warn'],
'unused-imports/no-unused-imports': 'error',
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'separate-type-imports',
},
],

'@typescript-eslint/no-array-constructor': ['off'],
'@typescript-eslint/no-explicit-any': ['warn'],

'no-extra-parens': 0,
'@typescript-eslint/no-extra-parens': 0,
},
'@typescript-eslint/prefer-optional-chain': 0, // ["warn"],
'@typescript-eslint/no-empty-function': 0, // ["warn"],
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/no-this-alias': 0,
'@typescript-eslint/no-empty-interface': ['warn'],

'@typescript-eslint/no-array-constructor': ['off'],

'no-extra-parens': 0,
'@typescript-eslint/no-extra-parens': 0,
'import/extensions': ['error', 'always'],
},
},
{
files: ['./src/**/*', './tests/**/*'],
rules: {
'import/no-commonjs': 'error',
'import/no-amd': 'error',
},
},
{
files: ['./tests/**/*'],
rules: {
'no-empty-function': 0,
'@typescript-eslint/no-empty-function': 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
2 changes: 1 addition & 1 deletion .github/workflows/nodejs-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- master

jobs:
build:
test:
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
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 "errors.js"`.
18 changes: 14 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,22 @@ $ git clone git@github.com: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
```

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

## Publishing new release
Edit `package.json` version and all other files to the latest version as shown below.
```sh
Expand Down
17 changes: 17 additions & 0 deletions babel-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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'],
plugins: [
'@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' }],
],
})

0 comments on commit d12cc45

Please sign in to comment.