1
1
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" ;
3
8
import { Packages , MonorepoRoot , Tool } from "@manypkg/tools" ;
4
9
5
10
export type { Tool , Package , Packages } from "@manypkg/tools" ;
@@ -36,12 +41,12 @@ export async function getPackages(
36
41
options ?: GetPackagesOptions
37
42
) : Promise < Packages > {
38
43
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` ) ;
42
47
48
+ const packages : Packages = await tool . getPackages ( monorepoRoot . rootDir ) ;
43
49
validatePackages ( packages ) ;
44
-
45
50
return packages ;
46
51
}
47
52
@@ -53,12 +58,12 @@ export function getPackagesSync(
53
58
options ?: GetPackagesOptions
54
59
) : Packages {
55
60
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` ) ;
59
64
65
+ const packages : Packages = tool . getPackagesSync ( monorepoRoot . rootDir ) ;
60
66
validatePackages ( packages ) ;
61
-
62
67
return packages ;
63
68
}
64
69
0 commit comments