Skip to content

Commit c9e84d0

Browse files
alan-agius4angular-robot[bot]
authored andcommitted
feat(@schematics/angular): remove generation of BrowserModule.withServerTransition
This commit removes generation of `.withServerTransition` in the universal schematic as is deprecated. DEPRECATED: the `app-id` option in the app-shell and universal schematics has been deprecated without replacement. See: angular/angular#49422 for more information about the rational of this change.
1 parent c09c1b3 commit c9e84d0

File tree

7 files changed

+7
-105
lines changed

7 files changed

+7
-105
lines changed

packages/angular_devkit/build_angular/src/builders/app-shell/app-shell_spec.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('AppShell Builder', () => {
5858
AppComponent
5959
],
6060
imports: [
61-
BrowserModule.withServerTransition({ appId: 'serverApp' }),
61+
BrowserModule,
6262
AppRoutingModule,
6363
RouterModule
6464
],
@@ -116,14 +116,6 @@ describe('AppShell Builder', () => {
116116
};
117117

118118
it('works (basic)', async () => {
119-
host.replaceInFile(
120-
'src/app/app.module.ts',
121-
/ {4}BrowserModule/,
122-
`
123-
BrowserModule.withServerTransition({ appId: 'some-app' })
124-
`,
125-
);
126-
127119
const run = await architect.scheduleTarget(target);
128120
const output = await run.result;
129121
await run.stop();

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"type": "string",
2323
"format": "html-selector",
2424
"description": "The application ID to use in withServerTransition().",
25-
"default": "serverApp"
25+
"default": "serverApp",
26+
"x-deprecated": "This option is no longer used."
2627
},
2728
"main": {
2829
"type": "string",

packages/schematics/angular/universal/index.ts

-52
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ import {
2121
url,
2222
} from '@angular-devkit/schematics';
2323
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
24-
import * as ts from '../third_party/github.com/Microsoft/TypeScript/lib/typescript';
25-
import { findNode, getDecoratorMetadata } from '../utility/ast-utils';
2624
import {
2725
NodeDependencyType,
2826
addPackageJsonDependency,
2927
getPackageJsonDependency,
3028
} from '../utility/dependencies';
3129
import { latestVersions } from '../utility/latest-versions';
32-
import { findBootstrapModulePath } from '../utility/ng-ast-utils';
3330
import { relativePathToWorkspaceRoot } from '../utility/paths';
3431
import { targetBuildNotFoundError } from '../utility/project-targets';
3532
import { getWorkspace, updateWorkspace } from '../utility/workspace';
@@ -95,54 +92,6 @@ function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): R
9592
});
9693
}
9794

98-
function findBrowserModuleImport(host: Tree, modulePath: string): ts.Node {
99-
const moduleFileText = host.readText(modulePath);
100-
const source = ts.createSourceFile(modulePath, moduleFileText, ts.ScriptTarget.Latest, true);
101-
102-
const decoratorMetadata = getDecoratorMetadata(source, 'NgModule', '@angular/core')[0];
103-
const browserModuleNode = findNode(decoratorMetadata, ts.SyntaxKind.Identifier, 'BrowserModule');
104-
105-
if (browserModuleNode === null) {
106-
throw new SchematicsException(`Cannot find BrowserModule import in ${modulePath}`);
107-
}
108-
109-
return browserModuleNode;
110-
}
111-
112-
function addServerTransition(
113-
options: UniversalOptions,
114-
mainFile: string,
115-
clientProjectRoot: string,
116-
): Rule {
117-
return (host: Tree) => {
118-
const mainPath = normalize('/' + mainFile);
119-
120-
const bootstrapModuleRelativePath = findBootstrapModulePath(host, mainPath);
121-
const bootstrapModulePath = normalize(
122-
`/${clientProjectRoot}/src/${bootstrapModuleRelativePath}.ts`,
123-
);
124-
125-
const browserModuleImport = findBrowserModuleImport(host, bootstrapModulePath);
126-
const transitionCallRecorder = host.beginUpdate(bootstrapModulePath);
127-
const position = browserModuleImport.pos + browserModuleImport.getFullWidth();
128-
const browserModuleFullImport = browserModuleImport.parent;
129-
130-
if (browserModuleFullImport.getText() === 'BrowserModule.withServerTransition') {
131-
// Remove any existing withServerTransition as otherwise we might have incorrect configuration.
132-
transitionCallRecorder.remove(
133-
position,
134-
browserModuleFullImport.parent.getFullWidth() - browserModuleImport.getFullWidth(),
135-
);
136-
}
137-
138-
transitionCallRecorder.insertLeft(
139-
position,
140-
`.withServerTransition({ appId: '${options.appId}' })`,
141-
);
142-
host.commitUpdate(transitionCallRecorder);
143-
};
144-
}
145-
14695
function addDependencies(): Rule {
14796
return (host: Tree) => {
14897
const coreDep = getPackageJsonDependency(host, '@angular/core');
@@ -214,7 +163,6 @@ export default function (options: UniversalOptions): Rule {
214163
mergeWith(rootSource),
215164
addDependencies(),
216165
updateConfigFile(options, tsConfigDirectory),
217-
addServerTransition(options, clientBuildOptions.main, clientProject.root),
218166
]);
219167
};
220168
}

packages/schematics/angular/universal/index_spec.ts

-40
Original file line numberDiff line numberDiff line change
@@ -151,46 +151,6 @@ describe('Universal Schematic', () => {
151151
expect(targets.build.options.outputPath).toEqual('dist/bar/browser');
152152
});
153153

154-
it('should add a server transition to BrowserModule import', async () => {
155-
const tree = await schematicRunner.runSchematic('universal', defaultOptions, appTree);
156-
const filePath = '/projects/bar/src/app/app.module.ts';
157-
const contents = tree.readContent(filePath);
158-
expect(contents).toMatch(/BrowserModule\.withServerTransition\({ appId: 'serverApp' }\)/);
159-
});
160-
161-
it('should replace existing `withServerTransition` in BrowserModule import', async () => {
162-
const filePath = '/projects/bar/src/app/app.module.ts';
163-
appTree.overwrite(
164-
filePath,
165-
`
166-
import { NgModule } from '@angular/core';
167-
import { BrowserModule } from '@angular/platform-browser';
168-
169-
import { AppRoutingModule } from './app-routing.module';
170-
import { AppComponent } from './app.component';
171-
172-
@NgModule({
173-
declarations: [
174-
AppComponent
175-
],
176-
imports: [
177-
BrowserModule.withServerTransition({ appId: 'foo' }),
178-
AppRoutingModule
179-
],
180-
providers: [],
181-
bootstrap: [AppComponent]
182-
})
183-
export class AppModule { }
184-
`,
185-
);
186-
const tree = await schematicRunner.runSchematic('universal', defaultOptions, appTree);
187-
const contents = tree.readContent(filePath);
188-
console.log(contents);
189-
190-
expect(contents).toContain(`BrowserModule.withServerTransition({ appId: 'serverApp' }),`);
191-
expect(contents).not.toContain(`withServerTransition({ appId: 'foo' })`);
192-
});
193-
194154
it('should install npm dependencies', async () => {
195155
await schematicRunner.runSchematic('universal', defaultOptions, appTree);
196156
expect(schematicRunner.tasks.length).toBe(1);

packages/schematics/angular/universal/schema.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"type": "string",
1818
"format": "html-selector",
1919
"description": "The application identifier to use for transition.",
20-
"default": "serverApp"
20+
"default": "serverApp",
21+
"x-deprecated": "This option is no longer used."
2122
},
2223
"main": {
2324
"type": "string",

packages/schematics/angular/utility/ng-ast-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function findBootstrapModuleCall(host: Tree, mainPath: string): ts.CallEx
4646
return bootstrapCall;
4747
}
4848

49-
export function findBootstrapModulePath(host: Tree, mainPath: string): string {
49+
function findBootstrapModulePath(host: Tree, mainPath: string): string {
5050
const bootstrapCall = findBootstrapModuleCall(host, mainPath);
5151
if (!bootstrapCall) {
5252
throw new SchematicsException('Bootstrap call not found');

tests/legacy-cli/e2e/tests/build/app-shell/app-shell-standalone.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default async function () {
6868
6969
export default () => bootstrapApplication(AppComponent, {
7070
providers: [
71-
importProvidersFrom(BrowserModule.withServerTransition({ appId: 'app' })),
71+
importProvidersFrom(BrowserModule),
7272
importProvidersFrom(ServerModule),
7373
provideRouter([{ path: 'shell', component: AppShellComponent }]),
7474
],

0 commit comments

Comments
 (0)