Skip to content

build(build-infrastructure): switch from ESM to CJS output#26895

Draft
tylerbutler wants to merge 1 commit intomicrosoft:mainfrom
tylerbutler:build-infra-dual-build
Draft

build(build-infrastructure): switch from ESM to CJS output#26895
tylerbutler wants to merge 1 commit intomicrosoft:mainfrom
tylerbutler:build-infra-dual-build

Conversation

@tylerbutler
Copy link
Copy Markdown
Member

@tylerbutler tylerbutler commented Mar 31, 2026

Description

Switch @fluid-tools/build-infrastructure from ESM ("type": "module") to CJS output by removing the type field from package.json. With module: Node16, tsc now reads the package type as CommonJS and emits CJS to lib/.

Why not dual ESM/CJS? Both build-cli (ESM) and build-tools (CJS) consume build-infrastructure. If both run in the same Node process — which they do, since build-cli imports from build-tools — a dual-build package would load two separate module instances (one ESM, one CJS). This causes the dual package hazard: instanceof checks, identity comparisons, and shared state break across the boundary. CJS-only avoids this because ESM can import CJS without creating a second copy.

Changes:

  • Remove "type": "module" from package.json
  • Simplify exports to a single entry (no import/require conditions)
  • Remove /dist from files and clean script (no dual output)
  • .mjs bin files are unchanged (always ESM regardless of package type)

Reviewer Guidance

The review process is outlined on this wiki page.

All dependencies were already pinned to CJS-compatible versions (execa@^5, globby@^11, detect-indent@^6, read-pkg-up@^7). No import.meta or top-level await in source. 52 tests pass.

Remove "type": "module" so tsc with module: Node16 emits CJS to lib/.
This avoids the dual package hazard: build-cli (ESM) and build-tools
(CJS) both consume build-infrastructure, and if both ran in the same
process with separate ESM/CJS copies, instanceof and identity checks
would break across the module boundary.

With CJS output, both consumers get the same CJS copy — ESM can import
CJS without hazard. The .mjs bin files remain ESM (always ESM regardless
of package type).
@tylerbutler tylerbutler force-pushed the build-infra-dual-build branch from b838878 to cf98db0 Compare March 31, 2026 01:32
@tylerbutler tylerbutler changed the title build(build-infrastructure): add CJS dual build output build(build-infrastructure): switch from ESM to CJS output Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant