Skip to content

Commit 9879bac

Browse files
committed
feat: serializable return values
1 parent 045f7d7 commit 9879bac

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

.changeset/chilly-bottles-eat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@manypkg/find-root": minor
3+
---
4+
5+
feat: export DEFAULT_TOOLS

.changeset/chilly-moles-grow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@manypkg/tools": major
3+
---
4+
5+
feat: serializable return values

packages/find-root/src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
* monorepo implementations first, with tools based on custom file schemas
2121
* checked last.
2222
*/
23-
const DEFAULT_TOOLS: Tool[] = [
23+
export const DEFAULT_TOOLS: Tool[] = [
2424
YarnTool,
2525
PnpmTool,
2626
LernaTool,
@@ -83,7 +83,7 @@ export async function findRoot(
8383
tools.map(async (tool): Promise<MonorepoRoot | undefined> => {
8484
if (await tool.isMonorepoRoot(directory)) {
8585
return {
86-
tool: tool,
86+
tool: tool.type,
8787
rootDir: directory,
8888
};
8989
}
@@ -125,7 +125,7 @@ export async function findRoot(
125125
}
126126

127127
return {
128-
tool: RootTool,
128+
tool: RootTool.type,
129129
rootDir,
130130
};
131131
}
@@ -144,7 +144,7 @@ export function findRootSync(
144144
for (const tool of tools) {
145145
if (tool.isMonorepoRootSync(directory)) {
146146
monorepoRoot = {
147-
tool: tool,
147+
tool: tool.type,
148148
rootDir: directory,
149149
};
150150
return directory;
@@ -173,7 +173,7 @@ export function findRootSync(
173173
}
174174

175175
return {
176-
tool: RootTool,
176+
tool: RootTool.type,
177177
rootDir,
178178
};
179179
}

packages/get-packages/src/index.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from "path";
2-
import { findRoot, findRootSync, FindRootOptions } from "@manypkg/find-root";
2+
import { findRoot, findRootSync, FindRootOptions, DEFAULT_TOOLS } from "@manypkg/find-root";
33
import { Packages, MonorepoRoot, Tool } from "@manypkg/tools";
44

55
export type { Tool, Package, Packages } from "@manypkg/tools";
@@ -36,12 +36,14 @@ export async function getPackages(
3636
options?: GetPackagesOptions
3737
): Promise<Packages> {
3838
const monorepoRoot: MonorepoRoot = await findRoot(dir, options);
39-
const packages: Packages = await monorepoRoot.tool.getPackages(
39+
const tools = options?.tools || DEFAULT_TOOLS;
40+
const tool = tools.find((t) => t.type === monorepoRoot.tool);
41+
if (!tool) throw new Error(`Could not find ${monorepoRoot.tool} tool`);
42+
43+
const packages: Packages = await tool.getPackages(
4044
monorepoRoot.rootDir
4145
);
42-
4346
validatePackages(packages);
44-
4547
return packages;
4648
}
4749

@@ -53,12 +55,14 @@ export function getPackagesSync(
5355
options?: GetPackagesOptions
5456
): Packages {
5557
const monorepoRoot: MonorepoRoot = findRootSync(dir, options);
56-
const packages: Packages = monorepoRoot.tool.getPackagesSync(
58+
const tools = options?.tools || DEFAULT_TOOLS;
59+
const tool = tools.find((t) => t.type === monorepoRoot.tool);
60+
if (!tool) throw new Error(`Could not find ${monorepoRoot.tool} tool`);
61+
62+
const packages: Packages = tool.getPackagesSync(
5763
monorepoRoot.rootDir
5864
);
59-
6065
validatePackages(packages);
61-
6266
return packages;
6367
}
6468

packages/tools/src/Tool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export interface MonorepoRoot {
9797
/**
9898
* The underlying tool implementation for this monorepo.
9999
*/
100-
tool: Tool;
100+
tool: string;
101101
}
102102

103103
/**

0 commit comments

Comments
 (0)