|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 |
| -import { JsonAstObject, logging } from '@angular-devkit/core'; |
| 8 | +import { JsonAstObject, join, logging, normalize } from '@angular-devkit/core'; |
9 | 9 | import { Rule, Tree, UpdateRecorder } from '@angular-devkit/schematics';
|
10 | 10 | import { dirname, relative } from 'path';
|
11 | 11 | import {
|
@@ -36,23 +36,29 @@ export function updateApplicationTsConfigs(): Rule {
|
36 | 36 | // Add `module` option in the workspace tsconfig
|
37 | 37 | updateModuleCompilerOption(tree, '/tsconfig.json');
|
38 | 38 |
|
39 |
| - for (const { target } of getTargets(workspace, 'build', Builders.Browser)) { |
40 |
| - updateTsConfig(tree, target, Builders.Browser, logger); |
| 39 | + for (const { target, project } of getTargets(workspace, 'build', Builders.Browser)) { |
| 40 | + updateTsConfig(tree, target, project, Builders.Browser, logger); |
41 | 41 | }
|
42 | 42 |
|
43 |
| - for (const { target } of getTargets(workspace, 'server', Builders.Server)) { |
44 |
| - updateTsConfig(tree, target, Builders.Server, logger); |
| 43 | + for (const { target, project } of getTargets(workspace, 'server', Builders.Server)) { |
| 44 | + updateTsConfig(tree, target, project, Builders.Server, logger); |
45 | 45 | }
|
46 | 46 |
|
47 |
| - for (const { target } of getTargets(workspace, 'test', Builders.Karma)) { |
48 |
| - updateTsConfig(tree, target, Builders.Karma, logger); |
| 47 | + for (const { target, project } of getTargets(workspace, 'test', Builders.Karma)) { |
| 48 | + updateTsConfig(tree, target, project, Builders.Karma, logger); |
49 | 49 | }
|
50 | 50 |
|
51 | 51 | return tree;
|
52 | 52 | };
|
53 | 53 | }
|
54 | 54 |
|
55 |
| -function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: Builders, logger: logging.LoggerApi) { |
| 55 | +function updateTsConfig( |
| 56 | + tree: Tree, |
| 57 | + builderConfig: JsonAstObject, |
| 58 | + project: JsonAstObject, |
| 59 | + builderName: Builders, |
| 60 | + logger: logging.LoggerApi, |
| 61 | +) { |
56 | 62 | const options = getAllOptions(builderConfig);
|
57 | 63 | for (const option of options) {
|
58 | 64 | let recorder: UpdateRecorder;
|
@@ -108,6 +114,18 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
|
108 | 114 | recorder.insertLeft(start.offset, tsInclude.text.replace('.ts', '.d.ts'));
|
109 | 115 | tree.commitUpdate(recorder);
|
110 | 116 | }
|
| 117 | + } else { |
| 118 | + // Includes are not present, add includes to dts files |
| 119 | + // By default when 'include' nor 'files' fields are used TypeScript |
| 120 | + // will include all ts files. |
| 121 | + const srcRootAst = findPropertyInAstObject(project, 'sourceRoot'); |
| 122 | + const include = srcRootAst?.kind === 'string' |
| 123 | + ? join(normalize(srcRootAst.value), '**/*.d.ts') |
| 124 | + : '**/*.d.ts'; |
| 125 | + |
| 126 | + recorder = tree.beginUpdate(tsConfigPath); |
| 127 | + insertPropertyInAstObjectInOrder(recorder, tsConfigAst, 'include', [include], 2); |
| 128 | + tree.commitUpdate(recorder); |
111 | 129 | }
|
112 | 130 |
|
113 | 131 | const files = findPropertyInAstObject(tsConfigAst, 'files');
|
|
0 commit comments