Skip to content

Commit 0fd188b

Browse files
committed
more comments
1 parent c4ea796 commit 0fd188b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/internal/modules/run_main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const path = require('path');
99

1010
/**
1111
* Get the absolute path to the main entry point.
12-
* @param {string} main Entry point path
12+
* @param {string} main - Entry point path
1313
*/
1414
function resolveMainPath(main) {
1515
// Note extension resolution for the main entry point can be deprecated in a

lib/internal/process/pre_execution.js

+10
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,20 @@ function refreshRuntimeOptions() {
176176
refreshOptions();
177177
}
178178

179+
/**
180+
* Patch the process object with legacy properties and normalizations.
181+
* Replace `process.argv[0]` with `process.execPath`, preserving the original `argv[0]` value as `process.argv0`.
182+
* Replace `process.argv[1]` with the resolved absolute file path of the entry point, if found.
183+
* @param {boolean} expandArgv1 - Whether to replace `process.argv[1]` with the resolved absolute file path of
184+
* the main entry point.
185+
*/
179186
function patchProcessObject(expandArgv1) {
180187
const binding = internalBinding('process_methods');
181188
binding.patchProcessObject(process);
182189

183190
require('internal/process/per_thread').refreshHrtimeBuffer();
184191

192+
// Since we replace process.argv[0] below, preserve the original value in case the user needs it.
185193
ObjectDefineProperty(process, 'argv0', {
186194
__proto__: null,
187195
enumerable: true,
@@ -194,6 +202,8 @@ function patchProcessObject(expandArgv1) {
194202
process._exiting = false;
195203
process.argv[0] = process.execPath;
196204

205+
// If requested, update process.argv[1] to replace whatever the user provided with the resolved absolute file path of
206+
// the entry point.
197207
if (expandArgv1 && process.argv[1] &&
198208
!StringPrototypeStartsWith(process.argv[1], '-')) {
199209
// Expand process.argv[1] into a full path.

0 commit comments

Comments
 (0)