@@ -29,7 +29,7 @@ import {
2929 getPackageJsonDependency,
3030} from '../utility/dependencies';
3131import { latestVersions } from '../utility/latest-versions';
32- import { findBootstrapModuleCall, findBootstrapModulePath } from '../utility/ng-ast-utils';
32+ import { findBootstrapModulePath } from '../utility/ng-ast-utils';
3333import { relativePathToWorkspaceRoot } from '../utility/paths';
3434import { targetBuildNotFoundError } from '../utility/project-targets';
3535import { getWorkspace, updateWorkspace } from '../utility/workspace';
@@ -109,84 +109,6 @@ function findBrowserModuleImport(host: Tree, modulePath: string): ts.Node {
109109 return browserModuleNode;
110110}
111111
112- function wrapBootstrapCall(mainFile: string): Rule {
113- return (host: Tree) => {
114- const mainPath = normalize('/' + mainFile);
115- let bootstrapCall: ts.Node | null = findBootstrapModuleCall(host, mainPath);
116- if (bootstrapCall === null) {
117- throw new SchematicsException('Bootstrap module not found.');
118- }
119-
120- let bootstrapCallExpression: ts.Node | null = null;
121- let currentCall = bootstrapCall;
122- while (bootstrapCallExpression === null && currentCall.parent) {
123- currentCall = currentCall.parent;
124- if (ts.isExpressionStatement(currentCall) || ts.isVariableStatement(currentCall)) {
125- bootstrapCallExpression = currentCall;
126- }
127- }
128- bootstrapCall = currentCall;
129-
130- // In case the bootstrap code is a variable statement
131- // we need to determine it's usage
132- if (bootstrapCallExpression && ts.isVariableStatement(bootstrapCallExpression)) {
133- const declaration = bootstrapCallExpression.declarationList.declarations[0];
134- const bootstrapVar = (declaration.name as ts.Identifier).text;
135- const sf = bootstrapCallExpression.getSourceFile();
136- bootstrapCall = findCallExpressionNode(sf, bootstrapVar) || currentCall;
137- }
138-
139- // indent contents
140- const triviaWidth = bootstrapCall.getLeadingTriviaWidth();
141- const beforeText =
142- `function bootstrap() {\n` + ' '.repeat(triviaWidth > 2 ? triviaWidth + 1 : triviaWidth);
143- const afterText =
144- `\n${triviaWidth > 2 ? ' '.repeat(triviaWidth - 1) : ''}};\n` +
145- `
146-
147- if (document.readyState === 'complete') {
148- bootstrap();
149- } else {
150- document.addEventListener('DOMContentLoaded', bootstrap);
151- }
152- `;
153-
154- // in some cases we need to cater for a trailing semicolon such as;
155- // bootstrap().catch(err => console.log(err));
156- const lastToken = bootstrapCall.parent.getLastToken();
157- let endPos = bootstrapCall.getEnd();
158- if (lastToken && lastToken.kind === ts.SyntaxKind.SemicolonToken) {
159- endPos = lastToken.getEnd();
160- }
161-
162- const recorder = host.beginUpdate(mainPath);
163- recorder.insertLeft(bootstrapCall.getStart(), beforeText);
164- recorder.insertRight(endPos, afterText);
165- host.commitUpdate(recorder);
166- };
167- }
168-
169- function findCallExpressionNode(node: ts.Node, text: string): ts.Node | null {
170- if (
171- ts.isCallExpression(node) &&
172- ts.isIdentifier(node.expression) &&
173- node.expression.text === text
174- ) {
175- return node;
176- }
177-
178- let foundNode: ts.Node | null = null;
179- ts.forEachChild(node, (childNode) => {
180- foundNode = findCallExpressionNode(childNode, text);
181-
182- if (foundNode) {
183- return true;
184- }
185- });
186-
187- return foundNode;
188- }
189-
190112function addServerTransition(
191113 options: UniversalOptions,
192114 mainFile: string,
@@ -292,7 +214,6 @@ export default function (options: UniversalOptions): Rule {
292214 mergeWith(rootSource),
293215 addDependencies(),
294216 updateConfigFile(options, tsConfigDirectory),
295- wrapBootstrapCall(clientBuildOptions.main),
296217 addServerTransition(options, clientBuildOptions.main, clientProject.root),
297218 ]);
298219 };
0 commit comments