From 7542d1050a61583d279bdd9c1cf05eaad71f4548 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 6 Mar 2024 19:10:47 +0530 Subject: [PATCH] fix(ext/node): strip `--enable-source-maps` from argv (#22743) Fixes https://github.com/denoland/deno/issues/21750 --- ext/node/polyfills/child_process.ts | 4 +++ tests/unit_node/child_process_test.ts | 27 +++++++++++++++++++ .../testdata/node_modules/foo/check_argv.js | 1 + 3 files changed, 32 insertions(+) create mode 100644 tests/unit_node/testdata/node_modules/foo/check_argv.js diff --git a/ext/node/polyfills/child_process.ts b/ext/node/polyfills/child_process.ts index 46a19983d4..2aba88d635 100644 --- a/ext/node/polyfills/child_process.ts +++ b/ext/node/polyfills/child_process.ts @@ -120,9 +120,13 @@ export function fork( if (flag.startsWith("--max-old-space-size")) { execArgv.splice(index, 1); v8Flags.push(flag); + } else if (flag.startsWith("--enable-source-maps")) { + // https://github.com/denoland/deno/issues/21750 + execArgv.splice(index, 1); } } } + const stringifiedV8Flags: string[] = []; if (v8Flags.length > 0) { stringifiedV8Flags.push("--v8-flags=" + v8Flags.join(",")); diff --git a/tests/unit_node/child_process_test.ts b/tests/unit_node/child_process_test.ts index 85bb6d3b09..60c646a214 100644 --- a/tests/unit_node/child_process_test.ts +++ b/tests/unit_node/child_process_test.ts @@ -755,6 +755,33 @@ Deno.test(async function forkIpcKillDoesNotHang() { await p.promise; }); +Deno.test(async function stripForkEnableSourceMaps() { + const testdataDir = path.join( + path.dirname(path.fromFileUrl(import.meta.url)), + "testdata", + ); + const script = path.join( + testdataDir, + "node_modules", + "foo", + "check_argv.js", + ); + const p = Promise.withResolvers(); + const cp = CP.fork(script, [], { + cwd: testdataDir, + stdio: "pipe", + execArgv: ["--enable-source-maps"], + }); + let output = ""; + cp.on("close", () => p.resolve()); + cp.stdout?.on("data", (data) => { + output += data; + cp.kill(); + }); + await p.promise; + assertEquals(output, "2\n"); +}); + Deno.test(async function execFileWithUndefinedTimeout() { const { promise, resolve, reject } = Promise.withResolvers(); CP.execFile( diff --git a/tests/unit_node/testdata/node_modules/foo/check_argv.js b/tests/unit_node/testdata/node_modules/foo/check_argv.js new file mode 100644 index 0000000000..c3b2eb3e60 --- /dev/null +++ b/tests/unit_node/testdata/node_modules/foo/check_argv.js @@ -0,0 +1 @@ +console.log(process.argv.length);