diff --git a/README.md b/README.md index 3e3825695..1991e6866 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ Example: Enable generating type definitions with `tsc` if your source code is written in [TypeScript](http://www.typescriptlang.org/). -By default, it'll use the `tsconfig.json` file in your project root. If you want to use a different config, you can specify it using the `project` option. +By default, it'll use the `tsconfig.json` file in your project root. If you want to use a different config, you can specify it using the `project` option. Furthermore, the tsc binary will be resolved to ./node_modules/.bin/tsc. Use the `tsc` option to specify a different path. Example: diff --git a/src/targets/typescript.ts b/src/targets/typescript.ts index 76926da4c..14552aebb 100644 --- a/src/targets/typescript.ts +++ b/src/targets/typescript.ts @@ -8,7 +8,7 @@ import { platform } from 'os'; import { Input } from '../types'; type Options = Input & { - options?: { project?: string }; + options?: { project?: string; tsc?: string }; }; export default async function build({ @@ -78,9 +78,9 @@ export default async function build({ ); } - let tsc = - path.join(root, 'node_modules', '.bin', 'tsc') + - (platform() === 'win32' ? '.cmd' : ''); + let tsc = options?.tsc + ? path.resolve(root, options.tsc) + : path.join(root, 'node_modules') + (platform() === 'win32' ? '.cmd' : ''); if (!(await fs.pathExists(tsc))) { tsc = spawn @@ -93,7 +93,9 @@ export default async function build({ 'tsc' )}. Consider adding ${chalk.blue('typescript')} to your ${chalk.blue( 'devDependencies' - )} instead.` + )} or specifying the ${chalk.blue( + 'tsc' + )} option for the typescript target.` ); } @@ -127,7 +129,9 @@ export default async function build({ 'node_modules' )} or present in $PATH. Make sure you have added ${chalk.blue( 'typescript' - )} to your ${chalk.blue('devDependencies')}.` + )} to your ${chalk.blue('devDependencies')} or specify the ${chalk.blue( + 'tsc' + )} option for typescript.` ); } } catch (e) {