project-tsconfig-paths.ts (material2-7.3.4) | : | project-tsconfig-paths.ts (material2-7.3.5) | ||
---|---|---|---|---|
/** | /** | |||
* @license | * @license | |||
* Copyright Google LLC All Rights Reserved. | * Copyright Google LLC All Rights Reserved. | |||
* | * | |||
* Use of this source code is governed by an MIT-style license that can be | * Use of this source code is governed by an MIT-style license that can be | |||
* found in the LICENSE file at https://angular.io/license | * found in the LICENSE file at https://angular.io/license | |||
*/ | */ | |||
import {normalize} from '@angular-devkit/core'; | ||||
import {Tree} from '@angular-devkit/schematics'; | import {Tree} from '@angular-devkit/schematics'; | |||
/** Name of the default Angular CLI workspace configuration files. */ | ||||
const defaultWorkspaceConfigPaths = ['/angular.json', '/.angular.json']; | ||||
/** | /** | |||
* Gets all tsconfig paths from a CLI project by reading the workspace configura tion | * Gets all tsconfig paths from a CLI project by reading the workspace configura tion | |||
* and looking for common tsconfig locations. | * and looking for common tsconfig locations. | |||
*/ | */ | |||
export function getProjectTsConfigPaths(tree: Tree): string[] { | export function getProjectTsConfigPaths(tree: Tree): string[] { | |||
// Start with some tsconfig paths that are generally used within CLI projects. | // Start with some tsconfig paths that are generally used within CLI projects. | |||
const tsconfigPaths = new Set<string>([ | const tsconfigPaths = new Set<string>([ | |||
'./tsconfig.json', | 'tsconfig.json', | |||
'./src/tsconfig.json', | 'src/tsconfig.json', | |||
'./src/tsconfig.app.json', | 'src/tsconfig.app.json', | |||
]); | ]); | |||
// Add any tsconfig directly referenced in a build or test task of the angular .json workspace. | // Add any tsconfig directly referenced in a build or test task of the angular .json workspace. | |||
const workspace = getWorkspaceConfigGracefully(tree); | const workspace = getWorkspaceConfigGracefully(tree); | |||
if (workspace) { | if (workspace) { | |||
for (const project of Object.values<any>(workspace.projects)) { | for (const project of Object.values<any>(workspace.projects)) { | |||
['build', 'test'].forEach(targetName => { | ['build', 'test'].forEach(targetName => { | |||
if (project.targets && | if (project.targets && project.targets[targetName] && project.targets[ta | |||
project.targets[targetName] && | rgetName].options && | |||
project.targets[targetName].options && | ||||
project.targets[targetName].options.tsConfig) { | project.targets[targetName].options.tsConfig) { | |||
tsconfigPaths.add(project.targets[targetName].options.tsConfig); | tsconfigPaths.add(normalize(project.targets[targetName].options.tsConf ig)); | |||
} | } | |||
if (project.architect && | if (project.architect && project.architect[targetName] && | |||
project.architect[targetName] && | ||||
project.architect[targetName].options && | project.architect[targetName].options && | |||
project.architect[targetName].options.tsConfig) { | project.architect[targetName].options.tsConfig) { | |||
tsconfigPaths.add(project.architect[targetName].options.tsConfig); | tsconfigPaths.add(normalize(project.architect[targetName].options.tsCo nfig)); | |||
} | } | |||
}); | }); | |||
} | } | |||
} | } | |||
// Filter out tsconfig files that don't exist in the CLI project. | // Filter out tsconfig files that don't exist in the CLI project. | |||
return Array.from(tsconfigPaths).filter(p => tree.exists(p)); | return Array.from(tsconfigPaths).filter(p => tree.exists(p)); | |||
} | } | |||
/** Name of the default Angular CLI workspace configuration files. */ | ||||
const defaultWorkspaceConfigPaths = ['/angular.json', '/.angular.json']; | ||||
/** | /** | |||
* Resolve the workspace configuration of the specified tree gracefully. We cann ot use the utility | * Resolve the workspace configuration of the specified tree gracefully. We cann ot use the utility | |||
* functions from the default Angular schematics because those might not be pres ent in older | * functions from the default Angular schematics because those might not be pres ent in older | |||
* versions of the CLI. Also it's important to resolve the workspace gracefully because | * versions of the CLI. Also it's important to resolve the workspace gracefully because | |||
* the CLI project could be still using `.angular-cli.json` instead of thew new config. | * the CLI project could be still using `.angular-cli.json` instead of thew new config. | |||
*/ | */ | |||
function getWorkspaceConfigGracefully(tree: Tree): any { | function getWorkspaceConfigGracefully(tree: Tree): any { | |||
const path = defaultWorkspaceConfigPaths.filter(filePath => tree.exists(filePa | const path = defaultWorkspaceConfigPaths.find(filePath => tree.exists(filePath | |||
th))[0]; | )); | |||
const configBuffer = tree.read(path); | const configBuffer = tree.read(path!); | |||
if (!path || !configBuffer) { | if (!path || !configBuffer) { | |||
return null; | return null; | |||
} | } | |||
try { | try { | |||
return JSON.parse(configBuffer.toString()); | return JSON.parse(configBuffer.toString()); | |||
} catch { | } catch { | |||
return null; | return null; | |||
} | } | |||
End of changes. 9 change blocks. | ||||
16 lines changed or deleted | 15 lines changed or added |