vite-plugin-agent-tail 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ import { BrowserLogsOptions, BrowserLogsOptions as BrowserLogsOptions$1, DEFAULT_OPTIONS, LogEntry, ResolvedOptions } from "agent-tail-core";
2
+ import { Plugin } from "vite";
3
+
4
+ //#region src/plugin.d.ts
5
+ declare function browser_logs(user_options?: BrowserLogsOptions$1): Plugin;
6
+ //#endregion
7
+ export { type BrowserLogsOptions, DEFAULT_OPTIONS, type LogEntry, type ResolvedOptions, browser_logs };
package/dist/index.mjs ADDED
@@ -0,0 +1,47 @@
1
+ import fs from "node:fs";
2
+ import { DEFAULT_OPTIONS, LogManager, format_log_line, generate_client_script, resolve_options } from "agent-tail-core";
3
+
4
+ //#region src/plugin.ts
5
+ function browser_logs(user_options) {
6
+ const options = resolve_options(user_options);
7
+ const log_manager = new LogManager(options);
8
+ let log_path;
9
+ return {
10
+ name: "vite-plugin-agent-tail",
11
+ apply: "serve",
12
+ configureServer(server) {
13
+ const project_root = server.config.root;
14
+ log_path = log_manager.initialize(project_root);
15
+ server.middlewares.use(options.endpoint, (req, res) => {
16
+ if (req.method !== "POST") {
17
+ res.writeHead(405);
18
+ res.end();
19
+ return;
20
+ }
21
+ let body = "";
22
+ req.on("data", (chunk) => {
23
+ body += chunk.toString();
24
+ });
25
+ req.on("end", () => {
26
+ try {
27
+ const lines = JSON.parse(body).map(format_log_line).join("");
28
+ fs.appendFileSync(log_path, lines);
29
+ } catch {}
30
+ res.writeHead(204);
31
+ res.end();
32
+ });
33
+ });
34
+ },
35
+ transformIndexHtml() {
36
+ return [{
37
+ tag: "script",
38
+ attrs: { type: "text/javascript" },
39
+ children: generate_client_script(options),
40
+ injectTo: "head-prepend"
41
+ }];
42
+ }
43
+ };
44
+ }
45
+
46
+ //#endregion
47
+ export { DEFAULT_OPTIONS, browser_logs };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "vite-plugin-agent-tail",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "Vite plugin for agent-tail — pipes browser console logs to files on disk during development.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/gillkyle/agent-tail",
10
+ "directory": "packages/vite-plugin"
11
+ },
12
+ "author": "Kyle Gill",
13
+ "keywords": ["vite", "vite-plugin", "browser-logs", "console", "logging"],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.mjs",
17
+ "types": "./dist/index.d.mts"
18
+ }
19
+ },
20
+ "main": "./dist/index.mjs",
21
+ "types": "./dist/index.d.mts",
22
+ "files": ["dist"],
23
+ "scripts": {
24
+ "build": "tsdown",
25
+ "typecheck": "tsc --noEmit"
26
+ },
27
+ "dependencies": {
28
+ "agent-tail-core": "workspace:*"
29
+ },
30
+ "peerDependencies": {
31
+ "vite": ">=5.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "tsdown": "^0.18.1",
35
+ "vite": "^6.0.0"
36
+ }
37
+ }