@gfean/react-native-bundle-drop 0.4.3 → 0.4.4
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/BundleDropExpo.podspec +21 -0
- package/README.md +250 -124
- package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +33 -3
- package/app.plugin.js +3 -0
- package/expo/android/build.gradle +159 -0
- package/expo/android/src/main/AndroidManifest.xml +1 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoConfiguration.kt +35 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoIdentityModule.kt +30 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoPackage.kt +29 -0
- package/expo/android/src/main/java/com/bundledrop/expo/BundleDropExpoReactNativeHostHandler.kt +16 -0
- package/expo/bundle-drop-expo-gradle-plugin/build.gradle +31 -0
- package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/BundleDropExpoPlugin.groovy +83 -0
- package/expo/bundle-drop-expo-gradle-plugin/src/main/groovy/com/bundledrop/gradle/GenerateBundleDropBuildIdentityTask.groovy +57 -0
- package/expo/ios/Sources/BundleDropExpoIdentity.m +31 -0
- package/expo/ios/Sources/BundleDropExpoReactDelegateHandler.swift +24 -0
- package/expo-module.config.json +19 -0
- package/ios/BundleDropLocator.swift +7 -1
- package/lib/CLI/cli.d.ts +1 -2
- package/lib/CLI/cli.js +116 -14
- package/lib/CLI/scripts/aipowered/apply-setup-plan.d.ts +12 -0
- package/lib/CLI/scripts/aipowered/apply-setup-plan.js +55 -0
- package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -1
- package/lib/CLI/scripts/aipowered/backend-client.js +25 -2
- package/lib/CLI/scripts/aipowered/init-project-config.d.ts +17 -0
- package/lib/CLI/scripts/aipowered/init-project-config.js +400 -0
- package/lib/CLI/scripts/aipowered/scanner.d.ts +10 -1
- package/lib/CLI/scripts/aipowered/scanner.js +252 -5
- package/lib/CLI/scripts/aipowered/types.d.ts +39 -0
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +12 -0
- package/lib/CLI/scripts/aipowered/validate-plan.js +76 -1
- package/lib/CLI/scripts/doctor.d.ts +17 -0
- package/lib/CLI/scripts/doctor.js +412 -0
- package/lib/CLI/scripts/expo/build-receipt.d.ts +26 -0
- package/lib/CLI/scripts/expo/build-receipt.js +223 -0
- package/lib/CLI/scripts/expo/configure-expo.d.ts +28 -0
- package/lib/CLI/scripts/expo/configure-expo.js +268 -0
- package/lib/CLI/scripts/expo/eas-build-proof.d.ts +22 -0
- package/lib/CLI/scripts/expo/eas-build-proof.js +116 -0
- package/lib/CLI/scripts/expo/package-manager.d.ts +11 -0
- package/lib/CLI/scripts/expo/package-manager.js +84 -0
- package/lib/CLI/scripts/expo/write-build-receipt.d.ts +25 -0
- package/lib/CLI/scripts/expo/write-build-receipt.js +325 -0
- package/lib/CLI/scripts/expo/write-eas-build-receipt.d.ts +8 -0
- package/lib/CLI/scripts/expo/write-eas-build-receipt.js +71 -0
- package/lib/CLI/scripts/init-config.d.ts +18 -1
- package/lib/CLI/scripts/init-config.js +29 -8
- package/lib/CLI/scripts/init-metro-config.d.ts +7 -0
- package/lib/CLI/scripts/init-metro-config.js +28 -8
- package/lib/CLI/scripts/login-cli.js +17 -3
- package/lib/CLI/scripts/post-init.d.ts +6 -1
- package/lib/CLI/scripts/post-init.js +6 -33
- package/lib/CLI/scripts/upload-cli.d.ts +1 -0
- package/lib/CLI/scripts/upload-cli.js +106 -36
- package/lib/context.d.ts +0 -2
- package/lib/context.js +18 -2
- package/lib/expo/buildIdentity.d.ts +15 -0
- package/lib/expo/buildIdentity.js +201 -0
- package/lib/expo/buildReceipt.d.ts +42 -0
- package/lib/expo/buildReceipt.js +272 -0
- package/lib/expo/config.d.ts +7 -0
- package/lib/expo/config.js +43 -0
- package/lib/expo/configCache.d.ts +1 -0
- package/lib/expo/configCache.js +20 -0
- package/lib/expo/errors.d.ts +6 -0
- package/lib/expo/errors.js +11 -0
- package/lib/expo/expoUpdatesOwnership.d.ts +13 -0
- package/lib/expo/expoUpdatesOwnership.js +22 -0
- package/lib/expo/exportExpoProject.d.ts +21 -0
- package/lib/expo/exportExpoProject.js +125 -0
- package/lib/expo/exportValidation.d.ts +11 -0
- package/lib/expo/exportValidation.js +115 -0
- package/lib/expo/index.d.ts +18 -0
- package/lib/expo/index.js +25 -0
- package/lib/expo/localModules.d.ts +4 -0
- package/lib/expo/localModules.js +51 -0
- package/lib/expo/nativeIdentity.d.ts +1 -0
- package/lib/expo/nativeIdentity.js +17 -0
- package/lib/expo/projectType.d.ts +7 -0
- package/lib/expo/projectType.js +200 -0
- package/lib/expo/runtimeVersion.d.ts +13 -0
- package/lib/expo/runtimeVersion.js +45 -0
- package/lib/expo/types.d.ts +15 -0
- package/lib/expo/types.js +2 -0
- package/lib/fs/userProperties.d.ts +0 -2
- package/lib/fs/userProperties.js +0 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -2
- package/lib/loadConfig.d.ts +15 -7
- package/lib/loadConfig.js +2 -19
- package/lib/metro.d.ts +17 -0
- package/lib/metro.js +57 -0
- package/lib/native/bundleDropNative.d.ts +2 -0
- package/lib/native/bundleDropNative.js +9 -1
- package/lib/runtime/service.js +12 -1
- package/lib/scripts/bundle.d.ts +2 -2
- package/lib/scripts/bundle.js +10 -97
- package/lib/scripts/canonicalArtifact.d.ts +30 -0
- package/lib/scripts/canonicalArtifact.js +212 -0
- package/lib/scripts/exportProject.d.ts +41 -0
- package/lib/scripts/exportProject.js +82 -0
- package/package.json +51 -46
- package/plugin/constants.js +9 -0
- package/plugin/expoUpdates.js +131 -0
- package/plugin/index.js +11 -0
- package/plugin/markers.js +31 -0
- package/plugin/withBundleDrop.js +36 -0
- package/plugin/xcodeBuildPhase.js +77 -0
- package/react-native.config.js +20 -0
package/lib/loadConfig.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadConfig = loadConfig;
|
|
4
|
-
const react_native_1 = require("react-native");
|
|
5
|
-
function resolveDebugLocalPort(serverUrl) {
|
|
6
|
-
try {
|
|
7
|
-
return new URL(serverUrl).port || '4000';
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
return '4000';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
4
|
function loadConfig() {
|
|
14
5
|
try {
|
|
15
6
|
// ✅ Resolved via Metro alias in the host app (extraNodeModules)
|
|
@@ -18,15 +9,8 @@ function loadConfig() {
|
|
|
18
9
|
if (!cfg?.serverUrl || !cfg?.project?.slug || !cfg?.org?.slug) {
|
|
19
10
|
throw new Error('bundle.drop.config.js missing serverUrl, org.slug or project.slug');
|
|
20
11
|
}
|
|
21
|
-
if (cfg.
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
...cfg,
|
|
25
|
-
serverUrl: react_native_1.Platform.OS === 'android'
|
|
26
|
-
? `http://10.0.2.2:${port}`
|
|
27
|
-
: `http://localhost:${port}`,
|
|
28
|
-
debugLocal: true,
|
|
29
|
-
};
|
|
12
|
+
if (cfg.runtimeVersion?.source === 'expo') {
|
|
13
|
+
throw new Error('Expo runtime identity was not embedded. Configure Metro with withBundleDropExpo().');
|
|
30
14
|
}
|
|
31
15
|
return cfg;
|
|
32
16
|
}
|
|
@@ -37,7 +21,6 @@ function loadConfig() {
|
|
|
37
21
|
serverUrl: 'https://api.bundledrop.app',
|
|
38
22
|
org: { slug: 'default-org' },
|
|
39
23
|
project: { name: 'BundleDrop', slug: 'default' },
|
|
40
|
-
debugLocal: false,
|
|
41
24
|
};
|
|
42
25
|
}
|
|
43
26
|
throw new Error('[BundleDrop] bundle.drop.config.js could not be loaded. ' +
|
package/lib/metro.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type { ExpoBuildIdentityReceipt } from './expo/buildReceipt';
|
|
2
|
+
export type BundleDropMetroConfig = {
|
|
3
|
+
resolver?: {
|
|
4
|
+
extraNodeModules?: Record<string, string>;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
export type WithBundleDropExpoOptions = {
|
|
10
|
+
projectRoot?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Preserves the caller's Expo Metro config and only adds Bundle Drop's config
|
|
14
|
+
* alias after resolving the same concrete identity used by build and upload.
|
|
15
|
+
*/
|
|
16
|
+
export declare function withBundleDropExpo<T extends BundleDropMetroConfig>(configOrPromise: T | Promise<T>, options?: WithBundleDropExpoOptions): Promise<T>;
|
|
17
|
+
export default withBundleDropExpo;
|
package/lib/metro.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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.withBundleDropExpo = withBundleDropExpo;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const expo_1 = require("./expo");
|
|
10
|
+
const writeGeneratedRuntimeConfig = (params) => {
|
|
11
|
+
const generatedDirectory = path_1.default.join(params.projectRoot, '.bundle-drop', 'generated');
|
|
12
|
+
const generatedConfigPath = path_1.default.join(generatedDirectory, 'bundle.drop.config.js');
|
|
13
|
+
fs_extra_1.default.ensureDirSync(generatedDirectory);
|
|
14
|
+
const baseConfigPath = path_1.default.join(params.projectRoot, 'bundle.drop.config.js');
|
|
15
|
+
if (!fs_extra_1.default.existsSync(baseConfigPath)) {
|
|
16
|
+
throw new Error('Bundle Drop Expo Metro setup requires bundle.drop.config.js in the project root.');
|
|
17
|
+
}
|
|
18
|
+
const content = [
|
|
19
|
+
"'use strict';",
|
|
20
|
+
'',
|
|
21
|
+
"const baseConfig = require('../../bundle.drop.config.js');",
|
|
22
|
+
'module.exports = {',
|
|
23
|
+
' ...baseConfig,',
|
|
24
|
+
` runtimeVersion: ${JSON.stringify({
|
|
25
|
+
ios: params.ios,
|
|
26
|
+
android: params.android,
|
|
27
|
+
})},`,
|
|
28
|
+
'};',
|
|
29
|
+
'',
|
|
30
|
+
].join('\n');
|
|
31
|
+
fs_extra_1.default.writeFileSync(generatedConfigPath, content, 'utf8');
|
|
32
|
+
return generatedConfigPath;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Preserves the caller's Expo Metro config and only adds Bundle Drop's config
|
|
36
|
+
* alias after resolving the same concrete identity used by build and upload.
|
|
37
|
+
*/
|
|
38
|
+
async function withBundleDropExpo(configOrPromise, options = {}) {
|
|
39
|
+
const projectRoot = path_1.default.resolve(options.projectRoot || process.cwd());
|
|
40
|
+
const [config, ios, android] = await Promise.all([
|
|
41
|
+
Promise.resolve(configOrPromise),
|
|
42
|
+
(0, expo_1.resolveExpoMetroRuntimeVersion)(projectRoot, 'ios'),
|
|
43
|
+
(0, expo_1.resolveExpoMetroRuntimeVersion)(projectRoot, 'android'),
|
|
44
|
+
]);
|
|
45
|
+
const generatedConfigPath = writeGeneratedRuntimeConfig({ projectRoot, ios, android });
|
|
46
|
+
return {
|
|
47
|
+
...config,
|
|
48
|
+
resolver: {
|
|
49
|
+
...(config.resolver || {}),
|
|
50
|
+
extraNodeModules: {
|
|
51
|
+
...(config.resolver?.extraNodeModules || {}),
|
|
52
|
+
'bundle-drop-config': generatedConfigPath,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.default = withBundleDropExpo;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare function isBundleDropNativeAvailable(): boolean;
|
|
2
|
+
export declare function isExpoOtaStartupEnabledNative(): boolean;
|
|
1
3
|
export declare function getDownloadedBundlePathNative(): Promise<string | null>;
|
|
2
4
|
export declare function restartReactNativeNative(): void;
|
|
3
5
|
export declare function setOtaEnabledNative(enabled: boolean): Promise<void>;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBundleDropNativeAvailable = isBundleDropNativeAvailable;
|
|
4
|
+
exports.isExpoOtaStartupEnabledNative = isExpoOtaStartupEnabledNative;
|
|
3
5
|
exports.getDownloadedBundlePathNative = getDownloadedBundlePathNative;
|
|
4
6
|
exports.restartReactNativeNative = restartReactNativeNative;
|
|
5
7
|
exports.setOtaEnabledNative = setOtaEnabledNative;
|
|
6
8
|
const react_native_1 = require("react-native");
|
|
7
|
-
const { BundleDrop } = react_native_1.NativeModules;
|
|
9
|
+
const { BundleDrop, BundleDropExpoIdentity } = react_native_1.NativeModules;
|
|
10
|
+
function isBundleDropNativeAvailable() {
|
|
11
|
+
return Boolean(BundleDrop);
|
|
12
|
+
}
|
|
13
|
+
function isExpoOtaStartupEnabledNative() {
|
|
14
|
+
return BundleDropExpoIdentity?.otaStartupEnabled === true;
|
|
15
|
+
}
|
|
8
16
|
async function getDownloadedBundlePathNative() {
|
|
9
17
|
if (!BundleDrop?.getDownloadedBundlePath) {
|
|
10
18
|
console.warn('BundleDrop.getDownloadedBundlePath is not defined');
|
package/lib/runtime/service.js
CHANGED
|
@@ -36,6 +36,9 @@ const updateState_1 = require("../manager/updateState");
|
|
|
36
36
|
const initState_1 = require("./initState");
|
|
37
37
|
const DEFAULT_STATUS = 'Click the button to check for updates';
|
|
38
38
|
const DISABLED_STATUS = 'BundleDrop is disabled';
|
|
39
|
+
const EXPO_DEVELOPMENT_FALLBACK_WARNING = '[BundleDrop] OTA startup is unavailable in this Expo runtime. ' +
|
|
40
|
+
'Expo Go and standard Debug/development-client builds keep Metro priority, so OTA features are disabled. ' +
|
|
41
|
+
'Use a non-Debug/Release native build to test Bundle Drop updates.';
|
|
39
42
|
let updateFlowActive = false;
|
|
40
43
|
let startupPromise = null;
|
|
41
44
|
let localStartupPromise = null;
|
|
@@ -43,6 +46,7 @@ let healthTimer = null;
|
|
|
43
46
|
let runtimeRestartRequested = false;
|
|
44
47
|
let activeBundleInfoForObservability = null;
|
|
45
48
|
let nativeOtaEnabledPromise = Promise.resolve();
|
|
49
|
+
let hasWarnedAboutExpoDevelopmentFallback = false;
|
|
46
50
|
let snapshot = {
|
|
47
51
|
status: DISABLED_STATUS,
|
|
48
52
|
isBusy: false,
|
|
@@ -368,7 +372,14 @@ function ensureStartupFlow() {
|
|
|
368
372
|
* `useBundleDrop()` or any OTA runtime APIs.
|
|
369
373
|
*/
|
|
370
374
|
function initBundleDrop(options) {
|
|
371
|
-
const
|
|
375
|
+
const useExpoDevelopmentFallback = options.enabled !== false &&
|
|
376
|
+
context_1.config.projectType === 'expo' &&
|
|
377
|
+
(!(0, bundleDropNative_1.isBundleDropNativeAvailable)() || !(0, bundleDropNative_1.isExpoOtaStartupEnabledNative)());
|
|
378
|
+
if (useExpoDevelopmentFallback && !hasWarnedAboutExpoDevelopmentFallback) {
|
|
379
|
+
hasWarnedAboutExpoDevelopmentFallback = true;
|
|
380
|
+
console.warn(EXPO_DEVELOPMENT_FALLBACK_WARNING);
|
|
381
|
+
}
|
|
382
|
+
const { alreadyInitialized, config } = (0, initState_1.initializeBundleDropRuntime)(useExpoDevelopmentFallback ? { ...options, enabled: false } : options);
|
|
372
383
|
if (!alreadyInitialized) {
|
|
373
384
|
runtimeRestartRequested = false;
|
|
374
385
|
activeBundleInfoForObservability = null;
|
package/lib/scripts/bundle.d.ts
CHANGED
|
@@ -6,10 +6,9 @@ export declare function runBundleScript(options?: {
|
|
|
6
6
|
cwd?: string;
|
|
7
7
|
sourcemap?: boolean;
|
|
8
8
|
}): {
|
|
9
|
-
projectRoot: string;
|
|
10
9
|
outputDir: string;
|
|
11
10
|
bundlePath: string;
|
|
12
|
-
sourceMapPath
|
|
11
|
+
sourceMapPath?: string;
|
|
13
12
|
metadataPath: string;
|
|
14
13
|
zipPath: string;
|
|
15
14
|
runtimeVersion: string;
|
|
@@ -17,4 +16,5 @@ export declare function runBundleScript(options?: {
|
|
|
17
16
|
bundleHash: string;
|
|
18
17
|
jsBundleHash: string;
|
|
19
18
|
manifestPath: string;
|
|
19
|
+
projectRoot: string;
|
|
20
20
|
};
|
package/lib/scripts/bundle.js
CHANGED
|
@@ -33,39 +33,19 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
return result;
|
|
34
34
|
};
|
|
35
35
|
})();
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
37
|
exports.findProjectRoot = void 0;
|
|
41
38
|
exports.runBundleScript = runBundleScript;
|
|
42
|
-
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
43
39
|
const child_process_1 = require("child_process");
|
|
44
|
-
const crypto_1 = require("crypto");
|
|
45
40
|
const fs = __importStar(require("fs"));
|
|
46
41
|
const path = __importStar(require("path"));
|
|
47
42
|
const bundleManifest_1 = require("../manifest/bundleManifest");
|
|
43
|
+
const canonicalArtifact_1 = require("./canonicalArtifact");
|
|
48
44
|
const projectRoot_1 = require("./projectRoot");
|
|
49
45
|
Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return projectRoot_1.findProjectRoot; } });
|
|
50
46
|
const SENTRY_HERMES_OTA_DOCS_URL = 'https://bundledrop.app/docs/observability#sentry-and-hermes-ota-builds';
|
|
51
47
|
const SENTRY_DEBUG_ID_MARKERS = ['//# debugId=', 'sentry-dbid-'];
|
|
52
48
|
const getPackageRoot = () => process.env.BUNDLE_DROP_PACKAGE_ROOT_OVERRIDE || path.resolve(__dirname, '..', '..');
|
|
53
|
-
const sha256Buffer = (buffer) => (0, crypto_1.createHash)('sha256').update(buffer).digest('hex');
|
|
54
|
-
const manifestRoleForPath = (filePath) => {
|
|
55
|
-
if (filePath === 'main.jsbundle')
|
|
56
|
-
return 'jsbundle';
|
|
57
|
-
if (filePath.startsWith('metadata-'))
|
|
58
|
-
return 'metadata';
|
|
59
|
-
if (filePath === 'image-manifest.json')
|
|
60
|
-
return 'androidImageManifest';
|
|
61
|
-
return 'asset';
|
|
62
|
-
};
|
|
63
|
-
const createFileEntry = (filePath, buffer) => ({
|
|
64
|
-
path: (0, bundleManifest_1.normalizeManifestPath)(filePath),
|
|
65
|
-
size: buffer.length,
|
|
66
|
-
sha256: sha256Buffer(buffer),
|
|
67
|
-
role: manifestRoleForPath((0, bundleManifest_1.normalizeManifestPath)(filePath)),
|
|
68
|
-
});
|
|
69
49
|
const readTextIfExists = (filePath) => {
|
|
70
50
|
if (!fs.existsSync(filePath))
|
|
71
51
|
return null;
|
|
@@ -203,7 +183,6 @@ function runBundleScript(options) {
|
|
|
203
183
|
const manifestPath = path.join(outputDir, bundleManifest_1.BUNDLE_MANIFEST);
|
|
204
184
|
const sourceMapPath = path.join(outputDir, 'main.jsbundle.map');
|
|
205
185
|
const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
|
|
206
|
-
const imageManifest = {};
|
|
207
186
|
const projectRoot = (0, projectRoot_1.findProjectRoot)(options?.cwd || process.cwd());
|
|
208
187
|
const generateSourceMap = options?.sourcemap ?? process.argv.includes('--sourcemap');
|
|
209
188
|
const appVersion = process.env.BUNDLE_DROP_APP_VERSION;
|
|
@@ -302,85 +281,19 @@ function runBundleScript(options) {
|
|
|
302
281
|
else {
|
|
303
282
|
console.log(`ℹ️ Hermes bytecode disabled for ${platform} — bundling plain JS`);
|
|
304
283
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const bundleBuffer = fs.readFileSync(bundlePath);
|
|
309
|
-
const jsBundleHash = sha256Buffer(bundleBuffer);
|
|
310
|
-
const metadata = {
|
|
311
|
-
platform,
|
|
312
|
-
jsBundleHash,
|
|
313
|
-
bundlePath: 'main.jsbundle',
|
|
314
|
-
sizeInBytes: bundleBuffer.length,
|
|
315
|
-
};
|
|
316
|
-
if (runtimeVersion) {
|
|
317
|
-
metadata.runtimeVersion = runtimeVersion;
|
|
318
|
-
}
|
|
319
|
-
const stagedFiles = new Map();
|
|
320
|
-
stagedFiles.set('main.jsbundle', bundleBuffer);
|
|
321
|
-
const metadataFilePath = `metadata-${fileSuffix}.json`;
|
|
322
|
-
const metadataBuffer = Buffer.from(JSON.stringify(metadata, null, 2));
|
|
323
|
-
stagedFiles.set(metadataFilePath, metadataBuffer);
|
|
324
|
-
const zip = new adm_zip_1.default();
|
|
325
|
-
const addAssetsToZip = (dir) => {
|
|
326
|
-
const items = fs.readdirSync(dir);
|
|
327
|
-
for (const item of items) {
|
|
328
|
-
const fullPath = path.join(dir, item);
|
|
329
|
-
const relPath = path.relative(assetsDir, fullPath);
|
|
330
|
-
const normalizedPath = relPath;
|
|
331
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
332
|
-
addAssetsToZip(fullPath);
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
const buffer = fs.readFileSync(fullPath);
|
|
336
|
-
stagedFiles.set((0, bundleManifest_1.normalizeManifestPath)(normalizedPath), buffer);
|
|
337
|
-
if (isAndroid) {
|
|
338
|
-
const manifestKey = (0, bundleManifest_1.normalizeManifestPath)(normalizedPath).replace(/^assets\//, '');
|
|
339
|
-
imageManifest[manifestKey] = (0, bundleManifest_1.normalizeManifestPath)(normalizedPath);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
addAssetsToZip(assetsDir);
|
|
345
|
-
if (isAndroid) {
|
|
346
|
-
stagedFiles.set('image-manifest.json', Buffer.from(JSON.stringify(imageManifest, null, 2)));
|
|
347
|
-
console.log(`🧩 Injected image-manifest.json with ${Object.keys(imageManifest).length} entries`);
|
|
348
|
-
}
|
|
349
|
-
const files = [...stagedFiles.entries()].map(([filePath, buffer]) => createFileEntry(filePath, buffer));
|
|
350
|
-
fs.writeFileSync(metadataPath, metadataBuffer);
|
|
351
|
-
const bundleHash = (0, bundleManifest_1.calculateBundleHash)(files);
|
|
352
|
-
const manifest = (0, bundleManifest_1.createBundleManifest)({
|
|
353
|
-
bundleHash,
|
|
354
|
-
jsBundleHash,
|
|
355
|
-
platform,
|
|
284
|
+
const artifact = (0, canonicalArtifact_1.buildCanonicalArtifact)({
|
|
285
|
+
platform: platform,
|
|
286
|
+
appVersion,
|
|
356
287
|
runtimeVersion,
|
|
357
|
-
|
|
358
|
-
|
|
288
|
+
bundlePath,
|
|
289
|
+
assetsDir,
|
|
290
|
+
outputDir,
|
|
291
|
+
sourceMapPath: generateSourceMap ? sourceMapPath : undefined,
|
|
292
|
+
assetTraversal: 'legacy-bare',
|
|
359
293
|
});
|
|
360
|
-
const manifestBuffer = Buffer.from(JSON.stringify(manifest, null, 2));
|
|
361
|
-
stagedFiles.set(bundleManifest_1.BUNDLE_MANIFEST, manifestBuffer);
|
|
362
|
-
fs.writeFileSync(manifestPath, manifestBuffer);
|
|
363
|
-
console.log('🧠 Metadata saved');
|
|
364
|
-
console.log('📌 Bundle Hash:', bundleHash);
|
|
365
|
-
console.log('📌 JS Bundle Hash:', jsBundleHash);
|
|
366
|
-
console.log('📦 Zipping bundle...');
|
|
367
|
-
for (const [filePath, buffer] of stagedFiles.entries()) {
|
|
368
|
-
zip.addFile(filePath, buffer);
|
|
369
|
-
}
|
|
370
|
-
zip.writeZip(zipPath);
|
|
371
|
-
console.log('✅ OTA bundle zipped');
|
|
372
294
|
return {
|
|
373
295
|
projectRoot,
|
|
374
|
-
|
|
375
|
-
bundlePath,
|
|
376
|
-
sourceMapPath: generateSourceMap ? sourceMapPath : undefined,
|
|
377
|
-
metadataPath,
|
|
378
|
-
zipPath,
|
|
379
|
-
runtimeVersion,
|
|
380
|
-
hash: bundleHash,
|
|
381
|
-
bundleHash,
|
|
382
|
-
jsBundleHash,
|
|
383
|
-
manifestPath,
|
|
296
|
+
...artifact,
|
|
384
297
|
};
|
|
385
298
|
}
|
|
386
299
|
/* istanbul ignore next */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type CanonicalArtifactPlatform = 'ios' | 'android';
|
|
2
|
+
export type CanonicalAssetTraversal = 'strict' | 'legacy-bare';
|
|
3
|
+
export type BuildCanonicalArtifactOptions = {
|
|
4
|
+
platform: CanonicalArtifactPlatform;
|
|
5
|
+
appVersion: string;
|
|
6
|
+
runtimeVersion: string;
|
|
7
|
+
bundlePath: string;
|
|
8
|
+
assetsDir: string;
|
|
9
|
+
outputDir: string;
|
|
10
|
+
sourceMapPath?: string;
|
|
11
|
+
assetTraversal?: CanonicalAssetTraversal;
|
|
12
|
+
};
|
|
13
|
+
export type CanonicalArtifact = {
|
|
14
|
+
outputDir: string;
|
|
15
|
+
bundlePath: string;
|
|
16
|
+
sourceMapPath?: string;
|
|
17
|
+
metadataPath: string;
|
|
18
|
+
zipPath: string;
|
|
19
|
+
runtimeVersion: string;
|
|
20
|
+
hash: string;
|
|
21
|
+
bundleHash: string;
|
|
22
|
+
jsBundleHash: string;
|
|
23
|
+
manifestPath: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const normalizeCanonicalAssetPath: (relativePath: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Normalizes a framework exporter result into Bundle Drop's frozen manifest and
|
|
28
|
+
* ZIP roles. Framework-specific export commands must finish before this runs.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildCanonicalArtifact(options: BuildCanonicalArtifactOptions): CanonicalArtifact;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.normalizeCanonicalAssetPath = void 0;
|
|
40
|
+
exports.buildCanonicalArtifact = buildCanonicalArtifact;
|
|
41
|
+
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
42
|
+
const crypto_1 = require("crypto");
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const bundleManifest_1 = require("../manifest/bundleManifest");
|
|
46
|
+
const sha256Buffer = (buffer) => (0, crypto_1.createHash)('sha256').update(buffer).digest('hex');
|
|
47
|
+
const manifestRoleForPath = (filePath) => {
|
|
48
|
+
if (filePath === 'main.jsbundle')
|
|
49
|
+
return 'jsbundle';
|
|
50
|
+
if (filePath.startsWith('metadata-'))
|
|
51
|
+
return 'metadata';
|
|
52
|
+
if (filePath === 'image-manifest.json')
|
|
53
|
+
return 'androidImageManifest';
|
|
54
|
+
return 'asset';
|
|
55
|
+
};
|
|
56
|
+
const createFileEntry = (filePath, buffer) => ({
|
|
57
|
+
path: (0, bundleManifest_1.normalizeManifestPath)(filePath),
|
|
58
|
+
size: buffer.length,
|
|
59
|
+
sha256: sha256Buffer(buffer),
|
|
60
|
+
role: manifestRoleForPath((0, bundleManifest_1.normalizeManifestPath)(filePath)),
|
|
61
|
+
});
|
|
62
|
+
const normalizeCanonicalAssetPath = (relativePath) => {
|
|
63
|
+
const nativeSeparatorsNormalized = relativePath.replace(/\\/g, '/');
|
|
64
|
+
const normalized = (0, bundleManifest_1.normalizeManifestPath)(nativeSeparatorsNormalized);
|
|
65
|
+
if (!normalized ||
|
|
66
|
+
path.isAbsolute(relativePath) ||
|
|
67
|
+
path.win32.isAbsolute(relativePath) ||
|
|
68
|
+
normalized.split('/').includes('..') ||
|
|
69
|
+
normalized === bundleManifest_1.BUNDLE_MANIFEST ||
|
|
70
|
+
normalized === 'main.jsbundle' ||
|
|
71
|
+
normalized === 'image-manifest.json' ||
|
|
72
|
+
normalized.startsWith('metadata-')) {
|
|
73
|
+
throw new Error(`Unsafe or reserved asset path: ${relativePath}`);
|
|
74
|
+
}
|
|
75
|
+
return normalized;
|
|
76
|
+
};
|
|
77
|
+
exports.normalizeCanonicalAssetPath = normalizeCanonicalAssetPath;
|
|
78
|
+
const collectStrictAssets = (assetsDir) => {
|
|
79
|
+
const assets = [];
|
|
80
|
+
const seenCaseInsensitive = new Set();
|
|
81
|
+
const visit = (directory) => {
|
|
82
|
+
for (const item of fs.readdirSync(directory)) {
|
|
83
|
+
const fullPath = path.join(directory, item);
|
|
84
|
+
const stat = fs.lstatSync(fullPath);
|
|
85
|
+
if (stat.isSymbolicLink()) {
|
|
86
|
+
throw new Error(`Asset symlinks are not supported: ${path.relative(assetsDir, fullPath)}`);
|
|
87
|
+
}
|
|
88
|
+
if (stat.isDirectory()) {
|
|
89
|
+
visit(fullPath);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!stat.isFile()) {
|
|
93
|
+
throw new Error(`Unsupported asset entry: ${path.relative(assetsDir, fullPath)}`);
|
|
94
|
+
}
|
|
95
|
+
const relativePath = (0, exports.normalizeCanonicalAssetPath)(path.relative(assetsDir, fullPath));
|
|
96
|
+
const collisionKey = relativePath.toLocaleLowerCase('en-US');
|
|
97
|
+
if (seenCaseInsensitive.has(collisionKey)) {
|
|
98
|
+
throw new Error(`Asset path collision: ${relativePath}`);
|
|
99
|
+
}
|
|
100
|
+
seenCaseInsensitive.add(collisionKey);
|
|
101
|
+
assets.push([relativePath, fs.readFileSync(fullPath)]);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
visit(assetsDir);
|
|
105
|
+
return assets;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Bare React Native bundling historically followed symlinks and keyed assets by
|
|
109
|
+
* their exact relative path. Keep that traversal intact for existing bare apps;
|
|
110
|
+
* Expo exports use the strict collector above.
|
|
111
|
+
*/
|
|
112
|
+
const collectLegacyBareAssets = (assetsDir) => {
|
|
113
|
+
const assets = [];
|
|
114
|
+
const visit = (directory) => {
|
|
115
|
+
for (const item of fs.readdirSync(directory)) {
|
|
116
|
+
const fullPath = path.join(directory, item);
|
|
117
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
118
|
+
visit(fullPath);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const relativePath = (0, bundleManifest_1.normalizeManifestPath)(path.relative(assetsDir, fullPath));
|
|
122
|
+
assets.push([relativePath, fs.readFileSync(fullPath)]);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
visit(assetsDir);
|
|
126
|
+
return assets;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Normalizes a framework exporter result into Bundle Drop's frozen manifest and
|
|
130
|
+
* ZIP roles. Framework-specific export commands must finish before this runs.
|
|
131
|
+
*/
|
|
132
|
+
function buildCanonicalArtifact(options) {
|
|
133
|
+
const { platform, appVersion, runtimeVersion, bundlePath, assetsDir, outputDir, sourceMapPath, assetTraversal = 'strict', } = options;
|
|
134
|
+
if (!appVersion.trim())
|
|
135
|
+
throw new Error('Canonical artifact requires an app version');
|
|
136
|
+
if (!runtimeVersion.trim())
|
|
137
|
+
throw new Error('Canonical artifact requires a runtime version');
|
|
138
|
+
if (!fs.existsSync(bundlePath) || !fs.statSync(bundlePath).isFile()) {
|
|
139
|
+
throw new Error(`Bundle output missing after bundling: ${bundlePath}`);
|
|
140
|
+
}
|
|
141
|
+
if (!fs.existsSync(assetsDir) || !fs.statSync(assetsDir).isDirectory()) {
|
|
142
|
+
throw new Error(`Assets directory missing after bundling: ${assetsDir}`);
|
|
143
|
+
}
|
|
144
|
+
const fileSuffix = platform;
|
|
145
|
+
const metadataPath = path.join(outputDir, `metadata-${fileSuffix}.json`);
|
|
146
|
+
const manifestPath = path.join(outputDir, bundleManifest_1.BUNDLE_MANIFEST);
|
|
147
|
+
const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
|
|
148
|
+
const bundleBuffer = fs.readFileSync(bundlePath);
|
|
149
|
+
const jsBundleHash = sha256Buffer(bundleBuffer);
|
|
150
|
+
const metadata = {
|
|
151
|
+
platform,
|
|
152
|
+
jsBundleHash,
|
|
153
|
+
bundlePath: 'main.jsbundle',
|
|
154
|
+
sizeInBytes: bundleBuffer.length,
|
|
155
|
+
runtimeVersion,
|
|
156
|
+
};
|
|
157
|
+
const metadataBuffer = Buffer.from(JSON.stringify(metadata, null, 2));
|
|
158
|
+
const stagedFiles = new Map([
|
|
159
|
+
['main.jsbundle', bundleBuffer],
|
|
160
|
+
[`metadata-${fileSuffix}.json`, metadataBuffer],
|
|
161
|
+
]);
|
|
162
|
+
const imageManifest = {};
|
|
163
|
+
const assets = assetTraversal === 'legacy-bare'
|
|
164
|
+
? collectLegacyBareAssets(assetsDir)
|
|
165
|
+
: collectStrictAssets(assetsDir);
|
|
166
|
+
for (const [assetPath, buffer] of assets) {
|
|
167
|
+
stagedFiles.set(assetPath, buffer);
|
|
168
|
+
if (platform === 'android') {
|
|
169
|
+
imageManifest[assetPath.replace(/^assets\//, '')] = assetPath;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (platform === 'android') {
|
|
173
|
+
stagedFiles.set('image-manifest.json', Buffer.from(JSON.stringify(imageManifest, null, 2)));
|
|
174
|
+
console.log(`🧩 Injected image-manifest.json with ${Object.keys(imageManifest).length} entries`);
|
|
175
|
+
}
|
|
176
|
+
const files = [...stagedFiles.entries()].map(([filePath, buffer]) => createFileEntry(filePath, buffer));
|
|
177
|
+
const bundleHash = (0, bundleManifest_1.calculateBundleHash)(files);
|
|
178
|
+
const manifest = (0, bundleManifest_1.createBundleManifest)({
|
|
179
|
+
bundleHash,
|
|
180
|
+
jsBundleHash,
|
|
181
|
+
platform,
|
|
182
|
+
runtimeVersion,
|
|
183
|
+
version: appVersion,
|
|
184
|
+
files,
|
|
185
|
+
});
|
|
186
|
+
const manifestBuffer = Buffer.from(JSON.stringify(manifest, null, 2));
|
|
187
|
+
stagedFiles.set(bundleManifest_1.BUNDLE_MANIFEST, manifestBuffer);
|
|
188
|
+
fs.writeFileSync(metadataPath, metadataBuffer);
|
|
189
|
+
fs.writeFileSync(manifestPath, manifestBuffer);
|
|
190
|
+
console.log('🧠 Metadata saved');
|
|
191
|
+
console.log('📌 Bundle Hash:', bundleHash);
|
|
192
|
+
console.log('📌 JS Bundle Hash:', jsBundleHash);
|
|
193
|
+
console.log('📦 Zipping bundle...');
|
|
194
|
+
const zip = new adm_zip_1.default();
|
|
195
|
+
for (const [filePath, buffer] of stagedFiles.entries()) {
|
|
196
|
+
zip.addFile(filePath, buffer);
|
|
197
|
+
}
|
|
198
|
+
zip.writeZip(zipPath);
|
|
199
|
+
console.log('✅ OTA bundle zipped');
|
|
200
|
+
return {
|
|
201
|
+
outputDir,
|
|
202
|
+
bundlePath,
|
|
203
|
+
sourceMapPath,
|
|
204
|
+
metadataPath,
|
|
205
|
+
zipPath,
|
|
206
|
+
runtimeVersion,
|
|
207
|
+
hash: bundleHash,
|
|
208
|
+
bundleHash,
|
|
209
|
+
jsBundleHash,
|
|
210
|
+
manifestPath,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ExpoBuildIdentity, MobilePlatform, ProjectType } from '../expo';
|
|
2
|
+
export type ExportProjectArtifactOptions = {
|
|
3
|
+
projectRoot: string;
|
|
4
|
+
platform: MobilePlatform;
|
|
5
|
+
appVersion: string;
|
|
6
|
+
generateSourceMap: boolean;
|
|
7
|
+
projectType?: ProjectType;
|
|
8
|
+
buildReceipt?: string;
|
|
9
|
+
buildIdentity?: ExpoBuildIdentity;
|
|
10
|
+
};
|
|
11
|
+
export declare function exportProjectArtifact(options: ExportProjectArtifactOptions): Promise<{
|
|
12
|
+
outputDir: string;
|
|
13
|
+
bundlePath: string;
|
|
14
|
+
sourceMapPath?: string;
|
|
15
|
+
metadataPath: string;
|
|
16
|
+
zipPath: string;
|
|
17
|
+
runtimeVersion: string;
|
|
18
|
+
hash: string;
|
|
19
|
+
bundleHash: string;
|
|
20
|
+
jsBundleHash: string;
|
|
21
|
+
manifestPath: string;
|
|
22
|
+
projectRoot: string;
|
|
23
|
+
projectType: "bare";
|
|
24
|
+
buildIdentity: any;
|
|
25
|
+
} | {
|
|
26
|
+
outputDir: string;
|
|
27
|
+
bundlePath: string;
|
|
28
|
+
sourceMapPath?: string;
|
|
29
|
+
metadataPath: string;
|
|
30
|
+
zipPath: string;
|
|
31
|
+
runtimeVersion: string;
|
|
32
|
+
hash: string;
|
|
33
|
+
bundleHash: string;
|
|
34
|
+
jsBundleHash: string;
|
|
35
|
+
manifestPath: string;
|
|
36
|
+
projectType: "expo";
|
|
37
|
+
projectRoot: string;
|
|
38
|
+
buildIdentity: ExpoBuildIdentity;
|
|
39
|
+
expoExportDirectory: string;
|
|
40
|
+
sourceMapDebugId: string;
|
|
41
|
+
}>;
|