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: main
Choose a base branch
from
Open
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
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"typescript:esbuild": "node scripts/unit-typescript-esbuild.js",
"typescript:vitest": "vitest run",
"typescript:vitest:dev": "vitest",
"unit": "node scripts/unit.js",
"unit": "node scripts/unit.js npm",
"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] + ' run unit:with-modules')
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add npm as a default?

You'd need to add bun to CI as well.

Copy link
Author

Choose a reason for hiding this comment

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

Sure can

I was going to ask actually, so the CI currently uses that shared workflow from the workflows repo, so to not muddy concerns in that workflow, would you be happy with an additional job added to the ci.yml that performs the tests for bun?

jobs:
  test:
    uses: fastify/workflows/.github/workflows/[email protected]
    with:
      license-check: true
      lint: true
  bun:
    uses: ...

Copy link
Author

Choose a reason for hiding this comment

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

Went with adding a job to the existing workflow for now, the erroneously published version aplha takes precedence over alpha in string ordering so until it reaches beta the workflow needs to specifically install the version required for tests to satisfy the semver usage (since semver doesn't recognise aplha as a valid version)


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