@yumerijs/core 1.1.2 → 1.1.3

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/dist/core.d.ts CHANGED
@@ -81,7 +81,7 @@ export declare class Core {
81
81
  * @param triggerPendingCheck 是否在加载后触发对其他待定插件的检查,默认为 true
82
82
  * @returns Promise<boolean> 是否加载成功
83
83
  */
84
- loadSinglePlugin(pluginName: string, triggerPendingCheck?: boolean): Promise<boolean>;
84
+ loadSinglePlugin(pluginName: string, triggerPendingCheck?: boolean, onlypending?: boolean): Promise<boolean>;
85
85
  /**
86
86
  * 内部函数:尝试加载所有处于 PENDING 状态的插件
87
87
  */
@@ -90,7 +90,7 @@ export declare class Core {
90
90
  * 卸载插件,并递归卸载依赖于它的其他插件
91
91
  * @param pluginNameToUnload 要卸载的插件名
92
92
  */
93
- unloadPlugin(pluginNameToUnload: string): Promise<void>;
93
+ unloadPlugin(pluginNameToUnload: string, ispending?: boolean): Promise<void>;
94
94
  /**
95
95
  * 内部函数:执行单个插件的卸载逻辑
96
96
  * @param pluginName 插件名
package/dist/core.js CHANGED
@@ -199,13 +199,13 @@ class Core {
199
199
  * @param triggerPendingCheck 是否在加载后触发对其他待定插件的检查,默认为 true
200
200
  * @returns Promise<boolean> 是否加载成功
201
201
  */
202
- async loadSinglePlugin(pluginName, triggerPendingCheck = true) {
202
+ async loadSinglePlugin(pluginName, triggerPendingCheck = true, onlypending = false) {
203
203
  // 如果插件不存在于状态记录中(例如,动态添加),则设为 PENDING
204
204
  if (!this.pluginStatus[pluginName]) {
205
205
  this.pluginStatus[pluginName] = "pending" /* PluginStatus.PENDING */;
206
206
  }
207
207
  // 只有 PENDING 状态的插件才能被加载
208
- if (this.pluginStatus[pluginName] !== "pending" /* PluginStatus.PENDING */) {
208
+ if (this.pluginStatus[pluginName] !== "pending" /* PluginStatus.PENDING */ && onlypending) {
209
209
  // this.logger.info(`Plugin "${pluginName}" is not in a pending state (current: ${this.pluginStatus[pluginName]}). Skipping load.`);
210
210
  return false;
211
211
  }
@@ -223,8 +223,8 @@ class Core {
223
223
  // 依赖满足,开始加载
224
224
  this.plugins[pluginName] = pluginInstance;
225
225
  if (pluginInstance.apply) {
226
+ this.pluginLoader.logger.info(`Apply plugin "${pluginName}"`);
226
227
  await pluginInstance.apply(new context_1.Context(this, pluginName), await this.getPluginConfig(pluginName));
227
- this.pluginLoader.logger.info(`Applied plugin "${pluginName}"`);
228
228
  }
229
229
  // 注册提供的组件
230
230
  if (pluginInstance.provide) {
@@ -238,7 +238,6 @@ class Core {
238
238
  }
239
239
  }
240
240
  this.pluginStatus[pluginName] = "enabled" /* PluginStatus.ENABLED */; // 更新状态为已启用
241
- // this.logger.info(`Plugin "${pluginName}" loaded successfully.`);
242
241
  // 加载成功后,检查是否可以加载其他等待中的插件
243
242
  if (triggerPendingCheck) {
244
243
  await this._loadPendingPlugins();
@@ -267,7 +266,7 @@ class Core {
267
266
  * 卸载插件,并递归卸载依赖于它的其他插件
268
267
  * @param pluginNameToUnload 要卸载的插件名
269
268
  */
270
- async unloadPlugin(pluginNameToUnload) {
269
+ async unloadPlugin(pluginNameToUnload, ispending = false) {
271
270
  // 1. 找出所有直接或间接依赖于此插件的插件
272
271
  const dependents = [];
273
272
  const pluginsToCheck = [pluginNameToUnload];
@@ -291,10 +290,10 @@ class Core {
291
290
  }
292
291
  // 2. 卸载所有依赖者
293
292
  for (const dependentName of dependents) {
294
- await this._unloadSinglePlugin(dependentName);
293
+ await this.unloadPlugin(dependentName, true);
295
294
  }
296
295
  // 3. 最后卸载目标插件
297
- await this._unloadSinglePlugin(pluginNameToUnload);
296
+ await this._unloadSinglePlugin(pluginNameToUnload, ispending);
298
297
  // 4. 卸载完成后,尝试重新加载处于 PENDING 状态的插件
299
298
  // await this._loadPendingPlugins();
300
299
  }
@@ -302,7 +301,7 @@ class Core {
302
301
  * 内部函数:执行单个插件的卸载逻辑
303
302
  * @param pluginName 插件名
304
303
  */
305
- async _unloadSinglePlugin(pluginName) {
304
+ async _unloadSinglePlugin(pluginName, ispending = false) {
306
305
  if (this.pluginStatus[pluginName] !== "enabled" /* PluginStatus.ENABLED */) {
307
306
  return; // 只卸载已启用的插件
308
307
  }
@@ -316,11 +315,8 @@ class Core {
316
315
  this.unregall(pluginName); // 清理该插件注册的所有内容
317
316
  delete this.plugins[pluginName];
318
317
  delete this.pluginModules[pluginName];
319
- // 更新状态为 PENDING,因为它的配置仍然是启用的
320
- // 如果它被其他插件依赖,当那个插件被卸载时,它也会被重新评估
321
- this.pluginStatus[pluginName] = "pending" /* PluginStatus.PENDING */;
318
+ this.pluginStatus[pluginName] = ispending ? "pending" /* PluginStatus.PENDING */ : "disabled" /* PluginStatus.DISABLED */;
322
319
  this.emit('plugin-unloaded', pluginName);
323
- // this.logger.info(`Plugin "${pluginName}" unloaded.`);
324
320
  }
325
321
  catch (error) {
326
322
  this.logger.error(`Failed to unload plugin "${pluginName}":`, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yumerijs/core",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Core module for yumeri",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",