Skip to content

Commit

Permalink
Fix sourcemap path problem (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 authored Oct 13, 2020
1 parent 2f31833 commit 351e7e7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[*]
indent_style = tab
indent_size = 2

[*.js]
indent_style = space
indent_size = 2
12 changes: 10 additions & 2 deletions internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/verify-source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 351e7e7

Please sign in to comment.