File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -73,8 +73,6 @@ export default class Serve extends Base {
7373 {
7474 onReady : async ( ) => {
7575 await this . ctx . hooks . callHook ( "serve:ready" , this . ctx ) ;
76- this . logger . clear ( ) ;
77- this . logger . ready ( "Server Ready!" ) ;
7876 } ,
7977 onChange : async ( path ) => {
8078 await this . ctx . hooks . callHook ( "serve:onChanged" , this . ctx , path ) ;
@@ -88,10 +86,6 @@ export default class Serve extends Base {
8886
8987 await this . reload ( ) ;
9088 } ,
91- onError : ( err ) => {
92- this . logger . fail ( "Server start failed!" ) ;
93- this . logger . error ( err ) ;
94- } ,
9589 } ,
9690 ) ;
9791 }
Original file line number Diff line number Diff line change @@ -15,26 +15,21 @@ export function watch(
1515 persistent : true ,
1616 } ) ;
1717
18- const onChangeDebounced = debounce ( event . onChange , 500 ) ;
18+ const onChangeDebounced = safeDebounce ( event . onChange ) ;
1919
2020 watcher
2121 . on ( "ready" , async ( ) => {
22+ if ( event . onReady )
23+ await event . onReady ( ) ;
2224 logger . clear ( ) ;
2325 logger . ready ( "Server Ready!" ) ;
24- if ( event . onReady )
25- await debounce ( event . onReady , 500 ) ( ) ;
2626 } )
2727 . on ( "change" , async ( path ) => {
2828 logger . clear ( ) ;
2929 logger . info ( `${ path } changed` ) ;
30- try {
31- await onChangeDebounced ( path ) ;
32- }
33- catch ( err ) {
34- // Do not abort the watcher when errors occur
35- // in builds triggered by the watcher.
36- logger . error ( err ) ;
37- }
30+ // Do not abort the watcher when errors occur
31+ // in builds triggered by the watcher.
32+ await onChangeDebounced ( path ) ;
3833 } )
3934 . on ( "error" , async ( err ) => {
4035 if ( event . onError )
@@ -45,3 +40,17 @@ export function watch(
4540
4641 // return watcher;
4742}
43+
44+ function safeDebounce ( fn ?: ( ...args : any [ ] ) => void ) {
45+ if ( ! fn )
46+ return ( ) => { } ;
47+
48+ return debounce ( async ( ...args ) => {
49+ try {
50+ await fn ( ...args ) ;
51+ }
52+ catch ( error ) {
53+ logger . error ( error ) ;
54+ }
55+ } , 500 ) ;
56+ }
You can’t perform that action at this time.
0 commit comments