mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Add an interactive REPL for Fantom (yarn fantom-cli) (#57387)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/57387 Adds `yarn fantom-cli`, an interactive REPL that evaluates JavaScript against the same native tester binary and Hermes runtime that Fantom tests run in. State persists across lines, input goes through Metro/Babel (so `import`, JSX and Flow all work), and the environment is set up the same way tests set it up — `React`, `ReactNative` and the `Fantom` API are available globally, so you can render surfaces and drive them interactively from the prompt. The native tester gains an `--interactive` mode that loads a warm-up bundle without running tests and then evaluates length-prefixed snippets read from stdin, reporting results, console output and errors back as newline-delimited JSON. A Node driver hosts a Metro server, builds the warm-up bundle, spawns the binary, and bridges each line of input into the live runtime (top-level declarations persist across evaluations). Features: - Console-style output: results are printed with an inspector similar to the Chrome DevTools / Node.js consoles (nested objects/arrays up to a depth limit, quoted strings, functions/classes, `Map`/`Set`/`RegExp`/`Date`/`Error`, class instances, circular references, multi-line wrapping), colorized by type when stdout is a terminal. Inspecting a property never aborts the result or leaks into later evaluations: a property whose getter fails renders as `[Thrown: <error>]`, including getters that fail asynchronously through the runtime's global error handler (e.g. accessing a `react-native` export backed by a TurboModule that isn't registered). - Autocompletion: pressing Tab completes global identifiers, in-scope bindings and object properties (property names are listed without invoking getters). - Node-like CLI: with no arguments it starts the REPL; `-e <code>` evaluates a snippet and exits; a filename runs that script and exits. In the non-interactive modes the value of a trailing expression is not printed (use `console.log`) and a thrown error exits with a non-zero status code. Also documents the REPL in the Fantom README. Changelog: [Internal] Reviewed By: javache, sammy-SC Differential Revision: D110187712 fbshipit-source-id: 3e76c498ae04b8b1ce9e0e27e5ce6b6a0cd11e09
This commit is contained in:
1 parent
d9d2502b61
commit
2bb7dbb499
17 files changed
+1687
-33
No files matched your search
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
set -e
|
||||
|
||||
if [[ -f "BUCK" && -z "$FANTOM_FORCE_OSS_BUILD" ]]; then
|
||||
export JS_DIR='..'
|
||||
else
|
||||
if [[ ! -f "private/react-native-fantom/build/tester/fantom_tester" ]]; then
|
||||
yarn workspace @react-native/fantom build
|
||||
fi
|
||||
export FANTOM_FORCE_OSS_BUILD=1
|
||||
fi
|
||||
|
||||
# Match the heap headroom used by `fantom.sh` for the in-process Metro server.
|
||||
export NODE_OPTIONS='--max-old-space-size=16384'
|
||||
|
||||
node private/react-native-fantom/repl/index.js "$@"
|
||||
Reference in new issue
Block a user