node
node copied to clipboard
esm: implement import.meta.main
Boolean value to check if a module is run as entry point of the current process.
ES module authors need a way to determine if their code is run as CLI or as a dependency. nodejs/node#49440 have some proposal, I am implementing import.meta.main
because:
- it is arguably similar to the CJS pattern:
- if (module === require.main) {
+ if (import.meta.main) {
- Deno has already implemented it, if we don't differ that is certainly easier for users to write code that runs everywhere.
- It was suggested originally in the
import.meta
proposal.
Fixes: https://github.com/nodejs/node/issues/49440
Checklist
- [x]
make -j4 test
(UNIX), orvcbuild test
(Windows) passes - [x] tests and/or benchmarks are included
- [x] documentation is changed or added
- [x] commit message follows commit guidelines