6.2.0 • Published 1 year ago

tsc-watch v6.2.0

Weekly downloads
192,729
License
MIT
Repository
github
Last release
1 year ago

Build Status

The nodemon for TypeScript

tsc-watch starts the installed TypeScript compiler (tsc) with --watch parameter, with the ability to react to compilation status. tsc-watch was created to allow an easy dev process with TypeScript. Commonly used to restart a node server, similar to nodemon but for TypeScript.

Anything that you can do with tsc you can do with tsc-watch, the only difference is that tsc-watch can react to compilation status.

ArgumentDescription
--onSuccess COMMANDExecutes COMMAND on every successful compilation.
--onFirstSuccess COMMANDExecutes COMMAND on the first successful compilation.
--onEmit COMMANDExecutes debounced COMMAND on every emitted file, ignoring unchanged files and disregards compilation success or failure.
--onEmitDebounceMs DELAYDelay by which to debounce --onEmit (default: 300).
--onFailure COMMANDExecutes COMMAND on every failed compilation.
--onCompilationStarted COMMANDExecutes COMMAND on every compilation start event (initial and incremental).
--onCompilationComplete COMMANDExecutes COMMAND on every successful or failed compilation.
--maxNodeMemCalls node with a specific memory limit max_old_space_size, to use if your project needs more memory.
--noColorsBy default tsc-watch adds colors the output with greenon success, and in red on failure. Add this argument to prevent that.
--noClearIn watch mode the tsc compiler clears the screen before reportingAdd this argument to prevent that.
--signalEmittedFilesWill run tsc compiler with --listEmittedFiles, but hiding TSFILE lines. Use it to enable file_emitted event, while keeping tsc stdout silent.
--silentDo not print any messages on stdout.
--compiler PATHThe PATH will be used instead of typescript compiler.Default is typescript/bin/tsc

Notes:

  • That all the above COMMANDs will be killed on process exit. (Using SIGTERM)

  • A COMMAND is a single command and not multi command like script1.sh && script2.sh

  • Any child process (COMMAND) will be terminated before creating a new one.

Install

npm install tsc-watch --save-dev
## for command-line usage
npm install -g typescript tsc-watch

Usage

From Command-Line

## Watching a project (with tsconfig.json)
tsc-watch --onSuccess "node ./dist/server.js"

## Beep on failure
tsc-watch --onFailure "echo Beep! Compilation Failed"

## Watching a single file
tsc-watch server.ts --outDir ./dist --onSuccess "node ./dist/server.js"

## Custom compiler
tsc-watch --onSuccess "node ./dist/server.js" --compiler my-typescript/bin/tsc

From npm script

"dev-server": "tsc-watch --noClear -p ./src/tsconfig.json --onSuccess \"node ./dist/server.js\"",

From javascript

You can see a detailed example here

The client is implemented as an instance of Node.JS's EventEmitter, with the following events:

  • started - Emitted upon the compilation start (initial or incremental).
  • first_success - Emitted upon first successful compilation.
  • subsequent_success - Emitted upon every subsequent successful compilation.
  • compile_errors - Emitted upon every failing compilation.
  • file_emitted - Emitted upon every file transpiled if --listEmittedFiles is used.

Once subscribed to the relevant events, start the client by running watch.start()

To kill the client, run watch.kill()

Example usage:

// Using CommonJS:
const { TscWatchClient } = require('tsc-watch/client');
// Using ES6 import:
import { TscWatchClient } from 'tsc-watch/client';

const watch = new TscWatchClient();

watch.on('started', () => {
  console.log('Compilation started');
});

watch.on('first_success', () => {
  console.log('First success!');
});

watch.on('success', () => {
  // Your code goes here...
});

watch.on('compile_errors', () => {
  // Your code goes here...
});

watch.start('--project', '.');

try {
  // do something...
} catch (e) {
  watch.kill(); // Fatal error, kill the compiler instance.
}

Notes:

  • The (onSuccess) COMMAND will not run if the compilation failed.
  • The (onEmit) COMMAND will not run if the compilation succeeded with no changed files, unless it is the first success.
  • The (onEmit) COMMAND will run even if the compilation failed, but emitted changed files.
  • The (onEmit) COMMAND will not run 100 times for 100 files, due to --onEmitDebounce
  • The (onEmit) COMMAND is not cancelling the onSuccess/onFirstSuccess/onFailure/onCompilationComplete/onCompilationStarted commands and vice versa.
  • tsc-watch is using the currently installed TypeScript compiler.
  • tsc-watch is not changing the compiler, just adds the new arguments, compilation is the same, and all other arguments are the same.
ultra-parserrentacar-proxy@textury/arlocal@adalov/clicroket_main@infinitebrahmanuniverse/nolb-tsc@quantform/cli@vestify/dev-kitteletron@everything-registry/sub-chunk-2980@shoma-mano/prismixwith-hfnwertik-jswow-eluna-ts-modulexhelpers-clisteam-comment-bot-resttestloggeruitestnewstructurevite-plugin-electron-tscvmaas@dlid/savona@prisma/mdxauth-service-manager@rana-mc/api@rana-mc/curseforge@rana-mc/fabric@rana-mc/forgeexpressloggeruihit-my-macros-apimtxcmsv3nodejs-crud-apistroom-corestrictsuffdatypeorm-migrate-to-sqltrendykyletrendy2kylets-crawler@autowired/vite-plugin-electron@agora-rte/rte-ts-build@aztec/archiver@agorarte/rte-ts-build@beyounglabs/alfred@biblioseo/inventorio-types@brickjs/devops@a-a-game-studio/aa-core@belvedere/groupryvan-cmduranio-dev@samen/samen@guaclive/guac.js@hobbs/z@hlolli/arlocal@elumeo/jfs-core@generationsoftware/pt-v5-utils-js@generationsoftware/pt-v5-utils-js-beta@goldfishjs/pre-build@makarandkate/invoice-templates@mailbook/core@mas.io/adc-miniu-cli@mas.io/cs-compiler@mas.io/misbop-portal-compiler-miniu@mas.io/misbop-portal-compiler-widget@mini-egg-gambit/cc@mitech/onit-cli@jiricekcz/opensea-collection-data@koex/cli@imbueapp/mockingbird@imbueapp/mocktillery@hexys/prismix@hlpi/tiktok-api@juicyllama/dev@hyper-graph/typescript@hyper-graph/cli@kevinefra/boiler-node-kevinefra@ratio.io/pi@ratio.me/pi@rana-mc/types@rws-framework/server@static-suite/static-suite-data-server@pooltogether/v5-autotasks-library@pooltogether/v5-utils-js@patys/snap-it@notants/amqp-adapter@parca/utilities@parca/client@parca/components@parca/hooks@parca/icons@parca/parser@parca/profile@parca/store@smartface/tsc-watch@skybackend/commonpanel@remol/boot@staccx/bento@stadtteilliebe/react-cookie-consentmusix-streamermpbuildmoe-scripts
6.2.0

1 year ago

6.1.0

1 year ago

6.0.5

1 year ago

6.0.1

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

6.0.4

2 years ago

6.0.0

3 years ago

6.0.0-dev.5

3 years ago

6.0.0-dev.4

3 years ago

6.0.0-dev.3

3 years ago

6.0.0-dev.2

3 years ago

4.6.1

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

4.6.2

3 years ago

6.0.0-dev.1

3 years ago

6.0.0-dev.0

3 years ago

4.6.0

3 years ago

4.5.0

4 years ago

4.4.0

4 years ago

4.3.1

4 years ago

4.3.0

4 years ago

4.2.9

5 years ago

4.2.8

5 years ago

4.2.7

5 years ago

4.2.6

5 years ago

4.2.5

5 years ago

4.2.4

5 years ago

4.2.3

5 years ago

4.2.2

5 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.2.0-rc1

5 years ago

4.1.0

5 years ago

4.0.0

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.4.0

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.2

6 years ago

1.1.39

6 years ago

1.1.38

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.37

6 years ago

1.1.36

6 years ago

1.1.35

6 years ago

1.1.34

6 years ago

1.1.33

6 years ago

1.1.32

6 years ago

1.0.32

6 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago