(groups)
| 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) { |
no test coverage detected