Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit b6d5549

Browse files
LotharSeezkat
authored andcommitted
pkglock: Make package-lock.json sorting locale-agnostic (#17844)
Fixes: #17048 PR-URL: #17844 Credit: @LotharSee Reviewed-By: @zkat
1 parent 3aee598 commit b6d5549

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

lib/shrinkwrap.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function shrinkwrapDeps (deps, top, tree, seen) {
101101
if (!seen) seen = new Set()
102102
if (seen.has(tree)) return
103103
seen.add(tree)
104-
tree.children.sort(function (aa, bb) { return moduleName(aa).localeCompare(moduleName(bb)) }).forEach(function (child) {
104+
sortModules(tree.children).forEach(function (child) {
105105
if (child.fakeChild) {
106106
deps[moduleName(child)] = child.fakeChild
107107
return
@@ -130,7 +130,7 @@ function shrinkwrapDeps (deps, top, tree, seen) {
130130
if (isOnlyOptional(child)) pkginfo.optional = true
131131
if (child.requires.length) {
132132
pkginfo.requires = {}
133-
child.requires.sort((a, b) => moduleName(a).localeCompare(moduleName(b))).forEach((required) => {
133+
sortModules(child.requires).forEach((required) => {
134134
var requested = required.package._requested || getRequested(required) || {}
135135
pkginfo.requires[moduleName(required)] = childVersion(top, required, requested)
136136
})
@@ -142,6 +142,14 @@ function shrinkwrapDeps (deps, top, tree, seen) {
142142
})
143143
}
144144

145+
function sortModules (modules) {
146+
// sort modules with the locale-agnostic Unicode sort
147+
var sortedModuleNames = modules.map(moduleName).sort()
148+
return modules.sort((a, b) => (
149+
sortedModuleNames.indexOf(moduleName(a)) - sortedModuleNames.indexOf(moduleName(b))
150+
))
151+
}
152+
145153
function childVersion (top, child, req) {
146154
if (req.type === 'directory' || req.type === 'file') {
147155
return 'file:' + unixFormatPath(path.relative(top.path, child.package._resolved || req.fetchSpec))

0 commit comments

Comments
 (0)