@efebia/fastify-auto-import 1.1.0 → 1.1.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.
@@ -41,7 +41,6 @@ const promises_1 = require("node:fs/promises");
41
41
  const node_path_1 = __importDefault(require("node:path"));
42
42
  const node_url_1 = __importStar(require("node:url"));
43
43
  const pkg_up_1 = __importDefault(require("pkg-up"));
44
- const serial_js_1 = require("./serial.js");
45
44
  const getPackageType = async (directory) => {
46
45
  const nearestPackage = await (0, pkg_up_1.default)({ cwd: directory });
47
46
  if (nearestPackage) {
@@ -53,18 +52,15 @@ const getPackageType = async (directory) => {
53
52
  }
54
53
  };
55
54
  const collectRecursivePlugins = async (dir, opts) => {
56
- var _a;
57
55
  const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
58
- const results = [];
59
- for (const entry of entries) {
60
- if (!entry.isDirectory())
61
- continue;
62
- if (opts.excludedDirectories.includes(entry.name))
63
- continue;
56
+ const dirEntries = entries.filter((entry) => entry.isDirectory() && !opts.excludedDirectories.includes(entry.name));
57
+ const perDirResults = await Promise.all(dirEntries.map(async (entry) => {
58
+ var _a;
64
59
  const subDir = node_path_1.default.join(dir, entry.name);
65
60
  const subEntries = await (0, promises_1.readdir)(subDir);
66
61
  const routeFileName = opts.routeFile.replace('.js', '');
67
62
  const hasRouteFile = subEntries.some((f) => f === `${routeFileName}.js` || f === `${routeFileName}.ts`);
63
+ const own = [];
68
64
  if (hasRouteFile) {
69
65
  const osPath = node_path_1.default.join(subDir, opts.packageType === 'module' ? `${routeFileName}.js` : routeFileName);
70
66
  const href = node_url_1.default.pathToFileURL(osPath).href;
@@ -72,12 +68,12 @@ const collectRecursivePlugins = async (dir, opts) => {
72
68
  if (opts.packageType === 'module') {
73
69
  const imported = await Promise.resolve(`${href}`).then(s => __importStar(require(s)));
74
70
  if (imported.default)
75
- results.push(imported.default);
71
+ own.push(imported.default);
76
72
  }
77
73
  else {
78
74
  const imported = require(osPath);
79
75
  if (imported)
80
- results.push(imported);
76
+ own.push(imported);
81
77
  }
82
78
  }
83
79
  catch (e) {
@@ -86,9 +82,9 @@ const collectRecursivePlugins = async (dir, opts) => {
86
82
  }
87
83
  }
88
84
  const nested = await collectRecursivePlugins(subDir, opts);
89
- results.push(...nested);
90
- }
91
- return results;
85
+ return [...own, ...nested];
86
+ }));
87
+ return perDirResults.flat();
92
88
  };
93
89
  const globFiles = async (opts) => {
94
90
  const packageType = await getPackageType(opts.directory);
@@ -105,7 +101,7 @@ const globFiles = async (opts) => {
105
101
  }
106
102
  const routesDirectories = await (0, promises_1.readdir)(pluginsDirectory);
107
103
  const filteredDirectories = routesDirectories.filter(dir => !opts.excludedDirectories.includes(dir));
108
- const importedFiles = await (0, serial_js_1.serial)(filteredDirectories.map((dir) => async () => {
104
+ const importedFiles = await Promise.all(filteredDirectories.map(async (dir) => {
109
105
  var _a;
110
106
  const osPath = node_path_1.default.join(pluginsDirectory, dir, packageType === 'module' ? `${opts.routeFile.replace(".js", "")}.js` : opts.routeFile.replace(".js", ""));
111
107
  const href = node_url_1.default.pathToFileURL(osPath).href;
@@ -2,7 +2,6 @@ import { readFile, readdir } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import url, { fileURLToPath } from "node:url";
4
4
  import pkgUp from "pkg-up";
5
- import { serial } from "./serial.js";
6
5
  const getPackageType = async (directory) => {
7
6
  const nearestPackage = await pkgUp({ cwd: directory });
8
7
  if (nearestPackage) {
@@ -14,18 +13,15 @@ const getPackageType = async (directory) => {
14
13
  }
15
14
  };
16
15
  const collectRecursivePlugins = async (dir, opts) => {
17
- var _a;
18
16
  const entries = await readdir(dir, { withFileTypes: true });
19
- const results = [];
20
- for (const entry of entries) {
21
- if (!entry.isDirectory())
22
- continue;
23
- if (opts.excludedDirectories.includes(entry.name))
24
- continue;
17
+ const dirEntries = entries.filter((entry) => entry.isDirectory() && !opts.excludedDirectories.includes(entry.name));
18
+ const perDirResults = await Promise.all(dirEntries.map(async (entry) => {
19
+ var _a;
25
20
  const subDir = path.join(dir, entry.name);
26
21
  const subEntries = await readdir(subDir);
27
22
  const routeFileName = opts.routeFile.replace('.js', '');
28
23
  const hasRouteFile = subEntries.some((f) => f === `${routeFileName}.js` || f === `${routeFileName}.ts`);
24
+ const own = [];
29
25
  if (hasRouteFile) {
30
26
  const osPath = path.join(subDir, opts.packageType === 'module' ? `${routeFileName}.js` : routeFileName);
31
27
  const href = url.pathToFileURL(osPath).href;
@@ -33,12 +29,12 @@ const collectRecursivePlugins = async (dir, opts) => {
33
29
  if (opts.packageType === 'module') {
34
30
  const imported = await import(href);
35
31
  if (imported.default)
36
- results.push(imported.default);
32
+ own.push(imported.default);
37
33
  }
38
34
  else {
39
35
  const imported = require(osPath);
40
36
  if (imported)
41
- results.push(imported);
37
+ own.push(imported);
42
38
  }
43
39
  }
44
40
  catch (e) {
@@ -47,9 +43,9 @@ const collectRecursivePlugins = async (dir, opts) => {
47
43
  }
48
44
  }
49
45
  const nested = await collectRecursivePlugins(subDir, opts);
50
- results.push(...nested);
51
- }
52
- return results;
46
+ return [...own, ...nested];
47
+ }));
48
+ return perDirResults.flat();
53
49
  };
54
50
  export const globFiles = async (opts) => {
55
51
  const packageType = await getPackageType(opts.directory);
@@ -66,7 +62,7 @@ export const globFiles = async (opts) => {
66
62
  }
67
63
  const routesDirectories = await readdir(pluginsDirectory);
68
64
  const filteredDirectories = routesDirectories.filter(dir => !opts.excludedDirectories.includes(dir));
69
- const importedFiles = await serial(filteredDirectories.map((dir) => async () => {
65
+ const importedFiles = await Promise.all(filteredDirectories.map(async (dir) => {
70
66
  var _a;
71
67
  const osPath = path.join(pluginsDirectory, dir, packageType === 'module' ? `${opts.routeFile.replace(".js", "")}.js` : opts.routeFile.replace(".js", ""));
72
68
  const href = url.pathToFileURL(osPath).href;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@efebia/fastify-auto-import",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "license": "MIT",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",