iterate-ui-next 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.cjs +235 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +216 -0
- package/package.json +52 -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.cjs
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
default: () => index_default,
|
|
24
|
+
withIterate: () => withIterate
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_node_child_process = require("child_process");
|
|
28
|
+
var import_node_net = require("net");
|
|
29
|
+
var import_node_module = require("module");
|
|
30
|
+
var import_node_path = require("path");
|
|
31
|
+
var import_node_fs = require("fs");
|
|
32
|
+
var import_meta = {};
|
|
33
|
+
function resolvePackageEntry(packageName, _require) {
|
|
34
|
+
try {
|
|
35
|
+
return _require.resolve(packageName);
|
|
36
|
+
} catch {
|
|
37
|
+
const pkgJsonPath = _require.resolve(`${packageName}/package.json`);
|
|
38
|
+
const pkg = JSON.parse((0, import_node_fs.readFileSync)(pkgJsonPath, "utf-8"));
|
|
39
|
+
const main = pkg.exports?.["."]?.import ?? pkg.main ?? "index.js";
|
|
40
|
+
return (0, import_node_path.join)((0, import_node_path.dirname)(pkgJsonPath), main);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var daemon = null;
|
|
44
|
+
var daemonStarting = false;
|
|
45
|
+
function withIterate(nextConfig = {}, options = {}) {
|
|
46
|
+
const daemonPort = options.daemonPort ?? 4e3;
|
|
47
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
48
|
+
if (!isDev) {
|
|
49
|
+
return nextConfig;
|
|
50
|
+
}
|
|
51
|
+
if (!daemon && !daemonStarting) {
|
|
52
|
+
daemonStarting = true;
|
|
53
|
+
const repoRoot = getGitRoot() ?? process.cwd();
|
|
54
|
+
startDaemonIfNeeded(daemonPort, repoRoot).then((child) => {
|
|
55
|
+
if (child) {
|
|
56
|
+
daemon = child;
|
|
57
|
+
const cleanup = () => {
|
|
58
|
+
if (daemon) {
|
|
59
|
+
stopDaemon(daemon, daemonPort);
|
|
60
|
+
daemon = null;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
process.on("SIGINT", cleanup);
|
|
64
|
+
process.on("SIGTERM", cleanup);
|
|
65
|
+
process.on("exit", cleanup);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const _require = typeof require !== "undefined" ? require : (0, import_node_module.createRequire)(import_meta.url);
|
|
70
|
+
let overlayBundlePath;
|
|
71
|
+
let babelPluginPath;
|
|
72
|
+
try {
|
|
73
|
+
overlayBundlePath = resolvePackageEntry("iterate-ui-overlay/standalone", _require);
|
|
74
|
+
if (!options.disableBabelPlugin) {
|
|
75
|
+
babelPluginPath = resolvePackageEntry("iterate-ui-babel-plugin", _require);
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
console.warn("[iterate] Could not resolve overlay bundle or babel plugin");
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
...nextConfig,
|
|
82
|
+
// Add rewrites to proxy to the daemon
|
|
83
|
+
async rewrites() {
|
|
84
|
+
const existingRewrites = await (nextConfig.rewrites?.() ?? []);
|
|
85
|
+
const iterateRewrites = [
|
|
86
|
+
{
|
|
87
|
+
source: "/__iterate__/:path*",
|
|
88
|
+
destination: `http://127.0.0.1:${daemonPort}/__iterate__/:path*`
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
source: "/api/iterations/:path*",
|
|
92
|
+
destination: `http://127.0.0.1:${daemonPort}/api/iterations/:path*`
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
source: "/api/annotations/:path*",
|
|
96
|
+
destination: `http://127.0.0.1:${daemonPort}/api/annotations/:path*`
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
source: "/api/dom-changes",
|
|
100
|
+
destination: `http://127.0.0.1:${daemonPort}/api/dom-changes`
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
source: "/api/command",
|
|
104
|
+
destination: `http://127.0.0.1:${daemonPort}/api/command`
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
source: "/api/command-context/:path*",
|
|
108
|
+
destination: `http://127.0.0.1:${daemonPort}/api/command-context/:path*`
|
|
109
|
+
}
|
|
110
|
+
];
|
|
111
|
+
if (Array.isArray(existingRewrites)) {
|
|
112
|
+
return [...iterateRewrites, ...existingRewrites];
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
...existingRewrites,
|
|
116
|
+
beforeFiles: [
|
|
117
|
+
...iterateRewrites,
|
|
118
|
+
...existingRewrites.beforeFiles ?? []
|
|
119
|
+
]
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
// Inject overlay via webpack
|
|
123
|
+
webpack(config, context) {
|
|
124
|
+
if (context.isServer || !context.dev) {
|
|
125
|
+
return nextConfig.webpack?.(config, context) ?? config;
|
|
126
|
+
}
|
|
127
|
+
const originalEntry = config.entry;
|
|
128
|
+
config.entry = async () => {
|
|
129
|
+
const entries = await (typeof originalEntry === "function" ? originalEntry() : originalEntry);
|
|
130
|
+
const injectorPath = createIterateInjector(overlayBundlePath, daemonPort);
|
|
131
|
+
if (injectorPath && entries["main-app"]) {
|
|
132
|
+
if (Array.isArray(entries["main-app"])) {
|
|
133
|
+
entries["main-app"].push(injectorPath);
|
|
134
|
+
}
|
|
135
|
+
} else if (injectorPath && entries["main"]) {
|
|
136
|
+
if (Array.isArray(entries["main"])) {
|
|
137
|
+
entries["main"].push(injectorPath);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return entries;
|
|
141
|
+
};
|
|
142
|
+
return nextConfig.webpack?.(config, context) ?? config;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function createIterateInjector(_overlayPath, daemonPort) {
|
|
147
|
+
const iterationName = process.env.ITERATE_ITERATION_NAME ?? "__original__";
|
|
148
|
+
const code = `
|
|
149
|
+
if (typeof window !== 'undefined') {
|
|
150
|
+
window.__iterate_shell__ = { activeTool: 'browse', activeIteration: ${JSON.stringify(iterationName)}, daemonPort: ${daemonPort} };
|
|
151
|
+
var s = document.createElement('script');
|
|
152
|
+
s.src = '/__iterate__/overlay.js';
|
|
153
|
+
s.defer = true;
|
|
154
|
+
document.head.appendChild(s);
|
|
155
|
+
}
|
|
156
|
+
`;
|
|
157
|
+
return `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
|
|
158
|
+
}
|
|
159
|
+
function isPortInUse(port) {
|
|
160
|
+
return new Promise((resolve) => {
|
|
161
|
+
const socket = (0, import_node_net.createConnection)({ port, host: "127.0.0.1" });
|
|
162
|
+
socket.on("connect", () => {
|
|
163
|
+
socket.destroy();
|
|
164
|
+
resolve(true);
|
|
165
|
+
});
|
|
166
|
+
socket.on("error", () => {
|
|
167
|
+
resolve(false);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function getGitRoot() {
|
|
172
|
+
try {
|
|
173
|
+
return (0, import_node_child_process.execSync)("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();
|
|
174
|
+
} catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async function startDaemonIfNeeded(port, cwd) {
|
|
179
|
+
if (await isPortInUse(port)) {
|
|
180
|
+
console.log(`[iterate] daemon already running on port ${port}`);
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
const _req = typeof require !== "undefined" ? require : (0, import_node_module.createRequire)(import_meta.url);
|
|
184
|
+
const daemonEntryPath = resolvePackageEntry("iterate-ui-daemon", _req);
|
|
185
|
+
const daemonPath = `file://${daemonEntryPath}`;
|
|
186
|
+
const child = (0, import_node_child_process.spawn)(
|
|
187
|
+
process.execPath,
|
|
188
|
+
[
|
|
189
|
+
"--input-type=module",
|
|
190
|
+
"-e",
|
|
191
|
+
`import { startDaemon } from ${JSON.stringify(daemonPath)}; startDaemon({ port: ${port}, cwd: ${JSON.stringify(cwd)} });`
|
|
192
|
+
],
|
|
193
|
+
{
|
|
194
|
+
cwd,
|
|
195
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
196
|
+
env: {
|
|
197
|
+
...process.env,
|
|
198
|
+
ITERATE_PORT: String(port),
|
|
199
|
+
ITERATE_CWD: cwd,
|
|
200
|
+
NODE_NO_WARNINGS: "1"
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
child.stdout?.on("data", (data) => {
|
|
205
|
+
const msg = data.toString().trim();
|
|
206
|
+
if (msg) console.log(`[iterate] ${msg}`);
|
|
207
|
+
});
|
|
208
|
+
child.stderr?.on("data", (data) => {
|
|
209
|
+
const msg = data.toString().trim();
|
|
210
|
+
if (msg && !msg.includes("ExperimentalWarning")) {
|
|
211
|
+
console.error(`[iterate] ${msg}`);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
child.on("exit", (code) => {
|
|
215
|
+
if (code !== 0 && code !== null) {
|
|
216
|
+
console.error(`[iterate] daemon exited with code ${code}`);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
return child;
|
|
220
|
+
}
|
|
221
|
+
function stopDaemon(child, port) {
|
|
222
|
+
try {
|
|
223
|
+
fetch(`http://127.0.0.1:${port}/api/shutdown`, { method: "POST" }).catch(
|
|
224
|
+
() => {
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
} catch {
|
|
228
|
+
}
|
|
229
|
+
child?.kill("SIGTERM");
|
|
230
|
+
}
|
|
231
|
+
var index_default = withIterate;
|
|
232
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
233
|
+
0 && (module.exports = {
|
|
234
|
+
withIterate
|
|
235
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface IterateNextOptions {
|
|
2
|
+
/** Port for the iterate daemon (default: 4000) */
|
|
3
|
+
daemonPort?: number;
|
|
4
|
+
/** Disable the babel plugin that injects component names/source locations (default: false) */
|
|
5
|
+
disableBabelPlugin?: boolean;
|
|
6
|
+
}
|
|
7
|
+
type NextConfig = Record<string, any>;
|
|
8
|
+
/**
|
|
9
|
+
* Next.js config wrapper for iterate.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```js
|
|
13
|
+
* // next.config.mjs
|
|
14
|
+
* import { withIterate } from 'iterate-ui-next'
|
|
15
|
+
* export default withIterate({
|
|
16
|
+
* // ...your Next.js config
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Automatically:
|
|
21
|
+
* 1. Starts the iterate daemon when `next dev` runs
|
|
22
|
+
* 2. Proxies /__iterate__/* and iterate API routes to the daemon via rewrites
|
|
23
|
+
* 3. Injects the overlay script via webpack entry
|
|
24
|
+
* 4. Cleans up daemon on exit
|
|
25
|
+
*/
|
|
26
|
+
declare function withIterate(nextConfig?: NextConfig, options?: IterateNextOptions): NextConfig;
|
|
27
|
+
|
|
28
|
+
export { type IterateNextOptions, withIterate as default, withIterate };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface IterateNextOptions {
|
|
2
|
+
/** Port for the iterate daemon (default: 4000) */
|
|
3
|
+
daemonPort?: number;
|
|
4
|
+
/** Disable the babel plugin that injects component names/source locations (default: false) */
|
|
5
|
+
disableBabelPlugin?: boolean;
|
|
6
|
+
}
|
|
7
|
+
type NextConfig = Record<string, any>;
|
|
8
|
+
/**
|
|
9
|
+
* Next.js config wrapper for iterate.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```js
|
|
13
|
+
* // next.config.mjs
|
|
14
|
+
* import { withIterate } from 'iterate-ui-next'
|
|
15
|
+
* export default withIterate({
|
|
16
|
+
* // ...your Next.js config
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Automatically:
|
|
21
|
+
* 1. Starts the iterate daemon when `next dev` runs
|
|
22
|
+
* 2. Proxies /__iterate__/* and iterate API routes to the daemon via rewrites
|
|
23
|
+
* 3. Injects the overlay script via webpack entry
|
|
24
|
+
* 4. Cleans up daemon on exit
|
|
25
|
+
*/
|
|
26
|
+
declare function withIterate(nextConfig?: NextConfig, options?: IterateNextOptions): NextConfig;
|
|
27
|
+
|
|
28
|
+
export { type IterateNextOptions, withIterate as default, withIterate };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import { spawn, execSync } from "child_process";
|
|
10
|
+
import { createConnection } from "net";
|
|
11
|
+
import { createRequire } from "module";
|
|
12
|
+
import { join, dirname } from "path";
|
|
13
|
+
import { readFileSync } from "fs";
|
|
14
|
+
function resolvePackageEntry(packageName, _require) {
|
|
15
|
+
try {
|
|
16
|
+
return _require.resolve(packageName);
|
|
17
|
+
} catch {
|
|
18
|
+
const pkgJsonPath = _require.resolve(`${packageName}/package.json`);
|
|
19
|
+
const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
|
|
20
|
+
const main = pkg.exports?.["."]?.import ?? pkg.main ?? "index.js";
|
|
21
|
+
return join(dirname(pkgJsonPath), main);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
var daemon = null;
|
|
25
|
+
var daemonStarting = false;
|
|
26
|
+
function withIterate(nextConfig = {}, options = {}) {
|
|
27
|
+
const daemonPort = options.daemonPort ?? 4e3;
|
|
28
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
29
|
+
if (!isDev) {
|
|
30
|
+
return nextConfig;
|
|
31
|
+
}
|
|
32
|
+
if (!daemon && !daemonStarting) {
|
|
33
|
+
daemonStarting = true;
|
|
34
|
+
const repoRoot = getGitRoot() ?? process.cwd();
|
|
35
|
+
startDaemonIfNeeded(daemonPort, repoRoot).then((child) => {
|
|
36
|
+
if (child) {
|
|
37
|
+
daemon = child;
|
|
38
|
+
const cleanup = () => {
|
|
39
|
+
if (daemon) {
|
|
40
|
+
stopDaemon(daemon, daemonPort);
|
|
41
|
+
daemon = null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
process.on("SIGINT", cleanup);
|
|
45
|
+
process.on("SIGTERM", cleanup);
|
|
46
|
+
process.on("exit", cleanup);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const _require = typeof __require !== "undefined" ? __require : createRequire(import.meta.url);
|
|
51
|
+
let overlayBundlePath;
|
|
52
|
+
let babelPluginPath;
|
|
53
|
+
try {
|
|
54
|
+
overlayBundlePath = resolvePackageEntry("iterate-ui-overlay/standalone", _require);
|
|
55
|
+
if (!options.disableBabelPlugin) {
|
|
56
|
+
babelPluginPath = resolvePackageEntry("iterate-ui-babel-plugin", _require);
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
console.warn("[iterate] Could not resolve overlay bundle or babel plugin");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
...nextConfig,
|
|
63
|
+
// Add rewrites to proxy to the daemon
|
|
64
|
+
async rewrites() {
|
|
65
|
+
const existingRewrites = await (nextConfig.rewrites?.() ?? []);
|
|
66
|
+
const iterateRewrites = [
|
|
67
|
+
{
|
|
68
|
+
source: "/__iterate__/:path*",
|
|
69
|
+
destination: `http://127.0.0.1:${daemonPort}/__iterate__/:path*`
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
source: "/api/iterations/:path*",
|
|
73
|
+
destination: `http://127.0.0.1:${daemonPort}/api/iterations/:path*`
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
source: "/api/annotations/:path*",
|
|
77
|
+
destination: `http://127.0.0.1:${daemonPort}/api/annotations/:path*`
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
source: "/api/dom-changes",
|
|
81
|
+
destination: `http://127.0.0.1:${daemonPort}/api/dom-changes`
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
source: "/api/command",
|
|
85
|
+
destination: `http://127.0.0.1:${daemonPort}/api/command`
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
source: "/api/command-context/:path*",
|
|
89
|
+
destination: `http://127.0.0.1:${daemonPort}/api/command-context/:path*`
|
|
90
|
+
}
|
|
91
|
+
];
|
|
92
|
+
if (Array.isArray(existingRewrites)) {
|
|
93
|
+
return [...iterateRewrites, ...existingRewrites];
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
...existingRewrites,
|
|
97
|
+
beforeFiles: [
|
|
98
|
+
...iterateRewrites,
|
|
99
|
+
...existingRewrites.beforeFiles ?? []
|
|
100
|
+
]
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
// Inject overlay via webpack
|
|
104
|
+
webpack(config, context) {
|
|
105
|
+
if (context.isServer || !context.dev) {
|
|
106
|
+
return nextConfig.webpack?.(config, context) ?? config;
|
|
107
|
+
}
|
|
108
|
+
const originalEntry = config.entry;
|
|
109
|
+
config.entry = async () => {
|
|
110
|
+
const entries = await (typeof originalEntry === "function" ? originalEntry() : originalEntry);
|
|
111
|
+
const injectorPath = createIterateInjector(overlayBundlePath, daemonPort);
|
|
112
|
+
if (injectorPath && entries["main-app"]) {
|
|
113
|
+
if (Array.isArray(entries["main-app"])) {
|
|
114
|
+
entries["main-app"].push(injectorPath);
|
|
115
|
+
}
|
|
116
|
+
} else if (injectorPath && entries["main"]) {
|
|
117
|
+
if (Array.isArray(entries["main"])) {
|
|
118
|
+
entries["main"].push(injectorPath);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return entries;
|
|
122
|
+
};
|
|
123
|
+
return nextConfig.webpack?.(config, context) ?? config;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function createIterateInjector(_overlayPath, daemonPort) {
|
|
128
|
+
const iterationName = process.env.ITERATE_ITERATION_NAME ?? "__original__";
|
|
129
|
+
const code = `
|
|
130
|
+
if (typeof window !== 'undefined') {
|
|
131
|
+
window.__iterate_shell__ = { activeTool: 'browse', activeIteration: ${JSON.stringify(iterationName)}, daemonPort: ${daemonPort} };
|
|
132
|
+
var s = document.createElement('script');
|
|
133
|
+
s.src = '/__iterate__/overlay.js';
|
|
134
|
+
s.defer = true;
|
|
135
|
+
document.head.appendChild(s);
|
|
136
|
+
}
|
|
137
|
+
`;
|
|
138
|
+
return `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
|
|
139
|
+
}
|
|
140
|
+
function isPortInUse(port) {
|
|
141
|
+
return new Promise((resolve) => {
|
|
142
|
+
const socket = createConnection({ port, host: "127.0.0.1" });
|
|
143
|
+
socket.on("connect", () => {
|
|
144
|
+
socket.destroy();
|
|
145
|
+
resolve(true);
|
|
146
|
+
});
|
|
147
|
+
socket.on("error", () => {
|
|
148
|
+
resolve(false);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function getGitRoot() {
|
|
153
|
+
try {
|
|
154
|
+
return execSync("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();
|
|
155
|
+
} catch {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function startDaemonIfNeeded(port, cwd) {
|
|
160
|
+
if (await isPortInUse(port)) {
|
|
161
|
+
console.log(`[iterate] daemon already running on port ${port}`);
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const _req = typeof __require !== "undefined" ? __require : createRequire(import.meta.url);
|
|
165
|
+
const daemonEntryPath = resolvePackageEntry("iterate-ui-daemon", _req);
|
|
166
|
+
const daemonPath = `file://${daemonEntryPath}`;
|
|
167
|
+
const child = spawn(
|
|
168
|
+
process.execPath,
|
|
169
|
+
[
|
|
170
|
+
"--input-type=module",
|
|
171
|
+
"-e",
|
|
172
|
+
`import { startDaemon } from ${JSON.stringify(daemonPath)}; startDaemon({ port: ${port}, cwd: ${JSON.stringify(cwd)} });`
|
|
173
|
+
],
|
|
174
|
+
{
|
|
175
|
+
cwd,
|
|
176
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
177
|
+
env: {
|
|
178
|
+
...process.env,
|
|
179
|
+
ITERATE_PORT: String(port),
|
|
180
|
+
ITERATE_CWD: cwd,
|
|
181
|
+
NODE_NO_WARNINGS: "1"
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
child.stdout?.on("data", (data) => {
|
|
186
|
+
const msg = data.toString().trim();
|
|
187
|
+
if (msg) console.log(`[iterate] ${msg}`);
|
|
188
|
+
});
|
|
189
|
+
child.stderr?.on("data", (data) => {
|
|
190
|
+
const msg = data.toString().trim();
|
|
191
|
+
if (msg && !msg.includes("ExperimentalWarning")) {
|
|
192
|
+
console.error(`[iterate] ${msg}`);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
child.on("exit", (code) => {
|
|
196
|
+
if (code !== 0 && code !== null) {
|
|
197
|
+
console.error(`[iterate] daemon exited with code ${code}`);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return child;
|
|
201
|
+
}
|
|
202
|
+
function stopDaemon(child, port) {
|
|
203
|
+
try {
|
|
204
|
+
fetch(`http://127.0.0.1:${port}/api/shutdown`, { method: "POST" }).catch(
|
|
205
|
+
() => {
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
} catch {
|
|
209
|
+
}
|
|
210
|
+
child?.kill("SIGTERM");
|
|
211
|
+
}
|
|
212
|
+
var index_default = withIterate;
|
|
213
|
+
export {
|
|
214
|
+
index_default as default,
|
|
215
|
+
withIterate
|
|
216
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "iterate-ui-next",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "iterate Next.js 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/next"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://iterate-ui.com",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"iterate",
|
|
14
|
+
"ui",
|
|
15
|
+
"nextjs",
|
|
16
|
+
"next",
|
|
17
|
+
"plugin",
|
|
18
|
+
"ai",
|
|
19
|
+
"worktree"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"require": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"iterate-ui-daemon": "0.1.0",
|
|
36
|
+
"iterate-ui-overlay": "0.1.0",
|
|
37
|
+
"iterate-ui-babel-plugin": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"next": "^14.0.0 || ^15.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.0.0",
|
|
44
|
+
"tsup": "^8.3.0",
|
|
45
|
+
"typescript": "^5.7.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
49
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
50
|
+
"clean": "rm -rf dist"
|
|
51
|
+
}
|
|
52
|
+
}
|