Skip to content

Commit f817eee

Browse files
authored
fix: providers order does not impact bootstrapApplication migration (#28)
Resolves #24
1 parent 8d5b8ae commit f817eee

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

packages/cli/src/angular/migrations/standalone/0003-migrate-bootstrap-application.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,60 @@ describe("migrateBootstrapApplication", () => {
6060
`),
6161
);
6262
});
63+
64+
it("order of providers should not impact migration", async () => {
65+
const project = new Project({ useInMemoryFileSystem: true });
66+
67+
const main = dedent(`
68+
import { enableProdMode, importProvidersFrom } from '@angular/core';
69+
import { bootstrapApplication } from '@angular/platform-browser';
70+
import { RouteReuseStrategy, provideRouter } from '@angular/router';
71+
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
72+
73+
import { routes } from './app/app.routes';
74+
import { AppComponent } from './app/app.component';
75+
import { environment } from './environments/environment';
76+
77+
if (environment.production) {
78+
enableProdMode();
79+
}
80+
81+
bootstrapApplication(AppComponent, {
82+
providers: [
83+
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
84+
provideRouter(routes),
85+
importProvidersFrom(IonicModule.forRoot({ mode: 'ios' })),
86+
],
87+
});
88+
`);
89+
90+
const mainSourceFile = project.createSourceFile("src/main.ts", main);
91+
92+
await migrateBootstrapApplication(project, { dryRun: false });
93+
94+
expect(dedent(mainSourceFile.getText())).toBe(
95+
dedent(`
96+
import { enableProdMode, importProvidersFrom } from '@angular/core';
97+
import { bootstrapApplication } from '@angular/platform-browser';
98+
import { RouteReuseStrategy, provideRouter } from '@angular/router';
99+
import { IonicRouteStrategy, provideIonicAngular } from '@ionic/angular/standalone';
100+
101+
import { routes } from './app/app.routes';
102+
import { AppComponent } from './app/app.component';
103+
import { environment } from './environments/environment';
104+
105+
if (environment.production) {
106+
enableProdMode();
107+
}
108+
109+
bootstrapApplication(AppComponent, {
110+
providers: [
111+
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
112+
provideRouter(routes),
113+
provideIonicAngular({ mode: 'ios' })
114+
],
115+
});
116+
`),
117+
);
118+
});
63119
});

packages/cli/src/angular/migrations/standalone/0003-migrate-bootstrap-application.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,17 @@ export const migrateBootstrapApplication = async (
6868
return;
6969
}
7070

71-
const importProvidersFromFunctionCall = providersArray.getFirstChildByKind(
72-
SyntaxKind.CallExpression,
73-
);
71+
const importProvidersFromFunctionCall = providersArray
72+
.getChildrenOfKind(SyntaxKind.CallExpression)
73+
.find((callExpression) => {
74+
const identifier = callExpression.getFirstChildByKind(
75+
SyntaxKind.Identifier,
76+
);
77+
return (
78+
identifier !== undefined &&
79+
identifier.getText() === "importProvidersFrom"
80+
);
81+
});
7482

7583
if (importProvidersFromFunctionCall === undefined) {
7684
return;

0 commit comments

Comments
 (0)