From cd53ab5427811bddbed1c30d3733e1df87bb23f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 20 Mar 2023 14:05:13 -0400 Subject: 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. --- ext/node/polyfills/process.ts | 48 +++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'ext/node/polyfills/process.ts') 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, ) { + // 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]; } -- cgit v1.2.3