File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change
1
+ import CacheFS from "../CacheFS" ;
2
+
3
+ const fs = new CacheFS ( ) ;
4
+
5
+ const treeText = require ( './__fixtures__/tree.txt.js' ) ;
6
+
7
+ describe ( "CacheFS module" , ( ) => {
8
+ it ( "print ∘ parse == id" , ( ) => {
9
+ let parsed = fs . parse ( treeText )
10
+ let text = fs . print ( parsed )
11
+ expect ( text ) . toEqual ( treeText )
12
+ } ) ;
13
+ } ) ;
Original file line number Diff line number Diff line change 1
- .git 777
1
+ module . exports = ` .git 777
2
2
hooks 777
3
3
info 777
4
4
objects 777
@@ -1765,4 +1765,4 @@ package.json 666 3996 1545535032598
1765
1765
renovate.json 666 244 1545535032598
1766
1766
rollup.config.js 666 804 1545535032598
1767
1767
tsconfig.json 666 581 1545535032598
1768
- webpack.config.js 666 1730 1545535032599
1768
+ webpack.config.js 666 1730 1545535032599`
Original file line number Diff line number Diff line change
1
+ var fs = require ( 'fs' )
2
+ var path = require ( 'path' )
3
+ var symLinks = { }
4
+
5
+ module . exports = ( dirpath ) => {
6
+ let str = "" ;
7
+ const printTree = ( root , indent ) => {
8
+ let files = fs . readdirSync ( root )
9
+ for ( let file of files ) {
10
+ let fpath = `${ root } /${ file } `
11
+ let lstat = fs . lstatSync ( fpath )
12
+ // Avoid infinite loops.
13
+ if ( lstat . isSymbolicLink ( ) ) {
14
+ if ( ! symLinks [ lstat . dev ] ) {
15
+ symLinks [ lstat . dev ] = { }
16
+ }
17
+ // Skip this entry if we've seen it before
18
+ if ( symLinks [ lstat . dev ] [ lstat . ino ] ) {
19
+ continue
20
+ }
21
+ symLinks [ lstat . dev ] [ lstat . ino ] = true
22
+ }
23
+ let mode = lstat . mode . toString ( 8 ) ;
24
+ str += `\n${ "\t" . repeat ( indent ) } `
25
+ if ( lstat . isDirectory ( ) ) {
26
+ str += `${ file } \t${ mode } ` ;
27
+ printTree ( fpath , indent + 1 ) ;
28
+ } else {
29
+ str += `${ file } \t${ mode } \t${ lstat . size } \t${ lstat . mtimeMs } ` ;
30
+ }
31
+ }
32
+ } ;
33
+ printTree ( dirpath , 0 ) ;
34
+ return str . trimStart ( ) ;
35
+ }
You can’t perform that action at this time.
0 commit comments