Skip to content

Add API diff tooling for v3-to-v4 migration#6547

Open
tim-smart wants to merge 6 commits into
mainfrom
t3code/detect-v3-api-changes
Open

Add API diff tooling for v3-to-v4 migration#6547
tim-smart wants to merge 6 commits into
mainfrom
t3code/detect-v3-api-changes

Conversation

@tim-smart

@tim-smart tim-smart commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a new API diff tool that discovers, snapshots, maps, and compares exported APIs across Effect versions.
  • Generate JSON and Markdown v3-to-v4 migration reports covering moved, split, added, removed, and changed APIs.
  • Add CLI documentation, package configuration, workspace integration, and focused tests for the diff pipeline.

Testing

  • Added unit tests for API discovery, snapshot generation, mapping, and diff behavior.
  • Not run (test results were not provided).

Summary by CodeRabbit

  • New Features
    • Added an API comparison command that compares two repository revisions and produces JSON snapshots, a structured diff, and a Markdown report.
    • Reports identify added, removed, moved, renamed, and structurally changed APIs, with suggested replacements where applicable.
    • Added automatic discovery of public package entry points and deterministic snapshot generation.
  • Documentation
    • Expanded the v3-to-v4 migration mapping and guide with updated module and API rename information.
    • Added usage documentation for the API comparison tool.

- Detect and report module and export changes across worktrees
- Generate machine-readable and Markdown v3-to-v4 migration maps
@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 23, 2026
@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8ed44c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds a new internal @effect/api-diff tool that compares consumer-visible TypeScript declarations between two git refs using isolated worktrees, TypeScript compiler-based snapshot extraction, similarity-based diffing, and Markdown/JSON reporting, wired through an Effect CLI. It also updates v3-to-v4 migration mapping files and documentation, and adds a design specification document.

Changes

API diff tool and migration mappings

Layer / File(s) Summary
Data model contracts and v3-to-v4 migration mappings
packages/tools/api-diff/src/Model.ts, migration/v3-to-v4.json, migration/v3-to-v4.md
Defines schema-backed types for ApiSnapshot/ApiDiff/ApiChange, and updates module/API import migration mappings and generated migration guide content.
Entrypoint discovery and API snapshot extraction
packages/tools/api-diff/src/Discovery.ts, Snapshot.ts, Json.ts, Error.ts, test/Discovery.test.ts, test/Snapshot.test.ts, test/utils.ts
Discovers public entrypoints from package exports maps and serializes TypeScript declarations/types/exports/docs into deterministic, fingerprinted snapshots, with supporting JSON helpers and error type plus fixture-based tests.
Snapshot matching, classification, and Markdown reporting
packages/tools/api-diff/src/Diff.ts, Report.ts, test/Diff.test.ts
Matches base/head entities by identity and similarity, classifies structural/movement/module changes, and renders a categorized Markdown report with tests validating classification and determinism.
Worktree snapshot preparation and CLI execution
packages/tools/api-diff/src/Worktrees.ts, ApiDiff.ts, Cli.ts, bin.ts, test/Cli.test.ts
Resolves refs to SHAs, prepares cached snapshots in detached git worktrees, orchestrates the compare workflow, writes output artifacts, and exposes the CLI/executable entrypoint with an integration test.
Package, TypeScript project, and changeset configuration
packages/tools/api-diff/package.json, tsconfig.json, vitest.config.ts, README.md, root tsconfig.json, tsconfig.packages.json, package.json, .changeset/*
Adds the new package manifest, TypeScript/Vitest configs, README, workspace path aliases/project references, root api-diff script, and changeset entries.

API diff tool design specification

Layer / File(s) Summary
Design specification document
plan.md
Documents the goals, architecture, canonical snapshot/diff model, matching rules, reporting format, test scope, and future work for the api-diff tool.

Estimated code review effort: 4 (Complex) | ~75 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Cli
  participant ApiDiff
  participant Worktrees
  participant Snapshotter
  participant DiffModule as Diff
  participant Report

  Cli->>ApiDiff: run({ baseRef, headRef, output })
  ApiDiff->>Worktrees: resolveRef(baseRef)
  ApiDiff->>Worktrees: resolveRef(headRef)
  ApiDiff->>Worktrees: prepareSnapshot(base options)
  Worktrees->>Snapshotter: extract(entrypoints)
  Snapshotter-->>Worktrees: ApiSnapshot (base)
  ApiDiff->>Worktrees: prepareSnapshot(head options)
  Worktrees->>Snapshotter: extract(entrypoints)
  Snapshotter-->>Worktrees: ApiSnapshot (head)
  ApiDiff->>DiffModule: diffSnapshots(base, head)
  DiffModule-->>ApiDiff: ApiDiff changes
  ApiDiff->>Report: renderMarkdownReport(diff)
  Report-->>ApiDiff: markdown report
  ApiDiff->>ApiDiff: write base/head/diff/report files
Loading

Suggested labels: enhancement

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the enhancement New feature or request label Jul 23, 2026
- Deduplicate rendered API rename entries
- Add coverage for grep-friendly migration mappings

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/tools/api-diff/src/Discovery.ts (1)

55-64: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant ternary — both branches are identical. declarationRoot evaluates to join(sourceRoot, "dist") regardless of packed, so the conditional serves no purpose. If a difference was intended (e.g., non-dist declaration root for non-packed packages), this looks unfinished; otherwise simplify.

♻️ Simplify if no per-packed difference is intended
-      declarationRoot: packed ? join(sourceRoot, "dist") : join(sourceRoot, "dist"),
+      declarationRoot: join(sourceRoot, "dist"),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/tools/api-diff/src/Discovery.ts` around lines 55 - 64, In the
package metadata mapping that constructs PackageInfo, simplify declarationRoot
to a single join(sourceRoot, "dist") expression because both packed branches are
identical; leave root and exports conditional logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/tools/api-diff/tsconfig.json`:
- Around line 1-8: Update the api-diff TypeScript configuration to include the
test files under test/*.test.ts in type-checking, using the repository’s
established test tsconfig or project-reference pattern if available. Preserve
the existing src inclusion and Node types configuration while ensuring pnpm
check covers the tests.

---

Nitpick comments:
In `@packages/tools/api-diff/src/Discovery.ts`:
- Around line 55-64: In the package metadata mapping that constructs
PackageInfo, simplify declarationRoot to a single join(sourceRoot, "dist")
expression because both packed branches are identical; leave root and exports
conditional logic unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1c6e0eb7-d8e3-4f84-b4d5-d3415a01649d

📥 Commits

Reviewing files that changed from the base of the PR and between 4e0be58 and 42b264e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (25)
  • migration/v3-to-v4.json
  • migration/v3-to-v4.md
  • package.json
  • packages/tools/api-diff/README.md
  • packages/tools/api-diff/package.json
  • packages/tools/api-diff/src/Cli.ts
  • packages/tools/api-diff/src/Diff.ts
  • packages/tools/api-diff/src/Discovery.ts
  • packages/tools/api-diff/src/Json.ts
  • packages/tools/api-diff/src/Mapping.ts
  • packages/tools/api-diff/src/Model.ts
  • packages/tools/api-diff/src/Report.ts
  • packages/tools/api-diff/src/Snapshot.ts
  • packages/tools/api-diff/src/Worktrees.ts
  • packages/tools/api-diff/src/bin.ts
  • packages/tools/api-diff/test/Diff.test.ts
  • packages/tools/api-diff/test/Discovery.test.ts
  • packages/tools/api-diff/test/Mapping.test.ts
  • packages/tools/api-diff/test/Snapshot.test.ts
  • packages/tools/api-diff/test/utils.ts
  • packages/tools/api-diff/tsconfig.json
  • packages/tools/api-diff/vitest.config.ts
  • plan.md
  • tsconfig.json
  • tsconfig.packages.json

Comment on lines +1 to +8
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "../../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"types": ["node"]
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Compare tsconfig "include" patterns across sibling tool/package configs
fd tsconfig.json packages -x cat -n {}

Repository: Effect-TS/effect

Length of output: 9568


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== api-diff package files =="
fd -a . packages/tools/api-diff -t f | sort

echo
echo "== package.json =="
cat -n packages/tools/api-diff/package.json

echo
echo "== tsconfig files =="
fd -a 'tsconfig*.json' packages/tools/api-diff -t f | sort | while read -r f; do
  echo "--- $f ---"
  cat -n "$f"
done

Repository: Effect-TS/effect

Length of output: 2311


Type-check the test files too. packages/tools/api-diff/tsconfig.json only includes src, so pnpm check skips test/*.test.ts; add a test tsconfig/reference if these should stay type-safe.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/tools/api-diff/tsconfig.json` around lines 1 - 8, Update the
api-diff TypeScript configuration to include the test files under test/*.test.ts
in type-checking, using the repository’s established test tsconfig or
project-reference pattern if available. Preserve the existing src inclusion and
Node types configuration while ensuring pnpm check covers the tests.

@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 23, 2026
- Run the command with Effect platform services
- Add coverage for mapping documentation generation

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/tools/api-diff/test/Cli.test.ts`:
- Around line 13-27: Update the test containing the temporary directory setup
and Command.runWith invocation to wrap the test body in try/finally, and call
rmSync(root, { recursive: true, force: true }) in the finally block so cleanup
runs on both success and failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a4fc3742-ad5a-496a-9f2e-75f143de512a

📥 Commits

Reviewing files that changed from the base of the PR and between 6f1a738 and bd15c70.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .changeset/migrate-api-diff-cli.md
  • packages/tools/api-diff/package.json
  • packages/tools/api-diff/src/Cli.ts
  • packages/tools/api-diff/src/bin.ts
  • packages/tools/api-diff/test/Cli.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/tools/api-diff/package.json

Comment thread packages/tools/api-diff/test/Cli.test.ts Outdated
- Use Effect platform services for discovery, snapshots, worktrees, and CLI execution
- Validate manifests, migration maps, and snapshots with Schema
- Report unmatched base and head APIs as removals and additions
- Suggest cross-module replacements while preserving class facets
@coderabbitai coderabbitai Bot added the 4.0 label Jul 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/tools/api-diff/src/Discovery.ts (1)

140-141: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant conditional on declarationRoot. Both branches of the ternary produce path.join(sourceRoot, "dist"), so the packed test has no effect here. Either collapse it, or—if the non-packed case was meant to resolve declarations somewhere other than dist—fix the intended branch.

♻️ Suggested simplification (if `dist` is correct for both)
-            declarationRoot: packed ? path.join(sourceRoot, "dist") : path.join(sourceRoot, "dist"),
+            declarationRoot: path.join(sourceRoot, "dist"),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/tools/api-diff/src/Discovery.ts` around lines 140 - 141, Update the
declarationRoot assignment in the Discovery configuration to remove the
redundant packed conditional and use the intended declaration directory
consistently. If non-packed builds should use a different location, correct that
branch instead; leave the root assignment unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/tools/api-diff/src/Discovery.ts`:
- Around line 140-141: Update the declarationRoot assignment in the Discovery
configuration to remove the redundant packed conditional and use the intended
declaration directory consistently. If non-packed builds should use a different
location, correct that branch instead; leave the root assignment unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 96f47929-6d66-4e32-b49c-19b3b74af0e0

📥 Commits

Reviewing files that changed from the base of the PR and between bd15c70 and 8ed44c3.

📒 Files selected for processing (21)
  • .changeset/detect-api-removals.md
  • .changeset/migrate-api-diff-cli.md
  • packages/tools/api-diff/README.md
  • packages/tools/api-diff/src/ApiDiff.ts
  • packages/tools/api-diff/src/Cli.ts
  • packages/tools/api-diff/src/Diff.ts
  • packages/tools/api-diff/src/Discovery.ts
  • packages/tools/api-diff/src/Error.ts
  • packages/tools/api-diff/src/Json.ts
  • packages/tools/api-diff/src/Mapping.ts
  • packages/tools/api-diff/src/Model.ts
  • packages/tools/api-diff/src/Report.ts
  • packages/tools/api-diff/src/Snapshot.ts
  • packages/tools/api-diff/src/Worktrees.ts
  • packages/tools/api-diff/src/bin.ts
  • packages/tools/api-diff/test/Cli.test.ts
  • packages/tools/api-diff/test/Diff.test.ts
  • packages/tools/api-diff/test/Discovery.test.ts
  • packages/tools/api-diff/test/Mapping.test.ts
  • packages/tools/api-diff/test/Snapshot.test.ts
  • packages/tools/api-diff/test/utils.ts
🚧 Files skipped from review as they are similar to previous changes (11)
  • .changeset/migrate-api-diff-cli.md
  • packages/tools/api-diff/src/bin.ts
  • packages/tools/api-diff/test/Cli.test.ts
  • packages/tools/api-diff/test/utils.ts
  • packages/tools/api-diff/test/Snapshot.test.ts
  • packages/tools/api-diff/test/Discovery.test.ts
  • packages/tools/api-diff/README.md
  • packages/tools/api-diff/src/Report.ts
  • packages/tools/api-diff/test/Diff.test.ts
  • packages/tools/api-diff/test/Mapping.test.ts
  • packages/tools/api-diff/src/Model.ts

- Discover public entrypoints independently for each revision
- Detect module additions, removals, and likely API moves from snapshots
@coderabbitai coderabbitai Bot removed the 4.0 label Jul 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/tools/api-diff/src/ApiDiff.ts (1)

93-97: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Empty-report guard is unreachable and runs after files are already written.

renderMarkdownReport (Report.ts) always emits header/summary lines unconditionally, so report.length === 0 can never be true — this safety net never fires. Additionally, the check currently runs after report.md and the snapshot/diff JSON files have already been written, so even a hypothetical failure here would leave partial output on disk.

♻️ Proposed reordering
+        if (report.length === 0) {
+          return yield* new ApiDiffError({ message: "Generated Markdown report is empty" })
+        }
         yield* fs.makeDirectory(output, { recursive: true })
         yield* fs.writeFileString(path.join(output, "base.snapshot.json"), prettyJson(base))
         yield* fs.writeFileString(path.join(output, "head.snapshot.json"), prettyJson(head))
         yield* fs.writeFileString(path.join(output, "diff.json"), prettyJson(diff))
         yield* fs.writeFileString(path.join(output, "report.md"), report)
         yield* Console.log(`Wrote ${path.relative(repoRoot, output)} (${diff.changes.length} changes)`)
-        if (report.length === 0) {
-          return yield* new ApiDiffError({ message: "Generated Markdown report is empty" })
-        }

Note this only fixes ordering; since renderMarkdownReport can't currently produce an empty string, consider whether this guard is still meaningful as written.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/tools/api-diff/src/ApiDiff.ts` around lines 93 - 97, Move the report
validation in the ApiDiff execution flow before writing report.md or any
snapshot/diff JSON files, so a failed validation cannot leave partial output.
Reassess the report.length === 0 guard alongside renderMarkdownReport and retain
or adjust it only if it checks a meaningful failure condition; preserve the
existing ApiDiffError behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/tools/api-diff/src/Report.ts`:
- Around line 63-68: Update the moduleCounts grouping in Report.ts to fall back
to the module/package name carried in change.delta when headApiId and baseApiId
are absent, especially for package-added, package-removed, module-added, and
module-removed changes produced by moduleChanges. Preserve the existing
API-ID-derived module logic and use the generic "<package>" bucket only when
neither source provides a name.

---

Outside diff comments:
In `@packages/tools/api-diff/src/ApiDiff.ts`:
- Around line 93-97: Move the report validation in the ApiDiff execution flow
before writing report.md or any snapshot/diff JSON files, so a failed validation
cannot leave partial output. Reassess the report.length === 0 guard alongside
renderMarkdownReport and retain or adjust it only if it checks a meaningful
failure condition; preserve the existing ApiDiffError behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 49e213ce-233f-4ee6-a530-a8b7c1432a6c

📥 Commits

Reviewing files that changed from the base of the PR and between 8ed44c3 and 20842fe.

📒 Files selected for processing (14)
  • .changeset/detect-api-removals.md
  • packages/tools/api-diff/README.md
  • packages/tools/api-diff/src/ApiDiff.ts
  • packages/tools/api-diff/src/Cli.ts
  • packages/tools/api-diff/src/Diff.ts
  • packages/tools/api-diff/src/Discovery.ts
  • packages/tools/api-diff/src/Model.ts
  • packages/tools/api-diff/src/Report.ts
  • packages/tools/api-diff/src/Snapshot.ts
  • packages/tools/api-diff/src/Worktrees.ts
  • packages/tools/api-diff/test/Cli.test.ts
  • packages/tools/api-diff/test/Diff.test.ts
  • packages/tools/api-diff/test/Discovery.test.ts
  • plan.md
💤 Files with no reviewable changes (1)
  • packages/tools/api-diff/src/Model.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • .changeset/detect-api-removals.md
  • packages/tools/api-diff/test/Discovery.test.ts
  • packages/tools/api-diff/README.md
  • packages/tools/api-diff/src/Discovery.ts
  • packages/tools/api-diff/src/Snapshot.ts
  • packages/tools/api-diff/src/Worktrees.ts

Comment on lines +63 to +68
const moduleCounts = new Map<string, number>()
for (const change of diff.changes) {
const id = change.headApiId ?? change.baseApiId
const module = id?.split("#")[0] ?? "<package>"
moduleCounts.set(module, (moduleCounts.get(module) ?? 0) + 1)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Module/package-level changes collapse into a generic "<package>" bucket.

moduleCounts only derives the module from change.headApiId ?? change.baseApiId. But package-added/package-removed/module-added/module-removed changes (produced by moduleChanges in Diff.ts) never set baseApiId/headApiId — only delta. As a result, every such change is grouped under the literal "<package>" row in the "Changes by module" table instead of the actual module/package name, even though that name is available in delta.

🐛 Proposed fix to fall back to `delta`
   const moduleCounts = new Map<string, number>()
   for (const change of diff.changes) {
     const id = change.headApiId ?? change.baseApiId
-    const module = id?.split("#")[0] ?? "<package>"
+    const delta = change.delta as { packageName?: string; from?: string; to?: ReadonlyArray<string> } | undefined
+    const module = id?.split("#")[0] ?? delta?.packageName ?? delta?.from ?? delta?.to?.[0] ?? "<package>"
     moduleCounts.set(module, (moduleCounts.get(module) ?? 0) + 1)
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const moduleCounts = new Map<string, number>()
for (const change of diff.changes) {
const id = change.headApiId ?? change.baseApiId
const module = id?.split("#")[0] ?? "<package>"
moduleCounts.set(module, (moduleCounts.get(module) ?? 0) + 1)
}
const moduleCounts = new Map<string, number>()
for (const change of diff.changes) {
const id = change.headApiId ?? change.baseApiId
const delta = change.delta as { packageName?: string; from?: string; to?: ReadonlyArray<string> } | undefined
const module = id?.split("#")[0] ?? delta?.packageName ?? delta?.from ?? delta?.to?.[0] ?? "<package>"
moduleCounts.set(module, (moduleCounts.get(module) ?? 0) + 1)
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/tools/api-diff/src/Report.ts` around lines 63 - 68, Update the
moduleCounts grouping in Report.ts to fall back to the module/package name
carried in change.delta when headApiId and baseApiId are absent, especially for
package-added, package-removed, module-added, and module-removed changes
produced by moduleChanges. Preserve the existing API-ID-derived module logic and
use the generic "<package>" bucket only when neither source provides a name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

1 participant