@gfean/react-native-bundle-drop 0.4.1 → 0.4.2

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.
@@ -102,6 +102,24 @@ repositories {
102
102
  google()
103
103
  }
104
104
 
105
+ if (project.hasProperty("standalone")) {
106
+ // The standalone unit-test build resolves "react-android:+" to exercise the module
107
+ // against the newest React Native. Gradle's "+" also matches pre-releases, and a
108
+ // pre-release react-android (e.g. 0.87.0-rc.1) can ship newer Kotlin metadata than
109
+ // the standalone Kotlin compiler (BundleDrop_kotlinVersion) can read, which breaks
110
+ // compileDebugKotlin. Reject pre-release candidates so "+" keeps meaning "latest
111
+ // stable" without pinning a specific version.
112
+ configurations.all {
113
+ resolutionStrategy.componentSelection.all { selection ->
114
+ if (selection.candidate.group == "com.facebook.react"
115
+ && selection.candidate.module == "react-android"
116
+ && selection.candidate.version ==~ /(?i).*[-.](rc|alpha|beta|snapshot|dev|preview|m)\d*.*/) {
117
+ selection.reject("pre-release React Native is unsupported by the pinned standalone Kotlin toolchain")
118
+ }
119
+ }
120
+ }
121
+ }
122
+
105
123
  def kotlin_version = getExtOrDefault("kotlinVersion")
106
124
 
107
125
  dependencies {
@@ -26,6 +26,18 @@ set_target_properties(
26
26
  C_STANDARD_REQUIRED ON
27
27
  )
28
28
 
29
+ # Force 16 KB ELF segment alignment on this shared library. Google Play rejects
30
+ # apps whose native libraries are not 16 KB page-size compatible on Android 15+
31
+ # devices. Setting the flags directly on the target is reliable across NDK
32
+ # versions; the ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES gradle argument alone does
33
+ # not consistently reach this target's link line on NDK r27 and lower.
34
+ target_link_options(
35
+ bundledropxdelta
36
+ PRIVATE
37
+ "-Wl,-z,max-page-size=16384"
38
+ "-Wl,-z,common-page-size=16384"
39
+ )
40
+
29
41
  target_compile_definitions(
30
42
  bundledropxdelta
31
43
  PRIVATE
@@ -49,7 +49,23 @@ const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
49
49
  const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
50
50
  const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
51
51
  const DOCS_RUNTIME_VERSION_URL = 'https://bundledrop.app/docs/runtime-version';
52
+ const BUNDLE_DROP_ARTIFACT_FILES = [
53
+ 'main.jsbundle',
54
+ 'main.jsbundle.map',
55
+ 'bundle-drop-result.json',
56
+ ];
52
57
  const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..', '..');
58
+ const readPackageVersion = (packageRoot) => {
59
+ try {
60
+ const packageJson = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf-8'));
61
+ return typeof packageJson.version === 'string' && packageJson.version.trim()
62
+ ? packageJson.version.trim()
63
+ : undefined;
64
+ }
65
+ catch {
66
+ return undefined;
67
+ }
68
+ };
53
69
  const readManifestRuntimeVersion = (manifestPath) => {
54
70
  let manifest;
55
71
  try {
@@ -66,10 +82,32 @@ const readManifestRuntimeVersion = (manifestPath) => {
66
82
  }
67
83
  return manifest.runtimeVersion;
68
84
  };
85
+ const prepareArtifactDirForRun = (artifactDir) => {
86
+ if (!artifactDir)
87
+ return;
88
+ fs.mkdirSync(artifactDir, { recursive: true });
89
+ for (const fileName of BUNDLE_DROP_ARTIFACT_FILES) {
90
+ const filePath = path.join(artifactDir, fileName);
91
+ if (fs.existsSync(filePath))
92
+ fs.unlinkSync(filePath);
93
+ }
94
+ };
95
+ const writeArtifactResult = (artifactDir, result) => {
96
+ if (!artifactDir)
97
+ return;
98
+ fs.mkdirSync(artifactDir, { recursive: true });
99
+ fs.writeFileSync(path.join(artifactDir, 'bundle-drop-result.json'), JSON.stringify(result, null, 2));
100
+ };
101
+ const stringifyUploadError = (err) => {
102
+ const raw = err?.response?.data || err.message;
103
+ return typeof raw === 'object' ? JSON.stringify(raw, null, 2) : String(raw);
104
+ };
69
105
  async function upload(platform, options) {
70
106
  console.log(); // blank line
71
107
  ui_1.log.info('🚀 React Native OTA Upload Initialized');
72
108
  const projectRoot = process.cwd();
109
+ const artifactDir = options.artifactDir ? path.resolve(options.artifactDir) : undefined;
110
+ prepareArtifactDirForRun(artifactDir);
73
111
  const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
74
112
  //eslint-disable-next-line
75
113
  const authPath = path.join(require('os').homedir(), '.bundle-drop', 'auth.json');
@@ -181,6 +219,7 @@ async function upload(platform, options) {
181
219
  console.log();
182
220
  ui_1.log.arrow(`Bundling ${platform} app...`);
183
221
  const packageRoot = getPackageRoot();
222
+ const packageVersion = readPackageVersion(packageRoot);
184
223
  const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
185
224
  const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
186
225
  const bundleCommand = fs.existsSync(compiledBundleScript)
@@ -224,6 +263,9 @@ async function upload(platform, options) {
224
263
  form.append('version', version);
225
264
  form.append('channelName', channel);
226
265
  form.append('runtimeVersion', runtimeVersion);
266
+ if (packageVersion) {
267
+ form.append('packageVersion', packageVersion);
268
+ }
227
269
  if (releaseNotes) {
228
270
  form.append('releaseNotes', releaseNotes);
229
271
  }
@@ -232,6 +274,7 @@ async function upload(platform, options) {
232
274
  }
233
275
  form.append('file', fs.createReadStream(zipPath));
234
276
  const uploadLoader = (0, ui_1.startLoadingStatus)('Uploading bundle to server');
277
+ let uploadSucceeded = false;
235
278
  try {
236
279
  const res = await axios_1.default.post(`${serverUrl}/bundle/upload`, form, {
237
280
  headers: {
@@ -243,14 +286,14 @@ async function upload(platform, options) {
243
286
  });
244
287
  const sourceMapFile = path.join(outputDir, 'main.jsbundle.map');
245
288
  const hasSourceMap = options.sourcemap && fs.existsSync(sourceMapFile);
246
- const artifactDir = options.artifactDir ? path.resolve(options.artifactDir) : undefined;
247
289
  const result = {
248
290
  platform,
249
- appVersion: version ?? null,
250
- channel: channel ?? null,
251
- orgSlug: orgSlug ?? null,
252
- projectSlug: projectSlug ?? null,
291
+ appVersion: version,
292
+ channel,
293
+ orgSlug,
294
+ projectSlug,
253
295
  runtimeVersion: res.data?.runtimeVersion ?? runtimeVersion ?? null,
296
+ packageVersion: res.data?.packageVersion ?? packageVersion ?? null,
254
297
  bundleId: res.data?.bundleId ?? null,
255
298
  bundleVersion: res.data?.bundleVersion ?? null,
256
299
  bundleVersionLabel: res.data?.bundleVersionLabel ?? null,
@@ -292,17 +335,28 @@ async function upload(platform, options) {
292
335
  if (artifactDir) {
293
336
  ui_1.log.label('Artifact dir', artifactDir);
294
337
  }
338
+ uploadSucceeded = true;
295
339
  }
296
340
  catch (err) {
297
341
  uploadLoader.stop();
298
- const raw = err?.response?.data || err.message;
299
- if (typeof raw === 'object') {
300
- ui_1.log.error(`Upload failed:\n${JSON.stringify(raw, null, 2)}`);
301
- }
302
- else {
303
- ui_1.log.error(`Upload failed: ${raw}`);
304
- }
305
- process.exit(1);
342
+ const uploadError = stringifyUploadError(err);
343
+ writeArtifactResult(artifactDir, {
344
+ success: false,
345
+ status: 'failed',
346
+ error: uploadError,
347
+ platform,
348
+ appVersion: version,
349
+ channel,
350
+ orgSlug,
351
+ projectSlug,
352
+ runtimeVersion,
353
+ packageVersion: packageVersion ?? null,
354
+ releaseNotes: releaseNotes ?? null,
355
+ author: options.author ?? null,
356
+ });
357
+ ui_1.log.error(`Upload failed: ${uploadError}`);
358
+ process.exitCode = 1;
359
+ return;
306
360
  }
307
361
  finally {
308
362
  try {
@@ -321,9 +375,11 @@ async function upload(platform, options) {
321
375
  if (fs.existsSync(assetsPath)) {
322
376
  fs.rmSync(assetsPath, { recursive: true, force: true });
323
377
  }
324
- console.log();
325
- ui_1.log.success('🎉 Done! Bundle uploaded and cleaned.');
326
- console.log();
378
+ if (uploadSucceeded) {
379
+ console.log();
380
+ ui_1.log.success('🎉 Done! Bundle uploaded and cleaned.');
381
+ console.log();
382
+ }
327
383
  }
328
384
  catch (cleanupErr) {
329
385
  ui_1.log.warn(`Cleanup failed: ${cleanupErr.message}`);
@@ -125,6 +125,13 @@ const buildHermesFlags = (hermescPath, generateSourceMap) => {
125
125
  }
126
126
  return flags;
127
127
  };
128
+ const promoteHermesBytecode = (hbcPath, bundlePath) => {
129
+ if (!fs.existsSync(hbcPath)) {
130
+ throw new Error(`Hermes compiler did not write bytecode output at ${hbcPath}`);
131
+ }
132
+ fs.copyFileSync(hbcPath, bundlePath);
133
+ fs.unlinkSync(hbcPath);
134
+ };
128
135
  const detectHermesFromNativeProject = (projectRoot, platform) => {
129
136
  if (platform === 'android') {
130
137
  return detectBoolean([
@@ -221,7 +228,8 @@ function runBundleScript(options) {
221
228
  --dev false \
222
229
  --entry-file index.js \
223
230
  --bundle-output "${bundlePath}" \
224
- --assets-dest "${assetsDir}"${sourcemapFlag}`, { stdio: 'inherit' });
231
+ --assets-dest "${assetsDir}" \
232
+ --reset-cache${sourcemapFlag}`, { stdio: 'inherit' });
225
233
  console.log('✅ Bundle created');
226
234
  const osBin = process.platform === 'darwin'
227
235
  ? 'osx-bin'
@@ -241,7 +249,7 @@ function runBundleScript(options) {
241
249
  console.log(`🔥 Compiling to Hermes bytecode (${platform})...`);
242
250
  const hermesFlags = buildHermesFlags(hermescPath, generateSourceMap).join(' ');
243
251
  (0, child_process_1.execSync)(`"${hermescPath}" ${hermesFlags} -out "${hbcPath}" "${bundlePath}"`, { stdio: ['ignore', 'ignore', 'ignore'] });
244
- fs.renameSync(hbcPath, bundlePath);
252
+ promoteHermesBytecode(hbcPath, bundlePath);
245
253
  console.log('✅ Hermes bytecode compiled');
246
254
  }
247
255
  catch (e) {
@@ -276,6 +284,9 @@ function runBundleScript(options) {
276
284
  else {
277
285
  console.log(`ℹ️ Hermes bytecode disabled for ${platform} — bundling plain JS`);
278
286
  }
287
+ if (!fs.existsSync(bundlePath)) {
288
+ throw new Error(`Bundle output missing after bundling: ${bundlePath}`);
289
+ }
279
290
  const bundleBuffer = fs.readFileSync(bundlePath);
280
291
  const jsBundleHash = sha256Buffer(bundleBuffer);
281
292
  const metadata = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gfean/react-native-bundle-drop",
3
- "version": "0.4.1",
4
- "nativeVersion": "0.4.1",
3
+ "version": "0.4.2",
4
+ "nativeVersion": "0.4.2",
5
5
  "description": "Over-the-air (OTA) updates for React Native — ship fixes instantly, no App Store or Play Store delays",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  ],
36
36
  "scripts": {
37
37
  "clean": "rimraf lib dist",
38
- "build": "tsc -p tsconfig.build.json && node scripts/make-cli-executable.js",
38
+ "build": "yarn clean && tsc -p tsconfig.build.json && node scripts/make-cli-executable.js",
39
39
  "prepare": "husky",
40
40
  "test": "jest --runInBand",
41
41
  "test:coverage": "jest --runInBand --coverage",
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
- import { findProjectRoot } from './projectRoot';
3
- export { findProjectRoot };
4
- export declare function parseAndroidVersionFromGradle(filePath: string): string;
5
- export declare const cleanupArtifacts: (platform: string, zipPath: string) => void;
6
- export declare function runUploadBundle(options?: {
7
- argv?: string[];
8
- cwd?: string;
9
- }): Promise<any>;
@@ -1,317 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- var __importDefault = (this && this.__importDefault) || function (mod) {
37
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.cleanupArtifacts = exports.findProjectRoot = void 0;
41
- exports.parseAndroidVersionFromGradle = parseAndroidVersionFromGradle;
42
- exports.runUploadBundle = runUploadBundle;
43
- const axios_1 = __importDefault(require("axios"));
44
- const child_process_1 = require("child_process");
45
- const form_data_1 = __importDefault(require("form-data"));
46
- const fs = __importStar(require("fs"));
47
- const os_1 = __importDefault(require("os"));
48
- const path = __importStar(require("path"));
49
- const plist = __importStar(require("plist"));
50
- const projectRoot_1 = require("./projectRoot");
51
- Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
52
- const resolve_ios_version_1 = require("./resolve-ios-version");
53
- const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
54
- const readManifestRuntimeVersion = (manifestPath) => {
55
- let manifest;
56
- try {
57
- manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
58
- }
59
- catch (error) {
60
- throw new Error(`bundle-manifest.json is required and must be valid JSON: ${error.message}`);
61
- }
62
- if (manifest.manifestVersion !== 1) {
63
- throw new Error('bundle-manifest.json must use manifestVersion 1');
64
- }
65
- if (typeof manifest.runtimeVersion !== 'string' || !manifest.runtimeVersion) {
66
- throw new Error('bundle-manifest.json is missing runtimeVersion');
67
- }
68
- return manifest.runtimeVersion;
69
- };
70
- function parseAndroidVersionFromGradle(filePath) {
71
- if (!fs.existsSync(filePath)) {
72
- console.error(`❌ build.gradle not found at ${filePath}`);
73
- process.exit(1);
74
- }
75
- const content = fs.readFileSync(filePath, 'utf-8');
76
- const match = content.match(/versionName\s+['"]([^'"]+)['"]/);
77
- if (!match) {
78
- console.error('❌ Could not parse versionName from build.gradle');
79
- process.exit(1);
80
- }
81
- return match[1];
82
- }
83
- const cleanupArtifacts = (platform, zipPath) => {
84
- const outputDir = path.join(getPackageRoot(), 'dist');
85
- try {
86
- const suffix = platform === 'ios' ? 'ios' : 'android';
87
- const filesToDelete = [
88
- zipPath,
89
- path.join(outputDir, `metadata-${suffix}.json`),
90
- path.join(outputDir, 'bundle-manifest.json'),
91
- path.join(outputDir, 'main.jsbundle'),
92
- path.join(outputDir, 'main.jsbundle.map'),
93
- ];
94
- for (const file of filesToDelete) {
95
- if (fs.existsSync(file))
96
- fs.unlinkSync(file);
97
- }
98
- const assetsPath = path.join(outputDir, 'assets');
99
- if (fs.existsSync(assetsPath)) {
100
- fs.rmSync(assetsPath, { recursive: true, force: true });
101
- }
102
- }
103
- catch (err) {
104
- console.warn('⚠️ Cleanup failed:', err);
105
- }
106
- };
107
- exports.cleanupArtifacts = cleanupArtifacts;
108
- async function runUploadBundle(options) {
109
- const packageRoot = getPackageRoot();
110
- const outputDir = path.join(packageRoot, 'dist');
111
- const argv = options?.argv || process.argv;
112
- const projectRoot = (0, projectRoot_1.findProjectRoot)(options?.cwd || process.cwd());
113
- const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
114
- if (!fs.existsSync(configPath)) {
115
- console.error('❌ bundle.drop.config.js not found in project root');
116
- process.exit(1);
117
- }
118
- // eslint-disable-next-line
119
- const config = require(configPath);
120
- if (!config.serverUrl) {
121
- console.error('❌ Missing "serverUrl" in bundle.drop.config.js');
122
- process.exit(1);
123
- }
124
- if (!config.project?.slug) {
125
- console.error('❌ Missing "project.slug" in bundle.drop.config.js');
126
- process.exit(1);
127
- }
128
- if (!config.org?.slug) {
129
- console.error('❌ Missing "org.slug" in bundle.drop.config.js');
130
- process.exit(1);
131
- }
132
- const serverUrl = config.serverUrl;
133
- const orgSlug = config.org.slug;
134
- const projectSlug = config.project.slug;
135
- const authPath = path.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
136
- if (!fs.existsSync(authPath)) {
137
- console.error('❌ Not authenticated. Please run `bundle-drop login` first.');
138
- process.exit(1);
139
- }
140
- let token;
141
- try {
142
- const parsedAuth = JSON.parse(fs.readFileSync(authPath, 'utf-8'));
143
- token = parsedAuth.token;
144
- if (!token) {
145
- throw new Error('Token missing in auth file');
146
- }
147
- }
148
- catch (err) {
149
- console.error(`❌ Invalid auth file at ${authPath}:`, err.message);
150
- console.error('ℹ️ Please log in again with `bundle-drop login`.');
151
- process.exit(1);
152
- }
153
- const platform = argv[2];
154
- const args = argv.slice(3);
155
- const plistArg = args.find(arg => arg.startsWith('--plist-file='));
156
- const plistFile = plistArg?.split('=')[1];
157
- const versionArg = args.find(arg => arg.startsWith('--version='));
158
- const versionFromFlag = versionArg?.split('=')[1];
159
- const buildGradleArg = args.find(arg => arg.startsWith('--buildgradle-path='));
160
- const buildGradlePath = buildGradleArg?.split('=')[1];
161
- const channelArg = args.find(arg => arg.startsWith('--channel='));
162
- const channelName = channelArg?.split('=')[1];
163
- const releaseNotesArg = args.find(arg => arg.startsWith('--release-notes='));
164
- let releaseNotes = releaseNotesArg ? releaseNotesArg.split('=')[1] : undefined;
165
- const generateSourceMap = args.includes('--sourcemap');
166
- const artifactDirArg = args.find(arg => arg.startsWith('--artifact-dir='));
167
- const artifactDir = artifactDirArg ? path.resolve(artifactDirArg.split('=')[1]) : undefined;
168
- const MAX_NOTES = 2000;
169
- if (releaseNotes && releaseNotes.length > MAX_NOTES) {
170
- console.warn(`⚠️ Release notes too long (${releaseNotes.length}); truncating to ${MAX_NOTES} chars.`);
171
- releaseNotes = releaseNotes.slice(0, MAX_NOTES);
172
- }
173
- if (!platform || !['ios', 'android'].includes(platform)) {
174
- console.error('❌ Please pass a platform: ios or android');
175
- process.exit(1);
176
- }
177
- if (!channelName) {
178
- console.error('❌ Missing required --channel=name');
179
- process.exit(1);
180
- }
181
- let version;
182
- if (platform === 'ios') {
183
- if (versionFromFlag) {
184
- version = versionFromFlag;
185
- }
186
- else {
187
- if (!plistFile) {
188
- console.error('❌ Please provide --plist-file=path/to/Info.plist or --version for iOS');
189
- process.exit(1);
190
- }
191
- try {
192
- const plistContent = fs.readFileSync(plistFile, 'utf-8');
193
- const parsed = plist.parse(plistContent);
194
- const rawVersion = parsed.CFBundleShortVersionString;
195
- if (!rawVersion) {
196
- console.error('❌ Could not find CFBundleShortVersionString in plist');
197
- process.exit(1);
198
- }
199
- const resolved = (0, resolve_ios_version_1.resolveIosPlistVersion)(rawVersion, projectRoot);
200
- if (!resolved) {
201
- process.exit(1);
202
- }
203
- version = resolved;
204
- }
205
- catch (err) {
206
- console.error('❌ Failed to read plist file:', err);
207
- process.exit(1);
208
- }
209
- }
210
- }
211
- else if (versionFromFlag) {
212
- version = versionFromFlag;
213
- }
214
- else if (buildGradlePath) {
215
- version = parseAndroidVersionFromGradle(path.resolve(projectRoot, buildGradlePath));
216
- }
217
- else {
218
- const defaultGradlePath = path.join(projectRoot, 'android', 'app', 'build.gradle');
219
- if (fs.existsSync(defaultGradlePath)) {
220
- version = parseAndroidVersionFromGradle(defaultGradlePath);
221
- }
222
- else {
223
- console.error('❌ Please provide --version=x.y.z for Android or --buildgradle-path=path/to/build.gradle');
224
- process.exit(1);
225
- }
226
- }
227
- let runtimeVersion;
228
- const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
229
- const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
230
- const bundleCommand = fs.existsSync(compiledBundleScript)
231
- ? `node "${compiledBundleScript}"`
232
- : `ts-node "${tsBundleScript}"`;
233
- try {
234
- const sourcemapArg = generateSourceMap ? ' --sourcemap' : '';
235
- console.log(`📦 Running bundler for ${platform}...`);
236
- (0, child_process_1.execSync)(`${bundleCommand} ${platform}${sourcemapArg}`, {
237
- stdio: 'inherit',
238
- env: {
239
- ...process.env,
240
- BUNDLE_DROP_APP_VERSION: version,
241
- },
242
- });
243
- const manifestPath = path.join(outputDir, 'bundle-manifest.json');
244
- runtimeVersion = readManifestRuntimeVersion(manifestPath);
245
- console.log(`🆔 Runtime Version: ${runtimeVersion}`);
246
- }
247
- catch (err) {
248
- console.error('❌ Failed to bundle:', err);
249
- process.exit(1);
250
- }
251
- const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
252
- if (!fs.existsSync(zipPath)) {
253
- console.error(`❌ Bundle ZIP not found at ${zipPath}`);
254
- process.exit(1);
255
- }
256
- const form = new form_data_1.default();
257
- form.append('orgSlug', orgSlug);
258
- form.append('projectSlug', projectSlug);
259
- form.append('project', projectSlug);
260
- form.append('platform', platform);
261
- form.append('version', version);
262
- form.append('channelName', channelName);
263
- form.append('runtimeVersion', runtimeVersion);
264
- if (releaseNotes) {
265
- form.append('releaseNotes', releaseNotes);
266
- }
267
- form.append('file', fs.createReadStream(zipPath));
268
- console.log(`→ Uploading bundle to server...`);
269
- try {
270
- const res = await axios_1.default.post(`${serverUrl}/bundle/upload`, form, {
271
- headers: {
272
- ...form.getHeaders(),
273
- Authorization: `Bearer ${token}`,
274
- },
275
- maxContentLength: Infinity,
276
- maxBodyLength: Infinity,
277
- });
278
- if (artifactDir) {
279
- try {
280
- fs.mkdirSync(artifactDir, { recursive: true });
281
- const bundleFile = path.join(outputDir, 'main.jsbundle');
282
- const sourceMapFile = path.join(outputDir, 'main.jsbundle.map');
283
- const result = { ...res.data };
284
- if (fs.existsSync(bundleFile)) {
285
- fs.copyFileSync(bundleFile, path.join(artifactDir, 'main.jsbundle'));
286
- result.bundlePath = path.join(artifactDir, 'main.jsbundle');
287
- }
288
- if (generateSourceMap && fs.existsSync(sourceMapFile)) {
289
- fs.copyFileSync(sourceMapFile, path.join(artifactDir, 'main.jsbundle.map'));
290
- result.sourceMapPath = path.join(artifactDir, 'main.jsbundle.map');
291
- }
292
- fs.writeFileSync(path.join(artifactDir, 'bundle-drop-result.json'), JSON.stringify(result, null, 2));
293
- console.log('📁 Artifacts saved to:', artifactDir);
294
- }
295
- catch (copyErr) {
296
- console.warn('⚠️ Upload succeeded but artifact copy failed:', copyErr.message);
297
- }
298
- }
299
- console.log('✅ Upload complete');
300
- if (res.data?.bundleVersion != null)
301
- console.log(`Bundle Version: ${res.data.bundleVersion}`);
302
- if (res.data?.hash)
303
- console.log(`Hash: ${res.data.hash}`);
304
- return res.data;
305
- }
306
- catch (err) {
307
- console.error('❌ Upload failed:', err?.response?.data || err.message);
308
- throw err;
309
- }
310
- finally {
311
- (0, exports.cleanupArtifacts)(platform, zipPath);
312
- }
313
- }
314
- /* istanbul ignore next */
315
- if (require.main === module) {
316
- runUploadBundle().catch(() => process.exit(1));
317
- }