update.js 1.7 KB

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