jiti
Runtime typescript and ESM support for Node.js (CommonJS)
Last updated 5 days ago by pi0 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install jiti 
SYNC missed versions from official npm registry.

jiti

Runtime typescript and ESM support for Node.js (CommonJS)

version downloads size

Features

  • Stable typescript and esm syntax support
  • Provide sync interface to replace require
  • Super slim and zero dependency
  • Syntax detect to avoid extra transform
  • CommonJS cache integration
  • Filesystem transpile cache + V8 compile cache

Usage

const jiti = require('jiti')(__filename)

jiti('./path/to/file.ts')

You can also pass options as second argument:

const jiti = require('jiti')(__filename, { debug: true })

Options

debug

  • Type: Boolean
  • Default: false
  • Environment Variable: JITI_DEBUG

Enable debug to see which files are transpiled

cache

  • Type: Boolean | String
  • Default: true
  • Environment Vriable: JITI_CACHE

Use transpile cache

If set to true will use node_modules/.cache/jiti (if exists) or {TMP_DIR}/node-jiti

transform

  • Type: Function
  • Default: Babel (lazy loaded)

Transform function. See src/babel for more details

Compared to Alternatives

standard-things/esm

  • + Much more stable thanks to babel
  • + Less low level operations
  • + Typescript support
  • - Slower (without cache)

babel-register

  • + Smaller install size (~1M vs ~11M with same plugins)
  • + Configured out of the box
  • + Smart syntax detect to avoid unnecessary trnaspilation
  • + Does not ignores node_modules. ESM everywhere yay!
  • + Embeddable

esbuild

  • + No native dependency
  • + More stable thanks to babel
  • - Slower
  • + Embeddable

ts-node

  • + Support both esm and typescript
  • / No typechecking support / Faster
  • + Smart syntax detect to avoid unnecessary transpilation

Native ESM Support (MJS)

  • It is not (yet) landed as a stable feature
  • No typescript support
  • Limitted to .mjs files with different executation context (no __filename, require, etc)

Bundlers (rollup, webpack, snowpack, etc)

Meanwhile it would be much better making an optimized bundle to deploy to production or as npm package, using bundler setup and watching is frustrating during project development that's where jiti (or similar tools like ts-node) would be more convenient.

Note: However currently only babel transform is supported, configurable transform support is in the roadmap so using esbuild or other solutions would be possible.

Development

  • Clone Repo
  • Run yarn
  • Run yarn build
  • Run yarn dev
  • Run node ./test/jiti.js

Roadmap

  • [x] Basic working
  • [x] Syntax detect and fallback to CJS require
  • [x] Improve project build system
  • [x] File system cache
  • [x] Configurable transform
  • [ ] Add tests
  • [ ] Support node -r jiti
  • [ ] esbuild support

License

MIT. Made with ????

Current Tags

  • 1.2.0                                ...           latest (5 days ago)

25 Versions

  • 1.2.0                                ...           5 days ago
  • 1.1.0                                ...           6 days ago
  • 1.0.0                                ...           7 days ago
  • 0.1.20                                ...           7 days ago
  • 0.1.19                                ...           20 days ago
  • 0.1.18                                ...           a month ago
  • 0.1.17                                ...           2 months ago
  • 0.1.16                                ...           2 months ago
  • 0.1.15                                ...           2 months ago
  • 0.1.14                                ...           2 months ago
  • 0.1.13                                ...           2 months ago
  • 0.1.12                                ...           3 months ago
  • 0.1.11                                ...           7 months ago
  • 0.1.10                                ...           7 months ago
  • 0.1.9                                ...           7 months ago
  • 0.1.8                                ...           7 months ago
  • 0.1.7                                ...           7 months ago
  • 0.1.6                                ...           7 months ago
  • 0.1.5                                ...           7 months ago
  • 0.1.4                                ...           7 months ago
  • 0.1.3                                ...           7 months ago
  • 0.1.2                                ...           7 months ago
  • 0.1.1                                ...           7 months ago
  • 0.1.0                                ...           7 months ago
  • 0.0.0                                ...           7 months ago
Maintainers (1)
Downloads
Today 1,713
This Week 3,576
This Month 18,778
Last Day 1,863
Last Week 8,373
Last Month 27,276
Dependencies (0)
None

Copyright 2014 - 2016 © taobao.org |