Skip to content

Commit 9a90c29

Browse files
committed
feat: add --no-bump-peer-deps flag to prevent bumping peerDependencies
1 parent e489896 commit 9a90c29

8 files changed

+61
-5
lines changed

src/__e2e__/bump.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,42 @@ describe('version bumping', () => {
155155
expect(changeFiles).toHaveLength(0);
156156
});
157157

158+
it('does not bumps dependent packages with `peerDependencies` when `bumpPeerDeps=false`', async () => {
159+
const monorepo: RepoFixture['folders'] = {
160+
packages: {
161+
'pkg-1': { version: '1.0.0' },
162+
'pkg-2': { version: '1.0.0', dependencies: { 'pkg-1': '1.0.0' } },
163+
'pkg-3': { version: '1.0.0', devDependencies: { 'pkg-2': '1.0.0' } },
164+
'pkg-4': { version: '1.0.0', peerDependencies: { 'pkg-3': '1.0.0' } },
165+
'pkg-5': { version: '1.0.0', optionalDependencies: { 'pkg-4': '1.0.0' } },
166+
},
167+
};
168+
repositoryFactory = new RepositoryFactory({ folders: monorepo });
169+
const repo = repositoryFactory.cloneRepository();
170+
171+
generateChangeFiles(['pkg-1'], repo.rootPath);
172+
173+
repo.push();
174+
175+
await bump({ path: repo.rootPath, bumpDeps: true, bumpPeerDeps: false } as BeachballOptions);
176+
177+
const packageInfos = getPackageInfos(repo.rootPath);
178+
179+
const pkg1NewVersion = '1.1.0';
180+
const dependentNewVersion = '1.0.1';
181+
expect(packageInfos['pkg-1'].version).toBe(pkg1NewVersion);
182+
expect(packageInfos['pkg-2'].version).toBe(dependentNewVersion);
183+
expect(packageInfos['pkg-3'].version).toBe(dependentNewVersion);
184+
185+
expect(packageInfos['pkg-2'].dependencies!['pkg-1']).toBe(pkg1NewVersion);
186+
expect(packageInfos['pkg-3'].devDependencies!['pkg-2']).toBe(dependentNewVersion);
187+
expect(packageInfos['pkg-4'].peerDependencies!['pkg-3']).toBe('1.0.0');
188+
expect(packageInfos['pkg-5'].optionalDependencies!['pkg-4']).toBe('1.0.0');
189+
190+
const changeFiles = getChangeFiles(repo.rootPath);
191+
expect(changeFiles).toHaveLength(0);
192+
});
193+
158194
it('bumps all grouped packages', async () => {
159195
const monorepo: RepoFixture['folders'] = {
160196
packages: {

src/bump/bumpInPlace.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function bumpInPlace(bumpInfo: BumpInfo, options: BeachballOptions): void
1717

1818
// pass 1: figure out all the change types for all the packages taking into account the bumpDeps option and version groups
1919
if (bumpDeps) {
20-
setDependentsInBumpInfo(bumpInfo);
20+
setDependentsInBumpInfo(bumpInfo, options);
2121
}
2222

2323
setGroupsInBumpInfo(bumpInfo, options);

src/bump/setDependentVersions.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { bumpMinSemverRange } from './bumpMinSemverRange';
55
export function setDependentVersions(
66
packageInfos: PackageInfos,
77
scopedPackages: Set<string>,
8-
{ verbose }: BeachballOptions
8+
{ verbose, bumpPeerDeps = true }: BeachballOptions
99
): { [dependent: string]: Set<string> } {
1010
const dependentChangedBy: { [dependent: string]: Set<string> } = {};
1111

@@ -14,7 +14,12 @@ export function setDependentVersions(
1414
continue;
1515
}
1616

17-
for (const deps of [info.dependencies, info.devDependencies, info.peerDependencies, info.optionalDependencies]) {
17+
for (const deps of [
18+
info.dependencies,
19+
info.devDependencies,
20+
bumpPeerDeps && info.peerDependencies,
21+
info.optionalDependencies,
22+
]) {
1823
if (!deps) {
1924
continue;
2025
}

src/bump/setDependentsInBumpInfo.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { BumpInfo } from '../types/BumpInfo';
2+
import type { BeachballOptions } from '../types/BeachballOptions';
23

34
/**
45
* Gets dependents for all packages
56
*
67
* Example: "BigApp" deps on "SomeUtil", "BigApp" would be the dependent
78
*/
8-
export function setDependentsInBumpInfo(bumpInfo: BumpInfo): void {
9+
export function setDependentsInBumpInfo(bumpInfo: BumpInfo, { bumpPeerDeps = true }: BeachballOptions): void {
910
const { packageInfos, scopedPackages } = bumpInfo;
1011
const dependents: BumpInfo['dependents'] = {};
1112

@@ -14,7 +15,12 @@ export function setDependentsInBumpInfo(bumpInfo: BumpInfo): void {
1415
continue;
1516
}
1617

17-
for (const deps of [info.dependencies, info.devDependencies, info.peerDependencies, info.optionalDependencies]) {
18+
for (const deps of [
19+
info.dependencies,
20+
info.devDependencies,
21+
bumpPeerDeps && info.peerDependencies,
22+
info.optionalDependencies,
23+
]) {
1824
for (const dep of Object.keys(deps || {})) {
1925
if (packageInfos[dep]) {
2026
dependents[dep] ??= [];

src/help.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Options:
3333
--no-push - skip pushing changes back to git remote origin
3434
--no-publish - skip publishing to the npm registry
3535
--no-bump - skip both bumping versions and pushing changes back to git remote origin when publishing;
36+
--no-bump-peer-deps - skip bumping versions of newly published peer dependencies
3637
--no-commit - for the change command: stage change files only without autocommitting them
3738
--help, -?, -h - this very help message
3839
--yes, -y - skips the prompts for publish

src/options/getCliOptions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const booleanOptions = [
99
'all',
1010
'bump',
1111
'bumpDeps',
12+
'bumpPeerDeps',
1213
'commit',
1314
'disallowDeletedChangeFiles',
1415
'fetch',

src/options/getDefaultOptions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function getDefaultOptions(): BeachballOptions {
1313
branch: 'origin/master',
1414
bump: true,
1515
bumpDeps: true,
16+
bumpPeerDeps: true,
1617
canaryName: undefined,
1718
changehint: 'Run "beachball change" to create a change file',
1819
command: 'change',

src/types/BeachballOptions.ts

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface CliOptions
3030
all: boolean;
3131
authType: AuthType;
3232
bump: boolean;
33+
bumpPeerDeps?: boolean;
3334
canaryName?: string | undefined;
3435
command: string;
3536
commit?: boolean;
@@ -81,6 +82,11 @@ export interface RepoOptions {
8182
* @default true
8283
*/
8384
bumpDeps: boolean;
85+
/**
86+
* Bump dependent packages (peerDependencies) during publish (bump A if A depends on B as `peerDependencies`)
87+
* @default true
88+
*/
89+
bumpPeerDeps?: boolean;
8490
/** Options for customizing change file prompt. */
8591
changeFilePrompt?: ChangeFilePromptOptions;
8692
/**

0 commit comments

Comments
 (0)