Skip to content
This repository was archived by the owner on Nov 3, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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