Skip to content

Commit ca5db37

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

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
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.4",
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: 32 additions & 8 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

@@ -182,6 +196,16 @@ function runTsc(
182196
});
183197

184198
proc.on('close', (code) => {
199+
// Exit code 127 means command not found - this is a fatal error
200+
if (code === 127) {
201+
reject(
202+
new Error(
203+
'TypeScript compiler (tsc) not found. Please install TypeScript in your project:\n npm install typescript --save-dev'
204+
)
205+
);
206+
return;
207+
}
208+
185209
// TypeScript may return non-zero exit code for type errors,
186210
// but trace should still be generated
187211
if (code !== 0 && verbose) {

0 commit comments

Comments
 (0)