@@ -12,7 +12,6 @@ import { prettyPath } from "../path-utils";
12
12
const HOST_PACKAGE_ROOT = path . resolve ( __dirname , "../../.." ) ;
13
13
// FIXME: make this configurable with reasonable fallback before public release
14
14
const HERMES_GIT_URL = "https://github.com/kraenhansen/hermes.git" ;
15
- const HERMES_GIT_TAG = "node-api-for-react-native-0.79.0" ;
16
15
17
16
export const command = new Command ( "vendor-hermes" )
18
17
. argument ( "[from]" , "Path to a file inside the app package" , process . cwd ( ) )
@@ -26,6 +25,27 @@ export const command = new Command("vendor-hermes")
26
25
try {
27
26
const appPackageRoot = packageDirectorySync ( { cwd : from } ) ;
28
27
assert ( appPackageRoot , "Failed to find package root" ) ;
28
+ const reactNativePath = path . dirname (
29
+ require . resolve ( "react-native/package.json" , {
30
+ // Ensures we'll be patching the React Native package actually used by the app
31
+ paths : [ appPackageRoot ] ,
32
+ } )
33
+ ) ;
34
+ const hermesVersionPath = path . join (
35
+ reactNativePath ,
36
+ "sdks" ,
37
+ ".hermesversion"
38
+ ) ;
39
+ const hermesVersion = fs . readFileSync ( hermesVersionPath , "utf8" ) . trim ( ) ;
40
+ if ( ! silent ) {
41
+ console . log ( `Using Hermes version: ${ hermesVersion } ` ) ;
42
+ }
43
+
44
+ const reactNativeJsiPath = path . join (
45
+ reactNativePath ,
46
+ "ReactCommon/jsi/jsi/"
47
+ ) ;
48
+
29
49
const hermesPath = path . join ( HOST_PACKAGE_ROOT , "hermes" ) ;
30
50
if ( force && fs . existsSync ( hermesPath ) ) {
31
51
await oraPromise (
@@ -40,42 +60,48 @@ export const command = new Command("vendor-hermes")
40
60
) ;
41
61
}
42
62
if ( ! fs . existsSync ( hermesPath ) ) {
43
- await oraPromise (
44
- spawn (
45
- "git" ,
46
- [
47
- "clone" ,
48
- "--recursive" ,
49
- "--depth" ,
50
- "1" ,
51
- "--branch" ,
52
- HERMES_GIT_TAG ,
53
- HERMES_GIT_URL ,
54
- hermesPath ,
55
- ] ,
63
+ const patchedTag = `node-api-${ hermesVersion } ` ;
64
+ try {
65
+ await oraPromise (
66
+ spawn (
67
+ "git" ,
68
+ [
69
+ "clone" ,
70
+ "--recursive" ,
71
+ "--depth" ,
72
+ "1" ,
73
+ "--branch" ,
74
+ patchedTag ,
75
+ HERMES_GIT_URL ,
76
+ hermesPath ,
77
+ ] ,
78
+ {
79
+ outputMode : "buffered" ,
80
+ }
81
+ ) ,
56
82
{
57
- outputMode : "buffered" ,
83
+ text : `Cloning custom Hermes into ${ prettyPath ( hermesPath ) } ` ,
84
+ successText : "Cloned custom Hermes" ,
85
+ failText : ( err ) =>
86
+ `Failed to clone custom Hermes: ${ err . message } ` ,
87
+ isEnabled : ! silent ,
58
88
}
59
- ) ,
60
- {
61
- text : `Cloning custom Hermes into ${ prettyPath ( hermesPath ) } ` ,
62
- successText : "Cloned custom Hermes" ,
63
- failText : ( err ) => `Failed to clone custom Hermes: ${ err . message } ` ,
64
- isEnabled : ! silent ,
89
+ ) ;
90
+ } catch ( error ) {
91
+ if ( error instanceof SpawnFailure ) {
92
+ error . flushOutput ( "both" ) ;
93
+ console . error (
94
+ `\n🛑 React Native uses the ${ hermesVersion } tag and cloning our fork failed.` ,
95
+ `Please see the Node-API package's peer dependency on "react-native" for supported versions.`
96
+ ) ;
97
+ process . exitCode = 1 ;
98
+ return ;
99
+ } else {
100
+ throw error ;
65
101
}
66
- ) ;
102
+ }
67
103
}
68
104
const hermesJsiPath = path . join ( hermesPath , "API/jsi/jsi" ) ;
69
- const reactNativePath = path . dirname (
70
- require . resolve ( "react-native/package.json" , {
71
- // Ensures we'll be patching the React Native package actually used by the app
72
- paths : [ appPackageRoot ] ,
73
- } )
74
- ) ;
75
- const reactNativeJsiPath = path . join (
76
- reactNativePath ,
77
- "ReactCommon/jsi/jsi/"
78
- ) ;
79
105
80
106
assert (
81
107
fs . existsSync ( hermesJsiPath ) ,
@@ -96,6 +122,7 @@ export const command = new Command("vendor-hermes")
96
122
) ;
97
123
console . log ( hermesPath ) ;
98
124
} catch ( error ) {
125
+ process . exitCode = 1 ;
99
126
if ( error instanceof SpawnFailure ) {
100
127
error . flushOutput ( "both" ) ;
101
128
}
0 commit comments