node-pluginsmanager 3.8.0 → 3.8.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.
- package/lib/cjs/PluginsManager.d.ts +3 -0
- package/lib/cjs/PluginsManager.js +41 -4
- package/lib/cjs/cmd/npm/npmInstall.js +37 -4
- package/lib/cjs/cmd/npm/npmUpdate.js +1 -1
- package/lib/cjs/createPluginByDirectory.js +2 -0
- package/lib/cjs/utils/clearRequireCache.d.ts +1 -0
- package/lib/cjs/utils/clearRequireCache.js +23 -0
- package/package.json +25 -18
|
@@ -54,6 +54,9 @@ export default class PluginsManager extends EventEmitter<{
|
|
|
54
54
|
installViaGithub(user: string, repo: string, ...data: unknown[]): Promise<Orchestrator>;
|
|
55
55
|
private _isExternalPlugin;
|
|
56
56
|
private _updateWithoutGit;
|
|
57
|
+
private _rejectReleasedUpdate;
|
|
58
|
+
private _splicePlugin;
|
|
59
|
+
private _destroyReleasedPlugin;
|
|
57
60
|
updateViaGithub(plugin: Orchestrator, ...data: unknown[]): Promise<Orchestrator>;
|
|
58
61
|
uninstall(plugin: Orchestrator, ...data: unknown[]): Promise<string>;
|
|
59
62
|
}
|
|
@@ -15,6 +15,7 @@ const check_node_engine_1 = __importDefault(require("check-node-engine"));
|
|
|
15
15
|
const semver_1 = __importDefault(require("semver"));
|
|
16
16
|
// locals
|
|
17
17
|
const rmdirp_1 = __importDefault(require("./utils/rmdirp"));
|
|
18
|
+
const clearRequireCache_1 = __importDefault(require("./utils/clearRequireCache"));
|
|
18
19
|
const checkAbsoluteDirectory_1 = __importDefault(require("./checkers/checkAbsoluteDirectory"));
|
|
19
20
|
const checkFunction_1 = __importDefault(require("./checkers/checkFunction"));
|
|
20
21
|
const checkNonEmptyArray_1 = __importDefault(require("./checkers/checkNonEmptyArray"));
|
|
@@ -38,6 +39,18 @@ const npmUpdate_1 = __importDefault(require("./cmd/npm/npmUpdate"));
|
|
|
38
39
|
// consts
|
|
39
40
|
const DEFAULT_PLUGINS_DIRECTORY = (0, node_path_1.join)((0, node_os_1.homedir)(), "node-pluginsmanager-plugins");
|
|
40
41
|
const DEFAULT_RESOURCES_DIRECTORY = (0, node_path_1.join)((0, node_os_1.homedir)(), "node-pluginsmanager-resources");
|
|
42
|
+
// private
|
|
43
|
+
// methods
|
|
44
|
+
function _removeReleasedDirectory(directory) {
|
|
45
|
+
return (0, rmdirp_1.default)(directory).catch(() => {
|
|
46
|
+
return (0, promises_1.rm)(directory, {
|
|
47
|
+
"recursive": true,
|
|
48
|
+
"force": true
|
|
49
|
+
});
|
|
50
|
+
}).catch(() => {
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
41
54
|
// module
|
|
42
55
|
class PluginsManager extends node_events_1.default {
|
|
43
56
|
// attributes
|
|
@@ -491,6 +504,30 @@ class PluginsManager extends node_events_1.default {
|
|
|
491
504
|
return (0, gitInstall_1.default)(directory, user, repo);
|
|
492
505
|
});
|
|
493
506
|
}
|
|
507
|
+
_rejectReleasedUpdate(pluginName, directory, err) {
|
|
508
|
+
if (this.getPluginsNames().includes(pluginName)) {
|
|
509
|
+
return Promise.reject(err);
|
|
510
|
+
}
|
|
511
|
+
(0, clearRequireCache_1.default)(directory);
|
|
512
|
+
return (0, rmdirp_1.default)((0, node_path_1.join)(this.externalResourcesDirectory, pluginName)).catch(() => {
|
|
513
|
+
return Promise.resolve();
|
|
514
|
+
}).then(() => {
|
|
515
|
+
return _removeReleasedDirectory(directory);
|
|
516
|
+
}).then(() => {
|
|
517
|
+
return Promise.reject(err);
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
_splicePlugin(key) {
|
|
521
|
+
if (-1 < key) {
|
|
522
|
+
this.plugins.splice(key, 1);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
_destroyReleasedPlugin(plugin, key, ...data) {
|
|
526
|
+
return plugin.destroy(...data).catch((err) => {
|
|
527
|
+
this._splicePlugin(key);
|
|
528
|
+
return Promise.reject(err);
|
|
529
|
+
});
|
|
530
|
+
}
|
|
494
531
|
// update a plugin via its github repo, using "data" in arguments for "release", "update" and "init" plugin's methods
|
|
495
532
|
updateViaGithub(plugin, ...data) {
|
|
496
533
|
let directory = "";
|
|
@@ -543,12 +580,10 @@ class PluginsManager extends node_events_1.default {
|
|
|
543
580
|
const key = this.plugins.indexOf(plugin);
|
|
544
581
|
return plugin.release(...data).then(() => {
|
|
545
582
|
this.emit("released", plugin, ...data);
|
|
546
|
-
return
|
|
583
|
+
return this._destroyReleasedPlugin(plugin, key, ...data);
|
|
547
584
|
}).then(() => {
|
|
548
585
|
this.emit("destroyed", pluginName, ...data);
|
|
549
|
-
|
|
550
|
-
this.plugins.splice(key, 1);
|
|
551
|
-
}
|
|
586
|
+
this._splicePlugin(key);
|
|
552
587
|
return latestTag;
|
|
553
588
|
});
|
|
554
589
|
// update plugin
|
|
@@ -590,6 +625,8 @@ class PluginsManager extends node_events_1.default {
|
|
|
590
625
|
this.plugins.push(_plugin);
|
|
591
626
|
return _plugin;
|
|
592
627
|
});
|
|
628
|
+
}).catch((err) => {
|
|
629
|
+
return this._rejectReleasedUpdate(pluginName, directory, err);
|
|
593
630
|
});
|
|
594
631
|
});
|
|
595
632
|
}
|
|
@@ -5,12 +5,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.default = npmInstall;
|
|
8
|
+
// natives
|
|
9
|
+
const promises_1 = require("node:fs/promises");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
8
11
|
// locals
|
|
9
12
|
const cmd_1 = __importDefault(require("../cmd"));
|
|
13
|
+
// private
|
|
14
|
+
// methods
|
|
15
|
+
function _hasInstallScripts(packageData) {
|
|
16
|
+
if ("object" !== typeof packageData.scripts || null === packageData.scripts) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const scripts = packageData.scripts;
|
|
20
|
+
const installDev = scripts["install-dev"];
|
|
21
|
+
const installProd = scripts["install-prod"];
|
|
22
|
+
if ("string" !== typeof installDev || "string" !== typeof installProd) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return "" !== installDev.trim() && "" !== installProd.trim();
|
|
26
|
+
}
|
|
10
27
|
// module
|
|
11
28
|
function npmInstall(directory, isBuildMode = false) {
|
|
12
|
-
return (0,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
29
|
+
return (0, promises_1.readFile)((0, node_path_1.join)(directory, "package.json"), "utf-8").then((content) => {
|
|
30
|
+
const packageData = JSON.parse(content);
|
|
31
|
+
if (_hasInstallScripts(packageData)) {
|
|
32
|
+
return (0, cmd_1.default)(directory, "npm", [
|
|
33
|
+
"run",
|
|
34
|
+
isBuildMode ? "install-dev" : "install-prod"
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
const flags = isBuildMode ? ["--omit=optional"] : ["--omit=dev", "--omit=optional"];
|
|
38
|
+
return (0, cmd_1.default)(directory, "npm", [
|
|
39
|
+
"install",
|
|
40
|
+
...flags
|
|
41
|
+
]).then(() => {
|
|
42
|
+
return (0, cmd_1.default)(directory, "npm", [
|
|
43
|
+
"audit",
|
|
44
|
+
"fix",
|
|
45
|
+
...flags
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
16
49
|
}
|
|
@@ -15,6 +15,7 @@ const node_path_1 = require("node:path");
|
|
|
15
15
|
const checkAbsoluteDirectory_1 = __importDefault(require("./checkers/checkAbsoluteDirectory"));
|
|
16
16
|
const checkOrchestrator_1 = __importDefault(require("./checkers/checkOrchestrator"));
|
|
17
17
|
const checkFunction_1 = __importDefault(require("./checkers/checkFunction"));
|
|
18
|
+
const clearRequireCache_1 = __importDefault(require("./utils/clearRequireCache"));
|
|
18
19
|
// module
|
|
19
20
|
function createPluginByDirectory(directory, externalResourcesDirectory, logger, ...data) {
|
|
20
21
|
return (0, checkAbsoluteDirectory_1.default)("createPluginByDirectory/directory", directory).then(() => {
|
|
@@ -22,6 +23,7 @@ function createPluginByDirectory(directory, externalResourcesDirectory, logger,
|
|
|
22
23
|
}).then(() => {
|
|
23
24
|
return new Promise((resolve, reject) => {
|
|
24
25
|
try {
|
|
26
|
+
(0, clearRequireCache_1.default)(directory);
|
|
25
27
|
resolve(require(directory));
|
|
26
28
|
}
|
|
27
29
|
catch (e) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function clearRequireCache(directory: string): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// deps
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.default = clearRequireCache;
|
|
5
|
+
// natives
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
// private
|
|
8
|
+
// methods
|
|
9
|
+
function _isUnderDirectory(directory, file) {
|
|
10
|
+
const fromDirectory = (0, node_path_1.relative)(directory, file);
|
|
11
|
+
if ("" === fromDirectory) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return !fromDirectory.startsWith("..") && !(0, node_path_1.isAbsolute)(fromDirectory);
|
|
15
|
+
}
|
|
16
|
+
// module
|
|
17
|
+
function clearRequireCache(directory) {
|
|
18
|
+
for (const file of Object.keys(require.cache)) {
|
|
19
|
+
if (_isUnderDirectory(directory, file)) {
|
|
20
|
+
Reflect.deleteProperty(require.cache, file);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
|
|
3
3
|
"name": "node-pluginsmanager",
|
|
4
|
-
"version": "3.8.
|
|
4
|
+
"version": "3.8.2",
|
|
5
5
|
"description": "A plugins manager.",
|
|
6
6
|
|
|
7
7
|
"type": "commonjs",
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
|
|
22
|
+
"install-prod": "npm install --omit=dev --omit=optional && npm audit fix --omit=dev --omit=optional",
|
|
23
|
+
"install-dev": "npm install --allow-git=root && npm audit fix --allow-git=root && npx husky",
|
|
24
|
+
|
|
22
25
|
"lint-back": "npx eslint --config .eslintrc-back.js --ext .ts,.cts,.mts ./lib/src/**/*",
|
|
23
26
|
"lint-tests": "npx eslint --config .eslintrc-tests.js --ext .js,.cjs,.mjs ./test/**/*.js",
|
|
24
27
|
"lint": "npm run lint-back && npm run lint-tests",
|
|
@@ -32,10 +35,10 @@
|
|
|
32
35
|
"check-node-engine": "npx check-node-engine",
|
|
33
36
|
"check-requires": "npx used-deps-analyzer ./package.json ./lib/src --no-dev",
|
|
34
37
|
"check-updates": "npx check-version-modules --no-fail-at-major --fail-at-minor --fail-at-patch",
|
|
35
|
-
"unit-tests": "npx mocha",
|
|
36
|
-
"unit-tests-local": "npx
|
|
38
|
+
"unit-tests": "npx c8 --reporter=text-summary --all --include \"lib/src/**/*.ts\" --include \"lib/src/**/*.cts\" --extension .ts --extension .cts --check-coverage --statements 95 --branches 95 --functions 95 --lines 95 mocha --require ./test/register.js",
|
|
39
|
+
"unit-tests-local": "npx c8 --reporter=html --reporter=text --all --include \"lib/src/**/*.ts\" --include \"lib/src/**/*.cts\" --extension .ts --extension .cts mocha --require ./test/register.js",
|
|
37
40
|
|
|
38
|
-
"tests": "npm run lint && npm run check-node-engine && npm run check-requires && npm run check-updates && npm run build && npm run unit-tests
|
|
41
|
+
"tests": "npm run lint && npm run check-node-engine && npm run check-requires && npm run check-updates && npm run build && npm run unit-tests"
|
|
39
42
|
|
|
40
43
|
},
|
|
41
44
|
|
|
@@ -43,32 +46,36 @@
|
|
|
43
46
|
"/lib/cjs"
|
|
44
47
|
],
|
|
45
48
|
"engines": {
|
|
46
|
-
"node": ">=22.
|
|
49
|
+
"node": ">=24.22.2"
|
|
47
50
|
},
|
|
48
51
|
|
|
49
52
|
"dependencies": {
|
|
50
|
-
"check-node-engine": "1.2.
|
|
51
|
-
"check-version-modules": "2.5.
|
|
52
|
-
"semver": "7.8.
|
|
53
|
+
"check-node-engine": "1.2.1",
|
|
54
|
+
"check-version-modules": "2.5.2",
|
|
55
|
+
"semver": "7.8.6"
|
|
53
56
|
},
|
|
54
57
|
"devDependencies": {
|
|
55
58
|
"@types/express": "5.0.6",
|
|
56
|
-
"@types/node": "26.
|
|
59
|
+
"@types/node": "26.6.6",
|
|
57
60
|
"@types/semver": "7.8.0",
|
|
58
61
|
"@types/socket.io": "3.0.2",
|
|
59
|
-
"@types/ws": "8.18.
|
|
62
|
+
"@types/ws": "8.18.2",
|
|
63
|
+
"c8": "12.0.0",
|
|
60
64
|
"eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
|
|
61
|
-
"express": "5.
|
|
65
|
+
"express": "5.3.0",
|
|
62
66
|
"husky": "9.1.7",
|
|
63
|
-
"mocha": "12.0.
|
|
64
|
-
"node-pluginsmanager-plugin": "7.4.
|
|
65
|
-
"nyc": "18.0.0",
|
|
67
|
+
"mocha": "12.0.3",
|
|
68
|
+
"node-pluginsmanager-plugin": "7.4.5",
|
|
66
69
|
"proxyquire": "2.1.3",
|
|
67
70
|
"rimraf": "6.1.3",
|
|
68
|
-
"socket.io": "4.8.
|
|
69
|
-
"typescript": "
|
|
70
|
-
"used-deps-analyzer": "0.4.
|
|
71
|
-
"ws": "8.
|
|
71
|
+
"socket.io": "4.8.4",
|
|
72
|
+
"typescript": "6.0.3",
|
|
73
|
+
"used-deps-analyzer": "0.4.1",
|
|
74
|
+
"ws": "8.22.1"
|
|
75
|
+
},
|
|
76
|
+
"overrides": {
|
|
77
|
+
"glob": "14.0.3",
|
|
78
|
+
"minimatch": "11.0.1"
|
|
72
79
|
},
|
|
73
80
|
|
|
74
81
|
"keywords": [
|