Skip to content

Commit

Permalink
Merge 731af02 into 5fefdf7
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Sep 21, 2023
2 parents 5fefdf7 + 731af02 commit 6fa4f32
Show file tree
Hide file tree
Showing 18 changed files with 848 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@
!/android/**/*
!src/js/NativeRNSentry.ts
!scripts/collect-modules.sh
!scripts/copy-debugid.js
!scripts/hasSourceMapDebugId.js
!scripts/hasSourceMapDebugId.js
!scripts/sentry-xcode.sh
!scripts/sentry-xcode-debug-files.sh
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,23 @@
"@sentry/wizard": "3.13.0",
"@types/jest": "^29.5.3",
"@types/react": "^18.2.14",
"@types/uuid": "^9.0.4",
"babel-jest": "^29.6.2",
"downlevel-dts": "^0.11.0",
"eslint": "^7.6.0",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-native": "^3.8.1",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"metro": "0.76",
"prettier": "^2.0.5",
"react": "18.2.0",
"react-native": "0.72.4",
"replace-in-file": "^7.0.1",
"rimraf": "^4.1.1",
"ts-jest": "^29.1.1",
"typescript": "4.9.5"
"typescript": "4.9.5",
"uuid": "^9.0.1"
},
"rnpm": {
"commands": {},
Expand Down
2 changes: 2 additions & 0 deletions sample-new-architecture/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ project.ext.sentryCli = [
"../..",
],
skipCollectModules: false,
copyDebugIdScript: "../../../scripts/copy-debugid.js",
hasSourceMapDebugIdScript: "../../../scripts/hasSourceMapDebugId.js",
]

apply from: "../../../sentry.gradle"
Expand Down
1 change: 1 addition & 0 deletions sample-new-architecture/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
org.gradle.logging.level=lifecycle

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
8 changes: 8 additions & 0 deletions sample-new-architecture/ios/.xcode.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@
# For example, to use nvm with brew, add the following line
#. "$(brew --prefix nvm)/nvm.sh" --no-use
export NODE_BINARY=$(command -v node)

export EXTRA_COMPILER_ARGS="-w"

export SENTRY_CLI_EXECUTABLE="../../node_modules/@sentry/cli/bin/sentry-cli"
export SENTRY_CLI_EXTRA_ARGS="--force-foreground"
export SENTRY_CLI_DEBUG_FILES_UPLOAD_EXTRA_ARGS=""
export SENTRY_CLI_RN_XCODE_EXTRA_ARGS=""
export MODULES_PATHS="$PWD/../node_modules,$PWD/../../.."
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\n\nexport SENTRY_PROPERTIES=sentry.properties\nexport EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\n\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\nSENTRY_CLI=\"../../node_modules/@sentry/cli/bin/sentry-cli\"\nBUNDLE_REACT_NATIVE=\"$SENTRY_CLI react-native xcode --force-foreground $REACT_NATIVE_XCODE\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"$BUNDLE_REACT_NATIVE\\\"\"\n\nexport MODULES_PATHS=\"$PWD/../node_modules,$PWD/../../..\"\nCOLLECT_MODULES=\"../../scripts/collect-modules.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"$COLLECT_MODULES\\\"\"\n";
shellScript = "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\nBUNDLE_REACT_NATIVE=\"/bin/sh ../../scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"$BUNDLE_REACT_NATIVE\\\"\"\n";
};
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -303,7 +303,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\n\nexport SENTRY_PROPERTIES=sentry.properties\n\n[[ $SENTRY_INCLUDE_NATIVE_SOURCES == \"true\" ]] && INCLUDE_SOURCES_FLAG=\"--include-sources\" || INCLUDE_SOURCES_FLAG=\"\"\nSENTRY_CLI=\"../../node_modules/@sentry/cli/bin/sentry-cli\"\nFLAGS=\"--force-foreground $INCLUDE_SOURCES_FLAG\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"$UPLOAD_DEBUG_FILES\\\"\"\n";
shellScript = "#/bin/sh ../../scripts/sentry-xcode-debug-files.sh\n";
};
A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
9 changes: 8 additions & 1 deletion sample-new-architecture/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const path = require('path');
const blacklist = require('metro-config/src/defaults/exclusionList');

const {
createSentryMetroSerializer,
} = require('../dist/js/tools/sentryMetroSerializer');
const parentDir = path.resolve(__dirname, '..');

/**
Expand Down Expand Up @@ -41,6 +44,10 @@ const config = {
},
),
},
serializer: {
customSerializer: createSentryMetroSerializer(),
},
};

module.exports = mergeConfig(getDefaultConfig(__dirname), config);
const m = mergeConfig(getDefaultConfig(__dirname), config);
module.exports = m;
52 changes: 52 additions & 0 deletions scripts/copy-debugid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const process = require('process');
const fs = require('fs');

console.log('Copy `debugId` from packager source map to Hermes source map...');

const packagerSourceMapPath = process.argv[2];
const hermesSourceMapPath = process.argv[3];

if (!packagerSourceMapPath) {
console.log('Please provide packager source map path (A path to copy `debugId` from).');
process.exit(0);
}
if (!hermesSourceMapPath) {
console.log('Please provide Hermes source map path. ((A path to copy `debugId` to))');
process.exit(0);
}
if (!fs.existsSync(packagerSourceMapPath)) {
console.log('Packager source map path (A path to copy `debugId` from).');
process.exit(0);
}
if (!fs.existsSync(hermesSourceMapPath)) {
console.log('Hermes source map not found. ((A path to copy `debugId` to))');
process.exit(0);
}

const from = fs.readFileSync(process.argv[2], 'utf8');
const to = fs.readFileSync(process.argv[3], 'utf8');

const fromParsed = JSON.parse(from);
const toParsed = JSON.parse(to);

if (!fromParsed.debugId && !fromParsed.debug_id) {
console.log('Packager source map does not have `debugId`.');
process.exit(0);
}

if (toParsed.debugId || toParsed.debug_id) {
console.log('Hermes combined source map already has `debugId`.');
process.exit(0);
}

if (fromParsed.debugId) {
toParsed.debugId = fromParsed.debugId;
toParsed.debug_id = fromParsed.debugId;
} else if (fromParsed.debug_id) {
toParsed.debugId = fromParsed.debug_id;
toParsed.debug_id = fromParsed.debug_id;
}

fs.writeFileSync(process.argv[3], JSON.stringify(toParsed));

console.log('Done.');
31 changes: 31 additions & 0 deletions scripts/hasSourceMapDebugId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const process = require('process');
const fs = require('fs');

const sourceMapPath = process.argv[2];

if (!sourceMapPath) {
console.log('Add source map path as first argument of the script.');
process.exit(1);
}

if (!fs.existsSync(sourceMapPath)) {
console.log(`${sourceMapPath} does not exist.`);
process.exit(1);
}

let sourceMap;
try {
sourceMap = JSON.parse(fs.readFileSync(sourceMapPath, 'utf8'));
} catch (e) {
console.log(`${sourceMapPath} is not valid JSON`, e);
process.exist(1);
}

if (typeof sourceMap.debugId === 'string' && sourceMap.debugId.length > 0) {
console.log(sourceMap.debugId);
} else if (typeof sourceMap.debug_id === 'string' && sourceMap.debug_id.length > 0) {
console.log(sourceMap.debug_id);
} else {
console.log(`${sourceMapPath} does not contain 'debugId' nor 'debug_id'.`);
process.exist(1);
}
13 changes: 13 additions & 0 deletions scripts/sentry-debugid-injection-snippet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is non minified version the debug id injection snippet used in the Metro plugin.
var _sentryDebugIds = {};
var _sentryDebugIdIdentifier = '';
try {
var stack = new Error().stack;
if (stack) {
_sentryDebugIds[stack] = '__SENTRY_DEBUG_ID__';
// eslint-disable-next-line no-unused-vars
_sentryDebugIdIdentifier = 'sentry-dbid-__SENTRY_DEBUG_ID__';
}
} catch (e) {
/**/
}
21 changes: 21 additions & 0 deletions scripts/sentry-xcode-debug-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Upload Debug Symbols to Sentry Xcode Build Phase
# PWD=ios

# print commands before executing them and stop on first error
set -x -e

# load envs if loader file exists (since rn 0.68)
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
if [ -f "$WITH_ENVIRONMENT" ]; then
. "$WITH_ENVIRONMENT"
fi

[ -z "$SENTRY_PROPERTIES" ] && export SENTRY_PROPERTIES=sentry.properties
[ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_EXECUTABLE="../node_modules/@sentry/cli/bin/sentry-cli"

[[ $SENTRY_INCLUDE_NATIVE_SOURCES == "true" ]] && INCLUDE_SOURCES_FLAG="--include-sources" || INCLUDE_SOURCES_FLAG=""

EXTRA_ARGS="$SENTRY_CLI_EXTRA_ARGS $SENTRY_CLI_DEBUG_FILES_UPLOAD_EXTRA_ARGS $INCLUDE_SOURCES_FLAG"

UPLOAD_DEBUG_FILES="\"$SENTRY_CLI_EXECUTABLE\" debug-files upload $EXTRA_ARGS \"$DWARF_DSYM_FOLDER_PATH\""
/bin/sh -c "$UPLOAD_DEBUG_FILES"
23 changes: 23 additions & 0 deletions scripts/sentry-xcode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Sentry Bundle React Native code and images
# PWD=ios

# print commands before executing them and stop on first error
set -x -e

# WITH_ENVIRONMENT is executed by React Native

[ -z "$SENTRY_PROPERTIES" ] && export SENTRY_PROPERTIES=sentry.properties
[ -z "$EXTRA_PACKAGER_ARGS" ] && export EXTRA_PACKAGER_ARGS="--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map"
[ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_EXECUTABLE="../node_modules/@sentry/cli/bin/sentry-cli"

REACT_NATIVE_XCODE=$1

BUNDLE_REACT_NATIVE="\"$SENTRY_CLI_EXECUTABLE\" react-native xcode $SENTRY_CLI_EXTRA_ARGS $SENTRY_CLI_RN_XCODE_EXTRA_ARGS \"$REACT_NATIVE_XCODE\""

/bin/sh -c "$BUNDLE_REACT_NATIVE"

[ -z "$SENTRY_COLLECT_MODULES" ] && SENTRY_COLLECT_MODULES="../../scripts/collect-modules.sh"

if [ -f "$SENTRY_COLLECT_MODULES" ]; then
/bin/sh "$SENTRY_COLLECT_MODULES"
fi
Loading

0 comments on commit 6fa4f32

Please # to comment.