@novacraft-engineering/pulsar-cli 1.5.0 → 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 +49 -1
- package/hash.js +1 -1
- package/hermes.js +131 -0
- package/migrate.js +6 -1
- package/package.json +3 -2
- package/private.js +2 -1
- package/pulsar.js +229 -77
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
|
|
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
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);
|
|
@@ -115,7 +118,9 @@ async function migrateApp({source, sourceApp, org, pulsarApps, args, dryRun, row
|
|
|
115
118
|
}
|
|
116
119
|
row.sourceKey = sourceDeployment.key || '-';
|
|
117
120
|
|
|
118
|
-
|
|
121
|
+
const existingDeployment = pulsarApp?.deployments?.[deploymentName];
|
|
122
|
+
if (existingDeployment && !existingDeployment.key) throw new Error('Deployment keys are hidden for this login. Run "pulsar login" again, then retry.');
|
|
123
|
+
row.pulsarKey = existingDeployment?.key;
|
|
119
124
|
if (!row.pulsarKey && dryRun) row.pulsarKey = '(new)';
|
|
120
125
|
else if (!row.pulsarKey) {
|
|
121
126
|
({key: row.pulsarKey} = await api(`/apps/${pulsarApp.id}/deployments`, {method: 'POST', body: {name: deploymentName}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novacraft-engineering/pulsar-cli",
|
|
3
|
-
"version": "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
|
|
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
|
|
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(),
|
|
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
|
}
|
|
@@ -351,25 +374,28 @@ async function cmdLogin(args) {
|
|
|
351
374
|
const email = await prompt('Email: ');
|
|
352
375
|
const password = await prompt('Password: ', true);
|
|
353
376
|
const deviceId = loadConfig().deviceId || crypto.randomBytes(16).toString('hex');
|
|
354
|
-
const {token, user} = await api('/auth/login', {method: 'POST', body: {email, password}, headers: {'x-device-id': deviceId}, allowAnonymous: true});
|
|
377
|
+
const {token, user} = await api('/auth/login', {method: 'POST', body: {email, password, client: 'cli'}, headers: {'x-device-id': deviceId}, allowAnonymous: true});
|
|
355
378
|
saveConfig({apiUrl, token, deviceId});
|
|
356
379
|
console.log(`✓ logged in as ${user.email} (${user.platformRole})`);
|
|
357
380
|
}
|
|
358
381
|
|
|
382
|
+
const HIDDEN_KEYS = 'Deployment keys are hidden for this login. Run "pulsar login" again to see them.';
|
|
383
|
+
const shownKey = (deployment) => deployment.key || `${deployment.keyHint || ''}•••• (hidden: run "pulsar login" again)`;
|
|
384
|
+
|
|
359
385
|
async function cmdApps() {
|
|
360
386
|
const apps = await api('/apps');
|
|
361
387
|
if (!apps.length) return console.log('(no apps)');
|
|
362
388
|
for (const app of apps) {
|
|
363
389
|
console.log(`\n${app.name} [${app.os}] ${app.id}`);
|
|
364
390
|
for (const [name, deployment] of Object.entries(app.deployments)) {
|
|
365
|
-
console.log(` ${name.padEnd(11)} key: ${deployment
|
|
391
|
+
console.log(` ${name.padEnd(11)} key: ${shownKey(deployment)}`);
|
|
366
392
|
}
|
|
367
393
|
}
|
|
368
394
|
}
|
|
369
395
|
|
|
370
396
|
// Sign for this app — with a local key when one was given, otherwise by asking Pulsar, which signs for
|
|
371
397
|
// anyone allowed to publish here. Each app can hold a different key, so a release train re-signs.
|
|
372
|
-
async function signForApp(app, deployment, contentsDir, packageHash, localKey) {
|
|
398
|
+
async function signForApp(app, deployment, contentsDir, packageHash, localKey, subject = '') {
|
|
373
399
|
const signaturePath = path.join(contentsDir, SIGNATURE_PATH);
|
|
374
400
|
fs.rmSync(signaturePath, {force: true});
|
|
375
401
|
let signature = null;
|
|
@@ -383,45 +409,88 @@ async function signForApp(app, deployment, contentsDir, packageHash, localKey) {
|
|
|
383
409
|
({signature} = await api(`/apps/${app.id}/deployments/${deployment}/sign`, {method: 'POST', body: {packageHash}}));
|
|
384
410
|
}
|
|
385
411
|
if (!signature) {
|
|
386
|
-
console.log(`• ${app.name} has no signing key — uploading unsigned`);
|
|
412
|
+
console.log(`• ${app.name} has no signing key — uploading${subject ? ` ${subject}` : ''} unsigned`);
|
|
387
413
|
return;
|
|
388
414
|
}
|
|
389
415
|
fs.mkdirSync(path.dirname(signaturePath), {recursive: true});
|
|
390
416
|
fs.writeFileSync(signaturePath, signature);
|
|
391
|
-
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);
|
|
392
447
|
}
|
|
393
448
|
|
|
394
449
|
// Sign and push an already-built bundle to one app's deployment, then generate and upload a
|
|
395
450
|
// differential patch against whatever that deployment was serving.
|
|
396
|
-
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.');
|
|
397
453
|
const privateBundles = await privateContext(app, args, localKey);
|
|
398
454
|
const sealing = Boolean(privateBundles) && !privateBundles.plain;
|
|
399
455
|
const plainCopy = sealing && args.includes('--plain-copy-for-old-builds');
|
|
400
456
|
if (privateBundles && !reachReported) reportReach(privateBundles, {mandatory: args.includes('--mandatory'), plainCopy});
|
|
401
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);
|
|
402
460
|
const plainZip = fs.readFileSync(zipContents(contentsDir));
|
|
403
|
-
const zip =
|
|
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;
|
|
404
464
|
let prevLatest = null;
|
|
405
465
|
try {
|
|
406
466
|
const existing = await api(`/apps/${app.id}/deployments/${deployment}/releases`, {optional: true});
|
|
407
467
|
prevLatest = [...existing].reverse().find((entry) => !entry.isDisabled) || existing[existing.length - 1] || null;
|
|
408
468
|
} catch {}
|
|
469
|
+
const target = getFlag(args, 'target');
|
|
470
|
+
let binaries = null;
|
|
409
471
|
try {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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);
|
|
421
485
|
}
|
|
422
486
|
const maxGrowth = getFlag(args, 'max-growth');
|
|
423
|
-
|
|
424
|
-
|
|
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
|
+
}
|
|
425
494
|
}
|
|
426
495
|
|
|
427
496
|
const startsAt = parseSchedule(getFlag(args, 'schedule'));
|
|
@@ -430,14 +499,15 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
430
499
|
method: 'POST',
|
|
431
500
|
raw: true,
|
|
432
501
|
body: zip,
|
|
433
|
-
onUploadProgress: uploadProgress(`uploading ${(zip.length / 1e6).toFixed(1)}MB bundle`),
|
|
502
|
+
onUploadProgress: uploadProgress(`uploading ${(zip.length / 1e6).toFixed(1)}MB ${hermes ? 'bytecode ' : ''}bundle`),
|
|
434
503
|
headers: {
|
|
435
504
|
...(sealing
|
|
436
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')}
|
|
437
506
|
: {'content-type': 'application/zip'}),
|
|
438
507
|
...(privateBundles?.plain === 'all' ? {'x-plain': '1'} : {}),
|
|
439
508
|
...(privateBundles?.plain === 'older' ? {'x-audience': 'older-builds'} : {}),
|
|
440
|
-
'x-
|
|
509
|
+
...(hermes ? {'x-hermes-bytecode-version': String(hermes.bytecodeVersion)} : {}),
|
|
510
|
+
'x-app-version': target,
|
|
441
511
|
'x-package-hash': packageHash,
|
|
442
512
|
'x-is-mandatory': String(args.includes('--mandatory')),
|
|
443
513
|
'x-disabled': String(args.includes('--disabled')),
|
|
@@ -452,22 +522,47 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
452
522
|
...(ramp ? {'x-rollout-to': String(ramp.to), 'x-rollout-hours': String(ramp.hours)} : {}),
|
|
453
523
|
},
|
|
454
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
|
+
}
|
|
455
529
|
const scopes = [
|
|
456
530
|
release.clientIds?.length ? `${release.clientIds.length} device id(s)` : null,
|
|
457
531
|
release.targetDevices?.length ? `${release.targetDevices.length} device model(s)` : null,
|
|
458
532
|
release.targetUserIds?.length ? `${release.targetUserIds.length} user(s)` : null,
|
|
459
533
|
release.targetFromLabels?.length ? `devices on ${release.targetFromLabels.join('/')}` : null,
|
|
460
534
|
].filter(Boolean);
|
|
461
|
-
const
|
|
535
|
+
const reachText = scopes.length ? scopes.join(' + ') : `${release.rollout}% of devices`;
|
|
462
536
|
const privacy = release.encrypted ? ' (private)' : release.olderBuildsOnly ? ' (plain, older builds only)' : privateBundles ? ' (plain)' : '';
|
|
463
|
-
|
|
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
|
+
}
|
|
464
559
|
if (plainCopy) {
|
|
465
560
|
await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/plain-copy`, {
|
|
466
561
|
method: 'POST',
|
|
467
562
|
raw: true,
|
|
468
|
-
body: plainZip,
|
|
469
|
-
onUploadProgress: uploadProgress(`uploading ${(plainZip.length / 1e6).toFixed(1)}MB plain copy for older builds`),
|
|
470
|
-
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} : {})},
|
|
471
566
|
});
|
|
472
567
|
console.log('• plain copy uploaded: older builds get this release too, and Pulsar can read that copy');
|
|
473
568
|
}
|
|
@@ -480,12 +575,13 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
480
575
|
if (release.startsAt) console.log(` scheduled — goes live ${new Date(release.startsAt).toLocaleString()}`);
|
|
481
576
|
if (release.rolloutRamp) console.log(` gradual rollout — ${release.rollout}% to ${release.rolloutRamp.to}% over ${release.rolloutRamp.hours}h`);
|
|
482
577
|
|
|
578
|
+
const modulesSourcemap = javascript?.sourcemapPath || sourcemapPath;
|
|
483
579
|
try {
|
|
484
580
|
const files = {files: fileManifest(contentsDir)};
|
|
485
581
|
const sealedManifest = () => {
|
|
486
582
|
let modules = null;
|
|
487
583
|
try {
|
|
488
|
-
modules =
|
|
584
|
+
modules = modulesSourcemap && fs.existsSync(modulesSourcemap) ? JSON.parse(fs.readFileSync(modulesSourcemap, 'utf8')).sources || null : null;
|
|
489
585
|
} catch {
|
|
490
586
|
modules = null;
|
|
491
587
|
}
|
|
@@ -497,50 +593,56 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
497
593
|
} catch (err) {
|
|
498
594
|
console.log(`• file list not recorded: ${err.message}`);
|
|
499
595
|
}
|
|
500
|
-
|
|
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;
|
|
501
602
|
try {
|
|
502
|
-
const plainMap = fs.readFileSync(
|
|
503
|
-
const map = sealing ? Buffer.from(await sealArtifact(privateBundles, app,
|
|
603
|
+
const plainMap = fs.readFileSync(mapPath);
|
|
604
|
+
const map = sealing ? Buffer.from(await sealArtifact(privateBundles, app, hash, plainMap, 'sourcemap')) : plainMap;
|
|
504
605
|
await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/sourcemap`, {
|
|
505
606
|
method: 'POST',
|
|
506
607
|
raw: true,
|
|
507
608
|
optional: true,
|
|
508
609
|
body: map,
|
|
509
|
-
onUploadProgress: uploadProgress(`uploading ${(map.length / 1e6).toFixed(1)}MB
|
|
510
|
-
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} : {})},
|
|
511
612
|
});
|
|
512
|
-
console.log(sealing ?
|
|
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`);
|
|
513
614
|
} catch (err) {
|
|
514
|
-
console.log(`•
|
|
615
|
+
console.log(`• ${name} not uploaded: ${err.message}`);
|
|
515
616
|
}
|
|
516
617
|
}
|
|
517
618
|
|
|
518
|
-
if (!args.includes('--no-diff')
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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}`);
|
|
526
645
|
}
|
|
527
|
-
const diffDir = await buildDiffPackage(baseZip, contentsDir);
|
|
528
|
-
const plainDiff = fs.readFileSync(zipContents(diffDir));
|
|
529
|
-
const diffZip = sealing
|
|
530
|
-
? Buffer.from(await sealArtifact(privateBundles, app, packageHash, plainDiff, 'diff', {baseHash: prevLatest.packageHash}))
|
|
531
|
-
: plainDiff;
|
|
532
|
-
await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/diff`, {
|
|
533
|
-
method: 'POST',
|
|
534
|
-
raw: true,
|
|
535
|
-
optional: true,
|
|
536
|
-
body: diffZip,
|
|
537
|
-
onUploadProgress: uploadProgress(`uploading ${(diffZip.length / 1e6).toFixed(1)}MB diff`),
|
|
538
|
-
headers: {...(sealing ? sealedHeaders : {'content-type': 'application/zip'}), 'x-base-hash': prevLatest.packageHash},
|
|
539
|
-
});
|
|
540
|
-
const saved = Math.round((1 - diffZip.length / zip.length) * 100);
|
|
541
|
-
console.log(`• diff vs ${prevLatest.label}: ${(diffZip.length / 1e3).toFixed(0)} KB (${saved}% smaller)`);
|
|
542
|
-
} catch (err) {
|
|
543
|
-
console.log(`• diff skipped (full bundle still serves): ${err.message}`);
|
|
544
646
|
}
|
|
545
647
|
}
|
|
546
648
|
return release;
|
|
@@ -562,7 +664,19 @@ async function checkPrivateBeforeBuild(apps, args) {
|
|
|
562
664
|
}
|
|
563
665
|
}
|
|
564
666
|
|
|
565
|
-
function
|
|
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) {
|
|
566
680
|
const platform = getFlag(args, 'platform', 'ios');
|
|
567
681
|
const localKey = localSigningKey(args);
|
|
568
682
|
const contentsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pulsar-build-'));
|
|
@@ -570,20 +684,46 @@ function buildOnce(args) {
|
|
|
570
684
|
bundle(platform, contentsDir, sourcemapPath);
|
|
571
685
|
const packageHash = computePackageHash(contentsDir);
|
|
572
686
|
console.log(`• hash ${packageHash.slice(0, 12)}…`);
|
|
573
|
-
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
|
+
};
|
|
574
713
|
}
|
|
575
714
|
|
|
576
715
|
async function cmdRelease(args) {
|
|
577
716
|
const [nameOrId, deployment = 'Staging'] = args;
|
|
578
|
-
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 "..."]');
|
|
579
718
|
if (!getFlag(args, 'target')) die('--target <binary version> is required (e.g. --target 1.0.0)');
|
|
580
719
|
const app = await resolveApp(nameOrId, getFlag(args, 'platform', 'ios'));
|
|
581
720
|
if (app.os !== getFlag(args, 'platform', 'ios')) {
|
|
582
721
|
console.log(`• note: resolved app "${app.name}" is ${app.os}; bundling ${getFlag(args, 'platform', 'ios')}`);
|
|
583
722
|
}
|
|
584
723
|
await checkPrivateBeforeBuild([app], args);
|
|
585
|
-
const
|
|
586
|
-
|
|
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});
|
|
587
727
|
}
|
|
588
728
|
|
|
589
729
|
// Release the same built bundle to several apps at once (shared-codebase / white-label fleets).
|
|
@@ -609,17 +749,26 @@ async function cmdReleaseTrain(args) {
|
|
|
609
749
|
if (!apps.length) die(`No ${platform} apps matched.`);
|
|
610
750
|
|
|
611
751
|
await checkPrivateBeforeBuild(apps, args);
|
|
612
|
-
const
|
|
752
|
+
const compiler = hermesCompiler(args);
|
|
753
|
+
const {contentsDir, packageHash, localKey, sourcemapPath, hermes, javascript} = buildOnce(args, compiler);
|
|
613
754
|
console.log(`• release train → ${apps.length} app(s): ${apps.map((app) => app.name).join(', ')}`);
|
|
614
755
|
for (const app of apps) {
|
|
615
756
|
try {
|
|
616
|
-
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});
|
|
617
758
|
} catch (err) {
|
|
618
759
|
console.log(`✗ ${app.name}: ${err.message}`);
|
|
619
760
|
}
|
|
620
761
|
}
|
|
621
762
|
}
|
|
622
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
|
+
|
|
623
772
|
async function cmdPromote(args) {
|
|
624
773
|
const [nameOrId, from = 'Staging', to = 'Production'] = args;
|
|
625
774
|
const app = await resolveApp(nameOrId, getFlag(args, 'platform'));
|
|
@@ -628,6 +777,7 @@ async function cmdPromote(args) {
|
|
|
628
777
|
body: {to, rollout: Number(getFlag(args, 'rollout', '100'))},
|
|
629
778
|
});
|
|
630
779
|
console.log(`✓ promoted ${from} → ${to} as ${release.label}`);
|
|
780
|
+
warnMissingJsCopy(release);
|
|
631
781
|
}
|
|
632
782
|
|
|
633
783
|
async function cmdRollback(args) {
|
|
@@ -635,6 +785,7 @@ async function cmdRollback(args) {
|
|
|
635
785
|
const app = await resolveApp(nameOrId, getFlag(args, 'platform'));
|
|
636
786
|
const release = await api(`/apps/${app.id}/deployments/${deployment}/rollback`, {method: 'POST'});
|
|
637
787
|
console.log(`✓ rolled back ${app.name}/${deployment} → ${release.label}`);
|
|
788
|
+
warnMissingJsCopy(release);
|
|
638
789
|
}
|
|
639
790
|
|
|
640
791
|
async function cmdDeployment(args) {
|
|
@@ -643,11 +794,11 @@ async function cmdDeployment(args) {
|
|
|
643
794
|
if (sub === 'add') {
|
|
644
795
|
if (!depName) die('Usage: pulsar deployment add <app> <name>');
|
|
645
796
|
const created = await api(`/apps/${app.id}/deployments`, {method: 'POST', body: {name: depName}});
|
|
646
|
-
console.log(`✓ added ${created.name}\n key: ${created
|
|
797
|
+
console.log(`✓ added ${created.name}\n key: ${shownKey(created)}`);
|
|
647
798
|
} else if (sub === 'ls' || sub === 'list') {
|
|
648
799
|
const full = await api(`/apps/${app.id}`);
|
|
649
800
|
for (const [name, deployment] of Object.entries(full.deployments)) {
|
|
650
|
-
console.log(` ${name.padEnd(12)} ${deployment
|
|
801
|
+
console.log(` ${name.padEnd(12)} ${shownKey(deployment)}`);
|
|
651
802
|
}
|
|
652
803
|
} else {
|
|
653
804
|
die('Usage: pulsar deployment <add|ls> <app> [name]');
|
|
@@ -661,7 +812,7 @@ async function cmdHistory(args) {
|
|
|
661
812
|
if (!releases.length) return console.log('(no releases)');
|
|
662
813
|
for (const release of [...releases].reverse()) {
|
|
663
814
|
const privacy = release.encrypted ? ` [private${release.plainCopy ? ' + plain copy' : ''}]` : release.olderBuildsOnly ? ' [plain, older builds only]' : release.plainOnPurpose ? ' [plain]' : '';
|
|
664
|
-
const flags = `${release.isMandatory ? ' [mandatory]' : ''}${release.isDisabled ? ' [disabled]' : ''}${privacy}`;
|
|
815
|
+
const flags = `${release.isMandatory ? ' [mandatory]' : ''}${release.isDisabled ? ' [disabled]' : ''}${privacy}${bytecodeTag(release)}`;
|
|
665
816
|
const rollout = release.currentRollout ?? release.rollout;
|
|
666
817
|
const state = release.state && release.state !== 'live' ? ` [${release.state}]` : '';
|
|
667
818
|
const when = release.startsAt ? ` starts ${new Date(release.startsAt).toLocaleString()}` : '';
|
|
@@ -707,6 +858,7 @@ async function cmdKeys(args) {
|
|
|
707
858
|
const matches = apps.filter((app) => app.name.toLowerCase().startsWith(`${project.toLowerCase()}-`));
|
|
708
859
|
if (!matches.length) die(`No apps for project "${project}". Known: ${apps.map((app) => app.name).join(', ')}`);
|
|
709
860
|
|
|
861
|
+
if (matches.some((app) => Object.values(app.deployments || {}).some((deployment) => !deployment.key))) die(HIDDEN_KEYS);
|
|
710
862
|
const vars = {};
|
|
711
863
|
for (const app of matches) {
|
|
712
864
|
for (const deployment of ['Staging', 'Production']) {
|
|
@@ -743,7 +895,7 @@ async function cmdKeys(args) {
|
|
|
743
895
|
console.log(`✓ wrote ${Object.keys(vars).length} key(s) to ${target} (${written.size} updated, ${missing.length} added)`);
|
|
744
896
|
}
|
|
745
897
|
|
|
746
|
-
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};
|
|
747
899
|
|
|
748
900
|
// Only dispatch when run as the CLI — importing the module (e.g. from tests) must not execute a command.
|
|
749
901
|
// Compare real paths: a global install runs through a bin symlink, so argv[1] is not this file's path.
|