Skip to content

Commit 5a6d882

Browse files
committed
feat: Add Bun and Deno to typescript support check
1 parent 688199d commit 5a6d882

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

lib/find-plugins.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ function accumulatePlugin ({ file, type, opts, pluginTree, prefix }) {
145145

146146
function handleTypeScriptSupport (file, language, isHook = false) {
147147
if (language === 'typescript' && !runtime.supportTypeScript) {
148-
throw new Error(`@fastify/autoload cannot import ${isHook ? 'hooks ' : ''}plugin at '${file}'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.`)
148+
throw new Error(
149+
`@fastify/autoload cannot import ${isHook ? 'hooks ' : ''}plugin at '${file}'. ` +
150+
'To fix this error transpile TypeScript to JavaScript or use an alternative loader/runtime to run your app.'
151+
)
149152
}
150153
}
151154

lib/runtime.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ function checkEnvVariable (name, value) {
3333
: process.env[name] !== undefined
3434
}
3535

36+
function isBun () {
37+
return 'Bun' in globalThis
38+
}
39+
40+
function isDeno () {
41+
return 'Deno' in globalThis
42+
}
43+
3644
const runtime = {}
3745
// use Object.defineProperties to provide lazy load
3846
Object.defineProperties(runtime, {
@@ -102,6 +110,8 @@ Object.defineProperties(runtime, {
102110
get () {
103111
cache.supportTypeScript ??= (
104112
checkEnvVariable('FASTIFY_AUTOLOAD_TYPESCRIPT') ||
113+
isBun() ||
114+
isDeno() ||
105115
runtime.tsNode ||
106116
runtime.vitest ||
107117
runtime.babelNode ||

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"typescript:esbuild": "node scripts/unit-typescript-esbuild.js",
1919
"typescript:vitest": "vitest run",
2020
"typescript:vitest:dev": "vitest",
21-
"unit": "node scripts/unit.js",
21+
"unit": "node scripts/unit.js npm",
22+
"unit:bun": "node scripts/unit.js bun",
2223
"unit:with-modules": "tap plugin rm @tapjs/typescript && tap plugin list && tap build && tap test/issues/*/test.js test/commonjs/*.js test/module/*.js"
2324
},
2425
"repository": {

scripts/unit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict'
22

33
const { exec } = require('node:child_process')
4+
const { argv } = require('node:process')
45

5-
const child = exec('npm run unit:with-modules')
6+
const child = exec(argv[2] + ' run unit:with-modules')
67

78
child.stdout.pipe(process.stdout)
89
child.stderr.pipe(process.stderr)

0 commit comments

Comments
 (0)