Skip to content

Commit 4f3561d

Browse files
gag0712trevor-yang
andauthored
feature: check hermesc path for react native 0.83 (#108)
Co-authored-by: trevor.yang <[email protected]>
1 parent ed5ae51 commit 4f3561d

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

cli/functions/runHermesEmitBinaryCommand.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,20 @@ function getHermesCommand(): string {
114114
return false;
115115
}
116116
};
117+
const reactNativePath = getReactNativePackagePath();
118+
const hermesCompilerPath = getHermesCompilerPackagePath();
119+
120+
// Since react-native 0.83, Hermes compiler in 'hermes-compiler' package
121+
if (hermesCompilerPath) {
122+
const engine = path.join(hermesCompilerPath, 'hermesc', getHermesOSBin(), getHermesOSExe());
123+
if (fileExists(engine)) {
124+
return engine;
125+
}
126+
}
127+
128+
// Hermes is bundled with react-native since 0.69
129+
const bundledHermesEngine = path.join(reactNativePath, 'sdks', 'hermesc', getHermesOSBin(), getHermesOSExe());
117130
// Hermes is bundled with react-native since 0.69
118-
const bundledHermesEngine = path.join(
119-
getReactNativePackagePath(),
120-
'sdks',
121-
'hermesc',
122-
getHermesOSBin(),
123-
getHermesOSExe(),
124-
);
125131
if (fileExists(bundledHermesEngine)) {
126132
return bundledHermesEngine;
127133
}
@@ -174,6 +180,22 @@ function getReactNativePackagePath(): string {
174180
return path.join('node_modules', 'react-native');
175181
}
176182

183+
function getHermesCompilerPackagePath() {
184+
try {
185+
const result = childProcess.spawnSync('node', [
186+
'--print',
187+
"require.resolve('hermes-compiler/package.json')",
188+
]);
189+
const packagePath = path.dirname(result.stdout.toString());
190+
if (result.status === 0 && directoryExistsSync(packagePath)) {
191+
return packagePath;
192+
}
193+
return path.join('node_modules', 'hermes-compiler');
194+
} catch {
195+
return null;
196+
}
197+
}
198+
177199
function directoryExistsSync(dirname: string): boolean {
178200
try {
179201
return fs.statSync(dirname).isDirectory();

0 commit comments

Comments
 (0)