Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

### Fixes

- Fix the iOS Release build failing in hoisted monorepos because `sentry-xcode.sh` looked for React Native in `../node_modules` ([#7182](https://github.com/getsentry/sentry-react-native/pull/7182))
- Keep the original exception as the main one when it has linked errors, so the `cause` no longer becomes the issue title ([#7179](https://github.com/getsentry/sentry-react-native/pull/7179))
- Errors with a linked cause may group into new issues after upgrading

Expand Down
10 changes: 9 additions & 1 deletion packages/core/scripts/sentry-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ $SENTRY_CLI_ENV
SENTRY_CLI_ENV_EOF
set -x

REACT_NATIVE_XCODE_DEFAULT="../node_modules/react-native/scripts/react-native-xcode.sh"
# React Native's bundle phase runs this script without an argument when REACT_NATIVE_XCODE points at it.
# Prefer the script in REACT_NATIVE_PATH, the build setting React Native's CocoaPods setup writes (0.69+),
# so hoisted monorepos, where react-native is not in ../node_modules, find it. Only use it if the script
# exists there. See https://github.com/getsentry/sentry-react-native/issues/7175
if [ -n "$REACT_NATIVE_PATH" ] && [ -f "$REACT_NATIVE_PATH/scripts/react-native-xcode.sh" ]; then
REACT_NATIVE_XCODE_DEFAULT="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh"
else
REACT_NATIVE_XCODE_DEFAULT="../node_modules/react-native/scripts/react-native-xcode.sh"
fi
REACT_NATIVE_XCODE="${1:-$REACT_NATIVE_XCODE_DEFAULT}"

[[ "$AUTO_RELEASE" == false ]] && [[ -z "$BUNDLE_COMMAND" || "$BUNDLE_COMMAND" != "ram-bundle" ]] && NO_AUTO_RELEASE="--no-auto-release"
Expand Down
107 changes: 107 additions & 0 deletions packages/core/test/scripts/sentry-xcode-scripts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,113 @@ describe('sentry-xcode.sh', () => {
expect(args.slice(-2)).toEqual(['--build-script', mockReactNativeScript]);
});

describe('React Native script resolution without an argument (issue #7175)', () => {
// React Native's bundle phase runs `$WITH_ENVIRONMENT $REACT_NATIVE_XCODE`, so when
// REACT_NATIVE_XCODE points at sentry-xcode.sh the script gets no argument.
const writeRnScript = (dir: string, message: string): string => {
const scriptsDir = path.join(dir, 'scripts');
fs.mkdirSync(scriptsDir, { recursive: true });
const script = path.join(scriptsDir, 'react-native-xcode.sh');
fs.writeFileSync(script, `#!/bin/bash\necho "${message}"\nexit 0\n`);
fs.chmodSync(script, '755');
return script;
};

const runWithoutArg = (cwd: string, env: Record<string, string> = {}) => {
const mockCollectModulesScript = path.join(tempDir, 'collect-modules.sh');
fs.writeFileSync(mockCollectModulesScript, '#!/bin/bash\nexit 0\n');
fs.chmodSync(mockCollectModulesScript, '755');
const childEnv: Record<string, string | undefined> = {
...process.env,
NODE_BINARY: process.execPath,
SENTRY_CLI_EXECUTABLE: mockSentryCliScript,
PROJECT_DIR: cwd,
DERIVED_FILE_DIR: tempDir,
SENTRY_COLLECT_MODULES: mockCollectModulesScript,
SENTRY_DISABLE_AUTO_UPLOAD: 'true',
...env,
};
if (!('REACT_NATIVE_PATH' in env)) {
delete childEnv.REACT_NATIVE_PATH;
}
const result = spawnSync('bash', [XCODE_SCRIPT], { cwd, env: childEnv, encoding: 'utf8' });
return { stdout: result.stdout, stderr: result.stderr, exitCode: result.status };
};

// Hoisted monorepo: <root>/node_modules/react-native, app in <root>/apps/mobile/ios.
const makeHoistedMonorepo = () => {
const root = path.join(tempDir, 'monorepo');
const iosDir = path.join(root, 'apps', 'mobile', 'ios');
fs.mkdirSync(iosDir, { recursive: true });
const reactNativePath = path.join(root, 'node_modules', 'react-native');
writeRnScript(reactNativePath, 'Hoisted React Native bundle');
return { iosDir, reactNativePath };
};

it('runs the script from REACT_NATIVE_PATH in a hoisted monorepo', () => {
const { iosDir, reactNativePath } = makeHoistedMonorepo();

const result = runWithoutArg(iosDir, { REACT_NATIVE_PATH: reactNativePath });

expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('Hoisted React Native bundle');
});

it('runs the script from REACT_NATIVE_PATH for the upload', () => {
const { iosDir, reactNativePath } = makeHoistedMonorepo();
const echoScript = path.join(tempDir, 'mock-sentry-cli-echo-args.js');
fs.writeFileSync(echoScript, "console.log('ARGS=' + JSON.stringify(process.argv.slice(2)));");

const result = runWithoutArg(iosDir, {
REACT_NATIVE_PATH: reactNativePath,
SENTRY_DISABLE_AUTO_UPLOAD: 'false',
SENTRY_CLI_EXECUTABLE: echoScript,
});

expect(result.exitCode).toBe(0);
const args: string[] = JSON.parse(/ARGS=(.+)/.exec(result.stdout)![1]);
expect(args.slice(-2)).toEqual([
'--build-script',
path.join(reactNativePath, 'scripts', 'react-native-xcode.sh'),
]);
});

it('falls back to ../node_modules/react-native when REACT_NATIVE_PATH is not set', () => {
const appRoot = path.join(tempDir, 'app');
const iosDir = path.join(appRoot, 'ios');
fs.mkdirSync(iosDir, { recursive: true });
writeRnScript(path.join(appRoot, 'node_modules', 'react-native'), 'Relative React Native bundle');

const result = runWithoutArg(iosDir);

expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('Relative React Native bundle');
});

it('falls back to ../node_modules/react-native when REACT_NATIVE_PATH has no React Native script', () => {
const appRoot = path.join(tempDir, 'app');
const iosDir = path.join(appRoot, 'ios');
fs.mkdirSync(iosDir, { recursive: true });
writeRnScript(path.join(appRoot, 'node_modules', 'react-native'), 'Relative React Native bundle');
const staleReactNativePath = path.join(tempDir, 'moved', 'node_modules', 'react-native');

const result = runWithoutArg(iosDir, { REACT_NATIVE_PATH: staleReactNativePath });

expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('Relative React Native bundle');
});

it('prefers the script passed as an argument over REACT_NATIVE_PATH', () => {
const { reactNativePath } = makeHoistedMonorepo();

const result = runScript({ REACT_NATIVE_PATH: reactNativePath, SENTRY_DISABLE_AUTO_UPLOAD: 'true' });

expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('Mock React Native bundle');
expect(result.stdout).not.toContain('Hoisted React Native bundle');
});
});

describe('project path containing spaces (issue #6583)', () => {
// Put react-native-xcode.sh in a directory whose path contains a space. The disable and Debug
// branches re-parse REACT_NATIVE_XCODE via `/bin/sh -c`, which word-splits on the space unless
Expand Down
Loading