Skip to content

Commit 7e69aa0

Browse files
committed
fix(@schematics/angular): migrate provideServerRoutesConfig to provideServerRendering
Previously, `provideServerRoutesConfig` was not properly migrated to `provideServerRendering`. This change ensures the migration is handled correctly.
1 parent e50d03d commit 7e69aa0

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

packages/schematics/angular/migrations/migration-collection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"replace-provide-server-routing": {
99
"version": "20.0.0",
1010
"factory": "./replace-provide-server-routing/migration",
11-
"description": "Migrate 'provideServerRendering' to use 'withRoutes' and remove 'provideServerRouting' from '@angular/ssr'."
11+
"description": "Migrate 'provideServerRendering' to use 'withRoutes', and remove 'provideServerRouting' and 'provideServerRoutesConfig' from '@angular/ssr'."
1212
},
1313
"update-module-resolution": {
1414
"version": "20.0.0",

packages/schematics/angular/migrations/replace-provide-server-routing/migration.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ function* visit(directory: DirEntry): IterableIterator<[fileName: string, conten
1616
const entry = directory.file(path);
1717
if (entry) {
1818
const content = entry.content;
19-
if (content.includes('provideServerRouting') && content.includes('@angular/ssr')) {
19+
if (
20+
(content.includes('provideServerRouting') ||
21+
content.includes('provideServerRoutesConfig')) &&
22+
content.includes('@angular/ssr')
23+
) {
2024
// Only need to rename the import so we can just string replacements.
2125
yield [entry.path, content.toString()];
2226
}
@@ -63,7 +67,8 @@ export default function (): Rule {
6367
if (
6468
ts.isCallExpression(el) &&
6569
ts.isIdentifier(el.expression) &&
66-
el.expression.text === 'provideServerRouting'
70+
(el.expression.text === 'provideServerRouting' ||
71+
el.expression.text === 'provideServerRoutesConfig')
6772
) {
6873
const [withRouteVal, ...others] = el.arguments.map((arg) => arg.getText());
6974

@@ -99,7 +104,7 @@ export default function (): Rule {
99104
const elements = namedBindings.elements;
100105
const updatedElements = elements
101106
.map((el) => el.getText())
102-
.filter((x) => x !== 'provideServerRouting');
107+
.filter((x) => x !== 'provideServerRouting' && x !== 'provideServerRoutesConfig');
103108

104109
updatedElements.push('withRoutes');
105110

packages/schematics/angular/migrations/replace-provide-server-routing/migration_spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ describe(`Migration to replace 'provideServerRouting' with 'provideServerRenderi
6161
expect(content).not.toContain(`provideServerRouting(serverRoutes)`);
6262
});
6363

64+
it('should remove "provideServerRoutesConfig" and update "provideServerRendering"', async () => {
65+
tree.overwrite(
66+
'src/app/app.config.ts',
67+
`
68+
import { ApplicationConfig } from '@angular/core';
69+
import { provideServerRendering, provideServerRoutesConfig } from '@angular/ssr';
70+
import { serverRoutes } from './app.routes';
71+
72+
const serverConfig: ApplicationConfig = {
73+
providers: [
74+
provideServerRendering(),
75+
provideServerRoutesConfig(serverRoutes)
76+
]
77+
};
78+
`,
79+
);
80+
81+
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);
82+
const content = newTree.readContent('src/app/app.config.ts');
83+
84+
expect(content).toContain(`providers: [provideServerRendering(withRoutes(serverRoutes))]`);
85+
expect(content).not.toContain(`provideServerRoutesConfig(serverRoutes)`);
86+
});
87+
6488
it('should correctly handle provideServerRouting with extra arguments', async () => {
6589
tree.overwrite(
6690
'src/app/app.config.ts',

0 commit comments

Comments
 (0)