refactor(core): static-query schematic should not run multiple times (#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 #29133
This commit is contained in:
Paul Gschwendtner 2019-03-09 16:58:26 +01:00 committed by Kara Erickson
parent 360730ce59
commit c5daaa91cf
3 changed files with 22 additions and 9 deletions

View File

@ -22,7 +22,7 @@ describe('project tsconfig paths', () => {
{my_name: {architect: {build: {options: {tsConfig: './my-custom-config.json'}}}}}
}));
expect(getProjectTsConfigPaths(testTree)).toEqual(['./my-custom-config.json']);
expect(getProjectTsConfigPaths(testTree)).toEqual(['my-custom-config.json']);
});
it('should detect test tsconfig path inside of .angular.json file', () => {
@ -32,7 +32,7 @@ describe('project tsconfig paths', () => {
{with_tests: {architect: {test: {options: {tsConfig: './my-test-config.json'}}}}}
}));
expect(getProjectTsConfigPaths(testTree)).toEqual(['./my-test-config.json']);
expect(getProjectTsConfigPaths(testTree)).toEqual(['my-test-config.json']);
});
it('should detect common tsconfigs if no workspace config could be found', () => {
@ -41,7 +41,16 @@ describe('project tsconfig paths', () => {
testTree.create('/src/tsconfig.app.json', '');
expect(getProjectTsConfigPaths(testTree)).toEqual([
'./tsconfig.json', './src/tsconfig.json', './src/tsconfig.app.json'
'tsconfig.json', 'src/tsconfig.json', 'src/tsconfig.app.json'
]);
});
it('should not return duplicate tsconfig files', () => {
testTree.create('/tsconfig.json', '');
testTree.create('/.angular.json', JSON.stringify({
projects: {app: {architect: {test: {options: {tsConfig: 'tsconfig.json'}}}}}
}));
expect(getProjectTsConfigPaths(testTree)).toEqual(['tsconfig.json']);
});
});

View File

@ -8,5 +8,8 @@ ts_library(
),
tsconfig = "//packages/core/schematics:tsconfig.json",
visibility = ["//packages/core/schematics:__subpackages__"],
deps = ["@npm//@angular-devkit/schematics"],
deps = [
"@npm//@angular-devkit/core",
"@npm//@angular-devkit/schematics",
],
)

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {normalize} from '@angular-devkit/core';
import {Tree} from '@angular-devkit/schematics';
/** Name of the default Angular CLI workspace configuration files. */
@ -18,9 +19,9 @@ const defaultWorkspaceConfigPaths = ['/angular.json', '/.angular.json'];
export function getProjectTsConfigPaths(tree: Tree): string[] {
// Start with some tsconfig paths that are generally used within CLI projects.
const tsconfigPaths = new Set<string>([
'./tsconfig.json',
'./src/tsconfig.json',
'./src/tsconfig.app.json',
'tsconfig.json',
'src/tsconfig.json',
'src/tsconfig.app.json',
]);
// 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[] {
['build', 'test'].forEach(targetName => {
if (project.targets && project.targets[targetName] && project.targets[targetName].options &&
project.targets[targetName].options.tsConfig) {
tsconfigPaths.add(project.targets[targetName].options.tsConfig);
tsconfigPaths.add(normalize(project.targets[targetName].options.tsConfig));
}
if (project.architect && project.architect[targetName] &&
project.architect[targetName].options &&
project.architect[targetName].options.tsConfig) {
tsconfigPaths.add(project.architect[targetName].options.tsConfig);
tsconfigPaths.add(normalize(project.architect[targetName].options.tsConfig));
}
});
}