Skip to content
Open
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
38 changes: 38 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,38 @@
import * as fs from 'fs';
import * as path from 'path';

const CORE_DIR = path.resolve(__dirname, '../..');
const EXPO_UPLOAD_SOURCEMAPS_DIR = path.resolve(CORE_DIR, '../expo-upload-sourcemaps');
const RELATIVE_SENTRY_CLI_RESOLVER =
"require.resolve('@sentry/cli/package.json', { paths: [require.resolve('@sentry/react-native/package.json')] })";
const RELATIVE_EXPO_UPLOAD_SOURCEMAPS_CLI_RESOLVER_PATH =
"paths: [require.resolve('@sentry/expo-upload-sourcemaps/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);
});

it('resolves @sentry/cli relative to @sentry/expo-upload-sourcemaps in the Expo uploader', () => {
const expoUploadSourcemapsScript = fs.readFileSync(
path.join(EXPO_UPLOAD_SOURCEMAPS_DIR, 'cli.js'),
'utf8',
);
Comment on lines +30 to +33
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should make the linter happy

Suggested change
const expoUploadSourcemapsScript = fs.readFileSync(
path.join(EXPO_UPLOAD_SOURCEMAPS_DIR, 'cli.js'),
'utf8',
);
const expoUploadSourcemapsScript = fs.readFileSync(path.join(EXPO_UPLOAD_SOURCEMAPS_DIR, 'cli.js'), 'utf8');


expect(expoUploadSourcemapsScript).toContain("require.resolve('@sentry/cli/bin/sentry-cli'");
expect(expoUploadSourcemapsScript).toContain(RELATIVE_EXPO_UPLOAD_SOURCEMAPS_CLI_RESOLVER_PATH);
});
});
6 changes: 5 additions & 1 deletion packages/expo-upload-sourcemaps/cli.js
100755 → 100644
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The executable bit was removed from this file. I think we need to restore 755

Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ let sentryOrg = getEnvVar(SENTRY_ORG);
let sentryUrl = getEnvVar(SENTRY_URL);
let sentryProject = getEnvVar(SENTRY_PROJECT);
let authToken = getEnvVar(SENTRY_AUTH_TOKEN);
const sentryCliBin = getEnvVar(SENTRY_CLI_EXECUTABLE) || require.resolve('@sentry/cli/bin/sentry-cli');
const sentryCliBin =
getEnvVar(SENTRY_CLI_EXECUTABLE) ||
require.resolve('@sentry/cli/bin/sentry-cli', {
paths: [require.resolve('@sentry/expo-upload-sourcemaps/package.json')],
});

if (!sentryOrg || !sentryProject || !sentryUrl) {
console.log('🐕 Fetching from expo config...');
Expand Down
Loading