@gfean/react-native-bundle-drop 0.5.1 → 0.7.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.
Files changed (127) hide show
  1. package/BundleDrop.podspec +96 -0
  2. package/README.md +194 -5
  3. package/android/build.gradle +66 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +206 -13
  6. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
  7. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
  8. package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
  9. package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
  10. package/ios/BundleDropBridge.m +45 -0
  11. package/ios/BundleDropLocator.swift +66 -4
  12. package/ios/BundleDropModule.swift +181 -3
  13. package/ios/BundleDropOtaResolver.swift +137 -29
  14. package/ios/BundleDropRuntimeCrypto.swift +45 -0
  15. package/ios/BundleDropStartupRecovery.swift +1108 -0
  16. package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
  17. package/lib/CLI/cli.d.ts +1 -0
  18. package/lib/CLI/cli.js +57 -6
  19. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
  20. package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
  21. package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
  22. package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
  23. package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
  24. package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
  25. package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
  26. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
  27. package/lib/CLI/scripts/aipowered/init-project-config.js +221 -45
  28. package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
  29. package/lib/CLI/scripts/aipowered/scanner.js +164 -32
  30. package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
  31. package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
  32. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
  33. package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
  34. package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
  35. package/lib/CLI/scripts/bare-metro-config.js +24 -32
  36. package/lib/CLI/scripts/doctor.js +162 -22
  37. package/lib/CLI/scripts/expo/configure-expo.js +52 -60
  38. package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
  39. package/lib/CLI/scripts/expo/package-manager.js +63 -25
  40. package/lib/CLI/scripts/init-config.d.ts +7 -7
  41. package/lib/CLI/scripts/init-config.js +198 -14
  42. package/lib/CLI/scripts/login-cli.js +31 -7
  43. package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
  44. package/lib/CLI/scripts/metro-config-authority.js +303 -0
  45. package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
  46. package/lib/CLI/scripts/native/write-runtime-identity.js +92 -0
  47. package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
  48. package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
  49. package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
  50. package/lib/CLI/scripts/native-setup-contract.js +63 -33
  51. package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
  52. package/lib/CLI/scripts/native-startup-validator.js +964 -0
  53. package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
  54. package/lib/CLI/scripts/safe-file-transaction.js +159 -0
  55. package/lib/CLI/scripts/upload-cli.d.ts +12 -2
  56. package/lib/CLI/scripts/upload-cli.js +74 -11
  57. package/lib/CLI/serverUrl.d.ts +3 -0
  58. package/lib/CLI/serverUrl.js +31 -0
  59. package/lib/api/clientApi.d.ts +3 -1
  60. package/lib/api/clientApi.js +14 -0
  61. package/lib/api/types.d.ts +39 -0
  62. package/lib/bundleInfo.d.ts +2 -0
  63. package/lib/bundleInfo.js +16 -1
  64. package/lib/context.d.ts +1 -1
  65. package/lib/context.js +12 -2
  66. package/lib/fs/bundlePointer.d.ts +1 -17
  67. package/lib/fs/bundlePointer.js +5 -93
  68. package/lib/index.d.ts +2 -0
  69. package/lib/index.js +3 -1
  70. package/lib/install/bundleInstallShared.js +4 -4
  71. package/lib/install/installFromZip.d.ts +3 -0
  72. package/lib/install/installFromZip.js +10 -1
  73. package/lib/loadConfig.d.ts +17 -1
  74. package/lib/loadConfig.js +16 -0
  75. package/lib/manager/downloadAndInstall.d.ts +3 -2
  76. package/lib/manager/downloadAndInstall.js +134 -66
  77. package/lib/manager/reporting.d.ts +8 -1
  78. package/lib/manager/reporting.js +17 -22
  79. package/lib/manager/rollbackState.d.ts +18 -52
  80. package/lib/manager/rollbackState.js +115 -216
  81. package/lib/manager/updateCheck.d.ts +1 -0
  82. package/lib/manager/updateCheck.js +224 -78
  83. package/lib/manager/updateState.d.ts +2 -1
  84. package/lib/manager/updateState.js +59 -6
  85. package/lib/metro.d.ts +8 -1
  86. package/lib/metro.js +69 -19
  87. package/lib/native/bundleDropNative.d.ts +62 -0
  88. package/lib/native/bundleDropNative.js +268 -2
  89. package/lib/native/fs.d.ts +6 -0
  90. package/lib/native/fs.js +24 -0
  91. package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
  92. package/lib/patch-engine/installFromPatchSet.js +16 -5
  93. package/lib/patch-engine/patchTransport.d.ts +2 -0
  94. package/lib/patch-engine/patchTransport.js +9 -0
  95. package/lib/runtime/initState.d.ts +5 -0
  96. package/lib/runtime/initState.js +4 -0
  97. package/lib/runtime/service.js +82 -67
  98. package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
  99. package/lib/runtime-delivery/artifactCapability.js +32 -0
  100. package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
  101. package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
  102. package/lib/runtime-delivery/bootstrapConfig.d.ts +68 -0
  103. package/lib/runtime-delivery/bootstrapConfig.js +278 -0
  104. package/lib/runtime-delivery/diagnostics.d.ts +17 -0
  105. package/lib/runtime-delivery/diagnostics.js +58 -0
  106. package/lib/runtime-delivery/encoding.d.ts +5 -0
  107. package/lib/runtime-delivery/encoding.js +132 -0
  108. package/lib/runtime-delivery/heartbeat.d.ts +3 -0
  109. package/lib/runtime-delivery/heartbeat.js +88 -0
  110. package/lib/runtime-delivery/localResolver.d.ts +23 -0
  111. package/lib/runtime-delivery/localResolver.js +81 -0
  112. package/lib/runtime-delivery/manifestState.d.ts +11 -0
  113. package/lib/runtime-delivery/manifestState.js +123 -0
  114. package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
  115. package/lib/runtime-delivery/manifestVerifier.js +335 -0
  116. package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
  117. package/lib/runtime-delivery/runtimeDelivery.js +375 -0
  118. package/lib/runtime-delivery/types.d.ts +87 -0
  119. package/lib/runtime-delivery/types.js +6 -0
  120. package/lib/scripts/bundle.d.ts +9 -2
  121. package/lib/scripts/bundle.js +68 -18
  122. package/lib/scripts/download-bundle.d.ts +1 -0
  123. package/lib/scripts/download-bundle.js +2 -2
  124. package/lib/scripts/resolveModule.d.ts +2 -0
  125. package/lib/scripts/resolveModule.js +5 -0
  126. package/package.json +5 -2
  127. package/plugin/xcodeBuildPhase.js +2 -1
@@ -0,0 +1,378 @@
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.findNativeEntrypointAuthorityIssue = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const safe_file_transaction_1 = require("./safe-file-transaction");
10
+ const native_setup_contract_1 = require("./native-setup-contract");
11
+ const toPosix = (filePath) => filePath.split(path_1.default.sep).join('/');
12
+ const maskXmlComments = (source) => {
13
+ let masked = '';
14
+ let cursor = 0;
15
+ while (cursor < source.length) {
16
+ const commentStart = source.indexOf('<!--', cursor);
17
+ if (commentStart < 0)
18
+ return masked + source.slice(cursor);
19
+ masked += source.slice(cursor, commentStart);
20
+ const commentEnd = source.indexOf('-->', commentStart + 4);
21
+ const maskedEnd = commentEnd < 0 ? source.length : commentEnd + 3;
22
+ masked += ' '.repeat(maskedEnd - commentStart);
23
+ cursor = maskedEnd;
24
+ }
25
+ return masked;
26
+ };
27
+ const androidPackageFromPath = (relativePath) => {
28
+ const match = relativePath.match(/^android\/app\/src\/main\/(?:java|kotlin)\/(.+)\/MainApplication\.(?:java|kt)$/);
29
+ return match ? match[1].split('/').join('.') : '';
30
+ };
31
+ const androidEntrypointClass = (relativePath, content) => {
32
+ const declaredPackage = content.match(/(?:^|\n)\s*package\s+([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\s*;?/)?.[1];
33
+ const packageName = declaredPackage || androidPackageFromPath(relativePath);
34
+ return packageName ? `${packageName}.MainApplication` : 'MainApplication';
35
+ };
36
+ const androidManifestFiles = (projectRoot) => {
37
+ const sourceRoot = path_1.default.join(projectRoot, 'android/app/src');
38
+ let sourceSets;
39
+ try {
40
+ const stat = fs_1.default.lstatSync(sourceRoot);
41
+ if (stat.isSymbolicLink() || !stat.isDirectory()) {
42
+ throw new Error('Android source-set root is not a regular project directory.');
43
+ }
44
+ sourceSets = fs_1.default.readdirSync(sourceRoot);
45
+ }
46
+ catch (error) {
47
+ if (error.code === 'ENOENT')
48
+ return [];
49
+ throw error;
50
+ }
51
+ return sourceSets.flatMap(sourceSet => {
52
+ if (/^(?:androidTest|benchmark|test|testFixtures|unitTest)$/i.test(sourceSet))
53
+ return [];
54
+ const relativeDirectory = `android/app/src/${sourceSet}`;
55
+ const directoryStat = fs_1.default.lstatSync(path_1.default.join(projectRoot, relativeDirectory));
56
+ if (directoryStat.isSymbolicLink()) {
57
+ throw new Error(`Android source-set path is a symbolic link: ${relativeDirectory}`);
58
+ }
59
+ if (!directoryStat.isDirectory())
60
+ return [];
61
+ const relativeManifest = `${relativeDirectory}/AndroidManifest.xml`;
62
+ return (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, relativeManifest).exists ? [relativeManifest] : [];
63
+ }).sort();
64
+ };
65
+ const androidGradleNamespace = (projectRoot) => {
66
+ for (const file of ['android/app/build.gradle', 'android/app/build.gradle.kts']) {
67
+ const buildFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, file);
68
+ if (!buildFile.exists)
69
+ continue;
70
+ const namespace = buildFile.content.match(/(?:^|\n)\s*namespace\s*(?:=\s*)?["']([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)["']/)?.[1];
71
+ if (namespace)
72
+ return namespace;
73
+ }
74
+ return '';
75
+ };
76
+ const androidAuthorityIssue = (projectRoot, entrypoint) => {
77
+ const entrypointFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, entrypoint);
78
+ if (!entrypointFile.exists)
79
+ return `Android application entrypoint is missing: ${entrypoint}`;
80
+ const entrypointClass = androidEntrypointClass(entrypoint, entrypointFile.content);
81
+ const manifests = androidManifestFiles(projectRoot);
82
+ const mainManifest = 'android/app/src/main/AndroidManifest.xml';
83
+ if (!manifests.includes(mainManifest)) {
84
+ return 'The main AndroidManifest.xml is missing; application startup authority is unknown.';
85
+ }
86
+ const gradleNamespace = androidGradleNamespace(projectRoot);
87
+ for (const manifestPath of manifests) {
88
+ const manifest = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, manifestPath);
89
+ const manifestSource = maskXmlComments(manifest.content);
90
+ const applicationTags = [...manifestSource.matchAll(/<application\b[^>]*>/gi)];
91
+ if (applicationTags.length > 1) {
92
+ return `${manifestPath} has multiple application declarations.`;
93
+ }
94
+ const applicationTag = applicationTags[0]?.[0];
95
+ if (!applicationTag) {
96
+ if (manifestPath === mainManifest) {
97
+ return `${manifestPath} has no application declaration to bind the native entrypoint.`;
98
+ }
99
+ continue;
100
+ }
101
+ const applicationNames = [...applicationTag.matchAll(/(?:^|\s)android:name\s*=\s*["']([^"']+)["']/gi)].map(match => match[1].trim());
102
+ if (applicationNames.length > 1) {
103
+ return `${manifestPath} has multiple android:name application authorities.`;
104
+ }
105
+ if (!applicationNames.length) {
106
+ if (manifestPath === mainManifest) {
107
+ return `${manifestPath} does not explicitly name the application class.`;
108
+ }
109
+ continue;
110
+ }
111
+ const applicationName = applicationNames[0];
112
+ if (/\$\{|[^A-Za-z0-9_.$]/.test(applicationName)) {
113
+ return `${manifestPath} application class is not statically resolvable: ${applicationName}`;
114
+ }
115
+ const manifestPackage = manifestSource.match(/<manifest\b[^>]*\s+package\s*=\s*["']([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)["']/i)?.[1] || '';
116
+ const namespace = manifestPackage || gradleNamespace;
117
+ if ((!applicationName.includes('.') || applicationName.startsWith('.')) && !namespace) {
118
+ return `${manifestPath} uses a relative application class without a manifest package or Gradle namespace.`;
119
+ }
120
+ const expectedClass = applicationName.startsWith('.')
121
+ ? `${namespace}${applicationName}`
122
+ : applicationName.includes('.')
123
+ ? applicationName
124
+ : `${namespace}.${applicationName}`;
125
+ if (expectedClass !== entrypointClass) {
126
+ return `${manifestPath} starts ${expectedClass}, not ${entrypointClass}.`;
127
+ }
128
+ }
129
+ return null;
130
+ };
131
+ const findIosAuthoritySources = (projectRoot) => {
132
+ const iosRoot = path_1.default.join(projectRoot, 'ios');
133
+ try {
134
+ const rootStat = fs_1.default.lstatSync(iosRoot);
135
+ if (rootStat.isSymbolicLink() || !rootStat.isDirectory()) {
136
+ throw new Error('iOS source root is not a regular project directory.');
137
+ }
138
+ }
139
+ catch (error) {
140
+ if (error.code === 'ENOENT') {
141
+ return { mainFiles: [], swiftFiles: [] };
142
+ }
143
+ throw error;
144
+ }
145
+ const pending = ['ios'];
146
+ const mainFiles = [];
147
+ const swiftFiles = [];
148
+ let visited = 0;
149
+ while (pending.length) {
150
+ const relativeDirectory = pending.pop();
151
+ for (const entry of fs_1.default.readdirSync(path_1.default.join(projectRoot, relativeDirectory), { withFileTypes: true })) {
152
+ visited += 1;
153
+ if (visited > 5000)
154
+ throw new Error('iOS principal source scan exceeded 5000 entries.');
155
+ if (entry.name === 'Pods' || entry.name === 'build' || entry.name === 'DerivedData')
156
+ continue;
157
+ const relativePath = toPosix(path_1.default.join(relativeDirectory, entry.name));
158
+ const stat = fs_1.default.lstatSync(path_1.default.join(projectRoot, relativePath));
159
+ if (stat.isSymbolicLink()) {
160
+ throw new Error(`iOS principal source path is a symbolic link: ${relativePath}`);
161
+ }
162
+ if (stat.isDirectory())
163
+ pending.push(relativePath);
164
+ else if (stat.isFile()) {
165
+ if (/\.swift$/i.test(entry.name))
166
+ swiftFiles.push(relativePath);
167
+ if (/^main\.(?:m|mm|swift)$/i.test(entry.name))
168
+ mainFiles.push(relativePath);
169
+ }
170
+ }
171
+ }
172
+ return { mainFiles: mainFiles.sort(), swiftFiles: swiftFiles.sort() };
173
+ };
174
+ const findBalancedCall = (source, name) => {
175
+ const calls = [];
176
+ let searchFrom = 0;
177
+ while (searchFrom < source.length) {
178
+ const nameIndex = source.indexOf(name, searchFrom);
179
+ if (nameIndex < 0)
180
+ break;
181
+ const previousCharacter = source[nameIndex - 1] || '';
182
+ const nextCharacter = source[nameIndex + name.length] || '';
183
+ if (/\w/.test(previousCharacter) || /\w/.test(nextCharacter)) {
184
+ searchFrom = nameIndex + name.length;
185
+ continue;
186
+ }
187
+ const opening = source.indexOf('(', nameIndex + name.length);
188
+ if (opening < 0)
189
+ break;
190
+ let depth = 0;
191
+ let quote = '';
192
+ let escaped = false;
193
+ for (let index = opening; index < source.length; index += 1) {
194
+ const character = source[index];
195
+ if (quote) {
196
+ if (escaped)
197
+ escaped = false;
198
+ else if (character === '\\')
199
+ escaped = true;
200
+ else if (character === quote)
201
+ quote = '';
202
+ continue;
203
+ }
204
+ if (character === '"' || character === "'") {
205
+ quote = character;
206
+ continue;
207
+ }
208
+ if (character === '(')
209
+ depth += 1;
210
+ if (character === ')')
211
+ depth -= 1;
212
+ if (depth === 0) {
213
+ calls.push(source.slice(opening + 1, index));
214
+ searchFrom = index + 1;
215
+ break;
216
+ }
217
+ }
218
+ if (depth !== 0)
219
+ break;
220
+ }
221
+ return calls;
222
+ };
223
+ const stripCComments = (source) => {
224
+ let output = '';
225
+ let quote = '';
226
+ let escaped = false;
227
+ let blockCommentDepth = 0;
228
+ for (let index = 0; index < source.length; index += 1) {
229
+ const character = source[index];
230
+ const next = source[index + 1];
231
+ if (quote) {
232
+ output += character;
233
+ if (escaped)
234
+ escaped = false;
235
+ else if (character === '\\')
236
+ escaped = true;
237
+ else if (character === quote)
238
+ quote = '';
239
+ continue;
240
+ }
241
+ if (character === '"' || character === "'") {
242
+ quote = character;
243
+ output += character;
244
+ continue;
245
+ }
246
+ if (character === '/' && next === '/') {
247
+ while (index < source.length && source[index] !== '\n')
248
+ index += 1;
249
+ output += '\n';
250
+ continue;
251
+ }
252
+ if (character === '/' && next === '*') {
253
+ blockCommentDepth = 1;
254
+ index += 2;
255
+ while (index < source.length && blockCommentDepth > 0) {
256
+ if (source[index] === '/' && source[index + 1] === '*') {
257
+ blockCommentDepth += 1;
258
+ index += 2;
259
+ continue;
260
+ }
261
+ if (source[index] === '*' && source[index + 1] === '/') {
262
+ blockCommentDepth -= 1;
263
+ index += 2;
264
+ continue;
265
+ }
266
+ if (source[index] === '\n')
267
+ output += '\n';
268
+ index += 1;
269
+ }
270
+ index -= 1;
271
+ continue;
272
+ }
273
+ output += character;
274
+ }
275
+ return output;
276
+ };
277
+ const topLevelCallArguments = (body) => {
278
+ const argumentsList = [];
279
+ const stack = [];
280
+ let quote = '';
281
+ let escaped = false;
282
+ let start = 0;
283
+ for (let index = 0; index < body.length; index += 1) {
284
+ const character = body[index];
285
+ if (quote) {
286
+ if (escaped)
287
+ escaped = false;
288
+ else if (character === '\\')
289
+ escaped = true;
290
+ else if (character === quote)
291
+ quote = '';
292
+ continue;
293
+ }
294
+ if (character === '"' || character === "'")
295
+ quote = character;
296
+ else if ('([{'.includes(character))
297
+ stack.push(character);
298
+ else if (')]}'.includes(character))
299
+ stack.pop();
300
+ else if (character === ',' && !stack.length) {
301
+ argumentsList.push(body.slice(start, index).trim());
302
+ start = index + 1;
303
+ }
304
+ }
305
+ argumentsList.push(body.slice(start).trim());
306
+ return argumentsList;
307
+ };
308
+ const exactPrincipalFromCall = (call, swift) => {
309
+ const argumentsList = topLevelCallArguments(call);
310
+ if (argumentsList.length !== 4)
311
+ return null;
312
+ const principal = argumentsList[3];
313
+ if (swift) {
314
+ if (/^NSStringFromClass\s*\(\s*AppDelegate\.self\s*\)$/.test(principal)) {
315
+ return 'AppDelegate';
316
+ }
317
+ return /^"AppDelegate"$/.test(principal) ? 'AppDelegate' : null;
318
+ }
319
+ if (/^NSStringFromClass\s*\(\s*\[\s*AppDelegate\s+class\s*\]\s*\)$/.test(principal)) {
320
+ return 'AppDelegate';
321
+ }
322
+ return /^@"AppDelegate"$/.test(principal) ? 'AppDelegate' : null;
323
+ };
324
+ const objcAuthorityIssue = (projectRoot, mainFiles) => {
325
+ if (mainFiles.length !== 1 || !/\.m{1,2}$/i.test(mainFiles[0])) {
326
+ return mainFiles.length
327
+ ? 'Multiple or conflicting iOS application principal sources were found.'
328
+ : 'Objective-C main/UIApplicationMain principal source is missing.';
329
+ }
330
+ const mainFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, mainFiles[0]);
331
+ const calls = findBalancedCall(stripCComments(mainFile.content), 'UIApplicationMain');
332
+ if (calls.length !== 1)
333
+ return 'Exactly one UIApplicationMain call is required.';
334
+ return exactPrincipalFromCall(calls[0], false)
335
+ ? null
336
+ : `UIApplicationMain argument 4 does not select AppDelegate.`;
337
+ };
338
+ const swiftAuthorityIssue = (projectRoot, entrypoint, mainFiles, swiftFiles) => {
339
+ const principals = swiftFiles.flatMap(file => {
340
+ const source = (0, native_setup_contract_1.stripCommentsAndStrings)((0, safe_file_transaction_1.inspectProjectFile)(projectRoot, file).content);
341
+ return [...source.matchAll(/@(?:main|UIApplicationMain)\b[\s\n]*(?:(?:final|public|private|internal|open)\s+)*(?:class|struct)\s+([A-Za-z_$][\w$]*)/g)].map(match => ({ file, name: match[1] }));
342
+ });
343
+ if (principals.length === 1 &&
344
+ principals[0].name === 'AppDelegate' &&
345
+ principals[0].file === entrypoint) {
346
+ return mainFiles.length
347
+ ? 'An annotated Swift AppDelegate conflicts with an external main source.'
348
+ : null;
349
+ }
350
+ if (principals.length)
351
+ return 'Swift principal annotation does not uniquely select AppDelegate.';
352
+ if (mainFiles.length !== 1 || !mainFiles[0].endsWith('/main.swift')) {
353
+ return mainFiles.length
354
+ ? 'Multiple or conflicting iOS application principal sources were found.'
355
+ : 'Swift @main/UIApplicationMain principal is missing.';
356
+ }
357
+ const mainFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, mainFiles[0]);
358
+ const calls = findBalancedCall(stripCComments(mainFile.content), 'UIApplicationMain');
359
+ if (calls.length !== 1 || !exactPrincipalFromCall(calls[0], true)) {
360
+ return 'Swift main UIApplicationMain argument 4 does not select AppDelegate.';
361
+ }
362
+ return null;
363
+ };
364
+ const findNativeEntrypointAuthorityIssue = (projectRoot, platform, entrypoints) => {
365
+ if (!entrypoints.length)
366
+ return null;
367
+ if (entrypoints.length > 1) {
368
+ return `Multiple ${platform} application entrypoints were found; startup authority is ambiguous.`;
369
+ }
370
+ if (platform === 'android')
371
+ return androidAuthorityIssue(projectRoot, entrypoints[0]);
372
+ const { mainFiles, swiftFiles } = findIosAuthoritySources(projectRoot);
373
+ if (entrypoints[0].endsWith('.swift')) {
374
+ return swiftAuthorityIssue(projectRoot, entrypoints[0], mainFiles, swiftFiles);
375
+ }
376
+ return objcAuthorityIssue(projectRoot, mainFiles);
377
+ };
378
+ exports.findNativeEntrypointAuthorityIssue = findNativeEntrypointAuthorityIssue;
@@ -3,5 +3,5 @@ export declare const ANDROID_BUNDLE_DROP_PATHS = "com.bundledrop.BundleDropNativ
3
3
  export declare const IOS_BUNDLE_DROP_MODULE = "BundleDrop";
4
4
  export declare const IOS_BUNDLE_DROP_LOCATOR_HEADER = "BundleDrop/BundleDropLocator.h";
5
5
  export declare const stripCommentsAndStrings: (content: string) => string;
6
- export declare const hasBareAndroidStartupIntegration: (code: string) => boolean;
7
- export declare const hasBareIosStartupIntegration: (filePath: string, code: string) => boolean;
6
+ export declare const stripComments: (content: string) => string;
7
+ export { findMissingBareNativeStartupStructure, hasBareAndroidStartupIntegration, hasBareIosStartupIntegration, } from './native-startup-validator';
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasBareIosStartupIntegration = exports.hasBareAndroidStartupIntegration = exports.stripCommentsAndStrings = exports.IOS_BUNDLE_DROP_LOCATOR_HEADER = exports.IOS_BUNDLE_DROP_MODULE = exports.ANDROID_BUNDLE_DROP_PATHS = exports.ANDROID_BUNDLE_DROP_MODULE = void 0;
3
+ exports.hasBareIosStartupIntegration = exports.hasBareAndroidStartupIntegration = exports.findMissingBareNativeStartupStructure = exports.stripComments = exports.stripCommentsAndStrings = exports.IOS_BUNDLE_DROP_LOCATOR_HEADER = exports.IOS_BUNDLE_DROP_MODULE = exports.ANDROID_BUNDLE_DROP_PATHS = exports.ANDROID_BUNDLE_DROP_MODULE = void 0;
4
4
  exports.ANDROID_BUNDLE_DROP_MODULE = 'com.bundledrop.BundleDropModule';
5
5
  exports.ANDROID_BUNDLE_DROP_PATHS = 'com.bundledrop.BundleDropNativePaths';
6
6
  exports.IOS_BUNDLE_DROP_MODULE = 'BundleDrop';
7
7
  exports.IOS_BUNDLE_DROP_LOCATOR_HEADER = 'BundleDrop/BundleDropLocator.h';
8
- const stripCommentsAndStrings = (content) => {
8
+ const sanitizeSource = (content, preserveStrings) => {
9
9
  let code = '';
10
10
  let state = 'code';
11
11
  let escaped = false;
12
+ let blockCommentDepth = 0;
13
+ let tripleQuoteHashes = '';
12
14
  for (let index = 0; index < content.length; index += 1) {
13
15
  const character = content[index];
14
16
  const nextCharacter = content[index + 1];
@@ -20,24 +22,51 @@ const stripCommentsAndStrings = (content) => {
20
22
  continue;
21
23
  }
22
24
  if (state === 'block-comment') {
25
+ if (character === '/' && nextCharacter === '*') {
26
+ blockCommentDepth += 1;
27
+ index += 1;
28
+ continue;
29
+ }
23
30
  if (character === '*' && nextCharacter === '/') {
24
- state = 'code';
31
+ blockCommentDepth -= 1;
32
+ if (blockCommentDepth === 0)
33
+ state = 'code';
25
34
  index += 1;
26
35
  }
27
36
  continue;
28
37
  }
38
+ if (state === 'triple-double') {
39
+ const closingDelimiter = `"""${tripleQuoteHashes}`;
40
+ if (content.startsWith(closingDelimiter, index)) {
41
+ if (preserveStrings)
42
+ code += closingDelimiter;
43
+ index += closingDelimiter.length - 1;
44
+ state = 'code';
45
+ tripleQuoteHashes = '';
46
+ }
47
+ else if (preserveStrings) {
48
+ code += character;
49
+ }
50
+ continue;
51
+ }
29
52
  if (state !== 'code') {
30
53
  if (escaped) {
54
+ if (preserveStrings)
55
+ code += character;
31
56
  escaped = false;
32
57
  continue;
33
58
  }
34
59
  if (character === '\\') {
60
+ if (preserveStrings)
61
+ code += character;
35
62
  escaped = true;
36
63
  continue;
37
64
  }
38
65
  const closesState = (state === 'single' && character === "'") ||
39
66
  (state === 'double' && character === '"') ||
40
67
  (state === 'template' && character === '`');
68
+ if (preserveStrings)
69
+ code += character;
41
70
  if (closesState)
42
71
  state = 'code';
43
72
  continue;
@@ -49,53 +78,54 @@ const stripCommentsAndStrings = (content) => {
49
78
  }
50
79
  if (character === '/' && nextCharacter === '*') {
51
80
  state = 'block-comment';
81
+ blockCommentDepth = 1;
52
82
  index += 1;
53
83
  continue;
54
84
  }
85
+ const swiftRawTripleQuote = content.slice(index).match(/^(#+)"""/);
86
+ if (character === '"' && content.startsWith('"""', index)) {
87
+ state = 'triple-double';
88
+ tripleQuoteHashes = '';
89
+ if (preserveStrings)
90
+ code += '"""';
91
+ index += 2;
92
+ continue;
93
+ }
94
+ if (swiftRawTripleQuote) {
95
+ state = 'triple-double';
96
+ tripleQuoteHashes = swiftRawTripleQuote[1];
97
+ if (preserveStrings)
98
+ code += swiftRawTripleQuote[0];
99
+ index += swiftRawTripleQuote[0].length - 1;
100
+ continue;
101
+ }
55
102
  if (character === "'") {
56
103
  state = 'single';
104
+ if (preserveStrings)
105
+ code += character;
57
106
  continue;
58
107
  }
59
108
  if (character === '"') {
60
109
  state = 'double';
110
+ if (preserveStrings)
111
+ code += character;
61
112
  continue;
62
113
  }
63
114
  if (character === '`') {
64
115
  state = 'template';
116
+ if (preserveStrings)
117
+ code += character;
65
118
  continue;
66
119
  }
67
120
  code += character;
68
121
  }
69
122
  return code;
70
123
  };
124
+ const stripCommentsAndStrings = (content) => sanitizeSource(content, false);
71
125
  exports.stripCommentsAndStrings = stripCommentsAndStrings;
72
- const hasJavaOrKotlinReference = (code, qualifiedName, member) => {
73
- const escapedName = qualifiedName.replace(/\./g, '\\.');
74
- return (new RegExp(`\\bimport\\s+${escapedName}\\s*;?`).test(code) ||
75
- code.includes(`${qualifiedName}.${member}`));
76
- };
77
- const hasBareAndroidStartupIntegration = (code) => {
78
- const nativeCode = (0, exports.stripCommentsAndStrings)(code);
79
- const usesModuleResolver = nativeCode.includes('getJSBundleFile') &&
80
- nativeCode.includes('BundleDropModule.resolveJSBundleFile') &&
81
- hasJavaOrKotlinReference(nativeCode, exports.ANDROID_BUNDLE_DROP_MODULE, 'resolveJSBundleFile');
82
- const usesNativePaths = nativeCode.includes('BundleDropNativePaths.getDownloadedBundlePath') &&
83
- hasJavaOrKotlinReference(nativeCode, exports.ANDROID_BUNDLE_DROP_PATHS, 'getDownloadedBundlePath');
84
- return usesModuleResolver || usesNativePaths;
85
- };
86
- exports.hasBareAndroidStartupIntegration = hasBareAndroidStartupIntegration;
87
- const hasBareIosStartupIntegration = (filePath, code) => {
88
- const nativeCode = (0, exports.stripCommentsAndStrings)(code);
89
- if (filePath.endsWith('.swift')) {
90
- const usesLocator = nativeCode.includes('bundleURL') &&
91
- nativeCode.includes('BundleDropLocator.bundleURL()');
92
- return usesLocator &&
93
- new RegExp(`\\bimport\\s+${exports.IOS_BUNDLE_DROP_MODULE}\\b`).test(nativeCode);
94
- }
95
- const usesLocator = (nativeCode.includes('sourceURLForBridge') || nativeCode.includes('bundleURL')) &&
96
- nativeCode.includes('[BundleDropLocator bundleURL]');
97
- const escapedHeader = exports.IOS_BUNDLE_DROP_LOCATOR_HEADER.replace(/[/.]/g, '\\$&');
98
- return usesLocator &&
99
- new RegExp(`#import\\s*[<\"]${escapedHeader}[>\"]`).test(nativeCode);
100
- };
101
- exports.hasBareIosStartupIntegration = hasBareIosStartupIntegration;
126
+ const stripComments = (content) => sanitizeSource(content, true);
127
+ exports.stripComments = stripComments;
128
+ var native_startup_validator_1 = require("./native-startup-validator");
129
+ Object.defineProperty(exports, "findMissingBareNativeStartupStructure", { enumerable: true, get: function () { return native_startup_validator_1.findMissingBareNativeStartupStructure; } });
130
+ Object.defineProperty(exports, "hasBareAndroidStartupIntegration", { enumerable: true, get: function () { return native_startup_validator_1.hasBareAndroidStartupIntegration; } });
131
+ Object.defineProperty(exports, "hasBareIosStartupIntegration", { enumerable: true, get: function () { return native_startup_validator_1.hasBareIosStartupIntegration; } });
@@ -0,0 +1,3 @@
1
+ export declare const hasBareAndroidStartupIntegration: (code: string) => boolean;
2
+ export declare const hasBareIosStartupIntegration: (filePath: string, code: string) => boolean;
3
+ export declare const findMissingBareNativeStartupStructure: (filePath: string, original: string, updated: string) => string[];