@koishi-ce/plugin-config 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -15,6 +15,8 @@ declare module "@koishi-ce/console" {
15
15
  }
16
16
  declare abstract class PackageProvider extends DataService<Dict<PackageProvider.Data>> {
17
17
  cache: Dict<PackageProvider.RuntimeData>;
18
+ /** 进行中的解析(键 → 共享 promise),同键并发请求合并为一次模块加载 */
19
+ inflight: Dict<Promise<PackageProvider.RuntimeData>>;
18
20
  debouncedRefresh: () => void;
19
21
  /** 完整包名 → 引用它的首个配置键(workspace 相对路径),由 node 端 collect 填充 */
20
22
  pathKeys: Dict<string>;
@@ -51,12 +53,15 @@ declare abstract class PackageProvider extends DataService<Dict<PackageProvider.
51
53
  /**
52
54
  * 解析插件模块的导出,提取配置 schema、用法文档、过滤器开关与
53
55
  * 注入的服务依赖(required / optional),并附带运行时 fork 状态。
54
- * 解析失败时返回 `{ failed: true }` 而不是抛错。
56
+ * 解析失败时返回 `{ failed: true }` 而不是抛错。同键并发调用共享
57
+ * 一次模块加载(抛错的模块不进 require.cache,每次都重新求值,
58
+ * 并发即多份重复求值与告警)。
55
59
  *
56
60
  * @param name 插件短名(不含 koishi-plugin- 前缀)
57
61
  * @returns 可序列化的运行时数据
58
62
  */
59
63
  parseExports(name: string): Promise<PackageProvider.RuntimeData>;
64
+ private resolveExports;
60
65
  }
61
66
  /** PackageProvider 相关的数据类型定义。 */
62
67
  declare namespace PackageProvider {
@@ -230,7 +235,14 @@ declare module "@koishi-ce/console" {
230
235
  //#endregion
231
236
  //#region src/node/index.d.ts
232
237
  declare const name = "config";
233
- declare const inject: string[];
238
+ declare const inject: {
239
+ console: {
240
+ required: boolean;
241
+ };
242
+ loader: {
243
+ required: boolean;
244
+ };
245
+ };
234
246
  type Config = Record<never, never>;
235
247
  declare const Config: Schema<Config>;
236
248
  declare function apply(ctx: Context): void;
package/lib/index.mjs CHANGED
@@ -18,6 +18,8 @@ import { Loader } from "@koishi-ce/loader";
18
18
  const logger$2 = new Logger("config");
19
19
  var PackageProvider = class extends DataService {
20
20
  cache = {};
21
+ /** 进行中的解析(键 → 共享 promise),同键并发请求合并为一次模块加载 */
22
+ inflight = {};
21
23
  debouncedRefresh;
22
24
  /** 完整包名 → 引用它的首个配置键(workspace 相对路径),由 node 端 collect 填充 */
23
25
  pathKeys = {};
@@ -41,15 +43,11 @@ var PackageProvider = class extends DataService {
41
43
  getPluginShortname(name),
42
44
  name
43
45
  ];
44
- for (const key of candidates) {
46
+ for (const key of new Set(candidates)) {
45
47
  if (!key) continue;
46
- const result = await this.parseExports(key);
47
- if (!result.failed) {
48
- this.cache[key] = result;
49
- break;
50
- }
48
+ if (!(this.cache[key] ??= await this.parseExports(key)).failed) break;
51
49
  }
52
- this.refresh(false);
50
+ this.debouncedRefresh();
53
51
  }, { authority: 4 });
54
52
  }
55
53
  /**
@@ -102,12 +100,19 @@ var PackageProvider = class extends DataService {
102
100
  /**
103
101
  * 解析插件模块的导出,提取配置 schema、用法文档、过滤器开关与
104
102
  * 注入的服务依赖(required / optional),并附带运行时 fork 状态。
105
- * 解析失败时返回 `{ failed: true }` 而不是抛错。
103
+ * 解析失败时返回 `{ failed: true }` 而不是抛错。同键并发调用共享
104
+ * 一次模块加载(抛错的模块不进 require.cache,每次都重新求值,
105
+ * 并发即多份重复求值与告警)。
106
106
  *
107
107
  * @param name 插件短名(不含 koishi-plugin- 前缀)
108
108
  * @returns 可序列化的运行时数据
109
109
  */
110
- async parseExports(name) {
110
+ parseExports(name) {
111
+ return this.inflight[name] ??= this.resolveExports(name).finally(() => {
112
+ delete this.inflight[name];
113
+ });
114
+ }
115
+ async resolveExports(name) {
111
116
  try {
112
117
  const exports = await this.ctx.loader.resolve(name);
113
118
  const result = {};
@@ -562,7 +567,10 @@ async function walkPlugins(plugins, handler) {
562
567
  * 配置写入器),并把 client 目录注册为控制台前端入口。
563
568
  */
564
569
  const name = "config";
565
- const inject = ["console"];
570
+ const inject = {
571
+ console: { required: true },
572
+ loader: { required: false }
573
+ };
566
574
  const Config = Schema.object({});
567
575
  function apply(ctx) {
568
576
  if (!ctx.loader?.writable) return ctx.logger("app").warn("@koishi-ce/plugin-config is only available for json/yaml config file");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koishi-ce/plugin-config",
3
3
  "description": "Manage your bots and plugins with console",
4
- "version": "1.0.7",
4
+ "version": "1.0.9",
5
5
  "type": "module",
6
6
  "main": "lib/index.mjs",
7
7
  "types": "lib/index.d.ts",
@@ -67,12 +67,15 @@
67
67
  "@koishi-ce/koishi": "^1.0.0"
68
68
  },
69
69
  "devDependencies": {
70
- "@koishi-ce/client": "^1.0.2",
71
- "@koishi-ce/plugin-hmr": "^1.0.4"
70
+ "@koishi-ce/client": "^1.0.3",
71
+ "@koishi-ce/plugin-hmr": "^1.0.5",
72
+ "element-plus": "^2.14.5",
73
+ "vue": "^3.5.12",
74
+ "vue-router": "^5.2.0"
72
75
  },
73
76
  "dependencies": {
74
77
  "@koishi-ce/console": "^1.0.0",
75
- "@koishi-ce/loader": "^1.0.3",
76
- "@koishi-ce/registry": "^1.0.4"
78
+ "@koishi-ce/loader": "^1.0.5",
79
+ "@koishi-ce/registry": "^1.0.5"
77
80
  }
78
81
  }