Skip to content

Commit 7e9503e

Browse files
DmitriyKirakosyanlucen-ms
authored andcommitted
[CLI] Support Hermes (microsoft#5)
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.
1 parent 84d2d10 commit 7e9503e

File tree

5 files changed

+359
-8
lines changed

5 files changed

+359
-8
lines changed

cli/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ code-push-standalone release-react <appName> <platform>
392392
[--sourcemapOutput <sourcemapOutput>]
393393
[--targetBinaryVersion <targetBinaryVersion>]
394394
[--rollout <rolloutPercentage>]
395+
[--useHermes <useHermes>]
396+
[--podFile <podFile>]
397+
[--extraHermesFlags <extraHermesFlags>]
395398
```
396399

397400
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:
@@ -521,6 +524,24 @@ This specifies the relative path to where the assets, JS bundle and sourcemap fi
521524

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

527+
#### Use Hermes parameter
528+
529+
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.
530+
531+
_NOTE: This parameter can be set using either --hermesEnabled or -h_
532+
533+
#### Podfile parameter (iOS only)
534+
535+
The Podfile path will be used for Hermes automatic check. Not used if `--useHermes` is specified.
536+
537+
_NOTE: This parameter can be set using either --podfile or -pod_
538+
539+
#### Extra hermes flags parameter
540+
541+
Hermes flags which will be passed to Hermes compiler.
542+
543+
_NOTE: This parameter can be set using either --extraHermesFlags or -hf_
544+
524545
## Debugging CodePush Integration
525546

526547
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:

cli/script/command-executor.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ import {
3636
Session,
3737
UpdateMetrics,
3838
} from "../script/types";
39+
import {
40+
fileDoesNotExistOrIsDirectory,
41+
getAndroidHermesEnabled,
42+
getiOSHermesEnabled,
43+
runHermesEmitBinaryCommand
44+
} from "./react-native-utils";
3945

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

553-
function fileDoesNotExistOrIsDirectory(filePath: string): boolean {
554-
try {
555-
return fs.lstatSync(filePath).isDirectory();
556-
} catch (error) {
557-
return true;
558-
}
559-
}
560-
561559
function getTotalActiveFromDeploymentMetrics(metrics: DeploymentMetrics): number {
562560
let totalActive = 0;
563561
Object.keys(metrics).forEach((label: string) => {
@@ -1307,6 +1305,24 @@ export const releaseReact = (command: cli.IReleaseReactCommand): Promise<void> =
13071305
command.sourcemapOutput
13081306
)
13091307
)
1308+
.then(async () => {
1309+
const isHermesEnabled =
1310+
command.useHermes ||
1311+
(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
1312+
(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
1313+
1314+
if (isHermesEnabled) {
1315+
log(chalk.cyan("\nRunning hermes compiler...\n"));
1316+
await runHermesEmitBinaryCommand(
1317+
bundleName,
1318+
outputFolder,
1319+
command.sourcemapOutput,
1320+
command.extraHermesFlags,
1321+
command.gradleFile
1322+
);
1323+
}
1324+
1325+
})
13101326
.then(() => {
13111327
log(chalk.cyan("\nReleasing update contents to CodePush:\n"));
13121328
return release(releaseCommand);

cli/script/command-parser.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,28 @@ yargs
775775
"Path to where the bundle and sourcemap should be written. If omitted, a bundle and sourcemap will not be written.",
776776
type: "string",
777777
})
778+
.option("useHermes", {
779+
alias: "h",
780+
default: false,
781+
demand: false,
782+
description: "Enable hermes and bypass automatic checks",
783+
type: "boolean",
784+
})
785+
.option("podFile", {
786+
alias: "pod",
787+
default: null,
788+
demand: false,
789+
description: "Path to the cocopods config file (iOS only).",
790+
type: "string",
791+
})
792+
.option("extraHermesFlags", {
793+
alias: "hf",
794+
default: [],
795+
demand: false,
796+
description:
797+
"Flags that get passed to Hermes, JavaScript to bytecode compiler. Can be specified multiple times.",
798+
type: "array",
799+
})
778800
.check((argv: any, aliases: { [aliases: string]: string }): any => {
779801
return checkValidReleaseOptions(argv);
780802
});
@@ -1169,6 +1191,9 @@ export function createCommand(): cli.ICommand {
11691191
releaseReactCommand.rollout = getRolloutValue(argv["rollout"] as any);
11701192
releaseReactCommand.sourcemapOutput = argv["sourcemapOutput"] as any;
11711193
releaseReactCommand.outputDir = argv["outputDir"] as any;
1194+
releaseReactCommand.useHermes = argv["useHermes"] as any;
1195+
releaseReactCommand.extraHermesFlags = argv["extraHermesFlags"] as any;
1196+
releaseReactCommand.podFile = argv["podFile"] as any;
11721197
}
11731198
break;
11741199

0 commit comments

Comments
 (0)