Commit c58c57f6 authored by nanahira's avatar nanahira

support plugin group

parent 86e96d62
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
"version": "6.2.1", "version": "6.2.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@koishijs/cli": "^4.7.2", "@koishijs/cli": "^4.7.3",
"@koishijs/loader": "^1.0.1", "@koishijs/loader": "^1.0.1",
"@koishijs/plugin-database-mysql": "^4.4.2", "@koishijs/plugin-database-mysql": "^4.4.3",
"@koishijs/plugin-help": "^1.0.1", "@koishijs/plugin-help": "^1.0.1",
"@koishijs/plugin-suggest": "^1.1.0", "@koishijs/plugin-suggest": "^1.1.0",
"koishi": "^4.7.2", "koishi": "^4.7.3",
"load-json-file": "^6.2.0", "load-json-file": "^6.2.0",
"ws": "^8.2.3", "ws": "^8.2.3",
"yaml": "^1.10.2" "yaml": "^1.10.2"
...@@ -191,9 +191,9 @@ ...@@ -191,9 +191,9 @@
} }
}, },
"node_modules/@koishijs/cli": { "node_modules/@koishijs/cli": {
"version": "4.7.2", "version": "4.7.3",
"resolved": "https://registry.npmjs.org/@koishijs/cli/-/cli-4.7.2.tgz", "resolved": "https://registry.npmjs.org/@koishijs/cli/-/cli-4.7.3.tgz",
"integrity": "sha512-1xv9he+uSNrjVaWb18xF18/P/xK/zLNUwJrXfc94CakiiOOkCMkj4WUkI3/Q3p/Qqh61JYB7bZcPZHFruOCzmw==", "integrity": "sha512-HX4eVGVkyofXvhJD5/ViisDF4Y5YD4H/02hgSjqLyd2Ui7X1ekwdO43eLKCwrFmM9C3SBIajV+n8H7wt3sH9Xg==",
"dependencies": { "dependencies": {
"@koishijs/loader": "^1.0.1", "@koishijs/loader": "^1.0.1",
"cac": "^6.7.12", "cac": "^6.7.12",
...@@ -211,16 +211,16 @@ ...@@ -211,16 +211,16 @@
"node": ">=12.0.0" "node": ">=12.0.0"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.7.2" "koishi": "^4.7.3"
} }
}, },
"node_modules/@koishijs/core": { "node_modules/@koishijs/core": {
"version": "4.7.2", "version": "4.7.3",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.7.2.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.7.3.tgz",
"integrity": "sha512-yO5Pyki1RV+MSqR1IzX02z6wLlJRej7RSH7zW4/+nd5r1fimtDaODiQz/F7lGfcuVthIPDg2aPxJXkl8eLCoSw==", "integrity": "sha512-05ZfusnZPbGt5oIBFkhYh1I6eCYGDpoIyR1tvmfEtPXya9zdNtdhHK0PR3/TwFUq8hSz8Xko1oqCLY3pqr0ZXg==",
"dependencies": { "dependencies": {
"@koishijs/utils": "^5.4.5", "@koishijs/utils": "^5.4.5",
"cordis": "^1.2.2", "cordis": "^1.3.2",
"fastest-levenshtein": "^1.0.12", "fastest-levenshtein": "^1.0.12",
"minato": "^1.1.0" "minato": "^1.1.0"
}, },
...@@ -253,14 +253,14 @@ ...@@ -253,14 +253,14 @@
} }
}, },
"node_modules/@koishijs/plugin-database-mysql": { "node_modules/@koishijs/plugin-database-mysql": {
"version": "4.4.2", "version": "4.4.3",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-database-mysql/-/plugin-database-mysql-4.4.2.tgz", "resolved": "https://registry.npmjs.org/@koishijs/plugin-database-mysql/-/plugin-database-mysql-4.4.3.tgz",
"integrity": "sha512-1Grt9+PC4BuG3fODirkQeZ/4ZAEzntiBkIORA4QgK1R277E+7c2n+7UObsYJDmOLa4/jCOnJIzgZaLmsELbgBg==", "integrity": "sha512-IhCFeRKVIo8xphe3FJdQIdaABvM+mnNG/82mSohaz3w/DOJnFuI+jnywyiPpB7p+7qh/YXOhxnzDuhwOD0LjGA==",
"dependencies": { "dependencies": {
"@minatojs/driver-mysql": "^1.1.0" "@minatojs/driver-mysql": "^1.1.0"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.7.2" "koishi": "^4.7.3"
} }
}, },
"node_modules/@koishijs/plugin-help": { "node_modules/@koishijs/plugin-help": {
...@@ -1155,9 +1155,9 @@ ...@@ -1155,9 +1155,9 @@
"integrity": "sha512-3DdaFaU/Zf1AnpLiFDeNCD4TOWe3Zl2RZaTzUvWiIk5ERzcCodOE20Vqq4fzCbNoHURFHT4/us/Lfq+S2zyY4w==" "integrity": "sha512-3DdaFaU/Zf1AnpLiFDeNCD4TOWe3Zl2RZaTzUvWiIk5ERzcCodOE20Vqq4fzCbNoHURFHT4/us/Lfq+S2zyY4w=="
}, },
"node_modules/cordis": { "node_modules/cordis": {
"version": "1.2.2", "version": "1.3.2",
"resolved": "https://registry.npmjs.org/cordis/-/cordis-1.2.2.tgz", "resolved": "https://registry.npmjs.org/cordis/-/cordis-1.3.2.tgz",
"integrity": "sha512-R6RhHuBu6be5DGXBkIGyw3W/yPBPqr69KBVEGVgBY38DzMBIXilmsfAdVdIIEe3G0vlnn5rtAgsMg2yGwRpkiQ==", "integrity": "sha512-nfz0iJlfwhSmTDpxbu4s7kRxYsn8XZ7s3hyXJrVdNj4UmB3xXDUYblKFbJKAfcAnwYLlAtpvP+7LRhU+zDyMcA==",
"dependencies": { "dependencies": {
"cosmokit": "^1.1.2" "cosmokit": "^1.1.2"
} }
...@@ -2349,12 +2349,12 @@ ...@@ -2349,12 +2349,12 @@
} }
}, },
"node_modules/koishi": { "node_modules/koishi": {
"version": "4.7.2", "version": "4.7.3",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.7.2.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.7.3.tgz",
"integrity": "sha512-oH1yIGX8skfPO4WcLPpnNqt+qzETVux7OIAK9jkMQxHLJv1fq1/OqsLS0wTvpTJ8qFZLt49lZ3gbLujga43RPA==", "integrity": "sha512-JfQJwUKXlfpybNSjXHUbdGB7giDt5FWzEcwD6brhhE/uM9PGs7c5dHyZsOKnlMi3JTCjjvdSxBz4C/KxXZko1g==",
"dependencies": { "dependencies": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.7.2", "@koishijs/core": "^4.7.3",
"@koishijs/utils": "^5.4.5", "@koishijs/utils": "^5.4.5",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
...@@ -3829,9 +3829,9 @@ ...@@ -3829,9 +3829,9 @@
} }
}, },
"@koishijs/cli": { "@koishijs/cli": {
"version": "4.7.2", "version": "4.7.3",
"resolved": "https://registry.npmjs.org/@koishijs/cli/-/cli-4.7.2.tgz", "resolved": "https://registry.npmjs.org/@koishijs/cli/-/cli-4.7.3.tgz",
"integrity": "sha512-1xv9he+uSNrjVaWb18xF18/P/xK/zLNUwJrXfc94CakiiOOkCMkj4WUkI3/Q3p/Qqh61JYB7bZcPZHFruOCzmw==", "integrity": "sha512-HX4eVGVkyofXvhJD5/ViisDF4Y5YD4H/02hgSjqLyd2Ui7X1ekwdO43eLKCwrFmM9C3SBIajV+n8H7wt3sH9Xg==",
"requires": { "requires": {
"@koishijs/loader": "^1.0.1", "@koishijs/loader": "^1.0.1",
"cac": "^6.7.12", "cac": "^6.7.12",
...@@ -3844,12 +3844,12 @@ ...@@ -3844,12 +3844,12 @@
} }
}, },
"@koishijs/core": { "@koishijs/core": {
"version": "4.7.2", "version": "4.7.3",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.7.2.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.7.3.tgz",
"integrity": "sha512-yO5Pyki1RV+MSqR1IzX02z6wLlJRej7RSH7zW4/+nd5r1fimtDaODiQz/F7lGfcuVthIPDg2aPxJXkl8eLCoSw==", "integrity": "sha512-05ZfusnZPbGt5oIBFkhYh1I6eCYGDpoIyR1tvmfEtPXya9zdNtdhHK0PR3/TwFUq8hSz8Xko1oqCLY3pqr0ZXg==",
"requires": { "requires": {
"@koishijs/utils": "^5.4.5", "@koishijs/utils": "^5.4.5",
"cordis": "^1.2.2", "cordis": "^1.3.2",
"fastest-levenshtein": "^1.0.12", "fastest-levenshtein": "^1.0.12",
"minato": "^1.1.0" "minato": "^1.1.0"
} }
...@@ -3878,9 +3878,9 @@ ...@@ -3878,9 +3878,9 @@
} }
}, },
"@koishijs/plugin-database-mysql": { "@koishijs/plugin-database-mysql": {
"version": "4.4.2", "version": "4.4.3",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-database-mysql/-/plugin-database-mysql-4.4.2.tgz", "resolved": "https://registry.npmjs.org/@koishijs/plugin-database-mysql/-/plugin-database-mysql-4.4.3.tgz",
"integrity": "sha512-1Grt9+PC4BuG3fODirkQeZ/4ZAEzntiBkIORA4QgK1R277E+7c2n+7UObsYJDmOLa4/jCOnJIzgZaLmsELbgBg==", "integrity": "sha512-IhCFeRKVIo8xphe3FJdQIdaABvM+mnNG/82mSohaz3w/DOJnFuI+jnywyiPpB7p+7qh/YXOhxnzDuhwOD0LjGA==",
"requires": { "requires": {
"@minatojs/driver-mysql": "^1.1.0" "@minatojs/driver-mysql": "^1.1.0"
} }
...@@ -4572,9 +4572,9 @@ ...@@ -4572,9 +4572,9 @@
"integrity": "sha512-3DdaFaU/Zf1AnpLiFDeNCD4TOWe3Zl2RZaTzUvWiIk5ERzcCodOE20Vqq4fzCbNoHURFHT4/us/Lfq+S2zyY4w==" "integrity": "sha512-3DdaFaU/Zf1AnpLiFDeNCD4TOWe3Zl2RZaTzUvWiIk5ERzcCodOE20Vqq4fzCbNoHURFHT4/us/Lfq+S2zyY4w=="
}, },
"cordis": { "cordis": {
"version": "1.2.2", "version": "1.3.2",
"resolved": "https://registry.npmjs.org/cordis/-/cordis-1.2.2.tgz", "resolved": "https://registry.npmjs.org/cordis/-/cordis-1.3.2.tgz",
"integrity": "sha512-R6RhHuBu6be5DGXBkIGyw3W/yPBPqr69KBVEGVgBY38DzMBIXilmsfAdVdIIEe3G0vlnn5rtAgsMg2yGwRpkiQ==", "integrity": "sha512-nfz0iJlfwhSmTDpxbu4s7kRxYsn8XZ7s3hyXJrVdNj4UmB3xXDUYblKFbJKAfcAnwYLlAtpvP+7LRhU+zDyMcA==",
"requires": { "requires": {
"cosmokit": "^1.1.2" "cosmokit": "^1.1.2"
} }
...@@ -5457,12 +5457,12 @@ ...@@ -5457,12 +5457,12 @@
} }
}, },
"koishi": { "koishi": {
"version": "4.7.2", "version": "4.7.3",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.7.2.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.7.3.tgz",
"integrity": "sha512-oH1yIGX8skfPO4WcLPpnNqt+qzETVux7OIAK9jkMQxHLJv1fq1/OqsLS0wTvpTJ8qFZLt49lZ3gbLujga43RPA==", "integrity": "sha512-JfQJwUKXlfpybNSjXHUbdGB7giDt5FWzEcwD6brhhE/uM9PGs7c5dHyZsOKnlMi3JTCjjvdSxBz4C/KxXZko1g==",
"requires": { "requires": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.7.2", "@koishijs/core": "^4.7.3",
"@koishijs/utils": "^5.4.5", "@koishijs/utils": "^5.4.5",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
......
export interface PluginInstallConfig { export interface PluginInstallConfig {
$install: boolean | string; $install: boolean | string;
$version: string; $version: string;
$community?: boolean;
$official?: boolean;
} }
export type PluginEntries = {
[K in string]: K extends `+${string}` ? PluginEntries : PluginInstallConfig;
};
export interface KoishiConfig { export interface KoishiConfig {
plugins: Record<string, PluginInstallConfig>; plugins: PluginEntries;
} }
export interface PackageConfig { export interface PackageConfig {
......
...@@ -5,7 +5,7 @@ import { promisify } from 'util'; ...@@ -5,7 +5,7 @@ import { promisify } from 'util';
import path from 'path'; import path from 'path';
import { getPackageJsonPackages } from './utils/read-package-json'; import { getPackageJsonPackages } from './utils/read-package-json';
import ConfigLoader from '@koishijs/loader'; import ConfigLoader from '@koishijs/loader';
import { KoishiConfig } from './def/interfaces'; import { KoishiConfig, PluginInstallConfig } from './def/interfaces';
const execFileAsync = promisify(execFile); const execFileAsync = promisify(execFile);
const logger = new Logger('bootstrap-install-plugin'); const logger = new Logger('bootstrap-install-plugin');
...@@ -54,6 +54,10 @@ async function npmInstall(name: string) { ...@@ -54,6 +54,10 @@ async function npmInstall(name: string) {
} }
} }
async function tryInstallPackages(names: string[]) { async function tryInstallPackages(names: string[]) {
if (process.env.DRY_RUN) {
logger.info(`Will install packages ${names.join(', ')}.`);
return true;
}
for (const name of names) { for (const name of names) {
if (await npmInstall(name)) { if (await npmInstall(name)) {
return true; return true;
...@@ -62,17 +66,22 @@ async function tryInstallPackages(names: string[]) { ...@@ -62,17 +66,22 @@ async function tryInstallPackages(names: string[]) {
return false; return false;
} }
async function installPlugin(name: string, info: any) { async function installPlugin(name: string, info: PluginInstallConfig) {
const suffixMatching = name.match(/(.+)@.+/);
if (suffixMatching) {
name = suffixMatching[1];
}
if (name.match(/^([\.\/~\\]|[A-Za-z]:[\/\\])/)) { if (name.match(/^([\.\/~\\]|[A-Za-z]:[\/\\])/)) {
logger.info(`Plugin ${name} is a local plugin, skipping.`); logger.info(`Plugin ${name} is a local plugin, skipping.`);
return; return;
} }
const version: string = const version =
info.$version || info.$version ||
(typeof info.$install === 'string' ? info.$install : undefined); (typeof info.$install === 'string' ? info.$install : undefined);
logger.info(`Installing plugin ${name}@${version || 'unknown'}.`); logger.info(`Installing plugin ${name}@${version || '*'}.`);
const allowCommunity = !info.$official; const allowCommunity = !info.$official;
const allowOfficial = !info.$community; const allowOfficial = !info.$community;
if (!allowCommunity && !allowOfficial) { if (!allowCommunity && !allowOfficial) {
...@@ -134,8 +143,19 @@ export async function installPluginEntry() { ...@@ -134,8 +143,19 @@ export async function installPluginEntry() {
// console.log(config.plugins); // console.log(config.plugins);
logger.info(`Cleaning NPM cache.`); logger.info(`Cleaning NPM cache.`);
await execFileAsync('npm', ['cache', 'clean', '--force']); await execFileAsync('npm', ['cache', 'clean', '--force']);
for (const [name, info] of Object.entries(plugins)) { let queue = Object.entries(plugins).reverse();
if ((!info.$install && !info.$version) || name.startsWith('~')) { while (queue.length) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const [name, info] = queue.pop()!;
if (name.startsWith('~') || !info) {
// disabled plugin
continue;
}
if (name.startsWith('+')) {
queue = queue.concat(Object.entries(info).reverse());
continue;
}
if (!info.$install && !info.$version) {
continue; continue;
} }
await installPlugin(name, info); await installPlugin(name, info);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment