Repository navigation
Declare dependencies required by published TypeScript types - #2149
Conversation
Metro review: Looks goodRisk: low · Commit: This PR moves the type packages that Metro's published declarations import ( No findings. Not run: Nothing was run. A maintainer has taken over the PR and asked for no more bot reviews, so this pass only rechecked the earlier findings against the current head. I also checked from source that each new dependency matches an import in the package's Flow sources, such as Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |
| }, | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "@types/connect": "^3.4.35", |
There was a problem hiding this comment.
nit · Non-hoisted installs still fail on undeclared metro-* imports in metro-config and metro-core
The PR aims to stop published declarations relying on packages that are only available accidentally through transitive dependencies, but the same pattern remains for some internal packages. It isn't a regression, and npm and default pnpm installs aren't affected.
Failure case: a strict TypeScript consumer of metro and metro-config, installed with pnpm hoist: false, gets 4 TS2307 errors at head:
metro-config/src/types.d.tscan't findmetro-file-map,metro-resolverormetro-transform-worker.metro-core/src/errors/AmbiguousModuleResolutionError.d.tscan't findmetro-file-map.
Fix: add these as dependencies of metro-config and metro-core, here or in a follow-up. An import audit of the declarations also flags metro-core to metro, metro-file-map to metro-config and metro-minify-terser to metro-transform-worker. Those would add new links between Metro's packages, so they may need a maintainer decision. They didn't produce errors in this consumer.
Reproduced: Packed head tarballs and installed them in a fresh pnpm 12 consumer with hoist: false. tsc -p . with TypeScript 6.0.3, strict and skipLibCheck: false exited 2 with exactly these 4 TS2307 errors. The same head tarballs pass under default pnpm hoisting. The PR doesn't change these imports or add these dependencies; the failure wasn't run against base. · id 0cfa611c
There was a problem hiding this comment.
Added all four direct dependencies in faba463: metro-config now declares metro-file-map, metro-resolver, and metro-transform-worker; metro-core declares metro-file-map. Each uses the existing 0.87.2 workspace version, with no lockfile change.
Freshly built and packed head tarballs reproduce exactly the four TS2307 errors in a strict TypeScript consumer with pnpm hoisting disabled. The same consumer passes with the new manifests; the default-hoisting baseline control also passes. Comparing all 17 tarballs shows only these two package manifests changed.
The config → transform-worker edge stays within the existing config → metro → transform-worker dependency component; the complete strongly connected component partition is unchanged. Other reverse edges noted in the comment remain outside this change.
Validation: frozen Yarn and pnpm installs; full repository checks (162 suites, 3059 tests, 495 snapshots passed; 14 existing skips); and yarn typecheck-ts pass.
|
Thanks @sorinc03 Apologies for the noisy review bot, I think your original version of this PR was probably best tbh. I’ll take it from here. Review bot: no more please |
# Conflicts: # packages/metro-config/package.json
faba463 to
41ac020
Compare
#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) => ...` ```
#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) => ...` ```
Summary
Published Metro declarations import external type packages and internal Metro packages that consumers could previously obtain only through development dependencies or accidental hoisting. Clean TypeScript consumers can fail with TS7016 or TS2307 errors.
Declare those dependencies in the packages that import them, preserve existing runtime constraints, and use the genuine
@types/source-map@0.5.2declarations for the unchanged source-map 0.5 runtime. This includes the direct dependencies used bymetro-configandmetro-corein non-hoisted installations.Fixes #2135. This addresses published declarations; #2116 concerns the monorepo's development dependencies.
Changelog: [Fix] Include dependencies required by Metro's published TypeScript declarations
Test plan
metroandmetro-configwith pnpm hoisting disabled reports four TS2307 errors. With the additional direct dependencies, the same consumer passes. The default-hoisting baseline control also passes.skipLibCheck: false, noNODE_PATHor TypeScript path mappings, and local tarball overrides for all Metro packages.metro-config/package.jsonandmetro-core/package.jsondiffer; runtime and declaration bytes are identical. The complete dependency-cycle partition is unchanged.yarn typecheck-ts, frozen Yarn and pnpm installs, and diff checks pass. The original five-line lock entry is retained; the internal-package additions need no lock change.Validation uses a temporary staging path without
typesto avoid the independently reproduced generator-path bug tracked by #2148. That fix and other unrequested reverse dependency edges are outside this PR.