node-pluginsmanager 3.3.0 → 3.4.1

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.
@@ -19,6 +19,8 @@ const checkFunction_1 = __importDefault(require("./checkers/checkFunction"));
19
19
  const checkNonEmptyArray_1 = __importDefault(require("./checkers/checkNonEmptyArray"));
20
20
  const checkNonEmptyString_1 = __importDefault(require("./checkers/checkNonEmptyString"));
21
21
  const checkOrchestrator_1 = __importDefault(require("./checkers/checkOrchestrator"));
22
+ const isDirectory_1 = __importDefault(require("./utils/isDirectory"));
23
+ const isFile_1 = __importDefault(require("./utils/isFile"));
22
24
  const createPluginByDirectory_1 = __importDefault(require("./createPluginByDirectory"));
23
25
  const loadSortedPlugins_1 = __importDefault(require("./loadSortedPlugins"));
24
26
  const initSortedPlugins_1 = __importDefault(require("./initSortedPlugins"));
@@ -280,8 +282,53 @@ class PluginsManager extends node_events_1.default {
280
282
  });
281
283
  });
282
284
  }).then((directory) => {
283
- return (0, gitInstall_1.default)(directory, user, repo).then(() => {
284
- // 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
+ if (!isPluginADirectory) {
292
+ throw new Error("\"" + repo + "\" plugin directory is not created");
293
+ }
294
+ });
295
+ // work around package.json
296
+ }).then(() => {
297
+ const packageFile = (0, node_path_1.join)(directory, "package.json");
298
+ // check if plugin has a valid package.json
299
+ return (0, isFile_1.default)(packageFile).then((isPluginAPackageFile) => {
300
+ if (!isPluginAPackageFile) {
301
+ throw new Error("\"" + repo + "\" plugin has no valid package.json");
302
+ }
303
+ // read package.json and parse it
304
+ }).then(() => {
305
+ return (0, promises_1.readFile)(packageFile, "utf-8").then((content) => {
306
+ return JSON.parse(content);
307
+ });
308
+ }).then((packageData) => {
309
+ const entryPoint = (0, node_path_1.join)(directory, packageData.main);
310
+ // check if the plugin has a valid entry point
311
+ return (0, isFile_1.default)(entryPoint).then((hasPluginEntryPoint) => {
312
+ if (!hasPluginEntryPoint) {
313
+ throw new Error("\"" + repo + "\" plugin has no valid entry point");
314
+ }
315
+ // check if the plugin is builded
316
+ // @TODO : "build installed plugin" feature to be implemented
317
+ }).then(() => {
318
+ return (0, isFile_1.default)(entryPoint).then((isEntryPointAFile) => {
319
+ if (!isEntryPointAFile) {
320
+ throw new Error("\"" + repo + "\" plugin entry point is not builded");
321
+ }
322
+ });
323
+ }).then(() => {
324
+ if ("object" !== typeof packageData.dependencies || null === packageData.dependencies || 0 >= Object.keys(packageData.dependencies).length) {
325
+ return Promise.resolve();
326
+ }
327
+ return (0, npmInstall_1.default)(directory);
328
+ });
329
+ });
330
+ // create plugin
331
+ }).then(() => {
285
332
  return (0, createPluginByDirectory_1.default)(directory, this.externalResourcesDirectory, this._logger, ...data);
286
333
  // check plugin modules versions
287
334
  }).then((plugin) => {
@@ -289,17 +336,19 @@ class PluginsManager extends node_events_1.default {
289
336
  return Promise.resolve(plugin);
290
337
  });
291
338
  }).then((plugin) => {
339
+ // execute plugin install script
292
340
  return Promise.resolve().then(() => {
293
- return !plugin.dependencies ? Promise.resolve() : (0, npmInstall_1.default)(directory);
294
- }).then(() => {
295
- return plugin.install(...data);
296
- // execute init script
341
+ return plugin.install(...data).then(() => {
342
+ this.emit("installed", plugin, ...data);
343
+ });
344
+ // execute init plugin script
297
345
  }).then(() => {
298
- this.emit("installed", plugin, ...data);
299
- return plugin.init(...data);
346
+ return plugin.init(...data).then(() => {
347
+ this.emit("initialized", plugin, ...data);
348
+ this.plugins.push(plugin);
349
+ });
350
+ // return installed plugin
300
351
  }).then(() => {
301
- this.emit("initialized", plugin, ...data);
302
- this.plugins.push(plugin);
303
352
  return Promise.resolve(plugin);
304
353
  }).catch((err) => {
305
354
  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.3.0",
4
+ "version": "3.4.1",
5
5
  "description": "A plugins manager.",
6
6
 
7
7
  "type": "commonjs",
@@ -47,25 +47,25 @@
47
47
  },
48
48
 
49
49
  "dependencies": {
50
- "check-node-engine": "1.0.0",
50
+ "check-node-engine": "1.1.0",
51
51
  "check-version-modules": "2.5.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/express": "5.0.6",
55
- "@types/node": "25.9.1",
55
+ "@types/node": "25.9.2",
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
61
  "mocha": "11.7.6",
62
- "node-pluginsmanager-plugin": "7.2.0",
62
+ "node-pluginsmanager-plugin": "7.3.2",
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",
68
+ "used-deps-analyzer": "0.4.0",
69
69
  "ws": "8.21.0"
70
70
  },
71
71