@player-devtools/client-flipper 0.14.1-next.0 → 0.14.2--canary.22.1064
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/index.legacy-esm.js +0 -274
- package/package.json +2 -2
package/dist/index.legacy-esm.js
CHANGED
|
@@ -1,274 +0,0 @@
|
|
|
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
|
-
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/flipper/src/transport.ts
|
|
9
|
-
import {
|
|
10
|
-
createFlipperServer,
|
|
11
|
-
FlipperServerState
|
|
12
|
-
} from "flipper-server-client";
|
|
13
|
-
import { spawn } from "child_process";
|
|
14
|
-
import * as net from "net";
|
|
15
|
-
import * as fs from "fs";
|
|
16
|
-
import * as os from "os";
|
|
17
|
-
import * as path from "path";
|
|
18
|
-
import { WebSocket as WsWebSocket } from "ws";
|
|
19
|
-
if (typeof globalThis.WebSocket === "undefined") {
|
|
20
|
-
globalThis.WebSocket = WsWebSocket;
|
|
21
|
-
}
|
|
22
|
-
var PLUGIN_API = "player-ui-devtools";
|
|
23
|
-
function waitForPort(host, port, timeoutMs = 3e4) {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
const deadline = Date.now() + timeoutMs;
|
|
26
|
-
const attempt = () => {
|
|
27
|
-
const socket = net.connect(port, host);
|
|
28
|
-
socket.once("connect", () => {
|
|
29
|
-
socket.destroy();
|
|
30
|
-
resolve();
|
|
31
|
-
});
|
|
32
|
-
socket.once("error", () => {
|
|
33
|
-
socket.destroy();
|
|
34
|
-
if (Date.now() >= deadline) {
|
|
35
|
-
reject(new Error(`Timed out waiting for ${host}:${port}`));
|
|
36
|
-
} else {
|
|
37
|
-
setTimeout(attempt, 500);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
attempt();
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
var FlipperRefcount = class {
|
|
45
|
-
constructor() {
|
|
46
|
-
this.dir = path.join(os.tmpdir(), "player-devtools-mcp");
|
|
47
|
-
this.file = path.join(this.dir, "flipper-server.refcount");
|
|
48
|
-
this.lock = path.join(this.dir, "flipper-server.lock");
|
|
49
|
-
}
|
|
50
|
-
/** Acquire the cross-process lock, run `fn`, then release — even on throw. */
|
|
51
|
-
withLock(fn) {
|
|
52
|
-
fs.mkdirSync(this.dir, { recursive: true });
|
|
53
|
-
const deadline = Date.now() + 5e3;
|
|
54
|
-
for (; ; ) {
|
|
55
|
-
try {
|
|
56
|
-
fs.mkdirSync(this.lock);
|
|
57
|
-
break;
|
|
58
|
-
} catch (err) {
|
|
59
|
-
if (err.code !== "EEXIST") throw err;
|
|
60
|
-
if (Date.now() >= deadline) {
|
|
61
|
-
try {
|
|
62
|
-
fs.rmdirSync(this.lock);
|
|
63
|
-
} catch {
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
return fn();
|
|
70
|
-
} finally {
|
|
71
|
-
try {
|
|
72
|
-
fs.rmdirSync(this.lock);
|
|
73
|
-
} catch {
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
read() {
|
|
78
|
-
try {
|
|
79
|
-
return JSON.parse(fs.readFileSync(this.file, "utf8"));
|
|
80
|
-
} catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
write(state) {
|
|
85
|
-
fs.writeFileSync(this.file, JSON.stringify(state));
|
|
86
|
-
}
|
|
87
|
-
clear() {
|
|
88
|
-
try {
|
|
89
|
-
fs.unlinkSync(this.file);
|
|
90
|
-
} catch {
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/** Is the recorded daemon PID still alive? */
|
|
94
|
-
isAlive(pid) {
|
|
95
|
-
try {
|
|
96
|
-
process.kill(pid, 0);
|
|
97
|
-
return true;
|
|
98
|
-
} catch {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Register interest in the daemon. Returns whether this caller is the one
|
|
104
|
-
* responsible for starting it (because no live daemon was recorded).
|
|
105
|
-
* `recordPid` is called with the started PID once the daemon is up.
|
|
106
|
-
*/
|
|
107
|
-
acquire() {
|
|
108
|
-
return this.withLock(() => {
|
|
109
|
-
const state = this.read();
|
|
110
|
-
if (state && this.isAlive(state.pid)) {
|
|
111
|
-
this.write({ pid: state.pid, refs: state.refs + 1 });
|
|
112
|
-
return { shouldStart: false, commit: () => {
|
|
113
|
-
} };
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
shouldStart: true,
|
|
117
|
-
commit: (pid) => this.withLock(() => this.write({ pid, refs: 1 }))
|
|
118
|
-
};
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Drop this caller's interest. Returns the PID to kill if this was the last
|
|
123
|
-
* reference, otherwise null.
|
|
124
|
-
*/
|
|
125
|
-
release() {
|
|
126
|
-
return this.withLock(() => {
|
|
127
|
-
const state = this.read();
|
|
128
|
-
if (!state) return null;
|
|
129
|
-
if (state.refs <= 1) {
|
|
130
|
-
this.clear();
|
|
131
|
-
return state.pid;
|
|
132
|
-
}
|
|
133
|
-
this.write({ pid: state.pid, refs: state.refs - 1 });
|
|
134
|
-
return null;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
var FlipperServerTransport = class {
|
|
139
|
-
constructor(options = {}) {
|
|
140
|
-
this.options = options;
|
|
141
|
-
this.server = null;
|
|
142
|
-
this.refcount = new FlipperRefcount();
|
|
143
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
144
|
-
/**
|
|
145
|
-
* Client IDs that have sent at least one message through the devtools
|
|
146
|
-
* plugin — these are the clients we send outbound messages to.
|
|
147
|
-
*/
|
|
148
|
-
this.activeClientIds = /* @__PURE__ */ new Set();
|
|
149
|
-
this.sendMessage = async (message) => {
|
|
150
|
-
if (!this.server) return;
|
|
151
|
-
const payload = {
|
|
152
|
-
method: "execute",
|
|
153
|
-
params: {
|
|
154
|
-
api: PLUGIN_API,
|
|
155
|
-
method: "message::flipper",
|
|
156
|
-
params: message
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
await Promise.all(
|
|
160
|
-
[...this.activeClientIds].map(
|
|
161
|
-
(clientId) => this.server.exec("client-request-response", clientId, payload).catch(
|
|
162
|
-
(err) => {
|
|
163
|
-
console.warn(
|
|
164
|
-
`[FlipperServerTransport] Failed to send to client ${clientId}:`,
|
|
165
|
-
err
|
|
166
|
-
);
|
|
167
|
-
this.activeClientIds.delete(clientId);
|
|
168
|
-
}
|
|
169
|
-
)
|
|
170
|
-
)
|
|
171
|
-
);
|
|
172
|
-
};
|
|
173
|
-
this.addListener = (callback) => {
|
|
174
|
-
this.listeners.add(callback);
|
|
175
|
-
};
|
|
176
|
-
this.removeListener = (callback) => {
|
|
177
|
-
this.listeners.delete(callback);
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
async connect() {
|
|
181
|
-
const host = this.options.host ?? "localhost";
|
|
182
|
-
const port = this.options.port ?? 52342;
|
|
183
|
-
const { shouldStart, commit } = this.refcount.acquire();
|
|
184
|
-
if (shouldStart) {
|
|
185
|
-
console.log("[FlipperServerTransport] Starting flipper-server...");
|
|
186
|
-
const serverScript = __require.resolve("flipper-server/server.js");
|
|
187
|
-
const child = spawn(process.execPath, [serverScript, "--open=true"], {
|
|
188
|
-
stdio: "inherit",
|
|
189
|
-
detached: true
|
|
190
|
-
});
|
|
191
|
-
child.on("error", (err) => {
|
|
192
|
-
console.error(
|
|
193
|
-
"[FlipperServerTransport] flipper-server process error:",
|
|
194
|
-
err
|
|
195
|
-
);
|
|
196
|
-
});
|
|
197
|
-
child.unref();
|
|
198
|
-
await waitForPort(host, port);
|
|
199
|
-
commit(child.pid);
|
|
200
|
-
console.log("[FlipperServerTransport] flipper-server ready.");
|
|
201
|
-
} else {
|
|
202
|
-
await waitForPort(host, port);
|
|
203
|
-
console.log("[FlipperServerTransport] Attached to flipper-server.");
|
|
204
|
-
}
|
|
205
|
-
const { getAuthToken } = (
|
|
206
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
207
|
-
__require("flipper-server/lib/app-connectivity/certificate-exchange/certificate-utils")
|
|
208
|
-
);
|
|
209
|
-
let cachedToken = null;
|
|
210
|
-
try {
|
|
211
|
-
cachedToken = await getAuthToken();
|
|
212
|
-
} catch (err) {
|
|
213
|
-
console.warn("[FlipperServerTransport] Could not read auth token:", err);
|
|
214
|
-
}
|
|
215
|
-
this.server = await createFlipperServer(
|
|
216
|
-
host,
|
|
217
|
-
port,
|
|
218
|
-
() => cachedToken,
|
|
219
|
-
(state) => {
|
|
220
|
-
if (state === FlipperServerState.DISCONNECTED) {
|
|
221
|
-
console.warn("[FlipperServerTransport] Disconnected from server");
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
);
|
|
225
|
-
await this.server.connect();
|
|
226
|
-
this.server.on("client-connected", (info) => {
|
|
227
|
-
console.log(
|
|
228
|
-
"[FlipperServerTransport] client-connected:",
|
|
229
|
-
JSON.stringify(info)
|
|
230
|
-
);
|
|
231
|
-
});
|
|
232
|
-
this.server.on("client-disconnected", ({ id }) => {
|
|
233
|
-
console.log("[FlipperServerTransport] client-disconnected:", id);
|
|
234
|
-
this.activeClientIds.delete(id);
|
|
235
|
-
});
|
|
236
|
-
this.server.on("client-message", ({ id, message }) => {
|
|
237
|
-
let parsed;
|
|
238
|
-
try {
|
|
239
|
-
parsed = JSON.parse(message);
|
|
240
|
-
} catch {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
console.debug(
|
|
244
|
-
`[FlipperServerTransport] client-message from ${id}: method=${parsed.method} api=${parsed.params?.api} pluginMethod=${parsed.params?.method}`
|
|
245
|
-
);
|
|
246
|
-
if (parsed.method !== "execute" || parsed.params?.api !== PLUGIN_API || parsed.params?.method !== "message::plugin") {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
this.activeClientIds.add(id);
|
|
250
|
-
const payload = parsed.params.params;
|
|
251
|
-
for (const listener of this.listeners) {
|
|
252
|
-
listener(payload);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
async close() {
|
|
257
|
-
this.listeners.clear();
|
|
258
|
-
this.activeClientIds.clear();
|
|
259
|
-
this.server?.close();
|
|
260
|
-
this.server = null;
|
|
261
|
-
const pidToKill = this.refcount.release();
|
|
262
|
-
if (pidToKill !== null) {
|
|
263
|
-
try {
|
|
264
|
-
process.kill(pidToKill);
|
|
265
|
-
console.log("[FlipperServerTransport] Shut down flipper-server.");
|
|
266
|
-
} catch {
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
export {
|
|
272
|
-
FlipperServerTransport
|
|
273
|
-
};
|
|
274
|
-
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
"types"
|
|
7
7
|
],
|
|
8
8
|
"name": "@player-devtools/client-flipper",
|
|
9
|
-
"version": "0.14.
|
|
9
|
+
"version": "0.14.2--canary.22.1064",
|
|
10
10
|
"main": "dist/cjs/index.cjs",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@player-devtools/types": "0.14.
|
|
12
|
+
"@player-devtools/types": "0.14.2--canary.22.1064",
|
|
13
13
|
"@types/ws": "^8.0.0",
|
|
14
14
|
"flipper-server": "^0.273.0",
|
|
15
15
|
"flipper-server-client": "^0.273.0",
|