diff --git a/CHANGELOG.md b/CHANGELOG.md index 09dea5613..40c182038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ - feat(sveltekit): Set `sendDefaultPii: true` by default ([#1055](https://github.com/getsentry/sentry-wizard/pull/1055)) - fix(apple): Remove `options.debug: true` from SDK init snippet ([#1096](https://github.com/getsentry/sentry-wizard/pull/1096)) - fix(nextjs): Remove `debug: false` option from SDK init snippets ([#1099](https://github.com/getsentry/sentry-wizard/pull/1099)) - +- 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 diff --git a/src/react-native/react-native-wizard.ts b/src/react-native/react-native-wizard.ts index b696b333e..e0bc31ba4 100644 --- a/src/react-native/react-native-wizard.ts +++ b/src/react-native/react-native-wizard.ts @@ -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')) { @@ -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', @@ -377,7 +372,6 @@ async function patchXcodeFiles( await patchBundlePhase( bundlePhase, - rnVersion, addSentryWithBundledScriptsToBundleShellScript, ); diff --git a/src/react-native/xcode.ts b/src/react-native/xcode.ts index 90919f8a9..a7f53dc17 100644 --- a/src/react-native/xcode.ts +++ b/src/react-native/xcode.ts @@ -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; @@ -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( @@ -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', @@ -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'); diff --git a/test/react-native/xcode.test.ts b/test/react-native/xcode.test.ts index e7034c08d..187cd82d6 100644 --- a/test/react-native/xcode.test.ts +++ b/test/react-native/xcode.test.ts @@ -17,9 +17,6 @@ vi.mock('@clack/prompts', async () => ({ ...(await vi.importActual('@clack/prompts')), })); -const rnVersionWithQuotes = '0.81.0'; -const rnVersionWithoutQuotes = '0.81.1'; - describe('react-native xcode', () => { beforeEach(() => { vi.spyOn(clack.log, 'error').mockImplementation(() => { @@ -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', () => { @@ -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" @@ -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', () => { @@ -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(