From 3415102d5a23cf50594d224e4a8c6089c980ce0b Mon Sep 17 00:00:00 2001 From: mithral Date: Mon, 12 Oct 2026 12:12:02 -0400 Subject: [PATCH] Keep web/dist/.gitkeep alive across a build The build deletes it. vite clears outDir (emptyOutDir: true), and that file is the only reason //go:embed all:dist compiles in a fresh clone - without it a clone that has not run a frontend build cannot run go build at all. Found because it happened: a pnpm build during the transcode work removed the tracked file, and it showed up as a deletion waiting to be committed. A developer who ran a build and then staged everything would have broken every clone silently, and the symptom would appear on someone else's machine. The build now regenerates it, with the explanation in the file itself so the next person to see it knows what it is for. --- web/dist/.gitkeep | 14 +++++--------- web/package.json | 2 +- web/scripts/keep-dist.mjs | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 web/scripts/keep-dist.mjs diff --git a/web/dist/.gitkeep b/web/dist/.gitkeep index 9e57975..5c863b8 100644 --- a/web/dist/.gitkeep +++ b/web/dist/.gitkeep @@ -1,10 +1,6 @@ -# Keeps web/dist present in a fresh clone. +# Generated by scripts/keep-dist.mjs after every build. # -# //go:embed all:dist in web/embed.go fails to compile if the directory is -# absent, so a clone with no frontend build could not run `go build` at all. -# With this file present the build succeeds and the server logs -# "web UI not embedded; run the frontend build to include it", which is the -# intended behaviour for someone who only wants the API. -# -# `pnpm build` overwrites dist/ with the real bundle; the Dockerfile builds the -# frontend first and overlays it. +# Keeps web/dist present so //go:embed all:dist in web/embed.go compiles +# in a fresh clone, where the frontend has not been built. Without it the +# server logs "web UI not embedded" and serves the API only, which is the +# intended behaviour for a clone that has not run `pnpm build`. diff --git a/web/package.json b/web/package.json index 4637601..9c35fd7 100644 --- a/web/package.json +++ b/web/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "vite build", + "build": "vite build && node scripts/keep-dist.mjs", "preview": "vite preview", "check": "svelte-check --tsconfig ./tsconfig.json" }, diff --git a/web/scripts/keep-dist.mjs b/web/scripts/keep-dist.mjs new file mode 100644 index 0000000..583983b --- /dev/null +++ b/web/scripts/keep-dist.mjs @@ -0,0 +1,22 @@ +// Recreates dist/.gitkeep after a build. +// +// vite clears outDir (emptyOutDir: true in vite.config.ts), which deletes the +// tracked placeholder. Without that file present, //go:embed all:dist in +// web/embed.go fails to compile, so a fresh clone with no frontend build cannot +// run `go build` at all - and a developer who ran `pnpm build` and then +// committed the deletion would silently break every clone. +// +// Writing it here means the file survives a build instead of needing to be +// restored by hand every time. +import { mkdirSync, writeFileSync } from 'node:fs' + +mkdirSync('dist', { recursive: true }) +writeFileSync( + 'dist/.gitkeep', + '# Generated by scripts/keep-dist.mjs after every build.\n' + + '#\n' + + '# Keeps web/dist present so //go:embed all:dist in web/embed.go compiles\n' + + '# in a fresh clone, where the frontend has not been built. Without it the\n' + + '# server logs "web UI not embedded" and serves the API only, which is the\n' + + '# intended behaviour for a clone that has not run `pnpm build`.\n', +)