Skip to content

Means to detect if the current code is run via --import  #53882

@timfish

Description

@timfish

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.loadersIssues and PRs related to ES module loadersstale

    Type

    No type

    Projects

    Status

    Triaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions