UNPKG

1.84 kBJavaScriptView Raw
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.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.findWorkspaceFile = void 0;
11const core_1 = require("@angular-devkit/core");
12const fs = require("fs");
13const os = require("os");
14const path = require("path");
15const find_up_1 = require("./find-up");
16function findWorkspaceFile(currentDirectory = process.cwd()) {
17 const possibleConfigFiles = [
18 'angular.json',
19 '.angular.json',
20 'angular-cli.json',
21 '.angular-cli.json',
22 ];
23 const configFilePath = find_up_1.findUp(possibleConfigFiles, currentDirectory);
24 if (configFilePath === null) {
25 return null;
26 }
27 const possibleDir = path.dirname(configFilePath);
28 const homedir = os.homedir();
29 if (core_1.normalize(possibleDir) === core_1.normalize(homedir)) {
30 const packageJsonPath = path.join(possibleDir, 'package.json');
31 try {
32 const packageJsonText = fs.readFileSync(packageJsonPath, 'utf-8');
33 const packageJson = JSON.parse(packageJsonText);
34 if (!containsCliDep(packageJson)) {
35 // No CLI dependency
36 return null;
37 }
38 }
39 catch {
40 // No or invalid package.json
41 return null;
42 }
43 }
44 return configFilePath;
45}
46exports.findWorkspaceFile = findWorkspaceFile;
47function containsCliDep(obj) {
48 var _a, _b;
49 const pkgName = '@angular/cli';
50 if (!obj) {
51 return false;
52 }
53 return !!(((_a = obj.dependencies) === null || _a === void 0 ? void 0 : _a[pkgName]) || ((_b = obj.devDependencies) === null || _b === void 0 ? void 0 : _b[pkgName]));
54}