Skip to content

Commit f9a3ea6

Browse files
committed
Make the reactNativeDir resolve from the app package root
1 parent 08e959c commit f9a3ea6

File tree

1 file changed

+23
-8
lines changed
  • packages/react-native-node-api-modules/src/node/cli

1 file changed

+23
-8
lines changed

packages/react-native-node-api-modules/src/node/cli/hermes.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { spawn, SpawnFailure } from "bufout";
77
import { oraPromise } from "ora";
88
import { packageDirectorySync } from "pkg-dir";
99

10-
import { prettyPath } from "../path-utils";
10+
import { getLatestMtime, prettyPath } from "../path-utils";
1111

12+
const HOST_PACKAGE_ROOT = path.resolve(__dirname, "../../..");
1213
const HERMES_GIT_URL = "https://github.com/kraenhansen/hermes.git";
1314
const HERMES_GIT_TAG = "node-api-for-react-native-0.79.0";
1415
const REACT_NATIVE_DIR = path.dirname(
@@ -65,14 +66,28 @@ export const command = new Command("vendor-hermes")
6566
isEnabled: !silent,
6667
}
6768
);
69+
}
70+
const hermesJsiPath = path.join(hermesPath, "API/jsi/jsi");
71+
const reactNativePath = path.dirname(
72+
require.resolve("react-native/package.json", {
73+
// Ensures we'll be patching the React Native package actually used by the app
74+
paths: [appPackageRoot],
75+
})
76+
);
77+
const reactNativeJsiPath = path.join(
78+
reactNativePath,
79+
"ReactCommon/jsi/jsi/"
80+
);
81+
82+
if (
83+
fs.existsSync(reactNativeJsiPath) &&
84+
(force ||
85+
getLatestMtime(hermesJsiPath) > getLatestMtime(reactNativeJsiPath))
86+
) {
6887
await oraPromise(
69-
fs.promises.cp(
70-
path.join(hermesPath, "API/jsi/jsi"),
71-
path.join(REACT_NATIVE_DIR, "ReactCommon/jsi/jsi/"),
72-
{
73-
recursive: true,
74-
}
75-
),
88+
fs.promises.cp(hermesJsiPath, reactNativeJsiPath, {
89+
recursive: true,
90+
}),
7691
{
7792
text: `Copying JSI from Hermes to React Native`,
7893
successText: "Copied JSI from Hermes to React Native",

0 commit comments

Comments
 (0)