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
<!-- Please provide enough information so that others can review your
pull request. -->
<!-- Keep pull requests small and focused on a single change. -->
### Summary
1. Disables the RNTA temporarily
2. Mentions you need to add `package.json` to your exports in the docs
3. Automatically adds `package.json` with bob if you don't have
`includesGeneratedCode: true`.
4. Closes#637
### Why the changes?
Currently, there are two approaches with React Native Codegen.
#### 1. Pregenerate
If you have `includesGeneratedCode: true` in your `codegenConfig`, you
can generate the Codegen specs in the build time and ship them with your
library. This is the recommended way.
#### 2. Let the app generate
If you don't have `includesGeneratedCode: true`, when the application
builds, the React Native Codegen is invoked and goes through all the
dependencies of the app and generates the codegen specs. However, if you
have ESModule exports and if you haven't added your `package.json` to
the exports property, then the Codegen __silently__ skips your library.
---
Because Codegen silently fails when you don't have `package.json` in the
exports or don't build Codegen specs at the build time, people might
have big problems figuring out this on their own. So we're temporarily
disabling RNTA until we enable build time spec generation for it.
### Test plan
#### CRNL
1. Generate a library using crnl
2. Make sure the RNTA isn't an option there
#### Bob
1. Do `bob init` on a library
2. Make sure `package.json` is added to the exports field.
If you created a project with [`create-react-native-library`](./create.md), `react-native-builder-bob` is **already pre-configured to build your project**. You don't need to configure it again.
This will ask you a few questions and add the required configuration and scripts for building the code. The code will be compiled automatically when the package is published.
25
26
27
+
> Note: the `init` command doesn't add the `codegen` target yet. You can either add it manually or create a new library with `create-react-native-library`.
28
+
26
29
You can find details on what exactly it adds in the [Manual configuration](#manual-configuration) section.
If your library is supporting the [New React Native Architecture](https://reactnative.dev/architecture/landing-page), you should also configure Codegen. This is not required for libraries that are only supporting the old architecture.
135
+
136
+
You can follow the [Official Codegen Setup Guide](https://reactnative.dev/docs/the-new-architecture/using-codegen) to enable Codegen.
137
+
138
+
It's also recommended to ship your Codegen generated scaffold code with your library since it has numerous benefits. To see the benefits and implement this behavior, you can see the [Official Codegen Shipping Guide](https://reactnative.dev/docs/the-new-architecture/codegen-cli#including-generated-code-into-libraries).
139
+
140
+
> Note: If you enable Codegen generated code shipping, React Native won't build the scaffold code automatically when you build your test app. You need to rebuild the codegen scaffold code manually each time you make changes to your spec. If you want to automate this process, you can create a new project with `create-react-native-library` and inspect the example app.
141
+
142
+
##### Opting out of Codegen shipping __(not recommended)__
143
+
144
+
If you have a reason to not ship Codegen generated scaffold code with your library, you need to remove the [codegen target](#codegen) and add `package.json` to your `exports` field. Otherwise, React Native Codegen will skip spec generation for your library when your library is consumed as an NPM library. You can find the related issue [here](https://github.com/callstack/react-native-builder-bob/issues/637).
145
+
146
+
```json
147
+
"exports": {
148
+
// ...
149
+
"./package.json": "./package.json"
150
+
},
151
+
```
152
+
128
153
And we're done 🎉
129
154
130
155
## Options
@@ -157,6 +182,12 @@ Example:
157
182
158
183
Various targets to build for. The available targets are:
159
184
185
+
#### `codegen`
186
+
187
+
Generates the [React Native Codegen](https://reactnative.dev/docs/the-new-architecture/what-is-codegen) scaffold code, which is used with the New React Native Architecture.
188
+
189
+
You can ensure your Codegen generated scaffold code is stable through different React Native versions by shipping it with your library. You can find more in the [React Native Official Docs](https://reactnative.dev/docs/the-new-architecture/codegen-cli#including-generated-code-into-libraries).
190
+
160
191
#### `commonjs`
161
192
162
193
Enable compiling source files with Babel and use CommonJS module system.
0 commit comments