Skip to content

Support vendoring Hermes for out-of-tree platforms #270

Description

@shirakaba

Currently, we look up the appropriate version of hermes from react-native like so:

const appPackageRoot = packageDirectorySync({ cwd: from });
assert(appPackageRoot, "Failed to find package root");
const reactNativePath = path.dirname(
require.resolve("react-native/package.json", {
// Ensures we'll be patching the React Native package actually used by the app
paths: [appPackageRoot],
}),
);

For out-of-tree platforms like react-native-macos, though, I had to apply the following patch before it'd resolve the correct root during pod install:

let reactNativePath;
if(from.endsWith("ios") || from.endsWith("android")){
  reactNativePath = node_path_1.default.dirname(require.resolve("react-native/package.json", {
      // Ensures we'll be patching the React Native package actually used by the app
      paths: [appPackageRoot],
  }));
} else if(from.endsWith("macos")){
  reactNativePath = node_path_1.default.dirname(require.resolve("react-native-macos/package.json", {
      // Ensures we'll be patching the React Native package actually used by the app
      paths: [appPackageRoot],
  }));
} else if(from.endsWith("windows")){
  reactNativePath = node_path_1.default.dirname(require.resolve("react-native-windows/package.json", {
      // Ensures we'll be patching the React Native package actually used by the app
      paths: [appPackageRoot],
  }));
} else {
  throw new Error("Unsupported platform.");
}

There is surely a more elegant way to do it (it would be nicest to know the platform for certain, rather than just guessing based on the presence of an ios/android/macos folder in the path), but just to illustrate the point.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions