@sentry/wizard 3.5.0 → 3.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 (115) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/bin.ts +1 -34
  3. package/dist/bin.js +1 -28
  4. package/dist/bin.js.map +1 -1
  5. package/dist/lib/Constants.d.ts +2 -0
  6. package/dist/lib/Constants.js +5 -0
  7. package/dist/lib/Constants.js.map +1 -1
  8. package/dist/lib/Helper/Wizard.js +2 -0
  9. package/dist/lib/Helper/Wizard.js.map +1 -1
  10. package/dist/lib/Helper/__tests__/SentryCli.js +1 -0
  11. package/dist/lib/Helper/__tests__/SentryCli.js.map +1 -1
  12. package/dist/lib/Steps/ChooseIntegration.js +4 -0
  13. package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
  14. package/dist/lib/Steps/Integrations/Apple.d.ts +10 -0
  15. package/dist/lib/Steps/Integrations/Apple.js +92 -0
  16. package/dist/lib/Steps/Integrations/Apple.js.map +1 -0
  17. package/dist/lib/Steps/Integrations/NextJsShim.js +1 -0
  18. package/dist/lib/Steps/Integrations/NextJsShim.js.map +1 -1
  19. package/dist/lib/Steps/Integrations/SourceMapsShim.d.ts +1 -1
  20. package/dist/lib/Steps/Integrations/SourceMapsShim.js +2 -1
  21. package/dist/lib/Steps/Integrations/SourceMapsShim.js.map +1 -1
  22. package/dist/lib/Steps/Integrations/SvelteKitShim.js +1 -0
  23. package/dist/lib/Steps/Integrations/SvelteKitShim.js.map +1 -1
  24. package/dist/package.json +2 -2
  25. package/dist/src/apple/apple-wizard.d.ts +2 -0
  26. package/dist/src/apple/apple-wizard.js +197 -0
  27. package/dist/src/apple/apple-wizard.js.map +1 -0
  28. package/dist/src/apple/code-tools.d.ts +1 -0
  29. package/dist/src/apple/code-tools.js +100 -0
  30. package/dist/src/apple/code-tools.js.map +1 -0
  31. package/dist/src/apple/templates.d.ts +4 -0
  32. package/dist/src/apple/templates.js +19 -0
  33. package/dist/src/apple/templates.js.map +1 -0
  34. package/dist/src/apple/xcode-manager.d.ts +4 -0
  35. package/dist/src/apple/xcode-manager.js +145 -0
  36. package/dist/src/apple/xcode-manager.js.map +1 -0
  37. package/dist/src/nextjs/nextjs-wizard.js +4 -10
  38. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  39. package/dist/src/sourcemaps/sourcemaps-wizard.js +193 -71
  40. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  41. package/dist/src/sourcemaps/tools/angular.d.ts +1 -0
  42. package/dist/src/sourcemaps/tools/angular.js +76 -0
  43. package/dist/src/sourcemaps/tools/angular.js.map +1 -0
  44. package/dist/src/sourcemaps/tools/esbuild.js +2 -1
  45. package/dist/src/sourcemaps/tools/esbuild.js.map +1 -1
  46. package/dist/src/sourcemaps/tools/rollup.js +2 -1
  47. package/dist/src/sourcemaps/tools/rollup.js.map +1 -1
  48. package/dist/src/sourcemaps/tools/sentry-cli.d.ts +1 -0
  49. package/dist/src/sourcemaps/tools/sentry-cli.js +52 -24
  50. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  51. package/dist/src/sourcemaps/tools/vite.js +2 -1
  52. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  53. package/dist/src/sourcemaps/tools/webpack.js +2 -1
  54. package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
  55. package/dist/src/sourcemaps/utils/detect-tool.d.ts +3 -0
  56. package/dist/src/sourcemaps/utils/detect-tool.js +73 -0
  57. package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -0
  58. package/dist/src/sourcemaps/utils/other-wizards.d.ts +4 -0
  59. package/dist/src/sourcemaps/utils/other-wizards.js +183 -0
  60. package/dist/src/sourcemaps/utils/other-wizards.js.map +1 -0
  61. package/dist/src/sourcemaps/utils/sdk-version.js +14 -13
  62. package/dist/src/sourcemaps/utils/sdk-version.js.map +1 -1
  63. package/dist/src/sveltekit/sdk-setup.js +5 -3
  64. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  65. package/dist/src/sveltekit/sveltekit-wizard.js +2 -1
  66. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  67. package/dist/src/sveltekit/templates.js +1 -1
  68. package/dist/src/sveltekit/templates.js.map +1 -1
  69. package/dist/src/telemetry.d.ts +1 -0
  70. package/dist/src/telemetry.js +7 -1
  71. package/dist/src/telemetry.js.map +1 -1
  72. package/dist/src/utils/bash.d.ts +3 -0
  73. package/dist/src/utils/bash.js +118 -0
  74. package/dist/src/utils/bash.js.map +1 -0
  75. package/dist/src/utils/clack-utils.d.ts +12 -8
  76. package/dist/src/utils/clack-utils.js +83 -40
  77. package/dist/src/utils/clack-utils.js.map +1 -1
  78. package/dist/src/utils/package-json.d.ts +19 -0
  79. package/dist/src/utils/package-json.js +29 -0
  80. package/dist/src/utils/package-json.js.map +1 -0
  81. package/dist/src/utils/types.d.ts +4 -0
  82. package/dist/src/utils/types.js.map +1 -1
  83. package/lib/Constants.ts +6 -0
  84. package/lib/Helper/Wizard.ts +3 -0
  85. package/lib/Helper/__tests__/SentryCli.ts +2 -1
  86. package/lib/Steps/ChooseIntegration.ts +4 -0
  87. package/lib/Steps/Integrations/Apple.ts +27 -0
  88. package/lib/Steps/Integrations/NextJsShim.ts +1 -0
  89. package/lib/Steps/Integrations/SourceMapsShim.ts +2 -1
  90. package/lib/Steps/Integrations/SvelteKitShim.ts +1 -0
  91. package/package-lock.json +8910 -0
  92. package/package.json +2 -2
  93. package/src/apple/apple-wizard.ts +150 -0
  94. package/src/apple/code-tools.ts +81 -0
  95. package/src/apple/templates.ts +39 -0
  96. package/src/apple/xcode-manager.ts +147 -0
  97. package/src/nextjs/nextjs-wizard.ts +6 -10
  98. package/src/sourcemaps/sourcemaps-wizard.ts +211 -92
  99. package/src/sourcemaps/tools/angular.ts +42 -0
  100. package/src/sourcemaps/tools/esbuild.ts +1 -1
  101. package/src/sourcemaps/tools/rollup.ts +2 -4
  102. package/src/sourcemaps/tools/sentry-cli.ts +45 -27
  103. package/src/sourcemaps/tools/vite.ts +1 -1
  104. package/src/sourcemaps/tools/webpack.ts +1 -1
  105. package/src/sourcemaps/utils/detect-tool.ts +41 -0
  106. package/src/sourcemaps/utils/other-wizards.ts +148 -0
  107. package/src/sourcemaps/utils/sdk-version.ts +9 -16
  108. package/src/sveltekit/sdk-setup.ts +5 -2
  109. package/src/sveltekit/sveltekit-wizard.ts +1 -1
  110. package/src/sveltekit/templates.ts +1 -1
  111. package/src/telemetry.ts +8 -0
  112. package/src/utils/bash.ts +44 -0
  113. package/src/utils/clack-utils.ts +82 -51
  114. package/src/utils/package-json.ts +45 -0
  115. package/src/utils/types.ts +5 -0
@@ -9,12 +9,15 @@ import {
9
9
  askForSelfHosted,
10
10
  askForWizardLogin,
11
11
  confirmContinueEvenThoughNoGitRepo,
12
+ detectPackageManager,
13
+ SENTRY_DOT_ENV_FILE,
12
14
  printWelcome,
15
+ SENTRY_CLI_RC_FILE,
13
16
  } from '../utils/clack-utils';
14
17
  import { isUnicodeSupported } from '../utils/vendor/is-unicorn-supported';
15
18
  import { SourceMapUploadToolConfigurationOptions } from './tools/types';
16
19
  import { configureVitePlugin } from './tools/vite';
17
- import { configureSentryCLI } from './tools/sentry-cli';
20
+ import { setupNpmScriptInCI, configureSentryCLI } from './tools/sentry-cli';
18
21
  import { configureWebPackPlugin } from './tools/webpack';
19
22
  import { configureTscSourcemapGenerationFlow } from './tools/tsc';
20
23
  import { configureRollupPlugin } from './tools/rollup';
@@ -22,18 +25,26 @@ import { configureEsbuildPlugin } from './tools/esbuild';
22
25
  import { WizardOptions } from '../utils/types';
23
26
  import { configureCRASourcemapGenerationFlow } from './tools/create-react-app';
24
27
  import { ensureMinimumSdkVersionIsInstalled } from './utils/sdk-version';
25
-
26
- type SupportedTools =
27
- | 'webpack'
28
- | 'vite'
29
- | 'rollup'
30
- | 'esbuild'
31
- | 'tsc'
32
- | 'sentry-cli'
33
- | 'create-react-app';
28
+ import { traceStep, withTelemetry } from '../telemetry';
29
+ import { URL } from 'url';
30
+ import { checkIfMoreSuitableWizardExistsAndAskForRedirect } from './utils/other-wizards';
31
+ import { configureAngularSourcemapGenerationFlow } from './tools/angular';
32
+ import { detectUsedTool, SupportedTools } from './utils/detect-tool';
34
33
 
35
34
  export async function runSourcemapsWizard(
36
35
  options: WizardOptions,
36
+ ): Promise<void> {
37
+ return withTelemetry(
38
+ {
39
+ enabled: options.telemetryEnabled,
40
+ integration: 'sourcemaps',
41
+ },
42
+ () => runSourcemapsWizardWithTelemetry(options),
43
+ );
44
+ }
45
+
46
+ async function runSourcemapsWizardWithTelemetry(
47
+ options: WizardOptions,
37
48
  ): Promise<void> {
38
49
  printWelcome({
39
50
  wizardName: 'Sentry Source Maps Upload Configuration Wizard',
@@ -42,102 +53,75 @@ export async function runSourcemapsWizard(
42
53
  promoCode: options.promoCode,
43
54
  });
44
55
 
45
- await confirmContinueEvenThoughNoGitRepo();
46
-
47
- await ensureMinimumSdkVersionIsInstalled();
48
-
49
- const { url: sentryUrl, selfHosted } = await askForSelfHosted(options.url);
50
-
51
- const { projects, apiKeys } = await askForWizardLogin({
52
- promoCode: options.promoCode,
53
- url: sentryUrl,
54
- });
55
-
56
- const selectedProject = await askForProjectSelection(projects);
57
-
58
- const selectedTool = await askForUsedBundlerTool();
59
-
60
- Sentry.setTag('selected-tool', selectedTool);
61
-
62
- await startToolSetupFlow(selectedTool, {
63
- selfHosted,
64
- orgSlug: selectedProject.organization.slug,
65
- projectSlug: selectedProject.slug,
66
- url: sentryUrl,
67
- authToken: apiKeys.token,
68
- });
69
-
70
- clack.log.step(
71
- 'Add the Sentry authentication token as an environment variable to your CI setup:',
56
+ const moreSuitableWizard = await traceStep(
57
+ 'check-framework-wizard',
58
+ checkIfMoreSuitableWizardExistsAndAskForRedirect,
72
59
  );
60
+ if (moreSuitableWizard) {
61
+ await traceStep('run-framework-wizard', () => moreSuitableWizard(options));
62
+ return;
63
+ }
73
64
 
74
- // Intentially logging directly to console here so that the code can be copied/pasted directly
75
- // eslint-disable-next-line no-console
76
- console.log(
77
- chalk.greenBright(`
78
- SENTRY_AUTH_TOKEN=${apiKeys.token}
79
- `),
80
- );
65
+ await traceStep('detect-git', confirmContinueEvenThoughNoGitRepo);
81
66
 
82
- clack.log.warn(
83
- chalk.yellow('DO NOT commit this auth token to your repository!'),
67
+ await traceStep('check-sdk-version', ensureMinimumSdkVersionIsInstalled);
68
+
69
+ const { url: sentryUrl, selfHosted } = await traceStep(
70
+ 'ask-self-hosted',
71
+ () => askForSelfHosted(options.url),
84
72
  );
85
73
 
86
- const addedEnvVarToCI = await abortIfCancelled(
87
- clack.select({
88
- message: 'Did you configure CI as shown above?',
89
- options: [
90
- { label: 'Yes, continue!', value: true },
91
- {
92
- label: "I'll do it later...",
93
- value: false,
94
- hint: chalk.yellow(
95
- 'You need to set the auth token to upload source maps in CI',
96
- ),
97
- },
98
- ],
99
- initialValue: true,
74
+ const { projects, apiKeys } = await traceStep('login', () =>
75
+ askForWizardLogin({
76
+ promoCode: options.promoCode,
77
+ url: sentryUrl,
100
78
  }),
101
79
  );
102
80
 
103
- Sentry.setTag('added-env-var-to-ci', addedEnvVarToCI);
81
+ const selectedProject = await traceStep('select-project', () =>
82
+ askForProjectSelection(projects),
83
+ );
104
84
 
105
- if (!addedEnvVarToCI) {
106
- clack.log.info("Don't forget! :)");
107
- }
85
+ const selectedTool = await traceStep('select-tool', askForUsedBundlerTool);
108
86
 
109
- const arrow = isUnicodeSupported() ? '' : '->';
110
-
111
- clack.outro(`${chalk.green("That's it - everything is set up!")}
87
+ Sentry.setTag('selected-tool', selectedTool);
112
88
 
113
- ${chalk.cyan(`Validate your setup with the following Steps:
89
+ await traceStep('tool-setup', () =>
90
+ startToolSetupFlow(selectedTool, {
91
+ selfHosted,
92
+ orgSlug: selectedProject.organization.slug,
93
+ projectSlug: selectedProject.slug,
94
+ url: sentryUrl,
95
+ authToken: apiKeys.token,
96
+ }),
97
+ );
114
98
 
115
- 1. Build your application in ${chalk.bold('production mode')}.
116
- ${chalk.gray(
117
- `${arrow} You should see source map upload logs in your console.`,
118
- )}
119
- 2. Run your application and throw a test error.
120
- ${chalk.gray(`${arrow} The error should be visible in Sentry.`)}
121
- 3. Open the error in Sentry and verify that it's source-mapped.
122
- ${chalk.gray(
123
- `${arrow} The stack trace should show your original source code.`,
124
- )}
125
- `)}
126
- ${chalk.dim(
127
- `If you encounter any issues, please refer to the Troubleshooting Guide:
128
- https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js
99
+ await traceStep('ci-setup', () => configureCI(selectedTool, apiKeys.token));
129
100
 
130
- If the guide doesn't help or you encounter a bug, please let us know:
131
- https://github.com/getsentry/sentry-javascript/issues`,
132
- )}
133
- `);
101
+ traceStep('outro', () =>
102
+ printOutro(
103
+ sentryUrl,
104
+ selectedProject.organization.slug,
105
+ selectedProject.id,
106
+ ),
107
+ );
134
108
  }
135
109
 
136
110
  async function askForUsedBundlerTool(): Promise<SupportedTools> {
137
111
  const selectedTool: SupportedTools | symbol = await abortIfCancelled(
138
112
  clack.select({
139
- message: 'Which bundler or build tool are you using?',
113
+ message: 'Which framework, bundler or build tool are you using?',
140
114
  options: [
115
+ {
116
+ label: 'Angular',
117
+ value: 'angular',
118
+ hint: 'Select this option if you are using Angular.',
119
+ },
120
+ {
121
+ label: 'Create React App',
122
+ value: 'create-react-app',
123
+ hint: 'Select this option if you set up your app with Create React App.',
124
+ },
141
125
  {
142
126
  label: 'Webpack',
143
127
  value: 'webpack',
@@ -163,17 +147,13 @@ async function askForUsedBundlerTool(): Promise<SupportedTools> {
163
147
  value: 'tsc',
164
148
  hint: 'Configure source maps when using tsc as build tool',
165
149
  },
166
- {
167
- label: 'Create React App',
168
- value: 'create-react-app',
169
- hint: 'Select this option if you set up your app with Create React App.',
170
- },
171
150
  {
172
151
  label: 'None of the above',
173
152
  value: 'sentry-cli',
174
153
  hint: 'This will configure source maps upload for you using sentry-cli',
175
154
  },
176
155
  ],
156
+ initialValue: await detectUsedTool(),
177
157
  }),
178
158
  );
179
159
 
@@ -203,8 +183,147 @@ async function startToolSetupFlow(
203
183
  case 'create-react-app':
204
184
  await configureSentryCLI(options, configureCRASourcemapGenerationFlow);
205
185
  break;
186
+ case 'angular':
187
+ await configureSentryCLI(
188
+ options,
189
+ configureAngularSourcemapGenerationFlow,
190
+ );
191
+ break;
206
192
  default:
207
193
  await configureSentryCLI(options);
208
194
  break;
209
195
  }
210
196
  }
197
+
198
+ async function configureCI(
199
+ selectedTool: SupportedTools,
200
+ authToken: string,
201
+ ): Promise<void> {
202
+ const isUsingCI = await abortIfCancelled(
203
+ clack.select({
204
+ message: `Are you using a CI/CD tool to build and deploy your application?`,
205
+ options: [
206
+ {
207
+ label: 'Yes',
208
+ hint: 'I use a tool like Github Actions, Gitlab, CircleCI, TravisCI, Jenkins, ...',
209
+ value: true,
210
+ },
211
+ {
212
+ label: 'No',
213
+ hint: 'I build and deploy my application manually',
214
+ value: false,
215
+ },
216
+ ],
217
+ initialValue: true,
218
+ }),
219
+ );
220
+
221
+ Sentry.setTag('using-ci', isUsingCI);
222
+
223
+ const isCliBasedFlowTool = [
224
+ 'sentry-cli',
225
+ 'tsc',
226
+ 'angular',
227
+ 'create-react-app',
228
+ ].includes(selectedTool);
229
+
230
+ const authTokenFile = isCliBasedFlowTool
231
+ ? SENTRY_CLI_RC_FILE
232
+ : SENTRY_DOT_ENV_FILE;
233
+
234
+ if (!isUsingCI) {
235
+ clack.log.info(
236
+ `No Problem! Just make sure that the Sentry auth token from ${chalk.cyan(
237
+ authTokenFile,
238
+ )} is available whenever you build and deploy your app.`,
239
+ );
240
+ return;
241
+ }
242
+
243
+ if (isCliBasedFlowTool) {
244
+ await traceStep('ci-npm-script-setup', setupNpmScriptInCI);
245
+ }
246
+
247
+ await traceStep('ci-auth-token-setup', () => setupAuthTokenInCI(authToken));
248
+ }
249
+
250
+ async function setupAuthTokenInCI(authToken: string) {
251
+ clack.log.step(
252
+ 'Add the Sentry authentication token as an environment variable to your CI setup:',
253
+ );
254
+
255
+ // Intentially logging directly to console here so that the code can be copied/pasted directly
256
+ // eslint-disable-next-line no-console
257
+ console.log(
258
+ chalk.greenBright(`
259
+ SENTRY_AUTH_TOKEN=${authToken}
260
+ `),
261
+ );
262
+
263
+ clack.log.warn(
264
+ chalk.yellow('DO NOT commit this auth token to your repository!'),
265
+ );
266
+
267
+ const addedEnvVarToCI = await abortIfCancelled(
268
+ clack.select({
269
+ message: 'Did you configure CI as shown above?',
270
+ options: [
271
+ { label: 'Yes, continue!', value: true },
272
+ {
273
+ label: "I'll do it later...",
274
+ value: false,
275
+ hint: chalk.yellow(
276
+ 'You need to set the auth token to upload source maps in CI',
277
+ ),
278
+ },
279
+ ],
280
+ initialValue: true,
281
+ }),
282
+ );
283
+
284
+ Sentry.setTag('added-env-var-to-ci', addedEnvVarToCI);
285
+
286
+ if (!addedEnvVarToCI) {
287
+ clack.log.info("Don't forget! :)");
288
+ }
289
+ }
290
+
291
+ function printOutro(url: string, orgSlug: string, projectId: string) {
292
+ const pacMan = detectPackageManager() || 'npm';
293
+ const buildCommand = `'${pacMan}${pacMan === 'npm' ? ' run' : ''} build'`;
294
+
295
+ const urlObject = new URL(url);
296
+ urlObject.host = `${orgSlug}.${urlObject.host}`;
297
+ urlObject.pathname = '/issues/';
298
+ urlObject.searchParams.set('project', projectId);
299
+
300
+ const issueStreamUrl = urlObject.toString();
301
+
302
+ const arrow = isUnicodeSupported() ? '→' : '->';
303
+
304
+ clack.outro(`${chalk.green("That's it - everything is set up!")}
305
+
306
+ ${chalk.cyan(`Test and validate your setup locally with the following Steps:
307
+
308
+ 1. Build your application in ${chalk.bold('production mode')}.
309
+ ${chalk.gray(`${arrow} For example, run ${chalk.bold(buildCommand)}.`)}
310
+ ${chalk.gray(
311
+ `${arrow} You should see source map upload logs in your console.`,
312
+ )}
313
+ 2. Run your application and throw a test error.
314
+ ${chalk.gray(`${arrow} The error should appear in Sentry:`)}
315
+ ${chalk.gray(`${arrow} ${issueStreamUrl}`)}
316
+ 3. Open the error in Sentry and verify that it's source-mapped.
317
+ ${chalk.gray(
318
+ `${arrow} The stack trace should show your original source code.`,
319
+ )}
320
+ `)}
321
+ ${chalk.dim(
322
+ `If you encounter any issues, please refer to the Troubleshooting Guide:
323
+ https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js
324
+
325
+ If the guide doesn't help or you encounter a bug, please let us know:
326
+ https://github.com/getsentry/sentry-javascript/issues`,
327
+ )}
328
+ `);
329
+ }
@@ -0,0 +1,42 @@
1
+ // @ts-ignore - clack is ESM and TS complains about that. It works though
2
+ import clack from '@clack/prompts';
3
+ import chalk from 'chalk';
4
+ import { abortIfCancelled } from '../../utils/clack-utils';
5
+
6
+ const angularJsonTemplate = chalk.gray(`{
7
+ "projects": {
8
+ "your-project": {
9
+ "architect": {
10
+ "build": {
11
+ "options": {
12
+ ${chalk.greenBright(`"sourceMap": true`)}
13
+ },
14
+ },
15
+ }
16
+ }
17
+ }
18
+ }`);
19
+
20
+ export async function configureAngularSourcemapGenerationFlow(): Promise<void> {
21
+ clack.log.info(
22
+ `Enable generating source maps in your ${chalk.bold('angular.json')} file:`,
23
+ );
24
+
25
+ // Intentially logging directly to console here so that the code can be copied/pasted directly
26
+ // eslint-disable-next-line no-console
27
+ console.log(angularJsonTemplate);
28
+
29
+ await abortIfCancelled(
30
+ clack.select({
31
+ message: `Verify that you are generating source maps when building your Angular app.`,
32
+ options: [
33
+ {
34
+ label: 'I checked!',
35
+ hint: 'My build output folder contains .js.map files after a build.',
36
+ value: true,
37
+ },
38
+ ],
39
+ initialValue: true,
40
+ }),
41
+ );
42
+ }
@@ -5,9 +5,9 @@ import {
5
5
  abortIfCancelled,
6
6
  addDotEnvSentryBuildPluginFile,
7
7
  getPackageDotJson,
8
- hasPackageInstalled,
9
8
  installPackage,
10
9
  } from '../../utils/clack-utils';
10
+ import { hasPackageInstalled } from '../../utils/package-json';
11
11
 
12
12
  import {
13
13
  SourceMapUploadToolConfigurationFunction,
@@ -5,9 +5,9 @@ import {
5
5
  abortIfCancelled,
6
6
  addDotEnvSentryBuildPluginFile,
7
7
  getPackageDotJson,
8
- hasPackageInstalled,
9
8
  installPackage,
10
9
  } from '../../utils/clack-utils';
10
+ import { hasPackageInstalled } from '../../utils/package-json';
11
11
 
12
12
  import {
13
13
  SourceMapUploadToolConfigurationFunction,
@@ -49,9 +49,7 @@ export const configureRollupPlugin: SourceMapUploadToolConfigurationFunction =
49
49
  ),
50
50
  });
51
51
 
52
- clack.log.step(
53
- `Add the following code to your rollup config:`,
54
- );
52
+ clack.log.step(`Add the following code to your rollup config:`);
55
53
 
56
54
  // Intentially logging directly to console here so that the code can be copied/pasted directly
57
55
  // eslint-disable-next-line no-console
@@ -8,11 +8,13 @@ import {
8
8
  abortIfCancelled,
9
9
  addSentryCliRc,
10
10
  getPackageDotJson,
11
- hasPackageInstalled,
12
11
  installPackage,
13
12
  } from '../../utils/clack-utils';
14
13
 
15
14
  import { SourceMapUploadToolConfigurationOptions } from './types';
15
+ import { hasPackageInstalled, PackageDotJson } from '../../utils/package-json';
16
+
17
+ const NPM_SCRIPT_NAME = 'sentry:sourcemaps';
16
18
 
17
19
  export async function configureSentryCLI(
18
20
  options: SourceMapUploadToolConfigurationOptions,
@@ -72,37 +74,23 @@ export async function configureSentryCLI(
72
74
 
73
75
  await configureSourcemapGenerationFlow();
74
76
 
75
- packageDotJson.scripts = packageDotJson.scripts || {};
76
- packageDotJson.scripts['sentry:ci'] = `sentry-cli sourcemaps inject --org ${
77
- options.orgSlug
78
- } --project ${
79
- options.projectSlug
80
- } ${relativePosixArtifactPath} && sentry-cli${
81
- options.selfHosted ? ` --url ${options.url}` : ''
82
- } sourcemaps upload --org ${options.orgSlug} --project ${
83
- options.projectSlug
84
- } ${relativePosixArtifactPath}`;
85
-
86
- await fs.promises.writeFile(
87
- path.join(process.cwd(), 'package.json'),
88
- JSON.stringify(packageDotJson, null, 2),
77
+ await createAndAddNpmScript(
78
+ packageDotJson,
79
+ options,
80
+ relativePosixArtifactPath,
89
81
  );
90
82
 
91
- clack.log.info(
92
- `Added a ${chalk.cyan('sentry:ci')} script to your ${chalk.cyan(
93
- 'package.json',
94
- )}. Make sure to run this script ${chalk.bold(
95
- 'after',
96
- )} building your application but ${chalk.bold('before')} deploying!`,
97
- );
83
+ await addSentryCliRc(options.authToken);
84
+ }
98
85
 
86
+ export async function setupNpmScriptInCI(): Promise<void> {
99
87
  const addedToCI = await abortIfCancelled(
100
88
  clack.select({
101
- message: `Did you add a step to your CI pipeline that runs the ${chalk.cyan(
102
- 'sentry:ci',
103
- )} script ${chalk.bold('right after')} building your application?`,
89
+ message: `Add a step to your CI pipeline that runs the ${chalk.cyan(
90
+ NPM_SCRIPT_NAME,
91
+ )} script ${chalk.bold('right after')} building your application.`,
104
92
  options: [
105
- { label: 'Yes, continue!', value: true },
93
+ { label: 'I did, continue!', value: true },
106
94
  {
107
95
  label: "I'll do it later...",
108
96
  value: false,
@@ -120,8 +108,38 @@ export async function configureSentryCLI(
120
108
  if (!addedToCI) {
121
109
  clack.log.info("Don't forget! :)");
122
110
  }
111
+ }
123
112
 
124
- await addSentryCliRc(options.authToken);
113
+ async function createAndAddNpmScript(
114
+ packageDotJson: PackageDotJson,
115
+ options: SourceMapUploadToolConfigurationOptions,
116
+ relativePosixArtifactPath: string,
117
+ ): Promise<void> {
118
+ const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${
119
+ options.orgSlug
120
+ } --project ${
121
+ options.projectSlug
122
+ } ${relativePosixArtifactPath} && sentry-cli${
123
+ options.selfHosted ? ` --url ${options.url}` : ''
124
+ } sourcemaps upload --org ${options.orgSlug} --project ${
125
+ options.projectSlug
126
+ } ${relativePosixArtifactPath}`;
127
+
128
+ packageDotJson.scripts = packageDotJson.scripts || {};
129
+ packageDotJson.scripts[NPM_SCRIPT_NAME] = sentryCliNpmScript;
130
+
131
+ await fs.promises.writeFile(
132
+ path.join(process.cwd(), 'package.json'),
133
+ JSON.stringify(packageDotJson, null, 2),
134
+ );
135
+
136
+ clack.log.info(
137
+ `Added a ${chalk.cyan(NPM_SCRIPT_NAME)} script to your ${chalk.cyan(
138
+ 'package.json',
139
+ )}. Make sure to run this script ${chalk.bold(
140
+ 'after',
141
+ )} building your application but ${chalk.bold('before')} deploying!`,
142
+ );
125
143
  }
126
144
 
127
145
  async function defaultConfigureSourcemapGenerationFlow(): Promise<void> {
@@ -5,9 +5,9 @@ import {
5
5
  abortIfCancelled,
6
6
  addDotEnvSentryBuildPluginFile,
7
7
  getPackageDotJson,
8
- hasPackageInstalled,
9
8
  installPackage,
10
9
  } from '../../utils/clack-utils';
10
+ import { hasPackageInstalled } from '../../utils/package-json';
11
11
 
12
12
  import {
13
13
  SourceMapUploadToolConfigurationFunction,
@@ -5,9 +5,9 @@ import {
5
5
  abortIfCancelled,
6
6
  addDotEnvSentryBuildPluginFile,
7
7
  getPackageDotJson,
8
- hasPackageInstalled,
9
8
  installPackage,
10
9
  } from '../../utils/clack-utils';
10
+ import { hasPackageInstalled } from '../../utils/package-json';
11
11
 
12
12
  import {
13
13
  SourceMapUploadToolConfigurationFunction,
@@ -0,0 +1,41 @@
1
+ import { getPackageDotJson } from '../../utils/clack-utils';
2
+ import { findInstalledPackageFromList } from '../../utils/package-json';
3
+
4
+ export type SupportedTools =
5
+ | 'webpack'
6
+ | 'vite'
7
+ | 'rollup'
8
+ | 'esbuild'
9
+ | 'tsc'
10
+ | 'sentry-cli'
11
+ | 'create-react-app'
12
+ | 'angular';
13
+
14
+ // A map of package names pointing to the tool slug.
15
+ // The order is important, because we want to detect the most specific tool first.
16
+ // For instance, webpack needs to come before tsc because typescript c
17
+ // Similarly
18
+ export const TOOL_PACKAGE_MAP: Record<string, SupportedTools> = {
19
+ '@angular/core': 'angular',
20
+ 'create-react-app': 'create-react-app',
21
+ webpack: 'webpack',
22
+ vite: 'vite',
23
+ esbuild: 'esbuild',
24
+ rollup: 'rollup',
25
+ typescript: 'tsc',
26
+ };
27
+
28
+ export async function detectUsedTool(): Promise<SupportedTools> {
29
+ const packageJson = await getPackageDotJson();
30
+
31
+ const foundToolPackage = findInstalledPackageFromList(
32
+ Object.keys(TOOL_PACKAGE_MAP),
33
+ packageJson,
34
+ );
35
+
36
+ if (foundToolPackage) {
37
+ return TOOL_PACKAGE_MAP[foundToolPackage.name];
38
+ }
39
+
40
+ return 'sentry-cli';
41
+ }