-
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: clarify require/import complement exclusivity #33832
Conversation
//cc @sokra |
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.
Technically there may be "classic-script" as a 3rd option but I'm fine with pretending that it doesn't exists, as far as exports
is concerned. Classic scripts don't have a notion of "import specifiers", really.
I'd just note that "mutual exclusivity" doesn't mean one or the other must be true, just that they both cannot be true, so it seems the example in the original comment about not being able to hit |
Thanks @bmeck for the logical assistance here... ok I've changed the wording to be explicit they that are fully complementary in matching. Let me know if that sounds better. |
sounds good |
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 don't agree with that. That might be true for node in the current state, but I don't think that should be a general precondition.
Other conditions should be allowed for future extensions or alternative module formats.
Esm might be superseded by a new module format in a long distant future. For this you might want to use a new condition zap
to point to the zap modules.
Non JavaScript module systems also want to use a different condition. For a css module using @import "package"
you may want to use the @import
condition name.
Mutually exclusive seems fine to me. Meaning when |
To clarify here: the condition is called “import” because it refers to a module graph, not to a module file format. So it may point to a web assembly module or a JSON module, assuming those can be linked into an import-style graph of modules. Just like “require” doesn’t mean CommonJS file format. It could also point to .node or .json files which are also supported in require-style module graphs (potentially). |
@sokra would it help if we specifically adjust the wording to distinguish between |
PR-URL: #33832 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Landed in f89530f. |
PR-URL: #33832 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
PR-URL: #33832 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
PR-URL: #33832 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
This PR adds a small doc change to clearly define that
"import"
and"require"
are always mutually exclusive in exports (if something was not required then it definitely was imported) when loading an ES module.Currently there isn't clear guidance that when defining in "exports":
that it should never be possible to resolve to
./main.js
.For example, other tools and bundlers could interpret
new Worker('pkg')
to not be animport
orrequire
path at all. Or similarly for other mechanisms of loading in future. When we should always define that loading an ES module goes through theimport
path.Otherwise, this leaves a semantic gap where users might find
default
matched by some tools in the above example. By narrowing this gap we ensure we can continue to provide predictability between tools.//cc @nodejs/modules-active-members
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes