Skip to content

Commit b500443

Browse files
committed
fix #3917: running esbuild cli with deno
1 parent b125e62 commit b500443

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
2424
Previously a `tsconfig.json` file that `extends` another file in a package with an `exports` map could cause a stack overflow when Yarn's Plug'n'Play resolution was active. This edge case should work now starting with this release.
2525
26+
* Work around more issues with Deno 1.31+ ([#3917](https://github.com/evanw/esbuild/pull/3917))
27+
28+
This version of Deno broke the `stdin` and `stdout` properties on command objects for inherited streams, which matters when you run esbuild's Deno module as the entry point (i.e. when `import.meta.main` is `true`). Previously esbuild would crash in Deno 1.31+ if you ran esbuild like that. This should be fixed starting with this release.
29+
30+
This fix was contributed by [@Joshix-1](https://github.com/Joshix-1).
31+
2632
## 0.23.1
2733
2834
* Allow using the `node:` import prefix with `es*` targets ([#3821](https://github.com/evanw/esbuild/issues/3821))

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ test-deno: esbuild platform-deno
6969
@echo '✅ deno tests passed' # I couldn't find a Deno API for telling when tests have failed, so I'm doing this here instead
7070
deno eval 'import { transform, stop } from "file://$(shell pwd)/deno/mod.js"; console.log((await transform("1+2")).code); stop()' | grep "1 + 2;"
7171
deno eval 'import { transform, stop } from "file://$(shell pwd)/deno/wasm.js"; console.log((await transform("1+2")).code); stop()' | grep "1 + 2;"
72+
deno run -A './deno/mod.js' # See: https://github.com/evanw/esbuild/pull/3917
7273

7374
test-deno-windows: esbuild platform-deno
7475
ESBUILD_BINARY_PATH=./esbuild.exe deno test --allow-run --allow-env --allow-net --allow-read --allow-write --no-check scripts/deno-tests.js

lib/deno/mod.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,12 @@ const spawnNew: SpawnFn = (cmd, { args, stdin, stdout, stderr }) => {
203203
stdout,
204204
stderr,
205205
}).spawn()
206-
const writer = child.stdin.getWriter()
207-
const reader = child.stdout.getReader()
206+
// Note: Need to check for "piped" in Deno ≥1.31.0 to avoid a crash
207+
const writer = stdin === 'piped' ? child.stdin.getWriter() : null
208+
const reader = stdout === 'piped' ? child.stdout.getReader() : null
208209
return {
209-
write: bytes => writer.write(bytes),
210-
read: () => reader.read().then(x => x.value || null),
210+
write: writer ? bytes => writer.write(bytes) : () => Promise.resolve(),
211+
read: reader ? () => reader.read().then(x => x.value || null) : () => Promise.resolve(null),
211212
close: async () => {
212213
// We can't call "kill()" because it doesn't seem to work. Tests will
213214
// still fail with "A child process was opened during the test, but not
@@ -223,8 +224,8 @@ const spawnNew: SpawnFn = (cmd, { args, stdin, stdout, stderr }) => {
223224
// we can do.
224225
//
225226
// See this for more info: https://github.com/evanw/esbuild/pull/3611
226-
await writer.close()
227-
await reader.cancel()
227+
if (writer) await writer.close()
228+
if (reader) await reader.cancel()
228229

229230
// Wait for the process to exit. The new "kill()" API doesn't flag the
230231
// process as having exited because processes can technically ignore the

0 commit comments

Comments
 (0)