mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
feat(lockfile): resolution should be the first key (#3194)
This commit is contained in:
5
.changeset/famous-tigers-rhyme.md
Normal file
5
.changeset/famous-tigers-rhyme.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/lockfile-file": minor
|
||||
---
|
||||
|
||||
The "resolution" field should always be the first key. This will reduce the number of issues during lockfile merges.
|
||||
@@ -53,6 +53,7 @@
|
||||
"js-yaml": "^4.0.0",
|
||||
"normalize-path": "^3.0.0",
|
||||
"ramda": "^0.27.1",
|
||||
"sort-keys": "^4.2.0",
|
||||
"strip-bom": "^4.0.0",
|
||||
"write-file-atomic": "^3.0.3"
|
||||
},
|
||||
|
||||
@@ -6,6 +6,7 @@ import { WANTED_LOCKFILE } from '@pnpm/constants'
|
||||
import rimraf from '@zkochan/rimraf'
|
||||
import yaml from 'js-yaml'
|
||||
import * as R from 'ramda'
|
||||
import sortKeys from 'sort-keys'
|
||||
import writeFileAtomicCB from 'write-file-atomic'
|
||||
import logger from './logger'
|
||||
|
||||
@@ -17,7 +18,7 @@ const LOCKFILE_YAML_FORMAT = {
|
||||
lineWidth: 1000,
|
||||
noCompatMode: true,
|
||||
noRefs: true,
|
||||
sortKeys: true,
|
||||
sortKeys: false,
|
||||
}
|
||||
|
||||
export async function writeWantedLockfile (
|
||||
@@ -62,7 +63,15 @@ async function writeLockfile (
|
||||
}
|
||||
|
||||
function yamlStringify (lockfile: Lockfile, forceSharedFormat: boolean) {
|
||||
const normalizedLockfile = normalizeLockfile(lockfile, forceSharedFormat)
|
||||
let normalizedLockfile = normalizeLockfile(lockfile, forceSharedFormat)
|
||||
normalizedLockfile = sortKeys(normalizedLockfile, {
|
||||
compare: (left, right) => {
|
||||
if (left === 'resolution') return -1
|
||||
if (right === 'resolution') return 1
|
||||
return left.localeCompare(right)
|
||||
},
|
||||
deep: true,
|
||||
})
|
||||
return yaml.dump(normalizedLockfile, LOCKFILE_YAML_FORMAT)
|
||||
}
|
||||
|
||||
|
||||
24
packages/lockfile-file/test/__snapshots__/write.ts.snap
Normal file
24
packages/lockfile-file/test/__snapshots__/write.ts.snap
Normal file
@@ -0,0 +1,24 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`writeLockfiles() 1`] = `
|
||||
"dependencies:
|
||||
is-negative: 1.0.0
|
||||
is-positive: 1.0.0
|
||||
lockfileVersion: 5.2
|
||||
packages:
|
||||
/is-negative/1.0.0:
|
||||
resolution:
|
||||
integrity: sha1-ChbBDewTLAqLCzb793Fo5VDvg/g=
|
||||
dependencies:
|
||||
is-positive: 2.0.0
|
||||
/is-positive/1.0.0:
|
||||
resolution:
|
||||
integrity: sha1-ChbBDewTLAqLCzb793Fo5VDvg/g=
|
||||
/is-positive/2.0.0:
|
||||
resolution:
|
||||
integrity: sha1-ChbBDewTLAqLCzb793Fo5VDvg/g=
|
||||
specifiers:
|
||||
is-negative: ^1.0.0
|
||||
is-positive: ^1.0.0
|
||||
"
|
||||
`;
|
||||
@@ -54,6 +54,9 @@ test('writeLockfiles()', async () => {
|
||||
})
|
||||
expect(await readCurrentLockfile(projectPath, { ignoreIncompatible: false })).toEqual(wantedLockfile)
|
||||
expect(await readWantedLockfile(projectPath, { ignoreIncompatible: false })).toEqual(wantedLockfile)
|
||||
|
||||
// Verifying the formatting of the lockfile
|
||||
expect(fs.readFileSync(path.join(projectPath, WANTED_LOCKFILE), 'utf8')).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('writeLockfiles() when no specifiers but dependencies present', async () => {
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
"json5": "^2.1.3",
|
||||
"parse-json": "^5.1.0",
|
||||
"read-yaml-file": "^2.1.0",
|
||||
"sort-keys": "^4.1.0",
|
||||
"sort-keys": "^4.2.0",
|
||||
"strip-bom": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
4
pnpm-lock.yaml
generated
4
pnpm-lock.yaml
generated
@@ -945,6 +945,7 @@ importers:
|
||||
js-yaml: 4.0.0
|
||||
normalize-path: 3.0.0
|
||||
ramda: 0.27.1
|
||||
sort-keys: 4.2.0
|
||||
strip-bom: 4.0.0
|
||||
write-file-atomic: 3.0.3
|
||||
devDependencies:
|
||||
@@ -973,6 +974,7 @@ importers:
|
||||
js-yaml: ^4.0.0
|
||||
normalize-path: ^3.0.0
|
||||
ramda: ^0.27.1
|
||||
sort-keys: ^4.2.0
|
||||
strip-bom: ^4.0.0
|
||||
tempy: ^1.0.0
|
||||
write-file-atomic: ^3.0.3
|
||||
@@ -2440,7 +2442,7 @@ importers:
|
||||
json5: ^2.1.3
|
||||
parse-json: ^5.1.0
|
||||
read-yaml-file: ^2.1.0
|
||||
sort-keys: ^4.1.0
|
||||
sort-keys: ^4.2.0
|
||||
strip-bom: ^4.0.0
|
||||
tempy: ^1.0.0
|
||||
packages/read-projects-context:
|
||||
|
||||
Reference in New Issue
Block a user