-
-
Notifications
You must be signed in to change notification settings - Fork 0
Does "mode" help or hinder? #1
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
Comments
You've actually touched on the two gotchas with exports here:
Now I certainly get your point about the "main" here. I've specified the exact behaviours in guybedford/ecmascript-modules@f4817c8. Please do let me know your thoughts further. |
It's worth noting that there is no conditional behaviour on the main from a user perspective. |
Response to Gotcha 1 This ordering hazard (forgetting to define Response to Point 2 Overall I agree where best practices are unclear or controversial, clearly we should not force anyone's hand. Encapsulation on the other hand is less controversial. Or at least I would argue that, if you want to use modules, you are implicitly asking for encapsulation. There's a reason the In this case I would also like to draw an analogy with strict-mode being force-enabled in ES modules. One could argue that introducing a new module system is orthogonal to tightening up the language specification. So why were they coupled? The reason is that the majority of developers recognize the value that a more constrained language provides to developers - especially providing it by default. If we really wanted to follow the principles of catering to everyone's wishes, we would be offering a Ryan Dahl recently acknowledged lack of package encapsulation as a design flaw in the original design of module. Which leaves a diminishingly small population (or set of use-cases) that might actively want to avoid package encapsulation. I would argue that if these use-cases are real, we could support them in an opt-in fashion, e.g. we define By default, I expect most users of modules will want package encapsulation just as much as they want module encapsulation and strict-mode. |
From a semantic point of view, yes. But from a user perspective there is very different user understanding of the two. Two examples:
This is an excellent argument, and I was almost convinced. But this argument only works when considering the "general user". We need to consider every user. Imagine one user who specifically wants an unencapsulated package (for whatever reason, it may be due to a large number of subpaths, instrumentation, internal tooling etc). Now this user will want to opt-out of encapsulation. So their workflow is now the following:
Again, it doesn't seem like much, but bear in mind that the opt-out syntax above is a little jarring to the eye. This sort of thing can easily feel like an over-encumbered Node.js organization placing unnecessary ceremony on users due to an inability to get consensus on simple proposals that optimize user experience :P |
Another thing to mention here is that the use case of publishing a dual mode package does imply encapsulation as you're after. To publish a package that has a different main in CommonJS and in ESM one can do: {
"main": "./index-cjs.js",
"exports": "./index-esm.mjs",
} where using So that a very large swath of user workflows will be pushed into encapsulation here anyway. |
(the rule being |
Agreed that "exports" does the job. That was not my concern. It seems like the core argument is that "mode" is a toggle to cater for users that (a) don't use mjs, and (b) don't understand or like "exports", and (c) don't want encapsulation. It feels odd to create a highly visible feature targeting just this set of users. It's like using an extreme court case to determine the law. It may get overused. |
I think they should be separate. Especially because I want to see |
If
My argument above is that, whilst this syntax is possible, the set of people who want this use-case is very small. If you think of encapsulation as the default user desire, it's a hazard for people to accidentally disable encapsulation just by specifying |
I think an appropriate middle ground for this mindset is to have the split options, and ask |
I agree that by slicing and dicing this way, we are indeed making the mode switch more orthogonal to the other concerns, such as defining explicit ESM package entrypoints and encouraging encapsulation of packages. This proposal permits reuse of the existing CJS "main" field to now refer to ESM-mode files.
In my opinion, this undermines the clarity and integrity of the existing "main" field. The user-facing story for migration to ESM is already quite complicated. I'd suggest we don't confuse the "main" field by making it conditionally serve a second purpose based on the value of another field ("mode"). Over time, this allows "main" to be left behind as a compatibility-only feature for CJS consumers, with "exports" serving as the unambiguous preferred field to use.
A secondary reason for not introducing "mode" is that by guiding users towards "exports" we also facilitate encapsulation. This is healthy for promoting an ecosystem where packages can evolve over time without breaking their dependents.
The text was updated successfully, but these errors were encountered: