MCPcopy Create free account
hub / github.com/npm/cli / findNodesForArgs

Method findNodesForArgs

lib/utils/allow-scripts-cmd.js:218–249  ·  view source on GitHub ↗
(args, arb)

Source from the content-addressed store, hash-verified

216 }
217
218 findNodesForArgs (args, arb) {
219 // Match positional args against each node's trusted name. Registry deps
220 // use the URL-derived name; non-registry deps fall back to the dependency
221 // edge name. A version or range on the arg narrows the match to installed
222 // versions that satisfy it. Bundled deps are excluded for the same reason
223 // as --all. Args that match nothing are returned in `unmatched`.
224 const matched = []
225 const unmatched = []
226 for (const arg of args) {
227 const { name: wantName, range } = parsePositional(arg)
228 const found = []
229 for (const node of arb.actualTree.inventory.values()) {
230 if (node.isProjectRoot || node.isWorkspace || node.inBundle) {
231 continue
232 }
233 const { name, version } = trustedDisplay(node)
234 if (!name || name !== wantName) {
235 continue
236 }
237 if (range && (!version || !semver.satisfies(version, range, { loose: true }))) {
238 continue
239 }
240 found.push(node)
241 }
242 if (found.length === 0) {
243 unmatched.push(arg)
244 } else {
245 matched.push(...found)
246 }
247 }
248 return { matched, unmatched }
249 }
250
251 get logTitle () {
252 return this.constructor.name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()

Callers 1

runPositionalMethod · 0.95

Calls 4

parsePositionalFunction · 0.85
trustedDisplayFunction · 0.85
satisfiesMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected