Skip to content

Commit

Permalink
[CLI] Support Hermes (#5)
Browse files Browse the repository at this point in the history
This PR adds support of Hermes for the code-push cli.
It will try checking if hermes is enabled in the build.gradle or Podfile
and run the hermes compiler if it is enabled.
  • Loading branch information
DmitriyKirakosyan authored and lucen-ms committed Oct 17, 2024
1 parent 84d2d10 commit 7e9503e
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 8 deletions.
21 changes: 21 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ code-push-standalone release-react <appName> <platform>
[--sourcemapOutput <sourcemapOutput>]
[--targetBinaryVersion <targetBinaryVersion>]
[--rollout <rolloutPercentage>]
[--useHermes <useHermes>]
[--podFile <podFile>]
[--extraHermesFlags <extraHermesFlags>]
```

The `release-react` command is a React Native-specific version of the "vanilla" [`release`](#releasing-app-updates) command, which supports all of the same parameters (e.g. `--mandatory`, `--description`), yet simplifies the process of releasing updates by performing the following additional behavior:
Expand Down Expand Up @@ -521,6 +524,24 @@ This specifies the relative path to where the assets, JS bundle and sourcemap fi

_NOTE: This parameter can be set using either --outputDir or -o_

#### Use Hermes parameter

This parameter enforces the use of the Hermes compiler. If not specified, the automatic checks will be performed, inspecting the `build.gradle` and `Podfile` for the Hermes flag.

_NOTE: This parameter can be set using either --hermesEnabled or -h_

#### Podfile parameter (iOS only)

The Podfile path will be used for Hermes automatic check. Not used if `--useHermes` is specified.

_NOTE: This parameter can be set using either --podfile or -pod_

#### Extra hermes flags parameter

Hermes flags which will be passed to Hermes compiler.

_NOTE: This parameter can be set using either --extraHermesFlags or -hf_

## Debugging CodePush Integration

Once you've released an update, React Native plugin has been integrated into your app, it can be helpful to diagnose how the plugin is behaving, especially if you run into an issue and want to understand why. In order to debug the CodePush update discovery experience, you can run the following command in order to easily view the diagnostic logs produced by the CodePush plugin within your app:
Expand Down
32 changes: 24 additions & 8 deletions cli/script/command-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ import {
Session,
UpdateMetrics,
} from "../script/types";
import {
fileDoesNotExistOrIsDirectory,
getAndroidHermesEnabled,
getiOSHermesEnabled,
runHermesEmitBinaryCommand
} from "./react-native-utils";

const configFilePath: string = path.join(process.env.LOCALAPPDATA || process.env.HOME, ".code-push.config");
const emailValidator = require("email-validator");
Expand Down Expand Up @@ -550,14 +556,6 @@ export function execute(command: cli.ICommand) {
});
}

function fileDoesNotExistOrIsDirectory(filePath: string): boolean {
try {
return fs.lstatSync(filePath).isDirectory();
} catch (error) {
return true;
}
}

function getTotalActiveFromDeploymentMetrics(metrics: DeploymentMetrics): number {
let totalActive = 0;
Object.keys(metrics).forEach((label: string) => {
Expand Down Expand Up @@ -1307,6 +1305,24 @@ export const releaseReact = (command: cli.IReleaseReactCommand): Promise<void> =
command.sourcemapOutput
)
)
.then(async () => {
const isHermesEnabled =
command.useHermes ||
(platform === "android" && (await getAndroidHermesEnabled(command.gradleFile))) || // Check if we have to run hermes to compile JS to Byte Code if Hermes is enabled in build.gradle and we're releasing an Android build
(platform === "ios" && (await getiOSHermesEnabled(command.podFile))); // Check if we have to run hermes to compile JS to Byte Code if Hermes is enabled in Podfile and we're releasing an iOS build

if (isHermesEnabled) {
log(chalk.cyan("\nRunning hermes compiler...\n"));
await runHermesEmitBinaryCommand(
bundleName,
outputFolder,
command.sourcemapOutput,
command.extraHermesFlags,
command.gradleFile
);
}

})
.then(() => {
log(chalk.cyan("\nReleasing update contents to CodePush:\n"));
return release(releaseCommand);
Expand Down
25 changes: 25 additions & 0 deletions cli/script/command-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,28 @@ yargs
"Path to where the bundle and sourcemap should be written. If omitted, a bundle and sourcemap will not be written.",
type: "string",
})
.option("useHermes", {
alias: "h",
default: false,
demand: false,
description: "Enable hermes and bypass automatic checks",
type: "boolean",
})
.option("podFile", {
alias: "pod",
default: null,
demand: false,
description: "Path to the cocopods config file (iOS only).",
type: "string",
})
.option("extraHermesFlags", {
alias: "hf",
default: [],
demand: false,
description:
"Flags that get passed to Hermes, JavaScript to bytecode compiler. Can be specified multiple times.",
type: "array",
})
.check((argv: any, aliases: { [aliases: string]: string }): any => {
return checkValidReleaseOptions(argv);
});
Expand Down Expand Up @@ -1169,6 +1191,9 @@ export function createCommand(): cli.ICommand {
releaseReactCommand.rollout = getRolloutValue(argv["rollout"] as any);
releaseReactCommand.sourcemapOutput = argv["sourcemapOutput"] as any;
releaseReactCommand.outputDir = argv["outputDir"] as any;
releaseReactCommand.useHermes = argv["useHermes"] as any;
releaseReactCommand.extraHermesFlags = argv["extraHermesFlags"] as any;
releaseReactCommand.podFile = argv["podFile"] as any;
}
break;

Expand Down
Loading

0 comments on commit 7e9503e

Please sign in to comment.