Skip to content

Commit

Permalink
fix: correct sources path calculate
Browse files Browse the repository at this point in the history
fix #245
  • Loading branch information
qmhc committed Jul 17, 2023
1 parent 27fe3c7 commit 0d84180
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/plugin.ts
Expand Up @@ -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')
Expand Down Expand Up @@ -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()),
Expand All @@ -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) {
Expand Down

0 comments on commit 0d84180

Please sign in to comment.