Skip to content

Commit

Permalink
fix(build-cli): Exclude independent packages when bumping release gro…
Browse files Browse the repository at this point in the history
…ups (#12652)

When bumping deps scoped to a single release group, the `bump deps` tool
was including independent
packages. This change corrects that behavior so that only the release
group specified will be
updated.

BREAKING CHANGE: The `-p` flag has been changed to specify a package
name, which is consistent with
other commands. Use `--prerelease` to replace former uses of `-p`.
  • Loading branch information
tylerbutler authored Oct 25, 2022
1 parent 20d2932 commit cfe3c9d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
10 changes: 6 additions & 4 deletions build-tools/packages/build-cli/docs/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,25 @@ Update the dependency version of a specified package or release group. That is,

```
USAGE
$ flub bump deps [PACKAGE_OR_RELEASE_GROUP] [-p -t latest|newest|greatest|minor|patch|@next|@canary]
[--onlyBumpPrerelease] [-g client|server|azure|build-tools] [-x | --install | --commit | | | ] [-v]
$ flub bump deps [PACKAGE_OR_RELEASE_GROUP] [--prerelease -t
latest|newest|greatest|minor|patch|@next|@canary] [--onlyBumpPrerelease] [-g client|server|azure|build-tools | -p
<value>] [-x | --install | --commit | | | ] [-v]
ARGUMENTS
PACKAGE_OR_RELEASE_GROUP The name of a package or a release group.
FLAGS
-g, --releaseGroup=<option> Only bump dependencies within this release group.
<options: client|server|azure|build-tools>
-p, --prerelease Treat prerelease versions as valid versions to update to.
-t, --updateType=<option> Bump the current version of the dependency according to this bump type.
-p, --package=<value> Only bump dependencies of this package.
-t, --updateType=<option> [default: minor] Bump the current version of the dependency according to this bump type.
<options: latest|newest|greatest|minor|patch|@next|@canary>
-v, --verbose Verbose logging.
-x, --skipChecks Skip all checks.
--[no-]commit Commit changes to a new branch.
--[no-]install Update lockfiles by running 'npm install' automatically.
--onlyBumpPrerelease Only bump dependencies that are on pre-release versions.
--prerelease Treat prerelease versions as valid versions to update to.
DESCRIPTION
Update the dependency version of a specified package or release group. That is, if one or more packages in the repo
Expand Down
28 changes: 18 additions & 10 deletions build-tools/packages/build-cli/src/commands/bump/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { FluidRepo } from "@fluidframework/build-tools";

import { packageOrReleaseGroupArg } from "../../args";
import { BaseCommand } from "../../base";
import { checkFlags, dependencyUpdateTypeFlag, releaseGroupFlag, skipCheckFlag } from "../../flags";
import {
checkFlags,
dependencyUpdateTypeFlag,
packageSelectorFlag,
releaseGroupFlag,
skipCheckFlag,
} from "../../flags";
import {
generateBumpDepsBranchName,
generateBumpDepsCommitMessage,
Expand Down Expand Up @@ -40,9 +46,9 @@ export default class DepsCommand extends BaseCommand<typeof DepsCommand.flags> {
updateType: dependencyUpdateTypeFlag({
char: "t",
description: "Bump the current version of the dependency according to this bump type.",
default: "minor",
}),
prerelease: Flags.boolean({
char: "p",
dependsOn: ["updateType"],
description: "Treat prerelease versions as valid versions to update to.",
}),
Expand All @@ -51,6 +57,11 @@ export default class DepsCommand extends BaseCommand<typeof DepsCommand.flags> {
}),
releaseGroup: releaseGroupFlag({
description: "Only bump dependencies within this release group.",
exclusive: ["package"],
}),
package: packageSelectorFlag({
description: "Only bump dependencies of this package.",
exclusive: ["releaseGroup"],
}),
commit: checkFlags.commit,
install: checkFlags.install,
Expand Down Expand Up @@ -102,11 +113,6 @@ export default class DepsCommand extends BaseCommand<typeof DepsCommand.flags> {
this.error("ERROR: No dependency provided.");
}

/**
* The version range or bump type (depending on the CLI arguments) to set.
*/
const versionToSet = flags.updateType ?? "current";

/**
* A list of package names on which to update dependencies.
*/
Expand Down Expand Up @@ -137,9 +143,11 @@ export default class DepsCommand extends BaseCommand<typeof DepsCommand.flags> {

this.logHr();
this.log(`Dependencies: ${chalk.blue(args.package_or_release_group)}`);
this.log(`Packages: ${chalk.blueBright(flags.releaseGroup ?? "all packages")}`);
this.log(
`Packages: ${chalk.blueBright(flags.releaseGroup ?? flags.package ?? "all packages")}`,
);
this.log(`Prerelease: ${flags.prerelease ? chalk.green("yes") : "no"}`);
this.log(`Bump type: ${chalk.bold(versionToSet)}`);
this.log(`Bump type: ${chalk.bold(flags.updateType ?? "unknown")}`);
this.logHr();
this.log("");

Expand All @@ -149,7 +157,7 @@ export default class DepsCommand extends BaseCommand<typeof DepsCommand.flags> {

const { updatedPackages, updatedDependencies } = await npmCheckUpdates(
context,
flags.releaseGroup, // if undefined the whole repo will be checked
flags.releaseGroup ?? flags.package, // if undefined the whole repo will be checked
depsToUpdate,
args.package_or_release_group,
flags.updateType,
Expand Down
43 changes: 17 additions & 26 deletions build-tools/packages/build-cli/src/lib/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,23 @@ export async function npmCheckUpdates(
// There can be a lot of duplicate log lines from npm-check-updates, so collect and dedupe before logging.
const upgradeLogLines = new Set<string>();
const searchGlobs: string[] = [];
let repoPath: string;
const repoPath = context.repo.resolvedRoot;

const releaseGroupsToCheck =
releaseGroup === undefined
releaseGroup === undefined // run on the whole repo
? [...context.repo.releaseGroups.keys()]
: isReleaseGroup(releaseGroup)
: isReleaseGroup(releaseGroup) // run on just this release group
? [releaseGroup]
: undefined;

const packagesToCheck = isReleaseGroup(releaseGroup) ? undefined : releaseGroup;

// Run on the whole repo
if (releaseGroupsToCheck === undefined) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const pkg = context.fullPackageMap.get(releaseGroup!);
if (pkg === undefined) {
throw new Error(`Package not found in context: ${releaseGroup}`);
}

repoPath = pkg.directory;
searchGlobs.push(pkg.directory);
} else {
repoPath = context.repo.resolvedRoot;
const packagesToCheck =
releaseGroup === undefined // run on the whole repo
? [...context.independentPackages] // include all independent packages
: isReleaseGroup(releaseGroup)
? [] // run on a release group so no independent packages should be included
: [context.fullPackageMap.get(releaseGroup)]; // the releaseGroup argument must be a package

if (releaseGroupsToCheck !== undefined) {
for (const group of releaseGroupsToCheck) {
if (group === releaseGroupFilter) {
log?.verbose(
Expand All @@ -113,21 +106,19 @@ export async function npmCheckUpdates(

searchGlobs.push(
...releaseGroupRoot.workspaceGlobs.map((g) =>
path.join(
path.relative(context.repo.resolvedRoot, releaseGroupRoot.repoPath),
g,
),
path.join(path.relative(repoPath, releaseGroupRoot.repoPath), g),
),
// Includes the root package.json, in case there are deps there that also need upgrade.
// path.join(releaseGroupRoot.repoPath, "package.json"),
path.relative(context.repo.resolvedRoot, releaseGroupRoot.repoPath),
path.relative(repoPath, releaseGroupRoot.repoPath),
);
}
}

if (packagesToCheck === undefined) {
for (const pkg of context.independentPackages) {
searchGlobs.push(path.relative(context.repo.resolvedRoot, pkg.directory));
if (packagesToCheck !== undefined) {
for (const pkg of packagesToCheck) {
if (pkg !== undefined) {
searchGlobs.push(path.relative(repoPath, pkg.directory));
}
}
}

Expand Down

0 comments on commit cfe3c9d

Please sign in to comment.