mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-01-12 17:13:19 +08:00
Fix sourcemap path problem (#450)
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_size = 2
|
||||
|
||||
[*.js]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user