Skip to content

Commit 21df5d7

Browse files
committed
feat(monorepo): support pnpm-workspace deep upgrade version without lerna turbo and nx
1 parent 7d054d0 commit 21df5d7

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"prepublishOnly": "pnpm build",
4343
"patch": "pnpm build && node dist/index.js log patch",
4444
"minor": "pnpm build && node dist/index.js log minor",
45-
"major": "pnpm build && node dist/index.js log major"
45+
"major": "pnpm build && node dist/index.js log major",
46+
"run:test": "pnpm build && node dist/index.js test"
4647
},
4748
"bin": {
4849
"generi": "dist/index.js"
@@ -55,13 +56,15 @@
5556
"execa": "^5.1.1",
5657
"fs-extra": "^11.3.2",
5758
"gradient-string": "^3.0.0",
59+
"js-yaml": "^4.1.0",
5860
"pathe": "^2.0.3",
5961
"sade": "^1.8.1",
6062
"tinyglobby": "^0.2.15"
6163
},
6264
"devDependencies": {
6365
"@types/fs-extra": "^11.0.4",
6466
"@types/gradient-string": "^1.1.6",
67+
"@types/js-yaml": "^4.0.9",
6568
"@types/node": "^24.9.2",
6669
"@vitest/coverage-v8": "4.0.5",
6770
"prettier": "^3.6.2",

pnpm-lock.yaml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/git.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Commit, GeneriConsole, GitNewTag, GitPrerelease, Root } from './ty
77
import { getRoot, setFile, getFile, getFileRoot } from './utils';
88
import { isChangesForCommit } from './utils';
99
import { destr } from 'destr';
10+
import { getPNPMWorkspace } from './monorepo';
1011

1112
export const isGit = () => {
1213
return fs.existsSync(path.resolve(getRoot(), '.git'));
@@ -133,8 +134,13 @@ export const setVersion = (
133134

134135
console.success('Set ' + target + ' Version In Lerna Monorepos!');
135136
} else {
136-
// TODO: custom pnpm-workspace.yaml packages list
137-
glob(['package.json', './packages/*/package.json'], {
137+
const workspace = getPNPMWorkspace();
138+
const targets =
139+
workspace && workspace.packages
140+
? workspace.packages
141+
: ['./packages/*/package.json'];
142+
143+
glob(['package.json', ...targets], {
138144
expandDirectories: false,
139145
}).then(async (packages) => {
140146
await versionBump({

src/monorepo.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import yaml from 'js-yaml';
12
import { exists } from './utils';
3+
import path from 'pathe';
4+
import { readFileSync } from 'fs-extra';
5+
import { Maybe } from './types';
26

37
export const getManager = (): {
48
tool: 'pnpm' | 'yarn' | 'bun' | 'npm';
@@ -14,7 +18,16 @@ export const getManager = (): {
1418
: 'npm';
1519

1620
const isMonorepoWithTool = exists('./lerna.json') || exists('./nx.json');
17-
const isPnpmWorkspace = exists('pnpm-workspace.yaml');
21+
const isPnpmWorkspace = exists('./pnpm-workspace.yaml');
1822

1923
return { tool, isMonorepoWithTool, isPnpmWorkspace };
2024
};
25+
26+
// TODO: deep type pnpm-workspace for edge cases use
27+
export const getPNPMWorkspace = (): Maybe<Record<'packages', string[]>> => {
28+
return getManager().isPnpmWorkspace
29+
? (yaml.load(
30+
readFileSync(path.resolve(process.cwd(), './pnpm-workspace.yaml'), 'utf8')
31+
) as Record<'packages', string[]>)
32+
: undefined;
33+
};

0 commit comments

Comments
 (0)