@novacraft-engineering/pulsar-cli 1.5.1 → 1.6.1
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 +136 -0
- package/migrate.js +7 -5
- package/package.json +4 -2
- package/private.js +2 -1
- package/pulsar.js +238 -83
- package/temp.js +58 -0
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,136 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {spawnSync} from 'node:child_process';
|
|
4
|
+
import {walk} from './hash.js';
|
|
5
|
+
import {exitIfInterrupted, makeTempDir, removeTemp, trackTemp} from './temp.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
|
+
exitIfInterrupted(result.signal);
|
|
98
|
+
if (result.error) throw new Error(`could not run ${hermesc}: ${result.error.message}`);
|
|
99
|
+
if (result.status !== 0) throw new Error(`hermesc failed:\n${diagnostics(result.stderr || result.stdout)}`);
|
|
100
|
+
const bytecodeVersion = fs.existsSync(outputPath) ? fileBytecodeVersion(outputPath) : null;
|
|
101
|
+
if (!bytecodeVersion) throw new Error('hermesc finished, but what it wrote is not Hermes bytecode');
|
|
102
|
+
const sourcemapPath = `${outputPath}.map`;
|
|
103
|
+
return {bytecodeVersion, sourcemapPath: sourcemap && fs.existsSync(sourcemapPath) ? sourcemapPath : null};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function composeSourcemaps(composeScript, packagerMapPath, compilerMapPath, outputPath) {
|
|
107
|
+
const result = spawnSync(process.execPath, [composeScript, packagerMapPath, compilerMapPath, '-o', outputPath], {encoding: 'utf8', maxBuffer: 64 * 1024 * 1024});
|
|
108
|
+
exitIfInterrupted(result.signal);
|
|
109
|
+
if (result.error) throw new Error(result.error.message);
|
|
110
|
+
if (result.status !== 0 || !fs.existsSync(outputPath)) throw new Error(diagnostics(result.stderr) || `exit code ${result.status}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function buildBytecode({hermesc, composeScript}, javascript, bundleName) {
|
|
114
|
+
const compilerDir = makeTempDir('pulsar-hermesc-');
|
|
115
|
+
try {
|
|
116
|
+
const compiledPath = path.join(compilerDir, bundleName);
|
|
117
|
+
const compiled = compileBytecode(hermesc, path.join(javascript.contentsDir, bundleName), compiledPath, {sourcemap: Boolean(javascript.sourcemapPath)});
|
|
118
|
+
const contentsDir = makeTempDir('pulsar-bytecode-');
|
|
119
|
+
fs.cpSync(javascript.contentsDir, contentsDir, {recursive: true});
|
|
120
|
+
fs.copyFileSync(compiledPath, path.join(contentsDir, bundleName));
|
|
121
|
+
let sourcemapPath = null;
|
|
122
|
+
let sourcemapError = null;
|
|
123
|
+
if (compiled.sourcemapPath) {
|
|
124
|
+
try {
|
|
125
|
+
if (!composeScript) throw new Error('react-native/scripts/compose-source-maps.js was not found in node_modules');
|
|
126
|
+
composeSourcemaps(composeScript, javascript.sourcemapPath, compiled.sourcemapPath, trackTemp(`${contentsDir}.map`));
|
|
127
|
+
sourcemapPath = `${contentsDir}.map`;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
sourcemapError = err.message;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {contentsDir, bytecodeVersion: compiled.bytecodeVersion, sourcemapPath, sourcemapError};
|
|
133
|
+
} finally {
|
|
134
|
+
removeTemp(compilerDir);
|
|
135
|
+
}
|
|
136
|
+
}
|
package/migrate.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
2
|
import path from 'node:path';
|
|
4
|
-
import {execFileSync} from 'node:child_process';
|
|
5
3
|
import {api, die, getFlag, loadConfig, pushBuiltRelease, splitList} from './pulsar.js';
|
|
6
4
|
import {computePackageHash} from './hash.js';
|
|
5
|
+
import {bundleBytecodeIn} from './hermes.js';
|
|
6
|
+
import {execFileSyncInterruptible, makeTempDir, removeTemp} from './temp.js';
|
|
7
7
|
|
|
8
8
|
const USAGE = 'Usage: pulsar migrate --from <serverUrl> --access-key <key> [--apps A,B] [--org <name>] [--platform ios|android] [--releases latest|none] [--dry-run]';
|
|
9
9
|
|
|
@@ -38,7 +38,7 @@ async function migrateRelease({source, pulsarApp, deploymentName, sourcePackage,
|
|
|
38
38
|
if (!sourcePackage) return 'no release on source';
|
|
39
39
|
if (!sourcePackage.appVersion) return `not migrated: ${sourcePackage.label} has no target app version`;
|
|
40
40
|
if (dryRun) return `would re-release ${sourcePackage.label} (target ${sourcePackage.appVersion})`;
|
|
41
|
-
const workDir =
|
|
41
|
+
const workDir = makeTempDir('pulsar-migrate-');
|
|
42
42
|
const zipPath = path.join(workDir, 'source.zip');
|
|
43
43
|
const contentsDir = path.join(workDir, 'contents');
|
|
44
44
|
try {
|
|
@@ -48,10 +48,12 @@ async function migrateRelease({source, pulsarApp, deploymentName, sourcePackage,
|
|
|
48
48
|
if (!response.ok) throw new Error(`download failed (${response.status})`);
|
|
49
49
|
fs.writeFileSync(zipPath, Buffer.from(await response.arrayBuffer()));
|
|
50
50
|
try {
|
|
51
|
-
|
|
51
|
+
execFileSyncInterruptible('unzip', ['-qq', '-o', zipPath, '-d', contentsDir], {stdio: 'pipe'});
|
|
52
52
|
} catch {
|
|
53
53
|
throw new Error('downloaded bundle is not a readable zip');
|
|
54
54
|
}
|
|
55
|
+
const bytecodeVersion = bundleBytecodeIn(contentsDir);
|
|
56
|
+
if (bytecodeVersion) return `not migrated: ${sourcePackage.label} is Hermes bytecode v${bytecodeVersion}; release it again from source with pulsar release`;
|
|
55
57
|
const packageHash = computePackageHash(contentsDir);
|
|
56
58
|
const existing = await api(`/apps/${pulsarApp.id}/deployments/${deploymentName}/releases`);
|
|
57
59
|
const already = existing.find((entry) => entry.packageHash === packageHash);
|
|
@@ -75,7 +77,7 @@ async function migrateRelease({source, pulsarApp, deploymentName, sourcePackage,
|
|
|
75
77
|
} catch (err) {
|
|
76
78
|
return `not migrated: ${err.message}`;
|
|
77
79
|
} finally {
|
|
78
|
-
|
|
80
|
+
removeTemp(workDir);
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novacraft-engineering/pulsar-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
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,8 @@
|
|
|
11
11
|
"hash.js",
|
|
12
12
|
"migrate.js",
|
|
13
13
|
"private.js",
|
|
14
|
+
"hermes.js",
|
|
15
|
+
"temp.js",
|
|
14
16
|
"envelope.js",
|
|
15
17
|
"releaseCompare.js",
|
|
16
18
|
"README.md",
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
"node": ">=18"
|
|
31
33
|
},
|
|
32
34
|
"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"
|
|
35
|
+
"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 && node test/temp.test.js"
|
|
34
36
|
},
|
|
35
37
|
"keywords": [
|
|
36
38
|
"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,8 @@ 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';
|
|
14
|
+
import {execFileSyncInterruptible, makeTempDir, removeTemp, trackTemp} from './temp.js';
|
|
13
15
|
|
|
14
16
|
// Code signing: sign the package hash into an RS256 JWT the client verifies against its
|
|
15
17
|
// CodePushPublicKey (Info.plist). Both native SDKs read it from <update>/CodePush/.codepushrelease
|
|
@@ -56,6 +58,19 @@ function saveConfig(config) {
|
|
|
56
58
|
try { fs.chmodSync(CONFIG_FILE, 0o600); } catch { /* best-effort on pre-existing files */ }
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
const STALE_CONNECTION_CODES = new Set(['ECONNRESET', 'EPIPE', 'UND_ERR_SOCKET']);
|
|
62
|
+
|
|
63
|
+
// A build blocks the event loop, so the server can close the pooled keep-alive connection unseen
|
|
64
|
+
// and the next request lands on a dead socket. Only a GET is safe to send twice.
|
|
65
|
+
async function send(url, options) {
|
|
66
|
+
try {
|
|
67
|
+
return await fetch(url, options);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
if (options.method !== 'GET' || !STALE_CONNECTION_CODES.has(err?.cause?.code)) throw err;
|
|
70
|
+
return fetch(url, options);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
59
74
|
async function api(pathname, {method = 'GET', body, headers = {}, raw, allowAnonymous, onUploadProgress, optional} = {}) {
|
|
60
75
|
const {apiUrl, token} = loadConfig();
|
|
61
76
|
if (!apiUrl) die('No API url. Run: pulsar login <apiUrl>');
|
|
@@ -87,7 +102,7 @@ async function api(pathname, {method = 'GET', body, headers = {}, raw, allowAnon
|
|
|
87
102
|
});
|
|
88
103
|
options.duplex = 'half';
|
|
89
104
|
}
|
|
90
|
-
const response = await
|
|
105
|
+
const response = await send(apiUrl.replace(/\/$/, '') + pathname, options);
|
|
91
106
|
const text = await response.text();
|
|
92
107
|
// Check the status BEFORE parsing: an edge/proxy error (413, 502, 524) returns
|
|
93
108
|
// an HTML page, and parsing that first turned every such failure into an
|
|
@@ -99,7 +114,7 @@ async function api(pathname, {method = 'GET', body, headers = {}, raw, allowAnon
|
|
|
99
114
|
} catch {
|
|
100
115
|
detail = text.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 300);
|
|
101
116
|
}
|
|
102
|
-
if (optional) throw new Error(`${response.status} ${detail}`);
|
|
117
|
+
if (optional) throw Object.assign(new Error(`${response.status} ${detail}`), {status: response.status});
|
|
103
118
|
die(`${response.status} ${response.statusText}: ${detail}`);
|
|
104
119
|
}
|
|
105
120
|
try {
|
|
@@ -206,17 +221,18 @@ async function resolveApp(nameOrId, platform) {
|
|
|
206
221
|
die(`Multiple apps named "${nameOrId}" (${named.map((app) => app.os).join(', ')}). Pass --platform ios|android, or use the app id.`);
|
|
207
222
|
}
|
|
208
223
|
|
|
209
|
-
function bundle(platform, contentsDir, sourcemapPath) {
|
|
210
|
-
const bundleName = platform
|
|
224
|
+
function bundle(platform, contentsDir, sourcemapPath, {forHermes = false} = {}) {
|
|
225
|
+
const bundleName = bundleFileName(platform);
|
|
211
226
|
fs.mkdirSync(contentsDir, {recursive: true});
|
|
212
|
-
console.log(`• bundling ${platform}…`);
|
|
213
|
-
|
|
227
|
+
console.log(forHermes ? `• bundling ${platform} unminified for the Hermes compiler, as React Native's release build does…` : `• bundling ${platform}…`);
|
|
228
|
+
execFileSyncInterruptible(
|
|
214
229
|
'npx',
|
|
215
230
|
[
|
|
216
231
|
'react-native',
|
|
217
232
|
'bundle',
|
|
218
233
|
'--platform', platform,
|
|
219
234
|
'--dev', 'false',
|
|
235
|
+
...(forHermes ? ['--minify', 'false'] : []),
|
|
220
236
|
'--entry-file', 'index.js',
|
|
221
237
|
'--bundle-output', path.join(contentsDir, bundleName),
|
|
222
238
|
'--assets-dest', contentsDir,
|
|
@@ -236,10 +252,21 @@ function sizeGrowth(previousSize, nextSize) {
|
|
|
236
252
|
return Math.round(((nextSize - previousSize) / previousSize) * 100);
|
|
237
253
|
}
|
|
238
254
|
|
|
255
|
+
function growthChecks(previous, {size, jsSize = null, hermes = false}) {
|
|
256
|
+
const previousJsSize = previous?.hermes ? previous.jsCopy?.size : previous?.size;
|
|
257
|
+
const checks = hermes
|
|
258
|
+
? [{name: 'bytecode', previousSize: previous?.hermes ? previous.size : null, size}, {name: 'JavaScript copy', previousSize: previousJsSize, size: jsSize}]
|
|
259
|
+
: [{name: 'bundle', previousSize: previousJsSize, size}];
|
|
260
|
+
return checks.map((check) => ({...check, growth: sizeGrowth(check.previousSize, check.size)}));
|
|
261
|
+
}
|
|
262
|
+
|
|
239
263
|
function zipContents(contentsDir) {
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
264
|
+
const zipDir = makeTempDir('pulsar-zip-');
|
|
265
|
+
const zipPath = path.join(zipDir, 'release.zip');
|
|
266
|
+
execFileSyncInterruptible('zip', ['-qq', '-r', '-X', zipPath, '.'], {cwd: contentsDir});
|
|
267
|
+
const zip = fs.readFileSync(zipPath);
|
|
268
|
+
removeTemp(zipDir);
|
|
269
|
+
return zip;
|
|
243
270
|
}
|
|
244
271
|
|
|
245
272
|
// Build a differential package: only the files that changed vs the base, plus a hotcodepush.json
|
|
@@ -247,14 +274,16 @@ function zipContents(contentsDir) {
|
|
|
247
274
|
// this diff, then verifies the result against the target hash. Returns the diff dir, or null if the
|
|
248
275
|
// base couldn't be fetched.
|
|
249
276
|
async function buildDiffPackage(baseZip, newDir) {
|
|
250
|
-
const
|
|
251
|
-
const basePath = path.join(
|
|
277
|
+
const baseWorkDir = makeTempDir('pulsar-base-');
|
|
278
|
+
const basePath = path.join(baseWorkDir, 'base.zip');
|
|
279
|
+
const baseDir = path.join(baseWorkDir, 'contents');
|
|
252
280
|
fs.writeFileSync(basePath, baseZip);
|
|
253
|
-
|
|
281
|
+
execFileSyncInterruptible('unzip', ['-qq', '-o', basePath, '-d', baseDir]);
|
|
254
282
|
|
|
255
283
|
const baseHashes = fileHashes(baseDir);
|
|
284
|
+
removeTemp(baseWorkDir);
|
|
256
285
|
const newHashes = fileHashes(newDir);
|
|
257
|
-
const diffDir =
|
|
286
|
+
const diffDir = makeTempDir('pulsar-diff-');
|
|
258
287
|
|
|
259
288
|
for (const [relativePath, hash] of Object.entries(newHashes)) {
|
|
260
289
|
if (baseHashes[relativePath] === hash) continue;
|
|
@@ -372,7 +401,7 @@ async function cmdApps() {
|
|
|
372
401
|
|
|
373
402
|
// Sign for this app — with a local key when one was given, otherwise by asking Pulsar, which signs for
|
|
374
403
|
// 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) {
|
|
404
|
+
async function signForApp(app, deployment, contentsDir, packageHash, localKey, subject = '') {
|
|
376
405
|
const signaturePath = path.join(contentsDir, SIGNATURE_PATH);
|
|
377
406
|
fs.rmSync(signaturePath, {force: true});
|
|
378
407
|
let signature = null;
|
|
@@ -386,45 +415,88 @@ async function signForApp(app, deployment, contentsDir, packageHash, localKey) {
|
|
|
386
415
|
({signature} = await api(`/apps/${app.id}/deployments/${deployment}/sign`, {method: 'POST', body: {packageHash}}));
|
|
387
416
|
}
|
|
388
417
|
if (!signature) {
|
|
389
|
-
console.log(`• ${app.name} has no signing key — uploading unsigned`);
|
|
418
|
+
console.log(`• ${app.name} has no signing key — uploading${subject ? ` ${subject}` : ''} unsigned`);
|
|
390
419
|
return;
|
|
391
420
|
}
|
|
392
421
|
fs.mkdirSync(path.dirname(signaturePath), {recursive: true});
|
|
393
422
|
fs.writeFileSync(signaturePath, signature);
|
|
394
|
-
console.log(`• signed${localKey ? ' with your local key' : ' by Pulsar'}`);
|
|
423
|
+
console.log(`• signed${subject ? ` ${subject}` : ''}${localKey ? ' with your local key' : ' by Pulsar'}`);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function reportBytecodeReach(bytecodeVersion, reach, target, recentDays) {
|
|
427
|
+
const active = reach.activeDevices || 0;
|
|
428
|
+
const matching = reach.bytecodeActiveDevices[bytecodeVersion] || 0;
|
|
429
|
+
const others = Object.entries(reach.bytecodeActiveDevices)
|
|
430
|
+
.filter(([reported, count]) => Number(reported) !== bytecodeVersion && count > 0)
|
|
431
|
+
.map(([reported, count]) => `${count} run v${reported}`);
|
|
432
|
+
if (!active) {
|
|
433
|
+
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`);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
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(', ')})` : ''}`);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const supportsBytecode = (reach) => Boolean(reach?.bytecodeActiveDevices) && typeof reach.bytecodeActiveDevices === 'object';
|
|
440
|
+
|
|
441
|
+
function diffBases(app, previous, packageHash) {
|
|
442
|
+
if (!previous) return [];
|
|
443
|
+
const blobFile = (blobKey) => blobKey.slice(app.id.length + 1);
|
|
444
|
+
const bases = [{
|
|
445
|
+
label: previous.label,
|
|
446
|
+
packageHash: previous.packageHash,
|
|
447
|
+
file: previous.encrypted && previous.blobKey ? blobFile(previous.blobKey) : `${previous.packageHash}.zip`,
|
|
448
|
+
}];
|
|
449
|
+
if (previous.jsCopy?.packageHash && previous.jsCopy.blobKey) {
|
|
450
|
+
bases.push({label: `${previous.label} JavaScript copy`, packageHash: previous.jsCopy.packageHash, file: blobFile(previous.jsCopy.blobKey), jsCopy: true});
|
|
451
|
+
}
|
|
452
|
+
return bases.filter((base) => base.packageHash && base.packageHash !== packageHash);
|
|
395
453
|
}
|
|
396
454
|
|
|
397
455
|
// Sign and push an already-built bundle to one app's deployment, then generate and upload a
|
|
398
456
|
// differential patch against whatever that deployment was serving.
|
|
399
|
-
async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported = false} = {}) {
|
|
457
|
+
async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported = false, hermes = null, javascript = null} = {}) {
|
|
458
|
+
if (hermes && !javascript) die('a Hermes bytecode release needs its JavaScript copy. Nothing was uploaded.');
|
|
400
459
|
const privateBundles = await privateContext(app, args, localKey);
|
|
401
460
|
const sealing = Boolean(privateBundles) && !privateBundles.plain;
|
|
402
461
|
const plainCopy = sealing && args.includes('--plain-copy-for-old-builds');
|
|
403
462
|
if (privateBundles && !reachReported) reportReach(privateBundles, {mandatory: args.includes('--mandatory'), plainCopy});
|
|
404
463
|
await signForApp(app, deployment, contentsDir, packageHash, localKey);
|
|
405
|
-
|
|
406
|
-
const
|
|
464
|
+
if (hermes) await signForApp(app, deployment, javascript.contentsDir, javascript.packageHash, localKey, 'the JavaScript copy');
|
|
465
|
+
const sealFull = async (hash, bytes) => (sealing ? Buffer.from(await sealArtifact(privateBundles, app, hash, bytes, 'full')) : bytes);
|
|
466
|
+
const plainZip = zipContents(contentsDir);
|
|
467
|
+
const zip = await sealFull(packageHash, plainZip);
|
|
468
|
+
const plainJsZip = hermes ? zipContents(javascript.contentsDir) : null;
|
|
469
|
+
const jsZip = hermes ? await sealFull(javascript.packageHash, plainJsZip) : null;
|
|
407
470
|
let prevLatest = null;
|
|
408
471
|
try {
|
|
409
472
|
const existing = await api(`/apps/${app.id}/deployments/${deployment}/releases`, {optional: true});
|
|
410
473
|
prevLatest = [...existing].reverse().find((entry) => !entry.isDisabled) || existing[existing.length - 1] || null;
|
|
411
474
|
} catch {}
|
|
475
|
+
const target = getFlag(args, 'target');
|
|
476
|
+
let binaries = null;
|
|
412
477
|
try {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
478
|
+
binaries = await api(`/apps/${app.id}/binary-versions?target=${encodeURIComponent(target)}`, {optional: true});
|
|
479
|
+
} catch (err) {
|
|
480
|
+
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.`);
|
|
481
|
+
}
|
|
482
|
+
const {versions, reach, recentDays} = binaries || {};
|
|
483
|
+
if (versions?.length && reach && !reach.everLaunched) {
|
|
484
|
+
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(', ')})`);
|
|
485
|
+
} else if (versions?.length && reach && !reach.recentLaunches) {
|
|
486
|
+
console.log(`⚠ no store build matching ${target} was opened in the last ${recentDays} days (matches: ${reach.matchingVersions.join(', ')})`);
|
|
487
|
+
}
|
|
488
|
+
if (hermes) {
|
|
489
|
+
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.`);
|
|
490
|
+
reportBytecodeReach(hermes.bytecodeVersion, reach, target, recentDays);
|
|
424
491
|
}
|
|
425
492
|
const maxGrowth = getFlag(args, 'max-growth');
|
|
426
|
-
|
|
427
|
-
|
|
493
|
+
for (const {name, previousSize, size, growth} of growthChecks(prevLatest, {size: zip.length, jsSize: jsZip?.length, hermes: Boolean(hermes)})) {
|
|
494
|
+
if (growth !== null && growth > 20) {
|
|
495
|
+
console.log(`⚠ ${name} is ${growth}% larger than ${prevLatest.label} (${(previousSize / 1e6).toFixed(2)}MB → ${(size / 1e6).toFixed(2)}MB)`);
|
|
496
|
+
}
|
|
497
|
+
if (maxGrowth !== undefined && growth !== null && growth > Number(maxGrowth)) {
|
|
498
|
+
die(`${name} grew ${growth}%, more than --max-growth ${maxGrowth}%. Nothing was released.`);
|
|
499
|
+
}
|
|
428
500
|
}
|
|
429
501
|
|
|
430
502
|
const startsAt = parseSchedule(getFlag(args, 'schedule'));
|
|
@@ -433,14 +505,15 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
433
505
|
method: 'POST',
|
|
434
506
|
raw: true,
|
|
435
507
|
body: zip,
|
|
436
|
-
onUploadProgress: uploadProgress(`uploading ${(zip.length / 1e6).toFixed(1)}MB bundle`),
|
|
508
|
+
onUploadProgress: uploadProgress(`uploading ${(zip.length / 1e6).toFixed(1)}MB ${hermes ? 'bytecode ' : ''}bundle`),
|
|
437
509
|
headers: {
|
|
438
510
|
...(sealing
|
|
439
511
|
? {...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
512
|
: {'content-type': 'application/zip'}),
|
|
441
513
|
...(privateBundles?.plain === 'all' ? {'x-plain': '1'} : {}),
|
|
442
514
|
...(privateBundles?.plain === 'older' ? {'x-audience': 'older-builds'} : {}),
|
|
443
|
-
'x-
|
|
515
|
+
...(hermes ? {'x-hermes-bytecode-version': String(hermes.bytecodeVersion)} : {}),
|
|
516
|
+
'x-app-version': target,
|
|
444
517
|
'x-package-hash': packageHash,
|
|
445
518
|
'x-is-mandatory': String(args.includes('--mandatory')),
|
|
446
519
|
'x-disabled': String(args.includes('--disabled')),
|
|
@@ -455,22 +528,47 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
455
528
|
...(ramp ? {'x-rollout-to': String(ramp.to), 'x-rollout-hours': String(ramp.hours)} : {}),
|
|
456
529
|
},
|
|
457
530
|
});
|
|
531
|
+
if (hermes && release.hermes?.bytecodeVersion !== hermes.bytecodeVersion) {
|
|
532
|
+
const disabled = await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}`, {method: 'PATCH', body: {isDisabled: true}, optional: true}).then(() => true, () => false);
|
|
533
|
+
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.`);
|
|
534
|
+
}
|
|
458
535
|
const scopes = [
|
|
459
536
|
release.clientIds?.length ? `${release.clientIds.length} device id(s)` : null,
|
|
460
537
|
release.targetDevices?.length ? `${release.targetDevices.length} device model(s)` : null,
|
|
461
538
|
release.targetUserIds?.length ? `${release.targetUserIds.length} user(s)` : null,
|
|
462
539
|
release.targetFromLabels?.length ? `devices on ${release.targetFromLabels.join('/')}` : null,
|
|
463
540
|
].filter(Boolean);
|
|
464
|
-
const
|
|
541
|
+
const reachText = scopes.length ? scopes.join(' + ') : `${release.rollout}% of devices`;
|
|
465
542
|
const privacy = release.encrypted ? ' (private)' : release.olderBuildsOnly ? ' (plain, older builds only)' : privateBundles ? ' (plain)' : '';
|
|
466
|
-
|
|
543
|
+
const bytecode = hermes ? ` (Hermes bytecode v${hermes.bytecodeVersion})` : '';
|
|
544
|
+
console.log(`✓ released ${release.label} to ${app.name}/${deployment} — ${release.isDisabled ? 'DISABLED' : reachText}${privacy}${bytecode}`);
|
|
545
|
+
if (hermes) {
|
|
546
|
+
try {
|
|
547
|
+
await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/js-copy`, {
|
|
548
|
+
method: 'POST',
|
|
549
|
+
raw: true,
|
|
550
|
+
optional: true,
|
|
551
|
+
body: jsZip,
|
|
552
|
+
onUploadProgress: uploadProgress(`uploading ${(jsZip.length / 1e6).toFixed(1)}MB JavaScript copy`),
|
|
553
|
+
headers: {
|
|
554
|
+
...(sealing
|
|
555
|
+
? {...sealedHeaders, 'x-release-signature': fs.readFileSync(path.join(javascript.contentsDir, SIGNATURE_PATH), 'utf8')}
|
|
556
|
+
: {'content-type': 'application/zip'}),
|
|
557
|
+
'x-package-hash': javascript.packageHash,
|
|
558
|
+
},
|
|
559
|
+
});
|
|
560
|
+
} catch (err) {
|
|
561
|
+
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}.`);
|
|
562
|
+
}
|
|
563
|
+
console.log(`• JavaScript copy uploaded: builds that don't run Hermes bytecode v${hermes.bytecodeVersion} get it`);
|
|
564
|
+
}
|
|
467
565
|
if (plainCopy) {
|
|
468
566
|
await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/plain-copy`, {
|
|
469
567
|
method: 'POST',
|
|
470
568
|
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'},
|
|
569
|
+
body: hermes ? plainJsZip : plainZip,
|
|
570
|
+
onUploadProgress: uploadProgress(`uploading ${((hermes ? plainJsZip : plainZip).length / 1e6).toFixed(1)}MB plain copy for older builds`),
|
|
571
|
+
headers: {'content-type': 'application/zip', ...(hermes ? {'x-package-hash': javascript.packageHash} : {})},
|
|
474
572
|
});
|
|
475
573
|
console.log('• plain copy uploaded: older builds get this release too, and Pulsar can read that copy');
|
|
476
574
|
}
|
|
@@ -483,12 +581,13 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
483
581
|
if (release.startsAt) console.log(` scheduled — goes live ${new Date(release.startsAt).toLocaleString()}`);
|
|
484
582
|
if (release.rolloutRamp) console.log(` gradual rollout — ${release.rollout}% to ${release.rolloutRamp.to}% over ${release.rolloutRamp.hours}h`);
|
|
485
583
|
|
|
584
|
+
const modulesSourcemap = javascript?.sourcemapPath || sourcemapPath;
|
|
486
585
|
try {
|
|
487
586
|
const files = {files: fileManifest(contentsDir)};
|
|
488
587
|
const sealedManifest = () => {
|
|
489
588
|
let modules = null;
|
|
490
589
|
try {
|
|
491
|
-
modules =
|
|
590
|
+
modules = modulesSourcemap && fs.existsSync(modulesSourcemap) ? JSON.parse(fs.readFileSync(modulesSourcemap, 'utf8')).sources || null : null;
|
|
492
591
|
} catch {
|
|
493
592
|
modules = null;
|
|
494
593
|
}
|
|
@@ -500,50 +599,57 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
500
599
|
} catch (err) {
|
|
501
600
|
console.log(`• file list not recorded: ${err.message}`);
|
|
502
601
|
}
|
|
503
|
-
|
|
602
|
+
const sourcemaps = [
|
|
603
|
+
{mapPath: sourcemapPath, hash: packageHash, name: hermes ? 'bytecode source map' : 'source map'},
|
|
604
|
+
...(hermes ? [{mapPath: javascript.sourcemapPath, hash: javascript.packageHash, name: 'JavaScript copy source map', jsCopy: true}] : []),
|
|
605
|
+
];
|
|
606
|
+
for (const {mapPath, hash, name, jsCopy} of sourcemaps) {
|
|
607
|
+
if (!mapPath || !fs.existsSync(mapPath)) continue;
|
|
504
608
|
try {
|
|
505
|
-
const plainMap = fs.readFileSync(
|
|
506
|
-
const map = sealing ? Buffer.from(await sealArtifact(privateBundles, app,
|
|
609
|
+
const plainMap = fs.readFileSync(mapPath);
|
|
610
|
+
const map = sealing ? Buffer.from(await sealArtifact(privateBundles, app, hash, plainMap, 'sourcemap')) : plainMap;
|
|
507
611
|
await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/sourcemap`, {
|
|
508
612
|
method: 'POST',
|
|
509
613
|
raw: true,
|
|
510
614
|
optional: true,
|
|
511
615
|
body: map,
|
|
512
|
-
onUploadProgress: uploadProgress(`uploading ${(map.length / 1e6).toFixed(1)}MB
|
|
513
|
-
headers: sealing ? sealedHeaders : {'content-type': 'application/json'},
|
|
616
|
+
onUploadProgress: uploadProgress(`uploading ${(map.length / 1e6).toFixed(1)}MB ${name}`),
|
|
617
|
+
headers: {...(sealing ? sealedHeaders : {'content-type': 'application/json'}), ...(jsCopy ? {'x-package-hash': hash} : {})},
|
|
514
618
|
});
|
|
515
|
-
console.log(sealing ?
|
|
619
|
+
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
620
|
} catch (err) {
|
|
517
|
-
console.log(`•
|
|
621
|
+
console.log(`• ${name} not uploaded: ${err.message}`);
|
|
518
622
|
}
|
|
519
623
|
}
|
|
520
624
|
|
|
521
|
-
if (!args.includes('--no-diff')
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
625
|
+
if (!args.includes('--no-diff')) {
|
|
626
|
+
for (const base of diffBases(app, prevLatest, packageHash)) {
|
|
627
|
+
try {
|
|
628
|
+
const {apiUrl} = loadConfig();
|
|
629
|
+
let baseZip = await fetchBlob(apiUrl, app.id, base.file);
|
|
630
|
+
if (prevLatest.encrypted) {
|
|
631
|
+
if (!privateBundles?.keys.length) throw new Error(`${prevLatest.label} is private and no bundle key was given`);
|
|
632
|
+
baseZip = await openArtifact(privateBundles.keys, baseZip, {appId: app.id, packageHash: base.packageHash, kind: 'full'});
|
|
633
|
+
}
|
|
634
|
+
const diffDir = await buildDiffPackage(baseZip, contentsDir);
|
|
635
|
+
const plainDiff = zipContents(diffDir);
|
|
636
|
+
removeTemp(diffDir);
|
|
637
|
+
const diffZip = sealing
|
|
638
|
+
? Buffer.from(await sealArtifact(privateBundles, app, packageHash, plainDiff, 'diff', {baseHash: base.packageHash}))
|
|
639
|
+
: plainDiff;
|
|
640
|
+
await api(`/apps/${app.id}/deployments/${deployment}/releases/${release.label}/diff`, {
|
|
641
|
+
method: 'POST',
|
|
642
|
+
raw: true,
|
|
643
|
+
optional: true,
|
|
644
|
+
body: diffZip,
|
|
645
|
+
onUploadProgress: uploadProgress(`uploading ${(diffZip.length / 1e6).toFixed(1)}MB diff`),
|
|
646
|
+
headers: {...(sealing ? sealedHeaders : {'content-type': 'application/zip'}), 'x-base-hash': base.packageHash},
|
|
647
|
+
});
|
|
648
|
+
const saved = Math.round((1 - diffZip.length / zip.length) * 100);
|
|
649
|
+
console.log(`• diff vs ${base.label}: ${(diffZip.length / 1e3).toFixed(0)} KB (${saved}% smaller)`);
|
|
650
|
+
} catch (err) {
|
|
651
|
+
console.log(`• diff ${base.jsCopy ? `vs ${base.label} ` : ''}skipped (full bundle still serves): ${err.message}`);
|
|
529
652
|
}
|
|
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
653
|
}
|
|
548
654
|
}
|
|
549
655
|
return release;
|
|
@@ -565,28 +671,66 @@ async function checkPrivateBeforeBuild(apps, args) {
|
|
|
565
671
|
}
|
|
566
672
|
}
|
|
567
673
|
|
|
568
|
-
function
|
|
674
|
+
function hermesCompiler(args, projectRoot = process.cwd()) {
|
|
675
|
+
const platform = getFlag(args, 'platform', 'ios');
|
|
676
|
+
const choice = hermesChoice(args, projectRoot, platform);
|
|
677
|
+
if (choice.error) die(`${choice.error}. Nothing was uploaded.`);
|
|
678
|
+
if (!choice.enabled) return null;
|
|
679
|
+
const hermesc = findHermesc(projectRoot);
|
|
680
|
+
if (!hermesc) {
|
|
681
|
+
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.`);
|
|
682
|
+
}
|
|
683
|
+
return {hermesc, composeScript: findComposeScript(projectRoot)};
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function buildOnce(args, compiler = null) {
|
|
569
687
|
const platform = getFlag(args, 'platform', 'ios');
|
|
570
688
|
const localKey = localSigningKey(args);
|
|
571
|
-
const contentsDir =
|
|
572
|
-
const sourcemapPath = args.includes('--no-sourcemap') ? null : `${contentsDir}.map
|
|
689
|
+
const contentsDir = makeTempDir('pulsar-build-');
|
|
690
|
+
const sourcemapPath = args.includes('--no-sourcemap') ? null : trackTemp(`${contentsDir}.map`);
|
|
573
691
|
bundle(platform, contentsDir, sourcemapPath);
|
|
574
692
|
const packageHash = computePackageHash(contentsDir);
|
|
575
693
|
console.log(`• hash ${packageHash.slice(0, 12)}…`);
|
|
576
|
-
return {contentsDir, packageHash, localKey, sourcemapPath};
|
|
694
|
+
if (!compiler) return {contentsDir, packageHash, localKey, sourcemapPath};
|
|
695
|
+
const sourceDir = makeTempDir('pulsar-hermes-source-');
|
|
696
|
+
const sourceMapPath = sourcemapPath ? trackTemp(`${sourceDir}.map`) : null;
|
|
697
|
+
bundle(platform, sourceDir, sourceMapPath, {forHermes: true});
|
|
698
|
+
console.log(`• compiling Hermes bytecode with ${path.relative(process.cwd(), compiler.hermesc) || compiler.hermesc}…`);
|
|
699
|
+
let bytecode;
|
|
700
|
+
let compileError = null;
|
|
701
|
+
try {
|
|
702
|
+
bytecode = buildBytecode(compiler, {contentsDir: sourceDir, sourcemapPath: sourceMapPath}, bundleFileName(platform));
|
|
703
|
+
} catch (err) {
|
|
704
|
+
compileError = err;
|
|
705
|
+
}
|
|
706
|
+
removeTemp(sourceDir);
|
|
707
|
+
if (sourceMapPath) removeTemp(sourceMapPath);
|
|
708
|
+
if (compileError) die(`${compileError.message}\nPass --no-hermes to release JavaScript instead. Nothing was uploaded.`);
|
|
709
|
+
if (bytecode.sourcemapError) console.log(`⚠ bytecode source map not composed (${bytecode.sourcemapError}): crash stacks from bytecode won't show your source files`);
|
|
710
|
+
const bytecodeHash = computePackageHash(bytecode.contentsDir);
|
|
711
|
+
console.log(`• Hermes bytecode v${bytecode.bytecodeVersion}, hash ${bytecodeHash.slice(0, 12)}…; the minified JavaScript build above is its JavaScript copy`);
|
|
712
|
+
return {
|
|
713
|
+
contentsDir: bytecode.contentsDir,
|
|
714
|
+
packageHash: bytecodeHash,
|
|
715
|
+
localKey,
|
|
716
|
+
sourcemapPath: bytecode.sourcemapPath,
|
|
717
|
+
hermes: {bytecodeVersion: bytecode.bytecodeVersion},
|
|
718
|
+
javascript: {contentsDir, packageHash, sourcemapPath},
|
|
719
|
+
};
|
|
577
720
|
}
|
|
578
721
|
|
|
579
722
|
async function cmdRelease(args) {
|
|
580
723
|
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 "..."]');
|
|
724
|
+
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
725
|
if (!getFlag(args, 'target')) die('--target <binary version> is required (e.g. --target 1.0.0)');
|
|
583
726
|
const app = await resolveApp(nameOrId, getFlag(args, 'platform', 'ios'));
|
|
584
727
|
if (app.os !== getFlag(args, 'platform', 'ios')) {
|
|
585
728
|
console.log(`• note: resolved app "${app.name}" is ${app.os}; bundling ${getFlag(args, 'platform', 'ios')}`);
|
|
586
729
|
}
|
|
587
730
|
await checkPrivateBeforeBuild([app], args);
|
|
588
|
-
const
|
|
589
|
-
|
|
731
|
+
const compiler = hermesCompiler(args);
|
|
732
|
+
const {contentsDir, packageHash, localKey, sourcemapPath, hermes, javascript} = buildOnce(args, compiler);
|
|
733
|
+
await pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported: true, hermes, javascript});
|
|
590
734
|
}
|
|
591
735
|
|
|
592
736
|
// Release the same built bundle to several apps at once (shared-codebase / white-label fleets).
|
|
@@ -612,17 +756,26 @@ async function cmdReleaseTrain(args) {
|
|
|
612
756
|
if (!apps.length) die(`No ${platform} apps matched.`);
|
|
613
757
|
|
|
614
758
|
await checkPrivateBeforeBuild(apps, args);
|
|
615
|
-
const
|
|
759
|
+
const compiler = hermesCompiler(args);
|
|
760
|
+
const {contentsDir, packageHash, localKey, sourcemapPath, hermes, javascript} = buildOnce(args, compiler);
|
|
616
761
|
console.log(`• release train → ${apps.length} app(s): ${apps.map((app) => app.name).join(', ')}`);
|
|
617
762
|
for (const app of apps) {
|
|
618
763
|
try {
|
|
619
|
-
await pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported: true});
|
|
764
|
+
await pushBuiltRelease(app, deployment, args, contentsDir, packageHash, localKey, {sourcemapPath, reachReported: true, hermes, javascript});
|
|
620
765
|
} catch (err) {
|
|
621
766
|
console.log(`✗ ${app.name}: ${err.message}`);
|
|
622
767
|
}
|
|
623
768
|
}
|
|
624
769
|
}
|
|
625
770
|
|
|
771
|
+
const bytecodeTag = (release) => (release.hermes ? ` [bytecode v${release.hermes.bytecodeVersion}${release.jsCopy ? ' + JS copy' : ', no JS copy'}]` : '');
|
|
772
|
+
|
|
773
|
+
function warnMissingJsCopy(release) {
|
|
774
|
+
if (!release?.hermes || release.jsCopy) return;
|
|
775
|
+
const version = release.hermes.bytecodeVersion;
|
|
776
|
+
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`);
|
|
777
|
+
}
|
|
778
|
+
|
|
626
779
|
async function cmdPromote(args) {
|
|
627
780
|
const [nameOrId, from = 'Staging', to = 'Production'] = args;
|
|
628
781
|
const app = await resolveApp(nameOrId, getFlag(args, 'platform'));
|
|
@@ -631,6 +784,7 @@ async function cmdPromote(args) {
|
|
|
631
784
|
body: {to, rollout: Number(getFlag(args, 'rollout', '100'))},
|
|
632
785
|
});
|
|
633
786
|
console.log(`✓ promoted ${from} → ${to} as ${release.label}`);
|
|
787
|
+
warnMissingJsCopy(release);
|
|
634
788
|
}
|
|
635
789
|
|
|
636
790
|
async function cmdRollback(args) {
|
|
@@ -638,6 +792,7 @@ async function cmdRollback(args) {
|
|
|
638
792
|
const app = await resolveApp(nameOrId, getFlag(args, 'platform'));
|
|
639
793
|
const release = await api(`/apps/${app.id}/deployments/${deployment}/rollback`, {method: 'POST'});
|
|
640
794
|
console.log(`✓ rolled back ${app.name}/${deployment} → ${release.label}`);
|
|
795
|
+
warnMissingJsCopy(release);
|
|
641
796
|
}
|
|
642
797
|
|
|
643
798
|
async function cmdDeployment(args) {
|
|
@@ -664,7 +819,7 @@ async function cmdHistory(args) {
|
|
|
664
819
|
if (!releases.length) return console.log('(no releases)');
|
|
665
820
|
for (const release of [...releases].reverse()) {
|
|
666
821
|
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}`;
|
|
822
|
+
const flags = `${release.isMandatory ? ' [mandatory]' : ''}${release.isDisabled ? ' [disabled]' : ''}${privacy}${bytecodeTag(release)}`;
|
|
668
823
|
const rollout = release.currentRollout ?? release.rollout;
|
|
669
824
|
const state = release.state && release.state !== 'live' ? ` [${release.state}]` : '';
|
|
670
825
|
const when = release.startsAt ? ` starts ${new Date(release.startsAt).toLocaleString()}` : '';
|
|
@@ -747,7 +902,7 @@ async function cmdKeys(args) {
|
|
|
747
902
|
console.log(`✓ wrote ${Object.keys(vars).length} key(s) to ${target} (${written.size} updated, ${missing.length} added)`);
|
|
748
903
|
}
|
|
749
904
|
|
|
750
|
-
export {saveConfig, browserLogin, signCodePushJWT, SIGNATURE_PATH, api, die, getFlag, loadConfig, pushBuiltRelease, splitList, resolveApp};
|
|
905
|
+
export {saveConfig, browserLogin, signCodePushJWT, SIGNATURE_PATH, api, die, getFlag, loadConfig, pushBuiltRelease, splitList, resolveApp, growthChecks, buildOnce};
|
|
751
906
|
|
|
752
907
|
// Only dispatch when run as the CLI — importing the module (e.g. from tests) must not execute a command.
|
|
753
908
|
// Compare real paths: a global install runs through a bin symlink, so argv[1] is not this file's path.
|
package/temp.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {execFileSync} from 'node:child_process';
|
|
5
|
+
|
|
6
|
+
const SIGNAL_EXIT_CODES = {SIGINT: 130, SIGTERM: 143, SIGHUP: 129, SIGQUIT: 131, ...(process.platform === 'win32' ? {SIGBREAK: 149} : {})};
|
|
7
|
+
const tempPaths = new Set();
|
|
8
|
+
let cleanupInstalled = false;
|
|
9
|
+
|
|
10
|
+
export function removeTemp(tempPath) {
|
|
11
|
+
fs.rmSync(tempPath, {recursive: true, force: true});
|
|
12
|
+
tempPaths.delete(tempPath);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function removeAllTemp() {
|
|
16
|
+
for (const tempPath of tempPaths) {
|
|
17
|
+
try {
|
|
18
|
+
removeTemp(tempPath);
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function exitBySignal(signal) {
|
|
24
|
+
removeAllTemp();
|
|
25
|
+
process.removeAllListeners(signal);
|
|
26
|
+
try {
|
|
27
|
+
process.kill(process.pid, signal);
|
|
28
|
+
} catch {}
|
|
29
|
+
process.exit(SIGNAL_EXIT_CODES[signal]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function exitIfInterrupted(signal) {
|
|
33
|
+
if (signal && Object.hasOwn(SIGNAL_EXIT_CODES, signal)) exitBySignal(signal);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function execFileSyncInterruptible(file, args, options) {
|
|
37
|
+
try {
|
|
38
|
+
return execFileSync(file, args, options);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
exitIfInterrupted(err.signal);
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function installCleanup() {
|
|
46
|
+
if (cleanupInstalled) return;
|
|
47
|
+
cleanupInstalled = true;
|
|
48
|
+
process.on('exit', removeAllTemp);
|
|
49
|
+
for (const signal of Object.keys(SIGNAL_EXIT_CODES)) process.on(signal, () => exitBySignal(signal));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function trackTemp(tempPath) {
|
|
53
|
+
installCleanup();
|
|
54
|
+
tempPaths.add(tempPath);
|
|
55
|
+
return tempPath;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const makeTempDir = (prefix) => trackTemp(fs.mkdtempSync(path.join(os.tmpdir(), prefix)));
|