@@ -38,11 +38,13 @@ export interface SimpleMemoryHostStats {
38
38
}
39
39
40
40
export class SimpleMemoryHost implements Host < { } > {
41
- private _cache = new Map < Path , Stats < SimpleMemoryHostStats > > ( ) ;
41
+ protected readonly _cache = new Map < Path , Stats < SimpleMemoryHostStats > > ( ) ;
42
42
private _watchers = new Map < Path , [ HostWatchOptions , Subject < HostWatchEvent > ] [ ] > ( ) ;
43
43
44
44
protected _newDirStats ( ) {
45
45
return {
46
+ inspect ( ) { return '<Directory>' ; } ,
47
+
46
48
isFile ( ) { return false ; } ,
47
49
isDirectory ( ) { return true ; } ,
48
50
size : 0 ,
@@ -57,6 +59,8 @@ export class SimpleMemoryHost implements Host<{}> {
57
59
}
58
60
protected _newFileStats ( content : FileBuffer , oldStats ?: Stats < SimpleMemoryHostStats > ) {
59
61
return {
62
+ inspect ( ) { return `<File size(${ content . byteLength } )>` ; } ,
63
+
60
64
isFile ( ) { return true ; } ,
61
65
isDirectory ( ) { return false ; } ,
62
66
size : content . byteLength ,
@@ -158,7 +162,7 @@ export class SimpleMemoryHost implements Host<{}> {
158
162
this . _cache . set ( path , stats ) ;
159
163
this . _updateWatchers ( path , old ? HostWatchEventType . Changed : HostWatchEventType . Created ) ;
160
164
}
161
- _read ( path : Path ) : FileBuffer {
165
+ protected _read ( path : Path ) : FileBuffer {
162
166
path = this . _toAbsolute ( path ) ;
163
167
const maybeStats = this . _cache . get ( path ) ;
164
168
if ( ! maybeStats ) {
@@ -171,7 +175,7 @@ export class SimpleMemoryHost implements Host<{}> {
171
175
return maybeStats . content ;
172
176
}
173
177
}
174
- _delete ( path : Path ) : void {
178
+ protected _delete ( path : Path ) : void {
175
179
path = this . _toAbsolute ( path ) ;
176
180
if ( this . _isDirectory ( path ) ) {
177
181
for ( const [ cachePath , _ ] of this . _cache . entries ( ) ) {
@@ -184,7 +188,7 @@ export class SimpleMemoryHost implements Host<{}> {
184
188
}
185
189
this . _updateWatchers ( path , HostWatchEventType . Deleted ) ;
186
190
}
187
- _rename ( from : Path , to : Path ) : void {
191
+ protected _rename ( from : Path , to : Path ) : void {
188
192
from = this . _toAbsolute ( from ) ;
189
193
to = this . _toAbsolute ( to ) ;
190
194
if ( ! this . _cache . has ( from ) ) {
@@ -214,7 +218,7 @@ export class SimpleMemoryHost implements Host<{}> {
214
218
this . _updateWatchers ( from , HostWatchEventType . Renamed ) ;
215
219
}
216
220
217
- _list ( path : Path ) : PathFragment [ ] {
221
+ protected _list ( path : Path ) : PathFragment [ ] {
218
222
path = this . _toAbsolute ( path ) ;
219
223
if ( this . _isFile ( path ) ) {
220
224
throw new PathIsFileException ( path ) ;
@@ -239,21 +243,21 @@ export class SimpleMemoryHost implements Host<{}> {
239
243
return [ ...result ] ;
240
244
}
241
245
242
- _exists ( path : Path ) : boolean {
246
+ protected _exists ( path : Path ) : boolean {
243
247
return ! ! this . _cache . get ( this . _toAbsolute ( path ) ) ;
244
248
}
245
- _isDirectory ( path : Path ) : boolean {
249
+ protected _isDirectory ( path : Path ) : boolean {
246
250
const maybeStats = this . _cache . get ( this . _toAbsolute ( path ) ) ;
247
251
248
252
return maybeStats ? maybeStats . isDirectory ( ) : false ;
249
253
}
250
- _isFile ( path : Path ) : boolean {
254
+ protected _isFile ( path : Path ) : boolean {
251
255
const maybeStats = this . _cache . get ( this . _toAbsolute ( path ) ) ;
252
256
253
257
return maybeStats ? maybeStats . isFile ( ) : false ;
254
258
}
255
259
256
- _stat ( path : Path ) : Stats < SimpleMemoryHostStats > {
260
+ protected _stat ( path : Path ) : Stats < SimpleMemoryHostStats > {
257
261
const maybeStats = this . _cache . get ( this . _toAbsolute ( path ) ) ;
258
262
259
263
if ( ! maybeStats ) {
@@ -263,6 +267,21 @@ export class SimpleMemoryHost implements Host<{}> {
263
267
}
264
268
}
265
269
270
+ protected _watch ( path : Path , options ?: HostWatchOptions ) : Observable < HostWatchEvent > {
271
+ path = this . _toAbsolute ( path ) ;
272
+
273
+ const subject = new Subject < HostWatchEvent > ( ) ;
274
+ let maybeWatcherArray = this . _watchers . get ( path ) ;
275
+ if ( ! maybeWatcherArray ) {
276
+ maybeWatcherArray = [ ] ;
277
+ this . _watchers . set ( path , maybeWatcherArray ) ;
278
+ }
279
+
280
+ maybeWatcherArray . push ( [ options || { } , subject ] ) ;
281
+
282
+ return subject . asObservable ( ) ;
283
+ }
284
+
266
285
write ( path : Path , content : FileBuffer ) : Observable < void > {
267
286
return new Observable < void > ( obs => {
268
287
this . _write ( path , content ) ;
@@ -332,17 +351,6 @@ export class SimpleMemoryHost implements Host<{}> {
332
351
}
333
352
334
353
watch ( path : Path , options ?: HostWatchOptions ) : Observable < HostWatchEvent > | null {
335
- path = this . _toAbsolute ( path ) ;
336
-
337
- const subject = new Subject < HostWatchEvent > ( ) ;
338
- let maybeWatcherArray = this . _watchers . get ( path ) ;
339
- if ( ! maybeWatcherArray ) {
340
- maybeWatcherArray = [ ] ;
341
- this . _watchers . set ( path , maybeWatcherArray ) ;
342
- }
343
-
344
- maybeWatcherArray . push ( [ options || { } , subject ] ) ;
345
-
346
- return subject . asObservable ( ) ;
354
+ return this . _watch ( path , options ) ;
347
355
}
348
356
}
0 commit comments