@sentry/wizard 3.42.0 → 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 (339) 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 +30 -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 -6
  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 -5
  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/nextjs/templates.test.ts +0 -12
  336. package/test/utils/clack-utils.test.ts +40 -50
  337. package/types/read-env.d.ts +3 -0
  338. package/types/xcode.d.ts +1 -0
  339. package/dist/package.json +0 -128
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -33,131 +22,67 @@ var __importStar = (this && this.__importStar) || function (mod) {
33
22
  __setModuleDefault(result, mod);
34
23
  return result;
35
24
  };
36
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
- return new (P || (P = Promise))(function (resolve, reject) {
39
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
- step((generator = generator.apply(thisArg, _arguments || [])).next());
43
- });
44
- };
45
- var __generator = (this && this.__generator) || function (thisArg, body) {
46
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
- function verb(n) { return function (v) { return step([n, v]); }; }
49
- function step(op) {
50
- if (f) throw new TypeError("Generator is already executing.");
51
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
- 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;
53
- if (y = 0, t) op = [op[0] & 2, t.value];
54
- switch (op[0]) {
55
- case 0: case 1: t = op; break;
56
- case 4: _.label++; return { value: op[1], done: false };
57
- case 5: _.label++; y = op[1]; op = [0]; continue;
58
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
- default:
60
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
- if (t[2]) _.ops.pop();
65
- _.trys.pop(); continue;
66
- }
67
- op = body.call(thisArg, _);
68
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
- }
71
- };
72
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
74
- if (ar || !(i in from)) {
75
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
76
- ar[i] = from[i];
77
- }
78
- }
79
- return to.concat(ar || Array.prototype.slice.call(from));
80
- };
81
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
82
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
83
27
  };
84
28
  Object.defineProperty(exports, "__esModule", { value: true });
85
29
  exports.loadSvelteConfig = exports.createOrMergeSvelteKitFiles = void 0;
86
- var fs = __importStar(require("fs"));
87
- var path = __importStar(require("path"));
88
- var url = __importStar(require("url"));
89
- var chalk_1 = __importDefault(require("chalk"));
90
- var Sentry = __importStar(require("@sentry/node"));
30
+ const fs = __importStar(require("fs"));
31
+ const path = __importStar(require("path"));
32
+ const url = __importStar(require("url"));
33
+ const chalk_1 = __importDefault(require("chalk"));
34
+ const Sentry = __importStar(require("@sentry/node"));
91
35
  // @ts-ignore - clack is ESM and TS complains about that. It works though
92
- var prompts_1 = __importDefault(require("@clack/prompts"));
36
+ const prompts_1 = __importDefault(require("@clack/prompts"));
93
37
  // @ts-ignore - magicast is ESM and TS complains about that. It works though
94
- var magicast_1 = require("magicast");
38
+ const magicast_1 = require("magicast");
95
39
  // @ts-ignore - magicast is ESM and TS complains about that. It works though
96
- var helpers_1 = require("magicast/helpers");
97
- var templates_1 = require("./templates");
98
- var clack_utils_1 = require("../utils/clack-utils");
99
- var debug_1 = require("../utils/debug");
100
- var ast_utils_1 = require("../utils/ast-utils");
101
- var telemetry_1 = require("../telemetry");
102
- var SVELTE_CONFIG_FILE = 'svelte.config.js';
103
- function createOrMergeSvelteKitFiles(projectInfo, svelteConfig) {
104
- return __awaiter(this, void 0, void 0, function () {
105
- var selectedFeatures, _a, clientHooksPath, serverHooksPath, originalClientHooksFile, originalServerHooksFile, viteConfig, fileEnding, dsn;
106
- return __generator(this, function (_b) {
107
- switch (_b.label) {
108
- case 0: return [4 /*yield*/, (0, clack_utils_1.featureSelectionPrompt)([
109
- {
110
- id: 'performance',
111
- prompt: "Do you want to enable ".concat(chalk_1.default.bold('Tracing'), " to track the performance of your application?"),
112
- enabledHint: 'recommended',
113
- },
114
- {
115
- id: 'replay',
116
- prompt: "Do you want to enable ".concat(chalk_1.default.bold('Sentry Session Replay'), " to get a video-like reproduction of errors during a user session?"),
117
- enabledHint: 'recommended, but increases bundle size',
118
- },
119
- ])];
120
- case 1:
121
- selectedFeatures = _b.sent();
122
- _a = getHooksConfigDirs(svelteConfig), clientHooksPath = _a.clientHooksPath, serverHooksPath = _a.serverHooksPath;
123
- originalClientHooksFile = (0, ast_utils_1.findFile)(clientHooksPath);
124
- originalServerHooksFile = (0, ast_utils_1.findFile)(serverHooksPath);
125
- viteConfig = (0, ast_utils_1.findFile)(path.resolve(process.cwd(), 'vite.config'));
126
- fileEnding = (0, clack_utils_1.isUsingTypeScript)() ? 'ts' : 'js';
127
- dsn = projectInfo.dsn;
128
- Sentry.setTag('client-hooks-file-strategy', originalClientHooksFile ? 'merge' : 'create');
129
- if (!!originalClientHooksFile) return [3 /*break*/, 3];
130
- prompts_1.default.log.info('No client hooks file found, creating a new one.');
131
- return [4 /*yield*/, createNewHooksFile("".concat(clientHooksPath, ".").concat(fileEnding), 'client', dsn, selectedFeatures)];
132
- case 2:
133
- _b.sent();
134
- return [3 /*break*/, 5];
135
- case 3: return [4 /*yield*/, mergeHooksFile(originalClientHooksFile, 'client', dsn, selectedFeatures)];
136
- case 4:
137
- _b.sent();
138
- _b.label = 5;
139
- case 5:
140
- Sentry.setTag('server-hooks-file-strategy', originalServerHooksFile ? 'merge' : 'create');
141
- if (!!originalServerHooksFile) return [3 /*break*/, 7];
142
- prompts_1.default.log.info('No server hooks file found, creating a new one.');
143
- return [4 /*yield*/, createNewHooksFile("".concat(serverHooksPath, ".").concat(fileEnding), 'server', dsn, selectedFeatures)];
144
- case 6:
145
- _b.sent();
146
- return [3 /*break*/, 9];
147
- case 7: return [4 /*yield*/, mergeHooksFile(originalServerHooksFile, 'server', dsn, selectedFeatures)];
148
- case 8:
149
- _b.sent();
150
- _b.label = 9;
151
- case 9:
152
- if (!viteConfig) return [3 /*break*/, 11];
153
- return [4 /*yield*/, modifyViteConfig(viteConfig, projectInfo)];
154
- case 10:
155
- _b.sent();
156
- _b.label = 11;
157
- case 11: return [2 /*return*/];
158
- }
159
- });
160
- });
40
+ const helpers_1 = require("magicast/helpers");
41
+ const templates_1 = require("./templates");
42
+ const clack_utils_1 = require("../utils/clack-utils");
43
+ const debug_1 = require("../utils/debug");
44
+ const ast_utils_1 = require("../utils/ast-utils");
45
+ const telemetry_1 = require("../telemetry");
46
+ const SVELTE_CONFIG_FILE = 'svelte.config.js';
47
+ async function createOrMergeSvelteKitFiles(projectInfo, svelteConfig) {
48
+ const selectedFeatures = await (0, clack_utils_1.featureSelectionPrompt)([
49
+ {
50
+ id: 'performance',
51
+ prompt: `Do you want to enable ${chalk_1.default.bold('Tracing')} to track the performance of your application?`,
52
+ enabledHint: 'recommended',
53
+ },
54
+ {
55
+ id: 'replay',
56
+ prompt: `Do you want to enable ${chalk_1.default.bold('Sentry Session Replay')} to get a video-like reproduction of errors during a user session?`,
57
+ enabledHint: 'recommended, but increases bundle size',
58
+ },
59
+ ]);
60
+ const { clientHooksPath, serverHooksPath } = getHooksConfigDirs(svelteConfig);
61
+ // full file paths with correct file ending (or undefined if not found)
62
+ const originalClientHooksFile = (0, ast_utils_1.findFile)(clientHooksPath);
63
+ const originalServerHooksFile = (0, ast_utils_1.findFile)(serverHooksPath);
64
+ const viteConfig = (0, ast_utils_1.findFile)(path.resolve(process.cwd(), 'vite.config'));
65
+ const fileEnding = (0, clack_utils_1.isUsingTypeScript)() ? 'ts' : 'js';
66
+ const { dsn } = projectInfo;
67
+ Sentry.setTag('client-hooks-file-strategy', originalClientHooksFile ? 'merge' : 'create');
68
+ if (!originalClientHooksFile) {
69
+ prompts_1.default.log.info('No client hooks file found, creating a new one.');
70
+ await createNewHooksFile(`${clientHooksPath}.${fileEnding}`, 'client', dsn, selectedFeatures);
71
+ }
72
+ else {
73
+ await mergeHooksFile(originalClientHooksFile, 'client', dsn, selectedFeatures);
74
+ }
75
+ Sentry.setTag('server-hooks-file-strategy', originalServerHooksFile ? 'merge' : 'create');
76
+ if (!originalServerHooksFile) {
77
+ prompts_1.default.log.info('No server hooks file found, creating a new one.');
78
+ await createNewHooksFile(`${serverHooksPath}.${fileEnding}`, 'server', dsn, selectedFeatures);
79
+ }
80
+ else {
81
+ await mergeHooksFile(originalServerHooksFile, 'server', dsn, selectedFeatures);
82
+ }
83
+ if (viteConfig) {
84
+ await modifyViteConfig(viteConfig, projectInfo);
85
+ }
161
86
  }
162
87
  exports.createOrMergeSvelteKitFiles = createOrMergeSvelteKitFiles;
163
88
  /**
@@ -165,16 +90,15 @@ exports.createOrMergeSvelteKitFiles = createOrMergeSvelteKitFiles;
165
90
  * If users specified a custom location, we'll use that. Otherwise, we'll use the default.
166
91
  */
167
92
  function getHooksConfigDirs(svelteConfig) {
168
- var _a, _b, _c, _d, _e, _f;
169
- var relativeUserClientHooksPath = (_c = (_b = (_a = svelteConfig === null || svelteConfig === void 0 ? void 0 : svelteConfig.kit) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b.hooks) === null || _c === void 0 ? void 0 : _c.client;
170
- var relativeUserServerHooksPath = (_f = (_e = (_d = svelteConfig === null || svelteConfig === void 0 ? void 0 : svelteConfig.kit) === null || _d === void 0 ? void 0 : _d.files) === null || _e === void 0 ? void 0 : _e.hooks) === null || _f === void 0 ? void 0 : _f.server;
171
- var userClientHooksPath = relativeUserClientHooksPath &&
93
+ const relativeUserClientHooksPath = svelteConfig?.kit?.files?.hooks?.client;
94
+ const relativeUserServerHooksPath = svelteConfig?.kit?.files?.hooks?.server;
95
+ const userClientHooksPath = relativeUserClientHooksPath &&
172
96
  path.resolve(process.cwd(), relativeUserClientHooksPath);
173
- var userServerHooksPath = relativeUserServerHooksPath &&
97
+ const userServerHooksPath = relativeUserServerHooksPath &&
174
98
  path.resolve(process.cwd(), relativeUserServerHooksPath);
175
- var defaulHooksDir = path.resolve(process.cwd(), 'src');
176
- var defaultClientHooksPath = path.resolve(defaulHooksDir, 'hooks.client'); // file ending missing on purpose
177
- var defaultServerHooksPath = path.resolve(defaulHooksDir, 'hooks.server'); // same here
99
+ const defaulHooksDir = path.resolve(process.cwd(), 'src');
100
+ const defaultClientHooksPath = path.resolve(defaulHooksDir, 'hooks.client'); // file ending missing on purpose
101
+ const defaultServerHooksPath = path.resolve(defaulHooksDir, 'hooks.server'); // same here
178
102
  return {
179
103
  clientHooksPath: userClientHooksPath || defaultClientHooksPath,
180
104
  serverHooksPath: userServerHooksPath || defaultServerHooksPath,
@@ -183,27 +107,14 @@ function getHooksConfigDirs(svelteConfig) {
183
107
  /**
184
108
  * Reads the template, replaces the dsn placeholder with the actual dsn and writes the file to @param hooksFileDest
185
109
  */
186
- function createNewHooksFile(hooksFileDest, hooktype, dsn, selectedFeatures) {
187
- return __awaiter(this, void 0, void 0, function () {
188
- var filledTemplate;
189
- return __generator(this, function (_a) {
190
- switch (_a.label) {
191
- case 0:
192
- filledTemplate = hooktype === 'client'
193
- ? (0, templates_1.getClientHooksTemplate)(dsn, selectedFeatures)
194
- : (0, templates_1.getServerHooksTemplate)(dsn, selectedFeatures);
195
- return [4 /*yield*/, fs.promises.mkdir(path.dirname(hooksFileDest), { recursive: true })];
196
- case 1:
197
- _a.sent();
198
- return [4 /*yield*/, fs.promises.writeFile(hooksFileDest, filledTemplate)];
199
- case 2:
200
- _a.sent();
201
- prompts_1.default.log.success("Created ".concat(hooksFileDest));
202
- Sentry.setTag("created-".concat(hooktype, "-hooks"), 'success');
203
- return [2 /*return*/];
204
- }
205
- });
206
- });
110
+ async function createNewHooksFile(hooksFileDest, hooktype, dsn, selectedFeatures) {
111
+ const filledTemplate = hooktype === 'client'
112
+ ? (0, templates_1.getClientHooksTemplate)(dsn, selectedFeatures)
113
+ : (0, templates_1.getServerHooksTemplate)(dsn, selectedFeatures);
114
+ await fs.promises.mkdir(path.dirname(hooksFileDest), { recursive: true });
115
+ await fs.promises.writeFile(hooksFileDest, filledTemplate);
116
+ prompts_1.default.log.success(`Created ${hooksFileDest}`);
117
+ Sentry.setTag(`created-${hooktype}-hooks`, 'success');
207
118
  }
208
119
  /**
209
120
  * Merges the users' hooks file with Sentry-related code.
@@ -216,79 +127,50 @@ function createNewHooksFile(hooksFileDest, hooktype, dsn, selectedFeatures) {
216
127
  * Additionally in Server hook:
217
128
  * - add handle hook handler
218
129
  */
219
- function mergeHooksFile(hooksFile, hookType, dsn, selectedFeatures) {
220
- return __awaiter(this, void 0, void 0, function () {
221
- var originalHooksMod, file;
222
- var _this = this;
223
- return __generator(this, function (_a) {
224
- switch (_a.label) {
225
- case 0: return [4 /*yield*/, (0, magicast_1.loadFile)(hooksFile)];
226
- case 1:
227
- originalHooksMod = _a.sent();
228
- file = "".concat(hookType, "-hooks");
229
- if ((0, ast_utils_1.hasSentryContent)(originalHooksMod.$ast)) {
230
- // We don't want to mess with files that already have Sentry content.
231
- // Let's just bail out at this point.
232
- prompts_1.default.log.warn("File ".concat(chalk_1.default.cyan(path.basename(hooksFile)), " already contains Sentry code.\nSkipping adding Sentry functionality to."));
233
- Sentry.setTag("modified-".concat(file), 'fail');
234
- Sentry.setTag("".concat(file, "-fail-reason"), 'has-sentry-content');
235
- return [2 /*return*/];
236
- }
237
- return [4 /*yield*/, modifyAndRecordFail(function () {
238
- return originalHooksMod.imports.$add({
239
- from: '@sentry/sveltekit',
240
- imported: '*',
241
- local: 'Sentry',
242
- });
243
- }, 'import-injection', file)];
244
- case 2:
245
- _a.sent();
246
- return [4 /*yield*/, modifyAndRecordFail(function () {
247
- if (hookType === 'client') {
248
- insertClientInitCall(dsn, originalHooksMod, selectedFeatures);
249
- }
250
- else {
251
- insertServerInitCall(dsn, originalHooksMod, selectedFeatures);
252
- }
253
- }, 'init-call-injection', file)];
254
- case 3:
255
- _a.sent();
256
- return [4 /*yield*/, modifyAndRecordFail(function () { return wrapHandleError(originalHooksMod); }, 'wrap-handle-error', file)];
257
- case 4:
258
- _a.sent();
259
- if (!(hookType === 'server')) return [3 /*break*/, 6];
260
- return [4 /*yield*/, modifyAndRecordFail(function () { return wrapHandle(originalHooksMod); }, 'wrap-handle', 'server-hooks')];
261
- case 5:
262
- _a.sent();
263
- _a.label = 6;
264
- case 6: return [4 /*yield*/, modifyAndRecordFail(function () { return __awaiter(_this, void 0, void 0, function () {
265
- var modifiedCode;
266
- return __generator(this, function (_a) {
267
- switch (_a.label) {
268
- case 0:
269
- modifiedCode = originalHooksMod.generate().code;
270
- return [4 /*yield*/, fs.promises.writeFile(hooksFile, modifiedCode)];
271
- case 1:
272
- _a.sent();
273
- return [2 /*return*/];
274
- }
275
- });
276
- }); }, 'write-file', file)];
277
- case 7:
278
- _a.sent();
279
- prompts_1.default.log.success("Added Sentry code to ".concat(hooksFile));
280
- Sentry.setTag("modified-".concat(hookType, "-hooks"), 'success');
281
- return [2 /*return*/];
282
- }
283
- });
284
- });
130
+ async function mergeHooksFile(hooksFile, hookType, dsn, selectedFeatures) {
131
+ const originalHooksMod = await (0, magicast_1.loadFile)(hooksFile);
132
+ const file = `${hookType}-hooks`;
133
+ if ((0, ast_utils_1.hasSentryContent)(originalHooksMod.$ast)) {
134
+ // We don't want to mess with files that already have Sentry content.
135
+ // Let's just bail out at this point.
136
+ prompts_1.default.log.warn(`File ${chalk_1.default.cyan(path.basename(hooksFile))} already contains Sentry code.
137
+ Skipping adding Sentry functionality to.`);
138
+ Sentry.setTag(`modified-${file}`, 'fail');
139
+ Sentry.setTag(`${file}-fail-reason`, 'has-sentry-content');
140
+ return;
141
+ }
142
+ await modifyAndRecordFail(() => originalHooksMod.imports.$add({
143
+ from: '@sentry/sveltekit',
144
+ imported: '*',
145
+ local: 'Sentry',
146
+ }), 'import-injection', file);
147
+ await modifyAndRecordFail(() => {
148
+ if (hookType === 'client') {
149
+ insertClientInitCall(dsn, originalHooksMod, selectedFeatures);
150
+ }
151
+ else {
152
+ insertServerInitCall(dsn, originalHooksMod, selectedFeatures);
153
+ }
154
+ }, 'init-call-injection', file);
155
+ await modifyAndRecordFail(() => wrapHandleError(originalHooksMod), 'wrap-handle-error', file);
156
+ if (hookType === 'server') {
157
+ await modifyAndRecordFail(() => wrapHandle(originalHooksMod), 'wrap-handle', 'server-hooks');
158
+ }
159
+ await modifyAndRecordFail(async () => {
160
+ const modifiedCode = originalHooksMod.generate().code;
161
+ await fs.promises.writeFile(hooksFile, modifiedCode);
162
+ }, 'write-file', file);
163
+ prompts_1.default.log.success(`Added Sentry code to ${hooksFile}`);
164
+ Sentry.setTag(`modified-${hookType}-hooks`, 'success');
285
165
  }
286
166
  function insertClientInitCall(dsn,
287
167
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
288
168
  originalHooksMod, selectedFeatures) {
289
- var initCallComment = "\n // If you don't want to use Session Replay, remove the `Replay` integration,\n // `replaysSessionSampleRate` and `replaysOnErrorSampleRate` options.";
290
- var initArgs = {
291
- dsn: dsn,
169
+ const initCallComment = `
170
+ // If you don't want to use Session Replay, remove the \`Replay\` integration,
171
+ // \`replaysSessionSampleRate\` and \`replaysOnErrorSampleRate\` options.`;
172
+ const initArgs = {
173
+ dsn,
292
174
  };
293
175
  if (selectedFeatures.performance) {
294
176
  initArgs.tracesSampleRate = 1.0;
@@ -300,13 +182,13 @@ originalHooksMod, selectedFeatures) {
300
182
  }
301
183
  // This assignment of any values is fine because we're just creating a function call in magicast
302
184
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
303
- var initCall = magicast_1.builders.functionCall('Sentry.init', initArgs);
185
+ const initCall = magicast_1.builders.functionCall('Sentry.init', initArgs);
304
186
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
305
- var initCallWithComment = magicast_1.builders.raw(
187
+ const initCallWithComment = magicast_1.builders.raw(
306
188
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
307
- "".concat(initCallComment, "\n").concat((0, magicast_1.generateCode)(initCall).code));
308
- var originalHooksModAST = originalHooksMod.$ast;
309
- var initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);
189
+ `${initCallComment}\n${(0, magicast_1.generateCode)(initCall).code}`);
190
+ const originalHooksModAST = originalHooksMod.$ast;
191
+ const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);
310
192
  originalHooksModAST.body.splice(initCallInsertionIndex, 0,
311
193
  // @ts-ignore - string works here because the AST is proxified by magicast
312
194
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
@@ -315,17 +197,17 @@ originalHooksMod, selectedFeatures) {
315
197
  function insertServerInitCall(dsn,
316
198
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
199
  originalHooksMod, selectedFeatures) {
318
- var initArgs = {
319
- dsn: dsn,
200
+ const initArgs = {
201
+ dsn,
320
202
  };
321
203
  if (selectedFeatures.performance) {
322
204
  initArgs.tracesSampleRate = 1.0;
323
205
  }
324
206
  // This assignment of any values is fine because we're just creating a function call in magicast
325
207
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
326
- var initCall = magicast_1.builders.functionCall('Sentry.init', initArgs);
327
- var originalHooksModAST = originalHooksMod.$ast;
328
- var initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);
208
+ const initCall = magicast_1.builders.functionCall('Sentry.init', initArgs);
209
+ const originalHooksModAST = originalHooksMod.$ast;
210
+ const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);
329
211
  originalHooksModAST.body.splice(initCallInsertionIndex, 0,
330
212
  // @ts-ignore - string works here because the AST is proxified by magicast
331
213
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
@@ -333,11 +215,11 @@ originalHooksMod, selectedFeatures) {
333
215
  }
334
216
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
335
217
  function wrapHandleError(mod) {
336
- var modAst = mod.exports.$ast;
337
- var namedExports = modAst.body.filter(function (node) { return node.type === 'ExportNamedDeclaration'; });
338
- var foundHandleError = false;
339
- namedExports.forEach(function (modExport) {
340
- var declaration = modExport.declaration;
218
+ const modAst = mod.exports.$ast;
219
+ const namedExports = modAst.body.filter((node) => node.type === 'ExportNamedDeclaration');
220
+ let foundHandleError = false;
221
+ namedExports.forEach((modExport) => {
222
+ const declaration = modExport.declaration;
341
223
  if (!declaration) {
342
224
  return;
343
225
  }
@@ -346,24 +228,24 @@ function wrapHandleError(mod) {
346
228
  return;
347
229
  }
348
230
  foundHandleError = true;
349
- var userCode = (0, magicast_1.generateCode)(declaration).code;
231
+ const userCode = (0, magicast_1.generateCode)(declaration).code;
350
232
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
351
- mod.exports.handleError = magicast_1.builders.raw("Sentry.handleErrorWithSentry(".concat(userCode.replace('handleError', '_handleError'), ")"));
233
+ mod.exports.handleError = magicast_1.builders.raw(`Sentry.handleErrorWithSentry(${userCode.replace('handleError', '_handleError')})`);
352
234
  // because magicast doesn't overwrite the original function export, we need to remove it manually
353
- modAst.body = modAst.body.filter(function (node) { return node !== modExport; });
235
+ modAst.body = modAst.body.filter((node) => node !== modExport);
354
236
  }
355
237
  else if (declaration.type === 'VariableDeclaration') {
356
- var declarations = declaration.declarations;
357
- declarations.forEach(function (declaration) {
238
+ const declarations = declaration.declarations;
239
+ declarations.forEach((declaration) => {
358
240
  // @ts-ignore - id should always have a name in this case
359
241
  if (!declaration.id || declaration.id.name !== 'handleError') {
360
242
  return;
361
243
  }
362
244
  foundHandleError = true;
363
- var userCode = declaration.init;
364
- var stringifiedUserCode = userCode ? (0, magicast_1.generateCode)(userCode).code : '';
245
+ const userCode = declaration.init;
246
+ const stringifiedUserCode = userCode ? (0, magicast_1.generateCode)(userCode).code : '';
365
247
  // @ts-ignore - we can just place a string here, magicast will convert it to a node
366
- declaration.init = "Sentry.handleErrorWithSentry(".concat(stringifiedUserCode, ")");
248
+ declaration.init = `Sentry.handleErrorWithSentry(${stringifiedUserCode})`;
367
249
  });
368
250
  }
369
251
  });
@@ -374,11 +256,11 @@ function wrapHandleError(mod) {
374
256
  }
375
257
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
376
258
  function wrapHandle(mod) {
377
- var modAst = mod.exports.$ast;
378
- var namedExports = modAst.body.filter(function (node) { return node.type === 'ExportNamedDeclaration'; });
379
- var foundHandle = false;
380
- namedExports.forEach(function (modExport) {
381
- var declaration = modExport.declaration;
259
+ const modAst = mod.exports.$ast;
260
+ const namedExports = modAst.body.filter((node) => node.type === 'ExportNamedDeclaration');
261
+ let foundHandle = false;
262
+ namedExports.forEach((modExport) => {
263
+ const declaration = modExport.declaration;
382
264
  if (!declaration) {
383
265
  return;
384
266
  }
@@ -387,23 +269,23 @@ function wrapHandle(mod) {
387
269
  return;
388
270
  }
389
271
  foundHandle = true;
390
- var userCode = (0, magicast_1.generateCode)(declaration).code;
272
+ const userCode = (0, magicast_1.generateCode)(declaration).code;
391
273
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
392
- mod.exports.handle = magicast_1.builders.raw("sequence(Sentry.sentryHandle(), ".concat(userCode.replace('handle', '_handle'), ")"));
274
+ mod.exports.handle = magicast_1.builders.raw(`sequence(Sentry.sentryHandle(), ${userCode.replace('handle', '_handle')})`);
393
275
  // because of an issue with magicast, we need to remove the original export
394
- modAst.body = modAst.body.filter(function (node) { return node !== modExport; });
276
+ modAst.body = modAst.body.filter((node) => node !== modExport);
395
277
  }
396
278
  else if (declaration.type === 'VariableDeclaration') {
397
- var declarations = declaration.declarations;
398
- declarations.forEach(function (declaration) {
279
+ const declarations = declaration.declarations;
280
+ declarations.forEach((declaration) => {
399
281
  // @ts-ignore - id should always have a name in this case
400
282
  if (!declaration.id || declaration.id.name !== 'handle') {
401
283
  return;
402
284
  }
403
- var userCode = declaration.init;
404
- var stringifiedUserCode = userCode ? (0, magicast_1.generateCode)(userCode).code : '';
285
+ const userCode = declaration.init;
286
+ const stringifiedUserCode = userCode ? (0, magicast_1.generateCode)(userCode).code : '';
405
287
  // @ts-ignore - we can just place a string here, magicast will convert it to a node
406
- declaration.init = "sequence(Sentry.sentryHandle(), ".concat(stringifiedUserCode, ")");
288
+ declaration.init = `sequence(Sentry.sentryHandle(), ${stringifiedUserCode})`;
407
289
  foundHandle = true;
408
290
  });
409
291
  }
@@ -425,145 +307,113 @@ function wrapHandle(mod) {
425
307
  // It's possible sequence is already imported. in this case, magicast throws but that's fine.
426
308
  }
427
309
  }
428
- function loadSvelteConfig() {
429
- return __awaiter(this, void 0, void 0, function () {
430
- var configFilePath, configUrl, svelteConfigModule, e_1;
431
- return __generator(this, function (_a) {
432
- switch (_a.label) {
433
- case 0:
434
- configFilePath = path.join(process.cwd(), SVELTE_CONFIG_FILE);
435
- _a.label = 1;
436
- case 1:
437
- _a.trys.push([1, 3, , 4]);
438
- if (!fs.existsSync(configFilePath)) {
439
- return [2 /*return*/, {}];
440
- }
441
- configUrl = url.pathToFileURL(configFilePath).href;
442
- return [4 /*yield*/, import(configUrl)];
443
- case 2:
444
- svelteConfigModule = (_a.sent());
445
- return [2 /*return*/, (svelteConfigModule === null || svelteConfigModule === void 0 ? void 0 : svelteConfigModule.default) || {}];
446
- case 3:
447
- e_1 = _a.sent();
448
- prompts_1.default.log.error("Couldn't load ".concat(SVELTE_CONFIG_FILE, ".\nPlease make sure, you're running this wizard with Node 16 or newer"));
449
- prompts_1.default.log.info(chalk_1.default.dim(typeof e_1 === 'object' && e_1 != null && 'toString' in e_1
450
- ? e_1.toString()
451
- : typeof e_1 === 'string'
452
- ? e_1
453
- : 'Unknown error'));
454
- return [2 /*return*/, {}];
455
- case 4: return [2 /*return*/];
456
- }
457
- });
458
- });
310
+ async function loadSvelteConfig() {
311
+ const configFilePath = path.join(process.cwd(), SVELTE_CONFIG_FILE);
312
+ try {
313
+ if (!fs.existsSync(configFilePath)) {
314
+ return {};
315
+ }
316
+ const configUrl = url.pathToFileURL(configFilePath).href;
317
+ const svelteConfigModule = (await import(configUrl));
318
+ return svelteConfigModule?.default || {};
319
+ }
320
+ catch (e) {
321
+ prompts_1.default.log.error(`Couldn't load ${SVELTE_CONFIG_FILE}.
322
+ Please make sure, you're running this wizard with Node 16 or newer`);
323
+ prompts_1.default.log.info(chalk_1.default.dim(typeof e === 'object' && e != null && 'toString' in e
324
+ ? e.toString()
325
+ : typeof e === 'string'
326
+ ? e
327
+ : 'Unknown error'));
328
+ return {};
329
+ }
459
330
  }
460
331
  exports.loadSvelteConfig = loadSvelteConfig;
461
- function modifyViteConfig(viteConfigPath, projectInfo) {
462
- return __awaiter(this, void 0, void 0, function () {
463
- var viteConfigContent, org, project, url, selfHosted, prettyViteConfigFilename, viteModule_1, e_2;
464
- var _this = this;
465
- return __generator(this, function (_a) {
466
- switch (_a.label) {
467
- case 0: return [4 /*yield*/, fs.promises.readFile(viteConfigPath, 'utf-8')];
468
- case 1:
469
- viteConfigContent = (_a.sent()).toString();
470
- org = projectInfo.org, project = projectInfo.project, url = projectInfo.url, selfHosted = projectInfo.selfHosted;
471
- prettyViteConfigFilename = chalk_1.default.cyan(path.basename(viteConfigPath));
472
- _a.label = 2;
473
- case 2:
474
- _a.trys.push([2, 5, , 7]);
475
- viteModule_1 = (0, magicast_1.parseModule)(viteConfigContent);
476
- if ((0, ast_utils_1.hasSentryContent)(viteModule_1.$ast)) {
477
- prompts_1.default.log.warn("File ".concat(prettyViteConfigFilename, " already contains Sentry code.\nSkipping adding Sentry functionality to."));
478
- Sentry.setTag("modified-vite-cfg", 'fail');
479
- Sentry.setTag("vite-cfg-fail-reason", 'has-sentry-content');
480
- return [2 /*return*/];
481
- }
482
- return [4 /*yield*/, modifyAndRecordFail(function () {
483
- return (0, helpers_1.addVitePlugin)(viteModule_1, {
484
- imported: 'sentrySvelteKit',
485
- from: '@sentry/sveltekit',
486
- constructor: 'sentrySvelteKit',
487
- options: {
488
- sourceMapsUploadOptions: __assign({ org: org, project: project }, (selfHosted && { url: url })),
489
- },
490
- index: 0,
491
- });
492
- }, 'add-vite-plugin', 'vite-cfg')];
493
- case 3:
494
- _a.sent();
495
- return [4 /*yield*/, modifyAndRecordFail(function () { return __awaiter(_this, void 0, void 0, function () {
496
- var code;
497
- return __generator(this, function (_a) {
498
- switch (_a.label) {
499
- case 0:
500
- code = (0, magicast_1.generateCode)(viteModule_1.$ast).code;
501
- return [4 /*yield*/, fs.promises.writeFile(viteConfigPath, code)];
502
- case 1:
503
- _a.sent();
504
- return [2 /*return*/];
505
- }
506
- });
507
- }); }, 'write-file', 'vite-cfg')];
508
- case 4:
509
- _a.sent();
510
- return [3 /*break*/, 7];
511
- case 5:
512
- e_2 = _a.sent();
513
- (0, debug_1.debug)(e_2);
514
- return [4 /*yield*/, showFallbackViteCopyPasteSnippet(viteConfigPath, getViteConfigCodeSnippet(org, project, selfHosted, url))];
515
- case 6:
516
- _a.sent();
517
- Sentry.captureException('Sveltekit Vite Config Modification Fail');
518
- return [3 /*break*/, 7];
519
- case 7:
520
- prompts_1.default.log.success("Added Sentry code to ".concat(prettyViteConfigFilename));
521
- Sentry.setTag("modified-vite-cfg", 'success');
522
- return [2 /*return*/];
523
- }
524
- });
525
- });
332
+ async function modifyViteConfig(viteConfigPath, projectInfo) {
333
+ const viteConfigContent = (await fs.promises.readFile(viteConfigPath, 'utf-8')).toString();
334
+ const { org, project, url, selfHosted } = projectInfo;
335
+ const prettyViteConfigFilename = chalk_1.default.cyan(path.basename(viteConfigPath));
336
+ try {
337
+ const viteModule = (0, magicast_1.parseModule)(viteConfigContent);
338
+ if ((0, ast_utils_1.hasSentryContent)(viteModule.$ast)) {
339
+ prompts_1.default.log.warn(`File ${prettyViteConfigFilename} already contains Sentry code.
340
+ Skipping adding Sentry functionality to.`);
341
+ Sentry.setTag(`modified-vite-cfg`, 'fail');
342
+ Sentry.setTag(`vite-cfg-fail-reason`, 'has-sentry-content');
343
+ return;
344
+ }
345
+ await modifyAndRecordFail(() => (0, helpers_1.addVitePlugin)(viteModule, {
346
+ imported: 'sentrySvelteKit',
347
+ from: '@sentry/sveltekit',
348
+ constructor: 'sentrySvelteKit',
349
+ options: {
350
+ sourceMapsUploadOptions: {
351
+ org,
352
+ project,
353
+ ...(selfHosted && { url }),
354
+ },
355
+ },
356
+ index: 0,
357
+ }), 'add-vite-plugin', 'vite-cfg');
358
+ await modifyAndRecordFail(async () => {
359
+ const code = (0, magicast_1.generateCode)(viteModule.$ast).code;
360
+ await fs.promises.writeFile(viteConfigPath, code);
361
+ }, 'write-file', 'vite-cfg');
362
+ }
363
+ catch (e) {
364
+ (0, debug_1.debug)(e);
365
+ await showFallbackViteCopyPasteSnippet(viteConfigPath, getViteConfigCodeSnippet(org, project, selfHosted, url));
366
+ Sentry.captureException('Sveltekit Vite Config Modification Fail');
367
+ }
368
+ prompts_1.default.log.success(`Added Sentry code to ${prettyViteConfigFilename}`);
369
+ Sentry.setTag(`modified-vite-cfg`, 'success');
526
370
  }
527
- function showFallbackViteCopyPasteSnippet(viteConfigPath, codeSnippet) {
528
- return __awaiter(this, void 0, void 0, function () {
529
- var viteConfigFilename;
530
- return __generator(this, function (_a) {
531
- switch (_a.label) {
532
- case 0:
533
- viteConfigFilename = path.basename(viteConfigPath);
534
- prompts_1.default.log.warning("Couldn't automatically modify your ".concat(chalk_1.default.cyan(viteConfigFilename), "\n").concat(chalk_1.default.dim("This sometimes happens when we encounter more complex vite configs.\nIt may not seem like it but sometimes our magical powers are limited ;)")));
535
- prompts_1.default.log.info("But don't worry - it's super easy to do this yourself!");
536
- prompts_1.default.log.step("Add the following code to your ".concat(chalk_1.default.cyan(viteConfigFilename), ":"));
537
- // Intentionally logging to console here for easier copy/pasting
538
- // eslint-disable-next-line no-console
539
- console.log(codeSnippet);
540
- return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.select({
541
- message: 'Did you copy the snippet above?',
542
- options: [
543
- { label: 'Yes!', value: true, hint: "Great, that's already it!" },
544
- ],
545
- initialValue: true,
546
- }))];
547
- case 1:
548
- _a.sent();
549
- return [2 /*return*/];
550
- }
551
- });
552
- });
371
+ async function showFallbackViteCopyPasteSnippet(viteConfigPath, codeSnippet) {
372
+ const viteConfigFilename = path.basename(viteConfigPath);
373
+ prompts_1.default.log.warning(`Couldn't automatically modify your ${chalk_1.default.cyan(viteConfigFilename)}
374
+ ${chalk_1.default.dim(`This sometimes happens when we encounter more complex vite configs.
375
+ It may not seem like it but sometimes our magical powers are limited ;)`)}`);
376
+ prompts_1.default.log.info("But don't worry - it's super easy to do this yourself!");
377
+ prompts_1.default.log.step(`Add the following code to your ${chalk_1.default.cyan(viteConfigFilename)}:`);
378
+ // Intentionally logging to console here for easier copy/pasting
379
+ // eslint-disable-next-line no-console
380
+ console.log(codeSnippet);
381
+ await (0, clack_utils_1.abortIfCancelled)(prompts_1.default.select({
382
+ message: 'Did you copy the snippet above?',
383
+ options: [
384
+ { label: 'Yes!', value: true, hint: "Great, that's already it!" },
385
+ ],
386
+ initialValue: true,
387
+ }));
553
388
  }
554
- var getViteConfigCodeSnippet = function (org, project, selfHosted, url) {
555
- return chalk_1.default.gray("\nimport { sveltekit } from '@sveltejs/kit/vite';\nimport { defineConfig } from 'vite';\n".concat(chalk_1.default.greenBright("import { sentrySvelteKit } from '@sentry/sveltekit'"), "\n\nexport default defineConfig({\n plugins: [\n // Make sure `sentrySvelteKit` is registered before `sveltekit`\n ").concat(chalk_1.default.greenBright("sentrySvelteKit({\n sourceMapsUploadOptions: {\n org: '".concat(org, "',\n project: '").concat(project, "',").concat(selfHosted ? "\n url: '".concat(url, "',") : '', "\n }\n }),")), "\n sveltekit(),\n ]\n});\n"));
556
- };
389
+ const getViteConfigCodeSnippet = (org, project, selfHosted, url) => chalk_1.default.gray(`
390
+ import { sveltekit } from '@sveltejs/kit/vite';
391
+ import { defineConfig } from 'vite';
392
+ ${chalk_1.default.greenBright("import { sentrySvelteKit } from '@sentry/sveltekit'")}
393
+
394
+ export default defineConfig({
395
+ plugins: [
396
+ // Make sure \`sentrySvelteKit\` is registered before \`sveltekit\`
397
+ ${chalk_1.default.greenBright(`sentrySvelteKit({
398
+ sourceMapsUploadOptions: {
399
+ org: '${org}',
400
+ project: '${project}',${selfHosted ? `\n url: '${url}',` : ''}
401
+ }
402
+ }),`)}
403
+ sveltekit(),
404
+ ]
405
+ });
406
+ `);
557
407
  /**
558
408
  * We want to insert the init call on top of the file but after all import statements
559
409
  */
560
410
  function getInitCallInsertionIndex(originalHooksModAST) {
561
411
  // We need to deep-copy here because reverse mutates in place
562
- var copiedBodyNodes = __spreadArray([], originalHooksModAST.body, true);
563
- var lastImportDeclaration = copiedBodyNodes
412
+ const copiedBodyNodes = [...originalHooksModAST.body];
413
+ const lastImportDeclaration = copiedBodyNodes
564
414
  .reverse()
565
- .find(function (node) { return node.type === 'ImportDeclaration'; });
566
- var initCallInsertionIndex = lastImportDeclaration
415
+ .find((node) => node.type === 'ImportDeclaration');
416
+ const initCallInsertionIndex = lastImportDeclaration
567
417
  ? originalHooksModAST.body.indexOf(lastImportDeclaration) + 1
568
418
  : 0;
569
419
  return initCallInsertionIndex;
@@ -573,25 +423,14 @@ function getInitCallInsertionIndex(originalHooksModAST) {
573
423
  * In case of a failure, a tag is set with @param reason as a fail reason
574
424
  * and the error is rethrown.
575
425
  */
576
- function modifyAndRecordFail(modifyCallback, reason, fileType) {
577
- return __awaiter(this, void 0, void 0, function () {
578
- var e_3;
579
- return __generator(this, function (_a) {
580
- switch (_a.label) {
581
- case 0:
582
- _a.trys.push([0, 2, , 3]);
583
- return [4 /*yield*/, (0, telemetry_1.traceStep)("".concat(fileType, "-").concat(reason), modifyCallback)];
584
- case 1:
585
- _a.sent();
586
- return [3 /*break*/, 3];
587
- case 2:
588
- e_3 = _a.sent();
589
- Sentry.setTag("modified-".concat(fileType), 'fail');
590
- Sentry.setTag("".concat(fileType, "-mod-fail-reason"), reason);
591
- throw e_3;
592
- case 3: return [2 /*return*/];
593
- }
594
- });
595
- });
426
+ async function modifyAndRecordFail(modifyCallback, reason, fileType) {
427
+ try {
428
+ await (0, telemetry_1.traceStep)(`${fileType}-${reason}`, modifyCallback);
429
+ }
430
+ catch (e) {
431
+ Sentry.setTag(`modified-${fileType}`, 'fail');
432
+ Sentry.setTag(`${fileType}-mod-fail-reason`, reason);
433
+ throw e;
434
+ }
596
435
  }
597
436
  //# sourceMappingURL=sdk-setup.js.map