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

Class ApiDiff

packages/tools/api-diff/src/ApiDiff.ts:30–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30export class ApiDiff extends Context.Service<ApiDiff, {
31 readonly run: (options: ApiDiffOptions) => Effect.Effect<void, ApiDiffError>
32}>()("@effect/api-diff/ApiDiff") {
33 static readonly layerNoDependencies = Layer.effect(
34 ApiDiff,
35 Effect.gen(function*() {
36 const fs = yield* FileSystem.FileSystem
37 const path = yield* Path.Path
38 const worktrees = yield* Worktrees
39
40 const absolute = (repoRoot: string, location: string): string =>
41 path.isAbsolute(location) ? location : path.resolve(repoRoot, location)
42
43 const findRepoRoot = Effect.fnUntraced(function*() {
44 let current = path.resolve()
45 while (true) {
46 if (
47 (yield* fs.exists(path.join(current, ".git"))) ||
48 (yield* fs.exists(path.join(current, "pnpm-workspace.yaml")))
49 ) {
50 return current
51 }
52 const parent = path.dirname(current)
53 if (parent === current) {
54 return yield* new ApiDiffError({
55 message: `Could not locate repository root from ${path.resolve()}`
56 })
57 }
58 current = parent
59 }
60 })
61
62 const runInternal = Effect.fnUntraced(function*(options: ApiDiffOptions) {
63 const repoRoot = yield* findRepoRoot()
64 if (options.output === undefined && options.writeDoc === undefined && !options.check) {
65 return yield* new ApiDiffError({ message: "Specify --output, --write-doc, or --check" })
66 }
67
68 const baseSha = yield* worktrees.resolveRef(repoRoot, options.baseRef)
69 const headSha = yield* (options.headRef === "main"
70 ? worktrees.resolveRef(repoRoot, "origin/main").pipe(
71 Effect.catch(() => worktrees.resolveRef(repoRoot, options.headRef))
72 )
73 : worktrees.resolveRef(repoRoot, options.headRef))
74 const toolRoot = path.join(repoRoot, "tmp", "api-diff")
75 const cacheRoot = path.join(toolRoot, "cache")
76 const worktreesRoot = path.join(toolRoot, "worktrees")
77 yield* Console.log(
78 `Base ${options.baseRef}: ${baseSha}\nHead ${options.headRef}: ${headSha}`
79 )
80 const base = yield* worktrees.prepareSnapshot({
81 repoRoot,
82 cacheRoot,
83 worktreesRoot,
84 name: "base",
85 ref: options.baseRef,
86 sha: baseSha
87 })

Callers

nothing calls this directly

Calls 15

diffSnapshotsFunction · 0.90
prettyJsonFunction · 0.90
renderMarkdownReportFunction · 0.90
loadAnnotationsFunction · 0.90
extractImportMapSectionsFunction · 0.90
renderMigrationDocumentFunction · 0.90
markdownSafetyIssuesFunction · 0.90
unannotatedApiIdsFunction · 0.90
unannotatedModuleIdsFunction · 0.90
renderMissingAnnotationsFunction · 0.90
joinMethod · 0.80
prepareSnapshotMethod · 0.80

Tested by

no test coverage detected