node-pluginsmanager 3.6.0 → 3.6.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.
|
@@ -31,7 +31,7 @@ export default class PluginsManager extends EventEmitter {
|
|
|
31
31
|
beforeInitAll(callback: tBeforeAllMethodCallback): Promise<void>;
|
|
32
32
|
initAll(...data: unknown[]): Promise<void>;
|
|
33
33
|
releaseAll(...data: unknown[]): Promise<void>;
|
|
34
|
-
getLatestGithubTag(
|
|
34
|
+
getLatestGithubTag(plugin: Orchestrator): Promise<string>;
|
|
35
35
|
installViaGithub(user: string, repo: string, ...data: unknown[]): Promise<Orchestrator>;
|
|
36
36
|
updateViaGithub(plugin: Orchestrator, ...data: unknown[]): Promise<Orchestrator>;
|
|
37
37
|
uninstall(plugin: Orchestrator, ...data: unknown[]): Promise<string>;
|
|
@@ -25,7 +25,6 @@ const isFile_1 = __importDefault(require("./utils/isFile"));
|
|
|
25
25
|
const createPluginByDirectory_1 = __importDefault(require("./createPluginByDirectory"));
|
|
26
26
|
const loadSortedPlugins_1 = __importDefault(require("./loadSortedPlugins"));
|
|
27
27
|
const initSortedPlugins_1 = __importDefault(require("./initSortedPlugins"));
|
|
28
|
-
const extractGithub_1 = __importDefault(require("./utils/extractGithub"));
|
|
29
28
|
const getLatestGithubTag_1 = __importDefault(require("./utils/getLatestGithubTag"));
|
|
30
29
|
const parseGithubUserRepo_1 = __importDefault(require("./utils/parseGithubUserRepo"));
|
|
31
30
|
// git
|
|
@@ -223,7 +222,7 @@ class PluginsManager extends node_events_1.default {
|
|
|
223
222
|
// after releasing, destroy packages data & free "plugins" list, using "data" in arguments for "destroy" plugin's Orchestrator method
|
|
224
223
|
destroyAll(...data) {
|
|
225
224
|
return Promise.all(this.plugins.map((plugin) => {
|
|
226
|
-
return plugin.destroy().then(() => {
|
|
225
|
+
return plugin.destroy(...data).then(() => {
|
|
227
226
|
this.emit("destroyed", plugin.name, ...data);
|
|
228
227
|
});
|
|
229
228
|
})).then(() => {
|
|
@@ -270,9 +269,15 @@ class PluginsManager extends node_events_1.default {
|
|
|
270
269
|
this.emit("allreleased", ...data);
|
|
271
270
|
});
|
|
272
271
|
}
|
|
273
|
-
getLatestGithubTag(
|
|
274
|
-
return (0,
|
|
275
|
-
|
|
272
|
+
getLatestGithubTag(plugin) {
|
|
273
|
+
return (0, checkOrchestrator_1.default)("getLatestGithubTag/plugin", plugin).then(() => {
|
|
274
|
+
const githubUserRepo = (0, parseGithubUserRepo_1.default)(plugin.repository);
|
|
275
|
+
if (!githubUserRepo) {
|
|
276
|
+
throw new Error("Plugin \"" + plugin.name + "\" has an invalid github project link");
|
|
277
|
+
}
|
|
278
|
+
return (0, getLatestGithubTag_1.default)(githubUserRepo.user, githubUserRepo.repo).then((tag) => {
|
|
279
|
+
return tag.name;
|
|
280
|
+
});
|
|
276
281
|
});
|
|
277
282
|
}
|
|
278
283
|
// install a plugin via github repo, using "data" in arguments for "install" and "init" plugin's Orchestrator methods
|
|
@@ -408,71 +413,60 @@ class PluginsManager extends node_events_1.default {
|
|
|
408
413
|
updateViaGithub(plugin, ...data) {
|
|
409
414
|
let directory = "";
|
|
410
415
|
let key = -1;
|
|
411
|
-
let
|
|
412
|
-
let latestTag = "";
|
|
416
|
+
let pluginName = "";
|
|
413
417
|
// check plugin
|
|
414
418
|
return (0, checkOrchestrator_1.default)("updateViaGithub/plugin", plugin).then(() => {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
return
|
|
418
|
-
}).then(() => {
|
|
419
|
-
githubUrl = github;
|
|
420
|
-
});
|
|
421
|
-
}).then(() => {
|
|
422
|
-
key = this.getPluginsNames().findIndex((pluginName) => {
|
|
423
|
-
return pluginName === plugin.name;
|
|
419
|
+
pluginName = plugin.name;
|
|
420
|
+
key = this.getPluginsNames().findIndex((pn) => {
|
|
421
|
+
return pluginName === pn;
|
|
424
422
|
});
|
|
425
423
|
if (-1 >= key) {
|
|
426
|
-
throw new Error("Plugin \"" +
|
|
424
|
+
throw new Error("Plugin \"" + pluginName + "\" is not registered");
|
|
427
425
|
}
|
|
428
426
|
// check plugin directory
|
|
429
427
|
}).then(() => {
|
|
430
428
|
return (0, checkAbsoluteDirectory_1.default)("updateViaGithub/directory", this.directory).then(() => {
|
|
431
|
-
directory = (0, node_path_1.join)(this.directory,
|
|
429
|
+
directory = (0, node_path_1.join)(this.directory, pluginName);
|
|
432
430
|
return (0, checkAbsoluteDirectory_1.default)("updateViaGithub/plugindirectory", directory);
|
|
433
431
|
});
|
|
434
432
|
// check remote version
|
|
435
433
|
}).then(() => {
|
|
436
|
-
const githubUserRepo = (0, parseGithubUserRepo_1.default)(githubUrl);
|
|
437
|
-
if (!githubUserRepo) {
|
|
438
|
-
throw new Error("Plugin \"" + plugin.name + "\" has an invalid github project link");
|
|
439
|
-
}
|
|
440
434
|
const currentVersion = semver_1.default.coerce(plugin.version);
|
|
441
435
|
if (!currentVersion) {
|
|
442
|
-
throw new Error("Plugin \"" +
|
|
436
|
+
throw new Error("Plugin \"" + pluginName + "\" has no valid version (\"" + plugin.version + "\")");
|
|
443
437
|
}
|
|
444
|
-
this._logger?.("debug", "Get github latest tag", false,
|
|
445
|
-
return
|
|
446
|
-
const latestVersion = semver_1.default.coerce(tag
|
|
438
|
+
this._logger?.("debug", "Get github latest tag", false, pluginName);
|
|
439
|
+
return this.getLatestGithubTag(plugin).then((tag) => {
|
|
440
|
+
const latestVersion = semver_1.default.coerce(tag);
|
|
447
441
|
if (!latestVersion) {
|
|
448
|
-
throw new Error("No valid version found for plugin \"" +
|
|
442
|
+
throw new Error("No valid version found for plugin \"" + pluginName + "\" on github");
|
|
449
443
|
}
|
|
450
|
-
this._logger?.("debug", "Compare local version with github
|
|
444
|
+
this._logger?.("debug", "Compare local version with github latest tag", false, pluginName);
|
|
451
445
|
if (!semver_1.default.gt(latestVersion, currentVersion)) {
|
|
452
|
-
throw new Error("Plugin \"" +
|
|
446
|
+
throw new Error("Plugin \"" + pluginName + "\" is already up to date (v" + plugin.version + ")");
|
|
453
447
|
}
|
|
454
|
-
|
|
455
|
-
|
|
448
|
+
this._logger?.("success", "New version available", false, pluginName);
|
|
449
|
+
return tag;
|
|
456
450
|
});
|
|
457
451
|
// release plugin
|
|
458
|
-
}).then(() => {
|
|
459
|
-
const pluginName = plugin.name;
|
|
452
|
+
}).then((latestTag) => {
|
|
460
453
|
return plugin.release(...data).then(() => {
|
|
461
454
|
this.emit("released", plugin, ...data);
|
|
462
|
-
return plugin.destroy();
|
|
455
|
+
return plugin.destroy(...data);
|
|
463
456
|
}).then(() => {
|
|
464
457
|
this.emit("destroyed", pluginName, ...data);
|
|
465
458
|
this.plugins.splice(key, 1);
|
|
459
|
+
return latestTag;
|
|
466
460
|
});
|
|
467
461
|
// update plugin
|
|
468
|
-
}).then(() => {
|
|
469
|
-
this._logger?.("debug", "Update with new plugin version", false,
|
|
462
|
+
}).then((latestTag) => {
|
|
463
|
+
this._logger?.("debug", "Update with new plugin version", false, pluginName);
|
|
470
464
|
return (0, gitUpdate_1.default)(directory, latestTag).then(() => {
|
|
471
465
|
return (0, createPluginByDirectory_1.default)(directory, this.externalResourcesDirectory, this._logger, ...data);
|
|
472
466
|
});
|
|
473
467
|
// check plugin modules versions
|
|
474
468
|
}).then((_plugin) => {
|
|
475
|
-
this._logger?.("debug", "Check modules", false,
|
|
469
|
+
this._logger?.("debug", "Check modules", false, pluginName);
|
|
476
470
|
return this.checkModules(_plugin).then(() => {
|
|
477
471
|
return _plugin;
|
|
478
472
|
});
|
|
@@ -496,25 +490,26 @@ class PluginsManager extends node_events_1.default {
|
|
|
496
490
|
// uninstall a plugin, using "data" in arguments for "release" and "uninstall" plugin's methods
|
|
497
491
|
uninstall(plugin, ...data) {
|
|
498
492
|
let directory = "";
|
|
499
|
-
let key = -1;
|
|
500
493
|
let pluginName = "";
|
|
501
494
|
// check plugin
|
|
502
495
|
return Promise.resolve().then(() => {
|
|
503
496
|
return (0, checkOrchestrator_1.default)("uninstall/plugin", plugin).then(() => {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
497
|
+
pluginName = plugin.name;
|
|
498
|
+
if (!this.getPluginsNames().includes(pluginName)) {
|
|
499
|
+
throw new Error("Plugin \"" + pluginName + "\" is not registered");
|
|
500
|
+
}
|
|
508
501
|
});
|
|
509
502
|
// check plugin directory
|
|
510
503
|
}).then(() => {
|
|
511
504
|
return (0, checkAbsoluteDirectory_1.default)("uninstall/directory", this.directory).then(() => {
|
|
512
|
-
pluginName = plugin.name;
|
|
513
505
|
directory = (0, node_path_1.join)(this.directory, pluginName);
|
|
514
506
|
return (0, checkAbsoluteDirectory_1.default)("uninstall/plugindirectory", directory);
|
|
515
507
|
});
|
|
516
508
|
// release plugin
|
|
517
509
|
}).then(() => {
|
|
510
|
+
const key = this.getPluginsNames().findIndex((name) => {
|
|
511
|
+
return name === pluginName;
|
|
512
|
+
});
|
|
518
513
|
return plugin.release(...data).then(() => {
|
|
519
514
|
return (0, rmdirp_1.default)((0, node_path_1.join)(this.externalResourcesDirectory, pluginName));
|
|
520
515
|
}).then(() => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
|
|
3
3
|
"name": "node-pluginsmanager",
|
|
4
|
-
"version": "3.6.
|
|
4
|
+
"version": "3.6.2",
|
|
5
5
|
"description": "A plugins manager.",
|
|
6
6
|
|
|
7
7
|
"type": "commonjs",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/express": "5.0.6",
|
|
56
|
-
"@types/node": "26.0
|
|
56
|
+
"@types/node": "26.1.0",
|
|
57
57
|
"@types/semver": "7.7.1",
|
|
58
58
|
"@types/socket.io": "3.0.2",
|
|
59
59
|
"@types/ws": "8.18.1",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"express": "5.2.1",
|
|
62
62
|
"husky": "9.1.7",
|
|
63
63
|
"mocha": "11.7.6",
|
|
64
|
-
"node-pluginsmanager-plugin": "7.4.
|
|
64
|
+
"node-pluginsmanager-plugin": "7.4.2",
|
|
65
65
|
"nyc": "18.0.0",
|
|
66
66
|
"proxyquire": "2.1.3",
|
|
67
67
|
"rimraf": "6.1.3",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Orchestrator } from "node-pluginsmanager-plugin";
|
|
2
|
-
interface OrchestratorExtended extends Orchestrator {
|
|
3
|
-
"github"?: string;
|
|
4
|
-
"repository"?: string | Record<string, string>;
|
|
5
|
-
}
|
|
6
|
-
export default function extractGithub(plugin: OrchestratorExtended): string | null;
|
|
7
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// types & interfaces
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.default = extractGithub;
|
|
5
|
-
// module
|
|
6
|
-
function extractGithub(plugin) {
|
|
7
|
-
let github = null;
|
|
8
|
-
if ("object" === typeof plugin) {
|
|
9
|
-
if ("string" === typeof plugin.github) {
|
|
10
|
-
github = plugin.github;
|
|
11
|
-
}
|
|
12
|
-
else if ("string" === typeof plugin.repository) {
|
|
13
|
-
github = plugin.repository;
|
|
14
|
-
}
|
|
15
|
-
else if ("object" === typeof plugin.repository && "string" === typeof plugin.repository.url) {
|
|
16
|
-
github = plugin.repository.url;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return github ?? null;
|
|
20
|
-
}
|