fix(cli): clean terminal output for TUI apps

- Silence Vite server logs (logLevel: 'silent')
- Intercept console.log/info/warn/error/debug in child process to
  suppress [vite] and [Vue warn] noise from HMR client
- Add 3s startup grace period to ignore initial reload requests
  (prevents double-spawn on first WS connection)
- Clear screen before spawning child process

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yunfei He
2026-05-24 21:28:29 +08:00
parent d31e8b7a65
commit 625aa138f1
9 changed files with 25 additions and 132 deletions
+9
View File
@@ -17,6 +17,7 @@ export async function dev(entry?: string) {
const server = await createServer({
plugins: [vueTuiDevPlugin({ entry })],
logLevel: "silent",
});
await server.listen();
@@ -55,8 +56,16 @@ export async function dev(entry?: string) {
pm.spawn();
// Ignore reload requests during startup — the initial WS connection
// may trigger vite:beforeFullReload before the app is ready
let acceptReloads = false;
setTimeout(() => {
acceptReloads = true;
}, 3000);
// Listen for full reload requests from child
server.hot.on("vue-tui:request-reload", async () => {
if (!acceptReloads) return;
const newPath = await extractBundle(clientEnv.memoryFiles, outDir);
pm.setBundlePath(newPath);
pm.restart();
+16 -1
View File
@@ -9,7 +9,22 @@ export interface ProcessManagerOptions {
}
const loaderUrl = new URL("./hmr-loader.mjs", import.meta.url).href;
const loaderBootstrap = `data:text/javascript,import{register}from"node:module";register(${JSON.stringify(loaderUrl)})`;
// Bootstrap script: register HMR loader hooks + silence Vite/Vue console noise
const loaderBootstrap = `data:text/javascript,${encodeURIComponent(`
import{register}from"node:module";
register(${JSON.stringify(loaderUrl)});
// Intercept all console methods to suppress Vite HMR client and Vue warn noise
for (const method of ["log", "info", "warn", "error", "debug"]) {
const orig = console[method];
console[method] = (...args) => {
const first = typeof args[0] === "string" ? args[0] : "";
if (first.includes("[vite]") || first.includes("[Vue warn]")) return;
orig.apply(console, args);
};
}
`)}`;
export function createProcessManager(options: ProcessManagerOptions) {
let child: ChildProcess | null = null;