Added to web/package.json devDeps: eslint (9, flat config) + eslint-plugin-svelte + typescript-eslint + globals; prettier + prettier-plugin-svelte; vitest (jsdom env) + jsdom. New scripts: lint, lint:fix, format, format:check, test, test:watch. Configs: - web/eslint.config.js — flat config, TS + Svelte, browser/node globals, no-explicit-any as warn, unused-vars as error (ignores _-prefixed). - web/.prettierrc.json — single-quote, 100 width, svelte parser override. - web/.prettierignore — dist/node_modules/build/lockfiles. - web/vite.config.ts — vitest test block via reference directive, jsdom env, globals enabled. Sample test: web/src/lib/utils.test.ts (6 tests covering relativeTime, truncateMiddle, debounce — all passing). CI: new web job in .gitea/workflows/ci.yml (npm ci, check [advisory], lint [advisory], format:check [advisory], test [gate], build [gate]). Advisory steps use continue-on-error until the baseline is clean — matching the existing golangci-lint advisory pattern. Known baseline surfaced by the new toolchain (pre-existing, not caused by R8): svelte-check 154 errors (133-file config cascade), eslint 126 errors + 12 warnings (unused vars, @html XSS, unused CSS), prettier 175 unformatted files. Fixing these is a follow-up cleanup. VERSION 0.7.9 -> 0.7.10. Plan R8 marked done; C.1 updated.
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
/// <reference types="vitest/config" />
|
|
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
import { readFileSync, existsSync } from 'fs'
|
|
import { defineConfig } from 'vite'
|
|
|
|
// In Docker, VERSION is copied into the build WORKDIR (/build/web/VERSION).
|
|
// In local dev, the cwd is web/ and VERSION is two dirs up (../../VERSION
|
|
// from vite.config.ts location in web/). Try both.
|
|
let version: string
|
|
if (existsSync('../VERSION')) {
|
|
version = readFileSync('../VERSION', 'utf-8').trim()
|
|
} else {
|
|
version = readFileSync('VERSION', 'utf-8').trim()
|
|
}
|
|
|
|
// Injects OIKOS_API_TOKEN into proxied /api requests in dev — the API no
|
|
// longer has a dev-open bypass (plans/2026-07-12-wails-desktop-app.md 0.4),
|
|
// so `OIKOS_API_TOKEN=dev-token npm run dev` needs this to reach it.
|
|
function authProxy(target: string, rewrite?: (path: string) => string) {
|
|
return {
|
|
target,
|
|
...(rewrite ? { rewrite } : {}),
|
|
configure: (proxy: any) => {
|
|
proxy.on('proxyReq', (proxyReq: any) => {
|
|
const token = process.env.OIKOS_API_TOKEN
|
|
if (token) proxyReq.setHeader('Authorization', `Bearer ${token}`)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [tailwindcss(), svelte()],
|
|
base: '/',
|
|
define: {
|
|
__OIKOS_VERSION__: JSON.stringify(`v${version}`),
|
|
},
|
|
resolve: {
|
|
alias: { $lib: '/src/lib' }
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
emptyOutDir: true
|
|
},
|
|
server: {
|
|
proxy: {
|
|
'/api': authProxy('http://localhost:8090'),
|
|
// Production Caddy strips /agent before forwarding to nomos
|
|
// (compose/caddy/Caddyfile.oikos handle_path /agent/*); match that
|
|
// here so dev and prod agree on nomos's actual route paths.
|
|
'/agent': authProxy('http://localhost:8092', (path) => path.replace(/^\/agent/, ''))
|
|
}
|
|
},
|
|
test: {
|
|
environment: 'jsdom',
|
|
globals: true,
|
|
include: ['src/**/*.{test,spec}.{ts,js}']
|
|
}
|
|
})
|