Skip to content

Commit 2723ff5

Browse files
authored
Refactor fastify-vite internals and improve code quality (#388)
- Rename Vite class to FastifyViteDecoration for clarity - Rename this.config to this.runtimeConfig to distinguish from Vite config - Refactor mode setup functions to accept context object instead of using `this` binding, improving testability and type safety - Extract shared FastifyViteDecorationPriorToSetup interface and hasIterableRoutes helper to new support.ts module - Move loadBundle and loadEntries to module scope in production mode - Simplify development.ts by importing vite at module level Code quality improvements: - Remove unused variables and function parameters across codebase - Add typescript/consistent-type-definitions eslint rule - Convert type aliases to interfaces where appropriate - Use type-only imports where applicable - Extend oxlint with additional plugins (eslint, oxc, typescript, unicorn) Testing: - Enable production mode tests - Add vitest globalSetup to build test fixtures before running tests
1 parent e0d99ac commit 2723ff5

File tree

35 files changed

+339
-298
lines changed

35 files changed

+339
-298
lines changed

.oxlintrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"categories": {
44
"correctness": "error"
55
},
6-
"plugins": ["import"],
6+
"plugins": ["eslint", "import", "oxc", "typescript", "unicorn"],
77
"rules": {
88
"import/extensions": [
99
"error",
@@ -12,6 +12,7 @@
1212
"ignorePackages": true
1313
}
1414
],
15-
"no-unused-vars": "warn"
15+
"no-unused-vars": "warn",
16+
"typescript/consistent-type-definitions": "error"
1617
}
1718
}

examples/middie-compat/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function mainMiddieFirst(dev) {
2525
return reply.html()
2626
})
2727

28-
server.get('/middleware-test', (req, reply) => {
28+
server.get('/middleware-test', (req) => {
2929
return { customMiddleware: req.raw.customMiddleware ?? false }
3030
})
3131

@@ -56,7 +56,7 @@ export async function mainViteFirst(dev) {
5656
return reply.html()
5757
})
5858

59-
server.get('/middleware-test', (req, reply) => {
59+
server.get('/middleware-test', (req) => {
6060
return { customMiddleware: req.raw.customMiddleware ?? false }
6161
})
6262

examples/react-next-mini/renderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
createRoute,
1212
}
1313

14-
function createRoute({ handler, errorHandler, route }, scope, config) {
14+
function createRoute({ handler, errorHandler, route }, scope) {
1515
if (route.getServerSideProps) {
1616
// If getServerSideProps is provided, register JSON endpoint for it
1717
scope.get(`/json${route.path}`, async (req, reply) => {
@@ -27,7 +27,7 @@ function createRoute({ handler, errorHandler, route }, scope, config) {
2727
// If getServerSideProps is provided,
2828
// make sure it runs before the SSR route handler
2929
...(route.getServerSideProps && {
30-
async preHandler(req, reply) {
30+
async preHandler(req) {
3131
req.serverSideProps = await route.getServerSideProps({
3232
req,
3333
fetchJSON: scope.fetchJSON,

examples/react-streaming/client/views/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Link } from 'react-router'
33
import { useAtom } from 'jotai'
44
import { todoList } from '../state.js'
55

6-
export default function Index(props) {
6+
export default function Index() {
77
const [state, updateState] = useAtom(todoList)
88
const [input, setInput] = useState(null)
99
const addItem = async () => {

examples/react-streaming/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
}
2323

2424
// The return value of this function gets registered as reply.html()
25-
async function createHtmlFunction(source, scope, config) {
25+
async function createHtmlFunction(source) {
2626
const [headSource, footer] = source.split('<!-- element -->')
2727
const headTemplate = await createHtmlTemplateFunction(headSource)
2828
return function ({ stream, data }) {

examples/vue-hydration/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function foobarHook(req) {
1212
req.server.log.info(`Hello from ${req.url} and foobarHook`)
1313
}
1414

15-
function createRoute({ handler, errorHandler, route }, scope, config) {
15+
function createRoute({ handler, errorHandler, route }, scope) {
1616
scope.route({
1717
url: route.path,
1818
method: 'GET',

examples/vue-hydration/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Fastify from 'fastify'
22
import FastifyVite from '@fastify/vite'
33
import renderer from './renderer.js'
44

5-
export async function main(dev) {
5+
export async function main() {
66
const server = Fastify({
77
logger: {
88
transport: {

examples/vue-next-mini/renderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function prepareServer(server) {
1616
server.log.info('prepareServer() hook picked up from configuration!')
1717
}
1818

19-
async function createRoute({ handler, errorHandler, route }, scope, config) {
19+
async function createRoute({ handler, errorHandler, route }, scope) {
2020
if (route.configure) {
2121
await route.configure(scope)
2222
}
@@ -35,7 +35,7 @@ async function createRoute({ handler, errorHandler, route }, scope, config) {
3535
// If getServerSideProps is provided,
3636
// make sure it runs before the SSR route handler
3737
...(route.getServerSideProps && {
38-
async preHandler(req, reply) {
38+
async preHandler(req) {
3939
req.serverSideProps = await route.getServerSideProps({
4040
req,
4141
ky: scope.ky,

examples/vue-streaming/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default {
2121
}
2222

2323
// The return value of this function gets registered as reply.html()
24-
async function createHtmlFunction(source, scope, config) {
24+
async function createHtmlFunction(source) {
2525
const [headSource, footer] = source.split('<!-- element -->')
2626
const headTemplate = await createHtmlTemplateFunction(headSource)
2727
return function ({ stream, data }) {

examples/vue-vanilla-ts/globals.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare module '*.vue' {
2-
import { DefineComponent } from 'vue'
2+
import type { DefineComponent } from 'vue'
33
const component: DefineComponent<{}, {}, any>
44
export default component
55
}

0 commit comments

Comments
 (0)