-
Notifications
You must be signed in to change notification settings - Fork 44
Index field proposal discussion #422
Comments
I’m surprised to see a PR for an undiscussed change; reading it I’m still unclear on why this is a good direction. I put a lot of weight on not adding new field names, and adding a third that node looks at seems like a big problem. |
To be clear the feature is not intended to land before the meeting - the PR is exactly for tangible discussion. |
I have a few thoughts on this:
I have some sympathy for the argument that I also don’t think |
Thanks for the considered response here @GeoffreyBooth. You raised the point that if most packages only have one specifier then index makes sense. To try clarify this I performed the following analysis:
That is, we can reliably say for this ~1500 package dataset, that less than 10% of packages are using subpath requires. |
(no I did not put that together in an hour... it just so happened I was working on the same problem analysis problems today anyway :P) |
This doesn't include any consumption by apps, or projects not published to npm or github - and the usage of "exports" means that multiple entry points will likely be explicitly requested more often, as users lose the ability to implicitly access them when authors add the mechanism to their packages. I don't think we should be basing this on how many people use deep entry points as much as based on whether we're trying to push "one entry point" onto the ecosystem - and I don't know why we'd want to do that. |
@ljharb the observation here is simply that over 90% of packages only expose a main entry point to consumers. The analysis covers many uses of require of each package - the analysis is not of the top 100 packages, it is of the 1400 dependencies and the ways they are loaded within the graph of the top 100 packages, which means every analysis is based on many usages to get to these numbers. |
I have no data to back this up, but my anecdotal experience is that most packages probably only expect users to use a root export. Packages where deep imports are documented and encouraged, like This might change with the existence of |
@guybedford that's not "only expose", that's "90% of packages are only consumed via a main entry point by other public packages". Every package exposes the same number of entry points as "files in the package". |
@ljharb If you had the choice, which one would you prefer:
Afaict those are the general options. |
5 would be the worst. I’m not sure why we’d be limited to a single conditional export, but if you mean in the case where there’s only the conceptual “main” and no additional entry points, I’d prefer 2, the current feature as i understand it. 3 is confusing since relative references should start with . always (unlike main/bin, and it’s confusing that main/bin alone works that way). I don’t understand why it would be useful to require array notation for any use case that doesn’t involve fallbacks, eg, 4. The proposal here is to change from 2 to 1, and i don’t think that it’s a good thing to:
|
I think what @jkrems meant was “for packages that want to provide only a single conditional export,” i.e. most packages today. They wouldn’t be limited to it, it’s just package author’s default design pattern (at least for now). |
Thanks for clarifying. To me, I think that adding "index" encourages people to be unaware that multiple entry points are possible, and that's not the mental model we should be encouraging. |
I've updated the conditional exports proposal as described in nodejs/node#29978 (comment), based on feedback from this proposal. |
The conditional exports sugar as discussed for this proposal was implemented into the conditional exports PR which landed on master. A new error is thrown for ambiguous exports objects that have both dot and non-dot-starting properties. Please do try it out! |
Creating this issue to discuss the index field PR created at nodejs/node#30239, as an alternative to the exports main sugar to support conditional exports.
See the PR there for further details. Marking modules agenda for Wednesday.
The text was updated successfully, but these errors were encountered: