Skip to content

Commit

Permalink
shared dep types
Browse files Browse the repository at this point in the history
  • Loading branch information
ecraig12345 committed Sep 10, 2024
1 parent 8c0a150 commit a0bf699
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion change/beachball-b14f577b-da9c-4db3-9cd8-f0d6fba25af8.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "patch",
"comment": "Internal refactoring: remove dependents from BumpInfo",
"comment": "Use a shared list of considered dependency types",
"packageName": "beachball",
"email": "[email protected]",
"dependentChangeType": "patch"
Expand Down
5 changes: 2 additions & 3 deletions src/bump/getDependentsForPackages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { BumpInfo, PackageDependents } from '../types/BumpInfo';

const depTypes = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'] as const;
import { consideredDependencies } from '../types/PackageInfo';

/**
* Gets dependents for all packages (child points to parents): if A depends on B, then `{B: [A]}`
Expand All @@ -20,7 +19,7 @@ export function getDependentsForPackages(
continue;
}

for (const depType of depTypes) {
for (const depType of consideredDependencies) {
for (const dep of Object.keys(info[depType] || {})) {
if (packageInfos[dep]) {
dependents[dep] ??= [];
Expand Down
4 changes: 2 additions & 2 deletions src/bump/performBump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { unlinkChangeFiles } from '../changefile/unlinkChangeFiles';
import { writeChangelog } from '../changelog/writeChangelog';
import { BumpInfo } from '../types/BumpInfo';
import { BeachballOptions } from '../types/BeachballOptions';
import { PackageInfos, PackageJson } from '../types/PackageInfo';
import { PackageInfos, PackageJson, consideredDependencies } from '../types/PackageInfo';
import { findProjectRoot } from 'workspace-tools';
import { npm } from '../packageManager/npm';
import { packageManager } from '../packageManager/packageManager';
Expand All @@ -23,7 +23,7 @@ export function writePackageJson(modifiedPackages: Set<string>, packageInfos: Pa
packageJson.version = info.version;
}

for (const depKind of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'] as const) {
for (const depKind of consideredDependencies) {
// updatedDeps contains all of the dependencies in the bump info since the beginning of a build job
const updatedDepsVersions = info[depKind];
if (updatedDepsVersions) {
Expand Down
10 changes: 3 additions & 7 deletions src/bump/setDependentVersions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BeachballOptions } from '../types/BeachballOptions';
import { BumpInfo } from '../types/BumpInfo';
import type { PackageInfos } from '../types/PackageInfo';
import { consideredDependencies, type PackageInfos } from '../types/PackageInfo';
import { bumpMinSemverRange } from './bumpMinSemverRange';

/**
Expand All @@ -21,12 +21,8 @@ export function setDependentVersions(
continue; // out of scope
}

for (const deps of [info.dependencies, info.devDependencies, info.peerDependencies, info.optionalDependencies]) {
if (!deps) {
continue; // package doesn't have this dep type
}

for (const [dep, existingVersionRange] of Object.entries(deps)) {
for (const depType of consideredDependencies) {
for (const [dep, existingVersionRange] of Object.entries(info[depType] || {})) {
const depPackage = packageInfos[dep];
if (!depPackage) {
continue; // external dependency
Expand Down
6 changes: 3 additions & 3 deletions src/publish/performPublishOverrides.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs-extra';
import { getWorkspaceRange } from '../packageManager/getWorkspaceRange';
import type { PackageInfos, PackageJson, PublishConfig } from '../types/PackageInfo';
import { consideredDependencies, type PackageInfos, type PackageJson, type PublishConfig } from '../types/PackageInfo';

const acceptedKeys: (keyof PublishConfig)[] = [
'types',
Expand Down Expand Up @@ -46,8 +46,8 @@ function performPublishConfigOverrides(packageJson: PackageJson): void {
* replacement.
*/
function performWorkspaceVersionOverrides(packageJson: PackageJson, packageInfos: PackageInfos): void {
const { dependencies, devDependencies, peerDependencies, optionalDependencies } = packageJson;
for (const deps of [dependencies, devDependencies, peerDependencies, optionalDependencies]) {
for (const depType of consideredDependencies) {
const deps = packageJson[depType];
if (!deps) continue;

for (const [depName, depVersion] of Object.entries(deps)) {
Expand Down
8 changes: 8 additions & 0 deletions src/types/PackageInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ export interface PackageGroupsInfo {
}

export type PackageGroups = { [groupName: string]: PackageGroupsInfo };

/** Types of dependencies to consider when bumping. */
export const consideredDependencies = [
'dependencies',
'devDependencies',
'peerDependencies',
'optionalDependencies',
] as const;

0 comments on commit a0bf699

Please sign in to comment.