Skip to content

Commit 329b61c

Browse files
committed
feat(@angular/cli): missing bootstrap code should not error
It is totally valid now to have a different bootstrapping process. By removing the error in resolveEntryModuleFromMain we allow the compilation to work.
1 parent b1baa0c commit 329b61c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

packages/@ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class AngularCompilerPlugin implements Tapable {
9696
// Contains `moduleImportPath#exportName` => `fullModulePath`.
9797
private _lazyRoutes: LazyRouteMap = Object.create(null);
9898
private _tsConfigPath: string;
99-
private _entryModule: string;
99+
private _entryModule: string | null;
100100
private _mainPath: string | undefined;
101101
private _basePath: string;
102102
private _transformers: ts.TransformerFactory<ts.SourceFile>[] = [];

packages/@ngtools/webpack/src/entry_resolver.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function _symbolImportLookup(refactor: TypeScriptFileRefactor,
130130

131131
export function resolveEntryModuleFromMain(mainPath: string,
132132
host: ts.CompilerHost,
133-
program: ts.Program) {
133+
program: ts.Program): string | null {
134134
const source = new TypeScriptFileRefactor(mainPath, host, program);
135135

136136
const bootstrap = source.findAstNodes(source.sourceFile, ts.SyntaxKind.CallExpression, true)
@@ -146,9 +146,7 @@ export function resolveEntryModuleFromMain(mainPath: string,
146146
.filter(node => node.kind == ts.SyntaxKind.Identifier);
147147

148148
if (bootstrap.length != 1) {
149-
throw new Error('Tried to find bootstrap code, but could not. Specify either '
150-
+ 'statically analyzable bootstrap code or pass in an entryModule '
151-
+ 'to the plugins options.');
149+
return null;
152150
}
153151
const bootstrapSymbolName = bootstrap[0].text;
154152
const module = _symbolImportLookup(source, bootstrapSymbolName, host, program);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { AppModule } from '../../assets/1.0.0-proj/src/app/app.module';
2+
import { readFile, writeFile } from '../../utils/fs';
3+
import { ng } from '../../utils/process';
4+
5+
6+
export default async function() {
7+
const mainTs = await readFile('src/main.ts');
8+
9+
const newMainTs = mainTs
10+
.replace(/platformBrowserDynamic.*?bootstrapModule.*?;/, '')
11+
+ 'console.log(AppModule);'; // Use AppModule to make sure it's imported properly.
12+
13+
await writeFile('src/main.ts', newMainTs);
14+
await ng('build');
15+
}

0 commit comments

Comments
 (0)