Skip to content

Commit efe32ac

Browse files
authored
chore: remove fastify-cli (#129)
* chore: remove fastify-cli helper from test helper * chore: remove unused options configuration from app.ts * chore: update start and dev scripts, remove fastify-cli dependency * chore: add pino-pretty dev dependency * chore: add type annotation for error handler in serviceApp * chore: remove unnecessary env-file option from start script
1 parent b446505 commit efe32ac

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
"test": "test"
99
},
1010
"scripts": {
11-
"start": "npm run build && fastify start -l info dist/app.js",
11+
"start": "npm run build && node dist/server.js",
1212
"build": "tsc",
1313
"watch": "tsc -w",
14-
"dev": "npm run build && concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"yellow.bold,cyan.bold\" \"npm:watch\" \"npm:dev:start\"",
15-
"dev:start": "npm run build && fastify start --ignore-watch=.ts$ -w -l info -P dist/app.js",
14+
"dev": "tsx --env-file=.env ./src/server.ts",
1615
"test": "npm run db:seed && c8 npm run test:run",
1716
"test:run": "glob -c \"tsx --test\" \"./test/**/*.ts\"",
18-
"standalone": "npm run build && node --env-file=.env dist/server.js",
1917
"lint": "eslint --ignore-pattern=dist",
2018
"lint:fix": "npm run lint -- --fix",
2119
"db:create": "tsx --env-file=.env ./scripts/create-database.ts",
@@ -54,7 +52,6 @@
5452
"concurrently": "^9.2.1",
5553
"csv-stringify": "^6.6.0",
5654
"fastify": "^5.6.0",
57-
"fastify-cli": "^7.4.0",
5855
"fastify-plugin": "^5.0.1",
5956
"knex": "^3.1.0",
6057
"mysql2": "^3.15.0",
@@ -69,6 +66,7 @@
6966
"form-data": "^4.0.4",
7067
"glob": "^11.0.3",
7168
"neostandard": "^0.12.2",
69+
"pino-pretty": "^13.1.2",
7270
"tsx": "^4.20.5",
7371
"typescript": "~5.9.2"
7472
}

src/app.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@
44

55
import path from 'node:path'
66
import fastifyAutoload from '@fastify/autoload'
7-
import { FastifyInstance, FastifyPluginOptions } from 'fastify'
8-
9-
export const options = {
10-
ajv: {
11-
customOptions: {
12-
coerceTypes: 'array',
13-
removeAdditional: 'all'
14-
}
15-
}
16-
}
7+
import { FastifyError, FastifyInstance, FastifyPluginOptions } from 'fastify'
178

189
export default async function serviceApp (
1910
fastify: FastifyInstance,
@@ -44,7 +35,7 @@ export default async function serviceApp (
4435
options: { ...opts }
4536
})
4637

47-
fastify.setErrorHandler((err, request, reply) => {
38+
fastify.setErrorHandler((err: FastifyError, request, reply) => {
4839
fastify.log.error(
4940
{
5041
err,

test/helper.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { FastifyInstance, InjectOptions, LightMyRequestResponse } from 'fastify'
2-
import { build as buildApplication } from 'fastify-cli/helper.js'
3-
import path from 'node:path'
1+
import Fastify, { FastifyInstance, InjectOptions, LightMyRequestResponse } from 'fastify'
2+
import fp from 'fastify-plugin'
43
import { TestContext } from 'node:test'
5-
import { options as serverOptions } from '../src/app.js'
4+
import serviceApp from '../src/app.js'
65
import assert from 'node:assert'
76

87
declare module 'fastify' {
@@ -12,8 +11,6 @@ declare module 'fastify' {
1211
}
1312
}
1413

15-
const AppPath = path.join(import.meta.dirname, '../src/app.ts')
16-
1714
// Fill in this config with all the configurations
1815
// needed for testing the application
1916
export function config () {
@@ -68,17 +65,11 @@ async function injectWithLogin (
6865

6966
// automatically build and tear down our instance
7067
export async function build (t?: TestContext) {
71-
// you can set all the options supported by the fastify CLI command
72-
const argv = [AppPath]
73-
74-
// fastify-plugin ensures that all decorators
75-
// are exposed for testing purposes, this is
76-
// different from the production setup
77-
const app = (await buildApplication(
78-
argv,
79-
config(),
80-
serverOptions
81-
)) as FastifyInstance
68+
const app = Fastify()
69+
70+
app.register(fp(serviceApp), config())
71+
72+
await app.ready()
8273

8374
// This is after start, so we can't decorate the instance using `.decorate`
8475
app.login = login

0 commit comments

Comments
 (0)