From 528d071bbe69ec473078c87c960cf3bcdaa3a5db Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 28 Aug 2023 16:02:24 +0900 Subject: [PATCH 1/2] fix(ext/node): fix argv[1] in Worker --- cli/tests/unit_node/process_test.ts | 12 ++++++++++++ ext/node/polyfills/process.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts index 461afb9f67b35..fc40b9e86dc99 100644 --- a/cli/tests/unit_node/process_test.ts +++ b/cli/tests/unit_node/process_test.ts @@ -774,3 +774,15 @@ Deno.test({ assertEquals(process.title, "deno"); }, }); + +Deno.test({ + name: "process.argv[1] in Worker", + async fn() { + const worker = new Worker( + `data:text/javascript,import process from "node:process";console.log(process.argv[1]);`, + { type: "module" }, + ); + await delay(10); + worker.terminate(); + } +}) diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index c7c22b562d2f7..64a3ef31be56a 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -873,7 +873,7 @@ internals.__bootstrapNodeProcess = function ( // Overwrites the 2st item with getter. Object.defineProperty(argv, "1", { get: () => { - if (Deno.mainModule.startsWith("file:")) { + if (Deno.mainModule?.startsWith("file:")) { return pathFromURL(new URL(Deno.mainModule)); } else { return join(Deno.cwd(), "$deno$node.js"); From 96704688432cacecef7e7343400835e725d68916 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 28 Aug 2023 18:58:50 +0900 Subject: [PATCH 2/2] fmt --- cli/tests/unit_node/process_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts index fc40b9e86dc99..bcb7a97679968 100644 --- a/cli/tests/unit_node/process_test.ts +++ b/cli/tests/unit_node/process_test.ts @@ -784,5 +784,5 @@ Deno.test({ ); await delay(10); worker.terminate(); - } -}) + }, +});