Skip to content

Commit

Permalink
feat: serializable return values
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Aug 26, 2024
1 parent 045f7d7 commit 9b52955
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-bottles-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@manypkg/find-root": minor
---

feat: export DEFAULT_TOOLS
5 changes: 5 additions & 0 deletions .changeset/chilly-moles-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@manypkg/tools": major
---

feat: serializable return values
10 changes: 5 additions & 5 deletions packages/find-root/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
* monorepo implementations first, with tools based on custom file schemas
* checked last.
*/
const DEFAULT_TOOLS: Tool[] = [
export const DEFAULT_TOOLS: Tool[] = [
YarnTool,
PnpmTool,
LernaTool,
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function findRoot(
tools.map(async (tool): Promise<MonorepoRoot | undefined> => {
if (await tool.isMonorepoRoot(directory)) {
return {
tool: tool,
tool: tool.type,
rootDir: directory,
};
}
Expand Down Expand Up @@ -125,7 +125,7 @@ export async function findRoot(
}

return {
tool: RootTool,
tool: RootTool.type,
rootDir,
};
}
Expand All @@ -144,7 +144,7 @@ export function findRootSync(
for (const tool of tools) {
if (tool.isMonorepoRootSync(directory)) {
monorepoRoot = {
tool: tool,
tool: tool.type,
rootDir: directory,
};
return directory;
Expand Down Expand Up @@ -173,7 +173,7 @@ export function findRootSync(
}

return {
tool: RootTool,
tool: RootTool.type,
rootDir,
};
}
Expand Down
23 changes: 14 additions & 9 deletions packages/get-packages/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import path from "path";
import { findRoot, findRootSync, FindRootOptions } from "@manypkg/find-root";
import {
findRoot,
findRootSync,
FindRootOptions,
DEFAULT_TOOLS,
} from "@manypkg/find-root";
import { Packages, MonorepoRoot, Tool } from "@manypkg/tools";

export type { Tool, Package, Packages } from "@manypkg/tools";
Expand Down Expand Up @@ -36,12 +41,12 @@ export async function getPackages(
options?: GetPackagesOptions
): Promise<Packages> {
const monorepoRoot: MonorepoRoot = await findRoot(dir, options);
const packages: Packages = await monorepoRoot.tool.getPackages(
monorepoRoot.rootDir
);
const tools = options?.tools || DEFAULT_TOOLS;
const tool = tools.find((t) => t.type === monorepoRoot.tool);
if (!tool) throw new Error(`Could not find ${monorepoRoot.tool} tool`);

const packages: Packages = await tool.getPackages(monorepoRoot.rootDir);
validatePackages(packages);

return packages;
}

Expand All @@ -53,12 +58,12 @@ export function getPackagesSync(
options?: GetPackagesOptions
): Packages {
const monorepoRoot: MonorepoRoot = findRootSync(dir, options);
const packages: Packages = monorepoRoot.tool.getPackagesSync(
monorepoRoot.rootDir
);
const tools = options?.tools || DEFAULT_TOOLS;
const tool = tools.find((t) => t.type === monorepoRoot.tool);
if (!tool) throw new Error(`Could not find ${monorepoRoot.tool} tool`);

const packages: Packages = tool.getPackagesSync(monorepoRoot.rootDir);
validatePackages(packages);

return packages;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tools/src/Tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface MonorepoRoot {
/**
* The underlying tool implementation for this monorepo.
*/
tool: Tool;
tool: string;
}

/**
Expand Down

0 comments on commit 9b52955

Please sign in to comment.