-
Notifications
You must be signed in to change notification settings - Fork 18
Entry points proposal spec and implementation #32
Conversation
I think a
|
@ljharb glad to hear that! When no |
The file extension has the highest precedence. If the filename has If the file extension is ambiguous ( If If there is no |
can it please be renamed to |
No. The point is to match
We considered Again, Stage 4 is designated for UX review and feedback. What we name things now doesn’t matter, everything is temporary until we get broader exposure and feedback from a wider audience of users. |
kinda unfortunate design 🤷 i guess we can discuss it later though
like i said, its fine to be "commonjs", it just needs to be updated in all the other places too.
personal reminder for |
66aebb1
to
5374da9
Compare
What is the expected behavior of having colliding CLI flag and package.json?
node -m bin/entry The spec makes it look like |
The spec says that the flag will “tell Node to parse as ESM entry points that would otherwise be ambiguous.” Hence the flag throws on I would be wary of throwing in the example you listed above, because the user’s intent is clear. They need to tell Node the module type to use for the entry point either via a flag or We can always add more error-checking later on to increase the cases under which we throw errors; we don’t need to throw for this case. Even though we could, it’s probably much simpler UX to just tell users that |
On further thought, I guess this is a case of user intent versus author intent. Currently author intent overrides user intent for file extensions but nothing else (I think). I could also see a UX case for user intent always taking priority. |
I don't understand this statement. A package is unrelated to my question really except that it is used as a configuration point, only files have specific formats and the configuration points seem to have some conflict in this PR about specifying formats for files. The question isn't about if we can have dual mode packages, but rather what happens when a resource has conflicting configuration.
I don't understand this either, the user has 2 configuration points via CLI and package.json, and they are conflicting in my example. Since we have this conflict, why not just state that the conflict itself is an error "Cannot treat bin/entry.js as ESM via --type because a package.json has marked it as CJS" or somesuch; that would cause the user to resolve the conflict. To clarify, the design of this PR currently means that files are not having a well defined format statically, as they can be altered depending on how they are consumed. node --type=module bin/entry.js // bin/entry.js
// package.json denotes this file as CJS
// CLI denotes this file as ESM
// works if loaded via CLI with --type=module
// fails if loaded via static information from package.json
import('./entry.js');
We don't need to do anything really since we can mandate any design decision we can agree upon and we can write up rationalizations afterwards. The concern I have is that we have multiple configuration points and they are contradicting each other. |
@bmeck Sure, we can error if the package scope and For the purposes of development, though, I think that that can be a separate PR, if @guybedford doesn’t have time to add that before this week’s meeting. |
Seems fine as a diff PR |
The other remaining thing we need to work out is how exactly dual-mode packages will work, since we would want to throw only if the flag conflicts with either way that a dual-mode package allows its files to be run. So maybe this error handling can be part of figuring out the details of how dual-mode packages can be specified by users and run by Node. |
55dcaf8
to
4228797
Compare
af0d1ef
to
a63e09c
Compare
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.
LGTM
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.
LGTM
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.
Rubber stamp LGTM
please run CI before landing and make commit messages follow upstream guidelines |
Finally… this is an amazing step in my books 🙏 |
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.
LGTM
☝️ someone’s following along closely |
4228797
to
39ba864
Compare
a63e09c
to
3a71de7
Compare
CI all green, merged. |
How would libraries(in node_modules) provide a path to the module, considering that "pkg.main" already points to for example a "umd" source file. Will there be a "pkg.src" field in symmetry with |
Currently in this implementation |
It doesn't preclude it if we do extension look up - you'd omit the extension (which is a reigning best practice anyways with cjs) and then have one extension for ESM and another for CJS. |
That's what I've been doing with Roff.js (and a few other projects published to NPM with both /* package.json */
{
…
"main": "./pan-and-zoom",
…
} With package contents like this:
Are you saying this will stop working at some point? |
Automatic extension resolution contradicts our goal of browser equivalence, so I assume it won't be enabled by default; though I expect it would be possible via opt-in configuration or a package-level loader. In ESM mode .js files are treated as ESM, so at the very least it would be confusing to rely on extensions for disambiguation. A better UX is probably a way to explicitly define each entry point. Such a new field would also allow specifications of other types of entry points, like for browsers (see the commonly used |
This implements a top-level
--type
flag for--experimental-modules
with the following behaviours.In addition
"type": "esm"
in the package.json is renamed to"type": "module"
, and a new extension.cjs
is supported.These behaviours are as defined in https://github.com/GeoffreyBooth/node-esm-entry-points-proposal.
node --experimental-modules ./x.unknown --type=module
will always execute the top-level file as an ES module, unless it ends in.cjs
, in which case an error is thrown.node --experimental-modules ./x.unknown --type=commonjs
will always execute the top-level file as a CommonJS module.node --experimental-modules
flags--check
,--print
,-e
and stdin, including compatibility with--type
With this PR, we get both the package.json boundary as the module format hint, as well as an ability to now override the format to a known format.
As with all previous PRs there are two commits - one with just the spec/doc changes, and another with the implementation.
The following features in the entry points proposal are not yet implemented in this PR and should be implemented as follow-up work:
--type=auto
for syntax detection-m
alias for--type=module