@amaster.ai/vite-plugins 1.0.0-beta.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amaster Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # @amaster.ai/vite-plugins
2
+
3
+ Collection of Vite plugins for React application development.
4
+
5
+ ## Features
6
+
7
+ - 📝 **Browser Logs Plugin** - Collect console logs and network requests to file
8
+ - 🔧 **Component ID Plugin** - Add unique IDs to HTML elements for debugging
9
+ - 🌉 **Editor Bridge Plugin** - Connect development UI with editor tools
10
+ - 🛣️ **Routes Expose Plugin** - Expose React Router routes in development
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add -D @amaster.ai/vite-plugins
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```typescript
21
+ // vite.config.ts
22
+ import { defineConfig } from "vite";
23
+ import react from "@vitejs/plugin-react";
24
+ import {
25
+ browserLogsPlugin,
26
+ componentIdPlugin,
27
+ editorBridgePlugin,
28
+ routesExposePlugin,
29
+ } from "@amaster.ai/vite-plugins";
30
+
31
+ export default defineConfig({
32
+ plugins: [
33
+ react(),
34
+ browserLogsPlugin(), // Collect browser logs
35
+ componentIdPlugin(),
36
+ editorBridgePlugin(),
37
+ routesExposePlugin(),
38
+ ],
39
+ });
40
+ ```
41
+
42
+ ## Plugins
43
+
44
+ ### browserLogsPlugin()
45
+
46
+ Collects console logs, network requests, and errors from the browser and writes them to a file.
47
+
48
+ **Features:**
49
+ - ✅ Intercepts console.log/info/warn/error/debug
50
+ - ✅ Captures fetch and XMLHttpRequest
51
+ - ✅ Records global errors and unhandled rejections
52
+ - ✅ Filters out Vite internal requests and SSE
53
+ - ✅ Writes to `browser.log` in project root
54
+ - ✅ Only runs in development mode
55
+
56
+ **Output:**
57
+
58
+ All logs are written to `browser.log` in your project root:
59
+
60
+ ```json
61
+ {"type":"console","timestamp":"2026-01-17T10:30:45.123Z","level":"log","message":"User logged in","stack":[...]}
62
+ {"type":"request","timestamp":"2026-01-17T10:30:46.456Z","method":"GET","url":"/api/users","status":200,...}
63
+ {"type":"error","timestamp":"2026-01-17T10:30:47.789Z","level":"error","message":"Uncaught Error: ..."}
64
+ ```
65
+
66
+ **Example:**
67
+
68
+ ```typescript
69
+ browserLogsPlugin()
70
+ ```
71
+
72
+ **Log Format:**
73
+
74
+ - **Console logs**: `{ type: 'console', level, message, stack }`
75
+ - **Network requests**: `{ type: 'request', method, url, status, duration, requestBody, responseBody }`
76
+ - **Errors**: `{ type: 'error', message, stack }`
77
+
78
+ **Programmatic Access:**
79
+
80
+ ```javascript
81
+ // In browser console
82
+
83
+ // Get queue status
84
+ window.__getBrowserLogsStatus__();
85
+ // => { queueLength: 0, isWriting: false }
86
+
87
+ // Flush logs manually
88
+ await window.__flushBrowserLogs__();
89
+ ```
90
+
91
+ ### componentIdPlugin()
92
+
93
+ Adds unique `data-node-component-id` attributes to HTML elements in JSX.
94
+
95
+ **Features:**
96
+ - ✅ Only runs in development mode
97
+ - ✅ Only affects native HTML tags (not custom components)
98
+ - ✅ Generates stable IDs based on file path and position
99
+ - ✅ IDs persist through hot reloads
100
+
101
+ **Example output:**
102
+
103
+ ```tsx
104
+ // Input
105
+ <div>
106
+ <button>Click me</button>
107
+ </div>
108
+
109
+ // Output (development only)
110
+ <div data-node-component-id="a1b2c3d4e5f6">
111
+ <button data-node-component-id="f6e5d4c3b2a1">Click me</button>
112
+ </div>
113
+ ```
114
+
115
+ ### editorBridgePlugin(options?)
116
+
117
+ Injects bridge script for editor integration.
118
+
119
+ **Options:**
120
+ - `bridgeScriptPath` - Path to bridge script (default: `/scripts/bridge.js`)
121
+
122
+ **Features:**
123
+ - ✅ Injects click handler for custom navigation
124
+ - ✅ Loads bridge.js in development mode
125
+ - ✅ Prevents unwanted navigation in editor mode
126
+
127
+ **Example:**
128
+
129
+ ```typescript
130
+ editorBridgePlugin({
131
+ bridgeScriptPath: "/custom/bridge.js",
132
+ })
133
+ ```
134
+
135
+ ### routesExposePlugin(options?)
136
+
137
+ Exposes React Router routes to `window.__APP_ROUTES__` in development.
138
+
139
+ **Options:**
140
+ - `routesFilePath` - Path to routes file (default: `src/routes.tsx`)
141
+
142
+ **Features:**
143
+ - ✅ Only runs in development mode
144
+ - ✅ Automatically detects routes export
145
+ - ✅ Accessible via browser DevTools
146
+
147
+ **Example:**
148
+
149
+ ```typescript
150
+ routesExposePlugin({
151
+ routesFilePath: "src/app/routes.tsx",
152
+ })
153
+ ```
154
+
155
+ **Access routes in browser:**
156
+
157
+ ```javascript
158
+ console.log(window.__APP_ROUTES__);
159
+ ```
160
+
161
+ ## Development Mode Only
162
+
163
+ All plugins are automatically disabled in production builds. They only run when:
164
+
165
+ ```bash
166
+ vite dev # Development server
167
+ vite serve # Development server
168
+ ```
169
+
170
+ ## TypeScript Support
171
+
172
+ Full TypeScript support with proper types:
173
+
174
+ ```typescript
175
+ import type { Plugin } from "vite";
176
+ import { componentIdPlugin } from "@amaster.ai/vite-plugins";
177
+
178
+ const plugin: Plugin = componentIdPlugin();
179
+ ```
180
+
181
+ ## License
182
+
183
+ MIT