Typescript node runtime powered by oxc-node
npm install @hairy/oxrunbash
npx oxrun hello.ts
`
or install as dependency
`bash
pnpm add oxrun -D
`
`json
{
"scripts": {
"dev": "oxrun scripts/dev.ts"
}
}
`
$3
oxrun supports watch mode with watch and this will automatically re-run your script whenever any of files under root dir changed.
`bash
npx oxrun watch hello.ts
`
$3
`ts
// hello.ts
const msg = 'hello'
console.log(msg)
export default msg
`
`js
// entry.js
import oxrun from 'oxrun'
(async () => {
await oxrun('./hello.ts') // output: hello
const mod = await oxrun.import('./hello.ts')
console.log(mod.default) // output: hello
})()
`
nuxlite use oxrun as typescript config file parser, and here is the source:
`ts
export async function resolveNuxliteConfig() {
const { default: config } = await oxrun.import<{ default: NuxliteConfig }>('./nuxlite.config.ts')
return defu(config, {
builder: 'rsbuild',
server: {
port: Number(process.env.NUXLITE_PORT) || 5173,
},
})
}
`
Props
$3
- Type: string | string[]
- Default: false
Watch can be a boolean or string (Can be set to a string of the path), empty string '' will be parse as a truthy value like true.
`sh
oxrun watch hello.ts --include ./other-dep.txt --include "./other-deps/*"
`
$3
- Type: string
- Default: undefined
`sh
oxrun watch hello.ts --exclude ./*/.test.js
`
Benchmark
`bash
cpu: Apple M2
runtime: node (arm64-darwin)
name hz min max mean p75 p99 p995 p999 rme samples
· oxrun 71.5572 1.1639 137.01 13.9748 16.0956 137.01 137.01 137.01 ±50.84% 40 fastest
· jiti (no-cache) 49.6227 0.6183 241.34 20.1521 9.4016 241.34 241.34 241.34 ±88.54% 30
· tsx (no-cache) 40.5017 2.3162 234.52 24.6903 16.3226 234.52 234.52 234.52 ±89.86% 23
· ts-node 19.4521 3.0683 238.53 51.4084 38.0820 238.53 238.53 238.53 ±104.82% 10 slowest
oxrun
1.44x faster than jiti (no-cache)
1.77x faster than tsx (no-cache)
3.68x faster than ts-node
`
Development
- Clone this repository
- Install dependencies using pnpm install
- Run pnpm build
- Run pnpm test`