Skip to content

Commit 2cf2a43

Browse files
committed
fix(web): silence vite web build warnings
1 parent 1e19bc5 commit 2cf2a43

4 files changed

Lines changed: 111 additions & 11 deletions

File tree

.github/workflows/final-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: bun ./packages/docker-git-session-sync/dist/docker-git-session-sync.js --help
3333
- name: Verify browser UI and menu clone smoke checks
3434
run: |
35-
bun run --cwd packages/app build:web
35+
bun run --cwd packages/app build:web:strict
3636
bun scripts/final-build/browser-web-smoke.mjs
3737
bun run --cwd packages/app vitest run tests/docker-git/browser-frontend.test.ts tests/docker-git/app-ready-create.test.ts tests/docker-git/actions-project-create.test.ts
3838
- name: Prepare package artifacts directory

packages/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"build": "bun run build:app && bun run build:docker-git",
1818
"build:app": "vite build --ssr src/app/main.ts",
1919
"build:web": "vite build --config vite.web.config.ts",
20+
"build:web:strict": "bun ../../scripts/ci/check-web-build-output.mjs",
2021
"prepack": "bun run build:docker-git",
2122
"dev": "vite build --watch --ssr src/app/main.ts",
2223
"dev:web": "vite --config vite.web.config.ts",

packages/app/vite.web.config.ts

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url"
55

66
import { gridlandWebPlugin } from "@gridland/web/vite-plugin"
77
import react from "@vitejs/plugin-react"
8-
import { defineConfig, loadEnv, type PluginOption } from "vite"
8+
import { defineConfig, loadEnv, type Plugin, type PluginOption, type UserConfig } from "vite"
99
import { type RawData, WebSocket, WebSocketServer } from "ws"
1010

1111
const __filename = fileURLToPath(import.meta.url)
@@ -165,14 +165,65 @@ const terminalWebSocketProxyPlugin = (apiTarget: string): PluginOption => ({
165165
}
166166
})
167167

168+
type VitePluginConfig = Omit<UserConfig, "plugins">
169+
170+
const removeDeprecatedOptimizeDepsOptions = (
171+
optimizeDeps: UserConfig["optimizeDeps"]
172+
): UserConfig["optimizeDeps"] => {
173+
if (optimizeDeps === undefined) {
174+
return undefined
175+
}
176+
177+
const { esbuildOptions: _esbuildOptions, ...remainingOptions } = optimizeDeps
178+
return remainingOptions
179+
}
180+
181+
const removeDeprecatedGridlandOptions = (
182+
config: VitePluginConfig | null | void
183+
): VitePluginConfig | null | void => {
184+
if (config === undefined || config === null) {
185+
return config
186+
}
187+
188+
const { esbuild: _esbuild, optimizeDeps, ...remainingConfig } = config
189+
const sanitizedOptimizeDeps = removeDeprecatedOptimizeDepsOptions(optimizeDeps)
190+
return sanitizedOptimizeDeps === undefined
191+
? remainingConfig
192+
: {
193+
...remainingConfig,
194+
optimizeDeps: sanitizedOptimizeDeps
195+
}
196+
}
197+
198+
const isVitePlugin = (plugin: PluginOption): plugin is Plugin =>
199+
typeof plugin === "object" && plugin !== null && !Array.isArray(plugin) && "name" in plugin
200+
201+
const gridlandWebPluginWithoutDeprecatedOptions = (): ReadonlyArray<PluginOption> =>
202+
gridlandWebPlugin().map((plugin) => {
203+
if (!isVitePlugin(plugin) || plugin.name !== "gridland-web-aliases" || typeof plugin.config !== "function") {
204+
return plugin
205+
}
206+
207+
const resolveGridlandConfig = plugin.config
208+
return {
209+
...plugin,
210+
config(config, env) {
211+
const result = resolveGridlandConfig.call(this, config, env)
212+
return result instanceof Promise
213+
? result.then(removeDeprecatedGridlandOptions)
214+
: removeDeprecatedGridlandOptions(result)
215+
}
216+
}
217+
})
218+
168219
export default defineConfig(({ mode }) => {
169220
const env = loadEnv(mode, __dirname, "")
170221
const apiTarget = env["DOCKER_GIT_API_URL"]?.trim() || defaultApiTarget
171222

172223
return {
173224
plugins: [
174225
terminalWebSocketProxyPlugin(apiTarget),
175-
...gridlandWebPlugin(),
226+
...gridlandWebPluginWithoutDeprecatedOptions(),
176227
react()
177228
],
178229
publicDir: false,
@@ -211,14 +262,12 @@ export default defineConfig(({ mode }) => {
211262
build: {
212263
target: "esnext",
213264
outDir: "dist-web",
214-
sourcemap: true
215-
},
216-
esbuild: {
217-
target: "esnext"
218-
},
219-
optimizeDeps: {
220-
esbuildOptions: {
221-
target: "esnext"
265+
sourcemap: true,
266+
chunkSizeWarningLimit: 1200,
267+
rolldownOptions: {
268+
checks: {
269+
invalidAnnotation: false
270+
}
222271
}
223272
}
224273
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { spawnSync } from "node:child_process"
2+
import { fileURLToPath } from "node:url"
3+
4+
const repoRoot = fileURLToPath(new URL("../..", import.meta.url))
5+
const runtime = process.versions.bun === undefined ? "bun" : process.execPath
6+
const forbiddenOutput = [
7+
{
8+
label: "Vite warning",
9+
pattern: /\[vite\]\s+warning:/iu
10+
},
11+
{
12+
label: "Rolldown invalid annotation warning",
13+
pattern: /\[INVALID_ANNOTATION\]/u
14+
},
15+
{
16+
label: "Deprecated build option warning",
17+
pattern: /\bdeprecated\b/iu
18+
},
19+
{
20+
label: "Chunk size warning",
21+
pattern: /Some chunks are larger than/u
22+
}
23+
]
24+
25+
const result = spawnSync(runtime, ["run", "--cwd", "packages/app", "build:web"], {
26+
cwd: repoRoot,
27+
encoding: "utf8"
28+
})
29+
30+
process.stdout.write(result.stdout)
31+
process.stderr.write(result.stderr)
32+
33+
if (result.error !== undefined) {
34+
console.error(result.error)
35+
process.exit(1)
36+
}
37+
38+
if (result.status !== 0) {
39+
process.exit(result.status ?? 1)
40+
}
41+
42+
const output = `${result.stdout}\n${result.stderr}`
43+
const matches = forbiddenOutput.filter(({ pattern }) => pattern.test(output))
44+
if (matches.length > 0) {
45+
console.error("Web build emitted forbidden warning output:")
46+
for (const match of matches) {
47+
console.error(`- ${match.label}`)
48+
}
49+
process.exit(1)
50+
}

0 commit comments

Comments
 (0)