@sentry/wizard 6.11.0 → 6.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/e2e-tests/tests/cloudflare-worker.test.js +5 -0
  3. package/dist/e2e-tests/tests/cloudflare-worker.test.js.map +1 -1
  4. package/dist/e2e-tests/tests/pnpm-workspace.test.js +2 -1
  5. package/dist/e2e-tests/tests/pnpm-workspace.test.js.map +1 -1
  6. package/dist/e2e-tests/tests/react-router-instrumentation-api.test.d.ts +1 -0
  7. package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js +96 -0
  8. package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js.map +1 -0
  9. package/dist/e2e-tests/tests/react-router.test.js +3 -1
  10. package/dist/e2e-tests/tests/react-router.test.js.map +1 -1
  11. package/dist/e2e-tests/tests/sveltekit-tracing.test.js +2 -1
  12. package/dist/e2e-tests/tests/sveltekit-tracing.test.js.map +1 -1
  13. package/dist/src/apple/code-tools.js +17 -3
  14. package/dist/src/apple/code-tools.js.map +1 -1
  15. package/dist/src/apple/configure-package-manager.js +18 -5
  16. package/dist/src/apple/configure-package-manager.js.map +1 -1
  17. package/dist/src/cloudflare/cloudflare-wizard.js +5 -0
  18. package/dist/src/cloudflare/cloudflare-wizard.js.map +1 -1
  19. package/dist/src/cloudflare/sdk-setup.d.ts +1 -0
  20. package/dist/src/cloudflare/sdk-setup.js.map +1 -1
  21. package/dist/src/cloudflare/templates.d.ts +1 -0
  22. package/dist/src/cloudflare/templates.js +7 -1
  23. package/dist/src/cloudflare/templates.js.map +1 -1
  24. package/dist/src/cloudflare/wrap-worker.d.ts +1 -0
  25. package/dist/src/cloudflare/wrap-worker.js +7 -0
  26. package/dist/src/cloudflare/wrap-worker.js.map +1 -1
  27. package/dist/src/react-native/expo.d.ts +6 -0
  28. package/dist/src/react-native/expo.js +27 -1
  29. package/dist/src/react-native/expo.js.map +1 -1
  30. package/dist/src/react-native/git.d.ts +5 -0
  31. package/dist/src/react-native/git.js +32 -1
  32. package/dist/src/react-native/git.js.map +1 -1
  33. package/dist/src/react-native/javascript.js +3 -1
  34. package/dist/src/react-native/javascript.js.map +1 -1
  35. package/dist/src/react-native/react-native-wizard.js +12 -6
  36. package/dist/src/react-native/react-native-wizard.js.map +1 -1
  37. package/dist/src/react-router/codemods/client.entry.d.ts +1 -1
  38. package/dist/src/react-router/codemods/client.entry.js +69 -12
  39. package/dist/src/react-router/codemods/client.entry.js.map +1 -1
  40. package/dist/src/react-router/codemods/react-router-config.js +1 -1
  41. package/dist/src/react-router/codemods/react-router-config.js.map +1 -1
  42. package/dist/src/react-router/codemods/root.js +1 -2
  43. package/dist/src/react-router/codemods/root.js.map +1 -1
  44. package/dist/src/react-router/codemods/server-entry.d.ts +1 -1
  45. package/dist/src/react-router/codemods/server-entry.js +39 -4
  46. package/dist/src/react-router/codemods/server-entry.js.map +1 -1
  47. package/dist/src/react-router/codemods/vite.js +46 -1
  48. package/dist/src/react-router/codemods/vite.js.map +1 -1
  49. package/dist/src/react-router/react-router-wizard.js +52 -5
  50. package/dist/src/react-router/react-router-wizard.js.map +1 -1
  51. package/dist/src/react-router/sdk-setup.d.ts +4 -2
  52. package/dist/src/react-router/sdk-setup.js +32 -5
  53. package/dist/src/react-router/sdk-setup.js.map +1 -1
  54. package/dist/src/react-router/templates.d.ts +2 -2
  55. package/dist/src/react-router/templates.js +72 -2
  56. package/dist/src/react-router/templates.js.map +1 -1
  57. package/dist/src/sourcemaps/tools/vite.js +1 -1
  58. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  59. package/dist/src/sveltekit/sdk-setup/vite.js +1 -1
  60. package/dist/src/sveltekit/sdk-setup/vite.js.map +1 -1
  61. package/dist/src/utils/ast-utils.d.ts +10 -0
  62. package/dist/src/utils/ast-utils.js +19 -1
  63. package/dist/src/utils/ast-utils.js.map +1 -1
  64. package/dist/src/version.d.ts +1 -1
  65. package/dist/src/version.js +1 -1
  66. package/dist/src/version.js.map +1 -1
  67. package/dist/test/apple/code-tools.test.js +78 -0
  68. package/dist/test/apple/code-tools.test.js.map +1 -1
  69. package/dist/test/apple/configure-package-manager.test.d.ts +1 -0
  70. package/dist/test/apple/configure-package-manager.test.js +161 -0
  71. package/dist/test/apple/configure-package-manager.test.js.map +1 -0
  72. package/dist/test/cloudflare/sdk-setup.test.js +20 -2
  73. package/dist/test/cloudflare/sdk-setup.test.js.map +1 -1
  74. package/dist/test/cloudflare/templates.test.js +54 -0
  75. package/dist/test/cloudflare/templates.test.js.map +1 -1
  76. package/dist/test/cloudflare/wrap-worker.test.js +74 -11
  77. package/dist/test/cloudflare/wrap-worker.test.js.map +1 -1
  78. package/dist/test/react-native/expo.test.js +140 -0
  79. package/dist/test/react-native/expo.test.js.map +1 -1
  80. package/dist/test/react-native/git.test.d.ts +1 -0
  81. package/dist/test/react-native/git.test.js +160 -0
  82. package/dist/test/react-native/git.test.js.map +1 -0
  83. package/dist/test/react-router/codemods/client-entry.test.js +29 -0
  84. package/dist/test/react-router/codemods/client-entry.test.js.map +1 -1
  85. package/dist/test/react-router/codemods/root.test.js +4 -0
  86. package/dist/test/react-router/codemods/root.test.js.map +1 -1
  87. package/dist/test/react-router/codemods/server-entry.test.js +70 -0
  88. package/dist/test/react-router/codemods/server-entry.test.js.map +1 -1
  89. package/dist/test/react-router/codemods/vite.test.js +89 -0
  90. package/dist/test/react-router/codemods/vite.test.js.map +1 -1
  91. package/dist/test/react-router/sdk-setup.test.js +62 -6
  92. package/dist/test/react-router/sdk-setup.test.js.map +1 -1
  93. package/dist/test/react-router/templates.test.js +50 -0
  94. package/dist/test/react-router/templates.test.js.map +1 -1
  95. package/dist/test/sourcemaps/tools/vite.test.js +12 -8
  96. package/dist/test/sourcemaps/tools/vite.test.js.map +1 -1
  97. package/dist/test/utils/ast-utils.test.js +22 -0
  98. package/dist/test/utils/ast-utils.test.js.map +1 -1
  99. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"react-native-wizard.js","sourceRoot":"","sources":["../../../src/react-native/react-native-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8BAA8B;AAC9B,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,uCAAyB;AAEzB,qDAAuC;AACvC,2BAA8B;AAC9B,gDAA+C;AAC/C,4CAAwD;AACxD,0DAAwE;AACxE,0CAcwB;AACxB,wDAA+E;AAC/E,sCAAiD;AACjD,iCAA2E;AAC3E,mDAAkD;AAClD,6CAA0D;AAC1D,iCAA8E;AAC9E,qCAIkB;AAClB,6CAKsB;AACtB,mCAAqD;AAErD,mCAQiB;AAEjB,kDAA0B;AAC1B,kGAA0F;AAE7E,QAAA,cAAc,GAAG,sBAAsB,CAAC;AACxC,QAAA,sBAAsB,GAAG,UAAU,CAAC;AAEpC,QAAA,UAAU,GAAG,cAAc,CAAC;AAC5B,QAAA,aAAa,GAAG,cAAc,CAAC;AAE/B,QAAA,kBAAkB,GAAG,UAAU,CAAC;AAChC,QAAA,oBAAoB,GAAG,UAAU,CAAC;AAOxC,KAAK,UAAU,oBAAoB,CACxC,MAAgC;IAEhC,OAAO,IAAA,yBAAa,EAClB;QACE,OAAO,EAAE,MAAM,CAAC,gBAAgB;QAChC,WAAW,EAAE,cAAc;QAC3B,aAAa,EAAE,MAAM;KACtB,EACD,GAAG,EAAE,CAAC,iCAAiC,CAAC,MAAM,CAAC,CAChD,CAAC;AACJ,CAAC;AAXD,oDAWC;AAEM,KAAK,UAAU,iCAAiC,CACrD,OAAiC;IAEjC,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAE9D,IAAA,oBAAY,EAAC;QACX,UAAU,EAAE,4BAA4B;QACxC,SAAS;QACT,gBAAgB;KACjB,CAAC,CAAC;IAEH,MAAM,IAAA,yCAAiC,EAAC;QACtC,gBAAgB,EAAE,OAAO,CAAC,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AK,UAAU,iBAAiB;IAC9B,OAAO,IAAA,qBAAS,EAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACjD,MAAM,sBAAsB,GAAG,MAAM,IAAA,wBAAgB,EACnD,iBAAK,CAAC,MAAM,CAAC;YACX,OAAO,EAAE,uCAAuC;YAChD,OAAO,EAAE;gBACP;oBACE,KAAK,EAAE,IAAI;oBACX,KAAK,EAAE,KAAK;oBACZ,IAAI,EAAE,mEAAmE;iBAC1E;gBACD,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE;aAChD;YACD,YAAY,EAAE,IAAI;SACnB,CAAC,CACH,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,2BAA2B,EAAE,sBAAsB,CAAC,CAAC;QACnE,OAAO,sBAAsB,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* eslint-disable max-lines */\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as fs from 'fs';\n\nimport * as Sentry from '@sentry/node';\nimport { platform } from 'os';\nimport { podInstall } from '../apple/cocoapod';\nimport { traceStep, withTelemetry } from '../telemetry';\nimport { offerProjectScopedMcpConfig } from '../utils/clack/mcp-config';\nimport {\n CliSetupConfigContent,\n abort,\n abortIfCancelled,\n addSentryCliConfig,\n confirmContinueIfNoOrDirtyGitRepo,\n confirmContinueIfPackageVersionNotSupported,\n ensurePackageIsInstalled,\n getOrAskForProjectData,\n getPackageDotJson,\n installPackage,\n printWelcome,\n propertiesCliSetupConfig,\n runPrettierIfInstalled,\n} from '../utils/clack';\nimport { getPackageVersion, hasPackageInstalled } from '../utils/package-json';\nimport { getIssueStreamUrl } from '../utils/url';\nimport { patchExpoAppConfig, printSentryExpoMigrationOutro } from './expo';\nimport { addExpoEnvLocal } from './expo-env-file';\nimport { addSentryToExpoMetroConfig } from './expo-metro';\nimport { APP_BUILD_GRADLE, XCODE_PROJECT, getFirstMatchedPath } from './glob';\nimport {\n addRNSentryGradlePlugin,\n doesAppBuildGradleIncludeRNSentryGradlePlugin,\n writeAppBuildGradle,\n} from './gradle';\nimport {\n addSentryInit,\n sessionReplayOnErrorSampleRate,\n sessionReplaySampleRate,\n wrapRootComponent,\n} from './javascript';\nimport { patchMetroWithSentryConfig } from './metro';\nimport { ReactNativeWizardOptions } from './options';\nimport {\n addDebugFilesUploadPhaseWithBundledScripts,\n addSentryWithBundledScriptsToBundleShellScript,\n findBundlePhase,\n findDebugFilesUploadPhase,\n getValidExistingBuildPhases,\n patchBundlePhase,\n writeXcodeProject,\n} from './xcode';\n\nimport xcode from 'xcode';\nimport { abortIfSpotlightNotSupported } from '../utils/abort-if-sportlight-not-supported';\n\nexport const RN_SDK_PACKAGE = '@sentry/react-native';\nexport const RN_SDK_SUPPORTED_RANGE = '>=6.12.0';\n\nexport const RN_PACKAGE = 'react-native';\nexport const RN_HUMAN_NAME = 'React Native';\n\nexport const SUPPORTED_RN_RANGE = '>=0.69.0';\nexport const SUPPORTED_EXPO_RANGE = '>=50.0.0';\n\nexport type RNCliSetupConfigContent = Pick<\n Required<CliSetupConfigContent>,\n 'authToken' | 'org' | 'project' | 'url'\n>;\n\nexport async function runReactNativeWizard(\n params: ReactNativeWizardOptions,\n): Promise<void> {\n return withTelemetry(\n {\n enabled: params.telemetryEnabled,\n integration: 'react-native',\n wizardOptions: params,\n },\n () => runReactNativeWizardWithTelemetry(params),\n );\n}\n\nexport async function runReactNativeWizardWithTelemetry(\n options: ReactNativeWizardOptions,\n): Promise<void> {\n const { promoCode, telemetryEnabled, forceInstall } = options;\n\n printWelcome({\n wizardName: 'Sentry React Native Wizard',\n promoCode,\n telemetryEnabled,\n });\n\n await confirmContinueIfNoOrDirtyGitRepo({\n ignoreGitChanges: options.ignoreGitChanges,\n cwd: undefined,\n });\n\n const packageJson = await getPackageDotJson();\n const hasInstalled = (dep: string) => hasPackageInstalled(dep, packageJson);\n\n if (hasInstalled('sentry-expo')) {\n Sentry.setTag('has-sentry-expo-installed', true);\n printSentryExpoMigrationOutro();\n return;\n }\n\n await ensurePackageIsInstalled(packageJson, RN_PACKAGE, RN_HUMAN_NAME);\n\n const rnVersion = getPackageVersion(RN_PACKAGE, packageJson);\n if (rnVersion) {\n await confirmContinueIfPackageVersionNotSupported({\n packageName: RN_HUMAN_NAME,\n packageVersion: rnVersion,\n packageId: RN_PACKAGE,\n acceptableVersions: SUPPORTED_RN_RANGE,\n note: `Please upgrade to ${SUPPORTED_RN_RANGE} if you wish to use the Sentry Wizard.\nOr setup using ${chalk.cyan(\n 'https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/',\n )}`,\n });\n }\n\n await installPackage({\n packageName: RN_SDK_PACKAGE,\n alreadyInstalled: hasPackageInstalled(RN_SDK_PACKAGE, packageJson),\n forceInstall,\n });\n const sdkVersion = getPackageVersion(\n RN_SDK_PACKAGE,\n await getPackageDotJson(),\n );\n if (sdkVersion) {\n await confirmContinueIfPackageVersionNotSupported({\n packageName: 'Sentry React Native SDK',\n packageVersion: sdkVersion,\n packageId: RN_SDK_PACKAGE,\n acceptableVersions: RN_SDK_SUPPORTED_RANGE,\n note: `Please upgrade to ${RN_SDK_SUPPORTED_RANGE} to continue with the wizard in this project.`,\n });\n } else {\n const continueWithoutSdk = await abortIfCancelled(\n clack.confirm({\n message:\n 'Could not detect Sentry React Native SDK version. Do you want to continue anyway?',\n }),\n );\n if (!continueWithoutSdk) {\n await abort(undefined, 0);\n }\n }\n Sentry.setTag(`detected-sentry-react-native-sdk-version`, sdkVersion);\n\n const expoVersion = getPackageVersion('expo', packageJson);\n const isExpo = !!expoVersion;\n if (expoVersion) {\n await confirmContinueIfPackageVersionNotSupported({\n packageName: 'Expo SDK',\n packageVersion: expoVersion,\n packageId: 'expo',\n acceptableVersions: SUPPORTED_EXPO_RANGE,\n note: `Please upgrade to ${SUPPORTED_EXPO_RANGE} to continue with the wizard in this Expo project.`,\n });\n }\n\n const projectData = await getOrAskForProjectData(options, 'react-native');\n\n if (projectData.spotlight) {\n return abortIfSpotlightNotSupported('React Native');\n }\n\n const { selectedProject, authToken, sentryUrl } = projectData;\n const orgSlug = selectedProject.organization.slug;\n const projectSlug = selectedProject.slug;\n const projectId = selectedProject.id;\n const cliConfig: RNCliSetupConfigContent = {\n authToken,\n org: orgSlug,\n project: projectSlug,\n url: sentryUrl,\n };\n\n // Ask if user wants to enable Session Replay\n const enableSessionReplay = await abortIfCancelled(\n clack.confirm({\n message:\n 'Do you want to enable Session Replay to help debug issues? (See https://docs.sentry.io/platforms/react-native/session-replay/)',\n }),\n );\n Sentry.setTag('enable-session-replay', enableSessionReplay);\n\n if (enableSessionReplay) {\n clack.log.info(\n `Session Replay will be enabled with default settings (replaysSessionSampleRate: ${sessionReplaySampleRate}, replaysOnErrorSampleRate: ${sessionReplayOnErrorSampleRate}).`,\n );\n clack.log.message(\n 'By default, all text content, images, and webviews will be masked for privacy. You can customize this in your code later.',\n );\n }\n\n // Ask if user wants to enable the Feedback Widget\n const enableFeedbackWidget = await abortIfCancelled(\n clack.confirm({\n message:\n 'Do you want to enable the Feedback Widget to collect feedback from your users? (See https://docs.sentry.io/platforms/react-native/user-feedback/)',\n }),\n );\n Sentry.setTag('enable-feedback-widget', enableFeedbackWidget);\n\n if (enableFeedbackWidget) {\n clack.log.info(\n `The Feedback Widget will be enabled with default settings. You can show the widget by calling Sentry.showFeedbackWidget() in your code.`,\n );\n }\n\n // Ask if user wants to enable Logs\n const enableLogs = await abortIfCancelled(\n clack.confirm({\n message:\n 'Do you want to enable Logs? (See https://docs.sentry.io/platforms/react-native/logs/)',\n }),\n );\n Sentry.setTag('enable-logs', enableLogs);\n\n if (enableLogs) {\n clack.log.info(\n `Logs will be enabled with default settings. You can send logs using the Sentry.logger APIs.`,\n );\n }\n\n await traceStep('patch-app-js', () =>\n addSentryInit({\n dsn: selectedProject.keys[0].dsn.public,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n }),\n );\n\n await traceStep('patch-app-js-wrap', () => wrapRootComponent());\n\n if (isExpo) {\n await traceStep('patch-expo-app-config', () =>\n patchExpoAppConfig(cliConfig),\n );\n await traceStep('add-expo-env-local', () => addExpoEnvLocal(cliConfig));\n }\n\n if (isExpo) {\n await traceStep('patch-metro-config', addSentryToExpoMetroConfig);\n } else {\n await traceStep('patch-metro-config', patchMetroWithSentryConfig);\n }\n\n if (fs.existsSync('ios')) {\n Sentry.setTag('patch-ios', true);\n await traceStep('patch-xcode-files', () => patchXcodeFiles(cliConfig));\n }\n\n if (fs.existsSync('android')) {\n Sentry.setTag('patch-android', true);\n await traceStep('patch-android-files', () => patchAndroidFiles(cliConfig));\n }\n\n await runPrettierIfInstalled({ cwd: undefined });\n\n // Offer optional project-scoped MCP config for Sentry with org and project scope\n await offerProjectScopedMcpConfig(\n selectedProject.organization.slug,\n selectedProject.slug,\n );\n\n const confirmedFirstException = await confirmFirstSentryException(\n sentryUrl,\n orgSlug,\n projectId,\n );\n\n Sentry.setTag('user-confirmed-first-error', confirmedFirstException);\n\n if (confirmedFirstException) {\n clack.outro(\n `${chalk.green('Everything is set up!')}\n\n ${chalk.dim(\n 'If you encounter any issues, let us know here: https://github.com/getsentry/sentry-react-native/issues',\n )}`,\n );\n } else {\n clack.outro(\n `${chalk.dim(\n 'Let us know here: https://github.com/getsentry/sentry-react-native/issues',\n )}`,\n );\n }\n}\n\nasync function confirmFirstSentryException(\n url: string,\n orgSlug: string,\n projectId: string,\n) {\n const issuesStreamUrl = getIssueStreamUrl({ url, orgSlug, projectId });\n\n clack.log\n .step(`To make sure everything is set up correctly, put the following code snippet into your application.\nThe snippet will create a button that, when tapped, sends a test event to Sentry.\n\nAfter that check your project issues:\n\n${chalk.cyan(issuesStreamUrl)}`);\n\n // We want the code snippet to be easily copy-pasteable, without any clack artifacts\n // eslint-disable-next-line no-console\n console.log(\n chalk.greenBright(`\n<Button title='Try!' onPress={ () => { Sentry.captureException(new Error('First error')) }}/>\n`),\n );\n\n const firstErrorConfirmed = clack.confirm({\n message: `Have you successfully sent a test event?`,\n });\n\n return firstErrorConfirmed;\n}\n\nasync function patchXcodeFiles(config: RNCliSetupConfigContent) {\n await addSentryCliConfig(config, {\n ...propertiesCliSetupConfig,\n name: 'source maps and iOS debug files',\n filename: 'ios/sentry.properties',\n gitignore: false,\n });\n\n if (platform() === 'darwin' && (await confirmPodInstall())) {\n await traceStep('pod-install', () => podInstall('ios'));\n }\n\n const xcodeProjectPath = traceStep('find-xcode-project', () =>\n getFirstMatchedPath(XCODE_PROJECT),\n );\n Sentry.setTag(\n 'xcode-project-status',\n xcodeProjectPath ? 'found' : 'not-found',\n );\n if (!xcodeProjectPath) {\n clack.log.warn(\n `Could not find Xcode project file using ${chalk.cyan(XCODE_PROJECT)}.`,\n );\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const [xcodeProject, buildPhasesMap] = traceStep(\n 'parse-xcode-project',\n () => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n const project = xcode.project(xcodeProjectPath);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n project.parseSync();\n\n const map = getValidExistingBuildPhases(project);\n return [project, map];\n },\n );\n Sentry.setTag('xcode-project-status', 'parsed');\n\n await traceStep('patch-bundle-phase', async () => {\n const bundlePhase = findBundlePhase(buildPhasesMap);\n Sentry.setTag(\n 'xcode-bundle-phase-status',\n bundlePhase ? 'found' : 'not-found',\n );\n\n await patchBundlePhase(\n bundlePhase,\n addSentryWithBundledScriptsToBundleShellScript,\n );\n\n Sentry.setTag('xcode-bundle-phase-status', 'patched');\n });\n\n traceStep('add-debug-files-upload-phase', () => {\n const debugFilesUploadPhaseExists =\n !!findDebugFilesUploadPhase(buildPhasesMap);\n Sentry.setTag(\n 'xcode-debug-files-upload-phase-status',\n debugFilesUploadPhaseExists ? 'already-exists' : undefined,\n );\n\n addDebugFilesUploadPhaseWithBundledScripts(xcodeProject, {\n debugFilesUploadPhaseExists,\n });\n\n Sentry.setTag('xcode-debug-files-upload-phase-status', 'added');\n });\n\n traceStep('write-xcode-project', () => {\n writeXcodeProject(xcodeProjectPath, xcodeProject);\n });\n Sentry.setTag('xcode-project-status', 'patched');\n}\n\nasync function patchAndroidFiles(config: RNCliSetupConfigContent) {\n await addSentryCliConfig(config, {\n ...propertiesCliSetupConfig,\n name: 'source maps and iOS debug files',\n filename: 'android/sentry.properties',\n gitignore: false,\n });\n\n const appBuildGradlePath = traceStep('find-app-build-gradle', () =>\n getFirstMatchedPath(APP_BUILD_GRADLE),\n );\n Sentry.setTag(\n 'app-build-gradle-status',\n appBuildGradlePath ? 'found' : 'not-found',\n );\n if (!appBuildGradlePath) {\n clack.log.warn(\n `Could not find Android ${chalk.cyan(\n 'app/build.gradle',\n )} file using ${chalk.cyan(APP_BUILD_GRADLE)}.`,\n );\n return;\n }\n\n const appBuildGradle = traceStep('read-app-build-gradle', () =>\n fs.readFileSync(appBuildGradlePath, 'utf-8'),\n );\n const includesSentry =\n doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle);\n if (includesSentry) {\n Sentry.setTag('app-build-gradle-status', 'already-includes-sentry');\n clack.log.warn(\n `Android ${chalk.cyan('app/build.gradle')} file already includes Sentry.`,\n );\n return;\n }\n\n const patchedAppBuildGradle = traceStep('add-rn-sentry-gradle-plugin', () =>\n addRNSentryGradlePlugin(appBuildGradle),\n );\n if (!doesAppBuildGradleIncludeRNSentryGradlePlugin(patchedAppBuildGradle)) {\n Sentry.setTag(\n 'app-build-gradle-status',\n 'failed-to-add-rn-sentry-gradle-plugin',\n );\n clack.log.warn(\n `Could not add Sentry RN Gradle Plugin to ${chalk.cyan(\n 'app/build.gradle',\n )}.`,\n );\n return;\n }\n\n Sentry.setTag('app-build-gradle-status', 'added-rn-sentry-gradle-plugin');\n clack.log.success(\n `Added Sentry RN Gradle Plugin to ${chalk.bold('app/build.gradle')}.`,\n );\n\n traceStep('write-app-build-gradle', () =>\n writeAppBuildGradle(appBuildGradlePath, patchedAppBuildGradle),\n );\n clack.log.success(\n chalk.green(`Android ${chalk.cyan('app/build.gradle')} saved.`),\n );\n}\n\nasync function confirmPodInstall(): Promise<boolean> {\n return traceStep('confirm-pod-install', async () => {\n const continueWithPodInstall = await abortIfCancelled(\n clack.select({\n message: 'Do you want to run `pod install` now?',\n options: [\n {\n value: true,\n label: 'Yes',\n hint: 'Recommended for smaller projects, this might take several minutes',\n },\n { value: false, label: `No, I'll do it later` },\n ],\n initialValue: true,\n }),\n );\n Sentry.setTag('continue-with-pod-install', continueWithPodInstall);\n return continueWithPodInstall;\n });\n}\n"]}
1
+ {"version":3,"file":"react-native-wizard.js","sourceRoot":"","sources":["../../../src/react-native/react-native-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8BAA8B;AAC9B,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,uCAAyB;AAEzB,qDAAuC;AACvC,2BAA8B;AAC9B,gDAA+C;AAC/C,4CAAwD;AACxD,0DAAwE;AACxE,0CAcwB;AACxB,wDAA+E;AAC/E,sCAAiD;AACjD,iCAIgB;AAChB,mDAAkD;AAClD,6CAA0D;AAC1D,iCAA8E;AAC9E,qCAIkB;AAClB,6CAKsB;AACtB,mCAAqD;AAErD,mCAQiB;AAEjB,kDAA0B;AAC1B,kGAA0F;AAE7E,QAAA,cAAc,GAAG,sBAAsB,CAAC;AACxC,QAAA,sBAAsB,GAAG,UAAU,CAAC;AAEpC,QAAA,UAAU,GAAG,cAAc,CAAC;AAC5B,QAAA,aAAa,GAAG,cAAc,CAAC;AAE/B,QAAA,kBAAkB,GAAG,UAAU,CAAC;AAChC,QAAA,oBAAoB,GAAG,UAAU,CAAC;AAOxC,KAAK,UAAU,oBAAoB,CACxC,MAAgC;IAEhC,OAAO,IAAA,yBAAa,EAClB;QACE,OAAO,EAAE,MAAM,CAAC,gBAAg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ACzE,MAAM,CAAC,MAAM,CACX,yBAAyB,EACzB,uCAAuC,CACxC,CAAC;QACF,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,4CAA4C,eAAK,CAAC,IAAI,CACpD,kBAAkB,CACnB,GAAG,CACL,CAAC;QACF,OAAO;KACR;IAED,MAAM,CAAC,MAAM,CAAC,yBAAyB,EAAE,+BAA+B,CAAC,CAAC;IAC1E,iBAAK,CAAC,GAAG,CAAC,OAAO,CACf,oCAAoC,eAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CACtE,CAAC;IAEF,IAAA,qBAAS,EAAC,wBAAwB,EAAE,GAAG,EAAE,CACvC,IAAA,4BAAmB,EAAC,kBAAkB,EAAE,qBAAqB,CAAC,CAC/D,CAAC;IACF,iBAAK,CAAC,GAAG,CAAC,OAAO,CACf,eAAK,CAAC,KAAK,CAAC,WAAW,eAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAChE,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,iBAAiB;IAC9B,OAAO,IAAA,qBAAS,EAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACjD,MAAM,sBAAsB,GAAG,MAAM,IAAA,wBAAgB,EACnD,iBAAK,CAAC,MAAM,CAAC;YACX,OAAO,EAAE,uCAAuC;YAChD,OAAO,EAAE;gBACP;oBACE,KAAK,EAAE,IAAI;oBACX,KAAK,EAAE,KAAK;oBACZ,IAAI,EAAE,mEAAmE;iBAC1E;gBACD,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE;aAChD;YACD,YAAY,EAAE,IAAI;SACnB,CAAC,CACH,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,2BAA2B,EAAE,sBAAsB,CAAC,CAAC;QACnE,OAAO,sBAAsB,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* eslint-disable max-lines */\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as fs from 'fs';\n\nimport * as Sentry from '@sentry/node';\nimport { platform } from 'os';\nimport { podInstall } from '../apple/cocoapod';\nimport { traceStep, withTelemetry } from '../telemetry';\nimport { offerProjectScopedMcpConfig } from '../utils/clack/mcp-config';\nimport {\n CliSetupConfigContent,\n abort,\n abortIfCancelled,\n addSentryCliConfig,\n confirmContinueIfNoOrDirtyGitRepo,\n confirmContinueIfPackageVersionNotSupported,\n ensurePackageIsInstalled,\n getOrAskForProjectData,\n getPackageDotJson,\n installPackage,\n printWelcome,\n propertiesCliSetupConfig,\n runPrettierIfInstalled,\n} from '../utils/clack';\nimport { getPackageVersion, hasPackageInstalled } from '../utils/package-json';\nimport { getIssueStreamUrl } from '../utils/url';\nimport {\n isExpoCNG,\n patchExpoAppConfig,\n printSentryExpoMigrationOutro,\n} from './expo';\nimport { addExpoEnvLocal } from './expo-env-file';\nimport { addSentryToExpoMetroConfig } from './expo-metro';\nimport { APP_BUILD_GRADLE, XCODE_PROJECT, getFirstMatchedPath } from './glob';\nimport {\n addRNSentryGradlePlugin,\n doesAppBuildGradleIncludeRNSentryGradlePlugin,\n writeAppBuildGradle,\n} from './gradle';\nimport {\n addSentryInit,\n sessionReplayOnErrorSampleRate,\n sessionReplaySampleRate,\n wrapRootComponent,\n} from './javascript';\nimport { patchMetroWithSentryConfig } from './metro';\nimport { ReactNativeWizardOptions } from './options';\nimport {\n addDebugFilesUploadPhaseWithBundledScripts,\n addSentryWithBundledScriptsToBundleShellScript,\n findBundlePhase,\n findDebugFilesUploadPhase,\n getValidExistingBuildPhases,\n patchBundlePhase,\n writeXcodeProject,\n} from './xcode';\n\nimport xcode from 'xcode';\nimport { abortIfSpotlightNotSupported } from '../utils/abort-if-sportlight-not-supported';\n\nexport const RN_SDK_PACKAGE = '@sentry/react-native';\nexport const RN_SDK_SUPPORTED_RANGE = '>=6.12.0';\n\nexport const RN_PACKAGE = 'react-native';\nexport const RN_HUMAN_NAME = 'React Native';\n\nexport const SUPPORTED_RN_RANGE = '>=0.69.0';\nexport const SUPPORTED_EXPO_RANGE = '>=50.0.0';\n\nexport type RNCliSetupConfigContent = Pick<\n Required<CliSetupConfigContent>,\n 'authToken' | 'org' | 'project' | 'url'\n>;\n\nexport async function runReactNativeWizard(\n params: ReactNativeWizardOptions,\n): Promise<void> {\n return withTelemetry(\n {\n enabled: params.telemetryEnabled,\n integration: 'react-native',\n wizardOptions: params,\n },\n () => runReactNativeWizardWithTelemetry(params),\n );\n}\n\nexport async function runReactNativeWizardWithTelemetry(\n options: ReactNativeWizardOptions,\n): Promise<void> {\n const { promoCode, telemetryEnabled, forceInstall } = options;\n\n printWelcome({\n wizardName: 'Sentry React Native Wizard',\n promoCode,\n telemetryEnabled,\n });\n\n await confirmContinueIfNoOrDirtyGitRepo({\n ignoreGitChanges: options.ignoreGitChanges,\n cwd: undefined,\n });\n\n const packageJson = await getPackageDotJson();\n const hasInstalled = (dep: string) => hasPackageInstalled(dep, packageJson);\n\n if (hasInstalled('sentry-expo')) {\n Sentry.setTag('has-sentry-expo-installed', true);\n printSentryExpoMigrationOutro();\n return;\n }\n\n await ensurePackageIsInstalled(packageJson, RN_PACKAGE, RN_HUMAN_NAME);\n\n const rnVersion = getPackageVersion(RN_PACKAGE, packageJson);\n if (rnVersion) {\n await confirmContinueIfPackageVersionNotSupported({\n packageName: RN_HUMAN_NAME,\n packageVersion: rnVersion,\n packageId: RN_PACKAGE,\n acceptableVersions: SUPPORTED_RN_RANGE,\n note: `Please upgrade to ${SUPPORTED_RN_RANGE} if you wish to use the Sentry Wizard.\nOr setup using ${chalk.cyan(\n 'https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/',\n )}`,\n });\n }\n\n await installPackage({\n packageName: RN_SDK_PACKAGE,\n alreadyInstalled: hasPackageInstalled(RN_SDK_PACKAGE, packageJson),\n forceInstall,\n });\n const sdkVersion = getPackageVersion(\n RN_SDK_PACKAGE,\n await getPackageDotJson(),\n );\n if (sdkVersion) {\n await confirmContinueIfPackageVersionNotSupported({\n packageName: 'Sentry React Native SDK',\n packageVersion: sdkVersion,\n packageId: RN_SDK_PACKAGE,\n acceptableVersions: RN_SDK_SUPPORTED_RANGE,\n note: `Please upgrade to ${RN_SDK_SUPPORTED_RANGE} to continue with the wizard in this project.`,\n });\n } else {\n const continueWithoutSdk = await abortIfCancelled(\n clack.confirm({\n message:\n 'Could not detect Sentry React Native SDK version. Do you want to continue anyway?',\n }),\n );\n if (!continueWithoutSdk) {\n await abort(undefined, 0);\n }\n }\n Sentry.setTag(`detected-sentry-react-native-sdk-version`, sdkVersion);\n\n const expoVersion = getPackageVersion('expo', packageJson);\n const isExpo = !!expoVersion;\n if (expoVersion) {\n await confirmContinueIfPackageVersionNotSupported({\n packageName: 'Expo SDK',\n packageVersion: expoVersion,\n packageId: 'expo',\n acceptableVersions: SUPPORTED_EXPO_RANGE,\n note: `Please upgrade to ${SUPPORTED_EXPO_RANGE} to continue with the wizard in this Expo project.`,\n });\n }\n\n const projectData = await getOrAskForProjectData(options, 'react-native');\n\n if (projectData.spotlight) {\n return abortIfSpotlightNotSupported('React Native');\n }\n\n const { selectedProject, authToken, sentryUrl } = projectData;\n const orgSlug = selectedProject.organization.slug;\n const projectSlug = selectedProject.slug;\n const projectId = selectedProject.id;\n const cliConfig: RNCliSetupConfigContent = {\n authToken,\n org: orgSlug,\n project: projectSlug,\n url: sentryUrl,\n };\n\n // Ask if user wants to enable Session Replay\n const enableSessionReplay = await abortIfCancelled(\n clack.confirm({\n message:\n 'Do you want to enable Session Replay to help debug issues? (See https://docs.sentry.io/platforms/react-native/session-replay/)',\n }),\n );\n Sentry.setTag('enable-session-replay', enableSessionReplay);\n\n if (enableSessionReplay) {\n clack.log.info(\n `Session Replay will be enabled with default settings (replaysSessionSampleRate: ${sessionReplaySampleRate}, replaysOnErrorSampleRate: ${sessionReplayOnErrorSampleRate}).`,\n );\n clack.log.message(\n 'By default, all text content, images, and webviews will be masked for privacy. You can customize this in your code later.',\n );\n }\n\n // Ask if user wants to enable the Feedback Widget\n const enableFeedbackWidget = await abortIfCancelled(\n clack.confirm({\n message:\n 'Do you want to enable the Feedback Widget to collect feedback from your users? (See https://docs.sentry.io/platforms/react-native/user-feedback/)',\n }),\n );\n Sentry.setTag('enable-feedback-widget', enableFeedbackWidget);\n\n if (enableFeedbackWidget) {\n clack.log.info(\n `The Feedback Widget will be enabled with default settings. You can show the widget by calling Sentry.showFeedbackWidget() in your code.`,\n );\n }\n\n // Ask if user wants to enable Logs\n const enableLogs = await abortIfCancelled(\n clack.confirm({\n message:\n 'Do you want to enable Logs? (See https://docs.sentry.io/platforms/react-native/logs/)',\n }),\n );\n Sentry.setTag('enable-logs', enableLogs);\n\n if (enableLogs) {\n clack.log.info(\n `Logs will be enabled with default settings. You can send logs using the Sentry.logger APIs.`,\n );\n }\n\n await traceStep('patch-app-js', () =>\n addSentryInit({\n dsn: selectedProject.keys[0].dsn.public,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n }),\n );\n\n await traceStep('patch-app-js-wrap', () => wrapRootComponent());\n\n if (isExpo) {\n await traceStep('patch-expo-app-config', () =>\n patchExpoAppConfig(cliConfig),\n );\n await traceStep('add-expo-env-local', () => addExpoEnvLocal(cliConfig));\n }\n\n if (isExpo) {\n await traceStep('patch-metro-config', addSentryToExpoMetroConfig);\n } else {\n await traceStep('patch-metro-config', patchMetroWithSentryConfig);\n }\n\n if (isExpo && (await isExpoCNG())) {\n Sentry.setTag('expo-cng', true);\n clack.log.info(\n `Detected Expo Continuous Native Generation (CNG) setup. Skipping native files patching.`,\n );\n } else {\n if (fs.existsSync('ios')) {\n Sentry.setTag('patch-ios', true);\n await traceStep('patch-xcode-files', () => patchXcodeFiles(cliConfig));\n }\n\n if (fs.existsSync('android')) {\n Sentry.setTag('patch-android', true);\n await traceStep('patch-android-files', () =>\n patchAndroidFiles(cliConfig),\n );\n }\n }\n\n await runPrettierIfInstalled({ cwd: undefined });\n\n // Offer optional project-scoped MCP config for Sentry with org and project scope\n await offerProjectScopedMcpConfig(\n selectedProject.organization.slug,\n selectedProject.slug,\n );\n\n const confirmedFirstException = await confirmFirstSentryException(\n sentryUrl,\n orgSlug,\n projectId,\n );\n\n Sentry.setTag('user-confirmed-first-error', confirmedFirstException);\n\n if (confirmedFirstException) {\n clack.outro(\n `${chalk.green('Everything is set up!')}\n\n ${chalk.dim(\n 'If you encounter any issues, let us know here: https://github.com/getsentry/sentry-react-native/issues',\n )}`,\n );\n } else {\n clack.outro(\n `${chalk.dim(\n 'Let us know here: https://github.com/getsentry/sentry-react-native/issues',\n )}`,\n );\n }\n}\n\nasync function confirmFirstSentryException(\n url: string,\n orgSlug: string,\n projectId: string,\n) {\n const issuesStreamUrl = getIssueStreamUrl({ url, orgSlug, projectId });\n\n clack.log\n .step(`To make sure everything is set up correctly, put the following code snippet into your application.\nThe snippet will create a button that, when tapped, sends a test event to Sentry.\n\nAfter that check your project issues:\n\n${chalk.cyan(issuesStreamUrl)}`);\n\n // We want the code snippet to be easily copy-pasteable, without any clack artifacts\n // eslint-disable-next-line no-console\n console.log(\n chalk.greenBright(`\n<Button title='Try!' onPress={ () => { Sentry.captureException(new Error('First error')) }}/>\n`),\n );\n\n const firstErrorConfirmed = clack.confirm({\n message: `Have you successfully sent a test event?`,\n });\n\n return firstErrorConfirmed;\n}\n\nasync function patchXcodeFiles(config: RNCliSetupConfigContent) {\n await addSentryCliConfig(config, {\n ...propertiesCliSetupConfig,\n name: 'source maps and iOS debug files',\n filename: 'ios/sentry.properties',\n gitignore: false,\n });\n\n if (platform() === 'darwin' && (await confirmPodInstall())) {\n await traceStep('pod-install', () => podInstall('ios'));\n }\n\n const xcodeProjectPath = traceStep('find-xcode-project', () =>\n getFirstMatchedPath(XCODE_PROJECT),\n );\n Sentry.setTag(\n 'xcode-project-status',\n xcodeProjectPath ? 'found' : 'not-found',\n );\n if (!xcodeProjectPath) {\n clack.log.warn(\n `Could not find Xcode project file using ${chalk.cyan(XCODE_PROJECT)}.`,\n );\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const [xcodeProject, buildPhasesMap] = traceStep(\n 'parse-xcode-project',\n () => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n const project = xcode.project(xcodeProjectPath);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n project.parseSync();\n\n const map = getValidExistingBuildPhases(project);\n return [project, map];\n },\n );\n Sentry.setTag('xcode-project-status', 'parsed');\n\n await traceStep('patch-bundle-phase', async () => {\n const bundlePhase = findBundlePhase(buildPhasesMap);\n Sentry.setTag(\n 'xcode-bundle-phase-status',\n bundlePhase ? 'found' : 'not-found',\n );\n\n await patchBundlePhase(\n bundlePhase,\n addSentryWithBundledScriptsToBundleShellScript,\n );\n\n Sentry.setTag('xcode-bundle-phase-status', 'patched');\n });\n\n traceStep('add-debug-files-upload-phase', () => {\n const debugFilesUploadPhaseExists =\n !!findDebugFilesUploadPhase(buildPhasesMap);\n Sentry.setTag(\n 'xcode-debug-files-upload-phase-status',\n debugFilesUploadPhaseExists ? 'already-exists' : undefined,\n );\n\n addDebugFilesUploadPhaseWithBundledScripts(xcodeProject, {\n debugFilesUploadPhaseExists,\n });\n\n Sentry.setTag('xcode-debug-files-upload-phase-status', 'added');\n });\n\n traceStep('write-xcode-project', () => {\n writeXcodeProject(xcodeProjectPath, xcodeProject);\n });\n Sentry.setTag('xcode-project-status', 'patched');\n}\n\nasync function patchAndroidFiles(config: RNCliSetupConfigContent) {\n await addSentryCliConfig(config, {\n ...propertiesCliSetupConfig,\n name: 'source maps and iOS debug files',\n filename: 'android/sentry.properties',\n gitignore: false,\n });\n\n const appBuildGradlePath = traceStep('find-app-build-gradle', () =>\n getFirstMatchedPath(APP_BUILD_GRADLE),\n );\n Sentry.setTag(\n 'app-build-gradle-status',\n appBuildGradlePath ? 'found' : 'not-found',\n );\n if (!appBuildGradlePath) {\n clack.log.warn(\n `Could not find Android ${chalk.cyan(\n 'app/build.gradle',\n )} file using ${chalk.cyan(APP_BUILD_GRADLE)}.`,\n );\n return;\n }\n\n const appBuildGradle = traceStep('read-app-build-gradle', () =>\n fs.readFileSync(appBuildGradlePath, 'utf-8'),\n );\n const includesSentry =\n doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle);\n if (includesSentry) {\n Sentry.setTag('app-build-gradle-status', 'already-includes-sentry');\n clack.log.warn(\n `Android ${chalk.cyan('app/build.gradle')} file already includes Sentry.`,\n );\n return;\n }\n\n const patchedAppBuildGradle = traceStep('add-rn-sentry-gradle-plugin', () =>\n addRNSentryGradlePlugin(appBuildGradle),\n );\n if (!doesAppBuildGradleIncludeRNSentryGradlePlugin(patchedAppBuildGradle)) {\n Sentry.setTag(\n 'app-build-gradle-status',\n 'failed-to-add-rn-sentry-gradle-plugin',\n );\n clack.log.warn(\n `Could not add Sentry RN Gradle Plugin to ${chalk.cyan(\n 'app/build.gradle',\n )}.`,\n );\n return;\n }\n\n Sentry.setTag('app-build-gradle-status', 'added-rn-sentry-gradle-plugin');\n clack.log.success(\n `Added Sentry RN Gradle Plugin to ${chalk.bold('app/build.gradle')}.`,\n );\n\n traceStep('write-app-build-gradle', () =>\n writeAppBuildGradle(appBuildGradlePath, patchedAppBuildGradle),\n );\n clack.log.success(\n chalk.green(`Android ${chalk.cyan('app/build.gradle')} saved.`),\n );\n}\n\nasync function confirmPodInstall(): Promise<boolean> {\n return traceStep('confirm-pod-install', async () => {\n const continueWithPodInstall = await abortIfCancelled(\n clack.select({\n message: 'Do you want to run `pod install` now?',\n options: [\n {\n value: true,\n label: 'Yes',\n hint: 'Recommended for smaller projects, this might take several minutes',\n },\n { value: false, label: `No, I'll do it later` },\n ],\n initialValue: true,\n }),\n );\n Sentry.setTag('continue-with-pod-install', continueWithPodInstall);\n return continueWithPodInstall;\n });\n}\n"]}
@@ -1 +1 @@
1
- export declare function instrumentClientEntry(clientEntryPath: string, dsn: string, enableTracing: boolean, enableReplay: boolean, enableLogs: boolean): Promise<void>;
1
+ export declare function instrumentClientEntry(clientEntryPath: string, dsn: string, enableTracing: boolean, enableReplay: boolean, enableLogs: boolean, useInstrumentationAPI?: boolean): Promise<void>;
@@ -38,7 +38,7 @@ const chalk_1 = __importDefault(require("chalk"));
38
38
  const magicast_1 = require("magicast");
39
39
  const ast_utils_1 = require("../../utils/ast-utils");
40
40
  const utils_1 = require("./utils");
41
- async function instrumentClientEntry(clientEntryPath, dsn, enableTracing, enableReplay, enableLogs) {
41
+ async function instrumentClientEntry(clientEntryPath, dsn, enableTracing, enableReplay, enableLogs, useInstrumentationAPI = false) {
42
42
  const clientEntryAst = await (0, magicast_1.loadFile)(clientEntryPath);
43
43
  if ((0, ast_utils_1.hasSentryContent)(clientEntryAst.$ast)) {
44
44
  const filename = path.basename(clientEntryPath);
@@ -50,27 +50,84 @@ async function instrumentClientEntry(clientEntryPath, dsn, enableTracing, enable
50
50
  imported: '*',
51
51
  local: 'Sentry',
52
52
  });
53
- const integrations = [];
54
- if (enableTracing) {
55
- integrations.push('Sentry.reactRouterTracingIntegration()');
56
- }
57
- if (enableReplay) {
58
- integrations.push('Sentry.replayIntegration()');
53
+ let initContent;
54
+ if (useInstrumentationAPI && enableTracing) {
55
+ const integrations = ['tracing'];
56
+ if (enableReplay) {
57
+ integrations.push('Sentry.replayIntegration()');
58
+ }
59
+ initContent = `
60
+ const tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });
61
+
62
+ Sentry.init({
63
+ dsn: "${dsn}",
64
+ sendDefaultPii: true,
65
+ integrations: [${integrations.join(', ')}],
66
+ ${enableLogs ? 'enableLogs: true,' : ''}
67
+ tracesSampleRate: 1.0,
68
+ tracePropagationTargets: [/^\\//, /^https:\\/\\/yourserver\\.io\\/api/],${enableReplay
69
+ ? '\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1.0,'
70
+ : ''}
71
+ });`;
59
72
  }
60
- const initContent = `
73
+ else {
74
+ const integrations = [];
75
+ if (enableTracing) {
76
+ integrations.push('Sentry.reactRouterTracingIntegration()');
77
+ }
78
+ if (enableReplay) {
79
+ integrations.push('Sentry.replayIntegration()');
80
+ }
81
+ initContent = `
61
82
  Sentry.init({
62
83
  dsn: "${dsn}",
63
84
  sendDefaultPii: true,
64
85
  integrations: [${integrations.join(', ')}],
65
86
  ${enableLogs ? 'enableLogs: true,' : ''}
66
87
  tracesSampleRate: ${enableTracing ? '1.0' : '0'},${enableTracing
67
- ? '\n tracePropagationTargets: [/^\\//, /^https:\\/\\/yourserver\\.io\\/api/],'
68
- : ''}${enableReplay
69
- ? '\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1.0,'
70
- : ''}
88
+ ? '\n tracePropagationTargets: [/^\\//, /^https:\\/\\/yourserver\\.io\\/api/],'
89
+ : ''}${enableReplay
90
+ ? '\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1.0,'
91
+ : ''}
71
92
  });`;
93
+ }
72
94
  clientEntryAst.$ast.body.splice((0, utils_1.getAfterImportsInsertionIndex)(clientEntryAst.$ast), 0, ...recast.parse(initContent).program.body);
95
+ if (useInstrumentationAPI && enableTracing) {
96
+ const hydratedRouterFound = addInstrumentationPropsToHydratedRouter(clientEntryAst.$ast);
97
+ if (!hydratedRouterFound) {
98
+ prompts_1.default.log.warn(`Could not find ${chalk_1.default.cyan('HydratedRouter')} component in your client entry file.\n` +
99
+ `To use the Instrumentation API, manually add the ${chalk_1.default.cyan('unstable_instrumentations')} prop:\n` +
100
+ ` ${chalk_1.default.green('<HydratedRouter unstable_instrumentations={[tracing.clientInstrumentation]} />')}`);
101
+ }
102
+ }
73
103
  await (0, magicast_1.writeFile)(clientEntryAst.$ast, clientEntryPath);
74
104
  }
75
105
  exports.instrumentClientEntry = instrumentClientEntry;
106
+ function addInstrumentationPropsToHydratedRouter(ast) {
107
+ let found = false;
108
+ recast.visit(ast, {
109
+ visitJSXElement(path) {
110
+ const openingElement = path.node.openingElement;
111
+ if (openingElement.name.type === 'JSXIdentifier' &&
112
+ openingElement.name.name === 'HydratedRouter') {
113
+ found = true;
114
+ const hasInstrumentationsProp = openingElement.attributes?.some((attr) => attr.type === 'JSXAttribute' &&
115
+ attr.name.type === 'JSXIdentifier' &&
116
+ attr.name.name === 'unstable_instrumentations');
117
+ if (!hasInstrumentationsProp) {
118
+ const instrumentationsProp = recast.types.builders.jsxAttribute(recast.types.builders.jsxIdentifier('unstable_instrumentations'), recast.types.builders.jsxExpressionContainer(recast.types.builders.arrayExpression([
119
+ recast.types.builders.memberExpression(recast.types.builders.identifier('tracing'), recast.types.builders.identifier('clientInstrumentation')),
120
+ ])));
121
+ if (!openingElement.attributes) {
122
+ openingElement.attributes = [];
123
+ }
124
+ openingElement.attributes.push(instrumentationsProp);
125
+ }
126
+ return false;
127
+ }
128
+ this.traverse(path);
129
+ },
130
+ });
131
+ return found;
132
+ }
76
133
  //# sourceMappingURL=client.entry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.entry.js","sourceRoot":"","sources":["../../../../src/react-router/codemods/client.entry.ts"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,+DAA+D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE/D,+CAAiC;AACjC,2CAA6B;AAG7B,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAE1B,kFAAkF;AAClF,uCAA+C;AAC/C,qDAAyD;AACzD,mCAAwD;AAEjD,KAAK,UAAU,qBAAqB,CACzC,eAAuB,EACvB,GAAW,EACX,aAAsB,EACtB,YAAqB,EACrB,UAAmB;IAEnB,MAAM,cAAc,GAAG,MAAM,IAAA,mBAAQ,EAAC,eAAe,CAAC,CAAC;IAEvD,IAAI,IAAA,4BAAgB,EAAC,cAAc,CAAC,IAAiB,CAAC,EAAE;QACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QAChD,iBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,kCAAkC,eAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACzE,OAAO;KACR;IAED,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC;QAC1B,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE,GAAG;QACb,KAAK,EAAE,QAAQ;KAChB,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,IAAI,aAAa,EAAE;QACjB,YAAY,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;KAC7D;IACD,IAAI,YAAY,EAAE;QAChB,YAAY,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;KACjD;IAED,MAAM,WAAW,GAAG;;UAEZ,GAAG;;mBAEM,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;IACtC,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE;sBACnB,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAC7C,aAAa;QACX,CAAC,CAAC,8EAA8E;QAChF,CAAC,CAAC,EACN,GACE,YAAY;QACV,CAAC,CAAC,sEAAsE;QACxE,CAAC,CAAC,EACN;IACE,CAAC;IAEF,cAAc,CAAC,IAAkB,CAAC,IAAI,CAAC,MAAM,CAC5C,IAAA,qCAA6B,EAAC,cAAc,CAAC,IAAiB,CAAC,EAC/D,CAAC,EACD,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,IAAI,CAC1C,CAAC;IAEF,MAAM,IAAA,oBAAS,EAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AACxD,CAAC;AArDD,sDAqDC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n\nimport * as recast from 'recast';\nimport * as path from 'path';\nimport type { namedTypes as t } from 'ast-types';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { loadFile, writeFile } from 'magicast';\nimport { hasSentryContent } from '../../utils/ast-utils';\nimport { getAfterImportsInsertionIndex } from './utils';\n\nexport async function instrumentClientEntry(\n clientEntryPath: string,\n dsn: string,\n enableTracing: boolean,\n enableReplay: boolean,\n enableLogs: boolean,\n): Promise<void> {\n const clientEntryAst = await loadFile(clientEntryPath);\n\n if (hasSentryContent(clientEntryAst.$ast as t.Program)) {\n const filename = path.basename(clientEntryPath);\n clack.log.info(`Sentry initialization found in ${chalk.cyan(filename)}`);\n return;\n }\n\n clientEntryAst.imports.$add({\n from: '@sentry/react-router',\n imported: '*',\n local: 'Sentry',\n });\n\n const integrations = [];\n if (enableTracing) {\n integrations.push('Sentry.reactRouterTracingIntegration()');\n }\n if (enableReplay) {\n integrations.push('Sentry.replayIntegration()');\n }\n\n const initContent = `\nSentry.init({\n dsn: \"${dsn}\",\n sendDefaultPii: true,\n integrations: [${integrations.join(', ')}],\n ${enableLogs ? 'enableLogs: true,' : ''}\n tracesSampleRate: ${enableTracing ? '1.0' : '0'},${\n enableTracing\n ? '\\n tracePropagationTargets: [/^\\\\//, /^https:\\\\/\\\\/yourserver\\\\.io\\\\/api/],'\n : ''\n }${\n enableReplay\n ? '\\n replaysSessionSampleRate: 0.1,\\n replaysOnErrorSampleRate: 1.0,'\n : ''\n }\n});`;\n\n (clientEntryAst.$ast as t.Program).body.splice(\n getAfterImportsInsertionIndex(clientEntryAst.$ast as t.Program),\n 0,\n ...recast.parse(initContent).program.body,\n );\n\n await writeFile(clientEntryAst.$ast, clientEntryPath);\n}\n"]}
1
+ {"version":3,"file":"client.entry.js","sourceRoot":"","sources":["../../../../src/react-router/codemods/client.entry.ts"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,+DAA+D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE/D,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AAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n\nimport * as recast from 'recast';\nimport * as path from 'path';\nimport type { namedTypes as t } from 'ast-types';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { loadFile, writeFile } from 'magicast';\nimport { hasSentryContent } from '../../utils/ast-utils';\nimport { getAfterImportsInsertionIndex } from './utils';\n\nexport async function instrumentClientEntry(\n clientEntryPath: string,\n dsn: string,\n enableTracing: boolean,\n enableReplay: boolean,\n enableLogs: boolean,\n useInstrumentationAPI = false,\n): Promise<void> {\n const clientEntryAst = await loadFile(clientEntryPath);\n\n if (hasSentryContent(clientEntryAst.$ast as t.Program)) {\n const filename = path.basename(clientEntryPath);\n clack.log.info(`Sentry initialization found in ${chalk.cyan(filename)}`);\n return;\n }\n\n clientEntryAst.imports.$add({\n from: '@sentry/react-router',\n imported: '*',\n local: 'Sentry',\n });\n\n let initContent: string;\n\n if (useInstrumentationAPI && enableTracing) {\n const integrations = ['tracing'];\n if (enableReplay) {\n integrations.push('Sentry.replayIntegration()');\n }\n\n initContent = `\nconst tracing = Sentry.reactRouterTracingIntegration({ useInstrumentationAPI: true });\n\nSentry.init({\n dsn: \"${dsn}\",\n sendDefaultPii: true,\n integrations: [${integrations.join(', ')}],\n ${enableLogs ? 'enableLogs: true,' : ''}\n tracesSampleRate: 1.0,\n tracePropagationTargets: [/^\\\\//, /^https:\\\\/\\\\/yourserver\\\\.io\\\\/api/],${\n enableReplay\n ? '\\n replaysSessionSampleRate: 0.1,\\n replaysOnErrorSampleRate: 1.0,'\n : ''\n }\n});`;\n } else {\n const integrations = [];\n if (enableTracing) {\n integrations.push('Sentry.reactRouterTracingIntegration()');\n }\n if (enableReplay) {\n integrations.push('Sentry.replayIntegration()');\n }\n\n initContent = `\nSentry.init({\n dsn: \"${dsn}\",\n sendDefaultPii: true,\n integrations: [${integrations.join(', ')}],\n ${enableLogs ? 'enableLogs: true,' : ''}\n tracesSampleRate: ${enableTracing ? '1.0' : '0'},${\n enableTracing\n ? '\\n tracePropagationTargets: [/^\\\\//, /^https:\\\\/\\\\/yourserver\\\\.io\\\\/api/],'\n : ''\n }${\n enableReplay\n ? '\\n replaysSessionSampleRate: 0.1,\\n replaysOnErrorSampleRate: 1.0,'\n : ''\n }\n});`;\n }\n\n (clientEntryAst.$ast as t.Program).body.splice(\n getAfterImportsInsertionIndex(clientEntryAst.$ast as t.Program),\n 0,\n ...recast.parse(initContent).program.body,\n );\n\n if (useInstrumentationAPI && enableTracing) {\n const hydratedRouterFound = addInstrumentationPropsToHydratedRouter(\n clientEntryAst.$ast as t.Program,\n );\n\n if (!hydratedRouterFound) {\n clack.log.warn(\n `Could not find ${chalk.cyan(\n 'HydratedRouter',\n )} component in your client entry file.\\n` +\n `To use the Instrumentation API, manually add the ${chalk.cyan(\n 'unstable_instrumentations',\n )} prop:\\n` +\n ` ${chalk.green(\n '<HydratedRouter unstable_instrumentations={[tracing.clientInstrumentation]} />',\n )}`,\n );\n }\n }\n\n await writeFile(clientEntryAst.$ast, clientEntryPath);\n}\n\nfunction addInstrumentationPropsToHydratedRouter(ast: t.Program): boolean {\n let found = false;\n\n recast.visit(ast, {\n visitJSXElement(path) {\n const openingElement = path.node.openingElement;\n\n if (\n openingElement.name.type === 'JSXIdentifier' &&\n openingElement.name.name === 'HydratedRouter'\n ) {\n found = true;\n\n const hasInstrumentationsProp = openingElement.attributes?.some(\n (attr) =>\n attr.type === 'JSXAttribute' &&\n attr.name.type === 'JSXIdentifier' &&\n attr.name.name === 'unstable_instrumentations',\n );\n\n if (!hasInstrumentationsProp) {\n const instrumentationsProp = recast.types.builders.jsxAttribute(\n recast.types.builders.jsxIdentifier('unstable_instrumentations'),\n recast.types.builders.jsxExpressionContainer(\n recast.types.builders.arrayExpression([\n recast.types.builders.memberExpression(\n recast.types.builders.identifier('tracing'),\n recast.types.builders.identifier('clientInstrumentation'),\n ),\n ]),\n ),\n );\n\n if (!openingElement.attributes) {\n openingElement.attributes = [];\n }\n openingElement.attributes.push(instrumentationsProp);\n }\n\n return false;\n }\n\n this.traverse(path);\n },\n });\n\n return found;\n}\n"]}
@@ -170,7 +170,7 @@ export default {
170
170
  if (!success) {
171
171
  throw new Error('Failed to modify React Router config structure');
172
172
  }
173
- const code = (0, magicast_1.generateCode)(mod.$ast).code;
173
+ const code = (0, ast_utils_1.preserveTrailingNewline)(configContent, (0, magicast_1.generateCode)(mod.$ast).code);
174
174
  await fs.promises.writeFile(configPath, code);
175
175
  return { ssrWasChanged };
176
176
  }
@@ -1 +1 @@
1
- {"version":3,"file":"react-router-config.js","sourceRoot":"","sources":["../../../../src/react-router/codemods/react-router-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AACjC,2CAA6B;AAC7B,uCAAyB;AAEzB,kFAAkF;AAClF,uCAAqD;AAErD,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAE1B,qDAAqD;AAErD;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,WAAyC;IAEzC,IAAI,WAAW,CAAC,IAAI,KAAK,kBAAkB,EAAE;QAC3C,OAAO,WAAiC,CAAC;KAC1C;IAED,IACE,WAAW,CAAC,IAAI,KAAK,uBAAuB;QAC5C,WAAW,CAAC,IAAI,KAAK,gBAAgB,EACrC;QACA,MAAM,IAAI,GAAI,WAA0D;aACrE,UAAU,CAAC;QACd,OAAO,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;KAC5D;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,SAAS,wBAAwB,CAAC,IAAY;IAC5C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAA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C,IAAI,2BAA2B,CAAC,GAAG,CAAC,IAAiB,CAAC,EAAE;QACtD,iBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,QAAQ,qCAAqC,CAAC,CAAC;QACjE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;KACjC;IAED,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE,kBAAkB;QAC5B,KAAK,EAAE,kBAAkB;KAC1B,CAAC,CAAC;IAEH,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,oCAAoC,CACrE,GAAG,CAAC,IAAiB,CACtB,CAAC;IAEF,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;KACnE;IAED,MAAM,IAAI,GAAG,IAAA,uBAAY,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;IACzC,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAE9C,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC;AA3DD,kEA2DC","sourcesContent":["import type { namedTypes as t } from 'ast-types';\nimport * as recast from 'recast';\nimport * as path from 'path';\nimport * as fs from 'fs';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { parseModule, generateCode } from 'magicast';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport { findProperty } from '../../utils/ast-utils';\n\n/**\n * Extracts the ObjectExpression from various export patterns.\n * Supports: direct object, `satisfies Config`, and `as Config` patterns.\n */\nfunction extractConfigObject(\n declaration: t.Declaration | t.Expression,\n): t.ObjectExpression | undefined {\n if (declaration.type === 'ObjectExpression') {\n return declaration as t.ObjectExpression;\n }\n\n if (\n declaration.type === 'TSSatisfiesExpression' ||\n declaration.type === 'TSAsExpression'\n ) {\n const expr = (declaration as t.TSSatisfiesExpression | t.TSAsExpression)\n .expression;\n return expr.type === 'ObjectExpression' ? expr : undefined;\n }\n\n return undefined;\n}\n\n/**\n * Creates an identifier property for object literals.\n */\nfunction createIdentifierProperty(name: string): t.Property {\n const b = recast.types.builders;\n return b.property('init', b.identifier(name), b.identifier(name));\n}\n\nexport function addSentryBuildEndToReactRouterConfig(program: t.Program): {\n success: boolean;\n ssrWasChanged: boolean;\n} {\n const b = recast.types.builders;\n let ssrWasChanged = false;\n\n const defaultExport = program.body.find(\n (node) => node.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration | undefined;\n\n if (!defaultExport) {\n return { success: false, ssrWasChanged: false };\n }\n\n const configObj = extractConfigObject(defaultExport.declaration);\n\n if (!configObj) {\n return { success: false, ssrWasChanged: false };\n }\n\n const buildEndProp = findProperty(configObj, 'buildEnd');\n\n if (buildEndProp) {\n throw new Error(\n 'A buildEnd hook already exists in your React Router config.',\n );\n }\n\n const ssrProp = findProperty(configObj, 'ssr');\n\n if (!ssrProp) {\n const ssrProperty = b.objectProperty(\n b.identifier('ssr'),\n b.booleanLiteral(true),\n );\n ssrProperty.comments = [\n {\n type: 'CommentLine',\n value:\n ' SSR is required for Sentry sourcemap uploads to work correctly',\n } as any, // eslint-disable-line @typescript-eslint/no-explicit-any\n ];\n configObj.properties.unshift(ssrProperty);\n ssrWasChanged = true;\n } else if (\n ssrProp.value.type === 'BooleanLiteral' ||\n ssrProp.value.type === 'Literal'\n ) {\n const wasExplicitlyFalse = ssrProp.value.value === false;\n\n if (wasExplicitlyFalse) {\n ssrWasChanged = true;\n }\n\n ssrProp.value = b.booleanLiteral(true);\n\n if (wasExplicitlyFalse) {\n ssrProp.comments = [\n {\n type: 'CommentLine',\n value:\n ' Changed to true - SSR is required for Sentry sourcemap uploads',\n } as any, // eslint-disable-line @typescript-eslint/no-explicit-any\n ];\n }\n }\n\n const paramNames = ['viteConfig', 'reactRouterConfig', 'buildManifest'];\n\n const buildEndFunction = b.arrowFunctionExpression(\n [b.objectPattern(paramNames.map(createIdentifierProperty))],\n b.blockStatement([\n b.expressionStatement(\n b.awaitExpression(\n b.callExpression(b.identifier('sentryOnBuildEnd'), [\n b.objectExpression(paramNames.map(createIdentifierProperty)),\n ]),\n ),\n ),\n ]),\n );\n buildEndFunction.async = true;\n\n configObj.properties.push(\n b.objectProperty(b.identifier('buildEnd'), buildEndFunction),\n );\n\n return { success: true, ssrWasChanged };\n}\n\nexport function hasReactRouterSentryContent(program: t.Program): boolean {\n let hasSentry = false;\n\n recast.visit(program, {\n visitIdentifier(path) {\n if (path.node.name === 'sentryOnBuildEnd') {\n hasSentry = true;\n return false; // stop traversal\n }\n this.traverse(path);\n },\n });\n\n return hasSentry;\n}\n\nexport async function instrumentReactRouterConfig(\n isTS: boolean,\n): Promise<{ ssrWasChanged: boolean }> {\n const configFilename = `react-router.config.${isTS ? 'ts' : 'js'}`;\n const configPath = path.join(process.cwd(), configFilename);\n\n if (!fs.existsSync(configPath)) {\n const defaultConfig = isTS\n ? `import type { Config } from \"@react-router/dev/config\";\nimport { sentryOnBuildEnd } from \"@sentry/react-router\";\n\nexport default {\n ssr: true,\n buildEnd: async ({ viteConfig, reactRouterConfig, buildManifest }) => {\n await sentryOnBuildEnd({ viteConfig, reactRouterConfig, buildManifest });\n },\n} satisfies Config;\n`\n : `import { sentryOnBuildEnd } from \"@sentry/react-router\";\n\nexport default {\n ssr: true,\n buildEnd: async ({ viteConfig, reactRouterConfig, buildManifest }) => {\n await sentryOnBuildEnd({ viteConfig, reactRouterConfig, buildManifest });\n },\n};\n`;\n await fs.promises.writeFile(configPath, defaultConfig);\n return { ssrWasChanged: false };\n }\n\n const configContent = await fs.promises.readFile(configPath, 'utf-8');\n const filename = chalk.cyan(configFilename);\n\n const mod = parseModule(configContent);\n\n if (hasReactRouterSentryContent(mod.$ast as t.Program)) {\n clack.log.info(`${filename} already contains sentryOnBuildEnd.`);\n return { ssrWasChanged: false };\n }\n\n mod.imports.$add({\n from: '@sentry/react-router',\n imported: 'sentryOnBuildEnd',\n local: 'sentryOnBuildEnd',\n });\n\n const { success, ssrWasChanged } = addSentryBuildEndToReactRouterConfig(\n mod.$ast as t.Program,\n );\n\n if (!success) {\n throw new Error('Failed to modify React Router config structure');\n }\n\n const code = generateCode(mod.$ast).code;\n await fs.promises.writeFile(configPath, code);\n\n return { ssrWasChanged };\n}\n"]}
1
+ {"version":3,"file":"react-router-config.js","sourceRoot":"","sources":["../../../../src/react-router/codemods/react-router-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AACjC,2CAA6B;AAC7B,uCAAyB;AAEzB,kFAAkF;AAClF,uCAAqD;AAErD,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAE1B,qDAA8E;AAE9E;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,WAAyC;IAEzC,IAAI,WAAW,CAAC,IAAI,KAAK,kBAAkB,EAAE;QAC3C,OAAO,WAAiC,CAAC;KAC1C;IAED,IACE,WAAW,CAAC,IAAI,KAAK,uBAAuB;QAC5C,WAAW,CAAC,IAAI,KAAK,gBAAgB,EACrC;QACA,MAAM,IAAI,GAAI,WAA0D;aACrE,UAAU,CAAC;QACd,OAAO,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;KAC5D;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,SAAS,wBAAwB,CAAC,IAAY;IAC5C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;IAChC,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,SAAgB,oCAAoC,CAAC,OAAkB;IAIrE,MAAM,CAAC,GAA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C;QACf,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE,kBAAkB;QAC5B,KAAK,EAAE,kBAAkB;KAC1B,CAAC,CAAC;IAEH,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,oCAAoC,CACrE,GAAG,CAAC,IAAiB,CACtB,CAAC;IAEF,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;KACnE;IAED,MAAM,IAAI,GAAG,IAAA,mCAAuB,EAClC,aAAa,EACb,IAAA,uBAAY,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAC5B,CAAC;IACF,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAE9C,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC;AA9DD,kEA8DC","sourcesContent":["import type { namedTypes as t } from 'ast-types';\nimport * as recast from 'recast';\nimport * as path from 'path';\nimport * as fs from 'fs';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { parseModule, generateCode } from 'magicast';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport { findProperty, preserveTrailingNewline } from '../../utils/ast-utils';\n\n/**\n * Extracts the ObjectExpression from various export patterns.\n * Supports: direct object, `satisfies Config`, and `as Config` patterns.\n */\nfunction extractConfigObject(\n declaration: t.Declaration | t.Expression,\n): t.ObjectExpression | undefined {\n if (declaration.type === 'ObjectExpression') {\n return declaration as t.ObjectExpression;\n }\n\n if (\n declaration.type === 'TSSatisfiesExpression' ||\n declaration.type === 'TSAsExpression'\n ) {\n const expr = (declaration as t.TSSatisfiesExpression | t.TSAsExpression)\n .expression;\n return expr.type === 'ObjectExpression' ? expr : undefined;\n }\n\n return undefined;\n}\n\n/**\n * Creates an identifier property for object literals.\n */\nfunction createIdentifierProperty(name: string): t.Property {\n const b = recast.types.builders;\n return b.property('init', b.identifier(name), b.identifier(name));\n}\n\nexport function addSentryBuildEndToReactRouterConfig(program: t.Program): {\n success: boolean;\n ssrWasChanged: boolean;\n} {\n const b = recast.types.builders;\n let ssrWasChanged = false;\n\n const defaultExport = program.body.find(\n (node) => node.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration | undefined;\n\n if (!defaultExport) {\n return { success: false, ssrWasChanged: false };\n }\n\n const configObj = extractConfigObject(defaultExport.declaration);\n\n if (!configObj) {\n return { success: false, ssrWasChanged: false };\n }\n\n const buildEndProp = findProperty(configObj, 'buildEnd');\n\n if (buildEndProp) {\n throw new Error(\n 'A buildEnd hook already exists in your React Router config.',\n );\n }\n\n const ssrProp = findProperty(configObj, 'ssr');\n\n if (!ssrProp) {\n const ssrProperty = b.objectProperty(\n b.identifier('ssr'),\n b.booleanLiteral(true),\n );\n ssrProperty.comments = [\n {\n type: 'CommentLine',\n value:\n ' SSR is required for Sentry sourcemap uploads to work correctly',\n } as any, // eslint-disable-line @typescript-eslint/no-explicit-any\n ];\n configObj.properties.unshift(ssrProperty);\n ssrWasChanged = true;\n } else if (\n ssrProp.value.type === 'BooleanLiteral' ||\n ssrProp.value.type === 'Literal'\n ) {\n const wasExplicitlyFalse = ssrProp.value.value === false;\n\n if (wasExplicitlyFalse) {\n ssrWasChanged = true;\n }\n\n ssrProp.value = b.booleanLiteral(true);\n\n if (wasExplicitlyFalse) {\n ssrProp.comments = [\n {\n type: 'CommentLine',\n value:\n ' Changed to true - SSR is required for Sentry sourcemap uploads',\n } as any, // eslint-disable-line @typescript-eslint/no-explicit-any\n ];\n }\n }\n\n const paramNames = ['viteConfig', 'reactRouterConfig', 'buildManifest'];\n\n const buildEndFunction = b.arrowFunctionExpression(\n [b.objectPattern(paramNames.map(createIdentifierProperty))],\n b.blockStatement([\n b.expressionStatement(\n b.awaitExpression(\n b.callExpression(b.identifier('sentryOnBuildEnd'), [\n b.objectExpression(paramNames.map(createIdentifierProperty)),\n ]),\n ),\n ),\n ]),\n );\n buildEndFunction.async = true;\n\n configObj.properties.push(\n b.objectProperty(b.identifier('buildEnd'), buildEndFunction),\n );\n\n return { success: true, ssrWasChanged };\n}\n\nexport function hasReactRouterSentryContent(program: t.Program): boolean {\n let hasSentry = false;\n\n recast.visit(program, {\n visitIdentifier(path) {\n if (path.node.name === 'sentryOnBuildEnd') {\n hasSentry = true;\n return false; // stop traversal\n }\n this.traverse(path);\n },\n });\n\n return hasSentry;\n}\n\nexport async function instrumentReactRouterConfig(\n isTS: boolean,\n): Promise<{ ssrWasChanged: boolean }> {\n const configFilename = `react-router.config.${isTS ? 'ts' : 'js'}`;\n const configPath = path.join(process.cwd(), configFilename);\n\n if (!fs.existsSync(configPath)) {\n const defaultConfig = isTS\n ? `import type { Config } from \"@react-router/dev/config\";\nimport { sentryOnBuildEnd } from \"@sentry/react-router\";\n\nexport default {\n ssr: true,\n buildEnd: async ({ viteConfig, reactRouterConfig, buildManifest }) => {\n await sentryOnBuildEnd({ viteConfig, reactRouterConfig, buildManifest });\n },\n} satisfies Config;\n`\n : `import { sentryOnBuildEnd } from \"@sentry/react-router\";\n\nexport default {\n ssr: true,\n buildEnd: async ({ viteConfig, reactRouterConfig, buildManifest }) => {\n await sentryOnBuildEnd({ viteConfig, reactRouterConfig, buildManifest });\n },\n};\n`;\n await fs.promises.writeFile(configPath, defaultConfig);\n return { ssrWasChanged: false };\n }\n\n const configContent = await fs.promises.readFile(configPath, 'utf-8');\n const filename = chalk.cyan(configFilename);\n\n const mod = parseModule(configContent);\n\n if (hasReactRouterSentryContent(mod.$ast as t.Program)) {\n clack.log.info(`${filename} already contains sentryOnBuildEnd.`);\n return { ssrWasChanged: false };\n }\n\n mod.imports.$add({\n from: '@sentry/react-router',\n imported: 'sentryOnBuildEnd',\n local: 'sentryOnBuildEnd',\n });\n\n const { success, ssrWasChanged } = addSentryBuildEndToReactRouterConfig(\n mod.$ast as t.Program,\n );\n\n if (!success) {\n throw new Error('Failed to modify React Router config structure');\n }\n\n const code = preserveTrailingNewline(\n configContent,\n generateCode(mod.$ast).code,\n );\n await fs.promises.writeFile(configPath, code);\n\n return { ssrWasChanged };\n}\n"]}
@@ -51,8 +51,7 @@ function hasCaptureExceptionCall(node) {
51
51
  return found;
52
52
  }
53
53
  function addCaptureExceptionCall(functionNode) {
54
- const captureExceptionCall = recast.parse(`Sentry.captureException(error);`)
55
- .program.body[0];
54
+ const captureExceptionCall = recast.parse(`if (error && error instanceof Error) {\n Sentry.captureException(error);\n}`).program.body[0];
56
55
  const functionBody = (0, ast_utils_1.safeGetFunctionBody)(functionNode);
57
56
  if (functionBody) {
58
57
  if (!(0, ast_utils_1.safeInsertBeforeReturn)(functionBody, captureExceptionCall)) {
@@ -1 +1 @@
1
- {"version":3,"file":"root.js","sourceRoot":"","sources":["../../../../src/react-router/codemods/root.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,sDAAsD;AACtD,0DAA0D;AAC1D,+CAAiC;AACjC,2CAA6B;AAK7B,uCAIkB;AAElB,4CAAuD;AACvD,qDAI+B;AAC/B,6CAA0C;AAE1C,SAAS,uBAAuB,CAAC,IAAY;IAC3C,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE;QACjB,mBAAmB,CAAC,IAAI;YACtB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YACjC,IACE,CAAC,MAAM,CAAC,IAAI,KAAK,kBAAkB;gBACjC,MAAM,CAAC,MAAM,EAAE,IAAI,KAAK,QAAQ;gBAChC,MAAM,CAAC,QAAQ,EAAE,IAAI,KAAK,kBAAkB,CAAC;gBAC/C,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,MAAM,CAAC,IAAI,KAAK,kBAAkB,CAAC,EACpE;gBACA,KAAK,GAAG,IAAI,CAAC;aACd;YACD,IAAI,CAAC,QAAQ,C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,CAAC,uBAAuB,CAAC,oBAAoB,CAAC,EAC9C;oBACA,uBAAuB,CAAC,oBAAoB,CAAC,CAAC;iBAC/C;gBAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;YAED,wBAAwB,CAAC,IAAI;gBAC3B,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,KAAK,eAAe,EAAE;oBAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;oBAC7C,IACE,IAAI;wBACJ,CAAC,IAAI,CAAC,IAAI,KAAK,oBAAoB;4BACjC,IAAI,CAAC,IAAI,KAAK,yBAAyB,CAAC;wBAC1C,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAC9B;wBACA,uBAAuB,CAAC,IAAI,CAAC,CAAC;qBAC/B;iBACF;gBACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;YAED,wBAAwB,CAAC,IAAI;gBAC3B,IACE,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,KAAK,eAAe;oBACvC,CAAC,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,EACpC;oBACA,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACrC;gBACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;SACF,CAAC,CAAC;KACJ;IAED,MAAM,IAAA,oBAAS,EAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAnHD,wCAmHC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\nimport * as recast from 'recast';\nimport * as path from 'path';\n\nimport type { ExportNamedDeclaration } from '@babel/types';\nimport type { namedTypes as t } from 'ast-types';\n\nimport {\n loadFile,\n writeFile,\n // @ts-expect-error - magicast is ESM and TS complains about that. It works though\n} from 'magicast';\n\nimport { ERROR_BOUNDARY_TEMPLATE } from '../templates';\nimport {\n hasSentryContent,\n safeGetFunctionBody,\n safeInsertBeforeReturn,\n} from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\nfunction hasCaptureExceptionCall(node: t.Node): boolean {\n let found = false;\n recast.visit(node, {\n visitCallExpression(path) {\n const callee = path.value.callee;\n if (\n (callee.type === 'MemberExpression' &&\n callee.object?.name === 'Sentry' &&\n callee.property?.name === 'captureException') ||\n (callee.type === 'Identifier' && callee.name === 'captureException')\n ) {\n found = true;\n }\n this.traverse(path);\n },\n });\n return found;\n}\n\nfunction addCaptureExceptionCall(functionNode: t.Node): void {\n const captureExceptionCall = recast.parse(`Sentry.captureException(error);`)\n .program.body[0];\n\n const functionBody = safeGetFunctionBody(functionNode);\n if (functionBody) {\n if (!safeInsertBeforeReturn(functionBody, captureExceptionCall)) {\n functionBody.push(captureExceptionCall);\n }\n } else {\n debug('Could not safely access ErrorBoundary function body');\n }\n}\n\nfunction findErrorBoundaryInExports(\n namedExports: ExportNamedDeclaration[],\n): boolean {\n return namedExports.some((namedExport) => {\n const declaration = namedExport.declaration;\n\n if (!declaration) {\n return namedExport.specifiers?.some(\n (spec) =>\n spec.type === 'ExportSpecifier' &&\n spec.exported?.type === 'Identifier' &&\n spec.exported.name === 'ErrorBoundary',\n );\n }\n\n if (declaration.type === 'FunctionDeclaration') {\n return declaration.id?.name === 'ErrorBoundary';\n }\n\n if (declaration.type === 'VariableDeclaration') {\n return declaration.declarations.some((decl) => {\n // @ts-expect-error - id should always have a name in this case\n return decl.id?.name === 'ErrorBoundary';\n });\n }\n\n return false;\n });\n}\n\nexport async function instrumentRoot(rootFileName: string): Promise<void> {\n const filePath = path.join(process.cwd(), 'app', rootFileName);\n const rootRouteAst = await loadFile(filePath);\n\n const exportsAst = rootRouteAst.exports.$ast as t.Program;\n const namedExports = exportsAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n const foundErrorBoundary = findErrorBoundaryInExports(namedExports);\n const alreadyHasSentry = hasSentryContent(rootRouteAst.$ast as t.Program);\n\n if (!alreadyHasSentry) {\n rootRouteAst.imports.$add({\n from: '@sentry/react-router',\n imported: '*',\n local: 'Sentry',\n });\n }\n\n if (!foundErrorBoundary) {\n const hasIsRouteErrorResponseImport = rootRouteAst.imports.$items.some(\n (item) =>\n item.imported === 'isRouteErrorResponse' &&\n item.from === 'react-router',\n );\n\n if (!hasIsRouteErrorResponseImport) {\n rootRouteAst.imports.$add({\n from: 'react-router',\n imported: 'isRouteErrorResponse',\n local: 'isRouteErrorResponse',\n });\n }\n\n recast.visit(rootRouteAst.$ast, {\n visitExportDefaultDeclaration(path) {\n const implementation = recast.parse(ERROR_BOUNDARY_TEMPLATE).program\n .body[0];\n\n path.insertBefore(\n recast.types.builders.exportDeclaration(false, implementation),\n );\n\n this.traverse(path);\n },\n });\n } else {\n recast.visit(rootRouteAst.$ast, {\n visitExportNamedDeclaration(path) {\n const declaration = path.value.declaration;\n if (!declaration) {\n this.traverse(path);\n return;\n }\n\n let functionToInstrument = null;\n\n if (\n declaration.type === 'FunctionDeclaration' &&\n declaration.id?.name === 'ErrorBoundary'\n ) {\n functionToInstrument = declaration;\n } else if (\n declaration.type === 'VariableDeclaration' &&\n declaration.declarations?.[0]?.id?.name === 'ErrorBoundary'\n ) {\n const init = declaration.declarations[0].init;\n if (\n init &&\n (init.type === 'FunctionExpression' ||\n init.type === 'ArrowFunctionExpression')\n ) {\n functionToInstrument = init;\n }\n }\n\n if (\n functionToInstrument &&\n !hasCaptureExceptionCall(functionToInstrument)\n ) {\n addCaptureExceptionCall(functionToInstrument);\n }\n\n this.traverse(path);\n },\n\n visitVariableDeclaration(path) {\n if (path.value.declarations?.[0]?.id?.name === 'ErrorBoundary') {\n const init = path.value.declarations[0].init;\n if (\n init &&\n (init.type === 'FunctionExpression' ||\n init.type === 'ArrowFunctionExpression') &&\n !hasCaptureExceptionCall(init)\n ) {\n addCaptureExceptionCall(init);\n }\n }\n this.traverse(path);\n },\n\n visitFunctionDeclaration(path) {\n if (\n path.value.id?.name === 'ErrorBoundary' &&\n !hasCaptureExceptionCall(path.value)\n ) {\n addCaptureExceptionCall(path.value);\n }\n this.traverse(path);\n },\n });\n }\n\n await writeFile(rootRouteAst.$ast, filePath);\n}\n"]}
1
+ {"version":3,"file":"root.js","sourceRoot":"","sources":["../../../../src/react-router/codemods/root.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,sDAAsD;AACtD,0DAA0D;AAC1D,+CAAiC;AACjC,2CAA6B;AAK7B,uCAIkB;AAElB,4CAAuD;AACvD,qDAI+B;AAC/B,6CAA0C;AAE1C,SAAS,uBAAuB,CAAC,IAAY;IAC3C,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE;QACjB,mBAAmB,CAAC,IAAI;YACtB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YACjC,IACE,CAAC,MAAM,CAAC,IAAI,KAAK,kBAAkB;gBACjC,MAAM,CAAC,MAAM,EAAE,IAAI,KAAK,QAAQ;gBAChC,MAAM,CAAC,QAAQ,EAAE,IAAI,KAAK,kBAAkB,CAAC;gBAC/C,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,MAAM,CAAC,IAAI,KAAK,kBAAkB,CAAC,EACpE;gBACA,KAAK,GAAG,IAAI,CAAC;aACd;YACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,uBAAuB,CAAC,YAAoB;IACn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C,IAAI,CAAC,CAAC;YACtB,CAAC;YAED,wBAAwB,CAAC,IAAI;gBAC3B,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,KAAK,eAAe,EAAE;oBAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;oBAC7C,IACE,IAAI;wBACJ,CAAC,IAAI,CAAC,IAAI,KAAK,oBAAoB;4BACjC,IAAI,CAAC,IAAI,KAAK,yBAAyB,CAAC;wBAC1C,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAC9B;wBACA,uBAAuB,CAAC,IAAI,CAAC,CAAC;qBAC/B;iBACF;gBACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;YAED,wBAAwB,CAAC,IAAI;gBAC3B,IACE,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,KAAK,eAAe;oBACvC,CAAC,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,EACpC;oBACA,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACrC;gBACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;SACF,CAAC,CAAC;KACJ;IAED,MAAM,IAAA,oBAAS,EAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAnHD,wCAmHC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\nimport * as recast from 'recast';\nimport * as path from 'path';\n\nimport type { ExportNamedDeclaration } from '@babel/types';\nimport type { namedTypes as t } from 'ast-types';\n\nimport {\n loadFile,\n writeFile,\n // @ts-expect-error - magicast is ESM and TS complains about that. It works though\n} from 'magicast';\n\nimport { ERROR_BOUNDARY_TEMPLATE } from '../templates';\nimport {\n hasSentryContent,\n safeGetFunctionBody,\n safeInsertBeforeReturn,\n} from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\nfunction hasCaptureExceptionCall(node: t.Node): boolean {\n let found = false;\n recast.visit(node, {\n visitCallExpression(path) {\n const callee = path.value.callee;\n if (\n (callee.type === 'MemberExpression' &&\n callee.object?.name === 'Sentry' &&\n callee.property?.name === 'captureException') ||\n (callee.type === 'Identifier' && callee.name === 'captureException')\n ) {\n found = true;\n }\n this.traverse(path);\n },\n });\n return found;\n}\n\nfunction addCaptureExceptionCall(functionNode: t.Node): void {\n const captureExceptionCall = recast.parse(\n `if (error && error instanceof Error) {\\n Sentry.captureException(error);\\n}`,\n ).program.body[0];\n\n const functionBody = safeGetFunctionBody(functionNode);\n if (functionBody) {\n if (!safeInsertBeforeReturn(functionBody, captureExceptionCall)) {\n functionBody.push(captureExceptionCall);\n }\n } else {\n debug('Could not safely access ErrorBoundary function body');\n }\n}\n\nfunction findErrorBoundaryInExports(\n namedExports: ExportNamedDeclaration[],\n): boolean {\n return namedExports.some((namedExport) => {\n const declaration = namedExport.declaration;\n\n if (!declaration) {\n return namedExport.specifiers?.some(\n (spec) =>\n spec.type === 'ExportSpecifier' &&\n spec.exported?.type === 'Identifier' &&\n spec.exported.name === 'ErrorBoundary',\n );\n }\n\n if (declaration.type === 'FunctionDeclaration') {\n return declaration.id?.name === 'ErrorBoundary';\n }\n\n if (declaration.type === 'VariableDeclaration') {\n return declaration.declarations.some((decl) => {\n // @ts-expect-error - id should always have a name in this case\n return decl.id?.name === 'ErrorBoundary';\n });\n }\n\n return false;\n });\n}\n\nexport async function instrumentRoot(rootFileName: string): Promise<void> {\n const filePath = path.join(process.cwd(), 'app', rootFileName);\n const rootRouteAst = await loadFile(filePath);\n\n const exportsAst = rootRouteAst.exports.$ast as t.Program;\n const namedExports = exportsAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n const foundErrorBoundary = findErrorBoundaryInExports(namedExports);\n const alreadyHasSentry = hasSentryContent(rootRouteAst.$ast as t.Program);\n\n if (!alreadyHasSentry) {\n rootRouteAst.imports.$add({\n from: '@sentry/react-router',\n imported: '*',\n local: 'Sentry',\n });\n }\n\n if (!foundErrorBoundary) {\n const hasIsRouteErrorResponseImport = rootRouteAst.imports.$items.some(\n (item) =>\n item.imported === 'isRouteErrorResponse' &&\n item.from === 'react-router',\n );\n\n if (!hasIsRouteErrorResponseImport) {\n rootRouteAst.imports.$add({\n from: 'react-router',\n imported: 'isRouteErrorResponse',\n local: 'isRouteErrorResponse',\n });\n }\n\n recast.visit(rootRouteAst.$ast, {\n visitExportDefaultDeclaration(path) {\n const implementation = recast.parse(ERROR_BOUNDARY_TEMPLATE).program\n .body[0];\n\n path.insertBefore(\n recast.types.builders.exportDeclaration(false, implementation),\n );\n\n this.traverse(path);\n },\n });\n } else {\n recast.visit(rootRouteAst.$ast, {\n visitExportNamedDeclaration(path) {\n const declaration = path.value.declaration;\n if (!declaration) {\n this.traverse(path);\n return;\n }\n\n let functionToInstrument = null;\n\n if (\n declaration.type === 'FunctionDeclaration' &&\n declaration.id?.name === 'ErrorBoundary'\n ) {\n functionToInstrument = declaration;\n } else if (\n declaration.type === 'VariableDeclaration' &&\n declaration.declarations?.[0]?.id?.name === 'ErrorBoundary'\n ) {\n const init = declaration.declarations[0].init;\n if (\n init &&\n (init.type === 'FunctionExpression' ||\n init.type === 'ArrowFunctionExpression')\n ) {\n functionToInstrument = init;\n }\n }\n\n if (\n functionToInstrument &&\n !hasCaptureExceptionCall(functionToInstrument)\n ) {\n addCaptureExceptionCall(functionToInstrument);\n }\n\n this.traverse(path);\n },\n\n visitVariableDeclaration(path) {\n if (path.value.declarations?.[0]?.id?.name === 'ErrorBoundary') {\n const init = path.value.declarations[0].init;\n if (\n init &&\n (init.type === 'FunctionExpression' ||\n init.type === 'ArrowFunctionExpression') &&\n !hasCaptureExceptionCall(init)\n ) {\n addCaptureExceptionCall(init);\n }\n }\n this.traverse(path);\n },\n\n visitFunctionDeclaration(path) {\n if (\n path.value.id?.name === 'ErrorBoundary' &&\n !hasCaptureExceptionCall(path.value)\n ) {\n addCaptureExceptionCall(path.value);\n }\n this.traverse(path);\n },\n });\n }\n\n await writeFile(rootRouteAst.$ast, filePath);\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  import type { ProxifiedModule } from 'magicast';
2
- export declare function instrumentServerEntry(serverEntryPath: string): Promise<void>;
2
+ export declare function instrumentServerEntry(serverEntryPath: string, useInstrumentationAPI?: boolean): Promise<void>;
3
3
  export declare function instrumentHandleRequest(originalEntryServerMod: ProxifiedModule<any>): void;
4
4
  export declare function instrumentHandleError(originalEntryServerMod: ProxifiedModule<any>): void;
@@ -42,7 +42,7 @@ const magicast_1 = require("magicast");
42
42
  const debug_1 = require("../../utils/debug");
43
43
  const ast_utils_1 = require("../../utils/ast-utils");
44
44
  const utils_1 = require("./utils");
45
- async function instrumentServerEntry(serverEntryPath) {
45
+ async function instrumentServerEntry(serverEntryPath, useInstrumentationAPI = false) {
46
46
  const serverEntryAst = await (0, magicast_1.loadFile)(serverEntryPath);
47
47
  if (!(0, ast_utils_1.hasSentryContent)(serverEntryAst.$ast)) {
48
48
  serverEntryAst.imports.$add({
@@ -53,9 +53,39 @@ async function instrumentServerEntry(serverEntryPath) {
53
53
  }
54
54
  instrumentHandleError(serverEntryAst);
55
55
  instrumentHandleRequest(serverEntryAst);
56
+ if (useInstrumentationAPI) {
57
+ instrumentUnstableInstrumentations(serverEntryAst);
58
+ }
56
59
  await (0, magicast_1.writeFile)(serverEntryAst.$ast, serverEntryPath);
57
60
  }
58
61
  exports.instrumentServerEntry = instrumentServerEntry;
62
+ function instrumentUnstableInstrumentations(originalEntryServerMod) {
63
+ const originalEntryServerModAST = originalEntryServerMod.$ast;
64
+ const hasUnstableInstrumentations = originalEntryServerModAST.body.some((node) => {
65
+ if (node.type !== 'ExportNamedDeclaration' ||
66
+ node.declaration?.type !== 'VariableDeclaration') {
67
+ return false;
68
+ }
69
+ const declarations = node.declaration.declarations;
70
+ if (!declarations || declarations.length === 0) {
71
+ return false;
72
+ }
73
+ const firstDeclaration = declarations[0];
74
+ if (!firstDeclaration || firstDeclaration.type !== 'VariableDeclarator') {
75
+ return false;
76
+ }
77
+ const id = firstDeclaration.id;
78
+ return (id &&
79
+ id.type === 'Identifier' &&
80
+ id.name === 'unstable_instrumentations');
81
+ });
82
+ if (hasUnstableInstrumentations) {
83
+ (0, debug_1.debug)('unstable_instrumentations export already exists, skipping adding it again');
84
+ return;
85
+ }
86
+ const instrumentationsExport = recast.parse(`export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];`).program.body[0];
87
+ originalEntryServerModAST.body.push(instrumentationsExport);
88
+ }
59
89
  function instrumentHandleRequest(originalEntryServerMod) {
60
90
  const originalEntryServerModAST = originalEntryServerMod.$ast;
61
91
  const defaultServerEntryExport = originalEntryServerModAST.body.find((node) => {
@@ -148,10 +178,15 @@ function instrumentHandleRequest(originalEntryServerMod) {
148
178
  this.traverse(path);
149
179
  },
150
180
  });
151
- // Replace the existing default export with the wrapped one
152
- originalEntryServerModAST.body.splice(defaultExportIndex, 1,
181
+ // Replace the existing default export with the unwrapped function declaration
153
182
  // @ts-expect-error - declaration works here because the AST is proxified by magicast
154
- defaultExportNode.declaration);
183
+ const funcDeclaration = defaultExportNode.declaration;
184
+ // Make non-async functions async so the return type matches wrapSentryHandleRequest
185
+ if (funcDeclaration.type === 'FunctionDeclaration' &&
186
+ !funcDeclaration.async) {
187
+ funcDeclaration.async = true;
188
+ }
189
+ originalEntryServerModAST.body.splice(defaultExportIndex, 1, funcDeclaration);
155
190
  // Adding our wrapped export
156
191
  originalEntryServerModAST.body.push(recast.types.builders.exportDefaultDeclaration(recast.types.builders.callExpression(recast.types.builders.memberExpression(recast.types.builders.identifier('Sentry'), recast.types.builders.identifier('wrapSentryHandleRequest')), [recast.types.builders.identifier('handleRequest')])));
157
192
  }
@@ -1 +1 @@
1
- {"version":3,"file":"server-entry.js","sourceRoot":"","sources":["../../../../src/react-router/codemods/server-entry.ts"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,uDAAuD;AACvD,sDAAsD;AACtD,+DAA+D;AAC/D,wDAAwD;AACxD,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAK5D,+CAAiC;AAGjC,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAE1B,kFAAkF;AAClF,uCAA6D;AAC7D,6CAA0C;AAC1C,qDAI+B;AAC/B,mCAAwD;AAEjD,KAAK,UAAU,qBAAqB,CACzC,eAAuB;IAEvB,MAAM,cAAc,GAAG,MAAM,IAAA,mBAAQ,EAAC,eAAe,CAAC,CAAC;IAEvD,IAAI,CAAC,IAAA,4BAAgB,EAAC,cAAc,CAAC,IAAiB,CAAC,EAAE;QACvD,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC;YAC1B,IAAI,EAAE,sBAAsB;YAC5B,QAAQ,EAAE,GAAG;YACb,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;KACJ;IAED,qBAAqB,CAAC,cAAc,CAAC,CAAC;IACtC,uBAAuB,CAAC,cAAc,CAAC,CAAC;IAExC,MAAM,IAAA,oBAAS,EAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AACxD,CAAC;AAjBD,sDAiBC;AAED,SAAgB,uBAAuB,CACrC,sBAA4C;IAE5C,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,IAAiB,CAAC;IAE3E,MAAM,wBAAwB,GAAG,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAClE,CAAC,IAAI,EAAE,EAAE;QACP,OAAO,IAAI,CAAC,IAAI,KAAK,0BAA0B,CAAC;IAClD,CAAC,CACF,CAAC;IAEF,IAAI,CAAC,wBAAwB,EAAE;QAC7B,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,2BAA2B,eAA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disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\n\nimport * as recast from 'recast';\nimport type { namedTypes as t } from 'ast-types';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, loadFile, writeFile } from 'magicast';\nimport { debug } from '../../utils/debug';\nimport {\n hasSentryContent,\n safeCalleeIdentifierMatch,\n safeGetIdentifierName,\n} from '../../utils/ast-utils';\nimport { getAfterImportsInsertionIndex } from './utils';\n\nexport async function instrumentServerEntry(\n serverEntryPath: string,\n): Promise<void> {\n const serverEntryAst = await loadFile(serverEntryPath);\n\n if (!hasSentryContent(serverEntryAst.$ast as t.Program)) {\n serverEntryAst.imports.$add({\n from: '@sentry/react-router',\n imported: '*',\n local: 'Sentry',\n });\n }\n\n instrumentHandleError(serverEntryAst);\n instrumentHandleRequest(serverEntryAst);\n\n await writeFile(serverEntryAst.$ast, serverEntryPath);\n}\n\nexport function instrumentHandleRequest(\n originalEntryServerMod: ProxifiedModule<any>,\n): void {\n const originalEntryServerModAST = originalEntryServerMod.$ast as t.Program;\n\n const defaultServerEntryExport = originalEntryServerModAST.body.find(\n (node) => {\n return node.type === 'ExportDefaultDeclaration';\n },\n );\n\n if (!defaultServerEntryExport) {\n clack.log.warn(\n `Could not find function ${chalk.cyan(\n 'handleRequest',\n )} in your server entry file. Creating one for you.`,\n );\n\n let foundServerRouterImport = false;\n let foundRenderToPipeableStreamImport = false;\n let foundCreateReadableStreamFromReadableImport = false;\n\n originalEntryServerMod.imports.$items.forEach((item) => {\n if (item.imported === 'ServerRouter' && item.from === 'react-router') {\n foundServerRouterImport = true;\n }\n if (\n item.imported === 'renderToPipeableStream' &&\n item.from === 'react-dom/server'\n ) {\n foundRenderToPipeableStreamImport = true;\n }\n if (\n item.imported === 'createReadableStreamFromReadable' &&\n item.from === '@react-router/node'\n ) {\n foundCreateReadableStreamFromReadableImport = true;\n }\n });\n\n if (!foundServerRouterImport) {\n originalEntryServerMod.imports.$add({\n from: 'react-router',\n imported: 'ServerRouter',\n local: 'ServerRouter',\n });\n }\n\n if (!foundRenderToPipeableStreamImport) {\n originalEntryServerMod.imports.$add({\n from: 'react-dom/server',\n imported: 'renderToPipeableStream',\n local: 'renderToPipeableStream',\n });\n }\n\n if (!foundCreateReadableStreamFromReadableImport) {\n originalEntryServerMod.imports.$add({\n from: '@react-router/node',\n imported: 'createReadableStreamFromReadable',\n local: 'createReadableStreamFromReadable',\n });\n }\n\n const implementation =\n recast.parse(`const handleRequest = Sentry.createSentryHandleRequest({\n ServerRouter,\n renderToPipeableStream,\n createReadableStreamFromReadable,\n})`).program.body[0];\n\n try {\n originalEntryServerModAST.body.splice(\n getAfterImportsInsertionIndex(originalEntryServerModAST),\n 0,\n implementation,\n );\n\n originalEntryServerModAST.body.push({\n type: 'ExportDefaultDeclaration',\n declaration: {\n type: 'Identifier',\n name: 'handleRequest',\n },\n });\n } catch (error) {\n debug('Failed to insert handleRequest implementation:', error);\n throw new Error(\n 'Could not automatically instrument handleRequest. Please add it manually.',\n );\n }\n } else if (\n defaultServerEntryExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(defaultServerEntryExport).code.includes(\n 'wrapSentryHandleRequest',\n )\n ) {\n debug('wrapSentryHandleRequest is already used, skipping wrapping again');\n clack.log.info(\n 'Sentry handleRequest wrapper already detected, skipping instrumentation.',\n );\n } else {\n let defaultExportNode: recast.types.namedTypes.ExportDefaultDeclaration | null =\n null;\n const defaultExportIndex = originalEntryServerModAST.body.findIndex(\n (node) => {\n const found = node.type === 'ExportDefaultDeclaration';\n\n if (found) {\n defaultExportNode = node;\n }\n\n return found;\n },\n );\n\n if (defaultExportIndex !== -1 && defaultExportNode !== null) {\n recast.visit(defaultExportNode, {\n visitCallExpression(path) {\n if (\n safeCalleeIdentifierMatch(path.value.callee, 'pipe') &&\n path.value.arguments.length &&\n path.value.arguments[0].type === 'Identifier' &&\n safeGetIdentifierName(path.value.arguments[0]) === 'body'\n ) {\n const wrapped = recast.types.builders.callExpression(\n recast.types.builders.memberExpression(\n recast.types.builders.identifier('Sentry'),\n recast.types.builders.identifier('getMetaTagTransformer'),\n ),\n [path.value.arguments[0]],\n );\n\n path.value.arguments[0] = wrapped;\n }\n\n this.traverse(path);\n },\n });\n\n // Replace the existing default export with the wrapped one\n originalEntryServerModAST.body.splice(\n defaultExportIndex,\n 1,\n // @ts-expect-error - declaration works here because the AST is proxified by magicast\n defaultExportNode.declaration,\n );\n\n // Adding our wrapped export\n originalEntryServerModAST.body.push(\n recast.types.builders.exportDefaultDeclaration(\n recast.types.builders.callExpression(\n recast.types.builders.memberExpression(\n recast.types.builders.identifier('Sentry'),\n recast.types.builders.identifier('wrapSentryHandleRequest'),\n ),\n [recast.types.builders.identifier('handleRequest')],\n ),\n ),\n );\n }\n }\n}\n\nexport function instrumentHandleError(\n originalEntryServerMod: ProxifiedModule<any>,\n): void {\n const originalEntryServerModAST = originalEntryServerMod.$ast as t.Program;\n\n const handleErrorFunctionExport = originalEntryServerModAST.body.find(\n (node) => {\n return (\n node.type === 'ExportNamedDeclaration' &&\n node.declaration?.type === 'FunctionDeclaration' &&\n node.declaration.id?.name === 'handleError'\n );\n },\n );\n\n const handleErrorFunctionVariableDeclarationExport =\n originalEntryServerModAST.body.find((node) => {\n if (\n node.type !== 'ExportNamedDeclaration' ||\n node.declaration?.type !== 'VariableDeclaration'\n ) {\n return false;\n }\n\n const declarations = node.declaration.declarations;\n if (!declarations || declarations.length === 0) {\n return false;\n }\n\n const firstDeclaration = declarations[0];\n if (!firstDeclaration || firstDeclaration.type !== 'VariableDeclarator') {\n return false;\n }\n\n const id = firstDeclaration.id;\n return id && id.type === 'Identifier' && id.name === 'handleError';\n });\n\n if (\n !handleErrorFunctionExport &&\n !handleErrorFunctionVariableDeclarationExport\n ) {\n clack.log.warn(\n `Could not find function ${chalk.cyan(\n 'handleError',\n )} in your server entry file. Creating one for you.`,\n );\n\n const implementation =\n recast.parse(`const handleError = Sentry.createSentryHandleError({\n logErrors: false\n})`).program.body[0];\n\n originalEntryServerModAST.body.splice(\n getAfterImportsInsertionIndex(originalEntryServerModAST),\n 0,\n recast.types.builders.exportNamedDeclaration(implementation),\n );\n } else if (\n (handleErrorFunctionExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(handleErrorFunctionExport).code.includes(\n 'captureException',\n )) ||\n (handleErrorFunctionVariableDeclarationExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(handleErrorFunctionVariableDeclarationExport).code.includes(\n 'captureException',\n ))\n ) {\n debug(\n 'Found captureException inside handleError, skipping adding it again',\n );\n } else if (\n (handleErrorFunctionExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(handleErrorFunctionExport).code.includes(\n 'createSentryHandleError',\n )) ||\n (handleErrorFunctionVariableDeclarationExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(handleErrorFunctionVariableDeclarationExport).code.includes(\n 'createSentryHandleError',\n ))\n ) {\n debug('createSentryHandleError is already used, skipping adding it again');\n } else if (handleErrorFunctionExport) {\n // Create the Sentry captureException call as an IfStatement\n const sentryCall = recast.parse(`if (!request.signal.aborted) {\n Sentry.captureException(error);\n}`).program.body[0];\n\n // Safely insert the Sentry call at the beginning of the handleError function body\n // @ts-expect-error - declaration works here because the AST is proxified by magicast\n const declaration = handleErrorFunctionExport.declaration;\n if (\n declaration &&\n declaration.body &&\n declaration.body.body &&\n Array.isArray(declaration.body.body)\n ) {\n declaration.body.body.unshift(sentryCall);\n } else {\n debug(\n 'Cannot safely access handleError function body, skipping instrumentation',\n );\n }\n } else if (handleErrorFunctionVariableDeclarationExport) {\n // Create the Sentry captureException call as an IfStatement\n const sentryCall = recast.parse(`if (!request.signal.aborted) {\n Sentry.captureException(error);\n}`).program.body[0];\n\n // Safe access to existing handle error implementation with proper null checks\n // We know this is ExportNamedDeclaration with VariableDeclaration from the earlier find\n const exportDeclaration =\n handleErrorFunctionVariableDeclarationExport as any;\n if (\n !exportDeclaration.declaration ||\n exportDeclaration.declaration.type !== 'VariableDeclaration' ||\n !exportDeclaration.declaration.declarations ||\n exportDeclaration.declaration.declarations.length === 0\n ) {\n debug(\n 'Cannot safely access handleError variable declaration, skipping instrumentation',\n );\n return;\n }\n\n const firstDeclaration = exportDeclaration.declaration.declarations[0];\n if (\n !firstDeclaration ||\n firstDeclaration.type !== 'VariableDeclarator' ||\n !firstDeclaration.init\n ) {\n debug(\n 'Cannot safely access handleError variable declarator init, skipping instrumentation',\n );\n return;\n }\n\n const existingHandleErrorImplementation = firstDeclaration.init;\n const existingParams = existingHandleErrorImplementation.params;\n const existingBody = existingHandleErrorImplementation.body;\n\n const requestParam = {\n ...recast.types.builders.property(\n 'init',\n recast.types.builders.identifier('request'), // key\n recast.types.builders.identifier('request'), // value\n ),\n shorthand: true,\n };\n // Add error and {request} parameters to handleError function if not present\n // When none of the parameters exist\n if (existingParams.length === 0) {\n existingParams.push(\n recast.types.builders.identifier('error'),\n recast.types.builders.objectPattern([requestParam]),\n );\n // When only error parameter exists\n } else if (existingParams.length === 1) {\n existingParams.push(recast.types.builders.objectPattern([requestParam]));\n // When both parameters exist, but request is not destructured\n } else if (\n existingParams[1].type === 'ObjectPattern' &&\n !existingParams[1].properties.some(\n (prop: t.ObjectProperty) =>\n safeGetIdentifierName(prop.key) === 'request',\n )\n ) {\n existingParams[1].properties.push(requestParam);\n }\n\n // Add the Sentry call to the function body\n existingBody.body.push(sentryCall);\n }\n}\n"]}
1
+ {"version":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UAAU,CAAC,CAAC;KACpC;AACH,CAAC;AAjLD,sDAiLC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\n\nimport * as recast from 'recast';\nimport type { namedTypes as t } from 'ast-types';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, loadFile, writeFile } from 'magicast';\nimport { debug } from '../../utils/debug';\nimport {\n hasSentryContent,\n safeCalleeIdentifierMatch,\n safeGetIdentifierName,\n} from '../../utils/ast-utils';\nimport { getAfterImportsInsertionIndex } from './utils';\n\nexport async function instrumentServerEntry(\n serverEntryPath: string,\n useInstrumentationAPI = false,\n): Promise<void> {\n const serverEntryAst = await loadFile(serverEntryPath);\n\n if (!hasSentryContent(serverEntryAst.$ast as t.Program)) {\n serverEntryAst.imports.$add({\n from: '@sentry/react-router',\n imported: '*',\n local: 'Sentry',\n });\n }\n\n instrumentHandleError(serverEntryAst);\n instrumentHandleRequest(serverEntryAst);\n\n if (useInstrumentationAPI) {\n instrumentUnstableInstrumentations(serverEntryAst);\n }\n\n await writeFile(serverEntryAst.$ast, serverEntryPath);\n}\n\nfunction instrumentUnstableInstrumentations(\n originalEntryServerMod: ProxifiedModule<any>,\n): void {\n const originalEntryServerModAST = originalEntryServerMod.$ast as t.Program;\n\n const hasUnstableInstrumentations = originalEntryServerModAST.body.some(\n (node) => {\n if (\n node.type !== 'ExportNamedDeclaration' ||\n node.declaration?.type !== 'VariableDeclaration'\n ) {\n return false;\n }\n\n const declarations = node.declaration.declarations;\n if (!declarations || declarations.length === 0) {\n return false;\n }\n\n const firstDeclaration = declarations[0];\n if (!firstDeclaration || firstDeclaration.type !== 'VariableDeclarator') {\n return false;\n }\n\n const id = firstDeclaration.id;\n return (\n id &&\n id.type === 'Identifier' &&\n id.name === 'unstable_instrumentations'\n );\n },\n );\n\n if (hasUnstableInstrumentations) {\n debug(\n 'unstable_instrumentations export already exists, skipping adding it again',\n );\n return;\n }\n\n const instrumentationsExport = recast.parse(\n `export const unstable_instrumentations = [Sentry.createSentryServerInstrumentation()];`,\n ).program.body[0];\n\n originalEntryServerModAST.body.push(instrumentationsExport);\n}\n\nexport function instrumentHandleRequest(\n originalEntryServerMod: ProxifiedModule<any>,\n): void {\n const originalEntryServerModAST = originalEntryServerMod.$ast as t.Program;\n\n const defaultServerEntryExport = originalEntryServerModAST.body.find(\n (node) => {\n return node.type === 'ExportDefaultDeclaration';\n },\n );\n\n if (!defaultServerEntryExport) {\n clack.log.warn(\n `Could not find function ${chalk.cyan(\n 'handleRequest',\n )} in your server entry file. Creating one for you.`,\n );\n\n let foundServerRouterImport = false;\n let foundRenderToPipeableStreamImport = false;\n let foundCreateReadableStreamFromReadableImport = false;\n\n originalEntryServerMod.imports.$items.forEach((item) => {\n if (item.imported === 'ServerRouter' && item.from === 'react-router') {\n foundServerRouterImport = true;\n }\n if (\n item.imported === 'renderToPipeableStream' &&\n item.from === 'react-dom/server'\n ) {\n foundRenderToPipeableStreamImport = true;\n }\n if (\n item.imported === 'createReadableStreamFromReadable' &&\n item.from === '@react-router/node'\n ) {\n foundCreateReadableStreamFromReadableImport = true;\n }\n });\n\n if (!foundServerRouterImport) {\n originalEntryServerMod.imports.$add({\n from: 'react-router',\n imported: 'ServerRouter',\n local: 'ServerRouter',\n });\n }\n\n if (!foundRenderToPipeableStreamImport) {\n originalEntryServerMod.imports.$add({\n from: 'react-dom/server',\n imported: 'renderToPipeableStream',\n local: 'renderToPipeableStream',\n });\n }\n\n if (!foundCreateReadableStreamFromReadableImport) {\n originalEntryServerMod.imports.$add({\n from: '@react-router/node',\n imported: 'createReadableStreamFromReadable',\n local: 'createReadableStreamFromReadable',\n });\n }\n\n const implementation =\n recast.parse(`const handleRequest = Sentry.createSentryHandleRequest({\n ServerRouter,\n renderToPipeableStream,\n createReadableStreamFromReadable,\n})`).program.body[0];\n\n try {\n originalEntryServerModAST.body.splice(\n getAfterImportsInsertionIndex(originalEntryServerModAST),\n 0,\n implementation,\n );\n\n originalEntryServerModAST.body.push({\n type: 'ExportDefaultDeclaration',\n declaration: {\n type: 'Identifier',\n name: 'handleRequest',\n },\n });\n } catch (error) {\n debug('Failed to insert handleRequest implementation:', error);\n throw new Error(\n 'Could not automatically instrument handleRequest. Please add it manually.',\n );\n }\n } else if (\n defaultServerEntryExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(defaultServerEntryExport).code.includes(\n 'wrapSentryHandleRequest',\n )\n ) {\n debug('wrapSentryHandleRequest is already used, skipping wrapping again');\n clack.log.info(\n 'Sentry handleRequest wrapper already detected, skipping instrumentation.',\n );\n } else {\n let defaultExportNode: recast.types.namedTypes.ExportDefaultDeclaration | null =\n null;\n const defaultExportIndex = originalEntryServerModAST.body.findIndex(\n (node) => {\n const found = node.type === 'ExportDefaultDeclaration';\n\n if (found) {\n defaultExportNode = node;\n }\n\n return found;\n },\n );\n\n if (defaultExportIndex !== -1 && defaultExportNode !== null) {\n recast.visit(defaultExportNode, {\n visitCallExpression(path) {\n if (\n safeCalleeIdentifierMatch(path.value.callee, 'pipe') &&\n path.value.arguments.length &&\n path.value.arguments[0].type === 'Identifier' &&\n safeGetIdentifierName(path.value.arguments[0]) === 'body'\n ) {\n const wrapped = recast.types.builders.callExpression(\n recast.types.builders.memberExpression(\n recast.types.builders.identifier('Sentry'),\n recast.types.builders.identifier('getMetaTagTransformer'),\n ),\n [path.value.arguments[0]],\n );\n\n path.value.arguments[0] = wrapped;\n }\n\n this.traverse(path);\n },\n });\n\n // Replace the existing default export with the unwrapped function declaration\n // @ts-expect-error - declaration works here because the AST is proxified by magicast\n const funcDeclaration = defaultExportNode.declaration;\n // Make non-async functions async so the return type matches wrapSentryHandleRequest\n if (\n funcDeclaration.type === 'FunctionDeclaration' &&\n !funcDeclaration.async\n ) {\n funcDeclaration.async = true;\n }\n originalEntryServerModAST.body.splice(\n defaultExportIndex,\n 1,\n funcDeclaration,\n );\n\n // Adding our wrapped export\n originalEntryServerModAST.body.push(\n recast.types.builders.exportDefaultDeclaration(\n recast.types.builders.callExpression(\n recast.types.builders.memberExpression(\n recast.types.builders.identifier('Sentry'),\n recast.types.builders.identifier('wrapSentryHandleRequest'),\n ),\n [recast.types.builders.identifier('handleRequest')],\n ),\n ),\n );\n }\n }\n}\n\nexport function instrumentHandleError(\n originalEntryServerMod: ProxifiedModule<any>,\n): void {\n const originalEntryServerModAST = originalEntryServerMod.$ast as t.Program;\n\n const handleErrorFunctionExport = originalEntryServerModAST.body.find(\n (node) => {\n return (\n node.type === 'ExportNamedDeclaration' &&\n node.declaration?.type === 'FunctionDeclaration' &&\n node.declaration.id?.name === 'handleError'\n );\n },\n );\n\n const handleErrorFunctionVariableDeclarationExport =\n originalEntryServerModAST.body.find((node) => {\n if (\n node.type !== 'ExportNamedDeclaration' ||\n node.declaration?.type !== 'VariableDeclaration'\n ) {\n return false;\n }\n\n const declarations = node.declaration.declarations;\n if (!declarations || declarations.length === 0) {\n return false;\n }\n\n const firstDeclaration = declarations[0];\n if (!firstDeclaration || firstDeclaration.type !== 'VariableDeclarator') {\n return false;\n }\n\n const id = firstDeclaration.id;\n return id && id.type === 'Identifier' && id.name === 'handleError';\n });\n\n if (\n !handleErrorFunctionExport &&\n !handleErrorFunctionVariableDeclarationExport\n ) {\n clack.log.warn(\n `Could not find function ${chalk.cyan(\n 'handleError',\n )} in your server entry file. Creating one for you.`,\n );\n\n const implementation =\n recast.parse(`const handleError = Sentry.createSentryHandleError({\n logErrors: false\n})`).program.body[0];\n\n originalEntryServerModAST.body.splice(\n getAfterImportsInsertionIndex(originalEntryServerModAST),\n 0,\n recast.types.builders.exportNamedDeclaration(implementation),\n );\n } else if (\n (handleErrorFunctionExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(handleErrorFunctionExport).code.includes(\n 'captureException',\n )) ||\n (handleErrorFunctionVariableDeclarationExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(handleErrorFunctionVariableDeclarationExport).code.includes(\n 'captureException',\n ))\n ) {\n debug(\n 'Found captureException inside handleError, skipping adding it again',\n );\n } else if (\n (handleErrorFunctionExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(handleErrorFunctionExport).code.includes(\n 'createSentryHandleError',\n )) ||\n (handleErrorFunctionVariableDeclarationExport &&\n // @ts-expect-error - StatementKind works here because the AST is proxified by magicast\n generateCode(handleErrorFunctionVariableDeclarationExport).code.includes(\n 'createSentryHandleError',\n ))\n ) {\n debug('createSentryHandleError is already used, skipping adding it again');\n } else if (handleErrorFunctionExport) {\n // Create the Sentry captureException call as an IfStatement\n const sentryCall = recast.parse(`if (!request.signal.aborted) {\n Sentry.captureException(error);\n}`).program.body[0];\n\n // Safely insert the Sentry call at the beginning of the handleError function body\n // @ts-expect-error - declaration works here because the AST is proxified by magicast\n const declaration = handleErrorFunctionExport.declaration;\n if (\n declaration &&\n declaration.body &&\n declaration.body.body &&\n Array.isArray(declaration.body.body)\n ) {\n declaration.body.body.unshift(sentryCall);\n } else {\n debug(\n 'Cannot safely access handleError function body, skipping instrumentation',\n );\n }\n } else if (handleErrorFunctionVariableDeclarationExport) {\n // Create the Sentry captureException call as an IfStatement\n const sentryCall = recast.parse(`if (!request.signal.aborted) {\n Sentry.captureException(error);\n}`).program.body[0];\n\n // Safe access to existing handle error implementation with proper null checks\n // We know this is ExportNamedDeclaration with VariableDeclaration from the earlier find\n const exportDeclaration =\n handleErrorFunctionVariableDeclarationExport as any;\n if (\n !exportDeclaration.declaration ||\n exportDeclaration.declaration.type !== 'VariableDeclaration' ||\n !exportDeclaration.declaration.declarations ||\n exportDeclaration.declaration.declarations.length === 0\n ) {\n debug(\n 'Cannot safely access handleError variable declaration, skipping instrumentation',\n );\n return;\n }\n\n const firstDeclaration = exportDeclaration.declaration.declarations[0];\n if (\n !firstDeclaration ||\n firstDeclaration.type !== 'VariableDeclarator' ||\n !firstDeclaration.init\n ) {\n debug(\n 'Cannot safely access handleError variable declarator init, skipping instrumentation',\n );\n return;\n }\n\n const existingHandleErrorImplementation = firstDeclaration.init;\n const existingParams = existingHandleErrorImplementation.params;\n const existingBody = existingHandleErrorImplementation.body;\n\n const requestParam = {\n ...recast.types.builders.property(\n 'init',\n recast.types.builders.identifier('request'), // key\n recast.types.builders.identifier('request'), // value\n ),\n shorthand: true,\n };\n // Add error and {request} parameters to handleError function if not present\n // When none of the parameters exist\n if (existingParams.length === 0) {\n existingParams.push(\n recast.types.builders.identifier('error'),\n recast.types.builders.objectPattern([requestParam]),\n );\n // When only error parameter exists\n } else if (existingParams.length === 1) {\n existingParams.push(recast.types.builders.objectPattern([requestParam]));\n // When both parameters exist, but request is not destructured\n } else if (\n existingParams[1].type === 'ObjectPattern' &&\n !existingParams[1].properties.some(\n (prop: t.ObjectProperty) =>\n safeGetIdentifierName(prop.key) === 'request',\n )\n ) {\n existingParams[1].properties.push(requestParam);\n }\n\n // Add the Sentry call to the function body\n existingBody.body.push(sentryCall);\n }\n}\n"]}