diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c3ffd4c..cf4c85f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,6 +25,13 @@ importers: vue-tsc: specifier: ^1.8.1 version: 1.8.1(typescript@5.1.3) + optionalDependencies: + rollup: + specifier: '*' + version: 3.20.2 + vite: + specifier: '*' + version: 4.3.9(@types/node@20.3.1) devDependencies: '@commitlint/cli': specifier: ^17.6.6 @@ -122,9 +129,6 @@ importers: unbuild: specifier: ^1.2.1 version: 1.2.1 - vite: - specifier: ^4.3.9 - version: 4.3.9(@types/node@20.3.1) vitest: specifier: ^0.32.2 version: 0.32.2 @@ -907,7 +911,6 @@ packages: cpu: [arm64] os: [android] requiresBuild: true - dev: true optional: true /@esbuild/android-arm@0.17.16: @@ -916,7 +919,6 @@ packages: cpu: [arm] os: [android] requiresBuild: true - dev: true optional: true /@esbuild/android-x64@0.17.16: @@ -925,7 +927,6 @@ packages: cpu: [x64] os: [android] requiresBuild: true - dev: true optional: true /@esbuild/darwin-arm64@0.17.16: @@ -934,7 +935,6 @@ packages: cpu: [arm64] os: [darwin] requiresBuild: true - dev: true optional: true /@esbuild/darwin-x64@0.17.16: @@ -943,7 +943,6 @@ packages: cpu: [x64] os: [darwin] requiresBuild: true - dev: true optional: true /@esbuild/freebsd-arm64@0.17.16: @@ -952,7 +951,6 @@ packages: cpu: [arm64] os: [freebsd] requiresBuild: true - dev: true optional: true /@esbuild/freebsd-x64@0.17.16: @@ -961,7 +959,6 @@ packages: cpu: [x64] os: [freebsd] requiresBuild: true - dev: true optional: true /@esbuild/linux-arm64@0.17.16: @@ -970,7 +967,6 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-arm@0.17.16: @@ -979,7 +975,6 @@ packages: cpu: [arm] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-ia32@0.17.16: @@ -988,7 +983,6 @@ packages: cpu: [ia32] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-loong64@0.17.16: @@ -997,7 +991,6 @@ packages: cpu: [loong64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-mips64el@0.17.16: @@ -1006,7 +999,6 @@ packages: cpu: [mips64el] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-ppc64@0.17.16: @@ -1015,7 +1007,6 @@ packages: cpu: [ppc64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-riscv64@0.17.16: @@ -1024,7 +1015,6 @@ packages: cpu: [riscv64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-s390x@0.17.16: @@ -1033,7 +1023,6 @@ packages: cpu: [s390x] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/linux-x64@0.17.16: @@ -1042,7 +1031,6 @@ packages: cpu: [x64] os: [linux] requiresBuild: true - dev: true optional: true /@esbuild/netbsd-x64@0.17.16: @@ -1051,7 +1039,6 @@ packages: cpu: [x64] os: [netbsd] requiresBuild: true - dev: true optional: true /@esbuild/openbsd-x64@0.17.16: @@ -1060,7 +1047,6 @@ packages: cpu: [x64] os: [openbsd] requiresBuild: true - dev: true optional: true /@esbuild/sunos-x64@0.17.16: @@ -1069,7 +1055,6 @@ packages: cpu: [x64] os: [sunos] requiresBuild: true - dev: true optional: true /@esbuild/win32-arm64@0.17.16: @@ -1078,7 +1063,6 @@ packages: cpu: [arm64] os: [win32] requiresBuild: true - dev: true optional: true /@esbuild/win32-ia32@0.17.16: @@ -1087,7 +1071,6 @@ packages: cpu: [ia32] os: [win32] requiresBuild: true - dev: true optional: true /@esbuild/win32-x64@0.17.16: @@ -1096,7 +1079,6 @@ packages: cpu: [x64] os: [win32] requiresBuild: true - dev: true optional: true /@eslint-community/eslint-utils@4.4.0(eslint@8.43.0): @@ -1290,7 +1272,7 @@ packages: dev: true optional: true - /@rollup/plugin-alias@5.0.0(rollup@3.20.2): + /@rollup/plugin-alias@5.0.0(rollup@3.25.2): resolution: {integrity: sha512-l9hY5chSCjuFRPsnRm16twWBiSApl2uYFLsepQYwtBuAxNMQ/1dJqADld40P0Jkqm65GRTLy/AC6hnpVebtLsA==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1299,11 +1281,11 @@ packages: rollup: optional: true dependencies: - rollup: 3.20.2 + rollup: 3.25.2 slash: 4.0.0 dev: true - /@rollup/plugin-commonjs@24.1.0(rollup@3.20.2): + /@rollup/plugin-commonjs@24.1.0(rollup@3.25.2): resolution: {integrity: sha512-eSL45hjhCWI0jCCXcNtLVqM5N1JlBGvlFfY0m6oOYnLCJ6N0qEXoZql4sY2MOUArzhH4SA/qBpTxvvZp2Sc+DQ==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1312,16 +1294,16 @@ packages: rollup: optional: true dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.20.2) + '@rollup/pluginutils': 5.0.2(rollup@3.25.2) commondir: 1.0.1 estree-walker: 2.0.2 glob: 8.1.0 is-reference: 1.2.1 magic-string: 0.27.0 - rollup: 3.20.2 + rollup: 3.25.2 dev: true - /@rollup/plugin-json@6.0.0(rollup@3.20.2): + /@rollup/plugin-json@6.0.0(rollup@3.25.2): resolution: {integrity: sha512-i/4C5Jrdr1XUarRhVu27EEwjt4GObltD7c+MkCIpO2QIbojw8MUs+CCTqOphQi3Qtg1FLmYt+l+6YeoIf51J7w==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1330,11 +1312,11 @@ packages: rollup: optional: true dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.20.2) - rollup: 3.20.2 + '@rollup/pluginutils': 5.0.2(rollup@3.25.2) + rollup: 3.25.2 dev: true - /@rollup/plugin-node-resolve@15.0.2(rollup@3.20.2): + /@rollup/plugin-node-resolve@15.0.2(rollup@3.25.2): resolution: {integrity: sha512-Y35fRGUjC3FaurG722uhUuG8YHOJRJQbI6/CkbRkdPotSpDj9NtIN85z1zrcyDcCQIW4qp5mgG72U+gJ0TAFEg==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1343,16 +1325,16 @@ packages: rollup: optional: true dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.20.2) + '@rollup/pluginutils': 5.0.2(rollup@3.25.2) '@types/resolve': 1.20.2 deepmerge: 4.3.1 is-builtin-module: 3.2.1 is-module: 1.0.0 resolve: 1.22.2 - rollup: 3.20.2 + rollup: 3.25.2 dev: true - /@rollup/plugin-replace@5.0.2(rollup@3.20.2): + /@rollup/plugin-replace@5.0.2(rollup@3.25.2): resolution: {integrity: sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA==} engines: {node: '>=14.0.0'} peerDependencies: @@ -1361,9 +1343,9 @@ packages: rollup: optional: true dependencies: - '@rollup/pluginutils': 5.0.2(rollup@3.20.2) + '@rollup/pluginutils': 5.0.2(rollup@3.25.2) magic-string: 0.27.0 - rollup: 3.20.2 + rollup: 3.25.2 dev: true /@rollup/pluginutils@5.0.2(rollup@3.20.2): @@ -1379,6 +1361,22 @@ packages: estree-walker: 2.0.2 picomatch: 2.3.1 rollup: 3.20.2 + dev: false + + /@rollup/pluginutils@5.0.2(rollup@3.25.2): + resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@types/estree': 1.0.0 + estree-walker: 2.0.2 + picomatch: 2.3.1 + rollup: 3.25.2 + dev: true /@rushstack/node-core-library@3.59.4(@types/node@20.3.1): resolution: {integrity: sha512-YAKJDC6Mz/KA1D7bvB88WaRX3knt/ZuLzkRu5G9QADGSjLtvTWzCNCytRF2PCSaaHOZaZsWul4F1KQdgFgUDqA==} @@ -1808,7 +1806,7 @@ packages: '@vue/shared': 3.2.41 estree-walker: 2.0.2 magic-string: 0.25.9 - postcss: 8.4.21 + postcss: 8.4.24 source-map: 0.6.1 /@vue/compiler-ssr@3.2.41: @@ -2863,7 +2861,6 @@ packages: '@esbuild/win32-arm64': 0.17.16 '@esbuild/win32-ia32': 0.17.16 '@esbuild/win32-x64': 0.17.16 - dev: true /escalade@3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} @@ -4755,14 +4752,6 @@ packages: util-deprecate: 1.0.2 dev: true - /postcss@8.4.21: - resolution: {integrity: sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==} - engines: {node: ^10 || ^12 || >=14} - dependencies: - nanoid: 3.3.6 - picocolors: 1.0.0 - source-map-js: 1.0.2 - /postcss@8.4.24: resolution: {integrity: sha512-M0RzbcI0sO/XJNucsGjvWU9ERWxb/ytp1w6dKtxTKgixdtQDq4rmx/g8W1hnaheq9jgwL/oyEdH5Bc4WwJKMqg==} engines: {node: ^10 || ^12 || >=14} @@ -4770,7 +4759,6 @@ packages: nanoid: 3.3.6 picocolors: 1.0.0 source-map-js: 1.0.2 - dev: true /prelude-ls@1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} @@ -5029,7 +5017,7 @@ packages: glob: 10.3.0 dev: true - /rollup-plugin-dts@5.3.0(rollup@3.20.2)(typescript@5.1.3): + /rollup-plugin-dts@5.3.0(rollup@3.25.2)(typescript@5.1.3): resolution: {integrity: sha512-8FXp0ZkyZj1iU5klkIJYLjIq/YZSwBoERu33QBDxm/1yw5UU4txrEtcmMkrq+ZiKu3Q4qvPCNqc3ovX6rjqzbQ==} engines: {node: '>=v14'} peerDependencies: @@ -5037,7 +5025,7 @@ packages: typescript: ^4.1 || ^5.0 dependencies: magic-string: 0.30.0 - rollup: 3.20.2 + rollup: 3.25.2 typescript: 5.1.3 optionalDependencies: '@babel/code-frame': 7.22.5 @@ -5047,8 +5035,10 @@ packages: resolution: {integrity: sha512-3zwkBQl7Ai7MFYQE0y1MeQ15+9jsi7XxfrqwTb/9EK8D9C9+//EBR4M+CuA1KODRaNbFez/lWxA5vhEGZp4MUg==} engines: {node: '>=14.18.0', npm: '>=8.0.0'} hasBin: true + requiresBuild: true optionalDependencies: fsevents: 2.3.2 + dev: false /rollup@3.25.2: resolution: {integrity: sha512-VLnkxZMDr3jpxgtmS8pQZ0UvhslmF4ADq/9w4erkctbgjCqLW9oa89fJuXEs4ZmgyoF7Dm8rMDKSS5b5u2hHUg==} @@ -5056,7 +5046,6 @@ packages: hasBin: true optionalDependencies: fsevents: 2.3.2 - dev: true /run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -5618,12 +5607,12 @@ packages: resolution: {integrity: sha512-J4efk69Aye43tWcBPCsLK7TIRppGrEN4pAlDzRKo3HSE6MgTSTBxSEuE3ccx7ixc62JvGQ/CoFXYqqF2AHozow==} hasBin: true dependencies: - '@rollup/plugin-alias': 5.0.0(rollup@3.20.2) - '@rollup/plugin-commonjs': 24.1.0(rollup@3.20.2) - '@rollup/plugin-json': 6.0.0(rollup@3.20.2) - '@rollup/plugin-node-resolve': 15.0.2(rollup@3.20.2) - '@rollup/plugin-replace': 5.0.2(rollup@3.20.2) - '@rollup/pluginutils': 5.0.2(rollup@3.20.2) + '@rollup/plugin-alias': 5.0.0(rollup@3.25.2) + '@rollup/plugin-commonjs': 24.1.0(rollup@3.25.2) + '@rollup/plugin-json': 6.0.0(rollup@3.25.2) + '@rollup/plugin-node-resolve': 15.0.2(rollup@3.25.2) + '@rollup/plugin-replace': 5.0.2(rollup@3.25.2) + '@rollup/pluginutils': 5.0.2(rollup@3.25.2) chalk: 5.2.0 consola: 3.1.0 defu: 6.1.2 @@ -5638,8 +5627,8 @@ packages: pathe: 1.1.0 pkg-types: 1.0.2 pretty-bytes: 6.1.0 - rollup: 3.20.2 - rollup-plugin-dts: 5.3.0(rollup@3.20.2)(typescript@5.1.3) + rollup: 3.25.2 + rollup-plugin-dts: 5.3.0(rollup@3.25.2)(typescript@5.1.3) scule: 1.0.0 typescript: 5.1.3 untyped: 1.3.2 @@ -5766,7 +5755,6 @@ packages: rollup: 3.25.2 optionalDependencies: fsevents: 2.3.2 - dev: true /vitest@0.32.2: resolution: {integrity: sha512-hU8GNNuQfwuQmqTLfiKcqEhZY72Zxb7nnN07koCUNmntNxbKQnVbeIS6sqUgR3eXSlbOpit8+/gr1KpqoMgWCQ==} diff --git a/src/plugin.ts b/src/plugin.ts index c823c72..d5a6750 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -266,6 +266,9 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { libName = libName || '_default' indexName = indexName || defaultIndex + entryRoot = entryRoot || queryPublicPath(rootNames) + entryRoot = ensureAbsolute(entryRoot, root) + const diagnostics = program.getDeclarationDiagnostics() if (diagnostics?.length) { @@ -287,7 +290,14 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { }, transform(_, id) { - if (!program || !filter(id) || id.includes('.vue?vue') || (!tsRE.test(id) && !vueRE.test(id))) { return } + if ( + !program || + !filter(id) || + id.includes('.vue?vue') || + (!tsRE.test(id) && !vueRE.test(id)) + ) { + return + } id = normalizePath(id) rootFiles.delete(id) @@ -308,7 +318,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { const service = program.__vue.languageService for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) { - outputFiles.set(resolve(root, relative(outDir, outputFile.name)), outputFile.text) + outputFiles.set(normalizePath(outputFile.name), outputFile.text) } const dtsId = id.replace(tjsRE, '.d.ts') @@ -316,7 +326,10 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { dtsSourceFile && filter(dtsSourceFile.fileName) && - outputFiles.set(dtsSourceFile.fileName, dtsSourceFile.getFullText()) + outputFiles.set( + resolve(outDir, relative(entryRoot, dtsSourceFile.fileName)), + dtsSourceFile.getFullText() + ) }, watchChange(id) { @@ -350,12 +363,15 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { if (!filter(sourceFile.fileName)) continue if (copyDtsFiles && dtsRE.test(sourceFile.fileName)) { - outputFiles.set(sourceFile.fileName, sourceFile.getFullText()) + outputFiles.set( + resolve(outDir, relative(entryRoot, sourceFile.fileName)), + sourceFile.getFullText() + ) } if (rootFiles.has(sourceFile.fileName)) { for (const outputFile of service.getEmitOutput(sourceFile.fileName, true).outputFiles) { - outputFiles.set(resolve(root, relative(outDir, outputFile.name)), outputFile.text) + outputFiles.set(normalizePath(outputFile.name), outputFile.text) } rootFiles.delete(sourceFile.fileName) @@ -364,9 +380,6 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { bundleDebug('emit output patch') - entryRoot = entryRoot || queryPublicPath(Array.from(outputFiles.keys())) - entryRoot = ensureAbsolute(entryRoot, root) - await runParallel( cpus().length, Array.from(outputFiles.entries()), @@ -375,14 +388,16 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { if (!isMapFile && content) { content = clearPureImport ? removePureImport(content) : content - content = transformAliasImport(path, content, aliases, aliasesExclude) + content = transformAliasImport( + resolve(entryRoot, relative(outDir, path)), + content, + aliases, + aliasesExclude + ) content = staticImport || rollupTypes ? transformDynamicImport(content) : content } - path = resolve( - outDir, - relative(entryRoot, cleanVueFileName ? path.replace('.vue.d.ts', '.d.ts') : path) - ) + path = cleanVueFileName ? path.replace('.vue.d.ts', '.d.ts') : path content = cleanVueFileName ? content.replace(/['"](.+)\.vue['"]/g, '"$1"') : content if (typeof beforeWriteFile === 'function') {