Skip to content

Commit 319ba0a

Browse files
huntiefacebook-github-bot
authored andcommitted
Define "exports" field on main package (#50872)
Summary: Pull Request resolved: #50872 NOTE: Resubmission of D71968187. 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. - Jest mocks to a `react-native` subpath will need to be updated to match the import path used in your code. - Imports from `src/` and `src/private/` directories are disallowed. Reviewed By: robhogan Differential Revision: D72228547 fbshipit-source-id: d50d6e556d32a9cf2f90855a562e61549853acb9
1 parent 9526406 commit 319ba0a

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

packages/react-native/Libraries/Core/Devtools/__tests__/loadBundleFromServer-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
// TODO(legacy-fake-timers): Fix these tests to work with modern timers.
1515
jest.useFakeTimers({legacyFakeTimers: true});
1616

17-
jest.mock('react-native/Libraries/Utilities/HMRClient');
17+
jest.mock('../../../Utilities/HMRClient');
1818

19-
jest.mock('react-native/Libraries/Core/Devtools/getDevServer', () => ({
19+
jest.mock('../../../Core/Devtools/getDevServer', () => ({
2020
__esModule: true,
2121
default: jest.fn(() => ({
2222
url: 'localhost:8042/',
@@ -32,7 +32,7 @@ const loadingViewMock = {
3232
showMessage: jest.fn(),
3333
hide: jest.fn(),
3434
};
35-
jest.mock('react-native/Libraries/Utilities/DevLoadingView', () => ({
35+
jest.mock('../../../Utilities/DevLoadingView', () => ({
3636
__esModule: true,
3737
default: loadingViewMock,
3838
}));
@@ -54,7 +54,7 @@ const sendRequest = jest.fn(
5454
},
5555
);
5656

57-
jest.mock('react-native/Libraries/Network/RCTNetworking', () => ({
57+
jest.mock('../../../Network/RCTNetworking', () => ({
5858
__esModule: true,
5959
default: {
6060
sendRequest,

packages/react-native/package.json

+18-5
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"
@@ -90,11 +108,6 @@
90108
"settings.gradle.kts",
91109
"src",
92110
"!src/private/testing",
93-
"template.config.js",
94-
"template",
95-
"!template/node_modules",
96-
"!template/package-lock.json",
97-
"!template/yarn.lock",
98111
"third-party-podspecs",
99112
"types",
100113
"!**/__docs__/**",

0 commit comments

Comments
 (0)