Skip to content

Commit

Permalink
rm setDependencyVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerbutler committed Oct 29, 2024
1 parent 6ac02ea commit 8e2237b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { simpleGit } from "simple-git";

import { loadFluidRepo } from "../fluidRepo.js";
import type { ReleaseGroupName, WorkspaceName } from "../types.js";
import { setDependencyVersion, setVersion } from "../versions.js";
import { setVersion } from "../versions.js";

import { testDataPath, testRepoRoot } from "./init.js";

Expand Down Expand Up @@ -70,35 +70,3 @@ describe("setVersion", () => {
expect(allCorrect).to.be.true;
});
});

describe("setDependencyVersion", () => {
afterEach(async () => {
await git.checkout(["HEAD", "--", testRepoRoot]);
repo.reload();
});

it("update release group deps", async () => {
await setDependencyVersion(
main.packages,
group2.packages.map((p) => p.name),
"workspace:~",
);
repo.reload();

const depsToCheck = new Set(group2.packages.map((p) => p.name));
const allCorrect = main.packages.every((pkg) => {
for (const { name, version } of pkg.combinedDependencies) {
if (!depsToCheck.has(name)) {
continue;
}
const matches = version === "workspace:~";
if (matches === false) {
console.error(`${name} has incorrect version/range: ${version}`);
return false;
}
}
return true;
});
expect(allCorrect).to.be.true;
});
});
55 changes: 0 additions & 55 deletions build-tools/packages/build-infrastructure/src/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License.
*/

import type { InterdependencyRange } from "@fluid-tools/version-tools";
import * as semver from "semver";

import { updatePackageJsonFile } from "./packageJsonUtils.js";
Expand All @@ -29,57 +28,3 @@ export async function setVersion<J extends PackageJson>(
});
}
}

/**
*
* Note that any loaded objects such as an IFluidRepo instance may need to be reloaded after calling this function.
*
* @param packages - Packages whose dependencies should be updated.
* @param dependencyNames - The names of the dependencies that should be modified.
* @param dependencyRange - The new dependency range to use.
*/
export async function setDependencyVersion(
packages: IPackage[],
dependencyNames: string[],
dependencyRange: InterdependencyRange,
): Promise<void> {
const depRangeToSet =
typeof dependencyRange === "string" ? dependencyRange : dependencyRange.version;

const dependenciesToUpdate: ReadonlySet<string> = new Set(dependencyNames);
const savePromises: Promise<void>[] = [];
for (const pkg of packages) {
for (const { name, depKind } of pkg.combinedDependencies) {
if (!dependenciesToUpdate.has(name)) {
continue;
}

switch (depKind) {
case "dev": {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
pkg.packageJson.devDependencies![name] = depRangeToSet;
break;
}

case "peer": {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
pkg.packageJson.peerDependencies![name] = depRangeToSet;
break;
}

case "prod": {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
pkg.packageJson.dependencies![name] = depRangeToSet;
break;
}

default: {
throw new Error(`Unknown dependency type: ${depKind}`);
}
}
}
savePromises.push(pkg.savePackageJson());
}

await Promise.all(savePromises);
}

0 comments on commit 8e2237b

Please sign in to comment.