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

Function applyDenyForPackage

lib/utils/allow-scripts-writer.js:325–353  ·  view source on GitHub ↗
(existing, nodes)

Source from the content-addressed store, hash-verified

323
324// Apply a deny for a single package. Always name-only; ignores `--allow-scripts-pin`.
325const 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
355module.exports = {
356 applyApprovalForPackage,

Callers 2

writePolicyChangesMethod · 0.85

Calls 3

nameKeyForFunction · 0.85
keyTargetsNodeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected