Skip to content

Commit 33b4826

Browse files
committed
fix: support lib tsc
1 parent 89b771d commit 33b4826

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-performance-analyzer",
3-
"version": "0.1.3",
3+
"version": "0.1.5",
44
"description": "TypeScript compilation performance analyzer",
55
"author": "hg-pyun",
66
"license": "MIT",
@@ -54,7 +54,8 @@
5454
"react": "^18.3.1",
5555
"react-dom": "^18.3.1",
5656
"recharts": "^2.15.0",
57-
"stream-json": "^1.9.1"
57+
"stream-json": "^1.9.1",
58+
"typescript": "^5.7.2"
5859
},
5960
"devDependencies": {
6061
"@eslint/js": "^9.39.1",
@@ -69,7 +70,6 @@
6970
"eslint-config-prettier": "^10.1.8",
7071
"eslint-plugin-react-hooks": "^7.0.1",
7172
"prettier": "^3.7.4",
72-
"typescript": "^5.7.2",
7373
"typescript-eslint": "^8.49.0",
7474
"vite": "^6.0.3",
7575
"vite-plugin-singlefile": "^2.0.3",

src/cli/commands/trace.ts

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { join, resolve } from 'path';
1+
import { join, resolve, dirname } from 'path';
2+
import { fileURLToPath } from 'url';
23
import { access, mkdir, rm } from 'fs/promises';
34
import { spawn } from 'child_process';
45
import 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
*/
146148
async 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

Comments
 (0)