@@ -29,7 +29,7 @@ import {
29
29
30
30
31
31
interface ChokidarWatcher {
32
- new ( options : { } ) : ChokidarWatcher ;
32
+ new ( options : { } ) : ChokidarWatcher ;
33
33
34
34
add ( path : string ) : ChokidarWatcher ;
35
35
on ( type : 'change' , cb : ( path : string ) => void ) : ChokidarWatcher ;
@@ -51,7 +51,7 @@ function loadFSWatcher() {
51
51
} catch ( e ) {
52
52
if ( e . code !== 'MODULE_NOT_FOUND' ) {
53
53
throw new Error ( 'As of angular-devkit version 8.0, the "chokidar" package ' +
54
- 'must be installed in order to use watch() features.' ) ;
54
+ 'must be installed in order to use watch() features.' ) ;
55
55
}
56
56
throw e ;
57
57
}
@@ -92,26 +92,17 @@ export class NodeJsAsyncHost implements virtualFs.Host<fs.Stats> {
92
92
}
93
93
94
94
write ( path : Path , content : virtualFs . FileBuffer ) : Observable < void > {
95
- return new Observable < void > ( obs => {
96
- // Create folders if necessary.
97
- const _createDir = ( path : Path ) => {
98
- if ( fs . existsSync ( getSystemPath ( path ) ) ) {
99
- return ;
100
- }
101
- if ( dirname ( path ) === path ) {
102
- throw new Error ( ) ;
103
- }
104
- _createDir ( dirname ( path ) ) ;
105
- fs . mkdirSync ( getSystemPath ( path ) ) ;
106
- } ;
107
- _createDir ( dirname ( path ) ) ;
108
-
109
- _callFs < void , string , Uint8Array > (
95
+ return _callFs < void , string , fs . MakeDirectoryOptions > (
96
+ fs . mkdir ,
97
+ getSystemPath ( dirname ( path ) ) ,
98
+ { recursive : true } ,
99
+ ) . pipe (
100
+ mergeMap ( ( ) => _callFs < void , string , Uint8Array > (
110
101
fs . writeFile ,
111
102
getSystemPath ( path ) ,
112
103
new Uint8Array ( content ) ,
113
- ) . subscribe ( obs ) ;
114
- } ) ;
104
+ ) ) ,
105
+ ) ;
115
106
}
116
107
117
108
read ( path : Path ) : Observable < virtualFs . FileBuffer > {
@@ -242,57 +233,30 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
242
233
243
234
write ( path : Path , content : virtualFs . FileBuffer ) : Observable < void > {
244
235
return new Observable ( obs => {
245
- // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
246
- // fixed.
247
- try {
248
- // Create folders if necessary.
249
- const _createDir = ( path : Path ) => {
250
- if ( fs . existsSync ( getSystemPath ( path ) ) ) {
251
- return ;
252
- }
253
- _createDir ( dirname ( path ) ) ;
254
- fs . mkdirSync ( getSystemPath ( path ) ) ;
255
- } ;
256
- _createDir ( dirname ( path ) ) ;
257
- fs . writeFileSync ( getSystemPath ( path ) , new Uint8Array ( content ) ) ;
258
-
259
- obs . next ( ) ;
260
- obs . complete ( ) ;
261
- } catch ( err ) {
262
- obs . error ( err ) ;
263
- }
236
+ fs . mkdirSync ( getSystemPath ( dirname ( path ) ) , { recursive : true } ) ;
237
+ fs . writeFileSync ( getSystemPath ( path ) , new Uint8Array ( content ) ) ;
238
+ obs . next ( ) ;
239
+ obs . complete ( ) ;
264
240
} ) ;
265
241
}
266
242
267
243
read ( path : Path ) : Observable < virtualFs . FileBuffer > {
268
244
return new Observable ( obs => {
269
- // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
270
- // fixed.
271
- try {
272
- const buffer = fs . readFileSync ( getSystemPath ( path ) ) ;
245
+ const buffer = fs . readFileSync ( getSystemPath ( path ) ) ;
273
246
274
- obs . next ( new Uint8Array ( buffer ) . buffer as virtualFs . FileBuffer ) ;
275
- obs . complete ( ) ;
276
- } catch ( err ) {
277
- obs . error ( err ) ;
278
- }
247
+ obs . next ( new Uint8Array ( buffer ) . buffer as virtualFs . FileBuffer ) ;
248
+ obs . complete ( ) ;
279
249
} ) ;
280
250
}
281
251
282
252
delete ( path : Path ) : Observable < void > {
283
253
return this . isDirectory ( path ) . pipe (
284
254
concatMap ( isDir => {
285
- // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
286
- // fixed.
287
255
if ( isDir ) {
288
256
const dirPaths = fs . readdirSync ( getSystemPath ( path ) ) ;
289
257
const rmDirComplete = new Observable < void > ( ( obs ) => {
290
- try {
291
- fs . rmdirSync ( getSystemPath ( path ) ) ;
292
- obs . complete ( ) ;
293
- } catch ( e ) {
294
- obs . error ( e ) ;
295
- }
258
+ fs . rmdirSync ( getSystemPath ( path ) ) ;
259
+ obs . complete ( ) ;
296
260
} ) ;
297
261
298
262
return concat (
@@ -314,69 +278,43 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
314
278
315
279
rename ( from : Path , to : Path ) : Observable < void > {
316
280
return new Observable ( obs => {
317
- // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
318
- // fixed.
319
- try {
320
- const toSystemPath = getSystemPath ( to ) ;
321
- if ( ! fs . existsSync ( path . dirname ( toSystemPath ) ) ) {
322
- fs . mkdirSync ( path . dirname ( toSystemPath ) , { recursive : true } ) ;
323
- }
324
- fs . renameSync ( getSystemPath ( from ) , getSystemPath ( to ) ) ;
325
- obs . next ( ) ;
326
- obs . complete ( ) ;
327
- } catch ( err ) {
328
- obs . error ( err ) ;
329
- }
281
+ const toSystemPath = getSystemPath ( to ) ;
282
+ fs . mkdirSync ( path . dirname ( toSystemPath ) , { recursive : true } ) ;
283
+ fs . renameSync ( getSystemPath ( from ) , toSystemPath ) ;
284
+ obs . next ( ) ;
285
+ obs . complete ( ) ;
330
286
} ) ;
331
287
}
332
288
333
289
list ( path : Path ) : Observable < PathFragment [ ] > {
334
290
return new Observable ( obs => {
335
- // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
336
- // fixed.
337
- try {
338
- const names = fs . readdirSync ( getSystemPath ( path ) ) ;
339
- obs . next ( names . map ( name => fragment ( name ) ) ) ;
340
- obs . complete ( ) ;
341
- } catch ( err ) {
342
- obs . error ( err ) ;
343
- }
291
+ const names = fs . readdirSync ( getSystemPath ( path ) ) ;
292
+ obs . next ( names . map ( name => fragment ( name ) ) ) ;
293
+ obs . complete ( ) ;
344
294
} ) ;
345
295
}
346
296
347
297
exists ( path : Path ) : Observable < boolean > {
348
298
return new Observable ( obs => {
349
- // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
350
- // fixed.
351
- try {
352
- obs . next ( fs . existsSync ( getSystemPath ( path ) ) ) ;
353
- obs . complete ( ) ;
354
- } catch ( err ) {
355
- obs . error ( err ) ;
356
- }
299
+ obs . next ( fs . existsSync ( getSystemPath ( path ) ) ) ;
300
+ obs . complete ( ) ;
357
301
} ) ;
358
302
}
359
303
360
304
isDirectory ( path : Path ) : Observable < boolean > {
361
305
// tslint:disable-next-line:no-non-null-assertion
362
- return this . stat ( path ) ! . pipe ( map ( stat => stat . isDirectory ( ) ) ) ;
306
+ return this . stat ( path ) ! . pipe ( map ( stat => stat . isDirectory ( ) ) ) ;
363
307
}
364
308
isFile ( path : Path ) : Observable < boolean > {
365
309
// tslint:disable-next-line:no-non-null-assertion
366
- return this . stat ( path ) ! . pipe ( map ( stat => stat . isFile ( ) ) ) ;
310
+ return this . stat ( path ) ! . pipe ( map ( stat => stat . isFile ( ) ) ) ;
367
311
}
368
312
369
313
// Some hosts may not support stat.
370
314
stat ( path : Path ) : Observable < virtualFs . Stats < fs . Stats > > {
371
315
return new Observable ( obs => {
372
- // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
373
- // fixed.
374
- try {
375
- obs . next ( fs . statSync ( getSystemPath ( path ) ) ) ;
376
- obs . complete ( ) ;
377
- } catch ( err ) {
378
- obs . error ( err ) ;
379
- }
316
+ obs . next ( fs . statSync ( getSystemPath ( path ) ) ) ;
317
+ obs . complete ( ) ;
380
318
} ) ;
381
319
}
382
320
0 commit comments