@@ -462,11 +462,16 @@ export class Application extends AbstractComponent<
462462 this . _watchFile ?.( path , shouldRestart ) ;
463463 }
464464
465- public convertAndWatch (
465+ /**
466+ * Run a convert / watch process.
467+ *
468+ * @param success Callback to run after each convert, receiving the project
469+ * @returns True if the watch process should be restarted due to a
470+ * configuration change, false for an options error
471+ */
472+ public async convertAndWatch (
466473 success : ( project : ProjectReflection ) => Promise < void > ,
467- /** Callback to restart watching when options or other critical files change */
468- restartWatch ?: ( ) => unknown ,
469- ) : void {
474+ ) : Promise < boolean > {
470475 if (
471476 ! this . options . getValue ( "preserveWatchOutput" ) &&
472477 this . logger instanceof ConsoleLogger
@@ -498,7 +503,7 @@ export class Application extends AbstractComponent<
498503 // have reported in the first time... just error out for now. I'm not convinced anyone will actually notice.
499504 if ( this . options . getFileNames ( ) . length === 0 ) {
500505 this . logger . error ( this . i18n . solution_not_supported_in_watch_mode ( ) ) ;
501- return ;
506+ return false ;
502507 }
503508
504509 // Support for packages mode is currently unimplemented
@@ -507,7 +512,7 @@ export class Application extends AbstractComponent<
507512 this . entryPointStrategy !== EntryPointStrategy . Expand
508513 ) {
509514 this . logger . error ( this . i18n . strategy_not_supported_in_watch_mode ( ) ) ;
510- return ;
515+ return false ;
511516 }
512517
513518 const tsconfigFile =
@@ -575,16 +580,13 @@ export class Application extends AbstractComponent<
575580 ) ;
576581 } ;
577582
583+ /** resolver for the returned promise */
584+ let exitWatch : ( restart : boolean ) => unknown ;
578585 const restartMain = ( file : string ) => {
579586 if ( restarting ) return ;
580- if ( ! restartWatch )
581- this . logger . warn (
582- this . i18n . file_0_changed_but_cant_restart ( nicePath ( file ) ) ,
583- ) ;
584- else
585- this . logger . info (
586- this . i18n . file_0_changed_restarting ( nicePath ( file ) ) ,
587- ) ;
587+ this . logger . info (
588+ this . i18n . file_0_changed_restarting ( nicePath ( file ) ) ,
589+ ) ;
588590 restarting = true ;
589591 currentProgram = undefined ;
590592 this . clearWatches ( ) ;
@@ -594,7 +596,7 @@ export class Application extends AbstractComponent<
594596 const runSuccess = ( ) => {
595597 if ( restarting && successFinished ) {
596598 successFinished = false ;
597- if ( restartWatch ) restartWatch ( ) ;
599+ exitWatch ( true ) ;
598600 return ;
599601 }
600602
@@ -673,6 +675,11 @@ export class Application extends AbstractComponent<
673675 } ;
674676
675677 const tsWatcher = ts . createWatchProgram ( host ) ;
678+
679+ // Don't return to caller until the watch needs to restart
680+ return await new Promise ( ( res ) => {
681+ exitWatch = res ;
682+ } ) ;
676683 }
677684
678685 validate ( project : ProjectReflection ) {
0 commit comments