Repository navigation
feat: sort dependencies with npm algorithm, sort npm Overrides key - #358
Conversation
| { key: 'resolutions', over: sortObject }, | ||
| { key: 'dependencies', over: sortObject }, | ||
| { key: 'devDependencies', over: sortObject }, | ||
| { key: 'overrides', over: sortDependenciesLikeNpm }, |
There was a problem hiding this comment.
also introduces sorting for the 'overrides' key for npm Overrides
|
This looks good to me, though you should update/add some tests ideally and also flagging I personally would prefer if this tried to check what package manager was being used since I think that'll be very cheap and the dependency objects are the only ones package managers actually sort themselves. I'm happy to add that myself as a follow-up but want to mention it here all the same to confirm people are agreeable to that |
Good idea, I'll take a look at this.
Hmm... although I can follow the idea behind it, I think I would have reservations with that:
|
NPM isn't the only package manager though, and it's the only one that does this method of sorting - that frustrates me to no end because it feels like a completely unneeded difference in our ecosystem, but when I tried talking about that with NPM they said they were not going to change back because (ironically) they felt it would be too much churn for NPM v7+ users, and I just don't see it being something that every really changes. I also would love to use the same package manager everywhere, but that too is something I don't think will ever be "solved" as the big four have their own merits and fans meaning you probably shouldn't rule out using a particular one indefinitely - I frequently have to jump between the original three due to my open source work. The reason why I care for it respecting the package manager is that this a tool that often only needs to get run on occasion as the majority of content in Hence my desire to try and be what I consider a little more friendly by doing a couple of cheap attempts to guess what package manager is being used and thus what sort order, such as (fwiw if you do ever want to talk to any of the other package managers about changing their order, feel free to tag me for my vote - I don't actually think they'd be opposed to changing it just requires someone being able to put the time in to get it across the line since it'll be hard to make a high priority) |
|
Hm, ok understood. What do you think about a different way: an option I guess I would prefer an option for disabling the sorting for dependencies altogether over maintaining the current (surprising) sorting behavior anywhere. |
|
Added some simple tests in 3df9260 - added the objects inline because I didn't clone the repo yet, and they're easier to add in the GitHub interface than the Ava snapshots. If the Ava snapshots need to be added, will do that too. |
|
The CLI purposely does not support configuration so that's a no-go |
I see that now, in the no-configuration section in the readme:
However, reading this I also think that introducing any branching in the dep-sorting behavior based on package manager would also be against this same philosophy (because it would be "keys in a different order"). I have no horse in the race here - so I'm happy to go with whatever the maintainer team here decides. But I would suggest getting rid of the current dependencies sorting, because the uppercase-before-lowercase sorting doesn't make sense the way it is currently. @keithamus any opinion here? Options I would suggest:
|
No because the sort would still be predictable and deterministic, like how the sorting of |
keithamus
left a comment
There was a problem hiding this comment.
Great work! Let’s merge this as is, and we can iterate further if people consider this change too problematic.
I’d like to avoid too many heuristics as with too many in place it can lead to a “sense” of indeterminism.
|
🎉 This PR is included in version 3.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #234
Closes #355
Closes #267
As per @keithamus' comment in #355, sorting via the npm CLI's algorithm would resolve #234 and #355
'overrides'key for npm Overridesoverrides,dependencies,devDependencies,peerDependencies,optionalDependencieswith npm algorithmNot sure if this is the preferred way of adding this change - happy to continue this to make this ready to accept