Skip to content

Commit 39e27eb

Browse files
committed
chore: synchronize dependent package version bumps
1 parent 68f81f1 commit 39e27eb

5 files changed

Lines changed: 182 additions & 6 deletions

File tree

.changeset/config.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
2+
"$schema": "https://unpkg.com/@changesets/config@latest/schema.json",
23
"changelog": ["@changesets/changelog-github", { "repo": "teneplaysofficial/js-utils-kit" }],
34
"commit": false,
45
"fixed": [],
56
"linked": [],
67
"access": "public",
78
"baseBranch": "main",
8-
"ignore": [],
9-
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
10-
"updateInternalDependents": "always"
11-
}
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
1211
}

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ jobs:
3737
id: changesets
3838
uses: changesets/action@v1
3939
with:
40-
version: pnpm changeset version
41-
publish: pnpm changeset publish
40+
version: pnpm run version
41+
publish: pnpm run publish
4242

4343
- uses: actions/upload-pages-artifact@v4
4444
with:

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"gen:docs": "node scripts/docs.js",
4040
"checks": "node scripts/checks.js",
4141
"changeset": "changeset",
42+
"preversion": "node scripts/sync-dependent-bumps.js",
4243
"version": "changeset version",
4344
"publish": "changeset publish",
4445
"lint": "eslint .",
@@ -63,11 +64,13 @@
6364
"devDependencies": {
6465
"@changesets/changelog-github": "^0.5.2",
6566
"@changesets/cli": "^2.29.7",
67+
"@changesets/parse": "^0.4.2",
6668
"@clack/prompts": "^0.11.0",
6769
"@eslint/compat": "^2.0.0",
6870
"@eslint/js": "^9.39.1",
6971
"@eslint/json": "^0.14.0",
7072
"@eslint/markdown": "^7.5.1",
73+
"@manypkg/get-packages": "^3.1.0",
7174
"@types/archiver": "^7.0.0",
7275
"@types/node": "^24.10.1",
7376
"@vitest/coverage-v8": "^4.0.14",

pnpm-lock.yaml

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

scripts/sync-dependent-bumps.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import parseChangesetFile from '@changesets/parse';
4+
import { getPackages } from '@manypkg/get-packages';
5+
import sylog from 'sylog';
6+
7+
const BUMP_PRIORITY = { patch: 0, minor: 1, major: 2 };
8+
const cwd = process.cwd();
9+
const changesetDir = path.join(cwd, '.changeset');
10+
11+
sylog.setLevels({
12+
info: 'sync-deps',
13+
});
14+
15+
if (!fs.existsSync(changesetDir)) {
16+
sylog.info('no .changeset directory, exiting');
17+
process.exit(0);
18+
}
19+
20+
sylog.info('starting');
21+
22+
const { packages } = await getPackages(cwd);
23+
24+
sylog.info('workspace packages:', packages.length);
25+
26+
const files = fs.readdirSync(changesetDir).filter((f) => f.endsWith('.md') && f !== 'README.md');
27+
28+
sylog.info('changeset files found:', files.length);
29+
30+
const explicitBumps = new Map();
31+
32+
for (const file of files) {
33+
const content = fs.readFileSync(path.join(changesetDir, file), 'utf-8');
34+
35+
if (!content.startsWith('---')) continue;
36+
37+
const { releases } = parseChangesetFile(content);
38+
39+
for (const r of releases) {
40+
const prev = explicitBumps.get(r.name);
41+
if (!prev || BUMP_PRIORITY[r.type] > BUMP_PRIORITY[prev]) {
42+
explicitBumps.set(r.name, r.type);
43+
}
44+
}
45+
}
46+
47+
sylog.info('explicit bumps:', explicitBumps.size);
48+
49+
const packageBumps = new Map(explicitBumps);
50+
51+
let changed = true;
52+
let iterations = 0;
53+
const MAX_ITERATIONS = packages.length + 5;
54+
55+
while (changed) {
56+
changed = false;
57+
iterations++;
58+
59+
if (iterations > MAX_ITERATIONS) {
60+
console.warn('[sync-deps] max iterations reached, stopping propagation');
61+
break;
62+
}
63+
64+
for (const pkg of packages) {
65+
const name = pkg.packageJson.name;
66+
if (!name) continue;
67+
68+
const deps = {
69+
...pkg.packageJson.dependencies,
70+
...pkg.packageJson.peerDependencies,
71+
};
72+
73+
let highest = null;
74+
75+
for (const dep of Object.keys(deps || {})) {
76+
if (dep === name) continue;
77+
78+
const bump = packageBumps.get(dep);
79+
if (bump && (!highest || BUMP_PRIORITY[bump] > BUMP_PRIORITY[highest])) {
80+
highest = bump;
81+
}
82+
}
83+
84+
if (!highest) continue;
85+
86+
const current = packageBumps.get(name);
87+
88+
if (current !== highest) {
89+
if (!current || BUMP_PRIORITY[highest] > BUMP_PRIORITY[current]) {
90+
packageBumps.set(name, highest);
91+
changed = true;
92+
}
93+
}
94+
}
95+
}
96+
97+
sylog.info('propagation iterations:', iterations);
98+
sylog.info('final bump count:', packageBumps.size);
99+
100+
let didChange = false;
101+
for (const [name, type] of packageBumps.entries()) {
102+
const explicit = explicitBumps.get(name);
103+
if (!explicit || BUMP_PRIORITY[type] > BUMP_PRIORITY[explicit]) {
104+
didChange = true;
105+
break;
106+
}
107+
}
108+
109+
if (!didChange) {
110+
sylog.info('no derived bumps, nothing to write');
111+
process.exit(0);
112+
}
113+
114+
const frontmatter =
115+
'---\n' +
116+
[...packageBumps.entries()].map(([name, type]) => `"${name}": ${type}`).join('\n') +
117+
'\n---\n';
118+
119+
const filePath = path.join(changesetDir, `sync-deps-${Date.now()}.md`);
120+
121+
fs.writeFileSync(filePath, frontmatter);
122+
123+
sylog.info('wrote synced changeset:', path.basename(filePath));
124+
sylog.info('done');

0 commit comments

Comments
 (0)