Skip to content

Commit 72644d6

Browse files
aduh95GeoffreyBooth
authored andcommitted
esm: improve JSDoc annotation of internal functions
Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: #49959 Backport-PR-URL: #50669 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 8c55f31 commit 72644d6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/internal/modules/run_main.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const path = require('path');
1010

1111
/**
1212
* Get the absolute path to the main entry point.
13-
* @param {string} main Entry point path
13+
* @param {string} main - Entry point path
1414
*/
1515
function resolveMainPath(main) {
1616
// Note extension resolution for the main entry point can be deprecated in a
@@ -31,7 +31,7 @@ function resolveMainPath(main) {
3131

3232
/**
3333
* 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
3535
*/
3636
function shouldUseESMLoader(mainPath) {
3737
/**
@@ -63,7 +63,7 @@ function shouldUseESMLoader(mainPath) {
6363

6464
/**
6565
* 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
6767
*/
6868
function runMainESM(mainPath) {
6969
const { loadESM } = require('internal/process/esm_loader');
@@ -78,7 +78,7 @@ function runMainESM(mainPath) {
7878

7979
/**
8080
* 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
8282
*/
8383
async function handleMainPromise(promise) {
8484
const {
@@ -96,7 +96,8 @@ async function handleMainPromise(promise) {
9696
* Parse the CLI main entry point string and run it.
9797
* For backwards compatibility, we have to run a bunch of monkey-patchable code that belongs to the CJS loader (exposed
9898
* 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
100101
*/
101102
function executeUserEntryPoint(main = process.argv[1]) {
102103
const resolvedMain = resolveMainPath(main);

lib/internal/process/pre_execution.js

+10
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,20 @@ function refreshRuntimeOptions() {
141141
refreshOptions();
142142
}
143143

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+
*/
144151
function patchProcessObject(expandArgv1) {
145152
const binding = internalBinding('process_methods');
146153
binding.patchProcessObject(process);
147154

148155
require('internal/process/per_thread').refreshHrtimeBuffer();
149156

157+
// Since we replace process.argv[0] below, preserve the original value in case the user needs it.
150158
ObjectDefineProperty(process, 'argv0', {
151159
__proto__: null,
152160
enumerable: true,
@@ -159,6 +167,8 @@ function patchProcessObject(expandArgv1) {
159167
process._exiting = false;
160168
process.argv[0] = process.execPath;
161169

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

0 commit comments

Comments
 (0)