@@ -33,23 +33,53 @@ if (gameVisualizers.length === 0) {
3333}
3434
3535/**
36- * Runs a command for a single package. Used for 'dev' or building one visualizer at a time.
36+ * Runs a command for a package.
37+ * - For 'dev', it first builds all dependencies, then runs dev servers in parallel.
38+ * - For 'build', it runs the command only for the selected package.
3739 */
3840const runCommand = ( pkg ) => {
3941 const packageName = pkg . name ;
4042 const relativePath = path . relative ( process . cwd ( ) , pkg . path ) ;
4143
42- // Clear the screen only for the 'dev' command to mimic Vite's behavior
44+ // Clear the screen only for 'dev' to mimic Vite's behavior
4345 if ( command === 'dev' ) {
4446 console . clear ( ) ;
4547 }
4648
47- console . log ( `Running "pnpm ${ command } " in ${ relativePath } ...` ) ;
49+ let cmdToRun , cmdArgs , cwd ;
4850
49- const child = spawn ( 'pnpm' , [ command ] , {
51+ if ( command === 'dev' ) {
52+ try {
53+ // STEP 1: Build all dependencies of the target package first.
54+ // The `...^` syntax targets all dependencies, but NOT the package itself.
55+ console . log ( `[1/2] Building dependencies for ${ packageName } ...` ) ;
56+ execSync ( `pnpm --filter ${ packageName } ...^ build` , {
57+ stdio : 'inherit' ,
58+ cwd : process . cwd ( )
59+ } ) ;
60+ console . log ( `✅ Dependencies built successfully.` ) ;
61+ } catch ( e ) {
62+ console . error ( '\n❌ Initial build of dependencies failed. Aborting.' ) ;
63+ process . exit ( 1 ) ;
64+ }
65+
66+ // STEP 2: Now, run the parallel dev/watch commands.
67+ console . log ( `\n[2/2] Starting dev servers for ${ packageName } and its dependencies...` ) ;
68+ cmdToRun = 'pnpm' ;
69+ cmdArgs = [ '--parallel' , '--filter' , `${ packageName } ...` , 'dev' ] ;
70+ cwd = process . cwd ( ) ; // Run from the monorepo root
71+ } else {
72+ // For 'build' of a single package, the original logic is fine.
73+ console . log ( `Running "pnpm ${ command } " in ${ relativePath } ...` ) ;
74+ cmdToRun = 'pnpm' ;
75+ cmdArgs = [ command ] ;
76+ cwd = pkg . path ; // Run inside the specific package directory
77+ }
78+
79+ const child = spawn ( cmdToRun , cmdArgs , {
5080 stdio : 'inherit' ,
51- shell : true , // Use shell: true to ensure pnpm is found in the path
52- cwd : pkg . path ,
81+ shell : true ,
82+ cwd : cwd ,
5383 env : {
5484 ...process . env ,
5585 VITE_CUSTOM_HEADER_NAME : packageName ,
@@ -64,7 +94,6 @@ const runCommand = (pkg) => {
6494 child . on ( 'exit' , ( code ) => {
6595 if ( code !== 0 ) {
6696 console . error ( `\n'${ packageName } ${ command } ' process exited with code ${ code } ` ) ;
67- // Propagate the error code for CI/CD environments
6897 process . exit ( code ) ;
6998 }
7099 } ) ;
0 commit comments