https://github.com/transloadit/ts-fly
Run TS on-the-fly on Node.js
https://github.com/transloadit/ts-fly
Last synced: 9 months ago
JSON representation
Run TS on-the-fly on Node.js
- Host: GitHub
- URL: https://github.com/transloadit/ts-fly
- Owner: transloadit
- Created: 2023-05-16T14:12:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-13T14:09:14.000Z (almost 2 years ago)
- Last Synced: 2025-03-24T01:25:15.198Z (10 months ago)
- Language: JavaScript
- Size: 65.4 KB
- Stars: 3
- Watchers: 8
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @transloadit/ts-fly
`ts-fly` is a simple wrapper around Node.js that registers [Sucrase][] hooks,
making it possible to run TypeScript files in addition to JavaScript files
transparently. The difference with Sucrase is that it would let you import
ESM-only libraries, as well as `.ts` files.
TypeScript and JavaScript files can also import each other.
Do not use this on production: Sucrase devs already recommend you not to run
their code on production, the code we're adding in this repo is even more unsafe
and tailored to Transloadit needs. If you do, you are on your own.
## Install
```sh
yarn add --dev @transloadit/ts-fly
```
## Usage
Use the `ts-fly` command the same as you would use `node`. Any CLI arguments are
passed along.
```sh
yarn ts-fly myFile.ts
```
You can use it with `--require` CLI flag:
```sh
node -r @transloadit/ts-fly myFile.ts
```
You can also `require` it from JS:
```js
'use strict';
require('@transloadit/ts-fly').defaultHooks();
require('./myFile.ts'); // works
```
### Limitations
- You can't import `.ts` files from ESM. If you want to use ESM syntax, you have
convert the file to TS and use `.ts` file extension, or use
[`createRequire`](https://nodejs.org/api/module.html#modulecreaterequirefilename).
- By default, we only support `.js` and `.ts` file extensions.
- Windows would only support the `node -r @transloadit/ts-fly …` form, as the
executable is a POSIX shell script.
- Only literal specifiers which start with `./` and do not contain any `'` or
`"` char are fully supported. Support for dynamic imports with dynamic
specifiers is limited.
## Contributing
```sh
corepack yarn
corepack yarn test
```
## Based on
-
-
[Sucrase]: https://github.com/alangpierce/sucrase