@koishijs/loader
Advanced tools
Comparing version 4.2.4 to 4.2.5
@@ -65,3 +65,3 @@ /// <reference types="node" /> | ||
interpolate(source: any): any; | ||
resolvePlugin(name: string): Promise<any>; | ||
resolve(name: string): Promise<any>; | ||
keyFor(plugin: any): string; | ||
@@ -72,5 +72,11 @@ replace(oldKey: any, newKey: any): void; | ||
private logUpdate; | ||
reloadPlugin(parent: Context, key: string, source: any): Promise<import("cordis").ForkScope<Context>>; | ||
reload(parent: Context, key: string, source: any): Promise<import("cordis").ForkScope<Context>>; | ||
unload(ctx: Context, key: string): void; | ||
getRefName(fork: ForkScope): string; | ||
/** @deprecated */ | ||
resolvePlugin(name: string): Promise<any>; | ||
/** @deprecated */ | ||
reloadPlugin(ctx: Context, key: string, source: any): Promise<import("cordis").ForkScope<Context>>; | ||
/** @deprecated */ | ||
unloadPlugin(ctx: Context, key: string): void; | ||
getRefName(fork: ForkScope): string; | ||
paths(scope: EffectScope, suffix?: string[]): string[]; | ||
@@ -77,0 +83,0 @@ createApp(): Promise<Context>; |
@@ -72,3 +72,3 @@ var __create = Object.create; | ||
continue; | ||
ctx.loader.reloadPlugin(ctx, name, plugins[name]); | ||
ctx.loader.reload(ctx, name, plugins[name]); | ||
} | ||
@@ -82,7 +82,7 @@ ctx.accept((neo) => { | ||
if (!fork) { | ||
ctx.loader.reloadPlugin(ctx, key, neo[key]); | ||
ctx.loader.reload(ctx, key, neo[key]); | ||
} else if (!(key in neo)) { | ||
ctx.loader.unloadPlugin(ctx, key); | ||
ctx.loader.unload(ctx, key); | ||
} else { | ||
ctx.loader.reloadPlugin(ctx, key, neo[key] || {}); | ||
ctx.loader.reload(ctx, key, neo[key] || {}); | ||
} | ||
@@ -204,3 +204,3 @@ } | ||
} | ||
async resolvePlugin(name) { | ||
async resolve(name) { | ||
const plugin = unwrapExports(await this.import(name)); | ||
@@ -226,3 +226,3 @@ if (plugin) | ||
async forkPlugin(name, config, parent) { | ||
const plugin = await this.resolvePlugin(name); | ||
const plugin = await this.resolve(name); | ||
if (!plugin) | ||
@@ -241,3 +241,3 @@ return; | ||
} | ||
async reloadPlugin(parent, key, source) { | ||
async reload(parent, key, source) { | ||
let fork = parent.scope[_Loader.kRecord][key]; | ||
@@ -248,3 +248,3 @@ const name = key.split(":", 1)[0]; | ||
if (!this.isTruthyLike(meta.$if)) { | ||
this.unloadPlugin(parent, key); | ||
this.unload(parent, key); | ||
return; | ||
@@ -276,3 +276,3 @@ } | ||
} | ||
unloadPlugin(ctx, key) { | ||
unload(ctx, key) { | ||
const fork = ctx.scope[_Loader.kRecord][key]; | ||
@@ -295,2 +295,14 @@ if (fork) { | ||
} | ||
/** @deprecated */ | ||
resolvePlugin(name) { | ||
return this.resolve(name); | ||
} | ||
/** @deprecated */ | ||
reloadPlugin(ctx, key, source) { | ||
return this.reload(ctx, key, source); | ||
} | ||
/** @deprecated */ | ||
unloadPlugin(ctx, key) { | ||
return this.unload(ctx, key); | ||
} | ||
paths(scope, suffix = []) { | ||
@@ -320,6 +332,6 @@ if (scope === scope.parent.scope) { | ||
app.scope[_Loader.kRecord] = /* @__PURE__ */ Object.create(null); | ||
const fork = await this.reloadPlugin(app, "group:entry", this.config.plugins); | ||
const fork = await this.reload(app, "group:entry", this.config.plugins); | ||
this.entry = fork.ctx; | ||
app.accept(["plugins"], (config) => { | ||
this.reloadPlugin(app, "group:entry", config.plugins); | ||
this.reload(app, "group:entry", config.plugins); | ||
}, { passive: true }); | ||
@@ -326,0 +338,0 @@ app.on("dispose", () => { |
{ | ||
"name": "@koishijs/loader", | ||
"description": "Config Loader for Koishi", | ||
"version": "4.2.4", | ||
"version": "4.2.5", | ||
"main": "lib/index.js", | ||
@@ -44,6 +44,6 @@ "module": "lib/shared.mjs", | ||
"peerDependencies": { | ||
"@koishijs/core": "4.15.4" | ||
"@koishijs/core": "4.15.5" | ||
}, | ||
"devDependencies": { | ||
"@koishijs/core": "4.15.4", | ||
"@koishijs/core": "4.15.5", | ||
"@types/js-yaml": "^4.0.8" | ||
@@ -56,2 +56,2 @@ }, | ||
} | ||
} | ||
} |
@@ -72,3 +72,3 @@ import { Context, Dict, EffectScope, ForkScope, interpolate, isNullable, Logger, Plugin, resolveConfig, Universal, valueMap, version } from '@koishijs/core' | ||
if (name.startsWith('~') || name.startsWith('$')) continue | ||
ctx.loader.reloadPlugin(ctx, name, plugins[name]) | ||
ctx.loader.reload(ctx, name, plugins[name]) | ||
} | ||
@@ -85,7 +85,7 @@ | ||
if (!fork) { | ||
ctx.loader.reloadPlugin(ctx, key, neo[key]) | ||
ctx.loader.reload(ctx, key, neo[key]) | ||
} else if (!(key in neo)) { | ||
ctx.loader.unloadPlugin(ctx, key) | ||
ctx.loader.unload(ctx, key) | ||
} else { | ||
ctx.loader.reloadPlugin(ctx, key, neo[key] || {}) | ||
ctx.loader.reload(ctx, key, neo[key] || {}) | ||
} | ||
@@ -229,3 +229,3 @@ } | ||
async resolvePlugin(name: string) { | ||
async resolve(name: string) { | ||
const plugin = unwrapExports(await this.import(name)) | ||
@@ -251,3 +251,3 @@ if (plugin) this.store.set(this.app.registry.resolve(plugin), name) | ||
private async forkPlugin(name: string, config: any, parent: Context) { | ||
const plugin = await this.resolvePlugin(name) | ||
const plugin = await this.resolve(name) | ||
if (!plugin) return | ||
@@ -268,3 +268,3 @@ | ||
async reloadPlugin(parent: Context, key: string, source: any) { | ||
async reload(parent: Context, key: string, source: any) { | ||
let fork = parent.scope[Loader.kRecord][key] | ||
@@ -275,3 +275,3 @@ const name = key.split(':', 1)[0] | ||
if (!this.isTruthyLike(meta.$if)) { | ||
this.unloadPlugin(parent, key) | ||
this.unload(parent, key) | ||
return | ||
@@ -302,3 +302,3 @@ } | ||
unloadPlugin(ctx: Context, key: string) { | ||
unload(ctx: Context, key: string) { | ||
const fork = ctx.scope[Loader.kRecord][key] | ||
@@ -321,2 +321,17 @@ if (fork) { | ||
/** @deprecated */ | ||
resolvePlugin(name: string) { | ||
return this.resolve(name) | ||
} | ||
/** @deprecated */ | ||
reloadPlugin(ctx: Context, key: string, source: any) { | ||
return this.reload(ctx, key, source) | ||
} | ||
/** @deprecated */ | ||
unloadPlugin(ctx: Context, key: string) { | ||
return this.unload(ctx, key) | ||
} | ||
paths(scope: EffectScope, suffix: string[] = []): string[] { | ||
@@ -349,7 +364,7 @@ // root scope | ||
app.scope[Loader.kRecord] = Object.create(null) | ||
const fork = await this.reloadPlugin(app, 'group:entry', this.config.plugins) | ||
const fork = await this.reload(app, 'group:entry', this.config.plugins) | ||
this.entry = fork.ctx | ||
app.accept(['plugins'], (config) => { | ||
this.reloadPlugin(app, 'group:entry', config.plugins) | ||
this.reload(app, 'group:entry', config.plugins) | ||
}, { passive: true }) | ||
@@ -356,0 +371,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62182
1325