Skip to content

Commit d47ee08

Browse files
committed
Add --react-native-package option to "vendor-hermes" command
1 parent 2ddc21d commit d47ee08

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

.changeset/chatty-states-build.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+
Add --react-native-package option to "vendor-hermes" command, allowing caller to choose the package to download hermes into

packages/host/src/node/cli/hermes.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ import path from "node:path";
55
import {
66
chalk,
77
Command,
8+
Option,
89
oraPromise,
910
spawn,
1011
UsageError,
1112
wrapAction,
1213
prettyPath,
1314
} from "@react-native-node-api/cli-utils";
14-
import { packageDirectorySync } from "pkg-dir";
15+
import { packageDirectory } from "pkg-dir";
16+
import { readPackage } from "read-pkg";
1517

16-
const HOST_PACKAGE_ROOT = path.resolve(__dirname, "../../..");
1718
// FIXME: make this configurable with reasonable fallback before public release
1819
const HERMES_GIT_URL = "https://github.com/kraenhansen/hermes.git";
1920

21+
const platformOption = new Option(
22+
"--react-native-package <package-name>",
23+
"The React Native package to vendor Hermes into",
24+
).default("react-native");
25+
2026
export const command = new Command("vendor-hermes")
2127
.argument("[from]", "Path to a file inside the app package", process.cwd())
2228
.option("--silent", "Don't print anything except the final path", false)
@@ -25,12 +31,20 @@ export const command = new Command("vendor-hermes")
2531
"Don't check timestamps of input files to skip unnecessary rebuilds",
2632
false,
2733
)
34+
.addOption(platformOption)
2835
.action(
29-
wrapAction(async (from, { force, silent }) => {
30-
const appPackageRoot = packageDirectorySync({ cwd: from });
36+
wrapAction(async (from, { force, silent, reactNativePackage }) => {
37+
const appPackageRoot = await packageDirectory({ cwd: from });
3138
assert(appPackageRoot, "Failed to find package root");
39+
40+
const { dependencies = {} } = await readPackage({ cwd: appPackageRoot });
41+
assert(
42+
Object.keys(dependencies).includes(reactNativePackage),
43+
`Expected app to have a dependency on the '${reactNativePackage}' package`,
44+
);
45+
3246
const reactNativePath = path.dirname(
33-
require.resolve("react-native/package.json", {
47+
require.resolve(reactNativePackage + "/package.json", {
3448
// Ensures we'll be patching the React Native package actually used by the app
3549
paths: [appPackageRoot],
3650
}),
@@ -40,6 +54,11 @@ export const command = new Command("vendor-hermes")
4054
"sdks",
4155
".hermesversion",
4256
);
57+
assert(
58+
fs.existsSync(hermesVersionPath),
59+
`Expected a file with a Hermes version at ${prettyPath(hermesVersionPath)}`,
60+
);
61+
4362
const hermesVersion = fs.readFileSync(hermesVersionPath, "utf8").trim();
4463
if (!silent) {
4564
console.log(`Using Hermes version: ${hermesVersion}`);
@@ -50,7 +69,7 @@ export const command = new Command("vendor-hermes")
5069
"ReactCommon/jsi/jsi/",
5170
);
5271

53-
const hermesPath = path.join(HOST_PACKAGE_ROOT, "hermes");
72+
const hermesPath = path.join(reactNativePath, "sdks", "node-api-hermes");
5473
if (force && fs.existsSync(hermesPath)) {
5574
await oraPromise(
5675
fs.promises.rm(hermesPath, { recursive: true, force: true }),

0 commit comments

Comments
 (0)