@@ -12,7 +12,7 @@ import * as chokidar from 'chokidar';
12
12
import * as jsYAML from 'js-yaml' ;
13
13
import { promises as fs } from 'fs' ;
14
14
import * as path from 'path' ;
15
- import { logger } from '../utils' ;
15
+ import { addShutdownJob , logger } from '../utils' ;
16
16
17
17
const callAfterFulfilled = ( func : ( ) => Promise < void > ) => {
18
18
let busy = false ;
@@ -70,8 +70,13 @@ export const handleStart = async (
70
70
71
71
const restartServer = async ( ) => {
72
72
if ( stopServer ) await stopServer ( ) ;
73
- await buildVulcan ( buildOptions ) ;
74
- stopServer = ( await serveVulcan ( serveOptions ) ) . stopServer ;
73
+ try {
74
+ await buildVulcan ( buildOptions ) ;
75
+ stopServer = ( await serveVulcan ( serveOptions ) ) . stopServer ;
76
+ } catch ( e ) {
77
+ // Ignore the error to keep watch process works
78
+ if ( ! startOptions . watch ) throw e ;
79
+ }
75
80
} ;
76
81
77
82
await restartServer ( ) ;
@@ -110,10 +115,13 @@ export const handleStart = async (
110
115
}
111
116
112
117
const restartWhenFulfilled = callAfterFulfilled ( restartServer ) ;
113
- chokidar
118
+ const watcher = chokidar
114
119
. watch ( pathsToWatch , { ignoreInitial : true } )
115
120
. on ( 'all' , ( ) => restartWhenFulfilled ( ) ) ;
116
-
121
+ addShutdownJob ( async ( ) => {
122
+ logger . info ( `Stop watching changes...` ) ;
123
+ await watcher . close ( ) ;
124
+ } ) ;
117
125
logger . info ( `Start watching changes...` ) ;
118
126
}
119
127
} ;
0 commit comments