Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions lib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,17 @@ Object.defineProperties(runtime, {
runtime.tsx ||
runtime.esbuild ||
runtime.tsimp ||
runtime.nodeVersion >= 23
runtime.supportNativeTypeScript
)
return cache.supportTypeScript
}
},
supportNativeTypeScript: {
get () {
cache.supportNativeTypeScript ??= process.features.typescript !== false
return cache.supportNativeTypeScript
}
},
forceESM: {
get () {
cache.forceESM ??= (
Expand All @@ -132,12 +138,6 @@ Object.defineProperties(runtime, {
return cache.forceESM
}
},
nodeVersion: {
get () {
cache.nodeVersion ??= Number(process.version.split('.')[0].slice(1))
return cache.nodeVersion
},
},
})

module.exports = runtime
Expand Down
8 changes: 4 additions & 4 deletions scripts/unit-typescript-native-type-stripping.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
const { exec } = require('node:child_process')
const runtime = require('../lib/runtime')

if (runtime.supportNativeTypeScript) {
common()
}

function common () {
const args = ['node', 'test/typescript-common/index.ts']
const child = exec(args.join(' '), {
Expand All @@ -24,7 +28,3 @@ function esm () {
child.stderr.pipe(process.stderr)
child.once('close', process.exit)
}

if (runtime.nodeVersion >= 23) {
common()
}
5 changes: 3 additions & 2 deletions scripts/unit-typescript-tsx.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict'

const { exec } = require('node:child_process')
const runtime = require('../lib/runtime')

const nodeVersion = Number(process.version.split('.')[0].slice(1))
Comment on lines -4 to +5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed nodeVersion from runtime because it is only used here and prevent to reach 100% coverage on the main test suite.


const args = [
'npx',
runtime.nodeVersion >= 18 ? '--node-options=--import=tsx' : '',
nodeVersion >= 18 ? '--node-options=--import=tsx' : '',
'tsnd',
'test/typescript/basic.ts'
]
Expand Down
4 changes: 1 addition & 3 deletions test/commonjs/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const Fastify = require('fastify')

const runtime = require('../../lib/runtime')

const typeStrippingEnabled = runtime.nodeVersion >= 23

describe('independent module support - unexpected token', function () {
const app = Fastify()

Expand Down Expand Up @@ -52,7 +50,7 @@ describe('independent module support - cannot import plugin typescript', functio
})

it('should return cannot import plugin typescript error', async function () {
if (typeStrippingEnabled) {
if (runtime.supportNativeTypeScript) {
assert.doesNotThrow(() => app.ready())
} else {
await assert.rejects(app.ready(), Error, /cannot import plugin.*typescript/i)
Expand Down
2 changes: 1 addition & 1 deletion test/issues/369/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Issue 369 tests', async function () {
dir: path.join(__dirname, 'invalid-index-type'),
autoHooks: true,
})
if (runtime.nodeVersion >= 23) {
if (runtime.supportNativeTypeScript) {
assert.doesNotThrow(() => app.ready())
} else {
await assert.rejects(
Expand Down
2 changes: 1 addition & 1 deletion test/typescript-common/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use script'

const t = require('tap')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird that it didn't fail previously 🤔

const { test: t } = require('node:test')
const fastify = require('fastify')

const basicApp = require('./basic/app.ts')
Expand Down
Loading