Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 241e2cf

Browse files
fix: use TSN_ESBUILD env instead of tsn2 bin
1 parent 9439f5d commit 241e2cf

5 files changed

Lines changed: 17 additions & 187 deletions

File tree

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"prepare": "husky install",
55
"debug": "tsn ./src/bin/tsn.ts",
66
"tsn-debug": "tsc && CLI_DEBUG=1 node ./dist/bin/tsn.js testscript.ts",
7-
"tsn2-debug": "tsc && CLI_DEBUG=1 node ./dist/bin/tsn2.js testscript.ts"
7+
"tsn-debug-esbuild": "tsc && CLI_DEBUG=1 TSN_ESBUILD=1 node ./dist/bin/tsn.js testscript.ts"
88
},
99
"dependencies": {
1010
"@naturalcycles/nodejs-lib": "^12.8.0",
@@ -32,7 +32,6 @@
3232
],
3333
"main": "dist/index.js",
3434
"bin": {
35-
"tsn2": "dist/bin/tsn2.js",
3635
"tsn": "dist/bin/tsn.js"
3736
},
3837
"publishConfig": {

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
`-T -r tsconfig-paths/register -r dotenv/config`. Will use `./scripts/tsconfig.json` (file will be
1717
auto-generated in not present).
1818

19-
- `tsn2` is an experimental version of `tsn` that uses `esbuild` and `esbuild-register` instead of
20-
`typescript` and `ts-node`.
19+
Set `TSN_ESBUILD` env variable to enable experimental `esbuild` transpilation, using `esbuild` and
20+
`esbuild-register` instead of `typescript` and `ts-node`.
2121

2222
# Packaging
2323

scripts/testscript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
33
yarn tsn-debug
4-
yarn tsn2-debug
4+
yarn tsn-debug-esbuild
55
66
*/
77

src/bin/tsn.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import * as fs from 'fs'
88
import * as path from 'path'
99
import type * as nodejsLib from '@naturalcycles/nodejs-lib/dist/fs'
1010
import * as c from 'chalk'
11-
import * as tsnode from 'ts-node'
1211

1312
const projectDir = path.join(__dirname, '../..')
1413
const cfgDir = `${projectDir}/cfg`
15-
const { CLI_DEBUG } = process.env
14+
const { CLI_DEBUG, TSN_ESBUILD } = process.env
1615

1716
try {
1817
main()
@@ -60,10 +59,18 @@ function main(): void {
6059
require('loud-rejection/register')
6160
require('dotenv/config')
6261

63-
tsnode.register({
64-
transpileOnly: true,
65-
project: projectTsconfigPath,
66-
})
62+
if (TSN_ESBUILD) {
63+
const { register } = require('esbuild-register/dist/node')
64+
register({
65+
tsconfigRaw: fs.readFileSync(projectTsconfigPath, 'utf8'),
66+
})
67+
} else {
68+
const tsnode = require('ts-node')
69+
tsnode.register({
70+
transpileOnly: true,
71+
project: projectTsconfigPath,
72+
})
73+
}
6774

6875
if (fs.existsSync(`./node_modules/tsconfig-paths`)) {
6976
// ok, for the `paths` it works to load from the root `tsconfig` too

src/bin/tsn2.ts

Lines changed: 0 additions & 176 deletions
This file was deleted.

0 commit comments

Comments
 (0)