update.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const path = require('path')
  2. const Arborist = require('@npmcli/arborist')
  3. const log = require('npmlog')
  4. const reifyFinish = require('./utils/reify-finish.js')
  5. const completion = require('./utils/completion/installed-deep.js')
  6. const ArboristWorkspaceCmd = require('./workspaces/arborist-cmd.js')
  7. class Update extends ArboristWorkspaceCmd {
  8. /* istanbul ignore next - see test/lib/load-all-commands.js */
  9. static get description () {
  10. return 'Update packages'
  11. }
  12. /* istanbul ignore next - see test/lib/load-all-commands.js */
  13. static get name () {
  14. return 'update'
  15. }
  16. /* istanbul ignore next - see test/lib/load-all-commands.js */
  17. static get params () {
  18. return [
  19. 'global',
  20. 'global-style',
  21. 'legacy-bundling',
  22. 'strict-peer-deps',
  23. 'package-lock',
  24. 'omit',
  25. 'ignore-scripts',
  26. 'audit',
  27. 'bin-links',
  28. 'fund',
  29. 'dry-run',
  30. ...super.params,
  31. ]
  32. }
  33. /* istanbul ignore next - see test/lib/load-all-commands.js */
  34. static get usage () {
  35. return ['[<pkg>...]']
  36. }
  37. /* istanbul ignore next - see test/lib/load-all-commands.js */
  38. async completion (opts) {
  39. return completion(this.npm, opts)
  40. }
  41. exec (args, cb) {
  42. this.update(args).then(() => cb()).catch(cb)
  43. }
  44. async update (args) {
  45. const update = args.length === 0 ? true : args
  46. const global = path.resolve(this.npm.globalDir, '..')
  47. const where = this.npm.config.get('global')
  48. ? global
  49. : this.npm.prefix
  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. const arb = new Arborist({
  55. ...this.npm.flatOptions,
  56. log: this.npm.log,
  57. path: where,
  58. workspaces: this.workspaceNames,
  59. })
  60. await arb.reify({ update })
  61. await reifyFinish(this.npm, arb)
  62. }
  63. }
  64. module.exports = Update