@sentry/wizard 3.6.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.
@@ -16,6 +16,9 @@ const opn = require('opn') as (
16
16
  url: string,
17
17
  ) => Promise<childProcess.ChildProcess>;
18
18
 
19
+ export const SENTRY_DOT_ENV_FILE = '.env.sentry-build-plugin';
20
+ export const SENTRY_CLI_RC_FILE = '.sentryclirc';
21
+
19
22
  const SAAS_URL = 'https://sentry.io/';
20
23
 
21
24
  interface WizardProjectData {
@@ -127,9 +130,12 @@ export async function confirmContinueEvenThoughNoGitRepo(): Promise<void> {
127
130
  }
128
131
 
129
132
  export async function askToInstallSentryCLI(): Promise<boolean> {
130
- return await abortIfCancelled(clack.confirm({
131
- message: "You don't have Sentry CLI installed. Do you want to install it?"
132
- }));
133
+ return await abortIfCancelled(
134
+ clack.confirm({
135
+ message:
136
+ "You don't have Sentry CLI installed. Do you want to install it?",
137
+ }),
138
+ );
133
139
  }
134
140
 
135
141
  export async function askForWizardLogin(options: {
@@ -188,7 +194,8 @@ export async function askForWizardLogin(options: {
188
194
  const urlToOpen = loginUrl.toString();
189
195
  clack.log.info(
190
196
  `${chalk.bold(
191
- `If the browser window didn't open automatically, please open the following link to ${hasSentryAccount ? 'log' : 'sign'
197
+ `If the browser window didn't open automatically, please open the following link to ${
198
+ hasSentryAccount ? 'log' : 'sign'
192
199
  } into Sentry:`,
193
200
  )}\n\n${chalk.cyan(urlToOpen)}`,
194
201
  );
@@ -235,19 +242,23 @@ export async function askForWizardLogin(options: {
235
242
  return data;
236
243
  }
237
244
 
238
- export async function askForItemSelection(items: string[], message: string): Promise<{ value: string, index: number }> {
239
- const selection: { value: string, index: number } | symbol = await abortIfCancelled(
240
- windowedSelect({
241
- maxItems: 12,
242
- message: message,
243
- options: items.map((item, index) => {
244
- return {
245
- value: { value: item, index: index },
246
- label: item,
247
- };
245
+ export async function askForItemSelection(
246
+ items: string[],
247
+ message: string,
248
+ ): Promise<{ value: string; index: number }> {
249
+ const selection: { value: string; index: number } | symbol =
250
+ await abortIfCancelled(
251
+ windowedSelect({
252
+ maxItems: 12,
253
+ message: message,
254
+ options: items.map((item, index) => {
255
+ return {
256
+ value: { value: item, index: index },
257
+ label: item,
258
+ };
259
+ }),
248
260
  }),
249
- }),
250
- );
261
+ );
251
262
 
252
263
  return selection;
253
264
  }
@@ -378,8 +389,9 @@ export async function askForSelfHosted(urlFromArgs?: string): Promise<{
378
389
  tmpUrlFromArgs ||
379
390
  (await abortIfCancelled(
380
391
  clack.text({
381
- message: `Please enter the URL of your ${urlFromArgs ? '' : 'self-hosted '
382
- }Sentry instance.`,
392
+ message: `Please enter the URL of your ${
393
+ urlFromArgs ? '' : 'self-hosted '
394
+ }Sentry instance.`,
383
395
  placeholder: 'https://sentry.io/',
384
396
  }),
385
397
  ));
@@ -408,10 +420,12 @@ export async function askForSelfHosted(urlFromArgs?: string): Promise<{
408
420
  }
409
421
 
410
422
  export async function addSentryCliRc(authToken: string): Promise<void> {
411
- const clircExists = fs.existsSync(path.join(process.cwd(), '.sentryclirc'));
423
+ const clircExists = fs.existsSync(
424
+ path.join(process.cwd(), SENTRY_CLI_RC_FILE),
425
+ );
412
426
  if (clircExists) {
413
427
  const clircContents = fs.readFileSync(
414
- path.join(process.cwd(), '.sentryclirc'),
428
+ path.join(process.cwd(), SENTRY_CLI_RC_FILE),
415
429
  'utf8',
416
430
  );
417
431
 
@@ -422,25 +436,25 @@ export async function addSentryCliRc(authToken: string): Promise<void> {
422
436
  if (likelyAlreadyHasAuthToken) {
423
437
  clack.log.warn(
424
438
  `${chalk.bold(
425
- '.sentryclirc',
439
+ SENTRY_CLI_RC_FILE,
426
440
  )} already has auth token. Will not add one.`,
427
441
  );
428
442
  } else {
429
443
  try {
430
444
  await fs.promises.writeFile(
431
- path.join(process.cwd(), '.sentryclirc'),
445
+ path.join(process.cwd(), SENTRY_CLI_RC_FILE),
432
446
  `${clircContents}\n[auth]\ntoken=${authToken}\n`,
433
447
  { encoding: 'utf8', flag: 'w' },
434
448
  );
435
449
  clack.log.success(
436
450
  `Added auth token to ${chalk.bold(
437
- '.sentryclirc',
451
+ SENTRY_CLI_RC_FILE,
438
452
  )} for you to test uploading source maps locally.`,
439
453
  );
440
454
  } catch {
441
455
  clack.log.warning(
442
456
  `Failed to add auth token to ${chalk.bold(
443
- '.sentryclirc',
457
+ SENTRY_CLI_RC_FILE,
444
458
  )}. Uploading source maps during build will likely not work locally.`,
445
459
  );
446
460
  }
@@ -448,32 +462,30 @@ export async function addSentryCliRc(authToken: string): Promise<void> {
448
462
  } else {
449
463
  try {
450
464
  await fs.promises.writeFile(
451
- path.join(process.cwd(), '.sentryclirc'),
465
+ path.join(process.cwd(), SENTRY_CLI_RC_FILE),
452
466
  `[auth]\ntoken=${authToken}\n`,
453
467
  { encoding: 'utf8', flag: 'w' },
454
468
  );
455
469
  clack.log.success(
456
470
  `Created ${chalk.bold(
457
- '.sentryclirc',
471
+ SENTRY_CLI_RC_FILE,
458
472
  )} with auth token for you to test uploading source maps locally.`,
459
473
  );
460
474
  } catch {
461
475
  clack.log.warning(
462
476
  `Failed to create ${chalk.bold(
463
- '.sentryclirc',
477
+ SENTRY_CLI_RC_FILE,
464
478
  )} with auth token. Uploading source maps during build will likely not work locally.`,
465
479
  );
466
480
  }
467
481
  }
468
482
 
469
- await addAuthTokenFileToGitIgnore('.sentryclirc');
483
+ await addAuthTokenFileToGitIgnore(SENTRY_CLI_RC_FILE);
470
484
  }
471
485
 
472
486
  export async function addDotEnvSentryBuildPluginFile(
473
487
  authToken: string,
474
488
  ): Promise<void> {
475
- const DOT_ENV_FILE = '.env.sentry-build-plugin';
476
-
477
489
  const envVarContent = `# DO NOT commit this file to your repository!
478
490
  # The SENTRY_AUTH_TOKEN variable is picked up by the Sentry Build Plugin.
479
491
  # It's used for authentication when uploading source maps.
@@ -481,7 +493,7 @@ export async function addDotEnvSentryBuildPluginFile(
481
493
  SENTRY_AUTH_TOKEN="${authToken}"
482
494
  `;
483
495
 
484
- const dotEnvFilePath = path.join(process.cwd(), DOT_ENV_FILE);
496
+ const dotEnvFilePath = path.join(process.cwd(), SENTRY_DOT_ENV_FILE);
485
497
  const dotEnvFileExists = fs.existsSync(dotEnvFilePath);
486
498
 
487
499
  if (dotEnvFileExists) {
@@ -493,7 +505,9 @@ SENTRY_AUTH_TOKEN="${authToken}"
493
505
 
494
506
  if (hasAuthToken) {
495
507
  clack.log.warn(
496
- `${chalk.bold(DOT_ENV_FILE)} already has auth token. Will not add one.`,
508
+ `${chalk.bold(
509
+ SENTRY_DOT_ENV_FILE,
510
+ )} already has auth token. Will not add one.`,
497
511
  );
498
512
  } else {
499
513
  try {
@@ -505,11 +519,13 @@ SENTRY_AUTH_TOKEN="${authToken}"
505
519
  flag: 'w',
506
520
  },
507
521
  );
508
- clack.log.success(`Added auth token to ${chalk.bold(DOT_ENV_FILE)}`);
522
+ clack.log.success(
523
+ `Added auth token to ${chalk.bold(SENTRY_DOT_ENV_FILE)}`,
524
+ );
509
525
  } catch {
510
526
  clack.log.warning(
511
527
  `Failed to add auth token to ${chalk.bold(
512
- DOT_ENV_FILE,
528
+ SENTRY_DOT_ENV_FILE,
513
529
  )}. Uploading source maps during build will likely not work locally.`,
514
530
  );
515
531
  }
@@ -522,19 +538,19 @@ SENTRY_AUTH_TOKEN="${authToken}"
522
538
  });
523
539
  clack.log.success(
524
540
  `Created ${chalk.bold(
525
- DOT_ENV_FILE,
541
+ SENTRY_DOT_ENV_FILE,
526
542
  )} with auth token for you to test source map uploading locally.`,
527
543
  );
528
544
  } catch {
529
545
  clack.log.warning(
530
546
  `Failed to create ${chalk.bold(
531
- DOT_ENV_FILE,
547
+ SENTRY_DOT_ENV_FILE,
532
548
  )} with auth token. Uploading source maps during build will likely not work locally.`,
533
549
  );
534
550
  }
535
551
  }
536
552
 
537
- await addAuthTokenFileToGitIgnore(DOT_ENV_FILE);
553
+ await addAuthTokenFileToGitIgnore(SENTRY_DOT_ENV_FILE);
538
554
  }
539
555
 
540
556
  async function addAuthTokenFileToGitIgnore(filename: string): Promise<void> {
@@ -637,3 +653,11 @@ export function detectPackageManager(): 'yarn' | 'npm' | 'pnpm' | undefined {
637
653
  }
638
654
  return undefined;
639
655
  }
656
+
657
+ export function isUsingTypeScript() {
658
+ try {
659
+ return fs.existsSync(path.join(process.cwd(), 'tsconfig.json'));
660
+ } catch {
661
+ return false;
662
+ }
663
+ }