Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for @swc-node/register #259

Merged
merged 1 commit into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const pkgUp = require('pkg-up')
const isTsNode = (Symbol.for('ts-node.register.instance') in process) || !!process.env.TS_NODE_DEV
const isJestEnvironment = process.env.JEST_WORKER_ID !== undefined
const isSWCRegister = process._preload_modules && process._preload_modules.includes('@swc/register')
const isSWCNodeRegister = process._preload_modules && process._preload_modules.includes('@swc-node/register')
const isSWCNode = typeof process.env._ === 'string' && process.env._.includes('.bin/swc-node')
const isTsm = process._preload_modules && process._preload_modules.includes('tsm')
const isTsx = process._preload_modules && process._preload_modules.toString().includes('tsx')
const typescriptSupport = isTsNode || isJestEnvironment || isSWCRegister || isSWCNode || isTsm || isTsx
const typescriptSupport = isTsNode || isJestEnvironment || isSWCRegister || isSWCNodeRegister || 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,11 +7,12 @@
"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 && npm run typescript:tsx",
"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:swc-node-register && 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:swc-node-register": "node scripts/unit-typescript-swc-node-register.js",
"typescript:tsm": "node scripts/unit-typescript-tsm.js",
"typescript:tsx": "node scripts/unit-typescript-tsx.js",
"unit": "node scripts/unit.js",
Expand Down Expand Up @@ -42,6 +43,7 @@
"devDependencies": {
"@fastify/pre-commit": "^2.0.2",
"@fastify/url-data": "^5.0.0",
"@swc-node/register": "^1.5.1",
"@swc/core": "^1.2.129",
"@swc/register": "^0.1.9",
"@types/jest": "^28.1.6",
Expand Down
21 changes: 21 additions & 0 deletions scripts/unit-typescript-swc-node-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

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

if (semver.satisfies(process.version, '>= 14')) {
const args = [
'tap',
'--node-arg=--require=@swc-node/register',
'--no-coverage',
'test/typescript/*.ts'
]

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

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