MCPcopy Index your code
hub / github.com/nodejs/node / writePolicyChanges

Method writePolicyChanges

deps/npm/lib/utils/allow-scripts-cmd.js:247–278  ·  view source on GitHub ↗
(groups)

Source from the content-addressed store, hash-verified

245 }
246
247 async writePolicyChanges (groups) {
248 const pin = this.npm.config.get('allow-scripts-pin') !== false
249
250 const pkg = await pkgJson.load(this.npm.prefix)
251 const content = pkg.content
252 const existing = content.allowScripts && typeof content.allowScripts === 'object'
253 ? content.allowScripts
254 : {}
255
256 let updated = existing
257 const summary = []
258
259 for (const [name, nodes] of Object.entries(groups)) {
260 const result = this.verb === 'approve'
261 ? applyApprovalForPackage(updated, nodes, { pin })
262 : applyDenyForPackage(updated, nodes)
263
264 if (result.warning) {
265 log.warn(this.logTitle, result.warning)
266 }
267 updated = result.allowScripts
268 summary.push({ name, changes: result.changes })
269 }
270
271 /* istanbul ignore else: writePolicyChanges only called when changes are expected */
272 if (updated !== existing) {
273 pkg.update({ allowScripts: updated })
274 await pkg.save()
275 }
276
277 this.printSummary(summary)
278 }
279
280 printSummary (summary) {
281 if (this.npm.flatOptions.json) {

Callers 2

runAllMethod · 0.95
runPositionalMethod · 0.95

Calls 10

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

Tested by

no test coverage detected