Skip to content

Commit

Permalink
fix: avoid using react-native field
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 5, 2024
1 parent 9ad2373 commit c30fd49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 0 additions & 2 deletions docs/pages/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ yarn add --dev react-native-builder-bob
```json
"main": "lib/commonjs/index.js",
"module": "lib/module/index.js",
"react-native": "src/index.ts",
"types": "lib/typescript/src/index.d.ts",
"source": "src/index.ts",
"files": [
Expand All @@ -88,7 +87,6 @@ yarn add --dev react-native-builder-bob

- `main`: The entry point for the commonjs build. This is used by Node - such as tests, SSR etc.
- `module`: The entry point for the ES module build. This is used by bundlers such as webpack.
- `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.
- `types`: The entry point for the TypeScript definitions. This is used by TypeScript to type check the code using your library.
- `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.
- `files`: The files to include in the package when publishing with `npm`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"main": "lib/commonjs/index",
"module": "lib/module/index",
"types": "lib/typescript/src/index.d.ts",
"react-native": "src/index",
"source": "src/index",
"files": [
"src",
Expand Down
22 changes: 19 additions & 3 deletions packages/react-native-builder-bob/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ yargs
: undefined;

const entries: { [key: string]: string } = {
'main': target
main: target
? path.join(output, target, 'index.js')
: path.join(source, entryFile),
'react-native': path.join(source, entryFile),
'source': path.join(source, entryFile),
source: path.join(source, entryFile),
};

if (targets.includes('module')) {
Expand Down Expand Up @@ -232,6 +231,23 @@ yargs
}
}

if (
pkg['react-native'] &&
(pkg['react-native'].startsWith(source) ||
pkg['react-native'].startsWith(`./${source}`))
) {
const { remove } = await prompts({
type: 'confirm',
name: 'remove',
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?`,
initial: true,
});

if (remove) {
delete pkg['react-native'];
}
}

if (pkg.scripts?.prepare && pkg.scripts.prepare !== prepare) {
const { replace } = await prompts({
type: 'confirm',
Expand Down

0 comments on commit c30fd49

Please sign in to comment.