Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aadfea4

Browse filesBrowse files
esm: improve JSDoc annotation of internal functions
Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: #49959 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 092fb9f commit aadfea4
Copy full SHA for aadfea4

File tree

Expand file treeCollapse file tree

2 files changed

+16
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/run_main.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/run_main.js
+6-5Lines changed: 6 additions & 5 deletions
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
@@ -30,7 +30,7 @@ function resolveMainPath(main) {
3030

3131
/**
3232
* Determine whether the main entry point should be loaded through the ESM Loader.
33-
* @param {string} mainPath Absolute path to the main entry point
33+
* @param {string} mainPath - Absolute path to the main entry point
3434
*/
3535
function shouldUseESMLoader(mainPath) {
3636
/**
@@ -57,7 +57,7 @@ function shouldUseESMLoader(mainPath) {
5757

5858
/**
5959
* Run the main entry point through the ESM Loader.
60-
* @param {string} mainPath Absolute path to the main entry point
60+
* @param {string} mainPath - Absolute path for the main entry point
6161
*/
6262
function runMainESM(mainPath) {
6363
const { loadESM } = require('internal/process/esm_loader');
@@ -72,7 +72,7 @@ function runMainESM(mainPath) {
7272

7373
/**
7474
* Handle process exit events around the main entry point promise.
75-
* @param {Promise} promise Main entry point promise
75+
* @param {Promise} promise - Main entry point promise
7676
*/
7777
async function handleMainPromise(promise) {
7878
const {
@@ -90,7 +90,8 @@ async function handleMainPromise(promise) {
9090
* Parse the CLI main entry point string and run it.
9191
* For backwards compatibility, we have to run a bunch of monkey-patchable code that belongs to the CJS loader (exposed
9292
* by `require('module')`) even when the entry point is ESM.
93-
* @param {string} main CLI main entry point string
93+
* Because of backwards compatibility, this function is exposed publicly via `import { runMain } from 'node:module'`.
94+
* @param {string} main - Resolved absolute path for the main entry point, if found
9495
*/
9596
function executeUserEntryPoint(main = process.argv[1]) {
9697
const resolvedMain = resolveMainPath(main);
Collapse file

‎lib/internal/process/pre_execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/process/pre_execution.js
+10Lines changed: 10 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.