-
Notifications
You must be signed in to change notification settings - Fork 98
Description
NPM v7 changed the way dependencies are sorted very slightly which means this:
{
"name": "spj-te",
"dependencies": {
"sort-package-json": "^1.52.0"
},
"devDependencies": {
"@types/koa-bodyparser": "^4.3.3",
"@types/koa__router": "^8.0.8"
}
}
becomes this:
{
"name": "spj-te",
"dependencies": {
"sort-package-json": "^1.52.0"
},
"devDependencies": {
"@types/koa__router": "^8.0.8",
"@types/koa-bodyparser": "^4.3.3"
}
}
The specific change they made was to use localeCompare
, which technically the better way for sorting strings than just calling sort
but means npm v7 & above sort differently compared to both sort-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 use localeCompare
by trying to read package-lock.json
and checking if the lockfileVersion
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.