Skip to content

Fix lint missing devDependency and private imports in published sources - #2272

Open
robhogan wants to merge 1 commit into
mainfrom
robhogan/lint-published-dependencies
Open

robhogan wants to merge 1 commit into
mainfrom
robhogan/lint-published-dependencies

Conversation

@robhogan

@robhogan robhogan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

import/no-extraneous-dependencies misses two kinds of bad import in published package sources: imports from devDependencies, which it allows, and metro*/private/* imports, which it can't resolve (they only exist through package.json#exports) and so skips. Both work in the monorepo thanks to hoisting, but can break for users.

This adds an override for packages/*/src that disallows devDependencies and resolves through exports, using eslint-import-resolver-node@^0.4.0 as a new root dev dependency. eslint-plugin-import still depends on ^0.3.9, hence the path reference in .eslintrc.js. The guarded metro-babel-register requires, which only run in the monorepo, are marked as exceptions.

Changelog: Internal

Test plan:
yarn lint passes. A value import of metro/private/* from a package that doesn't depend on metro, or only dev-depends on it, now fails lint.

…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
@robhogan
robhogan added this pull request to stack #2273 November 21, 2026 10:47
@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 21, 2026
@robhogan
robhogan requested review from huntie and vzaidman November 21, 2026 10:47
@robhogan robhogan changed the title Lint published sources against their own dependencies, including private imports Fix lint missing devDependency and private imports in published sources Nov 21, 2026
@github-actions

Copy link
Copy Markdown

Metro review: Looks good

Risk: low · Commit: 112ed74 · 5 commands run

This adds an ESLint override for published packages/*/src sources. Under it, import/no-extraneous-dependencies rejects devDependencies and resolves metro*/private/* through package.json#exports, using eslint-import-resolver-node@0.4.0. The guarded metro-babel-register requires are exempted. I checked the claim against the base: with the PR, lint now flags a value import of metro/private/* from a package that doesn't declare metro and from one that only dev-depends on it, and the full lint is clean, so I have no findings.

No findings.

Verified
  • ✅ yarn lint (head) — 0 errors, 1 warning that was already there in a test file
  • ✅ npx eslint --no-cache . (head) — Ruled out a stale lint cache hiding new errors
  • ✅ npx eslint --no-cache packages/metro-cache/src/__reviewRepro.js packages/metro-resolver/src/__reviewRepro.js (head) (failed as expected) — Flags metro/private/Server as undeclared in metro-cache and as a devDependency in metro-resolver. metro-core/private/canonicalize (a declared dependency) and the type-only metro/private import still pass.
  • ✅ npx eslint --no-cache packages/metro-cache/src/__reviewRepro.js packages/metro-resolver/src/__reviewRepro.js (base) — No metro/private/* errors at the base, so both cases were missed before; it only caught the hoisted debug, which the base already flagged
  • ✅ yarn jest --no-watchman scripts/__tests__/subpackages-test.js — 198 tests; the updated boilerplate template matches every file that uses it

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 resolve 2.0.0-next.5→next.7 (which now pulls in node-exports-info) and is-core-module; it is needed because 0.3.9 uses resolve@1, which doesn't support exports. The package.json/yarn.lock changes need a Meta import. I didn't check how Meta's internal lint treats the resolver key (an absolute path from require.resolve).

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

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