Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
fix: skip workspace detection when in global mode (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Mar 2, 2022
1 parent 6c1ef08 commit bedff61
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/index.js
Expand Up @@ -566,6 +566,7 @@ class Config {
}

const cliWorkspaces = this[_get]('workspaces', 'cli')
const isGlobal = this[_get]('global') || this[_get]('location') === 'global'

for (const p of walkUp(this.cwd)) {
const hasNodeModules = await stat(resolve(p, 'node_modules'))
Expand All @@ -579,8 +580,8 @@ class Config {
if (!this.localPrefix && (hasNodeModules || hasPackageJson)) {
this.localPrefix = p

// if workspaces are disabled, return now
if (cliWorkspaces === false) {
// if workspaces are disabled, or we're in global mode, return now
if (cliWorkspaces === false || isGlobal) {
return
}

Expand Down
40 changes: 40 additions & 0 deletions test/index.js
Expand Up @@ -1137,6 +1137,46 @@ t.test('workspaces', async (t) => {
t.equal(logs.length, 0, 'got no log messages')
})

t.test('global skips auto detect', async (t) => {
const cwd = process.cwd()
t.teardown(() => process.chdir(cwd))
process.chdir(`${path}/workspaces/one`)

const config = new Config({
npmPath: process.cwd(),
env: {},
argv: [process.execPath, __filename, '--global'],
cwd: `${path}/workspaces/one`,
shorthands,
definitions,
})

await config.load()
t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root')
t.same(config.get('workspace'), [], 'did not set workspace')
t.equal(logs.length, 0, 'got no log messages')
})

t.test('location=global skips auto detect', async (t) => {
const cwd = process.cwd()
t.teardown(() => process.chdir(cwd))
process.chdir(`${path}/workspaces/one`)

const config = new Config({
npmPath: process.cwd(),
env: {},
argv: [process.execPath, __filename, '--location=global'],
cwd: `${path}/workspaces/one`,
shorthands,
definitions,
})

await config.load()
t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root')
t.same(config.get('workspace'), [], 'did not set workspace')
t.equal(logs.length, 0, 'got no log messages')
})

t.test('does not error for invalid package.json', async (t) => {
const invalidPkg = join(path, 'workspaces', 'package.json')
const cwd = process.cwd()
Expand Down

0 comments on commit bedff61

Please sign in to comment.