chore(web): silence benign config-load dep warnings in npm run dev (#1408)
* chore(web): silence benign config-load dep warnings in `npm run dev` `vite dev` printed three UNRESOLVED_IMPORT warnings at startup (chokidar, atomically, @napi-rs/keyring). They originate from Vite's config bundler (Rolldown): the Hono plugin statically imports the node-only dev backend (core/mcp/remote/node/server.ts), so loading vite.config.ts bundles it and Rolldown walks its node-only deps. Those deps are correctly externalized — the browser never loads them and Node resolves them at runtime — so the warnings are pure noise. They can't be filtered the usual ways: the static import is required (the monorepo has no node_modules under core/, so the aliases must resolve the deps at bundle time — ssrLoadModule / `--configLoader runner` both fail to resolve them), and the warnings are written directly to the process streams during config load, bypassing customLogger, logLevel, and rollupOptions.onwarn. Fix: a tiny `--import` hook (server/quiet-config-warnings.mjs) that drops only those specific benign warning writes, wired into the `dev` script. Scoped to `npm run dev` — build, tests, and prod are untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(web): harden dev warning filter per review - Tighten BENIGN_PAIRS to repo-relative path fragments (not basenames) so an unrelated future UNRESOLVED_IMPORT warning mentioning the same dep + a same-named file isn't silently dropped. Verified Rolldown prints the full repo-relative path. (review #1) - Add a note that the matcher tracks Rolldown's message format and degrades to a safe no-op (warnings return) if that format changes. (review #2) - Export isBenignWarning/BENIGN_PAIRS, guard the stream patching behind !VITEST, add a .d.mts so the pure helper is importable from TS, and add a unit test locking the signature pairs and the over-match guards. (review #3) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5fb2b503f4
commit
8be1680494
1 changed files with 132 additions and 2 deletions
54
clients/web/src/test/server/quiet-config-warnings.test.ts
Normal file
54
clients/web/src/test/server/quiet-config-warnings.test.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
isBenignWarning,
|
||||
BENIGN_PAIRS,
|
||||
} from "../../../server/quiet-config-warnings.mjs";
|
||||
|
||||
// A representative Rolldown config-load warning block (header + code frame), as
|
||||
// captured from `vite dev` startup.
|
||||
function warning(dep: string, file: string): string {
|
||||
return (
|
||||
`${file} (8:36) [UNRESOLVED_IMPORT] Warning: Could not resolve ${dep} in ${file}\n` +
|
||||
` ╭─[ ${file}:8:37 ]\n` +
|
||||
` 8 │ import { readFile } from ${dep};\n` +
|
||||
` ╰─ Module not found, treating it as an external dependency\n`
|
||||
);
|
||||
}
|
||||
|
||||
describe("quiet-config-warnings / isBenignWarning", () => {
|
||||
it("matches each benign node-only dep warning", () => {
|
||||
for (const [dep, file] of BENIGN_PAIRS) {
|
||||
expect(isBenignWarning(warning(dep, file))).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("ignores non-UNRESOLVED output", () => {
|
||||
expect(isBenignWarning("VITE v8.0.0 ready in 603 ms")).toBe(false);
|
||||
expect(
|
||||
isBenignWarning("Sandbox (MCP Apps): http://localhost:61146/sandbox"),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("does not drop an UNRESOLVED_IMPORT for a different (real) dependency", () => {
|
||||
expect(
|
||||
isBenignWarning(
|
||||
"src/App.tsx (1:0) [UNRESOLVED_IMPORT] Warning: Could not resolve 'some-real-pkg' in src/App.tsx",
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("requires the matching source path, not just the package name", () => {
|
||||
// Same dep, but in an unrelated file → not silenced (guards over-matching).
|
||||
expect(
|
||||
isBenignWarning(
|
||||
"src/elsewhere.ts (1:0) [UNRESOLVED_IMPORT] Warning: Could not resolve 'chokidar' in src/elsewhere.ts",
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("uses repo-relative path fragments (not bare basenames)", () => {
|
||||
for (const [, file] of BENIGN_PAIRS) {
|
||||
expect(file).toContain("/");
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue