Skip to content

Commit c30fd49

Browse files
committed
fix: avoid using react-native field
1 parent 9ad2373 commit c30fd49

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

docs/pages/build.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ yarn add --dev react-native-builder-bob
7575
```json
7676
"main": "lib/commonjs/index.js",
7777
"module": "lib/module/index.js",
78-
"react-native": "src/index.ts",
7978
"types": "lib/typescript/src/index.d.ts",
8079
"source": "src/index.ts",
8180
"files": [
@@ -88,7 +87,6 @@ yarn add --dev react-native-builder-bob
8887

8988
- `main`: The entry point for the commonjs build. This is used by Node - such as tests, SSR etc.
9089
- `module`: The entry point for the ES module build. This is used by bundlers such as webpack.
91-
- `react-native`: The entry point for the React Native apps. This is used by Metro. It's common to point to the source code here as it can make debugging easier.
9290
- `types`: The entry point for the TypeScript definitions. This is used by TypeScript to type check the code using your library.
9391
- `source`: The path to the source code. It is used by `react-native-builder-bob` to detect the correct output files and provide better error messages.
9492
- `files`: The files to include in the package when publishing with `npm`.

packages/create-react-native-library/templates/common/$package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
77
"types": "lib/typescript/src/index.d.ts",
8-
"react-native": "src/index",
98
"source": "src/index",
109
"files": [
1110
"src",

packages/react-native-builder-bob/src/index.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,10 @@ yargs
148148
: undefined;
149149

150150
const entries: { [key: string]: string } = {
151-
'main': target
151+
main: target
152152
? path.join(output, target, 'index.js')
153153
: path.join(source, entryFile),
154-
'react-native': path.join(source, entryFile),
155-
'source': path.join(source, entryFile),
154+
source: path.join(source, entryFile),
156155
};
157156

158157
if (targets.includes('module')) {
@@ -232,6 +231,23 @@ yargs
232231
}
233232
}
234233

234+
if (
235+
pkg['react-native'] &&
236+
(pkg['react-native'].startsWith(source) ||
237+
pkg['react-native'].startsWith(`./${source}`))
238+
) {
239+
const { remove } = await prompts({
240+
type: 'confirm',
241+
name: 'remove',
242+
message: `Your package.json has the 'react-native' field pointing to source code.\n This can cause problems when customizing babel configuration.\n Do you want to remove it?`,
243+
initial: true,
244+
});
245+
246+
if (remove) {
247+
delete pkg['react-native'];
248+
}
249+
}
250+
235251
if (pkg.scripts?.prepare && pkg.scripts.prepare !== prepare) {
236252
const { replace } = await prompts({
237253
type: 'confirm',

0 commit comments

Comments
 (0)