diff --git a/cli/commands/bundleCommand/bundleCodePush.ts b/cli/commands/bundleCommand/bundleCodePush.ts index d4b74d08..3caf95b7 100644 --- a/cli/commands/bundleCommand/bundleCodePush.ts +++ b/cli/commands/bundleCommand/bundleCodePush.ts @@ -1,4 +1,5 @@ import fs from "fs"; +import path from "path"; import { prepareToBundleJS } from "../../functions/prepareToBundleJS.js"; import { runReactNativeBundleCommand } from "../../functions/runReactNativeBundleCommand.js"; import { runExpoBundleCommand } from "../../functions/runExpoBundleCommand.js"; @@ -17,6 +18,7 @@ export async function bundleCodePush( entryFile: string = ENTRY_FILE, jsBundleName: string, // JS bundle file name (not CodePush bundle file) bundleDirectory: string, // CodePush bundle output directory + outputMetroDir?: string, ): Promise { if (fs.existsSync(outputRootPath)) { fs.rmSync(outputRootPath, { recursive: true }); @@ -49,6 +51,8 @@ export async function bundleCodePush( console.log('log: JS bundling complete'); + copyMetroOutputsIfNeeded(outputRootPath, outputMetroDir, OUTPUT_CONTENT_PATH, _jsBundleName, SOURCEMAP_OUTPUT); + await runHermesEmitBinaryCommand( _jsBundleName, OUTPUT_CONTENT_PATH, @@ -61,3 +65,28 @@ export async function bundleCodePush( return codePushBundleFileName; } + +function copyMetroOutputsIfNeeded( + outputRootPath: string, + outputMetroDir: string | undefined, + outputContentPath: string, + jsBundleName: string, + sourceMapOutputPath: string, +) { + if (!outputMetroDir) { + return; + } + + const resolvedOutputMetroDir = path.join(outputRootPath, outputMetroDir); + + fs.mkdirSync(resolvedOutputMetroDir, { recursive: true }); + fs.copyFileSync( + path.join(outputContentPath, jsBundleName), + path.join(resolvedOutputMetroDir, jsBundleName), + ); + fs.copyFileSync( + sourceMapOutputPath, + path.join(resolvedOutputMetroDir, path.basename(sourceMapOutputPath)), + ); + console.log(`log: Metro outputs copied to: ${resolvedOutputMetroDir}`); +} diff --git a/cli/commands/bundleCommand/index.ts b/cli/commands/bundleCommand/index.ts index 5fd1d9f7..e1b8ffaf 100644 --- a/cli/commands/bundleCommand/index.ts +++ b/cli/commands/bundleCommand/index.ts @@ -9,6 +9,7 @@ type Options = { entryFile: string; bundleName: string; outputBundleDir: string; + outputMetroDir?: string; } program.command('bundle') @@ -18,6 +19,7 @@ program.command('bundle') .option('-o, --output-path ', 'path to output root directory', ROOT_OUTPUT_DIR) .option('-e, --entry-file ', 'path to JS/TS entry file', ENTRY_FILE) .option('-b, --bundle-name ', 'bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")') + .option('--output-metro-dir ', 'name of directory to copy the Metro JS bundle and sourcemap before Hermes compilation') .option('--output-bundle-dir ', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR) .action((options: Options) => { bundleCodePush( @@ -27,5 +29,6 @@ program.command('bundle') options.entryFile, options.bundleName, `${options.outputPath}/${options.outputBundleDir}`, + options.outputMetroDir, ) }); diff --git a/cli/commands/releaseCommand/index.ts b/cli/commands/releaseCommand/index.ts index a8d1d540..ec7e7b77 100644 --- a/cli/commands/releaseCommand/index.ts +++ b/cli/commands/releaseCommand/index.ts @@ -19,6 +19,7 @@ type Options = { skipBundle: boolean; skipCleanup: boolean; outputBundleDir: string; + outputMetroDir?: string; hashCalc?: boolean; } @@ -39,6 +40,7 @@ program.command('release') .option('--skip-bundle ', 'skip bundle process', parseBoolean, false) .option('--hash-calc ', 'calculates the bundle file hash used for packageHash in the release history (Requires setting --skip-bundle to true)', parseBoolean) .option('--skip-cleanup ', 'skip cleanup process', parseBoolean, false) + .option('--output-metro-dir ', 'name of directory to copy the Metro JS bundle and sourcemap before Hermes compilation') .option('--output-bundle-dir ', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR) .action(async (options: Options) => { const config = findAndReadConfigFile(process.cwd(), options.config); @@ -71,6 +73,7 @@ program.command('release') options.skipBundle, options.skipCleanup, `${options.outputPath}/${options.outputBundleDir}`, + options.outputMetroDir, options.hashCalc, ) diff --git a/cli/commands/releaseCommand/release.ts b/cli/commands/releaseCommand/release.ts index 724a61a3..521dfb59 100644 --- a/cli/commands/releaseCommand/release.ts +++ b/cli/commands/releaseCommand/release.ts @@ -24,11 +24,12 @@ export async function release( skipBundle: boolean, skipCleanup: boolean, bundleDirectory: string, + outputMetroDir?: string, hashCalc?: boolean, ): Promise { const bundleFileName = skipBundle ? readBundleFileNameFrom(bundleDirectory) - : await bundleCodePush(framework, platform, outputPath, entryFile, jsBundleName, bundleDirectory); + : await bundleCodePush(framework, platform, outputPath, entryFile, jsBundleName, bundleDirectory, outputMetroDir); const bundleFilePath = `${bundleDirectory}/${bundleFileName}`; const packageHash = await (() => {