Skip to content

Commit c5daaa9

Browse files
devversionkara
authored andcommitted
refactor(core): static-query schematic should not run multiple times (angular#29133)
With 6215799, we introduced a schematic for the new static-query timing. Currently when someone runs the update schematic manually within his CLI project (the schematic does not run automatically yet), he might have noticed that the migration is executed for the same `tsconfig` file multiple times. This can happen because the `getProjectTsConfigPaths` function can incorrectly return the same tsconfig multiple times. The paths are not properly deduped as we don't normalize the determined project tsconfig paths PR Close angular#29133
1 parent 360730c commit c5daaa9

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

packages/core/schematics/test/project_tsconfig_paths_spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('project tsconfig paths', () => {
2222
{my_name: {architect: {build: {options: {tsConfig: './my-custom-config.json'}}}}}
2323
}));
2424

25-
expect(getProjectTsConfigPaths(testTree)).toEqual(['./my-custom-config.json']);
25+
expect(getProjectTsConfigPaths(testTree)).toEqual(['my-custom-config.json']);
2626
});
2727

2828
it('should detect test tsconfig path inside of .angular.json file', () => {
@@ -32,7 +32,7 @@ describe('project tsconfig paths', () => {
3232
{with_tests: {architect: {test: {options: {tsConfig: './my-test-config.json'}}}}}
3333
}));
3434

35-
expect(getProjectTsConfigPaths(testTree)).toEqual(['./my-test-config.json']);
35+
expect(getProjectTsConfigPaths(testTree)).toEqual(['my-test-config.json']);
3636
});
3737

3838
it('should detect common tsconfigs if no workspace config could be found', () => {
@@ -41,7 +41,16 @@ describe('project tsconfig paths', () => {
4141
testTree.create('/src/tsconfig.app.json', '');
4242

4343
expect(getProjectTsConfigPaths(testTree)).toEqual([
44-
'./tsconfig.json', './src/tsconfig.json', './src/tsconfig.app.json'
44+
'tsconfig.json', 'src/tsconfig.json', 'src/tsconfig.app.json'
4545
]);
4646
});
47+
48+
it('should not return duplicate tsconfig files', () => {
49+
testTree.create('/tsconfig.json', '');
50+
testTree.create('/.angular.json', JSON.stringify({
51+
projects: {app: {architect: {test: {options: {tsConfig: 'tsconfig.json'}}}}}
52+
}));
53+
54+
expect(getProjectTsConfigPaths(testTree)).toEqual(['tsconfig.json']);
55+
});
4756
});

packages/core/schematics/utils/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ ts_library(
88
),
99
tsconfig = "//packages/core/schematics:tsconfig.json",
1010
visibility = ["//packages/core/schematics:__subpackages__"],
11-
deps = ["@npm//@angular-devkit/schematics"],
11+
deps = [
12+
"@npm//@angular-devkit/core",
13+
"@npm//@angular-devkit/schematics",
14+
],
1215
)

packages/core/schematics/utils/project_tsconfig_paths.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {normalize} from '@angular-devkit/core';
910
import {Tree} from '@angular-devkit/schematics';
1011

1112
/** Name of the default Angular CLI workspace configuration files. */
@@ -18,9 +19,9 @@ const defaultWorkspaceConfigPaths = ['/angular.json', '/.angular.json'];
1819
export function getProjectTsConfigPaths(tree: Tree): string[] {
1920
// Start with some tsconfig paths that are generally used within CLI projects.
2021
const tsconfigPaths = new Set<string>([
21-
'./tsconfig.json',
22-
'./src/tsconfig.json',
23-
'./src/tsconfig.app.json',
22+
'tsconfig.json',
23+
'src/tsconfig.json',
24+
'src/tsconfig.app.json',
2425
]);
2526

2627
// Add any tsconfig directly referenced in a build or test task of the angular.json workspace.
@@ -32,13 +33,13 @@ export function getProjectTsConfigPaths(tree: Tree): string[] {
3233
['build', 'test'].forEach(targetName => {
3334
if (project.targets && project.targets[targetName] && project.targets[targetName].options &&
3435
project.targets[targetName].options.tsConfig) {
35-
tsconfigPaths.add(project.targets[targetName].options.tsConfig);
36+
tsconfigPaths.add(normalize(project.targets[targetName].options.tsConfig));
3637
}
3738

3839
if (project.architect && project.architect[targetName] &&
3940
project.architect[targetName].options &&
4041
project.architect[targetName].options.tsConfig) {
41-
tsconfigPaths.add(project.architect[targetName].options.tsConfig);
42+
tsconfigPaths.add(normalize(project.architect[targetName].options.tsConfig));
4243
}
4344
});
4445
}

0 commit comments

Comments
 (0)