File tree 2 files changed +11
-1
lines changed
2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ const path = require('path');
9
9
10
10
/**
11
11
* Get the absolute path to the main entry point.
12
- * @param {string } main Entry point path
12
+ * @param {string } main - Entry point path
13
13
*/
14
14
function resolveMainPath ( main ) {
15
15
// Note extension resolution for the main entry point can be deprecated in a
Original file line number Diff line number Diff line change @@ -176,12 +176,20 @@ function refreshRuntimeOptions() {
176
176
refreshOptions ( ) ;
177
177
}
178
178
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
+ */
179
186
function patchProcessObject ( expandArgv1 ) {
180
187
const binding = internalBinding ( 'process_methods' ) ;
181
188
binding . patchProcessObject ( process ) ;
182
189
183
190
require ( 'internal/process/per_thread' ) . refreshHrtimeBuffer ( ) ;
184
191
192
+ // Since we replace process.argv[0] below, preserve the original value in case the user needs it.
185
193
ObjectDefineProperty ( process , 'argv0' , {
186
194
__proto__ : null ,
187
195
enumerable : true ,
@@ -194,6 +202,8 @@ function patchProcessObject(expandArgv1) {
194
202
process . _exiting = false ;
195
203
process . argv [ 0 ] = process . execPath ;
196
204
205
+ // If requested, update process.argv[1] to replace whatever the user provided with the resolved absolute file path of
206
+ // the entry point.
197
207
if ( expandArgv1 && process . argv [ 1 ] &&
198
208
! StringPrototypeStartsWith ( process . argv [ 1 ] , '-' ) ) {
199
209
// Expand process.argv[1] into a full path.
You can’t perform that action at this time.
0 commit comments