mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
Improve lockfile formatting (#3234)
* feat: change order of keys in lockfile * feat(lockfile): write os, engines, and cpu to single line
This commit is contained in:
5
.changeset/great-snails-fry.md
Normal file
5
.changeset/great-snails-fry.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/lockfile-file": patch
|
||||
---
|
||||
|
||||
Change order of keys in package snapshot.
|
||||
5
.changeset/thin-badgers-perform.md
Normal file
5
.changeset/thin-badgers-perform.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/lockfile-file": patch
|
||||
---
|
||||
|
||||
Write engines, os, and cpu to single line.
|
||||
@@ -61,7 +61,7 @@
|
||||
"http-errors": "^1.7.3",
|
||||
"table@^6.0.3": "6.0.4",
|
||||
"graceful-fs": "4.2.4",
|
||||
"js-yaml@^4.0.0": "npm:@zkochan/js-yaml@0.0.2"
|
||||
"js-yaml@^4.0.0": "npm:@zkochan/js-yaml@0.0.4"
|
||||
},
|
||||
"neverBuiltDependencies": [
|
||||
"core-js",
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
"@pnpm/merge-lockfile-changes": "workspace:1.0.1",
|
||||
"@pnpm/types": "workspace:6.4.0",
|
||||
"@zkochan/rimraf": "^1.0.0",
|
||||
"js-yaml": "npm:@zkochan/js-yaml@0.0.2",
|
||||
"js-yaml": "npm:@zkochan/js-yaml@0.0.4",
|
||||
"normalize-path": "^3.0.0",
|
||||
"ramda": "^0.27.1",
|
||||
"sort-keys": "^4.2.0",
|
||||
|
||||
@@ -63,12 +63,22 @@ async function writeLockfile (
|
||||
return writeFileAtomic(lockfilePath, yamlDoc)
|
||||
}
|
||||
|
||||
const ORDERED_KEYS = {
|
||||
resolution: 1,
|
||||
engines: 2,
|
||||
os: 3,
|
||||
cpu: 4,
|
||||
}
|
||||
|
||||
function yamlStringify (lockfile: Lockfile, forceSharedFormat: boolean) {
|
||||
let normalizedLockfile = normalizeLockfile(lockfile, forceSharedFormat)
|
||||
normalizedLockfile = sortKeys(normalizedLockfile, {
|
||||
compare: (left, right) => {
|
||||
if (left === 'resolution') return -1
|
||||
if (right === 'resolution') return 1
|
||||
const leftPriority = ORDERED_KEYS[left]
|
||||
const rightPriority = ORDERED_KEYS[right]
|
||||
if (leftPriority && rightPriority) return leftPriority - rightPriority
|
||||
if (leftPriority) return -1
|
||||
if (rightPriority) return 1
|
||||
return left.localeCompare(right)
|
||||
},
|
||||
deep: true,
|
||||
|
||||
@@ -11,6 +11,9 @@ packages:
|
||||
|
||||
/is-negative/1.0.0:
|
||||
resolution: {integrity: sha1-ChbBDewTLAqLCzb793Fo5VDvg/g=}
|
||||
engines: {node: '>=10'}
|
||||
os: [darwin]
|
||||
cpu: [x86]
|
||||
dependencies:
|
||||
is-positive: 2.0.0
|
||||
|
||||
|
||||
@@ -27,9 +27,14 @@ test('writeLockfiles()', async () => {
|
||||
lockfileVersion: LOCKFILE_VERSION,
|
||||
packages: {
|
||||
'/is-negative/1.0.0': {
|
||||
os: ['darwin'],
|
||||
dependencies: {
|
||||
'is-positive': '2.0.0',
|
||||
},
|
||||
cpu: ['x86'],
|
||||
engines: {
|
||||
node: '>=10',
|
||||
},
|
||||
resolution: {
|
||||
integrity: 'sha1-ChbBDewTLAqLCzb793Fo5VDvg/g=',
|
||||
},
|
||||
|
||||
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
@@ -983,7 +983,7 @@ importers:
|
||||
'@pnpm/merge-lockfile-changes': link:../merge-lockfile-changes
|
||||
'@pnpm/types': link:../types
|
||||
'@zkochan/rimraf': 1.0.0
|
||||
js-yaml: /@zkochan/js-yaml/0.0.2
|
||||
js-yaml: /@zkochan/js-yaml/0.0.4
|
||||
normalize-path: 3.0.0
|
||||
ramda: 0.27.1
|
||||
sort-keys: 4.2.0
|
||||
@@ -1012,7 +1012,7 @@ importers:
|
||||
'@types/ramda': ^0.27.35
|
||||
'@types/write-file-atomic': ^3.0.1
|
||||
'@zkochan/rimraf': ^1.0.0
|
||||
js-yaml: npm:@zkochan/js-yaml@0.0.2
|
||||
js-yaml: npm:@zkochan/js-yaml@0.0.4
|
||||
normalize-path: ^3.0.0
|
||||
ramda: ^0.27.1
|
||||
sort-keys: ^4.2.0
|
||||
@@ -3155,7 +3155,7 @@ overrides:
|
||||
graceful-fs: 4.2.4
|
||||
http-errors: ^1.7.3
|
||||
istanbul-reports: npm:@zkochan/istanbul-reports
|
||||
js-yaml@^4.0.0: npm:@zkochan/js-yaml@0.0.2
|
||||
js-yaml@^4.0.0: npm:@zkochan/js-yaml@0.0.4
|
||||
table@^6.0.3: 6.0.4
|
||||
|
||||
packages:
|
||||
@@ -5036,8 +5036,8 @@ packages:
|
||||
engines:
|
||||
node: '>=8'
|
||||
|
||||
/@zkochan/js-yaml/0.0.2:
|
||||
resolution: {integrity: sha512-rKya/3lsmDGQ/RJgaEZsfgVsD4zLfFqon/NXoejW1OhDSp5I+RU7sHbdj7VF8BZ+PIlTKuUUpYGXC6yQJx/PvQ==}
|
||||
/@zkochan/js-yaml/0.0.4:
|
||||
resolution: {integrity: sha512-2QAnTstlkKBF9fjjDE9geNQKCBIGqXsm+aZrbsbH0tXgj5k2eE0gDFZK1kx2KBRk+XvivuzypRupdGyP2xSliQ==}
|
||||
dependencies:
|
||||
argparse: 2.0.1
|
||||
hasBin: true
|
||||
@@ -12603,7 +12603,7 @@ packages:
|
||||
/read-yaml-file/2.1.0:
|
||||
resolution: {integrity: sha512-UkRNRIwnhG+y7hpqnycCL/xbTk7+ia9VuVTC0S+zVbwd65DI9eUpRMfsWIGrCWxTU/mi+JW8cHQCrv+zfCbEPQ==}
|
||||
dependencies:
|
||||
js-yaml: /@zkochan/js-yaml/0.0.2
|
||||
js-yaml: /@zkochan/js-yaml/0.0.4
|
||||
strip-bom: 4.0.0
|
||||
engines:
|
||||
node: '>=10.13'
|
||||
@@ -15043,7 +15043,7 @@ packages:
|
||||
/write-yaml-file/4.2.0:
|
||||
resolution: {integrity: sha512-LwyucHy0uhWqbrOkh9cBluZBeNVxzHjDaE9mwepZG3n3ZlbM4v3ndrFw51zW/NXYFFqP+QWZ72ihtLWTh05e4Q==}
|
||||
dependencies:
|
||||
js-yaml: /@zkochan/js-yaml/0.0.2
|
||||
js-yaml: /@zkochan/js-yaml/0.0.4
|
||||
write-file-atomic: 3.0.3
|
||||
engines:
|
||||
node: '>=10.13'
|
||||
|
||||
Reference in New Issue
Block a user