arborist-cmd.js 1.6 KB

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