-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat: improve sorting of imports/exports #336
Conversation
Force relative position of certain conditions, sort paths in alphabetically with exception of paths with wildcards.
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.
This seems reasonable to me but I'd like to get reviews from @jlarmstrongiv, @fisker, and @mrmckeb who all commented on the issue and so I imagine have opinions around this change.
Co-authored-by: Keith Cirkel <[email protected]>
Sounds good @keithamus. A question about the commit checks. The tests are failing on Node 12 and 14 because I'm using a relatively modern syntax ( |
They're quite out of date. No one has made a PR to update our supported versions (I don't author code for this repo any more, only steward PRs and releases). So that is to say, PRs welcome to update these! Given the current version supports these older versions, I'd recommend changing this PR to avoid using the new syntax, so that we can release this as a feature release. Beyond that I'd then encourage you or others to make a PR cutting off support for Node.js <20 (given that 18 will be EOL in ~2 months) while also updating our build matrix to include 20, 22, 24 (and maybe |
As I understand, we don't need list all conditions, we only need care about |
We should get current order keys, check the conditions above, and move them to correct position, and sort with the new oredered keys. |
1. types before target environments 2. environments first 3. support module-sync
@fisker That would be a simpler approach but I think the same issue applies to many of the conditions listed here (not all). In addition, I thought it would be a nice stylistic benefit to always group similar conditions (hence the condition groups). But to elaborate on how the same issue applies to other conditions, imagine a scenario like this {
"import": "./index.esm.js",
"require": "./index.cjs",
"node": "./index.node.cjs",
} In this example, the "node" condition has no effect because it is more specific than both "import" and "require" - node will generally use one of those conditions and always ignore the "node" one in this example. |
Additionally fix order of `module-sync` which goes after `require` and `import`
Not true, |
@fisker I've linked the node.js docs multiple times I'm not sure if we are looking at the same information. It says Quote from Node.js docs
The conditions I can give you plenty of other examples of why more of these conditions have to be sorted. For example:
There are SOME conditions that are being sorted that have less consequences if left unsorted, but I think there is value is keeping conditions that are classified similarly close to each other - for example Because these conditions are classified as "reference syntax" conditions, they are likely to suffer from the same issues and require the same treatment as other "reference syntax" conditions (like EDIT: More concrete examples supporting the need to sortExample: Package exposes
|
@fisker First off - thanks for taking the time to review this PR. My impression is that we are not aligned about what this is solving, so I'm summarizing our positions so that we can focus the conversation and move forward. TLDR:
Your position seems to be (correct me if I'm wrong):
To clarify my position: Sorting should follow guidelines of "more specific" to "least specific" with the following goals:
About I am coming around to your original idea to move it above
I hope this helps anchor our conversation. 🙏🏽 |
Adds known edge conditions and addition compilation targets from the WinterCG standard (Called out in the Node.js community conditions documentation. - https://nodejs.org/api/packages.html#community-conditions-definitions
Apply some alphabetical order
Update:
|
Yes, I still believe we should focus on solve problems mentioned in #294 , I don't want this PR break their conditions, and I hope PR as small as possible. Further improvements can be done if someone bring it up later.
For libs, most time there are only the most popular conditions used, I feel unnecessary to care about other conditions. |
The thing about #294 is that it is too narrow. I came to this repo to solve this problem because I maintain a monorepo with 100+ workspaces supporting conditions like I only tagged #294 because it was a related issue, but the issue is too narrow. I imagine that other maintainers of large complex projects with a lot of conditions will encounter the same issues I have and would benefit from this. Also, the rules are very straightforward and widely applicable:
With a few nuanced exceptions like I also believe that there is an unavoidable risk with this change. Even if you limit it to just I appreciate that you are being careful, but if I can't address my issues holistically, then I would prefer to find a solution with another package (my own or |
- move types to top - move browser under deno and bun since those can be used to bundle app for browsers
Update: I spoke with a wise man who clarified that you are likely resistant to the change because it has a large scope and prefer to incorporate the fixes in small increments. If it seems like I'm being stubborn is because I'm looking for validation of my examples and my description of the problems I've encountered. So far, the rejection of the changes have just come off as dismissive to my own problems. I'm okay with breaking up the PR, if we can find an agreement about incorporating all the other known conditions. |
Following up with this - I created a reproduction repo to show that the https://github.com/GeorgeTaveras1231/package-export-condition-errors/tree/main |
Update: I'm working out a proposal to handle this properly. Once I have the details figured out, I will open an issue to discuss it in detail. |
Implement sorting for
import
andexport
fields.Fixes #294
Resources