Skip to content

Commit

Permalink
add a test to verify that #693 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jan 26, 2021
1 parent 93423e5 commit b8f1e7b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
For zero exit codes, the `esbuild` command now loads a N-API native node extension that calls the operating system's `exit(0)` function. This is done without requiring `node-gyp` by precompiling each supported platform and just including all of them in the `esbuild-wasm` package since they are so small. If this hack doesn't work in certain cases, the process should exit anyway just potentially many seconds later. Currently the only supported platforms for this hack are 64-bit macOS, Windows, and Linux.

* Fix non-absolute paths with the `esbuild-wasm` package in the browser ([#693](https://github.com/evanw/esbuild/issues/693))

When using esbuild in the browser via WebAssembly, it was not possible to specify an non-absolute output path. Normally you can do this and esbuild will just convert it to an absolute path by resolving it as a relative path from the current working directory. However, Go's WebAssembly implementation has no current working directory so the conversion operation to an absolute path failed, causing esbuild's API to fail.

With this release, esbuild should now behave as if the current working directory is `/` in the browser. For example, this means calling the `build()` API with `outfile: 'file.js'` should now generate an output file called `/file.js` instead of causing an error.

## 0.8.34

* Fix a parser bug about suffix expressions after an arrow function body ([#701](https://github.com/evanw/esbuild/issues/701))
Expand Down
17 changes: 15 additions & 2 deletions scripts/browser/browser-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ async function runAllTests({ esbuild, service }) {
assertStrictEqual(fib10, 55)
},

async buildRelativeIssue693() {
const result = await service.build({
stdin: {
contents: `const x=1`,
},
write: false,
outfile: 'esbuild.js',
});
assertStrictEqual(result.outputFiles.length, 1)
assertStrictEqual(result.outputFiles[0].path, '/esbuild.js')
assertStrictEqual(result.outputFiles[0].text, 'const x = 1;\n')
},

async serve() {
expectThrownError(service.serve, 'The "serve" API only works in node')
},
Expand Down Expand Up @@ -96,8 +109,8 @@ async function runAllTests({ esbuild, service }) {
function assertStrictEqual(a, b) {
if (a !== b) {
throw new Error(`Assertion failed:
Expected: ${JSON.stringify(a)}
Observed: ${JSON.stringify(b)}`);
Observed: ${JSON.stringify(a)}
Expected: ${JSON.stringify(b)}`);
}
}

Expand Down
13 changes: 13 additions & 0 deletions scripts/js-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,19 @@ console.log("success");
assert.strictEqual(code, `div {\n color: red;\n}\n`)
},

async buildRelativeIssue693({ service }) {
const result = await service.build({
stdin: {
contents: `const x=1`,
},
write: false,
outfile: 'esbuild.js',
});
assert.strictEqual(result.outputFiles.length, 1)
assert.strictEqual(result.outputFiles[0].path, path.join(process.cwd(), 'esbuild.js'))
assert.strictEqual(result.outputFiles[0].text, 'const x = 1;\n')
},

async noRebuild({ esbuild, service, testDir }) {
for (const toTest of [esbuild, service]) {
const input = path.join(testDir, 'in.js')
Expand Down

0 comments on commit b8f1e7b

Please sign in to comment.