Skip to content

Commit

Permalink
filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tugrulates committed Feb 28, 2025
1 parent 69f4092 commit 9e7e6f1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
16 changes: 8 additions & 8 deletions tool/forge/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function compileCommand(targets: string[]) {
.option("--checksum", "Create a checksum file.", { default: false })
.option("--install=[directory:file]", "Install for local user.")
.option("--concurrency=<number:number>", "Max concurrent compilations.")
.action(async (options, ...filter) => {
const packages = (await workspace({ filter }))
.action(async (options, ...filters) => {
const packages = (await workspace({ filters }))
.filter((pkg) => pkg.config.compile);

Check warning on line 38 in tool/forge/cli.ts

View check run for this annotation

Codecov / codecov/patch

tool/forge/cli.ts#L36-L38

Added lines #L36 - L38 were not covered by tests
await pool(packages.map(async (pkg) => {
const artifacts = await compile(pkg, options);
Expand All @@ -60,8 +60,8 @@ function bumpCommand() {
"GitHub personal token for GitHub actions.",
{ prefix: "GITHUB_" },
)
.action(async (options, ...filter) => {
const packages = (await workspace({ filter }))
.action(async (options, ...filters) => {
const packages = (await workspace({ filters }))
.filter((pkg) => pkg.update);

Check warning on line 65 in tool/forge/cli.ts

View check run for this annotation

Codecov / codecov/patch

tool/forge/cli.ts#L63-L65

Added lines #L63 - L65 were not covered by tests
const pr = await bump(packages, options);
if (pr) console.log(`🚀 Created version bump pull request [${pr.url}]`);
Expand All @@ -79,8 +79,8 @@ function releaseCommand() {
"GitHub personal token for GitHub actions.",
{ prefix: "GITHUB_", required: true },
)
.action(async (options, ...filter) => {
const packages = (await workspace({ filter }))
.action(async (options, ...filters) => {
const packages = (await workspace({ filters }))
.filter((pkg) => pkg.config.version !== pkg.release?.version);

Check warning on line 84 in tool/forge/cli.ts

View check run for this annotation

Codecov / codecov/patch

tool/forge/cli.ts#L82-L84

Added lines #L82 - L84 were not covered by tests
await pool(packages.map(async (pkg) => {
const [rls, assets] = await release(pkg, options);
Expand All @@ -97,8 +97,8 @@ function listCommand() {
.option("--changelog", "Print changelog of updated packages.", {
default: false,
})
.action(async ({ changelog }, ...filter) => {
const packages = await workspace({ filter });
.action(async ({ changelog }, ...filters) => {
const packages = await workspace({ filters });

Check warning on line 101 in tool/forge/cli.ts

View check run for this annotation

Codecov / codecov/patch

tool/forge/cli.ts#L100-L101

Added lines #L100 - L101 were not covered by tests
new Table().body(
packages.map((pkg) => [
"📦",
Expand Down
32 changes: 14 additions & 18 deletions tool/forge/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,22 +310,18 @@ Deno.test("workspace() filters packages", async () => {
await createPackage(repo.path(), {
workspace: ["./dir1/pkg1", "./dir2/pkg2", "./dir2/pkg3"],
});
const pkg1 = await createPackage(repo.path("dir1/pkg1"), { name: "pkg1" });
const pkg2 = await createPackage(repo.path("dir2/pkg2"), { name: "pkg2" });
const pkg3 = await createPackage(repo.path("dir2/pkg3"), { name: "pkg3" });
assertEquals(await workspace({ directory, filter: ["pkg1"] }), [pkg1]);
assertEquals(await workspace({ directory, filter: ["pkg2"] }), [pkg2]);
assertEquals(await workspace({ directory, filter: ["*1"] }), [pkg1]);
assertEquals(await workspace({ directory, filter: ["pkg*"] }), [
pkg1,
pkg2,
pkg3,
]);
assertEquals(await workspace({ directory, filter: ["dir1/pkg1"] }), [pkg1]);
assertEquals(await workspace({ directory, filter: ["dir2/*"] }), [
pkg2,
pkg3,
]);
assertEquals(await workspace({ directory, filter: ["*/pkg2"] }), [pkg2]);
assertEquals(await workspace({ directory, filter: ["none*"] }), []);
const p1 = await createPackage(repo.path("dir1/pkg1"), { name: "pkg1" });
const p2 = await createPackage(repo.path("dir2/pkg2"), { name: "pkg2" });
const p3 = await createPackage(repo.path("dir2/pkg3"), { name: "pkg3" });
assertEquals(await workspace({ directory, filters: ["pkg1"] }), [p1]);
assertEquals(await workspace({ directory, filters: ["pkg2"] }), [p2]);
assertEquals(await workspace({ directory, filters: ["*1"] }), [p1]);
assertEquals(await workspace({ directory, filters: ["pkg*"] }), [p1, p2, p3]);
assertEquals(await workspace({ directory, filters: ["dir1/pkg1"] }), [p1]);
assertEquals(await workspace({ directory, filters: ["*1/*"] }), [p1]);
assertEquals(await workspace({ directory, filters: ["*2/pkg?"] }), [p2, p3]);
assertEquals(await workspace({ directory, filters: ["dir2/*"] }), [p2, p3]);
assertEquals(await workspace({ directory, filters: ["*/pkg2"] }), [p2]);
assertEquals(await workspace({ directory, filters: ["none*"] }), []);
assertEquals(await workspace({ directory, filters: ["*2", "*3"] }), [p2, p3]);
});
6 changes: 3 additions & 3 deletions tool/forge/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export interface WorkspaceOptions {
*
* @default {[]}
*/
filter?: string[];
filters?: string[];
}

/** Returns information about a package. */
Expand Down Expand Up @@ -217,8 +217,8 @@ export async function packageInfo(options?: PackageOptions): Promise<Package> {
export async function workspace(
options?: WorkspaceOptions,
): Promise<Package[]> {
const { directory = ".", filter = [] } = options ?? {};
const patterns = filter.map((f) => globToRegExp(f));
const { directory = ".", filters = [] } = options ?? {};
const patterns = filters.map((f) => globToRegExp(f));
const pkg = await packageInfo({ directory, ...options });
const packages = pkg.config.workspace === undefined
? [pkg]
Expand Down

0 comments on commit 9e7e6f1

Please sign in to comment.