Add support for named imports in ESM#1440
Merged
shadowspawn merged 12 commits intotj:developfrom Jan 20, 2021
Merged
Conversation
Closed
Collaborator
Author
|
So fast! 🚀 |
cravler
reviewed
Jan 21, 2021
| "main": "./index.js", | ||
| "files": [ | ||
| "index.js", | ||
| "wrapper.mjs", |
Contributor
There was a problem hiding this comment.
looks like a typo, must be esm.mjs
Collaborator
Author
There was a problem hiding this comment.
Oh, good catch, thanks! I changed the name half way through.
Collaborator
Author
There was a problem hiding this comment.
(For interest, I thought wrapper was a suitable name for a wrapper used with conditional exports and not seen by normal client use. But when I changed to deep import and the name became visible, I wanted something more meaningful.)
This was referenced Mar 8, 2021
This was referenced Mar 15, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Problem
Importing commander as CommonJs into an ECMAScript module only allows using the default import, and can not use named imports.
Related issue: #1284
Solution
Add esm wrapper and use as a deep import:
In the future we will add support so the deep import is not needed by using conditional exports and/or subpaths. Being conservative for now as the functionality is still marked as experimental in node 12. (There have been breaking changes in the support in minor versions of node 12 and 13.)
The
--experimental-modulesoption used in thetest-esmrun-script will get dropped by node eventually, but currently allows that test to run locally with node 10 through node 15.ChangeLog