Conversation
There was a problem hiding this comment.
Copilot review overview
馃煛 Changes recommended
Imported declarations remain unresolved, and @babel/parser is not declared as a dependency.
Review effort: Lite
Findings: 1
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.
| const name = declaredName(node); | ||
| if (name != null && name !== exportedName) { | ||
| edits.push([start, start, 'export ']); | ||
| } |
There was a problem hiding this comment.
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:
- https://api-extractor.com/pages/messages/ae-forgotten-export/
- https://api-extractor.com/pages/configs/api-extractor_json/#apireportincludeforgottenexports
We probably should use this, but its +2k lines across all snapshots so a much bigger change than this PR.
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.

This adds API.md files for packages that weren't previously covered even though they already have
.d.tstypes - becauseapi-extractordoesn't handle CommonJS declarations.API Extractor ignores
export =, so any entry point whose.d.tsuses it gets an empty API report. Currently that'smetro-minify-terserandmetro-transform-plugins, whose hand-written definitions both end inexport =:metro/packages/metro-minify-terser/src/index.d.ts
Lines 11 to 14 in b7c2055
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.tsthat usesexport defaultin place ofexport =and exports the module's local types, so they show up in the report. Published definitions keepexport =. The copy is made by parsing the.d.tswith 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.mdrather than an empty one, and--verifyfails on a stale one.Changelog: Internal
Test plan:
yarn run build-api-snapshotsfills in themetro-minify-terserandmetro-transform-pluginsreports and leaves the other 12 unchanged. The newmetro-runtimereports in #1977 come from the same change.