Skip to content

Commit 0824877

Browse files
slorberclaude
andauthored
chore(dependabot): group Babel packages so they are upgraded in a single PR (AI-assisted) (#12796)
* chore(dependabot): group Babel packages so they are upgraded in a single PR (AI-assisted) Upgrading Babel packages independently duplicates them in the lockfile. Babel only publishes the packages that changed, so the catalog versions of the group differ: pnpm lint:catalogs only checks their major version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(skills): don't say all dependency group members use the same version (AI-assisted) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9d18ab8 commit 0824877

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎.agents/skills/dependencies/SKILL.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ Exceptions, keeping explicit versions:
3333
Two checks enforce it:
3434

3535
- `pnpm lint:syncpack`: dependencies must use a catalog.
36-
- `pnpm lint:catalogs` (`admin/scripts/lintCatalogs.js`): catalog entries are used and in the right catalog, templates and overrides match the catalogs, and dependency group members use the same version.
36+
- `pnpm lint:catalogs` (`admin/scripts/lintCatalogs.js`): catalog entries are used and in the right catalog, templates and overrides match the catalogs, and dependency group members use matching versions.
3737

3838
## Dependency groups
3939

40-
Some packages must always use the same version. They are declared as `groups` in `.github/dependabot.yml`:
40+
Some packages must always be upgraded together. They are declared as `groups` in `.github/dependabot.yml`:
4141

4242
- Dependabot upgrades them atomically in a single PR, instead of opening broken intermediate PRs.
43-
- `pnpm lint:catalogs` fails if their catalog versions differ.
43+
- `pnpm lint:catalogs` fails if their catalog versions differ (only their major versions for the `babel` group, see `admin/scripts/lintCatalogs.js`).
4444

4545
Packages belong to a group when, for example:
4646

‎.github/dependabot.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ updates:
6868
svgr:
6969
patterns:
7070
- '@svgr/*'
71+
# Babel packages depend on each other
72+
# Upgrading them independently duplicates Babel packages in the lockfile
73+
# See https://github.com/facebook/docusaurus/pull/12704
74+
babel:
75+
patterns:
76+
- '@babel/*'

‎admin/scripts/lintCatalogs.js‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const RuntimeDependencyTypes = [
2525
];
2626
const AllDependencyTypes = [...RuntimeDependencyTypes, 'devDependencies'];
2727

28+
// Babel only publishes the packages that changed: their versions differ
29+
const SameMajorVersionDependencyGroups = ['babel'];
30+
2831
async function main() {
2932
const monorepo = await loadMonorepo();
3033

@@ -216,7 +219,7 @@ function checkOverridesMatchCatalogs({catalogs, overrides}) {
216219

217220
/**
218221
* The packages of a Dependabot group must be upgraded together, and must
219-
* use the same version.
222+
* use the same version, or the same major version for some groups.
220223
* @param {Monorepo} monorepo
221224
* @returns {string[]}
222225
*/
@@ -227,15 +230,25 @@ function checkDependencyGroups({catalogs, dependencyGroups}) {
227230
const members = catalogEntries.filter(([name]) =>
228231
matchesSomePattern(name, group.patterns),
229232
);
230-
const versions = new Set(members.map(([, version]) => version));
233+
const sameMajorVersion = SameMajorVersionDependencyGroups.includes(
234+
group.name,
235+
);
236+
const versions = new Set(
237+
members.map(([, version]) =>
238+
sameMajorVersion ? getMajorVersion(version) : version,
239+
),
240+
);
231241
if (versions.size <= 1) {
232242
return [];
233243
}
234244
const membersDescription = members
235245
.map(([name, version]) => `${name}@${version}`)
236246
.join(', ');
247+
const expectedVersion = sameMajorVersion
248+
? 'the same major version'
249+
: 'the same version';
237250
return [
238-
`pnpm-workspace.yaml: the packages of the "${group.name}" Dependabot group must use the same version: ${membersDescription}`,
251+
`pnpm-workspace.yaml: the packages of the "${group.name}" Dependabot group must use ${expectedVersion}: ${membersDescription}`,
239252
];
240253
});
241254
}
@@ -270,6 +283,11 @@ function differsFromCatalogs(catalogs, name, version) {
270283
return catalogVersion !== undefined && catalogVersion !== version;
271284
}
272285

286+
// "^7.29.7" => "7"
287+
function getMajorVersion(version) {
288+
return version.match(/\d+/)?.[0];
289+
}
290+
273291
// Dependabot patterns only support the "*" wildcard
274292
function matchesSomePattern(name, patterns) {
275293
return patterns.some((pattern) => {

0 commit comments

Comments
 (0)