From 69d92c25a64ae2710d26461fcfd2334d7f85dcbf Mon Sep 17 00:00:00 2001 From: wfc Date: Tue, 3 Dec 2024 15:12:53 +0800 Subject: [PATCH] feat: use @coze-infra/rslib-config feat: use @coze-infra/rslib-config feat: rush update --- .../config/subspaces/default/pnpm-lock.yaml | 40 +++++++++++++ config/rslib-config/eslint.config.js | 1 + config/rslib-config/index.ts | 59 +++++++++++++++++++ config/rslib-config/package.json | 28 +++++++++ packages/coze-js/package.json | 1 + packages/coze-js/rslib.config.ts | 41 +++---------- packages/realtime-api/package.json | 1 + packages/realtime-api/rslib.config.ts | 44 +++----------- rush.json | 4 ++ 9 files changed, 151 insertions(+), 68 deletions(-) create mode 100644 config/rslib-config/eslint.config.js create mode 100644 config/rslib-config/index.ts create mode 100644 config/rslib-config/package.json diff --git a/common/config/subspaces/default/pnpm-lock.yaml b/common/config/subspaces/default/pnpm-lock.yaml index b16d1e00..cf8054f4 100644 --- a/common/config/subspaces/default/pnpm-lock.yaml +++ b/common/config/subspaces/default/pnpm-lock.yaml @@ -170,6 +170,40 @@ importers: specifier: ^5.5.3 version: 5.6.3 + ../../../config/rslib-config: + dependencies: + '@rslib/core': + specifier: 0.0.18 + version: 0.0.18(typescript@5.6.3) + devDependencies: + '@coze-infra/eslint-config': + specifier: workspace:* + version: link:../eslint-config + '@coze-infra/ts-config': + specifier: workspace:* + version: link:../ts-config + '@types/node': + specifier: ^20 + version: 20.16.15 + '@vitejs/plugin-react': + specifier: ~4.3.3 + version: 4.3.3(vite@5.4.10(@types/node@20.16.15)(terser@5.36.0)) + '@vitest/coverage-v8': + specifier: ~2.1.4 + version: 2.1.4(vitest@2.1.4(@types/node@20.16.15)(happy-dom@15.11.0)(terser@5.36.0)) + happy-dom: + specifier: ~15.11.0 + version: 15.11.0 + sucrase: + specifier: ^3.32.0 + version: 3.35.0 + typescript: + specifier: ^5.5.3 + version: 5.6.3 + vitest: + specifier: ~2.1.4 + version: 2.1.4(@types/node@20.16.15)(happy-dom@15.11.0)(terser@5.36.0) + ../../../config/ts-config: devDependencies: eslint: @@ -1004,6 +1038,9 @@ importers: '@coze-infra/eslint-config': specifier: workspace:* version: link:../../config/eslint-config + '@coze-infra/rslib-config': + specifier: workspace:* + version: link:../../config/rslib-config '@coze-infra/ts-config': specifier: workspace:* version: link:../../config/ts-config @@ -1053,6 +1090,9 @@ importers: '@coze-infra/eslint-config': specifier: workspace:* version: link:../../config/eslint-config + '@coze-infra/rslib-config': + specifier: workspace:* + version: link:../../config/rslib-config '@coze-infra/ts-config': specifier: workspace:* version: link:../../config/ts-config diff --git a/config/rslib-config/eslint.config.js b/config/rslib-config/eslint.config.js new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/config/rslib-config/eslint.config.js @@ -0,0 +1 @@ +module.exports = []; diff --git a/config/rslib-config/index.ts b/config/rslib-config/index.ts new file mode 100644 index 00000000..5617c51b --- /dev/null +++ b/config/rslib-config/index.ts @@ -0,0 +1,59 @@ +import { defineConfig, LibConfig } from '@rslib/core'; + +type LibFormat = LibConfig['format']; +export type BundleType = Boolean | 'excludeExternal'; + +interface Options { + format?: LibFormat[]; + bundle?: BundleType; + tsconfigPath?: string; + umdName?: string; +} +const defaultOptions = { + format: ['esm', 'cjs'] as LibFormat[], + bundle: true, +}; + +function getRslibConfig(options: Options) { + const { format, bundle, umdName, tsconfigPath } = { + ...defaultOptions, + ...options, + }; + + const libs = format.map(libFormat => { + const lib = getLibShared(libFormat, bundle!); + if (libFormat === 'umd') { + lib.umdName = umdName; + lib.bundle = true; + } + return lib; + }); + + libs[0].dts = { + distPath: './dist/types', + }; + + return defineConfig({ + source: { + tsconfigPath, + }, + lib: libs, + }); +} + +function getLibShared(format: LibFormat, bundleType: BundleType) { + const shared: LibConfig = { + output: { + distPath: { + root: `./dist/${format}`, + }, + }, + format, + syntax: 'es6', + bundle: !!bundleType, + autoExternal: bundleType === 'excludeExternal', + }; + return shared; +} + +export default getRslibConfig; diff --git a/config/rslib-config/package.json b/config/rslib-config/package.json new file mode 100644 index 00000000..27d94a87 --- /dev/null +++ b/config/rslib-config/package.json @@ -0,0 +1,28 @@ +{ + "name": "@coze-infra/rslib-config", + "version": "0.0.1", + "author": "wangfocheng@bytedance.com", + "maintainers": [], + "main": "src/index.ts", + "types": "src/index.ts", + "scripts": { + "build": "exit", + "lint": "exit", + "test": "exit", + "test:cov": "exit 0" + }, + "dependencies": { + "@rslib/core": "0.0.18" + }, + "devDependencies": { + "@coze-infra/eslint-config": "workspace:*", + "@coze-infra/ts-config": "workspace:*", + "@types/node": "^20", + "@vitejs/plugin-react": "~4.3.3", + "@vitest/coverage-v8": "~2.1.4", + "happy-dom": "~15.11.0", + "sucrase": "^3.32.0", + "typescript": "^5.5.3", + "vitest": "~2.1.4" + } +} diff --git a/packages/coze-js/package.json b/packages/coze-js/package.json index 24d0517e..e048783b 100644 --- a/packages/coze-js/package.json +++ b/packages/coze-js/package.json @@ -56,6 +56,7 @@ }, "devDependencies": { "@coze-infra/eslint-config": "workspace:*", + "@coze-infra/rslib-config": "workspace:*", "@coze-infra/ts-config": "workspace:*", "@coze-infra/vitest-config": "workspace:*", "@rslib/core": "0.0.18", diff --git a/packages/coze-js/rslib.config.ts b/packages/coze-js/rslib.config.ts index e2730ef4..bea3a6d4 100644 --- a/packages/coze-js/rslib.config.ts +++ b/packages/coze-js/rslib.config.ts @@ -1,33 +1,10 @@ -import { defineConfig, type LibConfig } from '@rslib/core'; - -function getLibShared(format: LibConfig['format']) { - const shared: LibConfig = { - output: { - distPath: { - root: `./dist/${format}`, - }, - }, - format, - syntax: 'es6', - }; - return shared; -} - -export default defineConfig({ - source: { +import { defineConfig } from '@rslib/core'; +import getRslibConfig from '@coze-infra/rslib-config'; +export default defineConfig( + getRslibConfig({ + format: ['esm', 'cjs', 'umd'], + bundle: 'excludeExternal', + umdName: 'CozeJs', tsconfigPath: './tsconfig.build.json', - }, - lib: [ - { - ...getLibShared('esm'), - dts: { - distPath: './dist/types', - }, - }, - { - ...getLibShared('umd'), - umdName: 'CozeJs', - }, - getLibShared('cjs'), - ], -}); + }), +); diff --git a/packages/realtime-api/package.json b/packages/realtime-api/package.json index f5635490..dcf0cfc4 100644 --- a/packages/realtime-api/package.json +++ b/packages/realtime-api/package.json @@ -54,6 +54,7 @@ }, "devDependencies": { "@coze-infra/eslint-config": "workspace:*", + "@coze-infra/rslib-config": "workspace:*", "@coze-infra/ts-config": "workspace:*", "@coze-infra/vitest-config": "workspace:*", "@rslib/core": "0.0.18", diff --git a/packages/realtime-api/rslib.config.ts b/packages/realtime-api/rslib.config.ts index d290b442..0ca69ba0 100644 --- a/packages/realtime-api/rslib.config.ts +++ b/packages/realtime-api/rslib.config.ts @@ -1,37 +1,9 @@ -import { defineConfig, type LibConfig } from '@rslib/core'; - -function getLibShared(format: LibConfig['format']) { - const shared: LibConfig = { - output: { - distPath: { - root: `./dist/${format}`, - }, - }, - format, - syntax: 'es6', - autoExternal: false, - }; - return shared; -} - -export default defineConfig({ - source: { +import { defineConfig } from '@rslib/core'; +import getRslibConfig from '@coze-infra/rslib-config'; +export default defineConfig( + getRslibConfig({ + format: ['esm', 'cjs', 'umd'], + umdName: 'CozeRealtimeApi', tsconfigPath: './tsconfig.build.json', - }, - output: { - target: 'web', - }, - lib: [ - { - ...getLibShared('esm'), - dts: { - distPath: './dist/types', - }, - }, - { - ...getLibShared('umd'), - umdName: 'CozeRealtimeApi', - }, - getLibShared('cjs'), - ], -}); + }), +); diff --git a/rush.json b/rush.json index 38e22ab6..0a38c2f6 100644 --- a/rush.json +++ b/rush.json @@ -398,6 +398,10 @@ "packageName": "@coze-infra/package-audit", "projectFolder": "infra/package-audit" }, + { + "packageName": "@coze-infra/rslib-config", + "projectFolder": "config/rslib-config" + }, { "packageName": "@coze/api", "projectFolder": "packages/coze-js"