Commit 2c25ae0f authored by nanahira's avatar nanahira

fix plugin types again

parent 4c5d536c
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
"ws": "^8.2.3" "ws": "^8.2.3"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.0.0-rc.0" "koishi": "^4.0.0-rc.1"
} }
}, },
"node_modules/@babel/code-frame": { "node_modules/@babel/code-frame": {
......
...@@ -24,22 +24,32 @@ export interface ContextSelector { ...@@ -24,22 +24,32 @@ export interface ContextSelector {
export type KoishiPluginOptions<T extends Plugin> = boolean | Plugin.Config<T>; export type KoishiPluginOptions<T extends Plugin> = boolean | Plugin.Config<T>;
export interface KoishiModulePlugin<T extends Plugin> extends ContextSelector { export interface KoishiModulePluginExact<T extends Plugin>
plugin: T | string; extends ContextSelector {
options?: boolean | KoishiPluginOptions<T> | any; plugin: T;
options?: boolean | KoishiPluginOptions<T>;
} }
export function PluginDef<T extends keyof Plugin>( export interface KoishiModulePluginName extends ContextSelector {
plugin: string;
options?: any;
}
export type KoishiModulePlugin<T extends Plugin = any> =
| KoishiModulePluginExact<T>
| KoishiModulePluginName;
export function PluginDef(
name: string, name: string,
options?: any, options?: any,
select?: Selection, select?: Selection,
); ): KoishiModulePluginName;
export function PluginDef<T extends Plugin>( export function PluginDef<T extends Plugin>(
plugin: T, plugin: T,
options?: KoishiModulePlugin<T>, options?: KoishiPluginOptions<T>,
select?: Selection, select?: Selection,
); ): KoishiModulePluginExact<T>;
export function PluginDef<T extends keyof Plugin>( export function PluginDef<T extends Plugin>(
plugin: T, plugin: T,
options?: KoishiPluginOptions<T>, options?: KoishiPluginOptions<T>,
select?: Selection, select?: Selection,
......
import { App } from 'koishi';
import { DefinePlugin } from '../src/register';
import { UsePlugin } from '../src/decorators';
import { PluginDef } from '../src/def';
import PluginLru from '@koishijs/plugin-cache-lru';
import PluginOnebot from '@koishijs/plugin-adapter-onebot';
@DefinePlugin()
class MyPlugin {
@UsePlugin()
loadLru() {
return PluginDef(PluginLru);
}
@UsePlugin()
loadOnebot() {
return PluginDef(PluginOnebot, { bots: [] });
}
}
describe('Inner plugin', () => {
let app: App;
beforeEach(() => {
app = new App();
// app.plugin(PluginOnebot, { bots: [] });
});
it('should load inner plugin properly', () => {});
});
...@@ -94,8 +94,8 @@ describe('Apply and Connect in koishi-thirdeye', () => { ...@@ -94,8 +94,8 @@ describe('Apply and Connect in koishi-thirdeye', () => {
app.plugin(MyPlugin2); app.plugin(MyPlugin2);
await RunApplyTest(app); await RunApplyTest(app);
}); });
/*it('should be applied and connected with non-immediate dependency', async () => { it('should be applied and connected with non-immediate dependency', async () => {
app.plugin(MyPlugin3); app.plugin(MyPlugin3);
await RunApplyTest(app); await RunApplyTest(app);
});*/ });
}); });
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