@gfean/react-native-bundle-drop 0.6.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/BundleDrop.podspec +96 -0
- package/README.md +249 -9
- package/android/build.gradle +72 -5
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +137 -13
- package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
- package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
- package/ios/BundleDropBridge.m +27 -0
- package/ios/BundleDropLocator.swift +31 -15
- package/ios/BundleDropModule.swift +106 -3
- package/ios/BundleDropOtaResolver.swift +137 -29
- package/ios/BundleDropStartupRecovery.swift +1108 -0
- package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
- package/lib/CLI/cli.js +9 -5
- package/lib/CLI/scripts/doctor.js +28 -9
- package/lib/CLI/scripts/expo/configure-expo.js +2 -1
- package/lib/CLI/scripts/init-config.d.ts +2 -2
- package/lib/CLI/scripts/init-config.js +23 -14
- package/lib/CLI/scripts/login-cli.js +2 -3
- package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
- package/lib/CLI/scripts/native/write-runtime-identity.js +92 -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/CLI/scripts/upload-cli.d.ts +12 -2
- package/lib/CLI/scripts/upload-cli.js +74 -11
- package/lib/CLI/serverUrl.d.ts +3 -0
- package/lib/CLI/serverUrl.js +31 -0
- package/lib/bundleInfo.d.ts +2 -0
- package/lib/bundleInfo.js +16 -1
- package/lib/context.js +12 -2
- package/lib/fs/bundlePointer.d.ts +1 -17
- package/lib/fs/bundlePointer.js +5 -93
- package/lib/install/bundleInstallShared.js +4 -4
- package/lib/manager/downloadAndInstall.js +25 -22
- package/lib/manager/reporting.d.ts +8 -1
- package/lib/manager/reporting.js +17 -22
- package/lib/manager/rollbackState.d.ts +18 -54
- package/lib/manager/rollbackState.js +115 -216
- package/lib/manager/updateCheck.js +9 -3
- package/lib/manager/updateState.d.ts +2 -1
- package/lib/manager/updateState.js +59 -6
- package/lib/metro.d.ts +1 -1
- package/lib/metro.js +4 -3
- package/lib/native/bundleDropNative.d.ts +62 -0
- package/lib/native/bundleDropNative.js +266 -1
- package/lib/patch-engine/installFromPatchSet.js +2 -2
- package/lib/runtime/service.js +29 -71
- package/lib/runtime-delivery/bootstrapConfig.d.ts +29 -11
- package/lib/runtime-delivery/bootstrapConfig.js +83 -22
- package/lib/runtime-delivery/manifestState.d.ts +3 -1
- package/lib/runtime-delivery/manifestState.js +22 -1
- package/lib/runtime-delivery/manifestVerifier.js +7 -1
- package/lib/scripts/bundle.d.ts +12 -2
- package/lib/scripts/bundle.js +74 -21
- package/lib/scripts/download-bundle.d.ts +1 -0
- package/lib/scripts/download-bundle.js +2 -2
- package/lib/scripts/resolveModule.d.ts +2 -0
- package/lib/scripts/resolveModule.js +5 -0
- package/package.json +5 -2
- package/plugin/xcodeBuildPhase.js +2 -1
|
@@ -0,0 +1,279 @@
|
|
|
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.createComparisonSnapshots = createComparisonSnapshots;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const crypto_1 = require("crypto");
|
|
11
|
+
const git_1 = require("./git");
|
|
12
|
+
const process_1 = require("./process");
|
|
13
|
+
function isWithin(root, candidate) {
|
|
14
|
+
const relative = path_1.default.relative(root, candidate);
|
|
15
|
+
return relative !== '..' && !relative.startsWith(`..${path_1.default.sep}`) && !path_1.default.isAbsolute(relative);
|
|
16
|
+
}
|
|
17
|
+
function baselineLinkTarget(repositoryRoot, baselineRoot, link) {
|
|
18
|
+
if (isWithin(repositoryRoot, link))
|
|
19
|
+
return path_1.default.join(baselineRoot, path_1.default.relative(repositoryRoot, link));
|
|
20
|
+
// Recognize repository aliases (for example /var on macOS) without resolving
|
|
21
|
+
// the target against current files: it may exist only in the baseline.
|
|
22
|
+
let ancestor = path_1.default.dirname(link);
|
|
23
|
+
while (true) {
|
|
24
|
+
if (fs_1.default.existsSync(ancestor) && fs_1.default.realpathSync(ancestor) === repositoryRoot) {
|
|
25
|
+
return path_1.default.join(baselineRoot, path_1.default.relative(ancestor, link));
|
|
26
|
+
}
|
|
27
|
+
const parent = path_1.default.dirname(ancestor);
|
|
28
|
+
if (parent === ancestor)
|
|
29
|
+
return undefined;
|
|
30
|
+
ancestor = parent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function forbiddenPath(name) {
|
|
34
|
+
const parts = name.split('/');
|
|
35
|
+
return parts.some(part => part === '.git' || part === 'node_modules' || part === '.pnp.cjs' || part === '.pnp.loader.mjs') ||
|
|
36
|
+
/(^|\/)\.bundle-drop\/sight(?:\/|$)/.test(name) ||
|
|
37
|
+
/(^|\/)\.yarn\/(?:install-state\.gz|unplugged)(?:\/|$)/.test(name);
|
|
38
|
+
}
|
|
39
|
+
function parseTree(output) {
|
|
40
|
+
return output.split('\0').filter(Boolean).map(line => {
|
|
41
|
+
const separator = line.indexOf('\t');
|
|
42
|
+
return { mode: line.slice(0, 6), name: line.slice(separator + 1) };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function relevantToApp(name, appRelativePath) {
|
|
46
|
+
if (!appRelativePath)
|
|
47
|
+
return true;
|
|
48
|
+
const app = appRelativePath.split(path_1.default.sep).join('/');
|
|
49
|
+
return name === app || name.startsWith(`${app}/`) || app.startsWith(`${name}/`);
|
|
50
|
+
}
|
|
51
|
+
function validateTree(entries, appRelativePath) {
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
if (entry.name.split('/').includes('node_modules')) {
|
|
54
|
+
throw new Error('Tracked node_modules are not supported by Sight comparison.');
|
|
55
|
+
}
|
|
56
|
+
if (entry.mode === '160000' && relevantToApp(entry.name, appRelativePath)) {
|
|
57
|
+
throw new Error(`Sight comparison cannot build Git submodule "${entry.name}". Use a project with its build inputs in this repository.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function checkFilters(root, names, signal) {
|
|
62
|
+
if (!names.length)
|
|
63
|
+
return;
|
|
64
|
+
const attributes = (await (0, git_1.runComparisonGit)(root, ['check-attr', '--cached', '-z', '--stdin', 'filter'], signal, undefined, `${names.join('\0')}\0`)).split('\0');
|
|
65
|
+
for (let index = 0; index + 2 < attributes.length; index += 3) {
|
|
66
|
+
if (attributes[index + 2] !== 'unspecified' && attributes[index + 2] !== 'unset') {
|
|
67
|
+
throw new Error(`Sight comparison does not support Git LFS or checkout filters: ${attributes[index]}. Sight cannot establish that this path is unrelated before executing build configuration. Use a checkout without Git-filtered inputs.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function includeFiles(repositoryRoot, projectRoot, includes) {
|
|
72
|
+
const files = new Set();
|
|
73
|
+
const visit = (absolute) => {
|
|
74
|
+
const name = path_1.default.relative(repositoryRoot, absolute).split(path_1.default.sep).join('/');
|
|
75
|
+
const dependencyInputs = ['package.json', 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'pnpm-workspace.yaml', 'bun.lock', 'bun.lockb'];
|
|
76
|
+
if (!isWithin(repositoryRoot, absolute) || !name || forbiddenPath(name) || dependencyInputs.includes(path_1.default.basename(name))) {
|
|
77
|
+
throw new Error(`Unsafe --include path: ${name || '.'}. Choose source/configuration files inside the repository.`);
|
|
78
|
+
}
|
|
79
|
+
const stat = fs_1.default.lstatSync(absolute);
|
|
80
|
+
if (stat.isDirectory()) {
|
|
81
|
+
for (const child of fs_1.default.readdirSync(absolute).sort())
|
|
82
|
+
visit(path_1.default.join(absolute, child));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
files.add(name);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
for (const input of includes) {
|
|
89
|
+
if (!input.trim() || path_1.default.isAbsolute(input))
|
|
90
|
+
throw new Error('--include requires a relative file or directory inside the repository.');
|
|
91
|
+
visit(path_1.default.resolve(projectRoot, input));
|
|
92
|
+
}
|
|
93
|
+
return [...files].sort();
|
|
94
|
+
}
|
|
95
|
+
function copyFiles(repositoryRoot, names, destination, signal) {
|
|
96
|
+
const files = [];
|
|
97
|
+
for (const name of names) {
|
|
98
|
+
(0, process_1.checkComparisonAbort)(signal);
|
|
99
|
+
const source = path_1.default.join(repositoryRoot, name);
|
|
100
|
+
if (!isWithin(repositoryRoot, source) || forbiddenPath(name))
|
|
101
|
+
throw new Error(`Unsafe snapshot path: ${name}.`);
|
|
102
|
+
let stat;
|
|
103
|
+
try {
|
|
104
|
+
stat = fs_1.default.lstatSync(source);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (['ENOENT', 'ENOTDIR'].includes(error.code))
|
|
108
|
+
continue;
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
// Cached Git paths can remain after an unstaged file/directory replacement.
|
|
112
|
+
// The untracked listing supplies the replacement files separately.
|
|
113
|
+
if (stat.isDirectory())
|
|
114
|
+
continue;
|
|
115
|
+
if (!isWithin(repositoryRoot, fs_1.default.realpathSync(path_1.default.dirname(source)))) {
|
|
116
|
+
throw new Error(`Snapshot input escapes the repository through a symlink: ${name}.`);
|
|
117
|
+
}
|
|
118
|
+
const target = destination && path_1.default.join(destination, name);
|
|
119
|
+
if (target)
|
|
120
|
+
fs_1.default.mkdirSync(path_1.default.dirname(target), { recursive: true });
|
|
121
|
+
const mode = stat.mode & 0o777;
|
|
122
|
+
if (stat.isSymbolicLink()) {
|
|
123
|
+
const originalLink = fs_1.default.readlinkSync(source);
|
|
124
|
+
const resolved = fs_1.default.realpathSync(path_1.default.resolve(path_1.default.dirname(source), originalLink));
|
|
125
|
+
if (!isWithin(repositoryRoot, resolved)) {
|
|
126
|
+
throw new Error(`External symlink is not supported by Sight comparison: ${name}.`);
|
|
127
|
+
}
|
|
128
|
+
const link = path_1.default.isAbsolute(originalLink) ? path_1.default.relative(path_1.default.dirname(source), resolved) : originalLink;
|
|
129
|
+
if (target)
|
|
130
|
+
fs_1.default.symlinkSync(link, target, fs_1.default.statSync(resolved).isDirectory() ? 'dir' : 'file');
|
|
131
|
+
files.push({ name, mode, link, hash: (0, crypto_1.createHash)('sha256').update(link).digest('hex') });
|
|
132
|
+
}
|
|
133
|
+
else if (stat.isFile()) {
|
|
134
|
+
const content = fs_1.default.readFileSync(source);
|
|
135
|
+
if (content.subarray(0, 80).toString().startsWith('version https://git-lfs.github.com/spec/v1\n')) {
|
|
136
|
+
throw new Error(`Git LFS pointer cannot be bundled: ${name}. Sight cannot establish that this path is unrelated before executing build configuration.`);
|
|
137
|
+
}
|
|
138
|
+
if (target) {
|
|
139
|
+
fs_1.default.writeFileSync(target, content, { mode });
|
|
140
|
+
fs_1.default.chmodSync(target, mode);
|
|
141
|
+
}
|
|
142
|
+
files.push({ name, mode, hash: (0, crypto_1.createHash)('sha256').update(content).digest('hex') });
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
throw new Error(`Snapshot input must be a regular file or internal symlink: ${name}.`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return files;
|
|
149
|
+
}
|
|
150
|
+
function fingerprint(files) {
|
|
151
|
+
return (0, crypto_1.createHash)('sha256').update(JSON.stringify(files)).digest('hex');
|
|
152
|
+
}
|
|
153
|
+
function verifyCopiedLinks(root, files) {
|
|
154
|
+
for (const file of files) {
|
|
155
|
+
if (file.link !== undefined && !fs_1.default.existsSync(path_1.default.join(root, file.name))) {
|
|
156
|
+
throw new Error(`Symlink target was not captured: ${file.name}. Include its ignored target explicitly with --include.`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function createComparisonSnapshots(options) {
|
|
161
|
+
const { compareRef, signal, include = [] } = options;
|
|
162
|
+
const projectRoot = fs_1.default.realpathSync(options.projectRoot);
|
|
163
|
+
const repository = await (0, git_1.inspectComparisonRepository)(projectRoot, compareRef, options);
|
|
164
|
+
const { repositoryRoot, appRelativePath, currentCommit, baselineCommit } = repository;
|
|
165
|
+
const baselineTree = parseTree(await (0, git_1.runComparisonGit)(repositoryRoot, ['ls-tree', '-rz', baselineCommit], signal));
|
|
166
|
+
const currentIndex = parseTree(await (0, git_1.runComparisonGit)(repositoryRoot, ['ls-files', '--stage', '-z'], signal));
|
|
167
|
+
validateTree(currentIndex, appRelativePath);
|
|
168
|
+
validateTree(baselineTree, appRelativePath);
|
|
169
|
+
const submodules = new Set(currentIndex.filter(entry => entry.mode === '160000').map(entry => entry.name));
|
|
170
|
+
const includedPaths = includeFiles(repositoryRoot, projectRoot, include);
|
|
171
|
+
const trackedNames = [...currentIndex, ...baselineTree].map(entry => entry.name);
|
|
172
|
+
for (const name of includedPaths) {
|
|
173
|
+
if (trackedNames.some(tracked => tracked === name || tracked.startsWith(`${name}/`) || name.startsWith(`${tracked}/`))) {
|
|
174
|
+
throw new Error(`--include cannot overwrite a tracked input on either side: ${name}.`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const listCurrent = async () => {
|
|
178
|
+
const output = await (0, git_1.runComparisonGit)(repositoryRoot, ['ls-files', '--cached', '--others', '--exclude-standard', '-z'], signal);
|
|
179
|
+
return [...new Set([...output.split('\0').filter(name => name && !forbiddenPath(name) && !submodules.has(name)), ...includeFiles(repositoryRoot, projectRoot, include)])].sort();
|
|
180
|
+
};
|
|
181
|
+
const directory = fs_1.default.realpathSync(fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'bundle-drop-sight-compare-')));
|
|
182
|
+
const frozenRoot = path_1.default.join(directory, 'frozen');
|
|
183
|
+
const privateGit = path_1.default.join(directory, 'repository.git');
|
|
184
|
+
const currentRoot = path_1.default.join(directory, 'current');
|
|
185
|
+
const baselineRoot = path_1.default.join(directory, 'baseline');
|
|
186
|
+
const worktrees = [];
|
|
187
|
+
const disabledHooks = path_1.default.join(directory, 'disabled-hooks');
|
|
188
|
+
const cleanup = async () => {
|
|
189
|
+
if (!fs_1.default.existsSync(directory))
|
|
190
|
+
return;
|
|
191
|
+
for (const root of worktrees) {
|
|
192
|
+
// Even a project hook that changes private Git config cannot strand original worktrees.
|
|
193
|
+
try {
|
|
194
|
+
await (0, git_1.runComparisonGit)(privateGit, ['worktree', 'remove', '--force', root]);
|
|
195
|
+
}
|
|
196
|
+
catch { /* Remove the owned repository below. */ }
|
|
197
|
+
}
|
|
198
|
+
fs_1.default.rmSync(directory, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
199
|
+
};
|
|
200
|
+
try {
|
|
201
|
+
fs_1.default.mkdirSync(frozenRoot);
|
|
202
|
+
fs_1.default.mkdirSync(disabledHooks);
|
|
203
|
+
const names = await listCurrent();
|
|
204
|
+
const files = copyFiles(repositoryRoot, names, frozenRoot, signal);
|
|
205
|
+
const snapshotHash = fingerprint(files);
|
|
206
|
+
if (snapshotHash !== fingerprint(copyFiles(repositoryRoot, await listCurrent(), undefined, signal)) ||
|
|
207
|
+
repository.indexFingerprint !== await (0, git_1.comparisonIndexFingerprint)(repositoryRoot, signal) ||
|
|
208
|
+
currentCommit !== (await (0, git_1.runComparisonGit)(repositoryRoot, ['rev-parse', 'HEAD'], signal)).trim()) {
|
|
209
|
+
throw new Error('Working tree changed while Sight captured it; retry when edits settle.');
|
|
210
|
+
}
|
|
211
|
+
verifyCopiedLinks(frozenRoot, files);
|
|
212
|
+
await (0, git_1.runComparisonGit)(repositoryRoot, ['clone', '--mirror', '--no-hardlinks', '--dissociate', '--origin', 'sight-source', '--', repositoryRoot, privateGit], signal);
|
|
213
|
+
// Keep mirrored refs for versioning tools without leaving a build a remote back to the original checkout.
|
|
214
|
+
await (0, git_1.runComparisonGit)(privateGit, ['config', '--local', '--remove-section', 'remote.sight-source'], signal);
|
|
215
|
+
const checkoutSettings = await (0, git_1.runComparisonGit)(repositoryRoot, ['config', '--get-regexp', '^core[.](autocrlf|eol|filemode|symlinks)$'], signal, [0, 1]);
|
|
216
|
+
for (const setting of checkoutSettings.trim().split('\n').filter(Boolean)) {
|
|
217
|
+
const separator = setting.indexOf(' ');
|
|
218
|
+
await (0, git_1.runComparisonGit)(privateGit, ['config', '--local', setting.slice(0, separator), setting.slice(separator + 1)], signal);
|
|
219
|
+
}
|
|
220
|
+
if (await (0, git_1.comparisonRefs)(privateGit, signal) !== repository.refs)
|
|
221
|
+
throw new Error('Git refs changed while Sight captured the repository; retry.');
|
|
222
|
+
await (0, git_1.runComparisonGit)(privateGit, ['cat-file', '-e', `${currentCommit}^{commit}`], signal);
|
|
223
|
+
await (0, git_1.runComparisonGit)(privateGit, ['cat-file', '-e', `${baselineCommit}^{commit}`], signal);
|
|
224
|
+
for (const [root, commit] of [[baselineRoot, baselineCommit], [currentRoot, currentCommit]]) {
|
|
225
|
+
await (0, git_1.runComparisonGit)(privateGit, ['-c', `core.hooksPath=${disabledHooks}`, 'worktree', 'add', '--detach', '--no-checkout', root, commit], signal);
|
|
226
|
+
worktrees.push(root);
|
|
227
|
+
await (0, git_1.runComparisonGit)(root, ['read-tree', commit], signal);
|
|
228
|
+
const tree = parseTree(await (0, git_1.runComparisonGit)(root, ['ls-files', '--stage', '-z'], signal));
|
|
229
|
+
await checkFilters(root, tree.map(entry => entry.name), signal);
|
|
230
|
+
}
|
|
231
|
+
await (0, git_1.runComparisonGit)(baselineRoot, ['checkout-index', '--all', '--force'], signal);
|
|
232
|
+
copyFiles(frozenRoot, includedPaths, baselineRoot, signal);
|
|
233
|
+
for (const entry of baselineTree.filter(item => item.mode === '120000')) {
|
|
234
|
+
const linkPath = path_1.default.join(baselineRoot, entry.name);
|
|
235
|
+
if (!fs_1.default.lstatSync(linkPath).isSymbolicLink())
|
|
236
|
+
continue;
|
|
237
|
+
const link = fs_1.default.readlinkSync(linkPath);
|
|
238
|
+
const target = path_1.default.isAbsolute(link) ? baselineLinkTarget(repositoryRoot, baselineRoot, link) : undefined;
|
|
239
|
+
if (target !== undefined) {
|
|
240
|
+
fs_1.default.unlinkSync(linkPath);
|
|
241
|
+
// Normalize every link before validating their resolved baseline targets,
|
|
242
|
+
// so chains never follow another absolute link into the current checkout.
|
|
243
|
+
fs_1.default.symlinkSync(path_1.default.relative(path_1.default.dirname(linkPath), target), linkPath);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
copyFiles(frozenRoot, files.map(file => file.name), currentRoot, signal);
|
|
247
|
+
const baselineFiles = baselineTree.filter(entry => entry.mode !== '160000' && !forbiddenPath(entry.name)).map(entry => entry.name);
|
|
248
|
+
copyFiles(baselineRoot, baselineFiles, undefined, signal);
|
|
249
|
+
verifyCopiedLinks(baselineRoot, copyFiles(baselineRoot, [...baselineFiles, ...includedPaths], undefined, signal));
|
|
250
|
+
const currentProjectRoot = path_1.default.join(currentRoot, appRelativePath);
|
|
251
|
+
const baselineProjectRoot = path_1.default.join(baselineRoot, appRelativePath);
|
|
252
|
+
if (!fs_1.default.existsSync(path_1.default.join(baselineProjectRoot, 'package.json')))
|
|
253
|
+
throw new Error('The app package.json is missing at the baseline repository-relative path.');
|
|
254
|
+
const assertIdentity = async () => {
|
|
255
|
+
if ((await (0, git_1.runComparisonGit)(currentRoot, ['rev-parse', 'HEAD'], signal)).trim() !== currentCommit ||
|
|
256
|
+
(await (0, git_1.runComparisonGit)(baselineRoot, ['rev-parse', 'HEAD'], signal)).trim() !== baselineCommit ||
|
|
257
|
+
await (0, git_1.comparisonRefs)(privateGit, signal) !== repository.refs) {
|
|
258
|
+
throw new Error('A comparison build changed its Git HEAD or refs; refusing artifacts with altered revision identity.');
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
await assertIdentity();
|
|
262
|
+
return {
|
|
263
|
+
directory, currentRoot, baselineRoot, currentProjectRoot, baselineProjectRoot,
|
|
264
|
+
currentCommit, baselineCommit, currentLabel: repository.currentLabel, baselineLabel: repository.baselineLabel,
|
|
265
|
+
currentBranch: repository.currentBranch, currentDirty: repository.currentDirty,
|
|
266
|
+
baselineInputFingerprint: repository.baselineInputFingerprint, snapshotHash, includedPaths,
|
|
267
|
+
assertIdentity, cleanup,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
try {
|
|
272
|
+
await cleanup();
|
|
273
|
+
}
|
|
274
|
+
catch (cleanupError) {
|
|
275
|
+
throw new Error(`${error.message}\nCould not remove ${directory}: ${cleanupError.message}`);
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
@@ -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
|
+
}
|