Skip to content

Commit 155710d

Browse files
committed
feat: use tsc from PATH if available
1 parent 6a3d461 commit 155710d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/targets/typescript.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ export default async function build({ root, output, report }: Input) {
1515

1616
report.info(`Generating type definitions with ${chalk.blue('tsc')}`);
1717

18-
const tsc =
19-
path.join(root, 'node_modules', '.bin', 'tsc') +
20-
(platform() === 'win32' ? '.cmd' : '');
21-
2218
const tsconfig = path.join(root, 'tsconfig.json');
2319

2420
try {
@@ -57,6 +53,14 @@ export default async function build({ root, output, report }: Input) {
5753
}
5854
}
5955

56+
let tsc =
57+
path.join(root, 'node_modules', '.bin', 'tsc') +
58+
(platform() === 'win32' ? '.cmd' : '');
59+
60+
if (!await fs.pathExists(tsc)) {
61+
tsc = child_process.execSync('which tsc').toString('utf-8').trim();
62+
}
63+
6064
if (await fs.pathExists(tsc)) {
6165
child_process.execFileSync(tsc, [
6266
'--pretty',
@@ -75,7 +79,7 @@ export default async function build({ root, output, report }: Input) {
7579
'tsc'
7680
)} binary doesn't seem to be installed under ${chalk.blue(
7781
'node_modules'
78-
)}. Make sure you have added ${chalk.blue(
82+
)} or present in $PATH. Make sure you have added ${chalk.blue(
7983
'typescript'
8084
)} to your ${chalk.blue('devDependencies')}.`
8185
);

0 commit comments

Comments
 (0)