Skip to content
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

doc: add current recommendation for ESM/CommonJS dual packages #27957

Closed

Conversation

GeoffreyBooth
Copy link
Member

This PR updates the ECMAScript Modules docs to include a recommendation from the @nodejs/modules team regarding dual CommonJS/ESM packages. Per our current roadmap, there is a good chance that the current support for dual CommonJS/ESM packages is what will be the final support when the --experimental-modules flag is dropped; the package organization method suggested in this PR would then become the recommended way for public package authors to support both CommonJS and ESM consumers of their package, should the author desire to publish both types of sources within the same package. If either of the other dual package-related proposals still under consideration end up shipping, this recommendation would still be valid.

Checklist

@Trott
Copy link
Member

Trott commented May 30, 2019

@Trott Trott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 30, 2019
> it will very likely entail changes to the behavior of `"main"` as defined
> here.
The `"main"` field can point to exactly one file, regardless of whether the
package is referenced via `require` (in a CommonJS context) or `import` (in an
Copy link

@robpalme robpalme May 31, 2019

Choose a reason for hiding this comment

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

The bracketed clarifications seem a bit ambiguous about whether it's the context of the caller or the callee module. I think we're trying to make a statement about the callee module. And it's not true that import implies either the caller or the callee (if we consider dynamic import()) will be in ESM context. I am finding this hard to word accurately and unambiguously. Maybe something like:

The "main" field can point to exactly one file, regardless of whether the package is referenced via require (which will load the file as CommonJS) or import (which allows Node's loading rules to decide whether to load the file as either an ES module or as CommonJS).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the original is more correct. It is about which loader / module graph the module may be part of, not about the interpretation of the file contents. E.g. in a require context, it may be any number of file formats supported via require._extensions and in an import context it may be any content type supported by the import loader system.

The main point here is that it can only point to exactly one file on disk and it may only be instantiated/interpreted at most once: Either as part of the require module graph or as part of the import module graph (with the additional note that the import graph may point to nodes in the require graph).

@Trott Trott added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Jun 1, 2019
@bmeck
Copy link
Member

bmeck commented Jun 1, 2019 via email

@GeoffreyBooth
Copy link
Member Author

Does this PR need anything else?

@Trott
Copy link
Member

Trott commented Jun 7, 2019

Does this PR need anything else?

As long as there's nothing in @bmeck's comments that are blocking this, it can land.

@bmeck Can you confirm that this is A-OK to land as far as you are cocerned?

@Trott
Copy link
Member

Trott commented Jun 11, 2019

Landed in 62ac84b

@Trott Trott closed this Jun 11, 2019
Trott pushed a commit to Trott/io.js that referenced this pull request Jun 11, 2019
PR-URL: nodejs#27957
Reviewed-By: Ujjwal Sharma <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Jan Krems <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Bradley Farias <[email protected]>
@ljharb ljharb deleted the dual-packages-docs branch June 11, 2019 05:36
@GeoffreyBooth
Copy link
Member Author

@Trott Thanks! When does the docs site get updated? On each Node release?

@Trott
Copy link
Member

Trott commented Jun 11, 2019

@Trott Thanks! When does the docs site get updated? On each Node release?

Yes. Of the currently-supported versions of Node.js (8, 10, and 12), which should get this update? (The update will only happen if this commit is pulled over to the correct release line branches.)

@GeoffreyBooth
Copy link
Member Author

Yes. Of the currently-supported versions of Node.js (8, 10, and 12), which should get this update? (The update will only happen if this commit is pulled over to the correct release line branches.)

Only 12, at the moment, as this is only applicable to the Node 12+ --experimental-modules. As far as I understand things we haven’t backported the new implementation to 10 yet, though we hope to at some point.

BridgeAR pushed a commit that referenced this pull request Jun 17, 2019
PR-URL: #27957
Reviewed-By: Ujjwal Sharma <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Jan Krems <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Bradley Farias <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants