From 0c18e4f774562fa054fedf323bea25805ebf39b3 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Thu, 13 May 2021 12:24:39 -0400 Subject: [PATCH] @npmcli/arborist@2.5.0 --- .../@npmcli/arborist/lib/arborist/index.js | 23 +++++++++++++ .../arborist/lib/get-workspace-nodes.js | 33 +++++++++++++++++++ node_modules/@npmcli/arborist/package.json | 2 +- package-lock.json | 14 ++++---- package.json | 2 +- 5 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 node_modules/@npmcli/arborist/lib/get-workspace-nodes.js diff --git a/node_modules/@npmcli/arborist/lib/arborist/index.js b/node_modules/@npmcli/arborist/lib/arborist/index.js index 3578d50389ea6..cd39df01af6c6 100644 --- a/node_modules/@npmcli/arborist/lib/arborist/index.js +++ b/node_modules/@npmcli/arborist/lib/arborist/index.js @@ -45,6 +45,7 @@ const mixins = [ ] const Base = mixins.reduce((a, b) => b(a), require('events')) +const getWorkspaceNodes = require('../get-workspace-nodes.js') class Arborist extends Base { constructor (options = {}) { @@ -64,6 +65,28 @@ class Arborist extends Base { this.path = resolve(this.options.path) process.emit('timeEnd', 'arborist:ctor') } + + // returns an array of the actual nodes for all the workspaces + workspaceNodes (tree, workspaces) { + return getWorkspaceNodes(tree, workspaces, this.log) + } + + // returns a set of workspace nodes and all their deps + workspaceDependencySet (tree, workspaces) { + const wsNodes = this.workspaceNodes(tree, workspaces) + const set = new Set(wsNodes) + for (const node of set) { + for (const edge of node.edgesOut.values()) { + const dep = edge.to + if (dep) { + set.add(dep) + if (dep.target) + set.add(dep.target) + } + } + } + return set + } } module.exports = Arborist diff --git a/node_modules/@npmcli/arborist/lib/get-workspace-nodes.js b/node_modules/@npmcli/arborist/lib/get-workspace-nodes.js new file mode 100644 index 0000000000000..6db489f69c518 --- /dev/null +++ b/node_modules/@npmcli/arborist/lib/get-workspace-nodes.js @@ -0,0 +1,33 @@ +// Get the actual nodes corresponding to a root node's child workspaces, +// given a list of workspace names. +const relpath = require('./relpath.js') +const getWorkspaceNodes = (tree, workspaces, log) => { + const wsMap = tree.workspaces + if (!wsMap) { + log.warn('workspaces', 'filter set, but no workspaces present') + return [] + } + + const nodes = [] + for (const name of workspaces) { + const path = wsMap.get(name) + if (!path) { + log.warn('workspaces', `${name} in filter set, but not in workspaces`) + continue + } + + const loc = relpath(tree.realpath, path) + const node = tree.inventory.get(loc) + + if (!node) { + log.warn('workspaces', `${name} in filter set, but no workspace folder present`) + continue + } + + nodes.push(node) + } + + return nodes +} + +module.exports = getWorkspaceNodes diff --git a/node_modules/@npmcli/arborist/package.json b/node_modules/@npmcli/arborist/package.json index bbe87d8bf97ad..fd579cbf27fdc 100644 --- a/node_modules/@npmcli/arborist/package.json +++ b/node_modules/@npmcli/arborist/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/arborist", - "version": "2.4.4", + "version": "2.5.0", "description": "Manage node_modules trees", "dependencies": { "@npmcli/installed-package-contents": "^1.0.7", diff --git a/package-lock.json b/package-lock.json index 26d2536dcf081..8b03fb6e2cf71 100644 --- a/package-lock.json +++ b/package-lock.json @@ -78,7 +78,7 @@ ], "license": "Artistic-2.0", "dependencies": { - "@npmcli/arborist": "^2.4.4", + "@npmcli/arborist": "^2.5.0", "@npmcli/ci-detect": "^1.2.0", "@npmcli/config": "^2.2.0", "@npmcli/run-script": "^1.8.5", @@ -712,9 +712,9 @@ } }, "node_modules/@npmcli/arborist": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.4.4.tgz", - "integrity": "sha512-mqZvcPCWT6gSSYxs08aKvXmECXh9fP85q1pUIY/jDkaQ58QTRy6F7XrUQr7F77jXpYfpYKPUi6RhpuSpOXCITA==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.5.0.tgz", + "integrity": "sha512-YPSkV/8vofpbAJyeu52J12YnC5VTkYIcfcNkRoSW6qjfQG+QybgbJtCbcdx+M0YxfdzDKS6iDTjpNMoETZ8HOA==", "inBundle": true, "dependencies": { "@npmcli/installed-package-contents": "^1.0.7", @@ -10823,9 +10823,9 @@ "dev": true }, "@npmcli/arborist": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.4.4.tgz", - "integrity": "sha512-mqZvcPCWT6gSSYxs08aKvXmECXh9fP85q1pUIY/jDkaQ58QTRy6F7XrUQr7F77jXpYfpYKPUi6RhpuSpOXCITA==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@npmcli/arborist/-/arborist-2.5.0.tgz", + "integrity": "sha512-YPSkV/8vofpbAJyeu52J12YnC5VTkYIcfcNkRoSW6qjfQG+QybgbJtCbcdx+M0YxfdzDKS6iDTjpNMoETZ8HOA==", "requires": { "@npmcli/installed-package-contents": "^1.0.7", "@npmcli/map-workspaces": "^1.0.2", diff --git a/package.json b/package.json index 70f94838882b7..9ac34d43b9bca 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "./package.json": "./package.json" }, "dependencies": { - "@npmcli/arborist": "^2.4.4", + "@npmcli/arborist": "^2.5.0", "@npmcli/ci-detect": "^1.2.0", "@npmcli/config": "^2.2.0", "@npmcli/run-script": "^1.8.5",