From b777db5df5083bff4f8c689f19f07c89d39ddf60 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Sun, 28 Jul 2024 11:04:36 +0800 Subject: [PATCH] refactor(core): use tsup for building --- package.json | 1 + packages/core/nodemon.json | 17 -- packages/core/package.json | 5 +- packages/core/tsconfig.base.json | 13 -- packages/core/tsconfig.build.json | 10 - packages/core/tsconfig.json | 22 ++- packages/core/tsconfig.test.json | 5 +- packages/core/tsup.config.ts | 11 ++ packages/core/tsup.dev.config.ts | 9 + .../schemas/tsconfig.build.alterations.json | 5 +- packages/schemas/tsconfig.build.gen.json | 7 +- pnpm-lock.yaml | 175 +++++++++++++----- tsup.shared.config.ts | 10 + 13 files changed, 199 insertions(+), 91 deletions(-) delete mode 100644 packages/core/nodemon.json delete mode 100644 packages/core/tsconfig.base.json delete mode 100644 packages/core/tsconfig.build.json create mode 100644 packages/core/tsup.config.ts create mode 100644 packages/core/tsup.dev.config.ts create mode 100644 tsup.shared.config.ts diff --git a/package.json b/package.json index db517658c..254f4b842 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@types/pg": "^8.6.6", "husky": "^9.0.0", "pg": "^8.8.0", + "tsup": "^8.1.0", "typescript": "^5.0.0", "vite": "^5.3.4" }, diff --git a/packages/core/nodemon.json b/packages/core/nodemon.json deleted file mode 100644 index ca594d4cb..000000000 --- a/packages/core/nodemon.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "exec": "tsc -p tsconfig.build.json --incremental && pnpm copy:apidocs && node ./build/index.js || exit 1", - "ignore": [ - "node_modules/**/node_modules", - "../integration-tests/" - ], - "watch": [ - "../*/lib/", - "../core/src/", - "../core/node_modules/", - ".env", - "../../.env", - "../connectors/*/lib/" - ], - "ext": "json,js,jsx,ts,tsx", - "delay": 500 -} diff --git a/packages/core/package.json b/packages/core/package.json index 92b45f9d6..e08ab66cc 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -13,11 +13,11 @@ "scripts": { "precommit": "lint-staged", "copy:apidocs": "rsync -a -m --include '*/' --include '*.openapi.json' --exclude '*' src/routes/ build/routes/", - "build": "rm -rf build/ && tsc -p tsconfig.build.json && pnpm run copy:apidocs", + "build": "tsup", "build:test": "rm -rf build/ && tsc -p tsconfig.test.json --sourcemap && pnpm run copy:apidocs", "lint": "eslint --ext .ts --ext .json src", "lint:report": "pnpm lint --format json --output-file report.json", - "dev": "rm -rf build/ && nodemon", + "dev": "tsup --config tsup.dev.config.ts", "start": "NODE_ENV=production node .", "test:only": "NODE_OPTIONS=\"--experimental-vm-modules --max_old_space_size=4096\" jest --logHeapUsage", "test": "pnpm build:test && pnpm test:only", @@ -127,6 +127,7 @@ "prettier": "^3.0.0", "sinon": "^18.0.0", "supertest": "^7.0.0", + "tsup": "^8.1.0", "typescript": "^5.5.3" }, "engines": { diff --git a/packages/core/tsconfig.base.json b/packages/core/tsconfig.base.json deleted file mode 100644 index ff6206ddf..000000000 --- a/packages/core/tsconfig.base.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "@silverhand/ts-config/tsconfig.base", - "compilerOptions": { - "declaration": false, - "outDir": "build", - "baseUrl": ".", - "paths": { - "#src/*": [ - "src/*" - ] - } - } -} diff --git a/packages/core/tsconfig.build.json b/packages/core/tsconfig.build.json deleted file mode 100644 index 988844c2c..000000000 --- a/packages/core/tsconfig.build.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.base", - "include": [ - "src" - ], - "exclude": [ - "src/**/*.test.ts", - "src/**/__mocks__/", - ] -} diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 657642e2f..19c4ed160 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,7 +1,23 @@ { - "extends": "./tsconfig.base", + "extends": "@silverhand/ts-config/tsconfig.base", "compilerOptions": { - "types": ["node", "jest", "jest-matcher-specific-error"] + "declaration": false, + "outDir": "build", + "baseUrl": ".", + "paths": { + "#src/*": [ + "src/*" + ] + }, + "types": [ + "node", + "jest", + "jest-matcher-specific-error" + ] }, - "include": ["src"] + "include": [ + "src", + "*.config.ts", + "*.setup.ts" + ] } diff --git a/packages/core/tsconfig.test.json b/packages/core/tsconfig.test.json index 1424a1555..e5b8400be 100644 --- a/packages/core/tsconfig.test.json +++ b/packages/core/tsconfig.test.json @@ -3,5 +3,8 @@ "compilerOptions": { "isolatedModules": false, "allowJs": true, - } + }, + "include": [ + "src/" + ] } diff --git a/packages/core/tsup.config.ts b/packages/core/tsup.config.ts new file mode 100644 index 000000000..5cf5e1139 --- /dev/null +++ b/packages/core/tsup.config.ts @@ -0,0 +1,11 @@ +import { defineConfig, type Options } from 'tsup'; + +import { defaultConfig } from '../../tsup.shared.config.js'; + +export const config = Object.freeze({ + ...defaultConfig, + outDir: 'build', + onSuccess: 'pnpm run copy:apidocs', +} satisfies Options); + +export default defineConfig(config); diff --git a/packages/core/tsup.dev.config.ts b/packages/core/tsup.dev.config.ts new file mode 100644 index 000000000..b2c6b1aec --- /dev/null +++ b/packages/core/tsup.dev.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'tsup'; + +import { config as baseConfig } from './tsup.config.js'; + +export default defineConfig({ + ...baseConfig, + watch: ['src/**/*.ts', '.env', '../../.env', '../connectors/*/lib/'], + onSuccess: baseConfig.onSuccess + ' && node ./build/index.js', +}); diff --git a/packages/schemas/tsconfig.build.alterations.json b/packages/schemas/tsconfig.build.alterations.json index 96cde8fa1..5e7569a34 100644 --- a/packages/schemas/tsconfig.build.alterations.json +++ b/packages/schemas/tsconfig.build.alterations.json @@ -1,8 +1,11 @@ { "extends": "./tsconfig", "compilerOptions": { + "declaration": false, "outDir": "alterations-js", }, - "include": ["alterations"], + "include": [ + "alterations" + ], "exclude": [] } diff --git a/packages/schemas/tsconfig.build.gen.json b/packages/schemas/tsconfig.build.gen.json index eeed8fa29..0ed58c7cf 100644 --- a/packages/schemas/tsconfig.build.gen.json +++ b/packages/schemas/tsconfig.build.gen.json @@ -1,4 +1,9 @@ { "extends": "./tsconfig", - "include": ["src/gen"] + "compilerOptions": { + "declaration": false, + }, + "include": [ + "src/gen" + ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ec723e6d..b7bd1bc79 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,6 +36,9 @@ importers: pg: specifier: ^8.8.0 version: 8.8.0 + tsup: + specifier: ^8.1.0 + version: 8.1.0(@swc/core@1.3.52)(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.12.7)(typescript@5.0.2))(typescript@5.0.2) typescript: specifier: ^5.0.0 version: 5.0.2 @@ -3421,7 +3424,7 @@ importers: version: 8.57.0 jest: specifier: ^29.7.0 - version: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)) + version: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) jest-matcher-specific-error: specifier: ^1.0.0 version: 1.0.0 @@ -3449,6 +3452,9 @@ importers: supertest: specifier: ^7.0.0 version: 7.0.0 + tsup: + specifier: ^8.1.0 + version: 8.1.0(@swc/core@1.3.52)(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3))(typescript@5.5.3) typescript: specifier: ^5.5.3 version: 5.5.3 @@ -3855,7 +3861,7 @@ importers: version: 10.0.0 jest: specifier: ^29.7.0 - version: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)) + version: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) jest-matcher-specific-error: specifier: ^1.0.0 version: 1.0.0 @@ -14896,7 +14902,7 @@ snapshots: - supports-color - ts-node - '@jest/core@29.7.0(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3))': + '@jest/core@29.7.0(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3))': dependencies: '@jest/console': 29.7.0 '@jest/reporters': 29.7.0 @@ -14910,7 +14916,7 @@ snapshots: exit: 0.1.2 graceful-fs: 4.2.11 jest-changed-files: 29.7.0 - jest-config: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)) + jest-config: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) jest-haste-map: 29.7.0 jest-message-util: 29.7.0 jest-regex-util: 29.6.3 @@ -17859,13 +17865,13 @@ snapshots: dependencies: lodash.get: 4.4.2 - create-jest@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)): + create-jest@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)): dependencies: '@jest/types': 29.6.3 chalk: 4.1.2 exit: 0.1.2 graceful-fs: 4.2.11 - jest-config: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)) + jest-config: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) jest-util: 29.7.0 prompts: 2.4.2 transitivePeerDependencies: @@ -18180,10 +18186,6 @@ snapshots: debounce@1.2.1: {} - debug@3.2.7: - dependencies: - ms: 2.1.3 - debug@3.2.7(supports-color@5.5.0): dependencies: ms: 2.1.3 @@ -18659,7 +18661,7 @@ snapshots: eslint-import-resolver-node@0.3.9: dependencies: - debug: 3.2.7 + debug: 3.2.7(supports-color@5.5.0) is-core-module: 2.13.1 resolve: 1.22.8 transitivePeerDependencies: @@ -18684,7 +18686,7 @@ snapshots: eslint-module-utils@2.8.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.7.0(eslint@8.57.0)(typescript@5.5.3))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): dependencies: - debug: 3.2.7 + debug: 3.2.7(supports-color@5.5.0) optionalDependencies: '@typescript-eslint/parser': 7.7.0(eslint@8.57.0)(typescript@5.5.3) eslint: 8.57.0 @@ -18717,7 +18719,7 @@ snapshots: array.prototype.findlastindex: 1.2.5 array.prototype.flat: 1.3.2 array.prototype.flatmap: 1.3.2 - debug: 3.2.7 + debug: 3.2.7(supports-color@5.5.0) doctrine: 2.1.0 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 @@ -20195,16 +20197,16 @@ snapshots: - babel-plugin-macros - supports-color - jest-cli@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)): + jest-cli@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)): dependencies: - '@jest/core': 29.7.0(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)) + '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 chalk: 4.1.2 - create-jest: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)) + create-jest: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) exit: 0.1.2 import-local: 3.1.0 - jest-config: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)) + jest-config: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) jest-util: 29.7.0 jest-validate: 29.7.0 yargs: 17.7.2 @@ -20233,7 +20235,7 @@ snapshots: - supports-color - ts-node - jest-config@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)): + jest-config@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)): dependencies: '@babel/core': 7.24.4 '@jest/test-sequencer': 29.7.0 @@ -20259,7 +20261,7 @@ snapshots: strip-json-comments: 3.1.1 optionalDependencies: '@types/node': 20.10.4 - ts-node: 10.9.2(@types/node@20.10.4)(typescript@5.5.3) + ts-node: 10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3) transitivePeerDependencies: - babel-plugin-macros - supports-color @@ -20295,7 +20297,7 @@ snapshots: - babel-plugin-macros - supports-color - jest-config@29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)): + jest-config@29.7.0(@types/node@20.12.7)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)): dependencies: '@babel/core': 7.24.4 '@jest/test-sequencer': 29.7.0 @@ -20321,7 +20323,7 @@ snapshots: strip-json-comments: 3.1.1 optionalDependencies: '@types/node': 20.12.7 - ts-node: 10.9.2(@types/node@20.10.4)(typescript@5.5.3) + ts-node: 10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3) transitivePeerDependencies: - babel-plugin-macros - supports-color @@ -20634,12 +20636,12 @@ snapshots: merge-stream: 2.0.0 supports-color: 8.1.1 - jest@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)): + jest@29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)): dependencies: - '@jest/core': 29.7.0(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)) + '@jest/core': 29.7.0(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) '@jest/types': 29.6.3 import-local: 3.1.0 - jest-cli: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3)) + jest-cli: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) transitivePeerDependencies: - '@types/node' - babel-plugin-macros @@ -22567,6 +22569,22 @@ snapshots: possible-typed-array-names@1.0.0: {} + postcss-load-config@4.0.2(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)): + dependencies: + lilconfig: 3.1.2 + yaml: 2.4.5 + optionalDependencies: + postcss: 8.4.39 + ts-node: 10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3) + + postcss-load-config@4.0.2(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.12.7)(typescript@5.0.2)): + dependencies: + lilconfig: 3.1.2 + yaml: 2.4.5 + optionalDependencies: + postcss: 8.4.39 + ts-node: 10.9.2(@swc/core@1.3.52)(@types/node@20.12.7)(typescript@5.0.2) + postcss-load-config@4.0.2(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.12.7)(typescript@5.5.3)): dependencies: lilconfig: 3.1.2 @@ -24190,6 +24208,48 @@ snapshots: '@swc/core': 1.3.52(@swc/helpers@0.5.1) optional: true + ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3): + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.9 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.4 + '@types/node': 20.10.4 + acorn: 8.11.3 + acorn-walk: 8.3.2 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 5.5.3 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + optionalDependencies: + '@swc/core': 1.3.52(@swc/helpers@0.5.1) + optional: true + + ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.12.7)(typescript@5.0.2): + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.9 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.4 + '@types/node': 20.12.7 + acorn: 8.11.3 + acorn-walk: 8.3.2 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 5.0.2 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + optionalDependencies: + '@swc/core': 1.3.52(@swc/helpers@0.5.1) + optional: true + ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.12.7)(typescript@5.5.3): dependencies: '@cspotcode/source-map-support': 0.8.1 @@ -24211,25 +24271,6 @@ snapshots: '@swc/core': 1.3.52(@swc/helpers@0.5.1) optional: true - ts-node@10.9.2(@types/node@20.10.4)(typescript@5.5.3): - dependencies: - '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.9 - '@tsconfig/node12': 1.0.11 - '@tsconfig/node14': 1.0.3 - '@tsconfig/node16': 1.0.4 - '@types/node': 20.10.4 - acorn: 8.11.3 - acorn-walk: 8.3.2 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - typescript: 5.5.3 - v8-compile-cache-lib: 3.0.1 - yn: 3.1.1 - optional: true - tsconfig-paths@3.15.0: dependencies: '@types/json5': 0.0.29 @@ -24247,6 +24288,54 @@ snapshots: tsscmp@1.0.6: {} + tsup@8.1.0(@swc/core@1.3.52)(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3))(typescript@5.5.3): + dependencies: + bundle-require: 4.2.1(esbuild@0.21.5) + cac: 6.7.14 + chokidar: 3.5.3 + debug: 4.3.4 + esbuild: 0.21.5 + execa: 5.1.1 + globby: 11.1.0 + joycon: 3.1.1 + postcss-load-config: 4.0.2(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.10.4)(typescript@5.5.3)) + resolve-from: 5.0.0 + rollup: 4.14.3 + source-map: 0.8.0-beta.0 + sucrase: 3.35.0 + tree-kill: 1.2.2 + optionalDependencies: + '@swc/core': 1.3.52(@swc/helpers@0.5.1) + postcss: 8.4.39 + typescript: 5.5.3 + transitivePeerDependencies: + - supports-color + - ts-node + + tsup@8.1.0(@swc/core@1.3.52)(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.12.7)(typescript@5.0.2))(typescript@5.0.2): + dependencies: + bundle-require: 4.2.1(esbuild@0.21.5) + cac: 6.7.14 + chokidar: 3.5.3 + debug: 4.3.4 + esbuild: 0.21.5 + execa: 5.1.1 + globby: 11.1.0 + joycon: 3.1.1 + postcss-load-config: 4.0.2(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.12.7)(typescript@5.0.2)) + resolve-from: 5.0.0 + rollup: 4.14.3 + source-map: 0.8.0-beta.0 + sucrase: 3.35.0 + tree-kill: 1.2.2 + optionalDependencies: + '@swc/core': 1.3.52(@swc/helpers@0.5.1) + postcss: 8.4.39 + typescript: 5.0.2 + transitivePeerDependencies: + - supports-color + - ts-node + tsup@8.1.0(@swc/core@1.3.52)(postcss@8.4.39)(ts-node@10.9.2(@swc/core@1.3.52)(@types/node@20.12.7)(typescript@5.5.3))(typescript@5.5.3): dependencies: bundle-require: 4.2.1(esbuild@0.21.5) diff --git a/tsup.shared.config.ts b/tsup.shared.config.ts new file mode 100644 index 000000000..849626261 --- /dev/null +++ b/tsup.shared.config.ts @@ -0,0 +1,10 @@ +import { type Options } from 'tsup'; + +export const defaultConfig = Object.freeze({ + entry: ['src/index.ts'], + outDir: 'lib', + format: ['esm'], + dts: false, + sourcemap: true, + clean: true, +} satisfies Options);