Repository navigation
Fix lint missing devDependency and private imports in published sources - #2272
Conversation
…ate imports Package sources are published, so their imports have to resolve from the package's own `dependencies`, not from the monorepo's hoisted `node_modules`. `import/no-extraneous-dependencies` already runs everywhere, but it allows `devDependencies`, and it silently skips imports it can't resolve, which includes every `metro*/private/*` import, since those exist only through `package.json#exports`. This adds an override for `packages/*/src` (excluding tests, mocks and fixtures) that disallows `devDependencies` and resolves through `package.json#exports`. The five guarded `metro-babel-register` requires, which only run in the monorepo, are annotated as exceptions, along with the entry point template that enforces them. New dev dependency: `eslint-import-resolver-node@^0.4.0`, the first version that reads `package.json#exports`. `eslint-plugin-import` still depends on `^0.3.9`, so `.eslintrc.js` points at this one by path until the plugin catches up. Changelog: Internal
Metro review: Looks goodRisk: low · Commit: This adds an ESLint override for published No findings. Verified
Not run: I didn't benchmark: this only changes lint and dev tooling, with no runtime effect. I didn't measure install size for the new root devDependency. It's small, published from the eslint-plugin-import repo, and the lockfile bumps Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |
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 #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. Differential Revision: D134215879 Pull Request resolved: #2257
import/no-extraneous-dependenciesmisses two kinds of bad import in published package sources: imports fromdevDependencies, which it allows, andmetro*/private/*imports, which it can't resolve (they only exist throughpackage.json#exports) and so skips. Both work in the monorepo thanks to hoisting, but can break for users.This adds an override for
packages/*/srcthat disallowsdevDependenciesand resolves throughexports, usingeslint-import-resolver-node@^0.4.0as a new root dev dependency.eslint-plugin-importstill depends on^0.3.9, hence the path reference in.eslintrc.js. The guardedmetro-babel-registerrequires, which only run in the monorepo, are marked as exceptions.Changelog: Internal
Test plan:
yarn lintpasses. A value import ofmetro/private/*from a package that doesn't depend onmetro, or only dev-depends on it, now fails lint.