Repository navigation
process: add process.entrypoint - #64800
avivkeller wants to merge 4 commits into
Conversation
Signed-off-by: avivkeller <me@aviv.sh>
|
Review requested:
|
|
@nodejs/process |
|
in worker threadsx this is set to the entrypoint of the worker? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64800 +/- ##
==========================================
- Coverage 90.16% 90.12% -0.05%
==========================================
Files 744 752 +8
Lines 242518 251602 +9084
Branches 45705 47278 +1573
==========================================
+ Hits 218670 226757 +8087
- Misses 15357 16211 +854
- Partials 8491 8634 +143
🚀 New features to boost your workflow:
|
This is set to the entrypoint of the process that created the worker, not the worker itself. So if |
this is behaviorally different from the old "require.main". Can we have the same? |
|
IMO it makes more sense to show the entrypoint of the process, not the worker |
|
I'm saying this is not identical to require.main, or what import.main is defined. The issue linked refers to require.main. |
|
Okay, I've changed |
|
Opened #64903 with the thread-scoped counterpart ( |
|
Awesome! Aside from that, is this good to go? |
Add `module.entrypoint`, a property exposing the resolved URL of the entry point of the current thread. Unlike `require.main`, it works regardless of whether the entry point is a CommonJS or an ECMAScript module, and inside worker threads it reflects the entry point of the worker itself, matching the semantics of `require.main` and `import.meta.main`. Refs: nodejs#51840 Refs: nodejs#64800 Signed-off-by: Matteo Collina <hello@matteocollina.com>
|
bump @nodejs/process |
|
Bump @mcollina! |
|
Bump! |
Add `module.entrypoint`, a property exposing the resolved URL of the entry point of the current thread. Unlike `require.main`, it works regardless of whether the entry point is a CommonJS or an ECMAScript module, and inside worker threads it reflects the entry point of the worker itself, matching the semantics of `require.main` and `import.meta.main`. Refs: nodejs#51840 Refs: nodejs#64800 Signed-off-by: Matteo Collina <hello@matteocollina.com>
marcastben-hash
left a comment
There was a problem hiding this comment.
I read this at 4878c1f. I did not build the branch; point 1 I checked on a released Node (v24.15.0) using the same computation the PR uses, the rest is from reading.
-
The value is not the URL the entry module is actually loaded under when the path goes through a link.
mainEntryispath.resolve(process.argv[1]), with no realpath, while the CJS and ESM loaders resolve symlinks for the main module (unless--preserve-symlinks-main). Running a script through a directory junction on Windows:> node link/app.mjs import.meta.url file:///.../symtest/real/app.mjs pathToFileURL(resolve(argv[1])).href file:///.../symtest/link/app.mjsSo
process.entrypoint === import.meta.urlis false in that case, and I would expect the same fornode_modules/.binsymlinks on POSIX. Since "am I the main module?" is the use case in #51840, this is likely to be the first thing people try. Either resolve it the same way the loader does, or document that the value is the path as given on the command line, made absolute, and not necessarily equal toimport.meta.url. -
Description and code disagree on configurability. The description says the property is non-configurable;
defineEntrypoint()usesconfigurable: true(which the worker path needs in order to redefine it afterpatchProcessObject()). As written, user code can delete or redefineprocess.entrypoint. If that is not intended, the worker could be given the value before the first definition, or the final definition could be made non-configurable. -
With a relative
--entry-url, the result depends on the cwd at first access. The getter is lazy and callsgetCWDURL()when first read, andgetCWDURL()followsprocess.cwd().node --entry-url ./app.mjsfollowed byprocess.chdir()before the first read ofprocess.entrypointresolves against the new directory. Capturing the cwd at startup, or resolving eagerly in the--entry-urlcase only, would avoid that. -
Docs: it would help to state what the value is for
node -(stdin),--test,--watchand single executable applications, sinceprocess.argv[1]means something different in some of those. None of them are covered by the tests either.
Disclosure: this review was prepared with AI assistance (Claude).
There was a problem hiding this comment.
Nit: I think it's more efficient for the getter to overwrite itself upon execution, switching from a get to a value (then there is no scope to maintain).
There was a problem hiding this comment.
Nit: To avoid ambiguity (URL instance vs a string). As it was written, I would expect an instance.
| The file URL string of the entry point that Node.js was started with, such as |
Ref: #51840
Adds a
process.entrypointnon-configurable property to theprocessobject during bootstrap. This property reflects the executable's main entrypoint (i.e. not--requireor--import-ed files, the main file).Additionally, this entrypoint is passed to workers, so it reflects the entrypoint of the process that created the worker, not the entrypoint of the worker itself.