Skip to content

Commit 18e13e2

Browse files
committed
feat(@schematics/angular): remove --server-routing option
Server-side rendering (SSR) will always enable server routing when using the application builder. BREAKING CHANGE: `--server-routing` option has been removed from several schematics. Server routing will be used when using the application builder.
1 parent cdfc50c commit 18e13e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+95
-469
lines changed

packages/angular/ssr/schematics/ng-add/index_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { join } from 'node:path';
1414
describe('@angular/ssr ng-add schematic', () => {
1515
const defaultOptions = {
1616
project: 'test-app',
17-
serverRouting: false,
1817
};
1918

2019
const schematicRunner = new SchematicTestRunner(

packages/angular/ssr/schematics/ng-add/schema.json

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
"description": "Skip the automatic installation of packages. You will need to manually install the dependencies later.",
1717
"type": "boolean",
1818
"default": false
19-
},
20-
"serverRouting": {
21-
"description": "Configure the server application to use the Angular Server Routing API and App Engine APIs (currently in Developer Preview).",
22-
"type": "boolean"
2319
}
2420
},
2521
"required": ["project"],

packages/schematics/angular/app-shell/index.ts

+10-29
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import {
2727
} from '../utility/ast-utils';
2828
import { applyToUpdateRecorder } from '../utility/change';
2929
import { getAppModulePath, isStandaloneApp } from '../utility/ng-ast-utils';
30+
import { isUsingApplicationBuilder, targetBuildNotFoundError } from '../utility/project-targets';
3031
import { findBootstrapApplicationCall, getMainFilePath } from '../utility/standalone/util';
31-
import { getWorkspace, updateWorkspace } from '../utility/workspace';
32-
import { Builders } from '../utility/workspace-models';
32+
import { getWorkspace } from '../utility/workspace';
3333
import { Schema as AppShellOptions } from './schema';
3434

3535
const APP_SHELL_ROUTE = 'shell';
@@ -156,29 +156,6 @@ function getMetadataProperty(metadata: ts.Node, propertyName: string): ts.Proper
156156
return property;
157157
}
158158

159-
function addAppShellConfigToWorkspace(options: AppShellOptions): Rule {
160-
return updateWorkspace((workspace) => {
161-
const project = workspace.projects.get(options.project);
162-
if (!project) {
163-
return;
164-
}
165-
const buildTarget = project.targets.get('build');
166-
if (
167-
buildTarget?.builder === Builders.Application ||
168-
buildTarget?.builder === Builders.BuildApplication
169-
) {
170-
// Application builder configuration.
171-
const prodConfig = buildTarget.configurations?.production;
172-
if (!prodConfig) {
173-
throw new SchematicsException(
174-
`A "production" configuration is not defined for the "build" builder.`,
175-
);
176-
}
177-
prodConfig.appShell = true;
178-
}
179-
});
180-
}
181-
182159
function addServerRoutes(options: AppShellOptions): Rule {
183160
return async (host: Tree) => {
184161
// The workspace gets updated so this needs to be reloaded
@@ -359,17 +336,21 @@ export default function (options: AppShellOptions): Rule {
359336
const browserEntryPoint = await getMainFilePath(tree, options.project);
360337
const isStandalone = isStandaloneApp(tree, browserEntryPoint);
361338

339+
const workspace = await getWorkspace(tree);
340+
const project = workspace.projects.get(options.project);
341+
if (!project) {
342+
throw targetBuildNotFoundError();
343+
}
344+
362345
return chain([
363346
validateProject(browserEntryPoint),
364347
schematic('server', options),
365-
...(options.serverRouting
348+
...(isUsingApplicationBuilder(project)
366349
? [noop()]
367350
: isStandalone
368351
? [addStandaloneServerRoute(options)]
369352
: [addServerRoutes(options)]),
370-
options.serverRouting
371-
? addServerRoutingConfig(options, isStandalone)
372-
: addAppShellConfigToWorkspace(options),
353+
addServerRoutingConfig(options, isStandalone),
373354
schematic('component', {
374355
name: 'app-shell',
375356
module: 'app.module.server.ts',

packages/schematics/angular/app-shell/index_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ describe('App Shell Schematic', () => {
1919
);
2020
const defaultOptions: AppShellOptions = {
2121
project: 'bar',
22-
serverRouting: true,
2322
};
2423

2524
const workspaceOptions: WorkspaceOptions = {

packages/schematics/angular/app-shell/schema.json

-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
"$default": {
1313
"$source": "projectName"
1414
}
15-
},
16-
"serverRouting": {
17-
"description": "Set up a server application using the Server Routing and App Engine APIs (Developer Preview).",
18-
"type": "boolean",
19-
"default": false
2015
}
2116
},
2217
"required": ["project"]

packages/schematics/angular/application/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export default function (options: ApplicationOptions): Rule {
101101
options.ssr
102102
? schematic('ssr', {
103103
project: options.name,
104-
serverRouting: options.serverRouting,
105104
skipInstall: true,
106105
})
107106
: noop(),

packages/schematics/angular/application/index_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ describe('Application Schematic', () => {
3232
const defaultOptions: ApplicationOptions = {
3333
name: 'foo',
3434
skipPackageJson: false,
35-
serverRouting: false,
3635
};
3736

3837
let workspaceTree: UnitTestTree;

packages/schematics/angular/application/schema.json

-4
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@
118118
"default": false,
119119
"x-user-analytics": "ep.ng_ssr"
120120
},
121-
"serverRouting": {
122-
"description": "Set up a server application using the Server Routing and App Engine APIs (Developer Preview).",
123-
"type": "boolean"
124-
},
125121
"experimentalZoneless": {
126122
"description": "Generate an application that does not use `zone.js`.",
127123
"type": "boolean",

packages/schematics/angular/ng-new/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export default function (options: NgNewOptions): Rule {
5757
minimal: options.minimal,
5858
standalone: options.standalone,
5959
ssr: options.ssr,
60-
serverRouting: options.serverRouting,
6160
experimentalZoneless: options.experimentalZoneless,
6261
};
6362

packages/schematics/angular/ng-new/schema.json

-4
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@
139139
"type": "boolean",
140140
"x-user-analytics": "ep.ng_ssr"
141141
},
142-
"serverRouting": {
143-
"description": "Create a server application in the initial project using the Server Routing and App Engine APIs (Developer Preview).",
144-
"type": "boolean"
145-
},
146142
"experimentalZoneless": {
147143
"description": "Create an initial application that does not utilize `zone.js`.",
148144
"type": "boolean",
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { NgModule } from '@angular/core';
2-
import { ServerModule } from '@angular/platform-server';<% if(serverRouting) { %>
3-
import { provideServerRouting } from '@angular/ssr';<% } %>
2+
import { ServerModule } from '@angular/platform-server';
3+
import { provideServerRouting } from '@angular/ssr';
44
import { AppComponent } from './app.component';
5-
import { AppModule } from './app.module';<% if(serverRouting) { %>
6-
import { serverRoutes } from './app.routes.server';<% } %>
5+
import { AppModule } from './app.module';
6+
import { serverRoutes } from './app.routes.server';
77

88
@NgModule({
9-
imports: [AppModule, ServerModule],<% if(serverRouting) { %>
10-
providers: [provideServerRouting(serverRoutes)],<% } %>
9+
imports: [AppModule, ServerModule],
10+
providers: [provideServerRouting(serverRoutes)],
1111
bootstrap: [AppComponent],
1212
})
1313
export class AppServerModule {}

packages/schematics/angular/server/files/application-builder/standalone-src/app/app.config.server.ts.template

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
2-
import { provideServerRendering } from '@angular/platform-server';<% if(serverRouting) { %>
3-
import { provideServerRouting } from '@angular/ssr';<% } %>
4-
import { appConfig } from './app.config';<% if(serverRouting) { %>
5-
import { serverRoutes } from './app.routes.server';<% } %>
2+
import { provideServerRendering } from '@angular/platform-server';
3+
import { provideServerRouting } from '@angular/ssr';
4+
import { appConfig } from './app.config';
5+
import { serverRoutes } from './app.routes.server';
66

77
const serverConfig: ApplicationConfig = {
88
providers: [
9-
provideServerRendering(),<% if(serverRouting) { %>
10-
provideServerRouting(serverRoutes)<% } %>
9+
provideServerRendering(),
10+
provideServerRouting(serverRoutes)
1111
]
1212
};
1313

packages/schematics/angular/server/index.ts

+6-13
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { JSONFile } from '../utility/json-file';
2828
import { latestVersions } from '../utility/latest-versions';
2929
import { isStandaloneApp } from '../utility/ng-ast-utils';
3030
import { relativePathToWorkspaceRoot } from '../utility/paths';
31-
import { targetBuildNotFoundError } from '../utility/project-targets';
31+
import { isUsingApplicationBuilder, targetBuildNotFoundError } from '../utility/project-targets';
3232
import { getMainFilePath } from '../utility/standalone/util';
3333
import { getWorkspace, updateWorkspace } from '../utility/workspace';
3434
import { Builders } from '../utility/workspace-models';
@@ -113,9 +113,7 @@ function updateConfigFileApplicationBuilder(options: ServerOptions): Rule {
113113
serverMainEntryName,
114114
);
115115

116-
if (options.serverRouting) {
117-
buildTarget.options['outputMode'] = 'static';
118-
}
116+
buildTarget.options['outputMode'] = 'static';
119117
});
120118
}
121119

@@ -173,13 +171,11 @@ export default function (options: ServerOptions): Rule {
173171
throw targetBuildNotFoundError();
174172
}
175173

176-
const isUsingApplicationBuilder =
177-
clientBuildTarget.builder === Builders.Application ||
178-
clientBuildTarget.builder === Builders.BuildApplication;
174+
const usingApplicationBuilder = isUsingApplicationBuilder(clientProject);
179175

180176
if (
181177
clientProject.targets.has('server') ||
182-
(isUsingApplicationBuilder && clientBuildTarget.options?.server !== undefined)
178+
(usingApplicationBuilder && clientBuildTarget.options?.server !== undefined)
183179
) {
184180
// Server has already been added.
185181
return;
@@ -190,13 +186,10 @@ export default function (options: ServerOptions): Rule {
190186
const isStandalone = isStandaloneApp(host, browserEntryPoint);
191187
const sourceRoot = clientProject.sourceRoot ?? join(normalize(clientProject.root), 'src');
192188

193-
let filesUrl = `./files/${isUsingApplicationBuilder ? 'application-builder/' : 'server-builder/'}`;
189+
let filesUrl = `./files/${usingApplicationBuilder ? 'application-builder/' : 'server-builder/'}`;
194190
filesUrl += isStandalone ? 'standalone-src' : 'ngmodule-src';
195191

196192
const templateSource = apply(url(filesUrl), [
197-
options.serverRouting
198-
? noop()
199-
: filter((path) => !path.endsWith('app.routes.server.ts.template')),
200193
applyTemplates({
201194
...strings,
202195
...options,
@@ -210,7 +203,7 @@ export default function (options: ServerOptions): Rule {
210203

211204
return chain([
212205
mergeWith(templateSource),
213-
...(isUsingApplicationBuilder
206+
...(usingApplicationBuilder
214207
? [
215208
updateConfigFileApplicationBuilder(options),
216209
updateTsConfigFile(clientBuildOptions.tsConfig),

packages/schematics/angular/server/schema.json

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
"description": "Skip the automatic installation of packages. You will need to manually install the dependencies later.",
1818
"type": "boolean",
1919
"default": false
20-
},
21-
"serverRouting": {
22-
"description": "Configure the server application to use the Server Routing and App Engine APIs (Developer Preview).",
23-
"type": "boolean"
2420
}
2521
},
2622
"required": ["project"]

packages/schematics/angular/ssr/files/application-builder-common-engine/server.ts.template

-67
This file was deleted.

0 commit comments

Comments
 (0)