Skip to content

Commit 28c3ff4

Browse files
benmccannAndarist
andauthored
Make return values serializable again (#220)
* feat: serializable return values * Update .changeset/chilly-bottles-eat.md * Update .changeset/chilly-moles-grow.md --------- Co-authored-by: Mateusz Burzyński <[email protected]>
1 parent e6d32a3 commit 28c3ff4

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
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+
Added `DEFAULT_TOOLS` export

.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+
Return values became serializable again. An identifier for the detected tool is returned instead of an instance of a `Tool` object.

packages/find-root/src/index.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const runTests = (findRoot: FindRoot) => {
1515
path.join(tmpPath, "packages", "package-one", "src")
1616
);
1717
expect(monorepoRoot).toEqual({
18-
tool: YarnTool,
18+
tool: YarnTool.type,
1919
rootDir: tmpPath,
2020
});
2121
});
@@ -26,7 +26,7 @@ const runTests = (findRoot: FindRoot) => {
2626
path.join(tmpPath, "packages", "package-one", "src")
2727
);
2828
expect(monorepoRoot).toEqual({
29-
tool: LernaTool,
29+
tool: LernaTool.type,
3030
rootDir: tmpPath,
3131
});
3232
});
@@ -40,7 +40,7 @@ const runTests = (findRoot: FindRoot) => {
4040
path.join(tmpPath, "packages", "package-one", "src")
4141
);
4242
expect(monorepoRoot).toEqual({
43-
tool: YarnTool,
43+
tool: YarnTool.type,
4444
rootDir: tmpPath,
4545
});
4646
});
@@ -51,7 +51,7 @@ const runTests = (findRoot: FindRoot) => {
5151
path.join(tmpPath, "packages", "package-one", "src")
5252
);
5353
expect(monorepoRoot).toEqual({
54-
tool: PnpmTool,
54+
tool: PnpmTool.type,
5555
rootDir: tmpPath,
5656
});
5757
});
@@ -60,7 +60,7 @@ const runTests = (findRoot: FindRoot) => {
6060
let tmpPath = f.copy("single-pkg");
6161
let monorepoRoot = await findRoot(path.join(tmpPath, "src"));
6262
expect(monorepoRoot).toEqual({
63-
tool: RootTool,
63+
tool: RootTool.type,
6464
rootDir: tmpPath,
6565
});
6666
});

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import path from "path";
2-
import { findRoot, findRootSync, FindRootOptions } from "@manypkg/find-root";
2+
import {
3+
findRoot,
4+
findRootSync,
5+
FindRootOptions,
6+
DEFAULT_TOOLS,
7+
} from "@manypkg/find-root";
38
import { Packages, MonorepoRoot, Tool } from "@manypkg/tools";
49

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

48+
const packages: Packages = await tool.getPackages(monorepoRoot.rootDir);
4349
validatePackages(packages);
44-
4550
return packages;
4651
}
4752

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

65+
const packages: Packages = tool.getPackagesSync(monorepoRoot.rootDir);
6066
validatePackages(packages);
61-
6267
return packages;
6368
}
6469

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)