diff options
author | Gar <gar+gh@danger.computer> | 2021-08-12 22:14:41 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-08-12 22:14:41 +0300 |
commit | b88f770faa2651ca0833e1c9eb361e9e07e0bbc3 (patch) | |
tree | c7da25e8c70b1f5222aa35ff9071152c0be24fc8 /node_modules/@npmcli | |
parent | 5bebf280f228e818524f6989caab1cfba1ffaf90 (diff) |
@npmcli/arborist@2.8.1
* [#3632] Fix "cannot read property path of null" error in 'npm
dedupe'
* fix(shrinkwrap): always set name on the root node
Diffstat (limited to 'node_modules/@npmcli')
-rw-r--r-- | node_modules/@npmcli/arborist/bin/dedupe.js | 46 | ||||
-rw-r--r-- | node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js | 11 | ||||
-rw-r--r-- | node_modules/@npmcli/arborist/lib/can-place-dep.js | 19 | ||||
-rw-r--r-- | node_modules/@npmcli/arborist/lib/place-dep.js | 17 | ||||
-rw-r--r-- | node_modules/@npmcli/arborist/lib/shrinkwrap.js | 6 | ||||
-rw-r--r-- | node_modules/@npmcli/arborist/package.json | 2 |
6 files changed, 75 insertions, 26 deletions
diff --git a/node_modules/@npmcli/arborist/bin/dedupe.js b/node_modules/@npmcli/arborist/bin/dedupe.js new file mode 100644 index 000000000..96f754e34 --- /dev/null +++ b/node_modules/@npmcli/arborist/bin/dedupe.js @@ -0,0 +1,46 @@ +const Arborist = require('../') + +const options = require('./lib/options.js') +const print = require('./lib/print-tree.js') +require('./lib/logging.js') +require('./lib/timers.js') + +const printDiff = diff => { + const {depth} = require('treeverse') + depth({ + tree: diff, + visit: d => { + if (d.location === '') + return + switch (d.action) { + case 'REMOVE': + console.error('REMOVE', d.actual.location) + break + case 'ADD': + console.error('ADD', d.ideal.location, d.ideal.resolved) + break + case 'CHANGE': + console.error('CHANGE', d.actual.location, { + from: d.actual.resolved, + to: d.ideal.resolved, + }) + break + } + }, + getChildren: d => d.children, + }) +} + +const start = process.hrtime() +process.emit('time', 'install') +const arb = new Arborist(options) +arb.dedupe(options).then(tree => { + process.emit('timeEnd', 'install') + const end = process.hrtime(start) + print(tree) + if (options.dryRun) + printDiff(arb.diff) + console.error(`resolved ${tree.inventory.size} deps in ${end[0] + end[1] / 1e9}s`) + if (tree.meta && options.save) + tree.meta.save() +}).catch(er => console.error(require('util').inspect(er, { depth: Infinity }))) diff --git a/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js b/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js index 7ef42289d..679d52582 100644 --- a/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js +++ b/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js @@ -982,7 +982,6 @@ This is a one-time fix-up, please be patient... // Note that the virtual root will also have virtual copies of the // targets of any child Links, so that they resolve appropriately. const parent = parent_ || this[_virtualRoot](edge.from) - const realParent = edge.peer ? edge.from.resolveParent : edge.from const spec = npa.resolve(edge.name, edge.spec, edge.from.path) const first = await this[_nodeFromSpec](edge.name, spec, parent, edge) @@ -1013,16 +1012,6 @@ This is a one-time fix-up, please be patient... required.has(secondEdge.from) && secondEdge.type !== 'peerOptional')) required.add(node) - // handle otherwise unresolvable dependency nesting loops by - // creating a symbolic link - // a1 -> b1 -> a2 -> b2 -> a1 -> ... - // instead of nesting forever, when the loop occurs, create - // a symbolic link to the earlier instance - for (let p = edge.from.resolveParent; p; p = p.resolveParent) { - if (p.matches(node) && !p.isTop) - return new Link({ parent: realParent, target: p }) - } - // keep track of the thing that caused this node to be included. const src = parent.sourceReference this[_peerSetSource].set(node, src) diff --git a/node_modules/@npmcli/arborist/lib/can-place-dep.js b/node_modules/@npmcli/arborist/lib/can-place-dep.js index cf6b800c4..9601ad7af 100644 --- a/node_modules/@npmcli/arborist/lib/can-place-dep.js +++ b/node_modules/@npmcli/arborist/lib/can-place-dep.js @@ -73,8 +73,10 @@ class CanPlaceDep { if (!edge) throw new Error('no edge provided to CanPlaceDep') - this._nodeSnapshot = JSON.stringify(dep) - this._treeSnapshot = JSON.stringify(target.root) + this._treeSnapshot = JSON.stringify([...target.root.inventory.entries()] + .map(([loc, {packageName, version, resolved}]) => { + return [loc, packageName, version, resolved] + }).sort(([a], [b]) => a.localeCompare(b, 'en'))) }) // the result of whether we can place it or not @@ -110,15 +112,10 @@ class CanPlaceDep { this.canPlaceSelf = this.canPlace debug(() => { - const nodeSnapshot = JSON.stringify(dep) - const treeSnapshot = JSON.stringify(target.root) - /* istanbul ignore if */ - if (this._nodeSnapshot !== nodeSnapshot) { - throw Object.assign(new Error('dep changed in CanPlaceDep'), { - expect: this._nodeSnapshot, - actual: nodeSnapshot, - }) - } + const treeSnapshot = JSON.stringify([...target.root.inventory.entries()] + .map(([loc, {packageName, version, resolved}]) => { + return [loc, packageName, version, resolved] + }).sort(([a], [b]) => a.localeCompare(b, 'en'))) /* istanbul ignore if */ if (this._treeSnapshot !== treeSnapshot) { throw Object.assign(new Error('tree changed in CanPlaceDep'), { diff --git a/node_modules/@npmcli/arborist/lib/place-dep.js b/node_modules/@npmcli/arborist/lib/place-dep.js index 913b2ba6c..c0023e74a 100644 --- a/node_modules/@npmcli/arborist/lib/place-dep.js +++ b/node_modules/@npmcli/arborist/lib/place-dep.js @@ -16,6 +16,7 @@ const { } = CanPlaceDep const debug = require('./debug.js') +const Link = require('./link.js') const gatherDepSet = require('./gather-dep-set.js') const peerEntrySets = require('./peer-entry-sets.js') @@ -256,6 +257,20 @@ class PlaceDep { return } + // we were told to place it here in the target, so either it does not + // already exist in the tree, OR it's shadowed. + // handle otherwise unresolvable dependency nesting loops by + // creating a symbolic link + // a1 -> b1 -> a2 -> b2 -> a1 -> ... + // instead of nesting forever, when the loop occurs, create + // a symbolic link to the earlier instance + for (let p = target; p; p = p.resolveParent) { + if (p.matches(dep) && !p.isTop) { + this.placed = new Link({ parent: target, target: p }) + return + } + } + // XXX if we are replacing SOME of a peer entry group, we will need to // remove any that are not being replaced and will now be invalid, and // re-evaluate them deeper into the tree. @@ -268,7 +283,7 @@ class PlaceDep { integrity: dep.integrity, legacyPeerDeps: this.legacyPeerDeps, error: dep.errors[0], - ...(dep.isLink ? { target: dep.target, realpath: dep.target.path } : {}), + ...(dep.isLink ? { target: dep.target, realpath: dep.realpath } : {}), }) this.oldDep = target.children.get(this.name) diff --git a/node_modules/@npmcli/arborist/lib/shrinkwrap.js b/node_modules/@npmcli/arborist/lib/shrinkwrap.js index ebbe004de..83cb1f66f 100644 --- a/node_modules/@npmcli/arborist/lib/shrinkwrap.js +++ b/node_modules/@npmcli/arborist/lib/shrinkwrap.js @@ -255,9 +255,11 @@ class Shrinkwrap { if (val) meta[key.replace(/^_/, '')] = val }) - // we only include name if different from the node path name + // we only include name if different from the node path name, and for the + // root to help prevent churn based on the name of the directory the + // project is in const pname = node.packageName - if (pname && pname !== node.name) + if (pname && (node === node.root || pname !== node.name)) meta.name = pname if (node.isTop && node.package.devDependencies) diff --git a/node_modules/@npmcli/arborist/package.json b/node_modules/@npmcli/arborist/package.json index 56046eaa5..01f018a62 100644 --- a/node_modules/@npmcli/arborist/package.json +++ b/node_modules/@npmcli/arborist/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/arborist", - "version": "2.8.0", + "version": "2.8.1", "description": "Manage node_modules trees", "dependencies": { "@npmcli/installed-package-contents": "^1.0.7", |