Skip to content

Commit 9609e9e

Browse files
authored
feat: use v3 lockfiles by default (#5605)
1 parent 97c32ed commit 9609e9e

File tree

19 files changed

+235
-5071
lines changed

19 files changed

+235
-5071
lines changed

docs/content/using-npm/config.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1026,8 +1026,8 @@ instead of the current working directory. See
10261026

10271027
#### `lockfile-version`
10281028

1029-
* Default: Version 2 if no lockfile or current lockfile version less than or
1030-
equal to 2, otherwise maintain current lockfile version
1029+
* Default: Version 3 if no lockfile, auto-converting v1 lockfiles to v3,
1030+
otherwise maintain current lockfile version.
10311031
* Type: null, 1, 2, 3, "1", "2", or "3"
10321032

10331033
Set the lockfile format version to be used in package-lock.json and
@@ -1038,9 +1038,9 @@ is used during the install, resulting in slower and possibly less
10381038
deterministic installs. Prevents lockfile churn when interoperating with
10391039
older npm versions.
10401040

1041-
2: The default lockfile version used by npm version 7. Includes both the
1042-
version 1 lockfile data and version 3 lockfile data, for maximum determinism
1043-
and interoperability, at the expense of more bytes on disk.
1041+
2: The default lockfile version used by npm version 7 and 8. Includes both
1042+
the version 1 lockfile data and version 3 lockfile data, for maximum
1043+
determinism and interoperability, at the expense of more bytes on disk.
10441044

10451045
3: Only the new lockfile information introduced in npm version 7. Smaller on
10461046
disk than lockfile version 2, but not interoperable with older npm versions.

lib/utils/config/definitions.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1198,9 +1198,8 @@ define('lockfile-version', {
11981198
default: null,
11991199
type: [null, 1, 2, 3, '1', '2', '3'],
12001200
defaultDescription: `
1201-
Version 2 if no lockfile or current lockfile version less than or equal to
1202-
2, otherwise maintain current lockfile version
1203-
`,
1201+
Version 3 if no lockfile, auto-converting v1 lockfiles to v3, otherwise
1202+
maintain current lockfile version.`,
12041203
description: `
12051204
Set the lockfile format version to be used in package-lock.json and
12061205
npm-shrinkwrap-json files. Possible options are:
@@ -1210,8 +1209,8 @@ define('lockfile-version', {
12101209
deterministic installs. Prevents lockfile churn when interoperating with
12111210
older npm versions.
12121211
1213-
2: The default lockfile version used by npm version 7. Includes both the
1214-
version 1 lockfile data and version 3 lockfile data, for maximum
1212+
2: The default lockfile version used by npm version 7 and 8. Includes both
1213+
the version 1 lockfile data and version 3 lockfile data, for maximum
12151214
determinism and interoperability, at the expense of more bytes on disk.
12161215
12171216
3: Only the new lockfile information introduced in npm version 7. Smaller

smoke-tests/tap-snapshots/test/index.js.test.cjs

+4-44
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ exports[`test/index.js TAP npm install dev dep > should have expected dev dep ad
366366
{
367367
"name": "project",
368368
"version": "1.0.0",
369-
"lockfileVersion": 2,
369+
"lockfileVersion": 3,
370370
"requires": true,
371371
"packages": {
372372
"": {
@@ -394,19 +394,6 @@ exports[`test/index.js TAP npm install dev dep > should have expected dev dep ad
394394
"url": "https://github.com/sponsors/isaacs"
395395
}
396396
}
397-
},
398-
"dependencies": {
399-
"abbrev": {
400-
"version": "1.0.4",
401-
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.0.4.tgz",
402-
"integrity": "sha1-vVWuXkE7oXIu5Mq6H26hBBSlns0="
403-
},
404-
"promise-all-reject-late": {
405-
"version": "1.0.1",
406-
"resolved": "https://registry.npmjs.org/promise-all-reject-late/-/promise-all-reject-late-1.0.1.tgz",
407-
"integrity": "sha512-vuf0Lf0lOxyQREH7GDIOUMLS7kz+gs8i6B+Yi8dC68a2sychGrHTJYghMBD6k7eUcH0H5P73EckCA48xijWqXw==",
408-
"dev": true
409-
}
410397
}
411398
}
412399
@@ -453,7 +440,7 @@ exports[`test/index.js TAP npm install prodDep@version > should have expected lo
453440
{
454441
"name": "project",
455442
"version": "1.0.0",
456-
"lockfileVersion": 2,
443+
"lockfileVersion": 3,
457444
"requires": true,
458445
"packages": {
459446
"": {
@@ -469,13 +456,6 @@ exports[`test/index.js TAP npm install prodDep@version > should have expected lo
469456
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.0.4.tgz",
470457
"integrity": "sha1-vVWuXkE7oXIu5Mq6H26hBBSlns0="
471458
}
472-
},
473-
"dependencies": {
474-
"abbrev": {
475-
"version": "1.0.4",
476-
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.0.4.tgz",
477-
"integrity": "sha1-vVWuXkE7oXIu5Mq6H26hBBSlns0="
478-
}
479459
}
480460
}
481461
@@ -642,7 +622,7 @@ exports[`test/index.js TAP npm uninstall > should have expected uninstall lockfi
642622
{
643623
"name": "project",
644624
"version": "1.0.0",
645-
"lockfileVersion": 2,
625+
"lockfileVersion": 3,
646626
"requires": true,
647627
"packages": {
648628
"": {
@@ -658,13 +638,6 @@ exports[`test/index.js TAP npm uninstall > should have expected uninstall lockfi
658638
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
659639
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
660640
}
661-
},
662-
"dependencies": {
663-
"abbrev": {
664-
"version": "1.1.1",
665-
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
666-
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
667-
}
668641
}
669642
}
670643
@@ -700,7 +673,7 @@ exports[`test/index.js TAP npm update dep > should have expected update lockfile
700673
{
701674
"name": "project",
702675
"version": "1.0.0",
703-
"lockfileVersion": 2,
676+
"lockfileVersion": 3,
704677
"requires": true,
705678
"packages": {
706679
"": {
@@ -728,19 +701,6 @@ exports[`test/index.js TAP npm update dep > should have expected update lockfile
728701
"url": "https://github.com/sponsors/isaacs"
729702
}
730703
}
731-
},
732-
"dependencies": {
733-
"abbrev": {
734-
"version": "1.1.1",
735-
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
736-
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
737-
},
738-
"promise-all-reject-late": {
739-
"version": "1.0.1",
740-
"resolved": "https://registry.npmjs.org/promise-all-reject-late/-/promise-all-reject-late-1.0.1.tgz",
741-
"integrity": "sha512-vuf0Lf0lOxyQREH7GDIOUMLS7kz+gs8i6B+Yi8dC68a2sychGrHTJYghMBD6k7eUcH0H5P73EckCA48xijWqXw==",
742-
"dev": true
743-
}
744704
}
745705
}
746706

tap-snapshots/test/lib/commands/init.js.test.cjs

+1-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Array [
3131
exports[`test/lib/commands/init.js TAP workspaces post workspace-init reify > should reify tree on init ws complete 1`] = `
3232
{
3333
"name": "top-level",
34-
"lockfileVersion": 2,
34+
"lockfileVersion": 3,
3535
"requires": true,
3636
"packages": {
3737
"": {
@@ -49,11 +49,6 @@ exports[`test/lib/commands/init.js TAP workspaces post workspace-init reify > sh
4949
"resolved": "a",
5050
"link": true
5151
}
52-
},
53-
"dependencies": {
54-
"a": {
55-
"version": "file:a"
56-
}
5752
}
5853
}
5954

tap-snapshots/test/lib/commands/shrinkwrap.js.test.cjs

+6-6
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ exports[`test/lib/commands/shrinkwrap.js TAP with nothing ancient > must match s
125125
"config": {},
126126
"shrinkwrap": {
127127
"name": "prefix",
128-
"lockfileVersion": 2,
128+
"lockfileVersion": 3,
129129
"requires": true,
130130
"packages": {}
131131
},
132132
"logs": [
133-
"created a lockfile as npm-shrinkwrap.json with version 2"
133+
"created a lockfile as npm-shrinkwrap.json with version 3"
134134
]
135135
}
136136
`
@@ -163,7 +163,7 @@ exports[`test/lib/commands/shrinkwrap.js TAP with npm-shrinkwrap.json ancient >
163163
"config": {},
164164
"shrinkwrap": {
165165
"name": "prefix",
166-
"lockfileVersion": 2,
166+
"lockfileVersion": 3,
167167
"requires": true,
168168
"packages": {
169169
"": {
@@ -172,7 +172,7 @@ exports[`test/lib/commands/shrinkwrap.js TAP with npm-shrinkwrap.json ancient >
172172
}
173173
},
174174
"logs": [
175-
"npm-shrinkwrap.json updated to version 2"
175+
"npm-shrinkwrap.json updated to version 3"
176176
]
177177
}
178178
`
@@ -284,7 +284,7 @@ exports[`test/lib/commands/shrinkwrap.js TAP with package-lock.json ancient > mu
284284
"config": {},
285285
"shrinkwrap": {
286286
"name": "prefix",
287-
"lockfileVersion": 2,
287+
"lockfileVersion": 3,
288288
"requires": true,
289289
"packages": {
290290
"": {
@@ -293,7 +293,7 @@ exports[`test/lib/commands/shrinkwrap.js TAP with package-lock.json ancient > mu
293293
}
294294
},
295295
"logs": [
296-
"package-lock.json has been renamed to npm-shrinkwrap.json and updated to version 2"
296+
"package-lock.json has been renamed to npm-shrinkwrap.json and updated to version 3"
297297
]
298298
}
299299
`

tap-snapshots/test/lib/commands/version.js.test.cjs

+2-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports[`test/lib/commands/version.js TAP empty versions workspaces with one arg
99
{
1010
"name": "workspaces-test",
1111
"version": "1.0.0",
12-
"lockfileVersion": 2,
12+
"lockfileVersion": 3,
1313
"requires": true,
1414
"packages": {
1515
"": {
@@ -34,14 +34,6 @@ exports[`test/lib/commands/version.js TAP empty versions workspaces with one arg
3434
"workspace-b": {
3535
"version": "2.0.0"
3636
}
37-
},
38-
"dependencies": {
39-
"workspace-a": {
40-
"version": "file:workspace-a"
41-
},
42-
"workspace-b": {
43-
"version": "file:workspace-b"
44-
}
4537
}
4638
}
4739
@@ -51,7 +43,7 @@ exports[`test/lib/commands/version.js TAP empty versions workspaces with one arg
5143
{
5244
"name": "workspaces-test",
5345
"version": "1.0.0",
54-
"lockfileVersion": 2,
46+
"lockfileVersion": 3,
5547
"requires": true,
5648
"packages": {
5749
"": {
@@ -80,14 +72,6 @@ exports[`test/lib/commands/version.js TAP empty versions workspaces with one arg
8072
"workspace-b": {
8173
"version": "2.0.0"
8274
}
83-
},
84-
"dependencies": {
85-
"workspace-a": {
86-
"version": "file:workspace-a"
87-
},
88-
"workspace-b": {
89-
"version": "file:workspace-b"
90-
}
9175
}
9276
}
9377

tap-snapshots/test/lib/utils/config/definitions.js.test.cjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,8 @@ instead of the current working directory. See
10891089
exports[`test/lib/utils/config/definitions.js TAP > config description for lockfile-version 1`] = `
10901090
#### \`lockfile-version\`
10911091
1092-
* Default: Version 2 if no lockfile or current lockfile version less than or
1093-
equal to 2, otherwise maintain current lockfile version
1092+
* Default: Version 3 if no lockfile, auto-converting v1 lockfiles to v3,
1093+
otherwise maintain current lockfile version.
10941094
* Type: null, 1, 2, 3, "1", "2", or "3"
10951095
10961096
Set the lockfile format version to be used in package-lock.json and
@@ -1101,9 +1101,9 @@ is used during the install, resulting in slower and possibly less
11011101
deterministic installs. Prevents lockfile churn when interoperating with
11021102
older npm versions.
11031103
1104-
2: The default lockfile version used by npm version 7. Includes both the
1105-
version 1 lockfile data and version 3 lockfile data, for maximum determinism
1106-
and interoperability, at the expense of more bytes on disk.
1104+
2: The default lockfile version used by npm version 7 and 8. Includes both
1105+
the version 1 lockfile data and version 3 lockfile data, for maximum
1106+
determinism and interoperability, at the expense of more bytes on disk.
11071107
11081108
3: Only the new lockfile information introduced in npm version 7. Smaller on
11091109
disk than lockfile version 2, but not interoperable with older npm versions.

tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ instead of the current working directory. See
899899
900900
#### \`lockfile-version\`
901901
902-
* Default: Version 2 if no lockfile or current lockfile version less than or
903-
equal to 2, otherwise maintain current lockfile version
902+
* Default: Version 3 if no lockfile, auto-converting v1 lockfiles to v3,
903+
otherwise maintain current lockfile version.
904904
* Type: null, 1, 2, 3, "1", "2", or "3"
905905
906906
Set the lockfile format version to be used in package-lock.json and
@@ -911,9 +911,9 @@ is used during the install, resulting in slower and possibly less
911911
deterministic installs. Prevents lockfile churn when interoperating with
912912
older npm versions.
913913
914-
2: The default lockfile version used by npm version 7. Includes both the
915-
version 1 lockfile data and version 3 lockfile data, for maximum determinism
916-
and interoperability, at the expense of more bytes on disk.
914+
2: The default lockfile version used by npm version 7 and 8. Includes both
915+
the version 1 lockfile data and version 3 lockfile data, for maximum
916+
determinism and interoperability, at the expense of more bytes on disk.
917917
918918
3: Only the new lockfile information introduced in npm version 7. Smaller on
919919
disk than lockfile version 2, but not interoperable with older npm versions.

test/lib/commands/shrinkwrap.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ const NOTICES = {
112112
t.test('with nothing', t =>
113113
shrinkwrapMatrix(t, null, {
114114
ancient: {
115-
shrinkwrap: { lockfileVersion: 2 },
116-
logs: NOTICES.CREATED(2),
115+
shrinkwrap: { lockfileVersion: 3 },
116+
logs: NOTICES.CREATED(3),
117117
},
118118
ancientUpgrade: {
119119
shrinkwrap: { lockfileVersion: 3 },
@@ -125,8 +125,8 @@ t.test('with nothing', t =>
125125
t.test('with package-lock.json', t =>
126126
shrinkwrapMatrix(t, 'package-lock', {
127127
ancient: {
128-
shrinkwrap: { lockfileVersion: 2 },
129-
logs: NOTICES.RENAMED(2),
128+
shrinkwrap: { lockfileVersion: 3 },
129+
logs: NOTICES.RENAMED(3),
130130
},
131131
ancientUpgrade: {
132132
shrinkwrap: { lockfileVersion: 3 },
@@ -150,8 +150,8 @@ t.test('with package-lock.json', t =>
150150
t.test('with npm-shrinkwrap.json', t =>
151151
shrinkwrapMatrix(t, 'npm-shrinkwrap', {
152152
ancient: {
153-
shrinkwrap: { lockfileVersion: 2 },
154-
logs: NOTICES.UPDATED(2),
153+
shrinkwrap: { lockfileVersion: 3 },
154+
logs: NOTICES.UPDATED(3),
155155
},
156156
ancientUpgrade: {
157157
shrinkwrap: { lockfileVersion: 3 },

workspaces/arborist/lib/arborist/build-ideal-tree.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ Try using the package name instead, e.g:
330330
if (tree.children.size) {
331331
root.meta.loadedFromDisk = true
332332
// set these so that we don't try to ancient lockfile reload it
333-
root.meta.originalLockfileVersion = defaultLockfileVersion
334-
root.meta.lockfileVersion = defaultLockfileVersion
333+
root.meta.originalLockfileVersion = root.meta.lockfileVersion = this.options.lockfileVersion || defaultLockfileVersion
335334
}
336335
}
337336
root.meta.inferFormattingOptions(root.package)
@@ -758,7 +757,9 @@ This is a one-time fix-up, please be patient...
758757
// yes, yes, this isn't the "original" version, but now that it's been
759758
// upgraded, we need to make sure we don't do the work to upgrade it
760759
// again, since it's now as new as can be.
761-
meta.originalLockfileVersion = defaultLockfileVersion
760+
if (!this.options.lockfileVersion && !meta.hiddenLockfile) {
761+
meta.originalLockfileVersion = defaultLockfileVersion
762+
}
762763
this.finishTracker('idealTree:inflate')
763764
process.emit('timeEnd', 'idealTree:inflate')
764765
}

workspaces/arborist/lib/arborist/reify.js

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const optionalSet = require('../optional-set.js')
3535
const calcDepFlags = require('../calc-dep-flags.js')
3636
const { saveTypeMap, hasSubKey } = require('../add-rm-pkg-deps.js')
3737

38+
const Shrinkwrap = require('../shrinkwrap.js')
39+
const { defaultLockfileVersion } = Shrinkwrap
40+
3841
const _retiredPaths = Symbol('retiredPaths')
3942
const _retiredUnchanged = Symbol('retiredUnchanged')
4043
const _sparseTreeDirs = Symbol('sparseTreeDirs')
@@ -1514,11 +1517,16 @@ module.exports = cls => class Reifier extends cls {
15141517
this.idealTree.meta.filename =
15151518
this.idealTree.realpath + '/node_modules/.package-lock.json'
15161519
this.idealTree.meta.hiddenLockfile = true
1520+
const resetMeta = this.idealTree.meta && this.idealTree.meta.lockfileVersion !== defaultLockfileVersion
1521+
this.idealTree.meta.lockfileVersion = defaultLockfileVersion
15171522

15181523
this.actualTree = this.idealTree
15191524
this.idealTree = null
15201525

15211526
if (!this[_global]) {
1527+
if (resetMeta) {
1528+
await this.actualTree.meta.reset()
1529+
}
15221530
await this.actualTree.meta.save()
15231531
const ignoreScripts = !!this.options.ignoreScripts
15241532
// if we aren't doing a dry run or ignoring scripts and we actually made changes to the dep

0 commit comments

Comments
 (0)