-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
feat: add support for 'electron' condition in conditional exports #59002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add conditions.add('electron') after getConditionsSet() result.
Adds 'electron' to CommonJS conditions when in Electron.
Review requested:
|
How does adding this string to |
Hi! Something like (totally made up API, just giving an hint):
And in import { registerCondition } from 'node:module'
registerCondition((nmPath, request, conditions) {
if (process.versions?.electron && conditions?.add) {
conditions.add('electron');
}
}) |
Will definitely give it a try and open the PR! |
@@ -638,6 +638,12 @@ const EXPORTS_PATTERN = /^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/; | |||
*/ | |||
function resolveExports(nmPath, request, conditions) { | |||
// The implementation's behavior is meant to mirror resolution in ESM. | |||
|
|||
//Add electron | |||
if (process.versions?.electron && conditions?.add) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally really don't like to have such downstream (electron) code into upstream (node)
Description
This PR adds support for resolving "electron" condition in both ESM and CommonJS module resolution, based on process.versions.electron. Useful for runtime-specific exports for Electron apps.
Resolves electron/electron#47670