Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: serializable return values #220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const runTests = (findRoot: FindRoot) => {
path.join(tmpPath, "packages", "package-one", "src")
);
expect(monorepoRoot).toEqual({
tool: YarnTool,
tool: YarnTool.type,
rootDir: tmpPath,
});
});
Expand All @@ -26,7 +26,7 @@ const runTests = (findRoot: FindRoot) => {
path.join(tmpPath, "packages", "package-one", "src")
);
expect(monorepoRoot).toEqual({
tool: LernaTool,
tool: LernaTool.type,
rootDir: tmpPath,
});
});
Expand All @@ -40,7 +40,7 @@ const runTests = (findRoot: FindRoot) => {
path.join(tmpPath, "packages", "package-one", "src")
);
expect(monorepoRoot).toEqual({
tool: YarnTool,
tool: YarnTool.type,
rootDir: tmpPath,
});
});
Expand All @@ -51,7 +51,7 @@ const runTests = (findRoot: FindRoot) => {
path.join(tmpPath, "packages", "package-one", "src")
);
expect(monorepoRoot).toEqual({
tool: PnpmTool,
tool: PnpmTool.type,
rootDir: tmpPath,
});
});
Expand All @@ -60,7 +60,7 @@ const runTests = (findRoot: FindRoot) => {
let tmpPath = f.copy("single-pkg");
let monorepoRoot = await findRoot(path.join(tmpPath, "src"));
expect(monorepoRoot).toEqual({
tool: RootTool,
tool: RootTool.type,
rootDir: tmpPath,
});
});
Expand Down
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I listed it as a major in the changeset.

}

/**
Expand Down
Loading