Skip to content

Commit cd95cbd

Browse files
committed
fixup!
1 parent 992b11a commit cd95cbd

11 files changed

Lines changed: 37 additions & 27 deletions

File tree

β€Ždoc/api/process.mdβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,11 +1519,11 @@ emitMyWarning();
15191519
added: REPLACEME
15201520
-->
15211521
1522-
* Type: {URL | undefined}
1522+
* Type: {string | undefined}
15231523
1524-
The entry point that Node.js was started with. Worker threads inherit this
1525-
value. If Node.js was started without an entry point, such as in the REPL, the
1526-
value is {undefined}.
1524+
The URL of the entry point that Node.js was started with, such as
1525+
`'file:///path/to/app.js'`. Worker threads inherit this value. If Node.js was
1526+
started without an entry point, such as in the REPL, the value is {undefined}.
15271527
15281528
## `process.env`
15291529

β€Žlib/internal/main/worker_thread.jsβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ port.on('message', (message) => {
105105
mainThreadPort,
106106
} = message;
107107

108-
const { URL } = require('internal/url');
109-
defineEntrypoint(entrypoint === undefined ?
110-
undefined : new URL(entrypoint));
108+
defineEntrypoint(() => entrypoint);
111109

112110
if (doEval !== 'internal') {
113111
if (argv !== undefined) {

β€Žlib/internal/process/pre_execution.jsβ€Ž

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,22 @@ function refreshRuntimeOptions() {
255255
refreshOptions();
256256
}
257257

258-
function defineEntrypoint(entrypoint) {
258+
function defineEntrypoint(computeEntrypoint) {
259+
let entrypoint;
260+
let computed = false;
261+
259262
ObjectDefineProperty(process, 'entrypoint', {
260263
__proto__: null,
261-
writable: false,
262264
enumerable: true,
263265
configurable: true,
264-
value: entrypoint,
266+
get() {
267+
if (!computed) {
268+
entrypoint = computeEntrypoint();
269+
computed = true;
270+
}
271+
return entrypoint;
272+
},
273+
set: undefined,
265274
});
266275
}
267276

@@ -305,15 +314,18 @@ function patchProcessObject(expandArgv1) {
305314
}
306315
}
307316

308-
let entrypoint;
309-
if (mainEntry !== undefined) {
310-
const { pathToFileURL } = require('internal/url');
311-
entrypoint = pathToFileURL(mainEntry);
312-
} else if (getOptionValue('--entry-url') && process.argv[1]) {
313-
const { URL } = require('internal/url');
314-
entrypoint = new URL(process.argv[1], getCWDURL());
315-
}
316-
defineEntrypoint(entrypoint);
317+
const entryArg = process.argv[1];
318+
defineEntrypoint(() => {
319+
if (mainEntry !== undefined) {
320+
const { pathToFileURL } = require('internal/url');
321+
return pathToFileURL(mainEntry).href;
322+
}
323+
if (entryArg && getOptionValue('--entry-url')) {
324+
const { URL } = require('internal/url');
325+
return new URL(entryArg, getCWDURL()).href;
326+
}
327+
return undefined;
328+
});
317329

318330
// We need to initialize the global console here again with process.stdout
319331
// and friends for snapshot deserialization.

β€Žlib/internal/worker.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class Worker extends EventEmitter {
362362

363363
this[kPort].postMessage({
364364
argv,
365-
entrypoint: process.entrypoint?.href,
365+
entrypoint: process.entrypoint,
366366
type: messageTypes.LOAD_SCRIPT,
367367
filename,
368368
doEval,

β€Žtest/fixtures/entrypoint/check-commonjs.cjsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
const assert = require('node:assert');
44

5-
assert.strictEqual(process.entrypoint.href, process.env.NODE_TEST_ENTRYPOINT);
5+
assert.strictEqual(process.entrypoint, process.env.NODE_TEST_ENTRYPOINT);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import assert from 'node:assert';
22
import { entrypoint } from 'node:process';
33

4-
assert.strictEqual(entrypoint.href, process.env.NODE_TEST_ENTRYPOINT);
4+
assert.strictEqual(entrypoint, process.env.NODE_TEST_ENTRYPOINT);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log(process.entrypoint.href);
1+
console.log(process.entrypoint);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import assert from 'node:assert';
22
import { entrypoint } from 'node:process';
33

4-
assert.strictEqual(entrypoint.href, process.env.NODE_TEST_ENTRYPOINT);
4+
assert.strictEqual(entrypoint, process.env.NODE_TEST_ENTRYPOINT);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log(process.entrypoint.href);
1+
console.log(process.entrypoint);

β€Žtest/fixtures/entrypoint/worker.cjsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ const { isMainThread, workerData, Worker } = require('node:worker_threads');
55
if (isMainThread || workerData === 'nested') {
66
new Worker(__filename, { workerData: isMainThread ? 'nested' : 'leaf' });
77
} else {
8-
console.log(process.entrypoint.href);
8+
console.log(process.entrypoint);
99
}

0 commit comments

Comments
Β (0)