Commit Graph

76 Commits

Author SHA1 Message Date
Sam Zhou 722f5ba786 Remove global React$ type references (#49276)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49276

This diff replaces the remaining `React$` global types in the codebase, in preparation for their removal in Flow.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D69322418

fbshipit-source-id: 058a2489ce8e6bf59df2ec4e61e9708f63561671
2025-02-07 18:01:43 -08:00
Alex Hunt b54efb8d0d Update multi-platform handling in build-types, add debug logs (#49224)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49224

Refactor / quality pass.

- Remove `micromatch`, replace with glob ignores.
- Move and simplify platfom-specific file logic: mutate `files` as a single `Set`, reduce iterations.
    - This is reconfigured so that the input file path globs need only match `*.js` sources.
- Introduce `debug` logs and expose convenience `--debug` script flag.
- Move output error detection into inner function implementation.

Changelog: [Internal]

Metro changelog: Internal

Reviewed By: j-piasecki

Differential Revision: D69240543

fbshipit-source-id: c2faef8212a2995936362b3d33d189c405bd879d
2025-02-06 08:49:29 -08:00
Rubén Norte 96205dd78e Add tinybench to run benchmarks in Fantom (#48453)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48453

Changelog: [internal]

Adds tinybench 3.1.0 (which has support for sync execution) and defined Flow types for the package.

Reviewed By: dmytrorykun

Differential Revision: D66698545

fbshipit-source-id: faf44add74e5711ac0d50794ce3360eedc45f0a5
2025-01-06 07:10:28 -08:00
Blake Friedman 27ef13174c Add simple Objective-C/CPP api tracking (#48449)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48449

This is the simplest possible way to track changes to our public CPP / Objective-C API.

This is going to be really noisy, and there's a good chance it's not complete.

The tooling is also incomplete, as it just runs the preprocessor (then does some funky work to undo noise generated by the preprocessor).  If we want more control over this, we're going to have to jump into the guts of each of our build targets (and tooling) OR more clearer layout the repo to separate public and private header files to our users.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D67713408

fbshipit-source-id: 9578179bbc4d9be2f07d040b01f8a3ef105d7034
2025-01-02 15:58:04 -08:00
Andrew Datsenko a4a2c2867a Add jest-snapshot (#48095)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48095

Changelog: [Internal]
Add `jest-snapshot` `v29.7.0`

Reviewed By: christophpurrer

Differential Revision: D66714069

fbshipit-source-id: 783584519e95b337d36c4a00610bcd970a041d4d
2024-12-09 19:09:57 -08:00
Andrew Datsenko b27bd00a38 add jest-diff to dependencies (#47990)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47990

Changelog:
[General][Added] - add `jest-diff v29.7.0` to devDependencies

Reviewed By: NickGerleman

Differential Revision: D66541001

fbshipit-source-id: 01c59a936b66f85ce034b59c7928df3c3f8c2a01
2024-11-28 10:04:46 -08:00
Rubén Norte 737045217b Implement expect().toEqual() (#47697)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47697

Changelog: [internal]

Implements `expect(received).toEqual(expected)` in Fantom tests.

Reviewed By: sammy-SC

Differential Revision: D66108539

fbshipit-source-id: 4e1d2405064900ec9859220fb6a28ec25a5176f3
2024-11-20 04:27:10 -08:00
Alex Hunt 35ab62cca3 Substitute @pkgjs/parseargs for Node builtin (#47704)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47704

Now that we have a min requirement of Node 18.18 on `main`, drop dependency on this polyfill.

Changelog: [Internal]

Reviewed By: vzaidman

Differential Revision: D66162328

fbshipit-source-id: e8ab6669fe14ed177eccf4b861c01df4fb0d405a
2024-11-19 09:47:40 -08:00
Rob Hogan da62721061 dev-middleware: refactor tests to use undici.request (#47675)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47675

Use `request` over `fetch` in `dev-middleware`'s tests.

This is required by the next diff in the stack to spoof the `Host` header for testing purposes, which isn't permitted by the `fetch` spec.

The return type is a bit different (eg `statusCode` vs `status`, no `ok` prop), but the modifications needed are pretty straightforward.

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D66005427

fbshipit-source-id: f311b0188d6d0ec220a037774fca78df5373163a
2024-11-18 15:14:02 -08:00
Blake Friedman a7023414fd add yargs#usage typing (#46983)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46983

X-link: https://github.com/facebook/metro/pull/1370

Add support for `.usage` overload: https://github.com/yargs/yargs/blob/main/docs/api.md#usagemessagecommand-desc-builder-handler

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D64241927

fbshipit-source-id: 9928f08bad16a5e1a6bcfa7c2cf2bfa73668ff57
2024-10-11 11:27:09 -07: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
Vitali Zaidman b37101486b update babel and fix tests accordingly (#46295)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46295

X-link: https://github.com/facebook/metro/pull/1343

Updated all **babel** packages in all `package.json` across the repo and ran `npx yarn-deduplicate yarn.lock --scopes babel`. Afterwards, fixed the following issues appearing as a result of that (squashed the following initially separate diffs to make this packages update work atomically):
### (D61336392) updated jest snapshot tests failing
### (D61336393) updated babel types and corrected typings accordingly
The latest babel 7 introduces the following features we need to adjust our types to:
* `JSXNamespacedName` is removed from valid `CallExpression` args ([PR](https://github.com/babel/babel/pull/16421))
  * `JSXNamespacedName` is used for namespaced XML properties in things like `<div namespace:name="value">`, but `fn(namespace:name)` doesn't make any sense.
* Dynamic imports are enabled behind a new flag `createImportExpressions` ([PR](https://github.com/babel/babel/pull/15682)), introducing calls such as `import(foo, options)`. These complicate the expected values passed to `import` to be more than just strings.
  * Since these are behind a flag that is not expected to be enabled, we can throw an error for now and whoever uses it can add a support to it if needed later.

### Added a new metro ENV ignore
`BROWSERSLIST_ROOT_PATH` is set to `""` explicitly in `xplat/js/BUCK`
and then ignored in
`js/tools/metro-buck-transform-worker/src/EnvVarAllowList.js`

Reviewed By: robhogan

Differential Revision: D61543660

fbshipit-source-id: abbcab72642cf6dc03eed5142eb78dbcc7f63a86
2024-09-05 07:11:17 -07:00
Alan Lee 9cd6f3ea31 fix prettier error in CI (#46255)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46255

Trying to fix lint error in GH likely happening after this [commit](https://github.com/facebook/react-native/commit/7bc9244d0cbebc310116b6b2a2baf0781073d0f5) (D60533197).

used ` yarn run format-check --write` to get changes need to fix the error when running prettier v29

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D61951889

fbshipit-source-id: 891b6b90e854504a35452e546c81bca644661dde
2024-08-28 19:35:46 -07:00
David Prevost 7bc9244d0c Upgrade pretty-format to v29 (#45732)
Summary:
As described in [this issue](https://github.com/facebook/react-native/issues/45726), we had a problem where, at runtime, version v29 instead of v26 was used, so upgrading it is the fastest fix.

## Changelog:

[GENERAL] [CHANGED] - Upgrade pretty-format to 29.7.0

<!--
For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

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

Test Plan:
I use console log in the RN tester app
![image](https://github.com/user-attachments/assets/3e3ab0d1-e32b-4b73-8f00-cbd8f040c5aa)

Reviewed By: blakef

Differential Revision: D60533197

Pulled By: tdn120

fbshipit-source-id: b83dbfe463971abbf00cfebdcc9e5dd6975de0d8
2024-08-28 13:12:43 -07:00
Sam Zhou ae73fe462e Replace React$Element that will cause an error in the future
Summary:
For the ones where `React.MixedElement` would suffice, I change them to `React.MixedElement`. For everything else, I changed it to be `React.Element`

Changelog: [Internal]

Reviewed By: gkz

Differential Revision: D60798229

fbshipit-source-id: 40176b44769aade2c6b63a680d03c10056b2ddfa
2024-08-05 18:42:05 -07:00
Blake Friedman 0731f373c1 flow semver 6.2 -> 7 type defintions (#45495)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45495

Unify type definitions to semver@7, to fix a [type-sync](https://www.internalfb.com/intern/test/281475050813096/) test that was broken by D59378011.  The test is very simple and doesn't actually understand the typing.

I don't believe there is a significant difference in the typing, esp. with how we're using it.  Flow will tell us if this is the case though (🏖️ 🏰).

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D59855434

fbshipit-source-id: ae3c6b7aa81b3cde25468d72a7922bcb2b6f652f
2024-07-17 07:32:29 -07:00
Blake Friedman 6547b157b5 Remove dependency on rnc/cli-tools logger (#45381)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45381

Removing the remaining dependencies from the react-native-community/*. This
inlines a copy of the logger.

Changelog:
[Internal][Changed] Removed react-native-community/cli-tools logger dependency

Reviewed By: cipolleschi

Differential Revision: D59378011

fbshipit-source-id: ef93d9fff1c623658e33c36b6329f5d548f649e8
2024-07-15 04:35:26 -07:00
Blake Friedman 3b59b27087 fix rxjs flow types linting warnings (#44719)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44719

Removed shadowing of generic values, which would cause warnings.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D57915364

fbshipit-source-id: 6abf68a62fca88687343ac5677ac905e87220a91
2024-05-30 08:20:00 -07:00
Blake Friedman 32b5c9601f listr → listr2 (#44716)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44716

Move to listr2 which handle non-TTY environment, outputting to CircleCI logs in a useful way.  This gives our CI users more useful debugging information, but limits the output when running locally.

If you want more explicit output locally, do something like:

```
yarn run build | cat
```

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D57915369

fbshipit-source-id: ae9f87b0b9608f16ee035b791c5f7b81544c498c
2024-05-30 07:40:36 -07:00
Alex Hunt 5d827d83c1 Simplify debugger launch flow to invoke Chrome directly, drop kill API (#44672)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44672

Swaps out and simplifies the internals of the debugger launch flow.

We observed that we could achieve better launch/windowing behaviour by passing the `--app` argument directly to the detected Chrome path.

This shares the user's default Chrome profile:
- Fixes unwanted behaviour such as a separate dock icon on macOS (which, when clicked, would launch an unwanted empty window).
- Enables settings persistence.

This change also removes the `LaunchedBrowser.kill` API.

Changelog: [Internal]

Reviewed By: hoxyq

Differential Revision: D57726649

fbshipit-source-id: fc3a715dc852a50559048d1d1c378f64aeb2013f
2024-05-27 02:53:36 -07:00
Blake Friedman 67392cef3c add listr + rxjs flow types for OSS export
Summary:
Based on a more recent 14.x.x release of Listr.

Changelog: [Internal]

These are direct copies from `xplat/js/flow/{listr,rxjs_v6.x.x}.js`

Reviewed By: huntie

Differential Revision: D56576985

fbshipit-source-id: c850c89891bf8eb57586a5e2a50f0204fd885f65
2024-04-26 03:10:00 -07:00
Blake Friedman 9d1f951ab0 remove from build script (#44233)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44233

The package was added to our build scripts, but shouldn't have been.  We're not exporting this package or making it public.

Changelog: [Internal]

This should unblock our OSS CI.

Reviewed By: cipolleschi

Differential Revision: D56513694

fbshipit-source-id: f37c75871253b2570fb933175165d8f0a9593a16
2024-04-24 03:53:34 -07:00
Blake Friedman 995d5b832d Add an internal HelloWorld template
Summary:
This is a copy of the current packages/react-native/template that we exclusively use internally for testing.

Changelog: [Internal]

NOTE: Best contribution would be to scan the file list and ensure there isn't anything that shouldn't be in there.

bypass-github-export-checks

Reviewed By: cortinico, cipolleschi

Differential Revision: D56242484

fbshipit-source-id: 0913ff7acff9b0314b49f48e986674b77dbb908e
2024-04-23 15:07:59 -07:00
Edmond Chui 059615f336 fix Page visibility API in launched CDT (#43560)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43560

Changelog: [internal]

Reviewed By: huntie

Differential Revision: D55047534

fbshipit-source-id: e8e17bb1ca7282e0c29e968b6cbd5b4ec147d946
2024-03-20 05:54:12 -07:00
Moti Zilberman 1ae379c6ec Migrate back to chromium-edge-launcher since Windows fix was merged (#43562)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43562

A resubmission of D55013623 (Pull Request resolved: https://github.com/facebook/react-native/pull/43524) with a fix for the internal `.flowconfig` issue that got the initial diff reverted.

 ---

The [Windows fix](https://github.com/cezaraugusto/chromium-edge-launcher/pull/1) was merged and published. We no longer need to use the fork.

## Changelog:

[INTERNAL] [FIXED] - Fix experimental debugger launch flow with Edge on Windows

Reviewed By: NickGerleman

Differential Revision: D55087731

fbshipit-source-id: 6fd28a32447ad07dacdf6cd77390e18489fd6cfb
2024-03-20 03:55:35 -07:00
Wendi Du ff5e1a605a Revert D55013623: Migrate back to chromium-edge-launcher since Windows fix was merged
Differential Revision:
D55013623

Original commit changeset: bff2aa2801dd

Original Phabricator Diff: D55013623

fbshipit-source-id: d7f19068327b5cf427750fbcae01d3c10f9c89b5
2024-03-18 14:29:02 -07:00
Tommy Nguyen 43ffce9fb3 Migrate back to chromium-edge-launcher since Windows fix was merged (#43524)
Summary:
The [Windows fix](https://github.com/cezaraugusto/chromium-edge-launcher/pull/1) was merged and published. We no longer need to use the fork.

## Changelog:

[INTERNAL] [FIXED] - Fix experimental debugger launch flow with Edge on Windows

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

Test Plan: n/a

Reviewed By: robhogan

Differential Revision: D55013623

Pulled By: motiz88

fbshipit-source-id: bff2aa2801dd0dcdd6975dca0a2ec2aa9864ff6f
2024-03-18 10:45:04 -07:00
Pieter Vanderwerff 082decb76d Deploy 0.231.0 to xplat (#43475)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43475

Changelog: [Internal]

Reviewed By: SamChou19815

Differential Revision: D54886285

fbshipit-source-id: cc4f6eeb7986a25d2bb423dac0b7d1d5a74b9703
2024-03-13 22:23:03 -07:00
Alex Taylor (alta) 1ad3bbc437 Deploy 0.228.0 to xplat (#42802)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42802

Changelog: [Internal]

Reviewed By: SamChou19815

Differential Revision: D53337590

fbshipit-source-id: 31e40d692495fc795d3d69b20ba12fcb420b28e7
2024-02-05 19:12:57 -08:00
Rubén Norte dbbec3452f Use Flow in feature flags scripts (#42814)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42814

Improves the type safety of the feature flags generation and verification script.

Changelog: [internal]

Reviewed By: huntie

Differential Revision: D53351484

fbshipit-source-id: a71af1bb428cdec327d557de4d54bee9ece57f34
2024-02-05 11:02:48 -08:00
Luna Wei 0851f04353 Flow type some util files (#42372)
Summary:
Changelog: [Internal] Flow comment type some util scripts

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

Reviewed By: NickGerleman

Differential Revision: D52893759

Pulled By: lunaleaps

fbshipit-source-id: 6a3632f2c0b9faa97a451d82ef5a888bb5be81fa
2024-01-22 10:29:54 -08:00
Sam Zhou cd9b1d9e43 Replace $Call in babel-traverse libdef with conditional type (#41736)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41736

Changelog: [Internal]

Reviewed By: gkz

Differential Revision: D51735062

fbshipit-source-id: 942264cdc9f71e4aaa6f730d68f5a2a6e2fc7493
2023-11-30 19:40:12 -08:00
Sam Zhou 414357acde Update babel-types codegen to use type guards instead of %checks (#41597)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41597

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D51508414

fbshipit-source-id: 6572e02a42c30874bc7e2ef48b9c389dcb906914
2023-11-22 10:41:58 -08:00
Moti Zilberman 560e0f0005 Migrate to @rnx-kit/chromium-edge-launcher for Windows fix (#41367)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41367

Andrew Coates graciously published the Windows Edge launcher fix from https://github.com/cezaraugusto/chromium-edge-launcher/pull/1 as a new package (https://github.com/microsoft/rnx-kit/pull/2796), so let's pull that into `dev-middleware`.

Changelog: [Internal] - Fix experimental debugger launch flow with Edge on Windows

Reviewed By: robhogan

Differential Revision: D51086297

fbshipit-source-id: 3a8db351f71eb31a9609c987cdb4dc66f24f9403
2023-11-15 00:18:10 -08:00
Moti Zilberman 3afadef6d6 Add tests for source map fetching and URL rewriting hacks (#41339)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41339

Tests for D42973408, D14800976, and D15116579.

Changelog: [Internal]

Reviewed By: blakef

Differential Revision: D51013055

fbshipit-source-id: cff8a9d1dd22b642117594da16e6b74cf679aa34
2023-11-08 07:19:40 -08:00
Moti Zilberman c6eccda2c7 Add tests for HTTPS-specific behaviour (#41341)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41341

* Extends `dev-middleware`'s test utilities to enable testing against an HTTPS server with a self-signed cert.
* Runs the CDP transport integration tests (D51002261) using both HTTP and HTTPS.
* Adds a test to explicitly cover the `ws=...` / `wss=...` variation in `devtoolsFrontendUrl` first introduced in D49158227.

Changelog: [Internal]

Reviewed By: blakef

Differential Revision: D51006835

fbshipit-source-id: df3db8cd865898248cd0d8f307f75949a7f313fd
2023-11-08 07:19:40 -08:00
Moti Zilberman 38a878194b Add CDP transport tests (#41343)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41343

Changelog: [Internal]

Adds basic tests for two-way communication between a debugger (frontend) and a target (backend) using CDP over `inspector-proxy`.

Reviewed By: blakef

Differential Revision: D51002261

fbshipit-source-id: 44e571f89437c26e76ef6e6192b2bf6244665cf0
2023-11-08 07:19:40 -08:00
Moti Zilberman 68930f78d1 Add rejectUnauthorized option to ws types (#41337)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41337

X-link: https://github.com/facebook/metro/pull/1133

Changelog: [Internal]

Adds a Flow definition that allows passing the [`rejectUnauthorized`](https://nodejs.org/api/tls.html#tlscreateserveroptions-secureconnectionlistener:~:text=(120%20seconds).-,rejectUnauthorized,-%3Cboolean%3E%20If) option to a WebSocket client. (See [example usage](https://github.com/websockets/ws/blob/a049674d936746c36fe928cc1baaaafd3029a83e/examples/ssl.js#L33) in the `ws` repo.)

Reviewed By: robhogan

Differential Revision: D51014312

fbshipit-source-id: 25794b1867ca5f15fab1592e8f80cdad8cdf897a
2023-11-06 11:01:25 -08:00
Moti Zilberman b256f8b791 Sync @pkgjs/parseargs Flow types with Node types (#39163)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39163

Changelog: [Internal]

Flow knows about `util.parseArgs` now and has [really nice types for it](https://github.com/facebook/flow/commit/dc5c06a7cbf4b326bd1582b91c5cd0ed65a705bb), so let's update the type definitions for the `pkgjs/parseargs` shim to use those. The updated types use conditional and mapped types to generate a more precise return type for `parseArgs`, based directly on the provided config object.

Reviewed By: huntie

Differential Revision: D48683091

fbshipit-source-id: c0c8fe655a595e6f2f5cf1d4fc1ff0163ed3635f
2023-10-20 12:34:29 -07:00
Alex Hunt 9e068ac163 Add --experimental-debugger-frontend flag, restore 0.72 flow as base (#40766)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/40766

This changeset allows users to opt into the new debugger frontend experience by passing `--experimental-debugger` to `react-native start`. **We are defaulting this option to `true`** for now, but will continue to evaluate this feature before 0.73 ships. It restores Flipper (via `flipper://`) as the default handling for `/open-debugger` (matching 0.72 behaviour) when this flag is not enabled.

Detailed changes:

- Replaces `enableCustomDebuggerFrontend` experiment in `dev-middleware` with `enableNewDebugger`. The latter now hard-swaps between the Flipper and new launch flows.
    - Removes now-unused switching of `devtoolsFrontendUrl`.
- Implements `deprecated_openFlipperMiddleware` (matching previous RN CLI implementation).
- Disables "`j` to debug" key handler by default.
- Marks "`j` to debug" and `/open-debugger` console logs as experimental.

Changelog:
[Changed][General] Gate new debugger frontend behind `--experimental-debugger` flag, restore Flipper as base launch flow

Reviewed By: motiz88

Differential Revision: D50084590

fbshipit-source-id: 5234634f20110cb7933b1787bd2c86f645411fff
2023-10-10 09:37:41 -07:00
Alex Hunt 4dcd5f1065 Type serve-static and document /debugger-frontend (#40765)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/40765

Types based on https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/serve-static/index.d.ts.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D50084591

fbshipit-source-id: 92fd833d90dfc5acbd3be0476f1da34e5742a732
2023-10-10 09:37:41 -07:00
Alex Hunt 196b3f9ef9 Improve start command interactive behaviour (#39544)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39544

Misc improvements to `npx react-native start` interactive behaviour:

- Attaches key handlers on Metro `initialize_done` event — printing key command info earlier (once the server starts listening to bundle requests).
- Shutdown behaviour:
    - Awaits closing of Metro's HTTP server.
    - Pauses key listener while awaiting shutdown (dependency on `cli-tools` `addInteractionListener` dropped).
    - Now observes `ctrl+d` (`ctrl+z` pause behaviour removed).
- Updates reload handler message to 'Reloading connected app(s)...' (since ).
- Adds newline below key commands printout (even spacing).

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D49422206

fbshipit-source-id: 8963b22ddb182df7a1116906fc63cc65bfe982fc
2023-09-20 03:47:13 -07:00
Moti Zilberman 3ec22c1e69 Add option to enable experimental debugger frontend (#39227)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39227

Changelog: [Internal]

1. Adds an `unstable_experiments` option to `createDevMiddleware` in `react-native/dev-middleware`.
2. Adds `enableCustomDebuggerFrontend` (default `false` for now) as an experiment flag controlling whether the new debugger frontend (D48680624, D48682302) is in use. We plan to enable this by default in RN 0.73 after additional testing.

If enabled, the new debugger frontend will only be used for the `/open-debugger` flow

Reviewed By: huntie

Differential Revision: D48602725

fbshipit-source-id: 598865b559478df1f19420daf3633ee6c233362a
2023-09-04 12:21:47 -07:00
Alex Hunt 4cb9706331 Add Microsoft Edge support for opening debugger (#39146)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39146

Adds Microsoft Edge fallback for the `/open-debugger` endpoint when no Chrome installation is found.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D48563386

fbshipit-source-id: 74baba7c03a062bd769b2f9ac0cc35bac0b2ae65
2023-08-24 10:57:39 -07:00
Alex Hunt 13eda31d43 Simplify occupied port handling in start command (#39078)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39078

Simplifies and hardens behaviour for detecting other processes / dev server instances when running `react-native start`.

- New flow:
    - Exits with error message if port is taken by another process (*no longer suggests next port*).
    - Exits with info message if port is taken by another instance of this dev server (**unchanged**).
    - Continues if result unknown.
    - *(No longer logs dedicated message for another RN server running in a different project root.)*
- This now checks if the TCP port is in use before attempting an HTTP fetch.

Previous behaviour: [`handlePortUnavailable`](https://github.com/react-native-community/cli/blob/734222118707fff41c71463528e4e0c227b31cc6/packages/cli-tools/src/handlePortUnavailable.ts#L8). This decouples us from some lower-level `react-native-community/cli-tools` utils, which remain reused by the `android` and `ios` commands.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D48433285

fbshipit-source-id: 7056001d5fe2f90faf52143f2777c9e2bdf0646e
2023-08-22 12:56:19 -07:00
Moti Zilberman d10a8098b2 Log debugger command latency and status (#39107)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39107

Augments D48466760 to report debugger commands (request/response pairs) through `EventReporter`. With the appropriate backend integration, this can help validate the correctness/completeness of the CDP implementation (in the client, proxy and server) and measure the latency of debugger commands - more accurately, the time between the proxy receiving a command from the client and receiving the corresponding response from the server.

Most of the new logic here is in the `DeviceEventReporter` class, which is responsible for associating responses with requests. Requests are kept in a buffer with a 10s TTL which serves as a timeout in case of an unresponsive server.

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D48480372

fbshipit-source-id: 55360a14bbea05ef8ad1622e0d54f18b47483809
2023-08-22 11:11:50 -07:00
Alex Hunt c82cf64a22 Move metro-inspector-proxy into dev-middleware (#39045)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39045

## Context

RFC: Decoupling Flipper from React Native core: https://github.com/react-native-community/discussions-and-proposals/pull/641

## Changes

- Relocates `metro-inspector-proxy` source from the Metro repo into the React Native repo as part of the `react-native/dev-middleware` package.
    - Drops the `runInspectorProxy` entry point.
- Attaches the Inspector Proxy to the `createDevMiddleware()` API as the new integration point for this functionality.
- Documents migrated endpoints + usage of `createDevMiddleware()` in README.

Changelog: [Internal]
Metro changelog: None (`metro-inspector-proxy` is now an internal component of `react-native`, covered in the [release notes for 0.78.1](https://github.com/facebook/metro/releases/tag/v0.78.1))

Reviewed By: motiz88, blakef

Differential Revision: D48066213

fbshipit-source-id: 3fbef5d881f6f451cb5955dcbbc362c53347437e
2023-08-18 01:38:10 -07:00
Alex Hunt 39a41fa2a0 Convert community-cli-plugin to Flow strict (#38961)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38961

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D48066180

fbshipit-source-id: 72b8b25a70062a71ab13aa1d62f3418582e99013
2023-08-15 02:33:22 -07:00
Alex Hunt 164133cada Sync latest cli-plugin-metro changes (#38944)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38944

- Update `cli-commands` package to reflect latest source `react-native-community/cli-plugin-metro` changes.
	- https://github.com/react-native-community/cli/pull/2021
	- https://github.com/react-native-community/cli/pull/2024
	- https://github.com/react-native-community/cli/pull/2043
	- https://github.com/react-native-community/cli/pull/2047

### To do

WARNING: ~~This PR is non-functional until the next CLI alpha is published and bumped in `package.json` — since it depends on corresponding new APIs in `react-native-community/cli-tools` (https://github.com/react-native-community/cli/pull/2021). This package (and the upcoming work which integrates it) has been tested against locally linked copies of latest CLI.~~

- [x] Bump CLI dependencies when next alpha published.
- [x] Ensure Metro bump from `0.77.0` to `0.78.0` is consistently applied with this.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D48066179

fbshipit-source-id: b3dc8891cf33e537788f942dcaddff4d2f11a31f
2023-08-15 02:33:22 -07:00
Alex Hunt a978d343a6 Add auto-generation of TypeScript definitions on build (#38990)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38990

This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (https://github.com/facebook/react-native/pull/38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.
- Add minimal `flow-typed` definitions for `typescript` 😄.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D48312463

fbshipit-source-id: 817edb35f911f52fa987946f2d8fc1a319078c9d
2023-08-14 12:12:10 -07:00