@npmcli/arborist 6.0.0-pre.2 → 6.0.0-pre.4

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.
@@ -330,8 +330,7 @@ Try using the package name instead, e.g:
330
330
  if (tree.children.size) {
331
331
  root.meta.loadedFromDisk = true
332
332
  // 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
335
334
  }
336
335
  }
337
336
  root.meta.inferFormattingOptions(root.package)
@@ -758,7 +757,9 @@ This is a one-time fix-up, please be patient...
758
757
  // yes, yes, this isn't the "original" version, but now that it's been
759
758
  // upgraded, we need to make sure we don't do the work to upgrade it
760
759
  // 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
+ }
762
763
  this.finishTracker('idealTree:inflate')
763
764
  process.emit('timeEnd', 'idealTree:inflate')
764
765
  }
@@ -833,6 +834,7 @@ This is a one-time fix-up, please be patient...
833
834
  await cacache.tmp.withTmp(this.cache, opt, async path => {
834
835
  await pacote.extract(node.resolved, path, {
835
836
  ...opt,
837
+ Arborist,
836
838
  resolved: node.resolved,
837
839
  integrity: node.integrity,
838
840
  })
@@ -35,6 +35,9 @@ const optionalSet = require('../optional-set.js')
35
35
  const calcDepFlags = require('../calc-dep-flags.js')
36
36
  const { saveTypeMap, hasSubKey } = require('../add-rm-pkg-deps.js')
37
37
 
38
+ const Shrinkwrap = require('../shrinkwrap.js')
39
+ const { defaultLockfileVersion } = Shrinkwrap
40
+
38
41
  const _retiredPaths = Symbol('retiredPaths')
39
42
  const _retiredUnchanged = Symbol('retiredUnchanged')
40
43
  const _sparseTreeDirs = Symbol('sparseTreeDirs')
@@ -676,6 +679,7 @@ module.exports = cls => class Reifier extends cls {
676
679
  })
677
680
  await pacote.extract(res, node.path, {
678
681
  ...this.options,
682
+ Arborist: this.constructor,
679
683
  resolved: node.resolved,
680
684
  integrity: node.integrity,
681
685
  })
@@ -1513,11 +1517,16 @@ module.exports = cls => class Reifier extends cls {
1513
1517
  this.idealTree.meta.filename =
1514
1518
  this.idealTree.realpath + '/node_modules/.package-lock.json'
1515
1519
  this.idealTree.meta.hiddenLockfile = true
1520
+ const resetMeta = this.idealTree.meta && this.idealTree.meta.lockfileVersion !== defaultLockfileVersion
1521
+ this.idealTree.meta.lockfileVersion = defaultLockfileVersion
1516
1522
 
1517
1523
  this.actualTree = this.idealTree
1518
1524
  this.idealTree = null
1519
1525
 
1520
1526
  if (!this[_global]) {
1527
+ if (resetMeta) {
1528
+ await this.actualTree.meta.reset()
1529
+ }
1521
1530
  await this.actualTree.meta.save()
1522
1531
  const ignoreScripts = !!this.options.ignoreScripts
1523
1532
  // if we aren't doing a dry run or ignoring scripts and we actually made changes to the dep
package/lib/shrinkwrap.js CHANGED
@@ -10,7 +10,7 @@
10
10
  // definitely not before npm v8.
11
11
 
12
12
  const localeCompare = require('@isaacs/string-locale-compare')('en')
13
- const defaultLockfileVersion = 2
13
+ const defaultLockfileVersion = 3
14
14
 
15
15
  // for comparing nodes to yarn.lock entries
16
16
  const mismatch = (a, b) => a && b && a !== b
@@ -60,7 +60,7 @@ const readdir = async (path, opt) => {
60
60
  return ents
61
61
  }
62
62
 
63
- const { resolve, basename } = require('path')
63
+ const { resolve, basename, relative } = require('path')
64
64
  const specFromLock = require('./spec-from-lock.js')
65
65
  const versionFromTgz = require('./version-from-tgz.js')
66
66
  const npa = require('npm-package-arg')
@@ -224,6 +224,7 @@ const _buildLegacyLockfile = Symbol('_buildLegacyLockfile')
224
224
  const _filenameSet = Symbol('_filenameSet')
225
225
  const _maybeRead = Symbol('_maybeRead')
226
226
  const _maybeStat = Symbol('_maybeStat')
227
+
227
228
  class Shrinkwrap {
228
229
  static get defaultLockfileVersion () {
229
230
  return defaultLockfileVersion
@@ -252,17 +253,6 @@ class Shrinkwrap {
252
253
  s.loadedFromDisk = !!(sw || lock)
253
254
  s.type = basename(s.filename)
254
255
 
255
- try {
256
- if (s.loadedFromDisk && !s.lockfileVersion) {
257
- const json = parseJSON(await maybeReadFile(s.filename))
258
- if (json.lockfileVersion > defaultLockfileVersion) {
259
- s.lockfileVersion = json.lockfileVersion
260
- }
261
- }
262
- } catch {
263
- // ignore errors
264
- }
265
-
266
256
  return s
267
257
  }
268
258
 
@@ -342,6 +332,7 @@ class Shrinkwrap {
342
332
  this.lockfileVersion = hiddenLockfile ? 3
343
333
  : lockfileVersion ? parseInt(lockfileVersion, 10)
344
334
  : null
335
+
345
336
  this[_awaitingUpdate] = new Map()
346
337
  this.tree = null
347
338
  this.path = resolve(path || '.')
@@ -398,6 +389,7 @@ class Shrinkwrap {
398
389
  this[_awaitingUpdate] = new Map()
399
390
  const lockfileVersion = this.lockfileVersion || defaultLockfileVersion
400
391
  this.originalLockfileVersion = lockfileVersion
392
+
401
393
  this.data = {
402
394
  lockfileVersion,
403
395
  requires: true,
@@ -496,8 +488,14 @@ class Shrinkwrap {
496
488
  this.ancientLockfile = false
497
489
  return {}
498
490
  }).then(lock => {
499
- const lockfileVersion = this.lockfileVersion ? this.lockfileVersion
500
- : Math.max(lock.lockfileVersion || 0, defaultLockfileVersion)
491
+ // auto convert v1 lockfiles to v3
492
+ // leave v2 in place unless configured
493
+ // v3 by default
494
+ const lockfileVersion =
495
+ this.lockfileVersion ? this.lockfileVersion
496
+ : lock.lockfileVersion === 1 ? defaultLockfileVersion
497
+ : lock.lockfileVersion || defaultLockfileVersion
498
+
501
499
  this.data = {
502
500
  ...lock,
503
501
  lockfileVersion: lockfileVersion,
@@ -507,6 +505,7 @@ class Shrinkwrap {
507
505
  }
508
506
 
509
507
  this.originalLockfileVersion = lock.lockfileVersion
508
+
510
509
  // use default if it wasn't explicitly set, and the current file is
511
510
  // less than our default. otherwise, keep whatever is in the file,
512
511
  // unless we had an explicit setting already.
@@ -1135,7 +1134,17 @@ class Shrinkwrap {
1135
1134
  if (!this.data) {
1136
1135
  throw new Error('run load() before saving data')
1137
1136
  }
1137
+
1138
1138
  const json = this.toString(options)
1139
+ if (
1140
+ !this.hiddenLockfile
1141
+ && this.originalLockfileVersion !== undefined
1142
+ && this.originalLockfileVersion !== this.lockfileVersion
1143
+ ) {
1144
+ log.warn(
1145
+ `Converting lock file (${relative(process.cwd(), this.filename)}) from v${this.originalLockfileVersion} -> v${this.lockfileVersion}`
1146
+ )
1147
+ }
1139
1148
  return Promise.all([
1140
1149
  writeFile(this.filename, json).catch(er => {
1141
1150
  if (this.hiddenLockfile) {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@npmcli/arborist",
3
- "version": "6.0.0-pre.2",
3
+ "version": "6.0.0-pre.4",
4
4
  "description": "Manage node_modules trees",
5
5
  "dependencies": {
6
6
  "@isaacs/string-locale-compare": "^1.1.0",
7
7
  "@npmcli/installed-package-contents": "^1.0.7",
8
8
  "@npmcli/map-workspaces": "^2.0.3",
9
- "@npmcli/metavuln-calculator": "^3.0.1",
9
+ "@npmcli/metavuln-calculator": "^4.0.0",
10
10
  "@npmcli/move-file": "^2.0.0",
11
11
  "@npmcli/name-from-folder": "^1.0.1",
12
12
  "@npmcli/node-gyp": "^2.0.0",
@@ -27,7 +27,7 @@
27
27
  "npm-pick-manifest": "^7.0.2",
28
28
  "npm-registry-fetch": "^13.0.0",
29
29
  "npmlog": "^6.0.2",
30
- "pacote": "^13.6.1",
30
+ "pacote": "^14.0.0",
31
31
  "parse-conflict-json": "^2.0.1",
32
32
  "proc-log": "^2.0.0",
33
33
  "promise-all-reject-late": "^1.0.0",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@npmcli/eslint-config": "^3.1.0",
45
- "@npmcli/template-oss": "4.4.1",
45
+ "@npmcli/template-oss": "4.5.0",
46
46
  "benchmark": "^2.1.4",
47
47
  "chalk": "^4.1.0",
48
48
  "minify-registry-metadata": "^2.1.0",
@@ -104,7 +104,7 @@
104
104
  },
105
105
  "templateOSS": {
106
106
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
107
- "version": "4.4.1",
107
+ "version": "4.5.0",
108
108
  "content": "../../scripts/template-oss/index.js"
109
109
  }
110
110
  }