Skip to content

Commit 8769263

Browse files
committed
feat: use v3 lockfiles by default
1 parent bc21552 commit 8769263

File tree

19 files changed

+235
-5071
lines changed

19 files changed

+235
-5071
lines changed

docs/content/using-npm/config.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,8 @@ instead of the current working directory. See
10271027

10281028
#### `lockfile-version`
10291029

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

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

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

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

lib/utils/config/definitions.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,9 +1201,8 @@ define('lockfile-version', {
12011201
default: null,
12021202
type: [null, 1, 2, 3, '1', '2', '3'],
12031203
defaultDescription: `
1204-
Version 2 if no lockfile or current lockfile version less than or equal to
1205-
2, otherwise maintain current lockfile version
1206-
`,
1204+
Version 3 if no lockfile, auto-converting v1 lockfiles to v3, otherwise
1205+
maintain current lockfile version.`,
12071206
description: `
12081207
Set the lockfile format version to be used in package-lock.json and
12091208
npm-shrinkwrap-json files. Possible options are:
@@ -1213,8 +1212,8 @@ define('lockfile-version', {
12131212
deterministic installs. Prevents lockfile churn when interoperating with
12141213
older npm versions.
12151214
1216-
2: The default lockfile version used by npm version 7. Includes both the
1217-
version 1 lockfile data and version 3 lockfile data, for maximum
1215+
2: The default lockfile version used by npm version 7 and 8. Includes both
1216+
the version 1 lockfile data and version 3 lockfile data, for maximum
12181217
determinism and interoperability, at the expense of more bytes on disk.
12191218
12201219
3: Only the new lockfile information introduced in npm version 7. Smaller

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

Lines changed: 4 additions & 44 deletions
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

Lines changed: 1 addition & 6 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 2 additions & 18 deletions
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

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

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

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

test/lib/commands/shrinkwrap.js

Lines changed: 6 additions & 6 deletions
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

Lines changed: 4 additions & 3 deletions
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
}

0 commit comments

Comments
 (0)