Skip to content

Commit 74a2297

Browse files
TheBuggedYRNHeshamMegid
authored andcommitted
[MOB-11999] Use RN Internal Sourcemap Script (#942)
1 parent 3a3d932 commit 74a2297

File tree

6 files changed

+82
-108
lines changed

6 files changed

+82
-108
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
command: ls scripts/*.sh | xargs bash -n
8383
- run:
8484
name: Validate iOS Script
85-
command: bash -n ios/upload_sourcemap.sh
85+
command: bash -n ios/sourcemaps.sh
8686

8787
# Make sure that files like yarn.lock and project.pbxproj
8888
# are in sync with the latest changes in package.json and

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Changed
1010

1111
- Improve release variant's build time on Android, by using the react-native-generated source map file, instead of generating it within our scripts ([#938](https://github.com/Instabug/Instabug-React-Native/pull/938)).
12+
- Improve debug variant's build time on iOS, by disabling automatic source map file uploads ([#942](https://github.com/Instabug/Instabug-React-Native/pull/942)).
1213

1314
## [11.9.1](https://github.com/Instabug/Instabug-React-Native/compare/v11.9.0...v11.9.1) (March 01, 2023)
1415

examples/default/ios/InstabugExample.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@
401401
name = "[CP-User] [instabug-reactnative] Upload Sourcemap";
402402
runOnlyForDeploymentPostprocessing = 0;
403403
shellPath = /bin/sh;
404-
shellScript = "#!/bin/sh\ncd ${PROJECT_DIR}\ncd ..\nif [ -s \"$HOME/.nvm/nvm.sh\" ]; then\n. \"$HOME/.nvm/nvm.sh\"\nelif [ -x \"$(command -v brew)\" ] && [ -s \"$(brew --prefix nvm)/nvm.sh\" ]; then\n. \"$(brew --prefix nvm)/nvm.sh\"\nfi\nexport NODE_BINARY=node\n\nINSTABUG_SOURCEMAPS_UPLOAD_DISABLE=$(echo $INSTABUG_SOURCEMAPS_UPLOAD_DISABLE | tr 'A-Z' 'a-z')\nif [ \"${INSTABUG_SOURCEMAPS_UPLOAD_DISABLE}\" = \"true\" ]; then\n echo \"Instabug: Environment variable INSTABUG_SOURCEMAPS_UPLOAD_DISABLE was set to true, skipping sourcemap upload\"\n exit 0\nfi\n\nif [ ! \"$INFOPLIST_FILE\" ] || [ -z \"$INFOPLIST_FILE\" ]; then\n echo \"Instabug: INFOPLIST_FILE not found in Xcode build settings, skipping sourcemap upload\"\n exit 0\nfi\n\nif [ ! \"${PROJECT_DIR}\" ] || [ -z \"${PROJECT_DIR}\" ]; then\n echo \"Instabug: PROJECT_DIR not found in Xcode build settings, skipping sourcemap upload\"\n exit 0\nfi\n\nPLIST_ABS_PATH=\"$PROJECT_DIR/$INFOPLIST_FILE\"\necho \"Instabug: PLIST_ABS_PATH: $PLIST_ABS_PATH\"\n\nif [ ! \"${INSTABUG_APP_TOKEN}\" ] || [ -z \"${INSTABUG_APP_TOKEN}\" ]; then\n echo \"Instabug: Looking for Token...\"\n INSTABUG_APP_TOKEN=$(grep -r -A 6 --exclude-dir={node_modules,ios,android} --exclude='*.json' \"Instabug.init({\" ./ -m1 | grep \"token:[[:space:]]*[\\\"\\'][0-9a-zA-Z]*[\\\"\\']\" | grep -o \"[\\\"\\'][0-9a-zA-Z]*[\\\"\\']\" | cut -d \"\\\"\" -f 2 | cut -d \"'\" -f 2)\n if [ -z \"${INSTABUG_APP_TOKEN}\" ]; then\n INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} --exclude='*.json' \"Instabug.start[WithToken]*([\\\"\\'][0-9a-zA-Z]*[\\\"\\']\" ./ -m 1 | grep -o \"[\\\"\\'][0-9a-zA-Z]*[\\\"\\']\" | cut -d \"\\\"\" -f 2 | cut -d \"'\" -f 2)\n fi\nfi\n\nif [ ! \"${INSTABUG_APP_TOKEN}\" ] || [ -z \"${INSTABUG_APP_TOKEN}\" ]; then\n echo \"Instabug: INSTABUG_APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.init Or added the environment variable INSTABUG_APP_TOKEN\"\n exit 0\nelse\n if [ ! \"${INSTABUG_APP_VERSION_CODE}\" ] || [ -z \"${INSTABUG_APP_VERSION_CODE}\" ]; then\n INSTABUG_APP_VERSION_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' ${PLIST_ABS_PATH} )\n if [ ! \"${INSTABUG_APP_VERSION_CODE}\" ] || [ -z \"${INSTABUG_APP_VERSION_CODE}\" ]; then\n echo \"CFBundleVersion could not be found, please upload the sourcemap files manually\"\n exit 0\n fi\n INSTABUG_APP_VERSION_CODE_ENV=$(grep -o '$(.*)' <<< $INSTABUG_APP_VERSION_CODE | cut -d \"(\" -f2 | cut -d \")\" -f1)\n if !([ ! \"${INSTABUG_APP_VERSION_CODE_ENV}\" ] || [ -z \"${INSTABUG_APP_VERSION_CODE_ENV}\" ]); then\n INSTABUG_APP_VERSION_CODE=${!INSTABUG_APP_VERSION_CODE_ENV}\n if [ ! \"${INSTABUG_APP_VERSION_CODE}\" ] || [ -z \"${INSTABUG_APP_VERSION_CODE}\" ]; then\n echo \"Environment variable $INSTABUG_APP_VERSION_CODE_ENV was specified inside Info.plist but was not found, please upload the sourcemap files manually\" \n exit 0\n fi\n fi\n fi\n if [ ! \"${INSTABUG_APP_VERSION_NAME}\" ] || [ -z \"${INSTABUG_APP_VERSION_NAME}\" ]; then\n INSTABUG_APP_VERSION_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' ${PLIST_ABS_PATH} )\n if [ ! \"${INSTABUG_APP_VERSION_NAME}\" ] || [ -z \"${INSTABUG_APP_VERSION_NAME}\" ]; then\n echo \"CFBundleShortVersionString could not be found, please upload the sourcemap files manually\"\n exit 0\n fi\n INSTABUG_APP_VERSION_NAME_ENV=$(grep -o '$(.*)' <<< $INSTABUG_APP_VERSION_NAME | cut -d \"(\" -f2 | cut -d \")\" -f1)\n if !([ ! \"${INSTABUG_APP_VERSION_NAME_ENV}\" ] || [ -z \"${INSTABUG_APP_VERSION_NAME_ENV}\" ]); then\n INSTABUG_APP_VERSION_NAME=${!INSTABUG_APP_VERSION_NAME_ENV}\n if [ ! \"${INSTABUG_APP_VERSION_NAME}\" ] || [ -z \"${INSTABUG_APP_VERSION_NAME}\" ]; then\n echo \"Environment variable $INSTABUG_APP_VERSION_NAME_ENV was specified inside Info.plist but was not found, please upload the sourcemap files manually\" \n exit 0\n fi\n fi\n fi\n if [ -z \"${INSTABUG_ENTRY_FILE}\" ]; then \n ENTRY_FILE='index.js'\n else \n ENTRY_FILE=${INSTABUG_ENTRY_FILE}\n fi\n if [ ! -f $ENTRY_FILE ]; then\n echo \"Instabug: err: entry file not found. Make sure\" \"\\\"${ENTRY_FILE}\\\"\" \"exists in your projects root directory. Or add the environment variable INSTABUG_ENTRY_FILE with the name of your entry file\"\n exit 0\n fi\n VERSION='{\"code\":\"'\"$INSTABUG_APP_VERSION_CODE\"'\",\"name\":\"'\"$INSTABUG_APP_VERSION_NAME\"'\"}'\n echo \"Instabug: Token:\" \"\\\"\"${INSTABUG_APP_TOKEN}\"\\\"\"\n echo \"Instabug: VERSION: $VERSION\"\n echo \"Instabug: Entry file found\" \"\\\"\"${ENTRY_FILE}\"\\\"\"\n echo \"Instabug: Generating sourcemap files...\"\n HERMES_ENABLED=$(grep hermes-engine ./ios/Podfile.lock -m 1)\n INSTALLED_RN_VERSION_MAJOR=$(node -p \"require('react-native/package.json').version\" | cut -d \".\" -f2)\n if [[ ! -z \"$HERMES_ENABLED\" && \"$INSTALLED_RN_VERSION_MAJOR\" -ge 65 && \"$INSTALLED_RN_VERSION_MAJOR\" -lt 70 ]]; then\n EXTRA_ARGS=\"--minify false\"\n fi\n #Generate ios sourcemap\n npx react-native bundle --platform ios \\\n --reset-cache \\\n --entry-file $ENTRY_FILE \\\n --dev false \\\n --bundle-output ./ios/main.jsbundle \\\n --sourcemap-output ./ios-sourcemap.json \\\n $EXTRA_ARGS\n \n echo \"Instabug: Uploading files...\"\n #Upload ios sourcemap\n curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F \"app_version=${VERSION}\" -F \"symbols_file=@./ios-sourcemap.json\" -F \"application_token=${INSTABUG_APP_TOKEN}\" -F \"platform=react_native\" -F \"os=ios\" \n rm -rf ios-sourcemap.json\n echo \nfi\n";
404+
shellScript = "#!/bin/sh\n\nmain() {\n if [[ \"$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\" = true ]]; then\n echo \"[Info] \\`INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\\` was set to true, skipping sourcemaps upload...\"\n exit 0\n fi\n\n if [[ -z \"$INFOPLIST_FILE\" ]] || [[ -z \"$PROJECT_DIR\" ]]; then\n echo \"[Error] Instabug sourcemaps script must be invoked by Xcode\"\n exit 1\n fi\n\n local source_map_file=$(generate_sourcemaps | tail -n 1)\n\n local js_project_dir=\"$PROJECT_DIR/..\"\n local instabug_dir=$(dirname $(node -p \"require.resolve('instabug-reactnative/package.json')\"))\n local inferred_token=$(cd $js_project_dir && source $instabug_dir/scripts/find-token.sh)\n local app_token=$(resolve_var \"App Token\" \"INSTABUG_APP_TOKEN\" \"$inferred_token\" | tail -n 1)\n\n local inferred_name=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' \"$PROJECT_DIR/$INFOPLIST_FILE\")\n local version_name=$(resolve_var \"Version Name\" \"INSTABUG_APP_VERSION_NAME\" \"$inferred_name\" | tail -n 1)\n\n local inferred_code=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' \"$PROJECT_DIR/$INFOPLIST_FILE\")\n local version_code=$(resolve_var \"Version Code\" \"INSTABUG_APP_VERSION_CODE\" \"$inferred_code\" | tail -n 1)\n\n npx instabug upload-sourcemaps \\\n --platform ios \\\n --file $source_map_file \\\n --token $app_token \\\n --name $version_name \\\n --code $version_code\n}\n\ngenerate_sourcemaps() {\n local react_native_dir=$(dirname $(node -p \"require.resolve('react-native/package.json')\"))\n\n # Fixes an issue with react-native prior to v0.67.0\n # For more info: https://github.com/facebook/react-native/issues/32168\n export RN_DIR=$react_native_dir \n\n # Used withing `react-native-xcode.sh` to generate sourcemap file\n export SOURCEMAP_FILE=\"$(pwd)/main.jsbundle.map\";\n\n source \"$react_native_dir/scripts/react-native-xcode.sh\"\n\n if [[ ! -f \"$SOURCEMAP_FILE\" ]]; then\n echo \"[Error] Unable to find source map file at: $SOURCEMAP_FILE\"\n exit 1\n fi\n\n echo $SOURCEMAP_FILE\n}\n\nresolve_var() {\n local name=$1\n local env_key=$2\n local default_value=$3\n\n local env_value=\"${!env_key}\"\n\n if [[ -n \"$env_value\" ]] && [[ \"$env_value\" != default_value ]]; then\n echo \"[Warning] Environment variable \\`$env_key\\` might have incorrect value, make sure this was intentional:\"\n echo \" Environment Value: $env_value\"\n echo \" Default Value: $default_value\"\n fi\n\n local value=\"${env_value:-$default_value}\"\n\n if [[ -z \"$value\" ]]; then\n echo \"[Error] Unable to find $name! Set the environment variable \\`$env_key\\` and try again.\"\n exit 1\n fi\n\n echo $value\n}\n\nmain \"$@\"; exit\n";
405405
};
406406
DD1AA4DBFEAB75A854826F0C /* [CP] Embed Pods Frameworks */ = {
407407
isa = PBXShellScriptBuildPhase;

ios/sourcemaps.sh

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/sh
2+
3+
main() {
4+
if [[ "$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE" = true ]]; then
5+
echo "[Info] \`INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\` was set to true, skipping sourcemaps upload..."
6+
exit 0
7+
fi
8+
9+
if [[ -z "$INFOPLIST_FILE" ]] || [[ -z "$PROJECT_DIR" ]]; then
10+
echo "[Error] Instabug sourcemaps script must be invoked by Xcode"
11+
exit 1
12+
fi
13+
14+
local source_map_file=$(generate_sourcemaps | tail -n 1)
15+
16+
local js_project_dir="$PROJECT_DIR/.."
17+
local instabug_dir=$(dirname $(node -p "require.resolve('instabug-reactnative/package.json')"))
18+
local inferred_token=$(cd $js_project_dir && source $instabug_dir/scripts/find-token.sh)
19+
local app_token=$(resolve_var "App Token" "INSTABUG_APP_TOKEN" "$inferred_token" | tail -n 1)
20+
21+
local inferred_name=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' "$PROJECT_DIR/$INFOPLIST_FILE")
22+
local version_name=$(resolve_var "Version Name" "INSTABUG_APP_VERSION_NAME" "$inferred_name" | tail -n 1)
23+
24+
local inferred_code=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' "$PROJECT_DIR/$INFOPLIST_FILE")
25+
local version_code=$(resolve_var "Version Code" "INSTABUG_APP_VERSION_CODE" "$inferred_code" | tail -n 1)
26+
27+
npx instabug upload-sourcemaps \
28+
--platform ios \
29+
--file $source_map_file \
30+
--token $app_token \
31+
--name $version_name \
32+
--code $version_code
33+
}
34+
35+
generate_sourcemaps() {
36+
local react_native_dir=$(dirname $(node -p "require.resolve('react-native/package.json')"))
37+
38+
# Fixes an issue with react-native prior to v0.67.0
39+
# For more info: https://github.com/facebook/react-native/issues/32168
40+
export RN_DIR=$react_native_dir
41+
42+
# Used withing `react-native-xcode.sh` to generate sourcemap file
43+
export SOURCEMAP_FILE="$(pwd)/main.jsbundle.map";
44+
45+
source "$react_native_dir/scripts/react-native-xcode.sh"
46+
47+
if [[ ! -f "$SOURCEMAP_FILE" ]]; then
48+
echo "[Error] Unable to find source map file at: $SOURCEMAP_FILE"
49+
exit 1
50+
fi
51+
52+
echo $SOURCEMAP_FILE
53+
}
54+
55+
resolve_var() {
56+
local name=$1
57+
local env_key=$2
58+
local default_value=$3
59+
60+
local env_value="${!env_key}"
61+
62+
if [[ -n "$env_value" ]] && [[ "$env_value" != default_value ]]; then
63+
echo "[Warning] Environment variable \`$env_key\` might have incorrect value, make sure this was intentional:"
64+
echo " Environment Value: $env_value"
65+
echo " Default Value: $default_value"
66+
fi
67+
68+
local value="${env_value:-$default_value}"
69+
70+
if [[ -z "$value" ]]; then
71+
echo "[Error] Unable to find $name! Set the environment variable \`$env_key\` and try again."
72+
exit 1
73+
fi
74+
75+
echo $value
76+
}
77+
78+
main "$@"; exit

ios/upload_sourcemap.sh

-105
This file was deleted.

react-native.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
scriptPhases: [
66
{
77
name: '[instabug-reactnative] Upload Sourcemap',
8-
path: './ios/upload_sourcemap.sh',
8+
path: './ios/sourcemaps.sh',
99
execution_position: 'after_compile',
1010
},
1111
],

0 commit comments

Comments
 (0)