@gfean/react-native-bundle-drop 0.4.3 → 0.4.4
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/BundleDropExpo.podspec +21 -0
- package/README.md +250 -124
- package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +33 -3
- package/app.plugin.js +3 -0
- package/expo/android/build.gradle +159 -0
- package/expo/android/src/main/AndroidManifest.xml +1 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoConfiguration.kt +35 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoIdentityModule.kt +30 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoPackage.kt +29 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoReactNativeHostHandler.kt +16 -0
- package/expo/bundle-drop-expo-gradle-plugin/build.gradle +31 -0
- package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/BundleDropExpoPlugin.groovy +83 -0
- package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/GenerateBundleDropBuildIdentityTask.groovy +57 -0
- package/expo/ios/Sources/BundleDropExpoIdentity.m +31 -0
- package/expo/ios/Sources/BundleDropExpoReactDelegateHandler.swift +24 -0
- package/expo-module.config.json +19 -0
- package/ios/BundleDropLocator.swift +7 -1
- package/lib/CLI/cli.d.ts +1 -2
- package/lib/CLI/cli.js +116 -14
- package/lib/CLI/scripts/aipowered/apply-setup-plan.d.ts +12 -0
- package/lib/CLI/scripts/aipowered/apply-setup-plan.js +55 -0
- package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -1
- package/lib/CLI/scripts/aipowered/backend-client.js +25 -2
- package/lib/CLI/scripts/aipowered/init-project-config.d.ts +17 -0
- package/lib/CLI/scripts/aipowered/init-project-config.js +400 -0
- package/lib/CLI/scripts/aipowered/scanner.d.ts +10 -1
- package/lib/CLI/scripts/aipowered/scanner.js +252 -5
- package/lib/CLI/scripts/aipowered/types.d.ts +39 -0
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +12 -0
- package/lib/CLI/scripts/aipowered/validate-plan.js +76 -1
- package/lib/CLI/scripts/doctor.d.ts +17 -0
- package/lib/CLI/scripts/doctor.js +412 -0
- package/lib/CLI/scripts/expo/build-receipt.d.ts +26 -0
- package/lib/CLI/scripts/expo/build-receipt.js +223 -0
- package/lib/CLI/scripts/expo/configure-expo.d.ts +28 -0
- package/lib/CLI/scripts/expo/configure-expo.js +268 -0
- package/lib/CLI/scripts/expo/eas-build-proof.d.ts +22 -0
- package/lib/CLI/scripts/expo/eas-build-proof.js +116 -0
- package/lib/CLI/scripts/expo/package-manager.d.ts +11 -0
- package/lib/CLI/scripts/expo/package-manager.js +84 -0
- package/lib/CLI/scripts/expo/write-build-receipt.d.ts +25 -0
- package/lib/CLI/scripts/expo/write-build-receipt.js +325 -0
- package/lib/CLI/scripts/expo/write-eas-build-receipt.d.ts +8 -0
- package/lib/CLI/scripts/expo/write-eas-build-receipt.js +71 -0
- package/lib/CLI/scripts/init-config.d.ts +18 -1
- package/lib/CLI/scripts/init-config.js +29 -8
- package/lib/CLI/scripts/init-metro-config.d.ts +7 -0
- package/lib/CLI/scripts/init-metro-config.js +28 -8
- package/lib/CLI/scripts/login-cli.js +17 -3
- package/lib/CLI/scripts/post-init.d.ts +6 -1
- package/lib/CLI/scripts/post-init.js +6 -33
- package/lib/CLI/scripts/upload-cli.d.ts +1 -0
- package/lib/CLI/scripts/upload-cli.js +106 -36
- package/lib/context.d.ts +0 -2
- package/lib/context.js +18 -2
- package/lib/expo/buildIdentity.d.ts +15 -0
- package/lib/expo/buildIdentity.js +201 -0
- package/lib/expo/buildReceipt.d.ts +42 -0
- package/lib/expo/buildReceipt.js +272 -0
- package/lib/expo/config.d.ts +7 -0
- package/lib/expo/config.js +43 -0
- package/lib/expo/configCache.d.ts +1 -0
- package/lib/expo/configCache.js +20 -0
- package/lib/expo/errors.d.ts +6 -0
- package/lib/expo/errors.js +11 -0
- package/lib/expo/expoUpdatesOwnership.d.ts +13 -0
- package/lib/expo/expoUpdatesOwnership.js +22 -0
- package/lib/expo/exportExpoProject.d.ts +21 -0
- package/lib/expo/exportExpoProject.js +125 -0
- package/lib/expo/exportValidation.d.ts +11 -0
- package/lib/expo/exportValidation.js +115 -0
- package/lib/expo/index.d.ts +18 -0
- package/lib/expo/index.js +25 -0
- package/lib/expo/localModules.d.ts +4 -0
- package/lib/expo/localModules.js +51 -0
- package/lib/expo/nativeIdentity.d.ts +1 -0
- package/lib/expo/nativeIdentity.js +17 -0
- package/lib/expo/projectType.d.ts +7 -0
- package/lib/expo/projectType.js +200 -0
- package/lib/expo/runtimeVersion.d.ts +13 -0
- package/lib/expo/runtimeVersion.js +45 -0
- package/lib/expo/types.d.ts +15 -0
- package/lib/expo/types.js +2 -0
- package/lib/fs/userProperties.d.ts +0 -2
- package/lib/fs/userProperties.js +0 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -2
- package/lib/loadConfig.d.ts +15 -7
- package/lib/loadConfig.js +2 -19
- package/lib/metro.d.ts +17 -0
- package/lib/metro.js +57 -0
- package/lib/native/bundleDropNative.d.ts +2 -0
- package/lib/native/bundleDropNative.js +9 -1
- package/lib/runtime/service.js +12 -1
- package/lib/scripts/bundle.d.ts +2 -2
- package/lib/scripts/bundle.js +10 -97
- package/lib/scripts/canonicalArtifact.d.ts +30 -0
- package/lib/scripts/canonicalArtifact.js +212 -0
- package/lib/scripts/exportProject.d.ts +41 -0
- package/lib/scripts/exportProject.js +82 -0
- package/package.json +51 -46
- package/plugin/constants.js +9 -0
- package/plugin/expoUpdates.js +131 -0
- package/plugin/index.js +11 -0
- package/plugin/markers.js +31 -0
- package/plugin/withBundleDrop.js +36 -0
- package/plugin/xcodeBuildPhase.js +77 -0
- package/react-native.config.js +20 -0
|
@@ -3,18 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isTrustedAiPlanningServer = exports.isSummaryOnlyAiContextFile = void 0;
|
|
6
|
+
exports.isBundleDropHostedAiPlanningServer = exports.isTrustedAiPlanningServer = exports.isSummaryOnlyAiContextFile = exports.findCredentialLikeLiteral = void 0;
|
|
7
7
|
exports.findProjectRoot = findProjectRoot;
|
|
8
8
|
exports.scanProjectForAiNativeInit = scanProjectForAiNativeInit;
|
|
9
|
+
exports.scanProjectForAiSetup = scanProjectForAiSetup;
|
|
9
10
|
const crypto_1 = __importDefault(require("crypto"));
|
|
10
11
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
12
|
const module_1 = require("module");
|
|
12
13
|
const os_1 = __importDefault(require("os"));
|
|
13
14
|
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const expo_1 = require("../../../expo");
|
|
14
16
|
const MAX_UP = 12;
|
|
15
17
|
const MAX_FILE_BYTES = 80 * 1024;
|
|
16
18
|
const MAX_TOTAL_BYTES = 350 * 1024;
|
|
17
|
-
const
|
|
19
|
+
const TRUSTED_BUNDLE_DROP_AI_HOSTS = new Set(['api.bundledrop.app']);
|
|
18
20
|
const LOCAL_AI_HOSTS = new Set(['localhost', '127.0.0.1', '::1', '[::1]', '10.0.2.2']);
|
|
19
21
|
const SKIP_DIRS = new Set([
|
|
20
22
|
'node_modules',
|
|
@@ -30,6 +32,44 @@ const sha256 = (content) => crypto_1.default.createHash('sha256').update(content
|
|
|
30
32
|
const toPosix = (filePath) => filePath.split(path_1.default.sep).join('/');
|
|
31
33
|
const normalizeServerUrl = (url) => url.replace(/\/+$/, '');
|
|
32
34
|
const readJsonFile = (filePath) => JSON.parse(fs_extra_1.default.readFileSync(filePath, 'utf8'));
|
|
35
|
+
const CREDENTIAL_LITERAL_PATTERNS = [
|
|
36
|
+
{
|
|
37
|
+
name: 'credential-like property',
|
|
38
|
+
pattern: /["'`]?(?:api[_-]?key|access[_-]?key|auth[_-]?token|aws[_-]?secret[_-]?access[_-]?key|client[_-]?secret|deployment[_-]?key|password|passwd|private[_-]?key|secret[_-]?access[_-]?key|secret|token)["'`]?(?:\s*:\s*[A-Za-z_$][A-Za-z0-9_$?.<>,\[\] ]+)?\s*(?::|=|\()\s*@?(["'`])[^\r\n"'`]+\1/i,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'authorization header',
|
|
42
|
+
pattern: /authorization["'`]?\s*(?::|=)\s*@?(["'`])\s*(?:bearer|basic)\s+[^\r\n"'`]+\1/i,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'credential-bearing URL',
|
|
46
|
+
pattern: /https?:\/\/[^\s/@:]+:[^\s/@]+@|[?&](?:api[_-]?key|access[_-]?key|auth[_-]?token|password|secret|token)=[^&\s"'`]+/i,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'private key',
|
|
50
|
+
pattern: /-----BEGIN (?:[A-Z0-9 ]+ )?PRIVATE KEY-----/,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'known access token format',
|
|
54
|
+
pattern: /\b(?:AKIA[0-9A-Z]{16}|github_pat_[A-Za-z0-9_]{20,}|gh[oprsu]_[A-Za-z0-9]{20,}|xox[baprs]-[A-Za-z0-9-]{10,})\b/,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
const findCredentialLikeLiteral = (content) => {
|
|
58
|
+
for (const candidate of CREDENTIAL_LITERAL_PATTERNS) {
|
|
59
|
+
if (candidate.pattern.test(content))
|
|
60
|
+
return candidate.name;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
exports.findCredentialLikeLiteral = findCredentialLikeLiteral;
|
|
65
|
+
const assertSafeAiSetupContent = (relativePath, content) => {
|
|
66
|
+
const finding = (0, exports.findCredentialLikeLiteral)(content);
|
|
67
|
+
if (!finding)
|
|
68
|
+
return;
|
|
69
|
+
throw new Error(`Refusing AI setup because ${relativePath} contains a ${finding}. ` +
|
|
70
|
+
'Move the value to an environment variable or configure this file manually, then retry. ' +
|
|
71
|
+
'The file was not shared, and --yes cannot bypass this safety check.');
|
|
72
|
+
};
|
|
33
73
|
const CONTEXT_SUMMARY_SIGNALS = [
|
|
34
74
|
'react-native',
|
|
35
75
|
'@gfean/react-native-bundle-drop',
|
|
@@ -146,7 +186,7 @@ const isTrustedAiPlanningServer = (serverUrl) => {
|
|
|
146
186
|
return true;
|
|
147
187
|
try {
|
|
148
188
|
const parsed = new URL(serverUrl);
|
|
149
|
-
if (parsed.hostname
|
|
189
|
+
if (TRUSTED_BUNDLE_DROP_AI_HOSTS.has(parsed.hostname))
|
|
150
190
|
return parsed.protocol === 'https:';
|
|
151
191
|
if (LOCAL_AI_HOSTS.has(parsed.hostname)) {
|
|
152
192
|
return parsed.protocol === 'http:' || parsed.protocol === 'https:';
|
|
@@ -158,6 +198,16 @@ const isTrustedAiPlanningServer = (serverUrl) => {
|
|
|
158
198
|
return false;
|
|
159
199
|
};
|
|
160
200
|
exports.isTrustedAiPlanningServer = isTrustedAiPlanningServer;
|
|
201
|
+
const isBundleDropHostedAiPlanningServer = (serverUrl) => {
|
|
202
|
+
try {
|
|
203
|
+
const parsed = new URL(serverUrl);
|
|
204
|
+
return parsed.protocol === 'https:' && TRUSTED_BUNDLE_DROP_AI_HOSTS.has(parsed.hostname);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
exports.isBundleDropHostedAiPlanningServer = isBundleDropHostedAiPlanningServer;
|
|
161
211
|
const loadBundleDropConfig = (configPath) => {
|
|
162
212
|
const moduleLike = { exports: {} };
|
|
163
213
|
const content = fs_extra_1.default.readFileSync(configPath, 'utf8');
|
|
@@ -213,7 +263,10 @@ const maybeAddFile = (files, seen, projectRoot, filePath, totalBytes) => {
|
|
|
213
263
|
return;
|
|
214
264
|
const bytes = stat.size;
|
|
215
265
|
const rawContent = fs_extra_1.default.readFileSync(filePath, 'utf8');
|
|
216
|
-
const
|
|
266
|
+
const summaryOnly = (0, exports.isSummaryOnlyAiContextFile)(relative);
|
|
267
|
+
if (!summaryOnly)
|
|
268
|
+
assertSafeAiSetupContent(relative, rawContent);
|
|
269
|
+
const content = summaryOnly
|
|
217
270
|
? summarizeContextContent(relative, rawContent, bytes)
|
|
218
271
|
: rawContent;
|
|
219
272
|
const contentBytes = Buffer.byteLength(content, 'utf8');
|
|
@@ -349,7 +402,7 @@ function scanProjectForAiNativeInit(startDir = process.cwd()) {
|
|
|
349
402
|
}
|
|
350
403
|
if (!(0, exports.isTrustedAiPlanningServer)(serverUrl)) {
|
|
351
404
|
throw new Error(`Refusing to send project files to untrusted AI planning server: ${serverUrl}. ` +
|
|
352
|
-
'Use
|
|
405
|
+
'Use the Bundle Drop production server, a local development server, or explicitly allow an untrusted server.');
|
|
353
406
|
}
|
|
354
407
|
const files = collectFiles(projectRoot);
|
|
355
408
|
const detected = detectSignals(files);
|
|
@@ -369,3 +422,197 @@ function scanProjectForAiNativeInit(startDir = process.cwd()) {
|
|
|
369
422
|
},
|
|
370
423
|
};
|
|
371
424
|
}
|
|
425
|
+
const SETUP_CONFIG_FILES = [
|
|
426
|
+
'bundle.drop.config.js',
|
|
427
|
+
'bundle.drop.config.cjs',
|
|
428
|
+
'app.json',
|
|
429
|
+
'app.config.js',
|
|
430
|
+
'app.config.ts',
|
|
431
|
+
'app.config.cjs',
|
|
432
|
+
'app.config.mjs',
|
|
433
|
+
'metro.config.js',
|
|
434
|
+
'metro.config.ts',
|
|
435
|
+
'metro.config.cjs',
|
|
436
|
+
'metro.config.mjs',
|
|
437
|
+
];
|
|
438
|
+
const setupFileKind = (relativePath) => {
|
|
439
|
+
if (relativePath === 'package.json')
|
|
440
|
+
return 'package_manifest';
|
|
441
|
+
if (relativePath.startsWith('bundle.drop.config.'))
|
|
442
|
+
return 'bundle_drop_config';
|
|
443
|
+
if (relativePath === 'app.json' || relativePath.startsWith('app.config.')) {
|
|
444
|
+
return 'expo_app_config';
|
|
445
|
+
}
|
|
446
|
+
if (relativePath.startsWith('metro.config.'))
|
|
447
|
+
return 'metro_config';
|
|
448
|
+
if (relativePath.includes('MainApplication.'))
|
|
449
|
+
return 'android_entrypoint';
|
|
450
|
+
return 'ios_entrypoint';
|
|
451
|
+
};
|
|
452
|
+
const readSetupFile = (projectRoot, relativePath) => {
|
|
453
|
+
const filePath = path_1.default.join(projectRoot, relativePath);
|
|
454
|
+
if (!fs_extra_1.default.existsSync(filePath))
|
|
455
|
+
return null;
|
|
456
|
+
const stat = fs_extra_1.default.lstatSync(filePath);
|
|
457
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_FILE_BYTES)
|
|
458
|
+
return null;
|
|
459
|
+
const rawContent = fs_extra_1.default.readFileSync(filePath, 'utf8');
|
|
460
|
+
const kind = setupFileKind(relativePath);
|
|
461
|
+
if (kind !== 'package_manifest' && kind !== 'bundle_drop_config') {
|
|
462
|
+
assertSafeAiSetupContent(relativePath, rawContent);
|
|
463
|
+
}
|
|
464
|
+
const content = kind === 'package_manifest' || kind === 'bundle_drop_config'
|
|
465
|
+
? summarizeContextContent(relativePath, rawContent, stat.size)
|
|
466
|
+
: rawContent;
|
|
467
|
+
return {
|
|
468
|
+
kind,
|
|
469
|
+
path: relativePath,
|
|
470
|
+
content,
|
|
471
|
+
sha256: sha256(content),
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
const collectSetupFiles = (projectRoot, projectType) => {
|
|
475
|
+
const relativePaths = ['package.json', ...SETUP_CONFIG_FILES];
|
|
476
|
+
if (projectType === 'bare') {
|
|
477
|
+
for (const srcDir of ['java', 'kotlin']) {
|
|
478
|
+
relativePaths.push(...findFilesByName(path_1.default.join(projectRoot, 'android', 'app', 'src', 'main', srcDir), new Set(['MainApplication.kt', 'MainApplication.java'])).map(filePath => toPosix(path_1.default.relative(projectRoot, filePath))));
|
|
479
|
+
}
|
|
480
|
+
relativePaths.push(...findFilesByName(path_1.default.join(projectRoot, 'ios'), new Set(['AppDelegate.swift', 'AppDelegate.mm', 'AppDelegate.m'])).map(filePath => toPosix(path_1.default.relative(projectRoot, filePath))));
|
|
481
|
+
}
|
|
482
|
+
const files = [];
|
|
483
|
+
let totalBytes = 0;
|
|
484
|
+
for (const relativePath of relativePaths) {
|
|
485
|
+
const file = readSetupFile(projectRoot, relativePath);
|
|
486
|
+
if (!file)
|
|
487
|
+
continue;
|
|
488
|
+
const bytes = Buffer.byteLength(file.content, 'utf8');
|
|
489
|
+
if (totalBytes + bytes > MAX_TOTAL_BYTES)
|
|
490
|
+
continue;
|
|
491
|
+
totalBytes += bytes;
|
|
492
|
+
files.push(file);
|
|
493
|
+
}
|
|
494
|
+
return files;
|
|
495
|
+
};
|
|
496
|
+
const readPackageSignals = (projectRoot) => {
|
|
497
|
+
const packagePath = path_1.default.join(projectRoot, 'package.json');
|
|
498
|
+
const pkg = fs_extra_1.default.existsSync(packagePath) ? readJsonFile(packagePath) : {};
|
|
499
|
+
const dependencies = {
|
|
500
|
+
...(pkg.dependencies || {}),
|
|
501
|
+
...(pkg.devDependencies || {}),
|
|
502
|
+
...(pkg.peerDependencies || {}),
|
|
503
|
+
};
|
|
504
|
+
return { pkg, dependencies };
|
|
505
|
+
};
|
|
506
|
+
const resolveInstalledPackageVersion = (projectRoot, packageName) => {
|
|
507
|
+
try {
|
|
508
|
+
const projectRequire = (0, module_1.createRequire)(path_1.default.join(projectRoot, 'package.json'));
|
|
509
|
+
const manifest = readJsonFile(projectRequire.resolve(`${packageName}/package.json`));
|
|
510
|
+
return typeof manifest.version === 'string' ? manifest.version : null;
|
|
511
|
+
}
|
|
512
|
+
catch {
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
const detectSetupSignals = (projectRoot, projectType, files) => {
|
|
517
|
+
const { pkg, dependencies } = readPackageSignals(projectRoot);
|
|
518
|
+
const content = files.map(file => file.content).join('\n');
|
|
519
|
+
const expoVersion = dependencies.expo || null;
|
|
520
|
+
const hasBundleDropDependency = Boolean(dependencies['@gfean/react-native-bundle-drop'] || dependencies['react-native-bundle-drop']);
|
|
521
|
+
const hasBundleDropConfig = files.some(file => file.kind === 'bundle_drop_config');
|
|
522
|
+
const hasBundleDropIntegration = content.includes('@gfean/react-native-bundle-drop') ||
|
|
523
|
+
content.includes('bundle-drop-config') ||
|
|
524
|
+
hasBundleDropResolverCall(content);
|
|
525
|
+
const evaluatedExpoConfig = projectType === 'expo'
|
|
526
|
+
? (0, expo_1.evaluateExpoConfig)(projectRoot).exp
|
|
527
|
+
: {};
|
|
528
|
+
const expoUpdatesOwnership = (0, expo_1.inspectExpoUpdatesOwnership)(projectRoot, evaluatedExpoConfig);
|
|
529
|
+
const configuredEngine = /(?:["']jsEngine["']|\bjsEngine)\s*:\s*["']jsc["']/.test(content)
|
|
530
|
+
? 'jsc'
|
|
531
|
+
: /(?:["']jsEngine["']|\bjsEngine)\s*:\s*["']hermes["']/.test(content)
|
|
532
|
+
? 'hermes'
|
|
533
|
+
: 'unknown';
|
|
534
|
+
const signals = [
|
|
535
|
+
projectType === 'expo' ? 'expoProject' : 'bareProject',
|
|
536
|
+
fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'ios')) ? 'iosDirectory' : '',
|
|
537
|
+
fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'android')) ? 'androidDirectory' : '',
|
|
538
|
+
expoUpdatesOwnership.packageIsInstalled || expoUpdatesOwnership.packageIsDeclared
|
|
539
|
+
? 'expoUpdatesDependency'
|
|
540
|
+
: '',
|
|
541
|
+
dependencies['react-native-code-push'] ? 'codePushDependency' : '',
|
|
542
|
+
pkg.main === 'expo-router/entry' || dependencies['expo-router'] ? 'expoRouter' : '',
|
|
543
|
+
].filter(Boolean);
|
|
544
|
+
const detected = {
|
|
545
|
+
rnVersion: resolveInstalledPackageVersion(projectRoot, 'react-native') ||
|
|
546
|
+
dependencies['react-native'] || null,
|
|
547
|
+
expoSdkVersion: projectType === 'expo'
|
|
548
|
+
? resolveInstalledPackageVersion(projectRoot, 'expo') || expoVersion
|
|
549
|
+
: null,
|
|
550
|
+
bundleDropStatus: hasBundleDropDependency && hasBundleDropConfig && hasBundleDropIntegration
|
|
551
|
+
? 'configured'
|
|
552
|
+
: hasBundleDropDependency || hasBundleDropConfig || hasBundleDropIntegration
|
|
553
|
+
? 'partial'
|
|
554
|
+
: 'absent',
|
|
555
|
+
hasNativeDirectories: fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'ios')) ||
|
|
556
|
+
fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'android')),
|
|
557
|
+
usesExpoRouter: Boolean(pkg.main === 'expo-router/entry' || dependencies['expo-router']),
|
|
558
|
+
jsEngine: configuredEngine,
|
|
559
|
+
expoUpdatesStatus: expoUpdatesOwnership.state,
|
|
560
|
+
codePushDetected: Boolean(dependencies['react-native-code-push'] || /\bCodePush\b|codepush\.gradle/.test(content)),
|
|
561
|
+
signals,
|
|
562
|
+
};
|
|
563
|
+
if (projectType === 'expo') {
|
|
564
|
+
const exp = evaluatedExpoConfig;
|
|
565
|
+
const iosEngine = exp.ios?.jsEngine ?? exp.jsEngine ?? 'hermes';
|
|
566
|
+
const androidEngine = exp.android?.jsEngine ?? exp.jsEngine ?? 'hermes';
|
|
567
|
+
detected.jsEngine = iosEngine === androidEngine && ['hermes', 'jsc'].includes(iosEngine)
|
|
568
|
+
? iosEngine
|
|
569
|
+
: 'unknown';
|
|
570
|
+
}
|
|
571
|
+
return detected;
|
|
572
|
+
};
|
|
573
|
+
function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualConfig) {
|
|
574
|
+
const projectRoot = findProjectRoot(startDir);
|
|
575
|
+
const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
|
|
576
|
+
if (!fs_extra_1.default.existsSync(configPath) && !virtualConfig) {
|
|
577
|
+
throw new Error('bundle.drop.config.js not found; run `bundle-drop init` first.');
|
|
578
|
+
}
|
|
579
|
+
const config = virtualConfig ? null : loadBundleDropConfig(configPath);
|
|
580
|
+
const serverUrl = virtualConfig
|
|
581
|
+
? normalizeServerUrl(virtualConfig.serverUrl)
|
|
582
|
+
: typeof config?.serverUrl === 'string' ? normalizeServerUrl(config.serverUrl) : '';
|
|
583
|
+
const orgSlug = virtualConfig?.orgSlug ||
|
|
584
|
+
(typeof config?.org?.slug === 'string' ? config.org.slug.trim() : '');
|
|
585
|
+
const projectSlug = virtualConfig?.projectSlug ||
|
|
586
|
+
(typeof config?.project?.slug === 'string' ? config.project.slug.trim() : '');
|
|
587
|
+
if (!serverUrl || !orgSlug || !projectSlug) {
|
|
588
|
+
throw new Error('Missing "serverUrl", "org.slug" or "project.slug" in bundle.drop.config.js.');
|
|
589
|
+
}
|
|
590
|
+
if (!(0, exports.isTrustedAiPlanningServer)(serverUrl)) {
|
|
591
|
+
throw new Error(`Refusing to send project files to untrusted AI planning server: ${serverUrl}.`);
|
|
592
|
+
}
|
|
593
|
+
const files = collectSetupFiles(projectRoot, projectType);
|
|
594
|
+
if (virtualConfig && !files.some(file => file.kind === 'bundle_drop_config')) {
|
|
595
|
+
const summarizedConfig = summarizeContextContent('bundle.drop.config.js', virtualConfig.content, Buffer.byteLength(virtualConfig.content, 'utf8'));
|
|
596
|
+
files.push({
|
|
597
|
+
kind: 'bundle_drop_config',
|
|
598
|
+
path: 'bundle.drop.config.js',
|
|
599
|
+
content: summarizedConfig,
|
|
600
|
+
sha256: sha256(summarizedConfig),
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
projectRoot,
|
|
605
|
+
serverUrl,
|
|
606
|
+
orgSlug,
|
|
607
|
+
projectSlug,
|
|
608
|
+
authToken: virtualConfig?.authToken || readAuthToken(),
|
|
609
|
+
request: {
|
|
610
|
+
schemaVersion: 1,
|
|
611
|
+
orgSlug,
|
|
612
|
+
projectSlug,
|
|
613
|
+
projectType,
|
|
614
|
+
detected: detectSetupSignals(projectRoot, projectType, files),
|
|
615
|
+
files,
|
|
616
|
+
},
|
|
617
|
+
};
|
|
618
|
+
}
|
|
@@ -51,3 +51,42 @@ export type AiScannerResult = {
|
|
|
51
51
|
authToken: string;
|
|
52
52
|
request: AiInitPlanRequest;
|
|
53
53
|
};
|
|
54
|
+
export type AiSetupProjectType = 'expo' | 'bare';
|
|
55
|
+
export type AiSetupFileKind = 'package_manifest' | 'bundle_drop_config' | 'expo_app_config' | 'metro_config' | 'android_entrypoint' | 'ios_entrypoint';
|
|
56
|
+
export type AiSetupDetected = {
|
|
57
|
+
rnVersion: string | null;
|
|
58
|
+
expoSdkVersion: string | null;
|
|
59
|
+
bundleDropStatus: 'absent' | 'partial' | 'configured';
|
|
60
|
+
hasNativeDirectories: boolean;
|
|
61
|
+
usesExpoRouter: boolean;
|
|
62
|
+
jsEngine: 'hermes' | 'jsc' | 'unknown';
|
|
63
|
+
expoUpdatesStatus: 'absent' | 'disabled' | 'active';
|
|
64
|
+
codePushDetected: boolean;
|
|
65
|
+
signals: string[];
|
|
66
|
+
};
|
|
67
|
+
export type AiSetupPlanFile = AiInitPlanFile & {
|
|
68
|
+
kind: AiSetupFileKind;
|
|
69
|
+
};
|
|
70
|
+
export type AiSetupPlanRequest = {
|
|
71
|
+
schemaVersion: 1;
|
|
72
|
+
orgSlug: string;
|
|
73
|
+
projectSlug: string;
|
|
74
|
+
projectType: AiSetupProjectType;
|
|
75
|
+
detected: AiSetupDetected;
|
|
76
|
+
files: AiSetupPlanFile[];
|
|
77
|
+
};
|
|
78
|
+
export type AiSetupActionType = 'register_expo_plugin' | 'configure_bundle_drop' | 'preserve_expo_metro' | 'migrate_expo_updates' | 'configure_bare_native' | 'migrate_codepush' | 'require_native_rebuild' | 'run_doctor';
|
|
79
|
+
export type AiSetupPlanResponse = {
|
|
80
|
+
confidence: AiInitConfidence;
|
|
81
|
+
summary: string;
|
|
82
|
+
actions: Array<{
|
|
83
|
+
type: AiSetupActionType;
|
|
84
|
+
reason: string;
|
|
85
|
+
requiresConfirmation: boolean;
|
|
86
|
+
}>;
|
|
87
|
+
changes: AiPatchPlan[];
|
|
88
|
+
warnings: string[];
|
|
89
|
+
};
|
|
90
|
+
export type AiSetupScannerResult = Omit<AiScannerResult, 'request'> & {
|
|
91
|
+
request: AiSetupPlanRequest;
|
|
92
|
+
};
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { AiPatchPlan } from './types';
|
|
2
|
+
import { AiSetupProjectType } from './types';
|
|
2
3
|
export declare const isSafeRelativePath: (value: string) => boolean;
|
|
3
4
|
export declare const isPatchableNativeEntrypoint: (filePath: string) => boolean;
|
|
5
|
+
export declare const isPatchableExpoConfig: (filePath: string) => boolean;
|
|
4
6
|
export declare function validateChangesBeforeApply(params: {
|
|
5
7
|
originals: Map<string, string>;
|
|
6
8
|
changes: AiPatchPlan[];
|
|
7
9
|
}): void;
|
|
8
10
|
export declare function validateAppliedChanges(projectRoot: string, changes: AiPatchPlan[]): void;
|
|
11
|
+
export declare function validateSetupChangesBeforeApply(params: {
|
|
12
|
+
projectType: AiSetupProjectType;
|
|
13
|
+
originals: Map<string, string>;
|
|
14
|
+
changes: AiPatchPlan[];
|
|
15
|
+
}): void;
|
|
16
|
+
export declare function validateAppliedSetupChanges(params: {
|
|
17
|
+
projectRoot: string;
|
|
18
|
+
projectType: AiSetupProjectType;
|
|
19
|
+
changes: AiPatchPlan[];
|
|
20
|
+
}): void;
|
|
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isPatchableNativeEntrypoint = exports.isSafeRelativePath = void 0;
|
|
6
|
+
exports.isPatchableExpoConfig = exports.isPatchableNativeEntrypoint = exports.isSafeRelativePath = void 0;
|
|
7
7
|
exports.validateChangesBeforeApply = validateChangesBeforeApply;
|
|
8
8
|
exports.validateAppliedChanges = validateAppliedChanges;
|
|
9
|
+
exports.validateSetupChangesBeforeApply = validateSetupChangesBeforeApply;
|
|
10
|
+
exports.validateAppliedSetupChanges = validateAppliedSetupChanges;
|
|
9
11
|
const crypto_1 = __importDefault(require("crypto"));
|
|
10
12
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
13
|
const path_1 = __importDefault(require("path"));
|
|
@@ -20,6 +22,10 @@ exports.isSafeRelativePath = isSafeRelativePath;
|
|
|
20
22
|
const isPatchableNativeEntrypoint = (filePath) => /(^|\/)android\/(?:.*\/)?MainApplication\.(kt|java)$/.test(filePath) ||
|
|
21
23
|
/(^|\/)ios\/(?:.*\/)?AppDelegate\.(swift|m|mm)$/.test(filePath);
|
|
22
24
|
exports.isPatchableNativeEntrypoint = isPatchableNativeEntrypoint;
|
|
25
|
+
const isPatchableExpoConfig = (filePath) => filePath === 'app.json' ||
|
|
26
|
+
/^app\.config\.(js|ts|cjs|mjs)$/.test(filePath) ||
|
|
27
|
+
/^metro\.config\.(js|ts|cjs|mjs)$/.test(filePath);
|
|
28
|
+
exports.isPatchableExpoConfig = isPatchableExpoConfig;
|
|
23
29
|
const codeLikeContent = (content) => {
|
|
24
30
|
let result = '';
|
|
25
31
|
let state = 'code';
|
|
@@ -162,3 +168,72 @@ function validateAppliedChanges(projectRoot, changes) {
|
|
|
162
168
|
}
|
|
163
169
|
}
|
|
164
170
|
}
|
|
171
|
+
const validateCommonSetupChange = (change, originals, seen) => {
|
|
172
|
+
if (!(0, exports.isSafeRelativePath)(change.file)) {
|
|
173
|
+
throw new Error(`AI setup plan references an unsafe file path: ${change.file}`);
|
|
174
|
+
}
|
|
175
|
+
if (!originals.has(change.file)) {
|
|
176
|
+
throw new Error(`AI setup plan references a file that was not shared: ${change.file}`);
|
|
177
|
+
}
|
|
178
|
+
if (seen.has(change.file)) {
|
|
179
|
+
throw new Error(`AI setup plan contains multiple updates for ${change.file}`);
|
|
180
|
+
}
|
|
181
|
+
seen.add(change.file);
|
|
182
|
+
if (sha256(originals.get(change.file) || '') !== change.originalSha256) {
|
|
183
|
+
throw new Error(`AI setup plan hash mismatch for ${change.file}`);
|
|
184
|
+
}
|
|
185
|
+
if (!change.updated.trim()) {
|
|
186
|
+
throw new Error(`AI setup plan returned an empty update for ${change.file}`);
|
|
187
|
+
}
|
|
188
|
+
if (change.updated.includes('TODO_BUNDLEDROP') || change.updated.includes('<TODO')) {
|
|
189
|
+
throw new Error(`AI setup plan returned placeholder text in ${change.file}`);
|
|
190
|
+
}
|
|
191
|
+
if (!hasBalancedPairs(change.updated)) {
|
|
192
|
+
throw new Error(`AI setup plan returned unbalanced braces or brackets in ${change.file}`);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
function validateSetupChangesBeforeApply(params) {
|
|
196
|
+
const seen = new Set();
|
|
197
|
+
for (const change of params.changes) {
|
|
198
|
+
validateCommonSetupChange(change, params.originals, seen);
|
|
199
|
+
if (params.projectType === 'expo') {
|
|
200
|
+
if (!(0, exports.isPatchableExpoConfig)(change.file)) {
|
|
201
|
+
throw new Error(`AI Expo setup may not modify ${change.file}`);
|
|
202
|
+
}
|
|
203
|
+
if (change.file.startsWith('metro.config.') &&
|
|
204
|
+
!change.updated.includes('bundle-drop-config') &&
|
|
205
|
+
!change.updated.includes('withBundleDropExpo')) {
|
|
206
|
+
throw new Error(`AI Expo Metro update is missing the Bundle Drop wrapper: ${change.file}`);
|
|
207
|
+
}
|
|
208
|
+
if ((change.file === 'app.json' || change.file.startsWith('app.config.')) &&
|
|
209
|
+
!change.updated.includes('@gfean/react-native-bundle-drop')) {
|
|
210
|
+
throw new Error(`AI Expo config update is missing the Bundle Drop plugin: ${change.file}`);
|
|
211
|
+
}
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (!(0, exports.isPatchableNativeEntrypoint)(change.file)) {
|
|
215
|
+
throw new Error(`AI bare setup may not modify ${change.file}`);
|
|
216
|
+
}
|
|
217
|
+
if (change.file.includes('MainApplication.') && !hasAndroidBundleDropIntegration(change.updated)) {
|
|
218
|
+
throw new Error(`AI plan Android update does not contain BundleDrop resolver: ${change.file}`);
|
|
219
|
+
}
|
|
220
|
+
if (change.file.includes('AppDelegate.') && !hasIosBundleDropIntegration(change.updated)) {
|
|
221
|
+
throw new Error(`AI plan iOS update does not contain BundleDrop locator: ${change.file}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function validateAppliedSetupChanges(params) {
|
|
226
|
+
const originals = new Map(params.changes.map(change => [
|
|
227
|
+
change.file,
|
|
228
|
+
fs_extra_1.default.readFileSync(path_1.default.join(params.projectRoot, change.file), 'utf8'),
|
|
229
|
+
]));
|
|
230
|
+
validateSetupChangesBeforeApply({
|
|
231
|
+
projectType: params.projectType,
|
|
232
|
+
originals,
|
|
233
|
+
changes: params.changes.map(change => ({
|
|
234
|
+
...change,
|
|
235
|
+
originalSha256: sha256(originals.get(change.file) || ''),
|
|
236
|
+
updated: originals.get(change.file) || '',
|
|
237
|
+
})),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MobilePlatform, ProjectType } from '../../expo';
|
|
2
|
+
export type DoctorCheck = {
|
|
3
|
+
name: string;
|
|
4
|
+
status: 'pass' | 'warning' | 'error';
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
export type DoctorOptions = {
|
|
8
|
+
platform?: MobilePlatform;
|
|
9
|
+
projectType?: ProjectType;
|
|
10
|
+
cwd?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function inspectProject(options?: DoctorOptions): Promise<{
|
|
13
|
+
projectRoot: string;
|
|
14
|
+
projectType: ProjectType;
|
|
15
|
+
checks: DoctorCheck[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare function runDoctor(options?: DoctorOptions): Promise<void>;
|