-
Notifications
You must be signed in to change notification settings - Fork 935
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.shis calling packager.shpackager.shis callingreact-native startfromPROJECT_ROOTwhich is statically set to the path relative tonode_modules/react-native
Why is that a problem?
-
Currently the simplest option to change
PROJECT_ROOTfrom CLI perspective is to overwritePROJECT_ROOTenvironment variable inside.packager.env- In the currently released react-native 0.71
packager.shis always overwritingPROJECT_ROOTpath with a path relative to the script location. - In future version(react-native master) there it accepts
PROJECT_ROOTfrom 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 startfromCLIperspective is limited.
It seems thatpackager.shaccepts additional arguments (with"$@"at the end) that will be forwarded toreact-native start.
HoweverlaunchPackager.commandis not forwarding it fromCLI
Question
-
I'm curious what is the story behind this solution where
CLIhave to callreact-native internal scriptthat 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.shthat 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
CLIperspective.
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)