Skip to content

Commit

Permalink
migrated to tsup
Browse files Browse the repository at this point in the history
  • Loading branch information
onderonur committed Mar 10, 2024
1 parent 7e8cb70 commit 304b1b1
Show file tree
Hide file tree
Showing 19 changed files with 6,387 additions and 32,290 deletions.
52 changes: 12 additions & 40 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: [
'./config/eslint/javascript',
'./config/eslint/typescript',
'./config/eslint/import',
'./config/eslint/unicorn',
'prettier',
],
plugins: ['only-warn'],
reportUnusedDisableDirectives: true,
env: {
es6: true,
browser: true,
node: true,
// To fix '"describe" is not defined' and
// '"it" is not defined' errors in test files.
mocha: true,
// To fix '"expect" is not defined' error in test files.
jest: true,
},
extends: ['airbnb-base'],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts'],
},
},
},
plugins: ['@typescript-eslint'],
rules: {
'arrow-body-style': 'off',
// To fix the 'Missing file extension "ts" for "../src"' in test folder.
// https://stackoverflow.com/a/59268871/10876256
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
browser: true,
},
ignorePatterns: ['dist'],
};
32 changes: 10 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,25 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Begin CI...
- name: Checkout
uses: actions/checkout@v2

- name: Use Node 12
- name: Use Node 20
uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 20.x

- name: Use cached node_modules
uses: actions/cache@v1
with:
path: node_modules
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
nodeModules-
- name: Install dependencies
run: yarn install --frozen-lockfile
env:
CI: true
run: npm ci

- name: Format
run: npm run format

- name: Lint
run: yarn lint:fix
env:
CI: true
run: npm run lint

- name: Test
run: yarn test --ci --coverage --maxWorkers=2
env:
CI: true
run: npm test

- name: Build
run: yarn build
env:
CI: true
run: npm run build
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
node_modules
dist
coverage
.vscode
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npx lint-staged
npm test
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules\\typescript\\lib"
}
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,3 @@ const [error, users] = await goTry<User[]>(() => getUsers());
// or
const [error, users] = goTrySync<User[]>(() => getUsersSync());
```

_(This package is created by using [TSDX](https://github.com/formium/tsdx).)_
18 changes: 18 additions & 0 deletions config/eslint/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { resolve } = require('node:path');

/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ['plugin:import/recommended', 'plugin:import/typescript'],
settings: {
'import/resolver': {
typescript: {
project: resolve(process.cwd(), 'tsconfig.json'),
},
},
},
rules: {
'import/first': 'warn',
'import/newline-after-import': 'warn',
'import/no-duplicates': 'warn',
},
};
16 changes: 16 additions & 0 deletions config/eslint/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ['eslint:recommended'],
rules: {
'no-console': 'warn',
'no-alert': 'warn',
'object-shorthand': 'warn',
// TODO: `curly` rule is not working when it is in this extended config file.
// But it works when set in root level `.eslintrc.js`.
curly: 'warn',
eqeqeq: 'warn',
'no-param-reassign': 'error',
'prefer-template': 'warn',
'no-nested-ternary': 'warn',
},
};
25 changes: 25 additions & 0 deletions config/eslint/typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { resolve } = require('node:path');

/** @type {import("eslint").Linter.Config} */
module.exports = {
overrides: [
{
files: ['*.ts'],
parserOptions: {
project: resolve(process.cwd(), 'tsconfig.json'),
},
// Contains all of recommended, recommended-type-checked, and strict,
// along with additional strict rules that require type information.
// https://typescript-eslint.io/linting/configs/#strict-type-checked
extends: ['plugin:@typescript-eslint/strict-type-checked'],
rules: {
'@typescript-eslint/prefer-destructuring': 'warn',
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/no-misused-promises': [
'warn',
{ checksVoidReturn: false },
],
},
},
],
};
15 changes: 15 additions & 0 deletions config/eslint/unicorn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
plugins: ['unicorn'],
// https://github.com/sindresorhus/eslint-plugin-unicorn/tree/main?tab=readme-ov-file#rules
rules: {
'unicorn/filename-case': [
'warn',
{
case: 'kebabCase',
},
],
'unicorn/prefer-node-protocol': 'warn',
'unicorn/catch-error-name': 'warn',
},
};
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
4 changes: 4 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'*': 'prettier --write --ignore-unknown',
'*.ts': 'eslint src --max-warnings 0 --fix',
};
Loading

0 comments on commit 304b1b1

Please sign in to comment.