angular/packages/core/schematics/migrations.json
cexbrayat 01f86287db refactor(migrations): use import manager in provide-initializer (#58456)
The manual replacement logic had a flaw and was inserting the imports several times.

For example:

```ts
import { APP_INITIALIZER, ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { InitService } from './init.service';

export const appConfig: ApplicationConfig = {
  providers: [provideZoneChangeDetection({ eventCoalescing: true }),
    {
      provide: APP_INITIALIZER,
      useFactory: (initService: InitService) => initService.init(),
      deps: [InitService],
      multi: true
    },
    {
      provide: APP_INITIALIZER,
      useFactory: (initService: InitService) => initService.init(),
      deps: [InitService],
      multi: true
    }
  ]
};
```

produced:

```ts
import { ApplicationConfig, provideZoneChangeDetection, inject, provideAppInitializer }{ ApplicationConfig, provideZoneChangeDetection, inject, provideAppInitializer } from '@angular/core';
import { InitService } from './init.service';

export const appConfig: ApplicationConfig = {
  providers: [provideZoneChangeDetection({ eventCoalescing: true }),
    provideAppInitializer(() => { return ((initService: InitService) => initService.init())(inject(InitService)); }),
    provideAppInitializer(() => { return ((initService: InitService) => initService.init())(inject(InitService)); })
  ]
};
```

It now produces proper imports:

```ts
import { ApplicationConfig, provideZoneChangeDetection, inject, provideAppInitializer } from '@angular/core';
```

PR Close #58456
2024-11-04 18:15:00 +01:00

20 lines
851 B
JSON

{
"schematics": {
"explicit-standalone-flag": {
"version": "19.0.0",
"description": "Updates non-standalone Directives, Component and Pipes to 'standalone:false' and removes 'standalone:true' from those who are standalone",
"factory": "./bundles/explicit-standalone-flag#migrate"
},
"pending-tasks": {
"version": "19.0.0",
"description": "Updates ExperimentalPendingTasks to PendingTasks",
"factory": "./bundles/pending-tasks#migrate"
},
"provide-initializer": {
"version": "19.0.0",
"description": "Replaces `APP_INITIALIZER`, `ENVIRONMENT_INITIALIZER` & `PLATFORM_INITIALIZER` respectively with `provideAppInitializer`, `provideEnvironmentInitializer` & `providePlatformInitializer`.",
"factory": "./bundles/provide-initializer#migrate",
"optional": true
}
}
}