1- import { join , resolve } from 'path' ;
1+ import { join , resolve , dirname } from 'path' ;
2+ import { fileURLToPath } from 'url' ;
23import { access , mkdir , rm } from 'fs/promises' ;
34import { spawn } from 'child_process' ;
45import chalk from 'chalk' ;
@@ -141,17 +142,30 @@ export async function traceCommand(
141142}
142143
143144/**
144- * Find the tsc executable, preferring local node_modules
145+ * Find the tsc executable
146+ * Priority: 1) Project's local tsc, 2) This package's bundled tsc
145147 */
146148async function findTsc ( projectPath : string ) : Promise < string > {
147- // Try local node_modules first
148- const localTsc = join ( projectPath , 'node_modules' , '.bin' , 'tsc' ) ;
149+ // Try project's local node_modules first
150+ const projectTsc = join ( projectPath , 'node_modules' , '.bin' , 'tsc' ) ;
149151 try {
150- await access ( localTsc ) ;
151- return localTsc ;
152+ await access ( projectTsc ) ;
153+ return projectTsc ;
152154 } catch {
153- // Fall back to global tsc
154- return 'tsc' ;
155+ // Fall back to this package's bundled tsc
156+ const __filename = fileURLToPath ( import . meta. url ) ;
157+ const __dirname = dirname ( __filename ) ;
158+ // Navigate from dist/cli/commands/ to package root, then to node_modules
159+ const packageRoot = join ( __dirname , '..' , '..' , '..' ) ;
160+ const bundledTsc = join ( packageRoot , 'node_modules' , '.bin' , 'tsc' ) ;
161+
162+ try {
163+ await access ( bundledTsc ) ;
164+ return bundledTsc ;
165+ } catch {
166+ // Last resort: try global tsc
167+ return 'tsc' ;
168+ }
155169 }
156170}
157171
@@ -168,20 +182,27 @@ function runTsc(
168182 const proc = spawn ( tscPath , args , {
169183 cwd,
170184 shell : true ,
171- stdio : verbose ? 'inherit' : 'pipe' ,
185+ // Use 'inherit' to avoid buffer blocking issues with large outputs
186+ // When not verbose, we still inherit but the output will be visible
187+ // This prevents hanging on large projects
188+ stdio : 'inherit' ,
172189 } ) ;
173190
174- if ( ! verbose && proc . stderr ) {
175- proc . stderr . on ( 'data' , ( ) => {
176- // Capture stderr but don't store it - we only care about trace generation
177- } ) ;
178- }
179-
180191 proc . on ( 'error' , ( error ) => {
181192 reject ( new Error ( `Failed to run tsc: ${ error . message } ` ) ) ;
182193 } ) ;
183194
184195 proc . on ( 'close' , ( code ) => {
196+ // Exit code 127 means command not found - this is a fatal error
197+ if ( code === 127 ) {
198+ reject (
199+ new Error (
200+ 'TypeScript compiler (tsc) not found. Please install TypeScript in your project:\n npm install typescript --save-dev'
201+ )
202+ ) ;
203+ return ;
204+ }
205+
185206 // TypeScript may return non-zero exit code for type errors,
186207 // but trace should still be generated
187208 if ( code !== 0 && verbose ) {
0 commit comments