node-pluginsmanager 3.2.0 → 3.4.0

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.
@@ -11,6 +11,7 @@ const node_os_1 = require("node:os");
11
11
  const promises_1 = require("node:fs/promises");
12
12
  // externals
13
13
  const check_version_modules_1 = __importDefault(require("check-version-modules"));
14
+ const check_node_engine_1 = __importDefault(require("check-node-engine"));
14
15
  // locals
15
16
  const rmdirp_1 = __importDefault(require("./utils/rmdirp"));
16
17
  const checkAbsoluteDirectory_1 = __importDefault(require("./checkers/checkAbsoluteDirectory"));
@@ -18,6 +19,8 @@ const checkFunction_1 = __importDefault(require("./checkers/checkFunction"));
18
19
  const checkNonEmptyArray_1 = __importDefault(require("./checkers/checkNonEmptyArray"));
19
20
  const checkNonEmptyString_1 = __importDefault(require("./checkers/checkNonEmptyString"));
20
21
  const checkOrchestrator_1 = __importDefault(require("./checkers/checkOrchestrator"));
22
+ const isDirectory_1 = __importDefault(require("./utils/isDirectory"));
23
+ const isFile_1 = __importDefault(require("./utils/isFile"));
21
24
  const createPluginByDirectory_1 = __importDefault(require("./createPluginByDirectory"));
22
25
  const loadSortedPlugins_1 = __importDefault(require("./loadSortedPlugins"));
23
26
  const initSortedPlugins_1 = __importDefault(require("./initSortedPlugins"));
@@ -102,11 +105,16 @@ class PluginsManager extends node_events_1.default {
102
105
  return (0, checkAbsoluteDirectory_1.default)("checkModules/directory", this.directory).then(() => {
103
106
  return (0, checkOrchestrator_1.default)("checkModules/plugin", plugin);
104
107
  }).then(() => {
105
- return (0, check_version_modules_1.default)((0, node_path_1.join)(this.directory, plugin.name, "package.json"), {
106
- "failAtMajor": true,
107
- "failAtMinor": true,
108
- "failAtPatch": false,
109
- "dev": false
108
+ const packageFile = (0, node_path_1.join)(this.directory, plugin.name, "package.json");
109
+ // start with node engine checker to compare minimal node version used
110
+ return (0, check_node_engine_1.default)(packageFile).then(() => {
111
+ // then check used packages versions
112
+ return (0, check_version_modules_1.default)(packageFile, {
113
+ "failAtMajor": false, // can break and be a huge source of dev
114
+ "failAtMinor": true, // mandatory, most important updates
115
+ "failAtPatch": false, // not critical
116
+ "dev": false
117
+ });
110
118
  }).then((analyze) => {
111
119
  return analyze.result ? Promise.resolve() : Promise.reject(new Error("\"" + plugin.name + "\" plugin has obsoletes modules"));
112
120
  });
@@ -274,8 +282,30 @@ class PluginsManager extends node_events_1.default {
274
282
  });
275
283
  });
276
284
  }).then((directory) => {
277
- return (0, gitInstall_1.default)(directory, user, repo).then(() => {
278
- // install dependencies & execute install script
285
+ // download plugin
286
+ return Promise.resolve().then(() => {
287
+ return (0, gitInstall_1.default)(directory, user, repo);
288
+ // check if plugin directory is created
289
+ }).then(() => {
290
+ return (0, isDirectory_1.default)(directory).then((isPluginADirectory) => {
291
+ return !isPluginADirectory ? Promise.reject(new Error("\"" + repo + "\" plugin directory is not created")) : Promise.resolve();
292
+ });
293
+ // check if plugin has a valid package.json
294
+ }).then(() => {
295
+ return (0, isFile_1.default)((0, node_path_1.join)(directory, "package.json")).then((isPluginAPackageFile) => {
296
+ return !isPluginAPackageFile ? Promise.reject(new Error("\"" + repo + "\" plugin has no valid package.json")) : Promise.resolve();
297
+ });
298
+ // install dependencies if needed
299
+ }).then(() => {
300
+ return (0, promises_1.readFile)((0, node_path_1.join)(directory, "package.json"), "utf-8").then((content) => {
301
+ return JSON.parse(content);
302
+ }).then(({ dependencies }) => {
303
+ return "object" !== typeof dependencies || null === dependencies || 0 >= Object.keys(dependencies).length
304
+ ? Promise.resolve()
305
+ : (0, npmInstall_1.default)(directory);
306
+ });
307
+ // create plugin
308
+ }).then(() => {
279
309
  return (0, createPluginByDirectory_1.default)(directory, this.externalResourcesDirectory, this._logger, ...data);
280
310
  // check plugin modules versions
281
311
  }).then((plugin) => {
@@ -283,17 +313,19 @@ class PluginsManager extends node_events_1.default {
283
313
  return Promise.resolve(plugin);
284
314
  });
285
315
  }).then((plugin) => {
316
+ // execute plugin install script
286
317
  return Promise.resolve().then(() => {
287
- return !plugin.dependencies ? Promise.resolve() : (0, npmInstall_1.default)(directory);
288
- }).then(() => {
289
- return plugin.install(...data);
290
- // execute init script
318
+ return plugin.install(...data).then(() => {
319
+ this.emit("installed", plugin, ...data);
320
+ });
321
+ // execute init plugin script
291
322
  }).then(() => {
292
- this.emit("installed", plugin, ...data);
293
- return plugin.init(...data);
323
+ return plugin.init(...data).then(() => {
324
+ this.emit("initialized", plugin, ...data);
325
+ this.plugins.push(plugin);
326
+ });
327
+ // return installed plugin
294
328
  }).then(() => {
295
- this.emit("initialized", plugin, ...data);
296
- this.plugins.push(plugin);
297
329
  return Promise.resolve(plugin);
298
330
  }).catch((err) => {
299
331
  return this.uninstall(plugin, ...data).then(() => {
@@ -5,18 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.default = checkDirectory;
8
- // natives
9
- const node_fs_1 = require("node:fs");
10
8
  // locals
11
9
  const checkNonEmptyString_1 = __importDefault(require("./checkNonEmptyString"));
10
+ const isDirectory_1 = __importDefault(require("../utils/isDirectory"));
12
11
  // module
13
12
  function checkDirectory(dataName, directory) {
14
13
  return (0, checkNonEmptyString_1.default)(dataName, directory).then(() => {
15
- return new Promise((resolve) => {
16
- (0, node_fs_1.lstat)(directory, (err, stats) => {
17
- return resolve(Boolean(!err && stats.isDirectory()));
18
- });
19
- });
14
+ return (0, isDirectory_1.default)(directory);
20
15
  }).then((exists) => {
21
16
  return exists ? Promise.resolve() : Promise.reject(new Error("\"" + dataName + "\" (" + directory + ") is not a valid directory"));
22
17
  });
@@ -14,7 +14,7 @@ function isDirectory(directory) {
14
14
  reject(new TypeError("\"directory\" argument is not a string"));
15
15
  }
16
16
  else if ("" === directory.trim()) {
17
- reject(new Error("\"directory\" argument is empty"));
17
+ reject(new RangeError("\"directory\" argument is empty"));
18
18
  }
19
19
  else {
20
20
  (0, node_fs_1.lstat)(directory, (err, stats) => {
@@ -0,0 +1 @@
1
+ export default function isFile(directory: string): Promise<boolean>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // deps
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = isFile;
5
+ // natives
6
+ const node_fs_1 = require("node:fs");
7
+ // module
8
+ function isFile(directory) {
9
+ return new Promise((resolve, reject) => {
10
+ if ("undefined" === typeof directory) {
11
+ reject(new ReferenceError("missing \"directory\" argument"));
12
+ }
13
+ else if ("string" !== typeof directory) {
14
+ reject(new TypeError("\"directory\" argument is not a string"));
15
+ }
16
+ else if ("" === directory.trim()) {
17
+ reject(new RangeError("\"directory\" argument is empty"));
18
+ }
19
+ else {
20
+ (0, node_fs_1.lstat)(directory, (err, stats) => {
21
+ return resolve(Boolean(!err && stats.isFile()));
22
+ });
23
+ }
24
+ });
25
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "node-pluginsmanager",
4
- "version": "3.2.0",
4
+ "version": "3.4.0",
5
5
  "description": "A plugins manager.",
6
6
 
7
7
  "type": "commonjs",
@@ -19,8 +19,6 @@
19
19
 
20
20
  "scripts": {
21
21
 
22
- "prepare": "npx husky || true",
23
-
24
22
  "lint-back": "npx eslint --config .eslintrc-back.js --ext .ts,.cts,.mts ./lib/src/**/*",
25
23
  "lint-tests": "npx eslint --config .eslintrc-tests.js --ext .js,.cjs,.mjs ./test/**/*.js",
26
24
  "lint": "npm run lint-back && npm run lint-tests",
@@ -31,12 +29,13 @@
31
29
  "build-back": "npm run clean-back && npx tsc --project ./tsconfig.json",
32
30
  "build": "npm run build-back",
33
31
 
32
+ "check-node-engine": "npx check-node-engine",
34
33
  "check-requires": "npx used-deps-analyzer ./package.json ./lib/src --no-dev",
35
34
  "check-updates": "npx check-version-modules --no-fail-at-major --fail-at-minor --fail-at-patch",
36
35
  "unit-tests": "npx mocha",
37
36
  "unit-tests-local": "npx nyc --reporter=html --reporter=text mocha",
38
37
 
39
- "tests": "npm run lint && npm run check-requires && npm run check-updates && npm run build && npm run unit-tests-local"
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-local"
40
39
 
41
40
  },
42
41
 
@@ -44,36 +43,30 @@
44
43
  "/lib/cjs"
45
44
  ],
46
45
  "engines": {
47
- "node": ">=22.22.0"
46
+ "node": ">=22.22.3"
48
47
  },
49
48
 
50
49
  "dependencies": {
51
- "check-version-modules": "2.3.0"
50
+ "check-node-engine": "1.1.0",
51
+ "check-version-modules": "2.5.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/express": "5.0.6",
55
- "@types/node": "25.6.0",
55
+ "@types/node": "25.9.1",
56
56
  "@types/socket.io": "3.0.2",
57
57
  "@types/ws": "8.18.1",
58
58
  "eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
59
59
  "express": "5.2.1",
60
60
  "husky": "9.1.7",
61
- "mocha": "11.7.5",
62
- "node-pluginsmanager-plugin": "7.1.0",
61
+ "mocha": "11.7.6",
62
+ "node-pluginsmanager-plugin": "7.3.0",
63
63
  "nyc": "18.0.0",
64
64
  "proxyquire": "2.1.3",
65
65
  "rimraf": "6.1.3",
66
66
  "socket.io": "4.8.3",
67
67
  "typescript": "5.9.3",
68
- "used-deps-analyzer": "0.3.0",
69
- "ws": "8.20.0"
70
- },
71
-
72
- "husky": {
73
- "hooks": {
74
- "pre-commit": "npm run lint",
75
- "pre-push": "npm run build && npm run unit-tests-local"
76
- }
68
+ "used-deps-analyzer": "0.4.0",
69
+ "ws": "8.21.0"
77
70
  },
78
71
 
79
72
  "keywords": [