@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.
- package/BundleDrop.podspec +96 -0
- package/README.md +194 -5
- package/android/build.gradle +66 -0
- package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +206 -13
- package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
- package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
- package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
- package/ios/BundleDropBridge.m +45 -0
- package/ios/BundleDropLocator.swift +66 -4
- package/ios/BundleDropModule.swift +181 -3
- package/ios/BundleDropOtaResolver.swift +137 -29
- package/ios/BundleDropRuntimeCrypto.swift +45 -0
- package/ios/BundleDropStartupRecovery.swift +1108 -0
- package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
- package/lib/CLI/cli.d.ts +1 -0
- package/lib/CLI/cli.js +57 -6
- 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 +221 -45
- 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 +162 -22
- package/lib/CLI/scripts/expo/configure-expo.js +52 -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 +198 -14
- package/lib/CLI/scripts/login-cli.js +31 -7
- 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/write-runtime-identity.d.ts +19 -0
- package/lib/CLI/scripts/native/write-runtime-identity.js +92 -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/upload-cli.d.ts +12 -2
- package/lib/CLI/scripts/upload-cli.js +74 -11
- package/lib/CLI/serverUrl.d.ts +3 -0
- package/lib/CLI/serverUrl.js +31 -0
- package/lib/api/clientApi.d.ts +3 -1
- package/lib/api/clientApi.js +14 -0
- package/lib/api/types.d.ts +39 -0
- package/lib/bundleInfo.d.ts +2 -0
- package/lib/bundleInfo.js +16 -1
- package/lib/context.d.ts +1 -1
- package/lib/context.js +12 -2
- package/lib/fs/bundlePointer.d.ts +1 -17
- package/lib/fs/bundlePointer.js +5 -93
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/install/bundleInstallShared.js +4 -4
- 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 +134 -66
- package/lib/manager/reporting.d.ts +8 -1
- package/lib/manager/reporting.js +17 -22
- package/lib/manager/rollbackState.d.ts +18 -52
- package/lib/manager/rollbackState.js +115 -216
- package/lib/manager/updateCheck.d.ts +1 -0
- package/lib/manager/updateCheck.js +224 -78
- package/lib/manager/updateState.d.ts +2 -1
- package/lib/manager/updateState.js +59 -6
- package/lib/metro.d.ts +8 -1
- package/lib/metro.js +69 -19
- package/lib/native/bundleDropNative.d.ts +62 -0
- package/lib/native/bundleDropNative.js +268 -2
- 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 +16 -5
- 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 +82 -67
- 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 +68 -0
- package/lib/runtime-delivery/bootstrapConfig.js +278 -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 +11 -0
- package/lib/runtime-delivery/manifestState.js +123 -0
- package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
- package/lib/runtime-delivery/manifestVerifier.js +335 -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/lib/scripts/bundle.d.ts +9 -2
- package/lib/scripts/bundle.js +68 -18
- package/lib/scripts/download-bundle.d.ts +1 -0
- package/lib/scripts/download-bundle.js +2 -2
- package/lib/scripts/resolveModule.d.ts +2 -0
- package/lib/scripts/resolveModule.js +5 -0
- package/package.json +5 -2
- package/plugin/xcodeBuildPhase.js +2 -1
|
@@ -0,0 +1,964 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findMissingBareNativeStartupStructure = exports.hasBareIosStartupIntegration = exports.hasBareAndroidStartupIntegration = void 0;
|
|
4
|
+
const native_setup_contract_1 = require("./native-setup-contract");
|
|
5
|
+
const findBalancedBlockEnd = (code, openingIndex, openingCharacter = '{', closingCharacter = '}') => {
|
|
6
|
+
let depth = 0;
|
|
7
|
+
for (let index = openingIndex; index < code.length; index += 1) {
|
|
8
|
+
if (code[index] === openingCharacter)
|
|
9
|
+
depth += 1;
|
|
10
|
+
if (code[index] === closingCharacter)
|
|
11
|
+
depth -= 1;
|
|
12
|
+
if (depth === 0)
|
|
13
|
+
return index;
|
|
14
|
+
}
|
|
15
|
+
return -1;
|
|
16
|
+
};
|
|
17
|
+
const extractBalancedBlock = (code, openingBrace) => {
|
|
18
|
+
const closingBrace = findBalancedBlockEnd(code, openingBrace);
|
|
19
|
+
return closingBrace < 0 ? '' : code.slice(openingBrace + 1, closingBrace);
|
|
20
|
+
};
|
|
21
|
+
const extractExpressionBody = (code, equals, firstLineEnd) => {
|
|
22
|
+
let expressionEnd = firstLineEnd;
|
|
23
|
+
let braceDepth = [...code.slice(equals + 1, firstLineEnd)]
|
|
24
|
+
.reduce((depth, character) => {
|
|
25
|
+
if (character === '{')
|
|
26
|
+
return depth + 1;
|
|
27
|
+
if (character === '}')
|
|
28
|
+
return depth - 1;
|
|
29
|
+
return depth;
|
|
30
|
+
}, 0);
|
|
31
|
+
let nextLineStart = firstLineEnd < code.length ? firstLineEnd + 1 : code.length;
|
|
32
|
+
while (nextLineStart < code.length) {
|
|
33
|
+
const nextLineEnd = code.indexOf('\n', nextLineStart);
|
|
34
|
+
const lineEnd = nextLineEnd < 0 ? code.length : nextLineEnd;
|
|
35
|
+
const line = code.slice(nextLineStart, lineEnd).trim();
|
|
36
|
+
if (braceDepth === 0 && (line === '}' ||
|
|
37
|
+
/^(?:@|init\b|class\b|object\b|interface\b|companion\s+object\b)/.test(line) ||
|
|
38
|
+
/^(?:(?:override|private|protected|public|internal|final|open)\s+)*(?:fun|val|var)\b/.test(line))) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
expressionEnd = lineEnd;
|
|
42
|
+
braceDepth = [...code.slice(nextLineStart, lineEnd)]
|
|
43
|
+
.reduce((depth, character) => {
|
|
44
|
+
if (character === '{')
|
|
45
|
+
return depth + 1;
|
|
46
|
+
if (character === '}')
|
|
47
|
+
return depth - 1;
|
|
48
|
+
return depth;
|
|
49
|
+
}, braceDepth);
|
|
50
|
+
nextLineStart = nextLineEnd < 0 ? code.length : nextLineEnd + 1;
|
|
51
|
+
}
|
|
52
|
+
return code.slice(equals + 1, expressionEnd);
|
|
53
|
+
};
|
|
54
|
+
const findDeclaredMethods = (code, declarationPattern) => [...code.matchAll(declarationPattern)].map(match => {
|
|
55
|
+
const delimiter = match[1];
|
|
56
|
+
const declarationStart = match.index || 0;
|
|
57
|
+
const delimiterIndex = declarationStart + match[0].lastIndexOf(delimiter);
|
|
58
|
+
const lineEndIndex = code.indexOf('\n', delimiterIndex);
|
|
59
|
+
const lineEnd = lineEndIndex < 0 ? code.length : lineEndIndex;
|
|
60
|
+
return {
|
|
61
|
+
declarationStart,
|
|
62
|
+
declaration: match[0],
|
|
63
|
+
body: delimiter === '{'
|
|
64
|
+
? extractBalancedBlock(code, delimiterIndex)
|
|
65
|
+
: extractExpressionBody(code, delimiterIndex, lineEnd),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
const KOTLIN_JS_BUNDLE_METHOD = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|protected|internal|override|final|open)\s+)*fun\s+getJSBundleFile\s*\(\s*\)\s*(?::\s*[^=\{\n]+)?\s*([={])/g;
|
|
69
|
+
const JAVA_JS_BUNDLE_METHOD = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|protected|final|synchronized)\s+)*(?:[\w$.<>\[\]?@]+\s+)+getJSBundleFile\s*\(\s*\)\s*(?:throws\s+[^\{\n]+)?\s*(\{)/g;
|
|
70
|
+
const ANDROID_ON_CREATE_METHOD = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|protected|internal|override|final|open)\s+)*(?:fun\s+onCreate|void\s+onCreate)\s*\(\s*\)\s*(\{)/g;
|
|
71
|
+
const SWIFT_BUNDLE_URL_METHOD = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|internal|fileprivate|open|override|final)\s+)*func\s+bundleURL\s*\(\s*\)\s*(?:async\s+)?(?:throws\s+)?(?:->\s*[^\{\n]+)?\s*(\{)/g;
|
|
72
|
+
const SWIFT_APP_LAUNCH_METHOD = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|internal|fileprivate|open|override|final)\s+)*func\s+application\s*\(\s*_\s+[A-Za-z_]\w*\s*:\s*UIApplication\s*,\s*didFinishLaunchingWithOptions\s+[A-Za-z_]\w*\s*:[\s\S]*?\)\s*(?:async\s+)?(?:throws\s+)?->\s*Bool\s*(\{)/g;
|
|
73
|
+
const SWIFT_SOURCE_URL_METHOD = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|internal|fileprivate|open|override|final)\s+)*func\s+sourceURL\s*\(\s*for\s+[A-Za-z_]\w*\s*:\s*RCTBridge\s*\)\s*(?:async\s+)?(?:throws\s+)?(?:->\s*[^\{\n]+)?\s*(\{)/g;
|
|
74
|
+
const OBJC_SOURCE_URL_METHOD = /(?:^|\n)\s*-\s*\([^\n)]*\)\s*sourceURLForBridge\s*:\s*\([^\n)]*\)\s*\w+\s*(\{)/g;
|
|
75
|
+
const OBJC_BUNDLE_URL_METHOD = /(?:^|\n)\s*-\s*\([^\n)]*\)\s*bundleURL\s*(\{)/g;
|
|
76
|
+
const OBJC_SELF_BUNDLE_URL_DELEGATION = /\[\s*self\s+bundleURL\s*\]|\bself\s*\.\s*bundleURL\b/;
|
|
77
|
+
const KOTLIN_REACT_HOST_PROPERTY = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|protected|internal|override|final|open)\s+)*val\s+(reactHost)\s*:\s*ReactHost\s+by\s+lazy\s*(\{)/g;
|
|
78
|
+
const KOTLIN_LEGACY_NATIVE_HOST_INITIALIZER = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|protected|internal|override|final|open)\s+)*(?:val|var)\s+([A-Za-z_]\w*)\s*:\s*ReactNativeHost\s*=\s*object\s*:\s*(?:Default)?ReactNativeHost\s*\([^\n{]*\)\s*(\{)/g;
|
|
79
|
+
const JAVA_LEGACY_NATIVE_HOST_INITIALIZER = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|protected|static|final|volatile|transient)\s+)*ReactNativeHost\s+([A-Za-z_]\w*)\s*=\s*new\s+(?:Default)?ReactNativeHost\s*\([^\n{]*\)\s*(\{)/g;
|
|
80
|
+
const JAVA_GET_REACT_NATIVE_HOST_METHOD = /(?:^|\n)\s*(?:@\w+(?:\([^\n)]*\))?\s*)*(?:(?:public|private|protected|final|synchronized)\s+)*ReactNativeHost\s+getReactNativeHost\s*\(\s*\)\s*(\{)/g;
|
|
81
|
+
const findSourceTypes = (code) => [...code.matchAll(/\b(?:class|object)\s+([A-Za-z_]\w*)[^{}]*\{/g)].map(match => {
|
|
82
|
+
const openingBrace = (match.index || 0) + match[0].lastIndexOf('{');
|
|
83
|
+
return {
|
|
84
|
+
name: match[1],
|
|
85
|
+
declaration: match[0],
|
|
86
|
+
declarationStart: match.index || 0,
|
|
87
|
+
openingBrace,
|
|
88
|
+
closingBrace: findBalancedBlockEnd(code, openingBrace),
|
|
89
|
+
};
|
|
90
|
+
}).filter(type => type.closingBrace >= 0);
|
|
91
|
+
const findContainingType = (code, position) => findSourceTypes(code)
|
|
92
|
+
.filter(type => type.openingBrace < position && position < type.closingBrace)
|
|
93
|
+
.sort((left, right) => (left.closingBrace - left.openingBrace) - (right.closingBrace - right.openingBrace))[0] || null;
|
|
94
|
+
const isDirectMemberOfType = (code, position, owner) => {
|
|
95
|
+
if (position <= owner.openingBrace || position >= owner.closingBrace)
|
|
96
|
+
return false;
|
|
97
|
+
let braceDepth = 0;
|
|
98
|
+
for (let index = owner.openingBrace + 1; index < position; index += 1) {
|
|
99
|
+
if (code[index] === '{')
|
|
100
|
+
braceDepth += 1;
|
|
101
|
+
else if (code[index] === '}')
|
|
102
|
+
braceDepth -= 1;
|
|
103
|
+
}
|
|
104
|
+
return braceDepth === 0;
|
|
105
|
+
};
|
|
106
|
+
const findNamedType = (code, name) => {
|
|
107
|
+
const matches = findSourceTypes(code).filter(type => type.name === name);
|
|
108
|
+
return matches.length === 1 ? matches[0] : null;
|
|
109
|
+
};
|
|
110
|
+
const findNamedSourceBlocks = (code, declarationPattern) => [...code.matchAll(declarationPattern)].flatMap(match => {
|
|
111
|
+
const openingBrace = (match.index || 0) + match[0].lastIndexOf('{');
|
|
112
|
+
const closingBrace = findBalancedBlockEnd(code, openingBrace);
|
|
113
|
+
return closingBrace < 0 ? [] : [{
|
|
114
|
+
name: match[1],
|
|
115
|
+
declaration: match[0],
|
|
116
|
+
declarationStart: match.index || 0,
|
|
117
|
+
bodyStart: openingBrace + 1,
|
|
118
|
+
bodyEnd: closingBrace,
|
|
119
|
+
}];
|
|
120
|
+
});
|
|
121
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
122
|
+
const trimTrailingClosingBraces = (value) => {
|
|
123
|
+
let suffix = value.trim();
|
|
124
|
+
while (suffix.endsWith('}')) {
|
|
125
|
+
suffix = suffix.slice(0, -1).trimEnd();
|
|
126
|
+
}
|
|
127
|
+
return suffix.trim();
|
|
128
|
+
};
|
|
129
|
+
const findObjcImplementations = (code) => [...code.matchAll(/@implementation\s+([A-Za-z_]\w*)(?:\s*\(([^)]*)\))?/g)]
|
|
130
|
+
.flatMap(match => {
|
|
131
|
+
const bodyStart = (match.index || 0) + match[0].length;
|
|
132
|
+
const endPattern = /@end\b/g;
|
|
133
|
+
endPattern.lastIndex = bodyStart;
|
|
134
|
+
const endMatch = endPattern.exec(code);
|
|
135
|
+
if (!endMatch)
|
|
136
|
+
return [];
|
|
137
|
+
return [{
|
|
138
|
+
name: match[1],
|
|
139
|
+
category: match[2]?.trim() || undefined,
|
|
140
|
+
bodyStart,
|
|
141
|
+
bodyEnd: endMatch.index,
|
|
142
|
+
}];
|
|
143
|
+
});
|
|
144
|
+
const methodBelongsToObjcImplementation = (method, implementation) => implementation.bodyStart <= method.declarationStart &&
|
|
145
|
+
method.declarationStart < implementation.bodyEnd;
|
|
146
|
+
const findCallSites = (code, functionName) => {
|
|
147
|
+
const calls = [];
|
|
148
|
+
const callPattern = new RegExp(`\\b${escapeRegExp(functionName)}\\s*\\(`, 'g');
|
|
149
|
+
for (const match of code.matchAll(callPattern)) {
|
|
150
|
+
const openingParenthesis = (match.index || 0) + match[0].lastIndexOf('(');
|
|
151
|
+
const closingParenthesis = findBalancedBlockEnd(code, openingParenthesis, '(', ')');
|
|
152
|
+
if (closingParenthesis >= 0) {
|
|
153
|
+
calls.push({
|
|
154
|
+
argumentsBody: code.slice(openingParenthesis + 1, closingParenthesis),
|
|
155
|
+
start: match.index || 0,
|
|
156
|
+
end: closingParenthesis + 1,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return calls;
|
|
161
|
+
};
|
|
162
|
+
const hasAuthoritativeLazyHostCall = (body, acceptsArguments) => findCallSites(body, 'getDefaultReactHost').some(call => {
|
|
163
|
+
if (!acceptsArguments(call.argumentsBody))
|
|
164
|
+
return false;
|
|
165
|
+
const before = body.slice(0, call.start);
|
|
166
|
+
const after = body.slice(call.end);
|
|
167
|
+
if (/\breturn\s*@\s*lazy\b/.test(before))
|
|
168
|
+
return false;
|
|
169
|
+
if (!after.trim())
|
|
170
|
+
return true;
|
|
171
|
+
const assignment = /\b(?:val|var)\s+([A-Za-z_]\w*)\s*=\s*$/.exec(before);
|
|
172
|
+
return Boolean(assignment && new RegExp(`^\\s*;?\\s*${escapeRegExp(assignment[1])}\\s*;?\\s*$`).test(after));
|
|
173
|
+
});
|
|
174
|
+
const hasExactAndroidModuleReference = (code) => {
|
|
175
|
+
const escapedName = escapeRegExp(native_setup_contract_1.ANDROID_BUNDLE_DROP_MODULE);
|
|
176
|
+
return new RegExp(`(?:^|\\n)[ \\t]*import\\s+${escapedName}[ \\t]*;?[ \\t]*(?:\\n|$)`).test(code) ||
|
|
177
|
+
code.includes(`${native_setup_contract_1.ANDROID_BUNDLE_DROP_MODULE}.resolveJSBundleFile`);
|
|
178
|
+
};
|
|
179
|
+
const hasExactAndroidNativePathsReference = (code) => {
|
|
180
|
+
const escapedName = escapeRegExp(native_setup_contract_1.ANDROID_BUNDLE_DROP_PATHS);
|
|
181
|
+
return new RegExp(`\\bimport\\s+${escapedName}\\s*;?`).test(code) ||
|
|
182
|
+
code.includes(`${native_setup_contract_1.ANDROID_BUNDLE_DROP_PATHS}.getDownloadedBundlePath`);
|
|
183
|
+
};
|
|
184
|
+
const hasNativeCodePushResidue = (content) => {
|
|
185
|
+
const code = (0, native_setup_contract_1.stripCommentsAndStrings)(content);
|
|
186
|
+
return /\bCodePush\b|\bcom\.microsoft\.codepush\.react\b/i.test(code);
|
|
187
|
+
};
|
|
188
|
+
const androidStartupMethod = (nativeCode) => {
|
|
189
|
+
const kotlinMethods = findDeclaredMethods(nativeCode, KOTLIN_JS_BUNDLE_METHOD)
|
|
190
|
+
.map(method => ({ ...method, language: 'kotlin' }));
|
|
191
|
+
const javaMethods = findDeclaredMethods(nativeCode, JAVA_JS_BUNDLE_METHOD)
|
|
192
|
+
.map(method => ({ ...method, language: 'java' }));
|
|
193
|
+
const methods = [...new Map([...kotlinMethods, ...javaMethods].map(method => [method.declarationStart, method])).values()];
|
|
194
|
+
if (methods.length !== 1)
|
|
195
|
+
return null;
|
|
196
|
+
const method = methods[0];
|
|
197
|
+
const owner = findContainingType(nativeCode, method.declarationStart);
|
|
198
|
+
if (owner?.name !== 'MainApplication')
|
|
199
|
+
return null;
|
|
200
|
+
return { method, owner };
|
|
201
|
+
};
|
|
202
|
+
const methodsOwnedBy = (code, declarationPattern, ownerName) => {
|
|
203
|
+
const owner = findNamedType(code, ownerName);
|
|
204
|
+
if (!owner)
|
|
205
|
+
return [];
|
|
206
|
+
return findDeclaredMethods(code, declarationPattern).filter(method => findContainingType(code, method.declarationStart)?.declarationStart ===
|
|
207
|
+
owner.declarationStart &&
|
|
208
|
+
isDirectMemberOfType(code, method.declarationStart, owner));
|
|
209
|
+
};
|
|
210
|
+
const hasAndroidLifecycleIntegrity = (nativeCode, owner) => {
|
|
211
|
+
const ownerBody = nativeCode.slice(owner.openingBrace + 1, owner.closingBrace);
|
|
212
|
+
const lifecycleSignals = [
|
|
213
|
+
'super.onCreate',
|
|
214
|
+
'loadReactNative',
|
|
215
|
+
'SoLoader.init',
|
|
216
|
+
'DefaultNewArchitectureEntryPoint.load',
|
|
217
|
+
].filter(signal => ownerBody.includes(signal));
|
|
218
|
+
if (!lifecycleSignals.length)
|
|
219
|
+
return true;
|
|
220
|
+
const onCreateMethods = methodsOwnedBy(nativeCode, ANDROID_ON_CREATE_METHOD, 'MainApplication');
|
|
221
|
+
return onCreateMethods.length === 1 &&
|
|
222
|
+
lifecycleSignals.every(signal => onCreateMethods[0].body.includes(signal));
|
|
223
|
+
};
|
|
224
|
+
const authoritativeReactHostBlocks = (nativeCode) => {
|
|
225
|
+
const mainApplication = findNamedType(nativeCode, 'MainApplication');
|
|
226
|
+
if (!mainApplication)
|
|
227
|
+
return [];
|
|
228
|
+
const blocks = findNamedSourceBlocks(nativeCode, KOTLIN_REACT_HOST_PROPERTY).filter(block => /\boverride\s+val\s+reactHost\b/.test(block.declaration) &&
|
|
229
|
+
findContainingType(nativeCode, block.declarationStart)?.declarationStart ===
|
|
230
|
+
mainApplication.declarationStart &&
|
|
231
|
+
isDirectMemberOfType(nativeCode, block.declarationStart, mainApplication));
|
|
232
|
+
return blocks.length === 1 ? blocks : [];
|
|
233
|
+
};
|
|
234
|
+
const hasDirectReactHostConnection = (nativeCode) => {
|
|
235
|
+
const [reactHost] = authoritativeReactHostBlocks(nativeCode);
|
|
236
|
+
if (!reactHost)
|
|
237
|
+
return false;
|
|
238
|
+
const body = nativeCode.slice(reactHost.bodyStart, reactHost.bodyEnd);
|
|
239
|
+
return hasAuthoritativeLazyHostCall(body, argumentsBody => /\bjsBundleFilePath\s*=\s*(?:this\.)?getJSBundleFile\s*\(\s*\)/.test(argumentsBody));
|
|
240
|
+
};
|
|
241
|
+
const NATIVE_PATHS_CONTEXT = '(?:this(?:@MainApplication)?|[A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*)*)';
|
|
242
|
+
const NATIVE_PATHS_CALL = `(?:com\\.bundledrop\\.)?BundleDropNativePaths\\s*\\.\\s*` +
|
|
243
|
+
`getDownloadedBundlePath\\s*\\(\\s*${NATIVE_PATHS_CONTEXT}\\s*\\)`;
|
|
244
|
+
const hasDirectNativePathsHostConnection = (nativeCode) => {
|
|
245
|
+
const [reactHost] = authoritativeReactHostBlocks(nativeCode);
|
|
246
|
+
if (!reactHost)
|
|
247
|
+
return false;
|
|
248
|
+
const body = nativeCode.slice(reactHost.bodyStart, reactHost.bodyEnd);
|
|
249
|
+
return hasAuthoritativeLazyHostCall(body, argumentsBody => new RegExp(`\\bjsBundleFilePath\\s*=\\s*${NATIVE_PATHS_CALL}`).test(argumentsBody));
|
|
250
|
+
};
|
|
251
|
+
const hasNativePathsResolverCall = (body) => new RegExp(`\\b${NATIVE_PATHS_CALL}`).test(body);
|
|
252
|
+
const isAndroidNativeOverride = (startup) => startup.method.language === 'kotlin'
|
|
253
|
+
? /\boverride\s+fun\b/.test(startup.method.declaration)
|
|
254
|
+
: /@Override\b/.test(startup.method.declaration) ||
|
|
255
|
+
/\b(?:public|protected)\b/.test(startup.method.declaration);
|
|
256
|
+
const legacyAndroidHostBlocks = (nativeCode) => [
|
|
257
|
+
...findNamedSourceBlocks(nativeCode, KOTLIN_LEGACY_NATIVE_HOST_INITIALIZER),
|
|
258
|
+
...findNamedSourceBlocks(nativeCode, JAVA_LEGACY_NATIVE_HOST_INITIALIZER),
|
|
259
|
+
];
|
|
260
|
+
const isAuthoritativeLegacyAndroidHost = (nativeCode, host) => {
|
|
261
|
+
const mainApplication = findNamedType(nativeCode, 'MainApplication');
|
|
262
|
+
if (!mainApplication ||
|
|
263
|
+
findContainingType(nativeCode, host.declarationStart)?.declarationStart !==
|
|
264
|
+
mainApplication.declarationStart ||
|
|
265
|
+
!isDirectMemberOfType(nativeCode, host.declarationStart, mainApplication)) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
if (host.name === 'reactNativeHost' &&
|
|
269
|
+
/\boverride\s+(?:val|var)\s+reactNativeHost\b/.test(host.declaration)) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
const kotlinGetters = [...nativeCode.matchAll(/(?:^|\n)\s*override\s+(?:val|var)\s+reactNativeHost\s*:\s*ReactNativeHost\s*\n?\s*get\s*\(\s*\)\s*=\s*(?:this\.)?([A-Za-z_]\w*)\b/g)].filter(match => findContainingType(nativeCode, match.index || 0)?.declarationStart ===
|
|
273
|
+
mainApplication.declarationStart &&
|
|
274
|
+
isDirectMemberOfType(nativeCode, match.index || 0, mainApplication));
|
|
275
|
+
if (kotlinGetters.length === 1 && kotlinGetters[0][1] === host.name)
|
|
276
|
+
return true;
|
|
277
|
+
const javaGetters = methodsOwnedBy(nativeCode, JAVA_GET_REACT_NATIVE_HOST_METHOD, 'MainApplication');
|
|
278
|
+
if (javaGetters.length !== 1)
|
|
279
|
+
return false;
|
|
280
|
+
const returnedHosts = [...javaGetters[0].body.matchAll(/\breturn\s+(?:this\.)?([A-Za-z_]\w*)\s*;/g)].map(match => match[1]);
|
|
281
|
+
return returnedHosts.length === 1 && returnedHosts[0] === host.name;
|
|
282
|
+
};
|
|
283
|
+
const isResolverMethodConnectedToAndroidStartup = (nativeCode, startup) => {
|
|
284
|
+
const containingLegacyHosts = legacyAndroidHostBlocks(nativeCode).filter(host => host.bodyStart <= startup.method.declarationStart &&
|
|
285
|
+
startup.method.declarationStart < host.bodyEnd);
|
|
286
|
+
if (containingLegacyHosts.length) {
|
|
287
|
+
const authoritativeHosts = legacyAndroidHostBlocks(nativeCode).filter(host => isAuthoritativeLegacyAndroidHost(nativeCode, host));
|
|
288
|
+
return containingLegacyHosts.length === 1 &&
|
|
289
|
+
authoritativeHosts.length === 1 &&
|
|
290
|
+
authoritativeHosts[0].bodyStart === containingLegacyHosts[0].bodyStart &&
|
|
291
|
+
isAndroidNativeOverride(startup);
|
|
292
|
+
}
|
|
293
|
+
return startup.method.language === 'kotlin' &&
|
|
294
|
+
/\bprivate\s+fun\b/.test(startup.method.declaration) &&
|
|
295
|
+
hasDirectReactHostConnection(nativeCode);
|
|
296
|
+
};
|
|
297
|
+
const findBuildConfigDebugOnlyRanges = (source) => {
|
|
298
|
+
const ranges = [];
|
|
299
|
+
const conditions = /\bif\s*\(\s*(!\s*)?BuildConfig\.DEBUG\s*\)/g;
|
|
300
|
+
for (const match of source.matchAll(conditions)) {
|
|
301
|
+
const negated = Boolean(match[1]);
|
|
302
|
+
const conditionEnd = (match.index || 0) + match[0].length;
|
|
303
|
+
let branchStart = conditionEnd;
|
|
304
|
+
while (/\s/.test(source[branchStart] || ''))
|
|
305
|
+
branchStart += 1;
|
|
306
|
+
let trueStart = branchStart;
|
|
307
|
+
let trueEnd = branchStart;
|
|
308
|
+
let elseStart = -1;
|
|
309
|
+
let elseEnd = -1;
|
|
310
|
+
if (source[branchStart] === '{') {
|
|
311
|
+
const closingBrace = findBalancedBlockEnd(source, branchStart);
|
|
312
|
+
if (closingBrace < 0)
|
|
313
|
+
continue;
|
|
314
|
+
trueStart = branchStart + 1;
|
|
315
|
+
trueEnd = closingBrace;
|
|
316
|
+
const elseMatch = /^\s*else\b/.exec(source.slice(closingBrace + 1));
|
|
317
|
+
if (elseMatch) {
|
|
318
|
+
let cursor = closingBrace + 1 + elseMatch[0].length;
|
|
319
|
+
while (/\s/.test(source[cursor] || ''))
|
|
320
|
+
cursor += 1;
|
|
321
|
+
if (source[cursor] === '{') {
|
|
322
|
+
const closingElse = findBalancedBlockEnd(source, cursor);
|
|
323
|
+
if (closingElse >= 0) {
|
|
324
|
+
elseStart = cursor + 1;
|
|
325
|
+
elseEnd = closingElse;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
elseStart = cursor;
|
|
330
|
+
const end = source.slice(cursor).search(/[;\n]/);
|
|
331
|
+
elseEnd = end < 0 ? source.length : cursor + end;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
const tail = source.slice(branchStart);
|
|
337
|
+
const elseMatch = /\belse\b/.exec(tail);
|
|
338
|
+
const statementEnd = tail.search(/[;\n]/);
|
|
339
|
+
trueEnd = elseMatch
|
|
340
|
+
? branchStart + elseMatch.index
|
|
341
|
+
: statementEnd < 0 ? source.length : branchStart + statementEnd;
|
|
342
|
+
if (elseMatch) {
|
|
343
|
+
elseStart = branchStart + elseMatch.index + elseMatch[0].length;
|
|
344
|
+
const end = source.slice(elseStart).search(/[;\n]/);
|
|
345
|
+
elseEnd = end < 0 ? source.length : elseStart + end;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (!negated)
|
|
349
|
+
ranges.push({ start: trueStart, end: trueEnd });
|
|
350
|
+
if (negated && elseStart >= 0)
|
|
351
|
+
ranges.push({ start: elseStart, end: elseEnd });
|
|
352
|
+
}
|
|
353
|
+
return ranges;
|
|
354
|
+
};
|
|
355
|
+
const sourceWithoutDebugPreprocessorBranches = (source) => {
|
|
356
|
+
const output = [];
|
|
357
|
+
const stack = [];
|
|
358
|
+
for (const line of source.split('\n')) {
|
|
359
|
+
const directive = /^\s*#\s*(if|ifdef|ifndef|elseif|elif|else|endif)\b(.*)$/i.exec(line);
|
|
360
|
+
const kind = directive?.[1].toLowerCase();
|
|
361
|
+
const condition = directive?.[2] || '';
|
|
362
|
+
const debugCondition = /\bDEBUG\b/i.test(condition)
|
|
363
|
+
? /!\s*(?:defined\s*\()?\s*DEBUG\b|\bifndef\b/i.test(`${kind} ${condition}`)
|
|
364
|
+
? 'release'
|
|
365
|
+
: 'debug'
|
|
366
|
+
: 'other';
|
|
367
|
+
if (kind === 'if' || kind === 'ifdef' || kind === 'ifndef') {
|
|
368
|
+
stack.push({ initial: debugCondition, debugOnly: debugCondition === 'debug' });
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if ((kind === 'elseif' || kind === 'elif') && stack.length) {
|
|
372
|
+
stack[stack.length - 1].debugOnly = debugCondition === 'debug';
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (kind === 'else' && stack.length) {
|
|
376
|
+
stack[stack.length - 1].debugOnly = stack[stack.length - 1].initial === 'release';
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (kind === 'endif' && stack.length) {
|
|
380
|
+
stack.pop();
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
if (stack.every(frame => !frame.debugOnly)) {
|
|
384
|
+
output.push(line);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return output.join('\n');
|
|
388
|
+
};
|
|
389
|
+
const releaseSource = (body) => {
|
|
390
|
+
const hasCompoundDebugDirective = body.split('\n').some(line => {
|
|
391
|
+
const directive = /^\s*#\s*(if|ifdef|ifndef|elseif|elif)\b(.*)$/i.exec(line);
|
|
392
|
+
if (!directive || !/\bDEBUG\b/i.test(directive[2]))
|
|
393
|
+
return false;
|
|
394
|
+
const condition = directive[2].trim();
|
|
395
|
+
return !/^(?:!\s*)?(?:defined\s*\(\s*)?DEBUG\s*\)?$/i.test(condition);
|
|
396
|
+
});
|
|
397
|
+
if (hasCompoundDebugDirective)
|
|
398
|
+
return '';
|
|
399
|
+
const withoutPreprocessorDebug = sourceWithoutDebugPreprocessorBranches(body);
|
|
400
|
+
const characters = [...withoutPreprocessorDebug];
|
|
401
|
+
for (const condition of withoutPreprocessorDebug.matchAll(/\bif\s*\(\s*!?\s*BuildConfig\.DEBUG\s*\)/g)) {
|
|
402
|
+
const start = condition.index || 0;
|
|
403
|
+
for (let index = start; index < start + condition[0].length; index += 1) {
|
|
404
|
+
if (characters[index] !== '\n')
|
|
405
|
+
characters[index] = ' ';
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
for (const range of findBuildConfigDebugOnlyRanges(withoutPreprocessorDebug)) {
|
|
409
|
+
for (let index = range.start; index < range.end; index += 1) {
|
|
410
|
+
if (characters[index] !== '\n')
|
|
411
|
+
characters[index] = ' ';
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const projected = characters.join('');
|
|
415
|
+
return /\bBuildConfig\.DEBUG\b/.test(projected) ? '' : projected;
|
|
416
|
+
};
|
|
417
|
+
const resolverCallRanges = (source, resolver) => {
|
|
418
|
+
const ranges = [];
|
|
419
|
+
let resolverStart = source.indexOf(resolver);
|
|
420
|
+
while (resolverStart >= 0) {
|
|
421
|
+
const openingParenthesis = source.indexOf('(', resolverStart + resolver.length);
|
|
422
|
+
const closingParenthesis = openingParenthesis < 0
|
|
423
|
+
? -1
|
|
424
|
+
: findBalancedBlockEnd(source, openingParenthesis, '(', ')');
|
|
425
|
+
if (closingParenthesis >= 0)
|
|
426
|
+
ranges.push({ start: resolverStart, end: closingParenthesis + 1 });
|
|
427
|
+
resolverStart = source.indexOf(resolver, resolverStart + resolver.length);
|
|
428
|
+
}
|
|
429
|
+
return ranges;
|
|
430
|
+
};
|
|
431
|
+
const objcLocatorRanges = (source) => [...source.matchAll(/\[\s*BundleDropLocator\s+bundleURL\s*\]/g)].map(match => ({ start: match.index || 0, end: (match.index || 0) + match[0].length }));
|
|
432
|
+
const objcSelfBundleUrlRanges = (source) => [...source.matchAll(/\[\s*self\s+bundleURL\s*\]|\bself\s*\.\s*bundleURL\b/g)].map(match => ({ start: match.index || 0, end: (match.index || 0) + match[0].length }));
|
|
433
|
+
const splitTopLevelArguments = (body) => {
|
|
434
|
+
const parts = [];
|
|
435
|
+
const stack = [];
|
|
436
|
+
let start = 0;
|
|
437
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
438
|
+
const character = body[index];
|
|
439
|
+
if ('([{'.includes(character))
|
|
440
|
+
stack.push(character);
|
|
441
|
+
else if (')]}'.includes(character))
|
|
442
|
+
stack.pop();
|
|
443
|
+
else if (character === ',' && !stack.length) {
|
|
444
|
+
parts.push(body.slice(start, index).trim());
|
|
445
|
+
start = index + 1;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
parts.push(body.slice(start).trim());
|
|
449
|
+
if (parts.length > 2 &&
|
|
450
|
+
body.trimEnd().endsWith(',') &&
|
|
451
|
+
parts[parts.length - 1] === '') {
|
|
452
|
+
parts.pop();
|
|
453
|
+
}
|
|
454
|
+
return parts;
|
|
455
|
+
};
|
|
456
|
+
const hasValidAndroidModuleResolverCall = (nativeCode, startup) => {
|
|
457
|
+
const calls = findCallSites(startup.method.body, 'BundleDropModule.resolveJSBundleFile');
|
|
458
|
+
if (calls.length !== 1)
|
|
459
|
+
return false;
|
|
460
|
+
const argumentsList = splitTopLevelArguments(calls[0].argumentsBody);
|
|
461
|
+
if (argumentsList.length !== 2)
|
|
462
|
+
return false;
|
|
463
|
+
if (startup.method.language === 'java') {
|
|
464
|
+
return /^(?:MainApplication\.this|getApplicationContext\(\s*\))$/.test(argumentsList[0]);
|
|
465
|
+
}
|
|
466
|
+
const insideLegacyHost = legacyAndroidHostBlocks(nativeCode).some(host => host.bodyStart <= startup.method.declarationStart &&
|
|
467
|
+
startup.method.declarationStart < host.bodyEnd);
|
|
468
|
+
return insideLegacyHost
|
|
469
|
+
? /^(?:this@MainApplication|applicationContext|getApplicationContext\(\s*\))$/.test(argumentsList[0])
|
|
470
|
+
: /^(?:this(?:@MainApplication)?|applicationContext|getApplicationContext\(\s*\))$/.test(argumentsList[0]);
|
|
471
|
+
};
|
|
472
|
+
const canContinueValueExpressionAcrossNewline = (prefix) => {
|
|
473
|
+
if (!prefix.includes('\n'))
|
|
474
|
+
return true;
|
|
475
|
+
const completedLines = prefix.split('\n').slice(0, -1);
|
|
476
|
+
const precedingLine = [...completedLines].reverse().find(line => line.trim())?.trim() || '';
|
|
477
|
+
return !precedingLine ||
|
|
478
|
+
/(?:\breturn|\belse|[=?:({,+\-*/.!])$/.test(precedingLine);
|
|
479
|
+
};
|
|
480
|
+
const hasCanonicalGuardedResolverFallback = (source, resolver) => {
|
|
481
|
+
if (resolver === 'BundleDropLocator.bundleURL') {
|
|
482
|
+
const match = /^\s*if\s+let\s+([A-Za-z_]\w*)\s*=\s*BundleDropLocator\.bundleURL\s*\(\s*\)\s*\{\s*return\s+\1\s*;?\s*\}\s*return\s+[^;{}\n]+\s*;?\s*$/.exec(source);
|
|
483
|
+
return Boolean(match);
|
|
484
|
+
}
|
|
485
|
+
if (resolver === '[BundleDropLocator bundleURL]') {
|
|
486
|
+
const match = /^\s*NSURL\s*\*\s*([A-Za-z_]\w*)\s*=\s*\[\s*BundleDropLocator\s+bundleURL\s*\]\s*;\s*if\s*\(\s*\1\s*(?:!=\s*nil)?\s*\)\s*\{\s*return\s+\1\s*;\s*\}\s*return\s+[^;{}]+;\s*$/.exec(source);
|
|
487
|
+
return Boolean(match);
|
|
488
|
+
}
|
|
489
|
+
return false;
|
|
490
|
+
};
|
|
491
|
+
const hasCanonicalReturnedResolverSuffix = (afterResolver, resolver, language, requiresNonNullResult) => {
|
|
492
|
+
const suffix = trimTrailingClosingBraces(afterResolver);
|
|
493
|
+
if (!suffix || suffix === ';')
|
|
494
|
+
return !requiresNonNullResult;
|
|
495
|
+
if (language === 'kotlin' && resolver === 'BundleDropModule.resolveJSBundleFile') {
|
|
496
|
+
return /^!!\s*;?$/.test(suffix) ||
|
|
497
|
+
/^\?:\s*(?:super\.getJSBundleFile\s*\(\s*\)|[A-Za-z_]\w*)\s*;?$/.test(suffix);
|
|
498
|
+
}
|
|
499
|
+
if (language === 'swift' && resolver === 'BundleDropLocator.bundleURL') {
|
|
500
|
+
return new RegExp('^\\?\\?\\s*(?:' +
|
|
501
|
+
'RCTBundleURLProvider\\.sharedSettings\\s*\\(\\s*\\)' +
|
|
502
|
+
'\\.jsBundleURL\\s*\\([^)]*\\)|' +
|
|
503
|
+
'Bundle\\.main\\.url\\s*\\([^)]*\\)|' +
|
|
504
|
+
'[A-Za-z_]\\w*' +
|
|
505
|
+
')\\s*;?$').test(suffix);
|
|
506
|
+
}
|
|
507
|
+
if (language === 'objc' && resolver === '[BundleDropLocator bundleURL]') {
|
|
508
|
+
return /^\?:\s*(?:\[[^\]\n]+\]|[A-Za-z_]\w*)\s*;?$/.test(suffix);
|
|
509
|
+
}
|
|
510
|
+
return false;
|
|
511
|
+
};
|
|
512
|
+
const isSupportedJavaTernaryPart = (source) => {
|
|
513
|
+
const expression = source.trim();
|
|
514
|
+
if (!expression || /\b(?:break|continue|else|for|if|return|switch|throw|while)\b/.test(expression)) {
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
const stack = [];
|
|
518
|
+
for (const character of expression) {
|
|
519
|
+
if ('(['.includes(character))
|
|
520
|
+
stack.push(character);
|
|
521
|
+
else if (')]'.includes(character)) {
|
|
522
|
+
const opening = stack.pop();
|
|
523
|
+
if ((character === ')' && opening !== '(') ||
|
|
524
|
+
(character === ']' && opening !== '[')) {
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
else if (character === ',' && !stack.length) {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return stack.length === 0;
|
|
533
|
+
};
|
|
534
|
+
const hasCanonicalConditionalLocalFallback = (source, resolver, language) => {
|
|
535
|
+
if (resolver !== 'BundleDropModule.resolveJSBundleFile')
|
|
536
|
+
return false;
|
|
537
|
+
const calls = findCallSites(source, resolver);
|
|
538
|
+
if (calls.length !== 1)
|
|
539
|
+
return false;
|
|
540
|
+
const argumentsList = splitTopLevelArguments(calls[0].argumentsBody);
|
|
541
|
+
if (argumentsList.length !== 2 || !/^[A-Za-z_]\w*$/.test(argumentsList[1])) {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
const fallback = argumentsList[1];
|
|
545
|
+
if (language === 'java') {
|
|
546
|
+
const selection = new RegExp(`^\\s*(?:final\\s+)?String\\s+${escapeRegExp(fallback)}\\s*=\\s*` +
|
|
547
|
+
'([^?;{}]+)\\?([^?:;{}]+):([^?:;{}]+);\\s*return\\s*$').exec(source.slice(0, calls[0].start));
|
|
548
|
+
if (!selection || selection.slice(1).some(part => part.includes(resolver) || !isSupportedJavaTernaryPart(part))) {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
return /^\s*;?\s*$/.test(source.slice(calls[0].end));
|
|
552
|
+
}
|
|
553
|
+
if (language !== 'kotlin')
|
|
554
|
+
return false;
|
|
555
|
+
const assignment = new RegExp(`^\\s*(?:val|var)\\s+${escapeRegExp(fallback)}` +
|
|
556
|
+
`(?:\\s*:\\s*[^=\\n]+)?\\s*=\\s*if\\s*\\(`).exec(source);
|
|
557
|
+
if (!assignment)
|
|
558
|
+
return false;
|
|
559
|
+
const conditionOpening = assignment[0].lastIndexOf('(');
|
|
560
|
+
const conditionClosing = findBalancedBlockEnd(source, conditionOpening, '(', ')');
|
|
561
|
+
if (conditionClosing < 0)
|
|
562
|
+
return false;
|
|
563
|
+
let cursor = conditionClosing + 1;
|
|
564
|
+
while (/\s/.test(source[cursor] || ''))
|
|
565
|
+
cursor += 1;
|
|
566
|
+
if (source[cursor] !== '{')
|
|
567
|
+
return false;
|
|
568
|
+
const trueBranchClosing = findBalancedBlockEnd(source, cursor);
|
|
569
|
+
if (trueBranchClosing < 0)
|
|
570
|
+
return false;
|
|
571
|
+
const trueBranch = source.slice(cursor + 1, trueBranchClosing);
|
|
572
|
+
cursor = trueBranchClosing + 1;
|
|
573
|
+
while (/\s/.test(source[cursor] || ''))
|
|
574
|
+
cursor += 1;
|
|
575
|
+
if (!source.startsWith('else', cursor) || /\w/.test(source[cursor + 4] || ''))
|
|
576
|
+
return false;
|
|
577
|
+
cursor += 4;
|
|
578
|
+
while (/\s/.test(source[cursor] || ''))
|
|
579
|
+
cursor += 1;
|
|
580
|
+
if (source[cursor] !== '{')
|
|
581
|
+
return false;
|
|
582
|
+
const falseBranchClosing = findBalancedBlockEnd(source, cursor);
|
|
583
|
+
if (falseBranchClosing < 0)
|
|
584
|
+
return false;
|
|
585
|
+
const falseBranch = source.slice(cursor + 1, falseBranchClosing);
|
|
586
|
+
const beforeResolver = source.slice(falseBranchClosing + 1, calls[0].start);
|
|
587
|
+
if (!/^\s*;?\s*return\s*$/.test(beforeResolver))
|
|
588
|
+
return false;
|
|
589
|
+
if (/\breturn\b/.test(trueBranch) ||
|
|
590
|
+
/\breturn\b/.test(falseBranch) ||
|
|
591
|
+
trueBranch.includes(resolver) ||
|
|
592
|
+
falseBranch.includes(resolver)) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
return new RegExp(`^\\s*\\?:\\s*${escapeRegExp(fallback)}\\s*;?\\s*$`).test(source.slice(calls[0].end));
|
|
596
|
+
};
|
|
597
|
+
const resolverFeedsReturnedValue = (body, resolver, expressionBody, language, requiresNonNullResult = false) => {
|
|
598
|
+
const source = releaseSource(body);
|
|
599
|
+
if (hasCanonicalGuardedResolverFallback(source, resolver))
|
|
600
|
+
return true;
|
|
601
|
+
if (hasCanonicalConditionalLocalFallback(source, resolver, language))
|
|
602
|
+
return true;
|
|
603
|
+
const sourceWithoutFallbackOperators = source.replace(/\?\?|\?:/g, '');
|
|
604
|
+
if (/\b(?:if|when|switch)\b/.test(source) || sourceWithoutFallbackOperators.includes('?')) {
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
const ranges = resolver === '[BundleDropLocator bundleURL]'
|
|
608
|
+
? objcLocatorRanges(source)
|
|
609
|
+
: resolver === '[self bundleURL]' || resolver === 'self.bundleURL'
|
|
610
|
+
? objcSelfBundleUrlRanges(source)
|
|
611
|
+
: resolverCallRanges(source, resolver);
|
|
612
|
+
const returnIndices = [...source.matchAll(/\breturn\b/g)].map(match => match.index || 0);
|
|
613
|
+
const controlledReturns = new Set();
|
|
614
|
+
let hasValueFlow = false;
|
|
615
|
+
for (const range of ranges) {
|
|
616
|
+
const before = source.slice(0, range.start);
|
|
617
|
+
const after = source.slice(range.end);
|
|
618
|
+
const statementStart = Math.max(before.lastIndexOf(';'), before.lastIndexOf('{')) + 1;
|
|
619
|
+
const statementPrefix = before.slice(statementStart);
|
|
620
|
+
const returnedExpression = /\breturn\b([\s\S]*)$/.exec(statementPrefix);
|
|
621
|
+
if (returnedExpression &&
|
|
622
|
+
canContinueValueExpressionAcrossNewline(returnedExpression[1]) &&
|
|
623
|
+
hasCanonicalReturnedResolverSuffix(after, resolver, language, requiresNonNullResult)) {
|
|
624
|
+
controlledReturns.add(statementStart + (returnedExpression.index || 0));
|
|
625
|
+
hasValueFlow = true;
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
const assignment = /\b(?:val|var|let|NSURL\s*\*?|URL\s*\??|String\s*\??)\s*([A-Za-z_]\w*)\s*=\s*[^;{}]*$/.exec(statementPrefix);
|
|
629
|
+
const assignedExpression = assignment?.[0].slice(assignment[0].indexOf('=') + 1) || '';
|
|
630
|
+
if (assignment &&
|
|
631
|
+
canContinueValueExpressionAcrossNewline(assignedExpression) &&
|
|
632
|
+
new RegExp(`\\breturn\\s+${escapeRegExp(assignment[1])}\\b`).test(after)) {
|
|
633
|
+
for (const returnedVariable of after.matchAll(new RegExp(`\\breturn\\s+${escapeRegExp(assignment[1])}\\b`, 'g'))) {
|
|
634
|
+
controlledReturns.add(range.end + (returnedVariable.index || 0));
|
|
635
|
+
}
|
|
636
|
+
hasValueFlow = true;
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
const allowsImplicitSingleExpression = expressionBody ||
|
|
640
|
+
resolver === 'BundleDropLocator.bundleURL';
|
|
641
|
+
if (allowsImplicitSingleExpression) {
|
|
642
|
+
const prefix = statementPrefix.trim();
|
|
643
|
+
const allowedQualifiedPrefix = !prefix ||
|
|
644
|
+
prefix === 'else' ||
|
|
645
|
+
prefix === 'com.bundledrop.' ||
|
|
646
|
+
prefix === 'else com.bundledrop.';
|
|
647
|
+
if (allowedQualifiedPrefix && hasCanonicalReturnedResolverSuffix(after, resolver, language, requiresNonNullResult)) {
|
|
648
|
+
hasValueFlow = true;
|
|
649
|
+
}
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return hasValueFlow && returnIndices.every(index => controlledReturns.has(index));
|
|
654
|
+
};
|
|
655
|
+
const hasBareAndroidStartupIntegration = (code) => {
|
|
656
|
+
if (hasNativeCodePushResidue(code))
|
|
657
|
+
return false;
|
|
658
|
+
const nativeCode = (0, native_setup_contract_1.stripCommentsAndStrings)(code);
|
|
659
|
+
const mainApplication = findNamedType(nativeCode, 'MainApplication');
|
|
660
|
+
if (mainApplication &&
|
|
661
|
+
hasExactAndroidNativePathsReference(nativeCode) &&
|
|
662
|
+
hasDirectNativePathsHostConnection(nativeCode) &&
|
|
663
|
+
hasAndroidLifecycleIntegrity(nativeCode, mainApplication)) {
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
const startup = androidStartupMethod(nativeCode);
|
|
667
|
+
if (startup &&
|
|
668
|
+
hasExactAndroidNativePathsReference(nativeCode) &&
|
|
669
|
+
hasNativePathsResolverCall(startup.method.body) &&
|
|
670
|
+
resolverFeedsReturnedValue(startup.method.body, 'BundleDropNativePaths.getDownloadedBundlePath', startup.method.declaration.trimEnd().endsWith('='), startup.method.language) &&
|
|
671
|
+
hasAndroidLifecycleIntegrity(nativeCode, startup.owner) &&
|
|
672
|
+
isResolverMethodConnectedToAndroidStartup(nativeCode, startup)) {
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
675
|
+
if (!hasExactAndroidModuleReference(nativeCode))
|
|
676
|
+
return false;
|
|
677
|
+
if (!startup ||
|
|
678
|
+
!hasValidAndroidModuleResolverCall(nativeCode, startup) ||
|
|
679
|
+
!resolverFeedsReturnedValue(startup.method.body, 'BundleDropModule.resolveJSBundleFile', startup.method.declaration.trimEnd().endsWith('='), startup.method.language, startup.method.language === 'kotlin' &&
|
|
680
|
+
/:\s*(?:kotlin\.)?String\s*(?=[={])/.test(startup.method.declaration))) {
|
|
681
|
+
return false;
|
|
682
|
+
}
|
|
683
|
+
if (!hasAndroidLifecycleIntegrity(nativeCode, startup.owner))
|
|
684
|
+
return false;
|
|
685
|
+
return isResolverMethodConnectedToAndroidStartup(nativeCode, startup);
|
|
686
|
+
};
|
|
687
|
+
exports.hasBareAndroidStartupIntegration = hasBareAndroidStartupIntegration;
|
|
688
|
+
const swiftPrincipalTypes = (nativeCode) => findSourceTypes(nativeCode).filter(type => {
|
|
689
|
+
const prefix = nativeCode.slice(Math.max(0, type.declarationStart - 120), type.declarationStart);
|
|
690
|
+
return /@(?:main|UIApplicationMain)\b[\s\n]*(?:final\s+)?$/.test(prefix);
|
|
691
|
+
});
|
|
692
|
+
const hasConnectedSwiftFactoryDelegate = (nativeCode, delegateType) => {
|
|
693
|
+
const appDelegate = findNamedType(nativeCode, 'AppDelegate');
|
|
694
|
+
if (!appDelegate)
|
|
695
|
+
return false;
|
|
696
|
+
const principals = swiftPrincipalTypes(nativeCode);
|
|
697
|
+
if (principals.length > 1 ||
|
|
698
|
+
(principals.length === 1 && principals[0].declarationStart !== appDelegate.declarationStart)) {
|
|
699
|
+
return false;
|
|
700
|
+
}
|
|
701
|
+
if (!/:\s*[^\{]*(?:UIApplicationDelegate|RCTAppDelegate)\b/.test(appDelegate.declaration)) {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
const launchMethods = methodsOwnedBy(nativeCode, SWIFT_APP_LAUNCH_METHOD, 'AppDelegate');
|
|
705
|
+
if (launchMethods.length !== 1)
|
|
706
|
+
return false;
|
|
707
|
+
const launchBody = launchMethods[0].body;
|
|
708
|
+
const factoryCalls = [...launchBody.matchAll(/\bRCTReactNativeFactory\s*\(/g)];
|
|
709
|
+
const startCalls = [...launchBody.matchAll(/\b([A-Za-z_]\w*)\s*\.\s*startReactNative\s*\(/g)];
|
|
710
|
+
if (factoryCalls.length !== 1 || startCalls.length !== 1)
|
|
711
|
+
return false;
|
|
712
|
+
const startPosition = startCalls[0].index || 0;
|
|
713
|
+
const nestingDepth = [...launchBody.slice(0, startPosition)].reduce((depth, character) => {
|
|
714
|
+
if (character === '{')
|
|
715
|
+
return depth + 1;
|
|
716
|
+
if (character === '}')
|
|
717
|
+
return depth - 1;
|
|
718
|
+
return depth;
|
|
719
|
+
}, 0);
|
|
720
|
+
if (nestingDepth !== 0)
|
|
721
|
+
return false;
|
|
722
|
+
const delegateName = escapeRegExp(delegateType.name);
|
|
723
|
+
const delegateDeclarations = new RegExp(`\\b(?:let|var)\\s+([A-Za-z_]\\w*)\\s*(?::\\s*${delegateName})?` +
|
|
724
|
+
`\\s*=\\s*${delegateName}\\s*\\(\\s*\\)`, 'g');
|
|
725
|
+
return [...launchBody.matchAll(delegateDeclarations)].some(delegateMatch => {
|
|
726
|
+
const delegateVariable = escapeRegExp(delegateMatch[1]);
|
|
727
|
+
const factoryDeclaration = new RegExp(`\\b(?:let|var)\\s+([A-Za-z_]\\w*)\\s*=\\s*RCTReactNativeFactory\\s*` +
|
|
728
|
+
`\\(\\s*delegate\\s*:\\s*${delegateVariable}\\s*\\)`).exec(launchBody);
|
|
729
|
+
if (!factoryDeclaration)
|
|
730
|
+
return false;
|
|
731
|
+
return startCalls[0][1] === factoryDeclaration[1];
|
|
732
|
+
});
|
|
733
|
+
};
|
|
734
|
+
const factoryDelegateSourceUrlFeedsBundleUrl = (nativeCode, delegateType) => {
|
|
735
|
+
const sourceMethods = findDeclaredMethods(nativeCode, SWIFT_SOURCE_URL_METHOD).filter(method => findContainingType(nativeCode, method.declarationStart)?.declarationStart ===
|
|
736
|
+
delegateType.declarationStart);
|
|
737
|
+
if (sourceMethods.length !== 1)
|
|
738
|
+
return false;
|
|
739
|
+
const source = releaseSource(sourceMethods[0].body).trim();
|
|
740
|
+
return /^(?:return\s+)?(?:self\s*\.\s*)?bundleURL\s*\(\s*\)\s*;?$/.test(source);
|
|
741
|
+
};
|
|
742
|
+
const appDelegateSourceUrlPreservesBundleAuthority = (nativeCode, appDelegate) => {
|
|
743
|
+
const sourceMethods = findDeclaredMethods(nativeCode, SWIFT_SOURCE_URL_METHOD).filter(method => findContainingType(nativeCode, method.declarationStart)?.declarationStart ===
|
|
744
|
+
appDelegate.declarationStart);
|
|
745
|
+
if (!sourceMethods.length)
|
|
746
|
+
return true;
|
|
747
|
+
if (sourceMethods.length !== 1)
|
|
748
|
+
return false;
|
|
749
|
+
const source = releaseSource(sourceMethods[0].body).trim();
|
|
750
|
+
return /^(?:return\s+)?(?:self\s*\.\s*)?bundleURL\s*\(\s*\)\s*;?$/.test(source) ||
|
|
751
|
+
resolverFeedsReturnedValue(sourceMethods[0].body, 'BundleDropLocator.bundleURL', false, 'swift');
|
|
752
|
+
};
|
|
753
|
+
const swiftStartupMethod = (nativeCode) => {
|
|
754
|
+
const methods = findDeclaredMethods(nativeCode, SWIFT_BUNDLE_URL_METHOD);
|
|
755
|
+
if (methods.length !== 1)
|
|
756
|
+
return null;
|
|
757
|
+
const method = methods[0];
|
|
758
|
+
const owner = findContainingType(nativeCode, method.declarationStart);
|
|
759
|
+
const principals = swiftPrincipalTypes(nativeCode);
|
|
760
|
+
if (principals.length > 1)
|
|
761
|
+
return null;
|
|
762
|
+
if (owner?.name === 'AppDelegate') {
|
|
763
|
+
const ownsPrincipal = !principals.length ||
|
|
764
|
+
principals[0].declarationStart === owner.declarationStart;
|
|
765
|
+
return ownsPrincipal &&
|
|
766
|
+
/:\s*[^\{]*\bRCTAppDelegate\b/.test(owner.declaration) &&
|
|
767
|
+
/\boverride\s+func\s+bundleURL\b/.test(method.declaration) &&
|
|
768
|
+
appDelegateSourceUrlPreservesBundleAuthority(nativeCode, owner)
|
|
769
|
+
? method
|
|
770
|
+
: null;
|
|
771
|
+
}
|
|
772
|
+
const factoryDelegates = findSourceTypes(nativeCode).filter(type => /:\s*RCTDefaultReactNativeFactoryDelegate\b/.test(type.declaration));
|
|
773
|
+
return factoryDelegates.length === 1 &&
|
|
774
|
+
owner?.name === factoryDelegates[0].name &&
|
|
775
|
+
hasConnectedSwiftFactoryDelegate(nativeCode, factoryDelegates[0]) &&
|
|
776
|
+
factoryDelegateSourceUrlFeedsBundleUrl(nativeCode, factoryDelegates[0])
|
|
777
|
+
? method
|
|
778
|
+
: null;
|
|
779
|
+
};
|
|
780
|
+
const objcStartupMethods = (nativeCode) => {
|
|
781
|
+
const implementations = findObjcImplementations(nativeCode);
|
|
782
|
+
const appDelegateImplementations = implementations.filter(implementation => implementation.name === 'AppDelegate' && !implementation.category);
|
|
783
|
+
if (appDelegateImplementations.length !== 1)
|
|
784
|
+
return null;
|
|
785
|
+
const appDelegate = appDelegateImplementations[0];
|
|
786
|
+
const allSourceMethods = findDeclaredMethods(nativeCode, OBJC_SOURCE_URL_METHOD);
|
|
787
|
+
const allBundleMethods = findDeclaredMethods(nativeCode, OBJC_BUNDLE_URL_METHOD);
|
|
788
|
+
const sourceMethods = allSourceMethods.filter(method => methodBelongsToObjcImplementation(method, appDelegate));
|
|
789
|
+
const bundleMethods = allBundleMethods.filter(method => methodBelongsToObjcImplementation(method, appDelegate));
|
|
790
|
+
if (allSourceMethods.length !== sourceMethods.length || allBundleMethods.length !== bundleMethods.length) {
|
|
791
|
+
return null;
|
|
792
|
+
}
|
|
793
|
+
if (sourceMethods.length > 1 || bundleMethods.length > 1)
|
|
794
|
+
return null;
|
|
795
|
+
return { sourceMethod: sourceMethods[0] || null, bundleMethod: bundleMethods[0] || null };
|
|
796
|
+
};
|
|
797
|
+
const hasBareIosStartupIntegration = (filePath, code) => {
|
|
798
|
+
if (hasNativeCodePushResidue(code))
|
|
799
|
+
return false;
|
|
800
|
+
const nativeCode = (0, native_setup_contract_1.stripCommentsAndStrings)(code);
|
|
801
|
+
if (filePath.endsWith('.swift')) {
|
|
802
|
+
const startupMethod = swiftStartupMethod(nativeCode);
|
|
803
|
+
return Boolean(startupMethod &&
|
|
804
|
+
resolverFeedsReturnedValue(startupMethod.body, 'BundleDropLocator.bundleURL', false, 'swift') &&
|
|
805
|
+
new RegExp(`\\bimport\\s+${native_setup_contract_1.IOS_BUNDLE_DROP_MODULE}\\b`).test(nativeCode));
|
|
806
|
+
}
|
|
807
|
+
const escapedHeader = escapeRegExp(native_setup_contract_1.IOS_BUNDLE_DROP_LOCATOR_HEADER);
|
|
808
|
+
if (!new RegExp(`#import\\s*[<"]${escapedHeader}[>"]`).test(nativeCode))
|
|
809
|
+
return false;
|
|
810
|
+
const startup = objcStartupMethods(nativeCode);
|
|
811
|
+
if (!startup)
|
|
812
|
+
return false;
|
|
813
|
+
const locatorCall = '[BundleDropLocator bundleURL]';
|
|
814
|
+
const bundleHasLocator = startup.bundleMethod
|
|
815
|
+
? resolverFeedsReturnedValue(startup.bundleMethod.body, locatorCall, false, 'objc')
|
|
816
|
+
: false;
|
|
817
|
+
if (!startup.sourceMethod)
|
|
818
|
+
return bundleHasLocator;
|
|
819
|
+
return resolverFeedsReturnedValue(startup.sourceMethod.body, locatorCall, false, 'objc') ||
|
|
820
|
+
(bundleHasLocator && (resolverFeedsReturnedValue(startup.sourceMethod.body, '[self bundleURL]', false, 'objc') ||
|
|
821
|
+
resolverFeedsReturnedValue(startup.sourceMethod.body, 'self.bundleURL', false, 'objc')));
|
|
822
|
+
};
|
|
823
|
+
exports.hasBareIosStartupIntegration = hasBareIosStartupIntegration;
|
|
824
|
+
const preservationSignals = (originalBody, updatedBody, signals) => signals
|
|
825
|
+
.filter(signal => originalBody.includes(signal.token) && !updatedBody.includes(signal.token))
|
|
826
|
+
.map(signal => signal.label);
|
|
827
|
+
const findCodePushAliases = (content) => {
|
|
828
|
+
const aliases = new Set();
|
|
829
|
+
for (const match of content.matchAll(/^\s*import\s+com\.microsoft\.codepush\.react\.CodePush\s+as\s+([A-Za-z_]\w*)\s*;?\s*$/gim)) {
|
|
830
|
+
aliases.add(match[1]);
|
|
831
|
+
}
|
|
832
|
+
for (const match of content.matchAll(/^\s*#\s*define\s+([A-Za-z_]\w*)\s+CodePush\s*$/gim)) {
|
|
833
|
+
aliases.add(match[1]);
|
|
834
|
+
}
|
|
835
|
+
return [...aliases];
|
|
836
|
+
};
|
|
837
|
+
const withoutReplaceableCodePushReferences = (content, knownAliases = []) => {
|
|
838
|
+
const aliases = [...new Set([...findCodePushAliases(content), ...knownAliases])];
|
|
839
|
+
const resolverOwners = [
|
|
840
|
+
'com\\.microsoft\\.codepush\\.react\\.CodePush',
|
|
841
|
+
'CodePush',
|
|
842
|
+
...aliases.map(escapeRegExp),
|
|
843
|
+
].join('|');
|
|
844
|
+
return content
|
|
845
|
+
.replace(/^\s*import\s+(?:com\.microsoft\.codepush\.react\.CodePush(?:\s+as\s+[A-Za-z_]\w*)?|CodePush)\s*;?\s*$/gim, '')
|
|
846
|
+
.replace(/^\s*#\s*import\s*[<"][^>"\n]*CodePush[^>"\n]*[>"]\s*$/gim, '')
|
|
847
|
+
.replace(/^\s*#\s*define\s+[A-Za-z_]\w*\s+CodePush\s*$/gim, '')
|
|
848
|
+
.replace(new RegExp(`\\b(?:${resolverOwners})\\s*\\.\\s*getJSBundleFile\\s*\\([^)]*\\)`, 'gi'), '')
|
|
849
|
+
.replace(new RegExp(`\\b(?:${resolverOwners})\\s*\\.\\s*bundleURL\\s*\\([^)]*\\)`, 'gi'), '')
|
|
850
|
+
.replace(new RegExp(`\\[\\s*(?:${resolverOwners})\\s+bundleURL\\s*\\]`, 'gi'), '');
|
|
851
|
+
};
|
|
852
|
+
const substantiveNativeTokens = (content, codePushAliases = []) => {
|
|
853
|
+
const tokens = [];
|
|
854
|
+
const tokenPattern = /\/\/[^\n]*|\/\*[\s\S]*?\*\/|@?"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|[A-Za-z_]\w*|\d+(?:\.\d+)?/g;
|
|
855
|
+
for (const match of withoutReplaceableCodePushReferences(content, codePushAliases)
|
|
856
|
+
.matchAll(tokenPattern)) {
|
|
857
|
+
const token = match[0];
|
|
858
|
+
if (token.startsWith('//') || token.startsWith('/*'))
|
|
859
|
+
continue;
|
|
860
|
+
tokens.push(token);
|
|
861
|
+
}
|
|
862
|
+
return tokens;
|
|
863
|
+
};
|
|
864
|
+
const preservesSubstantiveNativeTokens = (original, updated, originalCodePushAliases = []) => {
|
|
865
|
+
const originalTokens = substantiveNativeTokens(original, originalCodePushAliases);
|
|
866
|
+
const updatedTokens = substantiveNativeTokens(updated);
|
|
867
|
+
let originalIndex = 0;
|
|
868
|
+
for (const token of updatedTokens) {
|
|
869
|
+
if (token === originalTokens[originalIndex])
|
|
870
|
+
originalIndex += 1;
|
|
871
|
+
}
|
|
872
|
+
return originalIndex === originalTokens.length;
|
|
873
|
+
};
|
|
874
|
+
const findMissingBareNativeStartupStructure = (filePath, original, updated) => {
|
|
875
|
+
const originalCode = (0, native_setup_contract_1.stripCommentsAndStrings)(original);
|
|
876
|
+
const updatedCode = (0, native_setup_contract_1.stripCommentsAndStrings)(updated);
|
|
877
|
+
const originalCodePushAliases = findCodePushAliases(original);
|
|
878
|
+
const retainedCodePushAliases = originalCodePushAliases.filter(alias => new RegExp(`\\b${escapeRegExp(alias)}\\b`).test(updatedCode));
|
|
879
|
+
const substantiveMissing = preservesSubstantiveNativeTokens(original, updated)
|
|
880
|
+
? []
|
|
881
|
+
: ['substantive native code or ordering'];
|
|
882
|
+
if (retainedCodePushAliases.length) {
|
|
883
|
+
substantiveMissing.push('CodePush alias residue');
|
|
884
|
+
}
|
|
885
|
+
if (filePath.includes('MainApplication.')) {
|
|
886
|
+
const missing = [...substantiveMissing];
|
|
887
|
+
const originalStartup = androidStartupMethod(originalCode);
|
|
888
|
+
if (originalStartup) {
|
|
889
|
+
const updatedStartup = androidStartupMethod(updatedCode);
|
|
890
|
+
if (!updatedStartup) {
|
|
891
|
+
missing.push('getJSBundleFile');
|
|
892
|
+
}
|
|
893
|
+
else if (!preservesSubstantiveNativeTokens(originalStartup.method.body, updatedStartup.method.body, originalCodePushAliases)) {
|
|
894
|
+
missing.push('getJSBundleFile/non-CodePush fallback');
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
const originalOwner = findNamedType(originalCode, 'MainApplication');
|
|
898
|
+
if (!originalOwner)
|
|
899
|
+
return missing;
|
|
900
|
+
const updatedOwner = findNamedType(updatedCode, 'MainApplication');
|
|
901
|
+
if (!updatedOwner)
|
|
902
|
+
return [...missing, 'MainApplication'];
|
|
903
|
+
const originalOnCreate = methodsOwnedBy(originalCode, ANDROID_ON_CREATE_METHOD, 'MainApplication')[0];
|
|
904
|
+
if (!originalOnCreate)
|
|
905
|
+
return missing;
|
|
906
|
+
const updatedOnCreate = methodsOwnedBy(updatedCode, ANDROID_ON_CREATE_METHOD, 'MainApplication')[0];
|
|
907
|
+
if (!updatedOnCreate)
|
|
908
|
+
return [...missing, 'onCreate'];
|
|
909
|
+
if (!preservesSubstantiveNativeTokens(originalOnCreate.body, updatedOnCreate.body, originalCodePushAliases)) {
|
|
910
|
+
missing.push('onCreate/substantive behavior');
|
|
911
|
+
}
|
|
912
|
+
return [...missing, ...preservationSignals(originalOnCreate.body, updatedOnCreate.body, [
|
|
913
|
+
{ label: 'onCreate/super.onCreate', token: 'super.onCreate' },
|
|
914
|
+
{ label: 'onCreate/loadReactNative', token: 'loadReactNative' },
|
|
915
|
+
{ label: 'onCreate/SoLoader.init', token: 'SoLoader.init' },
|
|
916
|
+
{
|
|
917
|
+
label: 'onCreate/DefaultNewArchitectureEntryPoint.load',
|
|
918
|
+
token: 'DefaultNewArchitectureEntryPoint.load',
|
|
919
|
+
},
|
|
920
|
+
])];
|
|
921
|
+
}
|
|
922
|
+
if (filePath.endsWith('.swift')) {
|
|
923
|
+
const originalMethod = swiftStartupMethod(originalCode);
|
|
924
|
+
if (!originalMethod)
|
|
925
|
+
return substantiveMissing;
|
|
926
|
+
const updatedMethod = swiftStartupMethod(updatedCode);
|
|
927
|
+
if (!updatedMethod)
|
|
928
|
+
return [...substantiveMissing, 'bundleURL'];
|
|
929
|
+
const missing = [...substantiveMissing];
|
|
930
|
+
if (!preservesSubstantiveNativeTokens(originalMethod.body, updatedMethod.body, originalCodePushAliases)) {
|
|
931
|
+
missing.push('bundleURL/non-CodePush fallback');
|
|
932
|
+
}
|
|
933
|
+
return [...missing, ...preservationSignals(originalMethod.body, updatedMethod.body, [
|
|
934
|
+
{ label: 'bundleURL/RCTBundleURLProvider', token: 'RCTBundleURLProvider' },
|
|
935
|
+
{ label: 'bundleURL/Bundle.main.url', token: 'Bundle.main.url' },
|
|
936
|
+
])];
|
|
937
|
+
}
|
|
938
|
+
const originalStartup = objcStartupMethods(originalCode);
|
|
939
|
+
if (!originalStartup)
|
|
940
|
+
return substantiveMissing;
|
|
941
|
+
const updatedStartup = objcStartupMethods(updatedCode);
|
|
942
|
+
if (!updatedStartup)
|
|
943
|
+
return [...substantiveMissing, 'sourceURLForBridge/bundleURL'];
|
|
944
|
+
const originalBody = [originalStartup.sourceMethod?.body, originalStartup.bundleMethod?.body]
|
|
945
|
+
.filter(Boolean)
|
|
946
|
+
.join('\n');
|
|
947
|
+
const updatedBody = [updatedStartup.sourceMethod?.body, updatedStartup.bundleMethod?.body]
|
|
948
|
+
.filter(Boolean)
|
|
949
|
+
.join('\n');
|
|
950
|
+
const missing = [...substantiveMissing];
|
|
951
|
+
if (!preservesSubstantiveNativeTokens(originalBody, updatedBody, originalCodePushAliases)) {
|
|
952
|
+
missing.push('sourceURLForBridge/bundleURL non-CodePush fallback');
|
|
953
|
+
}
|
|
954
|
+
missing.push(...preservationSignals(originalBody, updatedBody, [
|
|
955
|
+
{ label: 'sourceURL/RCTBundleURLProvider', token: 'RCTBundleURLProvider' },
|
|
956
|
+
{ label: 'sourceURL/NSBundle fallback', token: 'NSBundle mainBundle' },
|
|
957
|
+
]));
|
|
958
|
+
if (originalStartup.sourceMethod?.body.match(OBJC_SELF_BUNDLE_URL_DELEGATION) &&
|
|
959
|
+
!updatedStartup.sourceMethod?.body.match(OBJC_SELF_BUNDLE_URL_DELEGATION)) {
|
|
960
|
+
missing.push('sourceURLForBridge/bundleURL delegation');
|
|
961
|
+
}
|
|
962
|
+
return missing;
|
|
963
|
+
};
|
|
964
|
+
exports.findMissingBareNativeStartupStructure = findMissingBareNativeStartupStructure;
|