react-native-code-push
react-native-code-push copied to clipboard
gradle calculation of nodeModulesPath is poorly prioritized
If you specify a project root AND nodeModulesPath in your app/build.gradle, the nodeModulesPath is ignored, and the assumed root/node_modules is used. Instead, the more specific nodeModulesPath config should be used. I have not checked if an analogous problem exists in iOS
Steps to Reproduce
- Set up 2 react native projects in a monorepo at
monorepoRoot/packages/appA
andmonorepoRoot/packages/appB
- Fix hoisting so that react-native-code-push is installed at
monorepoRoot/node_modules/react-native-code-push
- Set values for
root
andnodeModulesPath
config.ext.react, e.g.
project.ext.react = [
entryFile: "index.js",
enableHermes: false, // clean and rebuild if changing
root: "../..",
cliPath: "../../node_modules/react-native/cli.js"
]
project.ext.nodeModulesPath = "../../../../node_modules"
Expected Behavior
I would expect for the nodeModulesPath used by codepush to be ../../../../node_modules
, which means the cli for bundling appA for example calls out to monorepoRoot/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js
Actual Behavior
the nodeModulesPath used by codepush ends up as ../../node_modules
which means the lie for bundling appA calls out to
monorepoRoot/packages/appA/node_modules/react-native-code-push/scripts/generateBundledResourcesHash.js
Proposed solution
I have not yet tested this deeply, but I unless pathing is an issue somewhere I am not seeing, we can reorder the calculation if statements to allow nodeModulesPath to take priority. Existing code (from codepush.gradle):
def nodeModulesPath;
if (config.root) {
nodeModulesPath = Paths.get(config.root, "/node_modules");
} else if (project.hasProperty('nodeModulesPath')) {
nodeModulesPath = project.nodeModulesPath
} else {
nodeModulesPath = "../../node_modules";
}
Proposed change:
def nodeModulesPath;
if (project.hasProperty('nodeModulesPath')) {
nodeModulesPath = project.nodeModulesPath
} else if (config.root) {
nodeModulesPath = Paths.get(config.root, "/node_modules");
} else else {
nodeModulesPath = "../../node_modules";
}
Reproducible Demo
I'll work on getting one set up.
Environment
- react-native-code-push version: 6.2.1
- react-native version: 0.61.4
- From inside appA for example you can run
android/gradlew assembleRelease -p android/
I will continue to test more thoroughly and can submit an MR if that works. Tangentially related issue for other react-native issues around the same project structure: https://github.com/react-native-community/cli/issues/826
Hi @maxkorp , Thanks for reporting and so detailed description! It is a good catch!
Please let us know results of testing your approach. And a demo app also will be helpful to investigate. Thanks!
So far everything seems to work! As far as testing, I'm simply building a "release" app for android with an odd version number for a different channel, and pushing up a codepush update. I've simply edited codepush.gradle
after installing my node_modules with yarn. Packaging via android/gradlew assembleRelease -p android/
works with changes but not without.
I'll get a working (not working? broken?) example repo up today for you!
https://github.com/maxkorp/codepush-monorepo-example
I left populating keys to you, you can just text search for <INSERT_STAGING_KEY>
and <INSERT_PRODUCTION_KEY>
for both android and ios
There is a script you can run at the root, ./fix-gradle.js
to patch the gradle file, and you can restore it to original with fix-gradle.js break
Cool! Thanks for so many details and demo project! We will test it soon and let you know our results. We will keep you posted.
Anything I can do to help out with this? I've got a bit more testing to do, but that fix script works for me locally, so I'd be happy to submit a PR with the change if you're open to it.
@alexandergoncharov Friendly ping to help move this along. Issue is preventing us from releasing with codepush integrated.
This worked for me just by adding the project.ext.nodeModulesPath = "../../../../node_modules"
to my app/build.gradle
Can now build app in a monorepo with all packages hoisted to the root.