diff --git a/node_modules/@npmcli/arborist/bin/lib/timers.js b/node_modules/@npmcli/arborist/bin/lib/timers.js index e72217c1e4ed9..b516af92c5b57 100644 --- a/node_modules/@npmcli/arborist/bin/lib/timers.js +++ b/node_modules/@npmcli/arborist/bin/lib/timers.js @@ -1,5 +1,6 @@ const timers = Object.create(null) const { format } = require('util') +const options = require('./options.js') process.on('time', name => { if (timers[name]) @@ -15,7 +16,8 @@ process.on('timeEnd', name => { const res = process.hrtime(timers[name]) delete timers[name] const msg = format(`${process.pid} ${name}`, res[0] * 1e3 + res[1] / 1e6) - console.error(dim(msg)) + if (options.timers !== false) + console.error(dim(msg)) }) process.on('exit', () => { diff --git a/node_modules/@npmcli/arborist/lib/arborist/reify.js b/node_modules/@npmcli/arborist/lib/arborist/reify.js index 55360538b901a..f259a69b548e1 100644 --- a/node_modules/@npmcli/arborist/lib/arborist/reify.js +++ b/node_modules/@npmcli/arborist/lib/arborist/reify.js @@ -15,6 +15,7 @@ const mkdirp = require('mkdirp-infer-owner') const justMkdirp = require('mkdirp') const moveFile = require('@npmcli/move-file') const rimraf = promisify(require('rimraf')) +const PackageJson = require('@npmcli/package-json') const packageContents = require('@npmcli/installed-package-contents') const { checkEngine, checkPlatform } = require('npm-install-checks') @@ -24,7 +25,6 @@ const Diff = require('../diff.js') const retirePath = require('../retire-path.js') const promiseAllRejectLate = require('promise-all-reject-late') const optionalSet = require('../optional-set.js') -const updateRootPackageJson = require('../update-root-package-json.js') const calcDepFlags = require('../calc-dep-flags.js') const { saveTypeMap, hasSubKey } = require('../add-rm-pkg-deps.js') @@ -1029,6 +1029,25 @@ module.exports = cls => class Reifier extends cls { const promises = [this[_saveLockFile](saveOpt)] + const updatePackageJson = async (tree) => { + const pkgJson = await PackageJson.load(tree.path) + .catch(() => new PackageJson(tree.path)) + const { + dependencies = {}, + devDependencies = {}, + optionalDependencies = {}, + peerDependencies = {}, + } = tree.package + + pkgJson.update({ + dependencies, + devDependencies, + optionalDependencies, + peerDependencies, + }) + await pkgJson.save() + } + // grab any from explicitRequests that had deps removed for (const { from: tree } of this.explicitRequests) updatedTrees.add(tree) @@ -1036,7 +1055,7 @@ module.exports = cls => class Reifier extends cls { for (const tree of updatedTrees) { // refresh the edges so they have the correct specs tree.package = tree.package - promises.push(updateRootPackageJson(tree)) + promises.push(updatePackageJson(tree)) } await Promise.all(promises) diff --git a/node_modules/@npmcli/arborist/lib/diff.js b/node_modules/@npmcli/arborist/lib/diff.js index dac7c81f8ecfb..1f8eff0f0c4d9 100644 --- a/node_modules/@npmcli/arborist/lib/diff.js +++ b/node_modules/@npmcli/arborist/lib/diff.js @@ -145,9 +145,9 @@ const allChildren = node => { if (!node) return new Map() - // if the node is a global root, and also a link, then what we really + // if the node is root, and also a link, then what we really // want is to traverse the target's children - if (node.global && node.isRoot && node.isLink) + if (node.isRoot && node.isLink) return allChildren(node.target) const kids = new Map() diff --git a/node_modules/@npmcli/arborist/lib/shrinkwrap.js b/node_modules/@npmcli/arborist/lib/shrinkwrap.js index 9fb0528db497c..b251539a94c90 100644 --- a/node_modules/@npmcli/arborist/lib/shrinkwrap.js +++ b/node_modules/@npmcli/arborist/lib/shrinkwrap.js @@ -349,6 +349,7 @@ class Shrinkwrap { reset () { this.tree = null this[_awaitingUpdate] = new Map() + this.originalLockfileVersion = lockfileVersion this.data = { lockfileVersion, requires: true, diff --git a/node_modules/@npmcli/arborist/lib/update-root-package-json.js b/node_modules/@npmcli/arborist/lib/update-root-package-json.js deleted file mode 100644 index 57ec414248756..0000000000000 --- a/node_modules/@npmcli/arborist/lib/update-root-package-json.js +++ /dev/null @@ -1,95 +0,0 @@ -const fs = require('fs') -const promisify = require('util').promisify -const readFile = promisify(fs.readFile) -const writeFile = promisify(fs.writeFile) -const {resolve} = require('path') - -const parseJSON = require('json-parse-even-better-errors') - -const depTypes = new Set([ - 'dependencies', - 'optionalDependencies', - 'devDependencies', - 'peerDependencies', -]) - -// sort alphabetically all types of deps for a given package -const orderDeps = (pkg) => { - for (const type of depTypes) { - if (pkg && pkg[type]) { - pkg[type] = Object.keys(pkg[type]) - .sort((a, b) => a.localeCompare(b, 'en')) - .reduce((res, key) => { - res[key] = pkg[type][key] - return res - }, {}) - } - } - return pkg -} -const parseJsonSafe = json => { - try { - return parseJSON(json) - } catch (er) { - return null - } -} - -const updateRootPackageJson = async tree => { - const filename = resolve(tree.path, 'package.json') - const originalJson = await readFile(filename, 'utf8').catch(() => null) - const originalContent = parseJsonSafe(originalJson) - - const depsData = orderDeps({ - ...tree.package, - }) - - // optionalDependencies don't need to be repeated in two places - if (depsData.dependencies) { - if (depsData.optionalDependencies) { - for (const name of Object.keys(depsData.optionalDependencies)) - delete depsData.dependencies[name] - } - if (Object.keys(depsData.dependencies).length === 0) - delete depsData.dependencies - } - - // if there's no package.json, just use internal pkg info as source of truth - // clone the object though, so we can still refer to what it originally was - const packageJsonContent = !originalContent ? depsData - : Object.assign({}, originalContent) - - // loop through all types of dependencies and update package json content - for (const type of depTypes) - packageJsonContent[type] = depsData[type] - - // if original package.json had dep in peerDeps AND deps, preserve that. - const { dependencies: origProd, peerDependencies: origPeer } = - originalContent || {} - const { peerDependencies: newPeer } = packageJsonContent - if (origProd && origPeer && newPeer) { - // we have original prod/peer deps, and new peer deps - // copy over any that were in both in the original - for (const name of Object.keys(origPeer)) { - if (origProd[name] !== undefined && newPeer[name] !== undefined) { - packageJsonContent.dependencies = packageJsonContent.dependencies || {} - packageJsonContent.dependencies[name] = newPeer[name] - } - } - } - - // format content - const { - [Symbol.for('indent')]: indent, - [Symbol.for('newline')]: newline, - } = tree.package - const format = indent === undefined ? ' ' : indent - const eol = newline === undefined ? '\n' : newline - const content = (JSON.stringify(packageJsonContent, null, format) + '\n') - .replace(/\n/g, eol) - - if (content !== originalJson) - return writeFile(filename, content) -} - -module.exports = updateRootPackageJson diff --git a/node_modules/@npmcli/arborist/package.json b/node_modules/@npmcli/arborist/package.json index bd27e4bbffa20..138d6ec25b4c2 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.3", + "version": "2.6.4", "description": "Manage node_modules trees", "dependencies": { "@npmcli/installed-package-contents": "^1.0.7", @@ -9,6 +9,7 @@ "@npmcli/move-file": "^1.1.0", "@npmcli/name-from-folder": "^1.0.1", "@npmcli/node-gyp": "^1.0.1", + "@npmcli/package-json": "^1.0.1", "@npmcli/run-script": "^1.8.2", "bin-links": "^2.2.1", "cacache": "^15.0.3", diff --git a/package-lock.json b/package-lock.json index 2ba8b8c612061..06ddc8604c53c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -83,7 +83,7 @@ "packages/*" ], "dependencies": { - "@npmcli/arborist": "^2.6.3", + "@npmcli/arborist": "^2.6.4", "@npmcli/ci-detect": "^1.2.0", "@npmcli/config": "^2.2.0", "@npmcli/package-json": "^1.0.1", @@ -735,9 +735,9 @@ } }, "node_modules/@npmcli/arborist": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.3.tgz", - "integrity": "sha512-R8U2dZ8+jeE7go+qNU4Mt6aiXyBu3mM75iRIugNCA4P0OWlsLOpuDPPhsaRcOVbtXheOGZXrqe36qP1g+M68KQ==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.4.tgz", + "integrity": "sha512-A/pDQ/VZpdxaqsQS5XOWrhrPuC+ER7HLq+4ZkEmnO2yo/USFCWEsiUPYKhfY+sWXK3pgKjN7B7CEFmAnSoAt3g==", "inBundle": true, "dependencies": { "@npmcli/installed-package-contents": "^1.0.7", @@ -746,6 +746,7 @@ "@npmcli/move-file": "^1.1.0", "@npmcli/name-from-folder": "^1.0.1", "@npmcli/node-gyp": "^1.0.1", + "@npmcli/package-json": "^1.0.1", "@npmcli/run-script": "^1.8.2", "bin-links": "^2.2.1", "cacache": "^15.0.3", @@ -10868,9 +10869,9 @@ "dev": true }, "@npmcli/arborist": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.3.tgz", - "integrity": "sha512-R8U2dZ8+jeE7go+qNU4Mt6aiXyBu3mM75iRIugNCA4P0OWlsLOpuDPPhsaRcOVbtXheOGZXrqe36qP1g+M68KQ==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.6.4.tgz", + "integrity": "sha512-A/pDQ/VZpdxaqsQS5XOWrhrPuC+ER7HLq+4ZkEmnO2yo/USFCWEsiUPYKhfY+sWXK3pgKjN7B7CEFmAnSoAt3g==", "requires": { "@npmcli/installed-package-contents": "^1.0.7", "@npmcli/map-workspaces": "^1.0.2", @@ -10878,6 +10879,7 @@ "@npmcli/move-file": "^1.1.0", "@npmcli/name-from-folder": "^1.0.1", "@npmcli/node-gyp": "^1.0.1", + "@npmcli/package-json": "^1.0.1", "@npmcli/run-script": "^1.8.2", "bin-links": "^2.2.1", "cacache": "^15.0.3", diff --git a/package.json b/package.json index 7a181b85f7f41..f6b5ff652cd50 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "./package.json": "./package.json" }, "dependencies": { - "@npmcli/arborist": "^2.6.3", + "@npmcli/arborist": "^2.6.4", "@npmcli/ci-detect": "^1.2.0", "@npmcli/config": "^2.2.0", "@npmcli/package-json": "^1.0.1",