mm_machine 3.2.0 → 3.2.2

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/manager.js +9 -15
  2. package/package.json +1 -1
package/manager.js CHANGED
@@ -260,8 +260,7 @@ Manager.prototype.getMod = function (name) {
260
260
  for (var i = 0; i < entries.length; i++) {
261
261
  if (entries[i].name === name) {
262
262
  var entry = entries[i];
263
- const ModClass = this.config.mod_type === 'script' ? Mod : this.Drive;
264
- mod = new ModClass(entry, this);
263
+ mod = new this.Drive(entry, this);
265
264
  mod.mode = this.config.mode;
266
265
  mod.config_file = entry.config_file;
267
266
  if (mod._preset) {
@@ -536,7 +535,6 @@ Manager.prototype._loadFromRegistry = function () {
536
535
  let lt = this._getInfos();
537
536
  if (!lt.length) return false;
538
537
 
539
- var mod_class = this.config.mod_type === 'script' ? Mod : this.Drive;
540
538
  var mode = this.config.mode;
541
539
  var mods = this.mods;
542
540
 
@@ -545,7 +543,7 @@ Manager.prototype._loadFromRegistry = function () {
545
543
 
546
544
  if (!this.config.lazy_load) {
547
545
  // 非懒加载模式:立即实例化
548
- var mod = new ModClass(entry, this);
546
+ var mod = new this.Drive(entry, this);
549
547
  mod.mode = mode;
550
548
  mod.config_file = entry.config_file;
551
549
  if (mod._preset) {
@@ -595,9 +593,7 @@ Manager.prototype.main = async function (name, method, ...params) {
595
593
  var entries = this._getInfos();
596
594
  var entry = entries.find((o) => { return o.name === name; });
597
595
  if (entry && entry.state === 1) {
598
- var mod_class = this.config.mod_type === 'script' ? Mod : this.Drive;
599
- mod = new ModClass(entry, this);
600
- mod.mode = this.config.mode;
596
+ var mod = new this.Drive(entry, this);
601
597
  mod.config_file = entry.config_file;
602
598
  if (mod._preset) mod._preset();
603
599
  this.mods[name] = mod;
@@ -701,31 +697,29 @@ Manager.prototype.getDir = function () {
701
697
  * 同时在后台异步扫描文件系统,确保注册表数据为物理最新。
702
698
  */
703
699
  Manager.prototype._loadSources = async function () {
704
- // 启用注册表且有缓存数据时,走内存快路径
705
- // 按管理器自身 name 过滤,多 Manager 共享 $.registry 时互不污染
700
+ // 启用注册表且有缓存数据时,走内存快路径,快速启动;
701
+ // 后台异步扫描文件系统更新注册表,确保物理最新。
706
702
  if (this.config.use_registry) {
707
- // 只有从注册表成功加载到模块时才跳过文件系统扫描,否则回退到文件系统
708
703
  if (this._loadFromRegistry()) {
709
- // 后台异步扫描文件系统,确保物理最新
710
704
  setImmediate(() => this._scanForUpdate(false));
711
705
  return;
712
706
  }
713
707
  }
714
708
 
715
- // 注册表无匹配,走文件系统扫描
716
- await this._scanForUpdate(false);
709
+ // 注册表无缓存,同步扫描文件系统
710
+ await this._scanForUpdate();
717
711
  };
718
712
 
719
713
  /**
720
714
  * 后台扫描文件系统并同步到注册表
721
715
  * 不阻塞启动,让注册表始终与磁盘保持同步
722
716
  */
723
- Manager.prototype._scanForUpdate = async function (clear = false) {
717
+ Manager.prototype._scanForUpdate = async function (clear = true) {
724
718
  var base_dir = this.getBaseDir();
725
719
  var dir = this.getDir();
726
720
  try {
727
721
  if (base_dir) {
728
- await Promise.all([this.call('update', base_dir, clear), this.call('update', dir, clear)]);
722
+ await Promise.all([this.call('update', base_dir, clear), this.call('update', dir, false)]);
729
723
  } else {
730
724
  await this.call('update', dir, clear);
731
725
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
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": {