UNPKG

2.22 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.listInstalledPlugins = exports.getInstalledPluginsFromPackageJson = void 0;
4const chalk = require("chalk");
5const devkit_1 = require("@nrwl/devkit");
6const output_1 = require("../output");
7const plugin_capabilities_1 = require("./plugin-capabilities");
8const shared_1 = require("./shared");
9const package_json_1 = require("nx/src/utils/package-json");
10function getInstalledPluginsFromPackageJson(workspaceRoot, corePlugins, communityPlugins = []) {
11 const packageJson = (0, devkit_1.readJsonFile)(`${workspaceRoot}/package.json`);
12 const plugins = new Set([
13 ...corePlugins.map((p) => p.name),
14 ...communityPlugins.map((p) => p.name),
15 ...Object.keys(packageJson.dependencies || {}),
16 ...Object.keys(packageJson.devDependencies || {}),
17 ]);
18 return new Map(Array.from(plugins)
19 .filter((name) => {
20 try {
21 // Check for `package.json` existence instead of requiring the module itself
22 // because malformed entries like `main`, may throw false exceptions.
23 (0, package_json_1.readModulePackageJson)(name);
24 return true;
25 }
26 catch (_a) {
27 return false;
28 }
29 })
30 .sort()
31 .map((name) => [
32 name,
33 (0, plugin_capabilities_1.getPluginCapabilities)(workspaceRoot, name),
34 ])
35 .filter(([, x]) => x && !!(x.generators || x.executors)));
36}
37exports.getInstalledPluginsFromPackageJson = getInstalledPluginsFromPackageJson;
38function listInstalledPlugins(installedPlugins) {
39 const bodyLines = [];
40 for (const [, p] of installedPlugins) {
41 const capabilities = [];
42 if ((0, shared_1.hasElements)(p.executors)) {
43 capabilities.push('executors');
44 }
45 if ((0, shared_1.hasElements)(p.generators)) {
46 capabilities.push('generators');
47 }
48 bodyLines.push(`${chalk.bold(p.name)} (${capabilities.join()})`);
49 }
50 output_1.output.log({
51 title: `Installed plugins:`,
52 bodyLines: bodyLines,
53 });
54}
55exports.listInstalledPlugins = listInstalledPlugins;
56//# sourceMappingURL=installed-plugins.js.map
\No newline at end of file