Skip to content

Commit

Permalink
dep: @npmcli/arborist 4.0.5
Browse files Browse the repository at this point in the history
PR-URL: #4065
Credit: @fritzy
Close: #4065
Reviewed-by: @lukekarrys
  • Loading branch information
fritzy committed Nov 18, 2021
1 parent 088c116 commit 44bfa37
Show file tree
Hide file tree
Showing 30 changed files with 166 additions and 146 deletions.
22 changes: 0 additions & 22 deletions node_modules/@npmcli/arborist/LICENSE

This file was deleted.

20 changes: 20 additions & 0 deletions node_modules/@npmcli/arborist/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->

ISC License

Copyright npm, Inc.

Permission to use, copy, modify, and/or distribute this
software for any purpose with or without fee is hereby
granted, provided that the above copyright notice and this
permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
USE OR PERFORMANCE OF THIS SOFTWARE.
2 changes: 1 addition & 1 deletion node_modules/@npmcli/arborist/bin/prune.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require('./lib/logging.js')
require('./lib/timers.js')

const printDiff = diff => {
const {depth} = require('treeverse')
const { depth } = require('treeverse')
depth({
tree: diff,
visit: d => {
Expand Down
2 changes: 1 addition & 1 deletion node_modules/@npmcli/arborist/bin/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require('./lib/logging.js')
require('./lib/timers.js')

const printDiff = diff => {
const {depth} = require('treeverse')
const { depth } = require('treeverse')
depth({
tree: diff,
visit: d => {
Expand Down
6 changes: 3 additions & 3 deletions node_modules/@npmcli/arborist/lib/add-rm-pkg-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const localeCompare = require('@isaacs/string-locale-compare')('en')

const add = ({pkg, add, saveBundle, saveType, log}) => {
const add = ({ pkg, add, saveBundle, saveType, log }) => {
for (const spec of add) {
addSingle({pkg, spec, saveBundle, saveType, log})
addSingle({ pkg, spec, saveBundle, saveType, log })
}

return pkg
Expand All @@ -20,7 +20,7 @@ const saveTypeMap = new Map([
['peer', 'peerDependencies'],
])

const addSingle = ({pkg, spec, saveBundle, saveType, log}) => {
const addSingle = ({ pkg, spec, saveBundle, saveType, log }) => {
const { name, rawSpec } = spec

// if the user does not give us a type, we infer which type(s)
Expand Down
12 changes: 6 additions & 6 deletions node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Node = require('../node.js')
const Link = require('../link.js')
const addRmPkgDeps = require('../add-rm-pkg-deps.js')
const optionalSet = require('../optional-set.js')
const {checkEngine, checkPlatform} = require('npm-install-checks')
const { checkEngine, checkPlatform } = require('npm-install-checks')

const relpath = require('../relpath.js')

Expand Down Expand Up @@ -311,7 +311,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
? Shrinkwrap.reset({
path: this.path,
lockfileVersion: this.options.lockfileVersion,
}).then(meta => Object.assign(root, {meta}))
}).then(meta => Object.assign(root, { meta }))
: this.loadVirtual({ root }))

// if we don't have a lockfile to go from, then start with the
Expand Down Expand Up @@ -492,7 +492,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {

// This returns a promise because we might not have the name yet,
// and need to call pacote.manifest to find the name.
[_add] (tree, {add, saveType = null, saveBundle = false}) {
[_add] (tree, { add, saveType = null, saveBundle = false }) {
// get the name for each of the specs in the list.
// ie, doing `foo@bar` we just return foo
// but if it's a url or git, we don't know the name until we
Expand Down Expand Up @@ -936,7 +936,7 @@ This is a one-time fix-up, please be patient...
}
})

tasks.push({edge, dep})
tasks.push({ edge, dep })
}

const placeDeps = tasks
Expand Down Expand Up @@ -1271,7 +1271,7 @@ This is a one-time fix-up, please be patient...
// we typically only install non-optional peers, but we have to
// factor them into the peerSet so that we can avoid conflicts
.filter(e => e.peer && !(e.valid && e.to))
.sort(({name: a}, {name: b}) => localeCompare(a, b))
.sort(({ name: a }, { name: b }) => localeCompare(a, b))

for (const edge of peerEdges) {
// already placed this one, and we're happy with it.
Expand All @@ -1280,7 +1280,7 @@ This is a one-time fix-up, please be patient...
}

const parentEdge = node.parent.edgesOut.get(edge.name)
const {isProjectRoot, isWorkspace} = node.parent.sourceReference
const { isProjectRoot, isWorkspace } = node.parent.sourceReference
const isMine = isProjectRoot || isWorkspace
const conflictOK = this[_force] || !isMine && !this[_strictPeerDeps]

Expand Down
56 changes: 34 additions & 22 deletions node_modules/@npmcli/arborist/lib/arborist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
// the base class, so that the overall voltron class is easier to test and
// cover, and separation of concerns can be maintained.

const {resolve} = require('path')
const {homedir} = require('os')
const { resolve } = require('path')
const { homedir } = require('os')
const procLog = require('proc-log')
const { depth } = require('treeverse')
const { saveTypeMap } = require('../add-rm-pkg-deps.js')

const mixins = [
Expand Down Expand Up @@ -88,6 +89,9 @@ class Arborist extends Base {
process.emit('timeEnd', 'arborist:ctor')
}

// TODO: We should change these to static functions instead
// of methods for the next major version

// returns an array of the actual nodes for all the workspaces
workspaceNodes (tree, workspaces) {
return getWorkspaceNodes(tree, workspaces, this.log)
Expand All @@ -103,15 +107,15 @@ class Arborist extends Base {
}
}
}
const set = new Set(wsNodes)
const wsDepSet = new Set(wsNodes)
const extraneous = new Set()
for (const node of set) {
for (const node of wsDepSet) {
for (const edge of node.edgesOut.values()) {
const dep = edge.to
if (dep) {
set.add(dep)
wsDepSet.add(dep)
if (dep.isLink) {
set.add(dep.target)
wsDepSet.add(dep.target)
}
}
}
Expand All @@ -122,28 +126,36 @@ class Arborist extends Base {
}
}
for (const extra of extraneous) {
set.add(extra)
wsDepSet.add(extra)
}

return set
return wsDepSet
}

// returns a set of root dependencies, excluding depdencies that are
// exclusively workspace dependencies
excludeWorkspacesDependencySet (tree) {
const set = new Set()
for (const edge of tree.edgesOut.values()) {
if (edge.type !== 'workspace' && edge.to) {
set.add(edge.to)
}
}
for (const node of set) {
for (const edge of node.edgesOut.values()) {
if (edge.to) {
set.add(edge.to)
const rootDepSet = new Set()
depth({
tree,
visit: node => {
for (const { to } of node.edgesOut.values()) {
if (!to || to.isWorkspace) {
continue
}
for (const edgeIn of to.edgesIn.values()) {
if (edgeIn.from.isRoot || rootDepSet.has(edgeIn.from)) {
rootDepSet.add(to)
}
}
}
}
}

return set
return node
},
filter: node => node,
getChildren: (node, tree) =>
[...tree.edgesOut.values()].map(edge => edge.to),
})
return rootDepSet
}
}

Expand Down
8 changes: 4 additions & 4 deletions node_modules/@npmcli/arborist/lib/arborist/load-actual.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// mix-in implementing the loadActual method

const {relative, dirname, resolve, join, normalize} = require('path')
const { relative, dirname, resolve, join, normalize } = require('path')

const rpj = require('read-package-json-fast')
const {promisify} = require('util')
const { promisify } = require('util')
const readdir = promisify(require('readdir-scoped-modules'))
const walkUp = require('walk-up-path')
const ancestorPath = require('common-ancestor-path')
Expand Down Expand Up @@ -128,7 +128,7 @@ module.exports = cls => class ActualLoader extends cls {
pkg: {},
global,
})
return this[_loadActualActually]({root, ignoreMissing, global})
return this[_loadActualActually]({ root, ignoreMissing, global })
}

// not in global mode, hidden lockfile is allowed, load root pkg too
Expand Down Expand Up @@ -163,7 +163,7 @@ module.exports = cls => class ActualLoader extends cls {
// we can't easily get a ref to Arborist in this module, without
// creating a circular reference, since this class is a mixin used
// to build up the Arborist class itself.
await new this.constructor({...this.options}).loadVirtual({
await new this.constructor({ ...this.options }).loadVirtual({
root: this[_actualTree],
})
await this[_loadWorkspaces](this[_actualTree])
Expand Down
8 changes: 4 additions & 4 deletions node_modules/@npmcli/arborist/lib/arborist/load-virtual.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// mixin providing the loadVirtual method
const localeCompare = require('@isaacs/string-locale-compare')('en')

const {resolve} = require('path')
const { resolve } = require('path')

const nameFromFolder = require('@npmcli/name-from-folder')
const consistentResolve = require('../consistent-resolve.js')
Expand Down Expand Up @@ -97,7 +97,7 @@ module.exports = cls => class VirtualLoader extends cls {
this[checkRootEdges](s, root)
root.meta = s
this.virtualTree = root
const {links, nodes} = this[resolveNodes](s, root)
const { links, nodes } = this[resolveNodes](s, root)
await this[resolveLinks](links, nodes)
if (!(s.originalLockfileVersion >= 2)) {
this[assignBundles](nodes)
Expand Down Expand Up @@ -208,7 +208,7 @@ module.exports = cls => class VirtualLoader extends cls {
nodes.set(location, this[loadNode](location, meta))
}
}
return {links, nodes}
return { links, nodes }
}

// links is the set of metadata, and nodes is the map of non-Link nodes
Expand Down Expand Up @@ -240,7 +240,7 @@ module.exports = cls => class VirtualLoader extends cls {
if (!location || node.isLink && !node.target.location) {
continue
}
const { name, parent, package: { inBundle }} = node
const { name, parent, package: { inBundle } } = node

if (!parent) {
continue
Expand Down
14 changes: 7 additions & 7 deletions node_modules/@npmcli/arborist/lib/arborist/rebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// bundle building needed. Called by reify, and by `npm rebuild`.

const localeCompare = require('@isaacs/string-locale-compare')('en')
const {depth: dfwalk} = require('treeverse')
const { depth: dfwalk } = require('treeverse')
const promiseAllRejectLate = require('promise-all-reject-late')
const rpj = require('read-package-json-fast')
const binLinks = require('bin-links')
const runScript = require('@npmcli/run-script')
const promiseCallLimit = require('promise-call-limit')
const {resolve} = require('path')
const { resolve } = require('path')
const {
isNodeGypPackage,
defaultGypInstallScript,
Expand Down Expand Up @@ -220,7 +220,7 @@ module.exports = cls => class Builder extends cls {
}

if (this[_oldMeta] === null) {
const {root: {meta}} = node
const { root: { meta } } = node
this[_oldMeta] = meta && meta.loadedFromDisk &&
!(meta.originalLockfileVersion >= 2)
}
Expand All @@ -242,7 +242,7 @@ module.exports = cls => class Builder extends cls {
const pkg = await rpj(node.path + '/package.json').catch(() => ({}))
set.delete(node)

const {scripts = {}} = pkg
const { scripts = {} } = pkg
node.package.scripts = scripts
return this[_addToBuildSet](node, set, true)
}
Expand Down Expand Up @@ -319,9 +319,9 @@ module.exports = cls => class Builder extends cls {
}
const p = runScript(runOpts).catch(er => {
const { code, signal } = er
this.log.info('run', pkg._id, event, {code, signal})
this.log.info('run', pkg._id, event, { code, signal })
throw er
}).then(({args, code, signal, stdout, stderr}) => {
}).then(({ args, code, signal, stdout, stderr }) => {
this.scriptsRun.add({
pkg,
path,
Expand All @@ -333,7 +333,7 @@ module.exports = cls => class Builder extends cls {
stdout,
stderr,
})
this.log.info('run', pkg._id, event, {code, signal})
this.log.info('run', pkg._id, event, { code, signal })
})

await (this[_doHandleOptionalFailure]
Expand Down
Loading

0 comments on commit 44bfa37

Please sign in to comment.