fix: sort patchedDependencies consistently in lockfiles (#6208)

This commit is contained in:
David Weitzman
2023-03-11 08:31:55 -08:00
committed by GitHub
parent 955874422c
commit 787c43dcc1
3 changed files with 19 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/lockfile-file": patch
"pnpm": patch
---
`patchedDependencies` are now sorted consistently in the lockfile [#6208](https://github.com/pnpm/pnpm/pull/6208).

View File

@@ -77,9 +77,9 @@ export function sortLockfileKeys (lockfile: LockfileFile) {
})
}
}
for (const key of ['specifiers', 'dependencies', 'devDependencies', 'optionalDependencies', 'time'] as const) {
for (const key of ['specifiers', 'dependencies', 'devDependencies', 'optionalDependencies', 'time', 'patchedDependencies'] as const) {
if (!lockfile[key]) continue
lockfile[key] = sortKeys(lockfile[key]!)
lockfile[key] = sortKeys<any>(lockfile[key]) // eslint-disable-line @typescript-eslint/no-explicit-any
}
return sortKeys(lockfile, { compare: compareRootKeys })
}

View File

@@ -26,6 +26,11 @@ test('sorts keys alphabetically', () => {
},
},
},
patchedDependencies: {
zzz: { path: 'foo', hash: 'bar' },
bar: { path: 'foo', hash: 'bar' },
aaa: { path: 'foo', hash: 'bar' },
},
})
expect(normalizedLockfile).toStrictEqual({
@@ -52,9 +57,15 @@ test('sorts keys alphabetically', () => {
},
},
},
patchedDependencies: {
aaa: { path: 'foo', hash: 'bar' },
bar: { path: 'foo', hash: 'bar' },
zzz: { path: 'foo', hash: 'bar' },
},
})
expect(Object.keys(normalizedLockfile.importers?.foo.dependencies ?? {})).toStrictEqual(['aaa', 'bar', 'zzz'])
expect(Object.keys(normalizedLockfile.importers?.foo.specifiers ?? {})).toStrictEqual(['aaa', 'bar', 'zzz'])
expect(Object.keys(normalizedLockfile.patchedDependencies ?? {})).toStrictEqual(['aaa', 'bar', 'zzz'])
})
test('sorting does not care about locale (e.g. Czech has "ch" as a single character after "h")', () => {