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:
|
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.
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--importand 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.isEntryPointor something like that?The entry point is already marked on
globalThisvia a private symbol:node/lib/internal/modules/esm/module_job.js
Lines 255 to 257 in aca49fc
What alternatives have you considered?
Currently the only way I can think to detect this would be to parse
new Error().stackto find the entry point file and then parse and compare toprocess.execArgv. This is not trivial since you'd need to resolve bare specifiers to their actual source files.