From f8287e25e11d56beb66ace414ca5f8a6a32405a9 Mon Sep 17 00:00:00 2001 From: Philip Su <39933441+fivecar@users.noreply.github.com> Date: Fri, 13 Sep 2024 05:09:51 -0700 Subject: [PATCH] feat(scripts): Support multiple bundles in react-native-xcode.sh (#46339) Summary: This enables projects to have multiple bundles built during the Xcode bundling phase (e.g. for projects where you might have a PhoneScene and a CarPlayScene each with their own RootView and bundle, if you're using [react-native-carplay](https://github.com/birkir/react-native-carplay)). ## Changelog: [IOS] [ADDED] - User-configurable BUNDLE_NAME when building bundles Pull Request resolved: https://github.com/facebook/react-native/pull/46339 Test Plan: Built my project with the following Xcode "Bundle React Native code" build step: ```sh set -e export SOURCEMAP_FILE="$(pwd)/../main.jsbundle.map"; SOURCEMAP_FILE="$(pwd)/../main.jsbundle.map" WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh" REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh" /bin/sh -c "BUNDLE_NAME=main $WITH_ENVIRONMENT $REACT_NATIVE_XCODE" /bin/sh -c "BUNDLE_NAME=carplay $WITH_ENVIRONMENT $REACT_NATIVE_XCODE" ``` Then launched the app with a modified `AppDelegate.swift` which loaded main.jsbundle into one RootView and carplay.bundle into another RootView. Reviewed By: cortinico Differential Revision: D62577314 Pulled By: cipolleschi fbshipit-source-id: 22312ca144146da6c71a8533a1883e720aff1e85 --- packages/react-native/scripts/react-native-xcode.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/react-native/scripts/react-native-xcode.sh b/packages/react-native/scripts/react-native-xcode.sh index 2f37a65b17b..0c072015356 100755 --- a/packages/react-native/scripts/react-native-xcode.sh +++ b/packages/react-native/scripts/react-native-xcode.sh @@ -100,7 +100,10 @@ else CONFIG_ARG="--config $BUNDLE_CONFIG" fi -BUNDLE_FILE="$CONFIGURATION_BUILD_DIR/main.jsbundle" +if [[ -z "$BUNDLE_NAME" ]]; then + BUNDLE_NAME="main" +fi +BUNDLE_FILE="$CONFIGURATION_BUILD_DIR/$BUNDLE_NAME.jsbundle" EXTRA_ARGS=() @@ -160,7 +163,7 @@ fi if [[ $USE_HERMES == false ]]; then cp "$BUNDLE_FILE" "$DEST/" - BUNDLE_FILE="$DEST/main.jsbundle" + BUNDLE_FILE="$DEST/$BUNDLE_NAME.jsbundle" else EXTRA_COMPILER_ARGS= if [[ $DEV == true ]]; then @@ -171,14 +174,14 @@ else if [[ $EMIT_SOURCEMAP == true ]]; then EXTRA_COMPILER_ARGS="$EXTRA_COMPILER_ARGS -output-source-map" fi - "$HERMES_CLI_PATH" -emit-binary -max-diagnostic-width=80 $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE" + "$HERMES_CLI_PATH" -emit-binary -max-diagnostic-width=80 $EXTRA_COMPILER_ARGS -out "$DEST/$BUNDLE_NAME.jsbundle" "$BUNDLE_FILE" if [[ $EMIT_SOURCEMAP == true ]]; then - HBC_SOURCEMAP_FILE="$DEST/main.jsbundle.map" + HBC_SOURCEMAP_FILE="$DEST/$BUNDLE_NAME.jsbundle.map" "$NODE_BINARY" "$COMPOSE_SOURCEMAP_PATH" "$PACKAGER_SOURCEMAP_FILE" "$HBC_SOURCEMAP_FILE" -o "$SOURCEMAP_FILE" rm "$HBC_SOURCEMAP_FILE" rm "$PACKAGER_SOURCEMAP_FILE" fi - BUNDLE_FILE="$DEST/main.jsbundle" + BUNDLE_FILE="$DEST/$BUNDLE_NAME.jsbundle" fi if [[ $DEV != true && ! -f "$BUNDLE_FILE" ]]; then