@@ -65,7 +65,7 @@ const updateWatchedFiles = async (watcher: FSWatcher, base: string, isFirstRun =
65
65
console . log ( '...done' )
66
66
}
67
67
68
- const start = async ( base : string ) => {
68
+ const start = async ( base : string , once = false ) => {
69
69
const watcher = watch ( [ 'middleware.js' , 'middleware.ts' , 'src/middleware.js' , 'src/middleware.ts' ] , {
70
70
// Try and ensure renames just emit one event
71
71
atomic : true ,
@@ -88,11 +88,15 @@ const start = async (base: string) => {
88
88
console . log ( `File ${ path } has been removed` )
89
89
updateWatchedFiles ( watcher , base )
90
90
} )
91
- . on ( 'ready' , ( ) => {
91
+ . on ( 'ready' , async ( ) => {
92
92
console . log ( 'Initial scan complete. Ready for changes' )
93
93
// This only happens on the first scan
94
- updateWatchedFiles ( watcher , base , true )
94
+ await updateWatchedFiles ( watcher , base , true )
95
+ if ( once ) {
96
+ watcher . close ( )
97
+ }
95
98
} )
99
+
96
100
await new Promise ( ( resolve ) => {
97
101
watcher . on ( 'close' , resolve )
98
102
} )
@@ -101,7 +105,7 @@ const start = async (base: string) => {
101
105
}
102
106
}
103
107
104
- start ( process . argv [ 2 ] ) . catch ( ( error ) => {
108
+ start ( process . argv [ 2 ] , process . argv [ 3 ] === '--once' ) . catch ( ( error ) => {
105
109
console . error ( error )
106
110
// eslint-disable-next-line n/no-process-exit
107
111
process . exit ( 1 )
0 commit comments