Skip to content

Commit c089ca0

Browse files
authored
feat: experimental bun and deno support (#480)
* feat: add bun and deno * add condition to check first bun and deno, to ensure we dont automerge accidently * use hashes for gh actions * force swc * upgrade vitest * try to fix * fix? * fix? * fix? * fix? * fix? * fix? * fix? * fix? * fix? * fix? * fix? * fix? * fix? * fix? * fix? * fix accordingly * fix accordingly --------- Signed-off-by: Aras Abbasi <[email protected]>
1 parent 0e3b985 commit c089ca0

File tree

7 files changed

+116
-11
lines changed

7 files changed

+116
-11
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@ permissions:
2323
contents: read
2424

2525
jobs:
26+
bun:
27+
runs-on: ubuntu-latest
28+
continue-on-error: true
29+
steps:
30+
- uses: actions/checkout@v5
31+
with:
32+
persist-credentials: false
33+
34+
- name: Setup Bun
35+
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76
36+
37+
- name: Install dependencies
38+
run: bun install
39+
40+
- name: Run unit tests
41+
run: bun run typescript:bun
42+
43+
deno:
44+
runs-on: ubuntu-latest
45+
continue-on-error: true
46+
steps:
47+
- uses: actions/checkout@v5
48+
with:
49+
persist-credentials: false
50+
51+
- name: Setup Deno
52+
uses: denoland/setup-deno@e95548e56dfa95d4e1a28d6f422fafe75c4c26fb
53+
54+
- name: Install dependencies
55+
run: deno install
56+
57+
- name: Run unit tests
58+
run: deno run typescript:deno
59+
2660
test:
2761
permissions:
2862
contents: write

lib/runtime.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ function checkEnvVariable (name, value) {
3636
const runtime = {}
3737
// use Object.defineProperties to provide lazy load
3838
Object.defineProperties(runtime, {
39+
bun: {
40+
get () {
41+
cache.bun ??= 'Bun' in globalThis
42+
return cache.bun
43+
}
44+
},
45+
deno: {
46+
get () {
47+
cache.deno ??= 'Deno' in globalThis
48+
return cache.deno
49+
}
50+
},
3951
tsNode: {
4052
get () {
4153
cache.tsNode ??= (
@@ -108,6 +120,8 @@ Object.defineProperties(runtime, {
108120
get () {
109121
cache.supportTypeScript ??= (
110122
checkEnvVariable('FASTIFY_AUTOLOAD_TYPESCRIPT') ||
123+
runtime.bun ||
124+
runtime.deno ||
111125
runtime.tsNode ||
112126
runtime.vitest ||
113127
runtime.babelNode ||

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"lint:fix": "eslint --fix",
1111
"test": "npm run typescript && npm run typescript:native && npm run typescript:jest && npm run typescript:swc-node-register && npm run typescript:tsm && npm run typescript:tsx && npm run typescript:vitest && npm run typescript:esbuild && npm run unit",
1212
"typescript": "tsd",
13+
"typescript:bun": "bun scripts/unit-typescript-bun-esm.js",
14+
"typescript:deno": "deno -A scripts/unit-typescript-deno-esm.js",
1315
"typescript:jest": "jest",
1416
"typescript:esm": "node scripts/unit-typescript-esm.js",
1517
"typescript:swc-node-register": "node scripts/unit-typescript-swc-node-register.js",
@@ -75,8 +77,8 @@
7577
"devDependencies": {
7678
"@fastify/url-data": "^6.0.0",
7779
"@jsumners/line-reporter": "^1.0.1",
78-
"@swc-node/register": "^1.9.1",
79-
"@swc/core": "^1.5.25",
80+
"@swc-node/register": "1.11.1",
81+
"@swc/core": "1.13.20",
8082
"@types/jest": "^30.0.0",
8183
"@types/node": "^24.0.8",
8284
"borp": "^0.21.0",

scripts/unit-typescript-bun-esm.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict'
2+
3+
const { exec } = require('node:child_process')
4+
const { argv } = require('node:process')
5+
6+
const args = [
7+
argv[0],
8+
'test',
9+
'./test/typescript-esm/forceESM.ts'
10+
]
11+
12+
const child = exec(args.join(' '), {
13+
shell: true,
14+
env: {
15+
...process.env,
16+
TS_NODE_COMPILER_OPTIONS: JSON.stringify({
17+
module: 'ESNext',
18+
target: 'ES2020',
19+
allowJs: false,
20+
moduleResolution: 'node',
21+
esModuleInterop: true
22+
})
23+
}
24+
})
25+
26+
child.stdout.pipe(process.stdout)
27+
child.stderr.pipe(process.stderr)
28+
child.once('close', process.exit)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict'
2+
3+
const { exec } = require('node:child_process')
4+
const { argv } = require('node:process')
5+
6+
const args = [
7+
argv[0],
8+
'test',
9+
'-A',
10+
'./test/typescript-esm/forceESM.ts'
11+
]
12+
13+
const child = exec(args.join(' '), {
14+
shell: true,
15+
env: {
16+
...process.env,
17+
TS_NODE_COMPILER_OPTIONS: JSON.stringify({
18+
module: 'ESNext',
19+
target: 'ES2020',
20+
allowJs: false,
21+
moduleResolution: 'node',
22+
esModuleInterop: true
23+
})
24+
}
25+
})
26+
27+
child.stdout.pipe(process.stdout)
28+
child.stderr.pipe(process.stderr)
29+
child.once('close', process.exit)

scripts/unit-typescript-swc-node-register.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const { exec } = require('node:child_process')
44

55
const args = [
66
'node',
7-
'--require=@swc-node/register',
7+
'-r',
8+
'@swc-node/register',
89
'test/typescript/basic.ts'
910
]
1011

test/typescript-esm/forceESM.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test, { describe, before, after } from 'node:test'
1+
import { describe, test } from 'node:test'
22
import assert from 'node:assert'
33
import fastify from 'fastify'
44

@@ -10,18 +10,15 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
1010

1111
describe('typescript/basic test suite', function () {
1212
const app = fastify()
13-
before(async function () {
13+
14+
test('should load routes and respond correctly', async function () {
1415
app.register(fastifyAutoLoad, { dir: resolve(__dirname, 'app'), forceESM: true })
1516
await app.ready()
16-
})
1717

18-
after(async function () {
19-
await app.close()
20-
})
21-
22-
test('should load routes and respond correctly', async function () {
2318
const res = await app.inject({ url: '/installed' })
2419
assert.strictEqual(res.statusCode, 200)
2520
assert.deepStrictEqual(JSON.parse(res.payload), { result: 'ok' })
21+
22+
await app.close()
2623
})
2724
})

0 commit comments

Comments
 (0)