(existing, nodes)
| 323 | |
| 324 | // Apply a deny for a single package. Always name-only; ignores `--allow-scripts-pin`. |
| 325 | const applyDenyForPackage = (existing, nodes) => { |
| 326 | const allowScripts = { ...existing } |
| 327 | const changes = [] |
| 328 | |
| 329 | if (!Array.isArray(nodes) || nodes.length === 0) { |
| 330 | return { allowScripts, changes } |
| 331 | } |
| 332 | |
| 333 | const sample = nodes[0] |
| 334 | const name = nameKeyFor(sample) |
| 335 | if (!name) { |
| 336 | return { allowScripts, changes } |
| 337 | } |
| 338 | |
| 339 | // Drop any pinned allow entries for this package: the name-only deny |
| 340 | // overrides them anyway, and leaving them in place is confusing. |
| 341 | for (const key of Object.keys(allowScripts)) { |
| 342 | if (keyTargetsNode(key, sample) && key !== name) { |
| 343 | delete allowScripts[key] |
| 344 | changes.push({ key, change: 'removed-pinned-allow' }) |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | if (allowScripts[name] !== false) { |
| 349 | allowScripts[name] = false |
| 350 | changes.push({ key: name, change: 'added' }) |
| 351 | } |
| 352 | return { allowScripts, changes } |
| 353 | } |
| 354 | |
| 355 | module.exports = { |
| 356 | applyApprovalForPackage, |
no test coverage detected