You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/0534-metro-package-exports-support.md
+25-4Lines changed: 25 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -221,14 +221,16 @@ import BazComponent from './BazComponent.mjs';
221
221
222
222
**Proposed**:
223
223
224
-
-**Breaking**: Under `"exports"`, we will remove support forplatform-specific extensions.
224
+
-**Breaking**: Under `"exports"`, Metro will not resolve platform-specific extensionsfor listed package entry points.
225
225
- When resolving any import specifier:
226
226
- If the package defines `"exports"` and the exact specifier is matched, the package-defined path will be used.
227
227
- If there is no match in`"exports"`, Metro will look for files at the imported subpath, trying all extension variants (existing resolution logic).
228
-
-Platform-specific extensions will narrow to a concept aimed at React Native app codebases, rather than forboth apps andpackages. We will communicate to React Native package authors that alternative patterns such as `Platform.select()` should be used.
229
-
- We have no near-term plans to drop platform-specific extensions for packages not using `"exports"`.
228
+
-With this decision, we will have narrowed support forplatform-specific extensions inpackages. We will communicate to React Native package authors that alternative patterns should be used.
229
+
- We have no near-term plans to drop platform-specific extensions for packages not using `"exports"`, or in app code.
230
230
- We will not take a strong stance on using extensionless or extensioned imports. The former may provide more flexibility for React Native package authors to change extensions in future without impacting consuming apps.
231
231
232
+
Note: We may yet (unplanned) independently make the platform-specific extensions feature work with extensioned specifiers, at which point this could be opened back up on `"exports"` entry points.
233
+
232
234
#### Illustrated
233
235
234
236
```json
@@ -259,7 +261,26 @@ import FooComponent from 'pkg/src/FooComponent';
259
261
260
262
The last example given is not expected to enable backwards compatibility, but may serendipitously capture pre-existing imports inapps. In a future strict mode, paths outside `"exports"` will not be considered.
261
263
262
-
We will recommend that packages which rely on platform-specific extensions being available to consuming apps do not migrate to `"exports"` or change these entry points to handle platforms using `Platform.select()` or conditional exports.
264
+
#### Workarounds
265
+
266
+
We will recommend that packages which rely on platform-specific extensions being available to consuming apps do not migrate to `"exports"` or update these entry points to handle platform internally.
267
+
268
+
One replacement pattern (besides `Platform.select()`) is a wrapper module:
269
+
270
+
```sh
271
+
└── src
272
+
├── FooComponent.js # Listed in "exports"
273
+
├── FooComponentImpl.android.js
274
+
├── FooComponentImpl.ios.js
275
+
└── FooComponentImpl.js
276
+
```
277
+
278
+
```js
279
+
// pkg/src/FooComponent.js
280
+
export * from './FooComponentImpl'; // Will resolve platform exts
281
+
```
282
+
283
+
Conditional exports will be the recommended solution for replacing current `.native.js` entry points where aiming to identify React Native projects.
0 commit comments