-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(material/schematics): support standalone components in ng-add #24931
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
Conversation
Adds code to handle apps that are bootstrapped through `bootstrapApplication` instead of `bootstrapModule`.
c0cc4f6
to
c74413f
Compare
if (importsProvidersFrom(host, mainFile, noopAnimationsModuleName)) { | ||
context.logger.error( | ||
`Could not set up "${browserAnimationsModuleName}" ` + | ||
`because "${noopAnimationsModuleName}" is already imported.`, |
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.
nit: can we include information on where the NoopAnimationsModule
is imported?
`because "${noopAnimationsModuleName}" is already imported.`, | |
`because "${noopAnimationsModuleName}" is already imported into ` + | |
`the "${...}" NgModule.`, |
try { | ||
addAnimationsModuleToNonStandaloneApp(host, project, context, options); | ||
} catch (e) { | ||
if (e instanceof SchematicsException && e.message.includes('Bootstrap call not found')) { |
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.
@crisbeto quick question: is there a situation now when the Bootstrap call not found
is thrown? If that's the case, may be we can try to improve the messaging there as well (just change the content)?
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.
It comes from the vendored utilities from the CLI repo. I'd rather avoid changing the message here since it'll be reset whenever they're updated. The only case where this will be thrown is if the main file doesn't have a bootstrapModule
or bootstrapApplication
call at all.
@@ -227,6 +227,52 @@ describe('ng-add schematic', () => { | |||
expect(errorOutput.length).toBe(1); | |||
expect(errorOutput[0]).toMatch(/Could not set up "BrowserAnimationsModule"/); | |||
}); | |||
|
|||
it('should add the BrowserAnimationsModule to a bootstrapApplication call', async () => { | |||
appTree.delete('/projects/material/src/app/app.module.ts'); |
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.
question: why do we need to delete this file?
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.
We don't, but I figured that if we had a --standalone
option for ng new
, this file wouldn't exist so I wanted the test to be as close as possible to the "real thing".
try { | ||
addAnimationsModuleToNonStandaloneApp(host, project, context, options); | ||
} catch (e) { | ||
if (e instanceof SchematicsException && e.message.includes('Bootstrap call not found')) { |
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'm worried that "sniffing" on the exception + its error message is rather fragile (will break any time someone decides to alter the error message). Could we have a specific exception type for this case? Or some other reliable way detecting what is going on?
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'm not a fan of it either, but I was trying to avoid changing any of the vendored schematic utilities. We have unit tests for this so if the message changes and the check doesn't hold anymore, we'll know about it.
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.
Yeah, I guess this comes down to the common utils at some point, but for now seems fine.
@@ -9,6 +9,9 @@ integration/ng-update-v13/node_modules | |||
integration/ng-add/.angular | |||
integration/ng-add/node_modules | |||
|
|||
integration/ng-add-standalone/.angular | |||
integration/ng-add-standalone/node_modules | |||
|
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.
Thx for adding it here!
… private export for Angular components The standalone component helper utilities introduced into the `@angular/cdk` via angular/components#24931 have been added to an export path (`private/components`) within `@schematics/angular`. The export path is primarily intended for the use of the components schematics within `@angular/cdk` and `@angular/material`. The API exported from this path is not considered public API, does not provide SemVer guarantees, and may be modified or removed without a deprecation cycle.
… private export for Angular components The standalone component helper utilities introduced into the `@angular/cdk` via angular/components#24931 have been added to an export path (`private/components`) within `@schematics/angular`. The export path is primarily intended for the use of the components schematics within `@angular/cdk` and `@angular/material`. The API exported from this path is not considered public API, does not provide SemVer guarantees, and may be modified or removed without a deprecation cycle.
… private export for Angular components The standalone component helper utilities introduced into the `@angular/cdk` via angular/components#24931 have been added to an export path (`private/components`) within `@schematics/angular`. The export path is primarily intended for the use of the components schematics within `@angular/cdk` and `@angular/material`. The API exported from this path is not considered public API, does not provide SemVer guarantees, and may be modified or removed without a deprecation cycle.
… private export for Angular components The standalone component helper utilities introduced into the `@angular/cdk` via angular/components#24931 have been added to an export path (`private/components`) within `@schematics/angular`. The export path is primarily intended for the use of the components schematics within `@angular/cdk` and `@angular/material`. The API exported from this path is not considered public API, does not provide SemVer guarantees, and may be modified or removed without a deprecation cycle. (cherry picked from commit e895fc7)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds code to handle apps that are bootstrapped through
bootstrapApplication
instead ofbootstrapModule
.