Skip to content

Commit 27e54fd

Browse files
authored
Merge pull request #9 from Karibash/feature/glob-path
Make it possible to specify a glob in the path
2 parents 9ae0758 + e5c088e commit 27e54fd

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

.changeset/small-pandas-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nestjs-modular/inject": minor
3+
---
4+
5+
Make it possible to specify a glob in the path

packages/inject/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
},
3232
"homepage": "https://github.com/Karibash/nestjs-modular/tree/main/packages/inject",
3333
"dependencies": {
34-
"@babel/runtime": "^7.18.3"
34+
"@babel/runtime": "^7.18.3",
35+
"glob": "^8.0.3"
3536
},
3637
"devDependencies": {
3738
"@nestjs/common": "^8.4.5",
39+
"@types/glob": "^7.2.0",
3840
"typescript": "^4.7.2"
3941
},
4042
"peerDependencies": {

packages/inject/src/index.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { DynamicModule, Module, ModuleMetadata } from '@nestjs/common';
2-
import { readdir } from 'fs/promises';
2+
import { stat } from 'fs/promises';
33
import { parse } from 'path';
4+
import { promisify } from 'util';
5+
import glob from 'glob';
6+
7+
const asyncGlob = promisify(glob);
48

59
const getFilePaths = async (path: string): Promise<string[]> => {
6-
const dirents = await readdir(path, { withFileTypes: true });
7-
const files = await Promise.all(dirents.map(dirent => {
8-
const result = `${path}/${dirent.name}`;
9-
return dirent.isDirectory() ? getFilePaths(result) : result;
10-
}));
11-
return files.flat();
10+
if (glob.hasMagic(path)) return await asyncGlob(path);
11+
12+
const stats = await stat(path);
13+
if (stats.isDirectory()) {
14+
return await asyncGlob(`${path}/**/*`);
15+
}
16+
17+
throw Error('The path must be a directory');
1218
};
1319

1420
const someTests = (value: string, terms: Array<string | RegExp>, _default: boolean): boolean => {

yarn.lock

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,14 @@
20112011
"@types/qs" "*"
20122012
"@types/serve-static" "*"
20132013

2014+
"@types/glob@^7.2.0":
2015+
version "7.2.0"
2016+
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
2017+
integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==
2018+
dependencies:
2019+
"@types/minimatch" "*"
2020+
"@types/node" "*"
2021+
20142022
"@types/graceful-fs@^4.1.3":
20152023
version "4.1.5"
20162024
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"
@@ -2059,6 +2067,11 @@
20592067
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
20602068
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==
20612069

2070+
"@types/minimatch@*":
2071+
version "3.0.5"
2072+
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
2073+
integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==
2074+
20622075
"@types/minimist@^1.2.0":
20632076
version "1.2.2"
20642077
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
@@ -2774,6 +2787,13 @@ brace-expansion@^1.1.7:
27742787
balanced-match "^1.0.0"
27752788
concat-map "0.0.1"
27762789

2790+
brace-expansion@^2.0.1:
2791+
version "2.0.1"
2792+
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"
2793+
integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==
2794+
dependencies:
2795+
balanced-match "^1.0.0"
2796+
27772797
braces@^3.0.2, braces@~3.0.2:
27782798
version "3.0.2"
27792799
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
@@ -4170,6 +4190,17 @@ glob@^7.0.0, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
41704190
once "^1.3.0"
41714191
path-is-absolute "^1.0.0"
41724192

4193+
glob@^8.0.3:
4194+
version "8.0.3"
4195+
resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e"
4196+
integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==
4197+
dependencies:
4198+
fs.realpath "^1.0.0"
4199+
inflight "^1.0.4"
4200+
inherits "2"
4201+
minimatch "^5.0.1"
4202+
once "^1.3.0"
4203+
41734204
globals@^11.1.0:
41744205
version "11.12.0"
41754206
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
@@ -5466,6 +5497,13 @@ minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2:
54665497
dependencies:
54675498
brace-expansion "^1.1.7"
54685499

5500+
minimatch@^5.0.1:
5501+
version "5.1.0"
5502+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.0.tgz#1717b464f4971b144f6aabe8f2d0b8e4511e09c7"
5503+
integrity sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==
5504+
dependencies:
5505+
brace-expansion "^2.0.1"
5506+
54695507
[email protected], minimist-options@^4.0.2:
54705508
version "4.1.0"
54715509
resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-4.1.0.tgz#c0655713c53a8a2ebd77ffa247d342c40f010619"

0 commit comments

Comments
 (0)