Repository navigation
feat(cli): add Nuxt and Angular to sentry wizard #2525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+5,556
−12
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
949060d
feat(cli): add sentry wizard with Next.js
sentry-junior[bot] 76e162b
feat(cli): add the wizard's shared AST and URL helpers
sentry-junior[bot] 0113841
feat(cli): reject the wizard's removed sign-up flags
sentry-junior[bot] 7e5f894
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] 16e6189
feat(cli): add Nuxt and Angular to sentry wizard
sentry-junior[bot] e7dd1c0
Merge origin/feat/cli-wizard-shared-ast-helpers into feat/cli-wizard-…
sentry-junior[bot] 59a1bd9
feat(cli): read wizard source map upload target from .sentryclirc
sentry-junior[bot] 58d673b
docs(cli): say why the wizard keeps the self-hosted URL out of .sentr…
sentry-junior[bot] 39e20d5
fix(cli): address review findings in sentry wizard
sentry-junior[bot] c4786b3
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] 09983d3
fix(cli): address Warden findings in the Nuxt and Angular wizards
sentry-junior[bot] e03e53f
feat(cli): list only the auth token for sentry.io CI, write self-host…
sentry-junior[bot] 2c98751
refactor(cli): reuse existing CLI helpers in the wizard AST utils
sentry-junior[bot] f9c9aa3
fix(cli): address second round of Warden findings in Nuxt and Angular…
sentry-junior[bot] ac6b75d
feat(cli): use positionals and existing CLI flags in sentry wizard
sentry-junior[bot] 75cda0c
Merge remote-tracking branch 'origin/feat/cli-wizard-shared-ast-helpe…
sentry-junior[bot] 4c93aa8
fix(cli): use the credential host for the project issues URL
sentry-junior[bot] d6a1c81
Merge remote-tracking branch 'origin/feat/cli-wizard-shared-ast-helpe…
sentry-junior[bot] bee2d24
fix(cli): build on the new wizard base: use buildProjectIssuesUrl and…
sentry-junior[bot] 2f2f91a
fix(mcp): regenerate the chart app after the for…of conversion
sentry-junior[bot] f0a48de
Merge remote-tracking branch 'origin/feat/cli-wizard-scaffold' into f…
sentry-junior[bot] 22c2b66
Merge commit 'f0a48dee68470690517ba652f224f6f6f8587528' into feat/cli…
sentry-junior[bot] 2e2f2ec
fix(cli): update the Nuxt and Angular wizards for the new wizard base
sentry-junior[bot] 1605587
docs(cli): correct the CI env vars for the Angular wizard
sentry-junior[bot] bb4886f
fix(cli): address third round of Warden findings in Nuxt and Angular …
sentry-junior[bot] f5ca46e
fix(cli): reconcile sentry-cli.ts and quote source map paths
sentry-junior[bot] f018d0a
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-nuxt-…
sentry-junior[bot] 7399ac7
fix(cli): catch unparseable app.config.ts and version specifiers in A…
sentry-junior[bot] d1093f3
fix(cli): fall back to manual setup when the Angular app config has n…
sentry-junior[bot] da1234c
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-nuxt-…
sentry-junior[bot] 370f74d
fix(cli): harden the Nuxt and Angular wizards from review findings
sentry-junior[bot] 8a72642
fix(cli): use the root srcDir for Nuxt 4 projects with a root app.vue
sentry-junior[bot] 7020018
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-nuxt-…
sentry-junior[bot] b60da74
fix(cli): drop the redundant inject step from the sentry:sourcemaps s…
sentry-junior[bot] 3d5522d
docs(cli): say the wizard's source map script only runs the upload
sentry-junior[bot] 8416233
fix(cli): install the sentry CLI major the wizard runs on
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,311 @@ | ||
| /** | ||
| * The Angular setup wizard: installs `@sentry/angular`, initializes it in | ||
| * `src/main.ts`, adds the Sentry providers to the app config, turns on | ||
| * source maps in `angular.json`, sets up their upload with `sentry | ||
| * sourcemap` commands, and optionally creates an example component. | ||
| */ | ||
|
|
||
| import path from "node:path"; | ||
| import chalk from "chalk"; | ||
| import { gte } from "semver"; | ||
| import { setupCI } from "../sourcemaps/ci.js"; | ||
| import { configureAngularSourcemapGenerationFlow } from "../sourcemaps/tools/angular.js"; | ||
| import { configureSentryCLI } from "../sourcemaps/tools/sentry-cli.js"; | ||
| import { Sentry, traceStep, withTelemetry } from "../telemetry.js"; | ||
| import { abortIfSpotlightNotSupported } from "../utils/abort-if-sportlight-not-supported.js"; | ||
| import { | ||
| abort, | ||
| abortIfCancelled, | ||
| askShouldCreateExampleComponent, | ||
| confirmContinueIfNoOrDirtyGitRepo, | ||
| ensurePackageIsInstalled, | ||
| featureSelectionPrompt, | ||
| getOrAskForProjectData, | ||
| getPackageDotJson, | ||
| installPackage, | ||
| printSdkV11MigrationGuideIfOutdated, | ||
| printWelcome, | ||
| runPrettierIfInstalled, | ||
| } from "../utils/clack/index.js"; | ||
| import { offerProjectScopedMcpConfig } from "../utils/clack/mcp-config.js"; | ||
| import { clack } from "../utils/clack/prompts.js"; | ||
| import { | ||
| askShouldReduceDataCollection, | ||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
| sdkSupportsDataCollection, | ||
| } from "../utils/data-collection.js"; | ||
| import { warnIfNodeVersionUnsupportedBySdkV11 } from "../utils/node-version.js"; | ||
| import { | ||
| getPackageVersion, | ||
| hasPackageInstalled, | ||
| } from "../utils/package-json.js"; | ||
| import { safeMinVersion } from "../utils/semver.js"; | ||
| import type { WizardOptions } from "../utils/types.js"; | ||
| import { addSourcemapEntryToAngularJSON } from "./codemods/sourcemaps.js"; | ||
| import { createExampleComponent } from "./example-component.js"; | ||
| import { | ||
| initializeSentryOnApplicationEntry, | ||
| updateAppConfig, | ||
| } from "./sdk-setup.js"; | ||
|
|
||
| const MIN_SUPPORTED_ANGULAR_VERSION = "14.0.0"; | ||
| const MIN_SUPPORTED_WIZARD_ANGULAR_VERSION = "17.0.0"; | ||
|
|
||
| /** Run the Angular wizard (`sentry wizard angular`). */ | ||
| export async function runAngularWizard(options: WizardOptions): Promise<void> { | ||
| return await withTelemetry( | ||
| { | ||
| enabled: options.telemetryEnabled, | ||
| integration: "angular", | ||
| wizardOptions: options, | ||
| }, | ||
| () => runAngularWizardWithTelemetry(options), | ||
| ); | ||
| } | ||
|
|
||
| async function runAngularWizardWithTelemetry( | ||
| options: WizardOptions, | ||
| ): Promise<void> { | ||
| printWelcome({ | ||
| wizardName: "Sentry Angular Wizard", | ||
| telemetryEnabled: options.telemetryEnabled, | ||
| }); | ||
|
|
||
| warnIfNodeVersionUnsupportedBySdkV11(); | ||
|
|
||
| await confirmContinueIfNoOrDirtyGitRepo({ | ||
| ignoreGitChanges: options.ignoreGitChanges, | ||
| cwd: undefined, | ||
| }); | ||
|
|
||
| const packageJson = await getPackageDotJson(); | ||
|
|
||
| await ensurePackageIsInstalled(packageJson, "@angular/core", "Angular"); | ||
|
|
||
| let installedAngularVersion = getPackageVersion("@angular/core", packageJson); | ||
|
|
||
| if (!installedAngularVersion) { | ||
| clack.log.warn("Could not determine installed Angular version."); | ||
|
|
||
| installedAngularVersion = await abortIfCancelled( | ||
| clack.text({ | ||
| message: `Please enter your installed Angular major version (e.g. ${chalk.cyan( | ||
| "18", | ||
| )} for Angular 18)`, | ||
| validate(value) { | ||
| if (!value) { | ||
| return "Angular version is required"; | ||
| } | ||
|
|
||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
| if (!safeMinVersion(value)) { | ||
| return `Invalid Angular version provided: ${value}`; | ||
| } | ||
| return undefined; | ||
| }, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| Sentry.setTag("angular-version", installedAngularVersion); | ||
|
|
||
| const installedMinVersion = safeMinVersion(installedAngularVersion); | ||
| if (!installedMinVersion) { | ||
| clack.log.warn( | ||
| `Could not parse the Angular version ${chalk.cyan(installedAngularVersion)}.`, | ||
| ); | ||
| return await abort("Exiting the wizard."); | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| const sdkSupportsAngularVersion = gte( | ||
| installedMinVersion, | ||
| MIN_SUPPORTED_ANGULAR_VERSION, | ||
| ); | ||
|
|
||
| const wizardSupportsAngularVersion = gte( | ||
| installedMinVersion, | ||
| MIN_SUPPORTED_WIZARD_ANGULAR_VERSION, | ||
| ); | ||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| if (!sdkSupportsAngularVersion) { | ||
| Sentry.setTag("angular-version-compatible", false); | ||
|
|
||
| clack.log.warn( | ||
| `Angular version ${chalk.cyan( | ||
| MIN_SUPPORTED_ANGULAR_VERSION, | ||
| )} or higher is required for the Sentry SDK.`, | ||
| ); | ||
| clack.log.warn( | ||
| `Please refer to Sentry's version compatibility table for more information: | ||
|
|
||
| ${chalk.underline( | ||
| "https://docs.sentry.io/platforms/javascript/guides/angular/#angular-version-compatibility", | ||
| )} | ||
| `, | ||
| ); | ||
|
|
||
| return await abort("Exiting the wizard.", 0); | ||
| } | ||
|
|
||
| if (!wizardSupportsAngularVersion) { | ||
| Sentry.setTag("angular-wizard-version-compatible", false); | ||
|
|
||
| clack.log.warn( | ||
| `The Sentry Angular Wizard requires Angular version ${chalk.cyan( | ||
| MIN_SUPPORTED_WIZARD_ANGULAR_VERSION, | ||
| )} or higher.`, | ||
| ); | ||
| clack.log.warn( | ||
| `Your Angular version (${installedAngularVersion}) is compatible with the Sentry SDK but you need to set it up manually by following our documentation: | ||
|
|
||
| ${chalk.underline("https://docs.sentry.io/platforms/javascript/guides/angular")} | ||
|
|
||
| Apologies for the inconvenience!`, | ||
| ); | ||
|
|
||
| return await abort("Exiting the wizard.", 0); | ||
| } | ||
|
|
||
| const projectData = await getOrAskForProjectData( | ||
| options, | ||
| "javascript-angular", | ||
| ); | ||
|
|
||
| if (projectData.spotlight) { | ||
| return await abortIfSpotlightNotSupported("Angular"); | ||
| } | ||
|
|
||
| const { selectedProject, authToken, sentryUrl, selfHosted } = projectData; | ||
|
|
||
| const dsn = selectedProject.keys[0].dsn.public; | ||
|
|
||
| const sdkAlreadyInstalled = hasPackageInstalled( | ||
| "@sentry/angular", | ||
| packageJson, | ||
| ); | ||
|
|
||
| Sentry.setTag("sdk-already-installed", sdkAlreadyInstalled); | ||
|
|
||
| printSdkV11MigrationGuideIfOutdated("@sentry/angular", packageJson); | ||
|
|
||
| await installPackage({ | ||
| packageName: "@sentry/angular@^11", | ||
| packageNameDisplayLabel: "@sentry/angular", | ||
| alreadyInstalled: sdkAlreadyInstalled, | ||
| forceInstall: options.forceInstall, | ||
| }); | ||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| // The install may have been skipped (user declined the update prompt), so | ||
| // re-read package.json to learn which SDK major is actually installed. | ||
| const installedSdkVersion = getPackageVersion( | ||
| "@sentry/angular", | ||
| await getPackageDotJson(), | ||
| ); | ||
|
|
||
| // From v11 on, the SDK collects rich context by default, so offer to | ||
| // reduce collection of data that can identify users. | ||
| const reduceDataCollection = | ||
| sdkSupportsDataCollection(installedSdkVersion, "^11") && | ||
| (await askShouldReduceDataCollection()); | ||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| const selectedFeatures = await featureSelectionPrompt([ | ||
| { | ||
| id: "performance", | ||
| prompt: `Do you want to enable ${chalk.bold( | ||
| "Tracing", | ||
| )} to track the performance of your application?`, | ||
| enabledHint: "recommended", | ||
| }, | ||
| { | ||
| id: "replay", | ||
| prompt: `Do you want to enable ${chalk.bold( | ||
| "Session Replay", | ||
| )} to get a video-like reproduction of errors during a user session?`, | ||
| enabledHint: "recommended, but increases bundle size", | ||
| }, | ||
| ] as const); | ||
|
|
||
| await traceStep( | ||
| "Initialize Sentry on Angular application entry point", | ||
| async () => { | ||
| await initializeSentryOnApplicationEntry( | ||
| dsn, | ||
| selectedFeatures, | ||
| reduceDataCollection, | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| await traceStep("Update Angular project configuration", async () => { | ||
| await updateAppConfig(installedMinVersion, selectedFeatures.performance); | ||
| }); | ||
|
|
||
| await traceStep("Setup for sourcemap uploads", async () => { | ||
| await addSourcemapEntryToAngularJSON(); | ||
|
|
||
| // sentry-wizard ran its source maps wizard with the Angular tool | ||
| // preselected here. Its other steps (redirect to a framework wizard, SDK | ||
| // version check, project selection) are already done by this point, so | ||
| // run the Angular tool setup and the CI step directly. | ||
| await configureSentryCLI( | ||
| { | ||
| orgSlug: selectedProject.organization.slug, | ||
| projectSlug: selectedProject.slug, | ||
| selfHosted, | ||
| url: sentryUrl, | ||
| authToken, | ||
| defaultArtifactPath: `.${path.sep}dist`, | ||
| forceInstall: options.forceInstall, | ||
| }, | ||
| configureAngularSourcemapGenerationFlow, | ||
| true, | ||
| ); | ||
|
|
||
| await setupCI("angular", authToken, { | ||
| org: selectedProject.organization.slug, | ||
| project: selectedProject.slug, | ||
| url: selfHosted ? sentryUrl : undefined, | ||
| }); | ||
| }); | ||
|
|
||
| const shouldCreateExampleComponent = await askShouldCreateExampleComponent(); | ||
|
|
||
| Sentry.setTag("create-example-component", shouldCreateExampleComponent); | ||
|
|
||
| if (shouldCreateExampleComponent) { | ||
| await traceStep( | ||
| "create-example-component", | ||
| async () => | ||
| await createExampleComponent({ | ||
| orgSlug: selectedProject.organization.slug, | ||
| projectId: selectedProject.id, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| await traceStep("Run Prettier", async () => { | ||
| await runPrettierIfInstalled({ cwd: undefined }); | ||
| }); | ||
|
|
||
| // Offer optional project-scoped MCP config for Sentry with org and project scope | ||
| await offerProjectScopedMcpConfig( | ||
| selectedProject.organization.slug, | ||
| selectedProject.slug, | ||
| ); | ||
|
|
||
| clack.outro(buildOutroMessage(shouldCreateExampleComponent)); | ||
| } | ||
|
|
||
| /** The closing message, with how to test the example component if one was created. */ | ||
| export function buildOutroMessage(createdExampleComponent: boolean): string { | ||
| let msg = chalk.green("Successfully installed the Sentry Angular SDK!"); | ||
|
|
||
| if (createdExampleComponent) { | ||
| msg += `\n\nYou can validate your setup by starting your dev environment (${chalk.cyan( | ||
| "ng serve", | ||
| )}) and throwing an error in the example component.`; | ||
| } | ||
|
|
||
| msg += `\n\nCheck out the SDK documentation for further configuration: | ||
| https://docs.sentry.io/platforms/javascript/guides/angular/`; | ||
|
|
||
| return msg; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.