Skip to content

Commit c84414a

Browse files
fix(node-workspace): Add update-peer-dependencies option that also updates peer dependencies (#2094)
* fix: Node workspace plugin now updates peer dependencies. Fixes #1943 * test: Remove obsolete snapshot * feat: Add update-peer-dependencies option to the node-workspace plugin * chore: Remove unused snapshot * test: Correct test for peerDependencies option Fixes #1943 --------- Co-authored-by: Jeff Ching <chingor@google.com>
1 parent ea774cb commit c84414a

7 files changed

Lines changed: 145 additions & 0 deletions

File tree

__snapshots__/node-workspace.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,36 @@ Release notes for path: node4, releaseType: node
207207
---
208208
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
209209
`
210+
211+
exports['NodeWorkspace plugin with updatePeerDependencies: true respects version prefix and updates peer dependencies 1'] = `
212+
{
213+
"name": "@here/plugin1",
214+
"version": "4.4.4",
215+
"peerDependencies": {
216+
"@here/pkgA": "^2.2.2"
217+
}
218+
}
219+
`
220+
221+
exports['NodeWorkspace plugin with updatePeerDependencies: true should not ignore peer dependencies 1'] = `
222+
:robot: I have created a release *beep* *boop*
223+
---
224+
225+
226+
<details><summary>@here/pkgA: 3.3.4</summary>
227+
228+
Release notes for path: node1, releaseType: node
229+
</details>
230+
231+
<details><summary>@here/plugin1: 4.4.5</summary>
232+
233+
### Dependencies
234+
235+
* The following workspace dependencies were updated
236+
* peerDependencies
237+
* @here/pkgA bumped from ^3.3.3 to ^3.3.4
238+
</details>
239+
240+
---
241+
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
242+
`

docs/manifest-releaser.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ defaults (those are documented in comments)
207207
// absence defaults to true
208208
"always-link-local": false,
209209

210+
// when using the `node-workspace` plugin, update peer dependency fields
211+
// that reference bumped packages.
212+
// absence defaults to false, and peer dependency fields are not updated.
213+
"update-peer-dependencies": true,
214+
210215
// if true, create separate pull requests for each package instead of a
211216
// single manifest release pull request
212217
// absence defaults to false and one pull request will be raised
@@ -495,6 +500,12 @@ your update pull request. If you don't agree with this behavior and would only l
495500
your local dependencies bumped if they are within the SemVer range, you can set the
496501
`"always-link-local"` option to `false` in your manifest config.
497502

503+
#### Linking peer dependencies
504+
505+
By default, the `node-workspace` plugin doesn't modify `peerDependencies` fields in
506+
package.json. If you would like version bumps to be also linked in `peerDependencies`
507+
fields, set `"update-peer-dependencies"` to `true` in your manifest config.
508+
498509
### cargo-workspace
499510

500511
The `cargo-workspace` plugin operates similarly to the `node-workspace` plugin,

schemas/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@
248248
"description": "When using the `node-workspace` plugin, force all local dependencies to be linked.",
249249
"type": "boolean"
250250
},
251+
"update-peer-dependencies": {
252+
"description": "When using the `node-workspace` plugin, also bump peer dependency versions if they are modified.",
253+
"type": "boolean"
254+
},
251255
"plugins": {
252256
"description": "Plugins to apply to pull requests. Plugins can be added to perform extra release processing that cannot be achieved by an individual release strategy.",
253257
"type": "array",
@@ -383,6 +387,7 @@
383387
"bootstrap-sha": true,
384388
"last-release-sha": true,
385389
"always-link-local": true,
390+
"update-peer-dependencies": true,
386391
"plugins": true,
387392
"group-pull-request-title-pattern": true,
388393
"release-search-depth": true,

src/factories/plugin-factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface PluginFactoryOptions {
4141

4242
// node options
4343
alwaysLinkLocal?: boolean;
44+
updatePeerDependencies?: boolean;
4445

4546
// workspace options
4647
updateAllPackages?: boolean;

src/manifest.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export interface ManifestOptions {
181181
bootstrapSha?: string;
182182
lastReleaseSha?: string;
183183
alwaysLinkLocal?: boolean;
184+
updatePeerDependencies?: boolean;
184185
separatePullRequests?: boolean;
185186
plugins?: PluginType[];
186187
fork?: boolean;
@@ -242,6 +243,7 @@ export interface ManifestConfig extends ReleaserConfigJson {
242243
'bootstrap-sha'?: string;
243244
'last-release-sha'?: string;
244245
'always-link-local'?: boolean;
246+
'update-peer-dependencies'?: boolean;
245247
plugins?: PluginType[];
246248
'group-pull-request-title-pattern'?: string;
247249
'release-search-depth'?: number;
@@ -317,6 +319,8 @@ export class Manifest {
317319
* as the point to consider commits after
318320
* @param {boolean} manifestOptions.alwaysLinkLocal Option for the node-workspace
319321
* plugin
322+
* @param {boolean} manifestOptions.updatePeerDependencies Option for the node-workspace
323+
* plugin
320324
* @param {boolean} manifestOptions.separatePullRequests If true, create separate pull
321325
* requests instead of a single manifest release pull request
322326
* @param {PluginType[]} manifestOptions.plugins Any plugins to use for this repository
@@ -432,6 +436,8 @@ export class Manifest {
432436
* as the point to consider commits after
433437
* @param {boolean} manifestOptions.alwaysLinkLocal Option for the node-workspace
434438
* plugin
439+
* @param {boolean} manifestOptions.updatePeerDependencies Option for the node-workspace
440+
* plugin
435441
* @param {boolean} manifestOptions.separatePullRequests If true, create separate pull
436442
* requests instead of a single manifest release pull request
437443
* @param {PluginType[]} manifestOptions.plugins Any plugins to use for this repository
@@ -1362,6 +1368,7 @@ async function parseConfig(
13621368
bootstrapSha: config['bootstrap-sha'],
13631369
lastReleaseSha: config['last-release-sha'],
13641370
alwaysLinkLocal: config['always-link-local'],
1371+
updatePeerDependencies: config['update-peer-dependencies'],
13651372
separatePullRequests: config['separate-pull-requests'],
13661373
groupPullRequestTitlePattern: config['group-pull-request-title-pattern'],
13671374
plugins: config['plugins'],

src/plugins/node-workspace.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ interface Package {
5555

5656
interface NodeWorkspaceOptions extends WorkspacePluginOptions {
5757
alwaysLinkLocal?: boolean;
58+
updatePeerDependencies?: boolean;
5859
}
5960

6061
/**
@@ -66,6 +67,7 @@ interface NodeWorkspaceOptions extends WorkspacePluginOptions {
6667
*/
6768
export class NodeWorkspace extends WorkspacePlugin<Package> {
6869
private alwaysLinkLocal: boolean;
70+
private updatePeerDependencies: boolean;
6971
constructor(
7072
github: GitHub,
7173
targetBranch: string,
@@ -74,6 +76,7 @@ export class NodeWorkspace extends WorkspacePlugin<Package> {
7476
) {
7577
super(github, targetBranch, repositoryConfig, options);
7678
this.alwaysLinkLocal = options.alwaysLinkLocal === false ? false : true;
79+
this.updatePeerDependencies = options.updatePeerDependencies === true;
7780
}
7881
protected async buildAllPackages(
7982
candidates: CandidateReleasePullRequest[]
@@ -342,6 +345,9 @@ export class NodeWorkspace extends WorkspacePlugin<Package> {
342345
...(packageJson.dependencies ?? {}),
343346
...(packageJson.devDependencies ?? {}),
344347
...(packageJson.optionalDependencies ?? {}),
348+
...(this.updatePeerDependencies
349+
? packageJson.peerDependencies ?? {}
350+
: {}),
345351
};
346352
}
347353
}

test/plugins/node-workspace.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,86 @@ describe('NodeWorkspace plugin', () => {
409409
snapshot(dateSafe(nodeCandidate!.pullRequest.body.toString()));
410410
});
411411
});
412+
describe('with updatePeerDependencies: true', () => {
413+
const options = {updatePeerDependencies: true};
414+
it('should not ignore peer dependencies', async () => {
415+
const candidates: CandidateReleasePullRequest[] = [
416+
buildMockCandidatePullRequest('node1', 'node', '3.3.4', {
417+
component: '@here/pkgA',
418+
updates: [
419+
buildMockPackageUpdate('node1/package.json', 'node1/package.json'),
420+
],
421+
}),
422+
];
423+
stubFilesFromFixtures({
424+
sandbox,
425+
github,
426+
fixturePath: fixturesPath,
427+
files: ['node1/package.json', 'plugin1/package.json'],
428+
flatten: false,
429+
targetBranch: 'main',
430+
});
431+
plugin = new NodeWorkspace(
432+
github,
433+
'main',
434+
{
435+
node1: {
436+
releaseType: 'node',
437+
},
438+
plugin1: {
439+
releaseType: 'node',
440+
},
441+
},
442+
options
443+
);
444+
const newCandidates = await plugin.run(candidates);
445+
expect(newCandidates).lengthOf(1);
446+
const nodeCandidate = newCandidates.find(
447+
candidate => candidate.config.releaseType === 'node'
448+
);
449+
expect(nodeCandidate).to.not.be.undefined;
450+
const updates = nodeCandidate!.pullRequest.updates;
451+
assertHasUpdate(updates, 'node1/package.json');
452+
assertHasUpdate(updates, 'plugin1/package.json');
453+
snapshot(dateSafe(nodeCandidate!.pullRequest.body.toString()));
454+
});
455+
456+
it('respects version prefix and updates peer dependencies', async () => {
457+
const candidates: CandidateReleasePullRequest[] = [
458+
buildMockCandidatePullRequest('plugin1', 'node', '4.4.4', {
459+
component: '@here/plugin1',
460+
updates: [
461+
buildMockPackageUpdate(
462+
'plugin1/package.json',
463+
'plugin1/package.json'
464+
),
465+
],
466+
}),
467+
buildMockCandidatePullRequest('node1', 'node', '2.2.2', {
468+
component: '@here/pkgA',
469+
updates: [
470+
buildMockPackageUpdate('node1/package.json', 'node1/package.json'),
471+
],
472+
}),
473+
];
474+
plugin = new NodeWorkspace(
475+
github,
476+
'main',
477+
{
478+
plugin1: {releaseType: 'node'},
479+
node1: {releaseType: 'node'},
480+
},
481+
options
482+
);
483+
const newCandidates = await plugin.run(candidates);
484+
expect(newCandidates).lengthOf(1);
485+
const nodeCandidate = newCandidates.find(
486+
candidate => candidate.config.releaseType === 'node'
487+
);
488+
expect(nodeCandidate).to.not.be.undefined;
489+
const updates = nodeCandidate!.pullRequest.updates;
490+
assertHasUpdate(updates, 'node1/package.json');
491+
snapshotUpdate(updates, 'plugin1/package.json');
492+
});
493+
});
412494
});

0 commit comments

Comments
 (0)