-
-
Notifications
You must be signed in to change notification settings - Fork 54
feat: esm support #192
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?
feat: esm support #192
Conversation
- Added ESM implementation research summary detailing testing evidence and technical findings. - Created test suite for pure ESM modules in `test/test-50-esm-pure`, including: - README.md outlining the problem with ESM packages. - main.js to run tests and package ESM modules. - test-x-index.js to validate ESM module loading. - package.json and package-lock.json for dependencies. - Developed test suite for UUID v10+ in `test/test-50-uuid-v10`, including: - README.md explaining the test objectives. - main.js to execute tests and validate outputs. - test-x-index.js to test various UUID functionalities. - Established a strategy for transforming ESM to CJS using Babel to ensure compatibility with existing pkg infrastructure.
- Created lib/resolver.ts with ESM-aware resolution using resolve.exports - Enhanced lib/follow.ts to try ESM resolution first for non-relative imports - Fixed package.json inclusion for ESM packages with exports field - Added synthetic 'main' field to package.json when only exports exists - Ensures all discovered package.json files are included in snapshot - Both test-50-esm-pure (nanoid) and test-50-uuid-v10 now pass - No regressions in existing tests This completes Sprint 2 of the ESM implementation plan.
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.
To delete
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.
to delete
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.
to delete
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.
to delete
This pull request introduces enhanced support for ECMAScript Modules (ESM) in the Node.js packaging workflow, ensuring that ESM modules are correctly resolved, transformed, and included in the package output. The changes add ESM-aware module resolution, automatic transformation of ESM code to CommonJS for bytecode compilation, and improved handling of
package.jsonfiles for ESM packages. Documentation and dependencies are updated to reflect these improvements.ESM Support and Module Resolution:
lib/resolver.tsthat handles package.json "exports" fields and resolves modules according to ESM rules, falling back to CommonJS resolution if needed.lib/follow.tsto use the new ESM resolver for non-relative module specifiers, including logic to ensure relatedpackage.jsonfiles are included and patched with syntheticmainfields when necessary. [1] [2] [3]ESM Detection and Transformation:
lib/common.tsto detect ESM files and packages by inspecting file extensions and the nearestpackage.json"type" field.lib/esm-transformer.tsto transform ESM code to CommonJS using Babel, enabling ESM modules to be compiled to bytecode.lib/walker.tsto patchpackage.jsonfiles for ESM packages and transform ESM.jsfiles to CommonJS before bytecode compilation. [1] [2] [3] [4]Documentation and Dependency Updates:
.github/copilot-instructions.mdto document the newplans/directory and clarify that Yarn is used for package management. [1] [2]package.json, including Babel plugins andresolve.exports. [1] [2] [3]