Runtime Typescript and ESM support for Node.js.
Kazuya is forked from jiti. It uses sucrase instaed of babel.
Sucrase is an alternative to Babel that allows super-fast development builds. It has better performance and smaller size, and supports only a subset of features to help you avoid unnecessary transforms.
Pros:
- Faster loading time
- Smaller bundle size
Cons:
- Less features (Does not support import.meta and decorators)
- No support for older node versions
- No sourcemap support
- No custom transform support
- Seamless typescript and ESM syntax support
- Seamless interoperability between ESM and CommonJS
- Synchronous API to replace
require
- Super slim and zero dependency
- Smart syntax detection to avoid extra transforms
- CommonJS cache integration
- Filesystem transpile hard cache
- V8 compile cache
- Custom resolve alias
const { createKazuya } = require("kazuya");
const kazuya = createKazuya(__filename);
kazuya("./path/to/file.ts");
You can also pass options as second argument:
const { createKazuya } = require("kazuya");
const kazuya = createKazuya(__filename, { debug: true });
kazuya index.ts
# or npx kazuya index.ts
node -r kazuya/register index.ts
Alternatively, you can register kazuya
as a require hook programmatically:
const { createKazuya } = require("kazuya");
const kazuya = createKazuya();
const unregister = kazuya.register();
- Type: Boolean
- Default:
false
- Environment Variable:
KAZUYA_DEBUG
Enable debug to see which files are transpiled.
- Type: Boolean | String
- Default:
true
- Environment Variable:
KAZUYA_CACHE
Use transpile cache
If set to true
will use node_modules/.cache/kazuya
(if exists) or {TMP_DIR}/node-kazuya
.
- Type: Boolean | String
- Default:
false
- Environment Variable:
KAZUYA_ESM_RESOLVE
Using esm resolution algorithm to support import
condition.
- Type: Boolean
- Default:
false
Return the .default
export of a module at the top-level.
- Type: Object
- Default: -
- Environment Variable:
KAZUYA_ALIAS
Custom alias map used to resolve ids.
- Type: Array
- Default:
["typescript"]
- Environment Variable:
KAZUYA_NATIVE_MODULES
List of modules (within node_modules
) to always use native require for them.
- Type: Array
- Default:
[]
- Environment Variable:
KAZUYA_TRANSFORM_MODULES
List of modules (within node_modules
) to transform them regardless of syntax.
- Clone this repository
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
- Run
pnpm watch
- Run
pnpm kazuya ./test/path/to/file.ts
Forked from jiti.