Commit Graph

24 Commits

Author SHA1 Message Date
Sam Zhou f697b5ad5c Make functions async and add await to prepare for prettier v3 upgrade: 6/n (#52770)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52770

Prettier v3 has an async API. This diff adds in async and await ahead of the upgrade to prepare for the API change.

Changelog: [Internal]

Reviewed By: pieterv

Differential Revision: D78752906

fbshipit-source-id: 2deeecfc283be30fd0840b2a089604f4e6804af5
2025-07-22 16:18:26 -07:00
Sam Zhou 2c3a00b7b1 Use the prettier config at the root for react-native-codegen (#52746)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52746

The config is needed for build, so I renamed it. In this way, the formatting of js code in react-native repo will be consistently controlled by the prettier config in the root. This change will make prettier v3 upgrade easier.

Changelog: [Internal]

Reviewed By: pieterv

Differential Revision: D78700564

fbshipit-source-id: 392ed490bf814870f285c8372ff68b454e228802
2025-07-21 19:45:34 -07:00
Alex Hunt 62bf92c896 Replace chalk in packages (#51905)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51905

Replaces `chalk` with Node's `util.styleText` in `packages/`.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D76273412

fbshipit-source-id: edaea5896751be1252056e0858daae46e97acc46
2025-06-09 18:21:18 -07:00
Tim Yung cc9074884a RN: Add @noflow to Node.js Scripts (#51779)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51779

Adds `noflow` to a bunch of Node.js script files.

In the future, these files could be migrated to use `flow strict-local` or `flow strict` using comment syntax for type annotations. But for now, adding `noflow` makes it explicit that these are known to not be typechecked.

Changelog:
[Internal]

Reviewed By: SamChou19815

Differential Revision: D75883703

fbshipit-source-id: a8fed3aaa9c55ecda919a705940f8b34504cb07c
2025-06-04 12:03:52 -07:00
Phil Pluckthun b52f0d8391 chore(react-native-codegen): Remove fixtures and outdated transforms from build output (#49916)
Summary:
- Update ignore micromatch pattern to filter out `__test_fixtures__` from build output
- Remove `babel/plugin-transform-object-rest-spread`
- Remove `babel/plugin-transform-async-to-generator`
- Remove `babel/plugin-transform-destructuring`

The `package.json:engines:node` field is already set to `>=18` which makes the three Babel transforms that were removed redundant.

## Changelog:

[INTERNAL] [CHANGED] - Remove fixtures files and outdated Babel transforms from `react-native/codegen` build output

Pull Request resolved: https://github.com/facebook/react-native/pull/49916

Test Plan: - Ran against Node 18

Reviewed By: robhogan

Differential Revision: D70885090

Pulled By: cortinico

fbshipit-source-id: 328b75a6031a7ca6a9b3ed170061ffb0a47d6d93
2025-03-10 05:44:32 -07:00
Nicola Corti 1282361573 Silence the eden info output from react-native-codegen (#48540)
Summary:
We currently see this error message on console:
![Screenshot 2025-01-08 at 19 09 47](https://github.com/user-attachments/assets/3b384772-9abc-40a5-83b3-9b4ccce85f4a)

This will silence it by piping stderr to /dev/null

## Changelog:

[INTERNAL] - Silence the `eden info` output from react-native-codegen

Pull Request resolved: https://github.com/facebook/react-native/pull/48540

Test Plan: CI

Reviewed By: robhogan

Differential Revision: D67948411

Pulled By: cortinico

fbshipit-source-id: f805634a65713f4f9bc2dce6d781664e7564bc96
2025-01-09 04:01:29 -08:00
anirudh.bharti 7cdb87eb19 chore: replace mkdirp with mkdir fs (#46388)
Summary:
This pull request replaces the use of mkdirp with Node.js's built-in fs.mkdirSync({ recursive: true }) function, which is available in Node.js version 10.12.0 and above. This change reduces the number of external dependencies and simplifies the codebase by using the native capabilities of Node.js.

The motivation behind this change is to remove the unnecessary mkdirp dependency, as Node.js natively supports recursive directory creation since version 10.12.0. This streamlines the code and reduces the reliance on external libraries.

## Changelog:

[INTERNAL] [REMOVED] - Replaced mkdirp with fs.mkdirSync({ recursive: true }) in build scripts and codegen. Requires Node.js 10.12.0 and above.

Pull Request resolved: https://github.com/facebook/react-native/pull/46388

Test Plan: I ran the build and codegen scripts locally with Node.js version 10.12.0 and above after replacing mkdirp, ensuring the scripts work as expected. No issues were encountered, and all processes, including directory creation and file handling, function correctly.

Reviewed By: cortinico

Differential Revision: D62852488

Pulled By: huntie

fbshipit-source-id: 76f44102a80b499521c156308d276a17d279ce38
2024-09-17 07:03:44 -07:00
Blake Friedman e0799536ef Fix: OSS builds can accidentally using coreutils cp (#44097)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44097

There are two places where we use a feature specific to the system version of 'cp', the:

  -X    Do not copy Extended Attributes (EAs) or resource forks.

This feature isn't available in GNU's cp, which is commonly installed on macOS using:

  brew install coreutils && brew link coreutils

We can avoid the problem alltogether by being specific about the path of the system cp.

Changelog: [General][Fixed] don't break script phase and codegen when coreutils installed on macOS

Reviewed By: cipolleschi

Differential Revision: D56143216

fbshipit-source-id: f1c1ef9ea2f01614d6d89c4e9eedf43113deb80c
2024-04-17 08:08:50 -07:00
Gijs Weterings d4ad19c969 Revert D49370200: Migrate codegen to shared build setup, remove package build pre-step from RNTester
Differential Revision:
D49370200

Original commit changeset: 992913155169

Original Phabricator Diff: D49370200

fbshipit-source-id: e8232c97c22065fb54ac940ee2351b2155eb51e0
2023-10-23 12:00:54 -07:00
Alex Hunt 4db31a3110 Migrate codegen to shared build setup, remove package build pre-step from RNTester (#39540)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39540

This simplifies the use of Codegen when creating dev builds of `rn-tester` in the monorepo. It now runs from source for this internal scenario, and this package is now built using the shared monorepo build setup.

Changes:
- Migrate `packages/react-native-codegen` to the shared `yarn build` setup.
    - Update package to use `"exports"` field and wrap entry point modules with `babel-register` (NOTE: This is only required for each entry point internally used in the monorepo).
- Fixup small Flow syntax quirks that fail under `hermes-parser`.
- Remove `BuildCodegenCLITask` task from Android build.
- Remove Codegen `build.sh` call from iOS build, use `require.resolve` for `combine-js-to-schema-cli.js` entry point.

Externally significant FYIs:
- `react-native/codegen` is converted to use the `"exports"` field — it should export all `.js` files, as before.
- `codegenPath` is now ignored and marked as deprecated on `ReactExtensions.kt`.

NOTE: TypeScript auto-generation is not yet enabled on this package, since it uses CommonJS `module.exports` syntax (unsupported by `flow-api-translator`).

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D49370200

fbshipit-source-id: 992913155169912ea1a3cb24cb26efbd3f783058
2023-10-23 08:32:33 -07:00
Alex Hunt eaec4f7fda Fix Codegen build script on EdenFS (#39566)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39566

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

NOTE: **This is temporary**. The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](https://github.com/facebook/react-native/pull/38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D49468891

fbshipit-source-id: 25d5db81798cf8ab150a135174a45f4d4c2cb5a2
2023-09-21 04:09:43 -07:00
Nicola Corti cf33e048dc Remove Codegen buck-oss scripts as they're unused (#39422)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39422

Those scripts were used when Buck OSS was invoking codegen. As we don't do Buck OSS anymore, we can remove them.

Changelog:
[Internal] [Changed] - Remove Codegen buck-oss scripts as they're unused

Reviewed By: huntie

Differential Revision: D49229846

fbshipit-source-id: fad0526e609bab159c56a62b85c91690e4cdbbce
2023-09-13 08:46:52 -07:00
Ian Childs bb8ddd6c12 Use realpath instead of readlink
Summary:
Changelog: [Internal]

Generated with:

```
python3 codemod.py -d xplat/js --extensions=sh 'THIS_DIR=\$\(cd -P "\$\(dirname "\$\(readlink "\${BASH_SOURCE\[0\]}"' 'THIS_DIR=$(cd -P "$(dirname "$(realpath "${BASH_SOURCE[0]}"'```

Reviewed By: motiz88

Differential Revision: D34379955

fbshipit-source-id: c60521cd6508b203f48ca8c890c450319991c2d4
2022-02-22 02:23:02 -08:00
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -08:00
Tim Yung 148c98ec80 RN: Resolve Outstanding ESLint Warnings
Summary:
Resolves outstanding ESLint warnings in React Native.

Changelog:
[Internal]

Reviewed By: lunaleaps

Differential Revision: D32291912

fbshipit-source-id: 61337d5a5a0e6ed55f732675e029f4b76d850af9
2021-11-09 21:46:21 -08:00
Tim Yung 77ecc7ede1 JS: Format with Prettier v2.4.1 [3/n]
Summary:
Changelog:
[General][Internal]

Reviewed By: zertosh

Differential Revision: D31883447

fbshipit-source-id: cbbf85e4bf935096d242336f41bf0cc5d6f92359
2021-11-02 22:14:16 -07:00
Igor Klemenski 5dc15222b2 Fix building RN Android from source on Windows. (#30535)
Summary:
Running `.\gradlew installArchives` is currently broken on Windows. This is because .sh scripts were added in the codegen module, which cannot be run by the Command Prompt on Windows. It can be worked around by installing eg. Git Bash., which can be then leveraged using the code modifications in this PR, which include sanitizing mixed Linux-Windows relative paths, and other minor Windows-specific adjustments.

It's required that the user adds a Windows Environment variable storing the path to their bash binary named `REACT_WINDOWS_BASH`.

Pair-programmed with davinci26
## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fix] - Fix building React Android on Windows.

Fixes https://github.com/facebook/react-native/issues/30271

Pull Request resolved: https://github.com/facebook/react-native/pull/30535

Reviewed By: ShikaSD

Differential Revision: D25909760

Pulled By: appden

fbshipit-source-id: ea0e6e7c161a5e4a937d46e8e6972ce142fead4e
2021-01-28 11:53:56 -08:00
Héctor Ramos e99b8bbb40 Use react-native-codegen@0.0.6 in new app template
Summary:
Use pre-built react-native-codegen library from npm in the iOS app template.
Built react-native-codegen from source when used with RNTester.
Published react-native-codegen@0.0.6.

Changelog:
[iOS][Added] - Use react-native-codegen in iOS app template
[Internal] - Bump react-native-codegen: 0.0.6

Reviewed By: fkgozali

Differential Revision: D25128036

fbshipit-source-id: f294c23b9b911aae6f404edc01b62426fb578477
2020-11-20 20:11:59 -08:00
Kevin Gozali 1bbcbd55ff Android OSS: fixed unbound variable error for codegen build script
Summary:
If $FBSOURCE_ENV isn't set, this failed with `/root/react-native/packages/react-native-codegen/android/../scripts/oss/build.sh: line 20: FBSOURCE_ENV: unbound variable`.

This commit fixes https://app.circleci.com/pipelines/github/facebook/react-native/7080/workflows/5cf18a1f-e6d2-4648-8217-d42e9a61fef1/jobs/176451

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24912950

fbshipit-source-id: 113e3dd7f78c75fc3adea0b21c9e38910be8c065
2020-11-11 22:39:27 -08:00
Janic Duplessis d5db2cb5d1 Build rn-codegen in a temporary directory (#30292)
Summary:
When running yarn install from the codegen directory it will reinstall all dependencies for the react-native workspace inside the react-native package. In my case this caused issues with metro because it would now have 2 copies of it (node_modules/metro and node_modules/react-native/node_modules/metro).

To avoid this copy the react-native-codegen source in a temporary directory and yarn install from there, then copy the built files back.

## Changelog

[Internal] - Build rn-codegen in a temporary directory

Pull Request resolved: https://github.com/facebook/react-native/pull/30292

Test Plan: Tested the script in an app with codegen enabled. Fresh install with rn-codegen not built, made sure no extra modules are installed under node_modules/react-native/node_modules.

Reviewed By: yungsters

Differential Revision: D24893216

Pulled By: fkgozali

fbshipit-source-id: 2c372b755632ea6f50ad5d4562248612b349a9a6
2020-11-11 19:17:12 -08:00
Kevin Gozali f2ba978cad Codegen Android: build react-native-codegen via yarn when building from source
Summary:
The Gradle codegen integration requires the JS CLI to be first built via `yarn run build`. This commit puts that logic in a `build.sh` script, then defines a Gradle task to build it.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24556992

fbshipit-source-id: 7092de7c1126edc157b122f4b2243e55f7188846
2020-10-26 23:47:54 -07:00
Kevin Gozali 2a634f452c Codegen BUCK: moved generate-test.sh to be general-purpose generate-all CLI
Summary:
This moves the test script that generates **all outputs using all generators** to a dedicated "generate-all" CLI. This allows us to use it via Buck, at FB and OSS.
Also renamed the target to be more specific: "rn_codegen" => "generate_all_from_schema"

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24513995

fbshipit-source-id: 8435d3d065718eb1309c1c61fe28fb592787311a
2020-10-24 14:02:47 -07:00
Kevin Gozali 16044b3c2a Codegen Buck: fork schema generator target for FB vs OSS via rn_codegen_cli()
Summary:
Introduced a helper macro `rn_codegen_cli()` that defines ":write_to_json" and ":rn_codegen" targets differently based on the environment. When run at FB, it uses FB-specific setup. When run in OSS as a standalone repo, we use `yarn install` and `yarn run build` directly, then use `node` to run the output CLI.

This way, the same target can be used in both environments on other Buck targets.

Motivation: we need this to define rn_codegen_modules() to use codegen to produce Java TurboModule specs, that can be built by CircleCI (we build ReactAndroid via Buck as well). That way we can finally removed the checked-in .java spec files.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24442468

fbshipit-source-id: b1e5fce275100cfe3a1b3ae6d61c1c6d4b25651b
2020-10-22 17:09:30 -07:00
empyrical c67e1fe42f Codegen: Add prepublish script to build Flow files (#28827)
Summary:
*This is a follow-up to https://github.com/facebook/react-native/issues/28645, redone using a build script based off of Metro's build script instead of using `flow-remove-types` and `flow-copy-source`.*

This pull request adds a build step to `react-native-codegen` that builds the Flow-annotated JS files so that users of the NPM module `react-native-codegen` do not need to use require hooks to be able to import it.

A new build script, `scripts/build.js` is added that builds every JS file in `src/` into a `lib/` folder, and also copies over the original Flow annotated files to `lib/` with a `.js.flow` extension, so users of `react-native-codegen` can still typecheck against it using Flow. The shell scripts in `src` are also copied over. It is based off of the [build script from Metro](https://github.com/facebook/metro/blob/00867816eb9b2f69c8af9cebb523e9e4d280671a/scripts/build.js)

## Changelog

[General] [Added] - Codegen: Add prepublish script to build Flow files
Pull Request resolved: https://github.com/facebook/react-native/pull/28827

Test Plan:
I am able to make use of the Codegen scripts without needing to use the `flow-node` CLI or the `flow-remove-types/register`
require hook.

Reviewed By: cpojer

Differential Revision: D21412173

Pulled By: hramos

fbshipit-source-id: 26ae67cdd04652ca4700a069a234a25558773cb1
2020-05-08 15:41:35 -07:00