Skip to content

Commit f69f989

Browse files
committed
feat: support pnpm-workspace publish
1 parent 9342dba commit f69f989

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/commands/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ export const setup = (tag: GitNewTag, options: LogOptions) => {
9191

9292
if (config?.release) release(next, true);
9393

94-
if (config?.publish) publish(next, lerna);
94+
if (config?.publish) publish(next, lerna, next);
9595
};

src/monorepo.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import path from 'pathe';
2+
import { getRoot } from './utils';
3+
import { existsSync } from 'fs-extra';
4+
5+
export const getManager = (): {
6+
tool: 'pnpm' | 'yarn' | 'bun' | 'npm';
7+
isMonorepoWithTool: boolean;
8+
isPnpmWorkspace: boolean;
9+
} => {
10+
const cwd = getRoot();
11+
12+
const exists = (file: string) => existsSync(path.join(cwd, file));
13+
14+
const tool = exists('./pnpm-lock.yaml')
15+
? 'pnpm'
16+
: exists('./yarn.lock')
17+
? 'yarn'
18+
: exists('./bun.lock')
19+
? 'bun'
20+
: 'npm';
21+
22+
const isMonorepoWithTool = exists('./lerna.json') || exists('./nx.json');
23+
const isPnpmWorkspace = exists('pnpm-workspace.yaml');
24+
25+
return { tool, isMonorepoWithTool, isPnpmWorkspace };
26+
};

src/npm.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { $ } from 'zx';
22
import { info, success, error } from './console';
3+
import { getManager } from './monorepo';
4+
import { lastTag } from './git';
35

4-
export const publish = (target: string, lerna?: boolean) => {
6+
export const publish = (target: string, lerna?: boolean, tag: string = lastTag()) => {
57
info('Publishing...');
68

79
if (lerna) {
@@ -12,7 +14,11 @@ export const publish = (target: string, lerna?: boolean) => {
1214
}
1315
} else {
1416
try {
15-
$.sync`npm publish`;
17+
const { isPnpmWorkspace, tool } = getManager();
18+
19+
isPnpmWorkspace && tool === 'pnpm'
20+
? $.sync`pnpm -r publish --access public --no-git-checks --tag ${tag}`
21+
: $.sync`npm publish`;
1622
} catch (e) {
1723
error('Unable to publish the package in NPM!');
1824
}

0 commit comments

Comments
 (0)