@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,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assertCommonJsMetroConfig = exports.newCommonJsMetroConfigFile = exports.findSingleMetroConfig = exports.hasAuthoritativeMetroWrapper = exports.hasExecutableMetroModuleReference = exports.hasExecutableMetroWrapperReference = exports.METRO_CONFIG_FILES = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const native_setup_contract_1 = require("./native-setup-contract");
|
|
9
|
+
const safe_file_transaction_1 = require("./safe-file-transaction");
|
|
10
|
+
exports.METRO_CONFIG_FILES = [
|
|
11
|
+
'metro.config.js',
|
|
12
|
+
'metro.config.cjs',
|
|
13
|
+
'metro.config.mjs',
|
|
14
|
+
'metro.config.ts',
|
|
15
|
+
];
|
|
16
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
17
|
+
const stripJavaScriptComments = (source) => {
|
|
18
|
+
let output = '';
|
|
19
|
+
let quote = '';
|
|
20
|
+
let escaped = false;
|
|
21
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
22
|
+
const character = source[index];
|
|
23
|
+
const next = source[index + 1];
|
|
24
|
+
if (quote) {
|
|
25
|
+
output += character;
|
|
26
|
+
if (escaped)
|
|
27
|
+
escaped = false;
|
|
28
|
+
else if (character === '\\')
|
|
29
|
+
escaped = true;
|
|
30
|
+
else if (character === quote)
|
|
31
|
+
quote = '';
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (character === '"' || character === "'" || character === '`') {
|
|
35
|
+
quote = character;
|
|
36
|
+
output += character;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (character === '/' && next === '/') {
|
|
40
|
+
while (index < source.length && source[index] !== '\n')
|
|
41
|
+
index += 1;
|
|
42
|
+
output += '\n';
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (character === '/' && next === '*') {
|
|
46
|
+
index += 2;
|
|
47
|
+
while (index < source.length && !(source[index] === '*' && source[index + 1] === '/')) {
|
|
48
|
+
if (source[index] === '\n')
|
|
49
|
+
output += '\n';
|
|
50
|
+
index += 1;
|
|
51
|
+
}
|
|
52
|
+
index += 1;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
output += character;
|
|
56
|
+
}
|
|
57
|
+
return output;
|
|
58
|
+
};
|
|
59
|
+
const javascriptStringRanges = (source) => {
|
|
60
|
+
const ranges = [];
|
|
61
|
+
let quote = '';
|
|
62
|
+
let start = -1;
|
|
63
|
+
let escaped = false;
|
|
64
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
65
|
+
const character = source[index];
|
|
66
|
+
if (!quote && (character === '"' || character === "'" || character === '`')) {
|
|
67
|
+
quote = character;
|
|
68
|
+
start = index;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (!quote)
|
|
72
|
+
continue;
|
|
73
|
+
if (escaped)
|
|
74
|
+
escaped = false;
|
|
75
|
+
else if (character === '\\')
|
|
76
|
+
escaped = true;
|
|
77
|
+
else if (character === quote) {
|
|
78
|
+
ranges.push({ start, end: index + 1 });
|
|
79
|
+
quote = '';
|
|
80
|
+
start = -1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (quote)
|
|
84
|
+
ranges.push({ start, end: source.length });
|
|
85
|
+
return ranges;
|
|
86
|
+
};
|
|
87
|
+
const executableMatches = (source, pattern) => {
|
|
88
|
+
const ranges = javascriptStringRanges(source);
|
|
89
|
+
return [...source.matchAll(pattern)].filter(match => {
|
|
90
|
+
const position = match.index || 0;
|
|
91
|
+
return ranges.every(range => position < range.start || position >= range.end);
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
const structuralSource = (source) => {
|
|
95
|
+
const characters = [...source];
|
|
96
|
+
for (const range of javascriptStringRanges(source)) {
|
|
97
|
+
for (let index = range.start; index < range.end; index += 1) {
|
|
98
|
+
if (characters[index] !== '\n')
|
|
99
|
+
characters[index] = ' ';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return characters.join('');
|
|
103
|
+
};
|
|
104
|
+
const isUnconditionalTopLevel = (source, position) => {
|
|
105
|
+
const structure = structuralSource(source);
|
|
106
|
+
const prefix = structure.slice(0, position);
|
|
107
|
+
const depth = [...prefix].reduce((value, character) => {
|
|
108
|
+
if ('{[('.includes(character))
|
|
109
|
+
return value + 1;
|
|
110
|
+
if ('}])'.includes(character))
|
|
111
|
+
return value - 1;
|
|
112
|
+
return value;
|
|
113
|
+
}, 0);
|
|
114
|
+
if (depth !== 0)
|
|
115
|
+
return false;
|
|
116
|
+
const statementPrefix = prefix.slice(Math.max(prefix.lastIndexOf('\n'), prefix.lastIndexOf(';'), prefix.lastIndexOf('}')) + 1);
|
|
117
|
+
return !/\b(?:if|for|while|switch|catch)\s*\(|=>/.test(statementPrefix);
|
|
118
|
+
};
|
|
119
|
+
const hasExactBindingEntry = (bindingBody, name) => bindingBody.split(',').map(entry => entry.trim()).includes(name);
|
|
120
|
+
const topLevelNamedBindingCount = (source, name, moduleNames) => {
|
|
121
|
+
const withoutComments = stripJavaScriptComments(source);
|
|
122
|
+
let count = 0;
|
|
123
|
+
for (const moduleName of moduleNames) {
|
|
124
|
+
const escapedModule = escapeRegExp(moduleName);
|
|
125
|
+
const commonJs = new RegExp(`\\b(?:const|let|var)\\s*\\{([^}]*)\\}\\s*=\\s*` +
|
|
126
|
+
`require\\(\\s*(['"])${escapedModule}\\2\\s*\\)`, 'g');
|
|
127
|
+
const moduleImport = new RegExp(`\\bimport\\s*\\{([^}]*)\\}\\s*from\\s*(['"])${escapedModule}\\2`, 'g');
|
|
128
|
+
for (const match of [
|
|
129
|
+
...executableMatches(withoutComments, commonJs),
|
|
130
|
+
...executableMatches(withoutComments, moduleImport),
|
|
131
|
+
]) {
|
|
132
|
+
if (isUnconditionalTopLevel(withoutComments, match.index || 0) &&
|
|
133
|
+
hasExactBindingEntry(match[1], name)) {
|
|
134
|
+
count += 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return count;
|
|
139
|
+
};
|
|
140
|
+
const hasPackageWrapperBinding = (source, wrapper) => topLevelNamedBindingCount(source, wrapper, ['@gfean/react-native-bundle-drop/metro']) === 1;
|
|
141
|
+
const hasExecutableMetroWrapperReference = (source, wrapper) => new RegExp(`\\b${escapeRegExp(wrapper)}\\b`).test((0, native_setup_contract_1.stripCommentsAndStrings)(source));
|
|
142
|
+
exports.hasExecutableMetroWrapperReference = hasExecutableMetroWrapperReference;
|
|
143
|
+
const hasExecutableMetroModuleReference = (source, moduleName) => {
|
|
144
|
+
const withoutComments = stripJavaScriptComments(source);
|
|
145
|
+
const escapedModule = escapeRegExp(moduleName);
|
|
146
|
+
return executableMatches(withoutComments, new RegExp(`\\brequire\\(\\s*(['"])${escapedModule}\\1\\s*\\)|` +
|
|
147
|
+
`\\bfrom\\s*(['"])${escapedModule}\\2`, 'g')).some(match => isUnconditionalTopLevel(withoutComments, match.index || 0));
|
|
148
|
+
};
|
|
149
|
+
exports.hasExecutableMetroModuleReference = hasExecutableMetroModuleReference;
|
|
150
|
+
const findBalancedParenthesis = (source, opening) => {
|
|
151
|
+
let depth = 0;
|
|
152
|
+
for (let index = opening; index < source.length; index += 1) {
|
|
153
|
+
if (source[index] === '(')
|
|
154
|
+
depth += 1;
|
|
155
|
+
if (source[index] === ')')
|
|
156
|
+
depth -= 1;
|
|
157
|
+
if (depth === 0)
|
|
158
|
+
return index;
|
|
159
|
+
}
|
|
160
|
+
return -1;
|
|
161
|
+
};
|
|
162
|
+
const splitTopLevelArguments = (source) => {
|
|
163
|
+
const argumentsList = [];
|
|
164
|
+
let depth = 0;
|
|
165
|
+
let start = 0;
|
|
166
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
167
|
+
if ('{[('.includes(source[index]))
|
|
168
|
+
depth += 1;
|
|
169
|
+
else if ('}])'.includes(source[index]))
|
|
170
|
+
depth -= 1;
|
|
171
|
+
else if (source[index] === ',' && depth === 0) {
|
|
172
|
+
argumentsList.push(source.slice(start, index).trim());
|
|
173
|
+
start = index + 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
argumentsList.push(source.slice(start).trim());
|
|
177
|
+
return argumentsList;
|
|
178
|
+
};
|
|
179
|
+
const expressionEnd = (source, start) => {
|
|
180
|
+
let depth = 0;
|
|
181
|
+
for (let index = start; index < source.length; index += 1) {
|
|
182
|
+
const character = source[index];
|
|
183
|
+
if ('{[('.includes(character))
|
|
184
|
+
depth += 1;
|
|
185
|
+
else if ('}])'.includes(character))
|
|
186
|
+
depth -= 1;
|
|
187
|
+
else if ((character === ';' || character === '\n') && depth === 0)
|
|
188
|
+
return index;
|
|
189
|
+
}
|
|
190
|
+
return source.length;
|
|
191
|
+
};
|
|
192
|
+
const topLevelVariableInitializer = (source, name, before) => {
|
|
193
|
+
const structure = structuralSource(source);
|
|
194
|
+
const pattern = new RegExp(`\\b(?:const|let|var)\\s+${escapeRegExp(name)}\\s*=`, 'g');
|
|
195
|
+
const declarations = [...structure.matchAll(pattern)].filter(match => (match.index || 0) < before && isUnconditionalTopLevel(structure, match.index || 0));
|
|
196
|
+
if (declarations.length !== 1)
|
|
197
|
+
return null;
|
|
198
|
+
const initializerStart = (declarations[0].index || 0) + declarations[0][0].length;
|
|
199
|
+
return structure.slice(initializerStart, expressionEnd(structure, initializerStart)).trim();
|
|
200
|
+
};
|
|
201
|
+
const hasSupportedMetroExpression = (source, expression, before, visited = new Set()) => {
|
|
202
|
+
const value = expression.trim();
|
|
203
|
+
if (!value || /^(?:null|undefined|false|true)$/.test(value))
|
|
204
|
+
return false;
|
|
205
|
+
if (/^\{[\s\S]*\}$/.test(value))
|
|
206
|
+
return true;
|
|
207
|
+
if (/^getDefaultConfig\s*\([^)]*\)$/.test(value)) {
|
|
208
|
+
return topLevelNamedBindingCount(source, 'getDefaultConfig', ['@react-native/metro-config', 'expo/metro-config']) === 1;
|
|
209
|
+
}
|
|
210
|
+
if (/^mergeConfig\s*\([\s\S]*\)$/.test(value)) {
|
|
211
|
+
if (topLevelNamedBindingCount(source, 'mergeConfig', ['@react-native/metro-config']) !== 1)
|
|
212
|
+
return false;
|
|
213
|
+
const opening = value.indexOf('(');
|
|
214
|
+
const closing = findBalancedParenthesis(value, opening);
|
|
215
|
+
if (opening < 0 || closing !== value.length - 1)
|
|
216
|
+
return false;
|
|
217
|
+
const argumentsList = splitTopLevelArguments(value.slice(opening + 1, closing));
|
|
218
|
+
return Boolean(argumentsList[0]) && hasSupportedMetroExpression(source, argumentsList[0], before, visited);
|
|
219
|
+
}
|
|
220
|
+
if (/^[A-Za-z_$][\w$]*$/.test(value)) {
|
|
221
|
+
if (visited.has(value))
|
|
222
|
+
return false;
|
|
223
|
+
const initializer = topLevelVariableInitializer(source, value, before);
|
|
224
|
+
return initializer !== null && hasSupportedMetroExpression(source, initializer, before, new Set([...visited, value]));
|
|
225
|
+
}
|
|
226
|
+
return false;
|
|
227
|
+
};
|
|
228
|
+
const hasSupportedEarlierExport = (source, before) => {
|
|
229
|
+
const structure = structuralSource(source);
|
|
230
|
+
const exports = [...structure.matchAll(/\bmodule\s*\.\s*exports\s*=\s*/g)].filter(match => (match.index || 0) < before && isUnconditionalTopLevel(structure, match.index || 0));
|
|
231
|
+
if (exports.length !== 1)
|
|
232
|
+
return false;
|
|
233
|
+
const expressionStart = (exports[0].index || 0) + exports[0][0].length;
|
|
234
|
+
const expression = structure.slice(expressionStart, expressionEnd(structure, expressionStart));
|
|
235
|
+
return hasSupportedMetroExpression(source, expression, exports[0].index || 0);
|
|
236
|
+
};
|
|
237
|
+
const hasSupportedMetroBase = (source, base, exportPosition) => {
|
|
238
|
+
if (/^module\s*\.\s*exports\s*\|\|\s*\{\s*\}$/.test(base))
|
|
239
|
+
return true;
|
|
240
|
+
if (/^module\s*\.\s*exports$/.test(base)) {
|
|
241
|
+
return hasSupportedEarlierExport(source, exportPosition);
|
|
242
|
+
}
|
|
243
|
+
return hasSupportedMetroExpression(source, base, exportPosition);
|
|
244
|
+
};
|
|
245
|
+
const hasAuthoritativeMetroWrapper = (source, wrapper) => {
|
|
246
|
+
if (!hasPackageWrapperBinding(source, wrapper))
|
|
247
|
+
return false;
|
|
248
|
+
const executable = stripJavaScriptComments(source);
|
|
249
|
+
const structure = structuralSource(executable);
|
|
250
|
+
const exports = [
|
|
251
|
+
...structure.matchAll(/\bmodule\s*\.\s*exports\s*=\s*/g),
|
|
252
|
+
...structure.matchAll(/\bexport\s+default\s+/g),
|
|
253
|
+
].filter(match => isUnconditionalTopLevel(structure, match.index || 0))
|
|
254
|
+
.sort((left, right) => (left.index || 0) - (right.index || 0));
|
|
255
|
+
const wrapperExports = exports.filter(match => {
|
|
256
|
+
const expressionStart = (match.index || 0) + match[0].length;
|
|
257
|
+
return new RegExp(`^\\s*${escapeRegExp(wrapper)}\\s*\\(`).test(structure.slice(expressionStart));
|
|
258
|
+
});
|
|
259
|
+
if (wrapperExports.length !== 1 || wrapperExports[0] !== exports[exports.length - 1]) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
const wrapperExport = wrapperExports[0];
|
|
263
|
+
const expressionStart = (wrapperExport.index || 0) + wrapperExport[0].length;
|
|
264
|
+
const opening = structure.indexOf('(', expressionStart + wrapper.length);
|
|
265
|
+
const closing = opening < 0 ? -1 : findBalancedParenthesis(structure, opening);
|
|
266
|
+
if (closing < 0)
|
|
267
|
+
return false;
|
|
268
|
+
if (!/^\s*;?\s*$/.test(structure.slice(closing + 1)))
|
|
269
|
+
return false;
|
|
270
|
+
const argumentsList = splitTopLevelArguments(structure.slice(opening + 1, closing));
|
|
271
|
+
if (!argumentsList[0])
|
|
272
|
+
return false;
|
|
273
|
+
return hasSupportedMetroBase(executable, argumentsList[0], wrapperExport.index || 0);
|
|
274
|
+
};
|
|
275
|
+
exports.hasAuthoritativeMetroWrapper = hasAuthoritativeMetroWrapper;
|
|
276
|
+
const findSingleMetroConfig = (projectRoot) => {
|
|
277
|
+
const existing = exports.METRO_CONFIG_FILES.filter(file => (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, file).exists);
|
|
278
|
+
if (existing.length > 1) {
|
|
279
|
+
throw new Error(`Multiple Metro config files were found (${existing.join(', ')}). ` +
|
|
280
|
+
'Keep one authoritative Metro config before running Bundle Drop setup.');
|
|
281
|
+
}
|
|
282
|
+
return existing[0];
|
|
283
|
+
};
|
|
284
|
+
exports.findSingleMetroConfig = findSingleMetroConfig;
|
|
285
|
+
const packageUsesEsm = (projectRoot) => {
|
|
286
|
+
const packageFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, 'package.json');
|
|
287
|
+
if (!packageFile.exists)
|
|
288
|
+
return false;
|
|
289
|
+
const manifest = JSON.parse(packageFile.content);
|
|
290
|
+
return manifest.type === 'module';
|
|
291
|
+
};
|
|
292
|
+
const newCommonJsMetroConfigFile = (projectRoot) => packageUsesEsm(projectRoot) ? 'metro.config.cjs' : 'metro.config.js';
|
|
293
|
+
exports.newCommonJsMetroConfigFile = newCommonJsMetroConfigFile;
|
|
294
|
+
const assertCommonJsMetroConfig = (projectRoot, relativePath) => {
|
|
295
|
+
const extension = path_1.default.extname(relativePath);
|
|
296
|
+
if (extension === '.mjs' ||
|
|
297
|
+
extension === '.ts' ||
|
|
298
|
+
(extension === '.js' && packageUsesEsm(projectRoot))) {
|
|
299
|
+
throw new Error(`${relativePath} uses ESM or TypeScript syntax. Bundle Drop will not append CommonJS ` +
|
|
300
|
+
'to it automatically; wrap its exported config manually, then rerun setup.');
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
exports.assertCommonJsMetroConfig = assertCommonJsMetroConfig;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MobilePlatform } from '../../../expo';
|
|
2
|
+
export type NativeRuntimeIdentity = {
|
|
3
|
+
schemaVersion: 1;
|
|
4
|
+
platform: MobilePlatform;
|
|
5
|
+
source: 'bundle-drop';
|
|
6
|
+
runtimeVersion: string;
|
|
7
|
+
} | {
|
|
8
|
+
schemaVersion: 1;
|
|
9
|
+
platform: MobilePlatform;
|
|
10
|
+
source: 'expo';
|
|
11
|
+
};
|
|
12
|
+
export type WriteNativeRuntimeIdentityOptions = {
|
|
13
|
+
projectRoot: string;
|
|
14
|
+
platform: MobilePlatform;
|
|
15
|
+
outputPath?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function resolveNativeRuntimeIdentity(projectRoot: string, platform: MobilePlatform): NativeRuntimeIdentity;
|
|
18
|
+
export declare function writeNativeRuntimeIdentity(options: WriteNativeRuntimeIdentityOptions): NativeRuntimeIdentity;
|
|
19
|
+
export declare function parseNativeRuntimeIdentityArguments(argv: string[]): WriteNativeRuntimeIdentityOptions;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveNativeRuntimeIdentity = resolveNativeRuntimeIdentity;
|
|
7
|
+
exports.writeNativeRuntimeIdentity = writeNativeRuntimeIdentity;
|
|
8
|
+
exports.parseNativeRuntimeIdentityArguments = parseNativeRuntimeIdentityArguments;
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const expo_1 = require("../../../expo");
|
|
12
|
+
function resolveNativeRuntimeIdentity(projectRoot, platform) {
|
|
13
|
+
const authority = (0, expo_1.resolveBundleDropRuntimeVersionAuthority)(projectRoot, platform);
|
|
14
|
+
if (authority.source === 'expo') {
|
|
15
|
+
return { schemaVersion: 1, platform, source: 'expo' };
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
schemaVersion: 1,
|
|
19
|
+
platform,
|
|
20
|
+
source: 'bundle-drop',
|
|
21
|
+
runtimeVersion: authority.runtimeVersion,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function writeAtomically(outputPath, content) {
|
|
25
|
+
const absoluteOutputPath = path_1.default.resolve(outputPath);
|
|
26
|
+
fs_extra_1.default.ensureDirSync(path_1.default.dirname(absoluteOutputPath));
|
|
27
|
+
const temporaryPath = path_1.default.join(path_1.default.dirname(absoluteOutputPath), `.${path_1.default.basename(absoluteOutputPath)}-${process.pid}-${Date.now()}.tmp`);
|
|
28
|
+
try {
|
|
29
|
+
fs_extra_1.default.writeFileSync(temporaryPath, content, 'utf8');
|
|
30
|
+
const descriptor = fs_extra_1.default.openSync(temporaryPath, 'r');
|
|
31
|
+
try {
|
|
32
|
+
fs_extra_1.default.fsyncSync(descriptor);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
fs_extra_1.default.closeSync(descriptor);
|
|
36
|
+
}
|
|
37
|
+
fs_extra_1.default.renameSync(temporaryPath, absoluteOutputPath);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
try {
|
|
41
|
+
fs_extra_1.default.removeSync(temporaryPath);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Preserve the original failure.
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function writeNativeRuntimeIdentity(options) {
|
|
50
|
+
const identity = resolveNativeRuntimeIdentity(options.projectRoot, options.platform);
|
|
51
|
+
const content = `${JSON.stringify(identity)}\n`;
|
|
52
|
+
if (options.outputPath) {
|
|
53
|
+
writeAtomically(options.outputPath, content);
|
|
54
|
+
}
|
|
55
|
+
return identity;
|
|
56
|
+
}
|
|
57
|
+
function parseNativeRuntimeIdentityArguments(argv) {
|
|
58
|
+
const values = new Map();
|
|
59
|
+
for (let index = 0; index < argv.length; index += 2) {
|
|
60
|
+
const flag = argv[index];
|
|
61
|
+
const value = argv[index + 1];
|
|
62
|
+
if (!['--project-root', '--platform', '--output'].includes(flag) || !value) {
|
|
63
|
+
throw new Error('Usage: write-runtime-identity --project-root <path> --platform ios|android [--output <path>]');
|
|
64
|
+
}
|
|
65
|
+
if (values.has(flag))
|
|
66
|
+
throw new Error(`Duplicate argument ${flag}.`);
|
|
67
|
+
values.set(flag, value);
|
|
68
|
+
}
|
|
69
|
+
const projectRoot = values.get('--project-root');
|
|
70
|
+
const platform = values.get('--platform');
|
|
71
|
+
if (!projectRoot || (platform !== 'ios' && platform !== 'android')) {
|
|
72
|
+
throw new Error('Usage: write-runtime-identity --project-root <path> --platform ios|android [--output <path>]');
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
projectRoot,
|
|
76
|
+
platform,
|
|
77
|
+
...(values.get('--output') ? { outputPath: values.get('--output') } : {}),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/* istanbul ignore next */
|
|
81
|
+
if (require.main === module) {
|
|
82
|
+
try {
|
|
83
|
+
const identity = writeNativeRuntimeIdentity(parseNativeRuntimeIdentityArguments(process.argv.slice(2)));
|
|
84
|
+
if (!process.argv.includes('--output')) {
|
|
85
|
+
process.stdout.write(`${JSON.stringify(identity)}\n`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
process.stderr.write(`${error.message}\n`);
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
}
|
|
92
|
+
}
|