diff --git a/__snapshots__/node-workspace.js b/__snapshots__/node-workspace.js index 56175e499..41cba5516 100644 --- a/__snapshots__/node-workspace.js +++ b/__snapshots__/node-workspace.js @@ -238,6 +238,61 @@ Release notes for path: node1, releaseType: node This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). ` +exports['NodeWorkspace plugin run walks dependency tree and updates previously untouched packages (prerelease) 1'] = ` +:robot: I have created a release *beep* *boop* +--- + + +
@here/pkgA: 3.3.4-beta + +Release notes for path: node1, releaseType: node +
+ +
pkgB: 2.2.3-beta + +## [2.2.3-beta](https://github.com/googleapis/node-test-repo/compare/pkgB-v2.2.2-beta...pkgB-v2.2.3-beta) (1983-10-10) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @here/pkgA bumped from 3.3.3 to 3.3.4-beta +
+ +
pkgC: 1.1.2-beta + +## 1.1.2-beta (1983-10-10) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @here/pkgB bumped from 2.2.2 to 2.2.3-beta +
+ +
@here/pkgD: 4.4.5-beta + +Release notes for path: node4, releaseType: node +
+ +
pkgE: 1.0.1-beta + +## 1.0.1-beta (1983-10-10) + + +### Dependencies + +* The following workspace dependencies were updated + * dependencies + * @here/pkgA bumped to 3.3.4-beta +
+ +--- +This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). +` + exports['NodeWorkspace plugin run walks dependency tree and updates previously untouched packages 1'] = ` :robot: I have created a release *beep* *boop* --- diff --git a/src/plugins/node-workspace.ts b/src/plugins/node-workspace.ts index 3e942899a..7424ab64d 100644 --- a/src/plugins/node-workspace.ts +++ b/src/plugins/node-workspace.ts @@ -29,13 +29,13 @@ import { appendDependenciesSectionToChangelog, addPath, } from './workspace'; -import {PatchVersionUpdate} from '../versioning-strategy'; import {Strategy} from '../strategy'; import {Commit} from '../commit'; import {Release} from '../release'; import {CompositeUpdater} from '../updaters/composite'; import {PackageJson, newVersionWithRange} from '../updaters/node/package-json'; import {Logger} from '../util/logger'; +import {PatchVersionUpdate} from '../versioning-strategy'; interface ParsedPackageJson { name: string; @@ -170,6 +170,9 @@ export class NodeWorkspace extends WorkspacePlugin { protected bumpVersion(pkg: Package): Version { const version = Version.parse(pkg.version); + const strategy = this.strategiesByPath[pkg.path]; + + if (strategy) return strategy.versioningStrategy.bump(version, []); return new PatchVersionUpdate().bump(version); } diff --git a/test/plugins/node-workspace.ts b/test/plugins/node-workspace.ts index b9a186acf..2bff93f73 100644 --- a/test/plugins/node-workspace.ts +++ b/test/plugins/node-workspace.ts @@ -38,6 +38,7 @@ import {ReleasePleaseManifest} from '../../src/updaters/release-please-manifest' import {Node} from '../../src/strategies/node'; import {TagName} from '../../src/util/tag-name'; import {Generic} from '../../src/updaters/generic'; +import {PrereleaseVersioningStrategy} from '../../src/versioning-strategies/prerelease'; const sandbox = sinon.createSandbox(); const fixturesPath = './test/fixtures/plugins/node-workspace'; @@ -314,6 +315,122 @@ describe('NodeWorkspace plugin', () => { expect(updater.versionsMap?.get('node5')?.toString()).to.eql('1.0.1'); snapshot(dateSafe(nodeCandidate!.pullRequest.body.toString())); }); + it('walks dependency tree and updates previously untouched packages (prerelease)', async () => { + const candidates: CandidateReleasePullRequest[] = [ + buildMockCandidatePullRequest('node1', 'node', '3.3.4-beta', { + component: '@here/pkgA', + updates: [ + buildMockPackageUpdate('node1/package.json', 'node1/package.json'), + ], + }), + buildMockCandidatePullRequest('node4', 'node', '4.4.5-beta', { + component: '@here/pkgD', + updates: [ + buildMockPackageUpdate('node4/package.json', 'node4/package.json'), + ], + }), + ]; + stubFilesFromFixtures({ + sandbox, + github, + fixturePath: fixturesPath, + files: [ + 'node1/package.json', + 'node2/package.json', + 'node3/package.json', + 'node4/package.json', + 'node5/package.json', + ], + flatten: false, + targetBranch: 'main', + }); + + await plugin.preconfigure( + { + node1: new Node({ + github, + targetBranch: 'main', + path: 'node1', + packageName: '@here/pkgA', + versioningStrategy: new PrereleaseVersioningStrategy({ + prereleaseType: 'beta', + }), + }), + node2: new Node({ + github, + targetBranch: 'main', + path: 'node2', + packageName: '@here/pkgB', + versioningStrategy: new PrereleaseVersioningStrategy({ + prereleaseType: 'beta', + }), + }), + node3: new Node({ + github, + targetBranch: 'main', + path: 'node3', + packageName: '@here/pkgC', + versioningStrategy: new PrereleaseVersioningStrategy({ + prereleaseType: 'beta', + }), + }), + node4: new Node({ + github, + targetBranch: 'main', + path: 'node4', + packageName: '@here/pkgD', + versioningStrategy: new PrereleaseVersioningStrategy({ + prereleaseType: 'beta', + }), + }), + node5: new Node({ + github, + targetBranch: 'main', + path: 'node5', + packageName: '@here/pkgE', + versioningStrategy: new PrereleaseVersioningStrategy({ + prereleaseType: 'beta', + }), + }), + }, + {}, + { + node2: { + tag: new TagName(new Version(2, 2, 2, 'beta'), 'pkgB'), + sha: '', + notes: '', + }, + } + ); + + const newCandidates = await plugin.run(candidates); + expect(newCandidates).lengthOf(1); + const nodeCandidate = newCandidates.find( + candidate => candidate.config.releaseType === 'node' + ); + expect(nodeCandidate).to.not.be.undefined; + const updates = nodeCandidate!.pullRequest.updates; + assertHasVersionUpdate(updates, 'node1/package.json', '3.3.4-beta'); + assertHasVersionUpdate(updates, 'node2/package.json', '2.2.3-beta'); + assertHasVersionUpdate(updates, 'node3/package.json', '1.1.2-beta'); + assertHasVersionUpdate(updates, 'node4/package.json', '4.4.5-beta'); + assertHasVersionUpdate(updates, 'node5/package.json', '1.0.1-beta'); + const updater = assertHasUpdate( + updates, + '.release-please-manifest.json', + ReleasePleaseManifest + ).updater as ReleasePleaseManifest; + expect(updater.versionsMap?.get('node2')?.toString()).to.eql( + '2.2.3-beta' + ); + expect(updater.versionsMap?.get('node3')?.toString()).to.eql( + '1.1.2-beta' + ); + expect(updater.versionsMap?.get('node5')?.toString()).to.eql( + '1.0.1-beta' + ); + snapshot(dateSafe(nodeCandidate!.pullRequest.body.toString())); + }); it('appends dependency notes to an updated module', async () => { const existingNotes = '### Dependencies\n\n* update dependency foo/bar to 1.2.3';