Skip to content

Commit 46d0041

Browse files
ahmdshrifmeta-codesync[bot]
authored andcommitted
Allow the react-native/package.json entry point in no-deep-imports (#58824)
Summary: `react-native/eslint-plugin`'s `no-deep-imports` rule keeps a hard-coded allowlist of the subpaths that `react-native` intentionally exposes (`isSecondaryEntryPoint`). `react-native/package.json` is exposed by the `"exports"` map in `packages/react-native/package.json` (`"./package.json": "./package.json"`) but is missing from that list, so importing it is reported as a deprecated deep import: ``` 'react-native/package.json' React Native deep imports are deprecated. Please use the top level import instead. ``` Reading `react-native/package.json` is the standard way for tooling and libraries to detect the installed React Native version, and there is no top level equivalent to migrate to, so the only way out today is an `eslint-disable`. This adds `react-native/package.json` to `isSecondaryEntryPoint`, which brings the allowlist back in line with every non-wildcard entry of the `"exports"` map (`.`, `./asset-registry`, `./react-private-interface`, `./setup-env`, `./unstable-internals-do-not-use`, `./package.json`). `Libraries/*` and `src/*` deep imports are still reported exactly as before. ## Changelog: [GENERAL] [FIXED] - Stop `no-deep-imports` from reporting `react-native/package.json`, which is a supported entry point Pull Request resolved: #58824 Test Plan: Added `import` and `require` cases for `react-native/package.json` to the `valid` list in `no-deep-imports-test.js`. Before the fix (new tests only): ``` $ yarn jest packages/eslint-plugin-react-native/__tests__/no-deep-imports-test.js ✕ import {version} from 'react-native/package.json'; ✕ require('react-native/package.json'); ● ../no-deep-imports › valid › import {version} from 'react-native/package.json'; message: "'react-native/package.json' React Native deep imports are deprecated. Please use the top level import instead.", ``` After the fix: ``` $ yarn jest packages/eslint-plugin-react-native PASS packages/eslint-plugin-react-native/__tests__/no-deep-imports-test.js PASS packages/eslint-plugin-react-native/__tests__/platform-colors-test.js Test Suites: 2 passed, 2 total Tests: 42 passed, 42 total ``` `eslint` is clean on the changed files. Reviewed By: christophpurrer Differential Revision: D125659549 Pulled By: cortinico fbshipit-source-id: c13b3895bbfb480166f548b704838e92ec3792c5
1 parent 0bd2cb1 commit 46d0041

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎packages/eslint-plugin-react-native/__tests__/no-deep-imports-test.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ eslintTester.run('../no-deep-imports', rule, {
3535
"require('react-native/setup-env');",
3636
"import {BatchedBridge} from 'react-native/react-private-interface';",
3737
"require('react-native/react-private-interface');",
38+
"import {version} from 'react-native/package.json';",
39+
"require('react-native/package.json');",
3840
],
3941
invalid: [
4042
{

‎packages/eslint-plugin-react-native/no-deep-imports.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ module.exports = {
203203
source.value === 'react-native/asset-registry' ||
204204
source.value === 'react-native/react-private-interface' ||
205205
source.value === 'react-native/setup-env' ||
206-
source.value === 'react-native/unstable-internals-do-not-use'
206+
source.value === 'react-native/unstable-internals-do-not-use' ||
207+
source.value === 'react-native/package.json'
207208
);
208209
}
209210

0 commit comments

Comments
 (0)