-
-
Notifications
You must be signed in to change notification settings - Fork 75
feat: support native type stripping for Node >= v23 #442
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
Changes from 8 commits
4b319e5
0149866
6aedb09
3dd6a7c
1306b77
d7d65a0
eaedfe0
d148a86
7af7bb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| 'use strict' | ||
|
|
||
| const { exec } = require('node:child_process') | ||
| const runtime = require('../lib/runtime') | ||
|
|
||
| function common () { | ||
| const args = ['node', 'test/typescript-common/index.ts'] | ||
| const child = exec(args.join(' '), { | ||
| shell: true, | ||
| }) | ||
| child.stdout.pipe(process.stdout) | ||
| child.stderr.pipe(process.stderr) | ||
| child.once('close', esm) | ||
| } | ||
|
|
||
| function esm () { | ||
| const args = ['node', 'test/typescript-esm/forceESM.ts'] | ||
|
|
||
| const child = exec(args.join(' '), { | ||
| shell: true, | ||
| }) | ||
|
|
||
| child.stdout.pipe(process.stdout) | ||
| child.stderr.pipe(process.stderr) | ||
| child.once('close', process.exit) | ||
| } | ||
|
|
||
| if (runtime.nodeVersion >= 23) { | ||
| common() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,12 @@ | |
|
|
||
| const t = require('tap') | ||
| const fastify = require('fastify') | ||
| const runtime = require('../../lib/runtime') | ||
|
|
||
| const typeStrippingEnabled = runtime.nodeVersion >= 23 | ||
|
|
||
| t.test('independent of module support', function (t) { | ||
| t.plan(8) | ||
| t.plan(typeStrippingEnabled ? 7 : 8) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be removed when #440 is merged. |
||
| const app = fastify() | ||
|
|
||
| app.register(require('./syntax-error/app')) | ||
|
|
@@ -28,8 +31,12 @@ t.test('independent of module support', function (t) { | |
| app3.register(require('./ts-error/app')) | ||
|
|
||
| app3.ready(function (err) { | ||
| t.type(err, Error) | ||
| t.match(err.message, /cannot import plugin.*typescript/i) | ||
| if (typeStrippingEnabled) { | ||
| t.error(err) | ||
| } else { | ||
| t.type(err, Error) | ||
| t.match(err.message, /cannot import plugin.*typescript/i) | ||
| } | ||
| }) | ||
|
|
||
| const app4 = fastify() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { FastifyInstance } from 'fastify' | ||
|
|
||
| const { join } = require('node:path') | ||
| const fastifyAutoLoad = require('../../../index.js') | ||
|
|
||
| module.exports = function (fastify: FastifyInstance, _opts: any, next: any) { | ||
| fastify.register(fastifyAutoLoad, { | ||
| dir: join(__dirname, 'foo'), | ||
| }) | ||
|
|
||
| next() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 'use strict' | ||
|
|
||
| module.exports = function (fastify, _opts, next) { | ||
| fastify.get('/javascript', (_request, reply) => { | ||
| reply.send({ script: 'java' }) | ||
| }) | ||
|
|
||
| next() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // See https://github.com/fastify/fastify-autoload/issues/65 | ||
| declare const definitionFilesAreIncluded: never | ||
| export default definitionFilesAreIncluded |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module.exports = function (fastify: any, _opts, next) { | ||
| fastify.get('/typescript', (_request, reply) => { | ||
| reply.send({ script: 'type' }) | ||
| }) | ||
|
|
||
| next() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| const t = require('tap') | ||
jean-michelet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const fastify = require('fastify') | ||
|
|
||
| const basicApp = require('./basic/app.ts') | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extensions seems mandatory for ts file too. |
||
|
|
||
| t.plan(5) | ||
|
|
||
| const app = fastify() | ||
|
|
||
| app.register(basicApp) | ||
|
|
||
| app.ready(async function (err) { | ||
| t.error(err) | ||
|
|
||
| await app | ||
| .inject({ | ||
| url: '/javascript', | ||
| }) | ||
| .then(function (res: any) { | ||
| t.equal(res.statusCode, 200) | ||
| t.same(JSON.parse(res.payload), { script: 'java' }) | ||
| }) | ||
| .catch((err) => { | ||
| t.error(err) | ||
| }) | ||
|
|
||
| await app | ||
| .inject({ | ||
| url: '/typescript', | ||
| }) | ||
| .then(function (res: any) { | ||
| t.equal(res.statusCode, 200) | ||
| t.same(JSON.parse(res.payload), { script: 'type' }) | ||
| }) | ||
| .catch((err) => { | ||
| t.error(err) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify' | ||
| import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify' | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From API docs:
|
||
|
|
||
| export default function (fastify: FastifyInstance, _: object, next: (err?: Error) => void): void { | ||
| fastify.get('/installed', (_: FastifyRequest, reply: FastifyReply): void => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.