Skip to content

transloadit/ts-fly

Repository files navigation

@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

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.

yarn ts-fly myFile.ts

You can use it with --require CLI flag:

node -r @transloadit/ts-fly myFile.ts

You can also require it from 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.
  • 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

corepack yarn
corepack yarn test

Based on