Skip to content

Commit d57ff22

Browse files
authored
[MOB-8853] Dynamic Package Path (#678)
* Pass base dir from Gradle to upload_sourcemap.sh * Use absolute module import for parseErrorStackLib * Use absolute path for iOS upload_sourcemap.sh * Pass Android rootDir to upload_sourcemap as an arg * Use `rootDir` instead of `System.getProperty('user.dir')`. * Pass the path to user's Android directory (`rootDir`) as an argument to `upload_sourcemap.sh` instead of using environment variables * Remove the check for the user's Android directory path in `upload_sourcemap.sh` as it's passed from Gradle * Get `link_bridge.js` path dynamically on linking * Fix manual linking paths * Import `package.json` from relative file path instead of a module import * Dynamically get `link.rb` file path
1 parent 750bd90 commit d57ff22

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ task upload_sourcemap(type: Exec) {
4545
commandLine 'cmd', '/c', 'echo Automatic Upload of sourcemap files is currently not available on windows, please generate the sourcemapfiles and upload them to the dashboard'
4646
project.logger.lifecycle('Automatic Upload of sourcemap files is currently not available on windows, please generate the sourcemapfiles and upload them to the dashboard')
4747
} else {
48-
commandLine 'sh', './upload_sourcemap.sh'
48+
commandLine 'sh', './upload_sourcemap.sh', rootDir
4949
}
5050
}
5151

android/upload_sourcemap.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
2-
cd ..
3-
cd ..
4-
cd ..
2+
USER_ANDROID_DIR=$1
3+
cd "${USER_ANDROID_DIR}/.."
4+
55
if [ -s "$HOME/.nvm/nvm.sh" ]; then
66
. "$HOME/.nvm/nvm.sh"
77
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then

link.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
end
1111

1212
# Replace these with your values
13+
sdk_path = File.dirname(File.realpath(__FILE__))
1314
current_path = Dir.pwd
1415
project_path = Dir.glob("#{current_path}/ios/*.xcodeproj").first
1516
file_name = File.basename(project_path, ".xcodeproj")
1617
project_location = "./ios/#{file_name}.xcodeproj"
1718
default_target_name = file_name
18-
framework_root = "../node_modules/#{package["name"]}/ios"
19+
framework_root = "#{sdk_path}/ios"
1920
framework_name = 'Instabug.xcframework'
2021

2122
INSTABUG_UPLOAD_NAME = "Upload Sourcemap"
2223

2324
INSTABUG_UPLOAD_SCRIPT = <<-SCRIPTEND
24-
bash "../node_modules/#{package["name"]}/ios/upload_sourcemap.sh"
25+
bash "#{sdk_path}/ios/upload_sourcemap.sh"
2526
SCRIPTEND
2627

2728
# Get useful variables

link_bridge.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const package = require('package.json');
1+
const package = require('./package.json');
2+
const path = require('path');
23
const exec = require('child_process').exec;
34
require('./link_gradle');
4-
exec(`ruby ./node_modules/${package.name}/link.rb || echo \"Ruby doesn't exist, if you're building this for Android only, then feel free to ignore this error, otherwise please install Ruby and run 'react-native link ${package.name}' again\"`);
5+
exec(`ruby ${path.resolve(__dirname, 'link.rb')} || echo \"Ruby doesn't exist, if you're building this for Android only, then feel free to ignore this error, otherwise please install Ruby and run 'react-native link ${package.name}' again\"`);

react-native.config.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1+
const path = require('path');
2+
13
module.exports = {
24
dependency: {
35
platforms: {
46
ios: {
57
scriptPhases: [
68
{
79
name: '[instabug-reactnative] Upload Sourcemap',
8-
script: 'bash "../node_modules/instabug-reactnative/ios/upload_sourcemap.sh"',
10+
script: `bash "${path.resolve(__dirname, 'ios/upload_sourcemap.sh')}"`,
911
execution_position: 'after_compile',
1012
},
1113
],
1214
},
13-
android: {
14-
},
15+
android: {},
1516
},
1617
hooks: {
17-
postlink: 'node node_modules/instabug-reactnative/link_bridge.js'
18+
postlink: `node ${path.resolve(__dirname, 'link_bridge.js')}`,
1819
},
1920
},
2021
commands: [
2122
{
2223
name: 'add-instabug',
2324
func: () => {
24-
require('./link_gradle');
25-
},
25+
require('./link_gradle');
26+
},
2627
},
2728
{
2829
name: 'remove-instabug',
2930
func: () => {
30-
require('./unlink_gradle');
31-
},
31+
require('./unlink_gradle');
32+
},
3233
},
3334
],
34-
};
35+
};

utils/InstabugUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NativeModules, Platform } from 'react-native';
33
let { Instabug } = NativeModules;
44
import IBGEventEmitter from './IBGEventEmitter';
55
import InstabugConstants from './InstabugConstants';
6-
import parseErrorStackLib from '../../react-native/Libraries/Core/Devtools/parseErrorStack.js';
6+
import parseErrorStackLib from 'react-native/Libraries/Core/Devtools/parseErrorStack';
77

88
export const parseErrorStack = (error) => {
99
return parseErrorStackLib(error);

0 commit comments

Comments
 (0)