Skip to content

Commit

Permalink
feat: add tsx support (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
wd-David authored Jul 9, 2022
1 parent f3b712e commit 7acc091
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const isJestEnvironment = process.env.JEST_WORKER_ID !== undefined
const isSWCRegister = process._preload_modules && process._preload_modules.includes('@swc/register')
const isSWCNode = typeof process.env._ === 'string' && process.env._.includes('.bin/swc-node')
const isTsm = process._preload_modules && process._preload_modules.includes('tsm')
const typescriptSupport = isTsNode || isJestEnvironment || isSWCRegister || isSWCNode || isTsm
const isTsx = process._preload_modules && process._preload_modules.toString().includes('tsx')
const typescriptSupport = isTsNode || isJestEnvironment || isSWCRegister || isSWCNode || isTsm || isTsx
const routeParamPattern = /\/_/ig
const routeMixedParamPattern = /__/g

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"scripts": {
"lint": "standard | snazzy",
"lint:fix": "standard --fix | snazzy",
"test": "npm run lint && npm run unit && npm run typescript && npm run typescript:jest && npm run typescript:esm && npm run typescript:swc && npm run typescript:tsm",
"test": "npm run lint && npm run unit && npm run typescript && npm run typescript:jest && npm run typescript:esm && npm run typescript:swc && npm run typescript:tsm && npm run typescript:tsx",
"typescript": "tsd",
"typescript:jest": "jest",
"typescript:esm": "node scripts/unit-typescript-esm.js",
"typescript:swc": "node scripts/unit-typescript-swc.js",
"typescript:tsm": "node scripts/unit-typescript-tsm.js",
"typescript:tsx": "node scripts/unit-typescript-tsx.js",
"unit": "node scripts/unit.js",
"unit:with-modules": "tap test/commonjs/*.js test/module/*.js test/typescript/*.ts",
"unit:without-modules": "tap test/commonjs/*.js test/typescript/*.ts"
Expand Down Expand Up @@ -57,6 +58,7 @@
"ts-node-dev": "^2.0.0",
"tsd": "^0.22.0",
"tsm": "^2.2.1",
"tsx": "^3.7.1",
"typescript": "^4.5.4"
},
"dependencies": {
Expand Down
20 changes: 20 additions & 0 deletions scripts/unit-typescript-tsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const { exec } = require('child_process')
const semver = require('semver')

if (semver.satisfies(process.version, '>= 14')) {
const args = [
'npx',
'tsx',
'test/typescript/basic.ts'
]

const child = exec(args.join(' '), {
shell: true
})

child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
child.once('close', process.exit)
}

0 comments on commit 7acc091

Please sign in to comment.