File tree 1 file changed +23
-20
lines changed
1 file changed +23
-20
lines changed Original file line number Diff line number Diff line change 4
4
*/
5
5
"use strict" ;
6
6
7
- const fs = require ( "graceful-fs" ) ;
7
+ const defaultFs = require ( "graceful-fs" ) ;
8
+
9
+ const fsMethods = [
10
+ "stat" ,
11
+ "statSync" ,
12
+ "readFile" ,
13
+ "readFileSync" ,
14
+ "readlink" ,
15
+ "readlinkSync"
16
+ ] ;
8
17
9
18
class NodeJsInputFileSystem {
19
+ constructor ( fs ) {
20
+ this . fs = fs || defaultFs ;
21
+ for ( const key of fsMethods ) {
22
+ Object . defineProperty ( this , key , {
23
+ configurable : true ,
24
+ writable : true ,
25
+ value : this . fs [ key ] . bind ( this . fs )
26
+ } ) ;
27
+ }
28
+ }
29
+
10
30
readdir ( path , callback ) {
11
- fs . readdir ( path , ( err , files ) => {
31
+ this . fs . readdir ( path , ( err , files ) => {
12
32
callback (
13
33
err ,
14
34
files &&
@@ -20,7 +40,7 @@ class NodeJsInputFileSystem {
20
40
}
21
41
22
42
readdirSync ( path ) {
23
- const files = fs . readdirSync ( path ) ;
43
+ const files = this . fs . readdirSync ( path ) ;
24
44
return (
25
45
files &&
26
46
files . map ( file => {
@@ -30,21 +50,4 @@ class NodeJsInputFileSystem {
30
50
}
31
51
}
32
52
33
- const fsMethods = [
34
- "stat" ,
35
- "statSync" ,
36
- "readFile" ,
37
- "readFileSync" ,
38
- "readlink" ,
39
- "readlinkSync"
40
- ] ;
41
-
42
- for ( const key of fsMethods ) {
43
- Object . defineProperty ( NodeJsInputFileSystem . prototype , key , {
44
- configurable : true ,
45
- writable : true ,
46
- value : fs [ key ] . bind ( fs )
47
- } ) ;
48
- }
49
-
50
53
module . exports = NodeJsInputFileSystem ;
You can’t perform that action at this time.
0 commit comments