Skip to content

Commit

Permalink
feat: add --no-bump-peer-deps flag to prevent bumping peerDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Aug 29, 2024
1 parent e489896 commit 583232a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 5 deletions.
36 changes: 36 additions & 0 deletions src/__e2e__/bump.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,42 @@ describe('version bumping', () => {
expect(changeFiles).toHaveLength(0);
});

it('does not bumps dependent packages with `peerDependencies` when `bumpPeerDeps=false`', async () => {
const monorepo: RepoFixture['folders'] = {
packages: {
'pkg-1': { version: '1.0.0' },
'pkg-2': { version: '1.0.0', dependencies: { 'pkg-1': '1.0.0' } },
'pkg-3': { version: '1.0.0', devDependencies: { 'pkg-2': '1.0.0' } },
'pkg-4': { version: '1.0.0', peerDependencies: { 'pkg-3': '1.0.0' } },
'pkg-5': { version: '1.0.0', optionalDependencies: { 'pkg-4': '1.0.0' } },
},
};
repositoryFactory = new RepositoryFactory({ folders: monorepo });
const repo = repositoryFactory.cloneRepository();

generateChangeFiles(['pkg-1'], repo.rootPath);

repo.push();

await bump({ path: repo.rootPath, bumpDeps: true, bumpPeerDeps: false } as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);

const pkg1NewVersion = '1.1.0';
const dependentNewVersion = '1.0.1';
expect(packageInfos['pkg-1'].version).toBe(pkg1NewVersion);
expect(packageInfos['pkg-2'].version).toBe(dependentNewVersion);
expect(packageInfos['pkg-3'].version).toBe(dependentNewVersion);

expect(packageInfos['pkg-2'].dependencies!['pkg-1']).toBe(pkg1NewVersion);
expect(packageInfos['pkg-3'].devDependencies!['pkg-2']).toBe(dependentNewVersion);
expect(packageInfos['pkg-4'].peerDependencies!['pkg-3']).toBe('1.0.0');
expect(packageInfos['pkg-5'].optionalDependencies!['pkg-4']).toBe('1.0.0');

const changeFiles = getChangeFiles(repo.rootPath);
expect(changeFiles).toHaveLength(0);
});

it('bumps all grouped packages', async () => {
const monorepo: RepoFixture['folders'] = {
packages: {
Expand Down
2 changes: 1 addition & 1 deletion src/bump/bumpInPlace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function bumpInPlace(bumpInfo: BumpInfo, options: BeachballOptions): void

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

setGroupsInBumpInfo(bumpInfo, options);
Expand Down
9 changes: 7 additions & 2 deletions src/bump/setDependentVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { bumpMinSemverRange } from './bumpMinSemverRange';
export function setDependentVersions(
packageInfos: PackageInfos,
scopedPackages: Set<string>,
{ verbose }: BeachballOptions
{ verbose, bumpPeerDeps = true }: BeachballOptions
): { [dependent: string]: Set<string> } {
const dependentChangedBy: { [dependent: string]: Set<string> } = {};

Expand All @@ -14,7 +14,12 @@ export function setDependentVersions(
continue;
}

for (const deps of [info.dependencies, info.devDependencies, info.peerDependencies, info.optionalDependencies]) {
for (const deps of [
info.dependencies,
info.devDependencies,
bumpPeerDeps && info.peerDependencies,
info.optionalDependencies,
]) {
if (!deps) {
continue;
}
Expand Down
10 changes: 8 additions & 2 deletions src/bump/setDependentsInBumpInfo.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { BumpInfo } from '../types/BumpInfo';
import type { BeachballOptions } from '../types/BeachballOptions';

/**
* Gets dependents for all packages
*
* Example: "BigApp" deps on "SomeUtil", "BigApp" would be the dependent
*/
export function setDependentsInBumpInfo(bumpInfo: BumpInfo): void {
export function setDependentsInBumpInfo(bumpInfo: BumpInfo, { bumpPeerDeps = true }: BeachballOptions): void {
const { packageInfos, scopedPackages } = bumpInfo;
const dependents: BumpInfo['dependents'] = {};

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

for (const deps of [info.dependencies, info.devDependencies, info.peerDependencies, info.optionalDependencies]) {
for (const deps of [
info.dependencies,
info.devDependencies,
bumpPeerDeps && info.peerDependencies,
info.optionalDependencies,
]) {
for (const dep of Object.keys(deps || {})) {
if (packageInfos[dep]) {
dependents[dep] ??= [];
Expand Down
1 change: 1 addition & 0 deletions src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Options:
--no-push - skip pushing changes back to git remote origin
--no-publish - skip publishing to the npm registry
--no-bump - skip both bumping versions and pushing changes back to git remote origin when publishing;
--no-bump-peer-deps - skip bumping versions of newly published peer dependencies
--no-commit - for the change command: stage change files only without autocommitting them
--help, -?, -h - this very help message
--yes, -y - skips the prompts for publish
Expand Down
1 change: 1 addition & 0 deletions src/options/getCliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const booleanOptions = [
'all',
'bump',
'bumpDeps',
'bumpPeerDeps',
'commit',
'disallowDeletedChangeFiles',
'fetch',
Expand Down
1 change: 1 addition & 0 deletions src/options/getDefaultOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function getDefaultOptions(): BeachballOptions {
branch: 'origin/master',
bump: true,
bumpDeps: true,
bumpPeerDeps: true,
canaryName: undefined,
changehint: 'Run "beachball change" to create a change file',
command: 'change',
Expand Down
6 changes: 6 additions & 0 deletions src/types/BeachballOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface CliOptions
| 'access'
| 'branch'
| 'bumpDeps'
| 'bumpPeerDeps'
| 'changehint'
| 'depth'
| 'disallowedChangeTypes'
Expand Down Expand Up @@ -81,6 +82,11 @@ export interface RepoOptions {
* @default true
*/
bumpDeps: boolean;
/**
* Bump dependent packages (peerDependencies) during publish (bump A if A depends on B as `peerDependencies`)
* @default true
*/
bumpPeerDeps?: boolean;
/** Options for customizing change file prompt. */
changeFilePrompt?: ChangeFilePromptOptions;
/**
Expand Down

0 comments on commit 583232a

Please sign in to comment.