@novacraft-engineering/pulsar-cli 1.6.0 → 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/hermes.js +23 -18
- package/migrate.js +4 -5
- package/package.json +3 -2
- package/pulsar.js +24 -17
- package/temp.js +58 -0
package/hermes.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import {spawnSync} from 'node:child_process';
|
|
5
4
|
import {walk} from './hash.js';
|
|
5
|
+
import {exitIfInterrupted, makeTempDir, removeTemp, trackTemp} from './temp.js';
|
|
6
6
|
|
|
7
7
|
const MAGIC = Buffer.from('c61fbc03c103191f', 'hex');
|
|
8
8
|
const HEADER_LENGTH = 12;
|
|
@@ -94,6 +94,7 @@ export function compileBytecode(hermesc, inputPath, outputPath, {sourcemap = fal
|
|
|
94
94
|
['-emit-binary', '-max-diagnostic-width=80', '-O', ...(sourcemap ? ['-output-source-map'] : []), '-out', outputPath, inputPath],
|
|
95
95
|
{encoding: 'utf8', maxBuffer: 256 * 1024 * 1024},
|
|
96
96
|
);
|
|
97
|
+
exitIfInterrupted(result.signal);
|
|
97
98
|
if (result.error) throw new Error(`could not run ${hermesc}: ${result.error.message}`);
|
|
98
99
|
if (result.status !== 0) throw new Error(`hermesc failed:\n${diagnostics(result.stderr || result.stdout)}`);
|
|
99
100
|
const bytecodeVersion = fs.existsSync(outputPath) ? fileBytecodeVersion(outputPath) : null;
|
|
@@ -104,28 +105,32 @@ export function compileBytecode(hermesc, inputPath, outputPath, {sourcemap = fal
|
|
|
104
105
|
|
|
105
106
|
export function composeSourcemaps(composeScript, packagerMapPath, compilerMapPath, outputPath) {
|
|
106
107
|
const result = spawnSync(process.execPath, [composeScript, packagerMapPath, compilerMapPath, '-o', outputPath], {encoding: 'utf8', maxBuffer: 64 * 1024 * 1024});
|
|
108
|
+
exitIfInterrupted(result.signal);
|
|
107
109
|
if (result.error) throw new Error(result.error.message);
|
|
108
110
|
if (result.status !== 0 || !fs.existsSync(outputPath)) throw new Error(diagnostics(result.stderr) || `exit code ${result.status}`);
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
export function buildBytecode({hermesc, composeScript}, javascript, bundleName) {
|
|
112
|
-
const compilerDir =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
+
}
|
|
127
131
|
}
|
|
132
|
+
return {contentsDir, bytecodeVersion: compiled.bytecodeVersion, sourcemapPath, sourcemapError};
|
|
133
|
+
} finally {
|
|
134
|
+
removeTemp(compilerDir);
|
|
128
135
|
}
|
|
129
|
-
fs.rmSync(compilerDir, {recursive: true, force: true});
|
|
130
|
-
return {contentsDir, bytecodeVersion: compiled.bytecodeVersion, sourcemapPath, sourcemapError};
|
|
131
136
|
}
|
package/migrate.js
CHANGED
|
@@ -1,10 +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';
|
|
7
5
|
import {bundleBytecodeIn} from './hermes.js';
|
|
6
|
+
import {execFileSyncInterruptible, makeTempDir, removeTemp} from './temp.js';
|
|
8
7
|
|
|
9
8
|
const USAGE = 'Usage: pulsar migrate --from <serverUrl> --access-key <key> [--apps A,B] [--org <name>] [--platform ios|android] [--releases latest|none] [--dry-run]';
|
|
10
9
|
|
|
@@ -39,7 +38,7 @@ async function migrateRelease({source, pulsarApp, deploymentName, sourcePackage,
|
|
|
39
38
|
if (!sourcePackage) return 'no release on source';
|
|
40
39
|
if (!sourcePackage.appVersion) return `not migrated: ${sourcePackage.label} has no target app version`;
|
|
41
40
|
if (dryRun) return `would re-release ${sourcePackage.label} (target ${sourcePackage.appVersion})`;
|
|
42
|
-
const workDir =
|
|
41
|
+
const workDir = makeTempDir('pulsar-migrate-');
|
|
43
42
|
const zipPath = path.join(workDir, 'source.zip');
|
|
44
43
|
const contentsDir = path.join(workDir, 'contents');
|
|
45
44
|
try {
|
|
@@ -49,7 +48,7 @@ async function migrateRelease({source, pulsarApp, deploymentName, sourcePackage,
|
|
|
49
48
|
if (!response.ok) throw new Error(`download failed (${response.status})`);
|
|
50
49
|
fs.writeFileSync(zipPath, Buffer.from(await response.arrayBuffer()));
|
|
51
50
|
try {
|
|
52
|
-
|
|
51
|
+
execFileSyncInterruptible('unzip', ['-qq', '-o', zipPath, '-d', contentsDir], {stdio: 'pipe'});
|
|
53
52
|
} catch {
|
|
54
53
|
throw new Error('downloaded bundle is not a readable zip');
|
|
55
54
|
}
|
|
@@ -78,7 +77,7 @@ async function migrateRelease({source, pulsarApp, deploymentName, sourcePackage,
|
|
|
78
77
|
} catch (err) {
|
|
79
78
|
return `not migrated: ${err.message}`;
|
|
80
79
|
} finally {
|
|
81
|
-
|
|
80
|
+
removeTemp(workDir);
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novacraft-engineering/pulsar-cli",
|
|
3
|
-
"version": "1.6.
|
|
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": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"migrate.js",
|
|
13
13
|
"private.js",
|
|
14
14
|
"hermes.js",
|
|
15
|
+
"temp.js",
|
|
15
16
|
"envelope.js",
|
|
16
17
|
"releaseCompare.js",
|
|
17
18
|
"README.md",
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"node": ">=18"
|
|
32
33
|
},
|
|
33
34
|
"scripts": {
|
|
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"
|
|
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"
|
|
35
36
|
},
|
|
36
37
|
"keywords": [
|
|
37
38
|
"cli",
|
package/pulsar.js
CHANGED
|
@@ -11,6 +11,7 @@ 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
13
|
import {bundleFileName, buildBytecode, findComposeScript, findHermesc, hermesChoice} from './hermes.js';
|
|
14
|
+
import {execFileSyncInterruptible, makeTempDir, removeTemp, trackTemp} from './temp.js';
|
|
14
15
|
|
|
15
16
|
// Code signing: sign the package hash into an RS256 JWT the client verifies against its
|
|
16
17
|
// CodePushPublicKey (Info.plist). Both native SDKs read it from <update>/CodePush/.codepushrelease
|
|
@@ -224,7 +225,7 @@ function bundle(platform, contentsDir, sourcemapPath, {forHermes = false} = {})
|
|
|
224
225
|
const bundleName = bundleFileName(platform);
|
|
225
226
|
fs.mkdirSync(contentsDir, {recursive: true});
|
|
226
227
|
console.log(forHermes ? `• bundling ${platform} unminified for the Hermes compiler, as React Native's release build does…` : `• bundling ${platform}…`);
|
|
227
|
-
|
|
228
|
+
execFileSyncInterruptible(
|
|
228
229
|
'npx',
|
|
229
230
|
[
|
|
230
231
|
'react-native',
|
|
@@ -260,9 +261,12 @@ function growthChecks(previous, {size, jsSize = null, hermes = false}) {
|
|
|
260
261
|
}
|
|
261
262
|
|
|
262
263
|
function zipContents(contentsDir) {
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
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;
|
|
266
270
|
}
|
|
267
271
|
|
|
268
272
|
// Build a differential package: only the files that changed vs the base, plus a hotcodepush.json
|
|
@@ -270,14 +274,16 @@ function zipContents(contentsDir) {
|
|
|
270
274
|
// this diff, then verifies the result against the target hash. Returns the diff dir, or null if the
|
|
271
275
|
// base couldn't be fetched.
|
|
272
276
|
async function buildDiffPackage(baseZip, newDir) {
|
|
273
|
-
const
|
|
274
|
-
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');
|
|
275
280
|
fs.writeFileSync(basePath, baseZip);
|
|
276
|
-
|
|
281
|
+
execFileSyncInterruptible('unzip', ['-qq', '-o', basePath, '-d', baseDir]);
|
|
277
282
|
|
|
278
283
|
const baseHashes = fileHashes(baseDir);
|
|
284
|
+
removeTemp(baseWorkDir);
|
|
279
285
|
const newHashes = fileHashes(newDir);
|
|
280
|
-
const diffDir =
|
|
286
|
+
const diffDir = makeTempDir('pulsar-diff-');
|
|
281
287
|
|
|
282
288
|
for (const [relativePath, hash] of Object.entries(newHashes)) {
|
|
283
289
|
if (baseHashes[relativePath] === hash) continue;
|
|
@@ -457,9 +463,9 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
457
463
|
await signForApp(app, deployment, contentsDir, packageHash, localKey);
|
|
458
464
|
if (hermes) await signForApp(app, deployment, javascript.contentsDir, javascript.packageHash, localKey, 'the JavaScript copy');
|
|
459
465
|
const sealFull = async (hash, bytes) => (sealing ? Buffer.from(await sealArtifact(privateBundles, app, hash, bytes, 'full')) : bytes);
|
|
460
|
-
const plainZip =
|
|
466
|
+
const plainZip = zipContents(contentsDir);
|
|
461
467
|
const zip = await sealFull(packageHash, plainZip);
|
|
462
|
-
const plainJsZip = hermes ?
|
|
468
|
+
const plainJsZip = hermes ? zipContents(javascript.contentsDir) : null;
|
|
463
469
|
const jsZip = hermes ? await sealFull(javascript.packageHash, plainJsZip) : null;
|
|
464
470
|
let prevLatest = null;
|
|
465
471
|
try {
|
|
@@ -626,7 +632,8 @@ async function pushBuiltRelease(app, deployment, args, contentsDir, packageHash,
|
|
|
626
632
|
baseZip = await openArtifact(privateBundles.keys, baseZip, {appId: app.id, packageHash: base.packageHash, kind: 'full'});
|
|
627
633
|
}
|
|
628
634
|
const diffDir = await buildDiffPackage(baseZip, contentsDir);
|
|
629
|
-
const plainDiff =
|
|
635
|
+
const plainDiff = zipContents(diffDir);
|
|
636
|
+
removeTemp(diffDir);
|
|
630
637
|
const diffZip = sealing
|
|
631
638
|
? Buffer.from(await sealArtifact(privateBundles, app, packageHash, plainDiff, 'diff', {baseHash: base.packageHash}))
|
|
632
639
|
: plainDiff;
|
|
@@ -679,14 +686,14 @@ function hermesCompiler(args, projectRoot = process.cwd()) {
|
|
|
679
686
|
function buildOnce(args, compiler = null) {
|
|
680
687
|
const platform = getFlag(args, 'platform', 'ios');
|
|
681
688
|
const localKey = localSigningKey(args);
|
|
682
|
-
const contentsDir =
|
|
683
|
-
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`);
|
|
684
691
|
bundle(platform, contentsDir, sourcemapPath);
|
|
685
692
|
const packageHash = computePackageHash(contentsDir);
|
|
686
693
|
console.log(`• hash ${packageHash.slice(0, 12)}…`);
|
|
687
694
|
if (!compiler) return {contentsDir, packageHash, localKey, sourcemapPath};
|
|
688
|
-
const sourceDir =
|
|
689
|
-
const sourceMapPath = sourcemapPath ? `${sourceDir}.map` : null;
|
|
695
|
+
const sourceDir = makeTempDir('pulsar-hermes-source-');
|
|
696
|
+
const sourceMapPath = sourcemapPath ? trackTemp(`${sourceDir}.map`) : null;
|
|
690
697
|
bundle(platform, sourceDir, sourceMapPath, {forHermes: true});
|
|
691
698
|
console.log(`• compiling Hermes bytecode with ${path.relative(process.cwd(), compiler.hermesc) || compiler.hermesc}…`);
|
|
692
699
|
let bytecode;
|
|
@@ -696,8 +703,8 @@ function buildOnce(args, compiler = null) {
|
|
|
696
703
|
} catch (err) {
|
|
697
704
|
compileError = err;
|
|
698
705
|
}
|
|
699
|
-
|
|
700
|
-
if (sourceMapPath)
|
|
706
|
+
removeTemp(sourceDir);
|
|
707
|
+
if (sourceMapPath) removeTemp(sourceMapPath);
|
|
701
708
|
if (compileError) die(`${compileError.message}\nPass --no-hermes to release JavaScript instead. Nothing was uploaded.`);
|
|
702
709
|
if (bytecode.sourcemapError) console.log(`⚠ bytecode source map not composed (${bytecode.sourcemapError}): crash stacks from bytecode won't show your source files`);
|
|
703
710
|
const bytecodeHash = computePackageHash(bytecode.contentsDir);
|
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)));
|