File tree 2 files changed +32
-3
lines changed
packages/schematics/angular/utility/standalone
2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -231,12 +231,10 @@ function addProvidersExpressionToAppConfig(
231
231
// If there's a `providers` property, we can add the provider
232
232
// to it, otherwise we need to declare it ourselves.
233
233
if ( providersLiteral ) {
234
- const hasTrailingComma = providersLiteral . elements . hasTrailingComma ;
235
-
236
234
applyChangesToFile ( tree , filePath , [
237
235
insertAfterLastOccurrence (
238
236
providersLiteral . elements ,
239
- ( hasTrailingComma || providersLiteral . elements . length === 0 ? '' : ', ' ) + expression ,
237
+ ( providersLiteral . elements . length === 0 ? '' : ', ' ) + expression ,
240
238
filePath ,
241
239
providersLiteral . getStart ( ) + 1 ,
242
240
) ,
Original file line number Diff line number Diff line change @@ -445,5 +445,36 @@ describe('standalone utilities', () => {
445
445
assertContains ( content , `import { provideModule } from '@my/module';` ) ;
446
446
assertContains ( content , `providers: [provideModule([])]` ) ;
447
447
} ) ;
448
+
449
+ it ( 'should add a root provider to a standalone app when has 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
+ } ) ;
448
479
} ) ;
449
480
} ) ;
You can’t perform that action at this time.
0 commit comments