project-tsconfig-paths.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.dev/license
  8. */
  9. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  10. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  11. return new (P || (P = Promise))(function (resolve, reject) {
  12. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  13. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  14. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  15. step((generator = generator.apply(thisArg, _arguments || [])).next());
  16. });
  17. };
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. exports.getTargetTsconfigPath = getTargetTsconfigPath;
  20. exports.getWorkspaceConfigGracefully = getWorkspaceConfigGracefully;
  21. const core_1 = require("@angular-devkit/core");
  22. const workspace_1 = require("@schematics/angular/utility/workspace");
  23. /** Name of the default Angular CLI workspace configuration files. */
  24. const defaultWorkspaceConfigPaths = ['/angular.json', '/.angular.json'];
  25. /** Gets the tsconfig path from the given target within the specified project. */
  26. function getTargetTsconfigPath(project, targetName) {
  27. var _a, _b, _c;
  28. const tsconfig = (_c = (_b = (_a = project.targets) === null || _a === void 0 ? void 0 : _a.get(targetName)) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c['tsConfig'];
  29. return tsconfig ? (0, core_1.normalize)(tsconfig) : null;
  30. }
  31. /** Resolve the workspace configuration of the specified tree gracefully. */
  32. function getWorkspaceConfigGracefully(tree) {
  33. return __awaiter(this, void 0, void 0, function* () {
  34. const path = defaultWorkspaceConfigPaths.find(filePath => tree.exists(filePath));
  35. if (!path) {
  36. return null;
  37. }
  38. try {
  39. return (0, workspace_1.getWorkspace)(tree, path);
  40. }
  41. catch (_a) {
  42. return null;
  43. }
  44. });
  45. }
  46. //# sourceMappingURL=project-tsconfig-paths.js.map