@novacraft-engineering/pulsar-cli 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,6 +28,7 @@ pulsar release <app> <deployment> --platform ios|android --target <ver> \
28
28
  [--rollout 25] [--mandatory] [--disabled] [--devices id1,id2,...] [--description "fix crash"] \
29
29
  [--private-key key.pem] [--bundle-key <file>]
30
30
  [--plain-copy-for-old-builds | --plain | --only-older-builds]
31
+ [--hermes | --no-hermes]
31
32
 
32
33
  pulsar promote <app> <from> <to> [--rollout 100]
33
34
  pulsar rollback <app> <deployment>
@@ -75,11 +76,56 @@ the device rejects any update not signed with the matching private key.
75
76
  - With neither, the CLI asks Pulsar to sign with the app's stored key. If Pulsar holds no key for
76
77
  the app, the release goes out unsigned and the CLI says so.
77
78
 
79
+ ## Hermes bytecode
80
+
81
+ `pulsar release` compiles the bundle to Hermes bytecode the way your store build does: from an
82
+ unminified bundle, with the compiler in your `node_modules`. The app no longer parses the JavaScript
83
+ on every cold start, which is what makes low-end Android phones slow to open after an OTA.
84
+
85
+ - Hermes is on unless the project turns it off: `hermesEnabled=false` in `android/gradle.properties`,
86
+ `enableHermes: false` in `android/app/build.gradle` (React Native 0.70 and older), or
87
+ `:hermes_enabled => false` in `ios/Podfile`.
88
+ - `--no-hermes` releases JavaScript. `--hermes` compiles even when the project says otherwise.
89
+ - The compiler comes from your `node_modules` (`hermes-compiler/hermesc`,
90
+ `react-native/sdks/hermesc` on React Native 0.82 and older, or `hermes-engine` on 0.68 and older).
91
+ If it is missing the CLI stops and suggests `--no-hermes`; it never ships JavaScript in its place.
92
+
93
+ Bytecode only runs on a Hermes with the same bytecode version, and React Native upgrades change it
94
+ (React Native 0.82 and 0.83 use v96, 0.84 to 0.86 use v98). So every bytecode release also carries a JavaScript
95
+ copy of the same release, with the same assets:
96
+
97
+ - A build that reports the same bytecode version (SDK 1.9 or later) gets the bytecode. Until your
98
+ store builds run SDK 1.9, most devices get the JavaScript copy. SDK 1.9 has no native changes over
99
+ 1.8, so a build on SDK 1.8 starts reporting once it installs an OTA built with 1.9.
100
+ - Every other build gets the JavaScript copy: older SDKs, other bytecode versions, JSC.
101
+ - Before uploading, the CLI prints how many active devices on `--target` report the matching
102
+ version and get the bytecode; the rest get the JavaScript copy.
103
+ - The CLI checks that your Pulsar server can serve bytecode releases this way first, and stops if it can't.
104
+ - For private apps both builds are encrypted, and `--plain-copy-for-old-builds` uploads the
105
+ JavaScript copy as the plain copy.
106
+ - Metro runs twice: minified for the JavaScript copy, the same kind of bundle earlier releases
107
+ shipped, and unminified for the bytecode. Both builds carry the same assets.
108
+ - When the app has a signing key, both builds are signed. Each gets its own source map, so on apps
109
+ without private bundles crash stacks map to your files whichever one a device runs.
110
+ - `--max-growth` compares bytecode with the last bytecode release and the JavaScript copy with the
111
+ last JavaScript, so the first bytecode release does not trip it.
112
+ - Diffs are built for the bytecode build, including from the previous release's JavaScript copy.
113
+ - `pulsar history` tags these releases `[bytecode v96 + JS copy]`.
114
+ - Pulsar won't roll back to a bytecode release without its JavaScript copy, and on a deployment that
115
+ needs approval the copy can't be added once the release is approved or rejected.
116
+
117
+ Limits: bytecode compresses less well than minified JavaScript, so a full download is larger (about
118
+ 1.9 times for one app we measured). It doesn't hide your code: any client that doesn't report a
119
+ bytecode version gets the JavaScript copy, so the code is as readable as before, and the benefit is
120
+ the faster cold start. Bytecode on its own is harder to read, not unreadable: decompilers exist and
121
+ strings stay visible. It is not a way to hide anything from app review.
122
+
78
123
  ## Private bundles (encrypted releases)
79
124
 
80
125
  When an app's Private bundles setting is Manual unlock or Auto unlock, `pulsar release` encrypts
81
126
  the bundle, diff, manifest and source map before upload, so Pulsar stores and serves only ciphertext.
82
- It is not protection against reverse engineering: the key ships inside your store build. Full guide:
127
+ It is not protection against reverse engineering: the key ships inside your store build, so anyone
128
+ who unpacks the app can extract it and decrypt that app's releases. Full guide:
83
129
  [usepulsar.dev/docs/private-bundles](https://usepulsar.dev/docs/private-bundles).
84
130
 
85
131
  ```bash
@@ -147,6 +193,8 @@ pulsar migrate --from https://<your-codepush-server> --access-key <source access
147
193
  the way `pulsar release` does, and publishes it with the same target version, description,
148
194
  mandatory flag, rollout and disabled state. A release that can't be downloaded or unzipped is
149
195
  reported and skipped. Re-running is safe: a bundle already on the Pulsar deployment is not re-uploaded.
196
+ A release that is already Hermes bytecode is skipped too, since it has no JavaScript copy for builds
197
+ that can't run it: release it again from source with `pulsar release`.
150
198
  - `--dry-run` reads both servers and prints the plan without writing anything to Pulsar.
151
199
 
152
200
  The run ends with a table of source key → new Pulsar key per deployment. Devices keep checking the
package/hash.js CHANGED
@@ -13,7 +13,7 @@ function isIgnored(relativePath) {
13
13
  );
14
14
  }
15
15
 
16
- function walk(dir) {
16
+ export function walk(dir) {
17
17
  const files = [];
18
18
  for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
19
19
  const full = path.join(dir, entry.name);
package/hermes.js ADDED
@@ -0,0 +1,131 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import {spawnSync} from 'node:child_process';
5
+ import {walk} from './hash.js';
6
+
7
+ const MAGIC = Buffer.from('c61fbc03c103191f', 'hex');
8
+ const HEADER_LENGTH = 12;
9
+ const OS_DIRS = {darwin: 'osx-bin', linux: 'linux64-bin', win32: 'win64-bin'};
10
+ const COMPILER_DIRS = [['hermes-compiler', 'hermesc'], ['react-native', 'sdks', 'hermesc'], ['hermes-engine']];
11
+ const COMPOSE_SCRIPT = ['react-native', 'scripts', 'compose-source-maps.js'];
12
+ const DIAGNOSTIC_LINES = 20;
13
+ const BUNDLE_FILES = [/(^|\/)(main\.jsbundle|index\.android\.bundle)$/, /(^|\/)[^/]+\.(jsbundle|bundle)$/];
14
+
15
+ export const bundleFileName = (platform) => (platform === 'ios' ? 'main.jsbundle' : 'index.android.bundle');
16
+
17
+ export function bytecodeVersionOf(bytes) {
18
+ if (!bytes || bytes.length < HEADER_LENGTH) return null;
19
+ const head = Buffer.from(bytes.buffer, bytes.byteOffset, HEADER_LENGTH);
20
+ if (!head.subarray(0, MAGIC.length).equals(MAGIC)) return null;
21
+ return head.readUInt32LE(MAGIC.length);
22
+ }
23
+
24
+ export function fileBytecodeVersion(filePath) {
25
+ const handle = fs.openSync(filePath, 'r');
26
+ try {
27
+ const head = Buffer.alloc(HEADER_LENGTH);
28
+ return bytecodeVersionOf(head.subarray(0, fs.readSync(handle, head, 0, HEADER_LENGTH, 0)));
29
+ } finally {
30
+ fs.closeSync(handle);
31
+ }
32
+ }
33
+
34
+ export function bundleBytecodeIn(contentsDir) {
35
+ const files = walk(contentsDir).map((file) => path.relative(contentsDir, file).split(path.sep).join('/'));
36
+ for (const pattern of BUNDLE_FILES) {
37
+ const bundle = files.find((file) => pattern.test(file));
38
+ if (bundle) return fileBytecodeVersion(path.join(contentsDir, bundle));
39
+ }
40
+ return null;
41
+ }
42
+
43
+ const readText = (filePath) => (fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '');
44
+ const uncommented = (text, commentPattern) => text.split(/\r?\n/).filter((line) => !commentPattern.test(line));
45
+
46
+ export function hermesEnabledIn(projectRoot, platform) {
47
+ if (platform === 'android') {
48
+ const properties = uncommented(readText(path.join(projectRoot, 'android', 'gradle.properties')), /^\s*[#!]/);
49
+ const appGradle = uncommented(readText(path.join(projectRoot, 'android', 'app', 'build.gradle')), /^\s*\/\//);
50
+ return !properties.some((line) => /^\s*hermesEnabled\s*[=:]\s*false\s*$/.test(line))
51
+ && !appGradle.some((line) => /^[^/]*\benableHermes\s*[:=]\s*false\b/.test(line));
52
+ }
53
+ const podfile = uncommented(readText(path.join(projectRoot, 'ios', 'Podfile')), /^\s*#/);
54
+ return !podfile.some((line) => /(?::hermes_enabled\s*=>|\bhermes_enabled:)\s*false\b/.test(line));
55
+ }
56
+
57
+ function findInNodeModules(projectRoot, candidates) {
58
+ let directory = path.resolve(projectRoot);
59
+ for (;;) {
60
+ for (const parts of candidates) {
61
+ const candidate = path.join(directory, 'node_modules', ...parts);
62
+ if (fs.existsSync(candidate)) return candidate;
63
+ }
64
+ const parent = path.dirname(directory);
65
+ if (parent === directory) return null;
66
+ directory = parent;
67
+ }
68
+ }
69
+
70
+ export function findHermesc(projectRoot, osName = process.platform) {
71
+ const osDir = OS_DIRS[osName];
72
+ if (!osDir) return null;
73
+ const binary = osName === 'win32' ? 'hermesc.exe' : 'hermesc';
74
+ return findInNodeModules(projectRoot, COMPILER_DIRS.map((parts) => [...parts, osDir, binary]));
75
+ }
76
+
77
+ export const findComposeScript = (projectRoot) => findInNodeModules(projectRoot, [COMPOSE_SCRIPT]);
78
+
79
+ export function hermesChoice(args, projectRoot, platform) {
80
+ if (args.includes('--hermes') && args.includes('--no-hermes')) return {error: 'pass --hermes or --no-hermes, not both'};
81
+ if (args.includes('--no-hermes')) return {enabled: false};
82
+ return {enabled: args.includes('--hermes') || hermesEnabledIn(projectRoot, platform)};
83
+ }
84
+
85
+ function diagnostics(output) {
86
+ const lines = String(output || '').split('\n').filter(Boolean);
87
+ const errors = lines.filter((line) => /\berror:/.test(line));
88
+ return (errors.length ? errors : lines).slice(0, DIAGNOSTIC_LINES).join('\n');
89
+ }
90
+
91
+ export function compileBytecode(hermesc, inputPath, outputPath, {sourcemap = false} = {}) {
92
+ const result = spawnSync(
93
+ hermesc,
94
+ ['-emit-binary', '-max-diagnostic-width=80', '-O', ...(sourcemap ? ['-output-source-map'] : []), '-out', outputPath, inputPath],
95
+ {encoding: 'utf8', maxBuffer: 256 * 1024 * 1024},
96
+ );
97
+ if (result.error) throw new Error(`could not run ${hermesc}: ${result.error.message}`);
98
+ if (result.status !== 0) throw new Error(`hermesc failed:\n${diagnostics(result.stderr || result.stdout)}`);
99
+ const bytecodeVersion = fs.existsSync(outputPath) ? fileBytecodeVersion(outputPath) : null;
100
+ if (!bytecodeVersion) throw new Error('hermesc finished, but what it wrote is not Hermes bytecode');
101
+ const sourcemapPath = `${outputPath}.map`;
102
+ return {bytecodeVersion, sourcemapPath: sourcemap && fs.existsSync(sourcemapPath) ? sourcemapPath : null};
103
+ }
104
+
105
+ export function composeSourcemaps(composeScript, packagerMapPath, compilerMapPath, outputPath) {
106
+ const result = spawnSync(process.execPath, [composeScript, packagerMapPath, compilerMapPath, '-o', outputPath], {encoding: 'utf8', maxBuffer: 64 * 1024 * 1024});
107
+ if (result.error) throw new Error(result.error.message);
108
+ if (result.status !== 0 || !fs.existsSync(outputPath)) throw new Error(diagnostics(result.stderr) || `exit code ${result.status}`);
109
+ }
110
+
111
+ export function buildBytecode({hermesc, composeScript}, javascript, bundleName) {
112
+ const compilerDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pulsar-hermesc-'));
113
+ const compiledPath = path.join(compilerDir, bundleName);
114
+ const compiled = compileBytecode(hermesc, path.join(javascript.contentsDir, bundleName), compiledPath, {sourcemap: Boolean(javascript.sourcemapPath)});
115
+ const contentsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pulsar-bytecode-'));
116
+ fs.cpSync(javascript.contentsDir, contentsDir, {recursive: true});
117
+ fs.copyFileSync(compiledPath, path.join(contentsDir, bundleName));
118
+ let sourcemapPath = null;
119
+ let sourcemapError = null;
120
+ if (compiled.sourcemapPath) {
121
+ try {
122
+ if (!composeScript) throw new Error('react-native/scripts/compose-source-maps.js was not found in node_modules');
123
+ composeSourcemaps(composeScript, javascript.sourcemapPath, compiled.sourcemapPath, `${contentsDir}.map`);
124
+ sourcemapPath = `${contentsDir}.map`;
125
+ } catch (err) {
126
+ sourcemapError = err.message;
127
+ }
128
+ }
129
+ fs.rmSync(compilerDir, {recursive: true, force: true});
130
+ return {contentsDir, bytecodeVersion: compiled.bytecodeVersion, sourcemapPath, sourcemapError};
131
+ }
package/migrate.js CHANGED
@@ -4,6 +4,7 @@ import path from 'node:path';
4
4
  import {execFileSync} from 'node:child_process';
5
5
  import {api, die, getFlag, loadConfig, pushBuiltRelease, splitList} from './pulsar.js';
6
6
  import {computePackageHash} from './hash.js';
7
+ import {bundleBytecodeIn} from './hermes.js';
7
8
 
8
9
  const USAGE = 'Usage: pulsar migrate --from <serverUrl> --access-key <key> [--apps A,B] [--org <name>] [--platform ios|android] [--releases latest|none] [--dry-run]';
9
10
 
@@ -52,6 +53,8 @@ async function migrateRelease({source, pulsarApp, deploymentName, sourcePackage,
52
53
  } catch {
53
54
  throw new Error('downloaded bundle is not a readable zip');
54
55
  }
56
+ const bytecodeVersion = bundleBytecodeIn(contentsDir);
57
+ if (bytecodeVersion) return `not migrated: ${sourcePackage.label} is Hermes bytecode v${bytecodeVersion}; release it again from source with pulsar release`;
55
58
  const packageHash = computePackageHash(contentsDir);
56
59
  const existing = await api(`/apps/${pulsarApp.id}/deployments/${deploymentName}/releases`);
57
60
  const already = existing.find((entry) => entry.packageHash === packageHash);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novacraft-engineering/pulsar-cli",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "Pulsar OTA release CLI — bundle, hash, and ship React Native updates over-the-air.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,6 +11,7 @@
11
11
  "hash.js",
12
12
  "migrate.js",
13
13
  "private.js",
14
+ "hermes.js",
14
15
  "envelope.js",
15
16
  "releaseCompare.js",
16
17
  "README.md",
@@ -30,7 +31,7 @@
30
31
  "node": ">=18"
31
32
  },
32
33
  "scripts": {
33
- "test": "node test/hash.test.js && node test/security.test.js && node test/signing.test.js && node test/entry.test.js && node test/migrate.test.js && node test/envelope.test.js && node test/private.test.js"
34
+ "test": "node test/hash.test.js && node test/security.test.js && node test/signing.test.js && node test/entry.test.js && node test/migrate.test.js && node test/envelope.test.js && node test/private.test.js && node test/hermes.test.js && node test/connection.test.js"
34
35
  },
35
36
  "keywords": [
36
37
  "cli",
package/private.js CHANGED
@@ -20,7 +20,8 @@ export async function privateContext(app, args, localKey) {
20
20
  let settings;
21
21
  try {
22
22
  settings = await api(`/apps/${app.id}/private-bundles`, {optional: true});
23
- } catch {
23
+ } catch (err) {
24
+ if (!err.status) die(`couldn't check whether ${app.name} uses private bundles (${[err.message, err.cause?.code].filter(Boolean).join(', ')}). Nothing was uploaded.`);
24
25
  return null;
25
26
  }
26
27
  if (!settings || settings.mode === 'off') return null;
package/pulsar.js CHANGED
@@ -10,6 +10,7 @@ import {fileURLToPath} from 'node:url';
10
10
  import {computePackageHash, fileHashes} from './hash.js';
11
11
  import {migrate} from './migrate.js';
12
12
  import {privateContext, reportReach, sealArtifact, openArtifact, sealedHeaders, cmdBundleKey, cmdChanges} from './private.js';
13
+ import {bundleFileName, buildBytecode, findComposeScript, findHermesc, hermesChoice} from './hermes.js';
13
14
 
14
15
  // Code signing: sign the package hash into an RS256 JWT the client verifies against its
15
16
  // CodePushPublicKey (Info.plist). Both native SDKs read it from <update>/CodePush/.codepushrelease
@@ -56,6 +57,19 @@ function saveConfig(config) {
56
57
  try { fs.chmodSync(CONFIG_FILE, 0o600); } catch { /* best-effort on pre-existing files */ }
57
58
  }
58
59
 
60
+ const STALE_CONNECTION_CODES = new Set(['ECONNRESET', 'EPIPE', 'UND_ERR_SOCKET']);
61
+
62
+ // A build blocks the event loop, so the server can close the pooled keep-alive connection unseen
63
+ // and the next request lands on a dead socket. Only a GET is safe to send twice.
64
+ async function send(url, options) {
65
+ try {
66
+ return await fetch(url, options);
67
+ } catch (err) {
68
+ if (options.method !== 'GET' || !STALE_CONNECTION_CODES.has(err?.cause?.code)) throw err;
69
+ return fetch(url, options);
70
+ }
71
+ }
72
+
59
73
  async function api(pathname, {method = 'GET', body, headers = {}, raw, allowAnonymous, onUploadProgress, optional} = {}) {
60
74
  const {apiUrl, token} = loadConfig();
61
75
  if (!apiUrl) die('No API url. Run: pulsar login <apiUrl>');
@@ -87,7 +101,7 @@ async function api(pathname, {method = 'GET', body, headers = {}, raw, allowAnon
87
101
  });
88
102
  options.duplex = 'half';
89
103
  }
90
- const response = await fetch(apiUrl.replace(/\/$/, '') + pathname, options);
104
+ const response = await send(apiUrl.replace(/\/$/, '') + pathname, options);
91
105
  const text = await response.text();
92
106
  // Check the status BEFORE parsing: an edge/proxy error (413, 502, 524) returns
93
107
  // an HTML page, and parsing that first turned every such failure into an
@@ -99,7 +113,7 @@ async function api(pathname, {method = 'GET', body, headers = {}, raw, allowAnon
99
113
  } catch {
100
114
  detail = text.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 300);
101
115
  }
102
- if (optional) throw new Error(`${response.status} ${detail}`);
116
+ if (optional) throw Object.assign(new Error(`${response.status} ${detail}`), {status: response.status});
103
117
  die(`${response.status} ${response.statusText}: ${detail}`);
104
118
  }
105
119
  try {
@@ -206,10 +220,10 @@ async function resolveApp(nameOrId, platform) {
206
220
  die(`Multiple apps named "${nameOrId}" (${named.map((app) => app.os).join(', ')}). Pass --platform ios|android, or use the app id.`);
207
221
  }
208
222
 
209
- function bundle(platform, contentsDir, sourcemapPath) {
210
- const bundleName = platform === 'ios' ? 'main.jsbundle' : 'index.android.bundle';
223
+ function bundle(platform, contentsDir, sourcemapPath, {forHermes = false} = {}) {
224
+ const bundleName = bundleFileName(platform);
211
225
  fs.mkdirSync(contentsDir, {recursive: true});
212
- console.log(`• bundling ${platform}…`);
226
+ console.log(forHermes ? `• bundling ${platform} unminified for the Hermes compiler, as React Native's release build does…` : `• bundling ${platform}…`);
213
227
  execFileSync(
214
228
  'npx',
215
229
  [
@@ -217,6 +231,7 @@ function bundle(platform, contentsDir, sourcemapPath) {
217
231
  'bundle',
218
232
  '--platform', platform,
219
233
  '--dev', 'false',
234
+ ...(forHermes ? ['--minify', 'false'] : []),
220
235
  '--entry-file', 'index.js',
221
236
  '--bundle-output', path.join(contentsDir, bundleName),
222
237
  '--assets-dest', contentsDir,
@@ -236,8 +251,16 @@ function sizeGrowth(previousSize, nextSize) {
236
251
  return Math.round(((nextSize - previousSize) / previousSize) * 100);
237
252
  }
238
253
 
254
+ function growthChecks(previous, {size, jsSize = null, hermes = false}) {
255
+ const previousJsSize = previous?.hermes ? previous.jsCopy?.size : previous?.size;
256
+ const checks = hermes
257
+ ? [{name: 'bytecode', previousSize: previous?.hermes ? previous.size : null, size}, {name: 'JavaScript copy', previousSize: previousJsSize, size: jsSize}]
258
+ : [{name: 'bundle', previousSize: previousJsSize, size}];
259
+ return checks.map((check) => ({...check, growth: sizeGrowth(check.previousSize, check.size)}));
260
+ }
261
+
239
262
  function zipContents(contentsDir) {
240
- const zipPath = path.join(os.tmpdir(), `pulsar-${Date.now()}.zip`);
263
+ const zipPath = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'pulsar-zip-')), 'release.zip');
241
264
  execFileSync('zip', ['-qq', '-r', '-X', zipPath, '.'], {cwd: contentsDir});
242
265
  return zipPath;
243
266
  }
@@ -372,7 +395,7 @@ async function cmdApps() {
372
395
 
373
396
  // Sign for this app — with a local key when one was given, otherwise by asking Pulsar, which signs for
374
397
  // anyone allowed to publish here. Each app can hold a different key, so a release train re-signs.
375
- async function signForApp(app, deployment, contentsDir, packageHash, localKey) {
398
+ async function signForApp(app, deployment, contentsDir, packageHash, localKey, subject = '') {
376
399
  const signaturePath = path.join(contentsDir, SIGNATURE_PATH);
377
400
  fs.rmSync(signaturePath, {force: true});
378
401
  let signature = null;
@@ -386,45 +409,88 @@ async function signForApp(app, deployment, contentsDir, packageHash, localKey) {
386
409
  ({signature} = await api(`/apps/${app.id}/deployments/${deployment}/sign`, {method: 'POST', body: {packageHash}}));
387
410
  }
388
411
  if (!signature) {
389
- console.log(`• ${app.name} has no signing key — uploading unsigned`);
412
+ console.log(`• ${app.name} has no signing key — uploading${subject ? ` ${subject}` : ''} unsigned`);
390
413
  return;
391
414
  }
392
415
  fs.mkdirSync(path.dirname(signaturePath), {recursive: true});
393
416
  fs.writeFileSync(signaturePath, signature);
394
- console.log(`• signed${localKey ? ' with your local key' : ' by Pulsar'}`);
417
+ console.log(`• signed${subject ? ` ${subject}` : ''}${localKey ? ' with your local key' : ' by Pulsar'}`);
418
+ }
419
+
420
+ function reportBytecodeReach(bytecodeVersion, reach, target, recentDays) {
421
+ const active = reach.activeDevices || 0;
422
+ const matching = reach.bytecodeActiveDevices[bytecodeVersion] || 0;
423
+ const others = Object.entries(reach.bytecodeActiveDevices)
424
+ .filter(([reported, count]) => Number(reported) !== bytecodeVersion && count > 0)
425
+ .map(([reported, count]) => `${count} run v${reported}`);
426
+ if (!active) {
427
+ console.log(`• Hermes bytecode v${bytecodeVersion}: no device on ${target} was active in the last ${recentDays} days. Builds get the bytecode once they report v${bytecodeVersion} (SDK 1.9 or later) and the JavaScript copy until then`);
428
+ return;
429
+ }
430
+ console.log(`• Hermes bytecode v${bytecodeVersion}: ${matching} of ${active} devices active on ${target} in the last ${recentDays} days run bytecode v${bytecodeVersion} and get it; the other ${active - matching} get the JavaScript copy${others.length ? ` (${others.join(', ')})` : ''}`);
431
+ }
432
+
433
+ const supportsBytecode = (reach) => Boolean(reach?.bytecodeActiveDevices) && typeof reach.bytecodeActiveDevices === 'object';
434
+
435
+ function diffBases(app, previous, packageHash) {
436
+ if (!previous) return [];
437
+ const blobFile = (blobKey) => blobKey.slice(app.id.length + 1);
438
+ const bases = [{
439
+ label: previous.label,
440
+ packageHash: previous.packageHash,
441
+ file: previous.encrypted && previous.blobKey ? blobFile(previous.blobKey) : `${previous.packageHash}.zip`,
442
+ }];
443
+ if (previous.jsCopy?.packageHash && previous.jsCopy.blobKey) {
444
+ bases.push({label: `${previous.label} JavaScript copy`, packageHash: previous.jsCopy.packageHash, file: blobFile(previous.jsCopy.blobKey), jsCopy: true});
445
+ }
446
+ return bases.filter((base) => base.packageHash && base.packageHash !== packageHash);
395
447
  }
396
448
 
397
449
  // Sign and push an already-built bundle to one app's deployment, then generate and upload a
398
450
  // differential patch against whatever that deployment was serving.
399
- async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported = false} = {}) {
451
+ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported = false, hermes = null, javascript = null} = {}) {
452
+ if (hermes && !javascript) die('a Hermes bytecode release needs its JavaScript copy. Nothing was uploaded.');
400
453
  const privateBundles = await privateContext(app, args, localKey);
401
454
  const sealing = Boolean(privateBundles) && !privateBundles.plain;
402
455
  const plainCopy = sealing && args.includes('--plain-copy-for-old-builds');
403
456
  if (privateBundles && !reachReported) reportReach(privateBundles, {mandatory: args.includes('--mandatory'), plainCopy});
404
457
  await signForApp(app, deployment, contentsDir, packageHash, localKey);
458
+ if (hermes) await signForApp(app, deployment, javascript.contentsDir, javascript.packageHash, localKey, 'the JavaScript copy');
459
+ const sealFull = async (hash, bytes) => (sealing ? Buffer.from(await sealArtifact(privateBundles, app, hash, bytes, 'full')) : bytes);
405
460
  const plainZip = fs.readFileSync(zipContents(contentsDir));
406
- const zip = sealing ? Buffer.from(await sealArtifact(privateBundles, app, packageHash, plainZip, 'full')) : plainZip;
461
+ const zip = await sealFull(packageHash, plainZip);
462
+ const plainJsZip = hermes ? fs.readFileSync(zipContents(javascript.contentsDir)) : null;
463
+ const jsZip = hermes ? await sealFull(javascript.packageHash, plainJsZip) : null;
407
464
  let prevLatest = null;
408
465
  try {
409
466
  const existing = await api(`/apps/${app.id}/deployments/${deployment}/releases`, {optional: true});
410
467
  prevLatest = [...existing].reverse().find((entry) => !entry.isDisabled) || existing[existing.length - 1] || null;
411
468
  } catch {}
469
+ const target = getFlag(args, 'target');
470
+ let binaries = null;
412
471
  try {
413
- const target = getFlag(args, 'target');
414
- const {versions, reach, recentDays} = await api(`/apps/${app.id}/binary-versions?target=${encodeURIComponent(target)}`, {optional: true});
415
- if (versions?.length && reach && !reach.everLaunched) {
416
- console.log(`⚠ no device has reported a store build matching ${target}; this release reaches nobody yet (builds seen: ${versions.slice(0, 5).map((entry) => entry.version).join(', ')})`);
417
- } else if (versions?.length && reach && !reach.recentLaunches) {
418
- console.log(`⚠ no store build matching ${target} was opened in the last ${recentDays} days (matches: ${reach.matchingVersions.join(', ')})`);
419
- }
420
- } catch {}
421
- const growth = sizeGrowth(prevLatest?.size, zip.length);
422
- if (growth !== null && growth > 20) {
423
- console.log(`⚠ bundle is ${growth}% larger than ${prevLatest.label} (${(prevLatest.size / 1e6).toFixed(2)}MB → ${(zip.length / 1e6).toFixed(2)}MB)`);
472
+ binaries = await api(`/apps/${app.id}/binary-versions?target=${encodeURIComponent(target)}`, {optional: true});
473
+ } catch (err) {
474
+ if (hermes) die(`couldn't confirm that ${app.name}'s Pulsar server can serve Hermes bytecode (${err.message}). Pass --no-hermes to release JavaScript. Nothing was uploaded.`);
475
+ }
476
+ const {versions, reach, recentDays} = binaries || {};
477
+ if (versions?.length && reach && !reach.everLaunched) {
478
+ console.log(`⚠ no device has reported a store build matching ${target}; this release reaches nobody yet (builds seen: ${versions.slice(0, 5).map((entry) => entry.version).join(', ')})`);
479
+ } else if (versions?.length && reach && !reach.recentLaunches) {
480
+ console.log(`⚠ no store build matching ${target} was opened in the last ${recentDays} days (matches: ${reach.matchingVersions.join(', ')})`);
481
+ }
482
+ if (hermes) {
483
+ if (!supportsBytecode(reach)) die(`${app.name}'s Pulsar server can't serve Hermes bytecode releases yet, so builds that can't run bytecode would get it too. Update the server, or pass --no-hermes to release JavaScript. Nothing was uploaded.`);
484
+ reportBytecodeReach(hermes.bytecodeVersion, reach, target, recentDays);
424
485
  }
425
486
  const maxGrowth = getFlag(args, 'max-growth');
426
- if (maxGrowth !== undefined && growth !== null && growth > Number(maxGrowth)) {
427
- die(`bundle grew ${growth}%, more than --max-growth ${maxGrowth}%. Nothing was released.`);
487
+ for (const {name, previousSize, size, growth} of growthChecks(prevLatest, {size: zip.length, jsSize: jsZip?.length, hermes: Boolean(hermes)})) {
488
+ if (growth !== null && growth > 20) {
489
+ console.log(`⚠ ${name} is ${growth}% larger than ${prevLatest.label} (${(previousSize / 1e6).toFixed(2)}MB → ${(size / 1e6).toFixed(2)}MB)`);
490
+ }
491
+ if (maxGrowth !== undefined && growth !== null && growth > Number(maxGrowth)) {
492
+ die(`${name} grew ${growth}%, more than --max-growth ${maxGrowth}%. Nothing was released.`);
493
+ }
428
494
  }
429
495
 
430
496
  const startsAt = parseSchedule(getFlag(args, 'schedule'));
@@ -433,14 +499,15 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
433
499
  method: 'POST',
434
500
  raw: true,
435
501
  body: zip,
436
- onUploadProgress: uploadProgress(`uploading ${(zip.length / 1e6).toFixed(1)}MB bundle`),
502
+ onUploadProgress: uploadProgress(`uploading ${(zip.length / 1e6).toFixed(1)}MB ${hermes ? 'bytecode ' : ''}bundle`),
437
503
  headers: {
438
504
  ...(sealing
439
505
  ? {...sealedHeaders, 'x-encrypted': '1', 'x-key-ids': privateBundles.keys.map((key) => key.kid).join(','), 'x-release-signature': fs.readFileSync(path.join(contentsDir, SIGNATURE_PATH), 'utf8')}
440
506
  : {'content-type': 'application/zip'}),
441
507
  ...(privateBundles?.plain === 'all' ? {'x-plain': '1'} : {}),
442
508
  ...(privateBundles?.plain === 'older' ? {'x-audience': 'older-builds'} : {}),
443
- 'x-app-version': getFlag(args, 'target'),
509
+ ...(hermes ? {'x-hermes-bytecode-version': String(hermes.bytecodeVersion)} : {}),
510
+ 'x-app-version': target,
444
511
  'x-package-hash': packageHash,
445
512
  'x-is-mandatory': String(args.includes('--mandatory')),
446
513
  'x-disabled': String(args.includes('--disabled')),
@@ -455,22 +522,47 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
455
522
  ...(ramp ? {'x-rollout-to': String(ramp.to), 'x-rollout-hours': String(ramp.hours)} : {}),
456
523
  },
457
524
  });
525
+ if (hermes && release.hermes?.bytecodeVersion !== hermes.bytecodeVersion) {
526
+ const disabled = await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}`, {method: 'PATCH', body: {isDisabled: true}, optional: true}).then(() => true, () => false);
527
+ die(`${app.name}'s Pulsar server stored ${release.label} without its Hermes bytecode version, so it would serve bytecode to builds that can't run it. ${disabled ? `${release.label} was disabled.` : `Disable ${release.label} in the dashboard now.`} Update the server, or release again with --no-hermes.`);
528
+ }
458
529
  const scopes = [
459
530
  release.clientIds?.length ? `${release.clientIds.length} device id(s)` : null,
460
531
  release.targetDevices?.length ? `${release.targetDevices.length} device model(s)` : null,
461
532
  release.targetUserIds?.length ? `${release.targetUserIds.length} user(s)` : null,
462
533
  release.targetFromLabels?.length ? `devices on ${release.targetFromLabels.join('/')}` : null,
463
534
  ].filter(Boolean);
464
- const reach = scopes.length ? scopes.join(' + ') : `${release.rollout}% of devices`;
535
+ const reachText = scopes.length ? scopes.join(' + ') : `${release.rollout}% of devices`;
465
536
  const privacy = release.encrypted ? ' (private)' : release.olderBuildsOnly ? ' (plain, older builds only)' : privateBundles ? ' (plain)' : '';
466
- console.log(`✓ released ${release.label} to ${app.name}/${deployment} — ${release.isDisabled ? 'DISABLED' : reach}${privacy}`);
537
+ const bytecode = hermes ? ` (Hermes bytecode v${hermes.bytecodeVersion})` : '';
538
+ console.log(`✓ released ${release.label} to ${app.name}/${deployment} — ${release.isDisabled ? 'DISABLED' : reachText}${privacy}${bytecode}`);
539
+ if (hermes) {
540
+ try {
541
+ await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/js-copy`, {
542
+ method: 'POST',
543
+ raw: true,
544
+ optional: true,
545
+ body: jsZip,
546
+ onUploadProgress: uploadProgress(`uploading ${(jsZip.length / 1e6).toFixed(1)}MB JavaScript copy`),
547
+ headers: {
548
+ ...(sealing
549
+ ? {...sealedHeaders, 'x-release-signature': fs.readFileSync(path.join(javascript.contentsDir, SIGNATURE_PATH), 'utf8')}
550
+ : {'content-type': 'application/zip'}),
551
+ 'x-package-hash': javascript.packageHash,
552
+ },
553
+ });
554
+ } catch (err) {
555
+ die(`the JavaScript copy of ${release.label} was not uploaded (${err.message}). ${release.label} reaches only builds that run Hermes bytecode v${hermes.bytecodeVersion}; every other build stays on its current release. Release again, or disable ${release.label}.`);
556
+ }
557
+ console.log(`• JavaScript copy uploaded: builds that don't run Hermes bytecode v${hermes.bytecodeVersion} get it`);
558
+ }
467
559
  if (plainCopy) {
468
560
  await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/plain-copy`, {
469
561
  method: 'POST',
470
562
  raw: true,
471
- body: plainZip,
472
- onUploadProgress: uploadProgress(`uploading ${(plainZip.length / 1e6).toFixed(1)}MB plain copy for older builds`),
473
- headers: {'content-type': 'application/zip'},
563
+ body: hermes ? plainJsZip : plainZip,
564
+ onUploadProgress: uploadProgress(`uploading ${((hermes ? plainJsZip : plainZip).length / 1e6).toFixed(1)}MB plain copy for older builds`),
565
+ headers: {'content-type': 'application/zip', ...(hermes ? {'x-package-hash': javascript.packageHash} : {})},
474
566
  });
475
567
  console.log('• plain copy uploaded: older builds get this release too, and Pulsar can read that copy');
476
568
  }
@@ -483,12 +575,13 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
483
575
  if (release.startsAt) console.log(` scheduled — goes live ${new Date(release.startsAt).toLocaleString()}`);
484
576
  if (release.rolloutRamp) console.log(` gradual rollout — ${release.rollout}% to ${release.rolloutRamp.to}% over ${release.rolloutRamp.hours}h`);
485
577
 
578
+ const modulesSourcemap = javascript?.sourcemapPath || sourcemapPath;
486
579
  try {
487
580
  const files = {files: fileManifest(contentsDir)};
488
581
  const sealedManifest = () => {
489
582
  let modules = null;
490
583
  try {
491
- modules = sourcemapPath && fs.existsSync(sourcemapPath) ? JSON.parse(fs.readFileSync(sourcemapPath, 'utf8')).sources || null : null;
584
+ modules = modulesSourcemap && fs.existsSync(modulesSourcemap) ? JSON.parse(fs.readFileSync(modulesSourcemap, 'utf8')).sources || null : null;
492
585
  } catch {
493
586
  modules = null;
494
587
  }
@@ -500,50 +593,56 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
500
593
  } catch (err) {
501
594
  console.log(`• file list not recorded: ${err.message}`);
502
595
  }
503
- if (sourcemapPath && fs.existsSync(sourcemapPath)) {
596
+ const sourcemaps = [
597
+ {mapPath: sourcemapPath, hash: packageHash, name: hermes ? 'bytecode source map' : 'source map'},
598
+ ...(hermes ? [{mapPath: javascript.sourcemapPath, hash: javascript.packageHash, name: 'JavaScript copy source map', jsCopy: true}] : []),
599
+ ];
600
+ for (const {mapPath, hash, name, jsCopy} of sourcemaps) {
601
+ if (!mapPath || !fs.existsSync(mapPath)) continue;
504
602
  try {
505
- const plainMap = fs.readFileSync(sourcemapPath);
506
- const map = sealing ? Buffer.from(await sealArtifact(privateBundles, app, packageHash, plainMap, 'sourcemap')) : plainMap;
603
+ const plainMap = fs.readFileSync(mapPath);
604
+ const map = sealing ? Buffer.from(await sealArtifact(privateBundles, app, hash, plainMap, 'sourcemap')) : plainMap;
507
605
  await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/sourcemap`, {
508
606
  method: 'POST',
509
607
  raw: true,
510
608
  optional: true,
511
609
  body: map,
512
- onUploadProgress: uploadProgress(`uploading ${(map.length / 1e6).toFixed(1)}MB source map`),
513
- headers: sealing ? sealedHeaders : {'content-type': 'application/json'},
610
+ onUploadProgress: uploadProgress(`uploading ${(map.length / 1e6).toFixed(1)}MB ${name}`),
611
+ headers: {...(sealing ? sealedHeaders : {'content-type': 'application/json'}), ...(jsCopy ? {'x-package-hash': hash} : {})},
514
612
  });
515
- console.log(sealing ? '• source map uploaded, encrypted: unlock it in the dashboard or with pulsar changes' : '• source map uploaded: crash stacks for this release will show your source files');
613
+ console.log(sealing ? `• ${name} uploaded, encrypted: unlock it in the dashboard or with pulsar changes` : `• ${name} uploaded: crash stacks for this release will show your source files`);
516
614
  } catch (err) {
517
- console.log(`• source map not uploaded: ${err.message}`);
615
+ console.log(`• ${name} not uploaded: ${err.message}`);
518
616
  }
519
617
  }
520
618
 
521
- if (!args.includes('--no-diff') && prevLatest && prevLatest.packageHash && prevLatest.packageHash !== packageHash) {
522
- try {
523
- const {apiUrl} = loadConfig();
524
- const baseFile = prevLatest.encrypted && prevLatest.blobKey ? prevLatest.blobKey.slice(app.id.length + 1) : `${prevLatest.packageHash}.zip`;
525
- let baseZip = await fetchBlob(apiUrl, app.id, baseFile);
526
- if (prevLatest.encrypted) {
527
- if (!privateBundles?.keys.length) throw new Error(`${prevLatest.label} is private and no bundle key was given`);
528
- baseZip = await openArtifact(privateBundles.keys, baseZip, {appId: app.id, packageHash: prevLatest.packageHash, kind: 'full'});
619
+ if (!args.includes('--no-diff')) {
620
+ for (const base of diffBases(app, prevLatest, packageHash)) {
621
+ try {
622
+ const {apiUrl} = loadConfig();
623
+ let baseZip = await fetchBlob(apiUrl, app.id, base.file);
624
+ if (prevLatest.encrypted) {
625
+ if (!privateBundles?.keys.length) throw new Error(`${prevLatest.label} is private and no bundle key was given`);
626
+ baseZip = await openArtifact(privateBundles.keys, baseZip, {appId: app.id, packageHash: base.packageHash, kind: 'full'});
627
+ }
628
+ const diffDir = await buildDiffPackage(baseZip, contentsDir);
629
+ const plainDiff = fs.readFileSync(zipContents(diffDir));
630
+ const diffZip = sealing
631
+ ? Buffer.from(await sealArtifact(privateBundles, app, packageHash, plainDiff, 'diff', {baseHash: base.packageHash}))
632
+ : plainDiff;
633
+ await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/diff`, {
634
+ method: 'POST',
635
+ raw: true,
636
+ optional: true,
637
+ body: diffZip,
638
+ onUploadProgress: uploadProgress(`uploading ${(diffZip.length / 1e6).toFixed(1)}MB diff`),
639
+ headers: {...(sealing ? sealedHeaders : {'content-type': 'application/zip'}), 'x-base-hash': base.packageHash},
640
+ });
641
+ const saved = Math.round((1 - diffZip.length / zip.length) * 100);
642
+ console.log(`• diff vs ${base.label}: ${(diffZip.length / 1e3).toFixed(0)} KB (${saved}% smaller)`);
643
+ } catch (err) {
644
+ console.log(`• diff ${base.jsCopy ? `vs ${base.label} ` : ''}skipped (full bundle still serves): ${err.message}`);
529
645
  }
530
- const diffDir = await buildDiffPackage(baseZip, contentsDir);
531
- const plainDiff = fs.readFileSync(zipContents(diffDir));
532
- const diffZip = sealing
533
- ? Buffer.from(await sealArtifact(privateBundles, app, packageHash, plainDiff, 'diff', {baseHash: prevLatest.packageHash}))
534
- : plainDiff;
535
- await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/diff`, {
536
- method: 'POST',
537
- raw: true,
538
- optional: true,
539
- body: diffZip,
540
- onUploadProgress: uploadProgress(`uploading ${(diffZip.length / 1e6).toFixed(1)}MB diff`),
541
- headers: {...(sealing ? sealedHeaders : {'content-type': 'application/zip'}), 'x-base-hash': prevLatest.packageHash},
542
- });
543
- const saved = Math.round((1 - diffZip.length / zip.length) * 100);
544
- console.log(`• diff vs ${prevLatest.label}: ${(diffZip.length / 1e3).toFixed(0)} KB (${saved}% smaller)`);
545
- } catch (err) {
546
- console.log(`• diff skipped (full bundle still serves): ${err.message}`);
547
646
  }
548
647
  }
549
648
  return release;
@@ -565,7 +664,19 @@ async function checkPrivateBeforeBuild(apps, args) {
565
664
  }
566
665
  }
567
666
 
568
- function buildOnce(args) {
667
+ function hermesCompiler(args, projectRoot = process.cwd()) {
668
+ const platform = getFlag(args, 'platform', 'ios');
669
+ const choice = hermesChoice(args, projectRoot, platform);
670
+ if (choice.error) die(`${choice.error}. Nothing was uploaded.`);
671
+ if (!choice.enabled) return null;
672
+ const hermesc = findHermesc(projectRoot);
673
+ if (!hermesc) {
674
+ die(`Hermes is on for ${platform}, but no Hermes compiler was found in node_modules (hermes-compiler/hermesc or react-native/sdks/hermesc). Install your dependencies, or pass --no-hermes to release JavaScript. Nothing was uploaded.`);
675
+ }
676
+ return {hermesc, composeScript: findComposeScript(projectRoot)};
677
+ }
678
+
679
+ function buildOnce(args, compiler = null) {
569
680
  const platform = getFlag(args, 'platform', 'ios');
570
681
  const localKey = localSigningKey(args);
571
682
  const contentsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pulsar-build-'));
@@ -573,20 +684,46 @@ function buildOnce(args) {
573
684
  bundle(platform, contentsDir, sourcemapPath);
574
685
  const packageHash = computePackageHash(contentsDir);
575
686
  console.log(`• hash ${packageHash.slice(0, 12)}…`);
576
- return {contentsDir, packageHash, localKey, sourcemapPath};
687
+ if (!compiler) return {contentsDir, packageHash, localKey, sourcemapPath};
688
+ const sourceDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pulsar-hermes-source-'));
689
+ const sourceMapPath = sourcemapPath ? `${sourceDir}.map` : null;
690
+ bundle(platform, sourceDir, sourceMapPath, {forHermes: true});
691
+ console.log(`• compiling Hermes bytecode with ${path.relative(process.cwd(), compiler.hermesc) || compiler.hermesc}…`);
692
+ let bytecode;
693
+ let compileError = null;
694
+ try {
695
+ bytecode = buildBytecode(compiler, {contentsDir: sourceDir, sourcemapPath: sourceMapPath}, bundleFileName(platform));
696
+ } catch (err) {
697
+ compileError = err;
698
+ }
699
+ fs.rmSync(sourceDir, {recursive: true, force: true});
700
+ if (sourceMapPath) fs.rmSync(sourceMapPath, {force: true});
701
+ if (compileError) die(`${compileError.message}\nPass --no-hermes to release JavaScript instead. Nothing was uploaded.`);
702
+ if (bytecode.sourcemapError) console.log(`⚠ bytecode source map not composed (${bytecode.sourcemapError}): crash stacks from bytecode won't show your source files`);
703
+ const bytecodeHash = computePackageHash(bytecode.contentsDir);
704
+ console.log(`• Hermes bytecode v${bytecode.bytecodeVersion}, hash ${bytecodeHash.slice(0, 12)}…; the minified JavaScript build above is its JavaScript copy`);
705
+ return {
706
+ contentsDir: bytecode.contentsDir,
707
+ packageHash: bytecodeHash,
708
+ localKey,
709
+ sourcemapPath: bytecode.sourcemapPath,
710
+ hermes: {bytecodeVersion: bytecode.bytecodeVersion},
711
+ javascript: {contentsDir, packageHash, sourcemapPath},
712
+ };
577
713
  }
578
714
 
579
715
  async function cmdRelease(args) {
580
716
  const [nameOrId, deployment = 'Staging'] = args;
581
- if (!nameOrId) die('Usage: pulsar release <app> <Staging|Production> --platform ios|android --target <ver> [--mandatory] [--disabled] [--rollout N] [--schedule +6h|ISO] [--ramp 100@48] [--from v6,ota,binary] [--devices id1,id2,...] [--device-models model1;model2] [--users u1,u2] [--private-key key.pem] [--bundle-key key.txt] [--plain-copy-for-old-builds | --plain | --only-older-builds] [--no-diff] [--no-sourcemap] [--max-growth <percent>] [--description "..."]');
717
+ if (!nameOrId) die('Usage: pulsar release <app> <Staging|Production> --platform ios|android --target <ver> [--mandatory] [--disabled] [--rollout N] [--schedule +6h|ISO] [--ramp 100@48] [--from v6,ota,binary] [--devices id1,id2,...] [--device-models model1;model2] [--users u1,u2] [--private-key key.pem] [--bundle-key key.txt] [--plain-copy-for-old-builds | --plain | --only-older-builds] [--hermes | --no-hermes] [--no-diff] [--no-sourcemap] [--max-growth <percent>] [--description "..."]');
582
718
  if (!getFlag(args, 'target')) die('--target <binary version> is required (e.g. --target 1.0.0)');
583
719
  const app = await resolveApp(nameOrId, getFlag(args, 'platform', 'ios'));
584
720
  if (app.os !== getFlag(args, 'platform', 'ios')) {
585
721
  console.log(`• note: resolved app "${app.name}" is ${app.os}; bundling ${getFlag(args, 'platform', 'ios')}`);
586
722
  }
587
723
  await checkPrivateBeforeBuild([app], args);
588
- const {contentsDir, packageHash, localKey, sourcemapPath} = buildOnce(args);
589
- await pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported: true});
724
+ const compiler = hermesCompiler(args);
725
+ const {contentsDir, packageHash, localKey, sourcemapPath, hermes, javascript} = buildOnce(args, compiler);
726
+ await pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported: true, hermes, javascript});
590
727
  }
591
728
 
592
729
  // Release the same built bundle to several apps at once (shared-codebase / white-label fleets).
@@ -612,17 +749,26 @@ async function cmdReleaseTrain(args) {
612
749
  if (!apps.length) die(`No ${platform} apps matched.`);
613
750
 
614
751
  await checkPrivateBeforeBuild(apps, args);
615
- const {contentsDir, packageHash, localKey, sourcemapPath} = buildOnce(args);
752
+ const compiler = hermesCompiler(args);
753
+ const {contentsDir, packageHash, localKey, sourcemapPath, hermes, javascript} = buildOnce(args, compiler);
616
754
  console.log(`• release train → ${apps.length} app(s): ${apps.map((app) => app.name).join(', ')}`);
617
755
  for (const app of apps) {
618
756
  try {
619
- await pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported: true});
757
+ await pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported: true, hermes, javascript});
620
758
  } catch (err) {
621
759
  console.log(`✗ ${app.name}: ${err.message}`);
622
760
  }
623
761
  }
624
762
  }
625
763
 
764
+ const bytecodeTag = (release) => (release.hermes ? ` [bytecode v${release.hermes.bytecodeVersion}${release.jsCopy ? ' + JS copy' : ', no JS copy'}]` : '');
765
+
766
+ function warnMissingJsCopy(release) {
767
+ if (!release?.hermes || release.jsCopy) return;
768
+ const version = release.hermes.bytecodeVersion;
769
+ console.log(`⚠ ${release.label} is Hermes bytecode v${version} without its JavaScript copy: only builds that run bytecode v${version} get it, every other build stays on its current release`);
770
+ }
771
+
626
772
  async function cmdPromote(args) {
627
773
  const [nameOrId, from = 'Staging', to = 'Production'] = args;
628
774
  const app = await resolveApp(nameOrId, getFlag(args, 'platform'));
@@ -631,6 +777,7 @@ async function cmdPromote(args) {
631
777
  body: {to, rollout: Number(getFlag(args, 'rollout', '100'))},
632
778
  });
633
779
  console.log(`✓ promoted ${from} → ${to} as ${release.label}`);
780
+ warnMissingJsCopy(release);
634
781
  }
635
782
 
636
783
  async function cmdRollback(args) {
@@ -638,6 +785,7 @@ async function cmdRollback(args) {
638
785
  const app = await resolveApp(nameOrId, getFlag(args, 'platform'));
639
786
  const release = await api(`/apps/${app.id}/deployments/${deployment}/rollback`, {method: 'POST'});
640
787
  console.log(`✓ rolled back ${app.name}/${deployment} → ${release.label}`);
788
+ warnMissingJsCopy(release);
641
789
  }
642
790
 
643
791
  async function cmdDeployment(args) {
@@ -664,7 +812,7 @@ async function cmdHistory(args) {
664
812
  if (!releases.length) return console.log('(no releases)');
665
813
  for (const release of [...releases].reverse()) {
666
814
  const privacy = release.encrypted ? ` [private${release.plainCopy ? ' + plain copy' : ''}]` : release.olderBuildsOnly ? ' [plain, older builds only]' : release.plainOnPurpose ? ' [plain]' : '';
667
- const flags = `${release.isMandatory ? ' [mandatory]' : ''}${release.isDisabled ? ' [disabled]' : ''}${privacy}`;
815
+ const flags = `${release.isMandatory ? ' [mandatory]' : ''}${release.isDisabled ? ' [disabled]' : ''}${privacy}${bytecodeTag(release)}`;
668
816
  const rollout = release.currentRollout ?? release.rollout;
669
817
  const state = release.state && release.state !== 'live' ? ` [${release.state}]` : '';
670
818
  const when = release.startsAt ? ` starts ${new Date(release.startsAt).toLocaleString()}` : '';
@@ -747,7 +895,7 @@ async function cmdKeys(args) {
747
895
  console.log(`✓ wrote ${Object.keys(vars).length} key(s) to ${target} (${written.size} updated, ${missing.length} added)`);
748
896
  }
749
897
 
750
- export {saveConfig, browserLogin, signCodePushJWT, SIGNATURE_PATH, api, die, getFlag, loadConfig, pushBuiltRelease, splitList, resolveApp};
898
+ export {saveConfig, browserLogin, signCodePushJWT, SIGNATURE_PATH, api, die, getFlag, loadConfig, pushBuiltRelease, splitList, resolveApp, growthChecks, buildOnce};
751
899
 
752
900
  // Only dispatch when run as the CLI — importing the module (e.g. from tests) must not execute a command.
753
901
  // Compare real paths: a global install runs through a bin symlink, so argv[1] is not this file's path.