Skip to content

API snapshots: Report CommonJS entry points - #1988

Merged
robhogan merged 1 commit into
mainfrom
pr1988
Sep 29, 2026
Merged

robhogan merged 1 commit into
mainfrom
pr1988

Conversation

@robhogan

@robhogan robhogan commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

This adds API.md files for packages that weren't previously covered even though they already have .d.ts types - because api-extractor doesn't handle CommonJS declarations.

API Extractor ignores export =, so any entry point whose .d.ts uses it gets an empty API report. Currently that's metro-minify-terser and metro-transform-plugins, whose hand-written definitions both end in export =:

import minifier from './minifier';
declare const minifierFn: typeof minifier;
export = minifierFn;

Once #1977 generates definitions for CommonJS modules, it'll be all of those too.

This works around it for extraction only. API Extractor gets a temporary copy of the .d.ts that uses export default in place of export = and exports the module's local types, so they show up in the report. Published definitions keep export =. The copy is made by parsing the .d.ts with Babel and editing its text in place, so comments and formatting carry through to the report.

An entry point with nothing to report now gets no API.md rather than an empty one, and --verify fails on a stale one.

Changelog: Internal

Test plan:
yarn run build-api-snapshots fills in the metro-minify-terser and metro-transform-plugins reports and leaves the other 12 unchanged. The new metro-runtime reports in #1977 come from the same change.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 28, 2026
@robhogan
robhogan requested a lite review from Copilot September 28, 2026 16:33

Copilot AI 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.

Copilot review overview

馃煛 Changes recommended

Imported declarations remain unresolved, and @babel/parser is not declared as a dependency.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Adds extraction-only API snapshot support for CommonJS export = entry points while preserving published typings.

Changes:

  • Rewrites declarations for API Extractor.
  • Handles empty and stale snapshots.
  • Adds reports for two CommonJS packages.
File Summary
scripts/鈥媑enerateApiSnapshots.js Implements declaration rewriting and snapshot handling.
packages/鈥媘etro-transform-plugins/鈥婣PI.md Adds the generated API snapshot.
packages/鈥媘etro-minify-terser/鈥婣PI.md Adds the generated API snapshot.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +221 to +224
const name = declaredName(node);
if (name != null && name !== exportedName) {
edits.push([start, start, 'export ']);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is true, but it's pre-existing and true of all of our current API.md files.

Apparently, api-extractor expects all types used in exported APIs to be explicitly exported themselves. It regards others as "forgotten exports". There's an option to keep them in the exported API we're not currently using:

We probably should use this, but its +2k lines across all snapshots so a much bigger change than this PR.

@robhogan
robhogan marked this pull request as ready for review September 29, 2026 14:44
@robhogan
robhogan requested review from huntie and vzaidman September 29, 2026 14:45
@robhogan
robhogan added this pull request to stack #1997 September 29, 2026 14:48
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 29, 2026
API Extractor ignores `export =`, so any entry point whose `.d.ts` uses it gets an empty API report. Currently that's `metro-minify-terser` and `metro-transform-plugins`, whose hand-written definitions both end in `export =`:

https://github.com/react/metro/blob/b7c20552a16a251507f753c3da23cc7d18488b6c/packages/metro-minify-terser/src/index.d.ts#L11-L14

Once #1977 generates definitions for CommonJS modules, it'll be all of those too.

This works around it for extraction only. API Extractor gets a temporary copy of the `.d.ts` that uses `export default` in place of `export =` and exports the module's local types, so they show up in the report. Published definitions keep `export =`. The copy is made by parsing the `.d.ts` with Babel and editing its text in place, so comments and formatting carry through to the report.

An entry point with nothing to report now gets no `API.md` rather than an empty one, and `--verify` fails on a stale one.

Changelog: Internal

Test plan:
`yarn run build-api-snapshots` fills in the `metro-minify-terser` and `metro-transform-plugins` reports and leaves the other 12 unchanged. The new `metro-runtime` reports in #1977 come from the same change.
@robhogan
robhogan merged commit d6cd99d into main Sep 29, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants