(args)
| 103 | } |
| 104 | |
| 105 | async exec (args) { |
| 106 | // the /path/to/node_modules/.. |
| 107 | const globalTop = resolve(this.npm.globalDir, '..') |
| 108 | const ignoreScripts = this.npm.config.get('ignore-scripts') |
| 109 | const isGlobalInstall = this.npm.global |
| 110 | const where = isGlobalInstall ? globalTop : this.npm.prefix |
| 111 | const forced = this.npm.config.get('force') |
| 112 | const scriptShell = this.npm.config.get('script-shell') || undefined |
| 113 | |
| 114 | // be very strict about engines when trying to update npm itself |
| 115 | const npmInstall = args.find(arg => arg.startsWith('npm@') || arg === 'npm') |
| 116 | if (isGlobalInstall && npmInstall) { |
| 117 | const npmOptions = this.npm.flatOptions |
| 118 | const npmManifest = await pacote.manifest(npmInstall, npmOptions) |
| 119 | try { |
| 120 | checks.checkEngine(npmManifest, npmManifest.version, process.version) |
| 121 | } catch (e) { |
| 122 | if (forced) { |
| 123 | log.warn( |
| 124 | 'install', |
| 125 | `Forcing global npm install with incompatible version ${npmManifest.version} into node ${process.version}` |
| 126 | ) |
| 127 | } else { |
| 128 | throw e |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // don't try to install the prefix into itself |
| 134 | args = args.filter(a => resolve(a) !== this.npm.prefix) |
| 135 | |
| 136 | // `npm i -g` => "install this package globally" |
| 137 | if (isGlobalInstall && !args.length) { |
| 138 | args = ['.'] |
| 139 | } |
| 140 | |
| 141 | // throw usage error if trying to install empty package name to global space, e.g: `npm i -g ""` |
| 142 | if (where === globalTop && !args.every(Boolean)) { |
| 143 | throw this.usageError() |
| 144 | } |
| 145 | |
| 146 | const Arborist = require('@npmcli/arborist') |
| 147 | const { policy: allowScriptsPolicy } = await resolveAllowScripts(this.npm) |
| 148 | const opts = { |
| 149 | ...this.npm.flatOptions, |
| 150 | auditLevel: null, |
| 151 | path: where, |
| 152 | add: args, |
| 153 | workspaces: this.workspaceNames, |
| 154 | allowScripts: allowScriptsPolicy, |
| 155 | } |
| 156 | const arb = new Arborist(opts) |
| 157 | await strictAllowScriptsPreflight({ arb, npm: this.npm, idealTreeOpts: opts }) |
| 158 | await arb.reify(opts) |
| 159 | |
| 160 | if (!args.length && !isGlobalInstall && !ignoreScripts) { |
| 161 | const scripts = [ |
| 162 | 'preinstall', |
nothing calls this directly
no test coverage detected