https://github.com/nlibjs/tsm
node --import=@nlib/tsm your-script.ts
https://github.com/nlibjs/tsm
esmodules nodejs testing typescript
Last synced: 5 months ago
JSON representation
node --import=@nlib/tsm your-script.ts
- Host: GitHub
- URL: https://github.com/nlibjs/tsm
- Owner: nlibjs
- Created: 2023-09-01T02:20:27.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-01T19:40:46.000Z (11 months ago)
- Last Synced: 2025-08-01T21:43:58.302Z (11 months ago)
- Topics: esmodules, nodejs, testing, typescript
- Language: JavaScript
- Homepage:
- Size: 558 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# @nlib/tsm
Thin .mts loader and test runner
[](https://github.com/nlibjs/tsm/actions/workflows/test.yml)
[](https://codecov.io/gh/nlibjs/tsm)
## Install
```
npm install @nlib/tsm
```
## Usage: Run \*.ts/\*.mts file
```
node --import=@nlib/tsm path/to/your/script.mts
```
`@nlib/tsm` exports `register.mjs` which [registers](https://nodejs.org/api/module.html#moduleregisterspecifier-parenturl-options) `loader.mjs`. `loader.mjs` is a [loader](https://nodejs.org/api/esm.html#loaders) to customize the default module resolution. It exports the [`load`](https://nodejs.org/api/esm.html#loadurl-context-nextload) function that loads modules with [esbuild](https://esbuild.github.io/).
## Usage: Run test files
Node.js added the stable [`node:test`](https://nodejs.org/api/test.html) in v20. We can run tests with `node --test`. It searches for test files when a directory is specified as arguments. But it doesn't search for `*.mts` (even with the `--experimental-loader` option). So, you must pass the files one by one to run it.
The `tsm-test` will search for the test files for you and pass them to `node --test`.
```sh
npx tsm-test src
```