iterate-ui-vite 0.1.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 +21 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +222 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Connor White
|
|
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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface IteratePluginOptions {
|
|
4
|
+
/** Port for the iterate daemon (default: 4000) */
|
|
5
|
+
daemonPort?: number;
|
|
6
|
+
/** Disable the babel plugin that injects component names/source locations (default: false) */
|
|
7
|
+
disableBabelPlugin?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Vite plugin for iterate.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```ts
|
|
14
|
+
* // vite.config.ts
|
|
15
|
+
* import { iterate } from 'iterate-ui-vite'
|
|
16
|
+
* export default defineConfig({
|
|
17
|
+
* plugins: [iterate()]
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Automatically:
|
|
22
|
+
* 1. Starts the iterate daemon when `vite dev` runs
|
|
23
|
+
* 2. Injects the overlay `<script>` into every HTML page
|
|
24
|
+
* 3. Proxies /__iterate__/* and /api/* to the daemon
|
|
25
|
+
* 4. Injects component name/source data attributes via babel
|
|
26
|
+
* 5. Cleans up daemon when dev server stops
|
|
27
|
+
*/
|
|
28
|
+
declare function iterate(options?: IteratePluginOptions): Plugin[];
|
|
29
|
+
|
|
30
|
+
export { type IteratePluginOptions, iterate as default, iterate };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { spawn, execSync } from "child_process";
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
import { readFileSync } from "fs";
|
|
5
|
+
import http from "http";
|
|
6
|
+
function iterate(options = {}) {
|
|
7
|
+
const daemonPort = options.daemonPort ?? 4e3;
|
|
8
|
+
let daemon = null;
|
|
9
|
+
let overlayJS = null;
|
|
10
|
+
const plugins = [];
|
|
11
|
+
if (!options.disableBabelPlugin) {
|
|
12
|
+
let babelCore = null;
|
|
13
|
+
let babelPluginPath = null;
|
|
14
|
+
plugins.push({
|
|
15
|
+
name: "iterate:component-source",
|
|
16
|
+
apply: "serve",
|
|
17
|
+
enforce: "pre",
|
|
18
|
+
// Run before @vitejs/plugin-react transforms JSX
|
|
19
|
+
async configResolved(config) {
|
|
20
|
+
try {
|
|
21
|
+
babelCore = await import("@babel/core");
|
|
22
|
+
const require2 = createRequire(import.meta.url);
|
|
23
|
+
babelPluginPath = require2.resolve("iterate-ui-babel-plugin");
|
|
24
|
+
} catch {
|
|
25
|
+
console.warn("[iterate] Babel plugin setup failed \u2014 component names will not be available");
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
async transform(code, id) {
|
|
29
|
+
if (!babelCore || !babelPluginPath) return null;
|
|
30
|
+
if (!/\.[jt]sx$/.test(id)) return null;
|
|
31
|
+
if (id.includes("node_modules")) return null;
|
|
32
|
+
try {
|
|
33
|
+
const result = await babelCore.transformAsync(code, {
|
|
34
|
+
filename: id,
|
|
35
|
+
plugins: [
|
|
36
|
+
[babelPluginPath, { root: process.cwd() }],
|
|
37
|
+
// Need JSX syntax plugin to parse JSX without transforming it
|
|
38
|
+
["@babel/plugin-syntax-jsx", {}],
|
|
39
|
+
...id.endsWith(".tsx") ? [["@babel/plugin-syntax-typescript", { isTSX: true }]] : []
|
|
40
|
+
],
|
|
41
|
+
parserOpts: {
|
|
42
|
+
plugins: [
|
|
43
|
+
"jsx",
|
|
44
|
+
...id.endsWith(".tsx") ? ["typescript"] : []
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
// Don't transform anything else — just inject attributes
|
|
48
|
+
presets: [],
|
|
49
|
+
sourceMaps: true,
|
|
50
|
+
configFile: false,
|
|
51
|
+
babelrc: false
|
|
52
|
+
});
|
|
53
|
+
if (!result?.code) return null;
|
|
54
|
+
return { code: result.code, map: result.map };
|
|
55
|
+
} catch (err) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
plugins.push({
|
|
62
|
+
name: "iterate",
|
|
63
|
+
apply: "serve",
|
|
64
|
+
// Only active during dev
|
|
65
|
+
configureServer(server) {
|
|
66
|
+
const repoRoot = getGitRoot() ?? server.config.root;
|
|
67
|
+
daemon = startDaemon(daemonPort, repoRoot);
|
|
68
|
+
server.middlewares.use("/__iterate__/overlay.js", (_req, res) => {
|
|
69
|
+
if (!overlayJS) {
|
|
70
|
+
try {
|
|
71
|
+
const require2 = createRequire(import.meta.url);
|
|
72
|
+
const overlayPath = require2.resolve("iterate-ui-overlay/standalone");
|
|
73
|
+
overlayJS = readFileSync(overlayPath, "utf-8");
|
|
74
|
+
} catch {
|
|
75
|
+
res.statusCode = 404;
|
|
76
|
+
res.end("Overlay bundle not found");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
81
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
82
|
+
res.end(overlayJS);
|
|
83
|
+
});
|
|
84
|
+
server.middlewares.use((req, res, next) => {
|
|
85
|
+
const url = req.url ?? "";
|
|
86
|
+
if (url.startsWith("/api/") || url.startsWith("/__iterate__/")) {
|
|
87
|
+
proxyRequest(req, res, daemonPort);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
next();
|
|
91
|
+
});
|
|
92
|
+
server.httpServer?.on("upgrade", (req, socket, head) => {
|
|
93
|
+
if (req.url === "/ws") {
|
|
94
|
+
const proxy = http.request(
|
|
95
|
+
{
|
|
96
|
+
hostname: "127.0.0.1",
|
|
97
|
+
port: daemonPort,
|
|
98
|
+
path: "/ws",
|
|
99
|
+
method: "GET",
|
|
100
|
+
headers: {
|
|
101
|
+
...req.headers,
|
|
102
|
+
host: `127.0.0.1:${daemonPort}`
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
() => {
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
proxy.on("upgrade", (_proxyRes, proxySocket, proxyHead) => {
|
|
109
|
+
socket.write(
|
|
110
|
+
`HTTP/1.1 101 Switching Protocols\r
|
|
111
|
+
Upgrade: websocket\r
|
|
112
|
+
Connection: Upgrade\r
|
|
113
|
+
Sec-WebSocket-Accept: ${_proxyRes.headers["sec-websocket-accept"]}\r
|
|
114
|
+
\r
|
|
115
|
+
`
|
|
116
|
+
);
|
|
117
|
+
if (proxyHead.length > 0) socket.write(proxyHead);
|
|
118
|
+
proxySocket.pipe(socket);
|
|
119
|
+
socket.pipe(proxySocket);
|
|
120
|
+
proxySocket.on("error", () => socket.destroy());
|
|
121
|
+
socket.on("error", () => proxySocket.destroy());
|
|
122
|
+
});
|
|
123
|
+
proxy.on("error", () => {
|
|
124
|
+
socket.destroy();
|
|
125
|
+
});
|
|
126
|
+
proxy.end();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
server.httpServer?.on("close", () => {
|
|
130
|
+
stopDaemon(daemon, daemonPort);
|
|
131
|
+
daemon = null;
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
// Inject the overlay script into HTML
|
|
135
|
+
transformIndexHtml(html) {
|
|
136
|
+
const iterationName = JSON.stringify(process.env.ITERATE_ITERATION_NAME ?? "__original__");
|
|
137
|
+
return html.replace(
|
|
138
|
+
"</body>",
|
|
139
|
+
`<script>
|
|
140
|
+
window.__iterate_shell__ = { activeTool: 'select', activeIteration: ${iterationName}, daemonPort: ${daemonPort} };
|
|
141
|
+
</script>
|
|
142
|
+
<script src="/__iterate__/overlay.js" defer></script>
|
|
143
|
+
</body>`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return plugins;
|
|
148
|
+
}
|
|
149
|
+
function getGitRoot() {
|
|
150
|
+
try {
|
|
151
|
+
return execSync("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();
|
|
152
|
+
} catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function startDaemon(port, cwd) {
|
|
157
|
+
const child = spawn(
|
|
158
|
+
process.execPath,
|
|
159
|
+
["--input-type=module", "-e", `import { startDaemon } from "iterate-ui-daemon"; startDaemon({ port: ${port}, cwd: ${JSON.stringify(cwd)} });`],
|
|
160
|
+
{
|
|
161
|
+
cwd,
|
|
162
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
163
|
+
env: {
|
|
164
|
+
...process.env,
|
|
165
|
+
ITERATE_PORT: String(port),
|
|
166
|
+
ITERATE_CWD: cwd,
|
|
167
|
+
NODE_NO_WARNINGS: "1"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
child.stdout?.on("data", (data) => {
|
|
172
|
+
const msg = data.toString().trim();
|
|
173
|
+
if (msg) console.log(`[iterate] ${msg}`);
|
|
174
|
+
});
|
|
175
|
+
child.stderr?.on("data", (data) => {
|
|
176
|
+
const msg = data.toString().trim();
|
|
177
|
+
if (msg && !msg.includes("ExperimentalWarning")) {
|
|
178
|
+
console.error(`[iterate] ${msg}`);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
child.on("exit", (code) => {
|
|
182
|
+
if (code !== 0 && code !== null) {
|
|
183
|
+
console.error(`[iterate] daemon exited with code ${code}`);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return child;
|
|
187
|
+
}
|
|
188
|
+
async function stopDaemon(child, port) {
|
|
189
|
+
try {
|
|
190
|
+
await fetch(`http://127.0.0.1:${port}/api/shutdown`, { method: "POST" });
|
|
191
|
+
} catch {
|
|
192
|
+
child?.kill("SIGTERM");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function proxyRequest(req, res, port) {
|
|
196
|
+
const proxyReq = http.request(
|
|
197
|
+
{
|
|
198
|
+
hostname: "127.0.0.1",
|
|
199
|
+
port,
|
|
200
|
+
path: req.url,
|
|
201
|
+
method: req.method,
|
|
202
|
+
headers: {
|
|
203
|
+
...req.headers,
|
|
204
|
+
host: `127.0.0.1:${port}`
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
(proxyRes) => {
|
|
208
|
+
res.writeHead(proxyRes.statusCode ?? 500, proxyRes.headers);
|
|
209
|
+
proxyRes.pipe(res);
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
proxyReq.on("error", () => {
|
|
213
|
+
res.statusCode = 502;
|
|
214
|
+
res.end("iterate daemon not available");
|
|
215
|
+
});
|
|
216
|
+
req.pipe(proxyReq);
|
|
217
|
+
}
|
|
218
|
+
var index_default = iterate;
|
|
219
|
+
export {
|
|
220
|
+
index_default as default,
|
|
221
|
+
iterate
|
|
222
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "iterate-ui-vite",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "iterate Vite plugin — auto-starts daemon and injects overlay",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/connorwhite-online/iterate",
|
|
9
|
+
"directory": "packages/vite"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://iterate-ui.com",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"iterate",
|
|
14
|
+
"ui",
|
|
15
|
+
"vite",
|
|
16
|
+
"plugin",
|
|
17
|
+
"ai",
|
|
18
|
+
"worktree"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"iterate-ui-overlay": "0.1.0",
|
|
34
|
+
"iterate-ui-babel-plugin": "0.1.0",
|
|
35
|
+
"iterate-ui-daemon": "0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"vite": "^5.0.0 || ^6.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/core": "^7.24.0",
|
|
42
|
+
"@types/babel__core": "^7.20.0",
|
|
43
|
+
"@types/node": "^22.0.0",
|
|
44
|
+
"tsup": "^8.3.0",
|
|
45
|
+
"typescript": "^5.7.0",
|
|
46
|
+
"vite": "^6.0.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsup src/index.ts --format esm --dts --external @babel/core",
|
|
50
|
+
"dev": "tsup src/index.ts --format esm --dts --watch --external @babel/core",
|
|
51
|
+
"clean": "rm -rf dist"
|
|
52
|
+
}
|
|
53
|
+
}
|