paneful 0.8.5 → 0.8.7
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/dist/server/port-monitor.js +38 -21
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import net from
|
|
1
|
+
import net from "node:net";
|
|
2
2
|
// Strip ANSI escape codes from PTY output
|
|
3
3
|
const ANSI_RE = /\x1b\[[0-9;]*[a-zA-Z]|\x1b\].*?(?:\x07|\x1b\\)|\x1b[()][0-9A-B]/g;
|
|
4
4
|
// Match dev-server URLs like http://localhost:3000, http://127.0.0.1:8080, etc.
|
|
@@ -18,7 +18,7 @@ export class PortMonitor {
|
|
|
18
18
|
return;
|
|
19
19
|
let info = this.terminals.get(terminalId);
|
|
20
20
|
if (!info) {
|
|
21
|
-
info = { projectId, ports: new Set(), lineBuffer:
|
|
21
|
+
info = { projectId, ports: new Set(), lineBuffer: "" };
|
|
22
22
|
this.terminals.set(terminalId, info);
|
|
23
23
|
}
|
|
24
24
|
// Already found ports for this terminal — skip scanning.
|
|
@@ -26,11 +26,13 @@ export class PortMonitor {
|
|
|
26
26
|
// so scanning resumes automatically on restart.
|
|
27
27
|
if (info.ports.size > 0)
|
|
28
28
|
return;
|
|
29
|
-
//
|
|
30
|
-
const clean =
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
// Strip ANSI codes from just the new chunk, then append to line buffer
|
|
30
|
+
const clean = data.replace(ANSI_RE, "");
|
|
31
|
+
const combined = info.lineBuffer + clean;
|
|
32
|
+
const lines = combined.split(/\r?\n/);
|
|
33
|
+
// Keep last incomplete line in buffer, capped to prevent unbounded growth
|
|
34
|
+
const tail = lines.pop() ?? "";
|
|
35
|
+
info.lineBuffer = tail.length > 512 ? tail.slice(-512) : tail;
|
|
34
36
|
let found = false;
|
|
35
37
|
for (const line of lines) {
|
|
36
38
|
PORT_RE.lastIndex = 0;
|
|
@@ -109,20 +111,35 @@ export class PortMonitor {
|
|
|
109
111
|
}
|
|
110
112
|
const probeResults = new Map();
|
|
111
113
|
await Promise.all([...uniquePorts].map((port) => new Promise((resolve) => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
114
|
+
// Try IPv4 first, fall back to IPv6 (::1).
|
|
115
|
+
// Many dev servers (Angular/Vite) bind to ::1 on macOS.
|
|
116
|
+
const tryConnect = (host, fallback) => {
|
|
117
|
+
const sock = net.createConnection({ port, host }, () => {
|
|
118
|
+
probeResults.set(port, true);
|
|
119
|
+
sock.destroy();
|
|
120
|
+
resolve();
|
|
121
|
+
});
|
|
122
|
+
sock.on("error", () => {
|
|
123
|
+
if (fallback) {
|
|
124
|
+
tryConnect(fallback);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
probeResults.set(port, false);
|
|
128
|
+
resolve();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
sock.setTimeout(2000, () => {
|
|
132
|
+
sock.destroy();
|
|
133
|
+
if (fallback) {
|
|
134
|
+
tryConnect(fallback);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
probeResults.set(port, false);
|
|
138
|
+
resolve();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
tryConnect("127.0.0.1", "::1");
|
|
126
143
|
})));
|
|
127
144
|
if (this.destroyed)
|
|
128
145
|
return;
|