2020-10-02 17:52:19 -04:00
|
|
|
const path = require('path')
|
2011-11-21 09:48:45 -08:00
|
|
|
|
2020-12-04 15:51:55 -05:00
|
|
|
const Arborist = require('@npmcli/arborist')
|
2017-12-07 14:05:23 -08:00
|
|
|
const log = require('npmlog')
|
2020-12-04 15:51:55 -05:00
|
|
|
|
2020-11-17 15:37:44 -05:00
|
|
|
const reifyFinish = require('./utils/reify-finish.js')
|
2020-10-02 17:52:19 -04:00
|
|
|
const completion = require('./utils/completion/installed-deep.js')
|
2016-05-06 15:22:02 -07:00
|
|
|
|
2021-03-11 17:54:23 -05:00
|
|
|
const BaseCommand = require('./base-command.js')
|
|
|
|
class Update extends BaseCommand {
|
2021-03-23 14:58:11 -04:00
|
|
|
/* istanbul ignore next - see test/lib/load-all-commands.js */
|
|
|
|
static get description () {
|
|
|
|
return 'Update packages'
|
|
|
|
}
|
|
|
|
|
2021-03-11 17:54:23 -05:00
|
|
|
/* istanbul ignore next - see test/lib/load-all-commands.js */
|
|
|
|
static get name () {
|
|
|
|
return 'update'
|
2021-03-04 17:40:28 -05:00
|
|
|
}
|
2011-11-21 09:48:45 -08:00
|
|
|
|
2021-03-23 14:58:11 -04:00
|
|
|
/* istanbul ignore next - see test/lib/load-all-commands.js */
|
|
|
|
static get params () {
|
|
|
|
return ['global']
|
|
|
|
}
|
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
/* istanbul ignore next - see test/lib/load-all-commands.js */
|
2021-03-11 17:54:23 -05:00
|
|
|
static get usage () {
|
2021-03-23 14:58:11 -04:00
|
|
|
return ['[<pkg>...]']
|
2021-03-04 17:40:28 -05:00
|
|
|
}
|
2015-03-13 02:07:27 -07:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
/* istanbul ignore next - see test/lib/load-all-commands.js */
|
|
|
|
async completion (opts) {
|
|
|
|
return completion(this.npm, opts)
|
2020-10-02 17:52:19 -04:00
|
|
|
}
|
2017-12-07 14:05:23 -08:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
exec (args, cb) {
|
|
|
|
this.update(args).then(() => cb()).catch(cb)
|
|
|
|
}
|
2020-10-02 17:52:19 -04:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
async update (args) {
|
|
|
|
const update = args.length === 0 ? true : args
|
|
|
|
const global = path.resolve(this.npm.globalDir, '..')
|
2021-03-23 14:58:11 -04:00
|
|
|
const where = this.npm.config.get('global')
|
2021-03-04 17:40:28 -05:00
|
|
|
? global
|
|
|
|
: this.npm.prefix
|
|
|
|
|
2021-03-23 14:58:11 -04:00
|
|
|
if (this.npm.config.get('depth')) {
|
2021-03-04 17:40:28 -05:00
|
|
|
log.warn('update', 'The --depth option no longer has any effect. See RFC0019.\n' +
|
|
|
|
'https://github.com/npm/rfcs/blob/latest/implemented/0019-remove-update-depth-option.md')
|
|
|
|
}
|
|
|
|
|
|
|
|
const arb = new Arborist({
|
|
|
|
...this.npm.flatOptions,
|
2021-03-24 17:25:32 -04:00
|
|
|
log: this.npm.log,
|
2021-03-04 17:40:28 -05:00
|
|
|
path: where,
|
|
|
|
})
|
|
|
|
|
|
|
|
await arb.reify({ update })
|
|
|
|
await reifyFinish(this.npm, arb)
|
|
|
|
}
|
2011-11-21 09:48:45 -08:00
|
|
|
}
|
2021-03-04 17:40:28 -05:00
|
|
|
module.exports = Update
|