Skip to content

Commit 69e6c71

Browse files
committed
feat(@angular/cli): use separate tsconfigs
This PR adds tsconfigs for each separate application: - `src/tsconfig.app.json`: configuration for the Angular app. - `src/tsconfig.spec.json`: configuration for the unit tests. Defaults to the Angular app config. - `e2e/tsconfig.e2e.json`: configuration for the e2e tests. There is an additional root-level `tsconfig.json` that is used for editor integration. For Angular version 4 projects, these tsconfigs will use inheritance since it's available with TypeScript 2.1. This is not a breaking change. Existing projects should not be affected.
1 parent 1e30159 commit 69e6c71

File tree

14 files changed

+171
-90
lines changed

14 files changed

+171
-90
lines changed

docs/documentation/stories/third-party-lib.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ npm install d3 --save
99
npm install @types/d3 --save-dev
1010
```
1111

12+
Then open `src/tsconfig.app.json` and add it to the `types` array:
13+
14+
```
15+
"types":[
16+
"d3"
17+
]
18+
```
19+
20+
If the library you added typings for is only to be used on your e2e tests,
21+
instead use `e2e/tsconfig.e2e.json`.
22+
The same goes for unit tests and `src/tsconfig.spec.json`.
23+
1224
If the library doesn't have typings available at `@types/`, you can still use it by
1325
manually adding typings for it:
1426

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{<% if (ng4) { %>
2+
"extends": "<%= relativeRootPath %>/tsconfig.json",
3+
"compilerOptions": {
4+
"lib": [
5+
"es2016",
6+
"dom"
7+
],<% } else { %>
8+
"compilerOptions": {
9+
"sourceMap": true,
10+
"declaration": false,
11+
"moduleResolution": "node",
12+
"emitDecoratorMetadata": true,
13+
"experimentalDecorators": true,
14+
"lib": [
15+
"es2016",
16+
"dom"
17+
],<% } %>
18+
"outDir": "<%= relativeRootPath %>/out-tsc/app",
19+
"target": "es5",
20+
"module": "es2015",
21+
"baseUrl": "",
22+
"types": []
23+
},
24+
"exclude": [
25+
"test.ts",
26+
"**/*.spec.ts"
27+
]
28+
}

packages/@angular/cli/blueprints/ng2/files/__path__/tsconfig.json

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{<% if (ng4) { %>
2+
"extends": "<%= relativeRootPath %>/tsconfig.json",
3+
"compilerOptions": {<% } else { %>
4+
"compilerOptions": {
5+
"sourceMap": true,
6+
"declaration": false,
7+
"moduleResolution": "node",
8+
"emitDecoratorMetadata": true,
9+
"experimentalDecorators": true,
10+
"lib": [
11+
"es2016"
12+
],<% } %>
13+
"outDir": "<%= relativeRootPath %>/out-tsc/spec",
14+
"module": "commonjs",
15+
"target": "es6",
16+
"baseUrl": "",
17+
"types": [
18+
"jasmine",
19+
"node"
20+
]
21+
},
22+
"files": [
23+
"test.ts"
24+
],
25+
"include": [
26+
"**/*.spec.ts"
27+
]
28+
}

packages/@angular/cli/blueprints/ng2/files/angular-cli.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"main": "main.ts",
1616
"polyfills": "polyfills.ts",
1717
"test": "test.ts",
18-
"tsconfig": "tsconfig.json",
18+
"tsconfig": "tsconfig.app.json",
19+
"testTsconfig": "tsconfig.spec.json",
1920
"prefix": "<%= prefix %>",
2021
"styles": [
2122
"styles.<%= styleExt %>"
@@ -35,12 +36,13 @@
3536
},
3637
"lint": [
3738
{
38-
"files": "<%= sourceDir %>/**/*.ts",
39-
"project": "<%= sourceDir %>/tsconfig.json"
39+
"project": "<%= sourceDir %>/tsconfig.app.json"
4040
},
4141
{
42-
"files": "e2e/**/*.ts",
43-
"project": "e2e/tsconfig.json"
42+
"project": "<%= sourceDir %>/tsconfig.spec.json"
43+
},
44+
{
45+
"project": "e2e/tsconfig.e2e.json"
4446
}
4547
],
4648
"test": {
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
{
2-
"compileOnSave": false,
1+
{<% if (ng4) { %>
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {<% } else { %>
34
"compilerOptions": {
5+
"sourceMap": true,
46
"declaration": false,
7+
"moduleResolution": "node",
58
"emitDecoratorMetadata": true,
69
"experimentalDecorators": true,
710
"lib": [
811
"es2016"
9-
],
10-
"module": "commonjs",
11-
"moduleResolution": "node",
12+
],<% } %>
1213
"outDir": "../dist/out-tsc-e2e",
13-
"sourceMap": true,
14+
"module": "commonjs",
1415
"target": "es6",
15-
"typeRoots": [
16-
"../node_modules/@types"
16+
"types":[
17+
"jasmine",
18+
"node"
1719
]
1820
}
1921
}

packages/@angular/cli/blueprints/ng2/files/protractor.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports.config = {
2222
},
2323
beforeLaunch: function() {
2424
require('ts-node').register({
25-
project: 'e2e'
25+
project: 'e2e/tsconfig.e2e.json'
2626
});
2727
},
2828
onPrepare() {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compileOnSave": false,
3+
"compilerOptions": {
4+
"outDir": "./dist/out-tsc",
5+
"sourceMap": true,
6+
"declaration": false,
7+
"moduleResolution": "node",
8+
"emitDecoratorMetadata": true,
9+
"experimentalDecorators": true,
10+
"lib": [
11+
"es2016"
12+
]
13+
}
14+
}

packages/@angular/cli/lib/config/schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,13 @@
9494
},
9595
"tsconfig": {
9696
"type": "string",
97-
"default": "tsconfig.json",
97+
"default": "tsconfig.app.json",
9898
"description": "The name of the TypeScript configuration file."
9999
},
100+
"testTsconfig": {
101+
"type": "string",
102+
"description": "The name of the TypeScript configuration file for unit tests."
103+
},
100104
"prefix": {
101105
"type": "string",
102106
"description": "The prefix to apply to generated selectors."

packages/@angular/cli/models/webpack-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export class NgCliWebpackConfig {
106106

107107
public addAppConfigDefaults(appConfig: any) {
108108
const appConfigDefaults: any = {
109+
testTsconfig: appConfig.tsconfig,
109110
scripts: [],
110111
styles: []
111112
};

0 commit comments

Comments
 (0)