@theomessin/ts-builder v0.1.8
@theomessin/ts-builder
ts-builder is a simple script that enables Node.js to require TypeScript files.
It is similar to ts-node.
It uses tsc --build to build a TypeScript project including any references.
The new TypeScript build mode is quite fast as it uses a cache to perform smart incremental builds.
Installation
Install the package from npm:
npm install --save-dev @theomessin/ts-builderYou may then use ts-builder by registering it with Node.js:
node -r @theomessin/ts-builder foobar.tsBehind the Scenes
ts-builder will register itself as the handler for all *.ts files. When a *.ts file is required the following steps will be performed.
- The corresponding
tsconfig.jsonfor that file will be found. - The project will be built using
tsc --build. This will build any project references. TheoutDirwill be unaltered so compiled files will be saved as configured intsconfig.json. - The contents of the compiled
.jsfile of the given.tsfile will be returned.
Using with Mocha
ts-node does not support project references, which means that Mocha could not be used with TypeScript project references and the new build system.
However, ts-builder can be used instead.
Just run mocha with -r @theomessin/ts-builder/register.
Alternatively, register ts-builder in your .mocharc.js:
module.exports = {
extension: ['ts'],
require: [
'@theomessin/ts-builder/register',
],
};