@npmcli/arborist 4.0.2 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/shrinkwrap.js +23 -12
  2. package/package.json +5 -6
package/lib/shrinkwrap.js CHANGED
@@ -238,21 +238,31 @@ class Shrinkwrap {
238
238
  return swKeyOrder
239
239
  }
240
240
 
241
- static reset (options) {
241
+ static async reset (options) {
242
242
  // still need to know if it was loaded from the disk, but don't
243
243
  // bother reading it if we're gonna just throw it away.
244
244
  const s = new Shrinkwrap(options)
245
245
  s.reset()
246
246
 
247
- return s[_maybeStat]().then(([sw, lock]) => {
248
- s.filename = resolve(s.path,
249
- (s.hiddenLockfile ? 'node_modules/.package-lock'
250
- : s.shrinkwrapOnly || sw ? 'npm-shrinkwrap'
251
- : 'package-lock') + '.json')
252
- s.loadedFromDisk = !!(sw || lock)
253
- s.type = basename(s.filename)
254
- return s
255
- })
247
+ const [sw, lock] = await s[_maybeStat]()
248
+
249
+ s.filename = resolve(s.path,
250
+ (s.hiddenLockfile ? 'node_modules/.package-lock'
251
+ : s.shrinkwrapOnly || sw ? 'npm-shrinkwrap'
252
+ : 'package-lock') + '.json')
253
+ s.loadedFromDisk = !!(sw || lock)
254
+ s.type = basename(s.filename)
255
+
256
+ try {
257
+ if (s.loadedFromDisk && !s.lockfileVersion) {
258
+ const json = parseJSON(await maybeReadFile(s.filename))
259
+ if (json.lockfileVersion > defaultLockfileVersion) {
260
+ s.lockfileVersion = json.lockfileVersion
261
+ }
262
+ }
263
+ } catch (e) {}
264
+
265
+ return s
256
266
  }
257
267
 
258
268
  static metaFromNode (node, path) {
@@ -380,9 +390,10 @@ class Shrinkwrap {
380
390
  reset () {
381
391
  this.tree = null
382
392
  this[_awaitingUpdate] = new Map()
383
- this.originalLockfileVersion = this.lockfileVersion
393
+ const lockfileVersion = this.lockfileVersion || defaultLockfileVersion
394
+ this.originalLockfileVersion = lockfileVersion
384
395
  this.data = {
385
- lockfileVersion: this.lockfileVersion || defaultLockfileVersion,
396
+ lockfileVersion,
386
397
  requires: true,
387
398
  packages: {},
388
399
  dependencies: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/arborist",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Manage node_modules trees",
5
5
  "dependencies": {
6
6
  "@isaacs/string-locale-compare": "^1.0.1",
@@ -45,11 +45,10 @@
45
45
  "tcompare": "^5.0.6"
46
46
  },
47
47
  "scripts": {
48
- "test": "npm run test-only --",
49
- "test-only": "tap",
50
- "posttest": "npm run lint --",
48
+ "test": "tap",
49
+ "posttest": "npm run lint",
51
50
  "snap": "tap",
52
- "postsnap": "npm run lintfix --",
51
+ "postsnap": "npm run lintfix",
53
52
  "test-proxy": "ARBORIST_TEST_PROXY=1 tap --snapshot",
54
53
  "preversion": "npm test",
55
54
  "postversion": "npm publish",
@@ -88,7 +87,7 @@
88
87
  "--no-warnings",
89
88
  "--no-deprecation"
90
89
  ],
91
- "timeout": "240"
90
+ "timeout": "360"
92
91
  },
93
92
  "engines": {
94
93
  "node": "^12.13.0 || ^14.15.0 || >=16"