fix(material/schematics): support standalone components in ng-add#24931
fix(material/schematics): support standalone components in ng-add#24931crisbeto merged 1 commit intoangular:mainfrom
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.
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.
@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.
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.
| }); | ||
|
|
||
| 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.
question: why do we need to delete this file?
There was a problem hiding this comment.
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.
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.
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.
Yeah, I guess this comes down to the common utils at some point, but for now seems fine.
|
|
||
| integration/ng-add-standalone/.angular | ||
| integration/ng-add-standalone/node_modules | ||
|
|
… 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
bootstrapApplicationinstead ofbootstrapModule.