-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Description
What is the problem this feature will solve?
Code might want to determine if it's running via main app entry point or via a module imported via --import
. For example, a library might instruct users to run the code via --import
and might want to warn users if this is not the case.
What is the feature you are proposing to solve the problem?
Not sure what the API should be, maybe process.isEntryPoint
or something like that?
The entry point is already marked on globalThis
via a private symbol:
node/lib/internal/modules/esm/module_job.js
Lines 255 to 257 in aca49fc
if (isEntryPoint) { | |
globalThis[entry_point_module_private_symbol] = this.module; | |
} |
What alternatives have you considered?
Currently the only way I can think to detect this would be to parse new Error().stack
to find the entry point file and then parse and compare to process.execArgv
. This is not trivial since you'd need to resolve bare specifiers to their actual source files.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status