[6a3a178] | 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 | */
|
---|
| 9 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
---|
| 10 | if (k2 === undefined) k2 = k;
|
---|
| 11 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
---|
| 12 | }) : (function(o, m, k, k2) {
|
---|
| 13 | if (k2 === undefined) k2 = k;
|
---|
| 14 | o[k2] = m[k];
|
---|
| 15 | }));
|
---|
| 16 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
---|
| 17 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
| 18 | }) : function(o, v) {
|
---|
| 19 | o["default"] = v;
|
---|
| 20 | });
|
---|
| 21 | var __importStar = (this && this.__importStar) || function (mod) {
|
---|
| 22 | if (mod && mod.__esModule) return mod;
|
---|
| 23 | var result = {};
|
---|
| 24 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
---|
| 25 | __setModuleDefault(result, mod);
|
---|
| 26 | return result;
|
---|
| 27 | };
|
---|
| 28 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 29 | exports.findWorkspaceFile = void 0;
|
---|
| 30 | const core_1 = require("@angular-devkit/core");
|
---|
| 31 | const fs = __importStar(require("fs"));
|
---|
| 32 | const os = __importStar(require("os"));
|
---|
| 33 | const path = __importStar(require("path"));
|
---|
| 34 | const find_up_1 = require("./find-up");
|
---|
| 35 | function findWorkspaceFile(currentDirectory = process.cwd()) {
|
---|
| 36 | const possibleConfigFiles = [
|
---|
| 37 | 'angular.json',
|
---|
| 38 | '.angular.json',
|
---|
| 39 | 'angular-cli.json',
|
---|
| 40 | '.angular-cli.json',
|
---|
| 41 | ];
|
---|
| 42 | const configFilePath = find_up_1.findUp(possibleConfigFiles, currentDirectory);
|
---|
| 43 | if (configFilePath === null) {
|
---|
| 44 | return null;
|
---|
| 45 | }
|
---|
| 46 | const possibleDir = path.dirname(configFilePath);
|
---|
| 47 | const homedir = os.homedir();
|
---|
| 48 | if (core_1.normalize(possibleDir) === core_1.normalize(homedir)) {
|
---|
| 49 | const packageJsonPath = path.join(possibleDir, 'package.json');
|
---|
| 50 | try {
|
---|
| 51 | const packageJsonText = fs.readFileSync(packageJsonPath, 'utf-8');
|
---|
| 52 | const packageJson = JSON.parse(packageJsonText);
|
---|
| 53 | if (!containsCliDep(packageJson)) {
|
---|
| 54 | // No CLI dependency
|
---|
| 55 | return null;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | catch {
|
---|
| 59 | // No or invalid package.json
|
---|
| 60 | return null;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | return configFilePath;
|
---|
| 64 | }
|
---|
| 65 | exports.findWorkspaceFile = findWorkspaceFile;
|
---|
| 66 | function containsCliDep(obj) {
|
---|
| 67 | var _a, _b;
|
---|
| 68 | const pkgName = '@angular/cli';
|
---|
| 69 | if (!obj) {
|
---|
| 70 | return false;
|
---|
| 71 | }
|
---|
| 72 | return !!(((_a = obj.dependencies) === null || _a === void 0 ? void 0 : _a[pkgName]) || ((_b = obj.devDependencies) === null || _b === void 0 ? void 0 : _b[pkgName]));
|
---|
| 73 | }
|
---|