mm_machine 3.2.9 → 3.3.1

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/drive.js CHANGED
@@ -1,13 +1,14 @@
1
- const prettier = require('@prettier/sync');
2
1
  require('mm_tpl');
3
2
  let { conf } = require('mm_config');
4
3
  const { Mod } = require('./mod');
5
4
 
6
- if (!$.prettyCode) {
7
- $.prettyCode = function (code, options) {
8
- return prettier.format(code, options);
9
- };
10
- }
5
+ const MODE = {
6
+ PRODUCTION: 1,
7
+ HOT_CONFIG: 2,
8
+ HOT_RELOAD: 3,
9
+ HOT_BOTH: 4,
10
+ RELOAD_ALWAYS: 5
11
+ };
11
12
 
12
13
  /**
13
14
  * 驱动基础类
@@ -42,8 +43,6 @@ class Drive extends Mod {
42
43
 
43
44
  // 当前脚本文件路径
44
45
  script_file = '';
45
- // 目录缓存
46
- _dir = undefined;
47
46
  /**
48
47
  * 构造函数
49
48
  * @param {object} config 配置项
@@ -65,7 +64,7 @@ Drive.prototype._onLoad = async function (ctx) {
65
64
  // 1. 加载
66
65
  this.on('load:before', async (ctx) => {
67
66
  this.setState('loading');
68
- await this.call('loadScript');
67
+ this.loadScript();
69
68
  await this._loadCore(...ctx.params);
70
69
  });
71
70
  this.on('load:after', (ctx) => {
@@ -86,10 +85,6 @@ Drive.prototype.getEventer = function () {
86
85
  * 配置驱动
87
86
  */
88
87
  Drive.prototype._preset = function () {
89
- let file = this.config.main;
90
- if (file) {
91
- this.script_file = file.fullname(this.getDir());
92
- }
93
88
  };
94
89
 
95
90
  /**
@@ -204,7 +199,7 @@ Drive.prototype._remove = function () {
204
199
  if (!file) return;
205
200
 
206
201
  try {
207
- if (this.mode >= 3) {
202
+ if (this.mode >= MODE.HOT_RELOAD) {
208
203
  $.mod.unload(file);
209
204
  } else {
210
205
  // 移除模块缓存
@@ -271,6 +266,10 @@ Drive.prototype.newScript = function (file) {
271
266
  this._createScriptFile(file);
272
267
  };
273
268
 
269
+ Drive.prototype.renderTpl = function(tpl, model){
270
+ return $.tpl.render(tpl, model);
271
+ }
272
+
274
273
  /**
275
274
  * 创建脚本
276
275
  * @param {string} file 文件路径
@@ -278,7 +277,7 @@ Drive.prototype.newScript = function (file) {
278
277
  */
279
278
  Drive.prototype._createScriptFile = function (file) {
280
279
  var tpl = this._getScriptTpl();
281
- var content = $.tpl.render(tpl, this.getModel('script'));
280
+ var content = this.renderTpl(tpl, this.getModel('script'));
282
281
  if (!content) {
283
282
  return '';
284
283
  }
@@ -341,7 +340,7 @@ Drive.prototype.loadScript = function () {
341
340
  let file = this._getScriptFile();
342
341
  if (!file) return null;
343
342
  try {
344
- if (this.mode >= 3) {
343
+ if (this.mode >= MODE.HOT_RELOAD) {
345
344
  var cs = $.require(file, (mod) => {
346
345
  this._setMainMethod(mod);
347
346
  });
@@ -424,7 +423,8 @@ Drive.prototype.prettyCode = function (code, type = 'json5') {
424
423
  options.parser = 'json';
425
424
  break;
426
425
  }
427
- let new_code = $.prettyCode(code, options);
426
+ const prettier = require('@prettier/sync');
427
+ let new_code = prettier.format(code, options);
428
428
  return new_code;
429
429
  };
430
430
 
@@ -445,7 +445,7 @@ Drive.prototype.getModel = function (type) {
445
445
  */
446
446
  Drive.prototype._createConfigFile = function (file, model) {
447
447
  var tpl = this._getConfigTpl();
448
- var content = $.tpl.render(tpl, model || this.getModel('config'));
448
+ var content = this.renderTpl(tpl, model || this.getModel('config'));
449
449
  let code = this.prettyCode(content, 'json');
450
450
  file.saveText(code);
451
451
  return file;
@@ -526,7 +526,7 @@ Drive.prototype.loadFile = function (file, name) {
526
526
  * @returns {object | Array | null} 配置对象
527
527
  */
528
528
  Drive.prototype._loadHotReload = function (file) {
529
- if (this.mode >= 2) {
529
+ if (this.mode >= MODE.HOT_CONFIG) {
530
530
  return $.loadJson(file, this._handleHotReload.bind(this));
531
531
  }
532
532
  return file.loadJson();
@@ -559,7 +559,7 @@ Drive.prototype._handleHotReload = function (config) {
559
559
  * 根据模式决定是否重新加载脚本
560
560
  */
561
561
  Drive.prototype._reloadIfNeeded = function () {
562
- if (this.mode >= 3) {
562
+ if (this.mode >= MODE.HOT_RELOAD) {
563
563
  this.reloadScript();
564
564
  }
565
565
  };
@@ -732,5 +732,6 @@ Drive.prototype.remove = function () {
732
732
  * @module 导出Drive类
733
733
  */
734
734
  module.exports = {
735
- Drive
735
+ Drive,
736
+ MODE
736
737
  };
package/lib/manager.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const { Mod } = require('./mod.js');
2
- const { Drive } = require('./drive.js');
2
+ const { Drive, MODE } = require('./drive.js');
3
3
  const { Scanner } = require('./scanner.js');
4
4
 
5
5
  /**
@@ -70,7 +70,7 @@ class Manager extends Mod {
70
70
  * 5.重载模式,执行完后重新加载脚本,避免变量污染
71
71
  * @type {number}
72
72
  */
73
- mode: 3,
73
+ mode: MODE.HOT_RELOAD,
74
74
  /**
75
75
  * 作用域
76
76
  * @type {string}
@@ -146,9 +146,9 @@ Manager.prototype.getList = function (keyword) {
146
146
  });
147
147
  }
148
148
 
149
- var list = [];
150
- for (var i = 0; i < infos.length; i++) {
151
- var mod = this.getMod(infos[i].name);
149
+ let list = [];
150
+ for (let i = 0; i < infos.length; i++) {
151
+ let mod = this.getMod(infos[i].name);
152
152
  if (!mod) continue;
153
153
  list.push(mod);
154
154
  }
@@ -176,12 +176,6 @@ Manager.prototype.getTplDir = function () {
176
176
  */
177
177
  Manager.prototype.Drive = Drive;
178
178
 
179
- /**
180
- * 更新模块信息
181
- */
182
- Manager.prototype.updateInfo = function () {
183
- };
184
-
185
179
  /**
186
180
  * 获取模块配置列表
187
181
  * @returns {Array} 排序后的模块配置数组
@@ -231,10 +225,10 @@ Manager.prototype.setMod = function (name, mod) {
231
225
  /**
232
226
  * 获取模块
233
227
  * @param {string} name 模块名
234
- * @returns {object|null} 模块对象
228
+ * @returns {object} 模块对象
235
229
  */
236
230
  Manager.prototype.getMod = function (name) {
237
- return this.mods[name] || null;
231
+ return this.mods[name];
238
232
  };
239
233
 
240
234
  /**
@@ -254,7 +248,7 @@ Manager.prototype.getMods = function () {
254
248
  */
255
249
  Manager.prototype.newMod = function (config_file, config, script) {
256
250
  try {
257
- var mod;
251
+ let mod;
258
252
  switch (this.config.mod_type) {
259
253
  case 'script':
260
254
  mod = new Mod(config, this);
@@ -272,8 +266,8 @@ Manager.prototype.newMod = function (config_file, config, script) {
272
266
  }
273
267
 
274
268
  if (script) {
275
- for (var key in script) {
276
- var obj = script[key];
269
+ for (let key in script) {
270
+ let obj = script[key];
277
271
  if (typeof obj == 'function') {
278
272
  mod.setMethod(key, obj);
279
273
  } else {
@@ -298,31 +292,15 @@ Manager.prototype.newMod = function (config_file, config, script) {
298
292
  Manager.prototype.regMod = function (config_file, config = {}, script = {}) {
299
293
  let cg = { ...config };
300
294
 
301
- var mod = this.newMod(config_file, cg, script);
295
+ let mod = this.newMod(config_file, cg, script);
302
296
  if (!mod) return null;
303
297
 
304
298
  // 模块已存在时不替换内存实例,避免破坏已初始化的模块
305
- if (!this.mods[mod.config.name]) {
299
+ if (!this.getMod(mod.config.name)) {
306
300
  this.setMod(mod.config.name, mod);
307
301
  }
308
302
 
309
- var info = {
310
- name: mod.config.name,
311
- title: mod.config.title,
312
- description: mod.config.description,
313
- sort: mod.config.sort,
314
- state: mod.config.state,
315
- config_file: config_file,
316
- auto_start: mod.config.auto_start || 'auto',
317
- main: mod.config.main || ''
318
- };
319
- // 获取触发键
320
- let keys = this.config.trigger_key;
321
- if (keys && keys.length > 0) {
322
- for (let key in keys) {
323
- info[key] = mod.config[key];
324
- }
325
- }
303
+ let info = { ...mod.config, config_file: config_file };
326
304
  this.infos.push(info);
327
305
  return mod;
328
306
  };
@@ -410,7 +388,7 @@ Manager.prototype.regMods = function (files, config = {}, script = {}) {
410
388
  * 加载所有模块
411
389
  */
412
390
  Manager.prototype.loadMods = async function () {
413
- var promises = [];
391
+ let promises = [];
414
392
  let mods = this.getMods();
415
393
  for (let name in mods) {
416
394
  let mod = mods[name];
@@ -437,7 +415,24 @@ Manager.prototype.updateBefore = function () { };
437
415
  /**
438
416
  * 更新配置前的钩子函数
439
417
  */
440
- Manager.prototype.updateAfter = function () { };
418
+ Manager.prototype.updateAfter = function () {
419
+ this._sort();
420
+ };
421
+
422
+ /**
423
+ * 排序模块信息
424
+ */
425
+ Manager.prototype._sort = function () {
426
+ this.infos.sort((a, b) => {
427
+ // 先按 sort 排序
428
+ let cha = a.sort - b.sort;
429
+ if (cha !== 0) {
430
+ return cha;
431
+ }
432
+ // 再按 name 排序
433
+ return a.name.localeCompare(b.name);
434
+ });
435
+ };
441
436
 
442
437
  /**
443
438
  * 更新配置
@@ -450,8 +445,8 @@ Manager.prototype.update = async function (dir, clear = true) {
450
445
  this.clearMods();
451
446
  }
452
447
 
453
- var search_dir = dir || this.config.dir;
454
- var files = await this._findFiles(search_dir);
448
+ let search_dir = dir || this.config.dir;
449
+ let files = await this._findFiles(search_dir);
455
450
  this.regMods(files);
456
451
 
457
452
  if (!this.config.lazy_load) {
@@ -492,9 +487,9 @@ Manager.prototype._findFiles = async function (dir) {
492
487
  * @returns {Promise<any>} 执行结果
493
488
  */
494
489
  Manager.prototype.main = async function (name, method, ...params) {
495
- var result = null;
490
+ let result = null;
496
491
  if (name) {
497
- var mod = this.mods[name];
492
+ let mod = this.getMod(name);
498
493
  if (mod) {
499
494
  result = await this._runMod(mod, method, ...params);
500
495
  }
@@ -505,24 +500,24 @@ Manager.prototype.main = async function (name, method, ...params) {
505
500
  };
506
501
 
507
502
  /**
508
- * 私有方法:执行所有模块方法
503
+ * 执行所有模块方法 - 内部方法
509
504
  * @param {string} method 方法名称
510
505
  * @param {...any} params 方法参数集合
511
506
  * @returns {Promise<any>} 执行结果
512
507
  * @private
513
508
  */
514
509
  Manager.prototype._runAllEnabled = async function (method, ...params) {
515
- var result;
516
- var infos = this._getInfos();
517
- for (var i = 0; i < infos.length; i++) {
518
- var info = infos[i];
510
+ let result;
511
+ let infos = this._getInfos();
512
+ for (let i = 0; i < infos.length; i++) {
513
+ let info = infos[i];
519
514
  // 直接用 info.state 过滤,避免无效实例化
520
515
  if (info.state !== 1) continue;
521
516
 
522
- var mod = this.getMod(info.name);
517
+ let mod = this.getMod(info.name);
523
518
  if (!mod) continue;
524
519
 
525
- var ret = null;
520
+ let ret = null;
526
521
  try {
527
522
  ret = await this._runMod(mod, method, ...params);
528
523
  } catch (err) {
@@ -540,7 +535,33 @@ Manager.prototype._runAllEnabled = async function (method, ...params) {
540
535
  };
541
536
 
542
537
  /**
543
- * 私有方法:执行模块方法
538
+ * 执行所有模块方法 - 内部方法
539
+ * @param {string} method 方法名称
540
+ * @param {...any} params 方法参数集合
541
+ * @returns {Promise<any>} 执行结果
542
+ * @private
543
+ */
544
+ Manager.prototype.doAll = async function (method, ...params) {
545
+ let promises = [];
546
+ let infos = this._getInfos();
547
+ for (let i = 0; i < infos.length; i++) {
548
+ let info = infos[i];
549
+ // 直接用 info.state 过滤,避免无效实例化
550
+ if (info.state !== 1) continue;
551
+
552
+ let mod = this.getMod(info.name);
553
+ if (!mod) continue;
554
+ try {
555
+ promises.push(this._runMod(mod, method, ...params));
556
+ } catch (err) {
557
+ this.log('error', `执行模块方法失败: `, err);
558
+ }
559
+ }
560
+ return await Promise.all(promises);
561
+ };
562
+
563
+ /**
564
+ * 执行模块方法 - 内部方法
544
565
  * @param {object} mod 模块对象
545
566
  * @param {string} method 方法名称
546
567
  * @param {...any} params 参数集合
@@ -548,18 +569,54 @@ Manager.prototype._runAllEnabled = async function (method, ...params) {
548
569
  * @private
549
570
  */
550
571
  Manager.prototype._runMod = async function (mod, method, ...params) {
551
- mod = this._ensureModLoaded(mod, method);
572
+ mod = await this._ensureModLoaded(mod, method);
573
+
574
+ // 执行方法
575
+ let ret = await mod.do(method, ...params);
576
+ // 根据模式决定是否重载
577
+ if (this.config.mode >= MODE.HOT_BOTH) {
578
+ await mod.do('reload');
579
+ }
580
+
581
+ return ret;
582
+ };
583
+
584
+ /**
585
+ * 调用模块方法 - 内部方法
586
+ * @param {object} mod 模块对象
587
+ * @param {string} method 方法名称
588
+ * @param {...any} params 参数集合
589
+ * @returns {Promise<any>} 执行结果
590
+ * @private
591
+ */
592
+ Manager.prototype._callMod = async function (mod, method, ...params) {
593
+ mod = await this._ensureModLoaded(mod, method);
552
594
 
553
595
  // 执行方法
554
596
  let ret = await mod.call(method, ...params);
555
597
  // 根据模式决定是否重载
556
- if (this.config.mode >= 4) {
598
+ if (this.config.mode >= MODE.HOT_BOTH) {
557
599
  await mod.do('reload');
558
600
  }
559
601
 
560
602
  return ret;
561
603
  };
562
604
 
605
+ /**
606
+ * 调用模块方法 - 外部方法
607
+ * @param {string} name 模块名
608
+ * @param {string} method 方法名称
609
+ * @param {...any} params 参数集合
610
+ * @returns {Promise<any>} 执行结果
611
+ */
612
+ Manager.prototype.callMod = async function (name, method, ...params) {
613
+ let mod = this.getMod(name);
614
+ if (!mod) {
615
+ throw new Error(`模块${name}不存在`);
616
+ }
617
+ return await this._callMod(mod, method, ...params);
618
+ };
619
+
563
620
  /**
564
621
  * 初始化管理器
565
622
  */
@@ -585,13 +642,13 @@ Manager.prototype._loadSources = async function () {
585
642
  * 后台扫描文件系统
586
643
  */
587
644
  Manager.prototype._scanForUpdate = async function (clear = true) {
588
- var base_dir = this.getBaseDir();
589
- var dir = this.getDir();
645
+ let base_dir = this.getBaseDir();
646
+ let dir = this.getDir();
590
647
  try {
591
648
  if (base_dir) {
592
- await Promise.all([this.call('update', base_dir, clear), this.call('update', dir, false)]);
649
+ await Promise.all([this.update(base_dir, clear), this.update(dir, false)]);
593
650
  } else {
594
- await this.call('update', dir, clear);
651
+ await this.update(dir, clear);
595
652
  }
596
653
  } catch (err) {
597
654
  this.log('error', '后台扫描同步失败', err);
@@ -619,7 +676,7 @@ Manager.prototype._loadCore = async function () {
619
676
  * 初始化公共属性
620
677
  */
621
678
  Manager.prototype._initCore = async function () {
622
- if (this.isLoaded()) {
679
+ if (!this.isLoaded()) {
623
680
  await this.do('load');
624
681
  }
625
682
  // 初始化AI客户端
@@ -666,25 +723,25 @@ Manager.prototype.exec = async function (name, method, ...params) {
666
723
  * 确保模块已加载
667
724
  * @param {object} mod 模块对象
668
725
  * @param {string} method 方法名称
669
- * @returns {Promise<object|null>} 模块实例或 null
726
+ * @returns {Promise<object>} 模块实例
670
727
  */
671
728
  Manager.prototype._ensureModLoaded = async function (mod, method) {
672
- if (!mod) return null;
729
+ if (!mod) {
730
+ throw new TypeError(`模块(mod)参数不能为空`);
731
+ }
673
732
  if (!['load', 'init'].includes(method)) {
674
733
  if (!mod.isLoaded()) {
675
734
  try {
676
735
  await mod.do('load');
677
736
  } catch (error) {
678
- this.log('error', `模块${mod.config.name}加载失败`, error);
679
- return null;
737
+ throw new Error(`模块${mod.config.name}加载失败,无法执行方法 ${method}`);
680
738
  }
681
739
  }
682
740
  if (!mod.isInited()) {
683
741
  try {
684
- await mod.do('init');
742
+ await mod.do('init', this.getParent());
685
743
  } catch (error) {
686
- this.log('error', `模块${mod.config.name}初始化失败`, error);
687
- return null;
744
+ throw new Error(`模块${mod.config.name}初始化失败,无法执行方法 ${method}`);
688
745
  }
689
746
  }
690
747
  };
@@ -696,13 +753,17 @@ Manager.prototype._ensureModLoaded = async function (mod, method) {
696
753
  * @returns {Promise} 加载完成
697
754
  */
698
755
  Manager.prototype._ensureAllLoaded = async function (method) {
699
- var promises = [];
700
- var infos = this._getInfos();
756
+ let promises = [];
757
+ let infos = this._getInfos();
701
758
 
702
- for (var i = 0; i < infos.length; i++) {
759
+ for (let i = 0; i < infos.length; i++) {
703
760
  let mod = this.getMod(infos[i].name);
704
761
  if (!mod) continue;
705
- promises.push(this._ensureModLoaded(mod, method));
762
+ try {
763
+ promises.push(this._ensureModLoaded(mod, method));
764
+ } catch (error) {
765
+ this._logModError(infos[i].name, method, error);
766
+ }
706
767
  }
707
768
 
708
769
  await Promise.all(promises);
@@ -720,19 +781,20 @@ Manager.prototype.runWait = async function (method, ...params) {
720
781
  }
721
782
 
722
783
  let result;
723
- var infos = this._getInfos();
784
+ let infos = this._getInfos();
724
785
 
725
- for (var i = 0; i < infos.length; i++) {
726
- let mod = this.getMod(infos[i].name);
786
+ for (let i = 0; i < infos.length; i++) {
787
+ let name = infos[i].name;
788
+ let mod = this.getMod(name);
727
789
  if (!mod) continue;
728
- mod = await this._ensureModLoaded(mod, method);
729
790
  try {
791
+ mod = await this._ensureModLoaded(mod, method);
730
792
  let ret = await mod.do(method, ...params);
731
793
  if (ret !== null && ret !== undefined) {
732
794
  result = ret;
733
795
  }
734
796
  } catch (error) {
735
- this._logModError(infos[i].name, method, error);
797
+ this._logModError(name, method, error);
736
798
  }
737
799
  }
738
800
 
@@ -753,10 +815,10 @@ Manager.prototype.runAsync = async function (method, ...params) {
753
815
  // 确保所有模块都已加载
754
816
  await this._ensureAllLoaded(method);
755
817
 
756
- var infos = this._getInfos();
818
+ let infos = this._getInfos();
757
819
 
758
- for (var i = 0; i < infos.length; i++) {
759
- var mod = this.mods[infos[i].name];
820
+ for (let i = 0; i < infos.length; i++) {
821
+ let mod = this.getMod(infos[i].name);
760
822
  if (!mod) continue;
761
823
 
762
824
  mod.do(method, ...params).catch((error) => {
@@ -778,17 +840,17 @@ Manager.prototype.runAll = async function (method, ...params) {
778
840
  throw new TypeError('方法名称必须是字符串');
779
841
  }
780
842
 
781
- // 确保所有模块都已加载
782
- await this._ensureAllLoaded(method);
783
-
784
843
  const promises = [];
785
- var infos = this._getInfos();
786
-
787
- for (var i = 0; i < infos.length; i++) {
788
- var mod = this.mods[infos[i].name];
844
+ let infos = this._getInfos();
845
+ for (let i = 0; i < infos.length; i++) {
846
+ let mod = this.getMod(infos[i].name);
789
847
  if (!mod) continue;
790
-
791
- promises.push(mod.do(method, ...params));
848
+ try {
849
+ mod = await this._ensureModLoaded(mod, method);
850
+ promises.push(mod.do(method, ...params));
851
+ } catch (error) {
852
+ this._logModError(infos[i].name, method, error);
853
+ }
792
854
  }
793
855
 
794
856
  return await Promise.all(promises);
@@ -809,10 +871,10 @@ Manager.prototype.runRace = async function (method, ...params) {
809
871
  await this._ensureAllLoaded(method);
810
872
 
811
873
  const promises = [];
812
- var infos = this._getInfos();
874
+ let infos = this._getInfos();
813
875
 
814
- for (var i = 0; i < infos.length; i++) {
815
- var mod = this.mods[infos[i].name];
876
+ for (let i = 0; i < infos.length; i++) {
877
+ let mod = this.getMod(infos[i].name);
816
878
  if (!mod) continue;
817
879
 
818
880
  promises.push(
@@ -837,13 +899,13 @@ Manager.prototype.runWaterfall = async function (method, result, ...params) {
837
899
  throw new TypeError('方法名称必须是字符串');
838
900
  }
839
901
 
840
- var infos = this._getInfos();
902
+ let infos = this._getInfos();
841
903
 
842
- for (var i = 0; i < infos.length; i++) {
904
+ for (let i = 0; i < infos.length; i++) {
843
905
  let mod = this.getMod(infos[i].name);
844
906
  if (!mod) continue;
845
- mod = await this._ensureModLoaded(mod, method);
846
907
  try {
908
+ mod = await this._ensureModLoaded(mod, method);
847
909
  let ret = await mod.do(method, result, ...params);
848
910
  if (ret !== null && ret !== undefined) {
849
911
  result = ret;
@@ -863,7 +925,7 @@ Manager.prototype.runWaterfall = async function (method, result, ...params) {
863
925
  * @param {...any} params 事件参数
864
926
  * @returns {Promise} 事件触发结果
865
927
  */
866
- Manager.prototype.runSubMod = async function (name, method, ...params) {
928
+ Manager.prototype.runMod = async function (name, method, ...params) {
867
929
  if (typeof method !== 'string') {
868
930
  throw new TypeError('方法名称必须是字符串');
869
931
  }
@@ -871,16 +933,7 @@ Manager.prototype.runSubMod = async function (name, method, ...params) {
871
933
  if (!mod) {
872
934
  throw new Error(`模块${name}不存在或加载失败`);
873
935
  }
874
- mod = await this._ensureModLoaded(mod, method);
875
- return await mod.do(method, ...params);
876
- };
877
-
878
- /**
879
- * 移除事件监听
880
- * @param {string} event 事件名
881
- */
882
- Manager.prototype.offEvent = function (event) {
883
- this.getEventer()?.off(event);
936
+ return await this._runMod(mod, method, ...params);
884
937
  };
885
938
 
886
939
  /**
package/lib/mod.js CHANGED
@@ -711,8 +711,7 @@ Mod.prototype.loadDatas = function () {
711
711
  Mod.prototype.call = async function (method, ...params) {
712
712
  let method_func = this.getMethod(method);
713
713
  if (typeof method_func !== 'function') {
714
- this.log('warn', `方法 ${method} 未注册,跳过执行`);
715
- return null;
714
+ throw new Error(`方法 ${method} 未注册,请确保模块已加载`);
716
715
  }
717
716
 
718
717
  let result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "3.2.9",
3
+ "version": "3.3.1",
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": {
@@ -34,12 +34,13 @@
34
34
  "dependencies": {
35
35
  "@prettier/sync": "^0.6.1",
36
36
  "mm_config": "^2.4.5",
37
+ "mm_expand": "^2.4.5",
37
38
  "mm_hot_reload": "^1.4.2",
38
39
  "mm_tpl": "^2.6.5"
39
40
  },
40
41
  "devDependencies": {
41
42
  "eslint": "^10.7.0",
42
- "eslint-plugin-jsdoc": "^63.0.14",
43
+ "eslint-plugin-jsdoc": "^63.2.0",
43
44
  "mm_eslint": "^1.7.5"
44
45
  }
45
46
  }