@@ -267,13 +267,17 @@ interface Array<T> { length: number; [n: number]: T; }`
267
267
inode : number | undefined ;
268
268
}
269
269
270
- export interface ReloadWatchInvokeOptions {
270
+ export interface WatchInvokeOptions {
271
271
/** Invokes the directory watcher for the parent instead of the file changed */
272
272
invokeDirectoryWatcherInsteadOfFileChanged : boolean ;
273
273
/** When new file is created, do not invoke watches for it */
274
274
ignoreWatchInvokedWithTriggerAsFileCreate : boolean ;
275
275
/** Invoke the file delete, followed by create instead of file changed */
276
276
invokeFileDeleteCreateAsPartInsteadOfChange : boolean ;
277
+ /** Dont invoke delete watches */
278
+ ignoreDelete : boolean ;
279
+ /** Skip inode check on file or folder create*/
280
+ skipInodeCheckOnCreate : boolean ;
277
281
}
278
282
279
283
export enum Tsc_WatchFile {
@@ -324,7 +328,7 @@ interface Array<T> { length: number; [n: number]: T; }`
324
328
public defaultWatchFileKind ?: ( ) => WatchFileKind | undefined ;
325
329
public storeFilesChangingSignatureDuringEmit = true ;
326
330
watchFile : HostWatchFile ;
327
- private readonly inodeWatching : boolean | undefined ;
331
+ private inodeWatching : boolean | undefined ;
328
332
private readonly inodes ?: ESMap < Path , number > ;
329
333
watchDirectory : HostWatchDirectory ;
330
334
constructor (
@@ -376,7 +380,7 @@ interface Array<T> { length: number; [n: number]: T; }`
376
380
tscWatchDirectory,
377
381
defaultWatchFileKind : ( ) => this . defaultWatchFileKind ?.( ) ,
378
382
inodeWatching : ! ! this . inodeWatching ,
379
- sysLog : this . write . bind ( this )
383
+ sysLog : s => this . write ( s + this . newLine ) ,
380
384
} ) ;
381
385
this . watchFile = watchFile ;
382
386
this . watchDirectory = watchDirectory ;
@@ -441,16 +445,16 @@ interface Array<T> { length: number; [n: number]: T; }`
441
445
}
442
446
}
443
447
444
- modifyFile ( filePath : string , content : string , options ?: Partial < ReloadWatchInvokeOptions > ) {
448
+ modifyFile ( filePath : string , content : string , options ?: Partial < WatchInvokeOptions > ) {
445
449
const path = this . toFullPath ( filePath ) ;
446
450
const currentEntry = this . fs . get ( path ) ;
447
451
if ( ! currentEntry || ! isFsFile ( currentEntry ) ) {
448
452
throw new Error ( `file not present: ${ filePath } ` ) ;
449
453
}
450
454
451
455
if ( options && options . invokeFileDeleteCreateAsPartInsteadOfChange ) {
452
- this . removeFileOrFolder ( currentEntry , returnFalse ) ;
453
- this . ensureFileOrFolder ( { path : filePath , content } ) ;
456
+ this . removeFileOrFolder ( currentEntry , /*isRenaming*/ false , options ) ;
457
+ this . ensureFileOrFolder ( { path : filePath , content } , /*ignoreWatchInvokedWithTriggerAsFileCreate*/ undefined , /*ignoreParentWatch*/ undefined , options ) ;
454
458
}
455
459
else {
456
460
currentEntry . content = content ;
@@ -475,7 +479,7 @@ interface Array<T> { length: number; [n: number]: T; }`
475
479
Debug . assert ( ! ! file ) ;
476
480
477
481
// Only remove the file
478
- this . removeFileOrFolder ( file , returnFalse , /*isRenaming*/ true ) ;
482
+ this . removeFileOrFolder ( file , /*isRenaming*/ true ) ;
479
483
480
484
// Add updated folder with new folder name
481
485
const newFullPath = getNormalizedAbsolutePath ( newFileName , this . currentDirectory ) ;
@@ -495,7 +499,7 @@ interface Array<T> { length: number; [n: number]: T; }`
495
499
Debug . assert ( ! ! folder ) ;
496
500
497
501
// Only remove the folder
498
- this . removeFileOrFolder ( folder , returnFalse , /*isRenaming*/ true ) ;
502
+ this . removeFileOrFolder ( folder , /*isRenaming*/ true ) ;
499
503
500
504
// Add updated folder with new folder name
501
505
const newFullPath = getNormalizedAbsolutePath ( newFolderName , this . currentDirectory ) ;
@@ -530,38 +534,38 @@ interface Array<T> { length: number; [n: number]: T; }`
530
534
}
531
535
}
532
536
533
- ensureFileOrFolder ( fileOrDirectoryOrSymLink : FileOrFolderOrSymLink , ignoreWatchInvokedWithTriggerAsFileCreate ?: boolean , ignoreParentWatch ?: boolean ) {
537
+ ensureFileOrFolder ( fileOrDirectoryOrSymLink : FileOrFolderOrSymLink , ignoreWatchInvokedWithTriggerAsFileCreate ?: boolean , ignoreParentWatch ?: boolean , options ?: Partial < WatchInvokeOptions > ) {
534
538
if ( isFile ( fileOrDirectoryOrSymLink ) ) {
535
539
const file = this . toFsFile ( fileOrDirectoryOrSymLink ) ;
536
540
// file may already exist when updating existing type declaration file
537
541
if ( ! this . fs . get ( file . path ) ) {
538
- const baseFolder = this . ensureFolder ( getDirectoryPath ( file . fullPath ) , ignoreParentWatch ) ;
539
- this . addFileOrFolderInFolder ( baseFolder , file , ignoreWatchInvokedWithTriggerAsFileCreate ) ;
542
+ const baseFolder = this . ensureFolder ( getDirectoryPath ( file . fullPath ) , ignoreParentWatch , options ) ;
543
+ this . addFileOrFolderInFolder ( baseFolder , file , ignoreWatchInvokedWithTriggerAsFileCreate , options ) ;
540
544
}
541
545
}
542
546
else if ( isSymLink ( fileOrDirectoryOrSymLink ) ) {
543
547
const symLink = this . toFsSymLink ( fileOrDirectoryOrSymLink ) ;
544
548
Debug . assert ( ! this . fs . get ( symLink . path ) ) ;
545
- const baseFolder = this . ensureFolder ( getDirectoryPath ( symLink . fullPath ) , ignoreParentWatch ) ;
546
- this . addFileOrFolderInFolder ( baseFolder , symLink , ignoreWatchInvokedWithTriggerAsFileCreate ) ;
549
+ const baseFolder = this . ensureFolder ( getDirectoryPath ( symLink . fullPath ) , ignoreParentWatch , options ) ;
550
+ this . addFileOrFolderInFolder ( baseFolder , symLink , ignoreWatchInvokedWithTriggerAsFileCreate , options ) ;
547
551
}
548
552
else {
549
553
const fullPath = getNormalizedAbsolutePath ( fileOrDirectoryOrSymLink . path , this . currentDirectory ) ;
550
- this . ensureFolder ( getDirectoryPath ( fullPath ) , ignoreParentWatch ) ;
551
- this . ensureFolder ( fullPath , ignoreWatchInvokedWithTriggerAsFileCreate ) ;
554
+ this . ensureFolder ( getDirectoryPath ( fullPath ) , ignoreParentWatch , options ) ;
555
+ this . ensureFolder ( fullPath , ignoreWatchInvokedWithTriggerAsFileCreate , options ) ;
552
556
}
553
557
}
554
558
555
- private ensureFolder ( fullPath : string , ignoreWatch : boolean | undefined ) : FsFolder {
559
+ private ensureFolder ( fullPath : string , ignoreWatch : boolean | undefined , options : Partial < WatchInvokeOptions > | undefined ) : FsFolder {
556
560
const path = this . toPath ( fullPath ) ;
557
561
let folder = this . fs . get ( path ) as FsFolder ;
558
562
if ( ! folder ) {
559
563
folder = this . toFsFolder ( fullPath ) ;
560
564
const baseFullPath = getDirectoryPath ( fullPath ) ;
561
565
if ( fullPath !== baseFullPath ) {
562
566
// Add folder in the base folder
563
- const baseFolder = this . ensureFolder ( baseFullPath , ignoreWatch ) ;
564
- this . addFileOrFolderInFolder ( baseFolder , folder , ignoreWatch ) ;
567
+ const baseFolder = this . ensureFolder ( baseFullPath , ignoreWatch , options ) ;
568
+ this . addFileOrFolderInFolder ( baseFolder , folder , ignoreWatch , options ) ;
565
569
}
566
570
else {
567
571
// root folder
@@ -574,7 +578,7 @@ interface Array<T> { length: number; [n: number]: T; }`
574
578
return folder ;
575
579
}
576
580
577
- private addFileOrFolderInFolder ( folder : FsFolder , fileOrDirectory : FsFile | FsFolder | FsSymLink , ignoreWatch ?: boolean ) {
581
+ private addFileOrFolderInFolder ( folder : FsFolder , fileOrDirectory : FsFile | FsFolder | FsSymLink , ignoreWatch ?: boolean , options ?: Partial < WatchInvokeOptions > ) {
578
582
if ( ! this . fs . has ( fileOrDirectory . path ) ) {
579
583
insertSorted ( folder . entries , fileOrDirectory , ( a , b ) => compareStringsCaseSensitive ( getBaseFileName ( a . path ) , getBaseFileName ( b . path ) ) ) ;
580
584
}
@@ -585,11 +589,14 @@ interface Array<T> { length: number; [n: number]: T; }`
585
589
if ( ignoreWatch ) {
586
590
return ;
587
591
}
592
+ const inodeWatching = this . inodeWatching ;
593
+ if ( options ?. skipInodeCheckOnCreate ) this . inodeWatching = false ;
588
594
this . invokeFileAndFsWatches ( fileOrDirectory . fullPath , FileWatcherEventKind . Created ) ;
589
595
this . invokeFileAndFsWatches ( folder . fullPath , FileWatcherEventKind . Changed ) ;
596
+ this . inodeWatching = inodeWatching ;
590
597
}
591
598
592
- private removeFileOrFolder ( fileOrDirectory : FsFile | FsFolder | FsSymLink , isRemovableLeafFolder : ( folder : FsFolder ) => boolean , isRenaming = false ) {
599
+ private removeFileOrFolder ( fileOrDirectory : FsFile | FsFolder | FsSymLink , isRenaming ?: boolean , options ?: Partial < WatchInvokeOptions > ) {
593
600
const basePath = getDirectoryPath ( fileOrDirectory . path ) ;
594
601
const baseFolder = this . fs . get ( basePath ) as FsFolder ;
595
602
if ( basePath !== fileOrDirectory . path ) {
@@ -602,21 +609,16 @@ interface Array<T> { length: number; [n: number]: T; }`
602
609
if ( isFsFolder ( fileOrDirectory ) ) {
603
610
Debug . assert ( fileOrDirectory . entries . length === 0 || isRenaming ) ;
604
611
}
605
- this . invokeFileAndFsWatches ( fileOrDirectory . fullPath , FileWatcherEventKind . Deleted ) ;
612
+ if ( ! options ?. ignoreDelete ) this . invokeFileAndFsWatches ( fileOrDirectory . fullPath , FileWatcherEventKind . Deleted ) ;
606
613
this . inodes ?. delete ( fileOrDirectory . path ) ;
607
- this . invokeFileAndFsWatches ( baseFolder . fullPath , FileWatcherEventKind . Changed ) ;
608
- if ( basePath !== fileOrDirectory . path &&
609
- baseFolder . entries . length === 0 &&
610
- isRemovableLeafFolder ( baseFolder ) ) {
611
- this . removeFileOrFolder ( baseFolder , isRemovableLeafFolder ) ;
612
- }
614
+ if ( ! options ?. ignoreDelete ) this . invokeFileAndFsWatches ( baseFolder . fullPath , FileWatcherEventKind . Changed ) ;
613
615
}
614
616
615
617
deleteFile ( filePath : string ) {
616
618
const path = this . toFullPath ( filePath ) ;
617
619
const currentEntry = this . fs . get ( path ) as FsFile ;
618
620
Debug . assert ( isFsFile ( currentEntry ) ) ;
619
- this . removeFileOrFolder ( currentEntry , returnFalse ) ;
621
+ this . removeFileOrFolder ( currentEntry ) ;
620
622
}
621
623
622
624
deleteFolder ( folderPath : string , recursive ?: boolean ) {
@@ -630,11 +632,11 @@ interface Array<T> { length: number; [n: number]: T; }`
630
632
this . deleteFolder ( fsEntry . fullPath , recursive ) ;
631
633
}
632
634
else {
633
- this . removeFileOrFolder ( fsEntry , returnFalse ) ;
635
+ this . removeFileOrFolder ( fsEntry ) ;
634
636
}
635
637
} ) ;
636
638
}
637
- this . removeFileOrFolder ( currentEntry , returnFalse ) ;
639
+ this . removeFileOrFolder ( currentEntry ) ;
638
640
}
639
641
640
642
private watchFileWorker ( fileName : string , cb : FileWatcherCallback , pollingInterval : PollingInterval ) {
@@ -947,11 +949,11 @@ interface Array<T> { length: number; [n: number]: T; }`
947
949
}
948
950
}
949
951
950
- prependFile ( path : string , content : string , options ?: Partial < ReloadWatchInvokeOptions > ) : void {
952
+ prependFile ( path : string , content : string , options ?: Partial < WatchInvokeOptions > ) : void {
951
953
this . modifyFile ( path , content + this . readFile ( path ) , options ) ;
952
954
}
953
955
954
- appendFile ( path : string , content : string , options ?: Partial < ReloadWatchInvokeOptions > ) : void {
956
+ appendFile ( path : string , content : string , options ?: Partial < WatchInvokeOptions > ) : void {
955
957
this . modifyFile ( path , this . readFile ( path ) + content , options ) ;
956
958
}
957
959
0 commit comments