Skip to content

Rename sourcemap-codec libdef to .js.flow - #2164

Merged
vzaidman merged 1 commit into
react:mainfrom
vzaidman:sourcemap-codec-flow-libdef
Nov 3, 2026
Merged

vzaidman merged 1 commit into
react:mainfrom
vzaidman:sourcemap-codec-flow-libdef

Conversation

@vzaidman

@vzaidman vzaidman commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #1984, which added flow-typed/sourcemap-codec.js with a declare module block.

declare module is only allowed in a library file. OSS Flow loads flow-typed/*.js as libdefs, so this passed OSS CI. Internal Flow only treats .flow files as library files, so the same file fails internally with unsupported-syntax, and the metro-transform-worker import of @jridgewell/sourcemap-codec falls back to untyped-import. Those two errors block landing the #1984 DiffTrain stack internally (flow-check-land on D129410423).

Renaming the file to flow-typed/sourcemap-codec.js.flow makes Flow treat it as a library file in both. No content change.

Validation on this branch:

  • OSS flow focus-check on packages/metro-transform-worker/src/index.js: 0 errors, and an intentional type error in the renamed file is reported, proving OSS Flow still loads it as a libdef.
  • prettier --check: pass.

Changelog: [Internal]

flow-typed/sourcemap-codec.js uses declare module, which Flow only allows in a library file. OSS Flow loads flow-typed/*.js as libdefs, but internal Flow only treats .flow files as libdefs, so the file errors internally with unsupported-syntax and the metro-transform-worker import falls back to untyped-import. Renaming to .js.flow makes Flow treat it as a library file in both.
@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 Nov 3, 2026
@vzaidman
vzaidman requested review from huntie and robhogan November 3, 2026 19:24
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Metro review: Looks good

Risk: low · Commit: bd4b5fa · 7 commands run

This renames the @jridgewell/sourcemap-codec libdef to flow-typed/sourcemap-codec.js.flow with no content change, matching the existing eventemitter3.js.flow. OSS Flow still loads it as a library file and the rename has no runtime effect, so it looks good; the internal Flow behavior it targets can't be checked here. Separately, once this lands internally, packages/metro-transform-worker/src/index.js:45 ($FlowFixMe[cannot-resolve-module] - No typings at Meta) looks stale: OSS Flow already reports it as an unused suppression, at base and head.

No findings.

Verified
  • ✅ yarn typecheck — Head: No errors.
  • ✅ flow check with a probe module assigning decode('AAAA') to a number (failed as expected) — Head: incompatible-type citing flow-typed/sourcemap-codec.js.flow:20, so OSS Flow loads the renamed file as a libdef. Probe removed afterwards.
  • ✅ flow type-at-pos packages/metro-transform-worker/src/index.js 46 20 — Head: decodeMappings resolves to the typed signature, defined at (lib) sourcemap-codec.js.flow.
  • ✅ flow check with the libdef's decode return type changed to string, at head and base — Both report No errors, so the worker call site doesn't catch this particular mutation. Behavior is the same before and after; cause not investigated. Libdef restored.
  • ✅ flow check --include-warnings --show-all-errors, at head and base — Both warn at metro-transform-worker/src/index.js:45. Head shows it as an unused suppression; base was matched by location only.
  • ✅ yarn prettier --check flow-typed/sourcemap-codec.js.flow — Clean on the restored file. An earlier run failed only because it overlapped my temporary libdef edit.
  • ✅ yarn jest --no-watchman packages/metro-transform-worker — 2 suites, 35 tests.

Not run: Internal Flow: its library-file handling and the flow-check-land errors the PR targets can't be reproduced here, including why other flow-typed/*.js files with declare module don't hit the same error. Benchmarks: a type-only rename has no runtime cost. Windows: not relevant to this change. One Flow command using a custom temp dir was denied by the permission layer, so yarn typecheck and yarn flow check with default settings were used instead; coverage was not affected.

Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call.

@vzaidman
vzaidman merged commit 7d68ba5 into react:main Nov 3, 2026
16 checks passed
@vzaidman
vzaidman deleted the sourcemap-codec-flow-libdef branch November 3, 2026 22:07
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. needs-meta-import

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants