diff --git a/cli/package.json b/cli/package.json index 5e717df3..cdab6ce1 100644 --- a/cli/package.json +++ b/cli/package.json @@ -27,7 +27,7 @@ "templates" ], "scripts": { - "build": "tsdown" + "build": "tsdown --config-loader unrun" }, "dependencies": { "@clack/prompts": "catalog:prod", diff --git a/cli/tsdown.config.mjs b/cli/tsdown.config.ts similarity index 100% rename from cli/tsdown.config.mjs rename to cli/tsdown.config.ts diff --git a/plugins/plugin-fonts/package.json b/plugins/plugin-fonts/package.json index b3530d20..a8795dd1 100644 --- a/plugins/plugin-fonts/package.json +++ b/plugins/plugin-fonts/package.json @@ -30,7 +30,7 @@ "build": "pnpm run tsdown && pnpm run copy", "clean": "rimraf --glob ./lib", "copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png,woff2}\" lib", - "tsdown": "tsdown" + "tsdown": "tsdown --config-loader unrun" }, "peerDependencies": { "vuepress": "catalog:vuepress" diff --git a/plugins/plugin-fonts/tsdown.config.mjs b/plugins/plugin-fonts/tsdown.config.ts similarity index 68% rename from plugins/plugin-fonts/tsdown.config.mjs rename to plugins/plugin-fonts/tsdown.config.ts index 04c322b0..486da7aa 100644 --- a/plugins/plugin-fonts/tsdown.config.mjs +++ b/plugins/plugin-fonts/tsdown.config.ts @@ -1,7 +1,5 @@ -import { defineConfig } from 'tsdown' -import { argv } from '../../scripts/tsdown-args.mjs' - -/** @import {Options} from 'tsdown' */ +import { defineConfig, type UserConfig } from 'tsdown' +import { argv } from '../../scripts/tsdown-args' const clientExternal = [ /.*\.vue$/, @@ -9,15 +7,13 @@ const clientExternal = [ ] export default defineConfig(() => { - /** @type {Options} */ - const DEFAULT_OPTIONS = { + const DEFAULT_OPTIONS: UserConfig = { dts: true, sourcemap: false, format: 'esm', fixedExtension: false, } - /** @type {Options[]} */ - const options = [] + const options: UserConfig[] = [] if (argv.node) { options.push({ @@ -36,7 +32,7 @@ export default defineConfig(() => { entry: ['./src/client/config.ts'], outDir: './lib/client', dts: false, - external: clientExternal, + deps: { neverBundle: clientExternal }, }, ]) } diff --git a/plugins/plugin-md-power/package.json b/plugins/plugin-md-power/package.json index 342d7b2d..3814b196 100644 --- a/plugins/plugin-md-power/package.json +++ b/plugins/plugin-md-power/package.json @@ -36,8 +36,8 @@ "clean": "rimraf --glob ./lib", "copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib", "copy:watch": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib -w", - "tsdown": "tsdown", - "tsdown:watch": "tsdown --watch -- -c" + "tsdown": "tsdown --config-loader unrun", + "tsdown:watch": "tsdown --config-loader unrun --watch -- -c" }, "peerDependencies": { "artplayer": "catalog:peer", diff --git a/plugins/plugin-md-power/tsdown.config.mjs b/plugins/plugin-md-power/tsdown.config.ts similarity index 77% rename from plugins/plugin-md-power/tsdown.config.mjs rename to plugins/plugin-md-power/tsdown.config.ts index e68634ac..e1e9cd8e 100644 --- a/plugins/plugin-md-power/tsdown.config.mjs +++ b/plugins/plugin-md-power/tsdown.config.ts @@ -1,7 +1,5 @@ -import { defineConfig } from 'tsdown' -import { argv } from '../../scripts/tsdown-args.mjs' - -/** @import {Options} from 'tsdown' */ +import { defineConfig, type UserConfig } from 'tsdown' +import { argv } from '../../scripts/tsdown-args' const config = [ { dir: 'composables', files: ['codeRepl.ts', 'pdf.ts', 'rustRepl.ts', 'size.ts', 'audio.ts', 'demo.ts', 'mark.ts', 'decrypt.ts'] }, @@ -18,8 +16,7 @@ const clientExternal = [ ] export default defineConfig((cli) => { - /** @type {Options} */ - const DEFAULT_OPTIONS = { + const DEFAULT_OPTIONS: UserConfig = { dts: true, sourcemap: false, format: 'esm', @@ -27,8 +24,7 @@ export default defineConfig((cli) => { fixedExtension: false, } - /** @type {Options[]} */ - const options = [] + const options: UserConfig[] = [] // shared options.push({ @@ -43,7 +39,7 @@ export default defineConfig((cli) => { entry: ['./src/node/index.ts'], outDir: './lib/node', target: 'node20.19.0', - external: ['markdown-it', /^@?vuepress/], + deps: { neverBundle: ['markdown-it', /^@?vuepress/] }, }) } @@ -52,7 +48,7 @@ export default defineConfig((cli) => { ...DEFAULT_OPTIONS, entry: files.map(file => `./src/client/${dir}/${file}`), outDir: `./lib/client/${dir}`, - external: clientExternal, + deps: { neverBundle: clientExternal }, }))) } return options diff --git a/plugins/plugin-search/package.json b/plugins/plugin-search/package.json index 8197b8b4..7b5ae352 100644 --- a/plugins/plugin-search/package.json +++ b/plugins/plugin-search/package.json @@ -34,7 +34,7 @@ "build": "pnpm run tsdown && pnpm run copy", "clean": "rimraf --glob ./lib", "copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib", - "tsdown": "tsdown" + "tsdown": "tsdown --config-loader unrun" }, "peerDependencies": { "vuepress": "catalog:vuepress" diff --git a/plugins/plugin-search/tsdown.config.mjs b/plugins/plugin-search/tsdown.config.ts similarity index 76% rename from plugins/plugin-search/tsdown.config.mjs rename to plugins/plugin-search/tsdown.config.ts index 70477fe5..39af934a 100644 --- a/plugins/plugin-search/tsdown.config.mjs +++ b/plugins/plugin-search/tsdown.config.ts @@ -1,7 +1,5 @@ -import { defineConfig } from 'tsdown' -import { argv } from '../../scripts/tsdown-args.mjs' - -/** @import {Options} from 'tsdown' */ +import { defineConfig, type UserConfig } from 'tsdown' +import { argv } from '../../scripts/tsdown-args' const sharedExternal = [ /.*\/shared\/index\.js$/, @@ -15,16 +13,14 @@ const clientExternal = [ ] export default defineConfig(() => { - /** @type {Options} */ - const DEFAULT_OPTIONS = { + const DEFAULT_OPTIONS: UserConfig = { dts: true, sourcemap: false, format: 'esm', fixedExtension: false, } - /** @type {Options[]} */ - const options = [] + const options: UserConfig[] = [] // shared options.push({ @@ -38,7 +34,7 @@ export default defineConfig(() => { ...DEFAULT_OPTIONS, entry: ['./src/node/index.ts'], outDir: './lib/node', - external: sharedExternal, + deps: { neverBundle: sharedExternal }, target: 'node20.19.0', }) } @@ -50,21 +46,21 @@ export default defineConfig(() => { ...DEFAULT_OPTIONS, entry: ['./src/client/utils/index.ts'], outDir: './lib/client/utils', - external: clientExternal, + deps: { neverBundle: clientExternal }, }, // client/composables/index.js { ...DEFAULT_OPTIONS, entry: ['./src/client/composables/index.ts'], outDir: './lib/client/composables', - external: clientExternal, + deps: { neverBundle: clientExternal }, }, // client/config.js { ...DEFAULT_OPTIONS, entry: ['./src/client/config.ts'], outDir: './lib/client', - external: clientExternal, + deps: { neverBundle: clientExternal }, dts: false, }, // client/index.js @@ -72,10 +68,10 @@ export default defineConfig(() => { ...DEFAULT_OPTIONS, entry: ['./src/client/index.ts'], outDir: './lib/client', - external: [ + deps: { neverBundle: [ ...clientExternal, './composables/index.js', - ], + ] }, }, ]) } diff --git a/scripts/mirror-sync.mjs b/scripts/mirror-sync.mjs index 7ace1211..1ae6b1b4 100644 --- a/scripts/mirror-sync.mjs +++ b/scripts/mirror-sync.mjs @@ -33,9 +33,7 @@ async function npmMirrorSync() { resolve() }) - req.on('error', (error) => { - reject(error) - }) + req.on('error', reject) req.end() }) diff --git a/scripts/tsdown-args.mjs b/scripts/tsdown-args.ts similarity index 66% rename from scripts/tsdown-args.mjs rename to scripts/tsdown-args.ts index b389aaaa..5b4386a7 100644 --- a/scripts/tsdown-args.mjs +++ b/scripts/tsdown-args.ts @@ -1,16 +1,10 @@ import process from 'node:process' import minimist from 'minimist' -// interface ArgvOptions { -// client: boolean -// node: boolean -// } - -/** - * @typedef {object} ArgvOptions - * @property {boolean} client - 是否构建客户端 - * @property {boolean} node - 是否构建 node 端 - */ +interface ArgvOptions { + client: boolean + node: boolean +} const rawArgv = process.argv.slice(2) const tsupArgv = rawArgv.includes('--') ? rawArgv.slice(rawArgv.indexOf('--') + 1) : [] @@ -30,8 +24,7 @@ const parsed = tsupArgv.length all: true, } -/** @type {ArgvOptions} */ -export const argv = { +export const argv: ArgvOptions = { client: parsed.client || parsed.all, node: parsed.node || parsed.all, } diff --git a/theme/package.json b/theme/package.json index ac2bab5a..bf9bd2ee 100644 --- a/theme/package.json +++ b/theme/package.json @@ -62,8 +62,8 @@ "clean": "rimraf --glob ./lib", "copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png,woff2}\" lib", "copy:watch": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png,woff2}\" lib -w", - "tsdown": "tsdown", - "tsdown:watch": "tsdown --watch -- -c" + "tsdown": "tsdown --config-loader unrun", + "tsdown:watch": "tsdown --config-loader unrun --watch -- -c" }, "peerDependencies": { "@iconify/json": ">=2", diff --git a/theme/tsdown.config.mjs b/theme/tsdown.config.ts similarity index 81% rename from theme/tsdown.config.mjs rename to theme/tsdown.config.ts index d59088a2..cd0f94f8 100644 --- a/theme/tsdown.config.mjs +++ b/theme/tsdown.config.ts @@ -1,8 +1,8 @@ import fs from 'node:fs' import path from 'node:path' import process from 'node:process' -import { defineConfig } from 'tsdown' -import { argv } from '../scripts/tsdown-args.mjs' +import { defineConfig, type UserConfig } from 'tsdown' +import { argv } from '../scripts/tsdown-args' /** @import {Options} from 'tsdown' */ @@ -24,25 +24,22 @@ const featuresComposables = fs.readdirSync( ) export default defineConfig((cli) => { - /** @type {Options} */ - const DEFAULT_OPTIONS = { + const DEFAULT_OPTIONS: UserConfig = { dts: true, sourcemap: false, watch: cli.watch, format: 'esm', - silent: !!cli.watch, clean: !cli.watch, fixedExtension: false, } - /** @type {Options[]} */ - const options = [] + const options: UserConfig[] = [] // shared options.push({ ...DEFAULT_OPTIONS, entry: ['./src/shared/index.ts'], outDir: './lib/shared', - external: ['sax'], + deps: { neverBundle: ['sax'] }, }) if (argv.node) { @@ -50,20 +47,20 @@ export default defineConfig((cli) => { ...DEFAULT_OPTIONS, entry: ['./src/node/index.ts'], outDir: './lib/node', - external: [...sharedExternal, '@pinyin-pro/data/complete'], + deps: { neverBundle: [...sharedExternal, '@pinyin-pro/data/complete'] }, target: 'node20.19.0', watch: false, }) } if (argv.client) { - options.push(...[ + options.push( // client/utils/index.js { ...DEFAULT_OPTIONS, entry: ['./src/client/utils/index.ts'], outDir: './lib/client/utils', platform: 'browser', - external: clientExternal, + deps: { neverBundle: clientExternal }, }, // client/composables/index.js { @@ -71,10 +68,10 @@ export default defineConfig((cli) => { entry: ['./src/client/composables/index.ts'], outDir: './lib/client/composables', platform: 'browser', - external: [ + deps: { neverBundle: [ ...clientExternal, '../utils/index.js', - ], + ] }, }, // client/config.js { @@ -83,11 +80,11 @@ export default defineConfig((cli) => { outDir: './lib/client', dts: false, platform: 'browser', - external: [ + deps: { neverBundle: [ ...clientExternal, './composables/index.js', './utils/index.js', - ], + ] }, }, // client/index.js { @@ -95,26 +92,26 @@ export default defineConfig((cli) => { entry: ['./src/client/index.ts'], outDir: './lib/client', platform: 'browser', - external: [ + deps: { neverBundle: [ ...clientExternal, './composables/index.js', './utils/index.js', './config.js', - ], + ] }, }, ...featuresComposables.map(file => ({ ...DEFAULT_OPTIONS, entry: [`./src/client/features/composables/${file}`], outDir: `./lib/client/features/composables/`, platform: 'browser', - external: [ + deps: { neverBundle: [ ...clientExternal, '../../composables/index.js', '../../utils/index.js', ...featuresComposables.map(file => `./${file.replace('.ts', '.js')}`), - ], - })), - ]) + ] }, + } as UserConfig)), + ) } return options }) diff --git a/tsconfig.json b/tsconfig.json index 6153f20b..3d570563 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,8 @@ "theme/**/*", "docs/.vuepress/**/*", "cli/**/*", - "scripts/**/*" + "scripts/**/*", + "**/tsdown.config.ts" ], "exclude": [ "**/node_modules/**",