Skip to content

Commit 2bb6964

Browse files
committed
feat: generate knownPlugins list at compile time
1 parent 7971b42 commit 2bb6964

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

packages/commandkit/src/cli/information.ts

+46-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,52 @@ import { version as commandkitVersion } from '../version';
44
import fs from 'node:fs';
55
import path from 'node:path';
66

7+
function $getKnownPlugins() {
8+
'use macro';
9+
10+
// remove name from the list when that plugin is stable
11+
const BLACKLISTED = new Set([
12+
'commandkit', // core package itself, not a plugin
13+
'create-commandkit', // generator, not a plugin
14+
'tsconfig', // repo config related, not a plugin
15+
'devtools-ui', // the ui part of devtools, not a plugin
16+
// the plugins below are TBD
17+
'devtools',
18+
'tasks',
19+
]);
20+
21+
const { readdirSync, readFileSync } =
22+
require('node:fs') as typeof import('node:fs');
23+
const { join } = require('node:path') as typeof path;
24+
25+
const pluginsPath = join(__dirname, '..', '..', '..');
26+
27+
const entries = readdirSync(pluginsPath, { withFileTypes: true }).filter(
28+
(e) => !BLACKLISTED.has(e.name),
29+
);
30+
31+
const packages = entries.map((p) =>
32+
join(p.parentPath, p.name, 'package.json'),
33+
);
34+
35+
const knownPlugins: string[] = [];
36+
37+
for (const pkg of packages) {
38+
try {
39+
const { name } = JSON.parse(readFileSync(pkg, 'utf8'));
40+
if (name && !BLACKLISTED.has(name)) {
41+
knownPlugins.push(name);
42+
}
43+
} catch {
44+
// Ignore errors
45+
}
46+
}
47+
48+
return knownPlugins;
49+
}
50+
51+
const knownPlugins: string[] = $getKnownPlugins();
52+
753
function findPackageVersion(packageName: string) {
854
try {
955
const packageJsonPath = require.resolve(`${packageName}/package.json`);
@@ -82,13 +128,6 @@ function getBinaryVersion(binary: string) {
82128
}
83129

84130
export async function showInformation() {
85-
const knownPlugins = [
86-
'@commandkit/redis',
87-
'@commandkit/legacy',
88-
'@commandkit/devtools',
89-
'@commandkit/i18n',
90-
];
91-
92131
const runtimeName: string = (() => {
93132
// @ts-ignore
94133
if ('Deno' in globalThis && typeof Deno !== 'undefined') return 'Deno';

0 commit comments

Comments
 (0)