Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit f23617b

Browse files
zkRichard Hua
authored andcommitted
Allow setting of node binary arguments via NODE_ARGS env var (#395)
Example usage: `env NODE_ARGS="--max-old-space-size=4096" code-push release-react APP_NAME ios` I couldn't find anywhere else secondary node processes are being spawned, but happy to add this functionality to those places as well. Issue #215
1 parent 25f4fb8 commit f23617b

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

cli/script/command-executor.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,14 +1347,21 @@ function requestAccessKey(): Promise<string> {
13471347
}
13481348

13491349
export var runReactNativeBundleCommand = (bundleName: string, development: boolean, entryFile: string, outputFolder: string, platform: string, sourcemapOutput: string): Promise<void> => {
1350-
var reactNativeBundleArgs = [
1351-
path.join("node_modules", "react-native", "local-cli", "cli.js"), "bundle",
1352-
"--assets-dest", outputFolder,
1353-
"--bundle-output", path.join(outputFolder, bundleName),
1354-
"--dev", development,
1355-
"--entry-file", entryFile,
1356-
"--platform", platform,
1357-
];
1350+
let reactNativeBundleArgs: string[] = [];
1351+
let envNodeArgs: string = process.env.CODE_PUSH_NODE_ARGS;
1352+
1353+
if (typeof envNodeArgs !== "undefined") {
1354+
Array.prototype.push.apply(reactNativeBundleArgs, envNodeArgs.trim().split(/\s+/));
1355+
}
1356+
1357+
Array.prototype.push.apply(reactNativeBundleArgs, [
1358+
path.join("node_modules", "react-native", "local-cli", "cli.js"), "bundle",
1359+
"--assets-dest", outputFolder,
1360+
"--bundle-output", path.join(outputFolder, bundleName),
1361+
"--dev", development,
1362+
"--entry-file", entryFile,
1363+
"--platform", platform,
1364+
]);
13581365

13591366
if (sourcemapOutput) {
13601367
reactNativeBundleArgs.push("--sourcemap-output", sourcemapOutput);

cli/test/cli.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,50 @@ describe("CLI", () => {
16811681
.done();
16821682
});
16831683

1684+
it("release-react applies arguments to node binary provided via the CODE_PUSH_NODE_ARGS env var", (done: MochaDone): void => {
1685+
var bundleName = "bundle.js";
1686+
var command: cli.IReleaseReactCommand = {
1687+
type: cli.CommandType.releaseReact,
1688+
appName: "a",
1689+
appStoreVersion: null,
1690+
bundleName: bundleName,
1691+
deploymentName: "Staging",
1692+
description: "Test default entry file",
1693+
mandatory: false,
1694+
rollout: null,
1695+
platform: "ios"
1696+
};
1697+
1698+
ensureInTestAppDirectory();
1699+
1700+
var release: Sinon.SinonSpy = sandbox.stub(cmdexec, "release", () => { return Q(<void>null) });
1701+
1702+
var _CODE_PUSH_NODE_ARGS: string = process.env.CODE_PUSH_NODE_ARGS;
1703+
process.env.CODE_PUSH_NODE_ARGS = " --foo=bar --baz ";
1704+
1705+
cmdexec.execute(command)
1706+
.then(() => {
1707+
var releaseCommand: cli.IReleaseCommand = <any>command;
1708+
releaseCommand.package = path.join(os.tmpdir(), "CodePush");
1709+
releaseCommand.appStoreVersion = "1.2.3";
1710+
1711+
sinon.assert.calledOnce(spawn);
1712+
var spawnCommand: string = spawn.args[0][0];
1713+
var spawnCommandArgs: string = spawn.args[0][1].join(" ");
1714+
assert.equal(spawnCommand, "node");
1715+
assert.equal(
1716+
spawnCommandArgs,
1717+
`--foo=bar --baz ${path.join("node_modules", "react-native", "local-cli", "cli.js")} bundle --assets-dest ${path.join(os.tmpdir(), "CodePush")} --bundle-output ${path.join(os.tmpdir(), "CodePush", bundleName)} --dev false --entry-file index.ios.js --platform ios`
1718+
);
1719+
assertJsonDescribesObject(JSON.stringify(release.args[0][0], /*replacer=*/ null, /*spacing=*/ 2), releaseCommand);
1720+
1721+
process.env.CODE_PUSH_NODE_ARGS = _CODE_PUSH_NODE_ARGS;
1722+
1723+
done();
1724+
})
1725+
.done();
1726+
});
1727+
16841728
it("sessionList lists session name and expires fields", (done: MochaDone): void => {
16851729
var command: cli.IAccessKeyListCommand = {
16861730
type: cli.CommandType.sessionList,

0 commit comments

Comments
 (0)