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

feat: Add Bun and Deno to typescript support check #408

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,31 @@ jobs:
with:
license-check: true
lint: true
bun:
runs-on: ubuntu-latest
Codex- marked this conversation as resolved.
Show resolved Hide resolved
continue-on-error: true
steps:
- uses: actions/checkout@v4
Codex- marked this conversation as resolved.
Show resolved Hide resolved
with:
persist-credentials: false

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
# The erraneous typod version `5.0.0-aplha` takes priority over .3 as 'p' > 'l'
run: |
bun i --ignore-scripts
bun i -D --ignore-scripts [email protected]

- name: Run types check
run: bun run typescript

- name: Run Jest tests
run: bun run typescript:jest

- name: Run Vitest tests
run: bun run typescript:vitest

- name: Run unit tests
run: bun run unit:bun
5 changes: 4 additions & 1 deletion lib/find-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ function accumulatePlugin ({ file, type, opts, pluginTree, prefix }) {

function handleTypeScriptSupport (file, language, isHook = false) {
if (language === 'typescript' && !runtime.supportTypeScript) {
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.`)
throw new Error(
`@fastify/autoload cannot import ${isHook ? 'hooks ' : ''}plugin at '${file}'. ` +
'To fix this error transpile TypeScript to JavaScript or use an alternative loader/runtime to run your app.'
)
}
}

Expand Down
10 changes: 10 additions & 0 deletions lib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ function checkEnvVariable (name, value) {
: process.env[name] !== undefined
}

function isBun () {
return 'Bun' in globalThis
}

function isDeno () {
return 'Deno' in globalThis
}

const runtime = {}
// use Object.defineProperties to provide lazy load
Object.defineProperties(runtime, {
Expand Down Expand Up @@ -102,6 +110,8 @@ Object.defineProperties(runtime, {
get () {
cache.supportTypeScript ??= (
checkEnvVariable('FASTIFY_AUTOLOAD_TYPESCRIPT') ||
isBun() ||
isDeno() ||
runtime.tsNode ||
runtime.vitest ||
runtime.babelNode ||
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"typescript:vitest": "vitest run",
"typescript:vitest:dev": "vitest",
"unit": "node scripts/unit.js",
"unit:bun": "node scripts/unit.js bun",
"unit:with-modules": "tap plugin rm @tapjs/typescript && tap plugin list && tap build && tap test/issues/*/test.js test/commonjs/*.js test/module/*.js"
},
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion scripts/unit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict'

const { exec } = require('node:child_process')
const { argv } = require('node:process')

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

child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
Expand Down
Loading