xref: /third_party/node/deps/npm/lib/commands/update.js (revision 1cb0ef41)
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    'include',
20    'strict-peer-deps',
21    'package-lock',
22    'foreground-scripts',
23    'ignore-scripts',
24    'audit',
25    'bin-links',
26    'fund',
27    'dry-run',
28    ...super.params,
29  ]
30
31  static usage = ['[<pkg>...]']
32
33  // TODO
34  /* istanbul ignore next */
35  static async completion (opts, npm) {
36    const completion = require('../utils/completion/installed-deep.js')
37    return completion(npm, opts)
38  }
39
40  async exec (args) {
41    const update = args.length === 0 ? true : args
42    const global = path.resolve(this.npm.globalDir, '..')
43    const where = this.npm.global ? global : this.npm.prefix
44
45    // In the context of `npm update` the save
46    // config value should default to `false`
47    const save = this.npm.config.isDefault('save')
48      ? false
49      : this.npm.config.get('save')
50
51    if (this.npm.config.get('depth')) {
52      log.warn('update', 'The --depth option no longer has any effect. See RFC0019.\n' +
53        'https://github.com/npm/rfcs/blob/latest/implemented/0019-remove-update-depth-option.md')
54    }
55
56    const Arborist = require('@npmcli/arborist')
57    const opts = {
58      ...this.npm.flatOptions,
59      path: where,
60      save,
61      workspaces: this.workspaceNames,
62    }
63    const arb = new Arborist(opts)
64
65    await arb.reify({ ...opts, update })
66    await reifyFinish(this.npm, arb)
67  }
68}
69module.exports = Update
70