From 5a6d882c521f32751acd1dbaab0859fd8d9eb779 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Sun, 25 Aug 2024 02:22:46 +1200 Subject: [PATCH 1/6] feat: Add Bun and Deno to typescript support check --- lib/find-plugins.js | 5 ++++- lib/runtime.js | 10 ++++++++++ package.json | 3 ++- scripts/unit.js | 3 ++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/find-plugins.js b/lib/find-plugins.js index 631d8705..5180adeb 100644 --- a/lib/find-plugins.js +++ b/lib/find-plugins.js @@ -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.' + ) } } diff --git a/lib/runtime.js b/lib/runtime.js index ed3623f2..eacf8a2d 100644 --- a/lib/runtime.js +++ b/lib/runtime.js @@ -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, { @@ -102,6 +110,8 @@ Object.defineProperties(runtime, { get () { cache.supportTypeScript ??= ( checkEnvVariable('FASTIFY_AUTOLOAD_TYPESCRIPT') || + isBun() || + isDeno() || runtime.tsNode || runtime.vitest || runtime.babelNode || diff --git a/package.json b/package.json index 6a7304f9..3e9478b6 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/scripts/unit.js b/scripts/unit.js index dd9f74c5..12655278 100644 --- a/scripts/unit.js +++ b/scripts/unit.js @@ -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') child.stdout.pipe(process.stdout) child.stderr.pipe(process.stderr) From 5489d2c8a2eba05af55575db1c50a6692576c789 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Sun, 25 Aug 2024 04:21:45 +1200 Subject: [PATCH 2/6] test: use npm by default --- package.json | 2 +- scripts/unit.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3e9478b6..f66a3679 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "typescript:esbuild": "node scripts/unit-typescript-esbuild.js", "typescript:vitest": "vitest run", "typescript:vitest:dev": "vitest", - "unit": "node scripts/unit.js npm", + "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" }, diff --git a/scripts/unit.js b/scripts/unit.js index 12655278..d8bb9ebc 100644 --- a/scripts/unit.js +++ b/scripts/unit.js @@ -3,7 +3,7 @@ const { exec } = require('node:child_process') const { argv } = require('node:process') -const child = exec(argv[2] + ' run unit:with-modules') +const child = exec((argv[2] ?? 'npm') + ' run unit:with-modules') child.stdout.pipe(process.stdout) child.stderr.pipe(process.stderr) From 150fafa342769a0c290a31b984e688bd66cfdb16 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Sun, 25 Aug 2024 15:33:23 +1200 Subject: [PATCH 3/6] test: add bun job to ci --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f916409f..9fa3e99a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,3 +21,28 @@ jobs: with: license-check: true lint: true + bun: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - 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 fastify@5.0.0-alpha.3 + + - 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 From d51ddea351bc4c324330a07ca7669a01356059ae Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Sun, 25 Aug 2024 21:05:09 +1200 Subject: [PATCH 4/6] test: address feedback on workflow --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9fa3e99a..6db01e12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,8 +23,11 @@ jobs: lint: true bun: runs-on: ubuntu-latest + continue-on-error: true steps: - uses: actions/checkout@v4 + with: + persist-credentials: false - name: Setup Bun uses: oven-sh/setup-bun@v2 From a90cd47d16503caa6bab39043d0a99d687f13a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Tue, 10 Sep 2024 18:08:31 +0200 Subject: [PATCH 5/6] latest version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6db01e12..333ac6ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,7 @@ jobs: # 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 fastify@5.0.0-alpha.3 + bun i -D --ignore-scripts fastify@5.0.0-alpha.4 - name: Run types check run: bun run typescript From ed71226530f225af784a9253ef53055d73e00eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Tue, 10 Sep 2024 18:54:03 +0200 Subject: [PATCH 6/6] latest version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f66a3679..eaf7036b 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@types/tap": "^15.0.11", "esbuild": "^0.23.0", "esbuild-register": "^3.5.0", - "fastify": "^5.0.0-alpha.3", + "fastify": "^5.0.0-alpha.4", "fastify-plugin": "^5.0.0-pre.fv5.1", "jest": "^29.7.0", "snazzy": "^9.0.0",