File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
packages/schematics/angular/utility/standalone Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -231,12 +231,10 @@ function addProvidersExpressionToAppConfig(
231231 // If there's a `providers` property, we can add the provider
232232 // to it, otherwise we need to declare it ourselves.
233233 if ( providersLiteral ) {
234- const hasTrailingComma = providersLiteral . elements . hasTrailingComma ;
235-
236234 applyChangesToFile ( tree , filePath , [
237235 insertAfterLastOccurrence (
238236 providersLiteral . elements ,
239- ( hasTrailingComma || providersLiteral . elements . length === 0 ? '' : ', ' ) + expression ,
237+ ( providersLiteral . elements . length === 0 ? '' : ', ' ) + expression ,
240238 filePath ,
241239 providersLiteral . getStart ( ) + 1 ,
242240 ) ,
Original file line number Diff line number Diff line change @@ -445,5 +445,36 @@ describe('standalone utilities', () => {
445445 assertContains ( content , `import { provideModule } from '@my/module';` ) ;
446446 assertContains ( content , `providers: [provideModule([])]` ) ;
447447 } ) ;
448+
449+ it ( 'should add a root provider to a standalone app when providers contain a trailing comma' , async ( ) => {
450+ await setupProject ( true ) ;
451+
452+ const configPath = 'app/app.config.ts' ;
453+ host . overwrite (
454+ getPathWithinProject ( configPath ) ,
455+ `
456+ import { ApplicationConfig } from '@angular/core';
457+ import { provideRouter } from '@angular/router';
458+
459+ export const appConfig: ApplicationConfig = {
460+ providers: [
461+ provideRouter([]),
462+ ]
463+ };
464+ ` ,
465+ ) ;
466+
467+ await testRule (
468+ addRootProvider (
469+ projectName ,
470+ ( { code, external } ) => code `${ external ( 'provideModule' , '@my/module' ) } ([])` ,
471+ ) ,
472+ host ,
473+ ) ;
474+
475+ const content = readFile ( 'app/app.config.ts' ) ;
476+ assertContains ( content , `import { provideModule } from '@my/module';` ) ;
477+ assertContains ( content , `providers: [provideRouter([]),provideModule([]),]` ) ;
478+ } ) ;
448479 } ) ;
449480} ) ;
You can’t perform that action at this time.
0 commit comments