arborist-cmd.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const log = require('./utils/log-shim.js')
  2. // This is the base for all commands whose execWorkspaces just gets
  3. // a list of workspace names and passes it on to new Arborist() to
  4. // be able to run a filtered Arborist.reify() at some point.
  5. const BaseCommand = require('./base-command.js')
  6. class ArboristCmd extends BaseCommand {
  7. get isArboristCmd () {
  8. return true
  9. }
  10. static params = [
  11. 'workspace',
  12. 'workspaces',
  13. 'include-workspace-root',
  14. 'install-links',
  15. ]
  16. static workspaces = true
  17. static ignoreImplicitWorkspace = false
  18. constructor (npm) {
  19. super(npm)
  20. const { config } = this.npm
  21. // when location isn't set and global isn't true check for a package.json at
  22. // the localPrefix and set the location to project if found
  23. const locationProject = config.get('location') === 'project' || (
  24. config.isDefault('location')
  25. // this is different then `npm.global` which falls back to checking
  26. // location which we do not want to use here
  27. && !config.get('global')
  28. && npm.localPackage
  29. )
  30. // if audit is not set and we are in global mode and location is not project
  31. // and we assume its not a project related context, then we set audit=false
  32. if (config.isDefault('audit') && (this.npm.global || !locationProject)) {
  33. config.set('audit', false)
  34. } else if (this.npm.global && config.get('audit')) {
  35. log.warn('config', 'includes both --global and --audit, which is currently unsupported.')
  36. }
  37. }
  38. async execWorkspaces (args) {
  39. await this.setWorkspaces()
  40. return this.exec(args)
  41. }
  42. }
  43. module.exports = ArboristCmd