@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
@@ -22,251 +22,161 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
62
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
63
- if (ar || !(i in from)) {
64
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
65
- ar[i] = from[i];
66
- }
67
- }
68
- return to.concat(ar || Array.prototype.slice.call(from));
69
- };
70
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
71
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
72
27
  };
73
28
  Object.defineProperty(exports, "__esModule", { value: true });
74
29
  exports.modifyWebpackConfig = exports.configureWebPackPlugin = void 0;
75
- var path = __importStar(require("path"));
76
- var fs = __importStar(require("fs"));
30
+ const path = __importStar(require("node:path"));
31
+ const fs = __importStar(require("node:fs"));
77
32
  // @ts-ignore - clack is ESM and TS complains about that. It works though
78
- var clack = __importStar(require("@clack/prompts"));
79
- var chalk_1 = __importDefault(require("chalk"));
80
- var recast = __importStar(require("recast"));
81
- var Sentry = __importStar(require("@sentry/node"));
82
- var clack_utils_1 = require("../../utils/clack-utils");
83
- var package_json_1 = require("../../utils/package-json");
84
- var ast_utils_1 = require("../../utils/ast-utils");
85
- var debug_1 = require("../../utils/debug");
86
- var getCodeSnippet = function (options, colors) {
87
- return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus) {
88
- return unchanged("".concat(plus('const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");'), "\n\nmodule.exports = {\n // ... other options\n ").concat(plus('devtool: "source-map", // Source map generation must be turned on'), "\n plugins: [\n // Put the Sentry Webpack plugin after all other plugins\n ").concat(plus("sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"".concat(options.orgSlug, "\",\n project: \"").concat(options.projectSlug, "\",").concat(options.selfHosted ? "\n url: \"".concat(options.url, "\",") : '', "\n }),")), "\n ],\n}"));
33
+ const clack = __importStar(require("@clack/prompts"));
34
+ const chalk_1 = __importDefault(require("chalk"));
35
+ const recast = __importStar(require("recast"));
36
+ const Sentry = __importStar(require("@sentry/node"));
37
+ const clack_utils_1 = require("../../utils/clack-utils");
38
+ const package_json_1 = require("../../utils/package-json");
39
+ const ast_utils_1 = require("../../utils/ast-utils");
40
+ const debug_1 = require("../../utils/debug");
41
+ const getCodeSnippet = (options, colors) => (0, clack_utils_1.makeCodeSnippet)(colors, (unchanged, plus) => unchanged(`${plus('const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");')}
42
+
43
+ module.exports = {
44
+ // ... other options
45
+ ${plus('devtool: "source-map", // Source map generation must be turned on')}
46
+ plugins: [
47
+ // Put the Sentry Webpack plugin after all other plugins
48
+ ${plus(`sentryWebpackPlugin({
49
+ authToken: process.env.SENTRY_AUTH_TOKEN,
50
+ org: "${options.orgSlug}",
51
+ project: "${options.projectSlug}",${options.selfHosted ? `\n url: "${options.url}",` : ''}
52
+ }),`)}
53
+ ],
54
+ }`));
55
+ const configureWebPackPlugin = async (options) => {
56
+ await (0, clack_utils_1.installPackage)({
57
+ packageName: '@sentry/webpack-plugin',
58
+ alreadyInstalled: (0, package_json_1.hasPackageInstalled)('@sentry/webpack-plugin', await (0, clack_utils_1.getPackageDotJson)()),
89
59
  });
60
+ const webpackConfigPath = (0, ast_utils_1.findFile)(path.resolve(process.cwd(), 'webpack.config')) ??
61
+ (await (0, clack_utils_1.askForToolConfigPath)('Webpack', 'webpack.config.js'));
62
+ let successfullyAdded = false;
63
+ if (webpackConfigPath) {
64
+ successfullyAdded = await modifyWebpackConfig(webpackConfigPath, options);
65
+ }
66
+ else {
67
+ successfullyAdded = await (0, clack_utils_1.createNewConfigFile)(path.join(process.cwd(), 'webpack.config.js'), getCodeSnippet(options, false), 'More information about Webpack configs: https://vitejs.dev/config/');
68
+ Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
69
+ }
70
+ if (successfullyAdded) {
71
+ clack.log.info(`We recommend checking the ${webpackConfigPath ? 'modified' : 'added'} file after the wizard finished to ensure it works with your build setup.`);
72
+ Sentry.setTag('ast-mod', 'success');
73
+ }
74
+ else {
75
+ Sentry.setTag('ast-mod', 'fail');
76
+ await (0, clack_utils_1.showCopyPasteInstructions)(path.basename(webpackConfigPath || 'webpack.config.js'), getCodeSnippet(options, true));
77
+ }
78
+ await (0, clack_utils_1.addDotEnvSentryBuildPluginFile)(options.authToken);
90
79
  };
91
- var configureWebPackPlugin = function (options) { return __awaiter(void 0, void 0, void 0, function () {
92
- var _a, _b, _c, webpackConfigPath, _d, successfullyAdded;
93
- var _e;
94
- var _f;
95
- return __generator(this, function (_g) {
96
- switch (_g.label) {
97
- case 0:
98
- _a = clack_utils_1.installPackage;
99
- _e = {
100
- packageName: '@sentry/webpack-plugin'
101
- };
102
- _b = package_json_1.hasPackageInstalled;
103
- _c = ['@sentry/webpack-plugin'];
104
- return [4 /*yield*/, (0, clack_utils_1.getPackageDotJson)()];
105
- case 1: return [4 /*yield*/, _a.apply(void 0, [(_e.alreadyInstalled = _b.apply(void 0, _c.concat([_g.sent()])),
106
- _e)])];
107
- case 2:
108
- _g.sent();
109
- if (!((_f = (0, ast_utils_1.findFile)(path.resolve(process.cwd(), 'webpack.config'))) !== null && _f !== void 0)) return [3 /*break*/, 3];
110
- _d = _f;
111
- return [3 /*break*/, 5];
112
- case 3: return [4 /*yield*/, (0, clack_utils_1.askForToolConfigPath)('Webpack', 'webpack.config.js')];
113
- case 4:
114
- _d = (_g.sent());
115
- _g.label = 5;
116
- case 5:
117
- webpackConfigPath = _d;
118
- successfullyAdded = false;
119
- if (!webpackConfigPath) return [3 /*break*/, 7];
120
- return [4 /*yield*/, modifyWebpackConfig(webpackConfigPath, options)];
121
- case 6:
122
- successfullyAdded = _g.sent();
123
- return [3 /*break*/, 9];
124
- case 7: return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)(path.join(process.cwd(), 'webpack.config.js'), getCodeSnippet(options, false), 'More information about Webpack configs: https://vitejs.dev/config/')];
125
- case 8:
126
- successfullyAdded = _g.sent();
127
- Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
128
- _g.label = 9;
129
- case 9:
130
- if (!successfullyAdded) return [3 /*break*/, 10];
131
- clack.log.info("We recommend checking the ".concat(webpackConfigPath ? 'modified' : 'added', " file after the wizard finished to ensure it works with your build setup."));
132
- Sentry.setTag('ast-mod', 'success');
133
- return [3 /*break*/, 12];
134
- case 10:
135
- Sentry.setTag('ast-mod', 'fail');
136
- return [4 /*yield*/, (0, clack_utils_1.showCopyPasteInstructions)(path.basename(webpackConfigPath || 'webpack.config.js'), getCodeSnippet(options, true))];
137
- case 11:
138
- _g.sent();
139
- _g.label = 12;
140
- case 12: return [4 /*yield*/, (0, clack_utils_1.addDotEnvSentryBuildPluginFile)(options.authToken)];
141
- case 13:
142
- _g.sent();
143
- return [2 /*return*/];
144
- }
145
- });
146
- }); };
147
80
  exports.configureWebPackPlugin = configureWebPackPlugin;
148
81
  /**
149
82
  * Modifies a webpack config file to enable source map generation and add the Sentry webpack plugin
150
83
  * exported only for testing
151
84
  */
152
- function modifyWebpackConfig(webpackConfigPath, options) {
153
- return __awaiter(this, void 0, void 0, function () {
154
- var webpackConfig, prettyConfigFilename, program, exportStmt, configObject, enabledSourcemaps, addedPlugin, code, e_1;
155
- return __generator(this, function (_a) {
156
- switch (_a.label) {
157
- case 0:
158
- _a.trys.push([0, 4, , 5]);
159
- return [4 /*yield*/, fs.promises.readFile(webpackConfigPath, {
160
- encoding: 'utf-8',
161
- })];
162
- case 1:
163
- webpackConfig = _a.sent();
164
- prettyConfigFilename = chalk_1.default.cyan(path.basename(webpackConfigPath));
165
- program = recast.parse(webpackConfig.toString()).program;
166
- return [4 /*yield*/, shouldModifyWebpackConfig(program, prettyConfigFilename)];
167
- case 2:
168
- if (!(_a.sent())) {
169
- // Sentry tag is set in shouldModifyWebpackConfig
170
- return [2 /*return*/, false];
171
- }
172
- exportStmt = getCjsModuleExports(program);
173
- if (!exportStmt) {
174
- // We only care about CJS at the moment since it's probably the most widely used format for webpack configs.
175
- (0, debug_1.debug)("Could not find module.exports = {...} in ".concat(webpackConfigPath, "."));
176
- Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');
177
- return [2 /*return*/, false];
178
- }
179
- configObject = getWebpackConfigObject(exportStmt, program);
180
- if (!configObject) {
181
- (0, debug_1.debug)("Couldn't find config object in ".concat(webpackConfigPath));
182
- Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');
183
- return [2 /*return*/, false];
184
- }
185
- enabledSourcemaps = enableSourcemapsGeneration(configObject);
186
- if (enabledSourcemaps) {
187
- clack.log.success("Enabled source map generation in ".concat(prettyConfigFilename, "."));
188
- }
189
- else {
190
- clack.log.warn("Couldn't enable source maps generation in ".concat(prettyConfigFilename, " Please follow the instructions below."));
191
- Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
192
- return [2 /*return*/, false];
193
- }
194
- addedPlugin = addSentryWebpackPlugin(program, configObject, options);
195
- if (addedPlugin) {
196
- clack.log.success("Added Sentry webpack plugin to ".concat(prettyConfigFilename, "."));
197
- }
198
- else {
199
- clack.log.warn("Couldn't add Sentry webpack plugin to ".concat(prettyConfigFilename, ". Please follow the instructions below."));
200
- Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
201
- return [2 /*return*/, false];
202
- }
203
- code = recast.print(program).code;
204
- return [4 /*yield*/, fs.promises.writeFile(webpackConfigPath, code)];
205
- case 3:
206
- _a.sent();
207
- return [2 /*return*/, true];
208
- case 4:
209
- e_1 = _a.sent();
210
- Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
211
- (0, debug_1.debug)(e_1);
212
- return [2 /*return*/, false];
213
- case 5: return [2 /*return*/];
214
- }
85
+ async function modifyWebpackConfig(webpackConfigPath, options) {
86
+ try {
87
+ const webpackConfig = await fs.promises.readFile(webpackConfigPath, {
88
+ encoding: 'utf-8',
215
89
  });
216
- });
90
+ const prettyConfigFilename = chalk_1.default.cyan(path.basename(webpackConfigPath));
91
+ // no idea why recast returns any here, this is dumb :/
92
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
93
+ const program = recast.parse(webpackConfig.toString()).program;
94
+ if (!(await shouldModifyWebpackConfig(program, prettyConfigFilename))) {
95
+ // Sentry tag is set in shouldModifyWebpackConfig
96
+ return false;
97
+ }
98
+ const exportStmt = getCjsModuleExports(program);
99
+ if (!exportStmt) {
100
+ // We only care about CJS at the moment since it's probably the most widely used format for webpack configs.
101
+ (0, debug_1.debug)(`Could not find module.exports = {...} in ${webpackConfigPath}.`);
102
+ Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');
103
+ return false;
104
+ }
105
+ const configObject = getWebpackConfigObject(exportStmt, program);
106
+ if (!configObject) {
107
+ (0, debug_1.debug)(`Couldn't find config object in ${webpackConfigPath}`);
108
+ Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');
109
+ return false;
110
+ }
111
+ const enabledSourcemaps = enableSourcemapsGeneration(configObject);
112
+ if (enabledSourcemaps) {
113
+ clack.log.success(`Enabled source map generation in ${prettyConfigFilename}.`);
114
+ }
115
+ else {
116
+ clack.log.warn(`Couldn't enable source maps generation in ${prettyConfigFilename} Please follow the instructions below.`);
117
+ Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
118
+ return false;
119
+ }
120
+ const addedPlugin = addSentryWebpackPlugin(program, configObject, options);
121
+ if (addedPlugin) {
122
+ clack.log.success(`Added Sentry webpack plugin to ${prettyConfigFilename}.`);
123
+ }
124
+ else {
125
+ clack.log.warn(`Couldn't add Sentry webpack plugin to ${prettyConfigFilename}. Please follow the instructions below.`);
126
+ Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
127
+ return false;
128
+ }
129
+ const code = recast.print(program).code;
130
+ await fs.promises.writeFile(webpackConfigPath, code);
131
+ return true;
132
+ }
133
+ catch (e) {
134
+ Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
135
+ (0, debug_1.debug)(e);
136
+ return false;
137
+ }
217
138
  }
218
139
  exports.modifyWebpackConfig = modifyWebpackConfig;
219
- function shouldModifyWebpackConfig(program, prettyConfigFilename) {
220
- return __awaiter(this, void 0, void 0, function () {
221
- var shouldContinue;
222
- return __generator(this, function (_a) {
223
- switch (_a.label) {
224
- case 0:
225
- if (!(0, ast_utils_1.hasSentryContent)(program)) return [3 /*break*/, 2];
226
- return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
227
- message: "Seems like ".concat(prettyConfigFilename, " already contains Sentry-related code. Should the wizard modify it anyway?"),
228
- options: [
229
- {
230
- label: 'Yes, add the Sentry Webpack plugin',
231
- value: true,
232
- },
233
- {
234
- label: 'No, show me instructions to manually add the plugin',
235
- value: false,
236
- },
237
- ],
238
- initialValue: true,
239
- }))];
240
- case 1:
241
- shouldContinue = _a.sent();
242
- if (!shouldContinue) {
243
- Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');
244
- return [2 /*return*/, false];
245
- }
246
- _a.label = 2;
247
- case 2: return [2 /*return*/, true];
248
- }
249
- });
250
- });
140
+ async function shouldModifyWebpackConfig(program, prettyConfigFilename) {
141
+ if ((0, ast_utils_1.hasSentryContent)(program)) {
142
+ const shouldContinue = await (0, clack_utils_1.abortIfCancelled)(clack.select({
143
+ message: `Seems like ${prettyConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,
144
+ options: [
145
+ {
146
+ label: 'Yes, add the Sentry Webpack plugin',
147
+ value: true,
148
+ },
149
+ {
150
+ label: 'No, show me instructions to manually add the plugin',
151
+ value: false,
152
+ },
153
+ ],
154
+ initialValue: true,
155
+ }));
156
+ if (!shouldContinue) {
157
+ Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');
158
+ return false;
159
+ }
160
+ }
161
+ return true;
251
162
  }
252
163
  function addSentryWebpackPlugin(program, configObj, options) {
253
- var b = addSentryWebpackPluginImport(program);
254
- var sentryPluginCall = b.callExpression(b.identifier('sentryWebpackPlugin'), [
255
- b.objectExpression(__spreadArray([
164
+ const b = addSentryWebpackPluginImport(program);
165
+ const sentryPluginCall = b.callExpression(b.identifier('sentryWebpackPlugin'), [
166
+ b.objectExpression([
256
167
  b.objectProperty(b.identifier('authToken'), b.identifier('process.env.SENTRY_AUTH_TOKEN')),
257
168
  b.objectProperty(b.identifier('org'), b.stringLiteral(options.orgSlug)),
258
- b.objectProperty(b.identifier('project'), b.stringLiteral(options.projectSlug))
259
- ], (options.selfHosted
260
- ? [
261
- b.objectProperty(b.identifier('url'), b.stringLiteral(options.url)),
262
- ]
263
- : []), true)),
169
+ b.objectProperty(b.identifier('project'), b.stringLiteral(options.projectSlug)),
170
+ ...(options.selfHosted
171
+ ? [
172
+ b.objectProperty(b.identifier('url'), b.stringLiteral(options.url)),
173
+ ]
174
+ : []),
175
+ ]),
264
176
  ]);
265
- var pluginsProp = configObj.properties.find(function (p) {
266
- return p.type === 'Property' &&
267
- p.key.type === 'Identifier' &&
268
- p.key.name === 'plugins';
269
- });
177
+ const pluginsProp = configObj.properties.find((p) => p.type === 'Property' &&
178
+ p.key.type === 'Identifier' &&
179
+ p.key.name === 'plugins');
270
180
  if (pluginsProp) {
271
181
  if (pluginsProp.value.type === 'ArrayExpression') {
272
182
  pluginsProp.value.elements.push(sentryPluginCall);
@@ -280,8 +190,8 @@ function addSentryWebpackPlugin(program, configObj, options) {
280
190
  return true;
281
191
  }
282
192
  function addSentryWebpackPluginImport(program) {
283
- var b = recast.types.builders;
284
- var sentryPluginRequireStmt = b.variableDeclaration('const', [
193
+ const b = recast.types.builders;
194
+ const sentryPluginRequireStmt = b.variableDeclaration('const', [
285
195
  b.variableDeclarator(b.objectPattern([
286
196
  b.objectProperty.from({
287
197
  key: b.identifier('sentryWebpackPlugin'),
@@ -296,13 +206,10 @@ function addSentryWebpackPluginImport(program) {
296
206
  return b;
297
207
  }
298
208
  function enableSourcemapsGeneration(configObj) {
299
- var _a;
300
- var b = recast.types.builders;
301
- var devtoolProp = configObj.properties.find(function (p) {
302
- return p.type === 'Property' &&
303
- p.key.type === 'Identifier' &&
304
- p.key.name === 'devtool';
305
- });
209
+ const b = recast.types.builders;
210
+ const devtoolProp = configObj.properties.find((p) => p.type === 'Property' &&
211
+ p.key.type === 'Identifier' &&
212
+ p.key.name === 'devtool');
306
213
  if (devtoolProp) {
307
214
  // devtool can have quite a lot of source maps values.
308
215
  // see: https://webpack.js.org/configuration/devtool/#devtool
@@ -312,7 +219,7 @@ function enableSourcemapsGeneration(configObj) {
312
219
  // - all other values will be set to "source-map"
313
220
  if ((devtoolProp.value.type === 'Literal' ||
314
221
  devtoolProp.value.type === 'StringLiteral') &&
315
- ((_a = devtoolProp.value.value) === null || _a === void 0 ? void 0 : _a.toString().startsWith('hidden-'))) {
222
+ devtoolProp.value.value?.toString().startsWith('hidden-')) {
316
223
  devtoolProp.value = b.stringLiteral('hidden-source-map');
317
224
  }
318
225
  else {
@@ -324,42 +231,33 @@ function enableSourcemapsGeneration(configObj) {
324
231
  return true;
325
232
  }
326
233
  function getWebpackConfigObject(moduleExports, program) {
327
- var _a;
328
- var rhs = moduleExports.right;
234
+ const rhs = moduleExports.right;
329
235
  if (rhs.type === 'ObjectExpression') {
330
236
  return rhs;
331
237
  }
332
238
  if (rhs.type === 'Identifier') {
333
- var configId_1 = rhs.name;
334
- var configDeclaration = program.body.find(function (s) {
335
- return s.type === 'VariableDeclaration' &&
336
- !!s.declarations.find(function (d) {
337
- return d.type === 'VariableDeclarator' &&
338
- d.id.type === 'Identifier' &&
339
- d.id.name === configId_1;
340
- });
341
- });
342
- var declarator = configDeclaration === null || configDeclaration === void 0 ? void 0 : configDeclaration.declarations.find(function (d) {
343
- return d.type === 'VariableDeclarator' &&
239
+ const configId = rhs.name;
240
+ const configDeclaration = program.body.find((s) => s.type === 'VariableDeclaration' &&
241
+ !!s.declarations.find((d) => d.type === 'VariableDeclarator' &&
344
242
  d.id.type === 'Identifier' &&
345
- d.id.name === configId_1;
346
- });
347
- return ((_a = declarator === null || declarator === void 0 ? void 0 : declarator.init) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression'
243
+ d.id.name === configId));
244
+ const declarator = configDeclaration?.declarations.find((d) => d.type === 'VariableDeclarator' &&
245
+ d.id.type === 'Identifier' &&
246
+ d.id.name === configId);
247
+ return declarator?.init?.type === 'ObjectExpression'
348
248
  ? declarator.init
349
249
  : undefined;
350
250
  }
351
251
  return undefined;
352
252
  }
353
253
  function getCjsModuleExports(program) {
354
- var moduleExports = program.body.find(function (s) {
355
- return s.type === 'ExpressionStatement' &&
356
- s.expression.type === 'AssignmentExpression' &&
357
- s.expression.left.type === 'MemberExpression' &&
358
- s.expression.left.object.type === 'Identifier' &&
359
- s.expression.left.object.name === 'module' &&
360
- s.expression.left.property.type === 'Identifier' &&
361
- s.expression.left.property.name === 'exports';
362
- });
363
- return moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.expression;
254
+ const moduleExports = program.body.find((s) => s.type === 'ExpressionStatement' &&
255
+ s.expression.type === 'AssignmentExpression' &&
256
+ s.expression.left.type === 'MemberExpression' &&
257
+ s.expression.left.object.type === 'Identifier' &&
258
+ s.expression.left.object.name === 'module' &&
259
+ s.expression.left.property.type === 'Identifier' &&
260
+ s.expression.left.property.name === 'exports');
261
+ return moduleExports?.expression;
364
262
  }
365
263
  //# sourceMappingURL=webpack.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/webpack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA6B;AAC7B,qCAAyB;AAEzB,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAE1B,6CAAiC;AAIjC,mDAAuC;AAEvC,uDASiC;AACjC,yDAA+D;AAO/D,mDAAmE;AACnE,2CAA0C;AAE1C,IAAM,cAAc,GAAG,UACrB,OAAgD,EAChD,MAAe;IAEf,OAAA,IAAA,6BAAe,EAAC,MAAM,EAAE,UAAC,SAAS,EAAE,IAAI;QACtC,OAAA,SAAS,CAAC,UAAG,IAAI,CACf,oEAAoE,CACrE,+DAID,IAAI,CAAC,mEAAmE,CAAC,+FAGvE,IAAI,CAAC,+FAEG,OAAO,CAAC,OAAO,mCACX,OAAO,CAAC,WAAW,gBAC/B,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,yBAAiB,OAAO,CAAC,GAAG,QAAI,CAAC,CAAC,CAAC,EAAE,cAExD,CAAC,cAEP,CAAC;IAjBC,CAiBD,CACA;AAnBD,CAmBC,CAAC;AAEG,IAAM,sBAAsB,GACjC,UAAO,OAAO;;;;;;;gBACN,KAAA,4BAAc,CAAA;;oBAClB,WAAW,EAAE,wBAAwB;;gBACnB,KAAA,kCAAmB,CAAA;sBACnC,wBAAwB;gBACxB,qBAAM,IAAA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nB,CAAC;AAED,SAAS,mBAAmB,CAC1B,OAAkB;IAElB,IAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CACrC,UAAC,CAAC;QACA,OAAA,CAAC,CAAC,IAAI,KAAK,qBAAqB;YAChC,CAAC,CAAC,UAAU,CAAC,IAAI,KAAK,sBAAsB;YAC5C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB;YAC7C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY;YAC9C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ;YAC1C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;YAChD,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS;IAN7C,CAM6C,CAChD,CAAC;IACF,OAAO,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,UAAoC,CAAC;AAC7D,CAAC","sourcesContent":["import * as path from 'path';\nimport * as fs from 'fs';\n\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nimport * as Sentry from '@sentry/node';\n\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n askForToolConfigPath,\n createNewConfigFile,\n getPackageDotJson,\n installPackage,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../../utils/clack-utils';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\n\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\nconst getCodeSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) =>\n makeCodeSnippet(colors, (unchanged, plus) =>\n unchanged(`${plus(\n 'const { sentryWebpackPlugin } = require(\"@sentry/webpack-plugin\");',\n )}\n\nmodule.exports = {\n // ... other options\n ${plus('devtool: \"source-map\", // Source map generation must be turned on')}\n plugins: [\n // Put the Sentry Webpack plugin after all other plugins\n ${plus(`sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"${options.orgSlug}\",\n project: \"${options.projectSlug}\",${\n options.selfHosted ? `\\n url: \"${options.url}\",` : ''\n }\n }),`)}\n ],\n}`),\n );\n\nexport const configureWebPackPlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/webpack-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/webpack-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const webpackConfigPath =\n findFile(path.resolve(process.cwd(), 'webpack.config')) ??\n (await askForToolConfigPath('Webpack', 'webpack.config.js'));\n\n let successfullyAdded = false;\n if (webpackConfigPath) {\n successfullyAdded = await modifyWebpackConfig(webpackConfigPath, options);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'webpack.config.js'),\n getCodeSnippet(options, false),\n 'More information about Webpack configs: https://vitejs.dev/config/',\n );\n Sentry.setTag(\n 'created-new-config',\n successfullyAdded ? 'success' : 'fail',\n );\n }\n\n if (successfullyAdded) {\n clack.log.info(\n `We recommend checking the ${\n webpackConfigPath ? 'modified' : 'added'\n } file after the wizard finished to ensure it works with your build setup.`,\n );\n\n Sentry.setTag('ast-mod', 'success');\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n path.basename(webpackConfigPath || 'webpack.config.js'),\n getCodeSnippet(options, true),\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\n/**\n * Modifies a webpack config file to enable source map generation and add the Sentry webpack plugin\n * exported only for testing\n */\nexport async function modifyWebpackConfig(\n webpackConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const webpackConfig = await fs.promises.readFile(webpackConfigPath, {\n encoding: 'utf-8',\n });\n\n const prettyConfigFilename = chalk.cyan(path.basename(webpackConfigPath));\n\n // no idea why recast returns any here, this is dumb :/\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const program = recast.parse(webpackConfig.toString()).program as t.Program;\n\n if (!(await shouldModifyWebpackConfig(program, prettyConfigFilename))) {\n // Sentry tag is set in shouldModifyWebpackConfig\n return false;\n }\n\n const exportStmt = getCjsModuleExports(program);\n if (!exportStmt) {\n // We only care about CJS at the moment since it's probably the most widely used format for webpack configs.\n debug(`Could not find module.exports = {...} in ${webpackConfigPath}.`);\n Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');\n return false;\n }\n\n const configObject = getWebpackConfigObject(exportStmt, program);\n\n if (!configObject) {\n debug(`Couldn't find config object in ${webpackConfigPath}`);\n Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');\n return false;\n }\n\n const enabledSourcemaps = enableSourcemapsGeneration(configObject);\n\n if (enabledSourcemaps) {\n clack.log.success(\n `Enabled source map generation in ${prettyConfigFilename}.`,\n );\n } else {\n clack.log.warn(\n `Couldn't enable source maps generation in ${prettyConfigFilename} Please follow the instructions below.`,\n );\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const addedPlugin = addSentryWebpackPlugin(program, configObject, options);\n if (addedPlugin) {\n clack.log.success(\n `Added Sentry webpack plugin to ${prettyConfigFilename}.`,\n );\n } else {\n clack.log.warn(\n `Couldn't add Sentry webpack plugin to ${prettyConfigFilename}. Please follow the instructions below.`,\n );\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const code = recast.print(program).code;\n await fs.promises.writeFile(webpackConfigPath, code);\n\n return true;\n } catch (e) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n debug(e);\n return false;\n }\n}\n\nasync function shouldModifyWebpackConfig(\n program: t.Program,\n prettyConfigFilename: string,\n) {\n if (hasSentryContent(program)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `Seems like ${prettyConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Webpack plugin',\n value: true,\n },\n {\n label: 'No, show me instructions to manually add the plugin',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n if (!shouldContinue) {\n Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');\n return false;\n }\n }\n\n return true;\n}\n\nfunction addSentryWebpackPlugin(\n program: t.Program,\n configObj: t.ObjectExpression,\n options: SourceMapUploadToolConfigurationOptions,\n) {\n const b = addSentryWebpackPluginImport(program);\n\n const sentryPluginCall = b.callExpression(\n b.identifier('sentryWebpackPlugin'),\n [\n b.objectExpression([\n b.objectProperty(\n b.identifier('authToken'),\n b.identifier('process.env.SENTRY_AUTH_TOKEN'),\n ),\n b.objectProperty(b.identifier('org'), b.stringLiteral(options.orgSlug)),\n b.objectProperty(\n b.identifier('project'),\n b.stringLiteral(options.projectSlug),\n ),\n ...(options.selfHosted\n ? [\n b.objectProperty(\n b.identifier('url'),\n b.stringLiteral(options.url),\n ),\n ]\n : []),\n ]),\n ],\n );\n\n const pluginsProp = configObj.properties.find(\n (p): p is t.Property =>\n p.type === 'Property' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'plugins',\n );\n\n if (pluginsProp) {\n if (pluginsProp.value.type === 'ArrayExpression') {\n pluginsProp.value.elements.push(sentryPluginCall);\n } else {\n pluginsProp.value = b.arrayExpression([sentryPluginCall]);\n }\n return true;\n }\n\n configObj.properties.push(\n b.objectProperty(\n b.identifier('plugins'),\n b.arrayExpression([sentryPluginCall]),\n ),\n );\n\n return true;\n}\n\nfunction addSentryWebpackPluginImport(program: t.Program) {\n const b = recast.types.builders;\n\n const sentryPluginRequireStmt = b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('sentryWebpackPlugin'),\n value: b.identifier('sentryWebpackPlugin'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.stringLiteral('@sentry/webpack-plugin'),\n ]),\n ),\n ]);\n\n program.body.unshift(sentryPluginRequireStmt);\n return b;\n}\n\nfunction enableSourcemapsGeneration(configObj: t.ObjectExpression): boolean {\n const b = recast.types.builders;\n\n const devtoolProp = configObj.properties.find(\n (p): p is t.Property =>\n p.type === 'Property' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'devtool',\n );\n\n if (devtoolProp) {\n // devtool can have quite a lot of source maps values.\n // see: https://webpack.js.org/configuration/devtool/#devtool\n // For Sentry to work best, we should set it to \"source-map\" or \"hidden-source-map\"\n // Heuristic:\n // - all values that contain \"hidden\" will be set to \"hidden-source-map\"\n // - all other values will be set to \"source-map\"\n if (\n (devtoolProp.value.type === 'Literal' ||\n devtoolProp.value.type === 'StringLiteral') &&\n devtoolProp.value.value?.toString().startsWith('hidden-')\n ) {\n devtoolProp.value = b.stringLiteral('hidden-source-map');\n } else {\n devtoolProp.value = b.stringLiteral('source-map');\n }\n return true;\n }\n\n configObj.properties.push(\n b.objectProperty(b.identifier('devtool'), b.stringLiteral('source-map')),\n );\n\n return true;\n}\n\nfunction getWebpackConfigObject(\n moduleExports: t.AssignmentExpression,\n program: t.Program,\n): t.ObjectExpression | undefined {\n const rhs = moduleExports.right;\n if (rhs.type === 'ObjectExpression') {\n return rhs;\n }\n if (rhs.type === 'Identifier') {\n const configId = rhs.name;\n\n const configDeclaration = program.body.find(\n (s): s is t.VariableDeclaration =>\n s.type === 'VariableDeclaration' &&\n !!s.declarations.find(\n (d) =>\n d.type === 'VariableDeclarator' &&\n d.id.type === 'Identifier' &&\n d.id.name === configId,\n ),\n );\n\n const declarator = configDeclaration?.declarations.find(\n (d): d is t.VariableDeclarator =>\n d.type === 'VariableDeclarator' &&\n d.id.type === 'Identifier' &&\n d.id.name === configId,\n );\n\n return declarator?.init?.type === 'ObjectExpression'\n ? declarator.init\n : undefined;\n }\n\n return undefined;\n}\n\nfunction getCjsModuleExports(\n program: t.Program,\n): t.AssignmentExpression | undefined {\n const moduleExports = program.body.find(\n (s): s is t.ExpressionStatement =>\n s.type === 'ExpressionStatement' &&\n s.expression.type === 'AssignmentExpression' &&\n s.expression.left.type === 'MemberExpression' &&\n s.expression.left.object.type === 'Identifier' &&\n s.expression.left.object.name === 'module' &&\n s.expression.left.property.type === 'Identifier' &&\n s.expression.left.property.name === 'exports',\n );\n return moduleExports?.expression as t.AssignmentExpression;\n}\n"]}
1
+ {"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/webpack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,4CAA8B;AAE9B,yEAAyE;AACzE,sDAAwC;AACxC,kDAA0B;AAE1B,+CAAiC;AAIjC,qDAAuC;AAEvC,yDASiC;AACjC,2DAA+D;AAO/D,qDAAmE;AACnE,6CAA0C;AAE1C,MAAM,cAAc,GAAG,CACrB,OAAgD,EAChD,MAAe,EACf,EAAE,CACF,IAAA,6BAAe,EAAC,MAAM,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAC1C,SAAS,CAAC,GAAG,IAAI,CACf,oEAAoE,CACrE;;;;IAID,IAAI,CAAC,mEAAmE,CAAC;;;MAGvE,IAAI,CAAC;;cAEG,OAAO,CAAC,OAAO;kBACX,OAAO,CAAC,WAAW,KAC/B,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAC1D;QACI,CAAC;;EAEP,CAAC,CACA,CAAC;AAEG,MAAM,sBAAsB,GACjC,KAAK,EAAE,OAAO,EAAE,EAAE;IAChB,MAAM,IAAA,4BAAc,EAAC;QACnB,WAAW,EAAE,wBAAwB;QACrC,gBAAgB,EAAE,IAAA,kCAAmB,EACnC,wBAAwB,EACxB,MAAM,IAAA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,CAAC,IAAI,KAAK,YAAY;QAC9C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC1C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;QAChD,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,CAChD,CAAC;IACF,OAAO,aAAa,EAAE,UAAoC,CAAC;AAC7D,CAAC","sourcesContent":["import * as path from 'node:path';\nimport * as fs from 'node:fs';\n\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nimport * as Sentry from '@sentry/node';\n\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n askForToolConfigPath,\n createNewConfigFile,\n getPackageDotJson,\n installPackage,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../../utils/clack-utils';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport type {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\n\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\nconst getCodeSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) =>\n makeCodeSnippet(colors, (unchanged, plus) =>\n unchanged(`${plus(\n 'const { sentryWebpackPlugin } = require(\"@sentry/webpack-plugin\");',\n )}\n\nmodule.exports = {\n // ... other options\n ${plus('devtool: \"source-map\", // Source map generation must be turned on')}\n plugins: [\n // Put the Sentry Webpack plugin after all other plugins\n ${plus(`sentryWebpackPlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"${options.orgSlug}\",\n project: \"${options.projectSlug}\",${\n options.selfHosted ? `\\n url: \"${options.url}\",` : ''\n }\n }),`)}\n ],\n}`),\n );\n\nexport const configureWebPackPlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/webpack-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/webpack-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const webpackConfigPath =\n findFile(path.resolve(process.cwd(), 'webpack.config')) ??\n (await askForToolConfigPath('Webpack', 'webpack.config.js'));\n\n let successfullyAdded = false;\n if (webpackConfigPath) {\n successfullyAdded = await modifyWebpackConfig(webpackConfigPath, options);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'webpack.config.js'),\n getCodeSnippet(options, false),\n 'More information about Webpack configs: https://vitejs.dev/config/',\n );\n Sentry.setTag(\n 'created-new-config',\n successfullyAdded ? 'success' : 'fail',\n );\n }\n\n if (successfullyAdded) {\n clack.log.info(\n `We recommend checking the ${\n webpackConfigPath ? 'modified' : 'added'\n } file after the wizard finished to ensure it works with your build setup.`,\n );\n\n Sentry.setTag('ast-mod', 'success');\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n path.basename(webpackConfigPath || 'webpack.config.js'),\n getCodeSnippet(options, true),\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\n/**\n * Modifies a webpack config file to enable source map generation and add the Sentry webpack plugin\n * exported only for testing\n */\nexport async function modifyWebpackConfig(\n webpackConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const webpackConfig = await fs.promises.readFile(webpackConfigPath, {\n encoding: 'utf-8',\n });\n\n const prettyConfigFilename = chalk.cyan(path.basename(webpackConfigPath));\n\n // no idea why recast returns any here, this is dumb :/\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const program = recast.parse(webpackConfig.toString()).program as t.Program;\n\n if (!(await shouldModifyWebpackConfig(program, prettyConfigFilename))) {\n // Sentry tag is set in shouldModifyWebpackConfig\n return false;\n }\n\n const exportStmt = getCjsModuleExports(program);\n if (!exportStmt) {\n // We only care about CJS at the moment since it's probably the most widely used format for webpack configs.\n debug(`Could not find module.exports = {...} in ${webpackConfigPath}.`);\n Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');\n return false;\n }\n\n const configObject = getWebpackConfigObject(exportStmt, program);\n\n if (!configObject) {\n debug(`Couldn't find config object in ${webpackConfigPath}`);\n Sentry.setTag('ast-mod-fail-reason', 'config-object-not-found');\n return false;\n }\n\n const enabledSourcemaps = enableSourcemapsGeneration(configObject);\n\n if (enabledSourcemaps) {\n clack.log.success(\n `Enabled source map generation in ${prettyConfigFilename}.`,\n );\n } else {\n clack.log.warn(\n `Couldn't enable source maps generation in ${prettyConfigFilename} Please follow the instructions below.`,\n );\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const addedPlugin = addSentryWebpackPlugin(program, configObject, options);\n if (addedPlugin) {\n clack.log.success(\n `Added Sentry webpack plugin to ${prettyConfigFilename}.`,\n );\n } else {\n clack.log.warn(\n `Couldn't add Sentry webpack plugin to ${prettyConfigFilename}. Please follow the instructions below.`,\n );\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const code = recast.print(program).code;\n await fs.promises.writeFile(webpackConfigPath, code);\n\n return true;\n } catch (e) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n debug(e);\n return false;\n }\n}\n\nasync function shouldModifyWebpackConfig(\n program: t.Program,\n prettyConfigFilename: string,\n) {\n if (hasSentryContent(program)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `Seems like ${prettyConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Webpack plugin',\n value: true,\n },\n {\n label: 'No, show me instructions to manually add the plugin',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n if (!shouldContinue) {\n Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');\n return false;\n }\n }\n\n return true;\n}\n\nfunction addSentryWebpackPlugin(\n program: t.Program,\n configObj: t.ObjectExpression,\n options: SourceMapUploadToolConfigurationOptions,\n) {\n const b = addSentryWebpackPluginImport(program);\n\n const sentryPluginCall = b.callExpression(\n b.identifier('sentryWebpackPlugin'),\n [\n b.objectExpression([\n b.objectProperty(\n b.identifier('authToken'),\n b.identifier('process.env.SENTRY_AUTH_TOKEN'),\n ),\n b.objectProperty(b.identifier('org'), b.stringLiteral(options.orgSlug)),\n b.objectProperty(\n b.identifier('project'),\n b.stringLiteral(options.projectSlug),\n ),\n ...(options.selfHosted\n ? [\n b.objectProperty(\n b.identifier('url'),\n b.stringLiteral(options.url),\n ),\n ]\n : []),\n ]),\n ],\n );\n\n const pluginsProp = configObj.properties.find(\n (p): p is t.Property =>\n p.type === 'Property' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'plugins',\n );\n\n if (pluginsProp) {\n if (pluginsProp.value.type === 'ArrayExpression') {\n pluginsProp.value.elements.push(sentryPluginCall);\n } else {\n pluginsProp.value = b.arrayExpression([sentryPluginCall]);\n }\n return true;\n }\n\n configObj.properties.push(\n b.objectProperty(\n b.identifier('plugins'),\n b.arrayExpression([sentryPluginCall]),\n ),\n );\n\n return true;\n}\n\nfunction addSentryWebpackPluginImport(program: t.Program) {\n const b = recast.types.builders;\n\n const sentryPluginRequireStmt = b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('sentryWebpackPlugin'),\n value: b.identifier('sentryWebpackPlugin'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.stringLiteral('@sentry/webpack-plugin'),\n ]),\n ),\n ]);\n\n program.body.unshift(sentryPluginRequireStmt);\n return b;\n}\n\nfunction enableSourcemapsGeneration(configObj: t.ObjectExpression): boolean {\n const b = recast.types.builders;\n\n const devtoolProp = configObj.properties.find(\n (p): p is t.Property =>\n p.type === 'Property' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'devtool',\n );\n\n if (devtoolProp) {\n // devtool can have quite a lot of source maps values.\n // see: https://webpack.js.org/configuration/devtool/#devtool\n // For Sentry to work best, we should set it to \"source-map\" or \"hidden-source-map\"\n // Heuristic:\n // - all values that contain \"hidden\" will be set to \"hidden-source-map\"\n // - all other values will be set to \"source-map\"\n if (\n (devtoolProp.value.type === 'Literal' ||\n devtoolProp.value.type === 'StringLiteral') &&\n devtoolProp.value.value?.toString().startsWith('hidden-')\n ) {\n devtoolProp.value = b.stringLiteral('hidden-source-map');\n } else {\n devtoolProp.value = b.stringLiteral('source-map');\n }\n return true;\n }\n\n configObj.properties.push(\n b.objectProperty(b.identifier('devtool'), b.stringLiteral('source-map')),\n );\n\n return true;\n}\n\nfunction getWebpackConfigObject(\n moduleExports: t.AssignmentExpression,\n program: t.Program,\n): t.ObjectExpression | undefined {\n const rhs = moduleExports.right;\n if (rhs.type === 'ObjectExpression') {\n return rhs;\n }\n if (rhs.type === 'Identifier') {\n const configId = rhs.name;\n\n const configDeclaration = program.body.find(\n (s): s is t.VariableDeclaration =>\n s.type === 'VariableDeclaration' &&\n !!s.declarations.find(\n (d) =>\n d.type === 'VariableDeclarator' &&\n d.id.type === 'Identifier' &&\n d.id.name === configId,\n ),\n );\n\n const declarator = configDeclaration?.declarations.find(\n (d): d is t.VariableDeclarator =>\n d.type === 'VariableDeclarator' &&\n d.id.type === 'Identifier' &&\n d.id.name === configId,\n );\n\n return declarator?.init?.type === 'ObjectExpression'\n ? declarator.init\n : undefined;\n }\n\n return undefined;\n}\n\nfunction getCjsModuleExports(\n program: t.Program,\n): t.AssignmentExpression | undefined {\n const moduleExports = program.body.find(\n (s): s is t.ExpressionStatement =>\n s.type === 'ExpressionStatement' &&\n s.expression.type === 'AssignmentExpression' &&\n s.expression.left.type === 'MemberExpression' &&\n s.expression.left.object.type === 'Identifier' &&\n s.expression.left.object.name === 'module' &&\n s.expression.left.property.type === 'Identifier' &&\n s.expression.left.property.name === 'exports',\n );\n return moduleExports?.expression as t.AssignmentExpression;\n}\n"]}