Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sourcemap path problem #450

Merged
merged 2 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3442,7 +3442,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 @@ -3795,7 +3795,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 @@ -3814,6 +3814,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