aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-modmgr.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core/module-modmgr.js')
-rw-r--r--modules/core/module-modmgr.js29
1 files changed, 17 insertions, 12 deletions
diff --git a/modules/core/module-modmgr.js b/modules/core/module-modmgr.js
index ec8c384..8c39e04 100644
--- a/modules/core/module-modmgr.js
+++ b/modules/core/module-modmgr.js
@@ -338,22 +338,27 @@
this.terminal.print(`✅ Module '${name}' marked as unloaded (commands will not be available)`, 'success');
};
- // module-reload <name> — unload + reload with diff
- this.commands['module-reload'] = (args) => {
+ // module-reload <name> — re-fetch, re-parse, re-register
+ this.commands['module-reload'] = async (args) => {
if (!args[0]) return this.terminal.print('Usage: module-reload <name>', 'warning');
const name = args[0];
const mod = this._getMod(name);
if (!mod) return this.terminal.print(`Module not found: ${name}`, 'error');
- const wasLoaded = mod.loaded !== false;
- const wasLazy = mod.lazy;
- this.terminal.print(`🔄 Reloading '${name}' (was: ${wasLoaded ? 'loaded' : 'unloaded'}, lazy=${wasLazy})`, 'info');
- mod.loaded = false;
- setTimeout(() => {
- mod.loaded = true;
- this.terminal.print(`✅ Module '${name}' reloaded`, 'success');
- const cmdCount = mod.commands ? Object.keys(mod.commands).length : 0;
- this.terminal.print(` Now: loaded=true, lazy=${mod.lazy}, ${cmdCount} commands`, 'info');
- }, 100);
+ const mm = this.terminal.moduleManager;
+ // Find the module's URL from registry
+ const regEntry = mm.moduleRegistry.find(m => m.name === name);
+ const url = regEntry ? regEntry.url : null;
+ if (!url) return this.terminal.print(`Module '${name}' has no URL — cannot reload (built-in)`, 'warning');
+ this.terminal.print(`🔄 Reloading '${name}' from ${url}...`, 'info');
+ // Unregister old instance
+ mm.unregisterModule(name);
+ // Re-fetch and re-register
+ const success = await mm.loadModuleFromURL(url);
+ if (success) {
+ this.terminal.print(`✅ Module '${name}' reloaded successfully`, 'success');
+ } else {
+ this.terminal.print(`❌ Failed to reload '${name}'`, 'error');
+ }
};
// module-reset <name> — clear module state and reload