@sentry/wizard 4.0.0 → 4.0.2

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 (330) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/dist/NextJs/configs/next.config.js +1 -1
  3. package/dist/bin.js +2 -1
  4. package/dist/bin.js.map +1 -1
  5. package/dist/bump-version.js +28 -0
  6. package/dist/craft-pre-release.sh +2 -0
  7. package/dist/lib/Steps/Initial.js +2 -12
  8. package/dist/lib/Steps/Initial.js.map +1 -1
  9. package/dist/lib/Steps/Integrations/Electron.js +1 -1
  10. package/dist/lib/Steps/Integrations/Electron.js.map +1 -1
  11. package/dist/src/nextjs/templates.js +1 -1
  12. package/dist/src/nextjs/templates.js.map +1 -1
  13. package/dist/src/run.js +2 -18
  14. package/dist/src/run.js.map +1 -1
  15. package/dist/src/telemetry.js +2 -16
  16. package/dist/src/telemetry.js.map +1 -1
  17. package/dist/src/utils/clack-utils.d.ts +16 -0
  18. package/dist/src/utils/clack-utils.js +53 -45
  19. package/dist/src/utils/clack-utils.js.map +1 -1
  20. package/dist/src/version.d.ts +1 -0
  21. package/dist/src/version.js +7 -0
  22. package/dist/src/version.js.map +1 -0
  23. package/dist/test/nextjs/templates.test.js +4 -4
  24. package/dist/test/nextjs/templates.test.js.map +1 -1
  25. package/dist/test/utils/clack-utils.test.js +52 -0
  26. package/dist/test/utils/clack-utils.test.js.map +1 -1
  27. package/package.json +5 -2
  28. package/.node-cache/node-v22.14.0-darwin-arm64 +0 -0
  29. package/.node-cache/node-v22.14.0-darwin-x64 +0 -0
  30. package/.node-cache/node-v22.14.0-linux-arm64 +0 -0
  31. package/.node-cache/node-v22.14.0-linux-x64 +0 -0
  32. package/.node-cache/node-v22.14.0-win-x64.exe +0 -0
  33. package/COPYING +0 -3575
  34. package/bin.ts +0 -143
  35. package/codecov.yml +0 -15
  36. package/e2e-tests/.env.example +0 -11
  37. package/e2e-tests/README.md +0 -63
  38. package/e2e-tests/jest.config.ts +0 -22
  39. package/e2e-tests/package.json +0 -14
  40. package/e2e-tests/run.sh +0 -15
  41. package/e2e-tests/test-applications/apple/damaged-missing-configuration-list/Project.xcodeproj/project.pbxproj +0 -52
  42. package/e2e-tests/test-applications/apple/damaged-missing-configuration-list/Project.xcodeproj/xcshareddata/xcschemes/Project1.xcscheme +0 -78
  43. package/e2e-tests/test-applications/apple/no-targets/Project.xcodeproj/project.pbxproj +0 -62
  44. package/e2e-tests/test-applications/apple/no-targets/Project.xcodeproj/xcshareddata/xcschemes/Project1.xcscheme +0 -78
  45. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project.xcodeproj/project.pbxproj +0 -470
  46. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project.xcodeproj/xcshareddata/xcschemes/Project1.xcscheme +0 -78
  47. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project1/ContentView.swift +0 -7
  48. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project1/Project1App.swift +0 -10
  49. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project2/ContentView.swift +0 -7
  50. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project2/Project2App.swift +0 -10
  51. package/e2e-tests/test-applications/apple/spm-swiftui-single-target/Project.xcodeproj/project.pbxproj +0 -382
  52. package/e2e-tests/test-applications/apple/spm-swiftui-single-target/Project.xcodeproj/xcshareddata/xcschemes/Project.xcscheme +0 -78
  53. package/e2e-tests/test-applications/apple/spm-swiftui-single-target/Sources/ContentView.swift +0 -7
  54. package/e2e-tests/test-applications/apple/spm-swiftui-single-target/Sources/MainApp.swift +0 -10
  55. package/e2e-tests/test-applications/flutter-test-app/.metadata +0 -45
  56. package/e2e-tests/test-applications/flutter-test-app/README.md +0 -16
  57. package/e2e-tests/test-applications/flutter-test-app/analysis_options.yaml +0 -28
  58. package/e2e-tests/test-applications/flutter-test-app/android/app/build.gradle +0 -44
  59. package/e2e-tests/test-applications/flutter-test-app/android/app/src/debug/AndroidManifest.xml +0 -7
  60. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/AndroidManifest.xml +0 -45
  61. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/kotlin/com/example/flutter_magic/MainActivity.kt +0 -5
  62. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/res/drawable/launch_background.xml +0 -12
  63. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/res/drawable-v21/launch_background.xml +0 -12
  64. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  65. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  66. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  67. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  68. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  69. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/res/values/styles.xml +0 -18
  70. package/e2e-tests/test-applications/flutter-test-app/android/app/src/main/res/values-night/styles.xml +0 -18
  71. package/e2e-tests/test-applications/flutter-test-app/android/app/src/profile/AndroidManifest.xml +0 -7
  72. package/e2e-tests/test-applications/flutter-test-app/android/build.gradle +0 -18
  73. package/e2e-tests/test-applications/flutter-test-app/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  74. package/e2e-tests/test-applications/flutter-test-app/android/gradle.properties +0 -3
  75. package/e2e-tests/test-applications/flutter-test-app/android/settings.gradle +0 -25
  76. package/e2e-tests/test-applications/flutter-test-app/lib/main.dart +0 -125
  77. package/e2e-tests/test-applications/flutter-test-app/linux/CMakeLists.txt +0 -145
  78. package/e2e-tests/test-applications/flutter-test-app/linux/flutter/CMakeLists.txt +0 -88
  79. package/e2e-tests/test-applications/flutter-test-app/linux/flutter/generated_plugin_registrant.cc +0 -11
  80. package/e2e-tests/test-applications/flutter-test-app/linux/flutter/generated_plugin_registrant.h +0 -15
  81. package/e2e-tests/test-applications/flutter-test-app/linux/flutter/generated_plugins.cmake +0 -23
  82. package/e2e-tests/test-applications/flutter-test-app/linux/main.cc +0 -6
  83. package/e2e-tests/test-applications/flutter-test-app/linux/my_application.cc +0 -124
  84. package/e2e-tests/test-applications/flutter-test-app/linux/my_application.h +0 -18
  85. package/e2e-tests/test-applications/flutter-test-app/macos/Flutter/Flutter-Debug.xcconfig +0 -2
  86. package/e2e-tests/test-applications/flutter-test-app/macos/Flutter/Flutter-Release.xcconfig +0 -2
  87. package/e2e-tests/test-applications/flutter-test-app/macos/Flutter/GeneratedPluginRegistrant.swift +0 -10
  88. package/e2e-tests/test-applications/flutter-test-app/macos/Podfile +0 -43
  89. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/AppDelegate.swift +0 -9
  90. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -68
  91. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png +0 -0
  92. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png +0 -0
  93. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png +0 -0
  94. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png +0 -0
  95. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png +0 -0
  96. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png +0 -0
  97. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png +0 -0
  98. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Base.lproj/MainMenu.xib +0 -343
  99. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Configs/AppInfo.xcconfig +0 -14
  100. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Configs/Debug.xcconfig +0 -2
  101. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Configs/Release.xcconfig +0 -2
  102. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Configs/Warnings.xcconfig +0 -13
  103. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/DebugProfile.entitlements +0 -12
  104. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Info.plist +0 -32
  105. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/MainFlutterWindow.swift +0 -15
  106. package/e2e-tests/test-applications/flutter-test-app/macos/Runner/Release.entitlements +0 -8
  107. package/e2e-tests/test-applications/flutter-test-app/macos/Runner.xcodeproj/project.pbxproj +0 -705
  108. package/e2e-tests/test-applications/flutter-test-app/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  109. package/e2e-tests/test-applications/flutter-test-app/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +0 -98
  110. package/e2e-tests/test-applications/flutter-test-app/macos/Runner.xcworkspace/contents.xcworkspacedata +0 -7
  111. package/e2e-tests/test-applications/flutter-test-app/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  112. package/e2e-tests/test-applications/flutter-test-app/macos/RunnerTests/RunnerTests.swift +0 -12
  113. package/e2e-tests/test-applications/flutter-test-app/pubspec.lock +0 -213
  114. package/e2e-tests/test-applications/flutter-test-app/pubspec.yaml +0 -89
  115. package/e2e-tests/test-applications/flutter-test-app/test/widget_test.dart +0 -30
  116. package/e2e-tests/test-applications/flutter-test-app/web/favicon.png +0 -0
  117. package/e2e-tests/test-applications/flutter-test-app/web/icons/Icon-192.png +0 -0
  118. package/e2e-tests/test-applications/flutter-test-app/web/icons/Icon-512.png +0 -0
  119. package/e2e-tests/test-applications/flutter-test-app/web/icons/Icon-maskable-192.png +0 -0
  120. package/e2e-tests/test-applications/flutter-test-app/web/icons/Icon-maskable-512.png +0 -0
  121. package/e2e-tests/test-applications/flutter-test-app/web/index.html +0 -38
  122. package/e2e-tests/test-applications/flutter-test-app/web/manifest.json +0 -35
  123. package/e2e-tests/test-applications/flutter-test-app/windows/CMakeLists.txt +0 -108
  124. package/e2e-tests/test-applications/flutter-test-app/windows/flutter/CMakeLists.txt +0 -109
  125. package/e2e-tests/test-applications/flutter-test-app/windows/flutter/generated_plugin_registrant.cc +0 -11
  126. package/e2e-tests/test-applications/flutter-test-app/windows/flutter/generated_plugin_registrant.h +0 -15
  127. package/e2e-tests/test-applications/flutter-test-app/windows/flutter/generated_plugins.cmake +0 -23
  128. package/e2e-tests/test-applications/flutter-test-app/windows/runner/CMakeLists.txt +0 -40
  129. package/e2e-tests/test-applications/flutter-test-app/windows/runner/Runner.rc +0 -121
  130. package/e2e-tests/test-applications/flutter-test-app/windows/runner/flutter_window.cpp +0 -71
  131. package/e2e-tests/test-applications/flutter-test-app/windows/runner/flutter_window.h +0 -33
  132. package/e2e-tests/test-applications/flutter-test-app/windows/runner/main.cpp +0 -43
  133. package/e2e-tests/test-applications/flutter-test-app/windows/runner/resource.h +0 -16
  134. package/e2e-tests/test-applications/flutter-test-app/windows/runner/resources/app_icon.ico +0 -0
  135. package/e2e-tests/test-applications/flutter-test-app/windows/runner/runner.exe.manifest +0 -14
  136. package/e2e-tests/test-applications/flutter-test-app/windows/runner/utils.cpp +0 -65
  137. package/e2e-tests/test-applications/flutter-test-app/windows/runner/utils.h +0 -19
  138. package/e2e-tests/test-applications/flutter-test-app/windows/runner/win32_window.cpp +0 -288
  139. package/e2e-tests/test-applications/flutter-test-app/windows/runner/win32_window.h +0 -102
  140. package/e2e-tests/test-applications/nextjs-test-app/next.config.mjs +0 -4
  141. package/e2e-tests/test-applications/nextjs-test-app/package.json +0 -22
  142. package/e2e-tests/test-applications/nextjs-test-app/src/app/layout.tsx +0 -20
  143. package/e2e-tests/test-applications/nextjs-test-app/src/app/page.tsx +0 -90
  144. package/e2e-tests/test-applications/nuxt-3-test-app/README.md +0 -75
  145. package/e2e-tests/test-applications/nuxt-3-test-app/nuxt.config.ts +0 -5
  146. package/e2e-tests/test-applications/nuxt-3-test-app/package.json +0 -18
  147. package/e2e-tests/test-applications/nuxt-3-test-app/public/favicon.ico +0 -0
  148. package/e2e-tests/test-applications/nuxt-3-test-app/public/robots.txt +0 -1
  149. package/e2e-tests/test-applications/nuxt-4-test-app/README.md +0 -75
  150. package/e2e-tests/test-applications/nuxt-4-test-app/nuxt.config.ts +0 -6
  151. package/e2e-tests/test-applications/nuxt-4-test-app/package.json +0 -18
  152. package/e2e-tests/test-applications/nuxt-4-test-app/public/favicon.ico +0 -0
  153. package/e2e-tests/test-applications/nuxt-4-test-app/public/robots.txt +0 -1
  154. package/e2e-tests/test-applications/remix-test-app/app/entry.client.tsx +0 -18
  155. package/e2e-tests/test-applications/remix-test-app/app/entry.server.tsx +0 -140
  156. package/e2e-tests/test-applications/remix-test-app/app/root.tsx +0 -30
  157. package/e2e-tests/test-applications/remix-test-app/app/routes/_index.tsx +0 -48
  158. package/e2e-tests/test-applications/remix-test-app/app/tailwind.css +0 -3
  159. package/e2e-tests/test-applications/remix-test-app/package.json +0 -37
  160. package/e2e-tests/test-applications/remix-test-app/postcss.config.js +0 -6
  161. package/e2e-tests/test-applications/remix-test-app/tailwind.config.ts +0 -9
  162. package/e2e-tests/test-applications/remix-test-app/vite.config.ts +0 -16
  163. package/e2e-tests/test-applications/sveltekit-test-app/package.json +0 -21
  164. package/e2e-tests/test-applications/sveltekit-test-app/src/app.d.ts +0 -13
  165. package/e2e-tests/test-applications/sveltekit-test-app/src/app.html +0 -11
  166. package/e2e-tests/test-applications/sveltekit-test-app/src/lib/index.ts +0 -1
  167. package/e2e-tests/test-applications/sveltekit-test-app/src/routes/+page.svelte +0 -2
  168. package/e2e-tests/test-applications/sveltekit-test-app/svelte.config.js +0 -18
  169. package/e2e-tests/test-applications/sveltekit-test-app/vite.config.ts +0 -6
  170. package/e2e-tests/tests/flutter.test.ts +0 -127
  171. package/e2e-tests/tests/nextjs.test.ts +0 -161
  172. package/e2e-tests/tests/nuxt-3.test.ts +0 -189
  173. package/e2e-tests/tests/nuxt-4.test.ts +0 -188
  174. package/e2e-tests/tests/remix.test.ts +0 -277
  175. package/e2e-tests/tests/sveltekit.test.ts +0 -284
  176. package/e2e-tests/utils/index.ts +0 -456
  177. package/index.ts +0 -2
  178. package/lib/Constants.ts +0 -118
  179. package/lib/Helper/BottomBar.ts +0 -28
  180. package/lib/Helper/Env.ts +0 -7
  181. package/lib/Helper/File.ts +0 -65
  182. package/lib/Helper/Git.ts +0 -39
  183. package/lib/Helper/Logging.ts +0 -44
  184. package/lib/Helper/MergeConfig.ts +0 -19
  185. package/lib/Helper/Package.ts +0 -80
  186. package/lib/Helper/SentryCli.ts +0 -139
  187. package/lib/Helper/Wizard.ts +0 -58
  188. package/lib/Helper/__tests__/File.ts +0 -15
  189. package/lib/Helper/__tests__/MergeConfig.ts +0 -98
  190. package/lib/Helper/__tests__/SentryCli.ts +0 -86
  191. package/lib/Helper/test-fixtures/next.config.1-merged.js +0 -18
  192. package/lib/Helper/test-fixtures/next.config.1.js +0 -6
  193. package/lib/Helper/test-fixtures/next.config.2.js +0 -8
  194. package/lib/Helper/test-fixtures/next.config.3-merged.js +0 -21
  195. package/lib/Helper/test-fixtures/next.config.3.js +0 -9
  196. package/lib/Helper/test-fixtures/next.config.4-merged.js +0 -21
  197. package/lib/Helper/test-fixtures/next.config.4.js +0 -9
  198. package/lib/Setup.ts +0 -40
  199. package/lib/Steps/BaseStep.ts +0 -25
  200. package/lib/Steps/ChooseIntegration.ts +0 -144
  201. package/lib/Steps/ConfigureProject.ts +0 -10
  202. package/lib/Steps/Initial.ts +0 -35
  203. package/lib/Steps/Integrations/BaseIntegration.ts +0 -42
  204. package/lib/Steps/Integrations/Cordova.ts +0 -283
  205. package/lib/Steps/Integrations/Electron.ts +0 -164
  206. package/lib/Steps/Integrations/MobileProject.ts +0 -72
  207. package/lib/Steps/OpenSentry.ts +0 -80
  208. package/lib/Steps/PromptForParameters.ts +0 -200
  209. package/lib/Steps/Result.ts +0 -22
  210. package/lib/Steps/SentryProjectSelector.ts +0 -83
  211. package/lib/Steps/ShouldConfigure.ts +0 -10
  212. package/lib/Steps/WaitForSentry.ts +0 -56
  213. package/lib/Steps/Welcome.ts +0 -21
  214. package/lib/Steps/index.ts +0 -10
  215. package/lib/__tests__/Env.ts +0 -29
  216. package/scripts/NextJs/configs/_error.js +0 -39
  217. package/scripts/NextJs/configs/next.config.js +0 -36
  218. package/scripts/NextJs/configs/next.config.template.js +0 -12
  219. package/scripts/NextJs/configs/sentry.client.config.js +0 -17
  220. package/scripts/NextJs/configs/sentry.edge.config.js +0 -17
  221. package/scripts/NextJs/configs/sentry.server.config.js +0 -17
  222. package/scripts/NextJs/sentry_sample_error.js +0 -47
  223. package/scripts/craft-pre-release.sh +0 -10
  224. package/src/android/android-wizard.ts +0 -192
  225. package/src/android/code-tools.ts +0 -170
  226. package/src/android/gradle.ts +0 -250
  227. package/src/android/manifest.ts +0 -180
  228. package/src/android/templates.ts +0 -86
  229. package/src/apple/apple-wizard.ts +0 -269
  230. package/src/apple/cocoapod.ts +0 -73
  231. package/src/apple/code-tools.ts +0 -147
  232. package/src/apple/fastlane.ts +0 -170
  233. package/src/apple/templates.ts +0 -65
  234. package/src/apple/xcode-manager.ts +0 -404
  235. package/src/flutter/code-tools.ts +0 -284
  236. package/src/flutter/flutter-wizard.ts +0 -164
  237. package/src/flutter/templates.ts +0 -90
  238. package/src/nextjs/nextjs-wizard.ts +0 -1007
  239. package/src/nextjs/templates.ts +0 -525
  240. package/src/nextjs/utils.ts +0 -21
  241. package/src/nuxt/nuxt-wizard.ts +0 -188
  242. package/src/nuxt/sdk-example.ts +0 -135
  243. package/src/nuxt/sdk-setup.ts +0 -352
  244. package/src/nuxt/templates.ts +0 -303
  245. package/src/nuxt/types.ts +0 -8
  246. package/src/nuxt/utils.ts +0 -42
  247. package/src/react-native/expo-env-file.ts +0 -55
  248. package/src/react-native/expo-metro.ts +0 -212
  249. package/src/react-native/expo.ts +0 -175
  250. package/src/react-native/git.ts +0 -25
  251. package/src/react-native/glob.ts +0 -13
  252. package/src/react-native/gradle.ts +0 -26
  253. package/src/react-native/javascript.ts +0 -103
  254. package/src/react-native/metro.ts +0 -599
  255. package/src/react-native/options.ts +0 -5
  256. package/src/react-native/react-native-wizard.ts +0 -512
  257. package/src/react-native/uninstall.ts +0 -109
  258. package/src/react-native/xcode.ts +0 -302
  259. package/src/remix/codemods/express-server.ts +0 -44
  260. package/src/remix/codemods/handle-error.ts +0 -118
  261. package/src/remix/codemods/root-common.ts +0 -63
  262. package/src/remix/codemods/root-v1.ts +0 -41
  263. package/src/remix/codemods/root-v2.ts +0 -153
  264. package/src/remix/remix-wizard.ts +0 -261
  265. package/src/remix/sdk-example.ts +0 -120
  266. package/src/remix/sdk-setup.ts +0 -546
  267. package/src/remix/templates.ts +0 -11
  268. package/src/remix/utils.ts +0 -96
  269. package/src/run.ts +0 -211
  270. package/src/sourcemaps/sourcemaps-wizard.ts +0 -364
  271. package/src/sourcemaps/tools/angular.ts +0 -42
  272. package/src/sourcemaps/tools/create-react-app.ts +0 -19
  273. package/src/sourcemaps/tools/esbuild.ts +0 -65
  274. package/src/sourcemaps/tools/nextjs.ts +0 -114
  275. package/src/sourcemaps/tools/remix.ts +0 -90
  276. package/src/sourcemaps/tools/rollup.ts +0 -67
  277. package/src/sourcemaps/tools/sentry-cli.ts +0 -287
  278. package/src/sourcemaps/tools/tsc.ts +0 -144
  279. package/src/sourcemaps/tools/types.ts +0 -11
  280. package/src/sourcemaps/tools/vite.ts +0 -300
  281. package/src/sourcemaps/tools/webpack.ts +0 -383
  282. package/src/sourcemaps/utils/detect-tool.ts +0 -46
  283. package/src/sourcemaps/utils/other-wizards.ts +0 -167
  284. package/src/sourcemaps/utils/sdk-version.ts +0 -266
  285. package/src/sveltekit/sdk-example.ts +0 -56
  286. package/src/sveltekit/sdk-setup.ts +0 -667
  287. package/src/sveltekit/sveltekit-wizard.ts +0 -192
  288. package/src/sveltekit/templates.ts +0 -185
  289. package/src/sveltekit/utils.ts +0 -50
  290. package/src/telemetry.ts +0 -144
  291. package/src/utils/ast-utils.ts +0 -270
  292. package/src/utils/bash.ts +0 -57
  293. package/src/utils/clack-utils.ts +0 -1536
  294. package/src/utils/debug.ts +0 -20
  295. package/src/utils/package-json.ts +0 -51
  296. package/src/utils/package-manager.ts +0 -172
  297. package/src/utils/release-registry.ts +0 -19
  298. package/src/utils/semver.ts +0 -33
  299. package/src/utils/sentrycli-utils.ts +0 -24
  300. package/src/utils/string.ts +0 -7
  301. package/src/utils/types.ts +0 -77
  302. package/src/utils/url.ts +0 -27
  303. package/src/utils/vendor/is-unicorn-supported.ts +0 -29
  304. package/test/android/code-tools.test.ts +0 -49
  305. package/test/apple/cocoapod.test.ts +0 -310
  306. package/test/apple/code-tools.test.ts +0 -1042
  307. package/test/apple/fastfile.test.ts +0 -555
  308. package/test/apple/templates.test.ts +0 -191
  309. package/test/apple/xcode-manager.test.ts +0 -1068
  310. package/test/flutter/code-tools.test.ts +0 -212
  311. package/test/flutter/templates.test.ts +0 -100
  312. package/test/nextjs/templates.test.ts +0 -429
  313. package/test/nuxt/templates.test.ts +0 -255
  314. package/test/react-native/expo-metro.test.ts +0 -81
  315. package/test/react-native/expo.test.ts +0 -86
  316. package/test/react-native/gradle.test.ts +0 -310
  317. package/test/react-native/javascript.test.ts +0 -134
  318. package/test/react-native/metro.test.ts +0 -396
  319. package/test/react-native/xcode.test.ts +0 -401
  320. package/test/remix/client-entry.test.ts +0 -122
  321. package/test/remix/server-instrumentation.test.ts +0 -36
  322. package/test/sourcemaps/tools/sentry-cli.test.ts +0 -57
  323. package/test/sourcemaps/tools/tsc.test.ts +0 -181
  324. package/test/sourcemaps/tools/vite.test.ts +0 -149
  325. package/test/sourcemaps/tools/webpack.test.ts +0 -303
  326. package/test/sveltekit/templates.test.ts +0 -152
  327. package/test/utils/ast-utils.test.ts +0 -264
  328. package/test/utils/clack-utils.test.ts +0 -224
  329. package/types/read-env.d.ts +0 -3
  330. package/types/xcode.d.ts +0 -527
@@ -1,1536 +0,0 @@
1
- import * as childProcess from 'node:child_process';
2
- import * as fs from 'node:fs';
3
- import * as os from 'node:os';
4
- import { basename, dirname, isAbsolute, join, relative } from 'node:path';
5
- import { setInterval } from 'node:timers';
6
- import { URL } from 'node:url';
7
- // @ts-ignore - clack is ESM and TS complains about that. It works though
8
- import * as clack from '@clack/prompts';
9
- import * as Sentry from '@sentry/node';
10
- import axios from 'axios';
11
- import chalk from 'chalk';
12
- import opn from 'opn';
13
- import { traceStep } from '../telemetry';
14
- import { debug } from './debug';
15
- import { type PackageDotJson, hasPackageInstalled } from './package-json';
16
- import {
17
- type PackageManager,
18
- detectPackageManger,
19
- packageManagers,
20
- } from './package-manager';
21
- import { fulfillsVersionRange } from './semver';
22
- import type { Feature, SentryProjectData, WizardOptions } from './types';
23
-
24
- export const SENTRY_DOT_ENV_FILE = '.env.sentry-build-plugin';
25
- export const SENTRY_CLI_RC_FILE = '.sentryclirc';
26
- export const SENTRY_PROPERTIES_FILE = 'sentry.properties';
27
-
28
- const SAAS_URL = 'https://sentry.io/';
29
-
30
- const DUMMY_AUTH_TOKEN = '_YOUR_SENTRY_AUTH_TOKEN_';
31
-
32
- interface WizardProjectData {
33
- apiKeys?: {
34
- token?: string;
35
- };
36
- projects?: SentryProjectData[];
37
- }
38
-
39
- export interface CliSetupConfig {
40
- filename: string;
41
- name: string;
42
- gitignore: boolean;
43
-
44
- likelyAlreadyHasAuthToken(contents: string): boolean;
45
- tokenContent(authToken: string): string;
46
-
47
- likelyAlreadyHasOrgAndProject(contents: string): boolean;
48
- orgAndProjContent(org: string, project: string): string;
49
-
50
- likelyAlreadyHasUrl?(contents: string): boolean;
51
- urlContent?(url: string): string;
52
- }
53
-
54
- export interface CliSetupConfigContent {
55
- authToken: string;
56
- org?: string;
57
- project?: string;
58
- url?: string;
59
- }
60
-
61
- export const rcCliSetupConfig: CliSetupConfig = {
62
- filename: SENTRY_CLI_RC_FILE,
63
- name: 'source maps',
64
- gitignore: true,
65
- likelyAlreadyHasAuthToken: function (contents: string): boolean {
66
- return !!(contents.includes('[auth]') && contents.match(/token=./g));
67
- },
68
- tokenContent: function (authToken: string): string {
69
- return `[auth]\ntoken=${authToken}`;
70
- },
71
- likelyAlreadyHasOrgAndProject: function (contents: string): boolean {
72
- return !!(
73
- contents.includes('[defaults]') &&
74
- contents.match(/org=./g) &&
75
- contents.match(/project=./g)
76
- );
77
- },
78
- orgAndProjContent: function (org: string, project: string): string {
79
- return `[defaults]\norg=${org}\nproject=${project}`;
80
- },
81
- };
82
-
83
- export const propertiesCliSetupConfig: Required<CliSetupConfig> = {
84
- filename: SENTRY_PROPERTIES_FILE,
85
- gitignore: true,
86
- name: 'debug files',
87
- likelyAlreadyHasAuthToken(contents: string): boolean {
88
- return !!contents.match(/auth\.token=./g);
89
- },
90
- tokenContent(authToken: string): string {
91
- return `auth.token=${authToken}`;
92
- },
93
- likelyAlreadyHasOrgAndProject(contents: string): boolean {
94
- return !!(
95
- contents.match(/defaults\.org=./g) &&
96
- contents.match(/defaults\.project=./g)
97
- );
98
- },
99
- orgAndProjContent(org: string, project: string): string {
100
- return `defaults.org=${org}\ndefaults.project=${project}`;
101
- },
102
- likelyAlreadyHasUrl(contents: string): boolean {
103
- return !!contents.match(/defaults\.url=./g);
104
- },
105
- urlContent(url: string): string {
106
- return `defaults.url=${url}`;
107
- },
108
- };
109
-
110
- export async function abort(message?: string, status?: number): Promise<never> {
111
- clack.outro(message ?? 'Wizard setup cancelled.');
112
- const sentryHub = Sentry.getCurrentHub();
113
- const sentryTransaction = sentryHub.getScope().getTransaction();
114
- sentryTransaction?.setStatus('aborted');
115
- sentryTransaction?.finish();
116
- const sentrySession = sentryHub.getScope().getSession();
117
- if (sentrySession) {
118
- sentrySession.status = status === 0 ? 'abnormal' : 'crashed';
119
- sentryHub.captureSession(true);
120
- }
121
- await Sentry.flush(3000);
122
- return process.exit(status ?? 1);
123
- }
124
-
125
- export async function abortIfCancelled<T>(
126
- input: T | Promise<T>,
127
- ): Promise<Exclude<T, symbol>> {
128
- if (clack.isCancel(await input)) {
129
- clack.cancel('Wizard setup cancelled.');
130
- const sentryHub = Sentry.getCurrentHub();
131
- const sentryTransaction = sentryHub.getScope().getTransaction();
132
- sentryTransaction?.setStatus('cancelled');
133
- sentryTransaction?.finish();
134
- sentryHub.captureSession(true);
135
- await Sentry.flush(3000);
136
- process.exit(0);
137
- } else {
138
- return input as Exclude<T, symbol>;
139
- }
140
- }
141
-
142
- type PackageJSON = { version?: string };
143
-
144
- export function printWelcome(options: {
145
- wizardName: string;
146
- promoCode?: string;
147
- message?: string;
148
- telemetryEnabled?: boolean;
149
- }): void {
150
- let wizardVersion = process.env.npm_package_version;
151
- if (!wizardVersion) {
152
- try {
153
- wizardVersion = (
154
- JSON.parse(
155
- fs.readFileSync(
156
- join(
157
- dirname(require.resolve('@sentry/wizard')),
158
- '..',
159
- 'package.json',
160
- ),
161
- 'utf-8',
162
- ),
163
- ) as PackageJSON
164
- ).version;
165
- } catch {
166
- // We don't need to have this
167
- }
168
- }
169
-
170
- // eslint-disable-next-line no-console
171
- console.log('');
172
- clack.intro(chalk.inverse(` ${options.wizardName} `));
173
-
174
- let welcomeText =
175
- options.message ||
176
- `The ${options.wizardName} will help you set up Sentry for your application.\nThank you for using Sentry :)`;
177
-
178
- if (options.promoCode) {
179
- welcomeText = `${welcomeText}\n\nUsing promo-code: ${options.promoCode}`;
180
- }
181
-
182
- if (wizardVersion) {
183
- welcomeText = `${welcomeText}\n\nVersion: ${wizardVersion}`;
184
- }
185
-
186
- if (options.telemetryEnabled) {
187
- welcomeText = `${welcomeText}
188
-
189
- This wizard sends telemetry data and crash reports to Sentry. This helps us improve the Wizard.
190
- You can turn this off at any time by running ${chalk.cyanBright(
191
- 'sentry-wizard --disable-telemetry',
192
- )}.`;
193
- }
194
-
195
- clack.note(welcomeText);
196
- }
197
-
198
- export async function confirmContinueIfNoOrDirtyGitRepo(): Promise<void> {
199
- return traceStep('check-git-status', async () => {
200
- if (!isInGitRepo()) {
201
- const continueWithoutGit = await abortIfCancelled(
202
- clack.confirm({
203
- message:
204
- 'You are not inside a git repository. The wizard will create and update files. Do you want to continue anyway?',
205
- }),
206
- );
207
-
208
- Sentry.setTag('continue-without-git', continueWithoutGit);
209
-
210
- if (!continueWithoutGit) {
211
- await abort(undefined, 0);
212
- }
213
- // return early to avoid checking for uncommitted files
214
- return;
215
- }
216
-
217
- const uncommittedOrUntrackedFiles = getUncommittedOrUntrackedFiles();
218
- if (uncommittedOrUntrackedFiles.length) {
219
- clack.log.warn(
220
- `You have uncommitted or untracked files in your repo:
221
-
222
- ${uncommittedOrUntrackedFiles.join('\n')}
223
-
224
- The wizard will create and update files.`,
225
- );
226
- const continueWithDirtyRepo = await abortIfCancelled(
227
- clack.confirm({
228
- message: 'Do you want to continue anyway?',
229
- }),
230
- );
231
-
232
- Sentry.setTag('continue-with-dirty-repo', continueWithDirtyRepo);
233
-
234
- if (!continueWithDirtyRepo) {
235
- await abort(undefined, 0);
236
- }
237
- }
238
- });
239
- }
240
-
241
- export function isInGitRepo() {
242
- try {
243
- childProcess.execSync('git rev-parse --is-inside-work-tree', {
244
- stdio: 'ignore',
245
- });
246
- return true;
247
- } catch {
248
- return false;
249
- }
250
- }
251
-
252
- export function getUncommittedOrUntrackedFiles(): string[] {
253
- try {
254
- const gitStatus = childProcess
255
- .execSync('git status --porcelain=v1', {
256
- // we only care about stdout
257
- stdio: ['ignore', 'pipe', 'ignore'],
258
- })
259
- .toString();
260
-
261
- const files = gitStatus
262
- .split(os.EOL)
263
- .map((line) => line.trim())
264
- .filter(Boolean)
265
- .map((f) => `- ${f.split(/\s+/)[1]}`);
266
-
267
- return files;
268
- } catch {
269
- return [];
270
- }
271
- }
272
-
273
- export async function askToInstallSentryCLI(): Promise<boolean> {
274
- return await abortIfCancelled(
275
- clack.confirm({
276
- message:
277
- "You don't have Sentry CLI installed. Do you want to install it?",
278
- }),
279
- );
280
- }
281
-
282
- export async function askForItemSelection(
283
- items: string[],
284
- message: string,
285
- ): Promise<{ value: string; index: number }> {
286
- const selection: { value: string; index: number } | symbol =
287
- await abortIfCancelled(
288
- clack.select({
289
- maxItems: 12,
290
- message: message,
291
- options: items.map((item, index) => {
292
- return {
293
- value: { value: item, index: index },
294
- label: item,
295
- };
296
- }),
297
- }),
298
- );
299
-
300
- return selection;
301
- }
302
-
303
- export async function confirmContinueIfPackageVersionNotSupported({
304
- packageId,
305
- packageName,
306
- packageVersion,
307
- acceptableVersions,
308
- note,
309
- }: {
310
- packageId: string;
311
- packageName: string;
312
- packageVersion: string;
313
- acceptableVersions: string;
314
- note?: string;
315
- }): Promise<void> {
316
- return traceStep(`check-package-version`, async () => {
317
- Sentry.setTag(`${packageName.toLowerCase()}-version`, packageVersion);
318
- const isSupportedVersion = fulfillsVersionRange({
319
- acceptableVersions,
320
- version: packageVersion,
321
- canBeLatest: true,
322
- });
323
-
324
- if (isSupportedVersion) {
325
- Sentry.setTag(`${packageName.toLowerCase()}-supported`, true);
326
- return;
327
- }
328
-
329
- clack.log.warn(
330
- `You have an unsupported version of ${packageName} installed:
331
-
332
- ${packageId}@${packageVersion}`,
333
- );
334
-
335
- clack.note(
336
- note ??
337
- `Please upgrade to ${acceptableVersions} if you wish to use the Sentry Wizard.`,
338
- );
339
- const continueWithUnsupportedVersion = await abortIfCancelled(
340
- clack.confirm({
341
- message: 'Do you want to continue anyway?',
342
- }),
343
- );
344
- Sentry.setTag(
345
- `${packageName.toLowerCase()}-continue-with-unsupported-version`,
346
- continueWithUnsupportedVersion,
347
- );
348
-
349
- if (!continueWithUnsupportedVersion) {
350
- await abort(undefined, 0);
351
- }
352
- });
353
- }
354
-
355
- /**
356
- * Installs or updates a package with the user's package manager.
357
- *
358
- * IMPORTANT: This function modifies the `package.json`! Be sure to re-read
359
- * it if you make additional modifications to it after calling this function!
360
- */
361
- export async function installPackage({
362
- packageName,
363
- alreadyInstalled,
364
- askBeforeUpdating = true,
365
- packageNameDisplayLabel,
366
- packageManager,
367
- forceInstall = false,
368
- }: {
369
- /** The string that is passed to the package manager CLI as identifier to install (e.g. `@sentry/nextjs`, or `@sentry/nextjs@^8`) */
370
- packageName: string;
371
- alreadyInstalled: boolean;
372
- askBeforeUpdating?: boolean;
373
- /** Overrides what is shown in the installation logs in place of the `packageName` option. Useful if the `packageName` is ugly (e.g. `@sentry/nextjs@^8`) */
374
- packageNameDisplayLabel?: string;
375
- packageManager?: PackageManager;
376
- /** Add force install flag to command to skip install precondition fails */
377
- forceInstall?: boolean;
378
- }): Promise<{ packageManager?: PackageManager }> {
379
- return traceStep('install-package', async () => {
380
- if (alreadyInstalled && askBeforeUpdating) {
381
- const shouldUpdatePackage = await abortIfCancelled(
382
- clack.confirm({
383
- message: `The ${chalk.bold.cyan(
384
- packageNameDisplayLabel ?? packageName,
385
- )} package is already installed. Do you want to update it to the latest version?`,
386
- }),
387
- );
388
-
389
- if (!shouldUpdatePackage) {
390
- return {};
391
- }
392
- }
393
-
394
- const sdkInstallSpinner = clack.spinner();
395
-
396
- const pkgManager = packageManager || (await getPackageManager());
397
-
398
- sdkInstallSpinner.start(
399
- `${alreadyInstalled ? 'Updating' : 'Installing'} ${chalk.bold.cyan(
400
- packageNameDisplayLabel ?? packageName,
401
- )} with ${chalk.bold(pkgManager.label)}.`,
402
- );
403
-
404
- try {
405
- await new Promise<void>((resolve, reject) => {
406
- childProcess.exec(
407
- `${pkgManager.installCommand} ${packageName} ${pkgManager.flags} ${
408
- forceInstall ? pkgManager.forceInstallFlag : ''
409
- }`,
410
- (err, stdout, stderr) => {
411
- if (err) {
412
- // Write a log file so we can better troubleshoot issues
413
- fs.writeFileSync(
414
- join(
415
- process.cwd(),
416
- `sentry-wizard-installation-error-${Date.now()}.log`,
417
- ),
418
- JSON.stringify({
419
- stdout,
420
- stderr,
421
- }),
422
- { encoding: 'utf8' },
423
- );
424
-
425
- reject(err);
426
- } else {
427
- resolve();
428
- }
429
- },
430
- );
431
- });
432
- } catch (e) {
433
- sdkInstallSpinner.stop('Installation failed.');
434
- clack.log.error(
435
- `${chalk.red(
436
- 'Encountered the following error during installation:',
437
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
438
- )}\n\n${e}\n\n${chalk.dim(
439
- "The wizard has created a `sentry-wizard-installation-error-*.log` file. If you think this issue is caused by the Sentry wizard, create an issue on GitHub and include the log file's content:\nhttps://github.com/getsentry/sentry-wizard/issues",
440
- )}`,
441
- );
442
- await abort();
443
- }
444
-
445
- sdkInstallSpinner.stop(
446
- `${alreadyInstalled ? 'Updated' : 'Installed'} ${chalk.bold.cyan(
447
- packageNameDisplayLabel ?? packageName,
448
- )} with ${chalk.bold(pkgManager.label)}.`,
449
- );
450
-
451
- return { packageManager: pkgManager };
452
- });
453
- }
454
-
455
- export async function addSentryCliConfig(
456
- { authToken, org, project, url }: CliSetupConfigContent,
457
- setupConfig: CliSetupConfig = rcCliSetupConfig,
458
- ): Promise<void> {
459
- return traceStep('add-sentry-cli-config', async () => {
460
- const configPath = join(process.cwd(), setupConfig.filename);
461
- const configExists = fs.existsSync(configPath);
462
-
463
- let configContents =
464
- (configExists && fs.readFileSync(configPath, 'utf8')) || '';
465
- configContents = addAuthTokenToSentryConfig(
466
- configContents,
467
- authToken,
468
- setupConfig,
469
- );
470
- configContents = addOrgAndProjectToSentryConfig(
471
- configContents,
472
- org,
473
- project,
474
- setupConfig,
475
- );
476
- configContents = addUrlToSentryConfig(configContents, url, setupConfig);
477
-
478
- try {
479
- await fs.promises.writeFile(configPath, configContents, {
480
- encoding: 'utf8',
481
- flag: 'w',
482
- });
483
- clack.log.success(
484
- `${configExists ? 'Saved' : 'Created'} ${chalk.cyan(
485
- setupConfig.filename,
486
- )}.`,
487
- );
488
- } catch {
489
- clack.log.warning(
490
- `Failed to add auth token to ${chalk.cyan(
491
- setupConfig.filename,
492
- )}. Uploading ${
493
- setupConfig.name
494
- } during build will likely not work locally.`,
495
- );
496
- }
497
-
498
- if (setupConfig.gitignore) {
499
- await addCliConfigFileToGitIgnore(setupConfig.filename);
500
- } else {
501
- clack.log.warn(
502
- chalk.yellow('DO NOT commit auth token to your repository!'),
503
- );
504
- }
505
- });
506
- }
507
-
508
- function addAuthTokenToSentryConfig(
509
- configContents: string,
510
- authToken: string | undefined,
511
- setupConfig: CliSetupConfig,
512
- ): string {
513
- if (!authToken) {
514
- return configContents;
515
- }
516
-
517
- if (setupConfig.likelyAlreadyHasAuthToken(configContents)) {
518
- clack.log.warn(
519
- `${chalk.cyan(
520
- setupConfig.filename,
521
- )} already has auth token. Will not add one.`,
522
- );
523
- return configContents;
524
- }
525
-
526
- const newContents = `${configContents}\n${setupConfig.tokenContent(
527
- authToken,
528
- )}\n`;
529
- clack.log.success(
530
- `Added auth token to ${chalk.cyan(
531
- setupConfig.filename,
532
- )} for you to test uploading ${setupConfig.name} locally.`,
533
- );
534
- return newContents;
535
- }
536
-
537
- function addOrgAndProjectToSentryConfig(
538
- configContents: string,
539
- org: string | undefined,
540
- project: string | undefined,
541
- setupConfig: CliSetupConfig,
542
- ): string {
543
- if (!org || !project) {
544
- return configContents;
545
- }
546
-
547
- if (setupConfig.likelyAlreadyHasOrgAndProject(configContents)) {
548
- clack.log.warn(
549
- `${chalk.cyan(
550
- setupConfig.filename,
551
- )} already has org and project. Will not add them.`,
552
- );
553
- return configContents;
554
- }
555
-
556
- const newContents = `${configContents}\n${setupConfig.orgAndProjContent(
557
- org,
558
- project,
559
- )}\n`;
560
- clack.log.success(
561
- `Added default org and project to ${chalk.cyan(
562
- setupConfig.filename,
563
- )} for you to test uploading ${setupConfig.name} locally.`,
564
- );
565
- return newContents;
566
- }
567
-
568
- function addUrlToSentryConfig(
569
- configContents: string,
570
- url: string | undefined,
571
- setupConfig: CliSetupConfig,
572
- ): string {
573
- if (!url || !setupConfig.urlContent || !setupConfig.likelyAlreadyHasUrl) {
574
- return configContents;
575
- }
576
-
577
- if (setupConfig.likelyAlreadyHasUrl(configContents)) {
578
- clack.log.warn(
579
- `${chalk.cyan(setupConfig.filename)} already has url. Will not add one.`,
580
- );
581
- return configContents;
582
- }
583
-
584
- const newContents = `${configContents}\n${setupConfig.urlContent(url)}\n`;
585
- clack.log.success(
586
- `Added default url to ${chalk.cyan(
587
- setupConfig.filename,
588
- )} for you to test uploading ${setupConfig.name} locally.`,
589
- );
590
- return newContents;
591
- }
592
-
593
- export async function addDotEnvSentryBuildPluginFile(
594
- authToken: string,
595
- ): Promise<void> {
596
- const envVarContent = `# DO NOT commit this file to your repository!
597
- # The SENTRY_AUTH_TOKEN variable is picked up by the Sentry Build Plugin.
598
- # It's used for authentication when uploading source maps.
599
- # You can also set this env variable in your own \`.env\` files and remove this file.
600
- SENTRY_AUTH_TOKEN=${authToken}
601
- `;
602
-
603
- const dotEnvFilePath = join(process.cwd(), SENTRY_DOT_ENV_FILE);
604
- const dotEnvFileExists = fs.existsSync(dotEnvFilePath);
605
-
606
- if (dotEnvFileExists) {
607
- const dotEnvFileContent = fs.readFileSync(dotEnvFilePath, 'utf8');
608
-
609
- const hasAuthToken = !!dotEnvFileContent.match(
610
- /^\s*SENTRY_AUTH_TOKEN\s*=/g,
611
- );
612
-
613
- if (hasAuthToken) {
614
- clack.log.warn(
615
- `${chalk.bold.cyan(
616
- SENTRY_DOT_ENV_FILE,
617
- )} already has auth token. Will not add one.`,
618
- );
619
- } else {
620
- try {
621
- await fs.promises.writeFile(
622
- dotEnvFilePath,
623
- `${dotEnvFileContent}\n${envVarContent}`,
624
- {
625
- encoding: 'utf8',
626
- flag: 'w',
627
- },
628
- );
629
- clack.log.success(
630
- `Added auth token to ${chalk.bold.cyan(SENTRY_DOT_ENV_FILE)}`,
631
- );
632
- } catch {
633
- clack.log.warning(
634
- `Failed to add auth token to ${chalk.bold.cyan(
635
- SENTRY_DOT_ENV_FILE,
636
- )}. Uploading source maps during build will likely not work locally.`,
637
- );
638
- }
639
- }
640
- } else {
641
- try {
642
- await fs.promises.writeFile(dotEnvFilePath, envVarContent, {
643
- encoding: 'utf8',
644
- flag: 'w',
645
- });
646
- clack.log.success(
647
- `Created ${chalk.bold.cyan(
648
- SENTRY_DOT_ENV_FILE,
649
- )} with auth token for you to test source map uploading locally.`,
650
- );
651
- } catch {
652
- clack.log.warning(
653
- `Failed to create ${chalk.bold.cyan(
654
- SENTRY_DOT_ENV_FILE,
655
- )} with auth token. Uploading source maps during build will likely not work locally.`,
656
- );
657
- }
658
- }
659
-
660
- await addCliConfigFileToGitIgnore(SENTRY_DOT_ENV_FILE);
661
- }
662
-
663
- async function addCliConfigFileToGitIgnore(filename: string): Promise<void> {
664
- const gitignorePath = join(process.cwd(), '.gitignore');
665
-
666
- try {
667
- const gitignoreContent = await fs.promises.readFile(gitignorePath, 'utf8');
668
- if (gitignoreContent.split(/\r?\n/).includes(filename)) {
669
- clack.log.info(
670
- `${chalk.bold('.gitignore')} already has ${chalk.bold(
671
- filename,
672
- )}. Will not add it again.`,
673
- );
674
- return;
675
- }
676
-
677
- await fs.promises.appendFile(
678
- gitignorePath,
679
- `\n# Sentry Config File\n${filename}\n`,
680
- { encoding: 'utf8' },
681
- );
682
- clack.log.success(
683
- `Added ${chalk.cyan(filename)} to ${chalk.cyan('.gitignore')}.`,
684
- );
685
- } catch {
686
- clack.log.error(
687
- `Failed adding ${chalk.cyan(filename)} to ${chalk.cyan(
688
- '.gitignore',
689
- )}. Please add it manually!`,
690
- );
691
- }
692
- }
693
-
694
- export async function runPrettierIfInstalled(): Promise<void> {
695
- return traceStep('run-prettier', async () => {
696
- if (!isInGitRepo()) {
697
- // We only run formatting on changed files. If we're not in a git repo, we can't find
698
- // changed files. So let's early-return without showing any formatting-related messages.
699
- return;
700
- }
701
-
702
- const changedOrUntrackedFiles = getUncommittedOrUntrackedFiles()
703
- .map((filename) => {
704
- return filename.startsWith('- ') ? filename.slice(2) : filename;
705
- })
706
- .join(' ');
707
-
708
- if (!changedOrUntrackedFiles.length) {
709
- // Likewise, if we can't find changed or untracked files, there's no point in running Prettier.
710
- return;
711
- }
712
-
713
- const packageJson = await getPackageDotJson();
714
- const prettierInstalled = hasPackageInstalled('prettier', packageJson);
715
-
716
- Sentry.setTag('prettier-installed', prettierInstalled);
717
-
718
- if (!prettierInstalled) {
719
- return;
720
- }
721
-
722
- // prompt the user if they want to run prettier
723
- const shouldRunPrettier = await abortIfCancelled(
724
- clack.confirm({
725
- message:
726
- 'Looks like you have Prettier in your project. Do you want to run it on your files?',
727
- }),
728
- );
729
-
730
- if (!shouldRunPrettier) {
731
- return;
732
- }
733
-
734
- const prettierSpinner = clack.spinner();
735
- prettierSpinner.start('Running Prettier on your files.');
736
-
737
- try {
738
- await new Promise<void>((resolve, reject) => {
739
- childProcess.exec(
740
- `npx prettier --ignore-unknown --write ${changedOrUntrackedFiles}`,
741
- (err) => {
742
- if (err) {
743
- reject(err);
744
- } else {
745
- resolve();
746
- }
747
- },
748
- );
749
- });
750
- } catch (e) {
751
- prettierSpinner.stop('Prettier failed to run.');
752
- clack.log.warn(
753
- 'Prettier failed to run. There may be formatting issues in your updated files.',
754
- );
755
- return;
756
- }
757
-
758
- prettierSpinner.stop('Prettier has formatted your files.');
759
- });
760
- }
761
-
762
- /**
763
- * Checks if @param packageId is listed as a dependency in @param packageJson.
764
- * If not, it will ask users if they want to continue without the package.
765
- *
766
- * Use this function to check if e.g. a the framework of the SDK is installed
767
- *
768
- * @param packageJson the package.json object
769
- * @param packageId the npm name of the package
770
- * @param packageName a human readable name of the package
771
- */
772
- export async function ensurePackageIsInstalled(
773
- packageJson: PackageDotJson,
774
- packageId: string,
775
- packageName: string,
776
- ): Promise<void> {
777
- return traceStep('ensure-package-installed', async () => {
778
- const installed = hasPackageInstalled(packageId, packageJson);
779
-
780
- Sentry.setTag(`${packageName.toLowerCase()}-installed`, installed);
781
-
782
- if (!installed) {
783
- Sentry.setTag(`${packageName.toLowerCase()}-installed`, false);
784
- const continueWithoutPackage = await abortIfCancelled(
785
- clack.confirm({
786
- message: `${packageName} does not seem to be installed. Do you still want to continue?`,
787
- initialValue: false,
788
- }),
789
- );
790
-
791
- if (!continueWithoutPackage) {
792
- await abort(undefined, 0);
793
- }
794
- }
795
- });
796
- }
797
-
798
- export async function getPackageDotJson(): Promise<PackageDotJson> {
799
- const packageJsonFileContents = await fs.promises
800
- .readFile(join(process.cwd(), 'package.json'), 'utf8')
801
- .catch(() => {
802
- clack.log.error(
803
- 'Could not find package.json. Make sure to run the wizard in the root of your app!',
804
- );
805
- return abort();
806
- });
807
-
808
- let packageJson: PackageDotJson | undefined = undefined;
809
-
810
- try {
811
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
812
- packageJson = JSON.parse(packageJsonFileContents);
813
- } catch {
814
- clack.log.error(
815
- `Unable to parse your ${chalk.cyan(
816
- 'package.json',
817
- )}. Make sure it has a valid format!`,
818
- );
819
-
820
- await abort();
821
- }
822
-
823
- return packageJson || {};
824
- }
825
-
826
- export async function updatePackageDotJson(
827
- packageDotJson: PackageDotJson,
828
- ): Promise<void> {
829
- try {
830
- await fs.promises.writeFile(
831
- join(process.cwd(), 'package.json'),
832
- // TODO: maybe figure out the original indentation
833
- JSON.stringify(packageDotJson, null, 2),
834
- {
835
- encoding: 'utf8',
836
- flag: 'w',
837
- },
838
- );
839
- } catch {
840
- clack.log.error(`Unable to update your ${chalk.cyan('package.json')}.`);
841
-
842
- await abort();
843
- }
844
- }
845
-
846
- export async function getPackageManager(): Promise<PackageManager> {
847
- const detectedPackageManager = detectPackageManger();
848
-
849
- if (detectedPackageManager) {
850
- return detectedPackageManager;
851
- }
852
-
853
- const selectedPackageManager: PackageManager | symbol =
854
- await abortIfCancelled(
855
- clack.select({
856
- message: 'Please select your package manager.',
857
- options: packageManagers.map((packageManager) => ({
858
- value: packageManager,
859
- label: packageManager.label,
860
- })),
861
- }),
862
- );
863
-
864
- Sentry.setTag('package-manager', selectedPackageManager.name);
865
-
866
- return selectedPackageManager;
867
- }
868
-
869
- export function isUsingTypeScript() {
870
- try {
871
- return fs.existsSync(join(process.cwd(), 'tsconfig.json'));
872
- } catch {
873
- return false;
874
- }
875
- }
876
-
877
- /**
878
- * Checks if we already got project data from a previous wizard invocation.
879
- * If yes, this data is returned.
880
- * Otherwise, we start the login flow and ask the user to select a project.
881
- *
882
- * Use this function to get project data for the wizard.
883
- *
884
- * @param options wizard options
885
- * @param platform the platform of the wizard
886
- * @returns project data (org, project, token, url)
887
- */
888
- export async function getOrAskForProjectData(
889
- options: WizardOptions,
890
- platform?:
891
- | 'javascript-nextjs'
892
- | 'javascript-nuxt'
893
- | 'javascript-remix'
894
- | 'javascript-sveltekit'
895
- | 'apple-ios'
896
- | 'android'
897
- | 'react-native'
898
- | 'flutter',
899
- ): Promise<{
900
- sentryUrl: string;
901
- selfHosted: boolean;
902
- selectedProject: SentryProjectData;
903
- authToken: string;
904
- }> {
905
- if (options.preSelectedProject) {
906
- return {
907
- selfHosted: options.preSelectedProject.selfHosted,
908
- sentryUrl: options.url ?? SAAS_URL,
909
- authToken: options.preSelectedProject.authToken,
910
- selectedProject: options.preSelectedProject.project,
911
- };
912
- }
913
- const { url: sentryUrl, selfHosted } = await traceStep(
914
- 'ask-self-hosted',
915
- () => askForSelfHosted(options.url, options.saas),
916
- );
917
-
918
- const { projects, apiKeys } = await traceStep('login', () =>
919
- askForWizardLogin({
920
- promoCode: options.promoCode,
921
- url: sentryUrl,
922
- platform: platform,
923
- orgSlug: options.orgSlug,
924
- projectSlug: options.projectSlug,
925
- }),
926
- );
927
-
928
- if (!projects || !projects.length) {
929
- clack.log.error(
930
- 'No projects found. Please create a project in Sentry and try again.',
931
- );
932
- Sentry.setTag('no-projects-found', true);
933
- await abort();
934
- // This rejection won't return due to the abort call but TS doesn't know that
935
- return Promise.reject();
936
- }
937
-
938
- const selectedProject = await traceStep('select-project', () =>
939
- askForProjectSelection(projects, options.orgSlug, options.projectSlug),
940
- );
941
-
942
- const { token } = apiKeys ?? {};
943
-
944
- if (!token) {
945
- clack.log.error(`Didn't receive an auth token. This shouldn't happen :(
946
-
947
- Please let us know if you think this is a bug in the wizard:
948
- ${chalk.cyan('https://github.com/getsentry/sentry-wizard/issues')}`);
949
-
950
- clack.log.info(`In the meantime, we'll add a dummy auth token (${chalk.cyan(
951
- `"${DUMMY_AUTH_TOKEN}"`,
952
- )}) for you to replace later.
953
- Create your auth token here:
954
- ${chalk.cyan(
955
- selfHosted
956
- ? `${sentryUrl}organizations/${selectedProject.organization.slug}/settings/auth-tokens`
957
- : `https://${selectedProject.organization.slug}.sentry.io/settings/auth-tokens`,
958
- )}`);
959
- }
960
-
961
- return {
962
- sentryUrl,
963
- selfHosted,
964
- authToken: apiKeys?.token || DUMMY_AUTH_TOKEN,
965
- selectedProject,
966
- };
967
- }
968
-
969
- /**
970
- * Asks users if they are using SaaS or self-hosted Sentry and returns the validated URL.
971
- *
972
- * If users started the wizard with a --url arg, that URL is used as the default and we skip
973
- * the self-hosted question. However, the passed url is still validated and in case it's
974
- * invalid, users are asked to enter a new one until it is valid.
975
- *
976
- * @param urlFromArgs the url passed via the --url arg
977
- */
978
- async function askForSelfHosted(
979
- urlFromArgs?: string,
980
- saas?: boolean,
981
- ): Promise<{
982
- url: string;
983
- selfHosted: boolean;
984
- }> {
985
- if (saas) {
986
- Sentry.setTag('url', SAAS_URL);
987
- Sentry.setTag('self-hosted', false);
988
- return { url: SAAS_URL, selfHosted: false };
989
- }
990
-
991
- if (!urlFromArgs) {
992
- const choice: 'saas' | 'self-hosted' | symbol = await abortIfCancelled(
993
- clack.select({
994
- message: 'Are you using Sentry SaaS or self-hosted Sentry?',
995
- options: [
996
- { value: 'saas', label: 'Sentry SaaS (sentry.io)' },
997
- {
998
- value: 'self-hosted',
999
- label: 'Self-hosted/on-premise/single-tenant',
1000
- },
1001
- ],
1002
- }),
1003
- );
1004
-
1005
- if (choice === 'saas') {
1006
- Sentry.setTag('url', SAAS_URL);
1007
- Sentry.setTag('self-hosted', false);
1008
- return { url: SAAS_URL, selfHosted: false };
1009
- }
1010
- }
1011
-
1012
- let validUrl: string | undefined;
1013
- let tmpUrlFromArgs = urlFromArgs;
1014
-
1015
- while (validUrl === undefined) {
1016
- const url =
1017
- tmpUrlFromArgs ||
1018
- (await abortIfCancelled(
1019
- clack.text({
1020
- message: `Please enter the URL of your ${
1021
- urlFromArgs ? '' : 'self-hosted '
1022
- }Sentry instance.`,
1023
- placeholder: 'https://sentry.io/',
1024
- }),
1025
- ));
1026
- tmpUrlFromArgs = undefined;
1027
-
1028
- try {
1029
- validUrl = new URL(url).toString();
1030
-
1031
- // We assume everywhere else that the URL ends in a slash
1032
- if (!validUrl.endsWith('/')) {
1033
- validUrl += '/';
1034
- }
1035
- } catch {
1036
- clack.log.error(
1037
- `Please enter a valid URL. (It should look something like "https://sentry.mydomain.com/", got ${url})`,
1038
- );
1039
- }
1040
- }
1041
-
1042
- const isSelfHostedUrl = new URL(validUrl).host !== new URL(SAAS_URL).host;
1043
-
1044
- Sentry.setTag('url', validUrl);
1045
- Sentry.setTag('self-hosted', isSelfHostedUrl);
1046
-
1047
- return { url: validUrl, selfHosted: true };
1048
- }
1049
-
1050
- async function askForWizardLogin(options: {
1051
- url: string;
1052
- promoCode?: string;
1053
- platform?:
1054
- | 'javascript-nextjs'
1055
- | 'javascript-nuxt'
1056
- | 'javascript-remix'
1057
- | 'javascript-sveltekit'
1058
- | 'apple-ios'
1059
- | 'android'
1060
- | 'react-native'
1061
- | 'flutter';
1062
- orgSlug?: string;
1063
- projectSlug?: string;
1064
- }): Promise<WizardProjectData> {
1065
- Sentry.setTag('has-promo-code', !!options.promoCode);
1066
-
1067
- let hasSentryAccount = await clack.confirm({
1068
- message: 'Do you already have a Sentry account?',
1069
- });
1070
-
1071
- hasSentryAccount = await abortIfCancelled(hasSentryAccount);
1072
-
1073
- Sentry.setTag('already-has-sentry-account', hasSentryAccount);
1074
-
1075
- let wizardHash: string;
1076
- try {
1077
- wizardHash = (
1078
- await axios.get<{ hash: string }>(`${options.url}api/0/wizard/`)
1079
- ).data.hash;
1080
- } catch (e: unknown) {
1081
- if (options.url !== SAAS_URL) {
1082
- clack.log.error('Loading Wizard failed. Did you provide the right URL?');
1083
- clack.log.info(JSON.stringify(e, null, 2));
1084
- await abort(
1085
- chalk.red(
1086
- 'Please check your configuration and try again.\n\n Let us know if you think this is an issue with the wizard or Sentry: https://github.com/getsentry/sentry-wizard/issues',
1087
- ),
1088
- );
1089
- } else {
1090
- clack.log.error('Loading Wizard failed.');
1091
- clack.log.info(JSON.stringify(e, null, 2));
1092
- await abort(
1093
- chalk.red(
1094
- 'Please try again in a few minutes and let us know if this issue persists: https://github.com/getsentry/sentry-wizard/issues',
1095
- ),
1096
- );
1097
- }
1098
- }
1099
-
1100
- const loginUrl = new URL(
1101
- `${options.url}account/settings/wizard/${wizardHash!}/`,
1102
- );
1103
-
1104
- if (options.orgSlug) {
1105
- loginUrl.searchParams.set('org_slug', options.orgSlug);
1106
- }
1107
-
1108
- if (options.projectSlug) {
1109
- loginUrl.searchParams.set('project_slug', options.projectSlug);
1110
- }
1111
-
1112
- if (!hasSentryAccount) {
1113
- loginUrl.searchParams.set('signup', '1');
1114
- }
1115
-
1116
- if (options.platform) {
1117
- loginUrl.searchParams.set('project_platform', options.platform);
1118
- }
1119
-
1120
- if (options.promoCode) {
1121
- loginUrl.searchParams.set('code', options.promoCode);
1122
- }
1123
-
1124
- const urlToOpen = loginUrl.toString();
1125
- clack.log.info(
1126
- `${chalk.bold(
1127
- `If the browser window didn't open automatically, please open the following link to ${
1128
- hasSentryAccount ? 'log' : 'sign'
1129
- } into Sentry:`,
1130
- )}\n\n${chalk.cyan(urlToOpen)}`,
1131
- );
1132
-
1133
- // opn throws in environments that don't have a browser (e.g. remote shells) so we just noop here
1134
- const noop = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function
1135
- opn(urlToOpen, { wait: false }).then((cp) => cp.on('error', noop), noop);
1136
-
1137
- const loginSpinner = clack.spinner();
1138
-
1139
- loginSpinner.start('Waiting for you to log in using the link above');
1140
-
1141
- const data = await new Promise<WizardProjectData>((resolve) => {
1142
- const pollingInterval = setInterval(() => {
1143
- axios
1144
- .get<WizardProjectData>(`${options.url}api/0/wizard/${wizardHash}/`, {
1145
- headers: {
1146
- 'Accept-Encoding': 'deflate',
1147
- },
1148
- })
1149
- .then((result) => {
1150
- resolve(result.data);
1151
- clearTimeout(timeout);
1152
- clearInterval(pollingInterval);
1153
- void axios.delete(`${options.url}api/0/wizard/${wizardHash}/`);
1154
- })
1155
- .catch(() => {
1156
- // noop - just try again
1157
- });
1158
- }, 500);
1159
-
1160
- const timeout = setTimeout(() => {
1161
- clearInterval(pollingInterval);
1162
- loginSpinner.stop(
1163
- 'Login timed out. No worries - it happens to the best of us.',
1164
- );
1165
-
1166
- Sentry.setTag('opened-wizard-link', false);
1167
- void abort('Please restart the Wizard and log in to complete the setup.');
1168
- }, 180_000);
1169
- });
1170
-
1171
- loginSpinner.stop('Login complete.');
1172
- Sentry.setTag('opened-wizard-link', true);
1173
-
1174
- return data;
1175
- }
1176
-
1177
- async function askForProjectSelection(
1178
- projects: SentryProjectData[],
1179
- orgSlug?: string,
1180
- projectSlug?: string,
1181
- ): Promise<SentryProjectData> {
1182
- const label = (project: SentryProjectData): string => {
1183
- return `${project.organization.slug}/${project.slug}`;
1184
- };
1185
-
1186
- const filteredProjects = filterProjectsBySlugs(
1187
- projects,
1188
- orgSlug,
1189
- projectSlug,
1190
- );
1191
-
1192
- if (filteredProjects.length === 1) {
1193
- const selection = filteredProjects[0];
1194
-
1195
- Sentry.setTag('project', selection.slug);
1196
- Sentry.setUser({ id: selection.organization.slug });
1197
- clack.log.step(`Selected project ${label(selection)}`);
1198
-
1199
- return selection;
1200
- }
1201
-
1202
- if (filteredProjects.length === 0) {
1203
- clack.log.warn('Could not find a project with the provided slugs.');
1204
- }
1205
-
1206
- const sortedProjects = filteredProjects.length ? filteredProjects : projects;
1207
- sortedProjects.sort((a: SentryProjectData, b: SentryProjectData) => {
1208
- return label(a).localeCompare(label(b));
1209
- });
1210
-
1211
- const selection: SentryProjectData | symbol = await abortIfCancelled(
1212
- clack.select({
1213
- maxItems: 12,
1214
- message: 'Select your Sentry project.',
1215
- options: sortedProjects.map((project) => {
1216
- return {
1217
- value: project,
1218
- label: label(project),
1219
- };
1220
- }),
1221
- }),
1222
- );
1223
-
1224
- Sentry.setTag('project', selection.slug);
1225
- Sentry.setUser({ id: selection.organization.slug });
1226
-
1227
- return selection;
1228
- }
1229
-
1230
- function filterProjectsBySlugs(
1231
- projects: SentryProjectData[],
1232
- orgSlug?: string,
1233
- projectSlug?: string,
1234
- ): SentryProjectData[] {
1235
- if (!orgSlug && !projectSlug) {
1236
- return projects;
1237
- }
1238
- if (orgSlug && !projectSlug) {
1239
- return projects.filter((p) => p.organization.slug === orgSlug);
1240
- }
1241
- if (!orgSlug && projectSlug) {
1242
- return projects.filter((p) => p.slug === projectSlug);
1243
- }
1244
-
1245
- return projects.filter(
1246
- (p) => p.organization.slug === orgSlug && p.slug === projectSlug,
1247
- );
1248
- }
1249
-
1250
- /**
1251
- * Asks users if they have a config file for @param tool (e.g. Vite).
1252
- * If yes, asks users to specify the path to their config file.
1253
- *
1254
- * Use this helper function as a fallback mechanism if the lookup for
1255
- * a config file with its most usual location/name fails.
1256
- *
1257
- * @param toolName Name of the tool for which we're looking for the config file
1258
- * @param configFileName Name of the most common config file name (e.g. vite.config.js)
1259
- *
1260
- * @returns a user path to the config file or undefined if the user doesn't have a config file
1261
- */
1262
- export async function askForToolConfigPath(
1263
- toolName: string,
1264
- configFileName: string,
1265
- ): Promise<string | undefined> {
1266
- const hasConfig = await abortIfCancelled(
1267
- clack.confirm({
1268
- message: `Do you have a ${toolName} config file (e.g. ${chalk.cyan(
1269
- configFileName,
1270
- )})?`,
1271
- initialValue: true,
1272
- }),
1273
- );
1274
-
1275
- if (!hasConfig) {
1276
- return undefined;
1277
- }
1278
-
1279
- return await abortIfCancelled(
1280
- clack.text({
1281
- message: `Please enter the path to your ${toolName} config file:`,
1282
- placeholder: join('.', configFileName),
1283
- validate: (value) => {
1284
- if (!value) {
1285
- return 'Please enter a path.';
1286
- }
1287
-
1288
- try {
1289
- fs.accessSync(value);
1290
- } catch {
1291
- return 'Could not access the file at this path.';
1292
- }
1293
- },
1294
- }),
1295
- );
1296
- }
1297
-
1298
- /**
1299
- * Prints copy/paste-able instructions to the console.
1300
- * Afterwards asks the user if they added the code snippet to their file.
1301
- *
1302
- * While there's no point in providing a "no" answer here, it gives users time to fulfill the
1303
- * task before the wizard continues with additional steps.
1304
- *
1305
- * Use this function if you want to show users instructions on how to add/modify
1306
- * code in their file. This is helpful if automatic insertion failed or is not possible/feasible.
1307
- *
1308
- * @param filename the name of the file to which the code snippet should be applied.
1309
- * If a path is provided, only the filename will be used.
1310
- *
1311
- * @param codeSnippet the snippet to be printed. Use {@link makeCodeSnippet} to create the
1312
- * diff-like format for visually highlighting unchanged or modified lines of code.
1313
- *
1314
- * @param hint (optional) a hint to be printed after the main instruction to add
1315
- * the code from @param codeSnippet to their @param filename.
1316
- *
1317
- * More guidelines on copy/paste instructions:
1318
- * @see {@link https://develop.sentry.dev/sdk/setup-wizards/#copy--paste-snippets}
1319
- *
1320
- * TODO: refactor copy paste instructions across different wizards to use this function.
1321
- * this might require adding a custom message parameter to the function
1322
- */
1323
- export async function showCopyPasteInstructions(
1324
- filename: string,
1325
- codeSnippet: string,
1326
- hint?: string,
1327
- ): Promise<void> {
1328
- clack.log.step(
1329
- `Add the following code to your ${chalk.cyan(basename(filename))} file:${
1330
- hint ? chalk.dim(` (${chalk.dim(hint)})`) : ''
1331
- }`,
1332
- );
1333
-
1334
- // Padding the code snippet to be printed with a \n at the beginning and end
1335
- // This makes it easier to distinguish the snippet from the rest of the output
1336
- // Intentionally logging directly to console here so that the code can be copied/pasted directly
1337
- // eslint-disable-next-line no-console
1338
- console.log(`\n${codeSnippet}\n`);
1339
-
1340
- await abortIfCancelled(
1341
- clack.select({
1342
- message: 'Did you apply the snippet above?',
1343
- options: [{ label: 'Yes, continue!', value: true }],
1344
- initialValue: true,
1345
- }),
1346
- );
1347
- }
1348
-
1349
- /**
1350
- * Callback that exposes formatting helpers for a code snippet.
1351
- * @param unchanged - Formats text as old code.
1352
- * @param plus - Formats text as new code.
1353
- * @param minus - Formats text as removed code.
1354
- */
1355
- type CodeSnippetFormatter = (
1356
- unchanged: (txt: string) => string,
1357
- plus: (txt: string) => string,
1358
- minus: (txt: string) => string,
1359
- ) => string;
1360
-
1361
- /**
1362
- * Crafts a code snippet that can be used to e.g.
1363
- * - print copy/paste instructions to the console
1364
- * - create a new config file.
1365
- *
1366
- * @param colors set this to true if you want the final snippet to be colored.
1367
- * This is useful for printing the snippet to the console as part of copy/paste instructions.
1368
- *
1369
- * @param callback the callback that returns the formatted code snippet.
1370
- * It exposes takes the helper functions for marking code as unchanged, new or removed.
1371
- * These functions no-op if no special formatting should be applied
1372
- * and otherwise apply the appropriate formatting/coloring.
1373
- * (@see {@link CodeSnippetFormatter})
1374
- *
1375
- * @see {@link showCopyPasteInstructions} for the helper with which to display the snippet in the console.
1376
- *
1377
- * @returns a string containing the final, formatted code snippet.
1378
- */
1379
- export function makeCodeSnippet(
1380
- colors: boolean,
1381
- callback: CodeSnippetFormatter,
1382
- ): string {
1383
- const unchanged = (txt: string) => (colors ? chalk.grey(txt) : txt);
1384
- const plus = (txt: string) => (colors ? chalk.greenBright(txt) : txt);
1385
- const minus = (txt: string) => (colors ? chalk.redBright(txt) : txt);
1386
-
1387
- return callback(unchanged, plus, minus);
1388
- }
1389
-
1390
- /**
1391
- * Creates a new config file with the given @param filepath and @param codeSnippet.
1392
- *
1393
- * Use this function to create a new config file for users. This is useful
1394
- * when users answered that they don't yet have a config file for a tool.
1395
- *
1396
- * (This doesn't mean that they don't yet have some other way of configuring
1397
- * their tool but we can leave it up to them to figure out how to merge configs
1398
- * here.)
1399
- *
1400
- * @param filepath absolute path to the new config file
1401
- * @param codeSnippet the snippet to be inserted into the file
1402
- * @param moreInformation (optional) the message to be printed after the file was created
1403
- * For example, this can be a link to more information about configuring the tool.
1404
- *
1405
- * @returns true on success, false otherwise
1406
- */
1407
- export async function createNewConfigFile(
1408
- filepath: string,
1409
- codeSnippet: string,
1410
- moreInformation?: string,
1411
- ): Promise<boolean> {
1412
- if (!isAbsolute(filepath)) {
1413
- debug(`createNewConfigFile: filepath is not absolute: ${filepath}`);
1414
- return false;
1415
- }
1416
-
1417
- const prettyFilename = chalk.cyan(relative(process.cwd(), filepath));
1418
-
1419
- try {
1420
- await fs.promises.writeFile(filepath, codeSnippet);
1421
-
1422
- clack.log.success(`Added new ${prettyFilename} file.`);
1423
-
1424
- if (moreInformation) {
1425
- clack.log.info(chalk.gray(moreInformation));
1426
- }
1427
-
1428
- return true;
1429
- } catch (e) {
1430
- debug(e);
1431
- clack.log.warn(
1432
- `Could not create a new ${prettyFilename} file. Please create one manually and follow the instructions below.`,
1433
- );
1434
- }
1435
-
1436
- return false;
1437
- }
1438
-
1439
- export async function askShouldCreateExamplePage(
1440
- customRoute?: string,
1441
- ): Promise<boolean> {
1442
- const route = chalk.cyan(customRoute ?? '/sentry-example-page');
1443
- return traceStep('ask-create-example-page', () =>
1444
- abortIfCancelled(
1445
- clack.select({
1446
- message: `Do you want to create an example page ("${route}") to test your Sentry setup?`,
1447
- options: [
1448
- {
1449
- value: true,
1450
- label: 'Yes',
1451
- hint: 'Recommended - Check your git status before committing!',
1452
- },
1453
- { value: false, label: 'No' },
1454
- ],
1455
- }),
1456
- ),
1457
- );
1458
- }
1459
-
1460
- export async function askShouldCreateExampleComponent(): Promise<boolean> {
1461
- return traceStep('ask-create-example-component', () =>
1462
- abortIfCancelled(
1463
- clack.select({
1464
- message: `Do you want to create an example component to test your Sentry setup?`,
1465
- options: [
1466
- {
1467
- value: true,
1468
- label: 'Yes',
1469
- hint: 'Recommended - Check your git status before committing!',
1470
- },
1471
- { value: false, label: 'No' },
1472
- ],
1473
- }),
1474
- ),
1475
- );
1476
- }
1477
-
1478
- export async function featureSelectionPrompt<F extends ReadonlyArray<Feature>>(
1479
- features: F,
1480
- ): Promise<{ [key in F[number]['id']]: boolean }> {
1481
- return traceStep('feature-selection', async () => {
1482
- const selectedFeatures: Record<string, boolean> = {};
1483
-
1484
- for (const feature of features) {
1485
- const selected = await abortIfCancelled(
1486
- clack.select({
1487
- message: feature.prompt,
1488
- initialValue: true,
1489
- options: [
1490
- {
1491
- value: true,
1492
- label: 'Yes',
1493
- hint: feature.enabledHint,
1494
- },
1495
- {
1496
- value: false,
1497
- label: 'No',
1498
- hint: feature.disabledHint,
1499
- },
1500
- ],
1501
- }),
1502
- );
1503
-
1504
- selectedFeatures[feature.id] = selected;
1505
- }
1506
-
1507
- return selectedFeatures as { [key in F[number]['id']]: boolean };
1508
- });
1509
- }
1510
-
1511
- export async function askShouldInstallPackage(
1512
- pkgName: string,
1513
- ): Promise<boolean> {
1514
- return traceStep(`ask-install-package`, () =>
1515
- abortIfCancelled(
1516
- clack.confirm({
1517
- message: `Do you want to install ${chalk.cyan(pkgName)}?`,
1518
- }),
1519
- ),
1520
- );
1521
- }
1522
-
1523
- export async function askShouldAddPackageOverride(
1524
- pkgName: string,
1525
- pkgVersion: string,
1526
- ): Promise<boolean> {
1527
- return traceStep(`ask-add-package-override`, () =>
1528
- abortIfCancelled(
1529
- clack.confirm({
1530
- message: `Do you want to add an override for ${chalk.cyan(
1531
- pkgName,
1532
- )} version ${chalk.cyan(pkgVersion)}?`,
1533
- }),
1534
- ),
1535
- );
1536
- }