Skip to content

Commit 43c1cb6

Browse files
authored
Clarify implications of using includesGeneratedCode = true with codegen (#4502)
Fixes #4460
1 parent 59afb3a commit 43c1cb6

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

docs/the-new-architecture/codegen-cli.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,26 @@ npx @react-native-community/cli codegen \
3939
--outputPath third-party/some-library/android/generated
4040
```
4141

42-
## Including Generated Code into Libraries
42+
# Including Generated Code into Libraries
4343

44-
The **Codegen** CLI is a great tool for library developers. It can be used to peek at the generated code to see which interfaces you need to implement. Or you can generate the code if you want to ship it in your library.
44+
The Codegen CLI is a great tool for library developers. It can be used to take a sneak-peek at the generated code to see which interfaces you need to implement.
4545

46-
This setup has several benefits:
46+
Normally the generated code is not included in the library, and the app that uses the library is responsible for running the Codegen at build time.
47+
This is a good setup for most cases, but Codegen also offers a mechanism to include the generated code in the library itself via the `includesGeneratedCode` property.
48+
49+
It's important to understand what are the implications of using `includesGeneratedCode = true`. Including the generated code comes with several benefits such as:
4750

4851
- No need to rely on the app to run **Codegen** for you, the generated code is always there.
49-
- The implementation files are always consistent with the generated interfaces.
52+
- The implementation files are always consistent with the generated interfaces (this makes your library code more resilient against API changes in codegen).
5053
- No need to include two sets of files to support both architectures on Android. You can only keep the New Architecture one, and it is guaranteed to be backwards compatible.
51-
- No need to worry about **Codegen** version mismatch between what is used by the app, and what was used during library development.
5254
- Since all native code is there, it is possible to ship the native part of the library as a prebuild.
5355

56+
On the other hand, you also need to be aware of one drawback:
57+
58+
- The generated code will use the React Native version defined inside your library. So if your library is shipping with React Native 0.76, the generated code will be based on that version. This could mean that the generated code is not compatible with apps using **previous** React Native version used by the app (e.g. an App running on React Native 0.75).
59+
60+
## Enabling `includesGeneratedCode`
61+
5462
To enable this setup:
5563

5664
- Add the `includesGeneratedCode` property into your library's `codegenConfig` field in the `package.json` file. Set its value to `true`.

website/versioned_docs/version-0.76/the-new-architecture/codegen-cli.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,26 @@ npx @react-native-community/cli codegen \
3939
--outputPath third-party/some-library/android/generated
4040
```
4141

42-
## Including Generated Code into Libraries
42+
# Including Generated Code into Libraries
4343

44-
The **Codegen** CLI is a great tool for library developers. It can be used to peek at the generated code to see which interfaces you need to implement. Or you can generate the code if you want to ship it in your library.
44+
The Codegen CLI is a great tool for library developers. It can be used to take a sneak-peek at the generated code to see which interfaces you need to implement.
4545

46-
This setup has several benefits:
46+
Normally the generated code is not included in the library, and the app that uses the library is responsible for running the Codegen at build time.
47+
This is a good setup for most cases, but Codegen also offers a mechanism to include the generated code in the library itself via the `includesGeneratedCode` property.
48+
49+
It's important to understand what are the implications of using `includesGeneratedCode = true`. Including the generated code comes with several benefits such as:
4750

4851
- No need to rely on the app to run **Codegen** for you, the generated code is always there.
49-
- The implementation files are always consistent with the generated interfaces.
52+
- The implementation files are always consistent with the generated interfaces (this makes your library code more resilient against API changes in codegen).
5053
- No need to include two sets of files to support both architectures on Android. You can only keep the New Architecture one, and it is guaranteed to be backwards compatible.
51-
- No need to worry about **Codegen** version mismatch between what is used by the app, and what was used during library development.
5254
- Since all native code is there, it is possible to ship the native part of the library as a prebuild.
5355

56+
On the other hand, you also need to be aware of one drawback:
57+
58+
- The generated code will use the React Native version defined inside your library. So if your library is shipping with React Native 0.76, the generated code will be based on that version. This could mean that the generated code is not compatible with apps using **previous** React Native version used by the app (e.g. an App running on React Native 0.75).
59+
60+
## Enabling `includesGeneratedCode`
61+
5462
To enable this setup:
5563

5664
- Add the `includesGeneratedCode` property into your library's `codegenConfig` field in the `package.json` file. Set its value to `true`.

website/versioned_docs/version-0.77/the-new-architecture/codegen-cli.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,26 @@ npx @react-native-community/cli codegen \
3939
--outputPath third-party/some-library/android/generated
4040
```
4141

42-
## Including Generated Code into Libraries
42+
# Including Generated Code into Libraries
4343

44-
The **Codegen** CLI is a great tool for library developers. It can be used to peek at the generated code to see which interfaces you need to implement. Or you can generate the code if you want to ship it in your library.
44+
The Codegen CLI is a great tool for library developers. It can be used to take a sneak-peek at the generated code to see which interfaces you need to implement.
4545

46-
This setup has several benefits:
46+
Normally the generated code is not included in the library, and the app that uses the library is responsible for running the Codegen at build time.
47+
This is a good setup for most cases, but Codegen also offers a mechanism to include the generated code in the library itself via the `includesGeneratedCode` property.
48+
49+
It's important to understand what are the implications of using `includesGeneratedCode = true`. Including the generated code comes with several benefits such as:
4750

4851
- No need to rely on the app to run **Codegen** for you, the generated code is always there.
49-
- The implementation files are always consistent with the generated interfaces.
52+
- The implementation files are always consistent with the generated interfaces (this makes your library code more resilient against API changes in codegen).
5053
- No need to include two sets of files to support both architectures on Android. You can only keep the New Architecture one, and it is guaranteed to be backwards compatible.
51-
- No need to worry about **Codegen** version mismatch between what is used by the app, and what was used during library development.
5254
- Since all native code is there, it is possible to ship the native part of the library as a prebuild.
5355

56+
On the other hand, you also need to be aware of one drawback:
57+
58+
- The generated code will use the React Native version defined inside your library. So if your library is shipping with React Native 0.76, the generated code will be based on that version. This could mean that the generated code is not compatible with apps using **previous** React Native version used by the app (e.g. an App running on React Native 0.75).
59+
60+
## Enabling `includesGeneratedCode`
61+
5462
To enable this setup:
5563

5664
- Add the `includesGeneratedCode` property into your library's `codegenConfig` field in the `package.json` file. Set its value to `true`.

0 commit comments

Comments
 (0)