| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8c55f31 commit 72644d6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ const path = require('path'); | |||
| 10 | 10 | ||
| 11 | 11 | /** | |
| 12 | 12 | * Get the absolute path to the main entry point. | |
| 13 | - * @param {string} main Entry point path | ||
| 13 | + * @param {string} main - Entry point path | ||
| 14 | 14 | */ | |
| 15 | 15 | function resolveMainPath(main) { | |
| 16 | 16 | // Note extension resolution for the main entry point can be deprecated in a | |
@@ -31,7 +31,7 @@ function resolveMainPath(main) { | |||
| 31 | 31 | ||
| 32 | 32 | /** | |
| 33 | 33 | * Determine whether the main entry point should be loaded through the ESM Loader. | |
| 34 | - * @param {string} mainPath Absolute path to the main entry point | ||
| 34 | + * @param {string} mainPath - Absolute path to the main entry point | ||
| 35 | 35 | */ | |
| 36 | 36 | function shouldUseESMLoader(mainPath) { | |
| 37 | 37 | /** | |
@@ -63,7 +63,7 @@ function shouldUseESMLoader(mainPath) { | |||
| 63 | 63 | ||
| 64 | 64 | /** | |
| 65 | 65 | * Run the main entry point through the ESM Loader. | |
| 66 | - * @param {string} mainPath Absolute path to the main entry point | ||
| 66 | + * @param {string} mainPath - Absolute path for the main entry point | ||
| 67 | 67 | */ | |
| 68 | 68 | function runMainESM(mainPath) { | |
| 69 | 69 | const { loadESM } = require('internal/process/esm_loader'); | |
@@ -78,7 +78,7 @@ function runMainESM(mainPath) { | |||
| 78 | 78 | ||
| 79 | 79 | /** | |
| 80 | 80 | * Handle process exit events around the main entry point promise. | |
| 81 | - * @param {Promise} promise Main entry point promise | ||
| 81 | + * @param {Promise} promise - Main entry point promise | ||
| 82 | 82 | */ | |
| 83 | 83 | async function handleMainPromise(promise) { | |
| 84 | 84 | const { | |
@@ -96,7 +96,8 @@ async function handleMainPromise(promise) { | |||
| 96 | 96 | * Parse the CLI main entry point string and run it. | |
| 97 | 97 | * For backwards compatibility, we have to run a bunch of monkey-patchable code that belongs to the CJS loader (exposed | |
| 98 | 98 | * by `require('module')`) even when the entry point is ESM. | |
| 99 | - * @param {string} main CLI main entry point string | ||
| 99 | + * Because of backwards compatibility, this function is exposed publicly via `import { runMain } from 'node:module'`. | ||
| 100 | + * @param {string} main - Resolved absolute path for the main entry point, if found | ||
| 100 | 101 | */ | |
| 101 | 102 | function executeUserEntryPoint(main = process.argv[1]) { | |
| 102 | 103 | const resolvedMain = resolveMainPath(main); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -141,12 +141,20 @@ function refreshRuntimeOptions() { | |||
| 141 | 141 | refreshOptions(); | |
| 142 | 142 | } | |
| 143 | 143 | ||
| 144 | + /** | ||
| 145 | + * Patch the process object with legacy properties and normalizations. | ||
| 146 | + * Replace `process.argv[0]` with `process.execPath`, preserving the original `argv[0]` value as `process.argv0`. | ||
| 147 | + * Replace `process.argv[1]` with the resolved absolute file path of the entry point, if found. | ||
| 148 | + * @param {boolean} expandArgv1 - Whether to replace `process.argv[1]` with the resolved absolute file path of | ||
| 149 | + * the main entry point. | ||
| 150 | + */ | ||
| 144 | 151 | function patchProcessObject(expandArgv1) { | |
| 145 | 152 | const binding = internalBinding('process_methods'); | |
| 146 | 153 | binding.patchProcessObject(process); | |
| 147 | 154 | ||
| 148 | 155 | require('internal/process/per_thread').refreshHrtimeBuffer(); | |
| 149 | 156 | ||
| 157 | + // Since we replace process.argv[0] below, preserve the original value in case the user needs it. | ||
| 150 | 158 | ObjectDefineProperty(process, 'argv0', { | |
| 151 | 159 | __proto__: null, | |
| 152 | 160 | enumerable: true, | |
@@ -159,6 +167,8 @@ function patchProcessObject(expandArgv1) { | |||
| 159 | 167 | process._exiting = false; | |
| 160 | 168 | process.argv[0] = process.execPath; | |
| 161 | 169 | ||
| 170 | + // If requested, update process.argv[1] to replace whatever the user provided with the resolved absolute file path of | ||
| 171 | + // the entry point. | ||
| 162 | 172 | if (expandArgv1 && process.argv[1] && | |
| 163 | 173 | !StringPrototypeStartsWith(process.argv[1], '-')) { | |
| 164 | 174 | // Expand process.argv[1] into a full path. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments