Skip to content

Commit 0d84180

Browse files
committedJul 17, 2023
fix: correct sources path calculate
fix #245
1 parent 27fe3c7 commit 0d84180

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed
 

‎src/plugin.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
417417
},
418418

419419
async writeBundle() {
420-
if (!program || bundled) return
420+
if (!host || !program || bundled) return
421421

422422
bundled = true
423423
bundleDebug('begin writeBundle')
@@ -480,6 +480,8 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
480480

481481
bundleDebug('emit output patch')
482482

483+
const currentDir = host.getCurrentDirectory()
484+
483485
await runParallel(
484486
cpus().length,
485487
Array.from(outputFiles.entries()),
@@ -504,7 +506,12 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
504506
const sourceMap: { sources: string[] } = JSON.parse(content)
505507

506508
sourceMap.sources = sourceMap.sources.map(source => {
507-
return normalizePath(relative(dirname(path), resolve(baseDir, source)))
509+
return normalizePath(
510+
relative(
511+
dirname(path),
512+
resolve(currentDir, relative(publicRoot, baseDir), source)
513+
)
514+
)
508515
})
509516
content = JSON.stringify(sourceMap)
510517
} catch (e) {

0 commit comments

Comments
 (0)
Please sign in to comment.