mm_machine 3.1.9 → 3.2.0

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/manager.js CHANGED
@@ -343,7 +343,11 @@ Manager.prototype.regMod = function (config_file, config = {}, script = {}) {
343
343
 
344
344
  var mod = this.newMod(config_file, cg, script);
345
345
  if (!mod) return null;
346
- this.setMod(mod.config.name, mod);
346
+
347
+ // 模块已存在时不替换内存实例,避免破坏已初始化的模块
348
+ if (!this.mods[mod.config.name]) {
349
+ this.setMod(mod.config.name, mod);
350
+ }
347
351
 
348
352
  var entry = {
349
353
  name: mod.config.name,
@@ -703,27 +707,27 @@ Manager.prototype._loadSources = async function () {
703
707
  // 只有从注册表成功加载到模块时才跳过文件系统扫描,否则回退到文件系统
704
708
  if (this._loadFromRegistry()) {
705
709
  // 后台异步扫描文件系统,确保物理最新
706
- setImmediate(() => this._scanForUpdate());
710
+ setImmediate(() => this._scanForUpdate(false));
707
711
  return;
708
712
  }
709
713
  }
710
714
 
711
715
  // 注册表无匹配,走文件系统扫描
712
- await this._scanForUpdate();
716
+ await this._scanForUpdate(false);
713
717
  };
714
718
 
715
719
  /**
716
720
  * 后台扫描文件系统并同步到注册表
717
721
  * 不阻塞启动,让注册表始终与磁盘保持同步
718
722
  */
719
- Manager.prototype._scanForUpdate = async function () {
723
+ Manager.prototype._scanForUpdate = async function (clear = false) {
720
724
  var base_dir = this.getBaseDir();
721
725
  var dir = this.getDir();
722
726
  try {
723
727
  if (base_dir) {
724
- await Promise.all([this.call('update', base_dir, true), this.call('update', dir, false)]);
728
+ await Promise.all([this.call('update', base_dir, clear), this.call('update', dir, clear)]);
725
729
  } else {
726
- await this.call('update', dir, true);
730
+ await this.call('update', dir, clear);
727
731
  }
728
732
  if (this.config.use_registry) {
729
733
  $.registry.save();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "3.1.9",
3
+ "version": "3.2.0",
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
@@ -28,7 +28,6 @@ class Registry {
28
28
  */
29
29
  Registry.prototype.newModel = function () {
30
30
  return {
31
- parent: '',
32
31
  name: '',
33
32
  title: '',
34
33
  description: '',