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:
Zoltan Kochan
2021-03-12 02:09:05 +02:00
committed by GitHub
parent 9c41e11b0b
commit 9c2a878c38
8 changed files with 39 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/lockfile-file": patch
---
Change order of keys in package snapshot.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/lockfile-file": patch
---
Write engines, os, and cpu to single line.

View File

@@ -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",

View File

@@ -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",

View File

@@ -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,

View File

@@ -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

View File

@@ -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
View File

@@ -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'