summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/process.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-20 14:05:13 -0400
committerGitHub <noreply@github.com>2023-03-20 14:05:13 -0400
commitcd53ab5427811bddbed1c30d3733e1df87bb23f9 (patch)
tree0e2ea8e1b45f2d1d4acd20b666ae1d52d40940c6 /ext/node/polyfills/process.ts
parentd78db7c0910aded010c2faee9a8c0f128f513985 (diff)
refactor(ext/node): untangle dependencies between js files (#18284)
Moving some code around in `ext/node` is it's a bit better well defined and makes it possible for others to embed it. I expect to see no difference in startup perf with this change.
Diffstat (limited to 'ext/node/polyfills/process.ts')
-rw-r--r--ext/node/polyfills/process.ts48
1 files changed, 26 insertions, 22 deletions
diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts
index 1f1702785..eb5a491ae 100644
--- a/ext/node/polyfills/process.ts
+++ b/ext/node/polyfills/process.ts
@@ -72,28 +72,6 @@ const notImplementedEvents = [
export const argv: string[] = [];
-// Overwrites the 1st item with getter.
-// TODO(bartlomieju): added "configurable: true" to make this work for binary
-// commands, but that is probably a wrong solution
-// TODO(bartlomieju): move the configuration for all "argv" to
-// "internals.__bootstrapNodeProcess"
-Object.defineProperty(argv, "0", {
- get: () => {
- return Deno.execPath();
- },
- configurable: true,
-});
-// Overwrites the 2st item with getter.
-Object.defineProperty(argv, "1", {
- get: () => {
- if (Deno.mainModule.startsWith("file:")) {
- return fromFileUrl(Deno.mainModule);
- } else {
- return join(Deno.cwd(), "$deno$node.js");
- }
- },
-});
-
/** https://nodejs.org/api/process.html#process_process_exit_code */
export const exit = (code?: number | string) => {
if (code || code === 0) {
@@ -686,9 +664,35 @@ export const removeAllListeners = process.removeAllListeners;
// Should be called only once, in `runtime/js/99_main.js` when the runtime is
// bootstrapped.
internals.__bootstrapNodeProcess = function (
+ argv0: string | undefined,
args: string[],
denoVersions: Record<string, string>,
) {
+ // Overwrites the 1st item with getter.
+ if (typeof argv0 === "string") {
+ Object.defineProperty(argv, "0", {
+ get: () => {
+ return argv0;
+ },
+ });
+ } else {
+ Object.defineProperty(argv, "0", {
+ get: () => {
+ return Deno.execPath();
+ },
+ });
+ }
+
+ // Overwrites the 2st item with getter.
+ Object.defineProperty(argv, "1", {
+ get: () => {
+ if (Deno.mainModule.startsWith("file:")) {
+ return fromFileUrl(Deno.mainModule);
+ } else {
+ return join(Deno.cwd(), "$deno$node.js");
+ }
+ },
+ });
for (let i = 0; i < args.length; i++) {
argv[i + 2] = args[i];
}