Skip to content

Remove undeclared type imports between Metro packages - #2257

Open
robhogan wants to merge 4 commits into
robhogan/lint-published-dependenciesfrom
robhogan/remove-type-only-edges
Open

robhogan wants to merge 4 commits into
robhogan/lint-published-dependenciesfrom
robhogan/remove-type-only-edges

Conversation

@robhogan

@robhogan robhogan commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

In the same spirit as #2149, this deals with missing type-only dependencies between Metro packages that currently cause TS to fail lib check under isolated node_modules.

One option would be to add these inter-package type deps as dependencies, but I'd rather avoid adding to that web just for the sake of types. In any case, when a dependency is only for types, it suggests a design issue - packages should define their own contracts.

Mechanics:

  • Small structural types are duplicated where they're used, rather than imported from another package.
  • metro-config, which does depend on metro, takes public types from metro's entry point and the rest from metro/private.
  • Packages import their own types relatively, not through their own metro/private/* path.
  • The published-sources lint from Fix lint missing devDependency and private imports in published sources #2272 now checks type imports too, so they can't come back unnoticed.

NOTE: Typed callers may need an annotation:

  • bundle_options moves from metro-core's LogEntry to MetroLogEntry, exported by metro. Annotate handlers that read it: Logger.on('log', (entry: MetroLogEntry) => ...).
  • AmbiguousModuleResolutionError#hasteError is a structural interface, no longer assignable to DuplicateHasteCandidatesError.
  • Custom resolvers can't read other fields of context.dependency.data (use context.isESMImport) or pass it on as a TransformResultDependency.
  • MinifierResult.map and decodedMap are read-only.

@vzaidman - I'd suggest importing this before merging, to check internal callers.

Changelog:

 - **[Types]**: Remove undeclared type-only imports between Metro packages. `bundle_options` moves from `metro-core`'s `LogEntry` to `MetroLogEntry`, exported by `metro` - annotate `Logger.on` handlers that read it as `(entry: MetroLogEntry) => ...`

Test plan:
Type-checked a packed TypeScript consumer of each entry point with skipLibCheck: false, under pnpm (hoist: false) and npm. Before, 8 of 13 pnpm consumers and npm metro-core fail with TS2307. After, all pass. Probed each pattern above in Flow and TypeScript. Under pnpm (with #2110 on top), flow check with the existing name_mapper now passes, where before it couldn't resolve 5 of these imports.

@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 20, 2026
@robhogan
robhogan requested a review from vzaidman November 20, 2026 18:20
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Metro review: Looks good

Risk: low · Commit: d1a9b10 · 6 commands run

This PR removes the type-only imports between Metro packages that the importing package doesn't declare as dependencies. It does this by copying small structural types into the packages that use them, and by having metro-config take its types from metro's entry point and metro/private. It also turns on includeTypes in the published-sources lint so these imports can't come back. Flow, lint, the API snapshots, the Jest tests for the affected packages and a TypeScript consumer probe all pass, and the lint now catches an undeclared type import, so I have no findings.

No findings.

Verified
  • ✅ yarn typecheck — No errors.
  • ✅ yarn eslint packages/*/src — 0 errors. The one warning is an existing one in JsFileWrapping-test.js.
  • ✅ yarn verify-api-snapshots — 18 snapshots verified, including the updated metro, metro-core, metro-resolver and metro-transform-worker API.md files.
  • ✅ yarn jest --no-watchman packages/metro-minify-terser packages/metro-core packages/metro-source-map packages/metro-resolver packages/metro/src/ModuleGraph/worker — 25 suites, 670 tests passed.
  • ✅ yarn eslint packages/metro-core/src/reviewProbe.js (temporary file: import type {DuplicateHasteCandidatesError} from 'metro-file-map') (failed as expected) — import/no-extraneous-dependencies reports 'metro-file-map' as undeclared, so the new includeTypes option covers type imports. I deleted the probe file afterwards.
  • ✅ node_modules/.bin/tsc -p review-tsprobe (strict, skipLibCheck: false, paths mapped to packages/*/types) — The probe uses Logger.on('log', (e: MetroLogEntry) => e.bundle_options?.dev), CustomResolver and JsTransformerConfig from metro, and ctx.dependency?.data.key. It type-checks. The only remaining errors were in my workspace path mapping (unmapped ob1).

Not run: I didn't repeat the description's packed-tarball TypeScript consumer runs under pnpm with hoist: false and under npm. Instead I checked the generated .d.ts files in place with a TypeScript probe and confirmed that the lint rejects undeclared type imports. The change is types-only, so there was nothing to benchmark and nothing Windows-specific to check.

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

robhogan added a commit that referenced this pull request Nov 21, 2026
Metro is developed with Yarn v1 and `yarn.lock` stays the source of truth, but this lets pnpm users work in the repo by generating a lockfile with `pnpm import`. It adds a `pnpm-workspace.yaml` (pnpm doesn't read `workspaces` from `package.json`), git-ignores the generated `pnpm-lock.yaml` and documents the two commands in the README.

The workspace file also sets two things. `linkWorkspacePackages` - without it, pnpm (since v9) resolves our exact-version internal dependencies like `"metro-core": "0.88.0"` from npm, which fails after a version bump that isn't published yet. `allowBuilds` declines `core-js-pure`'s postinstall (a funding banner) - otherwise pnpm 11+ fails the install with `ERR_PNPM_IGNORED_BUILDS`.

Linking workspace packages gives each one its own `node_modules` pointing at its siblings, where Yarn hoists them. Those links form cycles (`packages/metro-config/node_modules/metro` -> `packages/metro`, whose `node_modules/metro-config` links back), which Flow crawls without hanging since 0.341.0, and with #2257 and #2267 no type imports rely on hoisting, so Flow needs no config changes.

Changelog: Internal

Test plan:
On a fresh clone of this PR, with each of pnpm 11.28.12 and 12.21.0, `pnpm import` then `pnpm install --frozen-lockfile` succeed, `packages/metro/node_modules/metro-core` is a symlink to `../../metro-core`, and `pnpm exec jest --no-watchman packages` passes (167 suites, 3262 tests), as do `build`, `lint`, `format-check`, `verify-api-snapshots`, `typecheck-ts` and `test-smoke`.

`flow check` passes under pnpm 12.15.0 and under Yarn.

Without `allowBuilds`, `pnpm install` exits 1 on both versions.
@robhogan
robhogan changed the base branch from main to pr2116 November 21, 2026 09:05
@robhogan
robhogan changed the base branch from pr2116 to main November 21, 2026 09:05
@robhogan
robhogan added this pull request to stack #2268 November 21, 2026 09:05
robhogan added a commit that referenced this pull request Nov 21, 2026
Metro is developed with Yarn v1 and `yarn.lock` stays the source of truth, but this lets pnpm users work in the repo by generating a lockfile with `pnpm import`. It adds a `pnpm-workspace.yaml` (pnpm doesn't read `workspaces` from `package.json`), git-ignores the generated `pnpm-lock.yaml` and documents the two commands in the README.

The workspace file also sets two things. `linkWorkspacePackages` - without it, pnpm (since v9) resolves our exact-version internal dependencies like `"metro-core": "0.88.0"` from npm, which fails after a version bump that isn't published yet. `allowBuilds` declines `core-js-pure`'s postinstall (a funding banner) - otherwise pnpm 11+ fails the install with `ERR_PNPM_IGNORED_BUILDS`.

Linking workspace packages gives each one its own `node_modules` pointing at its siblings, where Yarn hoists them. Those links form cycles (`packages/metro-config/node_modules/metro` -> `packages/metro`, whose `node_modules/metro-config` links back), which Flow crawls without hanging since 0.341.0, and with #2257 no type imports rely on hoisting, so Flow needs no config changes.

Changelog: Internal

Test plan:
On a fresh clone of this PR, with each of pnpm 11.28.12 and 12.21.0, `pnpm import` then `pnpm install --frozen-lockfile` succeed, `packages/metro/node_modules/metro-core` is a symlink to `../../metro-core`, and `pnpm exec jest --no-watchman packages` passes (167 suites, 3262 tests), as do `build`, `lint`, `format-check`, `verify-api-snapshots`, `typecheck-ts` and `test-smoke`.

`flow check` passes under pnpm 12.15.0 and under Yarn.

Without `allowBuilds`, `pnpm install` exits 1 on both versions.
@robhogan
robhogan removed this pull request from stack #2268 November 21, 2026 09:07
@robhogan
robhogan added this pull request to stack #2269 November 21, 2026 09:08
robhogan added a commit that referenced this pull request Nov 21, 2026
Metro is developed with Yarn v1 and `yarn.lock` stays the source of truth, but this lets pnpm users work in the repo by generating a lockfile with `pnpm import`. It adds a `pnpm-workspace.yaml` (pnpm doesn't read `workspaces` from `package.json`), git-ignores the generated `pnpm-lock.yaml` and documents the two commands in the README.

The workspace file also sets `linkWorkspacePackages` - without it, pnpm (since v9) resolves our exact-version internal dependencies like `"metro-core": "0.88.0"` from npm, which fails after a version bump that isn't published yet. pnpm 11+ also fails the install over a dependency's unapproved build script, and with #2270 none has one.

Linking workspace packages gives each one its own `node_modules` pointing at its siblings, where Yarn hoists them. Those links form cycles (`packages/metro-config/node_modules/metro` -> `packages/metro`, whose `node_modules/metro-config` links back), which Flow crawls without hanging since 0.341.0, and with #2257 no type imports rely on hoisting, so Flow needs no config changes.

Changelog: Internal

Test plan:
On a fresh clone of this PR, with each of pnpm 11.28.12 and 12.21.0, `pnpm import` then `pnpm install --frozen-lockfile` succeed, `packages/metro/node_modules/metro-core` is a symlink to `../../metro-core`, and `pnpm exec jest --no-watchman packages` passes (167 suites, 3262 tests), as do `build`, `lint`, `format-check`, `verify-api-snapshots`, `typecheck-ts` and `test-smoke`.

`flow check` passes under pnpm 12.15.0 and under Yarn.
@robhogan
robhogan removed this pull request from stack #2269 November 21, 2026 09:23
@robhogan
robhogan added this pull request to stack #2271 November 21, 2026 09:23
robhogan added a commit that referenced this pull request Nov 21, 2026
Metro is developed with Yarn v1 and `yarn.lock` stays the source of truth, but this lets pnpm users work in the repo by generating a lockfile with `pnpm import`. It adds a `pnpm-workspace.yaml` (pnpm doesn't read `workspaces` from `package.json`), git-ignores the generated `pnpm-lock.yaml` and documents the two commands in the README.

The workspace file also sets `linkWorkspacePackages` - without it, pnpm (since v9) resolves our exact-version internal dependencies like `"metro-core": "0.88.0"` from npm, which fails after a version bump that isn't published yet. pnpm 11+ also fails the install over a dependency's unapproved build script, and with #2270 none has one.

Linking workspace packages gives each one its own `node_modules` pointing at its siblings, where Yarn hoists them. Those links form cycles (`packages/metro-config/node_modules/metro` -> `packages/metro`, whose `node_modules/metro-config` links back), which Flow crawls without hanging since 0.341.0, and with #2257 no type imports rely on hoisting, so Flow needs no config changes.

Changelog: Internal

Test plan:
On a fresh clone of this PR, with each of pnpm 11.28.12 and 12.21.0, `pnpm import` then `pnpm install --frozen-lockfile` succeed, `packages/metro/node_modules/metro-core` is a symlink to `../../metro-core`, and `pnpm exec jest --no-watchman packages` passes (167 suites, 3262 tests), as do `build`, `lint`, `format-check`, `verify-api-snapshots`, `typecheck-ts` and `test-smoke`.

`flow check` passes under pnpm 12.15.0 and under Yarn.
robhogan added a commit that referenced this pull request Nov 21, 2026
Metro is developed with Yarn v1 and `yarn.lock` stays the source of truth, but this lets pnpm users work in the repo by generating a lockfile with `pnpm import`. It adds a `pnpm-workspace.yaml` (pnpm doesn't read `workspaces` from `package.json`), git-ignores the generated `pnpm-lock.yaml` and documents the two commands in the README.

The workspace file also sets `linkWorkspacePackages` - without it, pnpm (since v9) resolves our exact-version internal dependencies like `"metro-core": "0.88.0"` from npm, which fails after a version bump that isn't published yet. pnpm 11+ also fails the install over a dependency's unapproved build script, and with #2270 none has one.

Linking workspace packages gives each one its own `node_modules` pointing at its siblings, where Yarn hoists them. Those links form cycles (`packages/metro-config/node_modules/metro` -> `packages/metro`, whose `node_modules/metro-config` links back), which Flow crawls without hanging since 0.341.0, and with #2257 no type imports rely on hoisting, so Flow needs no config changes.

Changelog: Internal

Test plan:
On a fresh clone of this PR, with each of pnpm 11.28.12 and 12.21.0, `pnpm import` then `pnpm install --frozen-lockfile` succeed, `packages/metro/node_modules/metro-core` is a symlink to `../../metro-core`, and `pnpm exec jest --no-watchman packages` passes (167 suites, 3262 tests), as do `build`, `lint`, `format-check`, `verify-api-snapshots`, `typecheck-ts` and `test-smoke`.

`flow check` passes under pnpm 12.15.0 and under Yarn.
robhogan added a commit that referenced this pull request Nov 21, 2026
#2116, #2257 etc fixed some missing dependencies, now we close the loop by ensuring we can't regress.

This adds a `test-pnpm` job to `build-test-and-deploy`. It generates `pnpm-lock.yaml` from `yarn.lock` with `pnpm import`, installs, and runs Flow, `typecheck-ts`, lint and Jest (with the same retries as the Yarn test job). It doesn't need to run on multiple platforms / versions so it's just Ubuntu and Node LTS.

Changelog: Internal

Test plan:
`actionlint` passes. Ran the job's steps locally against a fresh copy of this PR, with pnpm 12.21.0 (on Node 22.13 rather than 24) - all pass, including Jest (175 suites, 3475 tests).

CI on this PR runs the new job.
#2149 declared the third-party packages our generated TypeScript definitions import, but eight type-only imports between Metro packages are still undeclared (eg `metro-core` imports `BundleOptions` from `metro`). Under strict installs these fail with TS2307 unless the consumer sets `skipLibCheck`.

Rather than add dependencies that only exist for types, some of them circular, this removes the imports. Small structural types are duplicated where they're used, `metro-config` imports from `metro`'s entry point, and `ResolutionContext.dependency` becomes a minimal `Dependency` (`name`, `data.key`, `data.locs`, `data.asyncType`) instead of `TransformResultDependency`.

Typed callers may need an annotation:
 - `bundle_options` moves from `metro-core`'s `LogEntry` to `MetroLogEntry`, exported by `metro`. Annotate handlers that read it: `Logger.on('log', (entry: MetroLogEntry) => ...)`.
 - `AmbiguousModuleResolutionError#hasteError` is a structural interface, no longer assignable to `DuplicateHasteCandidatesError`.
 - Custom resolvers can't read other fields of `context.dependency.data` (use `context.isESMImport`) or pass it on as a `TransformResultDependency`.
 - `MinifierResult.map` and `decodedMap` are read-only.

Changelog:
```
 - **[Types]**: Remove undeclared type-only imports between Metro packages. `bundle_options` moves from `metro-core`'s `LogEntry` to `MetroLogEntry`, exported by `metro` - annotate `Logger.on` handlers that read it as `(entry: MetroLogEntry) => ...`
```
@robhogan
robhogan force-pushed the robhogan/remove-type-only-edges branch from 7d205e5 to d1a9b10 Compare November 21, 2026 10:46
robhogan added a commit that referenced this pull request Nov 21, 2026
Metro is developed with Yarn v1 and `yarn.lock` stays the source of truth, but this lets pnpm users work in the repo by generating a lockfile with `pnpm import`. It adds a `pnpm-workspace.yaml` (pnpm doesn't read `workspaces` from `package.json`), git-ignores the generated `pnpm-lock.yaml` and documents the two commands in the README.

The workspace file also sets `linkWorkspacePackages` - without it, pnpm (since v9) resolves our exact-version internal dependencies like `"metro-core": "0.88.0"` from npm, which fails after a version bump that isn't published yet. pnpm 11+ also fails the install over a dependency's unapproved build script, and with #2270 none has one.

Linking workspace packages gives each one its own `node_modules` pointing at its siblings, where Yarn hoists them. Those links form cycles (`packages/metro-config/node_modules/metro` -> `packages/metro`, whose `node_modules/metro-config` links back), which Flow crawls without hanging since 0.341.0, and with #2257 no type imports rely on hoisting, so Flow needs no config changes.

Changelog: Internal

Test plan:
On a fresh clone of this PR, with each of pnpm 11.28.12 and 12.21.0, `pnpm import` then `pnpm install --frozen-lockfile` succeed, `packages/metro/node_modules/metro-core` is a symlink to `../../metro-core`, and `pnpm exec jest --no-watchman packages` passes (167 suites, 3262 tests), as do `build`, `lint`, `format-check`, `verify-api-snapshots`, `typecheck-ts` and `test-smoke`.

`flow check` passes under pnpm 12.15.0 and under Yarn.
robhogan added a commit that referenced this pull request Nov 21, 2026
#2116, #2257 etc fixed some missing dependencies, now we close the loop by ensuring we can't regress.

This adds a `test-pnpm` job to `build-test-and-deploy`. It generates `pnpm-lock.yaml` from `yarn.lock` with `pnpm import`, installs, and runs Flow, `typecheck-ts`, lint and Jest (with the same retries as the Yarn test job). It doesn't need to run on multiple platforms / versions so it's just Ubuntu and Node LTS.

Changelog: Internal

Test plan:
`actionlint` passes. Ran the job's steps locally against a fresh copy of this PR, with pnpm 12.21.0 (on Node 22.13 rather than 24) - all pass, including Jest (175 suites, 3475 tests).

CI on this PR runs the new job.
@robhogan
robhogan removed this pull request from stack #2271 November 21, 2026 10:47
@robhogan
robhogan changed the base branch from main to robhogan/lint-published-dependencies November 21, 2026 10:47
@robhogan
robhogan added this pull request to stack #2273 November 21, 2026 10:47

This branch has not been deployed

No deployments
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.

1 participant