Skip to content

Commit

Permalink
fixup! feat(workspaces): --include-workspace-root
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Aug 11, 2021
1 parent 726b61c commit 532ba3e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/npm.js
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions test/lib/npm.js
Expand Up @@ -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, outputs } = mockNpm(t)
await npm.load()
npm.localPrefix = dir
await new Promise((res, rej) => {
npm.commands.run([], er => {
if (!er)
return rej('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: {
Expand Down

0 comments on commit 532ba3e

Please sign in to comment.