From 0d84180ddd237c4bf00c4e0c8e24d9b5d4423db8 Mon Sep 17 00:00:00 2001 From: qmhc <40221744+qmhc@users.noreply.github.com> Date: Mon, 17 Jul 2023 11:21:03 +0800 Subject: [PATCH] fix: correct sources path calculate fix #245 --- src/plugin.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugin.ts b/src/plugin.ts index 274f1eb..4e0a4b6 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -417,7 +417,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { }, async writeBundle() { - if (!program || bundled) return + if (!host || !program || bundled) return bundled = true bundleDebug('begin writeBundle') @@ -480,6 +480,8 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { bundleDebug('emit output patch') + const currentDir = host.getCurrentDirectory() + await runParallel( cpus().length, Array.from(outputFiles.entries()), @@ -504,7 +506,12 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin { const sourceMap: { sources: string[] } = JSON.parse(content) sourceMap.sources = sourceMap.sources.map(source => { - return normalizePath(relative(dirname(path), resolve(baseDir, source))) + return normalizePath( + relative( + dirname(path), + resolve(currentDir, relative(publicRoot, baseDir), source) + ) + ) }) content = JSON.stringify(sourceMap) } catch (e) {