@@ -393,21 +393,7 @@ interface Array<T> {}`
393
393
if ( isString ( fileOrDirectory . content ) ) {
394
394
// Update file
395
395
if ( currentEntry . content !== fileOrDirectory . content ) {
396
- if ( options && options . invokeFileDeleteCreateAsPartInsteadOfChange ) {
397
- this . removeFileOrFolder ( currentEntry , returnFalse ) ;
398
- this . ensureFileOrFolder ( fileOrDirectory ) ;
399
- }
400
- else {
401
- currentEntry . content = fileOrDirectory . content ;
402
- currentEntry . modifiedTime = this . now ( ) ;
403
- this . fs . get ( getDirectoryPath ( currentEntry . path ) ) . modifiedTime = this . now ( ) ;
404
- if ( options && options . invokeDirectoryWatcherInsteadOfFileChanged ) {
405
- this . invokeDirectoryWatcher ( getDirectoryPath ( currentEntry . fullPath ) , currentEntry . fullPath ) ;
406
- }
407
- else {
408
- this . invokeFileWatcher ( currentEntry . fullPath , FileWatcherEventKind . Changed ) ;
409
- }
410
- }
396
+ this . modifyFile ( fileOrDirectory . path , fileOrDirectory . content , options ) ;
411
397
}
412
398
}
413
399
else {
@@ -446,6 +432,30 @@ interface Array<T> {}`
446
432
}
447
433
}
448
434
435
+ modifyFile ( filePath : string , content : string , options ?: Partial < ReloadWatchInvokeOptions > ) {
436
+ const path = this . toFullPath ( filePath ) ;
437
+ const currentEntry = this . fs . get ( path ) ;
438
+ if ( ! currentEntry || ! isFile ( currentEntry ) ) {
439
+ throw new Error ( `file not present: ${ filePath } ` ) ;
440
+ }
441
+
442
+ if ( options && options . invokeFileDeleteCreateAsPartInsteadOfChange ) {
443
+ this . removeFileOrFolder ( currentEntry , returnFalse ) ;
444
+ this . ensureFileOrFolder ( { path : filePath , content } ) ;
445
+ }
446
+ else {
447
+ currentEntry . content = content ;
448
+ currentEntry . modifiedTime = this . now ( ) ;
449
+ this . fs . get ( getDirectoryPath ( currentEntry . path ) ) . modifiedTime = this . now ( ) ;
450
+ if ( options && options . invokeDirectoryWatcherInsteadOfFileChanged ) {
451
+ this . invokeDirectoryWatcher ( getDirectoryPath ( currentEntry . fullPath ) , currentEntry . fullPath ) ;
452
+ }
453
+ else {
454
+ this . invokeFileWatcher ( currentEntry . fullPath , FileWatcherEventKind . Changed ) ;
455
+ }
456
+ }
457
+ }
458
+
449
459
renameFolder ( folderName : string , newFolderName : string ) {
450
460
const fullPath = getNormalizedAbsolutePath ( folderName , this . currentDirectory ) ;
451
461
const path = this . toPath ( fullPath ) ;
0 commit comments