[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.getProjectDependencies = exports.findPackageJson = exports.readPackageJson = void 0;
|
---|
| 30 | const fs = __importStar(require("fs"));
|
---|
| 31 | const path_1 = require("path");
|
---|
| 32 | const resolve = __importStar(require("resolve"));
|
---|
| 33 | function getAllDependencies(pkg) {
|
---|
| 34 | return new Set([
|
---|
| 35 | ...Object.entries(pkg.dependencies || []),
|
---|
| 36 | ...Object.entries(pkg.devDependencies || []),
|
---|
| 37 | ...Object.entries(pkg.peerDependencies || []),
|
---|
| 38 | ...Object.entries(pkg.optionalDependencies || []),
|
---|
| 39 | ]);
|
---|
| 40 | }
|
---|
| 41 | async function readPackageJson(packageJsonPath) {
|
---|
| 42 | try {
|
---|
| 43 | return JSON.parse((await fs.promises.readFile(packageJsonPath)).toString());
|
---|
| 44 | }
|
---|
| 45 | catch {
|
---|
| 46 | return undefined;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | exports.readPackageJson = readPackageJson;
|
---|
| 50 | function findPackageJson(workspaceDir, packageName) {
|
---|
| 51 | try {
|
---|
| 52 | // avoid require.resolve here, see: https://github.com/angular/angular-cli/pull/18610#issuecomment-681980185
|
---|
| 53 | const packageJsonPath = resolve.sync(`${packageName}/package.json`, { basedir: workspaceDir });
|
---|
| 54 | return packageJsonPath;
|
---|
| 55 | }
|
---|
| 56 | catch {
|
---|
| 57 | return undefined;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | exports.findPackageJson = findPackageJson;
|
---|
| 61 | async function getProjectDependencies(dir) {
|
---|
| 62 | const pkg = await readPackageJson(path_1.join(dir, 'package.json'));
|
---|
| 63 | if (!pkg) {
|
---|
| 64 | throw new Error('Could not find package.json');
|
---|
| 65 | }
|
---|
| 66 | const results = new Map();
|
---|
| 67 | for (const [name, version] of getAllDependencies(pkg)) {
|
---|
| 68 | const packageJsonPath = findPackageJson(dir, name);
|
---|
| 69 | if (!packageJsonPath) {
|
---|
| 70 | continue;
|
---|
| 71 | }
|
---|
| 72 | results.set(name, {
|
---|
| 73 | name,
|
---|
| 74 | version,
|
---|
| 75 | path: path_1.dirname(packageJsonPath),
|
---|
| 76 | package: await readPackageJson(packageJsonPath),
|
---|
| 77 | });
|
---|
| 78 | }
|
---|
| 79 | return results;
|
---|
| 80 | }
|
---|
| 81 | exports.getProjectDependencies = getProjectDependencies;
|
---|