@@ -4,10 +4,10 @@ import { isCompilerPlugin } from '../plugins';
44import { createAppProcess } from './app-process' ;
55import { buildApplication } from './build' ;
66import { watch } from 'chokidar' ;
7- import { ChildProcessWithoutNullStreams } from 'child_process' ;
87import { readdirSync } from 'node:fs' ;
98import { debounce } from '../utils/utilities' ;
109import colors from '../utils/colors' ;
10+ import { ChildProcess } from 'node:child_process' ;
1111
1212async function buildAndStart ( configPath : string , skipStart = false ) {
1313 const config = await loadConfigFile ( configPath ) ;
@@ -22,7 +22,13 @@ async function buildAndStart(configPath: string, skipStart = false) {
2222
2323 if ( skipStart ) return null as never ;
2424
25- return createAppProcess ( mainFile , configPath , true ) ;
25+ const ps = createAppProcess ( mainFile , configPath , true ) ;
26+
27+ ps . on ( 'message' , ( message ) => {
28+ console . log ( `Received message from child process: ${ message } ` ) ;
29+ } ) ;
30+
31+ return ps ;
2632}
2733
2834const isCommandSource = ( p : string ) =>
@@ -42,17 +48,18 @@ export async function bootstrapDevelopmentServer(configPath?: string) {
4248 ignoreInitial : true ,
4349 } ) ;
4450
45- let ps : ChildProcessWithoutNullStreams | null = null ;
51+ let ps : ChildProcess | null = null ;
4652
4753 const performHMR = debounce ( async ( path ?: string ) : Promise < boolean > => {
4854 if ( ! path || ! ps ) return false ;
55+ if ( ! ps . send ) return false ;
4956
5057 if ( isCommandSource ( path ) ) {
5158 console . log (
5259 `${ colors . cyanBright ( 'Reloading command(s) at ' ) } ${ colors . yellowBright ( path ) } ` ,
5360 ) ;
5461 await buildAndStart ( cwd , true ) ;
55- ps . stdin . write ( `COMMANDKIT_EVENT= reload-commands| ${ path } \n` ) ;
62+ ps . send ( { event : ' reload-commands' , path } ) ;
5663 return true ;
5764 }
5865
@@ -61,7 +68,7 @@ export async function bootstrapDevelopmentServer(configPath?: string) {
6168 `${ colors . cyanBright ( 'Reloading event(s) at ' ) } ${ colors . yellowBright ( path ) } ` ,
6269 ) ;
6370 await buildAndStart ( cwd , true ) ;
64- ps . stdin . write ( `COMMANDKIT_EVENT= reload-events| ${ path } \n` ) ;
71+ ps . send ( { event : ' reload-events' , path } ) ;
6572 return true ;
6673 }
6774
@@ -70,15 +77,20 @@ export async function bootstrapDevelopmentServer(configPath?: string) {
7077 `${ colors . cyanBright ( 'Reloading locale(s) at ' ) } ${ colors . yellowBright ( path ) } ` ,
7178 ) ;
7279 await buildAndStart ( cwd , true ) ;
73- ps . stdin . write ( `COMMANDKIT_EVENT= reload-locales| ${ path } \n` ) ;
80+ ps . send ( { event : ' reload-locales' , path } ) ;
7481 return true ;
7582 }
7683
7784 return false ;
7885 } , 300 ) ;
7986
8087 const hmrHandler = async ( path : string ) => {
81- if ( await performHMR ( path ) ) return ;
88+ const hmr = await performHMR ( path ) ;
89+ if ( hmr ) return ;
90+
91+ console . log (
92+ `${ colors . yellowBright ( '⚡️ Performing full restart due to the changes in' ) } ${ colors . cyanBright ( path ) } ` ,
93+ ) ;
8294
8395 ps ?. kill ( ) ;
8496
@@ -97,15 +109,15 @@ export async function bootstrapDevelopmentServer(configPath?: string) {
97109 break ;
98110 case 'rc' :
99111 console . log ( `Received reload commands command, reloading...` ) ;
100- ps ?. stdin . write ( `COMMANDKIT_EVENT= reload-commands\n` ) ;
112+ ps ?. send ( { event : ' reload-commands' } ) ;
101113 break ;
102114 case 're' :
103115 console . log ( `Received reload events command, reloading...` ) ;
104- ps ?. stdin . write ( `COMMANDKIT_EVENT= reload-events\n` ) ;
116+ ps ?. send ( { event : ' reload-events' } ) ;
105117 break ;
106118 case 'rl' :
107119 console . log ( `Received reload locales command, reloading...` ) ;
108- ps ?. stdin . write ( `COMMANDKIT_EVENT= reload-locales\n` ) ;
120+ ps ?. send ( { event : ' reload-locales' } ) ;
109121 break ;
110122 }
111123 } ) ;
0 commit comments