diff --git a/.editorconfig b/.editorconfig index 1fdf6b65cfa..ef195e04a2e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +1,7 @@ [*] indent_style = tab indent_size = 2 + +[*.js] +indent_style = space +indent_size = 2 diff --git a/internal/bundler/linker.go b/internal/bundler/linker.go index 335c49bb765..21745b3ac24 100644 --- a/internal/bundler/linker.go +++ b/internal/bundler/linker.go @@ -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 diff --git a/scripts/verify-source-map.js b/scripts/verify-source-map.js index c8fd0bdac48..b358edc670f 100644 --- a/scripts/verify-source-map.js +++ b/scripts/verify-source-map.js @@ -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 })