diff --git a/packages/react-native-cli/src/lib/Xcode.ts b/packages/react-native-cli/src/lib/Xcode.ts index c9dec0e463..359d9e98bb 100644 --- a/packages/react-native-cli/src/lib/Xcode.ts +++ b/packages/react-native-cli/src/lib/Xcode.ts @@ -7,11 +7,11 @@ const DOCS_LINK = 'https://docs.bugsnag.com/platforms/react-native/react-native/ const UNLOCATED_PROJ_MSG = `The Xcode project was not in the expected location and so couldn't be updated automatically. Update the "Bundle React Native Code And Images" build phase with the following environment variables: -export EXTRA_PACKAGER_ARGS="--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map" +export EXTRA_PACKAGER_ARGS="--sourcemap-output $TMPDIR/$(md5 -qs "$CONFIGURATION_BUILD_DIR")-main.jsbundle.map"" See ${DOCS_LINK} for more information` -const EXTRA_PACKAGER_ARGS = 'export EXTRA_PACKAGER_ARGS="--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map"' +const EXTRA_PACKAGER_ARGS = 'export EXTRA_PACKAGER_ARGS="--sourcemap-output $TMPDIR/$(md5 -qs "$CONFIGURATION_BUILD_DIR")-main.jsbundle.map"' export async function updateXcodeProject (projectRoot: string, endpoint: string|undefined, logger: Logger) { const iosDir = path.join(projectRoot, 'ios') @@ -76,7 +76,7 @@ async function addUploadSourceMapsTask ( } } - let shellScript = '../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh' + let shellScript = 'SOURCE_MAP="$TMPDIR/$(md5 -qs "$CONFIGURATION_BUILD_DIR")-main.jsbundle.map" ../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh' if (endpoint) { shellScript = `export ENDPOINT='${endpoint}'\\n${shellScript}` diff --git a/packages/react-native-cli/src/lib/__test__/fixtures/project-after-with-endpoint.pbxproj b/packages/react-native-cli/src/lib/__test__/fixtures/project-after-with-endpoint.pbxproj index 564b7cdb16..93265ba4a0 100644 --- a/packages/react-native-cli/src/lib/__test__/fixtures/project-after-with-endpoint.pbxproj +++ b/packages/react-native-cli/src/lib/__test__/fixtures/project-after-with-endpoint.pbxproj @@ -376,7 +376,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; + shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; }; 2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = { isa = PBXShellScriptBuildPhase; @@ -390,7 +390,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; + shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; }; 3EBDF05F265B984FA826288C /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; @@ -566,7 +566,7 @@ outputPaths = ( ); shellPath = /bin/sh; - shellScript = "export ENDPOINT='https://upload.example.com'\n../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh"; + shellScript = "export ENDPOINT='https://upload.example.com'\nSOURCE_MAP=\"$TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\" ../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/packages/react-native-cli/src/lib/__test__/fixtures/project-after.pbxproj b/packages/react-native-cli/src/lib/__test__/fixtures/project-after.pbxproj index a0944830c6..8b440d1aa7 100644 --- a/packages/react-native-cli/src/lib/__test__/fixtures/project-after.pbxproj +++ b/packages/react-native-cli/src/lib/__test__/fixtures/project-after.pbxproj @@ -376,7 +376,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; + shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; }; 2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = { isa = PBXShellScriptBuildPhase; @@ -390,7 +390,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; + shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; }; 3EBDF05F265B984FA826288C /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; @@ -566,7 +566,7 @@ outputPaths = ( ); shellPath = /bin/sh; - shellScript = "../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh"; + shellScript = "SOURCE_MAP=\"$TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\" ../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/packages/react-native/bugsnag-react-native-xcode.sh b/packages/react-native/bugsnag-react-native-xcode.sh index e70f522ebb..1bf50d08ab 100755 --- a/packages/react-native/bugsnag-react-native-xcode.sh +++ b/packages/react-native/bugsnag-react-native-xcode.sh @@ -23,9 +23,12 @@ if [ ! -f "$BUNDLE_FILE" ]; then exit 0 fi -MAP_FILE="$BUNDLE_FILE.map" -if [ ! -f "$MAP_FILE" ]; then - echo "Error: Source map main.jsbundle.map could not be found." +if [ -z "$SOURCE_MAP" ]; then + echo "Warning: SOURCE_MAP was not specified, falling back to $BUNDLE_FILE.map" + SOURCE_MAP="$BUNDLE_FILE.map" +fi +if [ ! -f "$SOURCE_MAP" ]; then + echo "Error: SOURCE_MAP $SOURCE_MAP could not be found." echo "Ensure the --sourcemap-output option is passed to the react-native bundle command." exit 1 fi @@ -39,7 +42,7 @@ ARGS=( "--app-version" "$APP_VERSION" "--bundle" "$BUNDLE_FILE" "--platform" "ios" - "--source-map" "$MAP_FILE" + "--source-map" "$SOURCE_MAP" "--project-root" "$PROJECT_ROOT" ) diff --git a/test/react-native-cli/features/fixtures/rn0_60/check-ios-build-script.sh b/test/react-native-cli/features/fixtures/rn0_60/check-ios-build-script.sh index 94b2280f41..ee54e673df 100755 --- a/test/react-native-cli/features/fixtures/rn0_60/check-ios-build-script.sh +++ b/test/react-native-cli/features/fixtures/rn0_60/check-ios-build-script.sh @@ -6,7 +6,7 @@ set -ex -fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"' ios/rn0_60.xcodeproj/project.pbxproj +fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"' ios/rn0_60.xcodeproj/project.pbxproj if [ ! -z "$1" ]; then fgrep "export ENDPOINT='$1'" ios/rn0_60.xcodeproj/project.pbxproj diff --git a/test/react-native-cli/features/fixtures/rn0_61/check-ios-build-script.sh b/test/react-native-cli/features/fixtures/rn0_61/check-ios-build-script.sh index 11e1cc71c3..ec75dcc6de 100755 --- a/test/react-native-cli/features/fixtures/rn0_61/check-ios-build-script.sh +++ b/test/react-native-cli/features/fixtures/rn0_61/check-ios-build-script.sh @@ -6,7 +6,7 @@ set -ex -fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"' ios/rn0_61.xcodeproj/project.pbxproj +fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"' ios/rn0_61.xcodeproj/project.pbxproj if [ ! -z "$1" ]; then fgrep "export ENDPOINT='$1'" ios/rn0_61.xcodeproj/project.pbxproj diff --git a/test/react-native-cli/features/fixtures/rn0_62/check-ios-build-script.sh b/test/react-native-cli/features/fixtures/rn0_62/check-ios-build-script.sh index 5973a2aa4e..d65384981a 100755 --- a/test/react-native-cli/features/fixtures/rn0_62/check-ios-build-script.sh +++ b/test/react-native-cli/features/fixtures/rn0_62/check-ios-build-script.sh @@ -6,7 +6,7 @@ set -ex -fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"' ios/rn0_62.xcodeproj/project.pbxproj +fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"' ios/rn0_62.xcodeproj/project.pbxproj if [ ! -z "$1" ]; then fgrep "export ENDPOINT='$1'" ios/rn0_62.xcodeproj/project.pbxproj diff --git a/test/react-native-cli/features/fixtures/rn0_63/check-ios-build-script.sh b/test/react-native-cli/features/fixtures/rn0_63/check-ios-build-script.sh index 5b6d9aa069..d5ea6682f8 100755 --- a/test/react-native-cli/features/fixtures/rn0_63/check-ios-build-script.sh +++ b/test/react-native-cli/features/fixtures/rn0_63/check-ios-build-script.sh @@ -6,7 +6,7 @@ set -ex -fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"' ios/rn0_63.xcodeproj/project.pbxproj +fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"' ios/rn0_63.xcodeproj/project.pbxproj if [ ! -z "$1" ]; then fgrep "export ENDPOINT='$1'" ios/rn0_63.xcodeproj/project.pbxproj diff --git a/test/react-native-cli/features/steps/steps.rb b/test/react-native-cli/features/steps/steps.rb index 64fc6a438e..4233920a73 100644 --- a/test/react-native-cli/features/steps/steps.rb +++ b/test/react-native-cli/features/steps/steps.rb @@ -114,7 +114,7 @@ def parse_package_json Then("the iOS build has not been modified to upload source maps") do filename = "ios/#{current_fixture}.xcodeproj/project.pbxproj" - step("the interactive file '#{filename}' does not contain 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"'") + step("the interactive file '#{filename}' does not contain 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"'") step("the interactive file '#{filename}' does not contain 'Upload source maps to Bugsnag'") end