(npm, spec, version, current)
| 16 | |
| 17 | // Actual check for updates. This is a separate function so that we only load this if we are doing the actual update |
| 18 | const updateCheck = async (npm, spec, version, current) => { |
| 19 | const pacote = require('pacote') |
| 20 | |
| 21 | const mani = await pacote.manifest(`npm@${spec}`, { |
| 22 | // always prefer latest, even if doing --tag=whatever on the cmd |
| 23 | defaultTag: 'latest', |
| 24 | ...npm.flatOptions, |
| 25 | cache: false, |
| 26 | }).catch(() => null) |
| 27 | |
| 28 | // if pacote failed, give up |
| 29 | if (!mani) { |
| 30 | return null |
| 31 | } |
| 32 | |
| 33 | const latest = mani.version |
| 34 | |
| 35 | // if the current version is *greater* than latest, we're on a 'next' and should get the updates from that release train. |
| 36 | // Note that this isn't another http request over the network, because the packument will be cached by pacote from previous request. |
| 37 | if (gt(version, latest) && spec === '*') { |
| 38 | return updateNotifier(npm, `^${version}`) |
| 39 | } |
| 40 | |
| 41 | // if we already have something >= the desired spec, then we're done |
| 42 | if (gte(version, latest)) { |
| 43 | return null |
| 44 | } |
| 45 | |
| 46 | const chalk = npm.logChalk |
| 47 | |
| 48 | // ok! notify the user about this update they should get. |
| 49 | // The message is saved for printing at process exit so it will not get lost in any other messages being printed as part of the command. |
| 50 | const update = parse(mani.version) |
| 51 | const type = update.major !== current.major ? 'major' |
| 52 | : update.minor !== current.minor ? 'minor' |
| 53 | : update.patch !== current.patch ? 'patch' |
| 54 | : 'prerelease' |
| 55 | const typec = type === 'major' ? 'red' |
| 56 | : type === 'minor' ? 'yellow' |
| 57 | : 'cyan' |
| 58 | const message = [ |
| 59 | '', |
| 60 | `New ${chalk[typec](type)} version of npm available! ${chalk[typec](current)} -> ${chalk.blue(latest)}`, |
| 61 | `Changelog: ${chalk.blue(`https://github.com/npm/cli/releases/tag/v${latest}`)}`, |
| 62 | `To update run: ${chalk.underline(`npm install -g npm@${latest}`)}`, |
| 63 | '', |
| 64 | ].join('\n') |
| 65 | |
| 66 | return message |
| 67 | } |
| 68 | |
| 69 | const updateNotifier = async (npm, spec = '*') => { |
| 70 | // if we're on a prerelease train, then updates are coming fast check for a new one daily. |
no test coverage detected
searching dependent graphs…