From 44610c753783fa8ac713f26a0496ef9019d2987e Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sat, 21 Sep 2024 17:40:51 -0400 Subject: [PATCH] wip --- Makefile | 1 + lib/deno/mod.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 672053ca06d..f2f8d212a58 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,7 @@ test-deno: esbuild platform-deno @echo '✅ deno tests passed' # I couldn't find a Deno API for telling when tests have failed, so I'm doing this here instead deno eval 'import { transform, stop } from "file://$(shell pwd)/deno/mod.js"; console.log((await transform("1+2")).code); stop()' | grep "1 + 2;" deno eval 'import { transform, stop } from "file://$(shell pwd)/deno/wasm.js"; console.log((await transform("1+2")).code); stop()' | grep "1 + 2;" + deno run -A './deno/mod.js' # See: https://github.com/evanw/esbuild/pull/3917 test-deno-windows: esbuild platform-deno ESBUILD_BINARY_PATH=./esbuild.exe deno test --allow-run --allow-env --allow-net --allow-read --allow-write --no-check scripts/deno-tests.js diff --git a/lib/deno/mod.ts b/lib/deno/mod.ts index b6233929362..eea9a081111 100644 --- a/lib/deno/mod.ts +++ b/lib/deno/mod.ts @@ -203,11 +203,12 @@ const spawnNew: SpawnFn = (cmd, { args, stdin, stdout, stderr }) => { stdout, stderr, }).spawn() - const writer = child.stdin.getWriter() - const reader = child.stdout.getReader() + // Note: Need to check for "piped" in Deno ≥1.31.0 to avoid a crash + const writer = stdin === 'piped' ? child.stdin.getWriter() : null + const reader = stdout === 'piped' ? child.stdout.getReader() : null return { - write: bytes => writer.write(bytes), - read: () => reader.read().then(x => x.value || null), + write: writer ? bytes => writer.write(bytes) : () => Promise.resolve(), + read: reader ? () => reader.read().then(x => x.value || null) : () => Promise.resolve(null), close: async () => { // We can't call "kill()" because it doesn't seem to work. Tests will // 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 }) => { // we can do. // // See this for more info: https://github.com/evanw/esbuild/pull/3611 - await writer.close() - await reader.cancel() + if (writer) await writer.close() + if (reader) await reader.cancel() // Wait for the process to exit. The new "kill()" API doesn't flag the // process as having exited because processes can technically ignore the