@gfean/react-native-bundle-drop 0.4.6 → 0.6.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 +168 -4
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +69 -0
- package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
- package/ios/BundleDropBridge.m +18 -0
- package/ios/BundleDropLocator.swift +48 -2
- package/ios/BundleDropModule.swift +75 -0
- package/ios/BundleDropRuntimeCrypto.swift +45 -0
- package/lib/CLI/cli.d.ts +1 -0
- package/lib/CLI/cli.js +166 -79
- package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
- package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
- package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
- package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
- package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
- package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
- package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
- package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
- package/lib/CLI/scripts/aipowered/init-project-config.js +228 -43
- package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
- package/lib/CLI/scripts/aipowered/scanner.js +164 -32
- package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
- package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
- package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
- package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
- package/lib/CLI/scripts/bare-metro-config.js +24 -32
- package/lib/CLI/scripts/doctor.js +143 -22
- package/lib/CLI/scripts/expo/configure-expo.js +51 -60
- package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
- package/lib/CLI/scripts/expo/package-manager.js +63 -25
- package/lib/CLI/scripts/init-config.d.ts +7 -7
- package/lib/CLI/scripts/init-config.js +246 -32
- package/lib/CLI/scripts/login-cli.js +35 -10
- package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
- package/lib/CLI/scripts/metro-config-authority.js +303 -0
- package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
- package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
- package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
- package/lib/CLI/scripts/native-setup-contract.js +63 -33
- package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
- package/lib/CLI/scripts/native-startup-validator.js +964 -0
- package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
- package/lib/CLI/scripts/safe-file-transaction.js +159 -0
- package/lib/CLI/scripts/sight-artifacts.d.ts +17 -0
- package/lib/CLI/scripts/sight-artifacts.js +204 -0
- package/lib/CLI/scripts/sight-cli.d.ts +10 -0
- package/lib/CLI/scripts/sight-cli.js +127 -0
- package/lib/CLI/scripts/sight-session.d.ts +14 -0
- package/lib/CLI/scripts/sight-session.js +192 -0
- package/lib/api/clientApi.d.ts +3 -1
- package/lib/api/clientApi.js +14 -0
- package/lib/api/types.d.ts +39 -0
- package/lib/context.d.ts +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/install/installFromZip.d.ts +3 -0
- package/lib/install/installFromZip.js +10 -1
- package/lib/loadConfig.d.ts +17 -1
- package/lib/loadConfig.js +16 -0
- package/lib/manager/downloadAndInstall.d.ts +3 -2
- package/lib/manager/downloadAndInstall.js +111 -46
- package/lib/manager/rollbackState.d.ts +3 -1
- package/lib/manager/rollbackState.js +2 -2
- package/lib/manager/updateCheck.d.ts +1 -0
- package/lib/manager/updateCheck.js +218 -78
- package/lib/metro.d.ts +8 -1
- package/lib/metro.js +68 -19
- package/lib/native/bundleDropNative.js +2 -1
- package/lib/native/fs.d.ts +6 -0
- package/lib/native/fs.js +24 -0
- package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
- package/lib/patch-engine/installFromPatchSet.js +14 -3
- package/lib/patch-engine/patchTransport.d.ts +2 -0
- package/lib/patch-engine/patchTransport.js +9 -0
- package/lib/runtime/initState.d.ts +5 -0
- package/lib/runtime/initState.js +4 -0
- package/lib/runtime/service.js +60 -3
- package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
- package/lib/runtime-delivery/artifactCapability.js +32 -0
- package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
- package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
- package/lib/runtime-delivery/bootstrapConfig.d.ts +50 -0
- package/lib/runtime-delivery/bootstrapConfig.js +217 -0
- package/lib/runtime-delivery/diagnostics.d.ts +17 -0
- package/lib/runtime-delivery/diagnostics.js +58 -0
- package/lib/runtime-delivery/encoding.d.ts +5 -0
- package/lib/runtime-delivery/encoding.js +132 -0
- package/lib/runtime-delivery/heartbeat.d.ts +3 -0
- package/lib/runtime-delivery/heartbeat.js +88 -0
- package/lib/runtime-delivery/localResolver.d.ts +23 -0
- package/lib/runtime-delivery/localResolver.js +81 -0
- package/lib/runtime-delivery/manifestState.d.ts +9 -0
- package/lib/runtime-delivery/manifestState.js +102 -0
- package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
- package/lib/runtime-delivery/manifestVerifier.js +329 -0
- package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
- package/lib/runtime-delivery/runtimeDelivery.js +375 -0
- package/lib/runtime-delivery/types.d.ts +87 -0
- package/lib/runtime-delivery/types.js +6 -0
- package/package.json +2 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type InspectedFile = {
|
|
2
|
+
exists: boolean;
|
|
3
|
+
content: string;
|
|
4
|
+
mode: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const inspectProjectFile: (root: string, relativePath: string) => InspectedFile;
|
|
7
|
+
export declare const inspectProjectDirectory: (root: string, relativePath: string) => boolean;
|
|
8
|
+
export declare const writeProjectFileAtomically: (root: string, relativePath: string, content: string, mode?: number) => void;
|
|
9
|
+
export declare const createSafeBackupDirectory: (projectRoot: string, label: string) => string;
|
|
10
|
+
export declare const writeBackupFile: (backupRoot: string, relativePath: string, content: string, mode: number) => void;
|
|
11
|
+
export declare const restoreProjectFile: (projectRoot: string, backupRoot: string, relativePath: string) => void;
|
|
12
|
+
export declare const removeProjectFile: (projectRoot: string, relativePath: string) => void;
|
|
@@ -0,0 +1,159 @@
|
|
|
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.removeProjectFile = exports.restoreProjectFile = exports.writeBackupFile = exports.createSafeBackupDirectory = exports.writeProjectFileAtomically = exports.inspectProjectDirectory = exports.inspectProjectFile = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const assertSafeRelativePath = (relativePath) => {
|
|
11
|
+
if (!relativePath ||
|
|
12
|
+
path_1.default.isAbsolute(relativePath) ||
|
|
13
|
+
relativePath.includes('\\') ||
|
|
14
|
+
relativePath.split('/').includes('..')) {
|
|
15
|
+
throw new Error(`Refusing unsafe transaction path: ${relativePath}`);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const assertRegularDirectory = (directory) => {
|
|
19
|
+
const stat = fs_1.default.lstatSync(directory);
|
|
20
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
21
|
+
throw new Error(`Refusing symlinked or non-directory transaction path: ${directory}`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const lstatIfPresent = (targetPath) => {
|
|
25
|
+
try {
|
|
26
|
+
return fs_1.default.lstatSync(targetPath);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error.code === 'ENOENT')
|
|
30
|
+
return null;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const ensureSafeParentDirectory = (root, relativePath) => {
|
|
35
|
+
assertSafeRelativePath(relativePath);
|
|
36
|
+
assertRegularDirectory(root);
|
|
37
|
+
const parentParts = path_1.default.dirname(relativePath).split('/').filter(part => part !== '.');
|
|
38
|
+
let current = root;
|
|
39
|
+
for (const part of parentParts) {
|
|
40
|
+
current = path_1.default.join(current, part);
|
|
41
|
+
if (!lstatIfPresent(current)) {
|
|
42
|
+
fs_1.default.mkdirSync(current);
|
|
43
|
+
}
|
|
44
|
+
assertRegularDirectory(current);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const hasSafeParentDirectory = (root, relativePath) => {
|
|
48
|
+
assertSafeRelativePath(relativePath);
|
|
49
|
+
assertRegularDirectory(root);
|
|
50
|
+
const parentParts = path_1.default.dirname(relativePath).split('/').filter(part => part !== '.');
|
|
51
|
+
let current = root;
|
|
52
|
+
for (const part of parentParts) {
|
|
53
|
+
current = path_1.default.join(current, part);
|
|
54
|
+
if (!lstatIfPresent(current))
|
|
55
|
+
return false;
|
|
56
|
+
assertRegularDirectory(current);
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
const readRegularFile = (filePath) => {
|
|
61
|
+
const descriptor = fs_1.default.openSync(filePath, fs_1.default.constants.O_RDONLY | fs_1.default.constants.O_NOFOLLOW);
|
|
62
|
+
try {
|
|
63
|
+
const stat = fs_1.default.fstatSync(descriptor);
|
|
64
|
+
if (!stat.isFile()) {
|
|
65
|
+
throw new Error(`Refusing symlinked or non-regular transaction target: ${filePath}`);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
content: fs_1.default.readFileSync(descriptor, 'utf8'),
|
|
69
|
+
mode: stat.mode & 0o777,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
fs_1.default.closeSync(descriptor);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const inspectProjectFile = (root, relativePath) => {
|
|
77
|
+
if (!hasSafeParentDirectory(root, relativePath)) {
|
|
78
|
+
return { exists: false, content: '', mode: 0o666 };
|
|
79
|
+
}
|
|
80
|
+
const filePath = path_1.default.join(root, relativePath);
|
|
81
|
+
const stat = lstatIfPresent(filePath);
|
|
82
|
+
if (!stat)
|
|
83
|
+
return { exists: false, content: '', mode: 0o666 };
|
|
84
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
85
|
+
throw new Error(`Refusing symlinked or non-regular transaction target: ${relativePath}`);
|
|
86
|
+
}
|
|
87
|
+
return { exists: true, ...readRegularFile(filePath) };
|
|
88
|
+
};
|
|
89
|
+
exports.inspectProjectFile = inspectProjectFile;
|
|
90
|
+
const inspectProjectDirectory = (root, relativePath) => {
|
|
91
|
+
if (!hasSafeParentDirectory(root, relativePath))
|
|
92
|
+
return false;
|
|
93
|
+
const directoryPath = path_1.default.join(root, relativePath);
|
|
94
|
+
const stat = lstatIfPresent(directoryPath);
|
|
95
|
+
if (!stat)
|
|
96
|
+
return false;
|
|
97
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
98
|
+
throw new Error(`Refusing symlinked or non-directory transaction target: ${relativePath}`);
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
};
|
|
102
|
+
exports.inspectProjectDirectory = inspectProjectDirectory;
|
|
103
|
+
const writeExclusiveFile = (filePath, content, mode) => {
|
|
104
|
+
const descriptor = fs_1.default.openSync(filePath, fs_1.default.constants.O_WRONLY |
|
|
105
|
+
fs_1.default.constants.O_CREAT |
|
|
106
|
+
fs_1.default.constants.O_EXCL |
|
|
107
|
+
fs_1.default.constants.O_NOFOLLOW, mode);
|
|
108
|
+
try {
|
|
109
|
+
fs_1.default.writeFileSync(descriptor, content, 'utf8');
|
|
110
|
+
fs_1.default.fsyncSync(descriptor);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
fs_1.default.closeSync(descriptor);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const writeProjectFileAtomically = (root, relativePath, content, mode = 0o666) => {
|
|
117
|
+
const current = (0, exports.inspectProjectFile)(root, relativePath);
|
|
118
|
+
ensureSafeParentDirectory(root, relativePath);
|
|
119
|
+
const targetPath = path_1.default.join(root, relativePath);
|
|
120
|
+
const temporaryName = `.${path_1.default.basename(relativePath)}.bundledrop-${crypto_1.default.randomBytes(12).toString('hex')}.tmp`;
|
|
121
|
+
const temporaryPath = path_1.default.join(path_1.default.dirname(targetPath), temporaryName);
|
|
122
|
+
writeExclusiveFile(temporaryPath, content, current.exists ? current.mode : mode);
|
|
123
|
+
try {
|
|
124
|
+
fs_1.default.renameSync(temporaryPath, targetPath);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (lstatIfPresent(temporaryPath))
|
|
128
|
+
fs_1.default.unlinkSync(temporaryPath);
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
exports.writeProjectFileAtomically = writeProjectFileAtomically;
|
|
133
|
+
const createSafeBackupDirectory = (projectRoot, label) => {
|
|
134
|
+
ensureSafeParentDirectory(projectRoot, '.bundledrop-backup/transaction');
|
|
135
|
+
const backupRoot = path_1.default.join(projectRoot, '.bundledrop-backup');
|
|
136
|
+
const backupDirectory = fs_1.default.mkdtempSync(path_1.default.join(backupRoot, `${label}-`));
|
|
137
|
+
assertRegularDirectory(backupDirectory);
|
|
138
|
+
return backupDirectory;
|
|
139
|
+
};
|
|
140
|
+
exports.createSafeBackupDirectory = createSafeBackupDirectory;
|
|
141
|
+
const writeBackupFile = (backupRoot, relativePath, content, mode) => {
|
|
142
|
+
ensureSafeParentDirectory(backupRoot, relativePath);
|
|
143
|
+
writeExclusiveFile(path_1.default.join(backupRoot, relativePath), content, mode);
|
|
144
|
+
};
|
|
145
|
+
exports.writeBackupFile = writeBackupFile;
|
|
146
|
+
const restoreProjectFile = (projectRoot, backupRoot, relativePath) => {
|
|
147
|
+
const backup = (0, exports.inspectProjectFile)(backupRoot, relativePath);
|
|
148
|
+
if (!backup.exists)
|
|
149
|
+
throw new Error(`Missing transaction backup: ${relativePath}`);
|
|
150
|
+
(0, exports.inspectProjectFile)(projectRoot, relativePath);
|
|
151
|
+
(0, exports.writeProjectFileAtomically)(projectRoot, relativePath, backup.content, backup.mode);
|
|
152
|
+
};
|
|
153
|
+
exports.restoreProjectFile = restoreProjectFile;
|
|
154
|
+
const removeProjectFile = (projectRoot, relativePath) => {
|
|
155
|
+
const target = (0, exports.inspectProjectFile)(projectRoot, relativePath);
|
|
156
|
+
if (target.exists)
|
|
157
|
+
fs_1.default.unlinkSync(path_1.default.join(projectRoot, relativePath));
|
|
158
|
+
};
|
|
159
|
+
exports.removeProjectFile = removeProjectFile;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MobilePlatform, ProjectType } from '../../expo';
|
|
2
|
+
export type SightArtifacts = {
|
|
3
|
+
outputDirectory: string;
|
|
4
|
+
bundlePath: string;
|
|
5
|
+
sourceMapPath: string;
|
|
6
|
+
temporary: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type GenerateSightArtifactsOptions = {
|
|
9
|
+
projectRoot: string;
|
|
10
|
+
projectType: ProjectType;
|
|
11
|
+
platform: MobilePlatform;
|
|
12
|
+
output?: string;
|
|
13
|
+
keep?: boolean;
|
|
14
|
+
entryFile?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function validateSightArtifacts(bundlePath: string, sourceMapPath: string): void;
|
|
17
|
+
export declare function generateSightArtifacts({ projectRoot, projectType, platform, output, keep, entryFile: explicitEntryFile, }: GenerateSightArtifactsOptions): Promise<SightArtifacts>;
|
|
@@ -0,0 +1,204 @@
|
|
|
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.validateSightArtifacts = validateSightArtifacts;
|
|
7
|
+
exports.generateSightArtifacts = generateSightArtifacts;
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const module_1 = require("module");
|
|
13
|
+
const HERMES_BYTECODE_MAGIC = Buffer.from([0xc6, 0x1f, 0xbc, 0x03, 0xc1, 0x03, 0x19, 0x1f]);
|
|
14
|
+
function ensureOutputDirectory(projectRoot, requestedOutput, keep) {
|
|
15
|
+
if (!requestedOutput && !keep) {
|
|
16
|
+
return {
|
|
17
|
+
outputDirectory: fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'bundle-drop-sight-')),
|
|
18
|
+
temporary: true,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const outputDirectory = requestedOutput
|
|
22
|
+
? path_1.default.resolve(projectRoot, requestedOutput)
|
|
23
|
+
: path_1.default.join(projectRoot, '.bundle-drop', 'sight', new Date().toISOString().replace(/[:.]/g, '-'));
|
|
24
|
+
if (fs_1.default.existsSync(outputDirectory)) {
|
|
25
|
+
const stats = fs_1.default.lstatSync(outputDirectory);
|
|
26
|
+
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
27
|
+
throw new Error(`Sight output must be a real directory: ${outputDirectory}`);
|
|
28
|
+
}
|
|
29
|
+
if (fs_1.default.readdirSync(outputDirectory).length > 0) {
|
|
30
|
+
throw new Error(`Sight output directory must be empty: ${outputDirectory}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
fs_1.default.mkdirSync(outputDirectory, { recursive: true, mode: 0o755 });
|
|
35
|
+
}
|
|
36
|
+
return { outputDirectory, temporary: false };
|
|
37
|
+
}
|
|
38
|
+
function resolveProjectModule(projectRoot, moduleId) {
|
|
39
|
+
const manifestPath = path_1.default.join(projectRoot, 'package.json');
|
|
40
|
+
if (!fs_1.default.existsSync(manifestPath)) {
|
|
41
|
+
throw new Error(`No package.json was found at ${manifestPath}.`);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
return (0, module_1.createRequire)(manifestPath).resolve(moduleId);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new Error(`Could not resolve ${moduleId} from ${projectRoot}. Install dependencies and try again.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function resolveExpoModule(projectRoot, moduleId) {
|
|
51
|
+
const expoManifest = resolveProjectModule(projectRoot, 'expo/package.json');
|
|
52
|
+
try {
|
|
53
|
+
return (0, module_1.createRequire)(expoManifest).resolve(moduleId);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new Error(`The project-local Expo installation could not resolve ${moduleId}.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function resolveBareEntryFile(projectRoot, explicitEntryFile) {
|
|
60
|
+
const candidates = explicitEntryFile
|
|
61
|
+
? [explicitEntryFile]
|
|
62
|
+
: ['index.js', 'index.ts', 'index.tsx', 'index.jsx'];
|
|
63
|
+
const entryFile = candidates
|
|
64
|
+
.map(candidate => path_1.default.resolve(projectRoot, candidate))
|
|
65
|
+
.find(candidate => fs_1.default.existsSync(candidate) && fs_1.default.statSync(candidate).isFile());
|
|
66
|
+
if (!entryFile) {
|
|
67
|
+
throw new Error('Could not find a React Native entry file. Pass it explicitly with --entry-file <path>.');
|
|
68
|
+
}
|
|
69
|
+
return entryFile;
|
|
70
|
+
}
|
|
71
|
+
function resolveExpoEntryFile(projectRoot, platform) {
|
|
72
|
+
const configPathsPath = resolveExpoModule(projectRoot, '@expo/config/paths');
|
|
73
|
+
const configPaths = (0, module_1.createRequire)(path_1.default.join(projectRoot, 'package.json'))(configPathsPath);
|
|
74
|
+
const entryFile = configPaths.resolveEntryPoint?.(projectRoot, { platform });
|
|
75
|
+
if (!entryFile) {
|
|
76
|
+
throw new Error(`Expo could not resolve the ${platform} entrypoint.`);
|
|
77
|
+
}
|
|
78
|
+
return path_1.default.isAbsolute(entryFile) ? entryFile : path_1.default.resolve(projectRoot, entryFile);
|
|
79
|
+
}
|
|
80
|
+
function runMetroCommand(projectRoot, cliPath, args) {
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
const child = (0, child_process_1.spawn)(process.execPath, [cliPath, ...args], {
|
|
83
|
+
cwd: projectRoot,
|
|
84
|
+
env: { ...process.env, NODE_ENV: 'production' },
|
|
85
|
+
stdio: 'inherit',
|
|
86
|
+
});
|
|
87
|
+
child.once('error', reject);
|
|
88
|
+
child.once('exit', (code, signal) => {
|
|
89
|
+
if (code === 0) {
|
|
90
|
+
resolve();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
reject(new Error(`Metro bundle generation failed${signal ? ` with signal ${signal}` : ` with exit code ${code}`}.`));
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function sourceMapDebugId(sourceMap) {
|
|
98
|
+
const value = sourceMap.debugId ?? sourceMap.debug_id;
|
|
99
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
100
|
+
}
|
|
101
|
+
function bundleDebugId(bundle) {
|
|
102
|
+
return bundle.match(/^\/\/[#@]\s*debugId=([^\s]+)\s*$/m)?.[1] ?? null;
|
|
103
|
+
}
|
|
104
|
+
function validateSightArtifacts(bundlePath, sourceMapPath) {
|
|
105
|
+
for (const artifactPath of [bundlePath, sourceMapPath]) {
|
|
106
|
+
if (!fs_1.default.existsSync(artifactPath) ||
|
|
107
|
+
!fs_1.default.lstatSync(artifactPath).isFile() ||
|
|
108
|
+
fs_1.default.lstatSync(artifactPath).isSymbolicLink()) {
|
|
109
|
+
throw new Error(`Sight generation did not create ${artifactPath}.`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const bundleBuffer = fs_1.default.readFileSync(bundlePath);
|
|
113
|
+
if (bundleBuffer.length === 0) {
|
|
114
|
+
throw new Error('Sight cannot analyze an empty JavaScript bundle.');
|
|
115
|
+
}
|
|
116
|
+
if (bundleBuffer.subarray(0, HERMES_BYTECODE_MAGIC.length).equals(HERMES_BYTECODE_MAGIC)) {
|
|
117
|
+
throw new Error('Sight requires a JavaScript bundle, but Metro generated Hermes bytecode.');
|
|
118
|
+
}
|
|
119
|
+
let sourceMap;
|
|
120
|
+
try {
|
|
121
|
+
sourceMap = JSON.parse(fs_1.default.readFileSync(sourceMapPath, 'utf8'));
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
throw new Error('Metro generated an invalid source-map JSON file.');
|
|
125
|
+
}
|
|
126
|
+
if (sourceMap.version !== 3 ||
|
|
127
|
+
!Array.isArray(sourceMap.sources) ||
|
|
128
|
+
typeof sourceMap.mappings !== 'string') {
|
|
129
|
+
throw new Error('Sight requires a source-map version 3 file with sources and mappings.');
|
|
130
|
+
}
|
|
131
|
+
const bundle = bundleBuffer.toString('utf8');
|
|
132
|
+
const sourceMapReference = bundle.match(/^[/#@\s]*sourceMappingURL=([^\s]+)\s*$/m)?.[1];
|
|
133
|
+
if (sourceMapReference && path_1.default.basename(sourceMapReference) !== path_1.default.basename(sourceMapPath)) {
|
|
134
|
+
throw new Error('The generated bundle references a different source-map file.');
|
|
135
|
+
}
|
|
136
|
+
if (typeof sourceMap.file === 'string' &&
|
|
137
|
+
sourceMap.file.trim() &&
|
|
138
|
+
path_1.default.basename(sourceMap.file) !== path_1.default.basename(bundlePath)) {
|
|
139
|
+
throw new Error('The generated source map references a different bundle file.');
|
|
140
|
+
}
|
|
141
|
+
const mapDebugId = sourceMapDebugId(sourceMap);
|
|
142
|
+
const generatedBundleDebugId = bundleDebugId(bundle);
|
|
143
|
+
if (mapDebugId && generatedBundleDebugId && mapDebugId !== generatedBundleDebugId) {
|
|
144
|
+
throw new Error('The generated bundle and source map have different debug IDs.');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async function generateSightArtifacts({ projectRoot, projectType, platform, output, keep = false, entryFile: explicitEntryFile, }) {
|
|
148
|
+
const absoluteProjectRoot = path_1.default.resolve(projectRoot);
|
|
149
|
+
const { outputDirectory, temporary } = ensureOutputDirectory(absoluteProjectRoot, output, keep);
|
|
150
|
+
const bundlePath = path_1.default.join(outputDirectory, `main.${platform}.jsbundle`);
|
|
151
|
+
const sourceMapPath = `${bundlePath}.map`;
|
|
152
|
+
try {
|
|
153
|
+
if (projectType === 'expo') {
|
|
154
|
+
const cliPath = resolveExpoModule(absoluteProjectRoot, '@expo/cli');
|
|
155
|
+
const entryFile = explicitEntryFile
|
|
156
|
+
? path_1.default.resolve(absoluteProjectRoot, explicitEntryFile)
|
|
157
|
+
: resolveExpoEntryFile(absoluteProjectRoot, platform);
|
|
158
|
+
const assetsDirectory = path_1.default.join(outputDirectory, 'assets');
|
|
159
|
+
fs_1.default.mkdirSync(assetsDirectory, { recursive: true, mode: 0o755 });
|
|
160
|
+
await runMetroCommand(absoluteProjectRoot, cliPath, [
|
|
161
|
+
'export:embed',
|
|
162
|
+
'--platform',
|
|
163
|
+
platform,
|
|
164
|
+
'--entry-file',
|
|
165
|
+
entryFile,
|
|
166
|
+
'--bundle-output',
|
|
167
|
+
bundlePath,
|
|
168
|
+
'--sourcemap-output',
|
|
169
|
+
sourceMapPath,
|
|
170
|
+
'--assets-dest',
|
|
171
|
+
assetsDirectory,
|
|
172
|
+
'--dev',
|
|
173
|
+
'false',
|
|
174
|
+
'--minify',
|
|
175
|
+
'true',
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const cliPath = resolveProjectModule(absoluteProjectRoot, 'react-native/cli.js');
|
|
180
|
+
const entryFile = resolveBareEntryFile(absoluteProjectRoot, explicitEntryFile);
|
|
181
|
+
await runMetroCommand(absoluteProjectRoot, cliPath, [
|
|
182
|
+
'bundle',
|
|
183
|
+
'--platform',
|
|
184
|
+
platform,
|
|
185
|
+
'--dev',
|
|
186
|
+
'false',
|
|
187
|
+
'--entry-file',
|
|
188
|
+
entryFile,
|
|
189
|
+
'--bundle-output',
|
|
190
|
+
bundlePath,
|
|
191
|
+
'--sourcemap-output',
|
|
192
|
+
sourceMapPath,
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
validateSightArtifacts(bundlePath, sourceMapPath);
|
|
196
|
+
return { outputDirectory, bundlePath, sourceMapPath, temporary };
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
if (temporary) {
|
|
200
|
+
fs_1.default.rmSync(outputDirectory, { recursive: true, force: true });
|
|
201
|
+
}
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MobilePlatform, ProjectType } from '../../expo';
|
|
2
|
+
export type SightCommandOptions = {
|
|
3
|
+
platform?: MobilePlatform;
|
|
4
|
+
projectType?: ProjectType;
|
|
5
|
+
open?: boolean;
|
|
6
|
+
keep?: boolean;
|
|
7
|
+
output?: string;
|
|
8
|
+
entryFile?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function runSightCommand(options: SightCommandOptions): Promise<void>;
|
|
@@ -0,0 +1,127 @@
|
|
|
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.runSightCommand = runSightCommand;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
11
|
+
const expo_1 = require("../../expo");
|
|
12
|
+
const sight_artifacts_1 = require("./sight-artifacts");
|
|
13
|
+
const sight_session_1 = require("./sight-session");
|
|
14
|
+
const DEFAULT_SIGHT_URL = 'https://bundledrop.app/sight';
|
|
15
|
+
function detectAvailablePlatforms(projectRoot) {
|
|
16
|
+
return ['ios', 'android'].filter(platform => fs_1.default.existsSync(path_1.default.join(projectRoot, platform)));
|
|
17
|
+
}
|
|
18
|
+
async function resolvePlatform(projectRoot, explicitPlatform) {
|
|
19
|
+
if (explicitPlatform) {
|
|
20
|
+
return explicitPlatform;
|
|
21
|
+
}
|
|
22
|
+
const availablePlatforms = detectAvailablePlatforms(projectRoot);
|
|
23
|
+
if (availablePlatforms.length === 1) {
|
|
24
|
+
return availablePlatforms[0];
|
|
25
|
+
}
|
|
26
|
+
const answer = await (0, prompts_1.default)({
|
|
27
|
+
type: 'select',
|
|
28
|
+
name: 'platform',
|
|
29
|
+
message: 'Which platform should Sight analyze?',
|
|
30
|
+
choices: [
|
|
31
|
+
{ title: 'iOS', value: 'ios' },
|
|
32
|
+
{ title: 'Android', value: 'android' },
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
if (answer.platform !== 'ios' && answer.platform !== 'android') {
|
|
36
|
+
throw new Error('No platform was selected. Pass --platform ios or --platform android.');
|
|
37
|
+
}
|
|
38
|
+
return answer.platform;
|
|
39
|
+
}
|
|
40
|
+
function printArtifactPaths(artifacts, heading) {
|
|
41
|
+
console.log(chalk_1.default.green(`\n${heading}`));
|
|
42
|
+
console.log(` Bundle: ${artifacts.bundlePath}`);
|
|
43
|
+
console.log(` Source map: ${artifacts.sourceMapPath}`);
|
|
44
|
+
}
|
|
45
|
+
function printManualInstructions(artifacts) {
|
|
46
|
+
printArtifactPaths(artifacts, 'Source files have been generated here:');
|
|
47
|
+
console.log(chalk_1.default.cyan(`\nOpen ${DEFAULT_SIGHT_URL} and attach both files for analysis.`));
|
|
48
|
+
}
|
|
49
|
+
function removeTemporaryArtifacts(artifacts) {
|
|
50
|
+
if (artifacts.temporary) {
|
|
51
|
+
fs_1.default.rmSync(artifacts.outputDirectory, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function runSightCommand(options) {
|
|
55
|
+
if (options.platform && !['ios', 'android'].includes(options.platform)) {
|
|
56
|
+
throw new Error('--platform must be ios or android.');
|
|
57
|
+
}
|
|
58
|
+
if (options.projectType && !['expo', 'bare'].includes(options.projectType)) {
|
|
59
|
+
throw new Error('--project-type must be expo or bare.');
|
|
60
|
+
}
|
|
61
|
+
const projectRoot = process.cwd();
|
|
62
|
+
const projectType = (0, expo_1.detectProjectType)({
|
|
63
|
+
projectRoot,
|
|
64
|
+
explicitType: options.projectType,
|
|
65
|
+
});
|
|
66
|
+
const platform = await resolvePlatform(projectRoot, options.platform);
|
|
67
|
+
console.log(chalk_1.default.bold.cyan('\nBundle Drop Sight'));
|
|
68
|
+
console.log(chalk_1.default.gray(`Detected ${projectType === 'expo' ? 'Expo' : 'bare React Native'} project`));
|
|
69
|
+
console.log(chalk_1.default.gray(`Generating a production ${platform} bundle and source map…`));
|
|
70
|
+
const artifacts = await (0, sight_artifacts_1.generateSightArtifacts)({
|
|
71
|
+
projectRoot,
|
|
72
|
+
projectType,
|
|
73
|
+
platform,
|
|
74
|
+
output: options.output,
|
|
75
|
+
keep: options.keep,
|
|
76
|
+
entryFile: options.entryFile,
|
|
77
|
+
});
|
|
78
|
+
console.log(chalk_1.default.green(`✓ Generated ${platform} production bundle`));
|
|
79
|
+
console.log(chalk_1.default.green('✓ Generated matching source map'));
|
|
80
|
+
const shouldOpen = options.open === false
|
|
81
|
+
? false
|
|
82
|
+
: (await (0, prompts_1.default)({
|
|
83
|
+
type: 'confirm',
|
|
84
|
+
name: 'openSight',
|
|
85
|
+
message: 'Open Bundle Drop Sight and start the local analysis?',
|
|
86
|
+
initial: true,
|
|
87
|
+
})).openSight === true;
|
|
88
|
+
if (!shouldOpen) {
|
|
89
|
+
printManualInstructions(artifacts);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const sightPageUrl = process.env.BUNDLE_DROP_SIGHT_URL || DEFAULT_SIGHT_URL;
|
|
93
|
+
let session;
|
|
94
|
+
try {
|
|
95
|
+
session = await (0, sight_session_1.startSightSession)({ artifacts, sightPageUrl });
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
printManualInstructions(artifacts);
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
let transferSucceeded = false;
|
|
102
|
+
try {
|
|
103
|
+
console.log(chalk_1.default.gray('Opening Bundle Drop Sight…'));
|
|
104
|
+
try {
|
|
105
|
+
await (0, sight_session_1.openSightInBrowser)(session.sightUrl);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
console.log(chalk_1.default.yellow('Could not open the browser automatically.'));
|
|
109
|
+
console.log(chalk_1.default.gray(`Open this one-time URL manually:\n${session.sightUrl}`));
|
|
110
|
+
}
|
|
111
|
+
await session.waitForTransfer();
|
|
112
|
+
transferSucceeded = true;
|
|
113
|
+
console.log(chalk_1.default.green('✓ Bundle and source map loaded into Sight'));
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
await session.close();
|
|
117
|
+
if (transferSucceeded && !options.keep && !options.output) {
|
|
118
|
+
removeTemporaryArtifacts(artifacts);
|
|
119
|
+
}
|
|
120
|
+
else if (transferSucceeded) {
|
|
121
|
+
printArtifactPaths(artifacts, 'Generated files were kept here:');
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
printManualInstructions(artifacts);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SightArtifacts } from './sight-artifacts';
|
|
2
|
+
export type SightSession = {
|
|
3
|
+
sightUrl: string;
|
|
4
|
+
waitForTransfer: () => Promise<void>;
|
|
5
|
+
close: () => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
type StartSightSessionOptions = {
|
|
8
|
+
artifacts: SightArtifacts;
|
|
9
|
+
sightPageUrl: string;
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function openSightInBrowser(url: string): Promise<void>;
|
|
13
|
+
export declare function startSightSession({ artifacts, sightPageUrl, timeoutMs, }: StartSightSessionOptions): Promise<SightSession>;
|
|
14
|
+
export {};
|