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

Method exec

deps/npm/lib/utils/allow-scripts-cmd.js:57–103  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

55 }
56
57 async exec (args) {
58 if (this.npm.global) {
59 throw Object.assign(
60 new Error(`\`npm ${this.constructor.name}\` does not work for global installs`),
61 { code: 'EGLOBAL' }
62 )
63 }
64
65 const pending = !!this.npm.config.get('allow-scripts-pending')
66 const all = !!this.npm.config.get('all')
67
68 if (pending && (args.length > 0 || all)) {
69 throw this.usageError(
70 '`--allow-scripts-pending` cannot be combined with positional arguments or `--all`.'
71 )
72 }
73 if (!pending && !all && args.length === 0) {
74 throw this.usageError()
75 }
76 if (this.verb === 'deny' && pending) {
77 throw this.usageError('`npm deny-scripts --allow-scripts-pending` is not supported.')
78 }
79
80 const Arborist = require('@npmcli/arborist')
81 const { policy } = await resolveAllowScripts(this.npm)
82 const arb = new Arborist({
83 ...this.npm.flatOptions,
84 path: this.npm.prefix,
85 allowScripts: policy,
86 })
87 await arb.loadActual()
88
89 // Keep listing unreviewed packages even with ignore-scripts set, so
90 // you can move from a blanket ignore-scripts to an allowlist. This
91 // only lists; nothing runs.
92 const unreviewed = await checkAllowScripts({ arb, npm: this.npm, includeWhenIgnored: true })
93
94 if (pending) {
95 return this.runPending(unreviewed)
96 }
97
98 if (all) {
99 return this.runAll(unreviewed)
100 }
101
102 return this.runPositional(args, arb)
103 }
104
105 runPending (unreviewed) {
106 if (this.npm.flatOptions.json) {

Callers

nothing calls this directly

Calls 9

runPendingMethod · 0.95
runAllMethod · 0.95
runPositionalMethod · 0.95
resolveAllowScriptsFunction · 0.85
checkAllowScriptsFunction · 0.85
assignMethod · 0.80
usageErrorMethod · 0.80
getMethod · 0.65
requireFunction · 0.50

Tested by

no test coverage detected