mm_machine 2.8.4 → 2.8.6

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.
Files changed (2) hide show
  1. package/index.js +15 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -86,10 +86,10 @@ class Manager extends Mod {
86
86
  */
87
87
  use_snapshot: true,
88
88
  /**
89
- * 快照文件路径
89
+ * 快照文件路径,留空则自动生成到 cache/snapshot/ 目录下
90
90
  * @type {string}
91
91
  */
92
- snapshot_file: './snapshot.json'
92
+ snapshot_file: ''
93
93
  };
94
94
 
95
95
  /**
@@ -479,12 +479,19 @@ Manager.prototype._findFiles = async function (dir) {
479
479
 
480
480
  /**
481
481
  * 获取快照文件路径
482
+ * 默认统一放到 /cache/snapshot/ 目录,文件名由类名+配置名组成
482
483
  * @returns {string} 快照文件完整路径
483
484
  */
484
485
  Manager.prototype.getSnapshotPath = function () {
485
- var snapshot_file = this.config.snapshot_file || './snapshot.json';
486
- let dir = this.getBaseDir();
487
- return snapshot_file.fullname(dir);
486
+ var snapshot_file = this.config.snapshot_file;
487
+ if (!snapshot_file) {
488
+ var class_name = this.constructor.name.toLowerCase();
489
+ var name = this.config.name || 'default';
490
+ snapshot_file = `./cache/snapshot/${class_name}_${name}.json`;
491
+ // 确保目录存在
492
+ snapshot_file.addDir();
493
+ }
494
+ return snapshot_file.fullname();
488
495
  };
489
496
 
490
497
  /**
@@ -638,7 +645,6 @@ Manager.prototype._syncFromFile = async function (snapshot) {
638
645
  var f = current[fi];
639
646
  if (!old[f]) {
640
647
  this.registerMod(f);
641
- this.log('info', '快照同步: 新增模块 ' + f);
642
648
  }
643
649
  old[f] = false;
644
650
  }
@@ -648,7 +654,7 @@ Manager.prototype._syncFromFile = async function (snapshot) {
648
654
  await this._removeStale(old);
649
655
  this.updateInfo();
650
656
  await this._saveSnapshotDirs(Object.keys(old_dirs));
651
- this.log('info', '快照同步完成');
657
+ // this.log('info', '快照同步完成');
652
658
  } catch (err) {
653
659
  this.log('error', '快照增量同步失败', err);
654
660
  } finally {
@@ -683,7 +689,6 @@ Manager.prototype._removeStale = async function (old) {
683
689
  if (mod) {
684
690
  await this.unloadMod(mod.config.name);
685
691
  this.delMod(mod.config.name);
686
- this.log('info', '快照同步: 移除模块 ' + file);
687
692
  }
688
693
  }
689
694
  }
@@ -874,7 +879,7 @@ Manager.prototype._runMod = async function (mod, method, ...params) {
874
879
  /**
875
880
  * 初始化管理器
876
881
  */
877
- Manager.prototype._initManager = function () {};
882
+ Manager.prototype._initManager = function () { };
878
883
 
879
884
  /**
880
885
  * 获取公共模块目录
@@ -905,7 +910,7 @@ Manager.prototype._loadSources = async function () {
905
910
  if (snapshot) {
906
911
  // 快照存在,用config快速加载模块
907
912
  this._loadFromSnapshot(snapshot.mods_map);
908
- this.log('info', '已从快照快速加载模块,正在后台同步文件变更...');
913
+ // this.log('info', '已从快照快速加载模块,正在后台同步文件变更...');
909
914
  // 异步增量同步,不阻塞启动
910
915
  this._syncFromFile(snapshot);
911
916
  return;
@@ -1113,7 +1118,6 @@ Manager.prototype.runAll = async function (method, ...params) {
1113
1118
  let mod = this.getMod(info.name);
1114
1119
  promises.push(
1115
1120
  mod.do(method, ...params).catch((error) => {
1116
- this.log('error', `模块${info.name}执行${method}方法失败`, error);
1117
1121
  return null; // 失败时返回null
1118
1122
  })
1119
1123
  );
@@ -1146,7 +1150,6 @@ Manager.prototype.runRace = async function (method, ...params) {
1146
1150
  let mod = this.getMod(info.name);
1147
1151
  promises.push(
1148
1152
  mod.do(method, ...params).catch((error) => {
1149
- this.log('error', `模块${info.name}执行${method}方法失败`, error);
1150
1153
  throw error; // 竞争执行中,失败应该抛出错误
1151
1154
  })
1152
1155
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "2.8.4",
3
+ "version": "2.8.6",
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": {