@gfean/react-native-bundle-drop 0.4.6 → 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 +166 -79
- 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 +228 -43
- 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 +246 -32
- package/lib/CLI/scripts/login-cli.js +35 -10
- 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/CLI/scripts/sight-artifacts.d.ts +17 -0
- package/lib/CLI/scripts/sight-artifacts.js +204 -0
- package/lib/CLI/scripts/sight-cli.d.ts +10 -0
- package/lib/CLI/scripts/sight-cli.js +127 -0
- package/lib/CLI/scripts/sight-session.d.ts +14 -0
- package/lib/CLI/scripts/sight-session.js +192 -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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import CryptoKit
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
enum BundleDropRuntimeCrypto {
|
|
5
|
+
static func sha256String(_ value: String) -> String {
|
|
6
|
+
SHA256.hash(data: Data(value.utf8)).map { String(format: "%02x", $0) }.joined()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static func verifyEs256Signature(
|
|
10
|
+
signingInput: String,
|
|
11
|
+
signatureBase64Url: String,
|
|
12
|
+
xBase64Url: String,
|
|
13
|
+
yBase64Url: String
|
|
14
|
+
) throws -> Bool {
|
|
15
|
+
let signatureBytes = try decodeBase64Url(signatureBase64Url)
|
|
16
|
+
let x = try decodeBase64Url(xBase64Url)
|
|
17
|
+
let y = try decodeBase64Url(yBase64Url)
|
|
18
|
+
guard signatureBytes.count == 64 else {
|
|
19
|
+
throw error("ES256 signature must be 64 bytes")
|
|
20
|
+
}
|
|
21
|
+
guard x.count == 32 && y.count == 32 else {
|
|
22
|
+
throw error("P-256 coordinates must be 32 bytes")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let publicKey = try P256.Signing.PublicKey(
|
|
26
|
+
x963Representation: Data([0x04]) + x + y
|
|
27
|
+
)
|
|
28
|
+
let signature = try P256.Signing.ECDSASignature(rawRepresentation: signatureBytes)
|
|
29
|
+
return publicKey.isValidSignature(signature, for: Data(signingInput.utf8))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private static func decodeBase64Url(_ value: String) throws -> Data {
|
|
33
|
+
var normalized = value.replacingOccurrences(of: "-", with: "+")
|
|
34
|
+
.replacingOccurrences(of: "_", with: "/")
|
|
35
|
+
normalized += String(repeating: "=", count: (4 - normalized.count % 4) % 4)
|
|
36
|
+
guard let data = Data(base64Encoded: normalized) else {
|
|
37
|
+
throw error("Invalid base64url value")
|
|
38
|
+
}
|
|
39
|
+
return data
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private static func error(_ message: String) -> NSError {
|
|
43
|
+
NSError(domain: "BundleDrop", code: 1, userInfo: [NSLocalizedDescriptionKey: message])
|
|
44
|
+
}
|
|
45
|
+
}
|
package/lib/CLI/cli.d.ts
CHANGED
package/lib/CLI/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.buildProgram = void 0;
|
|
7
|
+
exports.runCli = exports.buildProgram = void 0;
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
10
|
const commander_1 = require("commander");
|
|
@@ -12,6 +12,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
12
12
|
const os_1 = __importDefault(require("os"));
|
|
13
13
|
const path_1 = __importDefault(require("path"));
|
|
14
14
|
const upload_cli_1 = __importDefault(require("./scripts/upload-cli"));
|
|
15
|
+
const sight_cli_1 = require("./scripts/sight-cli");
|
|
15
16
|
const post_init_1 = require("./scripts/post-init");
|
|
16
17
|
const logo_1 = require("./logo");
|
|
17
18
|
const package_json_1 = __importDefault(require("../../package.json"));
|
|
@@ -20,10 +21,23 @@ const DEFAULT_SERVER_URL = 'https://api.bundledrop.app';
|
|
|
20
21
|
const DOCS_CLI_URL = 'https://bundledrop.app/docs/cli';
|
|
21
22
|
const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
|
|
22
23
|
const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
|
|
23
|
-
const
|
|
24
|
-
const
|
|
24
|
+
const DOCS_MANUAL_SETUP_URL = 'https://bundledrop.app/docs/manual-setup';
|
|
25
|
+
const setupErrorWithManualSetup = (error) => {
|
|
25
26
|
const message = error instanceof Error ? error.message : String(error);
|
|
26
|
-
return new Error(`${message}\nManual
|
|
27
|
+
return new Error(`${message}\nManual setup: ${DOCS_MANUAL_SETUP_URL}`);
|
|
28
|
+
};
|
|
29
|
+
const runSetupWithManualFallback = async (params) => {
|
|
30
|
+
try {
|
|
31
|
+
await (0, post_init_1.runPostInitPrompts)(params.options);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (params.preservePendingConfig &&
|
|
35
|
+
params.pendingConfig &&
|
|
36
|
+
!fs_1.default.existsSync(params.pendingConfig.configPath)) {
|
|
37
|
+
await fs_1.default.promises.writeFile(params.pendingConfig.configPath, params.pendingConfig.content, 'utf8');
|
|
38
|
+
}
|
|
39
|
+
throw setupErrorWithManualSetup(error);
|
|
40
|
+
}
|
|
27
41
|
};
|
|
28
42
|
const getTokenPath = () => path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
|
|
29
43
|
const normalizeServerUrl = (url) => url?.replace(/\/$/, '') || DEFAULT_SERVER_URL;
|
|
@@ -96,6 +110,7 @@ ${chalk_1.default.bold.cyan('Common Usage:')}
|
|
|
96
110
|
${chalk_1.default.gray('bundle-drop login')}
|
|
97
111
|
${chalk_1.default.gray('bundle-drop init')}
|
|
98
112
|
${chalk_1.default.gray('bundle-drop doctor')}
|
|
113
|
+
${chalk_1.default.gray('bundle-drop sight')}
|
|
99
114
|
${chalk_1.default.gray('bundle-drop doctor --project-type bare --platform android')}
|
|
100
115
|
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel develop')}
|
|
101
116
|
${chalk_1.default.gray('bundle-drop upload ios --plist-file ios/Info.plist --channel develop')}
|
|
@@ -104,6 +119,23 @@ ${chalk_1.default.bold.cyan('Common Usage:')}
|
|
|
104
119
|
${chalk_1.default.gray('Docs →')} ${chalk_1.default.underline.gray(DOCS_CLI_URL)}
|
|
105
120
|
${chalk_1.default.gray('Uploading →')} ${chalk_1.default.underline.gray(DOCS_UPLOADING_URL)}
|
|
106
121
|
${chalk_1.default.gray('CI/CD →')} ${chalk_1.default.underline.gray(DOCS_CI_CD_URL)}\n`);
|
|
122
|
+
program
|
|
123
|
+
.command('sight')
|
|
124
|
+
.option('--platform <platform>', 'Platform to analyze: ios or android')
|
|
125
|
+
.option('--project-type <type>', 'Force project type: expo or bare')
|
|
126
|
+
.option('--entry-file <path>', 'Override the React Native entry file')
|
|
127
|
+
.option('--no-open', 'Keep the generated files and do not open the browser')
|
|
128
|
+
.option('--keep', 'Keep generated files after the browser loads them')
|
|
129
|
+
.option('--output <path>', 'Generate persistent files in an empty directory')
|
|
130
|
+
.description('Generate a production bundle and inspect it locally in Bundle Drop Sight')
|
|
131
|
+
.addHelpText('after', `
|
|
132
|
+
${chalk_1.default.bold('Examples:')}
|
|
133
|
+
${chalk_1.default.gray('bundle-drop sight')}
|
|
134
|
+
${chalk_1.default.gray('bundle-drop sight --platform android')}
|
|
135
|
+
${chalk_1.default.gray('bundle-drop sight --platform ios --keep')}
|
|
136
|
+
${chalk_1.default.gray('bundle-drop sight --no-open --output ./sight-analysis')}
|
|
137
|
+
`)
|
|
138
|
+
.action(sight_cli_1.runSightCommand);
|
|
107
139
|
program
|
|
108
140
|
.command('upload <platform>')
|
|
109
141
|
.option('--plist-file <path>', 'Path to Info.plist for iOS')
|
|
@@ -151,98 +183,109 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
|
|
|
151
183
|
.option('--token <token>', 'Personal Access Token (alternative to `bundle-drop login`)')
|
|
152
184
|
.option('--project-type <type>', 'Force project type: expo or bare')
|
|
153
185
|
.option('--dry-run', 'Preview setup and AI context without changing files')
|
|
186
|
+
.option('--migrate-code-push', 'Explicitly remove react-native-code-push after reviewing its native migration')
|
|
154
187
|
.option('--migrate-expo-updates', 'Explicitly remove active expo-updates configuration and dependency')
|
|
155
188
|
.option('--prebuild', 'Run a layered Expo prebuild for committed native directories')
|
|
156
189
|
.option('--yes', 'Approve ordinary setup changes noninteractively')
|
|
157
190
|
.description('Configure Bundle Drop for Expo or bare React Native')
|
|
158
191
|
.action(async (options) => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (options.token) {
|
|
164
|
-
const { detectProjectType } = require('../expo');
|
|
165
|
-
const projectType = detectProjectType({
|
|
166
|
-
projectRoot: process.cwd(),
|
|
167
|
-
explicitType: options.projectType,
|
|
168
|
-
});
|
|
169
|
-
const serverUrl = normalizeServerUrl(process.env.BUNDLE_DROP_SERVER_URL);
|
|
170
|
-
const tokenContext = await fetchFreshAuthContext({
|
|
171
|
-
serverUrl,
|
|
172
|
-
token: options.token,
|
|
173
|
-
});
|
|
174
|
-
const initConfigModule = require('../CLI/scripts/init-config');
|
|
175
|
-
const hadConfig = initConfigModule.hasExistingBundleDropConfig();
|
|
176
|
-
const configResult = await initConfigModule.initConfig({
|
|
177
|
-
serverUrl,
|
|
178
|
-
projects: tokenContext?.projects || [],
|
|
179
|
-
organizations: tokenContext?.organizations || [],
|
|
180
|
-
downloadApiKey: '',
|
|
181
|
-
authToken: options.token,
|
|
182
|
-
dryRun: true,
|
|
183
|
-
projectType,
|
|
184
|
-
});
|
|
185
|
-
await (0, post_init_1.runPostInitPrompts)({
|
|
186
|
-
...options,
|
|
187
|
-
projectType,
|
|
188
|
-
...(!hadConfig && configResult
|
|
189
|
-
? {
|
|
190
|
-
virtualConfig: {
|
|
191
|
-
content: configResult.content,
|
|
192
|
-
serverUrl: configResult.serverUrl,
|
|
193
|
-
orgSlug: configResult.orgSlug,
|
|
194
|
-
projectSlug: configResult.projectSlug,
|
|
195
|
-
authToken: options.token,
|
|
196
|
-
},
|
|
197
|
-
}
|
|
198
|
-
: {}),
|
|
199
|
-
});
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const authState = readStoredAuthData();
|
|
203
|
-
if (!authState.exists) {
|
|
204
|
-
console.log('ℹ️ Not logged in. Please run `bundle-drop login` or use --token.\n' +
|
|
205
|
-
`CLI docs: ${DOCS_CLI_URL}\n` +
|
|
206
|
-
`CI/CD docs: ${DOCS_CI_CD_URL}`);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
if (authState.isInvalid || !authState.data) {
|
|
210
|
-
logInvalidAuthFile();
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const data = authState.data;
|
|
214
|
-
if (!data.token) {
|
|
215
|
-
logInvalidAuthFile();
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
192
|
+
if (options.projectType && !['expo', 'bare'].includes(options.projectType)) {
|
|
193
|
+
throw new Error('--project-type must be expo or bare.');
|
|
194
|
+
}
|
|
195
|
+
if (options.token) {
|
|
218
196
|
const { detectProjectType } = require('../expo');
|
|
219
197
|
const projectType = detectProjectType({
|
|
220
198
|
projectRoot: process.cwd(),
|
|
221
199
|
explicitType: options.projectType,
|
|
222
200
|
});
|
|
223
|
-
const serverUrl = normalizeServerUrl(
|
|
224
|
-
const
|
|
201
|
+
const serverUrl = normalizeServerUrl(process.env.BUNDLE_DROP_SERVER_URL);
|
|
202
|
+
const tokenContext = await fetchFreshAuthContext({
|
|
225
203
|
serverUrl,
|
|
226
|
-
token:
|
|
204
|
+
token: options.token,
|
|
227
205
|
});
|
|
228
|
-
const initData = freshContext ? { ...data, ...freshContext } : data;
|
|
229
|
-
if (freshContext) {
|
|
230
|
-
writeStoredAuthData(authState.tokenPath, initData);
|
|
231
|
-
}
|
|
232
206
|
const initConfigModule = require('../CLI/scripts/init-config');
|
|
233
207
|
const hadConfig = initConfigModule.hasExistingBundleDropConfig();
|
|
234
208
|
const configResult = await initConfigModule.initConfig({
|
|
235
209
|
serverUrl,
|
|
236
|
-
projects:
|
|
237
|
-
organizations:
|
|
238
|
-
downloadApiKey:
|
|
239
|
-
authToken:
|
|
210
|
+
projects: tokenContext?.projects || [],
|
|
211
|
+
organizations: tokenContext?.organizations || [],
|
|
212
|
+
downloadApiKey: '',
|
|
213
|
+
authToken: options.token,
|
|
240
214
|
dryRun: true,
|
|
241
215
|
projectType,
|
|
242
216
|
});
|
|
243
|
-
await (
|
|
217
|
+
await runSetupWithManualFallback({
|
|
218
|
+
options: {
|
|
219
|
+
...options,
|
|
220
|
+
projectType,
|
|
221
|
+
...(configResult?.bootstrapContent
|
|
222
|
+
? { runtimeDeliveryBootstrap: { content: configResult.bootstrapContent } }
|
|
223
|
+
: {}),
|
|
224
|
+
...(!hadConfig && configResult
|
|
225
|
+
? {
|
|
226
|
+
virtualConfig: {
|
|
227
|
+
content: configResult.content,
|
|
228
|
+
serverUrl: configResult.serverUrl,
|
|
229
|
+
orgSlug: configResult.orgSlug,
|
|
230
|
+
projectSlug: configResult.projectSlug,
|
|
231
|
+
authToken: options.token,
|
|
232
|
+
},
|
|
233
|
+
}
|
|
234
|
+
: {}),
|
|
235
|
+
},
|
|
236
|
+
pendingConfig: configResult || undefined,
|
|
237
|
+
preservePendingConfig: !hadConfig && !options.dryRun,
|
|
238
|
+
});
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const authState = readStoredAuthData();
|
|
242
|
+
if (!authState.exists) {
|
|
243
|
+
console.log('ℹ️ Not logged in. Please run `bundle-drop login` or use --token.\n' +
|
|
244
|
+
`CLI docs: ${DOCS_CLI_URL}\n` +
|
|
245
|
+
`CI/CD docs: ${DOCS_CI_CD_URL}`);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (authState.isInvalid || !authState.data) {
|
|
249
|
+
logInvalidAuthFile();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const data = authState.data;
|
|
253
|
+
if (!data.token) {
|
|
254
|
+
logInvalidAuthFile();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const { detectProjectType } = require('../expo');
|
|
258
|
+
const projectType = detectProjectType({
|
|
259
|
+
projectRoot: process.cwd(),
|
|
260
|
+
explicitType: options.projectType,
|
|
261
|
+
});
|
|
262
|
+
const serverUrl = normalizeServerUrl(data.serverUrl || data.baseUrl || process.env.BUNDLE_DROP_SERVER_URL);
|
|
263
|
+
const freshContext = await fetchFreshAuthContext({
|
|
264
|
+
serverUrl,
|
|
265
|
+
token: data.token,
|
|
266
|
+
});
|
|
267
|
+
const initData = freshContext ? { ...data, ...freshContext } : data;
|
|
268
|
+
if (freshContext) {
|
|
269
|
+
writeStoredAuthData(authState.tokenPath, initData);
|
|
270
|
+
}
|
|
271
|
+
const initConfigModule = require('../CLI/scripts/init-config');
|
|
272
|
+
const hadConfig = initConfigModule.hasExistingBundleDropConfig();
|
|
273
|
+
const configResult = await initConfigModule.initConfig({
|
|
274
|
+
serverUrl,
|
|
275
|
+
projects: initData.projects || [],
|
|
276
|
+
organizations: initData.organizations || [],
|
|
277
|
+
downloadApiKey: data.downloadApiKey || '',
|
|
278
|
+
authToken: data.token,
|
|
279
|
+
dryRun: true,
|
|
280
|
+
projectType,
|
|
281
|
+
});
|
|
282
|
+
await runSetupWithManualFallback({
|
|
283
|
+
options: {
|
|
244
284
|
...options,
|
|
245
285
|
projectType,
|
|
286
|
+
...(configResult?.bootstrapContent
|
|
287
|
+
? { runtimeDeliveryBootstrap: { content: configResult.bootstrapContent } }
|
|
288
|
+
: {}),
|
|
246
289
|
...(!hadConfig && configResult
|
|
247
290
|
? {
|
|
248
291
|
virtualConfig: {
|
|
@@ -254,10 +297,43 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
|
|
|
254
297
|
},
|
|
255
298
|
}
|
|
256
299
|
: {}),
|
|
257
|
-
}
|
|
300
|
+
},
|
|
301
|
+
pendingConfig: configResult || undefined,
|
|
302
|
+
preservePendingConfig: !hadConfig && !options.dryRun,
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
program
|
|
306
|
+
.command('sync')
|
|
307
|
+
.option('--token <token>', 'Personal Access Token (alternative to `bundle-drop login`)')
|
|
308
|
+
.option('--dry-run', 'Validate and preview bootstrap synchronization without writing')
|
|
309
|
+
.description('Refresh the package-managed runtime delivery bootstrap')
|
|
310
|
+
.action(async (options) => {
|
|
311
|
+
const initConfigModule = require('../CLI/scripts/init-config');
|
|
312
|
+
if (!initConfigModule.hasExistingBundleDropConfig()) {
|
|
313
|
+
throw new Error('bundle-drop sync requires bundle.drop.config.js. Run `bundle-drop init` first.');
|
|
314
|
+
}
|
|
315
|
+
const authState = options.token ? null : readStoredAuthData();
|
|
316
|
+
const token = options.token || authState?.data?.token;
|
|
317
|
+
if (!token) {
|
|
318
|
+
throw new Error('Not authenticated. Run `bundle-drop login` or pass --token.');
|
|
319
|
+
}
|
|
320
|
+
const serverUrl = normalizeServerUrl(authState?.data?.serverUrl || authState?.data?.baseUrl || process.env.BUNDLE_DROP_SERVER_URL);
|
|
321
|
+
const result = await initConfigModule.initConfig({
|
|
322
|
+
serverUrl,
|
|
323
|
+
projects: [],
|
|
324
|
+
organizations: [],
|
|
325
|
+
authToken: token,
|
|
326
|
+
dryRun: Boolean(options.dryRun),
|
|
327
|
+
});
|
|
328
|
+
const deliveryDisabled = result?.bootstrapRetired === true;
|
|
329
|
+
if (!result?.bootstrapContent && !deliveryDisabled) {
|
|
330
|
+
throw new Error('The backend did not return a valid runtime delivery bootstrap for this project. ' +
|
|
331
|
+
'The existing bootstrap was preserved.');
|
|
258
332
|
}
|
|
259
|
-
|
|
260
|
-
|
|
333
|
+
if (options.dryRun) {
|
|
334
|
+
console.log(chalk_1.default.gray(deliveryDisabled
|
|
335
|
+
? 'Runtime delivery is disabled; the stale bootstrap would be removed. No files changed.'
|
|
336
|
+
: 'Runtime delivery bootstrap is valid. No files changed.'));
|
|
261
337
|
}
|
|
262
338
|
});
|
|
263
339
|
program
|
|
@@ -321,6 +397,17 @@ ${chalk_1.default.bold('Examples:')}
|
|
|
321
397
|
return program;
|
|
322
398
|
};
|
|
323
399
|
exports.buildProgram = buildProgram;
|
|
400
|
+
const runCli = async (argv = process.argv) => {
|
|
401
|
+
try {
|
|
402
|
+
await (0, exports.buildProgram)().parseAsync(argv);
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
406
|
+
console.error(chalk_1.default.red(`❌ ${message}`));
|
|
407
|
+
process.exitCode = 1;
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
exports.runCli = runCli;
|
|
324
411
|
if (require.main === module) {
|
|
325
|
-
(0, exports.
|
|
412
|
+
void (0, exports.runCli)();
|
|
326
413
|
}
|
|
@@ -6,26 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.restoreSetupBackups = restoreSetupBackups;
|
|
7
7
|
exports.applySetupPatchPlans = applySetupPatchPlans;
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
9
|
const validate_plan_1 = require("./validate-plan");
|
|
10
|
+
const safe_file_transaction_1 = require("../safe-file-transaction");
|
|
12
11
|
const sha256 = (content) => crypto_1.default.createHash('sha256').update(content).digest('hex');
|
|
13
|
-
const timestamp = () => new Date().toISOString().replace(/[:.]/g, '-');
|
|
14
12
|
const isAllowedSetupFile = (projectType, filePath) => projectType === 'expo'
|
|
15
13
|
? (0, validate_plan_1.isPatchableExpoConfig)(filePath)
|
|
16
14
|
: (0, validate_plan_1.isPatchableNativeEntrypoint)(filePath);
|
|
17
15
|
function restoreSetupBackups(result) {
|
|
18
16
|
for (const relativePath of result.changedFiles) {
|
|
19
|
-
|
|
20
|
-
if (fs_extra_1.default.existsSync(backupPath)) {
|
|
21
|
-
fs_extra_1.default.copyFileSync(backupPath, path_1.default.join(result.projectRoot, relativePath));
|
|
22
|
-
}
|
|
17
|
+
(0, safe_file_transaction_1.restoreProjectFile)(result.projectRoot, result.backupDir, relativePath);
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
20
|
function applySetupPatchPlans(params) {
|
|
26
21
|
const result = {
|
|
27
22
|
projectRoot: params.projectRoot,
|
|
28
|
-
backupDir:
|
|
23
|
+
backupDir: (0, safe_file_transaction_1.createSafeBackupDirectory)(params.projectRoot, 'ai-setup'),
|
|
29
24
|
changedFiles: [],
|
|
30
25
|
};
|
|
31
26
|
try {
|
|
@@ -33,18 +28,13 @@ function applySetupPatchPlans(params) {
|
|
|
33
28
|
if (!(0, validate_plan_1.isSafeRelativePath)(change.file) || !isAllowedSetupFile(params.projectType, change.file)) {
|
|
34
29
|
throw new Error(`Refusing to write AI setup plan outside its allowlist: ${change.file}`);
|
|
35
30
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
if (sha256(original) !== change.originalSha256) {
|
|
31
|
+
const target = (0, safe_file_transaction_1.inspectProjectFile)(params.projectRoot, change.file);
|
|
32
|
+
if (!target.exists || sha256(target.content) !== change.originalSha256) {
|
|
39
33
|
throw new Error(`File changed since AI setup scan: ${change.file}`);
|
|
40
34
|
}
|
|
41
|
-
|
|
42
|
-
fs_extra_1.default.ensureDirSync(path_1.default.dirname(backupPath));
|
|
43
|
-
fs_extra_1.default.copyFileSync(targetPath, backupPath);
|
|
35
|
+
(0, safe_file_transaction_1.writeBackupFile)(result.backupDir, change.file, target.content, target.mode);
|
|
44
36
|
result.changedFiles.push(change.file);
|
|
45
|
-
|
|
46
|
-
fs_extra_1.default.writeFileSync(temporaryPath, change.updated, 'utf8');
|
|
47
|
-
fs_extra_1.default.renameSync(temporaryPath, targetPath);
|
|
37
|
+
(0, safe_file_transaction_1.writeProjectFileAtomically)(params.projectRoot, change.file, change.updated, target.mode);
|
|
48
38
|
}
|
|
49
39
|
return result;
|
|
50
40
|
}
|
|
@@ -5,7 +5,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.requestAiSetupPlan = requestAiSetupPlan;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const credential_safety_1 = require("./credential-safety");
|
|
9
|
+
const terminal_safety_1 = require("./terminal-safety");
|
|
8
10
|
const DEFAULT_AI_INIT_TIMEOUT_MS = 180000;
|
|
11
|
+
const MAX_BACKEND_DIAGNOSTIC_LENGTH = 1000;
|
|
12
|
+
const safeBackendDiagnostic = (value) => {
|
|
13
|
+
if (typeof value !== 'string')
|
|
14
|
+
return null;
|
|
15
|
+
const diagnostic = value.trim();
|
|
16
|
+
if (!diagnostic ||
|
|
17
|
+
diagnostic.length > MAX_BACKEND_DIAGNOSTIC_LENGTH ||
|
|
18
|
+
(0, credential_safety_1.findKnownBundleDropCredential)(diagnostic)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return (0, terminal_safety_1.escapeTerminalControls)(diagnostic);
|
|
22
|
+
};
|
|
23
|
+
const safeBackendDetailReason = (details) => {
|
|
24
|
+
if (!details || typeof details !== 'object' || Array.isArray(details))
|
|
25
|
+
return null;
|
|
26
|
+
const descriptor = Object.getOwnPropertyDescriptor(details, 'reason');
|
|
27
|
+
if (!descriptor || !Object.prototype.hasOwnProperty.call(descriptor, 'value'))
|
|
28
|
+
return null;
|
|
29
|
+
return safeBackendDiagnostic(descriptor.value);
|
|
30
|
+
};
|
|
9
31
|
const resolveTimeoutMs = () => {
|
|
10
32
|
const value = Number(process.env.BUNDLE_DROP_AI_INIT_TIMEOUT_MS || '');
|
|
11
33
|
return Number.isFinite(value) && value > 0 ? value : DEFAULT_AI_INIT_TIMEOUT_MS;
|
|
@@ -26,9 +48,12 @@ async function requestAiSetupPlan(params) {
|
|
|
26
48
|
if (error?.code === 'ECONNABORTED' || /timeout/i.test(String(error?.message || ''))) {
|
|
27
49
|
throw new Error('AI setup planning timed out. Try again, or increase BUNDLE_DROP_AI_INIT_TIMEOUT_MS.');
|
|
28
50
|
}
|
|
29
|
-
const
|
|
30
|
-
? raw.
|
|
31
|
-
: raw
|
|
32
|
-
|
|
51
|
+
const diagnostic = raw && typeof raw === 'object'
|
|
52
|
+
? safeBackendDetailReason(raw.details) || safeBackendDiagnostic(raw.error)
|
|
53
|
+
: safeBackendDiagnostic(raw);
|
|
54
|
+
const fallback = diagnostic || safeBackendDiagnostic(error?.message);
|
|
55
|
+
throw new Error(fallback
|
|
56
|
+
? `AI setup planning failed: ${fallback}`
|
|
57
|
+
: 'AI setup planning failed');
|
|
33
58
|
}
|
|
34
59
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds CodePush ownership outside package files and provider-patched native entrypoints.
|
|
3
|
+
* Only relative paths are returned; file contents never leave this local validation boundary.
|
|
4
|
+
*/
|
|
5
|
+
export declare function findCodePushResiduePaths(projectRoot: string): string[];
|
|
@@ -0,0 +1,126 @@
|
|
|
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.findCodePushResiduePaths = findCodePushResiduePaths;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const MAX_VISITED_ENTRIES = 20000;
|
|
10
|
+
const MAX_CANDIDATE_FILES = 500;
|
|
11
|
+
const MAX_FILE_BYTES = 1024 * 1024;
|
|
12
|
+
const MAX_TOTAL_BYTES = 5 * 1024 * 1024;
|
|
13
|
+
const SKIPPED_DIRECTORIES = new Set([
|
|
14
|
+
'.bundle-drop',
|
|
15
|
+
'.bundledrop-backup',
|
|
16
|
+
'.expo',
|
|
17
|
+
'.git',
|
|
18
|
+
'.gradle',
|
|
19
|
+
'build',
|
|
20
|
+
'coverage',
|
|
21
|
+
'deriveddata',
|
|
22
|
+
'dist',
|
|
23
|
+
'generated',
|
|
24
|
+
'lib',
|
|
25
|
+
'node_modules',
|
|
26
|
+
'pods',
|
|
27
|
+
'vendor',
|
|
28
|
+
]);
|
|
29
|
+
const JS_SOURCE_EXTENSION = /\.(?:cjs|cts|js|jsx|mjs|mts|ts|tsx)$/i;
|
|
30
|
+
const CODE_PUSH_REFERENCE = /\b(?:react-native-code-push|code[\s_.-]*push|com\.microsoft\.codepush\.react)/i;
|
|
31
|
+
const toPosix = (filePath) => filePath.split(path_1.default.sep).join('/');
|
|
32
|
+
const isCodePushResidueCandidate = (relativePath) => {
|
|
33
|
+
const parts = relativePath.split('/');
|
|
34
|
+
const basename = parts[parts.length - 1];
|
|
35
|
+
if (JS_SOURCE_EXTENSION.test(basename))
|
|
36
|
+
return true;
|
|
37
|
+
if (parts[0] === 'android') {
|
|
38
|
+
if (/^MainApplication\.(?:java|kt)$/i.test(basename))
|
|
39
|
+
return false;
|
|
40
|
+
return /\.(?:gradle|gradle\.kts|java|kt|properties|xml)$/i.test(basename);
|
|
41
|
+
}
|
|
42
|
+
if (parts[0] === 'ios') {
|
|
43
|
+
if (/^AppDelegate\.(?:m|mm|swift)$/i.test(basename))
|
|
44
|
+
return false;
|
|
45
|
+
return basename === 'Podfile' ||
|
|
46
|
+
/\.(?:h|m|mm|pbxproj|plist|podspec|swift|xcconfig)$/i.test(basename);
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
};
|
|
50
|
+
const scanLimitError = (detail) => new Error(`CodePush residue validation could not safely complete (${detail}). ` +
|
|
51
|
+
'Clean up CodePush manually or reduce the project scan surface, then retry. No files changed.');
|
|
52
|
+
/**
|
|
53
|
+
* Finds CodePush ownership outside package files and provider-patched native entrypoints.
|
|
54
|
+
* Only relative paths are returned; file contents never leave this local validation boundary.
|
|
55
|
+
*/
|
|
56
|
+
function findCodePushResiduePaths(projectRoot) {
|
|
57
|
+
const pendingDirectories = [''];
|
|
58
|
+
const residuePaths = [];
|
|
59
|
+
let visitedEntries = 0;
|
|
60
|
+
let candidateFiles = 0;
|
|
61
|
+
let totalBytes = 0;
|
|
62
|
+
while (pendingDirectories.length) {
|
|
63
|
+
const relativeDirectory = pendingDirectories.pop();
|
|
64
|
+
const absoluteDirectory = path_1.default.join(projectRoot, relativeDirectory);
|
|
65
|
+
let entries;
|
|
66
|
+
try {
|
|
67
|
+
entries = fs_extra_1.default.readdirSync(absoluteDirectory, { withFileTypes: true });
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw scanLimitError(`cannot inspect ${toPosix(relativeDirectory) || '.'}`);
|
|
71
|
+
}
|
|
72
|
+
entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
visitedEntries += 1;
|
|
75
|
+
if (visitedEntries > MAX_VISITED_ENTRIES) {
|
|
76
|
+
throw scanLimitError(`more than ${MAX_VISITED_ENTRIES} filesystem entries`);
|
|
77
|
+
}
|
|
78
|
+
const relativePath = relativeDirectory
|
|
79
|
+
? path_1.default.join(relativeDirectory, entry.name)
|
|
80
|
+
: entry.name;
|
|
81
|
+
const absolutePath = path_1.default.join(projectRoot, relativePath);
|
|
82
|
+
let stat;
|
|
83
|
+
try {
|
|
84
|
+
stat = fs_extra_1.default.lstatSync(absolutePath);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw scanLimitError(`cannot inspect ${toPosix(relativePath)}`);
|
|
88
|
+
}
|
|
89
|
+
if (SKIPPED_DIRECTORIES.has(entry.name.toLowerCase()))
|
|
90
|
+
continue;
|
|
91
|
+
if (stat.isSymbolicLink()) {
|
|
92
|
+
throw scanLimitError(`relevant project path ${toPosix(relativePath)} is a symbolic link`);
|
|
93
|
+
}
|
|
94
|
+
if (stat.isDirectory()) {
|
|
95
|
+
pendingDirectories.push(relativePath);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (!stat.isFile())
|
|
99
|
+
continue;
|
|
100
|
+
const posixPath = toPosix(relativePath);
|
|
101
|
+
if (!isCodePushResidueCandidate(posixPath))
|
|
102
|
+
continue;
|
|
103
|
+
candidateFiles += 1;
|
|
104
|
+
if (candidateFiles > MAX_CANDIDATE_FILES) {
|
|
105
|
+
throw scanLimitError(`more than ${MAX_CANDIDATE_FILES} relevant files`);
|
|
106
|
+
}
|
|
107
|
+
if (stat.size > MAX_FILE_BYTES) {
|
|
108
|
+
throw scanLimitError(`${posixPath} exceeds the per-file limit`);
|
|
109
|
+
}
|
|
110
|
+
totalBytes += stat.size;
|
|
111
|
+
if (totalBytes > MAX_TOTAL_BYTES) {
|
|
112
|
+
throw scanLimitError(`relevant files exceed ${MAX_TOTAL_BYTES} bytes`);
|
|
113
|
+
}
|
|
114
|
+
let content;
|
|
115
|
+
try {
|
|
116
|
+
content = fs_extra_1.default.readFileSync(absolutePath, 'utf8');
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
throw scanLimitError(`cannot read ${posixPath}`);
|
|
120
|
+
}
|
|
121
|
+
if (CODE_PUSH_REFERENCE.test(content))
|
|
122
|
+
residuePaths.push(posixPath);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return residuePaths.sort();
|
|
126
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const findKnownBundleDropCredential: (value: string) => string | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findKnownBundleDropCredential = void 0;
|
|
4
|
+
const BUNDLE_DROP_PROJECT_KEY = /\bbdp_proj_[A-Za-z0-9_-]{32,}\b/;
|
|
5
|
+
const BUNDLE_DROP_PERSONAL_ACCESS_TOKEN = /\bbdp_pat_[A-Za-z0-9_-]{32,}\b/;
|
|
6
|
+
const findKnownBundleDropCredential = (value) => {
|
|
7
|
+
if (BUNDLE_DROP_PROJECT_KEY.test(value))
|
|
8
|
+
return 'Bundle Drop project key';
|
|
9
|
+
if (BUNDLE_DROP_PERSONAL_ACCESS_TOKEN.test(value)) {
|
|
10
|
+
return 'Bundle Drop personal access token';
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
exports.findKnownBundleDropCredential = findKnownBundleDropCredential;
|
|
@@ -7,16 +7,24 @@ exports.buildUnifiedDiff = buildUnifiedDiff;
|
|
|
7
7
|
exports.colorizeUnifiedDiff = colorizeUnifiedDiff;
|
|
8
8
|
const diff_1 = require("diff");
|
|
9
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const terminal_safety_1 = require("./terminal-safety");
|
|
11
|
+
const BUNDLE_DROP_CONFIG_PATH = /^bundle\.drop\.config\.(js|cjs)$/;
|
|
12
|
+
const API_KEY_LITERAL = /(\bapiKey\s*:\s*)(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;
|
|
13
|
+
const redactPreviewSecrets = (file, content) => BUNDLE_DROP_CONFIG_PATH.test(file)
|
|
14
|
+
? content.replace(API_KEY_LITERAL, '$1"<redacted>"')
|
|
15
|
+
: content;
|
|
10
16
|
function buildUnifiedDiff(params) {
|
|
11
|
-
|
|
17
|
+
const diff = params.changes
|
|
12
18
|
.map(change => {
|
|
13
|
-
const original = params.originals.get(change.file) ?? '';
|
|
14
|
-
|
|
19
|
+
const original = redactPreviewSecrets(change.file, params.originals.get(change.file) ?? '');
|
|
20
|
+
const updated = redactPreviewSecrets(change.file, change.updated);
|
|
21
|
+
return (0, diff_1.createTwoFilesPatch)(`a/${change.file}`, `b/${change.file}`, original, updated, '', '', { context: 3 });
|
|
15
22
|
})
|
|
16
23
|
.join('\n');
|
|
24
|
+
return (0, terminal_safety_1.escapeTerminalControls)(diff);
|
|
17
25
|
}
|
|
18
26
|
function colorizeUnifiedDiff(diff) {
|
|
19
|
-
return diff
|
|
27
|
+
return (0, terminal_safety_1.escapeTerminalControls)(diff)
|
|
20
28
|
.split('\n')
|
|
21
29
|
.map(line => {
|
|
22
30
|
if (line.startsWith('+++') || line.startsWith('---'))
|