Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
cli: shinier update-notifier
Browse files Browse the repository at this point in the history
This message is based on the one pnpm uses, which
I think takes care of all the false update messages and
missing -g that happens with the default notifier message.

It also tells people what "level" the update is.
  • Loading branch information
zkat committed Mar 21, 2018
1 parent bbe424b commit 9fbed3d
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions bin/npm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@

unsupported.checkForUnsupportedNode()

if (!unsupported.checkVersion(process.version).unsupported) {
var updater = require('update-notifier')
var pkg = require('../package.json')
updater({pkg: pkg}).notify({defer: true})
}

var path = require('path')
var npm = require('../lib/npm.js')
Expand Down Expand Up @@ -81,6 +76,50 @@
conf._exit = true
npm.load(conf, function (er) {
if (er) return errorHandler(er)
if (!unsupported.checkVersion(process.version).unsupported) {
const pkg = require('../package.json')
let notifier = require('update-notifier')({pkg})
if (
notifier.update &&
notifier.update.latest !== pkg.version
) {
const color = require('ansicolors')
const useColor = npm.config.get('color')
const useUnicode = npm.config.get('unicode')
const old = notifier.update.current
const latest = notifier.update.latest
let type = notifier.update.type
if (useColor) {
switch (type) {
case 'major':
type = color.red(type)
break
case 'minor':
type = color.yellow(type)
break
case 'patch':
type = color.green(type)
break
}
}
const changelog = `https://github.com/npm/npm/releases/tag/v${latest}`
notifier.notify({
message: `New ${type} version of npm available! ${
useColor ? color.red(old) : old
} ${useUnicode ? '→' : '->'} ${
useColor ? color.green(latest) : latest
}\n` +
`${
useColor ? color.yellow('Changelog:') : 'Changelog:'
} ${
useColor ? color.cyan(changelog + ':') : changelog + ':'
}\n` +
`Run ${
useColor ? color.green('npm install -g npm') : 'npm i -g npm'
} to update!`
})
}
}
npm.commands[npm.command](npm.argv, function (err) {
// https://www.youtube.com/watch?v=7nfPu8qTiQU
if (!err && npm.config.get('ham-it-up') && !npm.config.get('json') && !npm.config.get('parseable') && npm.command !== 'completion') {
Expand Down

0 comments on commit 9fbed3d

Please sign in to comment.