-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
feat: Add Angular Wizard #741
base: master
Are you sure you want to change the base?
Conversation
|
8fc1561
to
542ea8a
Compare
CHANGELOG.md
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
## Unreleased | |||
|
|||
- feat: Add Angular Wizard ([#741](https://github.com/getsentry/sentry-wizard/pull/741)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: could you move this down please? these are ordered by ticket number.
src/angular/angular-wizard.ts
Outdated
options: WizardOptions, | ||
): Promise<void> { | ||
printWelcome({ | ||
wizardName: 'Sentry Remix Wizard', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wizardName: 'Sentry Remix Wizard', | |
wizardName: 'Sentry Angular Wizard', |
src/angular/angular-wizard.ts
Outdated
await installPackage({ | ||
packageName: '@sentry/angular@^8', | ||
packageNameDisplayLabel: '@sentry/angular', | ||
alreadyInstalled: hasPackageInstalled('@sentry/angular', packageJson), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: let's extract the alreadyInstalled
flag and log it:
Sentry.setTag('sdk-already-installed', sdkAlreadyInstalled);
src/angular/codemods/app-config.ts
Outdated
item.imported === '*' && | ||
item.local === 'Sentry', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Should be enough to just check the from
here.
src/angular/codemods/app-config.ts
Outdated
): void { | ||
const imports = originalAppConfigMod.imports; | ||
const hasErrorHandler = imports.$items.some( | ||
(item) => item.local === 'ErrorHandler', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Can we narrow down here and add && item.from: '@angular/core'
? I think this might be too wide.
src/angular/codemods/app-config.ts
Outdated
const imports = originalAppConfigMod.imports; | ||
|
||
const hasProvideAppInitializer = imports.$items.some( | ||
(item) => item.local === 'provideAppInitializer', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: I think we could also narrow down here a bit, although the function is already very specific.
src/angular/codemods/app-config.ts
Outdated
}); | ||
} | ||
|
||
const hasInject = imports.$items.some((item) => item.local === 'inject'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: and here, can we narrow down?
src/angular/codemods/app-config.ts
Outdated
const imports = originalAppConfigMod.imports; | ||
|
||
const hasAppInitializer = imports.$items.some( | ||
(item) => item.local === 'APP_INITIALIZER', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: could also narrow here, although might be specific enough already.
src/angular/sdk-setup.ts
Outdated
const originalAppModule = await loadFile(appModulePath); | ||
|
||
if (hasSentryContent(appModulePath, originalAppModule.$code)) { | ||
return; | ||
} | ||
|
||
const updatedAppModuleMod = updateAppModuleMod( | ||
originalAppModule, | ||
dsn, | ||
selectedFeatures, | ||
); | ||
|
||
await writeFile(updatedAppModuleMod.$ast, appModulePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: I think we need a try/catch around this and gracefully abort the wizard. A single typo in user's config would crash this.
clack.log.error( | ||
`Failed to update your app config ${chalk.cyan(appConfigFilename)}`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l/m: In the nuxt wizard, I specifically checked for MagicastError
here and logged out what users need to do to their config to make it work. Maybe something to consider here too if possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Onur! I left some comments that we should address. One thing we still need to handle is to at least abort gracefully if we detect an NGModule-based project. Right now, I don't think the wizard would handle this very well. What we can do is to heuristically search for an app.module.ts
file. The file name is just a convention though (users could name this file however they like) but probably a good enough one.
My gut feeling tells me that a big part (if not the majority) of Angular users will still use NGModules so we should think about finding a way to support these as well. We can take care of this in a follow-up PR though. For now, let's focus on printing good fallback instructions.
Also, let's add a if we encounter a module- or app-config-based setup so that we can gather some data if it's worth investing time into handling NGModules better.
The general path through the wizard should be to always show fallback instructions (link to docs, in-wizard code snippets) of how users can manually do what the wizard fails to do.
So from my PoV let's do the following in this PR:
- address all review comments
For us to follow up in future PRs (who does it TBD):
- example page
- handle NGModules if data agrees with my gut feeling
src/angular/angular-wizard.ts
Outdated
if (!installedAngularVersion) { | ||
clack.log.warn('Could not determine installed Angular version.'); | ||
|
||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Given that this might be our fault rather than a user-misconfiguration or similar, can we fall back to asking users for the version?
src/angular/angular-wizard.ts
Outdated
if (!installedMinVersion) { | ||
clack.log.warn('Could not determine minimum Angular version.'); | ||
|
||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the above, we shouldn't fall into this case, so we might as well remove it
clack.log.warn( | ||
`Angular version ${MIN_SUPPORTED_ANGULAR_VERSION} or higher is required.`, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Let's print the link to our version compatibility table in the docs (https://docs.sentry.io/platforms/javascript/guides/angular/#angular-version-compatibility) and tell them to find the suitable SDK version instead.
src/angular/angular-wizard.ts
Outdated
await traceStep('Inject Sentry to Angular app config', async () => { | ||
await initalizeSentryOnAppModule(dsn, selectedFeatures); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what we're doing here is not related to the "app config" or "app module" at all, but we rather init Sentry in main.ts
right? I'd rather call the the step and function something like app entry point or so. The "app module" makes this sound like it modifies app.module.ts
.
src/angular/angular-wizard.ts
Outdated
}); | ||
|
||
await traceStep('Setup for sourcemap uploads', async () => { | ||
addSourcemapEntryToAngularJSON(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Let's log a message that we modified angular.json
. I completely missed this when running the wizard (also related to my comment below).
options.url = sentryUrl; | ||
} | ||
|
||
await runSourcemapsWizard(options, 'angular'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Generally, running the source maps wizard here seems fine to me. I found the integration quite seamless. However, in the source maps wizard, there's a step where I need to verify that source maps are created. I think, given that within the wizard run, already enabled source maps emission, we might as well just skip this step. This probably requires some kind of new option in the source maps wizard. Feel free to add that as you see fit.
|
||
await runSourcemapsWizard(options, 'angular'); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Before we print the outro, let's call runPrettierIfInstalled()
to optionally reformat the project files.
src/angular/codemods/sourcemaps.ts
Outdated
if (!angularJson) { | ||
throw new Error('Could not find in angular.json in your project'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: If we end up here, let's provide users a fallback, which in this case is to manually enable source maps upload. 2 ideas:
- we link to docs
- we show the snippet that we show in the source maps wizard if there's no pre-selected project
const errorHandlerObject = b.objectExpression([ | ||
b.objectProperty( | ||
b.identifier('provide'), | ||
b.identifier('ErrorHandler'), | ||
), | ||
b.objectProperty( | ||
b.identifier('useValue'), | ||
b.identifier('Sentry.createErrorHandler()'), | ||
), | ||
]); | ||
|
||
providers.elements.push( | ||
// @ts-expect-error - errorHandlerObject is an objectExpression | ||
errorHandlerObject, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Angular only permits one ErrorHandler per application. We need to check if users already declared one and if so, let's not add an additional one but link to our docs how to combine their handler with ours: https://docs.sentry.io/platforms/javascript/guides/angular/features/error-handler/
@andreiborza and I commented on the same line and discussed offline with which suggestion to go with. I just removed the comments to avoid confusion :) |
93acb01
to
96b4a25
Compare
96b4a25
to
e872236
Compare
message: 'Please enter the installed Angular version:', | ||
validate(value) { | ||
if (!value) { | ||
return 'Please enter the installed Angular version.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: As a user, I'd wonder what kind of answer format you want here. Could you add en example here, for example: Please enter your installed Angular version (e.g. chalk.cyan(18.4.5))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The major is enough though, right? Finding the specific minor/patch might be tricky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, if we're fine with major that's ok too but I think the point still stands that I'd want some guideline on what kind of answer you expect from me as a user. So we could just say (e.g. chalk.cyan(18) for version 18)? Something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, sounds good!
Resolves: #672
Adds wizard for Angular projects
Notes: