diff --git a/lockfile/lockfile-file/src/sortLockfileKeys.ts b/lockfile/lockfile-file/src/sortLockfileKeys.ts index 535054c637..9afd634170 100644 --- a/lockfile/lockfile-file/src/sortLockfileKeys.ts +++ b/lockfile/lockfile-file/src/sortLockfileKeys.ts @@ -1,6 +1,6 @@ import { lexCompare } from '@pnpm/util.lex-comparator' import sortKeys from 'sort-keys' -import { type LockfileFile } from '@pnpm/lockfile-types' +import { type LockfileFileV7, type LockfileFile } from '@pnpm/lockfile-types' const ORDERED_KEYS = { resolution: 1, @@ -57,7 +57,7 @@ function compareWithPriority (priority: Record, left: string, ri return lexCompare(left, right) } -export function sortLockfileKeys (lockfile: LockfileFile) { +export function sortLockfileKeys (lockfile: LockfileFileV7) { const compareRootKeys = compareWithPriority.bind(null, ROOT_KEYS_ORDER) if (lockfile.importers != null) { lockfile.importers = sortKeys(lockfile.importers) @@ -77,6 +77,15 @@ export function sortLockfileKeys (lockfile: LockfileFile) { }) } } + if (lockfile.snapshots != null) { + lockfile.snapshots = sortKeys(lockfile.snapshots) + for (const [pkgId, pkg] of Object.entries(lockfile.snapshots)) { + lockfile.snapshots[pkgId] = sortKeys(pkg, { + compare: compareWithPriority.bind(null, ORDERED_KEYS), + deep: true, + }) + } + } for (const key of ['dependencies', 'devDependencies', 'optionalDependencies', 'time', 'patchedDependencies'] as const) { if (!lockfile[key]) continue lockfile[key] = sortKeys(lockfile[key]) // eslint-disable-line @typescript-eslint/no-explicit-any