@sentry/wizard 3.9.2 → 3.11.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 (168) hide show
  1. package/CHANGELOG.md +58 -6
  2. package/dist/lib/Constants.d.ts +2 -0
  3. package/dist/lib/Constants.js +10 -0
  4. package/dist/lib/Constants.js.map +1 -1
  5. package/dist/lib/Steps/ChooseIntegration.js +15 -4
  6. package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
  7. package/dist/lib/Steps/Integrations/Android.d.ts +9 -0
  8. package/dist/lib/Steps/Integrations/Android.js +86 -0
  9. package/dist/lib/Steps/Integrations/Android.js.map +1 -0
  10. package/dist/lib/Steps/Integrations/Cordova.js +5 -1
  11. package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
  12. package/dist/lib/Steps/Integrations/ReactNative.js +3 -3
  13. package/dist/lib/Steps/Integrations/ReactNative.js.map +1 -1
  14. package/dist/lib/Steps/Integrations/Remix.d.ts +12 -0
  15. package/dist/lib/Steps/Integrations/Remix.js +98 -0
  16. package/dist/lib/Steps/Integrations/Remix.js.map +1 -0
  17. package/dist/lib/Steps/PromptForParameters.js +36 -3
  18. package/dist/lib/Steps/PromptForParameters.js.map +1 -1
  19. package/dist/lib/Steps/SentryProjectSelector.js +1 -1
  20. package/dist/lib/Steps/SentryProjectSelector.js.map +1 -1
  21. package/dist/package.json +4 -3
  22. package/dist/src/android/android-wizard.d.ts +2 -0
  23. package/dist/src/android/android-wizard.js +217 -0
  24. package/dist/src/android/android-wizard.js.map +1 -0
  25. package/dist/src/android/code-tools.d.ts +39 -0
  26. package/dist/src/android/code-tools.js +161 -0
  27. package/dist/src/android/code-tools.js.map +1 -0
  28. package/dist/src/android/gradle.d.ts +62 -0
  29. package/dist/src/android/gradle.js +281 -0
  30. package/dist/src/android/gradle.js.map +1 -0
  31. package/dist/src/android/manifest.d.ts +57 -0
  32. package/dist/src/android/manifest.js +183 -0
  33. package/dist/src/android/manifest.js.map +1 -0
  34. package/dist/src/android/templates.d.ts +11 -0
  35. package/dist/src/android/templates.js +34 -0
  36. package/dist/src/android/templates.js.map +1 -0
  37. package/dist/src/apple/apple-wizard.js +123 -64
  38. package/dist/src/apple/apple-wizard.js.map +1 -1
  39. package/dist/src/apple/cocoapod.js +4 -3
  40. package/dist/src/apple/cocoapod.js.map +1 -1
  41. package/dist/src/apple/code-tools.d.ts +1 -1
  42. package/dist/src/apple/code-tools.js +43 -19
  43. package/dist/src/apple/code-tools.js.map +1 -1
  44. package/dist/src/apple/fastlane.d.ts +1 -1
  45. package/dist/src/apple/fastlane.js +12 -6
  46. package/dist/src/apple/fastlane.js.map +1 -1
  47. package/dist/src/apple/templates.d.ts +2 -2
  48. package/dist/src/apple/templates.js +4 -4
  49. package/dist/src/apple/templates.js.map +1 -1
  50. package/dist/src/apple/xcode-manager.d.ts +19 -3
  51. package/dist/src/apple/xcode-manager.js +126 -24
  52. package/dist/src/apple/xcode-manager.js.map +1 -1
  53. package/dist/src/nextjs/nextjs-wizard.js +49 -11
  54. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  55. package/dist/src/nextjs/templates.d.ts +2 -0
  56. package/dist/src/nextjs/templates.js +6 -2
  57. package/dist/src/nextjs/templates.js.map +1 -1
  58. package/dist/src/remix/codemods/handle-error.d.ts +2 -0
  59. package/dist/src/remix/codemods/handle-error.js +70 -0
  60. package/dist/src/remix/codemods/handle-error.js.map +1 -0
  61. package/dist/src/remix/codemods/root-v1.d.ts +1 -0
  62. package/dist/src/remix/codemods/root-v1.js +133 -0
  63. package/dist/src/remix/codemods/root-v1.js.map +1 -0
  64. package/dist/src/remix/codemods/root-v2.d.ts +1 -0
  65. package/dist/src/remix/codemods/root-v2.js +134 -0
  66. package/dist/src/remix/codemods/root-v2.js.map +1 -0
  67. package/dist/src/remix/remix-wizard.d.ts +2 -0
  68. package/dist/src/remix/remix-wizard.js +196 -0
  69. package/dist/src/remix/remix-wizard.js.map +1 -0
  70. package/dist/src/remix/sdk-setup.d.ts +18 -0
  71. package/dist/src/remix/sdk-setup.js +293 -0
  72. package/dist/src/remix/sdk-setup.js.map +1 -0
  73. package/dist/src/remix/templates.d.ts +2 -0
  74. package/dist/src/remix/templates.js +6 -0
  75. package/dist/src/remix/templates.js.map +1 -0
  76. package/dist/src/remix/utils.d.ts +6 -0
  77. package/dist/src/remix/utils.js +55 -0
  78. package/dist/src/remix/utils.js.map +1 -0
  79. package/dist/src/sourcemaps/sourcemaps-wizard.js +49 -25
  80. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  81. package/dist/src/sourcemaps/tools/nextjs.js +1 -1
  82. package/dist/src/sourcemaps/tools/nextjs.js.map +1 -1
  83. package/dist/src/sourcemaps/tools/remix.d.ts +3 -0
  84. package/dist/src/sourcemaps/tools/remix.js +125 -0
  85. package/dist/src/sourcemaps/tools/remix.js.map +1 -0
  86. package/dist/src/sourcemaps/tools/sentry-cli.js +19 -16
  87. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  88. package/dist/src/sourcemaps/tools/vite.d.ts +2 -1
  89. package/dist/src/sourcemaps/tools/vite.js +99 -12
  90. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  91. package/dist/src/sourcemaps/utils/detect-tool.d.ts +1 -1
  92. package/dist/src/sourcemaps/utils/detect-tool.js +1 -0
  93. package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
  94. package/dist/src/sveltekit/sdk-setup.js +3 -3
  95. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  96. package/dist/src/sveltekit/sveltekit-wizard.js +34 -44
  97. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  98. package/dist/src/telemetry.js +1 -0
  99. package/dist/src/telemetry.js.map +1 -1
  100. package/dist/src/utils/ast-utils.d.ts +2 -2
  101. package/dist/src/utils/ast-utils.js +7 -7
  102. package/dist/src/utils/ast-utils.js.map +1 -1
  103. package/dist/src/utils/clack-utils.d.ts +23 -28
  104. package/dist/src/utils/clack-utils.js +287 -244
  105. package/dist/src/utils/clack-utils.js.map +1 -1
  106. package/dist/src/utils/package-manager.d.ts +10 -0
  107. package/dist/{lib/Helper/PackageManager.js → src/utils/package-manager.js} +42 -74
  108. package/dist/src/utils/package-manager.js.map +1 -0
  109. package/dist/src/utils/release-registry.d.ts +1 -0
  110. package/dist/src/utils/release-registry.js +68 -0
  111. package/dist/src/utils/release-registry.js.map +1 -0
  112. package/dist/src/utils/sentrycli-utils.d.ts +4 -0
  113. package/dist/src/utils/sentrycli-utils.js +41 -0
  114. package/dist/src/utils/sentrycli-utils.js.map +1 -0
  115. package/dist/test/sourcemaps/tools/vite.test.d.ts +1 -0
  116. package/dist/test/sourcemaps/tools/vite.test.js +132 -0
  117. package/dist/test/sourcemaps/tools/vite.test.js.map +1 -0
  118. package/lib/Constants.ts +10 -0
  119. package/lib/Steps/ChooseIntegration.ts +14 -3
  120. package/lib/Steps/Integrations/Android.ts +23 -0
  121. package/lib/Steps/Integrations/Cordova.ts +5 -1
  122. package/lib/Steps/Integrations/ReactNative.ts +9 -3
  123. package/lib/Steps/Integrations/Remix.ts +32 -0
  124. package/lib/Steps/PromptForParameters.ts +48 -3
  125. package/lib/Steps/SentryProjectSelector.ts +3 -1
  126. package/package.json +4 -3
  127. package/src/android/android-wizard.ts +196 -0
  128. package/src/android/code-tools.ts +156 -0
  129. package/src/android/gradle.ts +245 -0
  130. package/src/android/manifest.ts +180 -0
  131. package/src/android/templates.ts +88 -0
  132. package/src/apple/apple-wizard.ts +113 -35
  133. package/src/apple/cocoapod.ts +6 -3
  134. package/src/apple/code-tools.ts +46 -18
  135. package/src/apple/fastlane.ts +6 -12
  136. package/src/apple/templates.ts +2 -8
  137. package/src/apple/xcode-manager.ts +167 -25
  138. package/src/nextjs/nextjs-wizard.ts +72 -8
  139. package/src/nextjs/templates.ts +16 -2
  140. package/src/remix/codemods/handle-error.ts +67 -0
  141. package/src/remix/codemods/root-v1.ts +91 -0
  142. package/src/remix/codemods/root-v2.ts +84 -0
  143. package/src/remix/remix-wizard.ts +132 -0
  144. package/src/remix/sdk-setup.ts +300 -0
  145. package/src/remix/templates.ts +15 -0
  146. package/src/remix/utils.ts +41 -0
  147. package/src/sourcemaps/sourcemaps-wizard.ts +28 -5
  148. package/src/sourcemaps/tools/nextjs.ts +2 -2
  149. package/src/sourcemaps/tools/remix.ts +90 -0
  150. package/src/sourcemaps/tools/sentry-cli.ts +8 -7
  151. package/src/sourcemaps/tools/vite.ts +136 -6
  152. package/src/sourcemaps/utils/detect-tool.ts +4 -1
  153. package/src/sveltekit/sdk-setup.ts +4 -4
  154. package/src/sveltekit/sveltekit-wizard.ts +5 -14
  155. package/src/telemetry.ts +2 -0
  156. package/src/utils/ast-utils.ts +7 -5
  157. package/src/utils/clack-utils.ts +366 -258
  158. package/src/utils/package-manager.ts +61 -0
  159. package/src/utils/release-registry.ts +19 -0
  160. package/src/utils/sentrycli-utils.ts +22 -0
  161. package/test/sourcemaps/tools/vite.test.ts +149 -0
  162. package/dist/lib/Helper/PackageManager.d.ts +0 -22
  163. package/dist/lib/Helper/PackageManager.js.map +0 -1
  164. package/dist/src/utils/vendor/clack-custom-select.d.ts +0 -21
  165. package/dist/src/utils/vendor/clack-custom-select.js +0 -137
  166. package/dist/src/utils/vendor/clack-custom-select.js.map +0 -1
  167. package/lib/Helper/PackageManager.ts +0 -59
  168. package/src/utils/vendor/clack-custom-select.ts +0 -160
@@ -9,5 +9,7 @@ export declare function getSentryExamplePageContents(options: {
9
9
  url: string;
10
10
  orgSlug: string;
11
11
  projectId: string;
12
+ useClient: boolean;
12
13
  }): string;
13
14
  export declare function getSentryExampleApiRoute(): string;
15
+ export declare function getSentryExampleAppDirApiRoute(): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSentryExampleApiRoute = exports.getSentryExamplePageContents = exports.getSentryConfigContents = exports.getNextjsConfigEsmCopyPasteSnippet = exports.getNextjsConfigCjsAppendix = exports.getNextjsConfigCjsTemplate = exports.getNextjsSentryBuildOptionsTemplate = exports.getNextjsWebpackPluginOptionsTemplate = void 0;
3
+ exports.getSentryExampleAppDirApiRoute = exports.getSentryExampleApiRoute = exports.getSentryExamplePageContents = exports.getSentryConfigContents = exports.getNextjsConfigEsmCopyPasteSnippet = exports.getNextjsConfigCjsAppendix = exports.getNextjsConfigCjsTemplate = exports.getNextjsSentryBuildOptionsTemplate = exports.getNextjsWebpackPluginOptionsTemplate = void 0;
4
4
  function getNextjsWebpackPluginOptionsTemplate(orgSlug, projectSlug) {
5
5
  return "{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n // Suppresses source map uploading logs during build\n silent: true,\n\n org: \"".concat(orgSlug, "\",\n project: \"").concat(projectSlug, "\",\n }");
6
6
  }
@@ -44,11 +44,15 @@ function getSentryExamplePageContents(options) {
44
44
  var issuesPageLink = options.selfHosted
45
45
  ? "".concat(options.url, "organizations/").concat(options.orgSlug, "/issues/?project=").concat(options.projectId)
46
46
  : "https://".concat(options.orgSlug, ".sentry.io/issues/?project=").concat(options.projectId);
47
- return "import Head from \"next/head\";\nimport * as Sentry from \"@sentry/nextjs\";\n\nexport default function Home() {\n return (\n <div>\n <Head>\n <title>Sentry Onboarding</title>\n <meta name=\"description\" content=\"Test Sentry for your Next.js app!\" />\n </Head>\n\n <main\n style={{\n minHeight: \"100vh\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n }}\n >\n <h1 style={{ fontSize: \"4rem\", margin: \"14px 0\" }}>\n <svg\n style={{\n height: \"1em\",\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 200 44\"\n >\n <path\n fill=\"currentColor\"\n d=\"M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z\"\n ></path>\n </svg>\n </h1>\n\n <p>Get started by sending us a sample error:</p>\n <button\n type=\"button\"\n style={{\n padding: \"12px\",\n cursor: \"pointer\",\n backgroundColor: \"#AD6CAA\",\n borderRadius: \"4px\",\n border: \"none\",\n color: \"white\",\n fontSize: \"14px\",\n margin: \"18px\",\n }}\n onClick={async () => {\n const transaction = Sentry.startTransaction({\n name: \"Example Frontend Transaction\",\n });\n\n Sentry.configureScope((scope) => {\n scope.setSpan(transaction);\n });\n\n try {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n } finally {\n transaction.finish();\n }\n }}\n >\n Throw error!\n </button>\n\n <p>\n Next, look for the error on the{\" \"}\n <a href=\"".concat(issuesPageLink, "\">Issues Page</a>.\n </p>\n <p style={{ marginTop: \"24px\" }}>\n For more information, see{\" \"}\n <a href=\"https://docs.sentry.io/platforms/javascript/guides/nextjs/\">\n https://docs.sentry.io/platforms/javascript/guides/nextjs/\n </a>\n </p>\n </main>\n </div>\n );\n}\n");
47
+ return "".concat(options.useClient ? '"use client";\n\n' : '', "import Head from \"next/head\";\nimport * as Sentry from \"@sentry/nextjs\";\n\nexport default function Page() {\n return (\n <div>\n <Head>\n <title>Sentry Onboarding</title>\n <meta name=\"description\" content=\"Test Sentry for your Next.js app!\" />\n </Head>\n\n <main\n style={{\n minHeight: \"100vh\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n }}\n >\n <h1 style={{ fontSize: \"4rem\", margin: \"14px 0\" }}>\n <svg\n style={{\n height: \"1em\",\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 200 44\"\n >\n <path\n fill=\"currentColor\"\n d=\"M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z\"\n ></path>\n </svg>\n </h1>\n\n <p>Get started by sending us a sample error:</p>\n <button\n type=\"button\"\n style={{\n padding: \"12px\",\n cursor: \"pointer\",\n backgroundColor: \"#AD6CAA\",\n borderRadius: \"4px\",\n border: \"none\",\n color: \"white\",\n fontSize: \"14px\",\n margin: \"18px\",\n }}\n onClick={async () => {\n const transaction = Sentry.startTransaction({\n name: \"Example Frontend Transaction\",\n });\n\n Sentry.configureScope((scope) => {\n scope.setSpan(transaction);\n });\n\n try {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n } finally {\n transaction.finish();\n }\n }}\n >\n Throw error!\n </button>\n\n <p>\n Next, look for the error on the{\" \"}\n <a href=\"").concat(issuesPageLink, "\">Issues Page</a>.\n </p>\n <p style={{ marginTop: \"24px\" }}>\n For more information, see{\" \"}\n <a href=\"https://docs.sentry.io/platforms/javascript/guides/nextjs/\">\n https://docs.sentry.io/platforms/javascript/guides/nextjs/\n </a>\n </p>\n </main>\n </div>\n );\n}\n");
48
48
  }
49
49
  exports.getSentryExamplePageContents = getSentryExamplePageContents;
50
50
  function getSentryExampleApiRoute() {
51
51
  return "// A faulty API route to test Sentry's error monitoring\nexport default function handler(_req, res) {\n throw new Error(\"Sentry Example API Route Error\");\n res.status(200).json({ name: \"John Doe\" });\n}\n";
52
52
  }
53
53
  exports.getSentryExampleApiRoute = getSentryExampleApiRoute;
54
+ function getSentryExampleAppDirApiRoute() {
55
+ return "import { NextResponse } from \"next/server\";\n\n// A faulty API route to test Sentry's error monitoring\nexport function GET() {\n throw new Error(\"Sentry Example API Route Error\");\n return NextResponse.json({ data: \"Testing Sentry Error...\" });\n}\n";
56
+ }
57
+ exports.getSentryExampleAppDirApiRoute = getSentryExampleAppDirApiRoute;
54
58
  //# sourceMappingURL=templates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/nextjs/templates.ts"],"names":[],"mappings":";;;AAAA,SAAgB,qCAAqC,CACnD,OAAe,EACf,WAAmB;IAEnB,OAAO,oNAOG,OAAO,iCACH,WAAW,aACvB,CAAC;AACL,CAAC;AAdD,sFAcC;AAED,SAAgB,mCAAmC;IACjD,OAAO,usBAkBL,CAAC;AACL,CAAC;AApBD,kFAoBC;AAED,SAAgB,0BAA0B,CACxC,kCAA0C,EAC1C,0BAAkC;IAElC,OAAO,gMAOL,kCAAkC,kBAClC,0B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Content":["export function getNextjsWebpackPluginOptionsTemplate(\n orgSlug: string,\n projectSlug: string,\n): string {\n return `{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n // Suppresses source map uploading logs during build\n silent: true,\n\n org: \"${orgSlug}\",\n project: \"${projectSlug}\",\n }`;\n}\n\nexport function getNextjsSentryBuildOptionsTemplate(): string {\n return `{\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // Transpiles SDK to be compatible with IE11 (increases bundle size)\n transpileClientSDK: true,\n\n // Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)\n tunnelRoute: \"/monitoring\",\n\n // Hides source maps from generated client bundles\n hideSourceMaps: true,\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n }`;\n}\n\nexport function getNextjsConfigCjsTemplate(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: string,\n): string {\n return `const { withSentryConfig } = require(\"@sentry/nextjs\");\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {};\n\nmodule.exports = withSentryConfig(\n nextConfig,\n ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigCjsAppendix(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: string,\n): string {\n return `\n\n// Injected content via Sentry wizard below\n\nconst { withSentryConfig } = require(\"@sentry/nextjs\");\n\nmodule.exports = withSentryConfig(\n module.exports,\n ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigEsmCopyPasteSnippet(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: string,\n): string {\n return `\n\n// next.config.mjs\nimport { withSentryConfig } from \"@sentry/nextjs\";\n\nexport default withSentryConfig(\n yourNextConfig,\n ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getSentryConfigContents(\n dsn: string,\n config: 'server' | 'client' | 'edge',\n): string {\n let primer;\n if (config === 'server') {\n primer = `// This file configures the initialization of Sentry on the server.\n// The config you add here will be used whenever the server handles a request.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'client') {\n primer = `// This file configures the initialization of Sentry on the client.\n// The config you add here will be used whenever a users loads a page in their browser.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'edge') {\n primer = `// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n// The config you add here will be used whenever one of the edge features is loaded.\n// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n }\n\n let additionalOptions = '';\n if (config === 'client') {\n additionalOptions = `\n\n replaysOnErrorSampleRate: 1.0,\n\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n\n // You can remove this option if you're not planning to use the Sentry Session Replay feature:\n integrations: [\n new Sentry.Replay({\n // Additional Replay configuration goes in here, for example:\n maskAllText: true,\n blockAllMedia: true,\n }),\n ],`;\n }\n\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${primer}\n\nimport * as Sentry from \"@sentry/nextjs\";\n\nSentry.init({\n dsn: \"${dsn}\",\n\n // Adjust this value in production, or use tracesSampler for greater control\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,${additionalOptions}\n});\n`;\n}\n\nexport function getSentryExamplePageContents(options: {\n selfHosted: boolean;\n url: string;\n orgSlug: string;\n projectId: string;\n}): string {\n const issuesPageLink = options.selfHosted\n ? `${options.url}organizations/${options.orgSlug}/issues/?project=${options.projectId}`\n : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;\n\n return `import Head from \"next/head\";\nimport * as Sentry from \"@sentry/nextjs\";\n\nexport default function Home() {\n return (\n <div>\n <Head>\n <title>Sentry Onboarding</title>\n <meta name=\"description\" content=\"Test Sentry for your Next.js app!\" />\n </Head>\n\n <main\n style={{\n minHeight: \"100vh\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n }}\n >\n <h1 style={{ fontSize: \"4rem\", margin: \"14px 0\" }}>\n <svg\n style={{\n height: \"1em\",\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 200 44\"\n >\n <path\n fill=\"currentColor\"\n d=\"M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z\"\n ></path>\n </svg>\n </h1>\n\n <p>Get started by sending us a sample error:</p>\n <button\n type=\"button\"\n style={{\n padding: \"12px\",\n cursor: \"pointer\",\n backgroundColor: \"#AD6CAA\",\n borderRadius: \"4px\",\n border: \"none\",\n color: \"white\",\n fontSize: \"14px\",\n margin: \"18px\",\n }}\n onClick={async () => {\n const transaction = Sentry.startTransaction({\n name: \"Example Frontend Transaction\",\n });\n\n Sentry.configureScope((scope) => {\n scope.setSpan(transaction);\n });\n\n try {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n } finally {\n transaction.finish();\n }\n }}\n >\n Throw error!\n </button>\n\n <p>\n Next, look for the error on the{\" \"}\n <a href=\"${issuesPageLink}\">Issues Page</a>.\n </p>\n <p style={{ marginTop: \"24px\" }}>\n For more information, see{\" \"}\n <a href=\"https://docs.sentry.io/platforms/javascript/guides/nextjs/\">\n https://docs.sentry.io/platforms/javascript/guides/nextjs/\n </a>\n </p>\n </main>\n </div>\n );\n}\n`;\n}\n\nexport function getSentryExampleApiRoute() {\n return `// A faulty API route to test Sentry's error monitoring\nexport default function handler(_req, res) {\n throw new Error(\"Sentry Example API Route Error\");\n res.status(200).json({ name: \"John Doe\" });\n}\n`;\n}\n"]}
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/n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UAAG,OAAO,CAAC,GAAG,2BAAiB,OAAO,CAAC,OAAO,8BAAoB,OAAO,CAAC,SAAS,CAAE;QACvF,CAAC,CAAC,kBAAW,OAAO,CAAC,OAAO,wCAA8B,OAAO,CAAC,SAAS,CAAE,CAAC;IAEhF,OAAO,UACL,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,0xGAyE3B,cAAc,8VAYlC,CAAC;AACF,CAAC;AAlGD,oEAkGC;AAED,SAAgB,wBAAwB;IACtC,OAAO,qNAKR,CAAC;AACF,CAAC;AAPD,4DAOC;AAED,SAAgB,8BAA8B;IAC5C,OAAO,oQAOR,CAAC;AACF,CAAC;AATD,wEASC","sourcesContent":["export function getNextjsWebpackPluginOptionsTemplate(\n orgSlug: string,\n projectSlug: string,\n): string {\n return `{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n // Suppresses source map uploading logs during build\n silent: true,\n\n org: \"${orgSlug}\",\n project: \"${projectSlug}\",\n }`;\n}\n\nexport function getNextjsSentryBuildOptionsTemplate(): string {\n return `{\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // Transpiles SDK to be compatible with IE11 (increases bundle size)\n transpileClientSDK: true,\n\n // Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)\n tunnelRoute: \"/monitoring\",\n\n // Hides source maps from generated client bundles\n hideSourceMaps: true,\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n }`;\n}\n\nexport function getNextjsConfigCjsTemplate(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: string,\n): string {\n return `const { withSentryConfig } = require(\"@sentry/nextjs\");\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {};\n\nmodule.exports = withSentryConfig(\n nextConfig,\n ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigCjsAppendix(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: string,\n): string {\n return `\n\n// Injected content via Sentry wizard below\n\nconst { withSentryConfig } = require(\"@sentry/nextjs\");\n\nmodule.exports = withSentryConfig(\n module.exports,\n ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigEsmCopyPasteSnippet(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: string,\n): string {\n return `\n\n// next.config.mjs\nimport { withSentryConfig } from \"@sentry/nextjs\";\n\nexport default withSentryConfig(\n yourNextConfig,\n ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getSentryConfigContents(\n dsn: string,\n config: 'server' | 'client' | 'edge',\n): string {\n let primer;\n if (config === 'server') {\n primer = `// This file configures the initialization of Sentry on the server.\n// The config you add here will be used whenever the server handles a request.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'client') {\n primer = `// This file configures the initialization of Sentry on the client.\n// The config you add here will be used whenever a users loads a page in their browser.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'edge') {\n primer = `// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n// The config you add here will be used whenever one of the edge features is loaded.\n// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n }\n\n let additionalOptions = '';\n if (config === 'client') {\n additionalOptions = `\n\n replaysOnErrorSampleRate: 1.0,\n\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n\n // You can remove this option if you're not planning to use the Sentry Session Replay feature:\n integrations: [\n new Sentry.Replay({\n // Additional Replay configuration goes in here, for example:\n maskAllText: true,\n blockAllMedia: true,\n }),\n ],`;\n }\n\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${primer}\n\nimport * as Sentry from \"@sentry/nextjs\";\n\nSentry.init({\n dsn: \"${dsn}\",\n\n // Adjust this value in production, or use tracesSampler for greater control\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,${additionalOptions}\n});\n`;\n}\n\nexport function getSentryExamplePageContents(options: {\n selfHosted: boolean;\n url: string;\n orgSlug: string;\n projectId: string;\n useClient: boolean;\n}): string {\n const issuesPageLink = options.selfHosted\n ? `${options.url}organizations/${options.orgSlug}/issues/?project=${options.projectId}`\n : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;\n\n return `${\n options.useClient ? '\"use client\";\\n\\n' : ''\n }import Head from \"next/head\";\nimport * as Sentry from \"@sentry/nextjs\";\n\nexport default function Page() {\n return (\n <div>\n <Head>\n <title>Sentry Onboarding</title>\n <meta name=\"description\" content=\"Test Sentry for your Next.js app!\" />\n </Head>\n\n <main\n style={{\n minHeight: \"100vh\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n }}\n >\n <h1 style={{ fontSize: \"4rem\", margin: \"14px 0\" }}>\n <svg\n style={{\n height: \"1em\",\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 200 44\"\n >\n <path\n fill=\"currentColor\"\n d=\"M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z\"\n ></path>\n </svg>\n </h1>\n\n <p>Get started by sending us a sample error:</p>\n <button\n type=\"button\"\n style={{\n padding: \"12px\",\n cursor: \"pointer\",\n backgroundColor: \"#AD6CAA\",\n borderRadius: \"4px\",\n border: \"none\",\n color: \"white\",\n fontSize: \"14px\",\n margin: \"18px\",\n }}\n onClick={async () => {\n const transaction = Sentry.startTransaction({\n name: \"Example Frontend Transaction\",\n });\n\n Sentry.configureScope((scope) => {\n scope.setSpan(transaction);\n });\n\n try {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n } finally {\n transaction.finish();\n }\n }}\n >\n Throw error!\n </button>\n\n <p>\n Next, look for the error on the{\" \"}\n <a href=\"${issuesPageLink}\">Issues Page</a>.\n </p>\n <p style={{ marginTop: \"24px\" }}>\n For more information, see{\" \"}\n <a href=\"https://docs.sentry.io/platforms/javascript/guides/nextjs/\">\n https://docs.sentry.io/platforms/javascript/guides/nextjs/\n </a>\n </p>\n </main>\n </div>\n );\n}\n`;\n}\n\nexport function getSentryExampleApiRoute() {\n return `// A faulty API route to test Sentry's error monitoring\nexport default function handler(_req, res) {\n throw new Error(\"Sentry Example API Route Error\");\n res.status(200).json({ name: \"John Doe\" });\n}\n`;\n}\n\nexport function getSentryExampleAppDirApiRoute() {\n return `import { NextResponse } from \"next/server\";\n\n// A faulty API route to test Sentry's error monitoring\nexport function GET() {\n throw new Error(\"Sentry Example API Route Error\");\n return NextResponse.json({ data: \"Testing Sentry Error...\" });\n}\n`;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { ProxifiedModule } from 'magicast';
2
+ export declare function instrumentHandleError(originalEntryServerMod: ProxifiedModule<any>, serverEntryFilename: string): boolean;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.instrumentHandleError = void 0;
31
+ var recast = __importStar(require("recast"));
32
+ var templates_1 = require("../templates");
33
+ var utils_1 = require("../utils");
34
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
35
+ var prompts_1 = __importDefault(require("@clack/prompts"));
36
+ var chalk_1 = __importDefault(require("chalk"));
37
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
38
+ var magicast_1 = require("magicast");
39
+ function instrumentHandleError(originalEntryServerMod, serverEntryFilename) {
40
+ var originalEntryServerModAST = originalEntryServerMod.$ast;
41
+ var handleErrorFunction = originalEntryServerModAST.body.find(function (node) {
42
+ var _a, _b;
43
+ return node.type === 'ExportNamedDeclaration' &&
44
+ ((_a = node.declaration) === null || _a === void 0 ? void 0 : _a.type) === 'FunctionDeclaration' &&
45
+ ((_b = node.declaration.id) === null || _b === void 0 ? void 0 : _b.name) === 'handleError';
46
+ });
47
+ if (!handleErrorFunction) {
48
+ prompts_1.default.log.warn("Could not find function ".concat(chalk_1.default.cyan('handleError'), " in ").concat(chalk_1.default.cyan(serverEntryFilename), ". Creating one for you."));
49
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
50
+ var implementation = recast.parse(templates_1.HANDLE_ERROR_TEMPLATE_V2).program
51
+ .body[0];
52
+ originalEntryServerModAST.body.splice((0, utils_1.getInitCallInsertionIndex)(originalEntryServerModAST), 0,
53
+ // @ts-expect-error - string works here because the AST is proxified by magicast
54
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
55
+ recast.types.builders.exportNamedDeclaration(implementation));
56
+ }
57
+ else if ((0, utils_1.hasSentryContent)((0, magicast_1.generateCode)(handleErrorFunction).code, originalEntryServerMod.$code)) {
58
+ return false;
59
+ }
60
+ else {
61
+ // @ts-expect-error - string works here because the AST is proxified by magicast
62
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
63
+ handleErrorFunction.declaration.body.body.unshift(
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
65
+ recast.parse(templates_1.HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0]);
66
+ }
67
+ return true;
68
+ }
69
+ exports.instrumentHandleError = instrumentHandleError;
70
+ //# sourceMappingURL=handle-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-error.js","sourceRoot":"","sources":["../../../../src/remix/codemods/handle-error.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAM5D,6CAAiC;AAEjC,0CAAwD;AACxD,kCAAuE;AAEvE,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,kFAAkF;AAClF,qCAAwC;AAExC,SAAgB,qBAAqB,CACnC,sBAA4C,EAC5C,mBAA2B;IAE3B,IAAM,yBAAyB,GAAG,sBAAsB,CAAC,IAAe,CAAC;IAEzE,IAAM,mBAAmB,GAAG,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAC7D,UAAC,IAAI;;QACH,OAAA,IAAI,CAAC,IAAI,KAAK,wBAAwB;YACtC,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,MAAK,qBAAqB;YAChD,CAAA,MAAA,IAAI,CAAC,WAAW,CAAC,EAAE,0CAAE,IAAI,MAAK,aAAa,CAAA;KAAA,CAC9C,CAAC;IAEF,IAAI,CAAC,mBAAmB,EAAE;QACxB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,kCAA2B,eAAK,CAAC,IAAI,CAAC,aAAa,CAAC,iBAAO,eAAK,CAAC,IAAI,CACnE,mBAAmB,CACpB,4BAAyB,CAC3B,CAAC;QAEF,sEAAsE;QACtE,IAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,oCAAwB,CAAC,CAAC,OAAO;aAClE,IAAI,CAAC,CAAC,CAAC,CAAC;QAEX,yBAAyB,CAAC,IAAI,CAAC,MAAM,CACnC,IAAA,iCAAyB,EAAC,yBAAyB,CAAC,EACpD,CAAC;QACD,gFAAgF;QAChF,iEAAiE;QACjE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAC7D,CAAC;KACH;SAAM,IACL,IAAA,wBAAgB,EACd,IAAA,uBAAY,EAAC,mBAAmB,CAAC,CAAC,IAAI,EACtC,sBAAsB,CAAC,KAAK,CAC7B,EACD;QACA,OAAO,KAAK,CAAC;KACd;SAAM;QACL,gFAAgF;QAChF,yGAAyG;QACzG,mBAAmB,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO;QAC/C,sEAAsE;QACtE,MAAM,CAAC,KAAK,CAAC,oCAAwB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CACpE,CAAC;KACH;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAhDD,sDAgDC","sourcesContent":["/* 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';\nimport type { Program } from '@babel/types';\n\nimport * as recast from 'recast';\n\nimport { HANDLE_ERROR_TEMPLATE_V2 } from '../templates';\nimport { getInitCallInsertionIndex, hasSentryContent } from '../utils';\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 } from 'magicast';\n\nexport function instrumentHandleError(\n originalEntryServerMod: ProxifiedModule<any>,\n serverEntryFilename: string,\n): boolean {\n const originalEntryServerModAST = originalEntryServerMod.$ast as Program;\n\n const handleErrorFunction = originalEntryServerModAST.body.find(\n (node) =>\n node.type === 'ExportNamedDeclaration' &&\n node.declaration?.type === 'FunctionDeclaration' &&\n node.declaration.id?.name === 'handleError',\n );\n\n if (!handleErrorFunction) {\n clack.log.warn(\n `Could not find function ${chalk.cyan('handleError')} in ${chalk.cyan(\n serverEntryFilename,\n )}. Creating one for you.`,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program\n .body[0];\n\n originalEntryServerModAST.body.splice(\n getInitCallInsertionIndex(originalEntryServerModAST),\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n recast.types.builders.exportNamedDeclaration(implementation),\n );\n } else if (\n hasSentryContent(\n generateCode(handleErrorFunction).code,\n originalEntryServerMod.$code,\n )\n ) {\n return false;\n } else {\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n handleErrorFunction.declaration.body.body.unshift(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n recast.parse(HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0],\n );\n }\n\n return true;\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function instrumentRootRouteV1(rootFileName: string): Promise<void>;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ var __generator = (this && this.__generator) || function (thisArg, body) {
36
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
37
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
38
+ function verb(n) { return function (v) { return step([n, v]); }; }
39
+ function step(op) {
40
+ if (f) throw new TypeError("Generator is already executing.");
41
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
42
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
43
+ if (y = 0, t) op = [op[0] & 2, t.value];
44
+ switch (op[0]) {
45
+ case 0: case 1: t = op; break;
46
+ case 4: _.label++; return { value: op[1], done: false };
47
+ case 5: _.label++; y = op[1]; op = [0]; continue;
48
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
49
+ default:
50
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
51
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
52
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
53
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
54
+ if (t[2]) _.ops.pop();
55
+ _.trys.pop(); continue;
56
+ }
57
+ op = body.call(thisArg, _);
58
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
59
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
60
+ }
61
+ };
62
+ var __importDefault = (this && this.__importDefault) || function (mod) {
63
+ return (mod && mod.__esModule) ? mod : { "default": mod };
64
+ };
65
+ Object.defineProperty(exports, "__esModule", { value: true });
66
+ exports.instrumentRootRouteV1 = void 0;
67
+ var recast = __importStar(require("recast"));
68
+ var path = __importStar(require("path"));
69
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
70
+ var prompts_1 = __importDefault(require("@clack/prompts"));
71
+ var chalk_1 = __importDefault(require("chalk"));
72
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
73
+ var magicast_1 = require("magicast");
74
+ function instrumentRootRouteV1(rootFileName) {
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ var rootRouteAst_1, e_1;
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0:
80
+ _a.trys.push([0, 3, , 4]);
81
+ return [4 /*yield*/, (0, magicast_1.loadFile)(path.join(process.cwd(), 'app', rootFileName))];
82
+ case 1:
83
+ rootRouteAst_1 = _a.sent();
84
+ rootRouteAst_1.imports.$add({
85
+ from: '@sentry/remix',
86
+ imported: 'withSentry',
87
+ local: 'withSentry',
88
+ });
89
+ recast.visit(rootRouteAst_1.$ast, {
90
+ visitExportDefaultDeclaration: function (path) {
91
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
92
+ if (path.value.declaration.type === 'FunctionDeclaration') {
93
+ // Move the function declaration just before the default export
94
+ path.insertBefore(path.value.declaration);
95
+ // Get the name of the function to be wrapped
96
+ var functionName = path.value.declaration.id.name;
97
+ // Create the wrapped function call
98
+ var functionCall = recast.types.builders.callExpression(recast.types.builders.identifier('withSentry'), [recast.types.builders.identifier(functionName)]);
99
+ // Replace the default export with the wrapped function call
100
+ path.value.declaration = functionCall;
101
+ }
102
+ else if (path.value.declaration.type === 'Identifier') {
103
+ var rootRouteExport = rootRouteAst_1.exports.default;
104
+ var expressionToWrap = (0, magicast_1.generateCode)(
105
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
106
+ rootRouteExport.$ast).code;
107
+ rootRouteAst_1.exports.default = magicast_1.builders.raw("withSentry(".concat(expressionToWrap, ")"));
108
+ }
109
+ else {
110
+ prompts_1.default.log.warn(chalk_1.default.yellow("Couldn't instrument ".concat(chalk_1.default.bold(rootFileName), " automatically. Wrap your default export with: ").concat(chalk_1.default.dim('withSentry()'), "\n")));
111
+ }
112
+ this.traverse(path);
113
+ /* eslint-enable @typescript-eslint/no-unsafe-member-access */
114
+ },
115
+ });
116
+ return [4 /*yield*/, (0, magicast_1.writeFile)(rootRouteAst_1.$ast, path.join(process.cwd(), 'app', rootFileName))];
117
+ case 2:
118
+ _a.sent();
119
+ return [3 /*break*/, 4];
120
+ case 3:
121
+ e_1 = _a.sent();
122
+ // eslint-disable-next-line no-console
123
+ console.error(e_1);
124
+ prompts_1.default.log.warn(chalk_1.default.yellow("Something went wrong writing to ".concat(chalk_1.default.bold(rootFileName))));
125
+ prompts_1.default.log.info("Please put the following code snippet into ".concat(chalk_1.default.bold(rootFileName), ": ").concat(chalk_1.default.dim('You probably have to clean it up a bit.'), "\n"));
126
+ return [3 /*break*/, 4];
127
+ case 4: return [2 /*return*/];
128
+ }
129
+ });
130
+ });
131
+ }
132
+ exports.instrumentRootRouteV1 = instrumentRootRouteV1;
133
+ //# sourceMappingURL=root-v1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-v1.js","sourceRoot":"","sources":["../../../../src/remix/codemods/root-v1.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5D,6CAAiC;AACjC,yCAA6B;AAE7B,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,kFAAkF;AAClF,qCAAuE;AAEvE,SAAsB,qBAAqB,CACzC,YAAoB;;;;;;;oBAGG,qBAAM,IAAA,mBAAQ,EACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAFK,iBAAe,SAEpB;oBAED,cAAY,CAAC,OAAO,CAAC,IAAI,CAAC;wBACxB,IAAI,EAAE,eAAe;wBACrB,QAAQ,EAAE,YAAY;wBACtB,KAAK,EAAE,YAAY;qBACpB,CAAC,CAAC;oBAEH,MAAM,CAAC,KAAK,CAAC,cAAY,CAAC,IAAI,EAAE;wBAC9B,6BAA6B,YAAC,IAAI;4BAChC,+DAA+D;4BAC/D,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,qBAAqB,EAAE;gCACzD,+DAA+D;gCAC/D,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;gCAE1C,6CAA6C;gCAC7C,IAAM,YAAY,GAAW,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,IAAc,CAAC;gCAEtE,mCAAmC;gCACnC,IAAM,YAAY,G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AmC,eAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAE,CAC9D,CACF,CAAC;oBACF,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,qDAA8C,eAAK,CAAC,IAAI,CACtD,YAAY,CACb,eAAK,eAAK,CAAC,GAAG,CAAC,yCAAyC,CAAC,OAAI,CAC/D,CAAC;;;;;;CAEL;AA9ED,sDA8EC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport * as recast from 'recast';\nimport * as path from 'path';\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 { builders, generateCode, loadFile, writeFile } from 'magicast';\n\nexport async function instrumentRootRouteV1(\n rootFileName: string,\n): Promise<void> {\n try {\n const rootRouteAst = await loadFile(\n path.join(process.cwd(), 'app', rootFileName),\n );\n\n rootRouteAst.imports.$add({\n from: '@sentry/remix',\n imported: 'withSentry',\n local: 'withSentry',\n });\n\n recast.visit(rootRouteAst.$ast, {\n visitExportDefaultDeclaration(path) {\n /* eslint-disable @typescript-eslint/no-unsafe-member-access */\n if (path.value.declaration.type === 'FunctionDeclaration') {\n // Move the function declaration just before the default export\n path.insertBefore(path.value.declaration);\n\n // Get the name of the function to be wrapped\n const functionName: string = path.value.declaration.id.name as string;\n\n // Create the wrapped function call\n const functionCall = recast.types.builders.callExpression(\n recast.types.builders.identifier('withSentry'),\n [recast.types.builders.identifier(functionName)],\n );\n\n // Replace the default export with the wrapped function call\n path.value.declaration = functionCall;\n } else if (path.value.declaration.type === 'Identifier') {\n const rootRouteExport = rootRouteAst.exports.default;\n\n const expressionToWrap = generateCode(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n rootRouteExport.$ast,\n ).code;\n\n rootRouteAst.exports.default = builders.raw(\n `withSentry(${expressionToWrap})`,\n );\n } else {\n clack.log.warn(\n chalk.yellow(\n `Couldn't instrument ${chalk.bold(\n rootFileName,\n )} automatically. Wrap your default export with: ${chalk.dim(\n 'withSentry()',\n )}\\n`,\n ),\n );\n }\n\n this.traverse(path);\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n },\n });\n\n await writeFile(\n rootRouteAst.$ast,\n path.join(process.cwd(), 'app', rootFileName),\n );\n } catch (e: unknown) {\n // eslint-disable-next-line no-console\n console.error(e);\n clack.log.warn(\n chalk.yellow(\n `Something went wrong writing to ${chalk.bold(rootFileName)}`,\n ),\n );\n clack.log.info(\n `Please put the following code snippet into ${chalk.bold(\n rootFileName,\n )}: ${chalk.dim('You probably have to clean it up a bit.')}\\n`,\n );\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function instrumentRootRouteV2(rootFileName: string): Promise<void>;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ var __generator = (this && this.__generator) || function (thisArg, body) {
36
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
37
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
38
+ function verb(n) { return function (v) { return step([n, v]); }; }
39
+ function step(op) {
40
+ if (f) throw new TypeError("Generator is already executing.");
41
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
42
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
43
+ if (y = 0, t) op = [op[0] & 2, t.value];
44
+ switch (op[0]) {
45
+ case 0: case 1: t = op; break;
46
+ case 4: _.label++; return { value: op[1], done: false };
47
+ case 5: _.label++; y = op[1]; op = [0]; continue;
48
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
49
+ default:
50
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
51
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
52
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
53
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
54
+ if (t[2]) _.ops.pop();
55
+ _.trys.pop(); continue;
56
+ }
57
+ op = body.call(thisArg, _);
58
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
59
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
60
+ }
61
+ };
62
+ Object.defineProperty(exports, "__esModule", { value: true });
63
+ exports.instrumentRootRouteV2 = void 0;
64
+ var recast = __importStar(require("recast"));
65
+ var path = __importStar(require("path"));
66
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
67
+ var magicast_1 = require("magicast");
68
+ var templates_1 = require("../templates");
69
+ function instrumentRootRouteV2(rootFileName) {
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ var rootRouteAst, exportsAst, namedExports, foundErrorBoundary;
72
+ return __generator(this, function (_a) {
73
+ switch (_a.label) {
74
+ case 0: return [4 /*yield*/, (0, magicast_1.loadFile)(path.join(process.cwd(), 'app', rootFileName))];
75
+ case 1:
76
+ rootRouteAst = _a.sent();
77
+ exportsAst = rootRouteAst.exports.$ast;
78
+ namedExports = exportsAst.body.filter(function (node) { return node.type === 'ExportNamedDeclaration'; });
79
+ foundErrorBoundary = false;
80
+ namedExports.forEach(function (namedExport) {
81
+ var _a;
82
+ var declaration = namedExport.declaration;
83
+ if (!declaration) {
84
+ return;
85
+ }
86
+ if (declaration.type === 'FunctionDeclaration') {
87
+ if (((_a = declaration.id) === null || _a === void 0 ? void 0 : _a.name) === 'ErrorBoundary') {
88
+ foundErrorBoundary = true;
89
+ }
90
+ }
91
+ else if (declaration.type === 'VariableDeclaration') {
92
+ var declarations = declaration.declarations;
93
+ declarations.forEach(function (declaration) {
94
+ var _a;
95
+ // @ts-expect-error - id should always have a name in this case
96
+ if (((_a = declaration.id) === null || _a === void 0 ? void 0 : _a.name) === 'ErrorBoundary') {
97
+ foundErrorBoundary = true;
98
+ }
99
+ });
100
+ }
101
+ });
102
+ if (!foundErrorBoundary) {
103
+ rootRouteAst.imports.$add({
104
+ from: '@sentry/remix',
105
+ imported: 'captureRemixErrorBoundaryError',
106
+ local: 'captureRemixErrorBoundaryError',
107
+ });
108
+ rootRouteAst.imports.$add({
109
+ from: '@remix-run/react',
110
+ imported: 'useRouteError',
111
+ local: 'useRouteError',
112
+ });
113
+ recast.visit(rootRouteAst.$ast, {
114
+ visitExportDefaultDeclaration: function (path) {
115
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
116
+ var implementation = recast.parse(templates_1.ERROR_BOUNDARY_TEMPLATE_V2).program
117
+ .body[0];
118
+ path.insertBefore(
119
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
120
+ recast.types.builders.exportDeclaration(false, implementation));
121
+ this.traverse(path);
122
+ },
123
+ });
124
+ }
125
+ return [4 /*yield*/, (0, magicast_1.writeFile)(rootRouteAst.$ast, path.join(process.cwd(), 'app', rootFileName))];
126
+ case 2:
127
+ _a.sent();
128
+ return [2 /*return*/];
129
+ }
130
+ });
131
+ });
132
+ }
133
+ exports.instrumentRootRouteV2 = instrumentRootRouteV2;
134
+ //# sourceMappingURL=root-v2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root-v2.js","sourceRoot":"","sources":["../../../../src/remix/codemods/root-v2.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5D,6CAAiC;AACjC,yCAA6B;AAI7B,kFAAkF;AAClF,qCAA+C;AAE/C,0CAA0D;AAE1D,SAAsB,qBAAqB,CACzC,YAAoB;;;;;wBAEC,qBAAM,IAAA,mBAAQ,EACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAFK,YAAY,GAAG,SAEpB;oBAEK,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,IAAe,CAAC;oBAElD,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CACzC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,IAAI,KAAK,wBAAwB,EAAtC,CAA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C,CAAC,CAAC;gCAEX,IAAI,CAAC,YAAY;gCACf,iEAAiE;gCACjE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE,cAAc,CAAC,CAC/D,CAAC;gCAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;4BACtB,CAAC;yBACF,CAAC,CAAC;qBACJ;oBAED,qBAAM,IAAA,oBAAS,EACb,YAAY,CAAC,IAAI,EACjB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAHD,SAGC,CAAC;;;;;CACH;AAvED,sDAuEC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport * as recast from 'recast';\nimport * as path from 'path';\n\nimport type { ExportNamedDeclaration, Program } from '@babel/types';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { loadFile, writeFile } from 'magicast';\n\nimport { ERROR_BOUNDARY_TEMPLATE_V2 } from '../templates';\n\nexport async function instrumentRootRouteV2(\n rootFileName: string,\n): Promise<void> {\n const rootRouteAst = await loadFile(\n path.join(process.cwd(), 'app', rootFileName),\n );\n\n const exportsAst = rootRouteAst.exports.$ast as Program;\n\n const namedExports = exportsAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n let foundErrorBoundary = false;\n\n namedExports.forEach((namedExport) => {\n const declaration = namedExport.declaration;\n\n if (!declaration) {\n return;\n }\n\n if (declaration.type === 'FunctionDeclaration') {\n if (declaration.id?.name === 'ErrorBoundary') {\n foundErrorBoundary = true;\n }\n } else if (declaration.type === 'VariableDeclaration') {\n const declarations = declaration.declarations;\n\n declarations.forEach((declaration) => {\n // @ts-expect-error - id should always have a name in this case\n if (declaration.id?.name === 'ErrorBoundary') {\n foundErrorBoundary = true;\n }\n });\n }\n });\n\n if (!foundErrorBoundary) {\n rootRouteAst.imports.$add({\n from: '@sentry/remix',\n imported: 'captureRemixErrorBoundaryError',\n local: 'captureRemixErrorBoundaryError',\n });\n\n rootRouteAst.imports.$add({\n from: '@remix-run/react',\n imported: 'useRouteError',\n local: 'useRouteError',\n });\n\n recast.visit(rootRouteAst.$ast, {\n visitExportDefaultDeclaration(path) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(ERROR_BOUNDARY_TEMPLATE_V2).program\n .body[0];\n\n path.insertBefore(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n recast.types.builders.exportDeclaration(false, implementation),\n );\n\n this.traverse(path);\n },\n });\n }\n\n await writeFile(\n rootRouteAst.$ast,\n path.join(process.cwd(), 'app', rootFileName),\n );\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { WizardOptions } from '../utils/types';
2
+ export declare function runRemixWizard(options: WizardOptions): Promise<void>;