Skip to content

Commit 89357c7

Browse files
authored
iOS source map support (#244)
* iOS source map support * Modify xcode project * Remove project reference * Clean up project information * Readme update * Use npx everywhere * Correct npx usage
1 parent 4e562b3 commit 89357c7

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

examples/sdk/reactNative/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ This example app shows features available in the @backtrace/react-native package
1010

1111
#### Source maps
1212

13+
Before executing any step:
14+
15+
- Please update .backtracejsrc file with your symbols submission URL and your sourcemap settings.
16+
1317
On Android: You can verify our example app with the source map support. In order to do that, please use the
1418
android-sourcemap.sh script.
1519

@@ -19,3 +23,38 @@ android-sourcemap.sh script.
1923

2024
The script will prepare a release APK version of your React Native application with the sourcemap and Hermes support.
2125
The APK can be found in the ./android/app/build/outputs/apk/release/ directory.
26+
27+
On iOS: Backtrace simplify the flow needed to upload source maps by instructing hermesc how to generate and prepare
28+
source maps for your application. Without this additional step, react-native will not instruct your application to
29+
support Backtrace source maps.
30+
31+
In order to prepare your application for source maps and automatically upload them to Backtrace, modify your "Build
32+
Phase" with the following code:
33+
34+
```bash
35+
set -e
36+
37+
# destination source map directory
38+
SOURCE_MAP_DIR="$(pwd)/../build"
39+
mkdir -p $SOURCE_MAP_DIR
40+
41+
export SOURCEMAP_FILE="$SOURCE_MAP_DIR/main.js.map";
42+
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
43+
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
44+
45+
# use hermesc script provided by Backtrace to populate source maps
46+
# if you dont use hermes support, please skip this step.
47+
export HERMES_CLI_PATH="$(pwd)/../ios-hermesc.sh"
48+
49+
/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"
50+
51+
# copy javascript build output to the build directory
52+
cp "$CONFIGURATION_BUILD_DIR/main.jsbundle" $SOURCE_MAP_DIR
53+
54+
# process source map with javascript code
55+
npx --yes @backtrace/javascript-cli run --config "$(pwd)/../.backtracejsrc" --path "$SOURCE_MAP_DIR/main.jsbundle"
56+
57+
```
58+
59+
Note: this modification copy the output of the javascript build into the build directory created in your application
60+
folder. Please also put ios-hermesc.

examples/sdk/reactNative/android-sourcemap.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ npx react-native bundle \
2626

2727

2828
# add source map identifier to final javascript bundle
29-
npx backtrace-js process --path=$BUNDLE_PATH
29+
npx --yes @backtrace/javascript-cli process --path=$BUNDLE_PATH
3030

3131
HBC_OUTPUT="$BUILD_DIR/app.hbc"
3232
HBC_MAP_OUTPUT="$HBC_OUTPUT.map"
@@ -48,7 +48,7 @@ node ./node_modules/react-native/scripts/compose-source-maps.js \
4848
-o $SOURCE_MAP_PATH
4949

5050
# upload data to Backtrace
51-
backtrace-js run $BUNDLE_PATH
51+
npx --yes @backtrace/javascript-cli run $BUNDLE_PATH
5252

5353
# prepare android application
5454
mkdir -p ./android/app/src/main/assets
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#/bin/bash
2+
3+
# This script shows how process your application code with source maps and hermesc. By using this script, Backtrace integration can process
4+
# your source code to generate valid source map files. This script does exactly the same what the hermesc script does, with one exception -
5+
# before the native library is generated, this script will process source code and source map to generate output needed in next steps for source map integration.
6+
7+
8+
HERMES_ENGINE_PATH="$PODS_ROOT/hermes-engine"
9+
[ -z "$HERMES_CLI_PATH_OVERRIDE" ] && HERMES_CLI_PATH_OVERRIDE="$HERMES_ENGINE_PATH/destroot/bin/hermesc"
10+
11+
12+
APP_BUNDLE_FILE="${BASH_ARGV[0]}"
13+
14+
if [[ ! -f "$APP_BUNDLE_FILE" ]]; then
15+
echo "error: File $APP_BUNDLE_FILE does not exist. " >&2
16+
exit 2
17+
fi
18+
19+
npx --yes @backtrace/javascript-cli process --path=$APP_BUNDLE_FILE
20+
21+
$HERMES_CLI_PATH_OVERRIDE $@

examples/sdk/reactNative/ios/reactNative.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264
);
265265
runOnlyForDeploymentPostprocessing = 0;
266266
shellPath = /bin/sh;
267-
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
267+
shellScript = "set -e\n\n# destination source map directory\nSOURCE_MAP_DIR=\"$(pwd)/../build\"\nmkdir -p $SOURCE_MAP_DIR\n\nexport SOURCEMAP_FILE=\"$SOURCE_MAP_DIR/main.js.map\";\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n# use hermesc script provided by Backtrace to populate source maps\n# if you dont use hermes support, please skip this step.\nexport HERMES_CLI_PATH=\"$(pwd)/../ios-hermesc.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n\n# copy javascript build output to the build directory\ncp \"$CONFIGURATION_BUILD_DIR/main.jsbundle\" $SOURCE_MAP_DIR \n \n# process source map with javascript code\nnpx --yes @backtrace/javascript-cli run --config \"$(pwd)/../.backtracejsrc\" --path \"$SOURCE_MAP_DIR/main.jsbundle\" \n";
268268
};
269269
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
270270
isa = PBXShellScriptBuildPhase;

0 commit comments

Comments
 (0)