| 200 | |
| 201 | // Checks the devEngines entry in the package.json at this.localPrefix |
| 202 | async checkDevEngines () { |
| 203 | const force = this.npm.flatOptions.force |
| 204 | |
| 205 | const { devEngines } = await require('@npmcli/package-json') |
| 206 | .normalize(this.npm.config.localPrefix) |
| 207 | .then(p => p.content) |
| 208 | .catch(() => ({})) |
| 209 | |
| 210 | if (typeof devEngines === 'undefined') { |
| 211 | return |
| 212 | } |
| 213 | |
| 214 | const { checkDevEngines, currentEnv } = require('npm-install-checks') |
| 215 | const current = currentEnv.devEngines({ |
| 216 | nodeVersion: this.npm.nodeVersion, |
| 217 | npmVersion: this.npm.version, |
| 218 | }) |
| 219 | |
| 220 | const failures = checkDevEngines(devEngines, current) |
| 221 | const warnings = failures.filter(f => f.isWarn) |
| 222 | const errors = failures.filter(f => f.isError) |
| 223 | |
| 224 | const genMsg = (failure, i = 0) => { |
| 225 | return [...new Set([ |
| 226 | // eslint-disable-next-line |
| 227 | i === 0 ? 'The developer of this package has specified the following through devEngines' : '', |
| 228 | `${failure.message}`, |
| 229 | `${failure.errors.map(e => e.message).join('\n')}`, |
| 230 | ])].filter(v => v).join('\n') |
| 231 | } |
| 232 | |
| 233 | [...warnings, ...(force ? errors : [])].forEach((failure, i) => { |
| 234 | const message = genMsg(failure, i) |
| 235 | log.warn('EBADDEVENGINES', message) |
| 236 | log.warn('EBADDEVENGINES', { |
| 237 | current: failure.current, |
| 238 | required: failure.required, |
| 239 | }) |
| 240 | }) |
| 241 | |
| 242 | if (force) { |
| 243 | return |
| 244 | } |
| 245 | |
| 246 | if (errors.length) { |
| 247 | const failure = errors[0] |
| 248 | const message = genMsg(failure) |
| 249 | throw Object.assign(new Error(message), { |
| 250 | engine: failure.engine, |
| 251 | code: 'EBADDEVENGINES', |
| 252 | current: failure.current, |
| 253 | required: failure.required, |
| 254 | }) |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | async setWorkspaces () { |
| 259 | const { relative } = require('node:path') |