(allowScripts, nodes)
| 14 | // Unparseable keys are kept (prune never drops what it can't parse). Both |
| 15 | // `true` (approve) and `false` (deny) entries are pruned. |
| 16 | const 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 | |
| 47 | module.exports = { classifyUnusedEntries } |
no test coverage detected