Fix sourcemap path problem (#450)

This commit is contained in:
IU
2020-10-13 15:24:26 +08:00
committed by GitHub
parent 2f31833b74
commit 351e7e76e7
3 changed files with 15 additions and 3 deletions

View File

@@ -1,3 +1,7 @@
[*]
indent_style = tab
indent_size = 2
[*.js]
indent_style = space
indent_size = 2

View File

@@ -3436,7 +3436,7 @@ func (repr *chunkReprJS) generate(c *linkerContext, chunk *chunkInfo) func([]ast
}
if c.options.SourceMap != config.SourceMapNone {
sourceMap := c.generateSourceMapForChunk(compileResultsForSourceMap)
sourceMap := c.generateSourceMapForChunk(chunk.relDir, compileResultsForSourceMap)
// Store the generated source map
switch c.options.SourceMap {
@@ -3789,7 +3789,7 @@ func (c *linkerContext) preventExportsFromBeingRenamed(sourceIndex uint32) {
}
}
func (c *linkerContext) generateSourceMapForChunk(results []compileResultJS) []byte {
func (c *linkerContext) generateSourceMapForChunk(relDir string, results []compileResultJS) []byte {
j := js_printer.Joiner{}
j.AddString("{\n \"version\": 3")
@@ -3808,6 +3808,14 @@ func (c *linkerContext) generateSourceMapForChunk(results []compileResultJS) []b
}
j.AddString("]")
// Write the sourceRoot
j.AddString(",\n \"sourceRoot\": \"")
if rel, ok := c.fs.Rel(c.fs.Join(c.options.AbsOutputDir, relDir), c.fs.Cwd()); ok {
// Replace Windows backward slashes with standard forward slashes.
j.AddString(strings.ReplaceAll(rel, "\\", "/"))
}
j.AddString("\"")
// Write the sourcesContent
j.AddString(",\n \"sourcesContent\": [")
needComma = false

View File

@@ -314,7 +314,7 @@ async function check(kind, testCase, toSearch, { flags, entryPoints, crlf }) {
const out2JsMap = await readFileAsync(path.join(tempDir, 'out2.js.map'), 'utf8')
const out2Map = await new SourceMapConsumer(out2JsMap)
checkMap(out2Js, out2Map, path.relative(testDir, tempDir))
checkMap(out2Js, out2Map, path.join(path.relative(tempDir, testDir), path.basename(tempDir)))
}
if (!failed) rimraf.sync(tempDir, { disableGlob: true })