Skip to content

Stop checking in generated .d.ts; keep only public API snapshots (#1801) - #1801

Open
robhogan wants to merge 2 commits into
mainfrom
export-D112750746
Open

Stop checking in generated .d.ts; keep only public API snapshots (#1801)#1801
robhogan wants to merge 2 commits into
mainfrom
export-D112750746

Conversation

@robhogan

@robhogan robhogan commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary:

Makes the per-package TypeScript definition files (packages/*/types/*.d.ts) build artefacts instead of checked-in source, now that microsoft/api-extractor gives us snapshots of public APIs.

Note - .d.ts files are still emitted for every module at build time and published to npm.

The main benefit of this is to reduce developer friction - previously, any change to a module's API would require rebuilding TS definitions. Now, a manual step is only required when changing the public API, which is both much less common and should always be done intentionally.

Changelog: Internal

Reviewed By: huntie

Differential Revision: D112750746

Summary:
Adds Microsoft's `microsoft/api-extractor` (7.52.2) as a Metro dev
dependency and builds a system that captures a public API snapshot for
each OSS package based on its `package.json` `exports` entry points.

- `scripts/generateApiSnapshots.js` enumerates every package, derives the
  public entry points from `exports` (skipping `./package.json`, wildcard
  subpaths like `./private/*`, and entries with no generated `.d.ts`), and
  runs API Extractor over each package's generated TypeScript definitions
  to produce a public API report.
- The report is written to `API.md` at each package root (secondary entry
  points are suffixed, e.g. `API-<subpath>.md`).
- The report is post-processed to drop annotations that are pure noise for
  Metro (whose surface is documented by Flow types, not TSDoc): the
  release-tag comments (`// @public` etc.), `(undocumented)` markers, and
  the "(No packageDocumentation comment...)" notice. Meaningful modifiers
  such as `deprecated` are preserved. API Extractor exposes no config to
  suppress these (they are hardcoded in its ApiReportGenerator), so this is
  done in `cleanReport`.
- Wired into `js1 build metro-ts-defs` (runs after TS-def generation) and
  exposed to OSS as `yarn run build-api-snapshots`.
- `scripts/__tests__/api-snapshots-sync-test.js` fails if a committed
  snapshot is stale, mirroring the existing TS-defs sync test.
- `flow-typed/microsoft-api-extractor.js` provides a local libdef for the
  subset of the API Extractor API used here (Flow does not resolve
  `node_modules`); registered in `xplat/js/.flowconfig` `[libs]`.
- `tsconfig.api-extractor.json` mirrors the project tsconfig plus the `dom`
  lib so API Extractor resolves ambient globals.

14 snapshots are generated; `metro-runtime` runtime-only subpaths,
`metro-babel-register`, and the CLI-only `metro-symbolicate` are skipped
(no exported type surface).

Differential Revision: https://www.internalfb.com/D112750747
@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 Jul 28, 2026
@meta-codesync

meta-codesync Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112750746.

Summary:
Pull Request resolved: #1801

Makes the per-package TypeScript definition files (`packages/*/types/*.d.ts`) build artefacts instead of checked-in source, now that `microsoft/api-extractor` gives us snapshots of public APIs.

Note - `.d.ts` files are still emitted for every module at build time and published to npm.

The main benefit of this is to reduce developer friction - previously, any change to a module's API would require rebuilding TS definitions. Now, a manual step is only required when changing the *public* API, which is both much less common and should always be done intentionally.

Changelog: Internal

Reviewed By: huntie

Differential Revision: D112750746
@meta-codesync meta-codesync Bot changed the title Stop checking in generated .d.ts; keep only public API snapshots Stop checking in generated .d.ts; keep only public API snapshots (#1801) Jul 28, 2026
@robhogan
robhogan force-pushed the export-D112750746 branch from a941eea to b520d75 Compare July 28, 2026 13:44
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant