Domify commited on
Commit
e9265eb
·
verified ·
1 Parent(s): 7573b1e

Update vite.config.ts

Browse files
Files changed (1) hide show
  1. vite.config.ts +4 -16
vite.config.ts CHANGED
@@ -34,7 +34,6 @@ function trimLogFile(logPath: string, maxSize: number) {
34
  const keptLines: string[] = [];
35
  let keptBytes = 0;
36
 
37
- // Keep newest lines (from end) that fit within 60% of maxSize
38
  const targetSize = TRIM_TARGET_BYTES;
39
  for (let i = lines.length - 1; i >= 0; i--) {
40
  const lineBytes = Buffer.byteLength(`${lines[i]}\n`, "utf-8");
@@ -55,25 +54,16 @@ function writeToLogFile(source: LogSource, entries: unknown[]) {
55
  ensureLogDir();
56
  const logPath = path.join(LOG_DIR, `${source}.log`);
57
 
58
- // Format entries with timestamps
59
  const lines = entries.map((entry) => {
60
  const ts = new Date().toISOString();
61
  return `[${ts}] ${JSON.stringify(entry)}`;
62
  });
63
 
64
- // Append to log file
65
  fs.appendFileSync(logPath, `${lines.join("\n")}\n`, "utf-8");
66
 
67
- // Trim if exceeds max size
68
  trimLogFile(logPath, MAX_LOG_SIZE_BYTES);
69
  }
70
 
71
- /**
72
- * Vite plugin to collect browser debug logs
73
- * - POST /__manus__/logs: Browser sends logs, written directly to files
74
- * - Files: browserConsole.log, networkRequests.log, sessionReplay.log
75
- * - Auto-trimmed when exceeding 1MB (keeps newest entries)
76
- */
77
  function vitePluginManusDebugCollector(): Plugin {
78
  return {
79
  name: "manus-debug-collector",
@@ -98,14 +88,12 @@ function vitePluginManusDebugCollector(): Plugin {
98
  },
99
 
100
  configureServer(server: ViteDevServer) {
101
- // POST /__manus__/logs: Browser sends logs (written directly to files)
102
  server.middlewares.use("/__manus__/logs", (req, res, next) => {
103
  if (req.method !== "POST") {
104
  return next();
105
  }
106
 
107
  const handlePayload = (payload: any) => {
108
- // Write logs directly to files
109
  if (payload.consoleLogs?.length > 0) {
110
  writeToLogFile("browserConsole", payload.consoleLogs);
111
  }
@@ -156,14 +144,14 @@ export default defineConfig({
156
  plugins,
157
  resolve: {
158
  alias: {
159
- "@": path.resolve(import.meta.dirname, "client", "src"),
160
  "@shared": path.resolve(import.meta.dirname, "shared"),
161
  "@assets": path.resolve(import.meta.dirname, "attached_assets"),
162
  },
163
  },
164
  envDir: path.resolve(import.meta.dirname),
165
- root: path.resolve(import.meta.dirname, "client"),
166
- publicDir: path.resolve(import.meta.dirname, "client", "public"),
167
  build: {
168
  outDir: path.resolve(import.meta.dirname, "dist/public"),
169
  emptyOutDir: true,
@@ -184,4 +172,4 @@ export default defineConfig({
184
  deny: ["**/.*"],
185
  },
186
  },
187
- });
 
34
  const keptLines: string[] = [];
35
  let keptBytes = 0;
36
 
 
37
  const targetSize = TRIM_TARGET_BYTES;
38
  for (let i = lines.length - 1; i >= 0; i--) {
39
  const lineBytes = Buffer.byteLength(`${lines[i]}\n`, "utf-8");
 
54
  ensureLogDir();
55
  const logPath = path.join(LOG_DIR, `${source}.log`);
56
 
 
57
  const lines = entries.map((entry) => {
58
  const ts = new Date().toISOString();
59
  return `[${ts}] ${JSON.stringify(entry)}`;
60
  });
61
 
 
62
  fs.appendFileSync(logPath, `${lines.join("\n")}\n`, "utf-8");
63
 
 
64
  trimLogFile(logPath, MAX_LOG_SIZE_BYTES);
65
  }
66
 
 
 
 
 
 
 
67
  function vitePluginManusDebugCollector(): Plugin {
68
  return {
69
  name: "manus-debug-collector",
 
88
  },
89
 
90
  configureServer(server: ViteDevServer) {
 
91
  server.middlewares.use("/__manus__/logs", (req, res, next) => {
92
  if (req.method !== "POST") {
93
  return next();
94
  }
95
 
96
  const handlePayload = (payload: any) => {
 
97
  if (payload.consoleLogs?.length > 0) {
98
  writeToLogFile("browserConsole", payload.consoleLogs);
99
  }
 
144
  plugins,
145
  resolve: {
146
  alias: {
147
+ "@": path.resolve(import.meta.dirname, "src"),
148
  "@shared": path.resolve(import.meta.dirname, "shared"),
149
  "@assets": path.resolve(import.meta.dirname, "attached_assets"),
150
  },
151
  },
152
  envDir: path.resolve(import.meta.dirname),
153
+ root: path.resolve(import.meta.dirname),
154
+ publicDir: path.resolve(import.meta.dirname, "public") || false,
155
  build: {
156
  outDir: path.resolve(import.meta.dirname, "dist/public"),
157
  emptyOutDir: true,
 
172
  deny: ["**/.*"],
173
  },
174
  },
175
+ });