From c524cd40860fcb41d2fefffa8e472a57b982031e Mon Sep 17 00:00:00 2001 From: roymondchen Date: Tue, 21 Jan 2025 19:56:04 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E7=BB=9F=E4=B8=80=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E5=8A=A0=E5=85=A5runtime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- pnpm-lock.yaml | 31 --------- rollup.dts.config.js | 66 +++++++++++-------- runtime/react-runtime-help/package.json | 22 +++---- .../react-runtime-help/tsconfig.build.json | 11 ---- .../tsconfig.build.tsbuildinfo | 1 - runtime/react-runtime-help/tsconfig.json | 9 --- runtime/tmagic-form/package.json | 14 ---- runtime/tmagic-form/tsconfig.build.json | 13 ---- runtime/tmagic-form/tsconfig.json | 6 -- runtime/tmagic-form/vite.config.ts | 45 ------------- runtime/vue-runtime-help/package.json | 22 +++---- runtime/vue-runtime-help/tsconfig.build.json | 11 ---- .../tsconfig.build.tsbuildinfo | 1 - runtime/vue-runtime-help/tsconfig.json | 7 -- scripts/build.mjs | 39 +++++++---- tsconfig.build-browser.json | 2 + tsconfig.build-vue.json | 1 + tsconfig.check-vue.json | 1 + tsconfig.check.json | 2 + 20 files changed, 89 insertions(+), 219 deletions(-) delete mode 100644 runtime/react-runtime-help/tsconfig.build.json delete mode 100644 runtime/react-runtime-help/tsconfig.build.tsbuildinfo delete mode 100644 runtime/react-runtime-help/tsconfig.json delete mode 100644 runtime/tmagic-form/tsconfig.build.json delete mode 100644 runtime/tmagic-form/tsconfig.json delete mode 100644 runtime/tmagic-form/vite.config.ts delete mode 100644 runtime/vue-runtime-help/tsconfig.build.json delete mode 100644 runtime/vue-runtime-help/tsconfig.build.tsbuildinfo delete mode 100644 runtime/vue-runtime-help/tsconfig.json diff --git a/package.json b/package.json index 824864ac..82b0f338 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "packageManager": "pnpm@9.15.4", "scripts": { "bootstrap": "pnpm i && pnpm build", - "clean:top": "rimraf */**/dist */**/types */dist coverage dwt* temp", + "clean:top": "rimraf */**/dist */**/types */dist coverage dwt* temp packages/cli/lib", "clean:modules": "rimraf node_modules **/node_modules **/**/node_modules", "clean:all": "pnpm clean:top && pnpm clean:modules", "lint": "eslint . --ext .js,.vue,.ts,.tsx", @@ -17,7 +17,7 @@ "pg:vue2": "pnpm playground:vue2", "playground:react": "pnpm --filter \"runtime-react\" build:libs && pnpm --filter \"runtime-react\" --filter \"tmagic-playground\" dev:react", "pg:react": "pnpm playground:react", - "build": "pnpm build:dts && pnpm --filter \"@tmagic/cli\" build && node scripts/build.mjs", + "build": "pnpm build:dts && node scripts/build.mjs", "build:dts": "pnpm --filter \"@tmagic/cli\" build && tsc -p tsconfig.build-browser.json && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build-vue.json && rollup -c rollup.dts.config.js && rimraf temp", "check:type": "tsc --incremental --noEmit -p tsconfig.check.json && vue-tsc --noEmit -p tsconfig.check-vue.json", "build:playground": "pnpm --filter \"runtime-vue3\" build && pnpm --filter \"tmagic-playground\" build", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5d216a84..089e46e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -977,15 +977,9 @@ importers: '@types/lodash-es': specifier: ^4.17.4 version: 4.17.12 - '@types/node': - specifier: ^18.19.0 - version: 18.19.61 '@types/react': specifier: ^18.3.3 version: 18.3.18 - rimraf: - specifier: ^3.0.2 - version: 3.0.2 runtime/tmagic-form: dependencies: @@ -1004,25 +998,6 @@ importers: vue: specifier: '>=3.5.0' version: 3.5.13(typescript@5.7.3) - devDependencies: - '@types/node': - specifier: ^18.19.0 - version: 18.19.61 - '@vitejs/plugin-vue': - specifier: ^5.2.1 - version: 5.2.1(vite@6.0.10(@types/node@18.19.61)(jiti@2.4.2)(sass@1.83.4)(terser@5.37.0))(vue@3.5.13(typescript@5.7.3)) - '@vue/compiler-sfc': - specifier: ^3.5.13 - version: 3.5.13 - rimraf: - specifier: ^3.0.2 - version: 3.0.2 - vite: - specifier: ^6.0.10 - version: 6.0.10(@types/node@18.19.61)(jiti@2.4.2)(sass@1.83.4)(terser@5.37.0) - vue-tsc: - specifier: ^2.2.0 - version: 2.2.0(typescript@5.7.3) runtime/vue-runtime-help: dependencies: @@ -1045,15 +1020,9 @@ importers: specifier: ^0.14.10 version: 0.14.10(@vue/composition-api@1.7.2(vue@3.5.13(typescript@5.7.3)))(vue@3.5.13(typescript@5.7.3)) devDependencies: - '@types/node': - specifier: ^18.19.0 - version: 18.19.61 '@vue/test-utils': specifier: ^2.4.6 version: 2.4.6 - rimraf: - specifier: ^3.0.2 - version: 3.0.2 runtime/vue2: dependencies: diff --git a/rollup.dts.config.js b/rollup.dts.config.js index 726f6923..c395d4a1 100644 --- a/rollup.dts.config.js +++ b/rollup.dts.config.js @@ -12,41 +12,49 @@ if (!existsSync('temp')) { process.exit(1); } -removeScss('temp/editor/src/index.d.ts'); -removeScss('temp/form/src/index.d.ts'); -removeScss('temp/design/src/index.d.ts'); -removeScss('temp/table/src/index.d.ts'); +removeScss('temp/packages/editor/src/index.d.ts'); +removeScss('temp/packages/form/src/index.d.ts'); +removeScss('temp/packages/design/src/index.d.ts'); +removeScss('temp/packages/table/src/index.d.ts'); -const packages = readdirSync('temp'); +const packages = readdirSync('temp/packages'); +const runtimes = readdirSync('temp/runtime'); const targets = process.env.TARGETS ? process.env.TARGETS.split(',') : null; const targetPackages = targets ? packages.filter((pkg) => targets.includes(pkg)) : packages; const __dirname = path.dirname(fileURLToPath(import.meta.url)); -export default targetPackages.map((pkg) => ({ - input: `./temp/${pkg}/src/index.d.ts`, - output: { - file: `packages/${pkg}/types/index.d.ts`, - format: 'es', - }, - plugins: [ - alias({ - entries: [ - { find: /^@form/, replacement: path.join(__dirname, `./temp/form/src`) }, - { find: /^@editor/, replacement: path.join(__dirname, `./temp/editor/src`) }, - { find: /^@data-source/, replacement: path.join(__dirname, `./temp/data-source/src`) }, - ], - }), - dts(), - ], - onwarn(warning, warn) { - // during dts rollup, everything is externalized by default - if (warning.code === 'UNRESOLVED_IMPORT' && !warning.exporter?.startsWith('.')) { - return; - } - warn(warning); - }, -})); +function rollupConfig(pkg, base) { + return { + input: `./temp/${base}/${pkg}/src/index.d.ts`, + output: { + file: `${base}/${pkg}/types/index.d.ts`, + format: 'es', + }, + plugins: [ + alias({ + entries: [ + { find: /^@form/, replacement: path.join(__dirname, `./temp/packages/form/src`) }, + { find: /^@editor/, replacement: path.join(__dirname, `./temp/packages/editor/src`) }, + { find: /^@data-source/, replacement: path.join(__dirname, `./temp/packages/data-source/src`) }, + ], + }), + dts(), + ], + onwarn(warning, warn) { + // during dts rollup, everything is externalized by default + if (warning.code === 'UNRESOLVED_IMPORT' && !warning.exporter?.startsWith('.')) { + return; + } + warn(warning); + }, + }; +} + +export default [ + ...targetPackages.map((pkg) => rollupConfig(pkg, 'packages')), + ...runtimes.map((pkg) => rollupConfig(pkg, 'runtime')), +]; function removeScss(path) { writeFileSync(path, readFileSync(path).toString().replace(`import './theme/index.scss';`, '')); diff --git a/runtime/react-runtime-help/package.json b/runtime/react-runtime-help/package.json index 4d632fa0..1b324e24 100644 --- a/runtime/react-runtime-help/package.json +++ b/runtime/react-runtime-help/package.json @@ -3,24 +3,22 @@ "name": "@tmagic/react-runtime-help", "type": "module", "sideEffects": false, - "main": "dist/index.js", - "types": "dist/index.d.ts", + "main": "dist/tmagic-react-runtime-help.umd.cjs", + "module": "dist/tmagic-react-runtime-help.js", + "types": "types/index.d.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.js" + "types": "./types/index.d.ts", + "import": "./dist/tmagic-react-runtime-help.js", + "require": "./dist/tmagic-react-runtime-help.umd.cjs" }, "./*": "./*" }, "files": [ - "dist" + "dist", + "types" ], "license": "Apache-2.0", - "scripts": { - "build": "pnpm clean && tsc -b tsconfig.build.json", - "clean": "rimraf dist *.tsbuildinfo", - "check:type": "tsc --noEmit --project tsconfig.build.json" - }, "engines": { "node": ">=18" }, @@ -51,8 +49,6 @@ }, "devDependencies": { "@types/lodash-es": "^4.17.4", - "@types/node": "^18.19.0", - "@types/react": "^18.3.3", - "rimraf": "^3.0.2" + "@types/react": "^18.3.3" } } \ No newline at end of file diff --git a/runtime/react-runtime-help/tsconfig.build.json b/runtime/react-runtime-help/tsconfig.build.json deleted file mode 100644 index ea5ec8de..00000000 --- a/runtime/react-runtime-help/tsconfig.build.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "rootDir": "./src", - "outDir": "./dist", - "declaration": true, - "sourceMap": false, - "types": ["node"], - }, - "include": ["./src"], -} diff --git a/runtime/react-runtime-help/tsconfig.build.tsbuildinfo b/runtime/react-runtime-help/tsconfig.build.tsbuildinfo deleted file mode 100644 index bad55a57..00000000 --- a/runtime/react-runtime-help/tsconfig.build.tsbuildinfo +++ /dev/null @@ -1 +0,0 @@ -{"root":["./src/AppContent.ts","./src/index.ts","./src/hooks/use-app.ts","./src/hooks/use-dsl.ts","./src/hooks/use-editor-dsl.ts"],"version":"5.6.3"} \ No newline at end of file diff --git a/runtime/react-runtime-help/tsconfig.json b/runtime/react-runtime-help/tsconfig.json deleted file mode 100644 index cb593495..00000000 --- a/runtime/react-runtime-help/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "baseUrl": "./", - "jsx": "react", - "forceConsistentCasingInFileNames": true, - "types": ["node"], - }, -} diff --git a/runtime/tmagic-form/package.json b/runtime/tmagic-form/package.json index b97d8b93..36b434d8 100644 --- a/runtime/tmagic-form/package.json +++ b/runtime/tmagic-form/package.json @@ -18,12 +18,6 @@ "types" ], "license": "Apache-2.0", - "scripts": { - "build": "npm run build:type && vite build", - "build:type": "npm run clear:type && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build.json", - "clear:type": "rimraf ./types", - "type:check": "vue-tsc --noEmit" - }, "engines": { "node": ">=18" }, @@ -45,13 +39,5 @@ "typescript": { "optional": true } - }, - "devDependencies": { - "@types/node": "^18.19.0", - "@vitejs/plugin-vue": "^5.2.1", - "@vue/compiler-sfc": "^3.5.13", - "rimraf": "^3.0.2", - "vite": "^6.0.10", - "vue-tsc": "^2.2.0" } } diff --git a/runtime/tmagic-form/tsconfig.build.json b/runtime/tmagic-form/tsconfig.build.json deleted file mode 100644 index c9476221..00000000 --- a/runtime/tmagic-form/tsconfig.build.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "baseUrl": ".", - "declaration": true, - "declarationDir": "types", - "forceConsistentCasingInFileNames": true, - "paths": {}, - }, - "include": [ - "src" - ], -} diff --git a/runtime/tmagic-form/tsconfig.json b/runtime/tmagic-form/tsconfig.json deleted file mode 100644 index 6c40cf1e..00000000 --- a/runtime/tmagic-form/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "baseUrl": "../..", - }, -} diff --git a/runtime/tmagic-form/vite.config.ts b/runtime/tmagic-form/vite.config.ts deleted file mode 100644 index df809f53..00000000 --- a/runtime/tmagic-form/vite.config.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making TMagicEditor available. - * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { defineConfig } from 'vite'; -import vue from '@vitejs/plugin-vue'; - -import pkg from './package.json'; - -export default defineConfig({ - plugins: [vue()], - - build: { - cssCodeSplit: false, - sourcemap: false, - minify: false, - target: 'esnext', - - lib: { - entry: 'src/index.ts', - name: 'TMagicFormRuntime', - fileName: 'tmagic-form-runtime', - }, - - rollupOptions: { - // 确保外部化处理那些你不想打包进库的依赖 - external(id: string) { - return Object.keys(pkg.peerDependencies).some((k) => new RegExp(`^${k}`).test(id)); - }, - }, - }, -}); diff --git a/runtime/vue-runtime-help/package.json b/runtime/vue-runtime-help/package.json index 8052f740..c0b9320c 100644 --- a/runtime/vue-runtime-help/package.json +++ b/runtime/vue-runtime-help/package.json @@ -3,24 +3,22 @@ "name": "@tmagic/vue-runtime-help", "type": "module", "sideEffects": false, - "main": "dist/index.js", - "types": "dist/index.d.ts", + "main": "dist/tmagic-vue-runtime-help.umd.cjs", + "module": "dist/tmagic-vue-runtime-help.js", + "types": "types/index.d.ts", "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.js" + "types": "./types/index.d.ts", + "import": "./dist/tmagic-vue-runtime-help.js", + "require": "./dist/tmagic-vue-runtime-help.umd.cjs" }, "./*": "./*" }, "files": [ - "dist" + "dist", + "types" ], "license": "Apache-2.0", - "scripts": { - "build": "pnpm clean && tsc -b tsconfig.build.json", - "clean": "rimraf dist *.tsbuildinfo", - "check:type": "tsc --noEmit --project tsconfig.build.json" - }, "engines": { "node": ">=18" }, @@ -53,8 +51,6 @@ } }, "devDependencies": { - "@types/node": "^18.19.0", - "@vue/test-utils": "^2.4.6", - "rimraf": "^3.0.2" + "@vue/test-utils": "^2.4.6" } } \ No newline at end of file diff --git a/runtime/vue-runtime-help/tsconfig.build.json b/runtime/vue-runtime-help/tsconfig.build.json deleted file mode 100644 index ea5ec8de..00000000 --- a/runtime/vue-runtime-help/tsconfig.build.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "rootDir": "./src", - "outDir": "./dist", - "declaration": true, - "sourceMap": false, - "types": ["node"], - }, - "include": ["./src"], -} diff --git a/runtime/vue-runtime-help/tsconfig.build.tsbuildinfo b/runtime/vue-runtime-help/tsconfig.build.tsbuildinfo deleted file mode 100644 index a38d7546..00000000 --- a/runtime/vue-runtime-help/tsconfig.build.tsbuildinfo +++ /dev/null @@ -1 +0,0 @@ -{"root":["./src/index.ts","./src/hooks/use-app.ts","./src/hooks/use-component.ts","./src/hooks/use-dsl.ts","./src/hooks/use-editor-dsl.ts"],"version":"5.6.3"} \ No newline at end of file diff --git a/runtime/vue-runtime-help/tsconfig.json b/runtime/vue-runtime-help/tsconfig.json deleted file mode 100644 index d32895bd..00000000 --- a/runtime/vue-runtime-help/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "baseUrl": "./", - "types": ["node"], - }, -} diff --git a/scripts/build.mjs b/scripts/build.mjs index d85689a0..9701a2e4 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -14,6 +14,7 @@ const toPascalCase = (str) => str.replace(/(^\w|-\w)/g, (text) => text.replace(/ const __dirname = path.dirname(fileURLToPath(import.meta.url)); const packagesDir = path.resolve(__dirname, '../packages'); +const runtimeDir = path.resolve(__dirname, '../runtime'); if (args.package) { const pkgRoot = path.resolve(packagesDir, args.package); @@ -24,26 +25,27 @@ if (args.package) { build({ packageName: args.package, format: 'umd' }); } } else { - const packages = fs.readdirSync(packagesDir).filter((p) => { - const pkgRoot = path.resolve(packagesDir, p); - if (fs.statSync(pkgRoot).isDirectory()) { - const pkg = JSON.parse(fs.readFileSync(path.resolve(pkgRoot, 'package.json'), 'utf-8')); - return !pkg.private && !pkg.bin; - } - return false; - }); + const packages = getPackageNames(packagesDir); + const runtimeHelpers = getPackageNames(runtimeDir); for (const packageName of packages) { rimraf.sync(path.resolve(packagesDir, `./${packageName}/dist`)); + const pkg = createRequire(import.meta.url)(`../packages/${packageName}/package.json`); - build({ packageName, format: 'es' }); - build({ packageName, format: 'umd' }); + build({ packageName, format: 'es', pkg, packagesDir }); + build({ packageName, format: 'umd', pkg, packagesDir }); + } + + for (const packageName of runtimeHelpers) { + rimraf.sync(path.resolve(runtimeDir, `./${packageName}/dist`)); + const pkg = createRequire(import.meta.url)(`../runtime/${packageName}/package.json`); + + build({ packageName, format: 'es', pkg, packagesDir: runtimeDir }); + build({ packageName, format: 'umd', pkg, packagesDir: runtimeDir }); } } -async function build({ packageName, format }) { - const pkg = createRequire(import.meta.url)(`../packages/${packageName}/package.json`); - +async function build({ packageName, format, pkg, packagesDir }) { await buildVite({ root: path.resolve(packagesDir, `./${packageName}`), clearScreen: false, @@ -94,3 +96,14 @@ async function build({ packageName, format }) { }, }); } + +function getPackageNames(packagesDir) { + return fs.readdirSync(packagesDir).filter((p) => { + const pkgRoot = path.resolve(packagesDir, p); + if (fs.statSync(pkgRoot).isDirectory()) { + const pkg = JSON.parse(fs.readFileSync(path.resolve(pkgRoot, 'package.json'), 'utf-8')); + return !pkg.private && !pkg.bin; + } + return false; + }); +} diff --git a/tsconfig.build-browser.json b/tsconfig.build-browser.json index cade1360..943631ed 100644 --- a/tsconfig.build-browser.json +++ b/tsconfig.build-browser.json @@ -15,5 +15,7 @@ "packages/element-plus-adapter/src", "packages/ui/src", "packages/ui-react/src", + "runtime/react-runtime-help/src", + "runtime/vue-runtime-help/src", ] } diff --git a/tsconfig.build-vue.json b/tsconfig.build-vue.json index 87546a28..eba0975f 100644 --- a/tsconfig.build-vue.json +++ b/tsconfig.build-vue.json @@ -11,5 +11,6 @@ "packages/form/src", "packages/table/src", "packages/tdesign-vue-next-adapter/src", + "runtime/tmagic-form/src", ] } diff --git a/tsconfig.check-vue.json b/tsconfig.check-vue.json index 47f14bd1..11eac7e5 100644 --- a/tsconfig.check-vue.json +++ b/tsconfig.check-vue.json @@ -6,5 +6,6 @@ "packages/form/src", "packages/table/src", "packages/tdesign-vue-next-adapter/src", + "runtime/tmagic-form/src", ] } diff --git a/tsconfig.check.json b/tsconfig.check.json index badda01e..44dca5df 100644 --- a/tsconfig.check.json +++ b/tsconfig.check.json @@ -8,5 +8,7 @@ "packages/stage/src", "packages/utils/src", "packages/element-plus-adapter/src", + "runtime/react-runtime-help/src", + "runtime/vue-runtime-help/src", ] }