From 78f7ac7fc75d4412c0c1bc123804bcb86b36c3aa Mon Sep 17 00:00:00 2001 From: Jackson Hoffart Date: Wed, 5 Nov 2025 12:09:25 +0000 Subject: [PATCH 1/6] fix: resolve TypeScript errors in Vite config --- vite.config.ts | 80 +++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index b2fc9f97..a948d600 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,5 +1,6 @@ import { defineConfig, Plugin, version as viteVersion } from "vite"; -import type { PluginContext, ViteDevServer } from "vite"; +import type { ViteDevServer } from "vite"; +import type { PluginContext } from 'rollup'; import react from "@vitejs/plugin-react"; import { simpleGit } from "simple-git"; import os from "os"; @@ -77,7 +78,7 @@ const getGitInfo = async (): Promise<{ // Fallback to environment variables or defaults return { sha: getEnv("VITE_GIT_SHA", "unknown"), - isClean: getEnv("VITE_GIT_CLEAN", "unknown"), + isClean: getEnv("VITE_GIT_CLEAN", "false") === "true", branch: getEnv("VITE_GIT_BRANCH", "unknown"), }; } @@ -128,8 +129,8 @@ function buildInfoPlugin(): Plugin { function dataValidationPlugin(dir: string = "src/data") { return { name: "data-validation", - apply: "build", - enforce: "pre", + apply: "build" as const, + enforce: "pre" as const, async buildStart(this: PluginContext) { const names = (await fs.readdir(dir)).filter((f) => f.endsWith(".json")); const entries: FileEntry[] = []; @@ -184,12 +185,51 @@ function dataValidationPlugin(dir: string = "src/data") { }; } +// Create a new plugin for serving schema files +function schemaServePlugin(): Plugin { + return { + name: 'schema-serve', + configureServer(server: ViteDevServer) { + server.middlewares.use( + "/schema", + ( + req: IncomingMessage, + res: ServerResponse, + next: (err?: unknown) => void, + ): void => { + try { + const baseDir = resolve("src/schema"); + const relPath = decodeURIComponent( + (req.url || "").replace(/^\/schema\/?/, ""), + ); + if (!relPath) return next(); // no file requested, let Vite handle + const absPath = resolve(baseDir, relPath); + // prevent path traversal + if (!absPath.startsWith(baseDir)) return next(); + // only serve JSON files + if (!absPath.endsWith(".json")) return next(); + readFile(absPath, "utf8") + .then((json) => { + res.setHeader("Content-Type", "application/json"); + res.end(json); + }) + .catch(next); + } catch (err) { + next(err); + } + }, + ); + }, + }; +} + // https://vitejs.dev/config/ export default defineConfig({ plugins: [ react(), buildInfoPlugin(), dataValidationPlugin("src/data"), + schemaServePlugin(), viteStaticCopy({ // Copy the entire schema dir to /schema in the built output targets: [{ src: "src/schema/**/*", dest: "schema" }], @@ -199,36 +239,4 @@ export default defineConfig({ open: true, port: 3000, }, - configureServer(server: ViteDevServer) { - // Serve any file under src/schema at /schema/* during dev - server.middlewares.use( - "/schema", - ( - req: IncomingMessage, - res: ServerResponse, - next: (err?: unknown) => void, - ): void => { - try { - const baseDir = resolve("src/schema"); - const relPath = decodeURIComponent( - (req.url || "").replace(/^\/schema\/?/, ""), - ); - if (!relPath) return next(); // no file requested, let Vite handle - const absPath = resolve(baseDir, relPath); - // prevent path traversal - if (!absPath.startsWith(baseDir)) return next(); - // only serve JSON files - if (!absPath.endsWith(".json")) return next(); - readFile(absPath, "utf8") - .then((json) => { - res.setHeader("Content-Type", "application/json"); - res.end(json); - }) - .catch(next); - } catch (err) { - next(err); - } - }, - ); - }, }); From ce364bac9cad64e3005ba9c28f145af6cb4c2ddd Mon Sep 17 00:00:00 2001 From: Jackson Hoffart Date: Wed, 5 Nov 2025 12:13:23 +0000 Subject: [PATCH 2/6] prettier --write . --- vite.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index a948d600..d31e400c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,6 @@ import { defineConfig, Plugin, version as viteVersion } from "vite"; import type { ViteDevServer } from "vite"; -import type { PluginContext } from 'rollup'; +import type { PluginContext } from "rollup"; import react from "@vitejs/plugin-react"; import { simpleGit } from "simple-git"; import os from "os"; @@ -188,7 +188,7 @@ function dataValidationPlugin(dir: string = "src/data") { // Create a new plugin for serving schema files function schemaServePlugin(): Plugin { return { - name: 'schema-serve', + name: "schema-serve", configureServer(server: ViteDevServer) { server.middlewares.use( "/schema", From aff479042bf0ce055d1f05cd12fdce49cecd6383 Mon Sep 17 00:00:00 2001 From: Jackson Hoffart Date: Wed, 5 Nov 2025 12:17:28 +0000 Subject: [PATCH 3/6] chore: include utility files in node TS config --- tsconfig.node.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.node.json b/tsconfig.node.json index f3edef58..4c78e2b0 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -15,6 +15,7 @@ "eslint.config.ts", "vitest.config.ts", "postcss.config.ts", - "tailwind.config.ts" + "tailwind.config.ts", + "src/utils/*.ts" ] } From 025964f837b5dd7f968d6d9a0cf81d90a283a34c Mon Sep 17 00:00:00 2001 From: Jackson Hoffart Date: Wed, 5 Nov 2025 12:49:46 +0000 Subject: [PATCH 4/6] Update vite.config.ts Co-authored-by: Alex Axthelm --- vite.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/vite.config.ts b/vite.config.ts index d31e400c..e40e9342 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -186,6 +186,7 @@ function dataValidationPlugin(dir: string = "src/data") { } // Create a new plugin for serving schema files +// Used to access the schema files with the dev server function schemaServePlugin(): Plugin { return { name: "schema-serve", From 00ec6d8dd1576a4879eb9d9b6e49e70c2f7fcc67 Mon Sep 17 00:00:00 2001 From: Jackson Hoffart Date: Wed, 5 Nov 2025 12:52:37 +0000 Subject: [PATCH 5/6] Revert "chore: include utility files in node TS config" This reverts commit aff479042bf0ce055d1f05cd12fdce49cecd6383. --- tsconfig.node.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tsconfig.node.json b/tsconfig.node.json index 4c78e2b0..f3edef58 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -15,7 +15,6 @@ "eslint.config.ts", "vitest.config.ts", "postcss.config.ts", - "tailwind.config.ts", - "src/utils/*.ts" + "tailwind.config.ts" ] } From 88be5ae29ffb121174730cd7efd2291dea0c80c6 Mon Sep 17 00:00:00 2001 From: Jackson Hoffart Date: Wed, 5 Nov 2025 12:55:56 +0000 Subject: [PATCH 6/6] Reapply "chore: include utility files in node TS config" This reverts commit 00ec6d8dd1576a4879eb9d9b6e49e70c2f7fcc67. --- tsconfig.node.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.node.json b/tsconfig.node.json index f3edef58..4c78e2b0 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -15,6 +15,7 @@ "eslint.config.ts", "vitest.config.ts", "postcss.config.ts", - "tailwind.config.ts" + "tailwind.config.ts", + "src/utils/*.ts" ] }