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 73a6f667e35db..5db11eb3832eb 100644 --- a/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js +++ b/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js @@ -7,7 +7,7 @@ const semver = require('semver') const promiseCallLimit = require('promise-call-limit') const getPeerSet = require('../peer-set.js') const realpath = require('../../lib/realpath.js') -const { resolve } = require('path') +const { resolve, dirname } = require('path') const { promisify } = require('util') const treeCheck = require('../tree-check.js') const readdir = promisify(require('readdir-scoped-modules')) @@ -661,7 +661,7 @@ module.exports = cls => class IdealTreeBuilder extends cls { const ancient = meta.ancientLockfile const old = meta.loadedFromDisk && !(meta.originalLockfileVersion >= 2) - if (inventory.size === 0 || !ancient && !(old && this[_complete])) + if (inventory.size === 0 || !ancient && !old) return // if the lockfile is from node v5 or earlier, then we'll have to reload @@ -688,10 +688,12 @@ This is a one-time fix-up, please be patient... this.log.silly('inflate', node.location) const { resolved, version, path, name, location, integrity } = node // don't try to hit the registry for linked deps - const useResolved = !version || - resolved && resolved.startsWith('file:') - const id = useResolved ? resolved : version - const spec = npa.resolve(name, id, path) + const useResolved = resolved && ( + !version || resolved.startsWith('file:') + ) + const id = useResolved ? resolved + : version || `file:${node.path}` + const spec = npa.resolve(name, id, dirname(path)) const sloc = location.substr('node_modules/'.length) const t = `idealTree:inflate:${sloc}` this.addTracker(t) diff --git a/node_modules/@npmcli/arborist/lib/arborist/index.js b/node_modules/@npmcli/arborist/lib/arborist/index.js index b119d3117bc23..94501cae12c84 100644 --- a/node_modules/@npmcli/arborist/lib/arborist/index.js +++ b/node_modules/@npmcli/arborist/lib/arborist/index.js @@ -28,7 +28,7 @@ const {resolve} = require('path') const {homedir} = require('os') -const procLog = require('../proc-log.js') +const procLog = require('proc-log') const { saveTypeMap } = require('../add-rm-pkg-deps.js') const mixins = [ diff --git a/node_modules/@npmcli/arborist/lib/arborist/load-actual.js b/node_modules/@npmcli/arborist/lib/arborist/load-actual.js index d9e7fb46d6df9..9fca7d6425da0 100644 --- a/node_modules/@npmcli/arborist/lib/arborist/load-actual.js +++ b/node_modules/@npmcli/arborist/lib/arborist/load-actual.js @@ -22,6 +22,7 @@ const _loadFSTree = Symbol('loadFSTree') const _loadFSChildren = Symbol('loadFSChildren') const _findMissingEdges = Symbol('findMissingEdges') const _findFSParents = Symbol('findFSParents') +const _resetDepFlags = Symbol('resetDepFlags') const _actualTreeLoaded = Symbol('actualTreeLoaded') const _rpcache = Symbol.for('realpathCache') @@ -74,6 +75,19 @@ module.exports = cls => class ActualLoader extends cls { this[_topNodes] = new Set() } + [_resetDepFlags] (tree, root) { + // reset all deps to extraneous prior to recalc + if (!root) { + for (const node of tree.inventory.values()) + node.extraneous = true + } + + // only reset root flags if we're not re-rooting, + // otherwise leave as-is + calcDepFlags(tree, !root) + return tree + } + // public method async loadActual (options = {}) { // allow the user to set options on the ctor as well. @@ -88,6 +102,7 @@ module.exports = cls => class ActualLoader extends cls { return this.actualTree ? this.actualTree : this[_actualTreePromise] ? this[_actualTreePromise] : this[_actualTreePromise] = this[_loadActual](options) + .then(tree => this[_resetDepFlags](tree, options.root)) .then(tree => this.actualTree = treeCheck(tree)) } @@ -152,8 +167,7 @@ module.exports = cls => class ActualLoader extends cls { root: this[_actualTree], }) await this[_loadWorkspaces](this[_actualTree]) - if (this[_actualTree].workspaces && this[_actualTree].workspaces.size) - calcDepFlags(this[_actualTree], !root) + this[_transplant](root) return this[_actualTree] } @@ -178,8 +192,6 @@ module.exports = cls => class ActualLoader extends cls { dependencies[name] = dependencies[name] || '*' actualRoot.package = { ...actualRoot.package, dependencies } } - // only reset root flags if we're not re-rooting, otherwise leave as-is - calcDepFlags(this[_actualTree], !root) return this[_actualTree] } diff --git a/node_modules/@npmcli/arborist/lib/arborist/reify.js b/node_modules/@npmcli/arborist/lib/arborist/reify.js index 58dc7c68a4a40..55360538b901a 100644 --- a/node_modules/@npmcli/arborist/lib/arborist/reify.js +++ b/node_modules/@npmcli/arborist/lib/arborist/reify.js @@ -2,7 +2,6 @@ const onExit = require('../signal-handling.js') const pacote = require('pacote') -const rpj = require('read-package-json-fast') const AuditReport = require('../audit-report.js') const {subset, intersects} = require('semver') const npa = require('npm-package-arg') @@ -57,7 +56,6 @@ const _extractOrLink = Symbol('extractOrLink') const _checkBins = Symbol.for('checkBins') const _symlink = Symbol('symlink') const _warnDeprecated = Symbol('warnDeprecated') -const _loadAncientPackageDetails = Symbol('loadAncientPackageDetails') const _loadBundlesAndUpdateTrees = Symbol.for('loadBundlesAndUpdateTrees') const _submitQuickAudit = Symbol('submitQuickAudit') const _awaitQuickAudit = Symbol('awaitQuickAudit') @@ -522,7 +520,6 @@ module.exports = cls => class Reifier extends cls { await this[_checkBins](node) await this[_extractOrLink](node) await this[_warnDeprecated](node) - await this[_loadAncientPackageDetails](node) }) return this[_handleOptionalFailure](node, p) @@ -583,32 +580,6 @@ module.exports = cls => class Reifier extends cls { this.log.warn('deprecated', `${_id}: ${deprecated}`) } - async [_loadAncientPackageDetails] (node, forceReload = false) { - // If we're loading from a v1 lockfile, load details from the package.json - // that weren't recorded in the old format. - const {meta} = this.idealTree - const ancient = meta.ancientLockfile - const old = meta.loadedFromDisk && !(meta.originalLockfileVersion >= 2) - - // already replaced with the manifest if it's truly ancient - if (node.path && (forceReload || (old && !ancient))) { - // XXX should have a shared location where package.json is read, - // so we don't ever read the same pj more than necessary. - let pkg - try { - pkg = await rpj(node.path + '/package.json') - } catch (err) {} - - if (pkg) { - node.package.bin = pkg.bin - node.package.os = pkg.os - node.package.cpu = pkg.cpu - node.package.engines = pkg.engines - meta.add(node) - } - } - } - // if the node is optional, then the failure of the promise is nonfatal // just add it and its optional set to the trash list. [_handleOptionalFailure] (node, p) { @@ -1079,12 +1050,6 @@ module.exports = cls => class Reifier extends cls { const { meta } = this.idealTree - // might have to update metadata for bins and stuff that gets lost - if (meta.loadedFromDisk && !(meta.originalLockfileVersion >= 2)) { - for (const node of this.idealTree.inventory.values()) - await this[_loadAncientPackageDetails](node, true) - } - return meta.save(saveOpt) } diff --git a/node_modules/@npmcli/arborist/lib/audit-report.js b/node_modules/@npmcli/arborist/lib/audit-report.js index 139a7aefd2489..8f7d6546d64f4 100644 --- a/node_modules/@npmcli/arborist/lib/audit-report.js +++ b/node_modules/@npmcli/arborist/lib/audit-report.js @@ -12,7 +12,7 @@ const _fixAvailable = Symbol('fixAvailable') const _checkTopNode = Symbol('checkTopNode') const _init = Symbol('init') const _omit = Symbol('omit') -const procLog = require('./proc-log.js') +const procLog = require('proc-log') const fetch = require('npm-registry-fetch') diff --git a/node_modules/@npmcli/arborist/lib/calc-dep-flags.js b/node_modules/@npmcli/arborist/lib/calc-dep-flags.js index d6ae266db3bb0..21d8ddcf7b442 100644 --- a/node_modules/@npmcli/arborist/lib/calc-dep-flags.js +++ b/node_modules/@npmcli/arborist/lib/calc-dep-flags.js @@ -22,6 +22,11 @@ const calcDepFlagsStep = (node) => { // Since we're only walking through deps that are not already flagged // as non-dev/non-optional, it's typically a very shallow traversal node.extraneous = false + resetParents(node, 'extraneous') + resetParents(node, 'dev') + resetParents(node, 'peer') + resetParents(node, 'devOptional') + resetParents(node, 'optional') // for links, map their hierarchy appropriately if (node.target) { @@ -29,8 +34,7 @@ const calcDepFlagsStep = (node) => { node.target.optional = node.optional node.target.devOptional = node.devOptional node.target.peer = node.peer - node.target.extraneous = false - node = node.target + return calcDepFlagsStep(node.target) } node.edgesOut.forEach(({peer, optional, dev, to}) => { @@ -71,6 +75,14 @@ const calcDepFlagsStep = (node) => { return node } +const resetParents = (node, flag) => { + if (node[flag]) + return + + for (let p = node; p && (p === node || p[flag]); p = p.resolveParent) + p[flag] = false +} + // typically a short walk, since it only traverses deps that // have the flag set. const unsetFlag = (node, flag) => { diff --git a/node_modules/@npmcli/arborist/lib/inventory.js b/node_modules/@npmcli/arborist/lib/inventory.js index 7578291885223..a4ae11c2ab41e 100644 --- a/node_modules/@npmcli/arborist/lib/inventory.js +++ b/node_modules/@npmcli/arborist/lib/inventory.js @@ -7,6 +7,20 @@ const _index = Symbol('_index') const defaultKeys = ['name', 'license', 'funding', 'realpath', 'packageName'] const { hasOwnProperty } = Object.prototype const debug = require('./debug.js') + +// handling for the outdated "licenses" array, just pick the first one +// also support the alternative spelling "licence" +const getLicense = pkg => { + if (pkg) { + const lic = pkg.license || pkg.licence + if (lic) + return lic + const lics = pkg.licenses || pkg.licences + if (Array.isArray(lics)) + return lics[0] + } +} + class Inventory extends Map { constructor (opt = {}) { const { primary, keys } = opt @@ -56,7 +70,9 @@ class Inventory extends Map { for (const [key, map] of this[_index].entries()) { // if the node has the value, but it's false, then use that const val_ = hasOwnProperty.call(node, key) ? node[key] - : node[key] || (node.package && node.package[key]) + : key === 'license' ? getLicense(node.package) + : node[key] ? node[key] + : node.package && node.package[key] const val = typeof val_ === 'string' ? val_ : !val_ || typeof val_ !== 'object' ? val_ : key === 'license' ? val_.type diff --git a/node_modules/@npmcli/arborist/lib/node.js b/node_modules/@npmcli/arborist/lib/node.js index 1683c7049504e..c21bc46cfb539 100644 --- a/node_modules/@npmcli/arborist/lib/node.js +++ b/node_modules/@npmcli/arborist/lib/node.js @@ -547,6 +547,8 @@ class Node { // try to find our parent/fsParent in the new root inventory for (const p of walkUp(dirname(this.path))) { + if (p === this.path) + continue const ploc = relpath(root.realpath, p) const parent = root.inventory.get(ploc) if (parent) { @@ -783,7 +785,13 @@ class Node { } get fsParent () { - return this[_fsParent] + const parent = this[_fsParent] + /* istanbul ignore next - should be impossible */ + debug(() => { + if (parent === this) + throw new Error('node set to its own fsParent') + }) + return parent } set fsParent (fsParent) { @@ -1009,7 +1017,13 @@ class Node { } get parent () { - return this[_parent] + const parent = this[_parent] + /* istanbul ignore next - should be impossible */ + debug(() => { + if (parent === this) + throw new Error('node set to its own parent') + }) + return parent } // This setter keeps everything in order when we move a node from diff --git a/node_modules/@npmcli/arborist/lib/proc-log.js b/node_modules/@npmcli/arborist/lib/proc-log.js deleted file mode 100644 index 52e0e466798ee..0000000000000 --- a/node_modules/@npmcli/arborist/lib/proc-log.js +++ /dev/null @@ -1,21 +0,0 @@ -// default logger. -// emits 'log' events on the process -const LEVELS = [ - 'notice', - 'error', - 'warn', - 'info', - 'verbose', - 'http', - 'silly', - 'pause', - 'resume', -] - -const log = level => (...args) => process.emit('log', level, ...args) - -const logger = {} -for (const level of LEVELS) - logger[level] = log(level) - -module.exports = logger diff --git a/node_modules/@npmcli/arborist/lib/shrinkwrap.js b/node_modules/@npmcli/arborist/lib/shrinkwrap.js index 0a19ef93005ad..9fb0528db497c 100644 --- a/node_modules/@npmcli/arborist/lib/shrinkwrap.js +++ b/node_modules/@npmcli/arborist/lib/shrinkwrap.js @@ -32,7 +32,7 @@ const mismatch = (a, b) => a && b && a !== b // After calling this.commit(), any nodes not present in the tree will have // been removed from the shrinkwrap data as well. -const procLog = require('./proc-log.js') +const procLog = require('proc-log') const YarnLock = require('./yarn-lock.js') const {promisify} = require('util') const rimraf = promisify(require('rimraf')) diff --git a/node_modules/@npmcli/arborist/lib/tracker.js b/node_modules/@npmcli/arborist/lib/tracker.js index 47267872ce780..aefd5fe1bbf58 100644 --- a/node_modules/@npmcli/arborist/lib/tracker.js +++ b/node_modules/@npmcli/arborist/lib/tracker.js @@ -1,6 +1,6 @@ const _progress = Symbol('_progress') const _onError = Symbol('_onError') -const procLog = require('./proc-log.js') +const procLog = require('proc-log') module.exports = cls => class Tracker extends cls { constructor (options = {}) { diff --git a/node_modules/@npmcli/arborist/package.json b/node_modules/@npmcli/arborist/package.json index 7c2622f49e93e..bd27e4bbffa20 100644 --- a/node_modules/@npmcli/arborist/package.json +++ b/node_modules/@npmcli/arborist/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/arborist", - "version": "2.6.2", + "version": "2.6.3", "description": "Manage node_modules trees", "dependencies": { "@npmcli/installed-package-contents": "^1.0.7", @@ -22,6 +22,7 @@ "npm-registry-fetch": "^11.0.0", "pacote": "^11.2.6", "parse-conflict-json": "^1.1.1", + "proc-log": "^1.0.0", "promise-all-reject-late": "^1.0.0", "promise-call-limit": "^1.0.1", "read-package-json-fast": "^2.0.2", diff --git a/package-lock.json b/package-lock.json index edcbe26ae3b58..e49153959c919 100644 --- a/package-lock.json +++ b/package-lock.json @@ -82,7 +82,7 @@ "packages/*" ], "dependencies": { - "@npmcli/arborist": "^2.6.1", + "@npmcli/arborist": "^2.6.3", "@npmcli/ci-detect": "^1.2.0", "@npmcli/config": "^2.2.0", "@npmcli/run-script": "^1.8.5", @@ -733,9 +733,9 @@ } }, "node_modules/@npmcli/arborist": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.2.tgz", - "integrity": "sha512-CAo0HSziRdlpGUUheERmOrADnKHfBYpLAl/HmWGwGCtWKB3BCxfgb0rJ7MsFg38wy7YF3+fDs7R9dMVCH89K/A==", + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.3.tgz", + "integrity": "sha512-R8U2dZ8+jeE7go+qNU4Mt6aiXyBu3mM75iRIugNCA4P0OWlsLOpuDPPhsaRcOVbtXheOGZXrqe36qP1g+M68KQ==", "inBundle": true, "dependencies": { "@npmcli/installed-package-contents": "^1.0.7", @@ -757,6 +757,7 @@ "npm-registry-fetch": "^11.0.0", "pacote": "^11.2.6", "parse-conflict-json": "^1.1.1", + "proc-log": "^1.0.0", "promise-all-reject-late": "^1.0.0", "promise-call-limit": "^1.0.1", "read-package-json-fast": "^2.0.2", @@ -10856,9 +10857,9 @@ "dev": true }, "@npmcli/arborist": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.2.tgz", - "integrity": "sha512-CAo0HSziRdlpGUUheERmOrADnKHfBYpLAl/HmWGwGCtWKB3BCxfgb0rJ7MsFg38wy7YF3+fDs7R9dMVCH89K/A==", + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.3.tgz", + "integrity": "sha512-R8U2dZ8+jeE7go+qNU4Mt6aiXyBu3mM75iRIugNCA4P0OWlsLOpuDPPhsaRcOVbtXheOGZXrqe36qP1g+M68KQ==", "requires": { "@npmcli/installed-package-contents": "^1.0.7", "@npmcli/map-workspaces": "^1.0.2", @@ -10879,6 +10880,7 @@ "npm-registry-fetch": "^11.0.0", "pacote": "^11.2.6", "parse-conflict-json": "^1.1.1", + "proc-log": "^1.0.0", "promise-all-reject-late": "^1.0.0", "promise-call-limit": "^1.0.1", "read-package-json-fast": "^2.0.2", diff --git a/package.json b/package.json index 42e93f50b2891..851c4a2c6924a 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "./package.json": "./package.json" }, "dependencies": { - "@npmcli/arborist": "^2.6.1", + "@npmcli/arborist": "^2.6.3", "@npmcli/ci-detect": "^1.2.0", "@npmcli/config": "^2.2.0", "@npmcli/run-script": "^1.8.5",