1.6.2 • Published 1 year ago

live-tsc v1.6.2

Weekly downloads
-
License
BSD-2-Clause
Repository
github
Last release
1 year ago

live-tsc

A lightweight esbuild-based implementation of tsc that trim off the types (without type checking)

Intended to be used by ts-liveview but it should be generic enough as an alternative to "tsc --watch"

npm Package Version

Installation

npm i -D live-tsc

Command Line Usage

Usage Example:

npx live-tsc \
  --watch \
  --src     ./ \
  --dest    ./dist \
  --exclude ./scripts \
  --exclude ./public \
  --exclude ./data \
  --exclude ./db/data \
  --post-hook "npx fix-esm-import-path dist/db/proxy.js" \
  --server  ./dist/server/index.js \
  --open "https://localhost:8100"

Options:

  --src <dir|file>
    Specify the source directory/file
    Alias: -s

  --dest <dir|file>
    Specify the destination directory/file
    Alias: -d

  --exclude <dir|file>
    Specify the path to be excluded;
    Can be specified multiple times;
    The destination directory is excluded by default
    Alias: -e

  --project <file>
    Specify the path of tsconfig file
    Alias: -p
    Default: tsconfig.json

  --watch
    Watch for changes and rerun
    Alias: -w

  --format <cjs|esm|iife>
    Sets the output format for the generated JavaScript files
    Alias: -f
    Default: esm

  --post-hook <command>[#watch:<file1[,file2]>]
    Add command to run after initial scan and subsequence updates;
    If the watch files are specified, the hook will be re-run only if the specified files are changed,
    otherwise the hook will observe the source files;
    Can be specified multiple times;

  --post-script <npm script>[#watch:<file1[,file2]>]
    Add npm script to run after initial scan and subsequence updates;
    This is a shortcut as: --post-hook "npm run <script>";
    Details refers to "--post-hook"

  --server <file>
    Specify the path of server js file

  --cwd <dir>
    Specify the current working directory for the server and postHooks
    Alias: -c
    Default: sample as process.cwd

  --open <url>
    Open the url in the default browser after initial scanning
    Alias: -o

  --help
    Show help message
    Alias: -h

Why skip type checking?

This tool is intended to be used by the development server (potentially behind nodemon)

Running tsc on slow machine can takes some time.

Developers can get type checking error messages from the editor in realtime, so skipping type check on the build-flow should speed up iteration cycle without compromise.

It is a waste to do type checking twice in the cli build watcher and editor's language server.

Speed Comparison

Tested with ts-liveview v5

Environments

Env 1:

  • archlinux Desktop
  • btrfs on HDD

Env 2:

  • Mac mini (2014)
  • 2.6 GHz Dual-Core Intel i5
  • Macintosh HD (1TB SATA Disk)

Env 3:

  • Kudu3 laptop
  • archlinux
  • 6th Gen 2.6 GHz 4 Core Intel i7
  • zfs on top of lvm

Run Type

Fresh Build: Removed the outDir before run

Incremental Build: Keep the outDir from previous run

Comparison

EnvToolFresh BuildIncremental BuildImprovement
1tsc?4.3s?
1live-tsc?0.1s?
2tsc11.2s2.8s4x
2live-tsc0.36s0.22s1.6x
3tsc3.2s1.9s1.6x
3live-tsc0.152s0.148s1.02
EnvFresh bulid Speedup RateIncremtntal Build Speedup Rate
231x12x
321x12x

The time used is the average of multiple runs. In practice, the cold-start run time of fresh build is much longer if the Typescript files are not already cached by the OS.

You can run the speed test on your machine by running npx ts-node src/test/measure-speed.ts

Todo

The watch mode seems not working on mac mini, maybe use polling as fallback.

License

This project is licensed with BSD-2-Clause

This is free, libre, and open-source software. It comes down to four essential freedoms [ref]:

  • The freedom to run the program as you wish, for any purpose
  • The freedom to study how the program works, and change it so it does your computing as you wish
  • The freedom to redistribute copies so you can help others
  • The freedom to distribute copies of your modified versions to others
1.2.0

1 year ago

1.1.1

1 year ago

1.0.2

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.0

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.0.3

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago