Skip to content

Commit

Permalink
fix: ignore implict workspace for some commands (#4479)
Browse files Browse the repository at this point in the history
Closes #4404

Special thanks to @mshima for submitting a similar PR #4439
  • Loading branch information
fritzy authored Mar 2, 2022
1 parent defe79a commit 45fc297
Show file tree
Hide file tree
Showing 56 changed files with 191 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/arborist-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ArboristCmd extends BaseCommand {
'include-workspace-root',
]

static ignoreImplicitWorkspace = false

async execWorkspaces (args, filters) {
await this.setWorkspaces(filters)
return this.exec(args)
Expand Down
4 changes: 4 additions & 0 deletions lib/base-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class BaseCommand {
return this.constructor.description
}

get ignoreImplicitWorkspace () {
return this.constructor.ignoreImplicitWorkspace
}

get usage () {
let usage = `npm ${this.constructor.name}\n\n`
if (this.constructor.description) {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Access extends BaseCommand {
'otp',
]

static ignoreImplicitWorkspace = true

static usage = [
'public [<package>]',
'restricted [<package>]',
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/adduser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class AddUser extends BaseCommand {
'scope',
]

static ignoreImplicitWorkspace = true

async exec (args) {
const { scope } = this.npm.flatOptions
const registry = this.getRegistry(this.npm.flatOptions)
Expand Down
1 change: 1 addition & 0 deletions lib/commands/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Bin extends BaseCommand {
static description = 'Display npm bin folder'
static name = 'bin'
static params = ['global']
static ignoreImplicitWorkspace = true

async exec (args) {
const b = this.npm.bin
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/birthday.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const BaseCommand = require('../base-command.js')

class Birthday extends BaseCommand {
static name = 'birthday'
static ignoreImplicitWorkspace = true

async exec () {
this.npm.config.set('yes', true)
return this.npm.exec('exec', ['@npmcli/npm-birthday'])
Expand Down
1 change: 1 addition & 0 deletions lib/commands/bugs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Bugs extends BaseCommand {
static name = 'bugs'
static usage = ['[<pkgname>]']
static params = ['browser', 'registry']
static ignoreImplicitWorkspace = true

async exec (args) {
if (!args || !args.length) {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class Cache extends BaseCommand {
'verify',
]

static ignoreImplicitWorkspace = true

async completion (opts) {
const argv = opts.conf.argv.remain
if (argv.length === 2) {
Expand Down
1 change: 1 addition & 0 deletions lib/commands/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const BaseCommand = require('../base-command.js')
class Completion extends BaseCommand {
static description = 'Tab Completion for npm'
static name = 'completion'
static ignoreImplicitWorkspace = false

// completion for the completion command
async completion (opts) {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Config extends BaseCommand {
'long',
]

static ignoreImplicitWorkspace = false

async completion (opts) {
const argv = opts.conf.argv.remain
if (argv[1] !== 'config') {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Deprecate extends BaseCommand {
'otp',
]

static ignoreImplicitWorkspace = false

async completion (opts) {
if (opts.conf.argv.remain.length > 1) {
return []
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Diff extends BaseCommand {
'include-workspace-root',
]

static ignoreImplicitWorkspace = false

async exec (args) {
const specs = this.npm.config.get('diff').filter(d => d)
if (specs.length > 2) {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/dist-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class DistTag extends BaseCommand {
'ls [<pkg>]',
]

static ignoreImplicitWorkspace = false

async completion (opts) {
const argv = opts.conf.argv.remain
if (argv.length === 2) {
Expand Down
1 change: 1 addition & 0 deletions lib/commands/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Docs extends BaseCommand {
]

static usage = ['[<pkgname> [<pkgname> ...]]']
static ignoreImplicitWorkspace = false

async exec (args) {
if (!args || !args.length) {
Expand Down
1 change: 1 addition & 0 deletions lib/commands/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Doctor extends BaseCommand {
static description = 'Check your npm environment'
static name = 'doctor'
static params = ['registry']
static ignoreImplicitWorkspace = false

async exec (args) {
log.info('Running checkup')
Expand Down
1 change: 1 addition & 0 deletions lib/commands/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Edit extends BaseCommand {
static name = 'edit'
static usage = ['<pkg>[/<subpkg>...]']
static params = ['editor']
static ignoreImplicitWorkspace = false

// TODO
/* istanbul ignore next */
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Exec extends BaseCommand {
'--package=foo -c \'<cmd> [args...]\'',
]

static ignoreImplicitWorkspace = false

async exec (_args, { locationMsg, path, runPath } = {}) {
if (!path) {
path = this.npm.localPrefix
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/explain.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Explain extends ArboristWorkspaceCmd {
'workspace',
]

static ignoreImplicitWorkspace = false

// TODO
/* istanbul ignore next */
async completion (opts) {
Expand Down
1 change: 1 addition & 0 deletions lib/commands/explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Explore extends BaseCommand {
static name = 'explore'
static usage = ['<pkg> [ -- <command>]']
static params = ['shell']
static ignoreImplicitWorkspace = false

// TODO
/* istanbul ignore next */
Expand Down
1 change: 1 addition & 0 deletions lib/commands/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Get extends BaseCommand {
static description = 'Get a value from the npm configuration'
static name = 'get'
static usage = ['[<key> ...] (See `npm config`)']
static ignoreImplicitWorkspace = false

// TODO
/* istanbul ignore next */
Expand Down
1 change: 1 addition & 0 deletions lib/commands/help-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class HelpSearch extends BaseCommand {
static name = 'help-search'
static usage = ['<text>']
static params = ['long']
static ignoreImplicitWorkspace = true

async exec (args) {
if (!args.length) {
Expand Down
1 change: 1 addition & 0 deletions lib/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Help extends BaseCommand {
static name = 'help'
static usage = ['<term> [<terms..>]']
static params = ['viewer']
static ignoreImplicitWorkspace = true

async completion (opts) {
if (opts.conf.argv.remain.length > 2) {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Hook extends BaseCommand {
'update <id> <url> <secret>',
]

static ignoreImplicitWorkspace = true

async exec (args) {
return otplease({
...this.npm.flatOptions,
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Init extends BaseCommand {
'[<@scope>/]<name> (same as `npx [<@scope>/]create-<name>`)',
]

static ignoreImplicitWorkspace = false

async exec (args) {
// npm exec style
if (args.length) {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Logout extends BaseCommand {
'scope',
]

static ignoreImplicitWorkspace = true

async exec (args) {
const registry = this.npm.config.get('registry')
const scope = this.npm.config.get('scope')
Expand Down
1 change: 1 addition & 0 deletions lib/commands/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Org extends BaseCommand {
]

static params = ['registry', 'otp', 'json', 'parseable']
static ignoreImplicitWorkspace = true

async completion (opts) {
const argv = opts.conf.argv.remain
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Owner extends BaseCommand {
'ls [<@scope>/]<pkg>',
]

static ignoreImplicitWorkspace = false

async completion (opts) {
const argv = opts.conf.argv.remain
if (argv.length > 3) {
Expand Down
1 change: 1 addition & 0 deletions lib/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Pack extends BaseCommand {
]

static usage = ['[[<@scope>/]<pkg>...]']
static ignoreImplicitWorkspace = false

async exec (args) {
if (args.length === 0) {
Expand Down
1 change: 1 addition & 0 deletions lib/commands/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Ping extends BaseCommand {
static description = 'Ping npm registry'
static params = ['registry']
static name = 'ping'
static ignoreImplicitWorkspace = true

async exec (args) {
log.notice('PING', this.npm.config.get('registry'))
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Pkg extends BaseCommand {
'workspaces',
]

static ignoreImplicitWorkspace = false

async exec (args, { prefix } = {}) {
if (!prefix) {
this.prefix = this.npm.localPrefix
Expand Down
1 change: 1 addition & 0 deletions lib/commands/prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Prefix extends BaseCommand {
static name = 'prefix'
static params = ['global']
static usage = ['[-g]']
static ignoreImplicitWorkspace = true

async exec (args) {
return this.npm.output(this.npm.prefix)
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Profile extends BaseCommand {
'otp',
]

static ignoreImplicitWorkspace = true

async completion (opts) {
var argv = opts.conf.argv.remain

Expand Down
1 change: 1 addition & 0 deletions lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Publish extends BaseCommand {
]

static usage = ['[<folder>]']
static ignoreImplicitWorkspace = false

async exec (args) {
if (args.length === 0) {
Expand Down
1 change: 1 addition & 0 deletions lib/commands/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Repo extends BaseCommand {
static name = 'repo'
static params = ['browser', 'workspace', 'workspaces', 'include-workspace-root']
static usage = ['[<pkgname> [<pkgname> ...]]']
static ignoreImplicitWorkspace = false

async exec (args) {
if (!args || !args.length) {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/restart.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ class Restart extends LifecycleCmd {
'ignore-scripts',
'script-shell',
]

static ignoreImplicitWorkspace = false
}
module.exports = Restart
1 change: 1 addition & 0 deletions lib/commands/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Root extends BaseCommand {
static description = 'Display npm root'
static name = 'root'
static params = ['global']
static ignoreImplicitWorkspace = true

async exec () {
this.npm.output(this.npm.dir)
Expand Down
1 change: 1 addition & 0 deletions lib/commands/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RunScript extends BaseCommand {

static name = 'run-script'
static usage = ['<command> [-- <args>]']
static ignoreImplicitWorkspace = false

async completion (opts) {
const argv = opts.conf.argv.remain
Expand Down
1 change: 1 addition & 0 deletions lib/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Search extends BaseCommand {
]

static usage = ['[search terms ...]']
static ignoreImplicitWorkspace = true

async exec (args) {
const opts = {
Expand Down
1 change: 1 addition & 0 deletions lib/commands/set-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SetScript extends BaseCommand {
static params = ['workspace', 'workspaces', 'include-workspace-root']
static name = 'set-script'
static usage = ['[<script>] [<command>]']
static ignoreImplicitWorkspace = false

async completion (opts) {
const argv = opts.conf.argv.remain
Expand Down
1 change: 1 addition & 0 deletions lib/commands/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Set extends BaseCommand {
static description = 'Set a value in the npm configuration'
static name = 'set'
static usage = ['<key>=<value> [<key>=<value> ...] (See `npm config`)']
static ignoreImplicitWorkspace = false

// TODO
/* istanbul ignore next */
Expand Down
1 change: 1 addition & 0 deletions lib/commands/shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const BaseCommand = require('../base-command.js')
class Shrinkwrap extends BaseCommand {
static description = 'Lock down dependency versions for publication'
static name = 'shrinkwrap'
static ignoreImplicitWorkspace = false

async exec () {
// if has a npm-shrinkwrap.json, nothing to do
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/star.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Star extends BaseCommand {
'unicode',
]

static ignoreImplicitWorkspace = false

async exec (args) {
if (!args.length) {
throw this.usageError()
Expand Down
1 change: 1 addition & 0 deletions lib/commands/stars.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Stars extends BaseCommand {
static name = 'stars'
static usage = ['[<user>]']
static params = ['registry']
static ignoreImplicitWorkspace = false

async exec ([user]) {
try {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ class Start extends LifecycleCmd {
'ignore-scripts',
'script-shell',
]

static ignoreImplicitWorkspace = false
}
module.exports = Start
2 changes: 2 additions & 0 deletions lib/commands/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ class Stop extends LifecycleCmd {
'ignore-scripts',
'script-shell',
]

static ignoreImplicitWorkspace = false
}
module.exports = Stop
2 changes: 2 additions & 0 deletions lib/commands/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Team extends BaseCommand {
'json',
]

static ignoreImplicitWorkspace = false

async completion (opts) {
const { conf: { argv: { remain: argv } } } = opts
const subcommands = ['create', 'destroy', 'add', 'rm', 'ls']
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ class Test extends LifecycleCmd {
'ignore-scripts',
'script-shell',
]

static ignoreImplicitWorkspace = false
}
module.exports = Test
Loading

0 comments on commit 45fc297

Please sign in to comment.