Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -7,6 +7,7 @@
- feat(nextjs): Set `sendDefaultPii: true` by default ([#1052](https://github.com/getsentry/sentry-wizard/pull/1052))
- feat(nuxt): Set `sendDefaultPii: true` by default ([#1060](https://github.com/getsentry/sentry-wizard/pull/1060))
- fix(apple): Remove `options.debug: true` from SDK init snippet ([#1096](https://github.com/getsentry/sentry-wizard/pull/1096))
- feat(react-native): Updates the bundle script in React Native to match the one from the docs ([#1098](https://github.com/getsentry/sentry-wizard/pull/1098))


## 6.5.0
Expand Down
10 changes: 2 additions & 8 deletions src/react-native/react-native-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ Or setup using ${chalk.cyan(

if (fs.existsSync('ios')) {
Sentry.setTag('patch-ios', true);
await traceStep('patch-xcode-files', () =>
patchXcodeFiles(cliConfig, rnVersion),
);
await traceStep('patch-xcode-files', () => patchXcodeFiles(cliConfig));
}

if (fs.existsSync('android')) {
Expand Down Expand Up @@ -324,10 +322,7 @@ ${chalk.cyan(issuesStreamUrl)}`);
return firstErrorConfirmed;
}

async function patchXcodeFiles(
config: RNCliSetupConfigContent,
rnVersion: string | undefined,
) {
async function patchXcodeFiles(config: RNCliSetupConfigContent) {
await addSentryCliConfig(config, {
...propertiesCliSetupConfig,
name: 'source maps and iOS debug files',
Expand Down Expand Up @@ -377,7 +372,6 @@ async function patchXcodeFiles(

await patchBundlePhase(
bundlePhase,
rnVersion,
addSentryWithBundledScriptsToBundleShellScript,
);

Expand Down
28 changes: 8 additions & 20 deletions src/react-native/xcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import chalk from 'chalk';
import { makeCodeSnippet, showCopyPasteInstructions } from '../utils/clack';
import { Project } from 'xcode';
import * as Sentry from '@sentry/node';
import { fulfillsVersionRange } from '../utils/semver';

type BuildPhase = { shellScript: string };
type BuildPhaseMap = Record<string, BuildPhase>;
Expand All @@ -31,11 +30,7 @@ export class ErrorPatchSnippet {

export async function patchBundlePhase(
bundlePhase: BuildPhase | undefined,
rnVersion: string | undefined,
patch: (
script: string,
rnVersion: string | undefined,
) => string | ErrorPatchSnippet,
patch: (script: string) => string | ErrorPatchSnippet,
) {
if (!bundlePhase) {
clack.log.warn(
Expand All @@ -57,7 +52,7 @@ export async function patchBundlePhase(
}

const script: string = JSON.parse(bundlePhase.shellScript);
const patchedScript = patch(script, rnVersion);
const patchedScript = patch(script);
if (patchedScript instanceof ErrorPatchSnippet) {
await showCopyPasteInstructions({
filename: 'Xcode project',
Expand Down Expand Up @@ -89,23 +84,16 @@ export function doesBundlePhaseIncludeSentry(buildPhase: BuildPhase) {

export function addSentryWithBundledScriptsToBundleShellScript(
script: string,
rnVersion: string | undefined,
): string | ErrorPatchSnippet {
const useQuotes = fulfillsVersionRange({
version: rnVersion || 'latest',
acceptableVersions: '<0.81.1',
canBeLatest: false,
});

const quoteChar = useQuotes ? '\\"' : '';
let patchedScript = script;
const isLikelyPlainReactNativeScript = script.includes('$REACT_NATIVE_XCODE');
if (isLikelyPlainReactNativeScript) {
patchedScript = script.replace(
'$REACT_NATIVE_XCODE',
// eslint-disable-next-line no-useless-escape
`${quoteChar}/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE${quoteChar}`,
);
patchedScript = script
.replaceAll('REACT_NATIVE_XCODE', 'SENTRY_XCODE')
.replace(
'react-native/scripts/react-native-xcode.sh',
'@sentry/react-native/scripts/sentry-xcode.sh',
);
}

const isLikelyExpoScript = script.includes('expo');
Expand Down
61 changes: 10 additions & 51 deletions test/react-native/xcode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ vi.mock('@clack/prompts', async () => ({
...(await vi.importActual<typeof clack>('@clack/prompts')),
}));

const rnVersionWithQuotes = '0.81.0';
const rnVersionWithoutQuotes = '0.81.1';

describe('react-native xcode', () => {
beforeEach(() => {
vi.spyOn(clack.log, 'error').mockImplementation(() => {
Expand All @@ -45,38 +42,13 @@ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
const expectedOutput = `set -e

WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT \\"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\\""`;

expect(
addSentryWithBundledScriptsToBundleShellScript(
input,
rnVersionWithQuotes,
),
).toBe(expectedOutput);
});
SENTRY_XCODE="../node_modules/@sentry/react-native/scripts/sentry-xcode.sh"

it('does not add with-environment.sh parameter quotes for RN version >= 0.81.1 to rn bundle build phase', () => {
const input = `set -e

WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT $SENTRY_XCODE"`;

/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"`;
const expectedOutput = `set -e

WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT /bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE"`;

expect(
addSentryWithBundledScriptsToBundleShellScript(
input,
rnVersionWithoutQuotes,
),
).toBe(expectedOutput);
expect(addSentryWithBundledScriptsToBundleShellScript(input)).toBe(
expectedOutput,
);
});

it('does not add sentry cli to rn bundle build phase if $REACT_NATIVE_XCODE is not present and shows code snippet', () => {
Expand All @@ -87,12 +59,7 @@ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT $NOT_REACT_NATIVE_XCODE"`;

expect(
addSentryWithBundledScriptsToBundleShellScript(
input,
rnVersionWithQuotes,
),
).toEqual(
expect(addSentryWithBundledScriptsToBundleShellScript(input)).toEqual(
new ErrorPatchSnippet(
makeCodeSnippet(true, (unchanged, plus, _minus) => {
return unchanged(`WITH_ENVIRONMENT="$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
Expand Down Expand Up @@ -197,12 +164,9 @@ fi
/bin/sh \`"$NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/react-native/package.json')) + '/scripts/sentry-xcode.sh'"\` \`"$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"\`
`;

expect(
addSentryWithBundledScriptsToBundleShellScript(
input,
rnVersionWithQuotes,
),
).toBe(expectedOutput);
expect(addSentryWithBundledScriptsToBundleShellScript(input)).toBe(
expectedOutput,
);
});

it('if patching fails it does not add sentry cli to expo bundle build phase and shows code snippet', () => {
Expand All @@ -225,12 +189,7 @@ if [[ -z "$ENTRY_FILE" ]]; then
export ENTRY_FILE="$("$NODE_BINARY" -e "require('expo/scripts/resolveAppEntry')" "$PROJECT_ROOT" ios absolute | tail -n 1)"
fi
`;
expect(
addSentryWithBundledScriptsToBundleShellScript(
input,
rnVersionWithQuotes,
),
).toEqual(
expect(addSentryWithBundledScriptsToBundleShellScript(input)).toEqual(
new ErrorPatchSnippet(
makeCodeSnippet(true, (unchanged, plus, _minus) => {
return unchanged(
Expand Down