@gfean/react-native-bundle-drop 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -4
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +69 -0
- package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
- package/ios/BundleDropBridge.m +18 -0
- package/ios/BundleDropLocator.swift +48 -2
- package/ios/BundleDropModule.swift +75 -0
- package/ios/BundleDropRuntimeCrypto.swift +45 -0
- package/lib/CLI/cli.d.ts +1 -0
- package/lib/CLI/cli.js +54 -2
- 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 +143 -22
- package/lib/CLI/scripts/expo/configure-expo.js +51 -60
- package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
- package/lib/CLI/scripts/expo/package-manager.js +63 -25
- package/lib/CLI/scripts/init-config.d.ts +7 -7
- package/lib/CLI/scripts/init-config.js +185 -10
- package/lib/CLI/scripts/login-cli.js +29 -4
- package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
- package/lib/CLI/scripts/metro-config-authority.js +303 -0
- package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
- package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
- package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
- package/lib/CLI/scripts/native-setup-contract.js +63 -33
- package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
- package/lib/CLI/scripts/native-startup-validator.js +964 -0
- package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
- package/lib/CLI/scripts/safe-file-transaction.js +159 -0
- package/lib/api/clientApi.d.ts +3 -1
- package/lib/api/clientApi.js +14 -0
- package/lib/api/types.d.ts +39 -0
- package/lib/context.d.ts +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/install/installFromZip.d.ts +3 -0
- package/lib/install/installFromZip.js +10 -1
- package/lib/loadConfig.d.ts +17 -1
- package/lib/loadConfig.js +16 -0
- package/lib/manager/downloadAndInstall.d.ts +3 -2
- package/lib/manager/downloadAndInstall.js +111 -46
- package/lib/manager/rollbackState.d.ts +3 -1
- package/lib/manager/rollbackState.js +2 -2
- package/lib/manager/updateCheck.d.ts +1 -0
- package/lib/manager/updateCheck.js +218 -78
- package/lib/metro.d.ts +8 -1
- package/lib/metro.js +68 -19
- package/lib/native/bundleDropNative.js +2 -1
- package/lib/native/fs.d.ts +6 -0
- package/lib/native/fs.js +24 -0
- package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
- package/lib/patch-engine/installFromPatchSet.js +14 -3
- package/lib/patch-engine/patchTransport.d.ts +2 -0
- package/lib/patch-engine/patchTransport.js +9 -0
- package/lib/runtime/initState.d.ts +5 -0
- package/lib/runtime/initState.js +4 -0
- package/lib/runtime/service.js +60 -3
- package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
- package/lib/runtime-delivery/artifactCapability.js +32 -0
- package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
- package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
- package/lib/runtime-delivery/bootstrapConfig.d.ts +50 -0
- package/lib/runtime-delivery/bootstrapConfig.js +217 -0
- package/lib/runtime-delivery/diagnostics.d.ts +17 -0
- package/lib/runtime-delivery/diagnostics.js +58 -0
- package/lib/runtime-delivery/encoding.d.ts +5 -0
- package/lib/runtime-delivery/encoding.js +132 -0
- package/lib/runtime-delivery/heartbeat.d.ts +3 -0
- package/lib/runtime-delivery/heartbeat.js +88 -0
- package/lib/runtime-delivery/localResolver.d.ts +23 -0
- package/lib/runtime-delivery/localResolver.js +81 -0
- package/lib/runtime-delivery/manifestState.d.ts +9 -0
- package/lib/runtime-delivery/manifestState.js +102 -0
- package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
- package/lib/runtime-delivery/manifestVerifier.js +329 -0
- package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
- package/lib/runtime-delivery/runtimeDelivery.js +375 -0
- package/lib/runtime-delivery/types.d.ts +87 -0
- package/lib/runtime-delivery/types.js +6 -0
- package/package.json +2 -2
|
@@ -7,9 +7,10 @@ exports.isPatchableExpoConfig = exports.isPatchableNativeEntrypoint = exports.is
|
|
|
7
7
|
exports.validateSetupChangesBeforeApply = validateSetupChangesBeforeApply;
|
|
8
8
|
exports.validateAppliedSetupChanges = validateAppliedSetupChanges;
|
|
9
9
|
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const safe_file_transaction_1 = require("../safe-file-transaction");
|
|
11
|
+
const native_entrypoint_authority_1 = require("../native-entrypoint-authority");
|
|
12
12
|
const native_setup_contract_1 = require("../native-setup-contract");
|
|
13
|
+
const terminal_safety_1 = require("./terminal-safety");
|
|
13
14
|
const sha256 = (content) => crypto_1.default.createHash('sha256').update(content).digest('hex');
|
|
14
15
|
const isSafeRelativePath = (value) => {
|
|
15
16
|
if (!value || value.startsWith('/') || value.includes('\\'))
|
|
@@ -25,11 +26,14 @@ const isPatchableExpoConfig = (filePath) => filePath === 'app.json' ||
|
|
|
25
26
|
/^app\.config\.(js|ts|cjs|mjs)$/.test(filePath) ||
|
|
26
27
|
/^metro\.config\.(js|ts|cjs|mjs)$/.test(filePath);
|
|
27
28
|
exports.isPatchableExpoConfig = isPatchableExpoConfig;
|
|
28
|
-
const hasBalancedPairs = (content) => {
|
|
29
|
+
const hasBalancedPairs = (content, isDynamicExpoConfig) => {
|
|
29
30
|
const pairs = { ')': '(', '}': '{', ']': '[' };
|
|
30
31
|
const opens = new Set(Object.values(pairs));
|
|
31
32
|
const stack = [];
|
|
32
|
-
|
|
33
|
+
const structure = isDynamicExpoConfig
|
|
34
|
+
? maskStringAndRegexLiterals((0, native_setup_contract_1.stripComments)(content))
|
|
35
|
+
: (0, native_setup_contract_1.stripCommentsAndStrings)(content);
|
|
36
|
+
for (const char of structure) {
|
|
33
37
|
if (opens.has(char))
|
|
34
38
|
stack.push(char);
|
|
35
39
|
if (pairs[char] && stack.pop() !== pairs[char])
|
|
@@ -43,6 +47,1021 @@ const hasAndroidBundleDropIntegration = (content) => {
|
|
|
43
47
|
const hasIosBundleDropIntegration = (filePath, content) => {
|
|
44
48
|
return (0, native_setup_contract_1.hasBareIosStartupIntegration)(filePath, content);
|
|
45
49
|
};
|
|
50
|
+
const findBalancedDelimiterEnd = (source, openingIndex, opening, closing) => {
|
|
51
|
+
let depth = 0;
|
|
52
|
+
let quote = '';
|
|
53
|
+
let escaped = false;
|
|
54
|
+
for (let index = openingIndex; index < source.length; index += 1) {
|
|
55
|
+
const character = source[index];
|
|
56
|
+
if (quote) {
|
|
57
|
+
if (escaped)
|
|
58
|
+
escaped = false;
|
|
59
|
+
else if (character === '\\')
|
|
60
|
+
escaped = true;
|
|
61
|
+
else if (character === quote)
|
|
62
|
+
quote = '';
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (character === '"' || character === "'" || character === '`') {
|
|
66
|
+
quote = character;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (character === opening)
|
|
70
|
+
depth += 1;
|
|
71
|
+
if (character === closing)
|
|
72
|
+
depth -= 1;
|
|
73
|
+
if (depth === 0)
|
|
74
|
+
return index;
|
|
75
|
+
}
|
|
76
|
+
return -1;
|
|
77
|
+
};
|
|
78
|
+
const topLevelCommaRanges = (source, start, end) => {
|
|
79
|
+
const ranges = [];
|
|
80
|
+
let entryStart = start;
|
|
81
|
+
const stack = [];
|
|
82
|
+
let quote = '';
|
|
83
|
+
let escaped = false;
|
|
84
|
+
for (let index = start; index < end; index += 1) {
|
|
85
|
+
const character = source[index];
|
|
86
|
+
if (quote) {
|
|
87
|
+
if (escaped)
|
|
88
|
+
escaped = false;
|
|
89
|
+
else if (character === '\\')
|
|
90
|
+
escaped = true;
|
|
91
|
+
else if (character === quote)
|
|
92
|
+
quote = '';
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (character === '"' || character === "'" || character === '`') {
|
|
96
|
+
quote = character;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if ('[({'.includes(character))
|
|
100
|
+
stack.push(character);
|
|
101
|
+
else if (']})'.includes(character))
|
|
102
|
+
stack.pop();
|
|
103
|
+
else if (character === ',' && !stack.length) {
|
|
104
|
+
ranges.push({ start: entryStart, end: index + 1 });
|
|
105
|
+
entryStart = index + 1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
ranges.push({ start: entryStart, end });
|
|
109
|
+
return ranges;
|
|
110
|
+
};
|
|
111
|
+
const canStartRegexLiteral = (source, slashIndex) => {
|
|
112
|
+
const prefix = source.slice(0, slashIndex).trimEnd();
|
|
113
|
+
if (!prefix)
|
|
114
|
+
return true;
|
|
115
|
+
const previousCharacter = prefix[prefix.length - 1];
|
|
116
|
+
if (/^[=([{,:;!?&|+\-*%^~<>]$/.test(previousCharacter))
|
|
117
|
+
return true;
|
|
118
|
+
const previousWord = prefix.match(/([A-Za-z_$][\w$]*)$/)?.[1];
|
|
119
|
+
return Boolean(previousWord && [
|
|
120
|
+
'await',
|
|
121
|
+
'case',
|
|
122
|
+
'delete',
|
|
123
|
+
'do',
|
|
124
|
+
'else',
|
|
125
|
+
'in',
|
|
126
|
+
'instanceof',
|
|
127
|
+
'new',
|
|
128
|
+
'of',
|
|
129
|
+
'return',
|
|
130
|
+
'throw',
|
|
131
|
+
'typeof',
|
|
132
|
+
'void',
|
|
133
|
+
'yield',
|
|
134
|
+
].includes(previousWord));
|
|
135
|
+
};
|
|
136
|
+
const maskStringAndRegexLiterals = (source) => {
|
|
137
|
+
const characters = source.split('');
|
|
138
|
+
let quote = '';
|
|
139
|
+
let escaped = false;
|
|
140
|
+
let regexCharacterClass = false;
|
|
141
|
+
let templateExpressionDepth = 0;
|
|
142
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
143
|
+
const character = source[index];
|
|
144
|
+
if (quote === '/') {
|
|
145
|
+
if (character !== '\n')
|
|
146
|
+
characters[index] = ' ';
|
|
147
|
+
if (escaped)
|
|
148
|
+
escaped = false;
|
|
149
|
+
else if (character === '\\')
|
|
150
|
+
escaped = true;
|
|
151
|
+
else if (character === '[')
|
|
152
|
+
regexCharacterClass = true;
|
|
153
|
+
else if (character === ']')
|
|
154
|
+
regexCharacterClass = false;
|
|
155
|
+
else if (character === '/' && !regexCharacterClass)
|
|
156
|
+
quote = '';
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (quote === '`') {
|
|
160
|
+
if (character !== '\n')
|
|
161
|
+
characters[index] = ' ';
|
|
162
|
+
if (escaped)
|
|
163
|
+
escaped = false;
|
|
164
|
+
else if (character === '\\')
|
|
165
|
+
escaped = true;
|
|
166
|
+
else if (character === '`')
|
|
167
|
+
quote = '';
|
|
168
|
+
else if (character === '$' && source[index + 1] === '{') {
|
|
169
|
+
characters[index + 1] = ' ';
|
|
170
|
+
templateExpressionDepth += 1;
|
|
171
|
+
quote = '';
|
|
172
|
+
index += 1;
|
|
173
|
+
}
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (quote) {
|
|
177
|
+
if (character !== '\n')
|
|
178
|
+
characters[index] = ' ';
|
|
179
|
+
if (escaped)
|
|
180
|
+
escaped = false;
|
|
181
|
+
else if (character === '\\')
|
|
182
|
+
escaped = true;
|
|
183
|
+
else if (character === quote)
|
|
184
|
+
quote = '';
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (templateExpressionDepth > 0 && character === '{') {
|
|
188
|
+
templateExpressionDepth += 1;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (templateExpressionDepth > 0 && character === '}') {
|
|
192
|
+
templateExpressionDepth -= 1;
|
|
193
|
+
if (templateExpressionDepth === 0) {
|
|
194
|
+
characters[index] = ' ';
|
|
195
|
+
quote = '`';
|
|
196
|
+
}
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (character === '"' || character === "'" || character === '`') {
|
|
200
|
+
quote = character;
|
|
201
|
+
characters[index] = ' ';
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (character === '/' && canStartRegexLiteral(source, index)) {
|
|
205
|
+
quote = '/';
|
|
206
|
+
regexCharacterClass = false;
|
|
207
|
+
characters[index] = ' ';
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return characters.join('');
|
|
211
|
+
};
|
|
212
|
+
const maskCommentsPreservingLength = (source) => {
|
|
213
|
+
const characters = source.split('');
|
|
214
|
+
let state = 'code';
|
|
215
|
+
let escaped = false;
|
|
216
|
+
let blockCommentDepth = 0;
|
|
217
|
+
let regexCharacterClass = false;
|
|
218
|
+
let templateExpressionDepth = 0;
|
|
219
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
220
|
+
const character = source[index];
|
|
221
|
+
const nextCharacter = source[index + 1];
|
|
222
|
+
if (state === 'line-comment') {
|
|
223
|
+
if (character === '\n')
|
|
224
|
+
state = 'code';
|
|
225
|
+
else if (character !== '\r')
|
|
226
|
+
characters[index] = ' ';
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (state === 'block-comment') {
|
|
230
|
+
if (character !== '\n' && character !== '\r')
|
|
231
|
+
characters[index] = ' ';
|
|
232
|
+
if (character === '/' && nextCharacter === '*') {
|
|
233
|
+
characters[index + 1] = ' ';
|
|
234
|
+
blockCommentDepth += 1;
|
|
235
|
+
index += 1;
|
|
236
|
+
}
|
|
237
|
+
else if (character === '*' && nextCharacter === '/') {
|
|
238
|
+
characters[index + 1] = ' ';
|
|
239
|
+
blockCommentDepth -= 1;
|
|
240
|
+
index += 1;
|
|
241
|
+
if (blockCommentDepth === 0)
|
|
242
|
+
state = 'code';
|
|
243
|
+
}
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (state === 'regex') {
|
|
247
|
+
if (escaped)
|
|
248
|
+
escaped = false;
|
|
249
|
+
else if (character === '\\')
|
|
250
|
+
escaped = true;
|
|
251
|
+
else if (character === '[')
|
|
252
|
+
regexCharacterClass = true;
|
|
253
|
+
else if (character === ']')
|
|
254
|
+
regexCharacterClass = false;
|
|
255
|
+
else if (character === '/' && !regexCharacterClass)
|
|
256
|
+
state = 'code';
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (state === 'template') {
|
|
260
|
+
if (escaped)
|
|
261
|
+
escaped = false;
|
|
262
|
+
else if (character === '\\')
|
|
263
|
+
escaped = true;
|
|
264
|
+
else if (character === '`')
|
|
265
|
+
state = 'code';
|
|
266
|
+
else if (character === '$' && nextCharacter === '{') {
|
|
267
|
+
templateExpressionDepth = 1;
|
|
268
|
+
state = 'code';
|
|
269
|
+
index += 1;
|
|
270
|
+
}
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (state === 'single' || state === 'double') {
|
|
274
|
+
if (escaped)
|
|
275
|
+
escaped = false;
|
|
276
|
+
else if (character === '\\')
|
|
277
|
+
escaped = true;
|
|
278
|
+
else if ((state === 'single' && character === "'") ||
|
|
279
|
+
(state === 'double' && character === '"')) {
|
|
280
|
+
state = 'code';
|
|
281
|
+
}
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (templateExpressionDepth > 0 && character === '{') {
|
|
285
|
+
templateExpressionDepth += 1;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (templateExpressionDepth > 0 && character === '}') {
|
|
289
|
+
templateExpressionDepth -= 1;
|
|
290
|
+
if (templateExpressionDepth === 0)
|
|
291
|
+
state = 'template';
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (character === '/' && nextCharacter === '/') {
|
|
295
|
+
characters[index] = ' ';
|
|
296
|
+
characters[index + 1] = ' ';
|
|
297
|
+
state = 'line-comment';
|
|
298
|
+
index += 1;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (character === '/' && nextCharacter === '*') {
|
|
302
|
+
characters[index] = ' ';
|
|
303
|
+
characters[index + 1] = ' ';
|
|
304
|
+
state = 'block-comment';
|
|
305
|
+
blockCommentDepth = 1;
|
|
306
|
+
index += 1;
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (character === "'")
|
|
310
|
+
state = 'single';
|
|
311
|
+
else if (character === '"')
|
|
312
|
+
state = 'double';
|
|
313
|
+
else if (character === '`')
|
|
314
|
+
state = 'template';
|
|
315
|
+
else if (character === '/' && canStartRegexLiteral(source, index)) {
|
|
316
|
+
state = 'regex';
|
|
317
|
+
regexCharacterClass = false;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return characters.join('');
|
|
321
|
+
};
|
|
322
|
+
const skipWhitespace = (source, start) => {
|
|
323
|
+
let cursor = start;
|
|
324
|
+
while (/\s/.test(source[cursor] || ''))
|
|
325
|
+
cursor += 1;
|
|
326
|
+
return cursor;
|
|
327
|
+
};
|
|
328
|
+
const CANONICAL_ARROW_FUNCTION_SIGNATURE = /^(?:async\s*)?(?:[A-Za-z_$][\w$]*|\([\s\S]*\))(?:\s*:\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*(?:\s*<[^;={}]*>)?)?$/;
|
|
329
|
+
const endsAtTerminalStatement = (structure, start) => {
|
|
330
|
+
let cursor = skipWhitespace(structure, start);
|
|
331
|
+
if (structure[cursor] === ';')
|
|
332
|
+
cursor = skipWhitespace(structure, cursor + 1);
|
|
333
|
+
return cursor === structure.length;
|
|
334
|
+
};
|
|
335
|
+
const isUnconditionalTopLevelExport = (source, structure, exportIndex) => {
|
|
336
|
+
const stack = [];
|
|
337
|
+
let statementStart = 0;
|
|
338
|
+
for (let index = 0; index < exportIndex; index += 1) {
|
|
339
|
+
const character = structure[index];
|
|
340
|
+
if ('[({'.includes(character))
|
|
341
|
+
stack.push(character);
|
|
342
|
+
else if (']})'.includes(character))
|
|
343
|
+
stack.pop();
|
|
344
|
+
else if (character === ';' && !stack.length)
|
|
345
|
+
statementStart = index + 1;
|
|
346
|
+
else if (character === '\n' && !stack.length) {
|
|
347
|
+
const statement = structure.slice(statementStart, index).trim();
|
|
348
|
+
const sourceStatement = source.slice(statementStart, index).trim();
|
|
349
|
+
let nextTokenIndex = index + 1;
|
|
350
|
+
while (/\s/.test(source[nextTokenIndex] || ''))
|
|
351
|
+
nextTokenIndex += 1;
|
|
352
|
+
if (/^(?:const|let|var|import)\b/.test(statement) &&
|
|
353
|
+
!/[=([{,:!?&|+\-*%^~<>.]$/.test(sourceStatement) &&
|
|
354
|
+
!startsJavaScriptExpressionContinuation(source, nextTokenIndex)) {
|
|
355
|
+
statementStart = index + 1;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return !stack.length && !structure.slice(statementStart, exportIndex).trim();
|
|
360
|
+
};
|
|
361
|
+
const returnedObjectFromArrowBlock = (structure, blockOpening) => {
|
|
362
|
+
const blockClosing = findBalancedDelimiterEnd(structure, blockOpening, '{', '}');
|
|
363
|
+
if (blockClosing < 0)
|
|
364
|
+
return null;
|
|
365
|
+
const stack = [];
|
|
366
|
+
const returnIndices = [];
|
|
367
|
+
let statementStart = blockOpening + 1;
|
|
368
|
+
for (let index = blockOpening + 1; index < blockClosing; index += 1) {
|
|
369
|
+
const character = structure[index];
|
|
370
|
+
if ('[({'.includes(character))
|
|
371
|
+
stack.push(character);
|
|
372
|
+
else if (']})'.includes(character))
|
|
373
|
+
stack.pop();
|
|
374
|
+
else if (character === ';' && !stack.length)
|
|
375
|
+
statementStart = index + 1;
|
|
376
|
+
else if (!stack.length &&
|
|
377
|
+
structure.startsWith('return', index) &&
|
|
378
|
+
!/[\w$]/.test(structure[index - 1] || '') &&
|
|
379
|
+
!/[\w$]/.test(structure[index + 'return'.length] || '') &&
|
|
380
|
+
!structure.slice(statementStart, index).trim()) {
|
|
381
|
+
returnIndices.push(index);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (returnIndices.length !== 1)
|
|
385
|
+
return null;
|
|
386
|
+
let cursor = skipWhitespace(structure, returnIndices[0] + 'return'.length);
|
|
387
|
+
let parentheses = 0;
|
|
388
|
+
while (structure[cursor] === '(') {
|
|
389
|
+
parentheses += 1;
|
|
390
|
+
cursor = skipWhitespace(structure, cursor + 1);
|
|
391
|
+
}
|
|
392
|
+
if (structure[cursor] !== '{')
|
|
393
|
+
return null;
|
|
394
|
+
const opening = cursor;
|
|
395
|
+
const closing = findBalancedDelimiterEnd(structure, opening, '{', '}');
|
|
396
|
+
if (closing < 0 || closing > blockClosing)
|
|
397
|
+
return null;
|
|
398
|
+
cursor = skipWhitespace(structure, closing + 1);
|
|
399
|
+
while (parentheses > 0 && structure[cursor] === ')') {
|
|
400
|
+
parentheses -= 1;
|
|
401
|
+
cursor = skipWhitespace(structure, cursor + 1);
|
|
402
|
+
}
|
|
403
|
+
if (parentheses > 0)
|
|
404
|
+
return null;
|
|
405
|
+
if (structure[cursor] === ';')
|
|
406
|
+
cursor = skipWhitespace(structure, cursor + 1);
|
|
407
|
+
if (cursor !== blockClosing)
|
|
408
|
+
return null;
|
|
409
|
+
return { opening, closing, blockClosing };
|
|
410
|
+
};
|
|
411
|
+
const rootConfigObjectRange = (source) => {
|
|
412
|
+
const structure = maskStringAndRegexLiterals(source);
|
|
413
|
+
const exportAssignments = [...structure.matchAll(/\b(?:export\s+default|module\s*\.\s*exports\s*=)/g)];
|
|
414
|
+
if (exportAssignments.length !== 1)
|
|
415
|
+
return null;
|
|
416
|
+
const [exportAssignment] = exportAssignments;
|
|
417
|
+
const exportIndex = exportAssignment.index || 0;
|
|
418
|
+
if (!isUnconditionalTopLevelExport(source, structure, exportIndex))
|
|
419
|
+
return null;
|
|
420
|
+
let cursor = (exportAssignment.index || 0) + exportAssignment[0].length;
|
|
421
|
+
cursor = skipWhitespace(structure, cursor);
|
|
422
|
+
if (structure[cursor] === '{') {
|
|
423
|
+
const closing = findBalancedDelimiterEnd(structure, cursor, '{', '}');
|
|
424
|
+
return closing >= 0 && endsAtTerminalStatement(structure, closing + 1)
|
|
425
|
+
? { opening: cursor, closing }
|
|
426
|
+
: null;
|
|
427
|
+
}
|
|
428
|
+
const stack = [];
|
|
429
|
+
let arrow = -1;
|
|
430
|
+
for (let index = cursor; index < structure.length - 1; index += 1) {
|
|
431
|
+
const character = structure[index];
|
|
432
|
+
if ('[({'.includes(character))
|
|
433
|
+
stack.push(character);
|
|
434
|
+
else if (']})'.includes(character))
|
|
435
|
+
stack.pop();
|
|
436
|
+
else if (character === ';' && !stack.length)
|
|
437
|
+
return null;
|
|
438
|
+
else if (character === '=' && structure[index + 1] === '>' && !stack.length) {
|
|
439
|
+
arrow = index;
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (arrow < 0)
|
|
444
|
+
return null;
|
|
445
|
+
const parameters = structure.slice(cursor, arrow).trim();
|
|
446
|
+
if (!CANONICAL_ARROW_FUNCTION_SIGNATURE.test(parameters))
|
|
447
|
+
return null;
|
|
448
|
+
cursor = skipWhitespace(structure, arrow + 2);
|
|
449
|
+
if (structure[cursor] === '{') {
|
|
450
|
+
const returned = returnedObjectFromArrowBlock(structure, cursor);
|
|
451
|
+
if (!returned || !endsAtTerminalStatement(structure, returned.blockClosing + 1))
|
|
452
|
+
return null;
|
|
453
|
+
return { opening: returned.opening, closing: returned.closing };
|
|
454
|
+
}
|
|
455
|
+
let parentheses = 0;
|
|
456
|
+
while (structure[cursor] === '(') {
|
|
457
|
+
parentheses += 1;
|
|
458
|
+
cursor = skipWhitespace(structure, cursor + 1);
|
|
459
|
+
}
|
|
460
|
+
if (!parentheses || structure[cursor] !== '{')
|
|
461
|
+
return null;
|
|
462
|
+
const opening = cursor;
|
|
463
|
+
const closing = findBalancedDelimiterEnd(structure, opening, '{', '}');
|
|
464
|
+
if (closing < 0)
|
|
465
|
+
return null;
|
|
466
|
+
cursor = skipWhitespace(structure, closing + 1);
|
|
467
|
+
while (parentheses > 0 && structure[cursor] === ')') {
|
|
468
|
+
parentheses -= 1;
|
|
469
|
+
cursor = skipWhitespace(structure, cursor + 1);
|
|
470
|
+
}
|
|
471
|
+
return parentheses === 0 && endsAtTerminalStatement(structure, cursor)
|
|
472
|
+
? { opening, closing }
|
|
473
|
+
: null;
|
|
474
|
+
};
|
|
475
|
+
const decodeJavaScriptStringLiteral = (expression) => {
|
|
476
|
+
const quote = expression[0];
|
|
477
|
+
if (!['"', "'", '`'].includes(quote) || expression[expression.length - 1] !== quote) {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
const body = expression.slice(1, -1);
|
|
481
|
+
if (quote === '`') {
|
|
482
|
+
for (let index = 0; index < body.length - 1; index += 1) {
|
|
483
|
+
if (body[index] !== '$' || body[index + 1] !== '{')
|
|
484
|
+
continue;
|
|
485
|
+
let backslashes = 0;
|
|
486
|
+
for (let cursor = index - 1; cursor >= 0 && body[cursor] === '\\'; cursor -= 1) {
|
|
487
|
+
backslashes += 1;
|
|
488
|
+
}
|
|
489
|
+
if (backslashes % 2 === 0)
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
let decoded = '';
|
|
494
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
495
|
+
const character = body[index];
|
|
496
|
+
if (character === quote)
|
|
497
|
+
return null;
|
|
498
|
+
if (character !== '\\') {
|
|
499
|
+
decoded += character;
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
index += 1;
|
|
503
|
+
if (index >= body.length)
|
|
504
|
+
return null;
|
|
505
|
+
const escaped = body[index];
|
|
506
|
+
if (escaped === '\n')
|
|
507
|
+
continue;
|
|
508
|
+
if (escaped === '\r') {
|
|
509
|
+
if (body[index + 1] === '\n')
|
|
510
|
+
index += 1;
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
if (escaped === 'u') {
|
|
514
|
+
const braced = /^\{([0-9A-Fa-f]{1,6})\}/.exec(body.slice(index + 1));
|
|
515
|
+
if (braced) {
|
|
516
|
+
const codePoint = Number.parseInt(braced[1], 16);
|
|
517
|
+
if (codePoint > 0x10ffff)
|
|
518
|
+
return null;
|
|
519
|
+
decoded += String.fromCodePoint(codePoint);
|
|
520
|
+
index += braced[0].length;
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
const unicode = /^[0-9A-Fa-f]{4}/.exec(body.slice(index + 1));
|
|
524
|
+
if (!unicode)
|
|
525
|
+
return null;
|
|
526
|
+
decoded += String.fromCharCode(Number.parseInt(unicode[0], 16));
|
|
527
|
+
index += unicode[0].length;
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
if (escaped === 'x') {
|
|
531
|
+
const hex = /^[0-9A-Fa-f]{2}/.exec(body.slice(index + 1));
|
|
532
|
+
if (!hex)
|
|
533
|
+
return null;
|
|
534
|
+
decoded += String.fromCharCode(Number.parseInt(hex[0], 16));
|
|
535
|
+
index += hex[0].length;
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
if (/[0-7]/.test(escaped)) {
|
|
539
|
+
const octal = new RegExp(`^${escaped}[0-7]{0,2}`).exec(body.slice(index));
|
|
540
|
+
if (!octal)
|
|
541
|
+
return null;
|
|
542
|
+
decoded += String.fromCharCode(Number.parseInt(octal[0], 8));
|
|
543
|
+
index += octal[0].length - 1;
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
const simpleEscapes = {
|
|
547
|
+
b: '\b',
|
|
548
|
+
f: '\f',
|
|
549
|
+
n: '\n',
|
|
550
|
+
r: '\r',
|
|
551
|
+
t: '\t',
|
|
552
|
+
v: '\v',
|
|
553
|
+
};
|
|
554
|
+
decoded += simpleEscapes[escaped] ?? escaped;
|
|
555
|
+
}
|
|
556
|
+
return decoded;
|
|
557
|
+
};
|
|
558
|
+
const resolveConstantStringExpression = (expression, bindings) => {
|
|
559
|
+
let candidate = expression.trim();
|
|
560
|
+
candidate = candidate.replace(/\s+(?:(?:as\s+(?:const|string))|(?:satisfies\s+string))\s*$/, '').trim();
|
|
561
|
+
while (candidate.startsWith('(')) {
|
|
562
|
+
const structure = maskStringAndRegexLiterals(candidate);
|
|
563
|
+
const closing = findBalancedDelimiterEnd(structure, 0, '(', ')');
|
|
564
|
+
if (closing !== candidate.length - 1)
|
|
565
|
+
break;
|
|
566
|
+
candidate = candidate.slice(1, -1).trim();
|
|
567
|
+
}
|
|
568
|
+
const literal = decodeJavaScriptStringLiteral(candidate);
|
|
569
|
+
if (literal !== null)
|
|
570
|
+
return literal;
|
|
571
|
+
if (/^[A-Za-z_$][\w$]*$/.test(candidate))
|
|
572
|
+
return bindings.get(candidate) ?? null;
|
|
573
|
+
const structure = maskStringAndRegexLiterals(candidate);
|
|
574
|
+
const ranges = [];
|
|
575
|
+
const stack = [];
|
|
576
|
+
let start = 0;
|
|
577
|
+
for (let index = 0; index < structure.length; index += 1) {
|
|
578
|
+
const character = structure[index];
|
|
579
|
+
if ('[({'.includes(character))
|
|
580
|
+
stack.push(character);
|
|
581
|
+
else if (']})'.includes(character))
|
|
582
|
+
stack.pop();
|
|
583
|
+
else if (character === '+' && !stack.length) {
|
|
584
|
+
ranges.push({ start, end: index });
|
|
585
|
+
start = index + 1;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (!ranges.length)
|
|
589
|
+
return null;
|
|
590
|
+
ranges.push({ start, end: candidate.length });
|
|
591
|
+
const values = ranges.map(range => resolveConstantStringExpression(candidate.slice(range.start, range.end), bindings));
|
|
592
|
+
return values.every((value) => value !== null) ? values.join('') : null;
|
|
593
|
+
};
|
|
594
|
+
const startsJavaScriptExpressionContinuation = (source, start) => {
|
|
595
|
+
const remainder = source.slice(start);
|
|
596
|
+
if (/^(?:instanceof|in|as|satisfies)\b/.test(remainder))
|
|
597
|
+
return true;
|
|
598
|
+
return /^(?:\?\.|\?\?|&&|\|\||\*\*|===|!==|==|!=|=>|<<|>>>?|<=|>=|[+\-*/%&|^<>=?.[(,`])/.test(remainder);
|
|
599
|
+
};
|
|
600
|
+
const collectConstantStringBindings = (commentFreeSource) => {
|
|
601
|
+
const structure = maskStringAndRegexLiterals(commentFreeSource);
|
|
602
|
+
const values = new Map();
|
|
603
|
+
const ambiguousAuthorityNames = new Set();
|
|
604
|
+
for (const match of structure.matchAll(/\bconst\s+([A-Za-z_$][\w$]*)(?:\s*:\s*string)?\s*=/g)) {
|
|
605
|
+
const matchIndex = match.index || 0;
|
|
606
|
+
const stack = [];
|
|
607
|
+
for (let index = 0; index < matchIndex; index += 1) {
|
|
608
|
+
const character = structure[index];
|
|
609
|
+
if ('[({'.includes(character))
|
|
610
|
+
stack.push(character);
|
|
611
|
+
else if (']})'.includes(character))
|
|
612
|
+
stack.pop();
|
|
613
|
+
}
|
|
614
|
+
if (stack.length)
|
|
615
|
+
continue;
|
|
616
|
+
const expressionStart = matchIndex + match[0].length;
|
|
617
|
+
let expressionEnd = structure.length;
|
|
618
|
+
const expressionStack = [];
|
|
619
|
+
for (let index = expressionStart; index < structure.length; index += 1) {
|
|
620
|
+
const character = structure[index];
|
|
621
|
+
if ('[({'.includes(character))
|
|
622
|
+
expressionStack.push(character);
|
|
623
|
+
else if (']})'.includes(character))
|
|
624
|
+
expressionStack.pop();
|
|
625
|
+
else if (character === ';' && !expressionStack.length) {
|
|
626
|
+
expressionEnd = index;
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
else if (character === '\n' && !expressionStack.length) {
|
|
630
|
+
const expression = commentFreeSource.slice(expressionStart, index).trim();
|
|
631
|
+
let nextTokenIndex = index + 1;
|
|
632
|
+
while (/\s/.test(commentFreeSource[nextTokenIndex] || ''))
|
|
633
|
+
nextTokenIndex += 1;
|
|
634
|
+
const continuesExpression = startsJavaScriptExpressionContinuation(commentFreeSource, nextTokenIndex);
|
|
635
|
+
if (expression &&
|
|
636
|
+
!/[=([{,:!?&|+\-*%^~<>.]$/.test(expression) &&
|
|
637
|
+
!continuesExpression) {
|
|
638
|
+
expressionEnd = index;
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const expression = commentFreeSource.slice(expressionStart, expressionEnd);
|
|
644
|
+
const value = resolveConstantStringExpression(expression, values);
|
|
645
|
+
if (value !== null)
|
|
646
|
+
values.set(match[1], value);
|
|
647
|
+
else if (decodedExpressionMayReferenceSetupAuthority(expression) ||
|
|
648
|
+
[...ambiguousAuthorityNames].some(name => {
|
|
649
|
+
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
650
|
+
return new RegExp(`(^|[^\\w$])${escapedName}([^\\w$]|$)`).test(expression);
|
|
651
|
+
})) {
|
|
652
|
+
ambiguousAuthorityNames.add(match[1]);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return { values, ambiguousAuthorityNames };
|
|
656
|
+
};
|
|
657
|
+
const pluginEntryExpression = (entry) => {
|
|
658
|
+
if (!entry.startsWith('['))
|
|
659
|
+
return entry;
|
|
660
|
+
const structure = maskStringAndRegexLiterals(entry);
|
|
661
|
+
const closing = findBalancedDelimiterEnd(structure, 0, '[', ']');
|
|
662
|
+
if (closing !== entry.length - 1)
|
|
663
|
+
return null;
|
|
664
|
+
const [firstTupleEntry] = topLevelCommaRanges(structure, 1, closing);
|
|
665
|
+
return firstTupleEntry
|
|
666
|
+
? entry.slice(firstTupleEntry.start, firstTupleEntry.end).replace(/,\s*$/, '').trim()
|
|
667
|
+
: null;
|
|
668
|
+
};
|
|
669
|
+
const decodedExpressionMayReferenceSetupAuthority = (expression) => {
|
|
670
|
+
const decodedEscapes = expression
|
|
671
|
+
.replace(/\\u\{([0-9A-Fa-f]{1,6})\}/g, (_match, value) => String.fromCodePoint(Number.parseInt(value, 16)))
|
|
672
|
+
.replace(/\\u([0-9A-Fa-f]{4})/g, (_match, value) => String.fromCharCode(Number.parseInt(value, 16)))
|
|
673
|
+
.replace(/\\x([0-9A-Fa-f]{2})/g, (_match, value) => String.fromCharCode(Number.parseInt(value, 16)))
|
|
674
|
+
.replace(/\\([0-7]{1,3})/g, (_match, value) => String.fromCharCode(Number.parseInt(value, 8)));
|
|
675
|
+
const compact = decodedEscapes.toLowerCase().replace(/[\s'"`+${}()[\]\\]/g, '');
|
|
676
|
+
return compact.includes('expo-updates') ||
|
|
677
|
+
compact.includes('@gfean/react-native-bundle-drop');
|
|
678
|
+
};
|
|
679
|
+
const resolvePluginEntry = (entry, bindings) => {
|
|
680
|
+
const expression = pluginEntryExpression(entry);
|
|
681
|
+
if (!expression)
|
|
682
|
+
return { packageName: null, ambiguousAuthority: true };
|
|
683
|
+
const packageName = resolveConstantStringExpression(expression, bindings.values);
|
|
684
|
+
return {
|
|
685
|
+
packageName,
|
|
686
|
+
ambiguousAuthority: packageName === null && (decodedExpressionMayReferenceSetupAuthority(expression) ||
|
|
687
|
+
bindings.ambiguousAuthorityNames.has(expression)),
|
|
688
|
+
};
|
|
689
|
+
};
|
|
690
|
+
const isCanonicalExistingPluginsSpread = (entry) => /^\.\.\.\s*\(\s*config\s*\.\s*plugins\s*(?:\|\||\?\?)\s*\[\s*\]\s*\)$/.test(entry);
|
|
691
|
+
const decodeJavaScriptIdentifier = (identifier) => {
|
|
692
|
+
const decoded = identifier
|
|
693
|
+
.replace(/\\u\{([0-9A-Fa-f]{1,6})\}/g, (_match, value) => {
|
|
694
|
+
const codePoint = Number.parseInt(value, 16);
|
|
695
|
+
return codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : '';
|
|
696
|
+
})
|
|
697
|
+
.replace(/\\u([0-9A-Fa-f]{4})/g, (_match, value) => String.fromCharCode(Number.parseInt(value, 16)));
|
|
698
|
+
return /^[A-Za-z_$][\w$]*$/.test(decoded) ? decoded : null;
|
|
699
|
+
};
|
|
700
|
+
const directPropertyDefinition = (field) => {
|
|
701
|
+
const leadingWhitespace = field.match(/^\s*/)?.[0].length ?? 0;
|
|
702
|
+
const candidate = field.slice(leadingWhitespace);
|
|
703
|
+
const named = /^((?:[A-Za-z_$]|\\u(?:\{[0-9A-Fa-f]{1,6}\}|[0-9A-Fa-f]{4}))(?:[\w$]|\\u(?:\{[0-9A-Fa-f]{1,6}\}|[0-9A-Fa-f]{4}))*|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*')\s*:/.exec(candidate);
|
|
704
|
+
if (named) {
|
|
705
|
+
const name = /^['"]/.test(named[1])
|
|
706
|
+
? decodeJavaScriptStringLiteral(named[1])
|
|
707
|
+
: decodeJavaScriptIdentifier(named[1]);
|
|
708
|
+
return {
|
|
709
|
+
name,
|
|
710
|
+
computed: false,
|
|
711
|
+
valueStart: leadingWhitespace + named[0].length,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
if (!candidate.startsWith('['))
|
|
715
|
+
return null;
|
|
716
|
+
const structure = maskStringAndRegexLiterals(candidate);
|
|
717
|
+
const closing = findBalancedDelimiterEnd(structure, 0, '[', ']');
|
|
718
|
+
if (closing < 0)
|
|
719
|
+
return null;
|
|
720
|
+
const colon = /^\s*:/.exec(candidate.slice(closing + 1));
|
|
721
|
+
if (!colon)
|
|
722
|
+
return null;
|
|
723
|
+
const propertyExpression = candidate.slice(1, closing).trim();
|
|
724
|
+
const staticLiteral = /^(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*')$/.test(propertyExpression);
|
|
725
|
+
return {
|
|
726
|
+
name: staticLiteral ? decodeJavaScriptStringLiteral(propertyExpression) : null,
|
|
727
|
+
computed: true,
|
|
728
|
+
valueStart: leadingWhitespace + closing + 1 + colon[0].length,
|
|
729
|
+
};
|
|
730
|
+
};
|
|
731
|
+
const resolvedDirectPropertyName = (field) => {
|
|
732
|
+
const definition = directPropertyDefinition(field);
|
|
733
|
+
if (definition)
|
|
734
|
+
return definition.name;
|
|
735
|
+
const candidate = field.replace(/,\s*$/, '').trim();
|
|
736
|
+
const shorthand = /^((?:[A-Za-z_$]|\\u(?:\{[0-9A-Fa-f]{1,6}\}|[0-9A-Fa-f]{4}))(?:[\w$]|\\u(?:\{[0-9A-Fa-f]{1,6}\}|[0-9A-Fa-f]{4}))*)$/.exec(candidate);
|
|
737
|
+
return shorthand ? decodeJavaScriptIdentifier(shorthand[1]) : null;
|
|
738
|
+
};
|
|
739
|
+
const directPropertyContainerRange = (source, structure, range, expectedName, openingCharacter, closingCharacter) => {
|
|
740
|
+
const entry = source.slice(range.start, range.end);
|
|
741
|
+
const definition = directPropertyDefinition(entry);
|
|
742
|
+
if (!definition || definition.name !== expectedName)
|
|
743
|
+
return null;
|
|
744
|
+
const localOpening = skipWhitespace(entry, definition.valueStart);
|
|
745
|
+
if (entry[localOpening] !== openingCharacter)
|
|
746
|
+
return null;
|
|
747
|
+
const opening = range.start + localOpening;
|
|
748
|
+
const closing = findBalancedDelimiterEnd(structure, opening, openingCharacter, closingCharacter);
|
|
749
|
+
if (closing < 0 || closing > range.end)
|
|
750
|
+
return null;
|
|
751
|
+
const remainder = source.slice(closing + 1, range.end).replace(/,\s*$/, '').trim();
|
|
752
|
+
return remainder ? null : { opening, closing, computed: definition.computed };
|
|
753
|
+
};
|
|
754
|
+
const objectAccessorOrMethodDefinition = (entry) => {
|
|
755
|
+
const candidate = entry.trimStart();
|
|
756
|
+
const prefix = /^(?:(?:get|set)\s+|(?:async\s+)?\*?\s*)/.exec(candidate)?.[0] ?? '';
|
|
757
|
+
const nameSource = candidate.slice(prefix.length);
|
|
758
|
+
if (nameSource.startsWith('[')) {
|
|
759
|
+
const structure = maskStringAndRegexLiterals(nameSource);
|
|
760
|
+
const closing = findBalancedDelimiterEnd(structure, 0, '[', ']');
|
|
761
|
+
if (closing < 0 || !/^\s*\(/.test(nameSource.slice(closing + 1)))
|
|
762
|
+
return null;
|
|
763
|
+
const propertyExpression = nameSource.slice(1, closing).trim();
|
|
764
|
+
const staticLiteral = /^(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*')$/.test(propertyExpression);
|
|
765
|
+
return {
|
|
766
|
+
name: staticLiteral ? decodeJavaScriptStringLiteral(propertyExpression) : null,
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
const method = /^((?:[A-Za-z_$]|\\u(?:\{[0-9A-Fa-f]{1,6}\}|[0-9A-Fa-f]{4}))(?:[\w$]|\\u(?:\{[0-9A-Fa-f]{1,6}\}|[0-9A-Fa-f]{4}))*|"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*')\s*\(/.exec(nameSource);
|
|
770
|
+
if (!method)
|
|
771
|
+
return null;
|
|
772
|
+
const propertyName = /^['"]/.test(method[1])
|
|
773
|
+
? decodeJavaScriptStringLiteral(method[1])
|
|
774
|
+
: decodeJavaScriptIdentifier(method[1]);
|
|
775
|
+
return { name: propertyName };
|
|
776
|
+
};
|
|
777
|
+
const hasAmbiguousAuthorityAccessorOrMethod = (entry, authorityNames) => {
|
|
778
|
+
const method = objectAccessorOrMethodDefinition(entry);
|
|
779
|
+
return Boolean(method && (!method.name || authorityNames.includes(method.name)));
|
|
780
|
+
};
|
|
781
|
+
const authoritativeExpoConfigRange = (source) => {
|
|
782
|
+
const exportedRoot = rootConfigObjectRange(source);
|
|
783
|
+
if (!exportedRoot)
|
|
784
|
+
return null;
|
|
785
|
+
const structure = maskStringAndRegexLiterals(source);
|
|
786
|
+
const rootEntries = topLevelCommaRanges(structure, exportedRoot.opening + 1, exportedRoot.closing);
|
|
787
|
+
const rootEntrySources = rootEntries.map(range => source.slice(range.start, range.end));
|
|
788
|
+
const rootDefinitions = rootEntrySources.map(directPropertyDefinition);
|
|
789
|
+
const rootPropertyNames = rootEntrySources.map(resolvedDirectPropertyName);
|
|
790
|
+
const directExpoObjects = rootEntries.flatMap((range, entryIndex) => {
|
|
791
|
+
if (rootDefinitions[entryIndex]?.name !== 'expo')
|
|
792
|
+
return [];
|
|
793
|
+
const property = directPropertyContainerRange(source, structure, range, 'expo', '{', '}');
|
|
794
|
+
return property
|
|
795
|
+
? [{ ...property, entryIndex }]
|
|
796
|
+
: [];
|
|
797
|
+
});
|
|
798
|
+
const expoNamedPropertyCount = rootPropertyNames.filter(name => name === 'expo').length;
|
|
799
|
+
if (!directExpoObjects.length) {
|
|
800
|
+
return expoNamedPropertyCount ? null : exportedRoot;
|
|
801
|
+
}
|
|
802
|
+
if (directExpoObjects.length !== 1 ||
|
|
803
|
+
expoNamedPropertyCount !== 1 ||
|
|
804
|
+
rootEntrySources.some((entry, entryIndex) => Boolean(rootDefinitions[entryIndex] && !rootPropertyNames[entryIndex]) ||
|
|
805
|
+
(/^\s*\.\.\./.test(entry) && entryIndex > directExpoObjects[0].entryIndex) ||
|
|
806
|
+
hasAmbiguousAuthorityAccessorOrMethod(entry, ['expo', 'plugins', 'updates']) ||
|
|
807
|
+
['plugins', 'updates'].includes(rootPropertyNames[entryIndex] || ''))) {
|
|
808
|
+
return null;
|
|
809
|
+
}
|
|
810
|
+
return directExpoObjects[0];
|
|
811
|
+
};
|
|
812
|
+
const removableCommaRange = (source, range) => {
|
|
813
|
+
let end = range.end;
|
|
814
|
+
while (end > range.start && /\s/.test(source[end - 1]))
|
|
815
|
+
end -= 1;
|
|
816
|
+
if (source[end - 1] === ',')
|
|
817
|
+
return { start: range.start, end };
|
|
818
|
+
let start = range.start - 1;
|
|
819
|
+
while (start >= 0 && /\s/.test(source[start]))
|
|
820
|
+
start -= 1;
|
|
821
|
+
return source[start] === ','
|
|
822
|
+
? { start, end }
|
|
823
|
+
: { start: range.start, end };
|
|
824
|
+
};
|
|
825
|
+
const removeSourceRanges = (source, ranges) => {
|
|
826
|
+
const ordered = [...ranges].sort((left, right) => right.start - left.start);
|
|
827
|
+
let result = source;
|
|
828
|
+
for (const range of ordered) {
|
|
829
|
+
result = result.slice(0, range.start) + result.slice(range.end);
|
|
830
|
+
}
|
|
831
|
+
return result;
|
|
832
|
+
};
|
|
833
|
+
const removeTopLevelExpoUpdatesPluginEntries = (source) => {
|
|
834
|
+
const structuralSource = maskCommentsPreservingLength(source);
|
|
835
|
+
const root = authoritativeExpoConfigRange(structuralSource);
|
|
836
|
+
if (!root)
|
|
837
|
+
return source;
|
|
838
|
+
const structure = maskStringAndRegexLiterals(structuralSource);
|
|
839
|
+
const bindings = collectConstantStringBindings(structuralSource);
|
|
840
|
+
const rangesToRemove = [];
|
|
841
|
+
const rootEntries = topLevelCommaRanges(structure, root.opening + 1, root.closing);
|
|
842
|
+
for (const entryRange of rootEntries) {
|
|
843
|
+
const property = directPropertyContainerRange(structuralSource, structure, entryRange, 'plugins', '[', ']');
|
|
844
|
+
if (!property)
|
|
845
|
+
continue;
|
|
846
|
+
for (const range of topLevelCommaRanges(structure, property.opening + 1, property.closing)) {
|
|
847
|
+
const plugin = structuralSource
|
|
848
|
+
.slice(range.start, range.end)
|
|
849
|
+
.replace(/,\s*$/, '')
|
|
850
|
+
.trim();
|
|
851
|
+
if (!plugin)
|
|
852
|
+
continue;
|
|
853
|
+
if (resolvePluginEntry(plugin, bindings).packageName !== 'expo-updates')
|
|
854
|
+
continue;
|
|
855
|
+
rangesToRemove.push(removableCommaRange(source, range));
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
return removeSourceRanges(source, rangesToRemove);
|
|
859
|
+
};
|
|
860
|
+
const removeTopLevelBundleDropRegistration = (source, removeNewPluginProperty) => {
|
|
861
|
+
const structuralSource = maskCommentsPreservingLength(source);
|
|
862
|
+
const root = authoritativeExpoConfigRange(structuralSource);
|
|
863
|
+
if (!root)
|
|
864
|
+
return source;
|
|
865
|
+
const structure = maskStringAndRegexLiterals(structuralSource);
|
|
866
|
+
const rangesToRemove = [];
|
|
867
|
+
const rootEntries = topLevelCommaRanges(structure, root.opening + 1, root.closing);
|
|
868
|
+
for (const entryRange of rootEntries) {
|
|
869
|
+
const entry = structuralSource.slice(entryRange.start, entryRange.end);
|
|
870
|
+
const property = directPropertyContainerRange(structuralSource, structure, entryRange, 'plugins', '[', ']');
|
|
871
|
+
if (!property)
|
|
872
|
+
continue;
|
|
873
|
+
if (removeNewPluginProperty &&
|
|
874
|
+
!/^\s*(?:plugins|"plugins"|'plugins')\s*:/.test(entry)) {
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
const pluginRanges = topLevelCommaRanges(structure, property.opening + 1, property.closing);
|
|
878
|
+
const substantiveRanges = pluginRanges.filter(range => structuralSource.slice(range.start, range.end).replace(/[,\s]/g, ''));
|
|
879
|
+
const bundleDropRanges = substantiveRanges.filter(range => {
|
|
880
|
+
const plugin = structuralSource
|
|
881
|
+
.slice(range.start, range.end)
|
|
882
|
+
.replace(/,\s*$/, '')
|
|
883
|
+
.trim();
|
|
884
|
+
return /^(?:"@gfean\/react-native-bundle-drop"|'@gfean\/react-native-bundle-drop')$/.test(plugin);
|
|
885
|
+
});
|
|
886
|
+
if (bundleDropRanges.length !== 1)
|
|
887
|
+
continue;
|
|
888
|
+
const removesWholePluginProperty = removeNewPluginProperty && substantiveRanges.length === 1;
|
|
889
|
+
const authorizedRanges = removesWholePluginProperty
|
|
890
|
+
? [entryRange]
|
|
891
|
+
: bundleDropRanges;
|
|
892
|
+
const removesOnlyRootProperty = removesWholePluginProperty &&
|
|
893
|
+
rootEntries.filter(range => structuralSource.slice(range.start, range.end).replace(/[,\s]/g, '')).length === 1;
|
|
894
|
+
rangesToRemove.push(...authorizedRanges.map(range => removesOnlyRootProperty
|
|
895
|
+
? range
|
|
896
|
+
: removableCommaRange(source, range)));
|
|
897
|
+
}
|
|
898
|
+
return removeSourceRanges(source, rangesToRemove);
|
|
899
|
+
};
|
|
900
|
+
const hasTopLevelPluginsProperty = (source) => {
|
|
901
|
+
const structuralSource = (0, native_setup_contract_1.stripComments)(source);
|
|
902
|
+
const root = authoritativeExpoConfigRange(structuralSource);
|
|
903
|
+
if (!root)
|
|
904
|
+
return null;
|
|
905
|
+
const structure = maskStringAndRegexLiterals(structuralSource);
|
|
906
|
+
return topLevelCommaRanges(structure, root.opening + 1, root.closing).some(range => directPropertyDefinition(structuralSource.slice(range.start, range.end))?.name ===
|
|
907
|
+
'plugins');
|
|
908
|
+
};
|
|
909
|
+
const removeTopLevelExpoUpdatesFields = (source) => {
|
|
910
|
+
const structuralSource = maskCommentsPreservingLength(source);
|
|
911
|
+
const root = authoritativeExpoConfigRange(structuralSource);
|
|
912
|
+
if (!root)
|
|
913
|
+
return source;
|
|
914
|
+
const structure = maskStringAndRegexLiterals(structuralSource);
|
|
915
|
+
const rangesToRemove = [];
|
|
916
|
+
const rootEntries = topLevelCommaRanges(structure, root.opening + 1, root.closing);
|
|
917
|
+
for (const entryRange of rootEntries) {
|
|
918
|
+
const property = directPropertyContainerRange(structuralSource, structure, entryRange, 'updates', '{', '}');
|
|
919
|
+
if (!property)
|
|
920
|
+
continue;
|
|
921
|
+
const fieldRanges = topLevelCommaRanges(structure, property.opening + 1, property.closing);
|
|
922
|
+
const removable = fieldRanges.filter(range => {
|
|
923
|
+
const field = structuralSource
|
|
924
|
+
.slice(range.start, range.end)
|
|
925
|
+
.replace(/,\s*$/, '')
|
|
926
|
+
.trim();
|
|
927
|
+
return ['enabled', 'url'].includes(resolvedDirectPropertyName(field) || '');
|
|
928
|
+
});
|
|
929
|
+
if (!removable.length)
|
|
930
|
+
continue;
|
|
931
|
+
const substantiveFields = fieldRanges.filter(range => structuralSource.slice(range.start, range.end).replace(/[,\s]/g, ''));
|
|
932
|
+
const authorizedRanges = removable.length === substantiveFields.length
|
|
933
|
+
? [entryRange]
|
|
934
|
+
: removable;
|
|
935
|
+
rangesToRemove.push(...authorizedRanges.map(range => removableCommaRange(source, range)));
|
|
936
|
+
}
|
|
937
|
+
return removeSourceRanges(source, rangesToRemove);
|
|
938
|
+
};
|
|
939
|
+
const inspectAuthoritativeExpoConfig = (content) => {
|
|
940
|
+
const source = (0, native_setup_contract_1.stripComments)(content);
|
|
941
|
+
const structure = maskStringAndRegexLiterals(source);
|
|
942
|
+
const bindings = collectConstantStringBindings(source);
|
|
943
|
+
const root = authoritativeExpoConfigRange(source);
|
|
944
|
+
if (!root)
|
|
945
|
+
return null;
|
|
946
|
+
const rootEntries = topLevelCommaRanges(structure, root.opening + 1, root.closing);
|
|
947
|
+
const rootEntrySources = rootEntries.map(range => source.slice(range.start, range.end));
|
|
948
|
+
const rootDefinitions = rootEntrySources.map(directPropertyDefinition);
|
|
949
|
+
if (rootEntrySources.some((entry, index) => Boolean(rootDefinitions[index] && !rootDefinitions[index]?.name) ||
|
|
950
|
+
hasAmbiguousAuthorityAccessorOrMethod(entry, ['plugins', 'updates']) ||
|
|
951
|
+
(['plugins', 'updates'].includes(resolvedDirectPropertyName(entry) || '') &&
|
|
952
|
+
!rootDefinitions[index]))) {
|
|
953
|
+
return null;
|
|
954
|
+
}
|
|
955
|
+
const pluginProperties = rootEntries.filter((_range, index) => rootDefinitions[index]?.name === 'plugins');
|
|
956
|
+
if (pluginProperties.length !== 1)
|
|
957
|
+
return null;
|
|
958
|
+
const pluginProperty = pluginProperties[0];
|
|
959
|
+
const pluginArray = directPropertyContainerRange(source, structure, pluginProperty, 'plugins', '[', ']');
|
|
960
|
+
if (!pluginArray)
|
|
961
|
+
return null;
|
|
962
|
+
const pluginOpening = pluginArray.opening;
|
|
963
|
+
const pluginClosing = pluginArray.closing;
|
|
964
|
+
const updatesProperties = rootEntries.filter((_range, index) => rootDefinitions[index]?.name === 'updates');
|
|
965
|
+
if (updatesProperties.length > 1)
|
|
966
|
+
return null;
|
|
967
|
+
const pluginPropertyIndex = rootEntries.indexOf(pluginProperty);
|
|
968
|
+
const updatesPropertyIndex = updatesProperties.length
|
|
969
|
+
? rootEntries.indexOf(updatesProperties[0])
|
|
970
|
+
: -1;
|
|
971
|
+
const firstAuthorityIndex = updatesPropertyIndex < 0
|
|
972
|
+
? pluginPropertyIndex
|
|
973
|
+
: Math.min(pluginPropertyIndex, updatesPropertyIndex);
|
|
974
|
+
if (rootEntrySources.some((entry, index) => index > firstAuthorityIndex && /^\s*\.\.\./.test(entry))) {
|
|
975
|
+
return null;
|
|
976
|
+
}
|
|
977
|
+
let bundleDropPluginCount = 0;
|
|
978
|
+
let expoUpdatesPluginCount = 0;
|
|
979
|
+
let hasAmbiguousPluginAuthority = false;
|
|
980
|
+
let hasUnresolvedPluginExpression = false;
|
|
981
|
+
let supportedExistingPluginsSpreadCount = 0;
|
|
982
|
+
const pluginEntries = topLevelCommaRanges(structure, pluginOpening + 1, pluginClosing);
|
|
983
|
+
let bundleDropPluginIndex = -1;
|
|
984
|
+
for (const [index, range] of pluginEntries.entries()) {
|
|
985
|
+
const entry = source.slice(range.start, range.end).replace(/,\s*$/, '').trim();
|
|
986
|
+
if (!entry)
|
|
987
|
+
continue;
|
|
988
|
+
const resolvedPlugin = resolvePluginEntry(entry, bindings);
|
|
989
|
+
if (resolvedPlugin.packageName === null) {
|
|
990
|
+
if (isCanonicalExistingPluginsSpread(entry)) {
|
|
991
|
+
supportedExistingPluginsSpreadCount += 1;
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
hasUnresolvedPluginExpression = true;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (resolvedPlugin.packageName === '@gfean/react-native-bundle-drop') {
|
|
998
|
+
bundleDropPluginCount += 1;
|
|
999
|
+
bundleDropPluginIndex = index;
|
|
1000
|
+
}
|
|
1001
|
+
if (resolvedPlugin.packageName === 'expo-updates')
|
|
1002
|
+
expoUpdatesPluginCount += 1;
|
|
1003
|
+
if (resolvedPlugin.ambiguousAuthority)
|
|
1004
|
+
hasAmbiguousPluginAuthority = true;
|
|
1005
|
+
if (/^\.\.\./.test(entry) &&
|
|
1006
|
+
decodedExpressionMayReferenceSetupAuthority(entry.slice(3))) {
|
|
1007
|
+
hasAmbiguousPluginAuthority = true;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
if (bundleDropPluginIndex >= 0 &&
|
|
1011
|
+
pluginEntries.some((range, index) => index > bundleDropPluginIndex &&
|
|
1012
|
+
/^\s*\.\.\./.test(source.slice(range.start, range.end)))) {
|
|
1013
|
+
expoUpdatesPluginCount += 1;
|
|
1014
|
+
}
|
|
1015
|
+
let hasActiveExpoUpdatesField = false;
|
|
1016
|
+
if (updatesProperties.length === 1) {
|
|
1017
|
+
const updatesProperty = updatesProperties[0];
|
|
1018
|
+
const updatesObject = directPropertyContainerRange(source, structure, updatesProperty, 'updates', '{', '}');
|
|
1019
|
+
if (!updatesObject)
|
|
1020
|
+
return null;
|
|
1021
|
+
const updateFields = topLevelCommaRanges(structure, updatesObject.opening + 1, updatesObject.closing);
|
|
1022
|
+
for (const range of updateFields) {
|
|
1023
|
+
const field = source.slice(range.start, range.end).replace(/,\s*$/, '').trim();
|
|
1024
|
+
if (/^\.\.\./.test(field)) {
|
|
1025
|
+
hasActiveExpoUpdatesField = true;
|
|
1026
|
+
continue;
|
|
1027
|
+
}
|
|
1028
|
+
if (['enabled', 'url'].includes(resolvedDirectPropertyName(field) || '') ||
|
|
1029
|
+
Boolean(objectAccessorOrMethodDefinition(field)) ||
|
|
1030
|
+
/^\[/.test(field)) {
|
|
1031
|
+
hasActiveExpoUpdatesField = true;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return {
|
|
1036
|
+
bundleDropPluginCount,
|
|
1037
|
+
expoUpdatesPluginCount,
|
|
1038
|
+
hasAmbiguousPluginAuthority,
|
|
1039
|
+
hasUnresolvedPluginExpression,
|
|
1040
|
+
supportedExistingPluginsSpreadCount,
|
|
1041
|
+
hasActiveExpoUpdatesField,
|
|
1042
|
+
};
|
|
1043
|
+
};
|
|
1044
|
+
const withoutOptionalTerminalNewline = (content) => content.endsWith('\r\n')
|
|
1045
|
+
? content.slice(0, -2)
|
|
1046
|
+
: content.endsWith('\n')
|
|
1047
|
+
? content.slice(0, -1)
|
|
1048
|
+
: content;
|
|
1049
|
+
const preservesOnlyAuthorizedExpoChanges = (original, updated, migrateExpoUpdates) => {
|
|
1050
|
+
const originalHasPlugins = hasTopLevelPluginsProperty(original);
|
|
1051
|
+
if (originalHasPlugins === null)
|
|
1052
|
+
return false;
|
|
1053
|
+
const originalWithoutExactBundleDrop = removeTopLevelBundleDropRegistration(original, false);
|
|
1054
|
+
const originalHasExactBundleDrop = originalWithoutExactBundleDrop !== original;
|
|
1055
|
+
let normalizedOriginal = original;
|
|
1056
|
+
if (migrateExpoUpdates) {
|
|
1057
|
+
normalizedOriginal = removeTopLevelExpoUpdatesFields(removeTopLevelExpoUpdatesPluginEntries(normalizedOriginal));
|
|
1058
|
+
}
|
|
1059
|
+
const normalizedUpdated = originalHasExactBundleDrop
|
|
1060
|
+
? updated
|
|
1061
|
+
: removeTopLevelBundleDropRegistration(updated, !originalHasPlugins);
|
|
1062
|
+
return withoutOptionalTerminalNewline(normalizedOriginal) ===
|
|
1063
|
+
withoutOptionalTerminalNewline(normalizedUpdated);
|
|
1064
|
+
};
|
|
46
1065
|
const validateCommonSetupChange = (change, originals, seen) => {
|
|
47
1066
|
if (!(0, exports.isSafeRelativePath)(change.file)) {
|
|
48
1067
|
throw new Error(`AI setup plan references an unsafe file path: ${change.file}`);
|
|
@@ -63,32 +1082,51 @@ const validateCommonSetupChange = (change, originals, seen) => {
|
|
|
63
1082
|
if (change.updated.includes('TODO_BUNDLEDROP') || change.updated.includes('<TODO')) {
|
|
64
1083
|
throw new Error(`AI setup plan returned placeholder text in ${change.file}`);
|
|
65
1084
|
}
|
|
66
|
-
if (!hasBalancedPairs(change.updated)) {
|
|
1085
|
+
if (!hasBalancedPairs(change.updated, /^app\.config\./.test(change.file))) {
|
|
67
1086
|
throw new Error(`AI setup plan returned unbalanced braces or brackets in ${change.file}`);
|
|
68
1087
|
}
|
|
1088
|
+
if ((0, terminal_safety_1.hasUnsafeTerminalControl)(change.updated) ||
|
|
1089
|
+
(0, terminal_safety_1.hasUnsafeTerminalControl)(originals.get(change.file))) {
|
|
1090
|
+
throw new Error(`AI setup plan contains unsafe control or JavaScript line-separator characters in ${change.file}`);
|
|
1091
|
+
}
|
|
69
1092
|
};
|
|
70
1093
|
function validateSetupChangesBeforeApply(params) {
|
|
71
1094
|
const seen = new Set();
|
|
72
1095
|
for (const change of params.changes) {
|
|
73
1096
|
validateCommonSetupChange(change, params.originals, seen);
|
|
74
1097
|
if (params.projectType === 'expo') {
|
|
75
|
-
if (!(0, exports.isPatchableExpoConfig)(change.file)) {
|
|
76
|
-
throw new Error(`AI Expo setup may
|
|
1098
|
+
if (!change.file.startsWith('app.config.') || !(0, exports.isPatchableExpoConfig)(change.file)) {
|
|
1099
|
+
throw new Error(`AI Expo setup may modify only a dynamic root app.config.* file: ${change.file}`);
|
|
1100
|
+
}
|
|
1101
|
+
if (change.decisionType !== 'review_only_patch') {
|
|
1102
|
+
throw new Error(`AI dynamic Expo config updates require explicit review-only approval: ${change.file}`);
|
|
77
1103
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1104
|
+
const expoConfig = inspectAuthoritativeExpoConfig(change.updated);
|
|
1105
|
+
const originalExpoConfig = inspectAuthoritativeExpoConfig(params.originals.get(change.file));
|
|
1106
|
+
if (!expoConfig ||
|
|
1107
|
+
expoConfig.bundleDropPluginCount !== 1 ||
|
|
1108
|
+
expoConfig.hasAmbiguousPluginAuthority) {
|
|
1109
|
+
throw new Error(`AI Expo config update must contain exactly one Bundle Drop plugin in the exported root plugins property: ${change.file}`);
|
|
82
1110
|
}
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
1111
|
+
if (params.migrateExpoUpdates &&
|
|
1112
|
+
(expoConfig.expoUpdatesPluginCount > 0 ||
|
|
1113
|
+
expoConfig.hasActiveExpoUpdatesField ||
|
|
1114
|
+
expoConfig.hasUnresolvedPluginExpression ||
|
|
1115
|
+
expoConfig.supportedExistingPluginsSpreadCount >
|
|
1116
|
+
(originalExpoConfig?.supportedExistingPluginsSpreadCount ?? 0))) {
|
|
1117
|
+
throw new Error(`AI Expo config update did not fully remove active Expo Updates configuration: ${change.file}`);
|
|
1118
|
+
}
|
|
1119
|
+
if (!preservesOnlyAuthorizedExpoChanges(params.originals.get(change.file), change.updated, Boolean(params.migrateExpoUpdates))) {
|
|
1120
|
+
throw new Error(`AI dynamic Expo config update changed code outside authorized setup fields: ${change.file}`);
|
|
86
1121
|
}
|
|
87
1122
|
continue;
|
|
88
1123
|
}
|
|
89
1124
|
if (!(0, exports.isPatchableNativeEntrypoint)(change.file)) {
|
|
90
1125
|
throw new Error(`AI bare setup may not modify ${change.file}`);
|
|
91
1126
|
}
|
|
1127
|
+
if (change.decisionType !== 'review_only_patch') {
|
|
1128
|
+
throw new Error(`AI bare native updates require explicit review-only approval: ${change.file}`);
|
|
1129
|
+
}
|
|
92
1130
|
if (change.file.includes('MainApplication.') && !hasAndroidBundleDropIntegration(change.updated)) {
|
|
93
1131
|
throw new Error(`AI plan Android update does not contain BundleDrop resolver: ${change.file}`);
|
|
94
1132
|
}
|
|
@@ -96,20 +1134,43 @@ function validateSetupChangesBeforeApply(params) {
|
|
|
96
1134
|
!hasIosBundleDropIntegration(change.file, change.updated)) {
|
|
97
1135
|
throw new Error(`AI plan iOS update does not contain BundleDrop locator: ${change.file}`);
|
|
98
1136
|
}
|
|
1137
|
+
const missingStructure = (0, native_setup_contract_1.findMissingBareNativeStartupStructure)(change.file, params.originals.get(change.file), change.updated);
|
|
1138
|
+
if (missingStructure.length) {
|
|
1139
|
+
throw new Error(`AI plan removed native startup structure from ${change.file}: ` +
|
|
1140
|
+
missingStructure.join(', '));
|
|
1141
|
+
}
|
|
99
1142
|
}
|
|
100
1143
|
}
|
|
101
1144
|
function validateAppliedSetupChanges(params) {
|
|
102
|
-
const
|
|
103
|
-
change.file
|
|
104
|
-
|
|
105
|
-
|
|
1145
|
+
const appliedFiles = new Map(params.changes.map(change => {
|
|
1146
|
+
const applied = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, change.file);
|
|
1147
|
+
if (!applied.exists) {
|
|
1148
|
+
throw new Error(`Applied AI setup file is missing: ${change.file}`);
|
|
1149
|
+
}
|
|
1150
|
+
return [change.file, applied.content];
|
|
1151
|
+
}));
|
|
1152
|
+
const originals = params.originals || appliedFiles;
|
|
1153
|
+
if (params.projectType === 'bare') {
|
|
1154
|
+
for (const platform of ['android', 'ios']) {
|
|
1155
|
+
const entrypoints = params.changes
|
|
1156
|
+
.map(change => change.file)
|
|
1157
|
+
.filter(file => platform === 'android'
|
|
1158
|
+
? file.includes('/android/') || file.startsWith('android/')
|
|
1159
|
+
: file.includes('/ios/') || file.startsWith('ios/'));
|
|
1160
|
+
const authorityIssue = (0, native_entrypoint_authority_1.findNativeEntrypointAuthorityIssue)(params.projectRoot, platform, entrypoints);
|
|
1161
|
+
if (authorityIssue) {
|
|
1162
|
+
throw new Error(`Applied ${platform} entrypoint authority is invalid: ${authorityIssue}`);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
106
1166
|
validateSetupChangesBeforeApply({
|
|
107
1167
|
projectType: params.projectType,
|
|
108
1168
|
originals,
|
|
1169
|
+
migrateExpoUpdates: params.migrateExpoUpdates,
|
|
109
1170
|
changes: params.changes.map(change => ({
|
|
110
1171
|
...change,
|
|
111
1172
|
originalSha256: sha256(originals.get(change.file)),
|
|
112
|
-
updated:
|
|
1173
|
+
updated: appliedFiles.get(change.file),
|
|
113
1174
|
})),
|
|
114
1175
|
});
|
|
115
1176
|
}
|