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