Skip to content

Conversation

@JakobJingleheimer
Copy link
Member

This loader enables (with non-robust checks) loading both CJS and ESM from the same package where the package declares a single type.

This is a common scenario in older packages that distribute both CJS and ESM yet mark themselves as commonjs (either by omission of "type" or by relying on the non-standard "module" field).

Depends on nodejs/node#44396

Co-authored-by: Geoffrey Booth <[email protected]>
@JakobJingleheimer JakobJingleheimer merged commit b3fe2b0 into main Aug 31, 2022
Comment on lines +28 to +33
if (src.match(/exports[\.( ?=)]/)) { return true };

if (
src.match(/require\(/)
&& !src.match(/createRequire\(/)
) return true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using /regex/.test here, much faster than 'string'.match as it doesn't need to create an array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, good call. I'll send an update this evening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants