Uh oh!
There was an error while loading. Please reload this page.
ESM_FORMAT: Avoid reading package.json when extension is unambiguous - #33
ESM_FORMAT: Avoid reading package.json when extension is unambiguous#33mathiasbynens wants to merge 14 commits into
Conversation
Refs: nodejs/modules#180 PR-URL: nodejs#6 Reviewed-By: Myles Borins <MylesBorins@google.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Refs: nodejs/modules#180 PR-URL: nodejs#6 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Refs: nodejs/modules#180 PR-URL: nodejs#6 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Refs: nodejs/modules#180 PR-URL: nodejs#6 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: nodejs#6 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: nodejs#6 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <mylesborins@google.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: nodejs#6 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <mylesborins@google.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
It’s wasteful to load the package.json even if the extension is unambiguous. This patch optimizes for the zero-config case by avoiding needless package.json loads. With this patch, the mental model becomes a lot simpler too: - `.cjs` means `commonjs` - `.mjs` means `module` See discussion thread: https://twitter.com/mathias/status/1096167102455709696
ljharb
commented
Feb 16, 2019
I don’t think this is a future-looking optimization; eventually package.json should be able to override any extension to parse in any way. |
That’s what’s under discussion. IMHO it’s worth carving out We need to weigh the cost of allowing |
robpalme
commented
Feb 16, 2019
This PR looks good. My view is that package.json is about defining package-scoped things, whereas extensions/pragmas are a way of specialising/overriding behaviour on a per-file basis. This locality simplifies the mental model and eliminates a data-dependency. |
guybedford
commented
Feb 16, 2019
Thanks @mathiasbynens for the PR. This is a simplification of the existing spec that seems sensible to me. There is effectively only one behavioural change here from what was written previously and that is that previously if there was no package boundary, we would load This sounds like a spec bug to me, where the fix happens to enable an optimization. We as a group can decide over time whether we want that optimization to remain, but what we're really deciding from a behavioural perspective is if |
mathiasbynens
commented
Feb 16, 2019
+1 FWIW, there is precedent for this in both |
guybedford
commented
Feb 16, 2019
Note that the implementation already does this too, so that this is actually just a spec bug. |
GeoffreyBooth
commented
Feb 16, 2019
This is fine for where the implementation is now, but if we add package exports we'll always need to read package.json to know what the valid paths inside a package are. Also package-level loaders, if added, would also require always reading package.json. Ditto for file extension configuration like @ljharb said. Another point is if But for right now, sure. |
guybedford
left a comment
There was a problem hiding this comment.
Just noticed this line is missing.
Uh oh!
There was an error while loading. Please reload this page.
ljharb
left a comment
There was a problem hiding this comment.
We don’t even have consensus that the cjs extension will be a thing, and no extension should be special - if any of them can’t br overridden, then none of them can (including js)
guybedford
commented
Feb 16, 2019
@ljharb please read #33 (comment) and then let me know if you want to revise your comment. |
ljharb
commented
Feb 16, 2019
@guybedford that comment hasn’t made anything clear to me about why I’d revise it. In the absence of a package.json, and perhaps when run as an entry point, it makes sense that a file extension unambiguously determines the parse goal, but if a package.json is present (and certainly when it’s not an entry point), it must always be consulted regardless of the file extension. No extension should be special; either they can all be overridden from package.json or none of them can. Separately, adding the cjs extension, without any consensus besides apparent side channel discussions about it, isn’t something that should be done via a PR. |
guybedford
commented
Feb 16, 2019
Currently, by the spec, The change here ONLY changes the above. That is the only behavioural change. |
bd5c877 to
0237465Compare484d1fb to
7efc53dComparec7fa700 to
d69f765Compare335d584 to
9a343ceCompare3a00b51 to
bc101f6Comparefd5b55a to
3a40599CompareTrott
commented
Apr 9, 2020
I imagine this can/should be closed at this point? Or if not closed, then at least transferred to the main repository? |
It’s wasteful to load the package.json even if the extension is unambiguous. This patch optimizes for the zero-config case by avoiding needless package.json loads.
With this patch, the mental model becomes a lot simpler too:
.cjsmeanscommonjs.mjsmeansmoduleSee discussion thread: https://twitter.com/mathias/status/1096167102455709696
Checklist