-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: esm: options for package authors #29497
Conversation
aaeceba
to
c28ee9b
Compare
@nodejs/documentation @nodejs/modules @nodejs/collaborators This could use some reviews. |
Anyone care to review? 🙋 |
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'm not a subject-matter expert on ES modules by any means, but LGTM other than needing to move a bottom reference to a different location in the list.
I evaluated it it for formatting and clarity of text. It would be great if someone from @nodejs/modules-active-members could sign off on it (or provide a brief explanation of why perhaps it shouldn't land).
not sure if late for this party, but as soon as you decide to reserve an entry in
{
// backward compatible
"main": "cjs/index.js",
"type": {
"commonjs": "cjs/index.js",
"esm": "esm/index.mjs",
"json": "json/index.json",
"wasm": "wasm/index.wasm"
}
} Something like that would help dual, triple, quadruple package modules that could include present and future of any format we could come up with. TL;DR why would |
@WebReflection sounds like you're asking for nodejs/modules#283 :-) |
This is outside the scope of this PR, but it’s under development in nodejs/modules#368. |
I don't think |
@ljharb @GeoffreyBooth thanks, not sure it's the same, but I'll have a look
what I've said has nothing to do with A dual module would like to point at both CJS and ESM, but if loaded via WASM (in the future) it could point at WASM too, whenever it'll get some module namespace. Having a |
I'm not sure what you mean by "loaded as WASM" - wouldn't you expect that if the same package is reachable from JS and WASM, it would do the same thing / point to the same thing? In my head those boundaries between modules shouldn't care that either side is WASM or JS..? I would expect that if I have gone through the pains of shipping a binary AST format in the future, it would always be used even if the importing module happens to be written in plain JS. |
@WebReflection please open an issue in https://github.com/nodejs/modules if you don’t mind, this PR is just a documentation update 😄 |
if the bundler doesn't understand that, it can fallback. and so on and so forth, there are not just two kind of modules, as there was never just one kind, hence my comment. @GeoffreyBooth if you think it's needed, I will. Regaards |
As ES Modules are |
* organize sections more hierarchically * recommend always including "type" field, per 2019-06-19 meeting Refs: nodejs/modules#342 (comment) * expand discussion of publishing cjs/esm packages PR-URL: #29497 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 80cc6f5 |
* organize sections more hierarchically * recommend always including "type" field, per 2019-06-19 meeting Refs: nodejs/modules#342 (comment) * expand discussion of publishing cjs/esm packages PR-URL: #29497 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* organize sections more hierarchically * recommend always including "type" field, per 2019-06-19 meeting Refs: nodejs/modules#342 (comment) * expand discussion of publishing cjs/esm packages PR-URL: #29497 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This updates the ECMAScript Modules docs with a few changes agreed in recent modules group meetings:
Per the 2019-06-19 meeting, we decided that we want to encourage all package authors to always include the
package.json
"type"
field, even for CommonJS packages (where"type": "commonjs"
is implied).Per the 2019-08-28 meeting, we decided that the docs needed more discussion of packages and specifically what options are available for package authors wishing to support both CommonJS and ESM consumers of packages, and both current and older versions of Node.
Regarding the latter, this PR is just a first step; it will need expansion if/when #29494 is merged in, and possibly again later if more improvements are made to better support different module systems or Node runtime versions. For now, though, I think this text is an improvement on the very minimal mention that dual CommonJS/ESM support in packages has currently.
Checklist
//cc @nodejs/modules-active-members