Skip to content

Commit b78f018

Browse files
committed
Update Metro exports RFC with more detail on platform exts
1 parent 00f22cd commit b78f018

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

proposals/0534-metro-package-exports-support.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,16 @@ import BazComponent from './BazComponent.mjs';
221221

222222
**Proposed**:
223223

224-
- **Breaking**: Under `"exports"`, we will remove support for platform-specific extensions.
224+
- **Breaking**: Under `"exports"`, Metro will not resolve platform-specific extensions for listed package entry points.
225225
- When resolving any import specifier:
226226
- If the package defines `"exports"` and the exact specifier is matched, the package-defined path will be used.
227227
- 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 for both apps and packages. 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 for platform-specific extensions in packages. 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.
230230
- 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.
231231

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+
232234
#### Illustrated
233235

234236
```json
@@ -259,7 +261,26 @@ import FooComponent from 'pkg/src/FooComponent';
259261

260262
The last example given is not expected to enable backwards compatibility, but may serendipitously capture pre-existing imports in apps. In a future strict mode, paths outside `"exports"` will not be considered.
261263

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.
263284

264285
### Conditional exports
265286

0 commit comments

Comments
 (0)