@@ -18,22 +18,12 @@ import fs, {
18
18
readdirSync ,
19
19
renameSync ,
20
20
statSync ,
21
- unlinkSync ,
22
21
writeFileSync ,
23
22
} from 'fs' ;
24
23
import { dirname as pathDirname } from 'path' ;
25
- import { Observable , concat , from as observableFrom , of , throwError } from 'rxjs' ;
26
- import { concatMap , map , mergeMap , publish , refCount } from 'rxjs/operators' ;
27
- import {
28
- Path ,
29
- PathFragment ,
30
- dirname ,
31
- fragment ,
32
- getSystemPath ,
33
- join ,
34
- normalize ,
35
- virtualFs ,
36
- } from '../src' ;
24
+ import { Observable , from as observableFrom } from 'rxjs' ;
25
+ import { map , mergeMap , publish , refCount } from 'rxjs/operators' ;
26
+ import { Path , PathFragment , dirname , fragment , getSystemPath , normalize , virtualFs } from '../src' ;
37
27
38
28
async function exists ( path : PathLike ) : Promise < boolean > {
39
29
try {
@@ -88,31 +78,8 @@ export class NodeJsAsyncHost implements virtualFs.Host<Stats> {
88
78
}
89
79
90
80
delete ( path : Path ) : Observable < void > {
91
- return this . isDirectory ( path ) . pipe (
92
- mergeMap ( async ( isDirectory ) => {
93
- if ( isDirectory ) {
94
- // The below should be removed and replaced with just `rm` when support for Node.Js 12 is removed.
95
- const { rm, rmdir } = fsPromises as typeof fsPromises & {
96
- rm ?: (
97
- path : fs . PathLike ,
98
- options ?: {
99
- force ?: boolean ;
100
- maxRetries ?: number ;
101
- recursive ?: boolean ;
102
- retryDelay ?: number ;
103
- } ,
104
- ) => Promise < void > ;
105
- } ;
106
-
107
- if ( rm ) {
108
- await rm ( getSystemPath ( path ) , { force : true , recursive : true , maxRetries : 3 } ) ;
109
- } else {
110
- await rmdir ( getSystemPath ( path ) , { recursive : true , maxRetries : 3 } ) ;
111
- }
112
- } else {
113
- await fsPromises . unlink ( getSystemPath ( path ) ) ;
114
- }
115
- } ) ,
81
+ return observableFrom (
82
+ fsPromises . rm ( getSystemPath ( path ) , { force : true , recursive : true , maxRetries : 3 } ) ,
116
83
) ;
117
84
}
118
85
@@ -208,45 +175,11 @@ export class NodeJsSyncHost implements virtualFs.Host<Stats> {
208
175
}
209
176
210
177
delete ( path : Path ) : Observable < void > {
211
- return this . isDirectory ( path ) . pipe (
212
- concatMap ( ( isDir ) => {
213
- if ( isDir ) {
214
- const dirPaths = readdirSync ( getSystemPath ( path ) ) ;
215
- const rmDirComplete = new Observable < void > ( ( obs ) => {
216
- // The below should be removed and replaced with just `rmSync` when support for Node.Js 12 is removed.
217
- const { rmSync, rmdirSync } = fs as typeof fs & {
218
- rmSync ?: (
219
- path : fs . PathLike ,
220
- options ?: {
221
- force ?: boolean ;
222
- maxRetries ?: number ;
223
- recursive ?: boolean ;
224
- retryDelay ?: number ;
225
- } ,
226
- ) => void ;
227
- } ;
228
-
229
- if ( rmSync ) {
230
- rmSync ( getSystemPath ( path ) , { force : true , recursive : true , maxRetries : 3 } ) ;
231
- } else {
232
- rmdirSync ( getSystemPath ( path ) , { recursive : true , maxRetries : 3 } ) ;
233
- }
234
-
235
- obs . complete ( ) ;
236
- } ) ;
178
+ return new Observable < void > ( ( obs ) => {
179
+ fs . rmSync ( getSystemPath ( path ) , { force : true , recursive : true , maxRetries : 3 } ) ;
237
180
238
- return concat ( ...dirPaths . map ( ( name ) => this . delete ( join ( path , name ) ) ) , rmDirComplete ) ;
239
- } else {
240
- try {
241
- unlinkSync ( getSystemPath ( path ) ) ;
242
- } catch ( err ) {
243
- return throwError ( err ) ;
244
- }
245
-
246
- return of ( undefined ) ;
247
- }
248
- } ) ,
249
- ) ;
181
+ obs . complete ( ) ;
182
+ } ) ;
250
183
}
251
184
252
185
rename ( from : Path , to : Path ) : Observable < void > {
0 commit comments