@koishijs/loader
Advanced tools
Comparing version 2.5.2 to 2.5.3
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { Context } from '@koishijs/core'; | ||
@@ -2,0 +3,0 @@ import { Loader } from './shared'; |
@@ -52,14 +52,16 @@ var __defProp = Object.defineProperty; | ||
var _a, _b; | ||
(_a = ctx.state)[_b = Loader.kRecord] || (_a[_b] = /* @__PURE__ */ Object.create(null)); | ||
(_a = ctx.scope)[_b = Loader.kRecord] || (_a[_b] = /* @__PURE__ */ Object.create(null)); | ||
for (const name in plugins || {}) { | ||
if (name.startsWith("~") || name.startsWith("$")) | ||
continue; | ||
ctx.lifecycle.queue(ctx.loader.reloadPlugin(ctx, name, plugins[name])); | ||
ctx.scope.ensure(async () => { | ||
await ctx.loader.reloadPlugin(ctx, name, plugins[name]); | ||
}); | ||
} | ||
ctx.accept((neo) => { | ||
const old = ctx.state.config; | ||
const old = ctx.scope.config; | ||
for (const key in { ...old, ...neo }) { | ||
if (key.startsWith("~") || key.startsWith("$")) | ||
continue; | ||
const fork = ctx.state[Loader.kRecord][key]; | ||
const fork = ctx.scope[Loader.kRecord][key]; | ||
if (!fork) { | ||
@@ -109,3 +111,3 @@ ctx.loader.reloadPlugin(ctx, key, neo[key]); | ||
async reloadPlugin(parent, key, source) { | ||
let fork = parent.state[_Loader.kRecord][key]; | ||
let fork = parent.scope[_Loader.kRecord][key]; | ||
const name = key.split(":", 1)[0]; | ||
@@ -133,3 +135,3 @@ const [config, meta] = separate(source, name === "group"); | ||
fork.alias = key.slice(name.length + 1); | ||
parent.state[_Loader.kRecord][key] = fork; | ||
parent.scope[_Loader.kRecord][key] = fork; | ||
} | ||
@@ -142,6 +144,6 @@ fork.parent.filter = (session) => { | ||
unloadPlugin(ctx, key) { | ||
const fork = ctx.state[_Loader.kRecord][key]; | ||
const fork = ctx.scope[_Loader.kRecord][key]; | ||
if (fork) { | ||
fork.dispose(); | ||
delete ctx.state[_Loader.kRecord][key]; | ||
delete ctx.scope[_Loader.kRecord][key]; | ||
logger.info(`unload plugin %c`, key); | ||
@@ -155,3 +157,3 @@ } | ||
app.envData = this.envData; | ||
app.state[_Loader.kRecord] = /* @__PURE__ */ Object.create(null); | ||
app.scope[_Loader.kRecord] = /* @__PURE__ */ Object.create(null); | ||
const fork = await this.reloadPlugin(app, "group:entry", this.config.plugins); | ||
@@ -166,3 +168,3 @@ this.entry = fork.ctx; | ||
app.on("internal/update", (fork2) => { | ||
const record = fork2.parent.state[_Loader.kRecord]; | ||
const record = fork2.parent.scope[_Loader.kRecord]; | ||
if (!record) | ||
@@ -180,3 +182,3 @@ return; | ||
return delete fork2[kUpdate]; | ||
const record = fork2.parent.state[_Loader.kRecord]; | ||
const record = fork2.parent.scope[_Loader.kRecord]; | ||
if (!record) | ||
@@ -188,4 +190,4 @@ return; | ||
const simplify = (_a = fork2.runtime.schema) == null ? void 0 : _a.simplify; | ||
fork2.parent.state.config[name] = { | ||
...separate(fork2.parent.state.config[name])[1], | ||
fork2.parent.scope.config[name] = { | ||
...separate(fork2.parent.scope.config[name])[1], | ||
...simplify ? simplify(config) : config | ||
@@ -192,0 +194,0 @@ }; |
{ | ||
"name": "@koishijs/loader", | ||
"description": "Config Loader for Koishi", | ||
"version": "2.5.2", | ||
"version": "2.5.3", | ||
"main": "lib/node.js", | ||
@@ -41,7 +41,7 @@ "typings": "lib/index.d.ts", | ||
"peerDependencies": { | ||
"@koishijs/core": "^4.11.2" | ||
"@koishijs/core": "4.11.3" | ||
}, | ||
"devDependencies": { | ||
"@koishijs/core": "^4.11.2", | ||
"@koishijs/registry": "^4.4.3", | ||
"@koishijs/core": "4.11.3", | ||
"@koishijs/registry": "^4.4.4", | ||
"@types/js-yaml": "^4.0.5" | ||
@@ -48,0 +48,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
54504
713