mm_machine 3.0.0 → 3.0.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/drive.js CHANGED
@@ -501,7 +501,7 @@ Drive.prototype.loadFile = function (file, name) {
501
501
  let final_config = this._findConfigByName(config, name);
502
502
  return final_config;
503
503
  } catch (err) {
504
- this.log('error', `[${this.config.name}] 加载配置文件失败`, err);
504
+ this.log('error', `加载配置文件失败`, err);
505
505
  return null;
506
506
  }
507
507
  };
@@ -583,7 +583,7 @@ Drive.prototype.delFile = function () {
583
583
  script_file.delFile();
584
584
  }
585
585
  } catch (err) {
586
- this.log('error', `[${this.config.name}] 删除文件失败`, err);
586
+ this.log('error', `删除文件失败`, err);
587
587
  error_message = error_message || `删除失败: ${err.message}`;
588
588
  }
589
589
  return error_message;
@@ -658,7 +658,7 @@ Drive.prototype.loadBefore = function () {
658
658
  this._is_loaded = true;
659
659
  }
660
660
  } catch (err) {
661
- this.log('error', `[${this.config.name}] 加载前处理失败`, err);
661
+ this.log('error', `加载前处理失败`, err);
662
662
  this._is_loaded = false;
663
663
  }
664
664
  };
@@ -701,7 +701,7 @@ Drive.prototype.save = function () {
701
701
  // 单对象格式配置,直接保存
702
702
  file.saveText(JSON.stringify(this.config, null, 2));
703
703
  } catch (err) {
704
- this.log('error', `[${this.config.name}] 保存配置失败`, err);
704
+ this.log('error', `保存配置失败`, err);
705
705
  }
706
706
  };
707
707
 
package/manager.js CHANGED
@@ -696,7 +696,7 @@ Manager.prototype._runMod = async function (mod, method, ...params) {
696
696
  try {
697
697
  await mod.call('loadScript');
698
698
  } catch (err) {
699
- $.log.error(`加载模块脚本失败: `, err);
699
+ this.log('error', `加载模块脚本失败: `, err);
700
700
  }
701
701
  // 加载失败则不再执行,避免无方法调用
702
702
  if (!mod.isLoaded()) {
package/mod.js CHANGED
@@ -636,7 +636,7 @@ Mod.prototype.call = async function (method, ...params) {
636
636
  result = await this._callMain(method_func, params, before_result);
637
637
  result = await this._callAfter(method, params, result);
638
638
  } catch (err) {
639
- this.log('error', `[${this.config.name}] 执行 ${method} 失败: ${err.message}`, err);
639
+ this.log('error', `执行 ${method} 失败: ${err.message}`, err);
640
640
  return null;
641
641
  }
642
642
 
@@ -659,7 +659,7 @@ Mod.prototype._callBefore = async function (method, params) {
659
659
  let result = await before_func.call(this, ...params);
660
660
  return result;
661
661
  } catch (err) {
662
- this.log('error', `[${this.config.name}] 执行前置钩子 ${before_method} 失败`, err);
662
+ this.log('error', `执行前置钩子 ${before_method} 失败`, err);
663
663
  return undefined;
664
664
  }
665
665
  };
@@ -694,7 +694,7 @@ Mod.prototype._callAfter = async function (method, params, result) {
694
694
  let after = await after_func.call(this, result, ...params);
695
695
  return after !== undefined ? after : result;
696
696
  } catch (err) {
697
- this.log('error', `[${this.config.name}] 执行后置钩子 ${after_method} 失败`, err);
697
+ this.log('error', `执行后置钩子 ${after_method} 失败`, err);
698
698
  return result;
699
699
  }
700
700
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "3.0.0",
3
+ "version": "3.0.3",
4
4
  "description": "A flexible Node.js plugin mechanism system for dynamic loading, management and execution of modules. Supports hot reload, lifecycle management, and modern JavaScript features.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/registry.js CHANGED
@@ -100,8 +100,11 @@ Registry.prototype.getClass = function (class_name) {
100
100
  * @throws {Error} 模块配置项错误
101
101
  */
102
102
  Registry.prototype.registerModule = function (config) {
103
- if (!config || !config.name) {
104
- throw new TypeError('模块配置和模块名称不能为空');
103
+ if (!config) {
104
+ throw new TypeError('模块配置不能为空');
105
+ }
106
+ if (!config.name) {
107
+ throw new TypeError('模块名称不能为空');
105
108
  }
106
109
  var class_name = config.class_name || 'Drive';
107
110
  this._module_cache[config.name] = {
@@ -313,22 +316,22 @@ Registry.prototype.checkConfig = function (config) {
313
316
  cg.parent = '';
314
317
  }
315
318
  if (!name) {
316
- throw new Error('模块名称不能为空');
319
+ throw new TypeError('模块名称不能为空');
317
320
  }
318
321
  if (!title) {
319
- throw new Error('模块标题不能为空');
322
+ throw new TypeError('模块标题不能为空');
320
323
  }
321
324
  if (!description) {
322
- throw new Error('模块描述不能为空');
325
+ throw new TypeError('模块描述不能为空');
323
326
  }
324
327
  if (!config_file) {
325
- throw new Error('模块配置文件不能为空');
328
+ throw new TypeError('模块配置文件不能为空');
326
329
  }
327
330
  if (!['true', 'false', 'auto'].includes(auto_start)) {
328
- throw new Error('模块自动启动配置错误,只能为true、false、auto');
331
+ throw new TypeError('模块自动启动配置错误,只能为true、false、auto');
329
332
  }
330
333
  if (!this.class_dict[class_name]) {
331
- throw new Error('模块类不存在');
334
+ throw new TypeError('模块类不存在');
332
335
  }
333
336
  if (!enabled) {
334
337
  cg.enabled = false;
@@ -355,7 +358,7 @@ Registry.prototype.checkConfig = function (config) {
355
358
  Registry.prototype.getClassFile = function (class_name) {
356
359
  let file_name = this.config.name + '_class.json';
357
360
  let file = file_name.fullname(this.config.dir);
358
- file.addDir();
361
+ // file.addDir();
359
362
  return file;
360
363
  };
361
364
 
@@ -366,7 +369,7 @@ Registry.prototype.getClassFile = function (class_name) {
366
369
  Registry.prototype.getModuleFile = function () {
367
370
  let file_name = this.config.name + '_module.json';
368
371
  let file = file_name.fullname(this.config.dir);
369
- file.addDir();
372
+ // file.addDir();
370
373
  return file;
371
374
  };
372
375