import { info } from "@rnx-kit/console" ; import { bundle , BundleArgs as MetroBundleArgs } from "@rnx-kit/metro-service" ; import { createDirectory } from "@rnx-kit/tools-node/fs" ; import type { ConfigT } from "metro-config" ; import path from "path" ; import { customizeMetroConfig } from "../metro-config" ; import type { BundleConfig } from "./types" ; import type { TypeScriptValidationOptions } from "../types" ; param bundleConfig returns export function createMetroBundleArgs ( { entryPath : entryFile , distPath , assetsPath : assetsDest , bundlePrefix , bundleEncoding , sourceMapPath : sourcemapOutput , sourceMapSourceRootPath : sourcemapSourcesRoot , platform , dev , minify , } ) { const bundleExtension = platform === "ios" || platform === "macos" ? "jsbundle" : "bundle" ; const bundleFile = `${ bundlePrefix }.${ platform }.${ bundleExtension }` ; const bundlePath = path . join ( distPath , bundleFile ) ; if ( dev ) { sourcemapOutput = sourcemapOutput ?? bundleFile + ".map" ; } if ( sourcemapOutput ) { sourcemapOutput = path . join ( distPath , sourcemapOutput ) ; } return { assetsDest , entryFile , minify , platform , dev , bundleOutput : bundlePath , bundleEncoding , sourcemapOutput , sourcemapSourcesRoot } ; } param tsservice param metroConfig param bundleConfig export async function metroBundle ( metroConfig , bundleConfig ) { info ( `Bundling ${ bundleConfig . platform }...` ) ; const typescriptValidationOptions = { throwOnError : true } ; customizeMetroConfig ( metroConfig , bundleConfig . detectCyclicDependencies , bundleConfig . detectDuplicateDependencies , bundleConfig . typescriptValidation ? typescriptValidationOptions : false , bundleConfig . experimental_treeShake ) ; const metroBundleArgs = createMetroBundleArgs ( bundleConfig ) ; createDirectory ( path . dirname ( metroBundleArgs . bundleOutput ) ) ; metroBundleArgs . sourcemapOutput && createDirectory ( path . dirname ( metroBundleArgs . sourcemapOutput ) ) ; metroBundleArgs . assetsDest && createDirectory ( metroBundleArgs . assetsDest ) ; await bundle ( metroBundleArgs , metroConfig ) ; }