Skip to content

Commit e6da2e5

Browse files
authored
Document Flow libdefs for npm packages in AGENTS.md
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory. --> ## Summary Motivated by #59316. Changelog: [Internal] ## Test Plan ``` yarn prettier --check AGENTS.md ``` ✅ Clean. Documentation only. Differential Revision: D128379539 Pull Request resolved: #59621
1 parent f78bdd4 commit e6da2e5

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎AGENTS.md‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ JavaScript CI is the `lint`, `test_js`, and `build_js_types` jobs in [`.github/w
4343

4444
The formatting command uses pinned npm packages for Kotlin and Java and installs pinned Ruff through Python. To format every language, install a JDK with Java 17 or newer, Python 3 with pip, and a Swift 6.3 or newer toolchain in addition to Node and Yarn. Each language wrapper checks its own requirements and prints installation guidance when something is missing; `yarn format` then skips that language and continues formatting the others. Swift formatting accepts either `swift-format` or `swift format` from the installed toolchain.
4545

46-
### Verification: Running RNTester
47-
48-
Needed only for changes that have to be seen running, such as user interface behavior.
49-
50-
`yarn start` serves [RNTester](packages/rn-tester/README.md) over Metro at `http://localhost:8081`; `yarn android` builds and installs it on Android. Check the bundler with `curl "http://localhost:8081/js/RNTesterApp.bundle?platform=ios&dev=true"`.
51-
5246
## Gotchas
5347

5448
- `yarn install` dirties the working tree: a `preinstall` hook (`scripts/try-set-hermes-compiler-prebuilt.js`) resolves the `hermes-compiler` placeholder in `packages/react-native/package.json` (`0.0.0` → a real version) and touches `yarn.lock`. Expected — do not commit it.
5549
- Metro cannot bundle until codegen is built once — `yarn --cwd packages/react-native-codegen build`. Without it, bundling fails with `Cannot find module '@react-native/codegen/lib/parsers/flow/parser'`. Every other package runs from source — `yarn build` is not needed for development (see [`scripts/build/README.md`](scripts/build/README.md)).
5650

51+
## Verification: Running RNTester
52+
53+
Needed only for changes that have to be seen running, such as user interface behavior.
54+
55+
`yarn start` serves [RNTester](packages/rn-tester/README.md) over Metro at `http://localhost:8081`; `yarn android` builds and installs it on Android. Check the bundler with `curl "http://localhost:8081/js/RNTesterApp.bundle?platform=ios&dev=true"`.
56+
5757
## Generated code
5858

5959
Never hand-edit generated output — change the source and regenerate. CI validates the committed snapshots.
@@ -64,6 +64,14 @@ Never hand-edit generated output — change the source and regenerate. CI valida
6464
- The public native API is snapshotted as well: C++ under `scripts/cxx-api` (`yarn cxx-api-build`), and Android in `packages/react-native/ReactAndroid/api/ReactAndroid.api`.
6565
- `CHANGELOG.md` is compiled at release time from pull request descriptions.
6666

67+
## Flow types for npm packages
68+
69+
`node_modules` is a `[declarations]` path in `.flowconfig`: Flow reads a package's own Flow types when it ships them (`metro` does), and otherwise the import is untyped, which `@flow strict` and `strict-local` files reject with `untyped-import`. A package used from Flow source for the first time needs a libdef in `flow-typed/npm/`, which overrides anything in `node_modules`:
70+
71+
- Name it `<package>_v<major>.x.x.js` for the major in `package.json`, under `@<scope>/` for a scoped package.
72+
- Copy the shape of a neighbor: the license header, `@flow strict`, and `declare module '<package>' { … }` with `declare module.exports` or `declare export`. Declare only the surface the repo calls, typed as the package documents it, never `any`.
73+
- Check with `yarn flow-check`, and drop the libdef with the last use of the package.
74+
6775
## Contributing guidelines
6876

6977
- Keep each change focused — no unrelated refactors, formatting, or dependency updates.

0 commit comments

Comments
 (0)