Skip to content

Commit 8b0cc7d

Browse files
mpetrunicchingor13
andauthored
feat: add support for yarn workspace versions (#1819)
* feat: add support for yarn workspace versions * fix: workspace condition to cover edge cases Co-authored-by: Jeff Ching <chingor@google.com>
1 parent 25b518f commit 8b0cc7d

5 files changed

Lines changed: 69 additions & 11 deletions

File tree

__snapshots__/node-workspace.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ Release notes for path: node1, releaseType: node
2727
* @here/pkgB bumped from 2.2.2 to 2.2.3
2828
</details>
2929
30+
<details><summary>@here/pkgE: 1.0.1</summary>
31+
32+
### Dependencies
33+
34+
* The following workspace dependencies were updated
35+
* dependencies
36+
* @here/pkgA bumped to 3.3.4
37+
</details>
38+
3039
---
3140
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
3241
`
@@ -155,6 +164,15 @@ Release notes for path: node1, releaseType: node
155164
Release notes for path: node4, releaseType: node
156165
</details>
157166
167+
<details><summary>@here/pkgE: 1.0.1</summary>
168+
169+
### Dependencies
170+
171+
* The following workspace dependencies were updated
172+
* dependencies
173+
* @here/pkgA bumped to 3.3.4
174+
</details>
175+
158176
---
159177
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
160178
`

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
"@types/iarna__toml": "^2.0.1",
4545
"@types/js-yaml": "^4.0.0",
4646
"@types/jsonpath": "^0.2.0",
47-
"@types/lerna__collect-updates": "^5.0.0",
48-
"@types/lerna__package": "^5.0.0",
49-
"@types/lerna__package-graph": "^5.0.0",
50-
"@types/lerna__run-topologically": "^5.0.0",
47+
"@types/lerna__collect-updates": "^5.1.0",
48+
"@types/lerna__package": "^5.1.0",
49+
"@types/lerna__package-graph": "^5.1.0",
50+
"@types/lerna__run-topologically": "^5.1.0",
5151
"@types/mocha": "^9.0.0",
5252
"@types/node": "^18.0.0",
5353
"@types/pino": "^7.0.0",
@@ -70,10 +70,10 @@
7070
"@conventional-commits/parser": "^0.4.1",
7171
"@google-automations/git-file-utils": "^1.2.5",
7272
"@iarna/toml": "^2.2.5",
73-
"@lerna/collect-updates": "^4.0.0",
74-
"@lerna/package": "^4.0.0",
75-
"@lerna/package-graph": "^4.0.0",
76-
"@lerna/run-topologically": "^4.0.0",
73+
"@lerna/collect-updates": "^6.4.1",
74+
"@lerna/package": "^6.4.1",
75+
"@lerna/package-graph": "^6.4.1",
76+
"@lerna/run-topologically": "^6.4.1",
7777
"@octokit/graphql": "^5.0.0",
7878
"@octokit/request": "^6.0.0",
7979
"@octokit/request-error": "^3.0.0",

src/plugins/node-workspace.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ export class NodeWorkspace extends WorkspacePlugin<Package> {
181181
);
182182
}
183183
}
184-
const dependencyNotes = getChangelogDepsNotes(pkg, updatedPackage);
184+
const dependencyNotes = getChangelogDepsNotes(
185+
pkg,
186+
updatedPackage,
187+
updatedVersions
188+
);
185189
existingCandidate.pullRequest.updates =
186190
existingCandidate.pullRequest.updates.map(update => {
187191
if (update.path === addPath(existingCandidate.path, 'package.json')) {
@@ -256,7 +260,11 @@ export class NodeWorkspace extends WorkspacePlugin<Package> {
256260
);
257261
}
258262
}
259-
const dependencyNotes = getChangelogDepsNotes(pkg, updatedPackage);
263+
const dependencyNotes = getChangelogDepsNotes(
264+
pkg,
265+
updatedPackage,
266+
updatedVersions
267+
);
260268
const packageJson = updatedPackage.toJSON() as PackageJson;
261269
const version = Version.parse(packageJson.version);
262270
const pullRequest: ReleasePullRequest = {
@@ -374,7 +382,11 @@ enum SUPPORTED_RANGE_PREFIXES {
374382
EQUAL_OR_LESS_THAN = '<=',
375383
}
376384

377-
function getChangelogDepsNotes(original: Package, updated: Package): string {
385+
function getChangelogDepsNotes(
386+
original: Package,
387+
updated: Package,
388+
updateVersions: VersionsMap
389+
): string {
378390
let depUpdateNotes = '';
379391
type DT =
380392
| 'dependencies'
@@ -400,6 +412,16 @@ function getChangelogDepsNotes(original: Package, updated: Package): string {
400412
depUpdates.push(
401413
`\n * ${depName} bumped from ${origDepVer} to ${currentDepVer}`
402414
);
415+
//handle case when "workspace:" version is used
416+
} else if (
417+
currentDepVer.startsWith('workspace:') &&
418+
updateVersions.get(depName) !== undefined
419+
) {
420+
depUpdates.push(
421+
`\n * ${depName} bumped to ${updateVersions
422+
.get(depName)
423+
?.toString()}`
424+
);
403425
}
404426
}
405427
if (depUpdates.length > 0) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@here/pkgE",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"@here/pkgA": "workspace:^",
6+
"anotherExternal": "^4.3.1"
7+
}
8+
}

test/plugins/node-workspace.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ describe('NodeWorkspace plugin', () => {
102102
node4: {
103103
releaseType: 'node',
104104
},
105+
node5: {
106+
releaseType: 'node',
107+
},
105108
});
106109
});
107110
afterEach(() => {
@@ -256,6 +259,7 @@ describe('NodeWorkspace plugin', () => {
256259
'node2/package.json',
257260
'node3/package.json',
258261
'node4/package.json',
262+
'node5/package.json',
259263
],
260264
flatten: false,
261265
targetBranch: 'main',
@@ -283,13 +287,18 @@ describe('NodeWorkspace plugin', () => {
283287
assertHasUpdate(updates, 'node4/package.json', RawContent),
284288
'4.4.5'
285289
);
290+
assertHasVersionUpdate(
291+
assertHasUpdate(updates, 'node5/package.json', RawContent),
292+
'1.0.1'
293+
);
286294
const updater = assertHasUpdate(
287295
updates,
288296
'.release-please-manifest.json',
289297
ReleasePleaseManifest
290298
).updater as ReleasePleaseManifest;
291299
expect(updater.versionsMap?.get('node2')?.toString()).to.eql('2.2.3');
292300
expect(updater.versionsMap?.get('node3')?.toString()).to.eql('1.1.2');
301+
expect(updater.versionsMap?.get('node5')?.toString()).to.eql('1.0.1');
293302
snapshot(dateSafe(nodeCandidate!.pullRequest.body.toString()));
294303
});
295304
it('appends dependency notes to an updated module', async () => {
@@ -329,6 +338,7 @@ describe('NodeWorkspace plugin', () => {
329338
'node2/package.json',
330339
'node3/package.json',
331340
'node4/package.json',
341+
'node5/package.json',
332342
],
333343
flatten: false,
334344
targetBranch: 'main',

0 commit comments

Comments
 (0)