-
Notifications
You must be signed in to change notification settings - Fork 90
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
Use same sorting logic for sorting dependencies as npm v7 #234
Comments
I'd be quite happy to just unilaterally change to using localeCompare, if that seems like a good change to you? |
@keithamus yup I think in the long-run it makes sense, so if you're happy to start using it now I'll make a PR. |
hmm I've applied this but the output is still not what npm v7 is giving, so will need to look into this further. |
Any update on this? Would be nice to have the dependencies sorted the same order as |
@Nokel81 I've been really on the fence about this because NPM v7+ actually sorts slightly different to all other package managers and they're not going to change that because apparently it'll create too much churn for NPM v7+ users... In my experience I've only ever had this once on a project, with the dependencies mentioned above since it only impacts the sort order of |
I noticed it specifically because of the dash and underscore. Due to I definitely think that fit projects using |
We could also detect what npm version is being used and do the right thing. I'm happy to look over any PR that anyone wants to write on this 😉 |
Actually with |
Or even with |
Okay I can try |
NPM v7 changed the way dependencies are sorted very slightly which means this:
becomes this:
The specific change they made was to use
localeCompare
, which technically the better way for sorting strings than just callingsort
but means npm v7 & above sort differently compared to bothsort-package-json
and the other two main package managers.I opened an issue for discussion about this but it was closed with a comment about the change being intentional: npm/cli#3935
I was thinking that
sort-package-json
could attempt to figure out if it should uselocaleCompare
by trying to readpackage-lock.json
and checking if thelockfileVersion
is greater than 1, otherwise falling back to its current behaviour if its 1 or the lock cannot be read.I'm happy to implement this change.
The text was updated successfully, but these errors were encountered: