MCPcopy Create free account
hub / github.com/Effect-TS/effect / Discovery

Class Discovery

packages/tools/api-diff/src/Discovery.ts:64–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64export class Discovery extends Context.Service<Discovery, {
65 readonly discoverEntrypoints: (
66 repoRoot: string,
67 requestedModules?: ReadonlyArray<string>
68 ) => Effect.Effect<DiscoveryResult, ApiDiffError>
69}>()("@effect/api-diff/Discovery") {
70 static readonly layer = Layer.effect(
71 Discovery,
72 Effect.gen(function*() {
73 const fs = yield* FileSystem.FileSystem
74 const path = yield* Path.Path
75
76 const readManifest = Effect.fnUntraced(function*(location: string) {
77 const source = yield* fs.readFileString(location)
78 return yield* decodePackageManifest(source)
79 })
80
81 const walk = Effect.fnUntraced(function*(
82 root: string,
83 predicate: (location: string) => boolean
84 ) {
85 const output: Array<string> = []
86 const visit: (directory: string) => Effect.Effect<void, PlatformError.PlatformError> = Effect.fnUntraced(
87 function*(directory: string) {
88 const entries = yield* fs.readDirectory(directory)
89 for (const entry of entries) {
90 if (entry === "node_modules" || entry === ".git") {
91 continue
92 }
93 const location = path.join(directory, entry)
94 const info = yield* fs.stat(location)
95 if (info.type === "Directory") {
96 yield* visit(location)
97 } else if (predicate(location)) {
98 output.push(location)
99 }
100 }
101 }
102 )
103 if (yield* fs.exists(root)) {
104 yield* visit(root)
105 }
106 return output.sort()
107 })
108
109 const packagesIn = Effect.fnUntraced(function*(repoRoot: string) {
110 const manifestPaths = yield* walk(
111 path.join(repoRoot, "packages"),
112 (location) => location.endsWith(`${path.sep}package.json`)
113 )
114 const packages: Array<PackageInfo> = []
115 for (const manifestPath of manifestPaths) {
116 const sourceRoot = path.dirname(manifestPath)
117 if (
118 path.basename(sourceRoot) === "dist" &&
119 (yield* fs.exists(path.join(path.dirname(sourceRoot), "package.json")))
120 ) {
121 continue

Callers

nothing calls this directly

Calls 15

predicateFunction · 0.85
matchPatternFunction · 0.85
exportedTargetFunction · 0.85
joinMethod · 0.80
pushMethod · 0.80
someMethod · 0.80
filterMethod · 0.80
visitFunction · 0.70
setMethod · 0.65
ofMethod · 0.65
walkFunction · 0.50
statMethod · 0.45

Tested by

no test coverage detected