1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | (function (factory) {
|
---|
9 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
10 | var v = factory(require, exports);
|
---|
11 | if (v !== undefined) module.exports = v;
|
---|
12 | }
|
---|
13 | else if (typeof define === "function" && define.amd) {
|
---|
14 | define("@angular/core/schematics/utils/project_tsconfig_paths", ["require", "exports", "@angular-devkit/core"], factory);
|
---|
15 | }
|
---|
16 | })(function (require, exports) {
|
---|
17 | "use strict";
|
---|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
19 | exports.getProjectTsConfigPaths = void 0;
|
---|
20 | const core_1 = require("@angular-devkit/core");
|
---|
21 | /** Name of the default Angular CLI workspace configuration files. */
|
---|
22 | const defaultWorkspaceConfigPaths = ['/angular.json', '/.angular.json'];
|
---|
23 | /**
|
---|
24 | * Gets all tsconfig paths from a CLI project by reading the workspace configuration
|
---|
25 | * and looking for common tsconfig locations.
|
---|
26 | */
|
---|
27 | function getProjectTsConfigPaths(tree) {
|
---|
28 | // Start with some tsconfig paths that are generally used within CLI projects. Note
|
---|
29 | // that we are not interested in IDE-specific tsconfig files (e.g. /tsconfig.json)
|
---|
30 | const buildPaths = new Set(['src/tsconfig.app.json']);
|
---|
31 | const testPaths = new Set(['src/tsconfig.spec.json']);
|
---|
32 | // Add any tsconfig directly referenced in a build or test task of the angular.json workspace.
|
---|
33 | const workspace = getWorkspaceConfigGracefully(tree);
|
---|
34 | if (workspace) {
|
---|
35 | const projects = Object.keys(workspace.projects).map(name => workspace.projects[name]);
|
---|
36 | for (const project of projects) {
|
---|
37 | const buildPath = getTargetTsconfigPath(project, 'build');
|
---|
38 | const testPath = getTargetTsconfigPath(project, 'test');
|
---|
39 | if (buildPath) {
|
---|
40 | buildPaths.add(buildPath);
|
---|
41 | }
|
---|
42 | if (testPath) {
|
---|
43 | testPaths.add(testPath);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
47 | // Filter out tsconfig files that don't exist in the CLI project.
|
---|
48 | return {
|
---|
49 | buildPaths: Array.from(buildPaths).filter(p => tree.exists(p)),
|
---|
50 | testPaths: Array.from(testPaths).filter(p => tree.exists(p)),
|
---|
51 | };
|
---|
52 | }
|
---|
53 | exports.getProjectTsConfigPaths = getProjectTsConfigPaths;
|
---|
54 | /** Gets the tsconfig path from the given target within the specified project. */
|
---|
55 | function getTargetTsconfigPath(project, targetName) {
|
---|
56 | if (project.targets && project.targets[targetName] && project.targets[targetName].options &&
|
---|
57 | project.targets[targetName].options.tsConfig) {
|
---|
58 | return core_1.normalize(project.targets[targetName].options.tsConfig);
|
---|
59 | }
|
---|
60 | if (project.architect && project.architect[targetName] && project.architect[targetName].options &&
|
---|
61 | project.architect[targetName].options.tsConfig) {
|
---|
62 | return core_1.normalize(project.architect[targetName].options.tsConfig);
|
---|
63 | }
|
---|
64 | return null;
|
---|
65 | }
|
---|
66 | /**
|
---|
67 | * Resolve the workspace configuration of the specified tree gracefully. We cannot use the utility
|
---|
68 | * functions from the default Angular schematics because those might not be present in older
|
---|
69 | * versions of the CLI. Also it's important to resolve the workspace gracefully because
|
---|
70 | * the CLI project could be still using `.angular-cli.json` instead of thew new config.
|
---|
71 | */
|
---|
72 | function getWorkspaceConfigGracefully(tree) {
|
---|
73 | const path = defaultWorkspaceConfigPaths.find(filePath => tree.exists(filePath));
|
---|
74 | const configBuffer = tree.read(path);
|
---|
75 | if (!path || !configBuffer) {
|
---|
76 | return null;
|
---|
77 | }
|
---|
78 | try {
|
---|
79 | // Parse the workspace file as JSON5 which is also supported for CLI
|
---|
80 | // workspace configurations.
|
---|
81 | return core_1.parseJson(configBuffer.toString(), core_1.JsonParseMode.Json5);
|
---|
82 | }
|
---|
83 | catch (e) {
|
---|
84 | return null;
|
---|
85 | }
|
---|
86 | }
|
---|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