@sentry/wizard 4.5.0 → 4.7.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 (293) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +23 -19
  3. package/dist/bin.js +22 -0
  4. package/dist/bin.js.map +1 -1
  5. package/dist/e2e-tests/tests/flutter.test.js +16 -16
  6. package/dist/e2e-tests/tests/flutter.test.js.map +1 -1
  7. package/dist/e2e-tests/tests/help-message.test.js +56 -0
  8. package/dist/e2e-tests/tests/help-message.test.js.map +1 -0
  9. package/dist/e2e-tests/tests/nextjs-14.test.js +17 -16
  10. package/dist/e2e-tests/tests/nextjs-14.test.js.map +1 -1
  11. package/dist/e2e-tests/tests/nextjs-15.test.js +16 -16
  12. package/dist/e2e-tests/tests/nextjs-15.test.js.map +1 -1
  13. package/dist/e2e-tests/tests/nuxt-3.test.js +13 -12
  14. package/dist/e2e-tests/tests/nuxt-3.test.js.map +1 -1
  15. package/dist/e2e-tests/tests/nuxt-4.test.js +13 -12
  16. package/dist/e2e-tests/tests/nuxt-4.test.js.map +1 -1
  17. package/dist/e2e-tests/tests/remix.test.js +20 -20
  18. package/dist/e2e-tests/tests/remix.test.js.map +1 -1
  19. package/dist/e2e-tests/tests/sveltekit.test.js +20 -20
  20. package/dist/e2e-tests/tests/sveltekit.test.js.map +1 -1
  21. package/dist/e2e-tests/utils/index.d.ts +1 -1
  22. package/dist/e2e-tests/utils/index.js +35 -13
  23. package/dist/e2e-tests/utils/index.js.map +1 -1
  24. package/dist/lib/Constants.d.ts +7 -1
  25. package/dist/lib/Constants.js.map +1 -1
  26. package/dist/lib/Helper/File.d.ts +1 -1
  27. package/dist/lib/Helper/File.js +1 -3
  28. package/dist/lib/Helper/File.js.map +1 -1
  29. package/dist/lib/Helper/Logging.d.ts +4 -1
  30. package/dist/lib/Helper/Logging.js +3 -0
  31. package/dist/lib/Helper/Logging.js.map +1 -1
  32. package/dist/lib/Helper/Package.d.ts +5 -3
  33. package/dist/lib/Helper/Package.js +2 -2
  34. package/dist/lib/Helper/Package.js.map +1 -1
  35. package/dist/lib/Helper/SentryCli.d.ts +20 -7
  36. package/dist/lib/Helper/SentryCli.js +21 -13
  37. package/dist/lib/Helper/SentryCli.js.map +1 -1
  38. package/dist/lib/Helper/Wizard.js +9 -5
  39. package/dist/lib/Helper/Wizard.js.map +1 -1
  40. package/dist/lib/Helper/__tests__/File.js +9 -9
  41. package/dist/lib/Helper/__tests__/File.js.map +1 -1
  42. package/dist/lib/Helper/__tests__/MergeConfig.js +17 -17
  43. package/dist/lib/Helper/__tests__/MergeConfig.js.map +1 -1
  44. package/dist/lib/Helper/__tests__/SentryCli.js +39 -21
  45. package/dist/lib/Helper/__tests__/SentryCli.js.map +1 -1
  46. package/dist/lib/Setup.d.ts +4 -1
  47. package/dist/lib/Setup.js +12 -2
  48. package/dist/lib/Setup.js.map +1 -1
  49. package/dist/lib/Steps/BaseStep.d.ts +1 -1
  50. package/dist/lib/Steps/BaseStep.js.map +1 -1
  51. package/dist/lib/Steps/Integrations/BaseIntegration.js +1 -2
  52. package/dist/lib/Steps/Integrations/BaseIntegration.js.map +1 -1
  53. package/dist/lib/Steps/Integrations/Cordova.js +14 -10
  54. package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
  55. package/dist/lib/Steps/Integrations/Electron.d.ts +4 -1
  56. package/dist/lib/Steps/Integrations/Electron.js +1 -1
  57. package/dist/lib/Steps/Integrations/Electron.js.map +1 -1
  58. package/dist/lib/Steps/Integrations/MobileProject.d.ts +3 -1
  59. package/dist/lib/Steps/Integrations/MobileProject.js +1 -1
  60. package/dist/lib/Steps/Integrations/MobileProject.js.map +1 -1
  61. package/dist/lib/Steps/PromptForParameters.d.ts +4 -1
  62. package/dist/lib/Steps/PromptForParameters.js.map +1 -1
  63. package/dist/lib/Steps/SentryProjectSelector.d.ts +42 -1
  64. package/dist/lib/Steps/SentryProjectSelector.js +1 -1
  65. package/dist/lib/Steps/SentryProjectSelector.js.map +1 -1
  66. package/dist/lib/Steps/WaitForSentry.d.ts +3 -1
  67. package/dist/lib/Steps/WaitForSentry.js +4 -4
  68. package/dist/lib/Steps/WaitForSentry.js.map +1 -1
  69. package/dist/lib/Steps/Welcome.js +5 -0
  70. package/dist/lib/Steps/Welcome.js.map +1 -1
  71. package/dist/lib/Types.d.ts +14 -0
  72. package/dist/lib/Types.js +3 -0
  73. package/dist/lib/Types.js.map +1 -0
  74. package/dist/lib/__tests__/Env.js +10 -16
  75. package/dist/lib/__tests__/Env.js.map +1 -1
  76. package/dist/src/android/android-wizard.js +15 -12
  77. package/dist/src/android/android-wizard.js.map +1 -1
  78. package/dist/src/android/code-tools.js +1 -1
  79. package/dist/src/android/code-tools.js.map +1 -1
  80. package/dist/src/android/gradle.js +4 -4
  81. package/dist/src/android/gradle.js.map +1 -1
  82. package/dist/src/android/manifest.js +1 -1
  83. package/dist/src/android/manifest.js.map +1 -1
  84. package/dist/src/apple/apple-wizard.d.ts +2 -2
  85. package/dist/src/apple/apple-wizard.js +54 -175
  86. package/dist/src/apple/apple-wizard.js.map +1 -1
  87. package/dist/src/apple/check-installed-cli.d.ts +1 -0
  88. package/dist/src/apple/check-installed-cli.js +60 -0
  89. package/dist/src/apple/check-installed-cli.js.map +1 -0
  90. package/dist/src/apple/cocoapod.js +1 -1
  91. package/dist/src/apple/cocoapod.js.map +1 -1
  92. package/dist/src/apple/code-tools.js +1 -1
  93. package/dist/src/apple/code-tools.js.map +1 -1
  94. package/dist/src/apple/configure-fastlane.d.ts +5 -0
  95. package/dist/src/apple/configure-fastlane.js +66 -0
  96. package/dist/src/apple/configure-fastlane.js.map +1 -0
  97. package/dist/src/apple/configure-package-manager.d.ts +5 -0
  98. package/dist/src/apple/configure-package-manager.js +68 -0
  99. package/dist/src/apple/configure-package-manager.js.map +1 -0
  100. package/dist/src/apple/configure-sentry-cli.d.ts +4 -0
  101. package/dist/src/apple/configure-sentry-cli.js +47 -0
  102. package/dist/src/apple/configure-sentry-cli.js.map +1 -0
  103. package/dist/src/apple/configure-xcode-project.d.ts +8 -0
  104. package/dist/src/apple/configure-xcode-project.js +11 -0
  105. package/dist/src/apple/configure-xcode-project.js.map +1 -0
  106. package/dist/src/apple/fastlane.d.ts +1 -1
  107. package/dist/src/apple/fastlane.js +5 -5
  108. package/dist/src/apple/fastlane.js.map +1 -1
  109. package/dist/src/apple/inject-code-snippet.d.ts +6 -0
  110. package/dist/src/apple/inject-code-snippet.js +54 -0
  111. package/dist/src/apple/inject-code-snippet.js.map +1 -0
  112. package/dist/src/apple/lookup-xcode-project.d.ts +7 -0
  113. package/dist/src/apple/lookup-xcode-project.js +98 -0
  114. package/dist/src/apple/lookup-xcode-project.js.map +1 -0
  115. package/dist/src/apple/options.d.ts +4 -0
  116. package/dist/src/apple/options.js +3 -0
  117. package/dist/src/apple/options.js.map +1 -0
  118. package/dist/src/apple/search-xcode-project-at-path.d.ts +1 -0
  119. package/dist/src/apple/search-xcode-project-at-path.js +70 -0
  120. package/dist/src/apple/search-xcode-project-at-path.js.map +1 -0
  121. package/dist/src/apple/templates.js +11 -7
  122. package/dist/src/apple/templates.js.map +1 -1
  123. package/dist/src/apple/xcode-manager.js +4 -7
  124. package/dist/src/apple/xcode-manager.js.map +1 -1
  125. package/dist/src/flutter/code-tools.js +3 -3
  126. package/dist/src/flutter/code-tools.js.map +1 -1
  127. package/dist/src/flutter/flutter-wizard.js +21 -15
  128. package/dist/src/flutter/flutter-wizard.js.map +1 -1
  129. package/dist/src/flutter/templates.js +4 -4
  130. package/dist/src/flutter/templates.js.map +1 -1
  131. package/dist/src/nextjs/nextjs-wizard.js +118 -43
  132. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  133. package/dist/src/nextjs/templates.d.ts +10 -1
  134. package/dist/src/nextjs/templates.js +192 -62
  135. package/dist/src/nextjs/templates.js.map +1 -1
  136. package/dist/src/nuxt/nuxt-wizard.js +21 -16
  137. package/dist/src/nuxt/nuxt-wizard.js.map +1 -1
  138. package/dist/src/nuxt/sdk-example.js +3 -3
  139. package/dist/src/nuxt/sdk-example.js.map +1 -1
  140. package/dist/src/nuxt/sdk-setup.js +9 -9
  141. package/dist/src/nuxt/sdk-setup.js.map +1 -1
  142. package/dist/src/nuxt/templates.js +173 -58
  143. package/dist/src/nuxt/templates.js.map +1 -1
  144. package/dist/src/nuxt/utils.js +6 -3
  145. package/dist/src/nuxt/utils.js.map +1 -1
  146. package/dist/src/react-native/expo-env-file.js +1 -1
  147. package/dist/src/react-native/expo-env-file.js.map +1 -1
  148. package/dist/src/react-native/expo-metro.js +4 -4
  149. package/dist/src/react-native/expo-metro.js.map +1 -1
  150. package/dist/src/react-native/expo.js +4 -4
  151. package/dist/src/react-native/expo.js.map +1 -1
  152. package/dist/src/react-native/javascript.d.ts +6 -4
  153. package/dist/src/react-native/javascript.js +31 -15
  154. package/dist/src/react-native/javascript.js.map +1 -1
  155. package/dist/src/react-native/metro.js +8 -8
  156. package/dist/src/react-native/metro.js.map +1 -1
  157. package/dist/src/react-native/react-native-wizard.d.ts +5 -1
  158. package/dist/src/react-native/react-native-wizard.js +66 -36
  159. package/dist/src/react-native/react-native-wizard.js.map +1 -1
  160. package/dist/src/react-native/uninstall.js +8 -5
  161. package/dist/src/react-native/uninstall.js.map +1 -1
  162. package/dist/src/react-native/xcode.d.ts +9 -4
  163. package/dist/src/react-native/xcode.js +65 -22
  164. package/dist/src/react-native/xcode.js.map +1 -1
  165. package/dist/src/remix/codemods/handle-error.js +4 -1
  166. package/dist/src/remix/codemods/handle-error.js.map +1 -1
  167. package/dist/src/remix/remix-wizard.js +23 -18
  168. package/dist/src/remix/remix-wizard.js.map +1 -1
  169. package/dist/src/remix/sdk-example.js +163 -64
  170. package/dist/src/remix/sdk-example.js.map +1 -1
  171. package/dist/src/remix/sdk-setup.js +11 -7
  172. package/dist/src/remix/sdk-setup.js.map +1 -1
  173. package/dist/src/run.d.ts +3 -1
  174. package/dist/src/run.js +29 -9
  175. package/dist/src/run.js.map +1 -1
  176. package/dist/src/sourcemaps/sourcemaps-wizard.js +30 -28
  177. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  178. package/dist/src/sourcemaps/tools/angular.js +3 -3
  179. package/dist/src/sourcemaps/tools/angular.js.map +1 -1
  180. package/dist/src/sourcemaps/tools/create-react-app.js +3 -3
  181. package/dist/src/sourcemaps/tools/create-react-app.js.map +1 -1
  182. package/dist/src/sourcemaps/tools/esbuild.js +6 -6
  183. package/dist/src/sourcemaps/tools/esbuild.js.map +1 -1
  184. package/dist/src/sourcemaps/tools/nextjs.js +5 -5
  185. package/dist/src/sourcemaps/tools/nextjs.js.map +1 -1
  186. package/dist/src/sourcemaps/tools/remix.js +4 -4
  187. package/dist/src/sourcemaps/tools/remix.js.map +1 -1
  188. package/dist/src/sourcemaps/tools/rollup.js +6 -6
  189. package/dist/src/sourcemaps/tools/rollup.js.map +1 -1
  190. package/dist/src/sourcemaps/tools/sentry-cli.js +15 -15
  191. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  192. package/dist/src/sourcemaps/tools/tsc.js +6 -6
  193. package/dist/src/sourcemaps/tools/tsc.js.map +1 -1
  194. package/dist/src/sourcemaps/tools/vite.js +12 -12
  195. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  196. package/dist/src/sourcemaps/tools/webpack.js +10 -10
  197. package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
  198. package/dist/src/sourcemaps/utils/detect-tool.js +2 -2
  199. package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
  200. package/dist/src/sourcemaps/utils/other-wizards.js +5 -5
  201. package/dist/src/sourcemaps/utils/other-wizards.js.map +1 -1
  202. package/dist/src/sourcemaps/utils/sdk-version.js +7 -7
  203. package/dist/src/sourcemaps/utils/sdk-version.js.map +1 -1
  204. package/dist/src/sveltekit/sdk-example.js +1 -1
  205. package/dist/src/sveltekit/sdk-example.js.map +1 -1
  206. package/dist/src/sveltekit/sdk-setup.js +15 -14
  207. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  208. package/dist/src/sveltekit/sveltekit-wizard.js +25 -20
  209. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  210. package/dist/src/sveltekit/templates.js +126 -37
  211. package/dist/src/sveltekit/templates.js.map +1 -1
  212. package/dist/src/telemetry.js +11 -0
  213. package/dist/src/telemetry.js.map +1 -1
  214. package/dist/src/utils/{clack-utils.d.ts → clack/index.d.ts} +45 -7
  215. package/dist/src/utils/{clack-utils.js → clack/index.js} +75 -20
  216. package/dist/src/utils/clack/index.js.map +1 -0
  217. package/dist/src/utils/debug.js +1 -1
  218. package/dist/src/utils/debug.js.map +1 -1
  219. package/dist/src/utils/find-files-with-extension.d.ts +1 -0
  220. package/dist/src/utils/find-files-with-extension.js +39 -0
  221. package/dist/src/utils/find-files-with-extension.js.map +1 -0
  222. package/dist/src/utils/package-manager.d.ts +8 -1
  223. package/dist/src/utils/package-manager.js +79 -23
  224. package/dist/src/utils/package-manager.js.map +1 -1
  225. package/dist/src/utils/sentrycli-utils.js +0 -1
  226. package/dist/src/utils/sentrycli-utils.js.map +1 -1
  227. package/dist/src/utils/types.d.ts +4 -0
  228. package/dist/src/utils/types.js.map +1 -1
  229. package/dist/src/version.d.ts +1 -1
  230. package/dist/src/version.js +1 -1
  231. package/dist/src/version.js.map +1 -1
  232. package/dist/test/android/code-tools.test.js +13 -13
  233. package/dist/test/android/code-tools.test.js.map +1 -1
  234. package/dist/test/apple/cocoapod.test.js +78 -73
  235. package/dist/test/apple/cocoapod.test.js.map +1 -1
  236. package/dist/test/apple/code-tools.test.js +174 -167
  237. package/dist/test/apple/code-tools.test.js.map +1 -1
  238. package/dist/test/apple/fastfile.test.js +87 -84
  239. package/dist/test/apple/fastfile.test.js.map +1 -1
  240. package/dist/test/apple/templates.test.js +32 -27
  241. package/dist/test/apple/templates.test.js.map +1 -1
  242. package/dist/test/apple/xcode-manager.test.js +208 -185
  243. package/dist/test/apple/xcode-manager.test.js.map +1 -1
  244. package/dist/test/flutter/code-tools.test.js +29 -30
  245. package/dist/test/flutter/code-tools.test.js.map +1 -1
  246. package/dist/test/flutter/templates.test.js +38 -37
  247. package/dist/test/flutter/templates.test.js.map +1 -1
  248. package/dist/test/nextjs/templates.test.js +155 -103
  249. package/dist/test/nextjs/templates.test.js.map +1 -1
  250. package/dist/test/nuxt/templates.test.js +25 -24
  251. package/dist/test/nuxt/templates.test.js.map +1 -1
  252. package/dist/test/react-native/expo-metro.test.js +12 -11
  253. package/dist/test/react-native/expo-metro.test.js.map +1 -1
  254. package/dist/test/react-native/expo.test.js +11 -10
  255. package/dist/test/react-native/expo.test.js.map +1 -1
  256. package/dist/test/react-native/gradle.test.js +27 -26
  257. package/dist/test/react-native/gradle.test.js.map +1 -1
  258. package/dist/test/react-native/javascript.test.js +109 -59
  259. package/dist/test/react-native/javascript.test.js.map +1 -1
  260. package/dist/test/react-native/metro.test.js +66 -65
  261. package/dist/test/react-native/metro.test.js.map +1 -1
  262. package/dist/test/react-native/xcode.test.js +138 -37
  263. package/dist/test/react-native/xcode.test.js.map +1 -1
  264. package/dist/test/remix/client-entry.test.js +8 -7
  265. package/dist/test/remix/client-entry.test.js.map +1 -1
  266. package/dist/test/remix/server-instrumentation.test.js +6 -5
  267. package/dist/test/remix/server-instrumentation.test.js.map +1 -1
  268. package/dist/test/sourcemaps/tools/sentry-cli.test.js +21 -21
  269. package/dist/test/sourcemaps/tools/sentry-cli.test.js.map +1 -1
  270. package/dist/test/sourcemaps/tools/tsc.test.js +13 -14
  271. package/dist/test/sourcemaps/tools/tsc.test.js.map +1 -1
  272. package/dist/test/sourcemaps/tools/vite.test.js +13 -14
  273. package/dist/test/sourcemaps/tools/vite.test.js.map +1 -1
  274. package/dist/test/sourcemaps/tools/webpack.test.js +19 -20
  275. package/dist/test/sourcemaps/tools/webpack.test.js.map +1 -1
  276. package/dist/test/sveltekit/templates.test.js +13 -12
  277. package/dist/test/sveltekit/templates.test.js.map +1 -1
  278. package/dist/test/utils/ast-utils.test.js +45 -44
  279. package/dist/test/utils/ast-utils.test.js.map +1 -1
  280. package/dist/test/utils/clack/index.test.d.ts +1 -0
  281. package/dist/test/utils/clack/index.test.js +375 -0
  282. package/dist/test/utils/clack/index.test.js.map +1 -0
  283. package/dist/test/utils/package-manager.test.d.ts +1 -0
  284. package/dist/test/utils/package-manager.test.js +30 -0
  285. package/dist/test/utils/package-manager.test.js.map +1 -0
  286. package/package.json +10 -38
  287. package/dist/e2e-tests/jest.config.d.ts +0 -17
  288. package/dist/e2e-tests/jest.config.js +0 -23
  289. package/dist/e2e-tests/jest.config.js.map +0 -1
  290. package/dist/src/utils/clack-utils.js.map +0 -1
  291. package/dist/test/utils/clack-utils.test.js +0 -306
  292. package/dist/test/utils/clack-utils.test.js.map +0 -1
  293. /package/dist/{test/utils/clack-utils.test.d.ts → e2e-tests/tests/help-message.test.d.ts} +0 -0
@@ -27,28 +27,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.addSentryCommandToBuildCommand = exports.setupNpmScriptInCI = exports.configureSentryCLI = void 0;
30
- // @ts-ignore - clack is ESM and TS complains about that. It works though
30
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
31
31
  const clack = __importStar(require("@clack/prompts"));
32
32
  const chalk_1 = __importDefault(require("chalk"));
33
33
  const Sentry = __importStar(require("@sentry/node"));
34
34
  const path = __importStar(require("path"));
35
35
  const fs = __importStar(require("fs"));
36
- const clack_utils_1 = require("../../utils/clack-utils");
36
+ const clack_1 = require("../../utils/clack");
37
37
  const package_json_1 = require("../../utils/package-json");
38
38
  const telemetry_1 = require("../../telemetry");
39
39
  const package_manager_1 = require("../../utils/package-manager");
40
40
  const SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';
41
41
  let addedToBuildCommand = false;
42
42
  async function configureSentryCLI(options, configureSourcemapGenerationFlow = defaultConfigureSourcemapGenerationFlow) {
43
- const packageDotJson = await (0, clack_utils_1.getPackageDotJson)();
44
- await (0, clack_utils_1.installPackage)({
43
+ const packageDotJson = await (0, clack_1.getPackageDotJson)();
44
+ await (0, clack_1.installPackage)({
45
45
  packageName: '@sentry/cli',
46
46
  alreadyInstalled: (0, package_json_1.hasPackageInstalled)('@sentry/cli', packageDotJson),
47
47
  });
48
48
  let validPath = false;
49
49
  let relativeArtifactPath;
50
50
  do {
51
- const rawArtifactPath = await (0, clack_utils_1.abortIfCancelled)(clack.text({
51
+ const rawArtifactPath = await (0, clack_1.abortIfCancelled)(clack.text({
52
52
  message: 'Where are your build artifacts located?',
53
53
  placeholder: `.${path.sep}out`,
54
54
  validate(value) {
@@ -68,7 +68,7 @@ async function configureSentryCLI(options, configureSourcemapGenerationFlow = de
68
68
  validPath = true;
69
69
  }
70
70
  catch {
71
- validPath = await (0, clack_utils_1.abortIfCancelled)(clack.select({
71
+ validPath = await (0, clack_1.abortIfCancelled)(clack.select({
72
72
  message: `We couldn't find artifacts at ${relativeArtifactPath}. Are you sure that this is the location that contains your build artifacts?`,
73
73
  options: [
74
74
  {
@@ -92,7 +92,7 @@ async function configureSentryCLI(options, configureSourcemapGenerationFlow = de
92
92
  else {
93
93
  clack.log.info(`No problem, just make sure to run this script ${chalk_1.default.bold('after')} building your application but ${chalk_1.default.bold('before')} deploying!`);
94
94
  }
95
- await (0, clack_utils_1.addSentryCliConfig)({ authToken: options.authToken });
95
+ await (0, clack_1.addSentryCliConfig)({ authToken: options.authToken });
96
96
  }
97
97
  exports.configureSentryCLI = configureSentryCLI;
98
98
  async function setupNpmScriptInCI() {
@@ -101,7 +101,7 @@ async function setupNpmScriptInCI() {
101
101
  // if the script is already added to the build command
102
102
  return;
103
103
  }
104
- const addedToCI = await (0, clack_utils_1.abortIfCancelled)(clack.select({
104
+ const addedToCI = await (0, clack_1.abortIfCancelled)(clack.select({
105
105
  message: `Add a step to your CI pipeline that runs the ${chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME)} script ${chalk_1.default.bold('right after')} building your application.`,
106
106
  options: [
107
107
  { label: 'I did, continue!', value: true },
@@ -121,14 +121,14 @@ async function setupNpmScriptInCI() {
121
121
  exports.setupNpmScriptInCI = setupNpmScriptInCI;
122
122
  async function createAndAddNpmScript(options, relativePosixArtifactPath) {
123
123
  const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${options.orgSlug} --project ${options.projectSlug} ${relativePosixArtifactPath} && sentry-cli${options.selfHosted ? ` --url ${options.url}` : ''} sourcemaps upload --org ${options.orgSlug} --project ${options.projectSlug} ${relativePosixArtifactPath}`;
124
- const packageDotJson = await (0, clack_utils_1.getPackageDotJson)();
124
+ const packageDotJson = await (0, clack_1.getPackageDotJson)();
125
125
  packageDotJson.scripts = packageDotJson.scripts || {};
126
126
  packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;
127
127
  await fs.promises.writeFile(path.join(process.cwd(), 'package.json'), JSON.stringify(packageDotJson, null, 2));
128
128
  clack.log.info(`Added a ${chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk_1.default.cyan('package.json')}.`);
129
129
  }
130
130
  async function askShouldAddToBuildCommand() {
131
- const shouldAddToBuildCommand = await (0, clack_utils_1.abortIfCancelled)(clack.select({
131
+ const shouldAddToBuildCommand = await (0, clack_1.abortIfCancelled)(clack.select({
132
132
  message: `Do you want to automatically run the ${chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME)} script after each production build?`,
133
133
  options: [
134
134
  {
@@ -151,12 +151,12 @@ async function askShouldAddToBuildCommand() {
151
151
  * @param packageDotJson The package.json which will be modified.
152
152
  */
153
153
  async function addSentryCommandToBuildCommand() {
154
- const packageDotJson = await (0, clack_utils_1.getPackageDotJson)();
154
+ const packageDotJson = await (0, clack_1.getPackageDotJson)();
155
155
  // This usually shouldn't happen because earlier we added the
156
156
  // SENTRY_NPM_SCRIPT_NAME script but just to be sure
157
157
  packageDotJson.scripts = packageDotJson.scripts || {};
158
158
  const allNpmScripts = Object.keys(packageDotJson.scripts).filter((s) => s !== SENTRY_NPM_SCRIPT_NAME);
159
- const packageManager = (0, package_manager_1.detectPackageManger)() ?? package_manager_1.NPM;
159
+ const packageManager = await (0, clack_1.getPackageManager)(package_manager_1.NPM);
160
160
  // Heuristic to pre-select the build command:
161
161
  // Often, 'build' is the prod build command, so we favour it.
162
162
  // If it's not there, commands that include 'build' might be the prod build command.
@@ -164,11 +164,11 @@ async function addSentryCommandToBuildCommand() {
164
164
  ? 'build'
165
165
  : allNpmScripts.find((s) => s.toLocaleLowerCase().includes('build'));
166
166
  const isProdBuildCommand = !!buildCommand &&
167
- (await (0, clack_utils_1.abortIfCancelled)(clack.confirm({
167
+ (await (0, clack_1.abortIfCancelled)(clack.confirm({
168
168
  message: `Is ${chalk_1.default.cyan(`${packageManager.runScriptCommand} ${buildCommand}`)} your production build command?`,
169
169
  })));
170
170
  if (allNpmScripts.length && (!buildCommand || !isProdBuildCommand)) {
171
- buildCommand = await (0, clack_utils_1.abortIfCancelled)(clack.select({
171
+ buildCommand = await (0, clack_1.abortIfCancelled)(clack.select({
172
172
  message: `Which ${packageManager.name} command in your ${chalk_1.default.cyan('package.json')} builds your application for production?`,
173
173
  options: allNpmScripts
174
174
  .map((script) => ({
@@ -203,7 +203,7 @@ Would have injected: ${chalk_1.default.dim(newCommand)}`);
203
203
  }
204
204
  exports.addSentryCommandToBuildCommand = addSentryCommandToBuildCommand;
205
205
  async function defaultConfigureSourcemapGenerationFlow() {
206
- await (0, clack_utils_1.abortIfCancelled)(clack.select({
206
+ await (0, clack_1.abortIfCancelled)(clack.select({
207
207
  message: `Verify that your build tool is generating source maps. ${chalk_1.default.dim('(Your build output folder should contain .js.map files after a build)')}`,
208
208
  options: [{ label: 'I checked. Continue!', value: true }],
209
209
  initialValue: true,
@@ -1 +1 @@
1
- {"version":3,"file":"sentry-cli.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/sentry-cli.ts"],"names":[],"mappings":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;AACJ,CAAC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport {\n abortIfCancelled,\n addSentryCliConfig,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\n\nimport { SourceMapUploadToolConfigurationOptions } from './types';\nimport { hasPackageInstalled } from '../../utils/package-json';\nimport { traceStep } from '../../telemetry';\nimport { detectPackageManger, NPM } from '../../utils/package-manager';\n\nconst SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';\n\nlet addedToBuildCommand = false;\n\nexport async function configureSentryCLI(\n options: SourceMapUploadToolConfigurationOptions,\n configureSourcemapGenerationFlow: () => Promise<void> = defaultConfigureSourcemapGenerationFlow,\n): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n\n await installPackage({\n packageName: '@sentry/cli',\n alreadyInstalled: hasPackageInstalled('@sentry/cli', packageDotJson),\n });\n\n let validPath = false;\n let relativeArtifactPath;\n do {\n const rawArtifactPath = await abortIfCancelled(\n clack.text({\n message: 'Where are your build artifacts located?',\n placeholder: `.${path.sep}out`,\n validate(value) {\n if (!value) {\n return 'Please enter a path.';\n }\n },\n }),\n );\n\n if (path.isAbsolute(rawArtifactPath)) {\n relativeArtifactPath = path.relative(process.cwd(), rawArtifactPath);\n } else {\n relativeArtifactPath = rawArtifactPath;\n }\n\n try {\n await fs.promises.access(path.join(process.cwd(), relativeArtifactPath));\n validPath = true;\n } catch {\n validPath = await abortIfCancelled(\n clack.select({\n message: `We couldn't find artifacts at ${relativeArtifactPath}. Are you sure that this is the location that contains your build artifacts?`,\n options: [\n {\n label: 'No, let me verify.',\n value: false,\n },\n { label: 'Yes, I am sure!', value: true },\n ],\n initialValue: false,\n }),\n );\n }\n } while (!validPath);\n\n const relativePosixArtifactPath = relativeArtifactPath\n .split(path.sep)\n .join(path.posix.sep);\n\n await configureSourcemapGenerationFlow();\n\n await createAndAddNpmScript(options, relativePosixArtifactPath);\n\n if (await askShouldAddToBuildCommand()) {\n await traceStep('sentry-cli-add-to-build-cmd', () =>\n addSentryCommandToBuildCommand(),\n );\n } else {\n clack.log.info(\n `No problem, just make sure to run this script ${chalk.bold(\n 'after',\n )} building your application but ${chalk.bold('before')} deploying!`,\n );\n }\n\n await addSentryCliConfig({ authToken: options.authToken });\n}\n\nexport async function setupNpmScriptInCI(): Promise<void> {\n if (addedToBuildCommand) {\n // No need to tell users to add it manually to their CI\n // if the script is already added to the build command\n return;\n }\n\n const addedToCI = await abortIfCancelled(\n clack.select({\n message: `Add a step to your CI pipeline that runs the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script ${chalk.bold('right after')} building your application.`,\n options: [\n { label: 'I did, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `You need to run ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} after each build for source maps to work properly.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-ci-script', addedToCI);\n\n if (!addedToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function createAndAddNpmScript(\n options: SourceMapUploadToolConfigurationOptions,\n relativePosixArtifactPath: string,\n): Promise<void> {\n const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${\n options.orgSlug\n } --project ${\n options.projectSlug\n } ${relativePosixArtifactPath} && sentry-cli${\n options.selfHosted ? ` --url ${options.url}` : ''\n } sourcemaps upload --org ${options.orgSlug} --project ${\n options.projectSlug\n } ${relativePosixArtifactPath}`;\n\n const packageDotJson = await getPackageDotJson();\n\n packageDotJson.scripts = packageDotJson.scripts || {};\n packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n clack.log.info(\n `Added a ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\nasync function askShouldAddToBuildCommand(): Promise<boolean> {\n const shouldAddToBuildCommand = await abortIfCancelled(\n clack.select({\n message: `Do you want to automatically run the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script after each production build?`,\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'This will modify your prod build command',\n },\n { label: 'No', value: false },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('modify-build-command', shouldAddToBuildCommand);\n\n return shouldAddToBuildCommand;\n}\n\n/**\n * Add the sentry:sourcemaps command to the prod build command in the package.json\n * - Detect the user's build command\n * - Append the sentry:sourcemaps command to it\n *\n * @param packageDotJson The package.json which will be modified.\n */\nexport async function addSentryCommandToBuildCommand(): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n // This usually shouldn't happen because earlier we added the\n // SENTRY_NPM_SCRIPT_NAME script but just to be sure\n packageDotJson.scripts = packageDotJson.scripts || {};\n\n const allNpmScripts = Object.keys(packageDotJson.scripts).filter(\n (s) => s !== SENTRY_NPM_SCRIPT_NAME,\n );\n\n const packageManager = detectPackageManger() ?? NPM;\n\n // Heuristic to pre-select the build command:\n // Often, 'build' is the prod build command, so we favour it.\n // If it's not there, commands that include 'build' might be the prod build command.\n let buildCommand =\n typeof packageDotJson.scripts.build === 'string'\n ? 'build'\n : allNpmScripts.find((s) => s.toLocaleLowerCase().includes('build'));\n\n const isProdBuildCommand =\n !!buildCommand &&\n (await abortIfCancelled(\n clack.confirm({\n message: `Is ${chalk.cyan(\n `${packageManager.runScriptCommand} ${buildCommand}`,\n )} your production build command?`,\n }),\n ));\n\n if (allNpmScripts.length && (!buildCommand || !isProdBuildCommand)) {\n buildCommand = await abortIfCancelled(\n clack.select({\n message: `Which ${packageManager.name} command in your ${chalk.cyan(\n 'package.json',\n )} builds your application for production?`,\n options: allNpmScripts\n .map((script) => ({\n label: script,\n value: script,\n }))\n .concat({ label: 'None of the above', value: 'none' }),\n }),\n );\n }\n\n if (!buildCommand || buildCommand === 'none') {\n clack.log.warn(\n `We can only add the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script to another \\`script\\` in your ${chalk.cyan('package.json')}.\nPlease add it manually to your prod build command.`,\n );\n return;\n }\n\n const oldCommand = packageDotJson.scripts[buildCommand];\n if (!oldCommand) {\n // very unlikely to happen but nevertheless\n clack.log.warn(\n `\\`${buildCommand}\\` doesn't seem to be part of your package.json scripts`,\n );\n return;\n }\n\n const newCommand = `${oldCommand} && ${packageManager.runScriptCommand} ${SENTRY_NPM_SCRIPT_NAME}`;\n\n if (oldCommand.endsWith(SENTRY_NPM_SCRIPT_NAME)) {\n clack.log.info(\n `It seems like ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} is already part of your ${chalk.cyan(\n buildCommand,\n )} command. Will not add it again.\nCurrent command: ${chalk.dim(oldCommand)}\nWould have injected: ${chalk.dim(newCommand)}`,\n );\n\n return;\n }\n\n packageDotJson.scripts[buildCommand] = newCommand;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n addedToBuildCommand = true;\n\n clack.log.info(\n `Added ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n buildCommand,\n )} command.`,\n );\n}\n\nasync function defaultConfigureSourcemapGenerationFlow(): Promise<void> {\n await abortIfCancelled(\n clack.select({\n message: `Verify that your build tool is generating source maps. ${chalk.dim(\n '(Your build output folder should contain .js.map files after a build)',\n )}`,\n options: [{ label: 'I checked. Continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n"]}
1
+ {"version":3,"file":"sentry-cli.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/sentry-cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,sDAAwC;AACxC,kDAA0B;AAC1B,qD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ACR;IAED,MAAM,UAAU,GAAG,GAAG,UAAU,OAAO,cAAc,CAAC,gBAAgB,IAAI,sBAAsB,EAAE,CAAC;IAEnG,IAAI,UAAU,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE;QAC/C,KAAK,CAAC,GAAG,CAAC,IAAI,CACZ,iBAAiB,eAAK,CAAC,IAAI,CACzB,sBAAsB,CACvB,4BAA4B,eAAK,CAAC,IAAI,CACrC,YAAY,CACb;mBACY,eAAK,CAAC,GAAG,CAAC,UAAU,CAAC;uBACjB,eAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CACzC,CAAC;QAEF,OAAO;KACR;IAED,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC;IAElD,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,EACxC,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CACxC,CAAC;IAEF,mBAAmB,GAAG,IAAI,CAAC;IAE3B,KAAK,CAAC,GAAG,CAAC,IAAI,CACZ,SAAS,eAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,mBAAmB,eAAK,CAAC,IAAI,CACtE,YAAY,CACb,WAAW,CACb,CAAC;AACJ,CAAC;AA/FD,wEA+FC;AAED,KAAK,UAAU,uCAAuC;IACpD,MAAM,IAAA,wBAAgB,EACpB,KAAK,CAAC,MAAM,CAAC;QACX,OAAO,EAAE,0DAA0D,eAAK,CAAC,GAAG,CAC1E,uEAAuE,CACxE,EAAE;QACH,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzD,YAAY,EAAE,IAAI;KACnB,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport {\n abortIfCancelled,\n addSentryCliConfig,\n getPackageDotJson,\n getPackageManager,\n installPackage,\n} from '../../utils/clack';\n\nimport { SourceMapUploadToolConfigurationOptions } from './types';\nimport { hasPackageInstalled } from '../../utils/package-json';\nimport { traceStep } from '../../telemetry';\nimport { NPM } from '../../utils/package-manager';\n\nconst SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';\n\nlet addedToBuildCommand = false;\n\nexport async function configureSentryCLI(\n options: SourceMapUploadToolConfigurationOptions,\n configureSourcemapGenerationFlow: () => Promise<void> = defaultConfigureSourcemapGenerationFlow,\n): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n\n await installPackage({\n packageName: '@sentry/cli',\n alreadyInstalled: hasPackageInstalled('@sentry/cli', packageDotJson),\n });\n\n let validPath = false;\n let relativeArtifactPath;\n do {\n const rawArtifactPath = await abortIfCancelled(\n clack.text({\n message: 'Where are your build artifacts located?',\n placeholder: `.${path.sep}out`,\n validate(value) {\n if (!value) {\n return 'Please enter a path.';\n }\n },\n }),\n );\n\n if (path.isAbsolute(rawArtifactPath)) {\n relativeArtifactPath = path.relative(process.cwd(), rawArtifactPath);\n } else {\n relativeArtifactPath = rawArtifactPath;\n }\n\n try {\n await fs.promises.access(path.join(process.cwd(), relativeArtifactPath));\n validPath = true;\n } catch {\n validPath = await abortIfCancelled(\n clack.select({\n message: `We couldn't find artifacts at ${relativeArtifactPath}. Are you sure that this is the location that contains your build artifacts?`,\n options: [\n {\n label: 'No, let me verify.',\n value: false,\n },\n { label: 'Yes, I am sure!', value: true },\n ],\n initialValue: false,\n }),\n );\n }\n } while (!validPath);\n\n const relativePosixArtifactPath = relativeArtifactPath\n .split(path.sep)\n .join(path.posix.sep);\n\n await configureSourcemapGenerationFlow();\n\n await createAndAddNpmScript(options, relativePosixArtifactPath);\n\n if (await askShouldAddToBuildCommand()) {\n await traceStep('sentry-cli-add-to-build-cmd', () =>\n addSentryCommandToBuildCommand(),\n );\n } else {\n clack.log.info(\n `No problem, just make sure to run this script ${chalk.bold(\n 'after',\n )} building your application but ${chalk.bold('before')} deploying!`,\n );\n }\n\n await addSentryCliConfig({ authToken: options.authToken });\n}\n\nexport async function setupNpmScriptInCI(): Promise<void> {\n if (addedToBuildCommand) {\n // No need to tell users to add it manually to their CI\n // if the script is already added to the build command\n return;\n }\n\n const addedToCI = await abortIfCancelled(\n clack.select({\n message: `Add a step to your CI pipeline that runs the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script ${chalk.bold('right after')} building your application.`,\n options: [\n { label: 'I did, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `You need to run ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} after each build for source maps to work properly.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-ci-script', addedToCI);\n\n if (!addedToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function createAndAddNpmScript(\n options: SourceMapUploadToolConfigurationOptions,\n relativePosixArtifactPath: string,\n): Promise<void> {\n const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${\n options.orgSlug\n } --project ${\n options.projectSlug\n } ${relativePosixArtifactPath} && sentry-cli${\n options.selfHosted ? ` --url ${options.url}` : ''\n } sourcemaps upload --org ${options.orgSlug} --project ${\n options.projectSlug\n } ${relativePosixArtifactPath}`;\n\n const packageDotJson = await getPackageDotJson();\n\n packageDotJson.scripts = packageDotJson.scripts || {};\n packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n clack.log.info(\n `Added a ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\nasync function askShouldAddToBuildCommand(): Promise<boolean> {\n const shouldAddToBuildCommand = await abortIfCancelled(\n clack.select({\n message: `Do you want to automatically run the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script after each production build?`,\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'This will modify your prod build command',\n },\n { label: 'No', value: false },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('modify-build-command', shouldAddToBuildCommand);\n\n return shouldAddToBuildCommand;\n}\n\n/**\n * Add the sentry:sourcemaps command to the prod build command in the package.json\n * - Detect the user's build command\n * - Append the sentry:sourcemaps command to it\n *\n * @param packageDotJson The package.json which will be modified.\n */\nexport async function addSentryCommandToBuildCommand(): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n // This usually shouldn't happen because earlier we added the\n // SENTRY_NPM_SCRIPT_NAME script but just to be sure\n packageDotJson.scripts = packageDotJson.scripts || {};\n\n const allNpmScripts = Object.keys(packageDotJson.scripts).filter(\n (s) => s !== SENTRY_NPM_SCRIPT_NAME,\n );\n\n const packageManager = await getPackageManager(NPM);\n\n // Heuristic to pre-select the build command:\n // Often, 'build' is the prod build command, so we favour it.\n // If it's not there, commands that include 'build' might be the prod build command.\n let buildCommand =\n typeof packageDotJson.scripts.build === 'string'\n ? 'build'\n : allNpmScripts.find((s) => s.toLocaleLowerCase().includes('build'));\n\n const isProdBuildCommand =\n !!buildCommand &&\n (await abortIfCancelled(\n clack.confirm({\n message: `Is ${chalk.cyan(\n `${packageManager.runScriptCommand} ${buildCommand}`,\n )} your production build command?`,\n }),\n ));\n\n if (allNpmScripts.length && (!buildCommand || !isProdBuildCommand)) {\n buildCommand = await abortIfCancelled(\n clack.select({\n message: `Which ${packageManager.name} command in your ${chalk.cyan(\n 'package.json',\n )} builds your application for production?`,\n options: allNpmScripts\n .map((script) => ({\n label: script,\n value: script,\n }))\n .concat({ label: 'None of the above', value: 'none' }),\n }),\n );\n }\n\n if (!buildCommand || buildCommand === 'none') {\n clack.log.warn(\n `We can only add the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script to another \\`script\\` in your ${chalk.cyan('package.json')}.\nPlease add it manually to your prod build command.`,\n );\n return;\n }\n\n const oldCommand = packageDotJson.scripts[buildCommand];\n if (!oldCommand) {\n // very unlikely to happen but nevertheless\n clack.log.warn(\n `\\`${buildCommand}\\` doesn't seem to be part of your package.json scripts`,\n );\n return;\n }\n\n const newCommand = `${oldCommand} && ${packageManager.runScriptCommand} ${SENTRY_NPM_SCRIPT_NAME}`;\n\n if (oldCommand.endsWith(SENTRY_NPM_SCRIPT_NAME)) {\n clack.log.info(\n `It seems like ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} is already part of your ${chalk.cyan(\n buildCommand,\n )} command. Will not add it again.\nCurrent command: ${chalk.dim(oldCommand)}\nWould have injected: ${chalk.dim(newCommand)}`,\n );\n\n return;\n }\n\n packageDotJson.scripts[buildCommand] = newCommand;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n addedToBuildCommand = true;\n\n clack.log.info(\n `Added ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n buildCommand,\n )} command.`,\n );\n}\n\nasync function defaultConfigureSourcemapGenerationFlow(): Promise<void> {\n await abortIfCancelled(\n clack.select({\n message: `Verify that your build tool is generating source maps. ${chalk.dim(\n '(Your build output folder should contain .js.map files after a build)',\n )}`,\n options: [{ label: 'I checked. Continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n"]}
@@ -31,14 +31,14 @@ const fs = __importStar(require("fs"));
31
31
  const path = __importStar(require("path"));
32
32
  const recast = __importStar(require("recast"));
33
33
  const Sentry = __importStar(require("@sentry/node"));
34
- // @ts-ignore - clack is ESM and TS complains about that. It works though
34
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
35
35
  const clack = __importStar(require("@clack/prompts"));
36
36
  const chalk_1 = __importDefault(require("chalk"));
37
- const clack_utils_1 = require("../../utils/clack-utils");
37
+ const clack_1 = require("../../utils/clack");
38
38
  const ast_utils_1 = require("../../utils/ast-utils");
39
39
  const debug_1 = require("../../utils/debug");
40
40
  const b = recast.types.builders;
41
- const getCodeSnippet = (colors) => (0, clack_utils_1.makeCodeSnippet)(colors, (unchanged, plus, _) => unchanged(`{
41
+ const getCodeSnippet = (colors) => (0, clack_1.makeCodeSnippet)(colors, (unchanged, plus, _) => unchanged(`{
42
42
  "compilerOptions": {
43
43
  ${plus('"sourceMap": true,')}
44
44
  ${plus('"inlineSources": true,')}
@@ -50,13 +50,13 @@ const getCodeSnippet = (colors) => (0, clack_utils_1.makeCodeSnippet)(colors, (u
50
50
  }`));
51
51
  async function configureTscSourcemapGenerationFlow() {
52
52
  const tsConfigPath = (0, ast_utils_1.findFile)(path.join(process.cwd(), 'tsconfig'), ['.json']) ??
53
- (await (0, clack_utils_1.askForToolConfigPath)('TypeScript', 'tsconfig.json'));
53
+ (await (0, clack_1.askForToolConfigPath)('TypeScript', 'tsconfig.json'));
54
54
  let successfullyAdded = false;
55
55
  if (tsConfigPath) {
56
56
  successfullyAdded = await enableSourcemaps(tsConfigPath);
57
57
  }
58
58
  else {
59
- successfullyAdded = await (0, clack_utils_1.createNewConfigFile)(path.join(process.cwd(), 'tsconfig.json'), getCodeSnippet(false));
59
+ successfullyAdded = await (0, clack_1.createNewConfigFile)(path.join(process.cwd(), 'tsconfig.json'), getCodeSnippet(false));
60
60
  Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
61
61
  }
62
62
  if (successfullyAdded) {
@@ -65,7 +65,7 @@ async function configureTscSourcemapGenerationFlow() {
65
65
  }
66
66
  else {
67
67
  Sentry.setTag('ast-mod', 'fail');
68
- await (0, clack_utils_1.showCopyPasteInstructions)('tsconfig.json', getCodeSnippet(true), 'This ensures that source maps are generated correctly');
68
+ await (0, clack_1.showCopyPasteInstructions)('tsconfig.json', getCodeSnippet(true), 'This ensures that source maps are generated correctly');
69
69
  }
70
70
  }
71
71
  exports.configureTscSourcemapGenerationFlow = configureTscSourcemapGenerationFlow;
@@ -1 +1 @@
1
- {"version":3,"file":"tsc.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/tsc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,+CAAiC;AAEjC,qDAAuC;AAEvC,yEAAyE;AACzE,sDAAwC;AACxC,kDAA0B;AAE1B,yDAKiC;AACjC,qDAM+B;AAC/B,6CAA0C;AAE1C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC,MAAM,cAAc,GAAG,CAAC,MAAe,EAAE,EAAE,CACzC,IAAA,6BAAe,EAAC,MAAM,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAC7C,SAAS,CACP;;MAEA,IAAI,CAAC,oBAAoB,CAAC;MAC1B,IAAI,CAAC,wBAAwB,CAAC;;;;MAI9B,IAAI,CAAC,mBAAmB,CAAC;;EAE7B,CACG,CACF,CAAC;AAEG,KAAK,UAAU,mCAAmC;IACvD,MAAM,YAAY,GAChB,IAAA,oBAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QACzD,CAAC,MAAM,IAAA,kCAAoB,EAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;IAE9D,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,YAAY,EAAE;QAChB,iBAAiB,GAAG,MAAM,gBAAgB,CAAC,YAAY,CAAC,CAAC;KAC1D;SAAM;QACL,iBAAiB,GAAG,MAAM,IAAA,iCAAmB,EAC3C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,EACzC,cAAc,CAAC,KAAK,CAAC,CACtB,CAAC;QACF,MAAM,C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AAC,qBAAqB,EAAE,uBAAuB,CAAC,CAAC;YAC9D,OAAO,KAAK,CAAC;SACd;QAED,IAAA,qCAAyB,EACvB,kBAAkB,EAClB,WAAW,EACX,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CACvB,CAAC;QAEF,IAAA,qCAAyB,EACvB,kBAAkB,EAClB,eAAe,EACf,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CACvB,CAAC;QAEF,IAAA,qCAAyB,EACvB,kBAAkB,EAClB,YAAY,EACZ,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,EACpB,0IAA0I,CAC3I,CAAC;QAEF,MAAM,IAAI,GAAG,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC;QAE7B,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QAEhD,KAAK,CAAC,GAAG,CAAC,OAAO,CACf,qCAAqC,eAAK,CAAC,IAAI,CAC7C,IAAI,CAAC,QAAQ,CAAC,YAAY,IAAI,eAAe,CAAC,CAC/C,GAAG,CACL,CAAC;QAEF,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,aAAK,EAAC,CAAC,CAAC,CAAC;QACT,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;QACvD,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AA7DD,4CA6DC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\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 {\n askForToolConfigPath,\n createNewConfigFile,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../../utils/clack-utils';\nimport {\n findFile,\n getOrSetObjectProperty,\n parseJsonC,\n printJsonC,\n setOrUpdateObjectProperty,\n} from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\nconst b = recast.types.builders;\n\nconst getCodeSnippet = (colors: boolean) =>\n makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(\n `{\n \"compilerOptions\": {\n ${plus('\"sourceMap\": true,')}\n ${plus('\"inlineSources\": true,')}\n\n // Set \\`sourceRoot\\` to \"/\" to strip the build path prefix from\n // generated source code references. This will improve issue grouping in Sentry.\n ${plus('\"sourceRoot\": \"/\"')}\n }\n}`,\n ),\n );\n\nexport async function configureTscSourcemapGenerationFlow(): Promise<void> {\n const tsConfigPath =\n findFile(path.join(process.cwd(), 'tsconfig'), ['.json']) ??\n (await askForToolConfigPath('TypeScript', 'tsconfig.json'));\n\n let successfullyAdded = false;\n if (tsConfigPath) {\n successfullyAdded = await enableSourcemaps(tsConfigPath);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'tsconfig.json'),\n getCodeSnippet(false),\n );\n Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');\n }\n\n if (successfullyAdded) {\n Sentry.setTag('ast-mod', 'success');\n clack.log.info(\n `We recommend checking the ${\n tsConfigPath ? 'modified' : 'added'\n } file after the wizard finished to ensure it works with your build setup.`,\n );\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n 'tsconfig.json',\n getCodeSnippet(true),\n 'This ensures that source maps are generated correctly',\n );\n }\n}\n\n/**\n * Modifies tsconfig.json (@param tsConfigPath) to enable source maps generation.\n *\n * Exported only for testing\n */\nexport async function enableSourcemaps(tsConfigPath: string): Promise<boolean> {\n try {\n const tsConfig = await fs.promises.readFile(tsConfigPath, 'utf-8');\n\n const { ast, jsonObject } = parseJsonC(tsConfig.toString());\n\n if (!jsonObject || !ast) {\n // this will only happen if the input file isn't valid JSON-C\n Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');\n return false;\n }\n\n const compilerOptionsProp = getOrSetObjectProperty(\n jsonObject,\n 'compilerOptions',\n b.objectExpression([]),\n );\n\n const compilerOptionsObj = compilerOptionsProp.value;\n\n if (!compilerOptionsObj || compilerOptionsObj.type !== 'ObjectExpression') {\n // a valid compilerOptions prop should always be an object expression\n Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');\n return false;\n }\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'sourceMap',\n b.booleanLiteral(true),\n );\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'inlineSources',\n b.booleanLiteral(true),\n );\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'sourceRoot',\n b.stringLiteral('/'),\n 'Set `sourceRoot` to \"/\" to strip the build path prefix\\nfrom generated source code references.\\nThis improves issue grouping in Sentry.',\n );\n\n const code = printJsonC(ast);\n\n await fs.promises.writeFile(tsConfigPath, code);\n\n clack.log.success(\n `Enabled source maps generation in ${chalk.cyan(\n path.basename(tsConfigPath || 'tsconfig.json'),\n )}.`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"tsc.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/tsc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,+CAAiC;AAEjC,qDAAuC;AAEvC,+EAA+E;AAC/E,sDAAwC;AACxC,kDAA0B;AAE1B,6CAK2B;AAC3B,qDAM+B;AAC/B,6CAA0C;AAE1C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC,MAAM,cAAc,GAAG,CAAC,MAAe,EAAE,EAAE,CACzC,IAAA,uBAAe,EAAC,MAAM,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAC7C,SAAS,CACP;;MAEA,IAAI,CAAC,oBAAoB,CAAC;MAC1B,IAAI,CAAC,wBAAwB,CAAC;;;;MAI9B,IAAI,CAAC,mBAAmB,CAAC;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AG,CACL,CAAC;QAEF,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,aAAK,EAAC,CAAC,CAAC,CAAC;QACT,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;QACvD,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AA7DD,4CA6DC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport {\n askForToolConfigPath,\n createNewConfigFile,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../../utils/clack';\nimport {\n findFile,\n getOrSetObjectProperty,\n parseJsonC,\n printJsonC,\n setOrUpdateObjectProperty,\n} from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\nconst b = recast.types.builders;\n\nconst getCodeSnippet = (colors: boolean) =>\n makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(\n `{\n \"compilerOptions\": {\n ${plus('\"sourceMap\": true,')}\n ${plus('\"inlineSources\": true,')}\n\n // Set \\`sourceRoot\\` to \"/\" to strip the build path prefix from\n // generated source code references. This will improve issue grouping in Sentry.\n ${plus('\"sourceRoot\": \"/\"')}\n }\n}`,\n ),\n );\n\nexport async function configureTscSourcemapGenerationFlow(): Promise<void> {\n const tsConfigPath =\n findFile(path.join(process.cwd(), 'tsconfig'), ['.json']) ??\n (await askForToolConfigPath('TypeScript', 'tsconfig.json'));\n\n let successfullyAdded = false;\n if (tsConfigPath) {\n successfullyAdded = await enableSourcemaps(tsConfigPath);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'tsconfig.json'),\n getCodeSnippet(false),\n );\n Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');\n }\n\n if (successfullyAdded) {\n Sentry.setTag('ast-mod', 'success');\n clack.log.info(\n `We recommend checking the ${\n tsConfigPath ? 'modified' : 'added'\n } file after the wizard finished to ensure it works with your build setup.`,\n );\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n 'tsconfig.json',\n getCodeSnippet(true),\n 'This ensures that source maps are generated correctly',\n );\n }\n}\n\n/**\n * Modifies tsconfig.json (@param tsConfigPath) to enable source maps generation.\n *\n * Exported only for testing\n */\nexport async function enableSourcemaps(tsConfigPath: string): Promise<boolean> {\n try {\n const tsConfig = await fs.promises.readFile(tsConfigPath, 'utf-8');\n\n const { ast, jsonObject } = parseJsonC(tsConfig.toString());\n\n if (!jsonObject || !ast) {\n // this will only happen if the input file isn't valid JSON-C\n Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');\n return false;\n }\n\n const compilerOptionsProp = getOrSetObjectProperty(\n jsonObject,\n 'compilerOptions',\n b.objectExpression([]),\n );\n\n const compilerOptionsObj = compilerOptionsProp.value;\n\n if (!compilerOptionsObj || compilerOptionsObj.type !== 'ObjectExpression') {\n // a valid compilerOptions prop should always be an object expression\n Sentry.setTag('ast-mod-fail-reason', 'original-file-invalid');\n return false;\n }\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'sourceMap',\n b.booleanLiteral(true),\n );\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'inlineSources',\n b.booleanLiteral(true),\n );\n\n setOrUpdateObjectProperty(\n compilerOptionsObj,\n 'sourceRoot',\n b.stringLiteral('/'),\n 'Set `sourceRoot` to \"/\" to strip the build path prefix\\nfrom generated source code references.\\nThis improves issue grouping in Sentry.',\n );\n\n const code = printJsonC(ast);\n\n await fs.promises.writeFile(tsConfigPath, code);\n\n clack.log.success(\n `Enabled source maps generation in ${chalk.cyan(\n path.basename(tsConfigPath || 'tsconfig.json'),\n )}.`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n"]}
@@ -27,22 +27,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.addVitePluginToConfig = exports.configureVitePlugin = void 0;
30
- // @ts-ignore - clack is ESM and TS complains about that. It works though
30
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
31
31
  const clack = __importStar(require("@clack/prompts"));
32
- // @ts-ignore - magicast is ESM and TS complains about that. It works though
32
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
33
33
  const magicast_1 = require("magicast");
34
- // @ts-ignore - magicast is ESM and TS complains about that. It works though
34
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
35
35
  const helpers_1 = require("magicast/helpers");
36
36
  const recast = __importStar(require("recast"));
37
37
  const Sentry = __importStar(require("@sentry/node"));
38
38
  const chalk_1 = __importDefault(require("chalk"));
39
- const clack_utils_1 = require("../../utils/clack-utils");
39
+ const clack_1 = require("../../utils/clack");
40
40
  const package_json_1 = require("../../utils/package-json");
41
41
  const ast_utils_1 = require("../../utils/ast-utils");
42
42
  const path = __importStar(require("path"));
43
43
  const fs = __importStar(require("fs"));
44
44
  const debug_1 = require("../../utils/debug");
45
- const getViteConfigSnippet = (options, colors) => (0, clack_utils_1.makeCodeSnippet)(colors, (unchanged, plus, _) => unchanged(`import { defineConfig } from "vite";
45
+ const getViteConfigSnippet = (options, colors) => (0, clack_1.makeCodeSnippet)(colors, (unchanged, plus, _) => unchanged(`import { defineConfig } from "vite";
46
46
  ${plus('import { sentryVitePlugin } from "@sentry/vite-plugin";')}
47
47
 
48
48
  export default defineConfig({
@@ -59,18 +59,18 @@ export default defineConfig({
59
59
  ],
60
60
  });`));
61
61
  const configureVitePlugin = async (options) => {
62
- await (0, clack_utils_1.installPackage)({
62
+ await (0, clack_1.installPackage)({
63
63
  packageName: '@sentry/vite-plugin',
64
- alreadyInstalled: (0, package_json_1.hasPackageInstalled)('@sentry/vite-plugin', await (0, clack_utils_1.getPackageDotJson)()),
64
+ alreadyInstalled: (0, package_json_1.hasPackageInstalled)('@sentry/vite-plugin', await (0, clack_1.getPackageDotJson)()),
65
65
  });
66
66
  const viteConfigPath = (0, ast_utils_1.findFile)(path.resolve(process.cwd(), 'vite.config')) ??
67
- (await (0, clack_utils_1.askForToolConfigPath)('Vite', 'vite.config.js'));
67
+ (await (0, clack_1.askForToolConfigPath)('Vite', 'vite.config.js'));
68
68
  let successfullyAdded = false;
69
69
  if (viteConfigPath) {
70
70
  successfullyAdded = await addVitePluginToConfig(viteConfigPath, options);
71
71
  }
72
72
  else {
73
- successfullyAdded = await (0, clack_utils_1.createNewConfigFile)(path.join(process.cwd(), 'vite.config.js'), getViteConfigSnippet(options, false), 'More information about vite configs: https://vitejs.dev/config/');
73
+ successfullyAdded = await (0, clack_1.createNewConfigFile)(path.join(process.cwd(), 'vite.config.js'), getViteConfigSnippet(options, false), 'More information about vite configs: https://vitejs.dev/config/');
74
74
  Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
75
75
  }
76
76
  if (successfullyAdded) {
@@ -79,9 +79,9 @@ const configureVitePlugin = async (options) => {
79
79
  }
80
80
  else {
81
81
  Sentry.setTag('ast-mod', 'fail');
82
- await (0, clack_utils_1.showCopyPasteInstructions)(path.basename(viteConfigPath || 'vite.config.js'), getViteConfigSnippet(options, true));
82
+ await (0, clack_1.showCopyPasteInstructions)(path.basename(viteConfigPath || 'vite.config.js'), getViteConfigSnippet(options, true));
83
83
  }
84
- await (0, clack_utils_1.addDotEnvSentryBuildPluginFile)(options.authToken);
84
+ await (0, clack_1.addDotEnvSentryBuildPluginFile)(options.authToken);
85
85
  };
86
86
  exports.configureVitePlugin = configureVitePlugin;
87
87
  async function addVitePluginToConfig(viteConfigPath, options) {
@@ -90,7 +90,7 @@ async function addVitePluginToConfig(viteConfigPath, options) {
90
90
  const viteConfigContent = (await fs.promises.readFile(viteConfigPath)).toString();
91
91
  const mod = (0, magicast_1.parseModule)(viteConfigContent);
92
92
  if ((0, ast_utils_1.hasSentryContent)(mod.$ast)) {
93
- const shouldContinue = await (0, clack_utils_1.abortIfCancelled)(clack.select({
93
+ const shouldContinue = await (0, clack_1.abortIfCancelled)(clack.select({
94
94
  message: `${prettyViteConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,
95
95
  options: [
96
96
  {
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,sDAAwC;AACxC,4EAA4E;AAC5E,uCAAqD;AACrD,4EAA4E;AAC5E,8CAAiD;AAIjD,+CAAiC;AAEjC,qDAAuC;AAEvC,kDAA0B;AAC1B,yDASiC;AACjC,2DAA+D;AAM/D,qDAAmE;AAEnE,2CAA6B;AAC7B,uCAAyB;AACzB,6CAA0C;AAE1C,MAAM,oBAAoB,GAAG,CAC3B,OAAgD,EAChD,MAAe,EACf,EAAE,CACF,IAAA,6BAAe,EAAC,MAAM,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAC7C,SAAS,CAAC;EACZ,IAAI,CAAC,yDAAyD,CAAC;;;;MAI3D,IAAI,CAAC,6DAA6D,CAAC;;;;MAInE,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;;IAEL,CAAC,CACF,CAAC;AAEG,MAAM,mBAAmB,GAC9B,KAAK,EAAE,OAAO,EAAE,EAAE;IAChB,MAAM,IAAA,4BAAc,EAAC;QACnB,WAAW,EAAE,qBAAqB;QAClC,gBAAgB,EAAE,IAAA,kCAAmB,EACnC,qBAAqB,EACrB,MAAM,IAAA,+BAAiB,GAAE,CAC1B;KACF,CAAC,CAAC;IAEH,MAAM,cAAc,GAClB,IAAA,o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;AACnB,CAAC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { generateCode, parseModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\n\nimport type { namedTypes as t } from 'ast-types';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\nimport chalk from 'chalk';\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';\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { debug } from '../../utils/debug';\n\nconst getViteConfigSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) =>\n makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`import { defineConfig } from \"vite\";\n${plus('import { sentryVitePlugin } from \"@sentry/vite-plugin\";')}\n\nexport default defineConfig({\n build: {\n ${plus('sourcemap: true, // Source map generation must be turned on')}\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ${plus(`sentryVitePlugin({\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 configureVitePlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/vite-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/vite-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const viteConfigPath =\n findFile(path.resolve(process.cwd(), 'vite.config')) ??\n (await askForToolConfigPath('Vite', 'vite.config.js'));\n\n let successfullyAdded = false;\n if (viteConfigPath) {\n successfullyAdded = await addVitePluginToConfig(viteConfigPath, options);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'vite.config.js'),\n getViteConfigSnippet(options, false),\n 'More information about vite 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 viteConfigPath ? '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(viteConfigPath || 'vite.config.js'),\n getViteConfigSnippet(options, true),\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\nexport async function addVitePluginToConfig(\n viteConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath)\n ).toString();\n\n const mod = parseModule(viteConfigContent);\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `${prettyViteConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Vite 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 const enabledSourcemaps = enableSourcemapGeneration(mod.$ast as t.Program);\n if (!enabledSourcemaps) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const { orgSlug: org, projectSlug: project, selfHosted, url } = options;\n\n addVitePlugin(mod, {\n imported: 'sentryVitePlugin',\n from: '@sentry/vite-plugin',\n constructor: 'sentryVitePlugin',\n options: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n });\n\n const code = generateCode(mod.$ast).code;\n\n await fs.promises.writeFile(viteConfigPath, code);\n\n clack.log.success(\n `Added the Sentry Vite plugin to ${prettyViteConfigFilename} and enabled source maps`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n\nfunction enableSourcemapGeneration(program: t.Program): boolean {\n const configObj = getViteConfigObject(program);\n\n if (!configObj) {\n return false;\n }\n\n const b = recast.types.builders;\n\n const buildProp = configObj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'build',\n );\n\n // case 1: build property doesn't exist yet, so we can just add it\n if (!buildProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('build'),\n b.objectExpression([\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n ]),\n ),\n );\n return true;\n }\n\n const isValidBuildProp =\n buildProp.type === 'ObjectProperty' &&\n buildProp.value.type === 'ObjectExpression';\n\n if (!isValidBuildProp) {\n return false;\n }\n\n const sourceMapsProp =\n buildProp.value.type === 'ObjectExpression' &&\n buildProp.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'sourcemap',\n );\n\n // case 2: build.sourcemap property doesn't exist yet, so we just add it\n if (!sourceMapsProp && buildProp.value.type === 'ObjectExpression') {\n buildProp.value.properties.push(\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n );\n return true;\n }\n\n if (!sourceMapsProp || sourceMapsProp.type !== 'ObjectProperty') {\n return false;\n }\n\n // case 3: build.sourcemap property exists, and it's set to 'hidden'\n if (\n sourceMapsProp.value.type === 'StringLiteral' &&\n sourceMapsProp.value.value === 'hidden'\n ) {\n // nothing to do for us\n return true;\n }\n\n // case 4: build.sourcemap property exists, but it's not enabled, so we set it to true\n // or it is already true in which case this is a noop\n sourceMapsProp.value = b.booleanLiteral(true);\n return true;\n}\n\nfunction getViteConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n const defaultExport = program.body.find(\n (s) => s.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration;\n\n if (!defaultExport) {\n return undefined;\n }\n\n if (defaultExport.declaration.type === 'ObjectExpression') {\n return defaultExport.declaration;\n }\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.arguments[0].type === 'ObjectExpression'\n ) {\n return defaultExport.declaration.arguments[0];\n }\n\n if (defaultExport.declaration.type === 'Identifier') {\n const configId = defaultExport.declaration.name;\n return findConfigNode(configId, program);\n }\n\n return undefined;\n}\n\nfunction findConfigNode(\n configId: string,\n program: t.Program,\n): t.ObjectExpression | undefined {\n for (const node of program.body) {\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n if (\n declaration.type === 'VariableDeclarator' &&\n declaration.id.type === 'Identifier' &&\n declaration.id.name === configId &&\n declaration.init?.type === 'ObjectExpression'\n ) {\n return declaration.init;\n }\n }\n }\n }\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,sDAAwC;AACxC,kFAAkF;AAClF,uCAAqD;AACrD,kFAAkF;AAClF,8CAAiD;AAIjD,+CAAiC;AAEjC,qDAAuC;AAEvC,kDAA0B;AAC1B,6CAS2B;AAC3B,2DAA+D;AAM/D,qDAAmE;AAEnE,2CAA6B;AAC7B,uCAAyB;AACzB,6CAA0C;AAE1C,MAAM,oBAAoB,GAAG,CAC3B,OAAgD,EAChD,MAAe,EACf,EAAE,CACF,IAAA,uBAAe,EAAC,MAAM,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,EAA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AE,OAAO,CAAC,CAAC;KAC1C;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CACrB,QAAgB,EAChB,OAAkB;IAElB,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE;QAC/B,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,EAAE;YACvC,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,YAAY,EAAE;gBAC3C,IACE,WAAW,CAAC,IAAI,KAAK,oBAAoB;oBACzC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,YAAY;oBACpC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,QAAQ;oBAChC,WAAW,CAAC,IAAI,EAAE,IAAI,KAAK,kBAAkB,EAC7C;oBACA,OAAO,WAAW,CAAC,IAAI,CAAC;iBACzB;aACF;SACF;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, parseModule } from 'magicast';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\n\nimport type { namedTypes as t } from 'ast-types';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\nimport chalk from 'chalk';\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n askForToolConfigPath,\n createNewConfigFile,\n getPackageDotJson,\n installPackage,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../../utils/clack';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { debug } from '../../utils/debug';\n\nconst getViteConfigSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) =>\n makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`import { defineConfig } from \"vite\";\n${plus('import { sentryVitePlugin } from \"@sentry/vite-plugin\";')}\n\nexport default defineConfig({\n build: {\n ${plus('sourcemap: true, // Source map generation must be turned on')}\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ${plus(`sentryVitePlugin({\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 configureVitePlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/vite-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/vite-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const viteConfigPath =\n findFile(path.resolve(process.cwd(), 'vite.config')) ??\n (await askForToolConfigPath('Vite', 'vite.config.js'));\n\n let successfullyAdded = false;\n if (viteConfigPath) {\n successfullyAdded = await addVitePluginToConfig(viteConfigPath, options);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'vite.config.js'),\n getViteConfigSnippet(options, false),\n 'More information about vite 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 viteConfigPath ? '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(viteConfigPath || 'vite.config.js'),\n getViteConfigSnippet(options, true),\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\nexport async function addVitePluginToConfig(\n viteConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath)\n ).toString();\n\n const mod = parseModule(viteConfigContent);\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `${prettyViteConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Vite 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 const enabledSourcemaps = enableSourcemapGeneration(mod.$ast as t.Program);\n if (!enabledSourcemaps) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const { orgSlug: org, projectSlug: project, selfHosted, url } = options;\n\n addVitePlugin(mod, {\n imported: 'sentryVitePlugin',\n from: '@sentry/vite-plugin',\n constructor: 'sentryVitePlugin',\n options: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n });\n\n const code = generateCode(mod.$ast).code;\n\n await fs.promises.writeFile(viteConfigPath, code);\n\n clack.log.success(\n `Added the Sentry Vite plugin to ${prettyViteConfigFilename} and enabled source maps`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n\nfunction enableSourcemapGeneration(program: t.Program): boolean {\n const configObj = getViteConfigObject(program);\n\n if (!configObj) {\n return false;\n }\n\n const b = recast.types.builders;\n\n const buildProp = configObj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'build',\n );\n\n // case 1: build property doesn't exist yet, so we can just add it\n if (!buildProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('build'),\n b.objectExpression([\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n ]),\n ),\n );\n return true;\n }\n\n const isValidBuildProp =\n buildProp.type === 'ObjectProperty' &&\n buildProp.value.type === 'ObjectExpression';\n\n if (!isValidBuildProp) {\n return false;\n }\n\n const sourceMapsProp =\n buildProp.value.type === 'ObjectExpression' &&\n buildProp.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'sourcemap',\n );\n\n // case 2: build.sourcemap property doesn't exist yet, so we just add it\n if (!sourceMapsProp && buildProp.value.type === 'ObjectExpression') {\n buildProp.value.properties.push(\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n );\n return true;\n }\n\n if (!sourceMapsProp || sourceMapsProp.type !== 'ObjectProperty') {\n return false;\n }\n\n // case 3: build.sourcemap property exists, and it's set to 'hidden'\n if (\n sourceMapsProp.value.type === 'StringLiteral' &&\n sourceMapsProp.value.value === 'hidden'\n ) {\n // nothing to do for us\n return true;\n }\n\n // case 4: build.sourcemap property exists, but it's not enabled, so we set it to true\n // or it is already true in which case this is a noop\n sourceMapsProp.value = b.booleanLiteral(true);\n return true;\n}\n\nfunction getViteConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n const defaultExport = program.body.find(\n (s) => s.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration;\n\n if (!defaultExport) {\n return undefined;\n }\n\n if (defaultExport.declaration.type === 'ObjectExpression') {\n return defaultExport.declaration;\n }\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.arguments[0].type === 'ObjectExpression'\n ) {\n return defaultExport.declaration.arguments[0];\n }\n\n if (defaultExport.declaration.type === 'Identifier') {\n const configId = defaultExport.declaration.name;\n return findConfigNode(configId, program);\n }\n\n return undefined;\n}\n\nfunction findConfigNode(\n configId: string,\n program: t.Program,\n): t.ObjectExpression | undefined {\n for (const node of program.body) {\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n if (\n declaration.type === 'VariableDeclarator' &&\n declaration.id.type === 'Identifier' &&\n declaration.id.name === configId &&\n declaration.init?.type === 'ObjectExpression'\n ) {\n return declaration.init;\n }\n }\n }\n }\n return undefined;\n}\n"]}
@@ -29,16 +29,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.modifyWebpackConfig = exports.configureWebPackPlugin = void 0;
30
30
  const path = __importStar(require("node:path"));
31
31
  const fs = __importStar(require("node:fs"));
32
- // @ts-ignore - clack is ESM and TS complains about that. It works though
32
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
33
33
  const clack = __importStar(require("@clack/prompts"));
34
34
  const chalk_1 = __importDefault(require("chalk"));
35
35
  const recast = __importStar(require("recast"));
36
36
  const Sentry = __importStar(require("@sentry/node"));
37
- const clack_utils_1 = require("../../utils/clack-utils");
37
+ const clack_1 = require("../../utils/clack");
38
38
  const package_json_1 = require("../../utils/package-json");
39
39
  const ast_utils_1 = require("../../utils/ast-utils");
40
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");')}
41
+ const getCodeSnippet = (options, colors) => (0, clack_1.makeCodeSnippet)(colors, (unchanged, plus) => unchanged(`${plus('const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");')}
42
42
 
43
43
  module.exports = {
44
44
  // ... other options
@@ -53,18 +53,18 @@ module.exports = {
53
53
  ],
54
54
  }`));
55
55
  const configureWebPackPlugin = async (options) => {
56
- await (0, clack_utils_1.installPackage)({
56
+ await (0, clack_1.installPackage)({
57
57
  packageName: '@sentry/webpack-plugin',
58
- alreadyInstalled: (0, package_json_1.hasPackageInstalled)('@sentry/webpack-plugin', await (0, clack_utils_1.getPackageDotJson)()),
58
+ alreadyInstalled: (0, package_json_1.hasPackageInstalled)('@sentry/webpack-plugin', await (0, clack_1.getPackageDotJson)()),
59
59
  });
60
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'));
61
+ (await (0, clack_1.askForToolConfigPath)('Webpack', 'webpack.config.js'));
62
62
  let successfullyAdded = false;
63
63
  if (webpackConfigPath) {
64
64
  successfullyAdded = await modifyWebpackConfig(webpackConfigPath, options);
65
65
  }
66
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/');
67
+ successfullyAdded = await (0, clack_1.createNewConfigFile)(path.join(process.cwd(), 'webpack.config.js'), getCodeSnippet(options, false), 'More information about Webpack configs: https://vitejs.dev/config/');
68
68
  Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
69
69
  }
70
70
  if (successfullyAdded) {
@@ -73,9 +73,9 @@ const configureWebPackPlugin = async (options) => {
73
73
  }
74
74
  else {
75
75
  Sentry.setTag('ast-mod', 'fail');
76
- await (0, clack_utils_1.showCopyPasteInstructions)(path.basename(webpackConfigPath || 'webpack.config.js'), getCodeSnippet(options, true));
76
+ await (0, clack_1.showCopyPasteInstructions)(path.basename(webpackConfigPath || 'webpack.config.js'), getCodeSnippet(options, true));
77
77
  }
78
- await (0, clack_utils_1.addDotEnvSentryBuildPluginFile)(options.authToken);
78
+ await (0, clack_1.addDotEnvSentryBuildPluginFile)(options.authToken);
79
79
  };
80
80
  exports.configureWebPackPlugin = configureWebPackPlugin;
81
81
  /**
@@ -139,7 +139,7 @@ async function modifyWebpackConfig(webpackConfigPath, options) {
139
139
  exports.modifyWebpackConfig = modifyWebpackConfig;
140
140
  async function shouldModifyWebpackConfig(program, prettyConfigFilename) {
141
141
  if ((0, ast_utils_1.hasSentryContent)(program)) {
142
- const shouldContinue = await (0, clack_utils_1.abortIfCancelled)(clack.select({
142
+ const shouldContinue = await (0, clack_1.abortIfCancelled)(clack.select({
143
143
  message: `Seems like ${prettyConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,
144
144
  options: [
145
145
  {
@@ -1 +1 @@
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,+BAAiB,GAAE,CAC1B;KACF,CAAC,CAAC;IAEH,MAAM,iBAAiB,GACrB,IAAA,oBAAQ,EAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,CAAC,CAAC;QACvD,CAAC,MAAM,IAAA,kCAAoB,EAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAE/D,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,iBAAiB,EAAE;QACrB,iBA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ent":["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"]}
1
+ {"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/webpack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,4CAA8B;AAE9B,+EAA+E;AAC/E,sDAAwC;AACxC,kDAA0B;AAE1B,+CAAiC;AAIjC,qDAAuC;AAEvC,6CAS2B;AAC3B,2DAA+D;AAO/D,qDAAmE;AACnE,6CAA0C;AAE1C,MAAM,cAAc,GAAG,CACrB,OAAgD,EA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C,IAAI,KAAK,YAAY;YAC1B,CAAC,CAAC,EAAE,CAAC,IAAI,KAAK,QAAQ,CACzB,CAAC;QAEF,OAAO,UAAU,EAAE,IAAI,EAAE,IAAI,KAAK,kBAAkB;YAClD,CAAC,CAAC,UAAU,CAAC,IAAI;YACjB,CAAC,CAAC,SAAS,CAAC;KACf;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,mBAAmB,CAC1B,OAAkB;IAElB,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CACrC,CAAC,CAAC,EAA8B,EAAE,CAChC,CAAC,CAAC,IAAI,KAAK,qBAAqB;QAChC,CAAC,CAAC,UAAU,CAAC,IAAI,KAAK,sBAAsB;QAC5C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB;QAC7C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,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-expect-error - 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';\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"]}