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

Method writePolicyChanges

lib/utils/allow-scripts-cmd.js:275–306  ·  view source on GitHub ↗
(groups)

Source from the content-addressed store, hash-verified

273 }
274
275 async writePolicyChanges (groups) {
276 const pin = this.npm.config.get('allow-scripts-pin') !== false
277
278 const pkg = await pkgJson.load(this.npm.prefix)
279 const content = pkg.content
280 const existing = content.allowScripts && typeof content.allowScripts === 'object'
281 ? content.allowScripts
282 : {}
283
284 let updated = existing
285 const summary = []
286
287 for (const [name, nodes] of Object.entries(groups)) {
288 const result = this.verb === 'approve'
289 ? applyApprovalForPackage(updated, nodes, { pin })
290 : applyDenyForPackage(updated, nodes)
291
292 if (result.warning) {
293 log.warn(this.logTitle, result.warning)
294 }
295 updated = result.allowScripts
296 summary.push({ name, changes: result.changes })
297 }
298
299 /* istanbul ignore else: writePolicyChanges only called when changes are expected */
300 if (updated !== existing) {
301 pkg.update({ allowScripts: updated })
302 await pkg.save()
303 }
304
305 this.printSummary(summary)
306 }
307
308 printSummary (summary) {
309 if (this.npm.flatOptions.json) {

Callers 2

runAllMethod · 0.95
runPositionalMethod · 0.95

Calls 9

printSummaryMethod · 0.95
applyApprovalForPackageFunction · 0.85
applyDenyForPackageFunction · 0.85
warnMethod · 0.80
pushMethod · 0.80
updateMethod · 0.80
getMethod · 0.45
loadMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected