Skip to content

Commit 0a8af7b

Browse files
committed
Fix ENOWORKSPACES error when publishing from monorepo workspace
npm config commands don't support workspace operations. When running from within a workspace directory, npm would fail with ENOWORKSPACES. Adding --workspaces=false flag to all npm config commands fixes this issue. Fixes #715
1 parent ebdcbaa commit 0a8af7b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

source/package-manager/configs.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export const npmConfig = {
55
installCommand: ['npm', ['ci', '--engine-strict']],
66
installCommandNoLockfile: ['npm', ['install', '--no-package-lock', '--no-production', '--engine-strict']],
77
versionCommand: version => ['npm', ['version', version]],
8-
getRegistryCommand: ['npm', ['config', 'get', 'registry']],
9-
tagVersionPrefixCommand: ['npm', ['config', 'get', 'tag-version-prefix']],
8+
getRegistryCommand: ['npm', ['config', 'get', 'registry', '--workspaces=false']],
9+
tagVersionPrefixCommand: ['npm', ['config', 'get', 'tag-version-prefix', '--workspaces=false']],
1010
lockfiles: ['package-lock.json', 'npm-shrinkwrap.json'],
1111
};
1212

@@ -18,7 +18,7 @@ export const pnpmConfig = {
1818
installCommandNoLockfile: ['pnpm', ['install']],
1919
versionCommand: version => ['pnpm', ['version', version]],
2020
// By default, pnpm config returns `undefined` instead of `v` for tag-version-prefix, so for consistent default behavior, use npm.
21-
tagVersionPrefixCommand: ['npm', ['config', 'get', 'tag-version-prefix']],
21+
tagVersionPrefixCommand: ['npm', ['config', 'get', 'tag-version-prefix', '--workspaces=false']],
2222
// Disable duplicated pnpm Git checks
2323
publishCommand: arguments_ => ['pnpm', [...arguments_, '--no-git-checks']],
2424
getRegistryCommand: ['pnpm', ['config', 'get', 'registry']],
@@ -63,7 +63,7 @@ export const bunConfig = {
6363
// Bun doesn't support publishing, so we use npm instead. See https://github.com/oven-sh/bun/issues/5050
6464
publishCommand: arguments_ => ['npm', arguments_],
6565
// TODO: Bun doesn't support config get registry, this should be added in the future. See https://github.com/oven-sh/bun/issues/7140
66-
getRegistryCommand: ['npm', ['config', 'get', 'registry']],
67-
tagVersionPrefixCommand: ['npm', ['config', 'get', 'tag-version-prefix']],
66+
getRegistryCommand: ['npm', ['config', 'get', 'registry', '--workspaces=false']],
67+
tagVersionPrefixCommand: ['npm', ['config', 'get', 'tag-version-prefix', '--workspaces=false']],
6868
lockfiles: ['bun.lockb', 'bun.lock'],
6969
};

test/util/get-tag-version-prefix.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {npmConfig, yarnConfig, pnpmConfig} from '../../source/package-manager/co
77
const createFixture = _createFixture('../../source/util.js', import.meta.url);
88

99
test('returns tag prefix - npm', createFixture, [{
10-
command: 'npm config get tag-version-prefix',
10+
command: 'npm config get tag-version-prefix --workspaces=false',
1111
stdout: 'ver',
1212
}], async ({t, testedModule: {getTagVersionPrefix}}) => {
1313
t.is(
@@ -27,7 +27,7 @@ test('returns preId postfix - yarn', createFixture, [{
2727
});
2828

2929
test('defaults to "v" when command fails', createFixture, [{
30-
command: 'npm config get tag-version-prefix',
30+
command: 'npm config get tag-version-prefix --workspaces=false',
3131
exitCode: 1,
3232
}], async ({t, testedModule: {getTagVersionPrefix}}) => {
3333
t.is(
@@ -37,7 +37,7 @@ test('defaults to "v" when command fails', createFixture, [{
3737
});
3838

3939
test('returns tag prefix - pnpm (uses npm config)', createFixture, [{
40-
command: 'npm config get tag-version-prefix',
40+
command: 'npm config get tag-version-prefix --workspaces=false',
4141
stdout: 'v',
4242
}], async ({t, testedModule: {getTagVersionPrefix}}) => {
4343
t.is(
@@ -47,7 +47,7 @@ test('returns tag prefix - pnpm (uses npm config)', createFixture, [{
4747
});
4848

4949
test('returns custom tag prefix - pnpm', createFixture, [{
50-
command: 'npm config get tag-version-prefix',
50+
command: 'npm config get tag-version-prefix --workspaces=false',
5151
stdout: 'ver',
5252
}], async ({t, testedModule: {getTagVersionPrefix}}) => {
5353
t.is(
@@ -57,7 +57,7 @@ test('returns custom tag prefix - pnpm', createFixture, [{
5757
});
5858

5959
test('returns empty string tag prefix - pnpm', createFixture, [{
60-
command: 'npm config get tag-version-prefix',
60+
command: 'npm config get tag-version-prefix --workspaces=false',
6161
stdout: '',
6262
}], async ({t, testedModule: {getTagVersionPrefix}}) => {
6363
t.is(
@@ -67,7 +67,7 @@ test('returns empty string tag prefix - pnpm', createFixture, [{
6767
});
6868

6969
test('pnpm defaults to "v" when npm config fails', createFixture, [{
70-
command: 'npm config get tag-version-prefix',
70+
command: 'npm config get tag-version-prefix --workspaces=false',
7171
exitCode: 1,
7272
}], async ({t, testedModule: {getTagVersionPrefix}}) => {
7373
t.is(

0 commit comments

Comments
 (0)