Repository navigation
Conversation
Metro review: Looks goodRisk: low · Commit: 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 No findings. Verified
Not run: I didn't repeat the description's packed-tarball TypeScript consumer runs under pnpm with Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |
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.
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.
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.
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.
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.
#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) => ...` ```
7d205e5 to
d1a9b10
Compare
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.
#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.
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:
metro-config, which does depend onmetro, takes public types frommetro's entry point and the rest frommetro/private.metro/private/*path.NOTE: Typed callers may need an annotation:
bundle_optionsmoves frommetro-core'sLogEntrytoMetroLogEntry, exported bymetro. Annotate handlers that read it:Logger.on('log', (entry: MetroLogEntry) => ...).AmbiguousModuleResolutionError#hasteErroris a structural interface, no longer assignable toDuplicateHasteCandidatesError.context.dependency.data(usecontext.isESMImport) or pass it on as aTransformResultDependency.MinifierResult.mapanddecodedMapare read-only.@vzaidman - I'd suggest importing this before merging, to check internal callers.
Changelog:
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 npmmetro-corefail with TS2307. After, all pass. Probed each pattern above in Flow and TypeScript. Under pnpm (with #2110 on top),flow checkwith the existingname_mappernow passes, where before it couldn't resolve 5 of these imports.