build(build-tools): rename typeCompatibility to .cts for future ESM flip#27377
build(build-tools): rename typeCompatibility to .cts for future ESM flip#27377tylerbutler wants to merge 3 commits into
Conversation
|
Hi! Thank you for opening this PR. Want me to review it? Based on the diff (75 lines, 3 files), I've queued these reviewers:
How this works
|
There was a problem hiding this comment.
Pull request overview
Prepares @fluidframework/build-tools for a future ESM flip by moving the type-test compatibility exports into a .cts source file so the emitted artifacts remain CommonJS (.cjs + .d.cts) regardless of package module type.
Changes:
- Rename
typeCompatibility.tstotypeCompatibility.ctsand add an explanatory top-level docstring describing the ESM/CJS type-test motivation and constraints. - Update the root type-only re-export to target the
.cjsspecifier (so TS node16 resolution maps it back to the.ctssource and later to.d.cts). - Expand the package
tsconfig.jsonincludeglobs to compile.ctssources.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| build-tools/packages/build-tools/tsconfig.json | Include src/**/*.cts so the renamed .cts file participates in compilation/emit. |
| build-tools/packages/build-tools/src/index.ts | Re-export type utilities via ./common/typeCompatibility.cjs to align with the .cts→.cjs/.d.cts emit strategy. |
| build-tools/packages/build-tools/src/common/typeCompatibility.cts | Move the type-test compatibility utilities to .cts and document why this is needed for the eventual ESM flip. |
Description
Renames
build-tools/packages/build-tools/src/common/typeCompatibility.ts→typeCompatibility.ctsso it always emits CommonJS output (.cjs+.d.cts) regardless of the package's module type.Why now (when the package is still CJS)
This is preparatory work for an eventual flip of
@fluidframework/build-toolsto"type": "module". Today the rename is a no-op behaviorally:index.tsis updated tofrom "./common/typeCompatibility.cjs"(TypeScript'snode16moduleResolution maps the.cjsspecifier to the.ctssource).But it lets us land the
.ctsrename + the long explanatory docstring on its own, separately from the eventualpackage.jsontype/exportsflip, which will rely on this file being therequirecondition entry point for type-only consumers.Background
The generated type test files across the repo do:
These tests are dual-compiled (ESM + CJS). When the CJS pass runs against an ESM-only
build-tools, TypeScript throws TS1479 ("ESM module cannot be imported with require"). The standard fix is to expose a CJS-typed entry point viaexports.require. Producing one requires a.ctssource file — done here. The matchingpackage.jsonexportsmap will come with the ESM flip PR.A long docstring at the top of the renamed file explains all of the above for future readers.
Validation
From
build-tools/packages/build-tools:pnpm run clean && pnpm run tsc— clean; emit contains onlytypeCompatibility.cjs/.d.cts(no stale.js).pnpm run eslint— clean.pnpm run build:test && pnpm test:mocha— 137/137 passing.pnpm build core-utilsfrom the repo root — full client-release-group build still succeeds; type-test compilation in downstream packages is unaffected.Minor incidental change
tsconfig.json—"include"now lists both.tsand.cts. Required because TypeScript's default glob does not pick up.ctsfiles.Reviewer Guidance
The review process is outlined on this wiki page.
The file content is unchanged apart from the leading docstring. The only behavioral change is the emit extension. The follow-up ESM-flip PR will add the matching
exportsmap entries.