Skip to content

Commit cde5602

Browse files
committed
fix(@schematics/angular): exclusively list the files in tsconfigs
With the omission of `includes` or `files` in tsconfig files tsc will pick up all the files under the rootDir and make them as part of the compilation. In certain cases, redundant files will be picked up which will cause a slower compilations. Related to: TOOL-949
1 parent 4c6e7e2 commit cde5602

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

packages/schematics/angular/application/files/tsconfig.app.json.template

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
"outDir": "<%= relativePathToWorkspaceRoot %>/out-tsc/app",
55
"types": []
66
},
7+
"files": [
8+
"src/main.ts",
9+
"src/polyfills.ts"
10+
],<% if (!enableIvy) { %>
711
"include": [
812
"src/**/*.ts"
913
],
1014
"exclude": [
1115
"src/test.ts",
1216
"src/**/*.spec.ts"
13-
]<% if (enableIvy) { %>,
17+
]<% } %><% if (enableIvy) { %>
18+
"include": [
19+
"src/**/*.d.ts"
20+
],
1421
"angularCompilerOptions": {
1522
"enableIvy": true
1623
}<% } %>

packages/schematics/angular/application/index_spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,27 @@ describe('Application Schematic', () => {
232232
expect(workspace.projects.foo.architect.build.options.aot).toEqual(true);
233233
});
234234

235+
it('should set the right files, exclude, include in the tsconfig for VE projects', async () => {
236+
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)
237+
.toPromise();
238+
const path = '/projects/foo/tsconfig.app.json';
239+
const tsConfig = JSON.parse(tree.readContent(path));
240+
expect(tsConfig.files).toEqual(['src/main.ts', 'src/polyfills.ts']);
241+
expect(tsConfig.exclude).toEqual(['src/test.ts', 'src/**/*.spec.ts']);
242+
expect(tsConfig.include).toEqual(['src/**/*.ts']);
243+
});
244+
245+
it('should set the right files, exclude, include in the tsconfig for Ivy projects', async () => {
246+
const options = { ...defaultOptions, enableIvy: true };
247+
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)
248+
.toPromise();
249+
const path = '/projects/foo/tsconfig.app.json';
250+
const tsConfig = JSON.parse(tree.readContent(path));
251+
expect(tsConfig.files).toEqual(['src/main.ts', 'src/polyfills.ts']);
252+
expect(tsConfig.exclude).toBeUndefined();
253+
expect(tsConfig.include).toEqual(['src/**/*.d.ts']);
254+
});
255+
235256
describe(`update package.json`, () => {
236257
it(`should add build-angular to devDependencies`, async () => {
237258
const tree = await schematicRunner.runSchematicAsync('application', defaultOptions, workspaceTree)

packages/schematics/angular/universal/files/root/__tsconfigFileName__.json.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"compilerOptions": {
44
"outDir": "<%= outDir %>-server"
55
},
6+
"files": [
7+
"src/main.server.ts"
8+
],
69
"angularCompilerOptions": {
710
"entryModule": "./<%= rootInSrc ? '' : 'src/' %><%= appDir %>/<%= stripTsExtension(rootModuleFileName) %>#<%= rootModuleClassName %>"
811
}

packages/schematics/angular/universal/index_spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ describe('Universal Schematic', () => {
9191
compilerOptions: {
9292
outDir: './out-tsc/app-server',
9393
},
94+
files: [
95+
"src/main.server.ts"
96+
],
9497
angularCompilerOptions: {
9598
entryModule: './src/app/app.server.module#AppServerModule',
9699
},
@@ -111,6 +114,9 @@ describe('Universal Schematic', () => {
111114
compilerOptions: {
112115
outDir: '../../out-tsc/app-server',
113116
},
117+
files: [
118+
"src/main.server.ts"
119+
],
114120
angularCompilerOptions: {
115121
entryModule: './src/app/app.server.module#AppServerModule',
116122
},

0 commit comments

Comments
 (0)