Skip to content

Commit c72970f

Browse files
authored
Check for REACT_NATIVE_OVERRIDE_HERMES_DIR earlier (#246)
* Move REACT_NATIVE_OVERRIDE_HERMES_DIR out of tasks to fail earlier * Fix tests
1 parent 633dc34 commit c72970f

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

.changeset/red-candles-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-node-api": patch
3+
---
4+
5+
Move REACT_NATIVE_OVERRIDE_HERMES_DIR out of tasks to fail earlier

packages/host/android/build.gradle

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import java.nio.file.Paths
22
import groovy.json.JsonSlurper
33
import org.gradle.internal.os.OperatingSystem
44

5+
if (!System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR")) {
6+
throw new GradleException([
7+
"React Native Node-API needs a custom version of Hermes with Node-API enabled.",
8+
"Run the following in your terminal, to clone Hermes and instruct React Native to use it:",
9+
"",
10+
"export REACT_NATIVE_OVERRIDE_HERMES_DIR=\$(npx react-native-node-api vendor-hermes --silent --force)",
11+
"",
12+
"And follow this guide to build React Native from source:",
13+
"https://reactnative.dev/contributing/how-to-build-from-source#update-your-project-to-build-from-source"
14+
].join('\n'))
15+
}
16+
517
buildscript {
618
ext.getExtOrDefault = {name ->
719
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['NodeApiModules_' + name]
@@ -135,22 +147,6 @@ dependencies {
135147
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
136148
}
137149

138-
task checkHermesOverride {
139-
doFirst {
140-
if (!System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR")) {
141-
throw new GradleException([
142-
"React Native Node-API needs a custom version of Hermes with Node-API enabled.",
143-
"Run the following in your terminal, to clone Hermes and instruct React Native to use it:",
144-
"",
145-
"export REACT_NATIVE_OVERRIDE_HERMES_DIR=\$(npx react-native-node-api vendor-hermes --silent --force)",
146-
"",
147-
"And follow this guide to build React Native from source:",
148-
"https://reactnative.dev/contributing/how-to-build-from-source#update-your-project-to-build-from-source"
149-
].join('\n'))
150-
}
151-
}
152-
}
153-
154150
def commandLinePrefix = OperatingSystem.current().isWindows() ? ["cmd", "/c", "node"] : []
155151
def cliPath = file("../bin/react-native-node-api.mjs")
156152

@@ -169,5 +165,5 @@ task linkNodeApiModules {
169165
}
170166
}
171167

172-
preBuild.dependsOn checkHermesOverride, linkNodeApiModules
168+
preBuild.dependsOn linkNodeApiModules
173169

packages/host/src/node/gradle.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ describe(
1212
// Skipping these tests by default, as they download a lot and takes a long time
1313
{ skip: process.env.ENABLE_GRADLE_TESTS !== "true" },
1414
() => {
15-
describe("checkHermesOverride task", () => {
15+
describe("linkNodeApiModules task", () => {
1616
it("should fail if REACT_NATIVE_OVERRIDE_HERMES_DIR is not set", () => {
1717
const { status, stdout, stderr } = cp.spawnSync(
1818
"sh",
19-
["gradlew", "react-native-node-api:checkHermesOverride"],
19+
["gradlew", "react-native-node-api:linkNodeApiModules"],
2020
{
2121
cwd: TEST_APP_ANDROID_PATH,
2222
env: {
@@ -45,15 +45,18 @@ describe(
4545
/And follow this guide to build React Native from source/,
4646
);
4747
});
48-
});
4948

50-
describe("linkNodeApiModules task", () => {
5149
it("should call the CLI to autolink", () => {
5250
const { status, stdout, stderr } = cp.spawnSync(
5351
"sh",
5452
["gradlew", "react-native-node-api:linkNodeApiModules"],
5553
{
5654
cwd: TEST_APP_ANDROID_PATH,
55+
env: {
56+
...process.env,
57+
// We're passing some directory which exists
58+
REACT_NATIVE_OVERRIDE_HERMES_DIR: __dirname,
59+
},
5760
encoding: "utf-8",
5861
},
5962
);

0 commit comments

Comments
 (0)