node-pluginsmanager 3.8.1 → 3.8.3

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.
@@ -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"));
@@ -34,10 +35,21 @@ const gitUpdate_1 = __importDefault(require("./cmd/git/gitUpdate"));
34
35
  // npm
35
36
  const npmInstall_1 = __importDefault(require("./cmd/npm/npmInstall"));
36
37
  const npmBuild_1 = __importDefault(require("./cmd/npm/npmBuild"));
37
- const npmUpdate_1 = __importDefault(require("./cmd/npm/npmUpdate"));
38
38
  // consts
39
39
  const DEFAULT_PLUGINS_DIRECTORY = (0, node_path_1.join)((0, node_os_1.homedir)(), "node-pluginsmanager-plugins");
40
40
  const DEFAULT_RESOURCES_DIRECTORY = (0, node_path_1.join)((0, node_os_1.homedir)(), "node-pluginsmanager-resources");
41
+ // private
42
+ // methods
43
+ function _removeReleasedDirectory(directory) {
44
+ return (0, rmdirp_1.default)(directory).catch(() => {
45
+ return (0, promises_1.rm)(directory, {
46
+ "recursive": true,
47
+ "force": true
48
+ });
49
+ }).catch(() => {
50
+ return Promise.resolve();
51
+ });
52
+ }
41
53
  // module
42
54
  class PluginsManager extends node_events_1.default {
43
55
  // attributes
@@ -491,6 +503,30 @@ class PluginsManager extends node_events_1.default {
491
503
  return (0, gitInstall_1.default)(directory, user, repo);
492
504
  });
493
505
  }
506
+ _rejectReleasedUpdate(pluginName, directory, err) {
507
+ if (this.getPluginsNames().includes(pluginName)) {
508
+ return Promise.reject(err);
509
+ }
510
+ (0, clearRequireCache_1.default)(directory);
511
+ return (0, rmdirp_1.default)((0, node_path_1.join)(this.externalResourcesDirectory, pluginName)).catch(() => {
512
+ return Promise.resolve();
513
+ }).then(() => {
514
+ return _removeReleasedDirectory(directory);
515
+ }).then(() => {
516
+ return Promise.reject(err);
517
+ });
518
+ }
519
+ _splicePlugin(key) {
520
+ if (-1 < key) {
521
+ this.plugins.splice(key, 1);
522
+ }
523
+ }
524
+ _destroyReleasedPlugin(plugin, key, ...data) {
525
+ return plugin.destroy(...data).catch((err) => {
526
+ this._splicePlugin(key);
527
+ return Promise.reject(err);
528
+ });
529
+ }
494
530
  // update a plugin via its github repo, using "data" in arguments for "release", "update" and "init" plugin's methods
495
531
  updateViaGithub(plugin, ...data) {
496
532
  let directory = "";
@@ -543,12 +579,10 @@ class PluginsManager extends node_events_1.default {
543
579
  const key = this.plugins.indexOf(plugin);
544
580
  return plugin.release(...data).then(() => {
545
581
  this.emit("released", plugin, ...data);
546
- return plugin.destroy(...data);
582
+ return this._destroyReleasedPlugin(plugin, key, ...data);
547
583
  }).then(() => {
548
584
  this.emit("destroyed", pluginName, ...data);
549
- if (-1 < key) {
550
- this.plugins.splice(key, 1);
551
- }
585
+ this._splicePlugin(key);
552
586
  return latestTag;
553
587
  });
554
588
  // update plugin
@@ -574,7 +608,7 @@ class PluginsManager extends node_events_1.default {
574
608
  return Promise.resolve().then(() => {
575
609
  this._logger?.("debug", "Updating dependencies...", false, pluginName);
576
610
  this.emit("updating", pluginName, 5, MAX_UPDATE_STEPS, "Updating dependencies...");
577
- return !_plugin.dependencies ? Promise.resolve() : (0, npmUpdate_1.default)(directory);
611
+ return !_plugin.dependencies ? Promise.resolve() : (0, npmInstall_1.default)(directory);
578
612
  }).then(() => {
579
613
  this._logger?.("debug", "Executing plugin update script...", false, pluginName);
580
614
  this.emit("updating", pluginName, 6, MAX_UPDATE_STEPS, "Executing plugin update script...");
@@ -590,6 +624,8 @@ class PluginsManager extends node_events_1.default {
590
624
  this.plugins.push(_plugin);
591
625
  return _plugin;
592
626
  });
627
+ }).catch((err) => {
628
+ return this._rejectReleasedUpdate(pluginName, directory, err);
593
629
  });
594
630
  });
595
631
  }
@@ -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, cmd_1.default)(directory, "npm", [
13
- "install",
14
- ...(isBuildMode ? ["--no-optional"] : ["--omit=dev", "--no-optional"])
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.1",
4
+ "version": "3.8.3",
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",
@@ -43,17 +46,17 @@
43
46
  "/lib/cjs"
44
47
  ],
45
48
  "engines": {
46
- "node": ">=22.23.4"
49
+ "node": ">=24.22.2"
47
50
  },
48
51
 
49
52
  "dependencies": {
50
53
  "check-node-engine": "1.2.1",
51
54
  "check-version-modules": "2.5.2",
52
- "semver": "7.8.5"
55
+ "semver": "7.8.6"
53
56
  },
54
57
  "devDependencies": {
55
58
  "@types/express": "5.0.6",
56
- "@types/node": "26.6.5",
59
+ "@types/node": "26.6.6",
57
60
  "@types/semver": "7.8.0",
58
61
  "@types/socket.io": "3.0.2",
59
62
  "@types/ws": "8.18.2",
@@ -64,11 +67,15 @@
64
67
  "mocha": "12.0.3",
65
68
  "node-pluginsmanager-plugin": "7.4.5",
66
69
  "proxyquire": "2.1.3",
67
- "rimraf": "6.1.3",
70
+ "rimraf": "6.1.4",
68
71
  "socket.io": "4.8.4",
69
72
  "typescript": "6.0.3",
70
73
  "used-deps-analyzer": "0.4.1",
71
- "ws": "8.22.0"
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": [
@@ -1 +0,0 @@
1
- export default function npmUpdate(directory: string): Promise<void>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- // deps
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.default = npmUpdate;
8
- // locals
9
- const cmd_1 = __importDefault(require("../cmd"));
10
- // module
11
- function npmUpdate(directory) {
12
- return (0, cmd_1.default)(directory, "npm", [
13
- "update",
14
- "--omit=dev",
15
- "--no-optional"
16
- ]);
17
- }