@gfean/react-native-bundle-drop 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/BundleDrop.podspec +96 -0
  2. package/README.md +34 -9
  3. package/android/build.gradle +65 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +137 -13
  5. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
  6. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
  7. package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
  8. package/ios/BundleDropBridge.m +27 -0
  9. package/ios/BundleDropLocator.swift +31 -15
  10. package/ios/BundleDropModule.swift +106 -3
  11. package/ios/BundleDropOtaResolver.swift +137 -29
  12. package/ios/BundleDropStartupRecovery.swift +1108 -0
  13. package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
  14. package/lib/CLI/cli.js +4 -5
  15. package/lib/CLI/scripts/doctor.js +28 -9
  16. package/lib/CLI/scripts/expo/configure-expo.js +2 -1
  17. package/lib/CLI/scripts/init-config.d.ts +2 -2
  18. package/lib/CLI/scripts/init-config.js +23 -14
  19. package/lib/CLI/scripts/login-cli.js +2 -3
  20. package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
  21. package/lib/CLI/scripts/native/write-runtime-identity.js +92 -0
  22. package/lib/CLI/scripts/upload-cli.d.ts +12 -2
  23. package/lib/CLI/scripts/upload-cli.js +74 -11
  24. package/lib/CLI/serverUrl.d.ts +3 -0
  25. package/lib/CLI/serverUrl.js +31 -0
  26. package/lib/bundleInfo.d.ts +2 -0
  27. package/lib/bundleInfo.js +16 -1
  28. package/lib/context.js +12 -2
  29. package/lib/fs/bundlePointer.d.ts +1 -17
  30. package/lib/fs/bundlePointer.js +5 -93
  31. package/lib/install/bundleInstallShared.js +4 -4
  32. package/lib/manager/downloadAndInstall.js +25 -22
  33. package/lib/manager/reporting.d.ts +8 -1
  34. package/lib/manager/reporting.js +17 -22
  35. package/lib/manager/rollbackState.d.ts +18 -54
  36. package/lib/manager/rollbackState.js +115 -216
  37. package/lib/manager/updateCheck.js +9 -3
  38. package/lib/manager/updateState.d.ts +2 -1
  39. package/lib/manager/updateState.js +59 -6
  40. package/lib/metro.d.ts +1 -1
  41. package/lib/metro.js +4 -3
  42. package/lib/native/bundleDropNative.d.ts +62 -0
  43. package/lib/native/bundleDropNative.js +266 -1
  44. package/lib/patch-engine/installFromPatchSet.js +2 -2
  45. package/lib/runtime/service.js +29 -71
  46. package/lib/runtime-delivery/bootstrapConfig.d.ts +29 -11
  47. package/lib/runtime-delivery/bootstrapConfig.js +83 -22
  48. package/lib/runtime-delivery/manifestState.d.ts +3 -1
  49. package/lib/runtime-delivery/manifestState.js +22 -1
  50. package/lib/runtime-delivery/manifestVerifier.js +7 -1
  51. package/lib/scripts/bundle.d.ts +9 -2
  52. package/lib/scripts/bundle.js +68 -18
  53. package/lib/scripts/download-bundle.d.ts +1 -0
  54. package/lib/scripts/download-bundle.js +2 -2
  55. package/lib/scripts/resolveModule.d.ts +2 -0
  56. package/lib/scripts/resolveModule.js +5 -0
  57. package/package.json +5 -2
  58. package/plugin/xcodeBuildPhase.js +2 -1
@@ -3,23 +3,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH = exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION = void 0;
6
+ exports.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = exports.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH = exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH = exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION = void 0;
7
7
  exports.normalizeRuntimeDeliveryBootstrap = normalizeRuntimeDeliveryBootstrap;
8
- exports.createGeneratedRuntimeDeliveryBootstrap = createGeneratedRuntimeDeliveryBootstrap;
9
- exports.parseGeneratedRuntimeDeliveryBootstrap = parseGeneratedRuntimeDeliveryBootstrap;
8
+ exports.createRuntimeDeliveryBootstrapLockfile = createRuntimeDeliveryBootstrapLockfile;
9
+ exports.parseRuntimeDeliveryBootstrapLockfile = parseRuntimeDeliveryBootstrapLockfile;
10
10
  exports.runtimeDeliveryBootstrapPath = runtimeDeliveryBootstrapPath;
11
+ exports.legacyRuntimeDeliveryBootstrapPath = legacyRuntimeDeliveryBootstrapPath;
11
12
  exports.addRuntimeDeliveryBootstrapGitignoreRules = addRuntimeDeliveryBootstrapGitignoreRules;
12
- exports.readGeneratedRuntimeDeliveryBootstrap = readGeneratedRuntimeDeliveryBootstrap;
13
- exports.serializeGeneratedRuntimeDeliveryBootstrap = serializeGeneratedRuntimeDeliveryBootstrap;
14
- exports.writeGeneratedRuntimeDeliveryBootstrap = writeGeneratedRuntimeDeliveryBootstrap;
15
- exports.removeGeneratedRuntimeDeliveryBootstrap = removeGeneratedRuntimeDeliveryBootstrap;
13
+ exports.readRuntimeDeliveryLockfile = readRuntimeDeliveryLockfile;
14
+ exports.inspectRuntimeDeliveryBootstrap = inspectRuntimeDeliveryBootstrap;
15
+ exports.readRuntimeDeliveryBootstrap = readRuntimeDeliveryBootstrap;
16
+ exports.serializeRuntimeDeliveryBootstrapLockfile = serializeRuntimeDeliveryBootstrapLockfile;
17
+ exports.writeRuntimeDeliveryBootstrapLockfile = writeRuntimeDeliveryBootstrapLockfile;
18
+ exports.removeRuntimeDeliveryBootstrapLockfile = removeRuntimeDeliveryBootstrapLockfile;
19
+ exports.removeLegacyRuntimeDeliveryBootstrap = removeLegacyRuntimeDeliveryBootstrap;
20
+ exports.removeAllRuntimeDeliveryBootstraps = removeAllRuntimeDeliveryBootstraps;
16
21
  exports.ensureRuntimeDeliveryBootstrapGitignore = ensureRuntimeDeliveryBootstrapGitignore;
17
22
  const fs_extra_1 = __importDefault(require("fs-extra"));
18
23
  const path_1 = __importDefault(require("path"));
24
+ const util_1 = require("util");
19
25
  const safe_file_transaction_1 = require("../CLI/scripts/safe-file-transaction");
20
26
  exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION = 1;
21
- exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH = path_1.default.join('.bundle-drop', 'runtime-delivery.generated.json');
22
- exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = '!.bundle-drop/runtime-delivery.generated.json';
27
+ exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH = path_1.default.join('.bundle-drop', 'runtime-delivery.lock.json');
28
+ exports.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH = path_1.default.join('.bundle-drop', 'runtime-delivery.generated.json');
29
+ exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = '!.bundle-drop/runtime-delivery.lock.json';
30
+ exports.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER = '!.bundle-drop/runtime-delivery.generated.json';
23
31
  const RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_BLOCK = [
24
32
  '# Bundle Drop: commit the public trust bootstrap; ignore generated runtime artifacts.',
25
33
  '!.bundle-drop/',
@@ -97,7 +105,7 @@ function normalizeRuntimeDeliveryBootstrap(value) {
97
105
  publicKeys,
98
106
  };
99
107
  }
100
- function createGeneratedRuntimeDeliveryBootstrap(params) {
108
+ function createRuntimeDeliveryBootstrapLockfile(params) {
101
109
  const runtimeDelivery = normalizeRuntimeDeliveryBootstrap(params.runtimeDelivery);
102
110
  const serverUrl = normalizeHttpUrl(params.identity.serverUrl);
103
111
  const orgSlug = params.identity.orgSlug.trim();
@@ -119,7 +127,7 @@ function createGeneratedRuntimeDeliveryBootstrap(params) {
119
127
  runtimeDelivery,
120
128
  };
121
129
  }
122
- function parseGeneratedRuntimeDeliveryBootstrap(value, expectedIdentity) {
130
+ function parseRuntimeDeliveryBootstrapLockfile(value, expectedIdentity) {
123
131
  if (!isRecord(value) || value.schemaVersion !== exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION) {
124
132
  throw new Error(`Runtime delivery bootstrap must use schemaVersion ${exports.RUNTIME_DELIVERY_BOOTSTRAP_SCHEMA_VERSION}.`);
125
133
  }
@@ -136,7 +144,7 @@ function parseGeneratedRuntimeDeliveryBootstrap(value, expectedIdentity) {
136
144
  !value.project.orgId.trim()))) {
137
145
  throw new Error('Runtime delivery bootstrap contains an invalid stable project identity.');
138
146
  }
139
- const bootstrap = createGeneratedRuntimeDeliveryBootstrap({
147
+ const bootstrap = createRuntimeDeliveryBootstrapLockfile({
140
148
  identity: {
141
149
  serverUrl: typeof value.project.serverUrl === 'string' ? value.project.serverUrl : '',
142
150
  orgSlug: typeof value.project.orgSlug === 'string' ? value.project.orgSlug : '',
@@ -170,14 +178,26 @@ function parseGeneratedRuntimeDeliveryBootstrap(value, expectedIdentity) {
170
178
  function runtimeDeliveryBootstrapPath(projectRoot) {
171
179
  return path_1.default.join(projectRoot, exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH);
172
180
  }
181
+ function legacyRuntimeDeliveryBootstrapPath(projectRoot) {
182
+ return path_1.default.join(projectRoot, exports.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH);
183
+ }
184
+ const RUNTIME_DELIVERY_MANAGED_GITIGNORE_LINES = new Set([
185
+ '# Bundle Drop: commit the public trust bootstrap; ignore generated runtime artifacts.',
186
+ '!.bundle-drop/',
187
+ '.bundle-drop/*',
188
+ exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER,
189
+ exports.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER,
190
+ ]);
173
191
  function addRuntimeDeliveryBootstrapGitignoreRules(content) {
174
- if (content.includes(exports.RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_MARKER))
175
- return content;
176
- const prefix = content.trimEnd();
192
+ const prefix = content
193
+ .split('\n')
194
+ .filter(line => !RUNTIME_DELIVERY_MANAGED_GITIGNORE_LINES.has(line.trim()))
195
+ .join('\n')
196
+ .trimEnd();
177
197
  return `${prefix}${prefix ? '\n\n' : ''}${RUNTIME_DELIVERY_BOOTSTRAP_GITIGNORE_BLOCK}\n`;
178
198
  }
179
- function readGeneratedRuntimeDeliveryBootstrap(params) {
180
- const bootstrapPath = runtimeDeliveryBootstrapPath(params.projectRoot);
199
+ function readRuntimeDeliveryBootstrapFile(params) {
200
+ const bootstrapPath = path_1.default.join(params.projectRoot, params.relativePath);
181
201
  if (!fs_extra_1.default.existsSync(bootstrapPath))
182
202
  return null;
183
203
  let value;
@@ -187,23 +207,64 @@ function readGeneratedRuntimeDeliveryBootstrap(params) {
187
207
  catch {
188
208
  throw new Error(`Runtime delivery bootstrap is not valid JSON: ${bootstrapPath}`);
189
209
  }
190
- return parseGeneratedRuntimeDeliveryBootstrap(value, params.expectedIdentity);
210
+ return parseRuntimeDeliveryBootstrapLockfile(value, params.expectedIdentity);
211
+ }
212
+ function readRuntimeDeliveryLockfile(params) {
213
+ return readRuntimeDeliveryBootstrapFile({
214
+ ...params,
215
+ relativePath: exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH,
216
+ });
191
217
  }
192
- function serializeGeneratedRuntimeDeliveryBootstrap(bootstrap) {
218
+ function inspectRuntimeDeliveryBootstrap(params) {
219
+ const current = readRuntimeDeliveryLockfile(params);
220
+ const legacy = readRuntimeDeliveryBootstrapFile({
221
+ ...params,
222
+ relativePath: exports.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH,
223
+ });
224
+ if (current && legacy) {
225
+ if (!(0, util_1.isDeepStrictEqual)(current, legacy)) {
226
+ throw new Error('Runtime delivery lockfile and legacy bootstrap differ. Run `bundle-drop sync` to repair them.');
227
+ }
228
+ return { bootstrap: current, source: 'matching-dual' };
229
+ }
230
+ if (current)
231
+ return { bootstrap: current, source: 'lock' };
232
+ if (legacy)
233
+ return { bootstrap: legacy, source: 'legacy' };
234
+ return null;
235
+ }
236
+ function readRuntimeDeliveryBootstrap(params) {
237
+ return inspectRuntimeDeliveryBootstrap(params)?.bootstrap ?? null;
238
+ }
239
+ function serializeRuntimeDeliveryBootstrapLockfile(bootstrap) {
193
240
  return `${JSON.stringify(bootstrap, null, 2)}\n`;
194
241
  }
195
- async function writeGeneratedRuntimeDeliveryBootstrap(params) {
242
+ async function writeRuntimeDeliveryBootstrapLockfile(params) {
196
243
  const bootstrapPath = runtimeDeliveryBootstrapPath(params.projectRoot);
197
- (0, safe_file_transaction_1.writeProjectFileAtomically)(params.projectRoot, exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH, serializeGeneratedRuntimeDeliveryBootstrap(params.bootstrap));
244
+ (0, safe_file_transaction_1.writeProjectFileAtomically)(params.projectRoot, exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH, serializeRuntimeDeliveryBootstrapLockfile(params.bootstrap));
198
245
  return bootstrapPath;
199
246
  }
200
- async function removeGeneratedRuntimeDeliveryBootstrap(projectRoot) {
247
+ async function removeRuntimeDeliveryBootstrapLockfile(projectRoot) {
201
248
  const bootstrapPath = runtimeDeliveryBootstrapPath(projectRoot);
202
249
  if (!(0, safe_file_transaction_1.inspectProjectFile)(projectRoot, exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH).exists)
203
250
  return null;
204
251
  (0, safe_file_transaction_1.removeProjectFile)(projectRoot, exports.RUNTIME_DELIVERY_BOOTSTRAP_PATH);
205
252
  return bootstrapPath;
206
253
  }
254
+ async function removeLegacyRuntimeDeliveryBootstrap(projectRoot) {
255
+ const bootstrapPath = legacyRuntimeDeliveryBootstrapPath(projectRoot);
256
+ if (!(0, safe_file_transaction_1.inspectProjectFile)(projectRoot, exports.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH).exists)
257
+ return null;
258
+ (0, safe_file_transaction_1.removeProjectFile)(projectRoot, exports.LEGACY_RUNTIME_DELIVERY_BOOTSTRAP_PATH);
259
+ return bootstrapPath;
260
+ }
261
+ async function removeAllRuntimeDeliveryBootstraps(projectRoot) {
262
+ const removed = await Promise.all([
263
+ removeRuntimeDeliveryBootstrapLockfile(projectRoot),
264
+ removeLegacyRuntimeDeliveryBootstrap(projectRoot),
265
+ ]);
266
+ return removed.filter((file) => Boolean(file));
267
+ }
207
268
  async function ensureRuntimeDeliveryBootstrapGitignore(projectRoot) {
208
269
  const gitignorePath = path_1.default.join(projectRoot, '.gitignore');
209
270
  const original = fs_extra_1.default.existsSync(gitignorePath)
@@ -5,5 +5,7 @@ export type VerifiedLaneState = {
5
5
  revokedHashes: string[];
6
6
  verifiedAt: string;
7
7
  };
8
+ export type PersistVerifiedRuntimeRevocations = (revokedHashes: string[]) => Promise<void>;
8
9
  export declare function readVerifiedLaneState(identity: RuntimeDeliveryLaneIdentity): Promise<VerifiedLaneState | null>;
9
- export declare function recordVerifiedLaneManifest(manifest: RuntimeDeliveryLaneManifest, payloadSha256: string): Promise<void>;
10
+ export declare function readVerifiedRuntimeRevokedHashes(identity: RuntimeDeliveryLaneIdentity): Promise<string[]>;
11
+ export declare function recordVerifiedLaneManifest(manifest: RuntimeDeliveryLaneManifest, payloadSha256: string, persistRuntimeRevocations?: PersistVerifiedRuntimeRevocations): Promise<void>;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readVerifiedLaneState = readVerifiedLaneState;
7
+ exports.readVerifiedRuntimeRevokedHashes = readVerifiedRuntimeRevokedHashes;
7
8
  exports.recordVerifiedLaneManifest = recordVerifiedLaneManifest;
8
9
  const context_1 = require("../context");
9
10
  const fsUtils_1 = require("../fs/fsUtils");
@@ -59,6 +60,19 @@ function laneStateKey(identity) {
59
60
  .map(value => encodeURIComponent(value))
60
61
  .join('/');
61
62
  }
63
+ function belongsToRuntime(laneKey, identity) {
64
+ const parts = laneKey.split('/');
65
+ return parts.length === 4 &&
66
+ parts[0] === encodeURIComponent(identity.projectSlug) &&
67
+ parts[2] === encodeURIComponent(identity.platform) &&
68
+ parts[3] === encodeURIComponent(identity.runtimeVersion);
69
+ }
70
+ function verifiedRuntimeRevokedHashes(state, identity) {
71
+ const revokedHashes = Object.entries(state.lanes)
72
+ .filter(([key]) => belongsToRuntime(key, identity))
73
+ .flatMap(([, lane]) => lane.revokedHashes);
74
+ return Array.from(new Set(revokedHashes)).sort();
75
+ }
62
76
  async function readState() {
63
77
  if (!await fs_1.default.exists(STATE_PATH))
64
78
  return { schemaVersion: 1, lanes: {} };
@@ -75,7 +89,11 @@ async function readVerifiedLaneState(identity) {
75
89
  const state = await readState();
76
90
  return state.lanes[laneStateKey(identity)] || null;
77
91
  }
78
- async function recordVerifiedLaneManifest(manifest, payloadSha256) {
92
+ async function readVerifiedRuntimeRevokedHashes(identity) {
93
+ const state = await readState();
94
+ return verifiedRuntimeRevokedHashes(state, identity);
95
+ }
96
+ async function recordVerifiedLaneManifest(manifest, payloadSha256, persistRuntimeRevocations) {
79
97
  const mutation = stateMutation.then(async () => {
80
98
  const identity = manifest;
81
99
  const key = laneStateKey(identity);
@@ -95,6 +113,9 @@ async function recordVerifiedLaneManifest(manifest, payloadSha256) {
95
113
  revokedHashes: [...manifest.revokedHashes],
96
114
  verifiedAt: new Date().toISOString(),
97
115
  };
116
+ if (persistRuntimeRevocations) {
117
+ await persistRuntimeRevocations(verifiedRuntimeRevokedHashes(state, identity));
118
+ }
98
119
  await (0, fsUtils_1.atomicWriteJson)(STATE_PATH, state);
99
120
  });
100
121
  stateMutation = mutation.then(() => undefined, () => undefined);
@@ -7,6 +7,7 @@ exports.RuntimeDeliveryManifestError = exports.MAX_RUNTIME_MANIFEST_BYTES = void
7
7
  exports.verifyRuntimeDeliveryManifest = verifyRuntimeDeliveryManifest;
8
8
  exports.verifyRuntimeDeliverySignedPayload = verifyRuntimeDeliverySignedPayload;
9
9
  const fs_1 = __importDefault(require("../native/fs"));
10
+ const rollbackState_1 = require("../manager/rollbackState");
10
11
  const encoding_1 = require("./encoding");
11
12
  const manifestState_1 = require("./manifestState");
12
13
  const types_1 = require("./types");
@@ -293,7 +294,12 @@ async function verifyRuntimeDeliveryManifest(serializedJws, expectedIdentity, pu
293
294
  previousState.payloadSha256 !== payloadSha256) {
294
295
  throw new RuntimeDeliveryManifestError('generation_equivocation', 'Runtime manifest generation equivocation detected');
295
296
  }
296
- await (0, manifestState_1.recordVerifiedLaneManifest)(manifest, payloadSha256);
297
+ await (0, manifestState_1.recordVerifiedLaneManifest)(manifest, payloadSha256, async (runtimeRevokedHashes) => {
298
+ const persisted = await (0, rollbackState_1.syncVerifiedRevokedHashes)(runtimeRevokedHashes);
299
+ if (!persisted) {
300
+ throw new Error('Native startup recovery rejected the verified revocation set');
301
+ }
302
+ });
297
303
  return manifest;
298
304
  }
299
305
  async function verifyRuntimeDeliverySignedPayload(serializedJws, expectedType, publicKeys) {
@@ -1,11 +1,18 @@
1
1
  #!/usr/bin/env node
2
+ import { spawnSync } from 'child_process';
2
3
  import { findProjectRoot } from './projectRoot';
4
+ import { type ModuleResolver } from './resolveModule';
3
5
  export { findProjectRoot };
4
- export declare function runBundleScript(options?: {
6
+ type SpawnProcess = typeof spawnSync;
7
+ type BundleScriptOptions = {
5
8
  platform?: string;
6
9
  cwd?: string;
7
10
  sourcemap?: boolean;
8
- }): {
11
+ packageRoot?: string;
12
+ spawnProcess?: SpawnProcess;
13
+ resolveModule?: ModuleResolver;
14
+ };
15
+ export declare function runBundleScript(options?: BundleScriptOptions): {
9
16
  outputDir: string;
10
17
  bundlePath: string;
11
18
  sourceMapPath?: string;
@@ -43,9 +43,31 @@ const bundleManifest_1 = require("../manifest/bundleManifest");
43
43
  const canonicalArtifact_1 = require("./canonicalArtifact");
44
44
  const projectRoot_1 = require("./projectRoot");
45
45
  Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
46
+ const resolveModule_1 = require("./resolveModule");
46
47
  const SENTRY_HERMES_OTA_DOCS_URL = 'https://bundledrop.app/docs/observability#sentry-and-hermes-ota-builds';
47
48
  const SENTRY_DEBUG_ID_MARKERS = ['//# debugId=', 'sentry-dbid-'];
48
- const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
49
+ const runProcess = (spawnProcess, executable, args, options) => {
50
+ const result = spawnProcess(executable, args, {
51
+ ...options,
52
+ shell: false,
53
+ });
54
+ if (result.error)
55
+ throw result.error;
56
+ if (result.status !== 0) {
57
+ const detail = typeof result.stderr === 'string' ? result.stderr.trim() : '';
58
+ throw new Error(detail || `${path.basename(executable)} exited with status ${result.status}`);
59
+ }
60
+ return result;
61
+ };
62
+ const assertGeneratedPath = (targetPath, outputDir) => {
63
+ const relative = path.relative(path.resolve(outputDir), path.resolve(targetPath));
64
+ const escapesOutput = relative === '..' ||
65
+ relative.startsWith(`..${path.sep}`) ||
66
+ path.isAbsolute(relative);
67
+ if (escapesOutput) {
68
+ throw new Error(`Generated artifact path escaped the package output directory: ${targetPath}`);
69
+ }
70
+ };
49
71
  const readTextIfExists = (filePath) => {
50
72
  if (!fs.existsSync(filePath))
51
73
  return null;
@@ -84,17 +106,21 @@ const readIosProjectSettings = (projectRoot) => {
84
106
  .filter((content) => Boolean(content));
85
107
  return contents.length ? contents.join('\n') : null;
86
108
  };
87
- const readHermesHelp = (hermescPath) => {
109
+ const readHermesHelp = (hermescPath, spawnProcess) => {
88
110
  try {
89
- return String((0, child_process_1.execSync)(`"${hermescPath}" -help`, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }));
111
+ const result = runProcess(spawnProcess, hermescPath, ['-help'], {
112
+ encoding: 'utf8',
113
+ stdio: ['ignore', 'pipe', 'pipe'],
114
+ });
115
+ return String(result.stdout || '');
90
116
  }
91
117
  catch {
92
118
  return '';
93
119
  }
94
120
  };
95
121
  const hermesHelpIncludesFlag = (help, flag) => new RegExp(`(?:^|\\n)\\s*${flag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:\\s|=)`).test(help);
96
- const buildHermesFlags = (hermescPath, generateSourceMap) => {
97
- const help = readHermesHelp(hermescPath);
122
+ const buildHermesFlags = (hermescPath, generateSourceMap, spawnProcess) => {
123
+ const help = readHermesHelp(hermescPath, spawnProcess);
98
124
  const flags = ['-emit-binary'];
99
125
  if (hermesHelpIncludesFlag(help, '-O')) {
100
126
  flags.push('-O');
@@ -167,8 +193,10 @@ const shouldCompileHermesBytecode = (cfg, platform, projectRoot) => {
167
193
  }
168
194
  return false;
169
195
  };
170
- function runBundleScript(options) {
171
- const packageRoot = getPackageRoot();
196
+ function runBundleScript(options = {}) {
197
+ const packageRoot = options.packageRoot || path.resolve(__dirname, '..', '..');
198
+ const spawnProcess = options.spawnProcess || child_process_1.spawnSync;
199
+ const resolveModule = options.resolveModule || resolveModule_1.resolveModuleFrom;
172
200
  const platform = options?.platform || process.argv[2] || 'ios';
173
201
  if (!['ios', 'android'].includes(platform)) {
174
202
  console.error('❌ Please provide platform: ios or android');
@@ -205,22 +233,44 @@ function runBundleScript(options) {
205
233
  }
206
234
  const hermesEnabled = shouldCompileHermesBytecode(cfg, platform, projectRoot);
207
235
  [bundlePath, zipPath, metadataPath, manifestPath, sourceMapPath].forEach(file => {
236
+ assertGeneratedPath(file, outputDir);
208
237
  if (fs.existsSync(file))
209
238
  fs.unlinkSync(file);
210
239
  });
240
+ assertGeneratedPath(assetsDir, outputDir);
211
241
  if (fs.existsSync(assetsDir))
212
242
  fs.rmSync(assetsDir, { recursive: true, force: true });
213
243
  fs.mkdirSync(outputDir, { recursive: true });
214
244
  fs.mkdirSync(assetsDir, { recursive: true });
215
245
  console.log(`📦 Bundling React Native code for platform: ${platform}...`);
216
- const sourcemapFlag = generateSourceMap ? ` \\\n --sourcemap-output "${sourceMapPath}"` : '';
217
- (0, child_process_1.execSync)(`npx react-native bundle \
218
- --platform ${platform} \
219
- --dev false \
220
- --entry-file index.js \
221
- --bundle-output "${bundlePath}" \
222
- --assets-dest "${assetsDir}" \
223
- --reset-cache${sourcemapFlag}`, {
246
+ const reactNativePackageJson = resolveModule('react-native/package.json', [
247
+ projectRoot,
248
+ packageRoot,
249
+ __dirname,
250
+ ]);
251
+ const reactNativeCli = path.join(path.dirname(reactNativePackageJson), 'cli.js');
252
+ if (!fs.existsSync(reactNativeCli)) {
253
+ throw new Error(`React Native CLI entrypoint is missing: ${reactNativeCli}`);
254
+ }
255
+ const reactNativeArgs = [
256
+ reactNativeCli,
257
+ 'bundle',
258
+ '--platform',
259
+ platform,
260
+ '--dev',
261
+ 'false',
262
+ '--entry-file',
263
+ 'index.js',
264
+ '--bundle-output',
265
+ bundlePath,
266
+ '--assets-dest',
267
+ assetsDir,
268
+ '--reset-cache',
269
+ ];
270
+ if (generateSourceMap) {
271
+ reactNativeArgs.push('--sourcemap-output', sourceMapPath);
272
+ }
273
+ runProcess(spawnProcess, process.execPath, reactNativeArgs, {
224
274
  stdio: 'inherit',
225
275
  env: {
226
276
  ...process.env,
@@ -244,8 +294,8 @@ function runBundleScript(options) {
244
294
  const hbcPath = bundlePath + '.hbc';
245
295
  try {
246
296
  console.log(`🔥 Compiling to Hermes bytecode (${platform})...`);
247
- const hermesFlags = buildHermesFlags(hermescPath, generateSourceMap).join(' ');
248
- (0, child_process_1.execSync)(`"${hermescPath}" ${hermesFlags} -out "${hbcPath}" "${bundlePath}"`, { stdio: ['ignore', 'ignore', 'ignore'] });
297
+ const hermesFlags = buildHermesFlags(hermescPath, generateSourceMap, spawnProcess);
298
+ runProcess(spawnProcess, hermescPath, [...hermesFlags, '-out', hbcPath, bundlePath], { stdio: ['ignore', 'ignore', 'ignore'] });
249
299
  promoteHermesBytecode(hbcPath, bundlePath);
250
300
  console.log('✅ Hermes bytecode compiled');
251
301
  }
@@ -259,7 +309,7 @@ function runBundleScript(options) {
259
309
  if (fs.existsSync(composeScript)) {
260
310
  try {
261
311
  const composedPath = sourceMapPath + '.composed';
262
- (0, child_process_1.execSync)(`node "${composeScript}" "${sourceMapPath}" "${hermesMapPath}" -o "${composedPath}"`, { stdio: ['ignore', 'ignore', 'ignore'] });
312
+ runProcess(spawnProcess, process.execPath, [composeScript, sourceMapPath, hermesMapPath, '-o', composedPath], { stdio: ['ignore', 'ignore', 'ignore'] });
263
313
  fs.renameSync(composedPath, sourceMapPath);
264
314
  console.log('✅ Source maps composed');
265
315
  }
@@ -2,4 +2,5 @@
2
2
  export declare function runDownloadBundle(options?: {
3
3
  argv?: string[];
4
4
  cwd?: string;
5
+ packageRoot?: string;
5
6
  }): Promise<string>;
@@ -41,9 +41,9 @@ exports.runDownloadBundle = runDownloadBundle;
41
41
  const axios_1 = __importDefault(require("axios"));
42
42
  const fs = __importStar(require("fs"));
43
43
  const path = __importStar(require("path"));
44
- const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
45
44
  async function runDownloadBundle(options) {
46
- const outputDir = path.join(getPackageRoot(), 'dist');
45
+ const packageRoot = options?.packageRoot || path.resolve(__dirname, '..', '..');
46
+ const outputDir = path.join(packageRoot, 'dist');
47
47
  const argv = options?.argv || process.argv;
48
48
  const platform = argv[2];
49
49
  if (!platform || !['ios', 'android'].includes(platform)) {
@@ -0,0 +1,2 @@
1
+ export type ModuleResolver = (moduleId: string, searchPaths: string[]) => string;
2
+ export declare const resolveModuleFrom: ModuleResolver;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveModuleFrom = void 0;
4
+ const resolveModuleFrom = (moduleId, searchPaths) => require.resolve(moduleId, { paths: searchPaths });
5
+ exports.resolveModuleFrom = resolveModuleFrom;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gfean/react-native-bundle-drop",
3
- "version": "0.6.0",
4
- "nativeVersion": "0.5.0",
3
+ "version": "0.7.0",
4
+ "nativeVersion": "0.6.0",
5
5
  "description": "Over-the-air updates for Expo and bare React Native apps, with channels, staged rollouts, patch delivery, and rollback.",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -47,6 +47,9 @@
47
47
  "test:expo:plugin": "node --test plugin/__tests__/*.test.js",
48
48
  "package:check": "node scripts/check-package-contents.cjs",
49
49
  "audit:production": "yarn npm audit --environment production --recursive --severity high",
50
+ "codeql:local:fast": "node scripts/run-codeql-local.cjs fast",
51
+ "codeql:local:full": "node scripts/run-codeql-local.cjs full",
52
+ "codeql:local:compare": "node scripts/run-codeql-local.cjs compare",
50
53
  "verify:quick": "yarn build && yarn coverage:gate && yarn test:expo:plugin && yarn package:check",
51
54
  "verify:native": "yarn test:android && yarn test:ios",
52
55
  "verify:release": "yarn verify:quick && yarn verify:native && yarn audit:production",
@@ -28,7 +28,8 @@ function updatePhase(project, phaseUuid) {
28
28
  const phase = project.hash.project.objects.PBXShellScriptBuildPhase[phaseUuid];
29
29
  phase.name = `"${PHASE_NAME}"`;
30
30
  phase.shellPath = '/bin/sh';
31
- phase.shellScript = `"${SHELL_SCRIPT.replace(/"/g, '\\"')}"`;
31
+ const escapedShellScript = SHELL_SCRIPT.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
32
+ phase.shellScript = `"${escapedShellScript}"`;
32
33
  }
33
34
 
34
35
  function movePhaseToEnd(target, phaseUuid) {