MCPcopy Index your code
hub / github.com/nodejs/node / patchProcessObject

Function patchProcessObject

lib/internal/process/pre_execution.js:264–319  ·  view source on GitHub ↗

* Patch the process object with legacy properties and normalizations. * Replace `process.argv[0]` with `process.execPath`, preserving the original `argv[0]` value as `process.argv0`. * Replace `process.argv[1]` with the resolved absolute file path of the entry point, if found. * @param {boolean}

(expandArgv1)

Source from the content-addressed store, hash-verified

262 * @returns {string}
263 */
264function patchProcessObject(expandArgv1) {
265 const binding = internalBinding('process_methods');
266 binding.patchProcessObject(process);
267
268 // Since we replace process.argv[0] below, preserve the original value in case the user needs it.
269 ObjectDefineProperty(process, 'argv0', {
270 __proto__: null,
271 enumerable: true,
272 // Only set it to true during snapshot building.
273 configurable: isBuildingSnapshot(),
274 value: process.argv[0],
275 });
276
277 process.exitCode = undefined;
278 process._exiting = false;
279 process.argv[0] = process.execPath;
280
281 /** @type {string} */
282 let mainEntry;
283 // If requested, update process.argv[1] to replace whatever the user provided with the resolved absolute file path of
284 // the entry point.
285 if (expandArgv1 && process.argv[1] && process.argv[1][0] !== '-') {
286 // Expand process.argv[1] into a full path.
287 const path = require('path');
288 try {
289 mainEntry = path.resolve(process.argv[1]);
290 process.argv[1] = mainEntry;
291 } catch {
292 // Continue regardless of error.
293 }
294 }
295
296 // We need to initialize the global console here again with process.stdout
297 // and friends for snapshot deserialization.
298 const globalConsole = require('internal/console/global');
299 const { initializeGlobalConsole } = require('internal/console/constructor');
300 initializeGlobalConsole(globalConsole);
301
302 // TODO(joyeecheung): most of these should be deprecated and removed,
303 // except some that we need to be able to mutate during run time.
304 addReadOnlyProcessAlias('_eval', '--eval');
305 addReadOnlyProcessAlias('_print_eval', '--print');
306 addReadOnlyProcessAlias('_syntax_check_only', '--check');
307 addReadOnlyProcessAlias('_forceRepl', '--interactive');
308 addReadOnlyProcessAlias('_preload_modules', '--require');
309 addReadOnlyProcessAlias('noDeprecation', '--no-deprecation');
310 addReadOnlyProcessAlias('noProcessWarnings', '--no-warnings');
311 addReadOnlyProcessAlias('traceProcessWarnings', '--trace-warnings');
312 addReadOnlyProcessAlias('throwDeprecation', '--throw-deprecation');
313 addReadOnlyProcessAlias('profProcess', '--prof-process');
314 addReadOnlyProcessAlias('traceDeprecation', '--trace-deprecation');
315 addReadOnlyProcessAlias('_breakFirstLine', '--inspect-brk', false);
316 addReadOnlyProcessAlias('_breakNodeFirstLine', '--inspect-brk-node', false);
317
318 return mainEntry;
319}
320
321function addReadOnlyProcessAlias(name, option, enumerable = true) {

Callers 2

prepareExecutionFunction · 0.85

Calls 5

isBuildingSnapshotFunction · 0.85
initializeGlobalConsoleFunction · 0.85
addReadOnlyProcessAliasFunction · 0.85
requireFunction · 0.50
resolveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…