@gfean/react-native-bundle-drop 0.7.0 → 0.8.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 +215 -0
- package/android/build.gradle +7 -5
- package/lib/CLI/cli.js +5 -0
- package/lib/CLI/scripts/sight-artifacts.d.ts +9 -1
- package/lib/CLI/scripts/sight-artifacts.js +20 -8
- package/lib/CLI/scripts/sight-assets.d.ts +15 -0
- package/lib/CLI/scripts/sight-assets.js +71 -0
- package/lib/CLI/scripts/sight-cli.d.ts +3 -0
- package/lib/CLI/scripts/sight-cli.js +50 -4
- package/lib/CLI/scripts/sight-compare/assets.d.ts +6 -0
- package/lib/CLI/scripts/sight-compare/assets.js +73 -0
- package/lib/CLI/scripts/sight-compare/dependencies.d.ts +22 -0
- package/lib/CLI/scripts/sight-compare/dependencies.js +289 -0
- package/lib/CLI/scripts/sight-compare/git.d.ts +22 -0
- package/lib/CLI/scripts/sight-compare/git.js +116 -0
- package/lib/CLI/scripts/sight-compare/inspect-project.d.ts +37 -0
- package/lib/CLI/scripts/sight-compare/inspect-project.js +191 -0
- package/lib/CLI/scripts/sight-compare/metadata.d.ts +4 -0
- package/lib/CLI/scripts/sight-compare/metadata.js +39 -0
- package/lib/CLI/scripts/sight-compare/process.d.ts +22 -0
- package/lib/CLI/scripts/sight-compare/process.js +221 -0
- package/lib/CLI/scripts/sight-compare/run.d.ts +3 -0
- package/lib/CLI/scripts/sight-compare/run.js +290 -0
- package/lib/CLI/scripts/sight-compare/snapshot.d.ts +26 -0
- package/lib/CLI/scripts/sight-compare/snapshot.js +279 -0
- package/lib/CLI/scripts/sight-compare/types.d.ts +87 -0
- package/lib/CLI/scripts/sight-compare/types.js +2 -0
- package/lib/CLI/scripts/sight-ota.d.ts +18 -0
- package/lib/CLI/scripts/sight-ota.js +260 -0
- package/lib/CLI/scripts/sight-session.d.ts +9 -2
- package/lib/CLI/scripts/sight-session.js +58 -20
- package/lib/scripts/bundle.d.ts +3 -0
- package/lib/scripts/bundle.js +7 -4
- package/package.json +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { MobilePlatform, ProjectType } from '../../../expo';
|
|
2
|
+
import type { SightArtifacts } from '../sight-artifacts';
|
|
3
|
+
export type ComparisonEntryPoint = {
|
|
4
|
+
kind: 'relative' | 'module';
|
|
5
|
+
value: string;
|
|
6
|
+
};
|
|
7
|
+
export type ComparisonSourceContext = {
|
|
8
|
+
repositoryRoot: string;
|
|
9
|
+
projectRelativePath: string;
|
|
10
|
+
sourcesBase: string;
|
|
11
|
+
pathConvention?: 'filesystem' | 'expo-server-root';
|
|
12
|
+
};
|
|
13
|
+
export type ComparisonSide = {
|
|
14
|
+
label: string;
|
|
15
|
+
commit: string;
|
|
16
|
+
branch: string | null;
|
|
17
|
+
dirty: boolean;
|
|
18
|
+
projectType: ProjectType;
|
|
19
|
+
versions: {
|
|
20
|
+
reactNative: string;
|
|
21
|
+
expo?: string;
|
|
22
|
+
metro?: string;
|
|
23
|
+
};
|
|
24
|
+
packageManager: {
|
|
25
|
+
name: 'npm' | 'yarn' | 'pnpm';
|
|
26
|
+
version: string;
|
|
27
|
+
};
|
|
28
|
+
builtAt: string;
|
|
29
|
+
inputFingerprint: string;
|
|
30
|
+
configFingerprint: string;
|
|
31
|
+
sourceContext: ComparisonSourceContext;
|
|
32
|
+
};
|
|
33
|
+
export type ComparisonArtifactField = 'baselineBundle' | 'baselineSourceMap' | 'currentBundle' | 'currentSourceMap';
|
|
34
|
+
export type ComparisonArtifact = {
|
|
35
|
+
path: string;
|
|
36
|
+
bytes: number;
|
|
37
|
+
sha256: string;
|
|
38
|
+
};
|
|
39
|
+
export type ComparisonAssetEntry = {
|
|
40
|
+
path: string;
|
|
41
|
+
bytes: number;
|
|
42
|
+
sha256: string;
|
|
43
|
+
};
|
|
44
|
+
export type SightOtaMeasurement = {
|
|
45
|
+
status: 'available';
|
|
46
|
+
engine: 'hermes' | 'javascript';
|
|
47
|
+
bundleBytes: number;
|
|
48
|
+
zipBytes: number;
|
|
49
|
+
} | {
|
|
50
|
+
status: 'unavailable';
|
|
51
|
+
reason: string;
|
|
52
|
+
};
|
|
53
|
+
export type ComparisonAssetManifest = {
|
|
54
|
+
version: 1;
|
|
55
|
+
metric: 'emitted-asset-bytes';
|
|
56
|
+
baseline: ComparisonAssetEntry[];
|
|
57
|
+
current: ComparisonAssetEntry[];
|
|
58
|
+
ota?: {
|
|
59
|
+
baseline: SightOtaMeasurement;
|
|
60
|
+
current: SightOtaMeasurement;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export type ComparisonMetadata = {
|
|
64
|
+
version: 2;
|
|
65
|
+
mode: 'compare';
|
|
66
|
+
metric: 'javascript-utf8-bytes';
|
|
67
|
+
settings: {
|
|
68
|
+
platform: MobilePlatform;
|
|
69
|
+
dev: false;
|
|
70
|
+
minify: true;
|
|
71
|
+
nodeVersion: string;
|
|
72
|
+
entryPoint: ComparisonEntryPoint;
|
|
73
|
+
};
|
|
74
|
+
baseline: ComparisonSide;
|
|
75
|
+
current: ComparisonSide;
|
|
76
|
+
artifacts: Record<ComparisonArtifactField, ComparisonArtifact>;
|
|
77
|
+
assetManifest?: ComparisonArtifact;
|
|
78
|
+
includedPaths: string[];
|
|
79
|
+
warnings: string[];
|
|
80
|
+
};
|
|
81
|
+
export type ComparisonArtifacts = {
|
|
82
|
+
outputDirectory: string;
|
|
83
|
+
metadataPath: string;
|
|
84
|
+
assetManifestPath?: string;
|
|
85
|
+
baseline: SightArtifacts;
|
|
86
|
+
current: SightArtifacts;
|
|
87
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MobilePlatform, ProjectType } from '../../expo';
|
|
2
|
+
import type { DependencyProcessOptions } from './sight-compare/dependencies';
|
|
3
|
+
import type { SightOtaMeasurement } from './sight-compare/types';
|
|
4
|
+
export type MeasureSightOtaOptions = {
|
|
5
|
+
projectRoot: string;
|
|
6
|
+
snapshotRoot?: string;
|
|
7
|
+
projectType: ProjectType;
|
|
8
|
+
platform: MobilePlatform;
|
|
9
|
+
entryFile?: string;
|
|
10
|
+
bundlePath: string;
|
|
11
|
+
sourceMapPath: string;
|
|
12
|
+
assetsDirectory: string;
|
|
13
|
+
/** Existing invocation-owned directory; this helper removes only its nested temporary directory. */
|
|
14
|
+
workDirectory: string;
|
|
15
|
+
};
|
|
16
|
+
/** Executed in a separate process so project configuration and compiler children stay isolated. */
|
|
17
|
+
export declare function measureInstalledSightOta(options: MeasureSightOtaOptions): Promise<SightOtaMeasurement>;
|
|
18
|
+
export declare function measureSightOta(options: MeasureSightOtaOptions, processOptions?: DependencyProcessOptions): Promise<SightOtaMeasurement>;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.measureInstalledSightOta = measureInstalledSightOta;
|
|
7
|
+
exports.measureSightOta = measureSightOta;
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const module_1 = require("module");
|
|
12
|
+
const plist_1 = __importDefault(require("plist"));
|
|
13
|
+
const buildIdentity_1 = require("../../expo/buildIdentity");
|
|
14
|
+
const exportValidation_1 = require("../../expo/exportValidation");
|
|
15
|
+
const canonicalArtifact_1 = require("../../scripts/canonicalArtifact");
|
|
16
|
+
const bundle_1 = require("../../scripts/bundle");
|
|
17
|
+
const process_1 = require("./sight-compare/process");
|
|
18
|
+
const assets_1 = require("./sight-compare/assets");
|
|
19
|
+
const HERMES_MAGIC = Buffer.from([0xc6, 0x1f, 0xbc, 0x03, 0xc1, 0x03, 0x19, 0x1f]);
|
|
20
|
+
const unavailable = (reason) => ({ status: 'unavailable', reason });
|
|
21
|
+
function insideSnapshot(options, candidate) {
|
|
22
|
+
const resolved = fs_1.default.realpathSync(candidate);
|
|
23
|
+
if (options.snapshotRoot) {
|
|
24
|
+
const relative = path_1.default.relative(fs_1.default.realpathSync(options.snapshotRoot), resolved);
|
|
25
|
+
if (relative === '..' || relative.startsWith(`..${path_1.default.sep}`) || path_1.default.isAbsolute(relative)) {
|
|
26
|
+
throw new Error('The OTA toolchain resolved outside its isolated snapshot.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return resolved;
|
|
30
|
+
}
|
|
31
|
+
function concreteVersion(value) {
|
|
32
|
+
return typeof value === 'string' && /^\d+(?:\.\d+){0,3}(?:[-+][A-Za-z0-9.-]+)?$/.test(value);
|
|
33
|
+
}
|
|
34
|
+
function iosVersion(options, value) {
|
|
35
|
+
if (concreteVersion(value))
|
|
36
|
+
return value;
|
|
37
|
+
const variable = typeof value === 'string' && /^\$\(([A-Za-z_][A-Za-z0-9_]*)\)$/.exec(value)?.[1];
|
|
38
|
+
if (!variable)
|
|
39
|
+
return undefined;
|
|
40
|
+
const ios = path_1.default.join(options.projectRoot, 'ios');
|
|
41
|
+
const values = [];
|
|
42
|
+
for (const project of fs_1.default.readdirSync(ios).filter(name => name.endsWith('.xcodeproj'))) {
|
|
43
|
+
const file = path_1.default.join(ios, project, 'project.pbxproj');
|
|
44
|
+
if (!fs_1.default.existsSync(file))
|
|
45
|
+
continue;
|
|
46
|
+
const contents = fs_1.default.readFileSync(insideSnapshot(options, file), 'utf8');
|
|
47
|
+
const pattern = new RegExp(`^\\s*${variable}\\s*=\\s*([^;\\n]+);`, 'gm');
|
|
48
|
+
for (const match of contents.matchAll(pattern))
|
|
49
|
+
values.push(match[1].trim().replace(/^"(.*)"$/, '$1'));
|
|
50
|
+
}
|
|
51
|
+
return values.length > 0 && values.every(concreteVersion) && new Set(values).size === 1 ? values[0] : undefined;
|
|
52
|
+
}
|
|
53
|
+
/** Only literal, unambiguous native versions are used; no native build configuration is executed. */
|
|
54
|
+
function bareAppVersion(options) {
|
|
55
|
+
if (options.platform === 'android') {
|
|
56
|
+
const files = ['build.gradle', 'build.gradle.kts'].map(name => path_1.default.join(options.projectRoot, 'android', 'app', name)).filter(file => fs_1.default.existsSync(file));
|
|
57
|
+
if (files.length !== 1)
|
|
58
|
+
return undefined;
|
|
59
|
+
const contents = fs_1.default.readFileSync(insideSnapshot(options, files[0]), 'utf8');
|
|
60
|
+
const literals = [...contents.matchAll(/^\s*versionName\s*(?:=\s*)?['"]([^'"]+)['"]\s*;?\s*$/gm)].map(match => match[1]);
|
|
61
|
+
if (literals.length !== 1 || !concreteVersion(literals[0]))
|
|
62
|
+
return undefined;
|
|
63
|
+
return literals[0];
|
|
64
|
+
}
|
|
65
|
+
const ios = path_1.default.join(options.projectRoot, 'ios');
|
|
66
|
+
if (!fs_1.default.existsSync(ios))
|
|
67
|
+
return undefined;
|
|
68
|
+
const candidates = [path_1.default.join(ios, 'Info.plist')];
|
|
69
|
+
for (const item of fs_1.default.readdirSync(ios, { withFileTypes: true })) {
|
|
70
|
+
if (item.isDirectory() && !['Pods', 'build'].includes(item.name))
|
|
71
|
+
candidates.push(path_1.default.join(ios, item.name, 'Info.plist'));
|
|
72
|
+
}
|
|
73
|
+
const documents = candidates.filter(file => fs_1.default.existsSync(file)).map(file => plist_1.default.parse(fs_1.default.readFileSync(insideSnapshot(options, file), 'utf8')));
|
|
74
|
+
const applications = documents.filter(document => document.CFBundlePackageType === 'APPL');
|
|
75
|
+
// Test bundles and extensions have their own versions, unrelated to the app's OTA identity.
|
|
76
|
+
// Older app plists may omit the package type; use those only when no explicit app exists.
|
|
77
|
+
const appDocuments = applications.length > 0 ? applications : documents.filter(document => document.CFBundlePackageType === undefined && document.NSExtension === undefined);
|
|
78
|
+
const versions = appDocuments.map(document => iosVersion(options, document.CFBundleShortVersionString));
|
|
79
|
+
if (!versions.length || !versions.every(concreteVersion) || new Set(versions).size !== 1)
|
|
80
|
+
return undefined;
|
|
81
|
+
return versions[0];
|
|
82
|
+
}
|
|
83
|
+
function compilerPath(options, expo) {
|
|
84
|
+
const projectRequire = (0, module_1.createRequire)(path_1.default.join(options.projectRoot, 'package.json'));
|
|
85
|
+
const rnManifest = insideSnapshot(options, projectRequire.resolve('react-native/package.json'));
|
|
86
|
+
const rnRoot = path_1.default.dirname(rnManifest);
|
|
87
|
+
const osBin = process.platform === 'darwin' ? 'osx-bin' : process.platform === 'win32' ? 'win64-bin' : 'linux64-bin';
|
|
88
|
+
const executable = process.platform === 'win32' ? 'hermesc.exe' : 'hermesc';
|
|
89
|
+
const candidates = [path_1.default.join(rnRoot, 'sdks', 'hermesc', osBin, executable)];
|
|
90
|
+
for (const moduleId of expo ? ['hermes-compiler'] : ['hermes-compiler', 'hermes-engine']) {
|
|
91
|
+
let manifest;
|
|
92
|
+
try {
|
|
93
|
+
manifest = (0, module_1.createRequire)(rnManifest).resolve(`${moduleId}/package.json`);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Older React Native releases ship the compiler inside react-native itself.
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const root = path_1.default.dirname(insideSnapshot(options, manifest));
|
|
100
|
+
const compiler = path_1.default.join(root, ...(moduleId === 'hermes-compiler' ? ['hermesc'] : []), osBin, executable);
|
|
101
|
+
if (expo)
|
|
102
|
+
candidates.unshift(compiler);
|
|
103
|
+
else
|
|
104
|
+
candidates.push(compiler);
|
|
105
|
+
}
|
|
106
|
+
if (expo) {
|
|
107
|
+
// Expo's serializer checks source-built and overridden compilers before npm binaries.
|
|
108
|
+
candidates.unshift(path_1.default.join(rnRoot, 'ReactAndroid', 'hermes-engine', 'build', 'hermes', 'bin', 'hermesc'));
|
|
109
|
+
if (process.env.REACT_NATIVE_OVERRIDE_HERMES_DIR) {
|
|
110
|
+
candidates.unshift(path_1.default.join(process.env.REACT_NATIVE_OVERRIDE_HERMES_DIR, 'build', 'bin', 'hermesc'));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const selected = candidates.find(candidate => fs_1.default.existsSync(candidate) && fs_1.default.statSync(candidate).isFile());
|
|
114
|
+
return selected ? insideSnapshot(options, selected) : undefined;
|
|
115
|
+
}
|
|
116
|
+
/** Executed in a separate process so project configuration and compiler children stay isolated. */
|
|
117
|
+
async function measureInstalledSightOta(options) {
|
|
118
|
+
let reason = 'The project configuration could not be read for Bundle Drop OTA packaging.';
|
|
119
|
+
try {
|
|
120
|
+
let appVersion;
|
|
121
|
+
let runtimeVersion;
|
|
122
|
+
let hermes;
|
|
123
|
+
let expoRequire;
|
|
124
|
+
if (options.projectType === 'expo') {
|
|
125
|
+
reason = 'The Expo configuration could not resolve a local app version and runtime version for Bundle Drop OTA packaging.';
|
|
126
|
+
const projectRequire = (0, module_1.createRequire)(path_1.default.join(options.projectRoot, 'package.json'));
|
|
127
|
+
expoRequire = (0, module_1.createRequire)(insideSnapshot(options, projectRequire.resolve('expo/package.json')));
|
|
128
|
+
const envLoader = expoRequire(insideSnapshot(options, expoRequire.resolve('@expo/cli/build/src/utils/nodeEnv')));
|
|
129
|
+
envLoader.loadEnvFiles(options.projectRoot);
|
|
130
|
+
const identity = await (0, buildIdentity_1.resolveExpoBuildIdentity)(options.projectRoot, options.platform);
|
|
131
|
+
appVersion = identity.appVersion;
|
|
132
|
+
runtimeVersion = identity.runtimeVersion;
|
|
133
|
+
hermes = identity.javaScriptEngine === 'hermes';
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const configPath = path_1.default.join(options.projectRoot, 'bundle.drop.config.js');
|
|
137
|
+
if (!fs_1.default.existsSync(configPath))
|
|
138
|
+
return unavailable('This project has no bundle.drop.config.js. Configure Bundle Drop to measure its OTA archive.');
|
|
139
|
+
const config = (0, module_1.createRequire)(path_1.default.join(options.projectRoot, 'package.json'))(insideSnapshot(options, configPath));
|
|
140
|
+
const runtime = config.runtimeVersion?.[options.platform];
|
|
141
|
+
if (typeof runtime !== 'string' || !runtime.trim()) {
|
|
142
|
+
return unavailable(`Bundle Drop has no runtime version configured for ${options.platform}. Set runtimeVersion.${options.platform} in bundle.drop.config.js.`);
|
|
143
|
+
}
|
|
144
|
+
reason = `The native ${options.platform} app version could not be resolved unambiguously for Bundle Drop OTA packaging.`;
|
|
145
|
+
const version = bareAppVersion(options);
|
|
146
|
+
if (!version)
|
|
147
|
+
return unavailable(reason);
|
|
148
|
+
appVersion = version;
|
|
149
|
+
runtimeVersion = runtime;
|
|
150
|
+
hermes = (0, bundle_1.shouldCompileHermesBytecode)(config, options.platform, options.projectRoot);
|
|
151
|
+
}
|
|
152
|
+
const bundlePath = path_1.default.join(options.workDirectory, 'main.jsbundle');
|
|
153
|
+
let assetsDirectory = options.assetsDirectory;
|
|
154
|
+
reason = 'The enabled Hermes compiler is unavailable or could not produce valid bytecode for this build.';
|
|
155
|
+
if (hermes) {
|
|
156
|
+
const compiler = compilerPath(options, options.projectType === 'expo');
|
|
157
|
+
if (!compiler)
|
|
158
|
+
return unavailable(reason);
|
|
159
|
+
if (expoRequire) {
|
|
160
|
+
// Expo changes Metro transforms for --bytecode, so compiling the analysis JavaScript
|
|
161
|
+
// directly would not measure the output of its normal OTA export pipeline.
|
|
162
|
+
const paths = expoRequire(insideSnapshot(options, expoRequire.resolve('@expo/config/paths')));
|
|
163
|
+
const entry = options.entryFile ?? paths.resolveEntryPoint(options.projectRoot, { platform: options.platform });
|
|
164
|
+
if (!entry)
|
|
165
|
+
return unavailable(reason);
|
|
166
|
+
const entryFile = insideSnapshot(options, path_1.default.resolve(options.projectRoot, entry));
|
|
167
|
+
const cli = insideSnapshot(options, expoRequire.resolve('@expo/cli'));
|
|
168
|
+
const sourceMapPath = path_1.default.join(options.workDirectory, 'main.jsbundle.map');
|
|
169
|
+
assetsDirectory = path_1.default.join(options.workDirectory, 'assets');
|
|
170
|
+
fs_1.default.mkdirSync(assetsDirectory);
|
|
171
|
+
const compiled = (0, child_process_1.spawnSync)(process.execPath, [cli, 'export:embed', '--platform', options.platform,
|
|
172
|
+
'--entry-file', entryFile, '--bundle-output', bundlePath, '--assets-dest', assetsDirectory,
|
|
173
|
+
'--sourcemap-output', sourceMapPath, '--dev', 'false', '--minify', 'true', '--bytecode', '--reset-cache'], {
|
|
174
|
+
cwd: options.projectRoot, env: process.env, stdio: ['ignore', 'ignore', 'inherit'], shell: false,
|
|
175
|
+
});
|
|
176
|
+
if (compiled.error || compiled.status !== 0) {
|
|
177
|
+
console.error('Sight Expo bytecode export failed.', compiled.error ?? compiled.status);
|
|
178
|
+
return unavailable(reason);
|
|
179
|
+
}
|
|
180
|
+
(0, exportValidation_1.validateExpoExportOutput)({ outputDirectory: options.workDirectory, bundlePath, sourceMapPath, assetsDirectory });
|
|
181
|
+
const signal = new AbortController().signal;
|
|
182
|
+
const originalAssets = await (0, assets_1.collectComparisonAssets)(options.assetsDirectory, signal);
|
|
183
|
+
const compiledAssets = await (0, assets_1.collectComparisonAssets)(assetsDirectory, signal);
|
|
184
|
+
if (JSON.stringify(originalAssets) !== JSON.stringify(compiledAssets)) {
|
|
185
|
+
return unavailable('The Expo bytecode export emitted different assets from the JavaScript analysis build.');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
const flags = (0, bundle_1.buildHermesFlags)(compiler, true, child_process_1.spawnSync);
|
|
190
|
+
const compiled = (0, child_process_1.spawnSync)(compiler, [...flags, '-out', bundlePath, options.bundlePath], { cwd: options.projectRoot, env: process.env, stdio: ['ignore', 'ignore', 'inherit'], shell: false });
|
|
191
|
+
if (compiled.error || compiled.status !== 0) {
|
|
192
|
+
console.error('Sight Hermes compilation failed.', compiled.error ?? compiled.status);
|
|
193
|
+
return unavailable(reason);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const magic = Buffer.alloc(HERMES_MAGIC.length);
|
|
197
|
+
const descriptor = fs_1.default.openSync(bundlePath, 'r');
|
|
198
|
+
try {
|
|
199
|
+
fs_1.default.readSync(descriptor, magic, 0, magic.length, 0);
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
fs_1.default.closeSync(descriptor);
|
|
203
|
+
}
|
|
204
|
+
if (!magic.equals(HERMES_MAGIC))
|
|
205
|
+
return unavailable(reason);
|
|
206
|
+
}
|
|
207
|
+
else
|
|
208
|
+
fs_1.default.copyFileSync(options.bundlePath, bundlePath);
|
|
209
|
+
reason = 'The generated files could not be packaged into a valid local Bundle Drop OTA archive.';
|
|
210
|
+
const artifact = (0, canonicalArtifact_1.buildCanonicalArtifact)({
|
|
211
|
+
platform: options.platform, appVersion, runtimeVersion, bundlePath,
|
|
212
|
+
assetsDir: assetsDirectory, outputDir: options.workDirectory,
|
|
213
|
+
// Sight's inventory rejects symlinks; strict canonical traversal preserves that boundary.
|
|
214
|
+
assetTraversal: 'strict',
|
|
215
|
+
});
|
|
216
|
+
return { status: 'available', engine: hermes ? 'hermes' : 'javascript', bundleBytes: fs_1.default.statSync(bundlePath).size, zipBytes: fs_1.default.statSync(artifact.zipPath).size };
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
// Child stderr is retained in the invocation's local diagnostic log, never in browser metadata.
|
|
220
|
+
console.error('Sight local OTA measurement failed.', error);
|
|
221
|
+
return unavailable(reason);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const resultMarker = 'BUNDLE_DROP_SIGHT_OTA=';
|
|
225
|
+
const childScript = `const helper=require(process.argv[1]);helper.measureInstalledSightOta(JSON.parse(process.argv[2])).then(result=>process.stdout.write('\\n${resultMarker}'+JSON.stringify(result)+'\\n')).catch(error=>{console.error(error);process.exitCode=1;});`;
|
|
226
|
+
async function measureSightOta(options, processOptions = {}) {
|
|
227
|
+
const controller = processOptions.signal ? undefined : new AbortController();
|
|
228
|
+
const signal = processOptions.signal ?? controller.signal;
|
|
229
|
+
const abort = () => controller.abort();
|
|
230
|
+
if (controller) {
|
|
231
|
+
process.on('SIGINT', abort);
|
|
232
|
+
process.on('SIGTERM', abort);
|
|
233
|
+
}
|
|
234
|
+
let directory;
|
|
235
|
+
try {
|
|
236
|
+
(0, process_1.checkComparisonAbort)(signal);
|
|
237
|
+
directory = fs_1.default.mkdtempSync(path_1.default.join(options.workDirectory, 'sight-ota-'));
|
|
238
|
+
const result = await (0, process_1.runComparisonProcess)({
|
|
239
|
+
command: process.execPath, args: ['-e', childScript, __filename, JSON.stringify({ ...options, workDirectory: directory })],
|
|
240
|
+
cwd: options.projectRoot, phase: 'Measure local OTA artifact', signal,
|
|
241
|
+
env: processOptions.env, logPath: processOptions.logPath,
|
|
242
|
+
});
|
|
243
|
+
const line = result.stdout.split('\n').reverse().find(value => value.startsWith(resultMarker));
|
|
244
|
+
if (!line)
|
|
245
|
+
return unavailable('The local OTA measurement did not return a result.');
|
|
246
|
+
return JSON.parse(line.slice(resultMarker.length));
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
(0, process_1.checkComparisonAbort)(signal);
|
|
250
|
+
return unavailable('The local OTA measurement could not be completed.');
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
if (controller) {
|
|
254
|
+
process.removeListener('SIGINT', abort);
|
|
255
|
+
process.removeListener('SIGTERM', abort);
|
|
256
|
+
}
|
|
257
|
+
if (directory)
|
|
258
|
+
fs_1.default.rmSync(directory, { recursive: true, force: true });
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import type { SightArtifacts } from './sight-artifacts';
|
|
2
|
+
import type { ComparisonArtifacts } from './sight-compare/types';
|
|
2
3
|
export type SightSession = {
|
|
3
4
|
sightUrl: string;
|
|
4
5
|
waitForTransfer: () => Promise<void>;
|
|
5
6
|
close: () => Promise<void>;
|
|
6
7
|
};
|
|
7
|
-
type StartSightSessionOptions = {
|
|
8
|
+
type StartSightSessionOptions = ({
|
|
8
9
|
artifacts: SightArtifacts;
|
|
10
|
+
comparison?: never;
|
|
11
|
+
} | {
|
|
12
|
+
artifacts?: never;
|
|
13
|
+
comparison: ComparisonArtifacts;
|
|
14
|
+
}) & {
|
|
9
15
|
sightPageUrl: string;
|
|
10
16
|
timeoutMs?: number;
|
|
17
|
+
signal?: AbortSignal;
|
|
11
18
|
};
|
|
12
19
|
export declare function openSightInBrowser(url: string): Promise<void>;
|
|
13
|
-
export declare function startSightSession({ artifacts, sightPageUrl, timeoutMs, }: StartSightSessionOptions): Promise<SightSession>;
|
|
20
|
+
export declare function startSightSession({ artifacts, comparison, sightPageUrl, timeoutMs, signal, }: StartSightSessionOptions): Promise<SightSession>;
|
|
14
21
|
export {};
|
|
@@ -10,10 +10,11 @@ const crypto_1 = require("crypto");
|
|
|
10
10
|
const fs_1 = __importDefault(require("fs"));
|
|
11
11
|
const http_1 = __importDefault(require("http"));
|
|
12
12
|
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const assets_1 = require("./sight-compare/assets");
|
|
13
14
|
const SESSION_TIMEOUT_MS = 5 * 60 * 1000;
|
|
14
15
|
const LOOPBACK_HOST = '127.0.0.1';
|
|
15
|
-
function sessionFragment(port, token) {
|
|
16
|
-
const payload = Buffer.from(JSON.stringify({ version
|
|
16
|
+
function sessionFragment(port, token, version) {
|
|
17
|
+
const payload = Buffer.from(JSON.stringify({ version, port, token }), 'utf8')
|
|
17
18
|
.toString('base64url');
|
|
18
19
|
return `sight-session=${payload}`;
|
|
19
20
|
}
|
|
@@ -28,10 +29,8 @@ function writeFilePart(response, header, filePath, signal) {
|
|
|
28
29
|
const input = fs_1.default.createReadStream(filePath);
|
|
29
30
|
const cleanup = () => signal.removeEventListener('abort', abort);
|
|
30
31
|
const abort = () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: new Error('Sight closed the local artifact transfer.');
|
|
34
|
-
input.destroy(reason);
|
|
32
|
+
// This private transfer controller is always aborted with an Error below.
|
|
33
|
+
input.destroy(signal.reason);
|
|
35
34
|
};
|
|
36
35
|
input.once('error', error => {
|
|
37
36
|
cleanup();
|
|
@@ -46,16 +45,14 @@ function writeFilePart(response, header, filePath, signal) {
|
|
|
46
45
|
input.pipe(response, { end: false });
|
|
47
46
|
});
|
|
48
47
|
}
|
|
49
|
-
function closeServer(server, sockets
|
|
48
|
+
function closeServer(server, sockets) {
|
|
50
49
|
return new Promise(resolve => {
|
|
51
50
|
if (!server.listening) {
|
|
52
51
|
resolve();
|
|
53
52
|
return;
|
|
54
53
|
}
|
|
55
54
|
server.close(() => resolve());
|
|
56
|
-
|
|
57
|
-
sockets.forEach(socket => socket.destroy());
|
|
58
|
-
}
|
|
55
|
+
sockets.forEach(socket => socket.destroy());
|
|
59
56
|
});
|
|
60
57
|
}
|
|
61
58
|
function openSightInBrowser(url) {
|
|
@@ -77,7 +74,8 @@ function openSightInBrowser(url) {
|
|
|
77
74
|
});
|
|
78
75
|
});
|
|
79
76
|
}
|
|
80
|
-
async function startSightSession({ artifacts, sightPageUrl, timeoutMs = SESSION_TIMEOUT_MS, }) {
|
|
77
|
+
async function startSightSession({ artifacts, comparison, sightPageUrl, timeoutMs = SESSION_TIMEOUT_MS, signal, }) {
|
|
78
|
+
signal?.throwIfAborted();
|
|
81
79
|
const pageUrl = new URL(sightPageUrl);
|
|
82
80
|
const isOfficialSightPage = pageUrl.origin === 'https://bundledrop.app' && pageUrl.pathname === '/sight';
|
|
83
81
|
const isLocalSightPage = ['http:', 'https:'].includes(pageUrl.protocol) &&
|
|
@@ -97,6 +95,8 @@ async function startSightSession({ artifacts, sightPageUrl, timeoutMs = SESSION_
|
|
|
97
95
|
settleTransfer = resolve;
|
|
98
96
|
rejectTransfer = reject;
|
|
99
97
|
});
|
|
98
|
+
// Cancellation can arrive before the caller starts waiting for the transfer.
|
|
99
|
+
void transfer.catch(() => undefined);
|
|
100
100
|
const server = http_1.default.createServer(async (request, response) => {
|
|
101
101
|
const origin = request.headers.origin;
|
|
102
102
|
const isAllowedOrigin = origin === allowedOrigin;
|
|
@@ -140,7 +140,7 @@ async function startSightSession({ artifacts, sightPageUrl, timeoutMs = SESSION_
|
|
|
140
140
|
const error = new Error('Bundle Drop Sight closed before the generated files finished loading.');
|
|
141
141
|
transferAbort.abort(error);
|
|
142
142
|
rejectTransfer?.(error);
|
|
143
|
-
void closeServer(server, sockets
|
|
143
|
+
void closeServer(server, sockets);
|
|
144
144
|
};
|
|
145
145
|
request.once('aborted', rejectPrematureClose);
|
|
146
146
|
response.once('close', rejectPrematureClose);
|
|
@@ -153,15 +153,39 @@ async function startSightSession({ artifacts, sightPageUrl, timeoutMs = SESSION_
|
|
|
153
153
|
'X-Content-Type-Options': 'nosniff',
|
|
154
154
|
});
|
|
155
155
|
try {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
const files = comparison
|
|
157
|
+
? [
|
|
158
|
+
['baselineBundle', comparison.baseline.bundlePath],
|
|
159
|
+
['baselineSourceMap', comparison.baseline.sourceMapPath],
|
|
160
|
+
['currentBundle', comparison.current.bundlePath],
|
|
161
|
+
['currentSourceMap', comparison.current.sourceMapPath],
|
|
162
|
+
]
|
|
163
|
+
: [['bundle', artifacts.bundlePath], ['sourceMap', artifacts.sourceMapPath]];
|
|
164
|
+
const assetManifestPath = comparison?.assetManifestPath ?? artifacts?.assetManifestPath;
|
|
165
|
+
if (assetManifestPath) {
|
|
166
|
+
if (fs_1.default.statSync(assetManifestPath).size > assets_1.MAX_ASSET_MANIFEST_BYTES) {
|
|
167
|
+
throw new Error('Sight asset manifest exceeds 4 MiB.');
|
|
168
|
+
}
|
|
169
|
+
files.push(['assetManifest', assetManifestPath]);
|
|
170
|
+
}
|
|
171
|
+
if (comparison) {
|
|
172
|
+
const metadata = fs_1.default.readFileSync(comparison.metadataPath);
|
|
173
|
+
if (metadata.length > 64 * 1024)
|
|
174
|
+
throw new Error('Sight comparison metadata exceeds 64 KiB.');
|
|
175
|
+
response.write(`--${boundary}\r\nContent-Disposition: form-data; name="metadata"\r\nContent-Type: application/json\r\n\r\n`);
|
|
176
|
+
response.write(metadata);
|
|
177
|
+
response.write('\r\n');
|
|
178
|
+
}
|
|
179
|
+
for (const [field, filePath] of files) {
|
|
180
|
+
await writeFilePart(response, multipartHeader(boundary, field, filePath), filePath, transferAbort.signal);
|
|
181
|
+
response.write('\r\n');
|
|
182
|
+
}
|
|
159
183
|
response.once('finish', () => {
|
|
160
184
|
request.removeListener('aborted', rejectPrematureClose);
|
|
161
185
|
response.removeListener('close', rejectPrematureClose);
|
|
162
186
|
settleTransfer?.();
|
|
163
187
|
});
|
|
164
|
-
response.end(
|
|
188
|
+
response.end(`--${boundary}--\r\n`);
|
|
165
189
|
}
|
|
166
190
|
catch (error) {
|
|
167
191
|
response.destroy(error instanceof Error ? error : undefined);
|
|
@@ -178,15 +202,29 @@ async function startSightSession({ artifacts, sightPageUrl, timeoutMs = SESSION_
|
|
|
178
202
|
});
|
|
179
203
|
const timeout = setTimeout(() => {
|
|
180
204
|
rejectTransfer?.(new Error('Timed out waiting for Bundle Drop Sight to load the generated files.'));
|
|
181
|
-
void closeServer(server, sockets
|
|
205
|
+
void closeServer(server, sockets);
|
|
182
206
|
}, timeoutMs);
|
|
183
207
|
timeout.unref();
|
|
184
|
-
void transfer.finally(() => clearTimeout(timeout)).catch(() => undefined);
|
|
185
208
|
const address = server.address();
|
|
186
|
-
|
|
209
|
+
const abort = () => {
|
|
210
|
+
rejectTransfer?.(new Error('Sight comparison cancelled during local transfer.'));
|
|
211
|
+
void closeServer(server, sockets);
|
|
212
|
+
};
|
|
213
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
214
|
+
if (signal?.aborted)
|
|
215
|
+
abort();
|
|
216
|
+
const clearSession = () => {
|
|
217
|
+
clearTimeout(timeout);
|
|
218
|
+
signal?.removeEventListener('abort', abort);
|
|
219
|
+
};
|
|
220
|
+
void transfer.finally(clearSession).catch(() => undefined);
|
|
221
|
+
pageUrl.hash = sessionFragment(address.port, token, comparison ? 2 : 1);
|
|
187
222
|
return {
|
|
188
223
|
sightUrl: pageUrl.toString(),
|
|
189
224
|
waitForTransfer: () => transfer,
|
|
190
|
-
close: () =>
|
|
225
|
+
close: () => {
|
|
226
|
+
clearSession();
|
|
227
|
+
return closeServer(server, sockets);
|
|
228
|
+
},
|
|
191
229
|
};
|
|
192
230
|
}
|
package/lib/scripts/bundle.d.ts
CHANGED
|
@@ -12,6 +12,9 @@ type BundleScriptOptions = {
|
|
|
12
12
|
spawnProcess?: SpawnProcess;
|
|
13
13
|
resolveModule?: ModuleResolver;
|
|
14
14
|
};
|
|
15
|
+
export declare const buildHermesFlags: (hermescPath: string, generateSourceMap: boolean, spawnProcess: SpawnProcess) => string[];
|
|
16
|
+
export declare const detectHermesFromNativeProject: (projectRoot: string, platform: string) => boolean | undefined;
|
|
17
|
+
export declare const shouldCompileHermesBytecode: (cfg: Record<string, unknown>, platform: string, projectRoot: string) => boolean;
|
|
15
18
|
export declare function runBundleScript(options?: BundleScriptOptions): {
|
|
16
19
|
outputDir: string;
|
|
17
20
|
bundlePath: string;
|
package/lib/scripts/bundle.js
CHANGED
|
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.findProjectRoot = void 0;
|
|
37
|
+
exports.shouldCompileHermesBytecode = exports.detectHermesFromNativeProject = exports.buildHermesFlags = exports.findProjectRoot = void 0;
|
|
38
38
|
exports.runBundleScript = runBundleScript;
|
|
39
39
|
const child_process_1 = require("child_process");
|
|
40
40
|
const fs = __importStar(require("fs"));
|
|
@@ -133,6 +133,7 @@ const buildHermesFlags = (hermescPath, generateSourceMap, spawnProcess) => {
|
|
|
133
133
|
}
|
|
134
134
|
return flags;
|
|
135
135
|
};
|
|
136
|
+
exports.buildHermesFlags = buildHermesFlags;
|
|
136
137
|
const promoteHermesBytecode = (hbcPath, bundlePath) => {
|
|
137
138
|
if (!fs.existsSync(hbcPath)) {
|
|
138
139
|
throw new Error(`Hermes compiler did not write bytecode output at ${hbcPath}`);
|
|
@@ -180,12 +181,13 @@ const detectHermesFromNativeProject = (projectRoot, platform) => {
|
|
|
180
181
|
/\bUSE_HERMES\s*=\s*false\s*;/,
|
|
181
182
|
]);
|
|
182
183
|
};
|
|
184
|
+
exports.detectHermesFromNativeProject = detectHermesFromNativeProject;
|
|
183
185
|
const shouldCompileHermesBytecode = (cfg, platform, projectRoot) => {
|
|
184
186
|
const explicit = readPlatformSetting(cfg.hermesBytecode, platform) ??
|
|
185
187
|
readPlatformSetting(cfg.hermes, platform);
|
|
186
188
|
if (typeof explicit === 'boolean')
|
|
187
189
|
return explicit;
|
|
188
|
-
const detected = detectHermesFromNativeProject(projectRoot, platform);
|
|
190
|
+
const detected = (0, exports.detectHermesFromNativeProject)(projectRoot, platform);
|
|
189
191
|
if (detected !== undefined)
|
|
190
192
|
return detected;
|
|
191
193
|
if (explicit === 'auto') {
|
|
@@ -193,6 +195,7 @@ const shouldCompileHermesBytecode = (cfg, platform, projectRoot) => {
|
|
|
193
195
|
}
|
|
194
196
|
return false;
|
|
195
197
|
};
|
|
198
|
+
exports.shouldCompileHermesBytecode = shouldCompileHermesBytecode;
|
|
196
199
|
function runBundleScript(options = {}) {
|
|
197
200
|
const packageRoot = options.packageRoot || path.resolve(__dirname, '..', '..');
|
|
198
201
|
const spawnProcess = options.spawnProcess || child_process_1.spawnSync;
|
|
@@ -231,7 +234,7 @@ function runBundleScript(options = {}) {
|
|
|
231
234
|
console.error('❌ BUNDLE_DROP_APP_VERSION is required so bundle-manifest.json can include the app version');
|
|
232
235
|
process.exit(1);
|
|
233
236
|
}
|
|
234
|
-
const hermesEnabled = shouldCompileHermesBytecode(cfg, platform, projectRoot);
|
|
237
|
+
const hermesEnabled = (0, exports.shouldCompileHermesBytecode)(cfg, platform, projectRoot);
|
|
235
238
|
[bundlePath, zipPath, metadataPath, manifestPath, sourceMapPath].forEach(file => {
|
|
236
239
|
assertGeneratedPath(file, outputDir);
|
|
237
240
|
if (fs.existsSync(file))
|
|
@@ -294,7 +297,7 @@ function runBundleScript(options = {}) {
|
|
|
294
297
|
const hbcPath = bundlePath + '.hbc';
|
|
295
298
|
try {
|
|
296
299
|
console.log(`🔥 Compiling to Hermes bytecode (${platform})...`);
|
|
297
|
-
const hermesFlags = buildHermesFlags(hermescPath, generateSourceMap, spawnProcess);
|
|
300
|
+
const hermesFlags = (0, exports.buildHermesFlags)(hermescPath, generateSourceMap, spawnProcess);
|
|
298
301
|
runProcess(spawnProcess, hermescPath, [...hermesFlags, '-out', hbcPath, bundlePath], { stdio: ['ignore', 'ignore', 'ignore'] });
|
|
299
302
|
promoteHermesBytecode(hbcPath, bundlePath);
|
|
300
303
|
console.log('✅ Hermes bytecode compiled');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gfean/react-native-bundle-drop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"nativeVersion": "0.6.0",
|
|
5
5
|
"description": "Over-the-air updates for Expo and bare React Native apps, with channels, staged rollouts, patch delivery, and rollback.",
|
|
6
6
|
"main": "lib/index.js",
|