-
Notifications
You must be signed in to change notification settings - Fork 904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: run npx from JS app dir #824
Conversation
def npx = Os.isFamily(Os.FAMILY_WINDOWS) ? "npx.cmd" : "npx" | ||
def command = "${npx} --quiet react-native config" | ||
def command = "${npx} --quiet --no-install react-native config" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding --no-install
so we don't accidentally install react-native
into local npm cache. Verified that it's already present in npx shipped with Node 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it related to #823?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really sure, but it's preferable to run with --no-install
anyway. Feel free to send a PR, as I don't want to mix iOS and Android in this one :)
I applied these changes inside node_modules and I"m still seeing an issue, it's no longer the same one pointed out in #793. Here is a gist of the error outputted by Gradle |
@AndreiCalazans it's a normal project structure, in terms of running from Android Studio. I'll need you to debug this a little deeper, as Gradle sync and build works on my machine. This is likely an environmental issue I cannot reproduce. |
How about simple heuristics here: if |
I'm not sure how to access the -p value. Cc @Salakar |
Afaik it's not possible to read this. Only properties passed via |
In my testing, a |
As far as I know, module scope is better because Gradle can run task in
separate thread with different env variables and current dir.
…On Tue, Nov 5, 2019, 23:04 Mike Grabowski ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In packages/platform-android/native_modules.gradle
<#824 (comment)>
:
> this.logger = logger
+ this.jsAppDir = jsAppDir
Is this.jsAppDir needed or can be a module variable? (Gradle newbie here)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#824?email_source=notifications&email_token=AEB3SYJH4V35E53Q3IUEGITQSGKSLA5CNFSM4JEVRO22YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCKK74WA#pullrequestreview-311819864>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEB3SYLDO34SK333R3XR4MLQSGKSLANCNFSM4JEVRO2Q>
.
|
4ab5666
to
65e2275
Compare
Bump Looking forward to v3 |
Do we know why the Windows CI is failing? It's blocking few important PRs that are good to be merged otherwise. I'd ship them all if that's not the case. |
@@ -2,6 +2,7 @@ import groovy.json.JsonSlurper | |||
import org.gradle.initialization.DefaultSettings | |||
import org.apache.tools.ant.taskdefs.condition.Os | |||
|
|||
def jsAppDir = buildscript.sourceFile.toString().split("node_modules/@react-native-community/cli-platform-android/native_modules.gradle")[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we can just split by node_modules/@react-native-community/cli-platform-android
, which is a path to the module (the gradle file at the end is not needed and may break if we refactor files).
I was thinking to go with node_modules
, but that would break in case dependencies were not hoisted.
ArrayList<HashMap<String, String>> reactNativeModules = new ArrayList<HashMap<String, String>>() | ||
def npx = Os.isFamily(Os.FAMILY_WINDOWS) ? "npx.cmd" : "npx" | ||
def command = "${npx} --quiet --no-install react-native config" | ||
// Running npx from the directory of the JS app which holds this script in its node_modules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: blank space before comment and prefer /* */
?
nit: I'd rephrase the comment a bit to explain when such a case happens, in other words, when it's run with a -p
flag. We can also link to this PR for further ref.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for keeping this clean. Left few commits and let's ship it.
829a685
to
a978a53
Compare
I believe this has broken projects running in a monorepo as the react-native config needs to be run in the package directory, however is now running in the root directory as the node_module dependencies are hoisted. |
@mbios could you provide a repro we could investigate? |
yields this:
but works without removing the yarn.lock as that points to 3.0.0 alpha |
Yep, it's a regression, thanks for noticing! |
Summary:
Gradle may be run from a driectory that's outside of JS project, with a passed project dir (through
-p
flag) likepath/to/app/android/gradlew bundleRelease -p ../app/android/app
.Gradle CWD is usually (maybe always, but they don't give guarantees) set to the directory where it's ran from. This tricks
npx
, which doesn't know where to findreact-native
binary. To account for it, we can spawnnpx
with a CWD passed to it. We don't need an exact path to android project directory, path to the project which holds@react-native-community/cli
in node_modules is just fine with current config search mechanism.I'm not 100% sure about this fix, open for discussion.
Fixes #793
Fixes #804
Test Plan:
I don't have an automated test for this, you'll need to verify on repro provided in #793.