Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/core/scripts/sentry-xcode-debug-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ RN_PROJECT_ROOT="${SENTRY_PROJECT_ROOT:-${PROJECT_DIR}/..}"
[ -z "$SOURCEMAP_FILE" ] && export SOURCEMAP_FILE="$DERIVED_FILE_DIR/main.jsbundle.map"

if [ -z "$SENTRY_CLI_EXECUTABLE" ]; then
# Try standard resolution safely
# Resolve from @sentry/react-native so package managers with isolated dependencies
# can find the transitive @sentry/cli dependency.
RESOLVED_PATH=$(
"$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json'))" 2>/dev/null
"$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json', { paths: [require.resolve('@sentry/react-native/package.json')] }))" 2>/dev/null
) || true
if [ -n "$RESOLVED_PATH" ]; then
SENTRY_CLI_PACKAGE_PATH="$RESOLVED_PATH/bin/sentry-cli"
Expand Down
5 changes: 3 additions & 2 deletions packages/core/scripts/sentry-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ if [[ "$SOURCEMAP_FILE" != /* ]]; then
fi

if [ -z "$SENTRY_CLI_EXECUTABLE" ]; then
# Try standard resolution safely
# Resolve from @sentry/react-native so package managers with isolated dependencies
# can find the transitive @sentry/cli dependency.
RESOLVED_PATH=$(
"$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json'))" 2>/dev/null
"$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json', { paths: [require.resolve('@sentry/react-native/package.json')] }))" 2>/dev/null
) || true
if [ -n "$RESOLVED_PATH" ]; then
SENTRY_CLI_PACKAGE_PATH="$RESOLVED_PATH/bin/sentry-cli"
Expand Down
8 changes: 7 additions & 1 deletion packages/core/sentry.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ fun resolveSentryCliPackagePath(reactRoot: File): String {
var resolvedCliPath: File? = null
try {
val process =
ProcessBuilder(listOf("node", "--print", "require.resolve('@sentry/cli/package.json')"))
ProcessBuilder(
listOf(
"node",
"--print",
"require.resolve('@sentry/cli/package.json', { paths: [require.resolve('@sentry/react-native/package.json')] })",
),
)
.directory(rootDir)
.start()
val output =
Expand Down
25 changes: 25 additions & 0 deletions packages/core/test/scripts/sentry-cli-resolution.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as fs from 'fs';
import * as path from 'path';

const CORE_DIR = path.resolve(__dirname, '../..');
const RELATIVE_SENTRY_CLI_RESOLVER =
"require.resolve('@sentry/cli/package.json', { paths: [require.resolve('@sentry/react-native/package.json')] })";

describe('sentry-cli resolution', () => {
it('resolves @sentry/cli relative to @sentry/react-native on Android', () => {
const gradleScript = fs.readFileSync(path.join(CORE_DIR, 'sentry.gradle.kts'), 'utf8');

expect(gradleScript).toContain(RELATIVE_SENTRY_CLI_RESOLVER);
});

it('resolves @sentry/cli relative to @sentry/react-native on iOS', () => {
const xcodeScript = fs.readFileSync(path.join(CORE_DIR, 'scripts', 'sentry-xcode.sh'), 'utf8');
const xcodeDebugFilesScript = fs.readFileSync(
path.join(CORE_DIR, 'scripts', 'sentry-xcode-debug-files.sh'),
'utf8',
);

expect(xcodeScript).toContain(RELATIVE_SENTRY_CLI_RESOLVER);
expect(xcodeDebugFilesScript).toContain(RELATIVE_SENTRY_CLI_RESOLVER);
});
});
Loading