Commit c58c57f6 authored by nanahira's avatar nanahira

support plugin group

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