mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-05-28 08:18:01 +08:00
fix #188: use standard path separators in all output
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
|
||||
* Source maps use `/` on Windows ([#188](https://github.com/evanw/esbuild/issues/188))
|
||||
|
||||
Before generated source maps used `\` on Windows, which meant that tools consuming these source maps (e.g. Chrome) didn't recognize these characters as path separators. Now all platforms consistently use `/` as a path separator.
|
||||
|
||||
## 0.5.3
|
||||
|
||||
* Special-case `require` in browserify bundles ([#80](https://github.com/evanw/esbuild/issues/80) and [#90](https://github.com/evanw/esbuild/issues/90))
|
||||
|
||||
@@ -42,10 +42,22 @@ type Msg struct {
|
||||
}
|
||||
|
||||
type Source struct {
|
||||
Index uint32
|
||||
Index uint32
|
||||
|
||||
// This is a platform-dependent path that includes environment-specific things
|
||||
// such as Windows backslash path separators and potentially the user's home
|
||||
// directory. Only use this for passing to syscalls for reading and writing to
|
||||
// the file system. Do not include this in any output data.
|
||||
AbsolutePath string
|
||||
PrettyPath string
|
||||
Contents string
|
||||
|
||||
// This is a mostly platform-independent path. It's relative to the current
|
||||
// working directory and always uses standard path separators. Use this for
|
||||
// referencing a file in all output data. These paths still use the original
|
||||
// case of the path so they may still work differently on file systems that
|
||||
// are case-insensitive vs. case-sensitive.
|
||||
PrettyPath string
|
||||
|
||||
Contents string
|
||||
}
|
||||
|
||||
func (s *Source) TextForRange(r ast.Range) string {
|
||||
|
||||
@@ -206,8 +206,16 @@ func (r *resolver) Read(path string) (string, bool) {
|
||||
|
||||
func (r *resolver) PrettyPath(path string) string {
|
||||
if rel, ok := r.fs.RelativeToCwd(path); ok {
|
||||
return rel
|
||||
path = rel
|
||||
}
|
||||
|
||||
// These human-readable paths are used in error messages, comments in output
|
||||
// files, source names in source maps, and paths in the metadata JSON file.
|
||||
// These should be platform-independent so our output doesn't depend on which
|
||||
// operating system it was run. Replace Windows backward slashes with standard
|
||||
// forward slashes.
|
||||
path = strings.ReplaceAll(path, "\\", "/")
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
|
||||
@@ -118,29 +118,30 @@ let buildTests = {
|
||||
assert.strictEqual(Object.keys(json.inputs).length, 3)
|
||||
assert.strictEqual(Object.keys(json.outputs).length, 3)
|
||||
const cwd = process.cwd()
|
||||
const makePath = absPath => path.relative(cwd, absPath).split(path.sep).join('/')
|
||||
|
||||
// Check inputs
|
||||
assert.deepStrictEqual(json.inputs[path.relative(cwd, entry)].bytes, 113)
|
||||
assert.deepStrictEqual(json.inputs[path.relative(cwd, entry)].imports, [
|
||||
{ path: path.relative(cwd, imported) },
|
||||
{ path: path.relative(cwd, text) },
|
||||
assert.deepStrictEqual(json.inputs[makePath(entry)].bytes, 113)
|
||||
assert.deepStrictEqual(json.inputs[makePath(entry)].imports, [
|
||||
{ path: makePath(imported) },
|
||||
{ path: makePath(text) },
|
||||
])
|
||||
assert.deepStrictEqual(json.inputs[path.relative(cwd, imported)].bytes, 18)
|
||||
assert.deepStrictEqual(json.inputs[path.relative(cwd, imported)].imports, [])
|
||||
assert.deepStrictEqual(json.inputs[path.relative(cwd, text)].bytes, 9)
|
||||
assert.deepStrictEqual(json.inputs[path.relative(cwd, text)].imports, [])
|
||||
assert.deepStrictEqual(json.inputs[makePath(imported)].bytes, 18)
|
||||
assert.deepStrictEqual(json.inputs[makePath(imported)].imports, [])
|
||||
assert.deepStrictEqual(json.inputs[makePath(text)].bytes, 9)
|
||||
assert.deepStrictEqual(json.inputs[makePath(text)].imports, [])
|
||||
|
||||
// Check outputs
|
||||
assert.strictEqual(typeof json.outputs[path.relative(cwd, output)].bytes, 'number')
|
||||
assert.strictEqual(typeof json.outputs[path.relative(cwd, output) + '.map'].bytes, 'number')
|
||||
assert.deepStrictEqual(json.outputs[path.relative(cwd, output) + '.map'].inputs, {})
|
||||
assert.strictEqual(typeof json.outputs[makePath(output)].bytes, 'number')
|
||||
assert.strictEqual(typeof json.outputs[makePath(output) + '.map'].bytes, 'number')
|
||||
assert.deepStrictEqual(json.outputs[makePath(output) + '.map'].inputs, {})
|
||||
|
||||
// Check inputs for main output
|
||||
const outputInputs = json.outputs[path.relative(cwd, output)].inputs
|
||||
const outputInputs = json.outputs[makePath(output)].inputs
|
||||
assert.strictEqual(Object.keys(outputInputs).length, 3)
|
||||
assert.strictEqual(typeof outputInputs[path.relative(cwd, entry)].bytesInOutput, 'number')
|
||||
assert.strictEqual(typeof outputInputs[path.relative(cwd, imported)].bytesInOutput, 'number')
|
||||
assert.strictEqual(typeof outputInputs[path.relative(cwd, text)].bytesInOutput, 'number')
|
||||
assert.strictEqual(typeof outputInputs[makePath(entry)].bytesInOutput, 'number')
|
||||
assert.strictEqual(typeof outputInputs[makePath(imported)].bytesInOutput, 'number')
|
||||
assert.strictEqual(typeof outputInputs[makePath(text)].bytesInOutput, 'number')
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user