From 0cdfb2e65fddae65705203cb0b1f094104874191 Mon Sep 17 00:00:00 2001 From: Shawn Thye Date: Mon, 1 Jun 2026 23:28:57 +0800 Subject: [PATCH] fix: resolve sentry cli from react native package --- .../core/scripts/sentry-xcode-debug-files.sh | 5 ++-- packages/core/scripts/sentry-xcode.sh | 5 ++-- packages/core/sentry.gradle.kts | 8 +++++- .../scripts/sentry-cli-resolution.test.ts | 25 +++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 packages/core/test/scripts/sentry-cli-resolution.test.ts diff --git a/packages/core/scripts/sentry-xcode-debug-files.sh b/packages/core/scripts/sentry-xcode-debug-files.sh index fe65325aa6..d05f2012c6 100755 --- a/packages/core/scripts/sentry-xcode-debug-files.sh +++ b/packages/core/scripts/sentry-xcode-debug-files.sh @@ -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" diff --git a/packages/core/scripts/sentry-xcode.sh b/packages/core/scripts/sentry-xcode.sh index 229ac90bb2..aa4ead6225 100755 --- a/packages/core/scripts/sentry-xcode.sh +++ b/packages/core/scripts/sentry-xcode.sh @@ -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" diff --git a/packages/core/sentry.gradle.kts b/packages/core/sentry.gradle.kts index 9c813c7cfb..51163f97a5 100644 --- a/packages/core/sentry.gradle.kts +++ b/packages/core/sentry.gradle.kts @@ -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 = diff --git a/packages/core/test/scripts/sentry-cli-resolution.test.ts b/packages/core/test/scripts/sentry-cli-resolution.test.ts new file mode 100644 index 0000000000..53a3ad57f3 --- /dev/null +++ b/packages/core/test/scripts/sentry-cli-resolution.test.ts @@ -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); + }); +});