summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-10-18 01:51:39 +0200
committerGitHub <noreply@github.com>2023-10-18 01:51:39 +0200
commit5095af78018f1d77374bc06cbb58231e631056b9 (patch)
tree6774952a000d287ded4d98a81171414a2d955eb5
parent7561f6eceacc46c6f4f5f66cf03e627821b64f02 (diff)
fix(ext/node): process.argv0 (#20925)
Fixes https://github.com/denoland/deno/issues/20924
-rw-r--r--cli/tests/unit_node/process_test.ts17
-rw-r--r--ext/node/polyfills/process.ts20
2 files changed, 34 insertions, 3 deletions
diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts
index 78c5fcc97..1f4638b91 100644
--- a/cli/tests/unit_node/process_test.ts
+++ b/cli/tests/unit_node/process_test.ts
@@ -259,6 +259,23 @@ Deno.test({
});
Deno.test({
+ name: "process.argv0",
+ fn() {
+ assertEquals(typeof process.argv0, "string");
+ assert(
+ process.argv0.match(/[^/\\]*deno[^/\\]*$/),
+ "deno included in the file name of argv[0]",
+ );
+ // Setting should be a noop
+ process.argv0 = "foobar";
+ assert(
+ process.argv0.match(/[^/\\]*deno[^/\\]*$/),
+ "deno included in the file name of argv[0]",
+ );
+ },
+});
+
+Deno.test({
name: "process.execArgv",
fn() {
assert(Array.isArray(process.execArgv));
diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts
index 64a3ef31b..618f92d3f 100644
--- a/ext/node/polyfills/process.ts
+++ b/ext/node/polyfills/process.ts
@@ -45,6 +45,9 @@ import { isWindows } from "ext:deno_node/_util/os.ts";
import * as io from "ext:deno_io/12_io.js";
import { Command } from "ext:runtime/40_process.js";
+let argv0Getter = () => "";
+export let argv0 = "deno";
+
// TODO(kt3k): This should be set at start up time
export let arch = "";
@@ -408,6 +411,15 @@ class Process extends EventEmitter {
*/
argv = argv;
+ get argv0() {
+ if (!argv0) {
+ argv0 = argv0Getter();
+ }
+ return argv0;
+ }
+
+ set argv0(_val) {}
+
/** https://nodejs.org/api/process.html#process_process_chdir_directory */
chdir = chdir;
@@ -851,23 +863,25 @@ function synchronizeListeners() {
// Should be called only once, in `runtime/js/99_main.js` when the runtime is
// bootstrapped.
internals.__bootstrapNodeProcess = function (
- argv0: string | undefined,
+ argv0Val: string | undefined,
args: string[],
denoVersions: Record<string, string>,
) {
// Overwrites the 1st item with getter.
- if (typeof argv0 === "string") {
+ if (typeof argv0Val === "string") {
Object.defineProperty(argv, "0", {
get: () => {
- return argv0;
+ return argv0Val;
},
});
+ argv0Getter = () => argv0Val;
} else {
Object.defineProperty(argv, "0", {
get: () => {
return Deno.execPath();
},
});
+ argv0Getter = () => Deno.execPath();
}
// Overwrites the 2st item with getter.