-
Notifications
You must be signed in to change notification settings - Fork 928
Description
Background
I'm actively working on preparing a react-native monorepo template with enabled hoisting.
I've everything working besides one thing.
When I'm running react-native run-android
packager is starting from monorepo root(./
) instead of app package ./apps/app
I can workaround it by running packager upfront but I would love to have that template working without such workarounds.
Findings
I've dived deeply into how I can work around it and figured out that there is no option to solve that without patching react-native
.
Why is that?
Current flow
Currently running packager for run-android
is working the following way:
- CLI is calling startServerInNewWindow
startServerInNewWindow
- is overriding
.packager.env
- and is calling lauchPackager.sh
- is overriding
lauchPackager.sh
is calling packager.shpackager.sh
is callingreact-native start
fromPROJECT_ROOT
which is statically set to the path relative tonode_modules/react-native
Why is that a problem?
-
Currently the simplest option to change
PROJECT_ROOT
from CLI perspective is to overwritePROJECT_ROOT
environment variable inside.packager.env
- In the currently released react-native 0.71
packager.sh
is always overwritingPROJECT_ROOT
path with a path relative to the script location. - In future version(react-native master) there it accepts
PROJECT_ROOT
from outside. - Sadly there is still this condition that will overwrite this path because in monorepo we have hoisting so the react-native package is located in monorepo root instead
PROJECT_ROOT
- In the currently released react-native 0.71
-
Generally configuration of
react-native start
fromCLI
perspective is limited.
It seems thatpackager.sh
accepts additional arguments (with"$@"
at the end) that will be forwarded toreact-native start
.
HoweverlaunchPackager.command
is not forwarding it fromCLI
Question
-
I'm curious what is the story behind this solution where
CLI
have to callreact-native internal script
that will callCLI
.
Maybe there is someone who has some background on this one? -
Is this script treated internally in react-native as something that should be used by the community?
This question is based on this comment insidepackager.sh
that sounds like it is something for internal react-native testing. -
If this is something that should be used by the community then I'm wondering if there is a way to make it more configurable from a
CLI
perspective.
Reproducible demo:
- clone repo https://github.com/MateWW/react-native-new-arch-monorepo
- install dependencies
- make sure you have packager running
- trigger
yarn android
(doesn't matter if you will do that from app directory or root)