@sentry/wizard 3.42.1 → 4.0.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 (338) hide show
  1. package/.node-cache/node-v22.14.0-darwin-arm64 +0 -0
  2. package/.node-cache/node-v22.14.0-darwin-x64 +0 -0
  3. package/.node-cache/node-v22.14.0-linux-arm64 +0 -0
  4. package/.node-cache/node-v22.14.0-linux-x64 +0 -0
  5. package/.node-cache/node-v22.14.0-win-x64.exe +0 -0
  6. package/CHANGELOG.md +26 -0
  7. package/COPYING +3575 -0
  8. package/bin.ts +85 -80
  9. package/dist/bin.js +44 -35
  10. package/dist/bin.js.map +1 -1
  11. package/dist/e2e-tests/jest.config.js +1 -1
  12. package/dist/e2e-tests/jest.config.js.map +1 -1
  13. package/dist/e2e-tests/tests/flutter.test.js +62 -147
  14. package/dist/e2e-tests/tests/flutter.test.js.map +1 -1
  15. package/dist/e2e-tests/tests/nextjs.test.js +77 -175
  16. package/dist/e2e-tests/tests/nextjs.test.js.map +1 -1
  17. package/dist/e2e-tests/tests/nuxt-3.test.js +61 -162
  18. package/dist/e2e-tests/tests/nuxt-3.test.js.map +1 -1
  19. package/dist/e2e-tests/tests/nuxt-4.test.js +62 -163
  20. package/dist/e2e-tests/tests/nuxt-4.test.js.map +1 -1
  21. package/dist/e2e-tests/tests/remix.test.js +147 -189
  22. package/dist/e2e-tests/tests/remix.test.js.map +1 -1
  23. package/dist/e2e-tests/tests/sveltekit.test.js +133 -187
  24. package/dist/e2e-tests/tests/sveltekit.test.js.map +1 -1
  25. package/dist/e2e-tests/utils/index.d.ts +1 -1
  26. package/dist/e2e-tests/utils/index.js +113 -195
  27. package/dist/e2e-tests/utils/index.js.map +1 -1
  28. package/dist/lib/Constants.js +5 -5
  29. package/dist/lib/Constants.js.map +1 -1
  30. package/dist/lib/Helper/BottomBar.d.ts +1 -1
  31. package/dist/lib/Helper/BottomBar.js +14 -15
  32. package/dist/lib/Helper/BottomBar.js.map +1 -1
  33. package/dist/lib/Helper/Env.js +5 -2
  34. package/dist/lib/Helper/Env.js.map +1 -1
  35. package/dist/lib/Helper/File.js +14 -27
  36. package/dist/lib/Helper/File.js.map +1 -1
  37. package/dist/lib/Helper/Git.js +24 -59
  38. package/dist/lib/Helper/Git.js.map +1 -1
  39. package/dist/lib/Helper/Logging.js +2 -2
  40. package/dist/lib/Helper/Logging.js.map +1 -1
  41. package/dist/lib/Helper/MergeConfig.js +4 -4
  42. package/dist/lib/Helper/MergeConfig.js.map +1 -1
  43. package/dist/lib/Helper/Package.d.ts +4 -1
  44. package/dist/lib/Helper/Package.js +12 -38
  45. package/dist/lib/Helper/Package.js.map +1 -1
  46. package/dist/lib/Helper/SentryCli.js +77 -149
  47. package/dist/lib/Helper/SentryCli.js.map +1 -1
  48. package/dist/lib/Helper/Wizard.js +29 -124
  49. package/dist/lib/Helper/Wizard.js.map +1 -1
  50. package/dist/lib/Helper/__tests__/File.js +4 -4
  51. package/dist/lib/Helper/__tests__/File.js.map +1 -1
  52. package/dist/lib/Helper/__tests__/MergeConfig.js +24 -24
  53. package/dist/lib/Helper/__tests__/MergeConfig.js.map +1 -1
  54. package/dist/lib/Helper/__tests__/SentryCli.js +33 -23
  55. package/dist/lib/Helper/__tests__/SentryCli.js.map +1 -1
  56. package/dist/lib/Setup.js +23 -85
  57. package/dist/lib/Setup.js.map +1 -1
  58. package/dist/lib/Steps/BaseStep.js +8 -8
  59. package/dist/lib/Steps/BaseStep.js.map +1 -1
  60. package/dist/lib/Steps/ChooseIntegration.js +80 -125
  61. package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
  62. package/dist/lib/Steps/ConfigureProject.js +6 -66
  63. package/dist/lib/Steps/ConfigureProject.js.map +1 -1
  64. package/dist/lib/Steps/Initial.js +16 -104
  65. package/dist/lib/Steps/Initial.js.map +1 -1
  66. package/dist/lib/Steps/Integrations/BaseIntegration.js +24 -118
  67. package/dist/lib/Steps/Integrations/BaseIntegration.js.map +1 -1
  68. package/dist/lib/Steps/Integrations/Cordova.js +95 -183
  69. package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
  70. package/dist/lib/Steps/Integrations/Electron.js +87 -145
  71. package/dist/lib/Steps/Integrations/Electron.js.map +1 -1
  72. package/dist/lib/Steps/Integrations/MobileProject.js +40 -148
  73. package/dist/lib/Steps/Integrations/MobileProject.js.map +1 -1
  74. package/dist/lib/Steps/OpenSentry.js +63 -126
  75. package/dist/lib/Steps/OpenSentry.js.map +1 -1
  76. package/dist/lib/Steps/PromptForParameters.js +110 -206
  77. package/dist/lib/Steps/PromptForParameters.js.map +1 -1
  78. package/dist/lib/Steps/Result.js +19 -79
  79. package/dist/lib/Steps/Result.js.map +1 -1
  80. package/dist/lib/Steps/SentryProjectSelector.js +57 -148
  81. package/dist/lib/Steps/SentryProjectSelector.js.map +1 -1
  82. package/dist/lib/Steps/ShouldConfigure.js +6 -66
  83. package/dist/lib/Steps/ShouldConfigure.js.map +1 -1
  84. package/dist/lib/Steps/WaitForSentry.js +43 -120
  85. package/dist/lib/Steps/WaitForSentry.js.map +1 -1
  86. package/dist/lib/Steps/Welcome.js +17 -76
  87. package/dist/lib/Steps/Welcome.js.map +1 -1
  88. package/dist/lib/__tests__/Env.js +3 -3
  89. package/dist/lib/__tests__/Env.js.map +1 -1
  90. package/dist/src/android/android-wizard.js +100 -176
  91. package/dist/src/android/android-wizard.js.map +1 -1
  92. package/dist/src/android/code-tools.js +24 -33
  93. package/dist/src/android/code-tools.js.map +1 -1
  94. package/dist/src/android/gradle.js +106 -165
  95. package/dist/src/android/gradle.js.map +1 -1
  96. package/dist/src/android/manifest.js +26 -27
  97. package/dist/src/android/manifest.js.map +1 -1
  98. package/dist/src/android/templates.js +76 -23
  99. package/dist/src/android/templates.js.map +1 -1
  100. package/dist/src/apple/apple-wizard.js +129 -225
  101. package/dist/src/apple/apple-wizard.js.map +1 -1
  102. package/dist/src/apple/cocoapod.js +47 -109
  103. package/dist/src/apple/cocoapod.js.map +1 -1
  104. package/dist/src/apple/code-tools.js +32 -35
  105. package/dist/src/apple/code-tools.js.map +1 -1
  106. package/dist/src/apple/fastlane.js +51 -97
  107. package/dist/src/apple/fastlane.js.map +1 -1
  108. package/dist/src/apple/templates.js +41 -5
  109. package/dist/src/apple/templates.js.map +1 -1
  110. package/dist/src/apple/xcode-manager.d.ts +2 -2
  111. package/dist/src/apple/xcode-manager.js +93 -108
  112. package/dist/src/apple/xcode-manager.js.map +1 -1
  113. package/dist/src/flutter/code-tools.js +79 -127
  114. package/dist/src/flutter/code-tools.js.map +1 -1
  115. package/dist/src/flutter/flutter-wizard.js +75 -136
  116. package/dist/src/flutter/flutter-wizard.js.map +1 -1
  117. package/dist/src/flutter/templates.js +48 -12
  118. package/dist/src/flutter/templates.js.map +1 -1
  119. package/dist/src/nextjs/nextjs-wizard.js +527 -805
  120. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  121. package/dist/src/nextjs/templates.js +380 -40
  122. package/dist/src/nextjs/templates.js.map +1 -1
  123. package/dist/src/nextjs/utils.js +5 -5
  124. package/dist/src/nextjs/utils.js.map +1 -1
  125. package/dist/src/nuxt/nuxt-wizard.js +91 -188
  126. package/dist/src/nuxt/nuxt-wizard.js.map +1 -1
  127. package/dist/src/nuxt/sdk-example.js +68 -137
  128. package/dist/src/nuxt/sdk-example.js.map +1 -1
  129. package/dist/src/nuxt/sdk-setup.d.ts +4 -4
  130. package/dist/src/nuxt/sdk-setup.js +180 -336
  131. package/dist/src/nuxt/sdk-setup.js.map +1 -1
  132. package/dist/src/nuxt/templates.js +195 -18
  133. package/dist/src/nuxt/templates.js.map +1 -1
  134. package/dist/src/nuxt/utils.js +29 -76
  135. package/dist/src/nuxt/utils.js.map +1 -1
  136. package/dist/src/react-native/expo-env-file.js +41 -94
  137. package/dist/src/react-native/expo-env-file.js.map +1 -1
  138. package/dist/src/react-native/expo-metro.d.ts +1 -1
  139. package/dist/src/react-native/expo-metro.js +75 -130
  140. package/dist/src/react-native/expo-metro.js.map +1 -1
  141. package/dist/src/react-native/expo.js +61 -114
  142. package/dist/src/react-native/expo.js.map +1 -1
  143. package/dist/src/react-native/git.js +23 -56
  144. package/dist/src/react-native/git.js.map +1 -1
  145. package/dist/src/react-native/glob.js +3 -3
  146. package/dist/src/react-native/glob.js.map +1 -1
  147. package/dist/src/react-native/gradle.js +4 -4
  148. package/dist/src/react-native/gradle.js.map +1 -1
  149. package/dist/src/react-native/javascript.js +51 -95
  150. package/dist/src/react-native/javascript.js.map +1 -1
  151. package/dist/src/react-native/metro.js +176 -296
  152. package/dist/src/react-native/metro.js.map +1 -1
  153. package/dist/src/react-native/react-native-wizard.js +267 -418
  154. package/dist/src/react-native/react-native-wizard.js.map +1 -1
  155. package/dist/src/react-native/uninstall.js +37 -80
  156. package/dist/src/react-native/uninstall.js.map +1 -1
  157. package/dist/src/react-native/xcode.js +57 -55
  158. package/dist/src/react-native/xcode.js.map +1 -1
  159. package/dist/src/remix/codemods/express-server.js +27 -82
  160. package/dist/src/remix/codemods/express-server.js.map +1 -1
  161. package/dist/src/remix/codemods/handle-error.js +28 -31
  162. package/dist/src/remix/codemods/handle-error.js.map +1 -1
  163. package/dist/src/remix/codemods/root-common.js +11 -11
  164. package/dist/src/remix/codemods/root-common.js.map +1 -1
  165. package/dist/src/remix/codemods/root-v1.js +17 -67
  166. package/dist/src/remix/codemods/root-v1.js.map +1 -1
  167. package/dist/src/remix/codemods/root-v2.js +89 -140
  168. package/dist/src/remix/codemods/root-v2.js.map +1 -1
  169. package/dist/src/remix/remix-wizard.js +181 -343
  170. package/dist/src/remix/remix-wizard.js.map +1 -1
  171. package/dist/src/remix/sdk-example.js +84 -66
  172. package/dist/src/remix/sdk-example.js.map +1 -1
  173. package/dist/src/remix/sdk-setup.js +161 -293
  174. package/dist/src/remix/sdk-setup.js.map +1 -1
  175. package/dist/src/remix/templates.js +10 -2
  176. package/dist/src/remix/templates.js.map +1 -1
  177. package/dist/src/remix/utils.js +13 -14
  178. package/dist/src/remix/utils.js.map +1 -1
  179. package/dist/src/run.js +106 -178
  180. package/dist/src/run.js.map +1 -1
  181. package/dist/src/sourcemaps/sourcemaps-wizard.js +248 -372
  182. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  183. package/dist/src/sourcemaps/tools/angular.js +32 -66
  184. package/dist/src/sourcemaps/tools/angular.js.map +1 -1
  185. package/dist/src/sourcemaps/tools/create-react-app.js +14 -59
  186. package/dist/src/sourcemaps/tools/create-react-app.js.map +1 -1
  187. package/dist/src/sourcemaps/tools/esbuild.js +34 -77
  188. package/dist/src/sourcemaps/tools/esbuild.js.map +1 -1
  189. package/dist/src/sourcemaps/tools/nextjs.d.ts +2 -2
  190. package/dist/src/sourcemaps/tools/nextjs.js +75 -102
  191. package/dist/src/sourcemaps/tools/nextjs.js.map +1 -1
  192. package/dist/src/sourcemaps/tools/remix.js +53 -93
  193. package/dist/src/sourcemaps/tools/remix.js.map +1 -1
  194. package/dist/src/sourcemaps/tools/rollup.js +35 -76
  195. package/dist/src/sourcemaps/tools/rollup.js.map +1 -1
  196. package/dist/src/sourcemaps/tools/sentry-cli.js +157 -289
  197. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  198. package/dist/src/sourcemaps/tools/tsc.js +68 -134
  199. package/dist/src/sourcemaps/tools/tsc.js.map +1 -1
  200. package/dist/src/sourcemaps/tools/vite.js +111 -196
  201. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  202. package/dist/src/sourcemaps/tools/webpack.d.ts +1 -1
  203. package/dist/src/sourcemaps/tools/webpack.js +158 -260
  204. package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
  205. package/dist/src/sourcemaps/utils/detect-tool.js +9 -54
  206. package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
  207. package/dist/src/sourcemaps/utils/other-wizards.js +77 -144
  208. package/dist/src/sourcemaps/utils/other-wizards.js.map +1 -1
  209. package/dist/src/sourcemaps/utils/sdk-version.js +112 -191
  210. package/dist/src/sourcemaps/utils/sdk-version.js.map +1 -1
  211. package/dist/src/sveltekit/sdk-example.js +20 -70
  212. package/dist/src/sveltekit/sdk-example.js.map +1 -1
  213. package/dist/src/sveltekit/sdk-setup.js +250 -411
  214. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  215. package/dist/src/sveltekit/sveltekit-wizard.js +107 -191
  216. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  217. package/dist/src/sveltekit/templates.js +147 -13
  218. package/dist/src/sveltekit/templates.js.map +1 -1
  219. package/dist/src/sveltekit/utils.js +3 -3
  220. package/dist/src/sveltekit/utils.js.map +1 -1
  221. package/dist/src/telemetry.d.ts +2 -2
  222. package/dist/src/telemetry.js +58 -108
  223. package/dist/src/telemetry.js.map +1 -1
  224. package/dist/src/utils/ast-utils.js +39 -54
  225. package/dist/src/utils/ast-utils.js.map +1 -1
  226. package/dist/src/utils/bash.js +28 -75
  227. package/dist/src/utils/bash.js.map +1 -1
  228. package/dist/src/utils/clack-utils.d.ts +3 -7
  229. package/dist/src/utils/clack-utils.js +688 -1083
  230. package/dist/src/utils/clack-utils.js.map +1 -1
  231. package/dist/src/utils/debug.js +6 -10
  232. package/dist/src/utils/debug.js.map +1 -1
  233. package/dist/src/utils/package-json.js +5 -6
  234. package/dist/src/utils/package-json.js.map +1 -1
  235. package/dist/src/utils/package-manager.js +65 -139
  236. package/dist/src/utils/package-manager.js.map +1 -1
  237. package/dist/src/utils/release-registry.js +12 -59
  238. package/dist/src/utils/release-registry.js.map +1 -1
  239. package/dist/src/utils/semver.js +3 -4
  240. package/dist/src/utils/semver.js.map +1 -1
  241. package/dist/src/utils/sentrycli-utils.js +4 -4
  242. package/dist/src/utils/sentrycli-utils.js.map +1 -1
  243. package/dist/src/utils/url.js +5 -6
  244. package/dist/src/utils/url.js.map +1 -1
  245. package/dist/test/android/code-tools.test.js +18 -18
  246. package/dist/test/android/code-tools.test.js.map +1 -1
  247. package/dist/test/apple/cocoapod.test.js +154 -299
  248. package/dist/test/apple/cocoapod.test.js.map +1 -1
  249. package/dist/test/apple/code-tools.test.js +375 -263
  250. package/dist/test/apple/code-tools.test.js.map +1 -1
  251. package/dist/test/apple/fastfile.test.js +319 -271
  252. package/dist/test/apple/fastfile.test.js.map +1 -1
  253. package/dist/test/apple/templates.test.js +114 -30
  254. package/dist/test/apple/templates.test.js.map +1 -1
  255. package/dist/test/apple/xcode-manager.test.js +230 -234
  256. package/dist/test/apple/xcode-manager.test.js.map +1 -1
  257. package/dist/test/flutter/code-tools.test.js +119 -48
  258. package/dist/test/flutter/code-tools.test.js.map +1 -1
  259. package/dist/test/flutter/templates.test.js +63 -20
  260. package/dist/test/flutter/templates.test.js.map +1 -1
  261. package/dist/test/nextjs/templates.test.js +332 -43
  262. package/dist/test/nextjs/templates.test.js.map +1 -1
  263. package/dist/test/nuxt/templates.test.js +161 -33
  264. package/dist/test/nuxt/templates.test.js.map +1 -1
  265. package/dist/test/react-native/expo-metro.test.js +61 -15
  266. package/dist/test/react-native/expo-metro.test.js.map +1 -1
  267. package/dist/test/react-native/expo.test.js +37 -17
  268. package/dist/test/react-native/expo.test.js.map +1 -1
  269. package/dist/test/react-native/gradle.test.js +260 -28
  270. package/dist/test/react-native/gradle.test.js.map +1 -1
  271. package/dist/test/react-native/javascript.test.js +85 -19
  272. package/dist/test/react-native/javascript.test.js.map +1 -1
  273. package/dist/test/react-native/metro.test.js +261 -187
  274. package/dist/test/react-native/metro.test.js.map +1 -1
  275. package/dist/test/react-native/xcode.test.js +243 -62
  276. package/dist/test/react-native/xcode.test.js.map +1 -1
  277. package/dist/test/remix/client-entry.test.js +81 -21
  278. package/dist/test/remix/client-entry.test.js.map +1 -1
  279. package/dist/test/remix/server-instrumentation.test.js +21 -8
  280. package/dist/test/remix/server-instrumentation.test.js.map +1 -1
  281. package/dist/test/sourcemaps/tools/sentry-cli.test.js +20 -72
  282. package/dist/test/sourcemaps/tools/sentry-cli.test.js.map +1 -1
  283. package/dist/test/sourcemaps/tools/tsc.test.js +142 -68
  284. package/dist/test/sourcemaps/tools/tsc.test.js.map +1 -1
  285. package/dist/test/sourcemaps/tools/vite.test.js +106 -75
  286. package/dist/test/sourcemaps/tools/vite.test.js.map +1 -1
  287. package/dist/test/sourcemaps/tools/webpack.test.js +226 -102
  288. package/dist/test/sourcemaps/tools/webpack.test.js.map +1 -1
  289. package/dist/test/sveltekit/templates.test.js +117 -18
  290. package/dist/test/sveltekit/templates.test.js.map +1 -1
  291. package/dist/test/utils/ast-utils.test.js +99 -58
  292. package/dist/test/utils/ast-utils.test.js.map +1 -1
  293. package/dist/test/utils/clack-utils.test.js +142 -247
  294. package/dist/test/utils/clack-utils.test.js.map +1 -1
  295. package/e2e-tests/package.json +1 -1
  296. package/e2e-tests/tests/flutter.test.ts +20 -20
  297. package/e2e-tests/tests/nextjs.test.ts +2 -2
  298. package/e2e-tests/tests/nuxt-3.test.ts +4 -4
  299. package/e2e-tests/tests/nuxt-4.test.ts +3 -3
  300. package/e2e-tests/tests/remix.test.ts +3 -3
  301. package/e2e-tests/tests/sveltekit.test.ts +3 -3
  302. package/e2e-tests/utils/index.ts +33 -15
  303. package/lib/Helper/BottomBar.ts +1 -1
  304. package/lib/Helper/Env.ts +1 -1
  305. package/lib/Helper/Package.ts +12 -10
  306. package/lib/Helper/SentryCli.ts +18 -27
  307. package/lib/Helper/Wizard.ts +1 -2
  308. package/lib/Setup.ts +4 -5
  309. package/lib/Steps/ChooseIntegration.ts +40 -8
  310. package/lib/Steps/Initial.ts +17 -26
  311. package/lib/Steps/Integrations/BaseIntegration.ts +2 -8
  312. package/lib/Steps/Integrations/Cordova.ts +9 -15
  313. package/lib/Steps/Integrations/Electron.ts +23 -20
  314. package/lib/Steps/Integrations/MobileProject.ts +18 -15
  315. package/lib/Steps/OpenSentry.ts +12 -7
  316. package/lib/Steps/PromptForParameters.ts +12 -19
  317. package/lib/Steps/SentryProjectSelector.ts +30 -29
  318. package/lib/Steps/WaitForSentry.ts +29 -23
  319. package/package.json +12 -8
  320. package/src/apple/xcode-manager.ts +10 -10
  321. package/src/nextjs/templates.ts +2 -3
  322. package/src/nuxt/sdk-setup.ts +21 -18
  323. package/src/react-native/expo-metro.ts +2 -2
  324. package/src/react-native/react-native-wizard.ts +1 -2
  325. package/src/react-native/uninstall.ts +1 -2
  326. package/src/react-native/xcode.ts +1 -1
  327. package/src/run.ts +12 -5
  328. package/src/sourcemaps/tools/nextjs.ts +2 -2
  329. package/src/sourcemaps/tools/webpack.ts +3 -3
  330. package/src/telemetry.ts +27 -7
  331. package/src/utils/clack-utils.ts +50 -47
  332. package/test/apple/cocoapod.test.ts +4 -0
  333. package/test/apple/fastfile.test.ts +12 -7
  334. package/test/apple/xcode-manager.test.ts +13 -11
  335. package/test/utils/clack-utils.test.ts +40 -50
  336. package/types/read-env.d.ts +3 -0
  337. package/types/xcode.d.ts +1 -0
  338. package/dist/package.json +0 -128
@@ -26,158 +26,107 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  __setModuleDefault(result, mod);
27
27
  return result;
28
28
  };
29
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
30
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
31
- return new (P || (P = Promise))(function (resolve, reject) {
32
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
33
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
34
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
35
- step((generator = generator.apply(thisArg, _arguments || [])).next());
36
- });
37
- };
38
- var __generator = (this && this.__generator) || function (thisArg, body) {
39
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
40
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
41
- function verb(n) { return function (v) { return step([n, v]); }; }
42
- function step(op) {
43
- if (f) throw new TypeError("Generator is already executing.");
44
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
45
- 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;
46
- if (y = 0, t) op = [op[0] & 2, t.value];
47
- switch (op[0]) {
48
- case 0: case 1: t = op; break;
49
- case 4: _.label++; return { value: op[1], done: false };
50
- case 5: _.label++; y = op[1]; op = [0]; continue;
51
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
52
- default:
53
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
54
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
55
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
56
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
57
- if (t[2]) _.ops.pop();
58
- _.trys.pop(); continue;
59
- }
60
- op = body.call(thisArg, _);
61
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
62
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
63
- }
64
- };
65
29
  Object.defineProperty(exports, "__esModule", { value: true });
66
30
  exports.instrumentRootRouteV2 = void 0;
67
- var recast = __importStar(require("recast"));
68
- var path = __importStar(require("path"));
31
+ const recast = __importStar(require("recast"));
32
+ const path = __importStar(require("path"));
69
33
  // @ts-expect-error - magicast is ESM and TS complains about that. It works though
70
- var magicast_1 = require("magicast");
71
- var templates_1 = require("../templates");
72
- var utils_1 = require("../utils");
73
- var root_common_1 = require("./root-common");
74
- function instrumentRootRouteV2(rootFileName) {
75
- return __awaiter(this, void 0, void 0, function () {
76
- var rootRouteAst, exportsAst, namedExports, foundErrorBoundary;
77
- return __generator(this, function (_a) {
78
- switch (_a.label) {
79
- case 0: return [4 /*yield*/, (0, magicast_1.loadFile)(path.join(process.cwd(), 'app', rootFileName))];
80
- case 1:
81
- rootRouteAst = _a.sent();
82
- exportsAst = rootRouteAst.exports.$ast;
83
- namedExports = exportsAst.body.filter(function (node) { return node.type === 'ExportNamedDeclaration'; });
84
- foundErrorBoundary = false;
85
- namedExports.forEach(function (namedExport) {
86
- var _a;
87
- var declaration = namedExport.declaration;
88
- if (!declaration) {
89
- return;
90
- }
91
- if (declaration.type === 'FunctionDeclaration') {
92
- if (((_a = declaration.id) === null || _a === void 0 ? void 0 : _a.name) === 'ErrorBoundary') {
93
- foundErrorBoundary = true;
34
+ const magicast_1 = require("magicast");
35
+ const templates_1 = require("../templates");
36
+ const utils_1 = require("../utils");
37
+ const root_common_1 = require("./root-common");
38
+ async function instrumentRootRouteV2(rootFileName) {
39
+ const rootRouteAst = await (0, magicast_1.loadFile)(path.join(process.cwd(), 'app', rootFileName));
40
+ const exportsAst = rootRouteAst.exports.$ast;
41
+ const namedExports = exportsAst.body.filter((node) => node.type === 'ExportNamedDeclaration');
42
+ let foundErrorBoundary = false;
43
+ namedExports.forEach((namedExport) => {
44
+ const declaration = namedExport.declaration;
45
+ if (!declaration) {
46
+ return;
47
+ }
48
+ if (declaration.type === 'FunctionDeclaration') {
49
+ if (declaration.id?.name === 'ErrorBoundary') {
50
+ foundErrorBoundary = true;
51
+ }
52
+ }
53
+ else if (declaration.type === 'VariableDeclaration') {
54
+ const declarations = declaration.declarations;
55
+ declarations.forEach((declaration) => {
56
+ // @ts-expect-error - id should always have a name in this case
57
+ if (declaration.id?.name === 'ErrorBoundary') {
58
+ foundErrorBoundary = true;
59
+ }
60
+ });
61
+ }
62
+ });
63
+ if (!foundErrorBoundary) {
64
+ rootRouteAst.imports.$add({
65
+ from: '@sentry/remix',
66
+ imported: 'captureRemixErrorBoundaryError',
67
+ local: 'captureRemixErrorBoundaryError',
68
+ });
69
+ rootRouteAst.imports.$add({
70
+ from: '@remix-run/react',
71
+ imported: 'useRouteError',
72
+ local: 'useRouteError',
73
+ });
74
+ recast.visit(rootRouteAst.$ast, {
75
+ visitExportDefaultDeclaration(path) {
76
+ const implementation = recast.parse(templates_1.ERROR_BOUNDARY_TEMPLATE_V2).program
77
+ .body[0];
78
+ path.insertBefore(recast.types.builders.exportDeclaration(false, implementation));
79
+ this.traverse(path);
80
+ },
81
+ });
82
+ // If there is already a ErrorBoundary export, and it doesn't have Sentry content
83
+ }
84
+ else if (!(0, utils_1.hasSentryContent)(rootFileName, rootRouteAst.$code)) {
85
+ rootRouteAst.imports.$add({
86
+ from: '@sentry/remix',
87
+ imported: 'captureRemixErrorBoundaryError',
88
+ local: 'captureRemixErrorBoundaryError',
89
+ });
90
+ (0, root_common_1.wrapAppWithSentry)(rootRouteAst, rootFileName);
91
+ recast.visit(rootRouteAst.$ast, {
92
+ visitExportNamedDeclaration(path) {
93
+ // Find ErrorBoundary export
94
+ if (path.value.declaration?.id?.name === 'ErrorBoundary') {
95
+ const errorBoundaryExport = path.value.declaration;
96
+ let errorIdentifier;
97
+ // check if useRouteError is called
98
+ recast.visit(errorBoundaryExport, {
99
+ visitVariableDeclaration(path) {
100
+ const variableDeclaration = path.value.declarations[0];
101
+ const initializer = variableDeclaration.init;
102
+ if (initializer.type === 'CallExpression' &&
103
+ initializer.callee.name === 'useRouteError') {
104
+ errorIdentifier = variableDeclaration.id.name;
94
105
  }
95
- }
96
- else if (declaration.type === 'VariableDeclaration') {
97
- var declarations = declaration.declarations;
98
- declarations.forEach(function (declaration) {
99
- var _a;
100
- // @ts-expect-error - id should always have a name in this case
101
- if (((_a = declaration.id) === null || _a === void 0 ? void 0 : _a.name) === 'ErrorBoundary') {
102
- foundErrorBoundary = true;
103
- }
104
- });
105
- }
106
+ this.traverse(path);
107
+ },
106
108
  });
107
- if (!foundErrorBoundary) {
108
- rootRouteAst.imports.$add({
109
- from: '@sentry/remix',
110
- imported: 'captureRemixErrorBoundaryError',
111
- local: 'captureRemixErrorBoundaryError',
112
- });
109
+ // We don't have an errorIdentifier, which means useRouteError is not called / imported
110
+ // We need to add it and capture the error
111
+ if (!errorIdentifier) {
113
112
  rootRouteAst.imports.$add({
114
113
  from: '@remix-run/react',
115
114
  imported: 'useRouteError',
116
115
  local: 'useRouteError',
117
116
  });
118
- recast.visit(rootRouteAst.$ast, {
119
- visitExportDefaultDeclaration: function (path) {
120
- var implementation = recast.parse(templates_1.ERROR_BOUNDARY_TEMPLATE_V2).program
121
- .body[0];
122
- path.insertBefore(recast.types.builders.exportDeclaration(false, implementation));
123
- this.traverse(path);
124
- },
125
- });
126
- // If there is already a ErrorBoundary export, and it doesn't have Sentry content
117
+ const useRouteErrorCall = recast.parse(`const error = useRouteError();`).program.body[0];
118
+ // Insert at the top of ErrorBoundary body
119
+ errorBoundaryExport.body.body.splice(0, 0, useRouteErrorCall);
127
120
  }
128
- else if (!(0, utils_1.hasSentryContent)(rootFileName, rootRouteAst.$code)) {
129
- rootRouteAst.imports.$add({
130
- from: '@sentry/remix',
131
- imported: 'captureRemixErrorBoundaryError',
132
- local: 'captureRemixErrorBoundaryError',
133
- });
134
- (0, root_common_1.wrapAppWithSentry)(rootRouteAst, rootFileName);
135
- recast.visit(rootRouteAst.$ast, {
136
- visitExportNamedDeclaration: function (path) {
137
- var _a, _b;
138
- // Find ErrorBoundary export
139
- if (((_b = (_a = path.value.declaration) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.name) === 'ErrorBoundary') {
140
- var errorBoundaryExport = path.value.declaration;
141
- var errorIdentifier_1;
142
- // check if useRouteError is called
143
- recast.visit(errorBoundaryExport, {
144
- visitVariableDeclaration: function (path) {
145
- var variableDeclaration = path.value.declarations[0];
146
- var initializer = variableDeclaration.init;
147
- if (initializer.type === 'CallExpression' &&
148
- initializer.callee.name === 'useRouteError') {
149
- errorIdentifier_1 = variableDeclaration.id.name;
150
- }
151
- this.traverse(path);
152
- },
153
- });
154
- // We don't have an errorIdentifier, which means useRouteError is not called / imported
155
- // We need to add it and capture the error
156
- if (!errorIdentifier_1) {
157
- rootRouteAst.imports.$add({
158
- from: '@remix-run/react',
159
- imported: 'useRouteError',
160
- local: 'useRouteError',
161
- });
162
- var useRouteErrorCall = recast.parse("const error = useRouteError();").program.body[0];
163
- // Insert at the top of ErrorBoundary body
164
- errorBoundaryExport.body.body.splice(0, 0, useRouteErrorCall);
165
- }
166
- var captureErrorCall = recast.parse("captureRemixErrorBoundaryError(error);").program.body[0];
167
- // Insert just before the the fallback page is returned
168
- errorBoundaryExport.body.body.splice(errorBoundaryExport.body.body.length - 1, 0, captureErrorCall);
169
- }
170
- this.traverse(path);
171
- },
172
- });
173
- }
174
- return [4 /*yield*/, (0, magicast_1.writeFile)(rootRouteAst.$ast, path.join(process.cwd(), 'app', rootFileName))];
175
- case 2:
176
- _a.sent();
177
- return [2 /*return*/];
178
- }
121
+ const captureErrorCall = recast.parse(`captureRemixErrorBoundaryError(error);`).program.body[0];
122
+ // Insert just before the the fallback page is returned
123
+ errorBoundaryExport.body.body.splice(errorBoundaryExport.body.body.length - 1, 0, captureErrorCall);
124
+ }
125
+ this.traverse(path);
126
+ },
179
127
  });
180
- });
128
+ }
129
+ await (0, magicast_1.writeFile)(rootRouteAst.$ast, path.join(process.cwd(), 'app', rootFileName));
181
130
  }
182
131
  exports.instrumentRootRouteV2 = instrumentRootRouteV2;
183
132
  //# sourceMappingURL=root-v2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"root-v2.js","sourceRoot":"","sources":["../../../../src/remix/codemods/root-v2.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,sDAAsD;AACtD,0DAA0D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1D,6CAAiC;AACjC,yCAA6B;AAI7B,kFAAkF;AAClF,qCAA+C;AAE/C,0CAA0D;AAC1D,kCAA4C;AAC5C,6CAAkD;AAElD,SAAsB,qBAAqB,CACzC,YAAoB;;;;;wBAEC,qBAAM,IAAA,mBAAQ,EACjC,IAAI,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,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,EAAA;;oBAHD,SAGC,CAAC;;;;;CACH;AAvID,sDAuIC","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 */\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';\nimport { hasSentryContent } from '../utils';\nimport { wrapAppWithSentry } from './root-common';\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 const implementation = recast.parse(ERROR_BOUNDARY_TEMPLATE_V2).program\n .body[0];\n\n path.insertBefore(\n recast.types.builders.exportDeclaration(false, implementation),\n );\n\n this.traverse(path);\n },\n });\n // If there is already a ErrorBoundary export, and it doesn't have Sentry content\n } else if (!hasSentryContent(rootFileName, rootRouteAst.$code)) {\n rootRouteAst.imports.$add({\n from: '@sentry/remix',\n imported: 'captureRemixErrorBoundaryError',\n local: 'captureRemixErrorBoundaryError',\n });\n\n wrapAppWithSentry(rootRouteAst, rootFileName);\n\n recast.visit(rootRouteAst.$ast, {\n visitExportNamedDeclaration(path) {\n // Find ErrorBoundary export\n if (path.value.declaration?.id?.name === 'ErrorBoundary') {\n const errorBoundaryExport = path.value.declaration;\n\n let errorIdentifier;\n\n // check if useRouteError is called\n recast.visit(errorBoundaryExport, {\n visitVariableDeclaration(path) {\n const variableDeclaration = path.value.declarations[0];\n const initializer = variableDeclaration.init;\n\n if (\n initializer.type === 'CallExpression' &&\n initializer.callee.name === 'useRouteError'\n ) {\n errorIdentifier = variableDeclaration.id.name;\n }\n\n this.traverse(path);\n },\n });\n\n // We don't have an errorIdentifier, which means useRouteError is not called / imported\n // We need to add it and capture the error\n if (!errorIdentifier) {\n rootRouteAst.imports.$add({\n from: '@remix-run/react',\n imported: 'useRouteError',\n local: 'useRouteError',\n });\n\n const useRouteErrorCall = recast.parse(\n `const error = useRouteError();`,\n ).program.body[0];\n\n // Insert at the top of ErrorBoundary body\n errorBoundaryExport.body.body.splice(0, 0, useRouteErrorCall);\n }\n\n const captureErrorCall = recast.parse(\n `captureRemixErrorBoundaryError(error);`,\n ).program.body[0];\n\n // Insert just before the the fallback page is returned\n errorBoundaryExport.body.body.splice(\n errorBoundaryExport.body.body.length - 1,\n 0,\n captureErrorCall,\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"]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AI,CAAC,MAAM,CAClC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EACxC,CAAC,EACD,gBAAgB,CACjB,CAAC;iBACH;gBACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;SACF,CAAC,CAAC;KACJ;IAED,MAAM,IAAA,oBAAS,EACb,YAAY,CAAC,IAAI,EACjB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,CAC9C,CAAC;AACJ,CAAC;AAvID,sDAuIC","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 */\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';\nimport { hasSentryContent } from '../utils';\nimport { wrapAppWithSentry } from './root-common';\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 const implementation = recast.parse(ERROR_BOUNDARY_TEMPLATE_V2).program\n .body[0];\n\n path.insertBefore(\n recast.types.builders.exportDeclaration(false, implementation),\n );\n\n this.traverse(path);\n },\n });\n // If there is already a ErrorBoundary export, and it doesn't have Sentry content\n } else if (!hasSentryContent(rootFileName, rootRouteAst.$code)) {\n rootRouteAst.imports.$add({\n from: '@sentry/remix',\n imported: 'captureRemixErrorBoundaryError',\n local: 'captureRemixErrorBoundaryError',\n });\n\n wrapAppWithSentry(rootRouteAst, rootFileName);\n\n recast.visit(rootRouteAst.$ast, {\n visitExportNamedDeclaration(path) {\n // Find ErrorBoundary export\n if (path.value.declaration?.id?.name === 'ErrorBoundary') {\n const errorBoundaryExport = path.value.declaration;\n\n let errorIdentifier;\n\n // check if useRouteError is called\n recast.visit(errorBoundaryExport, {\n visitVariableDeclaration(path) {\n const variableDeclaration = path.value.declarations[0];\n const initializer = variableDeclaration.init;\n\n if (\n initializer.type === 'CallExpression' &&\n initializer.callee.name === 'useRouteError'\n ) {\n errorIdentifier = variableDeclaration.id.name;\n }\n\n this.traverse(path);\n },\n });\n\n // We don't have an errorIdentifier, which means useRouteError is not called / imported\n // We need to add it and capture the error\n if (!errorIdentifier) {\n rootRouteAst.imports.$add({\n from: '@remix-run/react',\n imported: 'useRouteError',\n local: 'useRouteError',\n });\n\n const useRouteErrorCall = recast.parse(\n `const error = useRouteError();`,\n ).program.body[0];\n\n // Insert at the top of ErrorBoundary body\n errorBoundaryExport.body.body.splice(0, 0, useRouteErrorCall);\n }\n\n const captureErrorCall = recast.parse(\n `captureRemixErrorBoundaryError(error);`,\n ).program.body[0];\n\n // Insert just before the the fallback page is returned\n errorBoundaryExport.body.body.splice(\n errorBoundaryExport.body.body.length - 1,\n 0,\n captureErrorCall,\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"]}