diff --git a/lib/npm.js b/lib/npm.js index ace6ecf03a941..62be437fa003d 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -137,6 +137,9 @@ const npm = module.exports = new class extends EventEmitter { const workspacesEnabled = this.config.get('workspaces') const workspacesFilters = this.config.get('workspace') + if (workspacesEnabled === false && workspacesFilters.length > 0) + return cb(new Error('Can not use --no-workspaces and --workspace at the same time')) + const filterByWorkspaces = workspacesEnabled || workspacesFilters.length > 0 // normally this would go in the constructor, but our tests don't // actually use a real npm object so this.npm.config isn't always diff --git a/test/lib/npm.js b/test/lib/npm.js index 03bb46d8d8451..aa31147fa0fac 100644 --- a/test/lib/npm.js +++ b/test/lib/npm.js @@ -292,6 +292,44 @@ t.test('npm.load', t => { await new Promise((res) => setTimeout(res)) }) + t.test('--no-workspaces with --workspace', async t => { + const dir = t.testdir({ + packages: { + a: { + 'package.json': JSON.stringify({ + name: 'a', + version: '1.0.0', + scripts: { test: 'echo test a' }, + }), + }, + }, + 'package.json': JSON.stringify({ + name: 'root', + version: '1.0.0', + workspaces: ['./packages/*'], + }), + }) + process.argv = [ + process.execPath, + process.argv[1], + '--userconfig', resolve(dir, '.npmrc'), + '--color', 'false', + '--workspaces', 'false', + '--workspace', 'a', + ] + const { npm } = mockNpm(t) + await npm.load() + npm.localPrefix = dir + await new Promise((res, rej) => { + npm.commands.run([], er => { + if (!er) + return rej(new Error('Expected an error')) + t.match(er.message, 'Can not use --no-workspaces and --workspace at the same time') + res() + }) + }) + }) + t.test('workspace-aware configs and commands', async t => { const dir = t.testdir({ packages: {