Skip to content

Commit a19eb2a

Browse files
committed
cleanup after landing evanw#450
1 parent 351e7e7 commit a19eb2a

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
indent_style = tab
33
indent_size = 2
44

5-
[*.js]
5+
[*.{js,ts}]
66
indent_style = space
77
indent_size = 2

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
4343
The `importsNotUsedAsValues` field in `tsconfig.json` is now respected. Setting it to `"preserve"` means esbuild will no longer remove unused imports in TypeScript files. This field was added in TypeScript 3.8.
4444
45+
* Fix relative paths in generated source maps ([#444](https://github.com/evanw/esbuild/issues/444))
46+
47+
Currently paths in generated source map files don't necessarily correspond to real file system paths. They are really only meant to be human-readable when debugging in the browser.
48+
49+
However, the Visual Studio Code debugger expects these paths to point back to the original files on the file system. With this release, it should now always be possible to get back to the original source file by joining the directory containing the source map file with the relative path in the source map.
50+
51+
This fix was contributed by [@yoyo930021](https://github.com/yoyo930021).
52+
4553
## 0.7.14
4654

4755
* Fix a bug with compound import statements ([#446](https://github.com/evanw/esbuild/issues/446))

internal/bundler/linker.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3809,12 +3809,13 @@ func (c *linkerContext) generateSourceMapForChunk(relDir string, results []compi
38093809
j.AddString("]")
38103810

38113811
// Write the sourceRoot
3812-
j.AddString(",\n \"sourceRoot\": \"")
3812+
sourceRoot := ""
38133813
if rel, ok := c.fs.Rel(c.fs.Join(c.options.AbsOutputDir, relDir), c.fs.Cwd()); ok {
38143814
// Replace Windows backward slashes with standard forward slashes.
3815-
j.AddString(strings.ReplaceAll(rel, "\\", "/"))
3815+
sourceRoot = strings.ReplaceAll(rel, "\\", "/")
38163816
}
3817-
j.AddString("\"")
3817+
j.AddString(",\n \"sourceRoot\": ")
3818+
j.AddBytes(js_printer.QuoteForJSON(sourceRoot))
38183819

38193820
// Write the sourcesContent
38203821
j.AddString(",\n \"sourcesContent\": [")

scripts/verify-source-map.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ async function check(kind, testCase, toSearch, { flags, entryPoints, crlf }) {
260260

261261
const inSource = isStdin ? '<stdin>' : files.find(x => path.basename(x).startsWith(id[0]))
262262
const expectedSource = path.join(relativeTo, inSource).replace(/\\/g, '/')
263-
recordCheck(source === expectedSource, `expected: ${expectedSource} observed: ${source}`)
263+
const observedSource = path.join(relativeTo, source).replace(/\\/g, '/')
264+
recordCheck(observedSource === expectedSource, `expected: ${expectedSource} observed: ${observedSource}`)
264265

265266
const inJs = map.sourceContentFor(source)
266267
const inIndex = inJs.indexOf(`"${id}"`)
@@ -314,7 +315,7 @@ async function check(kind, testCase, toSearch, { flags, entryPoints, crlf }) {
314315
const out2JsMap = await readFileAsync(path.join(tempDir, 'out2.js.map'), 'utf8')
315316

316317
const out2Map = await new SourceMapConsumer(out2JsMap)
317-
checkMap(out2Js, out2Map, path.join(path.relative(tempDir, testDir), path.basename(tempDir)))
318+
checkMap(out2Js, out2Map, tempDir)
318319
}
319320

320321
if (!failed) rimraf.sync(tempDir, { disableGlob: true })

0 commit comments

Comments
 (0)