@yumerijs/loader 2.0.3 → 2.0.5
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/dist/index.js +17 -6
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -57,8 +57,6 @@ class PluginLoader {
|
|
|
57
57
|
constructor(core, pluginsDir = 'plugins') {
|
|
58
58
|
this.pluginsDir = pluginsDir;
|
|
59
59
|
this.core = core || new core_1.Core(this, undefined, false);
|
|
60
|
-
this.core.uuid = Math.random().toString(36).substring(2);
|
|
61
|
-
this.logger.info(`[DIAG] Loader created/received Core instance with UUID: ${this.core.uuid}`);
|
|
62
60
|
this.isDev = process.env.NODE_ENV === 'development';
|
|
63
61
|
core_1.Logger.setCore(this.core);
|
|
64
62
|
}
|
|
@@ -278,15 +276,28 @@ class PluginLoader {
|
|
|
278
276
|
* @param pluginName The name of the plugin to reload.
|
|
279
277
|
*/
|
|
280
278
|
async reloadPlugin(pluginName) {
|
|
281
|
-
this.logger.info(`Reloading plugin
|
|
282
|
-
|
|
283
|
-
|
|
279
|
+
this.logger.info(`Reloading plugin: "${pluginName}"...`);
|
|
280
|
+
// Clear the module cache for the plugin. This is critical for hot-reloading.
|
|
281
|
+
try {
|
|
282
|
+
const resolvedPath = require.resolve(pluginName);
|
|
283
|
+
this.clearRequireCache(resolvedPath, new Set());
|
|
284
|
+
this.logger.info(`Cache cleared for plugin "${pluginName}".`);
|
|
285
|
+
}
|
|
286
|
+
catch (e) {
|
|
287
|
+
this.logger.error(`Could not resolve path for plugin ${pluginName} to clear cache.`, e);
|
|
288
|
+
}
|
|
289
|
+
// Reload the configuration from disk to catch any changes.
|
|
290
|
+
await this.reloadConfigFile();
|
|
291
|
+
// Unload the plugin and its dependents.
|
|
292
|
+
await this.unloadPlugin(pluginName, true);
|
|
293
|
+
// Load the plugin again. This will also trigger a check for other pending plugins.
|
|
284
294
|
const success = await this.loadSinglePlugin(pluginName);
|
|
285
295
|
if (success) {
|
|
296
|
+
this.logger.info(`Plugin "${pluginName}" reloaded successfully.`);
|
|
286
297
|
this.core.emit('plugin-reloaded', pluginName);
|
|
287
298
|
}
|
|
288
299
|
else {
|
|
289
|
-
this.logger.error(`Failed to reload plugin "${pluginName}". It may have unmet dependencies.`);
|
|
300
|
+
this.logger.error(`Failed to reload plugin "${pluginName}". It may have unmet dependencies or other errors.`);
|
|
290
301
|
}
|
|
291
302
|
}
|
|
292
303
|
watchPlugin(pluginName, pluginPath) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yumerijs/loader",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "Module loader for yumeri",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "tsc"
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|