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

Function classifyUnusedEntries

lib/utils/allow-scripts-prune.js:16–45  ·  view source on GitHub ↗
(allowScripts, nodes)

Source from the content-addressed store, hash-verified

14// Unparseable keys are kept (prune never drops what it can't parse). Both
15// `true` (approve) and `false` (deny) entries are pruned.
16const classifyUnusedEntries = (allowScripts, nodes) => {
17 const remaining = {}
18 const removed = []
19
20 for (const [key, value] of Object.entries(allowScripts || {})) {
21 let parseable = true
22 try {
23 npa(key)
24 } catch {
25 parseable = false
26 }
27 if (!parseable) {
28 remaining[key] = value
29 continue
30 }
31
32 const matching = nodes.filter(({ node }) => matches(node, key))
33 if (matching.length === 0) {
34 removed.push({ key, value, reason: 'not-installed' })
35 continue
36 }
37 if (!matching.some(({ hasScripts }) => hasScripts)) {
38 removed.push({ key, value, reason: 'no-scripts' })
39 continue
40 }
41 remaining[key] = value
42 }
43
44 return { remaining, removed }
45}
46
47module.exports = { classifyUnusedEntries }

Callers 2

runPruneMethod · 0.85

Calls 3

matchesFunction · 0.85
filterMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected