diff --git a/packages/core/schematics/test/project_tsconfig_paths_spec.ts b/packages/core/schematics/test/project_tsconfig_paths_spec.ts index b26137eb37..31cc793ae7 100644 --- a/packages/core/schematics/test/project_tsconfig_paths_spec.ts +++ b/packages/core/schematics/test/project_tsconfig_paths_spec.ts @@ -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']); + }); }); diff --git a/packages/core/schematics/utils/BUILD.bazel b/packages/core/schematics/utils/BUILD.bazel index cffc353f4d..df0004600e 100644 --- a/packages/core/schematics/utils/BUILD.bazel +++ b/packages/core/schematics/utils/BUILD.bazel @@ -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", + ], ) diff --git a/packages/core/schematics/utils/project_tsconfig_paths.ts b/packages/core/schematics/utils/project_tsconfig_paths.ts index 4623f012af..a6ef3219c7 100644 --- a/packages/core/schematics/utils/project_tsconfig_paths.ts +++ b/packages/core/schematics/utils/project_tsconfig_paths.ts @@ -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([ - './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)); } }); }