@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,289 @@
|
|
|
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.inspectDependencyPlan = inspectDependencyPlan;
|
|
7
|
+
exports.installDependencies = installDependencies;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const process_1 = require("./process");
|
|
12
|
+
const lockfiles = {
|
|
13
|
+
npm: ['npm-shrinkwrap.json', 'package-lock.json'],
|
|
14
|
+
yarn: ['yarn.lock'],
|
|
15
|
+
pnpm: ['pnpm-lock.yaml'],
|
|
16
|
+
bun: ['bun.lock', 'bun.lockb'],
|
|
17
|
+
};
|
|
18
|
+
const configFiles = ['.npmrc', '.yarnrc', '.yarnrc.yml', 'pnpm-workspace.yaml', '.pnpmfile.cjs'];
|
|
19
|
+
function packageManagerEnvironment(env = process.env) {
|
|
20
|
+
return { ...env, COREPACK_ENABLE_AUTO_PIN: '0', COREPACK_ENABLE_NETWORK: '0' };
|
|
21
|
+
}
|
|
22
|
+
function inside(root, target) {
|
|
23
|
+
const relative = path_1.default.relative(root, target);
|
|
24
|
+
return relative === '' || (!relative.startsWith(`..${path_1.default.sep}`) && relative !== '..' && !path_1.default.isAbsolute(relative));
|
|
25
|
+
}
|
|
26
|
+
function confinedPath(root, target) {
|
|
27
|
+
const absolute = path_1.default.resolve(target);
|
|
28
|
+
if (!inside(root, absolute) || (fs_1.default.existsSync(absolute) && !inside(root, fs_1.default.realpathSync(absolute)))) {
|
|
29
|
+
throw new Error(`Comparison dependencies must stay inside the repository snapshot: ${target}`);
|
|
30
|
+
}
|
|
31
|
+
return absolute;
|
|
32
|
+
}
|
|
33
|
+
function readManifest(directory) {
|
|
34
|
+
return JSON.parse(fs_1.default.readFileSync(path_1.default.join(directory, 'package.json'), 'utf8'));
|
|
35
|
+
}
|
|
36
|
+
function findInstallRoot(snapshotRoot, projectRoot) {
|
|
37
|
+
let directory = projectRoot;
|
|
38
|
+
const workspaceRoots = [];
|
|
39
|
+
while (true) {
|
|
40
|
+
const manifestPath = path_1.default.join(directory, 'package.json');
|
|
41
|
+
if ((fs_1.default.existsSync(manifestPath) && readManifest(directory).workspaces !== undefined) ||
|
|
42
|
+
fs_1.default.existsSync(path_1.default.join(directory, 'pnpm-workspace.yaml'))) {
|
|
43
|
+
workspaceRoots.push(directory);
|
|
44
|
+
}
|
|
45
|
+
if (directory === snapshotRoot)
|
|
46
|
+
break;
|
|
47
|
+
directory = path_1.default.dirname(directory);
|
|
48
|
+
}
|
|
49
|
+
if (workspaceRoots.length > 1) {
|
|
50
|
+
throw new Error('Nested workspace roots are not supported by Sight comparison.');
|
|
51
|
+
}
|
|
52
|
+
return workspaceRoots[0] || projectRoot;
|
|
53
|
+
}
|
|
54
|
+
function existingLocks(directory) {
|
|
55
|
+
return Object.values(lockfiles).flat().filter(file => fs_1.default.existsSync(path_1.default.join(directory, file)));
|
|
56
|
+
}
|
|
57
|
+
function validateLocalReferences(value, directory, snapshotRoot, localPackages, inputFiles) {
|
|
58
|
+
if (typeof value === 'string') {
|
|
59
|
+
if (/^git\+file:/i.test(value)) {
|
|
60
|
+
throw new Error('Local Git dependencies are not supported by Sight comparison.');
|
|
61
|
+
}
|
|
62
|
+
const local = value.match(/^(?:file:|link:|portal:)(.*)$/)?.[1] ?? value.match(/^workspace:(\.{1,2}[\\/].*)$/)?.[1];
|
|
63
|
+
if (local !== undefined) {
|
|
64
|
+
// Percent escapes are accepted by package managers in file URLs.
|
|
65
|
+
const decoded = decodeURIComponent(local);
|
|
66
|
+
if (decoded.startsWith('~'))
|
|
67
|
+
throw new Error('Home-directory dependencies are outside the repository snapshot.');
|
|
68
|
+
recordLocalDependency(snapshotRoot, path_1.default.resolve(directory, decoded), localPackages, inputFiles);
|
|
69
|
+
}
|
|
70
|
+
else if (path_1.default.isAbsolute(value) || value.startsWith('./') || value.startsWith('../')) {
|
|
71
|
+
recordLocalDependency(snapshotRoot, path_1.default.resolve(directory, value), localPackages, inputFiles);
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (value && typeof value === 'object') {
|
|
76
|
+
for (const child of Object.values(value))
|
|
77
|
+
validateLocalReferences(child, directory, snapshotRoot, localPackages, inputFiles);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function recordLocalDependency(snapshotRoot, target, localPackages, inputFiles) {
|
|
81
|
+
const localPath = confinedPath(snapshotRoot, target);
|
|
82
|
+
if (fs_1.default.existsSync(localPath) && fs_1.default.statSync(localPath).isFile()) {
|
|
83
|
+
inputFiles.push(localPath);
|
|
84
|
+
}
|
|
85
|
+
else if (fs_1.default.existsSync(path_1.default.join(localPath, 'package.json'))) {
|
|
86
|
+
localPackages.add(fs_1.default.realpathSync(localPath));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function inspectNpmLock(lockPath, snapshotRoot, localPackages, inputFiles) {
|
|
90
|
+
const installRoot = path_1.default.dirname(lockPath);
|
|
91
|
+
const lock = JSON.parse(fs_1.default.readFileSync(lockPath, 'utf8'));
|
|
92
|
+
for (const [location, entry] of Object.entries(lock.packages || {})) {
|
|
93
|
+
recordLocalDependency(snapshotRoot, path_1.default.resolve(installRoot, location), localPackages, inputFiles);
|
|
94
|
+
if (entry.link && typeof entry.resolved === 'string') {
|
|
95
|
+
recordLocalDependency(snapshotRoot, path_1.default.resolve(installRoot, entry.resolved), localPackages, inputFiles);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
validateLocalReferences(entry.resolved, installRoot, snapshotRoot, localPackages, inputFiles);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const inspectDependencies = (dependencies) => {
|
|
102
|
+
if (!dependencies || typeof dependencies !== 'object')
|
|
103
|
+
return;
|
|
104
|
+
for (const dependency of Object.values(dependencies)) {
|
|
105
|
+
validateLocalReferences(dependency.resolved, installRoot, snapshotRoot, localPackages, inputFiles);
|
|
106
|
+
validateLocalReferences(dependency.version, installRoot, snapshotRoot, localPackages, inputFiles);
|
|
107
|
+
inspectDependencies(dependency.dependencies);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
inspectDependencies(lock.dependencies);
|
|
111
|
+
}
|
|
112
|
+
function parseClassicJson(output) {
|
|
113
|
+
let records;
|
|
114
|
+
try {
|
|
115
|
+
records = [JSON.parse(output)];
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
records = output.trim().split('\n').map(line => JSON.parse(line));
|
|
119
|
+
}
|
|
120
|
+
const record = records.find(item => item.type === 'inspect' || item.type === 'log');
|
|
121
|
+
const data = record ? record.data : records[0];
|
|
122
|
+
return typeof data === 'string' && data.startsWith('{') ? JSON.parse(data) : data;
|
|
123
|
+
}
|
|
124
|
+
async function validateNodeEngine(range, options) {
|
|
125
|
+
const probeRoot = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'bundle-drop-sight-engine-'));
|
|
126
|
+
try {
|
|
127
|
+
fs_1.default.writeFileSync(path_1.default.join(probeRoot, 'package.json'), JSON.stringify({
|
|
128
|
+
name: 'bundle-drop-sight-engine-check', version: '1.0.0', private: true, engines: { node: range },
|
|
129
|
+
}));
|
|
130
|
+
// npm supplies the complete semver implementation. This synthetic project has
|
|
131
|
+
// no dependencies or scripts, and offline dry-run cannot download packages.
|
|
132
|
+
await (0, process_1.runComparisonProcess)({
|
|
133
|
+
command: 'npm',
|
|
134
|
+
args: ['install', '--prefix', probeRoot, '--dry-run', '--ignore-scripts', '--engine-strict', '--force=false', '--package-lock=false', '--offline', '--no-audit', '--no-fund'],
|
|
135
|
+
cwd: probeRoot, phase: `Validate Node ${process.versions.node} against engines.node ${range} (requires npm)`,
|
|
136
|
+
signal: options.signal, env: packageManagerEnvironment(options.env), logPath: options.logPath,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
fs_1.default.rmSync(probeRoot, { recursive: true, force: true });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function inspectDependencyPlan(options) {
|
|
144
|
+
const snapshotRoot = fs_1.default.realpathSync(options.snapshotRoot);
|
|
145
|
+
const projectRoot = confinedPath(snapshotRoot, path_1.default.resolve(snapshotRoot, options.projectRelativePath));
|
|
146
|
+
const installRoot = findInstallRoot(snapshotRoot, projectRoot);
|
|
147
|
+
const manifest = readManifest(installRoot);
|
|
148
|
+
const locks = existingLocks(installRoot);
|
|
149
|
+
const families = Object.entries(lockfiles).filter(([, files]) => files.some(file => locks.includes(file)));
|
|
150
|
+
if (families.length !== 1)
|
|
151
|
+
throw new Error('Sight comparison requires exactly one package-manager lockfile family.');
|
|
152
|
+
const name = families[0][0];
|
|
153
|
+
if (name === 'bun')
|
|
154
|
+
throw new Error('Bun is not supported by Sight comparison yet.');
|
|
155
|
+
if (installRoot !== projectRoot && existingLocks(projectRoot).length) {
|
|
156
|
+
throw new Error('A workspace app has its own lockfile. Remove the ambiguous nested lockfile before comparing.');
|
|
157
|
+
}
|
|
158
|
+
const declaration = manifest.packageManager;
|
|
159
|
+
const declared = declaration?.match(/^(npm|yarn|pnpm)@(\d+\.\d+\.\d+(?:-[\w.-]+)?)(?:\+[^\s]+)?$/);
|
|
160
|
+
if (declaration && (!declared || declared[1] !== name)) {
|
|
161
|
+
throw new Error('packageManager must name an exact supported version matching the lockfile.');
|
|
162
|
+
}
|
|
163
|
+
const appDeclaration = readManifest(projectRoot).packageManager;
|
|
164
|
+
if (appDeclaration && appDeclaration !== declaration) {
|
|
165
|
+
throw new Error('The app and workspace root declare different package-manager versions.');
|
|
166
|
+
}
|
|
167
|
+
const run = async (args) => (await (0, process_1.runComparisonProcess)({
|
|
168
|
+
command: name, args, cwd: installRoot, phase: 'Inspect comparison dependencies',
|
|
169
|
+
signal: options.signal, env: packageManagerEnvironment(options.env), logPath: options.logPath,
|
|
170
|
+
})).stdout.trim();
|
|
171
|
+
const version = await run(['--version']);
|
|
172
|
+
if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(version) || (declared && declared[2] !== version)) {
|
|
173
|
+
throw new Error(`The available ${name} version (${version}) does not match ${declaration || 'a supported version'}. Install the required package manager and retry.`);
|
|
174
|
+
}
|
|
175
|
+
const packageManager = { name, version };
|
|
176
|
+
const modernYarn = name === 'yarn' && Number(version.split('.')[0]) >= 2;
|
|
177
|
+
const inputFiles = locks.map(file => path_1.default.join(installRoot, file));
|
|
178
|
+
for (const file of configFiles) {
|
|
179
|
+
const target = path_1.default.join(installRoot, file);
|
|
180
|
+
if (fs_1.default.existsSync(target))
|
|
181
|
+
inputFiles.push(confinedPath(snapshotRoot, target));
|
|
182
|
+
}
|
|
183
|
+
if (name === 'yarn') {
|
|
184
|
+
if (manifest.installConfig?.pnp || fs_1.default.existsSync(path_1.default.join(installRoot, '.pnp.cjs')) || fs_1.default.existsSync(path_1.default.join(installRoot, '.pnp.js'))) {
|
|
185
|
+
throw new Error('Yarn Plug’n’Play is not supported by Sight comparison. Use a node_modules installation.');
|
|
186
|
+
}
|
|
187
|
+
if (modernYarn) {
|
|
188
|
+
const linker = JSON.parse(await run(['config', 'get', 'nodeLinker', '--json']));
|
|
189
|
+
if (linker !== 'node-modules')
|
|
190
|
+
throw new Error('Sight comparison requires Yarn nodeLinker: node-modules.');
|
|
191
|
+
const yarnPath = JSON.parse(await run(['config', 'get', 'yarnPath', '--json']));
|
|
192
|
+
if (yarnPath)
|
|
193
|
+
inputFiles.push(confinedPath(snapshotRoot, path_1.default.resolve(installRoot, yarnPath)));
|
|
194
|
+
const statePath = JSON.parse(await run(['config', 'get', 'installStatePath', '--json']));
|
|
195
|
+
confinedPath(snapshotRoot, path_1.default.resolve(installRoot, statePath));
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const yarnPath = parseClassicJson(await run(['config', 'get', 'yarn-path', '--json']));
|
|
199
|
+
if (typeof yarnPath === 'string' && yarnPath !== 'undefined') {
|
|
200
|
+
inputFiles.push(confinedPath(snapshotRoot, path_1.default.resolve(installRoot, yarnPath)));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (name === 'pnpm') {
|
|
205
|
+
for (const setting of ['node-linker', 'virtual-store-dir', 'modules-dir', 'lockfile-dir']) {
|
|
206
|
+
const value = await run(['config', 'get', setting]);
|
|
207
|
+
if (setting === 'node-linker') {
|
|
208
|
+
if (value === 'pnp')
|
|
209
|
+
throw new Error('pnpm Plug’n’Play is not supported by Sight comparison.');
|
|
210
|
+
}
|
|
211
|
+
else if (value && value !== 'undefined') {
|
|
212
|
+
confinedPath(snapshotRoot, path_1.default.resolve(installRoot, value));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
let workspaceDirectories = [installRoot];
|
|
217
|
+
const isWorkspace = manifest.workspaces !== undefined || fs_1.default.existsSync(path_1.default.join(installRoot, 'pnpm-workspace.yaml'));
|
|
218
|
+
if (isWorkspace) {
|
|
219
|
+
if (name === 'pnpm') {
|
|
220
|
+
const workspaces = JSON.parse(await run(['list', '--recursive', '--depth', '-1', '--json']));
|
|
221
|
+
workspaceDirectories.push(...workspaces.map(workspace => workspace.path));
|
|
222
|
+
}
|
|
223
|
+
else if (modernYarn) {
|
|
224
|
+
const workspaces = (await run(['workspaces', 'list', '--json'])).split('\n').map(line => JSON.parse(line));
|
|
225
|
+
workspaceDirectories.push(...workspaces.map(workspace => path_1.default.resolve(installRoot, workspace.location)));
|
|
226
|
+
}
|
|
227
|
+
else if (name === 'yarn') {
|
|
228
|
+
const workspaces = parseClassicJson(await run(['--silent', 'workspaces', 'info', '--json']));
|
|
229
|
+
workspaceDirectories.push(...Object.values(workspaces).map(workspace => path_1.default.resolve(installRoot, workspace.location)));
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
const workspaces = JSON.parse(await run(['pkg', 'get', 'name', '--workspaces', '--json']));
|
|
233
|
+
const lock = JSON.parse(fs_1.default.readFileSync(inputFiles[0], 'utf8'));
|
|
234
|
+
if (!lock.packages)
|
|
235
|
+
throw new Error('npm workspace comparison requires a package-lock v2 or newer.');
|
|
236
|
+
const locations = Object.keys(lock.packages).filter(location => location && !location.split('/').includes('node_modules'));
|
|
237
|
+
workspaceDirectories.push(...locations.map(location => path_1.default.resolve(installRoot, location)));
|
|
238
|
+
const lockedNames = workspaceDirectories.slice(1).map(directory => readManifest(confinedPath(snapshotRoot, directory)).name);
|
|
239
|
+
if (Object.keys(workspaces).some(workspace => !lockedNames.includes(workspace))) {
|
|
240
|
+
throw new Error('Workspace declarations and the npm lockfile disagree. Update the lockfile before comparing.');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
workspaceDirectories = [...new Set(workspaceDirectories.map(directory => confinedPath(snapshotRoot, directory)))];
|
|
245
|
+
if (!workspaceDirectories.includes(projectRoot))
|
|
246
|
+
throw new Error('The app is not a member of the detected package-manager workspace.');
|
|
247
|
+
const localPackages = new Set(workspaceDirectories.map(directory => fs_1.default.realpathSync(directory)));
|
|
248
|
+
if (name === 'npm')
|
|
249
|
+
inspectNpmLock(inputFiles[0], snapshotRoot, localPackages, inputFiles);
|
|
250
|
+
const nodeRanges = new Set();
|
|
251
|
+
// Set iteration also visits local packages discovered in preceding manifests.
|
|
252
|
+
for (const directory of localPackages) {
|
|
253
|
+
const packageFile = confinedPath(snapshotRoot, path_1.default.join(directory, 'package.json'));
|
|
254
|
+
const workspace = readManifest(directory);
|
|
255
|
+
const nodeRange = workspace.engines?.node;
|
|
256
|
+
if (nodeRange !== undefined) {
|
|
257
|
+
if (typeof nodeRange !== 'string')
|
|
258
|
+
throw new Error('engines.node must be a version-range string.');
|
|
259
|
+
nodeRanges.add(nodeRange);
|
|
260
|
+
}
|
|
261
|
+
for (const dependencies of [workspace.dependencies, workspace.devDependencies, workspace.optionalDependencies, workspace.peerDependencies, workspace.resolutions, workspace.overrides, workspace.pnpm]) {
|
|
262
|
+
validateLocalReferences(dependencies, directory, snapshotRoot, localPackages, inputFiles);
|
|
263
|
+
}
|
|
264
|
+
inputFiles.push(packageFile);
|
|
265
|
+
}
|
|
266
|
+
for (const range of nodeRanges)
|
|
267
|
+
await validateNodeEngine(range, options);
|
|
268
|
+
const installArgs = name === 'npm'
|
|
269
|
+
? ['ci', '--include=dev', '--no-audit', '--no-fund']
|
|
270
|
+
: name === 'pnpm'
|
|
271
|
+
? ['install', '--frozen-lockfile', '--prod=false']
|
|
272
|
+
: modernYarn
|
|
273
|
+
? ['install', '--immutable']
|
|
274
|
+
: ['install', '--frozen-lockfile', '--production=false', '--non-interactive'];
|
|
275
|
+
return { snapshotRoot, projectRoot, installRoot, packageManager, installArgs, inputFiles: [...new Set(inputFiles)] };
|
|
276
|
+
}
|
|
277
|
+
async function installDependencies(plan, options = {}) {
|
|
278
|
+
const before = new Map(plan.inputFiles.map(file => [file, fs_1.default.readFileSync(file)]));
|
|
279
|
+
await (0, process_1.runComparisonProcess)({
|
|
280
|
+
command: plan.packageManager.name, args: plan.installArgs, cwd: plan.installRoot,
|
|
281
|
+
phase: 'Install comparison dependencies', signal: options.signal, logPath: options.logPath,
|
|
282
|
+
env: { ...packageManagerEnvironment(options.env), NODE_ENV: 'development' },
|
|
283
|
+
});
|
|
284
|
+
for (const [file, contents] of before) {
|
|
285
|
+
if (!fs_1.default.existsSync(file) || !fs_1.default.readFileSync(file).equals(contents)) {
|
|
286
|
+
throw new Error(`Dependency installation modified a comparison input: ${path_1.default.relative(plan.snapshotRoot, file)}. A frozen install is required.`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type ComparisonRepository = {
|
|
2
|
+
repositoryRoot: string;
|
|
3
|
+
appRelativePath: string;
|
|
4
|
+
currentCommit: string;
|
|
5
|
+
currentBranch: string | null;
|
|
6
|
+
currentDirty: boolean;
|
|
7
|
+
currentLabel: string;
|
|
8
|
+
baselineCommit: string;
|
|
9
|
+
baselineLabel: string;
|
|
10
|
+
baselineInputFingerprint: string;
|
|
11
|
+
refs: string;
|
|
12
|
+
indexFingerprint: string;
|
|
13
|
+
};
|
|
14
|
+
/** Never inherit a caller's index/worktree overrides into an isolated Git invocation. */
|
|
15
|
+
export declare function comparisonGitEnvironment(): NodeJS.ProcessEnv;
|
|
16
|
+
export declare function runComparisonGit(cwd: string, args: string[], signal?: AbortSignal, allowedExitCodes?: number[], input?: string): Promise<string>;
|
|
17
|
+
export declare function comparisonRefs(cwd: string, signal?: AbortSignal): Promise<string>;
|
|
18
|
+
export declare function comparisonIndexFingerprint(cwd: string, signal?: AbortSignal): Promise<string>;
|
|
19
|
+
export declare function inspectComparisonRepository(projectRoot: string, compareRef: string, options?: {
|
|
20
|
+
fetch?: boolean;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}): Promise<ComparisonRepository>;
|
|
@@ -0,0 +1,116 @@
|
|
|
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.comparisonGitEnvironment = comparisonGitEnvironment;
|
|
7
|
+
exports.runComparisonGit = runComparisonGit;
|
|
8
|
+
exports.comparisonRefs = comparisonRefs;
|
|
9
|
+
exports.comparisonIndexFingerprint = comparisonIndexFingerprint;
|
|
10
|
+
exports.inspectComparisonRepository = inspectComparisonRepository;
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
const process_1 = require("./process");
|
|
15
|
+
/** Never inherit a caller's index/worktree overrides into an isolated Git invocation. */
|
|
16
|
+
function comparisonGitEnvironment() {
|
|
17
|
+
const env = { ...process.env, GIT_OPTIONAL_LOCKS: '0', GIT_NO_LAZY_FETCH: '1', GIT_TERMINAL_PROMPT: '1' };
|
|
18
|
+
for (const name of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_INDEX_FILE', 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES']) {
|
|
19
|
+
delete env[name];
|
|
20
|
+
}
|
|
21
|
+
return env;
|
|
22
|
+
}
|
|
23
|
+
async function runComparisonGit(cwd, args, signal, allowedExitCodes, input) {
|
|
24
|
+
const result = await (0, process_1.runComparisonProcess)({
|
|
25
|
+
command: 'git',
|
|
26
|
+
args: ['--literal-pathspecs', '-c', 'maintenance.auto=false', ...args],
|
|
27
|
+
cwd,
|
|
28
|
+
phase: 'Sight Git preparation',
|
|
29
|
+
env: comparisonGitEnvironment(),
|
|
30
|
+
signal,
|
|
31
|
+
allowedExitCodes,
|
|
32
|
+
input,
|
|
33
|
+
inheritStdin: args.includes('fetch'),
|
|
34
|
+
});
|
|
35
|
+
return result.stdout;
|
|
36
|
+
}
|
|
37
|
+
function comparisonRefs(cwd, signal) {
|
|
38
|
+
return runComparisonGit(cwd, ['for-each-ref', '--sort=refname', '--format=%(refname) %(objectname)'], signal);
|
|
39
|
+
}
|
|
40
|
+
async function comparisonIndexFingerprint(cwd, signal) {
|
|
41
|
+
const indexPath = (await runComparisonGit(cwd, ['rev-parse', '--git-path', 'index'], signal)).trim();
|
|
42
|
+
const absolutePath = path_1.default.resolve(cwd, indexPath);
|
|
43
|
+
return (0, crypto_1.createHash)('sha256').update(fs_1.default.existsSync(absolutePath) ? fs_1.default.readFileSync(absolutePath) : '').digest('hex');
|
|
44
|
+
}
|
|
45
|
+
async function refreshBaseline(repositoryRoot, ref, signal) {
|
|
46
|
+
const remoteNames = (await runComparisonGit(repositoryRoot, ['remote'], signal)).trim().split('\n').filter(Boolean);
|
|
47
|
+
const shortRef = ref.startsWith('refs/remotes/') ? ref.slice('refs/remotes/'.length) : ref;
|
|
48
|
+
const matches = remoteNames.filter(remote => shortRef.startsWith(`${remote}/`));
|
|
49
|
+
if (matches.length !== 1) {
|
|
50
|
+
throw new Error('--fetch requires one explicit configured remote branch, such as --compare origin/main --fetch.');
|
|
51
|
+
}
|
|
52
|
+
const remote = matches[0];
|
|
53
|
+
const branch = shortRef.slice(remote.length + 1);
|
|
54
|
+
// Validate the literal branch before building a refspec; revision expressions are not refresh targets.
|
|
55
|
+
await runComparisonGit(repositoryRoot, ['check-ref-format', `refs/heads/${branch}`], signal);
|
|
56
|
+
const trackingRef = `refs/remotes/${remote}/${branch}`;
|
|
57
|
+
await runComparisonGit(repositoryRoot, [
|
|
58
|
+
'fetch', '--no-tags', '--no-recurse-submodules', '--no-prune', '--no-auto-maintenance',
|
|
59
|
+
'--no-write-commit-graph', '--refmap=', '--', remote,
|
|
60
|
+
`+refs/heads/${branch}:${trackingRef}`,
|
|
61
|
+
], signal);
|
|
62
|
+
return trackingRef;
|
|
63
|
+
}
|
|
64
|
+
async function inspectComparisonRepository(projectRoot, compareRef, options = {}) {
|
|
65
|
+
const { signal } = options;
|
|
66
|
+
if (!compareRef.trim() || compareRef.includes('\0'))
|
|
67
|
+
throw new Error('--compare requires a nonempty Git ref.');
|
|
68
|
+
const repositoryRoot = (await runComparisonGit(projectRoot, ['rev-parse', '--show-toplevel'], signal)).trim();
|
|
69
|
+
const appRelativePath = path_1.default.relative(repositoryRoot, fs_1.default.realpathSync(projectRoot));
|
|
70
|
+
if (appRelativePath === '..' || appRelativePath.startsWith(`..${path_1.default.sep}`) || path_1.default.isAbsolute(appRelativePath)) {
|
|
71
|
+
throw new Error('The comparison app must be inside its Git repository.');
|
|
72
|
+
}
|
|
73
|
+
const sparse = (await runComparisonGit(repositoryRoot, ['config', '--get', 'core.sparseCheckout'], signal, [0, 1])).trim();
|
|
74
|
+
const partial = await runComparisonGit(repositoryRoot, ['config', '--get-regexp', '^(extensions[.]partialclone|remote[.].*[.]promisor)$'], signal, [0, 1]);
|
|
75
|
+
if (sparse === 'true' || /(?:^|\n)(?:extensions\.partialclone\s+\S+|remote\..*\.promisor\s+true)(?:\n|$)/i.test(partial)) {
|
|
76
|
+
throw new Error('Sight comparison requires a complete, non-sparse local checkout; sparse and partial clones are not supported.');
|
|
77
|
+
}
|
|
78
|
+
if ((await runComparisonGit(repositoryRoot, ['ls-files', '--unmerged', '-z'], signal)).length) {
|
|
79
|
+
throw new Error('Resolve Git merge conflicts before comparing with Sight.');
|
|
80
|
+
}
|
|
81
|
+
let currentCommit;
|
|
82
|
+
try {
|
|
83
|
+
currentCommit = (await runComparisonGit(repositoryRoot, ['rev-parse', '--verify', 'HEAD^{commit}'], signal)).trim();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error.name === 'AbortError')
|
|
87
|
+
throw error;
|
|
88
|
+
throw new Error('Sight comparison requires an existing HEAD commit; commit the initial revision first.');
|
|
89
|
+
}
|
|
90
|
+
const baselineRef = options.fetch ? await refreshBaseline(repositoryRoot, compareRef, signal) : compareRef;
|
|
91
|
+
let baselineCommit;
|
|
92
|
+
try {
|
|
93
|
+
baselineCommit = (await runComparisonGit(repositoryRoot, ['rev-parse', '--verify', '--end-of-options', `${baselineRef}^{commit}`], signal)).trim();
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error.name === 'AbortError')
|
|
97
|
+
throw error;
|
|
98
|
+
throw new Error(`Baseline "${compareRef}" is not available locally. Fetch the required ref/history with Git, or use --compare origin/main --fetch.`);
|
|
99
|
+
}
|
|
100
|
+
const currentBranch = (await runComparisonGit(repositoryRoot, ['symbolic-ref', '--quiet', '--short', 'HEAD'], signal, [0, 1])).trim() || null;
|
|
101
|
+
const currentDirty = (await runComparisonGit(repositoryRoot, ['status', '--porcelain=v1', '--untracked-files=all', '-z'], signal)).length > 0;
|
|
102
|
+
const baselineInputFingerprint = (await runComparisonGit(repositoryRoot, ['rev-parse', `${baselineCommit}^{tree}`], signal)).trim();
|
|
103
|
+
return {
|
|
104
|
+
repositoryRoot,
|
|
105
|
+
appRelativePath,
|
|
106
|
+
currentCommit,
|
|
107
|
+
currentBranch,
|
|
108
|
+
currentDirty,
|
|
109
|
+
currentLabel: currentBranch || `HEAD ${currentCommit.slice(0, 8)}`,
|
|
110
|
+
baselineCommit,
|
|
111
|
+
baselineLabel: compareRef,
|
|
112
|
+
baselineInputFingerprint,
|
|
113
|
+
refs: await comparisonRefs(repositoryRoot, signal),
|
|
114
|
+
indexFingerprint: await comparisonIndexFingerprint(repositoryRoot, signal),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MobilePlatform, ProjectType } from '../../../expo';
|
|
2
|
+
import type { DependencyProcessOptions } from './dependencies';
|
|
3
|
+
export type LogicalSightEntry = {
|
|
4
|
+
kind: 'relative' | 'module';
|
|
5
|
+
value: string;
|
|
6
|
+
};
|
|
7
|
+
type InstalledSightProject = {
|
|
8
|
+
projectType: ProjectType;
|
|
9
|
+
entry: LogicalSightEntry;
|
|
10
|
+
resolvedEntryFile: string;
|
|
11
|
+
versions: {
|
|
12
|
+
reactNative: string;
|
|
13
|
+
expo?: string;
|
|
14
|
+
metro?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
type SourceMapContext = {
|
|
18
|
+
sourceMapBase: string;
|
|
19
|
+
sourcePathConvention: 'filesystem' | 'expo-server-root';
|
|
20
|
+
};
|
|
21
|
+
export type InspectedSightProject = InstalledSightProject & SourceMapContext;
|
|
22
|
+
export type InspectSightProjectOptions = {
|
|
23
|
+
snapshotRoot: string;
|
|
24
|
+
projectRoot: string;
|
|
25
|
+
platform: MobilePlatform;
|
|
26
|
+
explicitType?: ProjectType;
|
|
27
|
+
entryFile?: string;
|
|
28
|
+
logicalEntry?: LogicalSightEntry;
|
|
29
|
+
};
|
|
30
|
+
/** Match export:embed's dotenv loading before evaluating dynamic app configuration. */
|
|
31
|
+
export declare function prepareProjectEnvironment(options: InspectSightProjectOptions): void;
|
|
32
|
+
/** Runs only in the disposable snapshot child process; exported for fixture tests. */
|
|
33
|
+
export declare function inspectInstalledProject(options: InspectSightProjectOptions): InstalledSightProject;
|
|
34
|
+
/** Use the same config loader as export:embed; custom Metro roots must be honored. */
|
|
35
|
+
export declare function inspectSourceMapContext(options: InspectSightProjectOptions, projectType: ProjectType): Promise<SourceMapContext>;
|
|
36
|
+
export declare function inspectSightProject(options: InspectSightProjectOptions, processOptions?: DependencyProcessOptions): Promise<InspectedSightProject>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,191 @@
|
|
|
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.prepareProjectEnvironment = prepareProjectEnvironment;
|
|
7
|
+
exports.inspectInstalledProject = inspectInstalledProject;
|
|
8
|
+
exports.inspectSourceMapContext = inspectSourceMapContext;
|
|
9
|
+
exports.inspectSightProject = inspectSightProject;
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const module_1 = require("module");
|
|
13
|
+
const expo_1 = require("../../../expo");
|
|
14
|
+
const process_1 = require("./process");
|
|
15
|
+
function requireInsideSnapshot(snapshotRoot, resolved) {
|
|
16
|
+
const real = fs_1.default.realpathSync(resolved);
|
|
17
|
+
const relative = path_1.default.relative(snapshotRoot, real);
|
|
18
|
+
if (relative === '..' || relative.startsWith(`..${path_1.default.sep}`) || path_1.default.isAbsolute(relative)) {
|
|
19
|
+
throw new Error(`Sight comparison resolved a file outside the repository snapshot: ${resolved}`);
|
|
20
|
+
}
|
|
21
|
+
return real;
|
|
22
|
+
}
|
|
23
|
+
function logicalEntryForResolvedFile(projectRoot, entryFile) {
|
|
24
|
+
const relative = path_1.default.relative(projectRoot, entryFile).split(path_1.default.sep).join('/');
|
|
25
|
+
const marker = '/node_modules/';
|
|
26
|
+
const normalized = entryFile.split(path_1.default.sep).join('/');
|
|
27
|
+
const moduleStart = normalized.lastIndexOf(marker);
|
|
28
|
+
if (moduleStart !== -1) {
|
|
29
|
+
return { kind: 'module', value: normalized.slice(moduleStart + marker.length).replace(/\.[cm]?[jt]sx?$/, '') };
|
|
30
|
+
}
|
|
31
|
+
return { kind: 'relative', value: relative };
|
|
32
|
+
}
|
|
33
|
+
/** Match export:embed's dotenv loading before evaluating dynamic app configuration. */
|
|
34
|
+
function prepareProjectEnvironment(options) {
|
|
35
|
+
if (options.explicitType === 'bare')
|
|
36
|
+
return;
|
|
37
|
+
const snapshotRoot = fs_1.default.realpathSync(options.snapshotRoot);
|
|
38
|
+
const projectRoot = requireInsideSnapshot(snapshotRoot, options.projectRoot);
|
|
39
|
+
const projectRequire = (0, module_1.createRequire)(path_1.default.join(projectRoot, 'package.json'));
|
|
40
|
+
let expoManifest;
|
|
41
|
+
try {
|
|
42
|
+
expoManifest = projectRequire.resolve('expo/package.json');
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const expoRequire = (0, module_1.createRequire)(requireInsideSnapshot(snapshotRoot, expoManifest));
|
|
48
|
+
let loaderPath;
|
|
49
|
+
try {
|
|
50
|
+
loaderPath = expoRequire.resolve('@expo/cli/build/src/utils/nodeEnv');
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Bare apps may have Expo modules without the export CLI installed.
|
|
54
|
+
}
|
|
55
|
+
const loader = loaderPath ? expoRequire(requireInsideSnapshot(snapshotRoot, loaderPath)) : undefined;
|
|
56
|
+
if (typeof loader?.loadEnvFiles !== 'function') {
|
|
57
|
+
if ((0, expo_1.detectProjectType)({ projectRoot, explicitType: options.explicitType }) === 'bare')
|
|
58
|
+
return;
|
|
59
|
+
throw new Error('This Expo CLI does not expose its environment loader. Sight cannot reproduce export:embed configuration for this version.');
|
|
60
|
+
}
|
|
61
|
+
// The installed loader owns dotenv precedence and EXPO_NO_DOTENV behavior.
|
|
62
|
+
loader.loadEnvFiles(projectRoot);
|
|
63
|
+
}
|
|
64
|
+
/** Runs only in the disposable snapshot child process; exported for fixture tests. */
|
|
65
|
+
function inspectInstalledProject(options) {
|
|
66
|
+
const snapshotRoot = fs_1.default.realpathSync(options.snapshotRoot);
|
|
67
|
+
const projectRoot = requireInsideSnapshot(snapshotRoot, options.projectRoot);
|
|
68
|
+
const manifestPath = requireInsideSnapshot(snapshotRoot, path_1.default.join(projectRoot, 'package.json'));
|
|
69
|
+
const projectRequire = (0, module_1.createRequire)(manifestPath);
|
|
70
|
+
const projectType = (0, expo_1.detectProjectType)({ projectRoot, explicitType: options.explicitType });
|
|
71
|
+
const resolve = (specifier) => requireInsideSnapshot(snapshotRoot, projectRequire.resolve(specifier));
|
|
72
|
+
const reactNativeManifest = resolve('react-native/package.json');
|
|
73
|
+
const versions = {
|
|
74
|
+
reactNative: JSON.parse(fs_1.default.readFileSync(reactNativeManifest, 'utf8')).version,
|
|
75
|
+
};
|
|
76
|
+
let expoRequire;
|
|
77
|
+
if (projectType === 'expo') {
|
|
78
|
+
const expoManifest = resolve('expo/package.json');
|
|
79
|
+
versions.expo = JSON.parse(fs_1.default.readFileSync(expoManifest, 'utf8')).version;
|
|
80
|
+
expoRequire = (0, module_1.createRequire)(expoManifest);
|
|
81
|
+
}
|
|
82
|
+
const moduleResolvers = [projectRequire, (0, module_1.createRequire)(reactNativeManifest)];
|
|
83
|
+
if (expoRequire)
|
|
84
|
+
moduleResolvers.push(expoRequire);
|
|
85
|
+
for (const resolver of moduleResolvers) {
|
|
86
|
+
let metroManifest;
|
|
87
|
+
try {
|
|
88
|
+
metroManifest = resolver.resolve('metro/package.json');
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
versions.metro = JSON.parse(fs_1.default.readFileSync(requireInsideSnapshot(snapshotRoot, metroManifest), 'utf8')).version;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
let resolvedEntryFile;
|
|
97
|
+
let logicalEntry = options.logicalEntry;
|
|
98
|
+
if (logicalEntry) {
|
|
99
|
+
resolvedEntryFile = logicalEntry.kind === 'module'
|
|
100
|
+
? resolve(logicalEntry.value)
|
|
101
|
+
: path_1.default.resolve(projectRoot, logicalEntry.value);
|
|
102
|
+
}
|
|
103
|
+
else if (options.entryFile) {
|
|
104
|
+
if (path_1.default.isAbsolute(options.entryFile)) {
|
|
105
|
+
throw new Error('Comparison --entry-file must be relative to the app directory.');
|
|
106
|
+
}
|
|
107
|
+
resolvedEntryFile = path_1.default.resolve(projectRoot, options.entryFile);
|
|
108
|
+
}
|
|
109
|
+
else if (expoRequire) {
|
|
110
|
+
const configPaths = expoRequire(requireInsideSnapshot(snapshotRoot, expoRequire.resolve('@expo/config/paths')));
|
|
111
|
+
const entry = configPaths.resolveEntryPoint(projectRoot, { platform: options.platform });
|
|
112
|
+
if (!entry)
|
|
113
|
+
throw new Error(`Expo could not resolve the ${options.platform} entrypoint.`);
|
|
114
|
+
resolvedEntryFile = path_1.default.resolve(projectRoot, entry);
|
|
115
|
+
const manifest = JSON.parse(fs_1.default.readFileSync(manifestPath, 'utf8'));
|
|
116
|
+
if (manifest.main && !manifest.main.startsWith('.') && !path_1.default.isAbsolute(manifest.main)) {
|
|
117
|
+
try {
|
|
118
|
+
if (resolve(manifest.main) === fs_1.default.realpathSync(resolvedEntryFile)) {
|
|
119
|
+
logicalEntry = { kind: 'module', value: manifest.main };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// A file such as index.js is a valid main field but not a module specifier.
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const entry = ['index.js', 'index.ts', 'index.tsx', 'index.jsx'].find(file => {
|
|
129
|
+
const candidate = path_1.default.join(projectRoot, file);
|
|
130
|
+
return fs_1.default.existsSync(candidate) && fs_1.default.statSync(candidate).isFile();
|
|
131
|
+
});
|
|
132
|
+
if (!entry)
|
|
133
|
+
throw new Error('Could not find a React Native entry file. Pass --entry-file <relative-path>.');
|
|
134
|
+
resolvedEntryFile = path_1.default.join(projectRoot, entry);
|
|
135
|
+
}
|
|
136
|
+
logicalEntry = logicalEntry || logicalEntryForResolvedFile(projectRoot, resolvedEntryFile);
|
|
137
|
+
resolvedEntryFile = requireInsideSnapshot(snapshotRoot, resolvedEntryFile);
|
|
138
|
+
if (!fs_1.default.statSync(resolvedEntryFile).isFile())
|
|
139
|
+
throw new Error('The comparison entrypoint must be a file.');
|
|
140
|
+
return { projectType, entry: logicalEntry, resolvedEntryFile, versions };
|
|
141
|
+
}
|
|
142
|
+
/** Use the same config loader as export:embed; custom Metro roots must be honored. */
|
|
143
|
+
async function inspectSourceMapContext(options, projectType) {
|
|
144
|
+
const snapshotRoot = fs_1.default.realpathSync(options.snapshotRoot);
|
|
145
|
+
if (projectType === 'bare')
|
|
146
|
+
return { sourceMapBase: snapshotRoot, sourcePathConvention: 'filesystem' };
|
|
147
|
+
const projectRoot = requireInsideSnapshot(snapshotRoot, options.projectRoot);
|
|
148
|
+
const projectRequire = (0, module_1.createRequire)(path_1.default.join(projectRoot, 'package.json'));
|
|
149
|
+
const expoManifest = requireInsideSnapshot(snapshotRoot, projectRequire.resolve('expo/package.json'));
|
|
150
|
+
const expoRequire = (0, module_1.createRequire)(expoManifest);
|
|
151
|
+
let loaderPath;
|
|
152
|
+
try {
|
|
153
|
+
loaderPath = requireInsideSnapshot(snapshotRoot, expoRequire.resolve('@expo/cli/build/src/start/server/metro/instantiateMetro'));
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
throw new Error('This Expo CLI does not expose its Metro configuration loader. Sight cannot establish source-map paths for this version.');
|
|
157
|
+
}
|
|
158
|
+
const loader = expoRequire(loaderPath);
|
|
159
|
+
if (typeof loader.loadMetroConfigAsync !== 'function') {
|
|
160
|
+
throw new Error('This Expo CLI does not expose loadMetroConfigAsync. Sight cannot establish source-map paths for this version.');
|
|
161
|
+
}
|
|
162
|
+
const expoConfig = expoRequire(requireInsideSnapshot(snapshotRoot, expoRequire.resolve('@expo/config')));
|
|
163
|
+
const { exp } = expoConfig.getConfig(projectRoot, { skipSDKVersionRequirement: true });
|
|
164
|
+
const { config } = await loader.loadMetroConfigAsync(projectRoot, {}, { exp, isExporting: true });
|
|
165
|
+
const sourceMapBase = requireInsideSnapshot(snapshotRoot, config.server?.unstable_serverRoot ?? config.projectRoot);
|
|
166
|
+
return { sourceMapBase, sourcePathConvention: 'expo-server-root' };
|
|
167
|
+
}
|
|
168
|
+
const resultMarker = 'BUNDLE_DROP_SIGHT_PROJECT=';
|
|
169
|
+
const childScript = `const helper = require(process.argv[1]);
|
|
170
|
+
void (async () => {
|
|
171
|
+
const options = JSON.parse(process.argv[2]);
|
|
172
|
+
helper.prepareProjectEnvironment(options);
|
|
173
|
+
const result = helper.inspectInstalledProject(options);
|
|
174
|
+
const context = await helper.inspectSourceMapContext(options, result.projectType);
|
|
175
|
+
process.stdout.write('\\n${resultMarker}' + JSON.stringify({ ...result, ...context }) + '\\n');
|
|
176
|
+
})().catch(error => { console.error(error); process.exitCode = 1; });`;
|
|
177
|
+
async function inspectSightProject(options, processOptions = {}) {
|
|
178
|
+
const result = await (0, process_1.runComparisonProcess)({
|
|
179
|
+
command: process.execPath,
|
|
180
|
+
args: ['-e', childScript, __filename, JSON.stringify(options)],
|
|
181
|
+
cwd: options.projectRoot,
|
|
182
|
+
phase: 'Inspect comparison project',
|
|
183
|
+
signal: processOptions.signal,
|
|
184
|
+
env: { ...(processOptions.env || process.env), NODE_ENV: 'production' },
|
|
185
|
+
logPath: processOptions.logPath,
|
|
186
|
+
});
|
|
187
|
+
const line = result.stdout.split('\n').reverse().find(value => value.startsWith(resultMarker));
|
|
188
|
+
if (!line)
|
|
189
|
+
throw new Error('Project inspection did not return comparison metadata. See the inspection log.');
|
|
190
|
+
return JSON.parse(line.slice(resultMarker.length));
|
|
191
|
+
}
|