1const path = require('path') 2 3const log = require('../utils/log-shim.js') 4 5const reifyFinish = require('../utils/reify-finish.js') 6 7const ArboristWorkspaceCmd = require('../arborist-cmd.js') 8class Update extends ArboristWorkspaceCmd { 9 static description = 'Update packages' 10 static name = 'update' 11 12 static params = [ 13 'save', 14 'global', 15 'install-strategy', 16 'legacy-bundling', 17 'global-style', 18 'omit', 19 'strict-peer-deps', 20 'package-lock', 21 'foreground-scripts', 22 'ignore-scripts', 23 'audit', 24 'bin-links', 25 'fund', 26 'dry-run', 27 ...super.params, 28 ] 29 30 static usage = ['[<pkg>...]'] 31 32 // TODO 33 /* istanbul ignore next */ 34 static async completion (opts, npm) { 35 const completion = require('../utils/completion/installed-deep.js') 36 return completion(npm, opts) 37 } 38 39 async exec (args) { 40 const update = args.length === 0 ? true : args 41 const global = path.resolve(this.npm.globalDir, '..') 42 const where = this.npm.global ? global : this.npm.prefix 43 44 // In the context of `npm update` the save 45 // config value should default to `false` 46 const save = this.npm.config.isDefault('save') 47 ? false 48 : this.npm.config.get('save') 49 50 if (this.npm.config.get('depth')) { 51 log.warn('update', 'The --depth option no longer has any effect. See RFC0019.\n' + 52 'https://github.com/npm/rfcs/blob/latest/implemented/0019-remove-update-depth-option.md') 53 } 54 55 const Arborist = require('@npmcli/arborist') 56 const opts = { 57 ...this.npm.flatOptions, 58 path: where, 59 save, 60 workspaces: this.workspaceNames, 61 } 62 const arb = new Arborist(opts) 63 64 await arb.reify({ ...opts, update }) 65 await reifyFinish(this.npm, arb) 66 } 67} 68module.exports = Update 69