Skip to content

Commit 9fc2a9b

Browse files
huntiefacebook-github-bot
authored andcommitted
Define "exports" field on main package (#50320)
Summary: Pull Request resolved: #50320 Define `"exports"` field on the main `react-native` package. **Notes** Module resolution should be equivalent to the previous implicit `"main"` field (backwards compatible). - Exports all module subpaths to JavaScript (Flow) source files, with and without `.js` suffix (unchanged ✅) - These are restricted to the `flow/` and `Libraries/` subdirectories (ℹ️ this should be unchanged, matching any JS imports apps may have today) - Still includes 3P integration scripts such as `./jest-preset.js` and `./rn-get-polyfills.js` (unchanged ✅) - Exports `./package.json` (unchanged ✅) - TypeScript should: - fall back to the `"types"` field (unchanged ✅) - OR to `"."`,`"./*"` when Package Exports support is enabled via `compilerOptions`, and use the *adjacent `.d.ts` file* (unchanged ✅) Changelog: [General][Breaking] - The `react-native` package now defines package.json `"exports"`. - While these expose existing JavaScript and TypeScript modules, this change may affect deep imports of non-JS files via Node in third party tools. - Imports from `src/` and `src/private/` directories are disallowed. Reviewed By: robhogan Differential Revision: D71968187 fbshipit-source-id: 28ff941692d1822a916457c4fb891e200e3bca61
1 parent 398ac1f commit 9fc2a9b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

packages/react-native/package.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,25 @@
2626
"bin": {
2727
"react-native": "cli.js"
2828
},
29+
"main": "./index.js",
2930
"types": "types",
31+
"exports": {
32+
".": "./index.js",
33+
"./*": "./*.js",
34+
"./*.js": "./*.js",
35+
"./Libraries/*.d.ts": "./Libraries/*.d.ts",
36+
"./types/*.d.ts": "./types/*.d.ts",
37+
"./gradle/*": null,
38+
"./React/*": null,
39+
"./ReactAndroid/*": null,
40+
"./ReactApple/*": null,
41+
"./ReactCommon/*": null,
42+
"./sdks/*": null,
43+
"./src/*": null,
44+
"./third-party-podspecs/*": null,
45+
"./types/*": null,
46+
"./package.json": "./package.json"
47+
},
3048
"jest-junit": {
3149
"outputDirectory": "reports/junit",
3250
"outputName": "js-test-results.xml"
@@ -84,11 +102,6 @@
84102
"sdks/hermesc",
85103
"settings.gradle.kts",
86104
"src",
87-
"template.config.js",
88-
"template",
89-
"!template/node_modules",
90-
"!template/package-lock.json",
91-
"!template/yarn.lock",
92105
"third-party-podspecs",
93106
"types"
94107
],

0 commit comments

Comments
 (0)