Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cuddly-months-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Fix hermes-compiler path for RN 0.82+ in the hermes bytecode plugin
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';

Expand All @@ -20,7 +21,7 @@ const getHermesOSBin = (): string | null => {
/**
* Determines the path to the Hermes compiler binary.
*
* Defaults to './node_modules/react-native/sdks/hermesc/{os-bin}/hermesc'
* Defaults to './node_modules/hermes-compiler/hermesc/{os-bin}/hermesc'
*/
export const getHermesCLIPath = (reactNativePath: string): string => {
const osBin = getHermesOSBin();
Expand All @@ -32,5 +33,19 @@ export const getHermesCLIPath = (reactNativePath: string): string => {
);
}

const hermesCompilerPath = path.join(
reactNativePath,
'..',
'hermes-compiler',
'hermesc',
osBin,
'hermesc'
);

if (fs.existsSync(hermesCompilerPath)) {
return hermesCompilerPath;
}

// Fallback to the previous hermesc path in older react native versions, <0.82.
return path.join(reactNativePath, 'sdks', 'hermesc', osBin, 'hermesc');
};
29 changes: 29 additions & 0 deletions packages/repack/src/plugins/__tests__/HermesBytecodePlugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import fs from 'node:fs';
import os from 'node:os';
import { type Compiler, ModuleFilenameHelpers } from '@rspack/core';
import execa from 'execa';
import { HermesBytecodePlugin } from '../HermesBytecodePlugin/index.js';
import { getHermesCLIPath } from '../HermesBytecodePlugin/utils/getHermesCLIPath.js';

jest.mock('node:fs', () => ({
__esModule: true,
default: {
existsSync: jest.fn(),
promises: {
access: jest.fn(),
rename: jest.fn(),
Expand Down Expand Up @@ -142,4 +145,30 @@ describe('HermesBytecodePlugin', () => {
expect(execaMock.mock.calls[0][0]).toEqual('path/to/hermesc');
});
});

describe('getHermesCLIPath', () => {
const reactNativePath = 'path/to/react-native';

it('returns new hermes-compiler path when it exists', () => {
jest.spyOn(os, 'platform').mockReturnValue('darwin');
jest.mocked(fs.existsSync).mockReturnValue(true);

const hermesPath = getHermesCLIPath(reactNativePath);

expect(hermesPath).toBe(
'path/to/hermes-compiler/hermesc/osx-bin/hermesc'
);
});

it('falls back to legacy hermesc path when hermes-compiler does not exist', () => {
jest.spyOn(os, 'platform').mockReturnValue('darwin');
jest.mocked(fs.existsSync).mockReturnValue(false);

const hermesPath = getHermesCLIPath(reactNativePath);

expect(hermesPath).toBe(
'path/to/react-native/sdks/hermesc/osx-bin/hermesc'
);
});
});
});