Skip to content

Commit bedff61

Browse files
authored
fix: skip workspace detection when in global mode (npm#47)
1 parent 6c1ef08 commit bedff61

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ class Config {
566566
}
567567

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

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

582-
// if workspaces are disabled, return now
583-
if (cliWorkspaces === false) {
583+
// if workspaces are disabled, or we're in global mode, return now
584+
if (cliWorkspaces === false || isGlobal) {
584585
return
585586
}
586587

test/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,46 @@ t.test('workspaces', async (t) => {
11371137
t.equal(logs.length, 0, 'got no log messages')
11381138
})
11391139

1140+
t.test('global skips auto detect', async (t) => {
1141+
const cwd = process.cwd()
1142+
t.teardown(() => process.chdir(cwd))
1143+
process.chdir(`${path}/workspaces/one`)
1144+
1145+
const config = new Config({
1146+
npmPath: process.cwd(),
1147+
env: {},
1148+
argv: [process.execPath, __filename, '--global'],
1149+
cwd: `${path}/workspaces/one`,
1150+
shorthands,
1151+
definitions,
1152+
})
1153+
1154+
await config.load()
1155+
t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root')
1156+
t.same(config.get('workspace'), [], 'did not set workspace')
1157+
t.equal(logs.length, 0, 'got no log messages')
1158+
})
1159+
1160+
t.test('location=global skips auto detect', async (t) => {
1161+
const cwd = process.cwd()
1162+
t.teardown(() => process.chdir(cwd))
1163+
process.chdir(`${path}/workspaces/one`)
1164+
1165+
const config = new Config({
1166+
npmPath: process.cwd(),
1167+
env: {},
1168+
argv: [process.execPath, __filename, '--location=global'],
1169+
cwd: `${path}/workspaces/one`,
1170+
shorthands,
1171+
definitions,
1172+
})
1173+
1174+
await config.load()
1175+
t.equal(config.localPrefix, join(path, 'workspaces', 'one'), 'localPrefix is the root')
1176+
t.same(config.get('workspace'), [], 'did not set workspace')
1177+
t.equal(logs.length, 0, 'got no log messages')
1178+
})
1179+
11401180
t.test('does not error for invalid package.json', async (t) => {
11411181
const invalidPkg = join(path, 'workspaces', 'package.json')
11421182
const cwd = process.cwd()

0 commit comments

Comments
 (0)