Skip to content

Commit 73aa236

Browse files
authored
Bump versions for everything with a workspace dep that was bumped (#2640)
1 parent 2ab9b9d commit 73aa236

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"build:api-published": "node scripts/buildPublishedAPI.js",
3737
"build:api-branch": "node scripts/buildBranchAPI.js",
3838
"compare:apis": "node scripts/compareAPIs.js",
39-
"check-apis": "yarn build:api-published && yarn build:api-branch && yarn compare:apis"
39+
"check-apis": "yarn build:api-published && yarn build:api-branch && yarn compare:apis",
40+
"bumpVersions": "node scripts/bumpVersions.js"
4041
},
4142
"workspaces": [
4243
"packages/react-stately",

scripts/bumpVersions.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,18 @@ let monopackages = new Set([
4444
class VersionManager {
4545
constructor() {
4646
// Get dependency tree from yarn workspaces
47-
this.workspacePackages = JSON.parse(exec('yarn workspaces info --json').toString().split('\n').slice(1, -2).join('\n'));
47+
try {
48+
// yarn 1.21 returns this structure
49+
this.workspacePackages = JSON.parse(JSON.parse(exec('yarn workspaces info --json').toString()).data);
50+
} catch (e) {
51+
try {
52+
// Unknown what versions of yarn return this, but it was the original implementation.
53+
this.workspacePackages = JSON.parse(exec('yarn workspaces info --json').toString().split('\n').slice(1, -2).join('\n'));
54+
} catch (e) {
55+
// If that failed to parse, then it's because we have yarn 1.22 and this is how we need to parse it.
56+
this.workspacePackages = JSON.parse(exec('yarn workspaces info --json').toString());
57+
}
58+
}
4859
this.existingPackages = new Set();
4960
this.changedPackages = new Set();
5061
this.versionBumps = {};
@@ -135,6 +146,7 @@ class VersionManager {
135146
return;
136147
}
137148

149+
138150
// Diff each package individually. Some packages might have been skipped during last release,
139151
// so we cannot simply look at the last tag on the whole repo.
140152
for (let name in this.workspacePackages) {
@@ -144,7 +156,7 @@ class VersionManager {
144156
// Diff this package since the last published version, according to the package.json.
145157
// We create a git tag for each package version.
146158
let tag = `${pkg.name}@${pkg.version}`;
147-
let res = spawn('git', ['diff', '--exit-code', tag + '..HEAD', this.workspacePackages[name].location, ':!**/docs/**', ':!**/test/**', ':!**/stories/**', ':!**/chromatic/**']);
159+
let res = spawn('git', ['diff', '--exit-code', tag + '..HEAD', this.workspacePackages[name].location, ':!**/docs/**', ':!**/test/**', ':!**/test-utils/**', ':!**/stories/**', ':!**/chromatic/**']);
148160
if (res.status !== 0) {
149161
this.changedPackages.add(name);
150162
}
@@ -271,22 +283,23 @@ class VersionManager {
271283

272284
// Bump anything that depends on this package if it's a prerelease
273285
// because dependencies will be pinned rather than caret ranges.
274-
if (status !== 'released') {
275-
for (let p in this.workspacePackages) {
276-
if (this.releasedPackages.has(p)) {
277-
continue;
278-
}
286+
// Bump anything that has this as a dep by a patch, all the way up the tree
287+
for (let p in this.workspacePackages) {
288+
if (this.releasedPackages.has(p)) {
289+
continue;
290+
}
279291

280-
if (this.workspacePackages[p].workspaceDependencies.includes(pkg)) {
281-
if (this.existingPackages.has(p)) {
282-
// Bump a patch version of the dependent package if it's not also a prerelease.
283-
// Otherwise, bump to the next prerelease in the existing status.
284-
let filePath = this.workspacePackages[p].location + '/package.json';
285-
let pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
286-
let prerelease = semver.parse(pkg.version).prerelease;
287-
let b = prerelease.length === 0 ? 'patch' : prerelease[0];
288-
this.addReleasedPackage(p, b, true);
289-
}
292+
if (this.workspacePackages[p].workspaceDependencies.includes(pkg)) {
293+
let filePath = this.workspacePackages[p].location + '/package.json';
294+
let pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
295+
let prerelease = semver.parse(pkg.version).prerelease;
296+
let b = prerelease.length === 0 ? 'patch' : prerelease[0];
297+
if (this.existingPackages.has(p) && status !== 'released') {
298+
// Bump a patch version of the dependent package if it's not also a prerelease.
299+
// Otherwise, bump to the next prerelease in the existing status.
300+
this.addReleasedPackage(p, b, true);
301+
} else if (this.existingPackages.has(p) && status === 'released') {
302+
this.addReleasedPackage(p, b);
290303
}
291304
}
292305
}
@@ -334,6 +347,8 @@ class VersionManager {
334347
}
335348
}
336349

350+
351+
337352
return versions;
338353
}
339354

0 commit comments

Comments
 (0)