extension-develop 3.17.0 → 3.18.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.
Files changed (43) hide show
  1. package/dist/0~dev-server.mjs +660 -59
  2. package/dist/0~rspack-config.mjs +867 -881
  3. package/dist/0~zip.mjs +39 -10
  4. package/dist/45.mjs +39 -0
  5. package/dist/946.mjs +142 -36
  6. package/dist/962.mjs +299 -250
  7. package/dist/bridge.mjs +228 -0
  8. package/dist/extension-js-devtools/chrome/content_scripts/content-0.js +2 -2
  9. package/dist/extension-js-devtools/chrome/pages/centralized-logger.js +1 -1
  10. package/dist/extension-js-devtools/chrome/pages/welcome.js +2 -2
  11. package/dist/extension-js-devtools/chrome/scripts/logger-client.js +1 -1
  12. package/dist/extension-js-devtools/chromium/content_scripts/content-0.js +2 -2
  13. package/dist/extension-js-devtools/chromium/pages/centralized-logger.js +1 -1
  14. package/dist/extension-js-devtools/chromium/pages/welcome.js +2 -2
  15. package/dist/extension-js-devtools/chromium/scripts/logger-client.js +1 -1
  16. package/dist/extension-js-devtools/edge/content_scripts/content-0.js +2 -2
  17. package/dist/extension-js-devtools/edge/pages/centralized-logger.js +1 -1
  18. package/dist/extension-js-devtools/edge/pages/welcome.js +2 -2
  19. package/dist/extension-js-devtools/edge/scripts/logger-client.js +1 -1
  20. package/dist/extension-js-devtools/extension-js/chrome/events.ndjson +2 -0
  21. package/dist/extension-js-devtools/extension-js/chrome/ready.json +16 -0
  22. package/dist/extension-js-devtools/extension-js/chromium/events.ndjson +2 -0
  23. package/dist/extension-js-devtools/extension-js/chromium/ready.json +16 -0
  24. package/dist/extension-js-devtools/extension-js/edge/events.ndjson +2 -0
  25. package/dist/extension-js-devtools/extension-js/edge/ready.json +16 -0
  26. package/dist/extension-js-devtools/extension-js/firefox/events.ndjson +2 -0
  27. package/dist/extension-js-devtools/extension-js/firefox/ready.json +16 -0
  28. package/dist/extension-js-devtools/firefox/content_scripts/content-0.js +2 -2
  29. package/dist/extension-js-devtools/firefox/pages/centralized-logger.js +1 -1
  30. package/dist/extension-js-devtools/firefox/pages/welcome.js +2 -2
  31. package/dist/extension-js-devtools/firefox/scripts/logger-client.js +1 -1
  32. package/dist/extension-js-theme/extension-js/chrome/events.ndjson +2 -0
  33. package/dist/extension-js-theme/extension-js/chrome/ready.json +16 -0
  34. package/dist/extension-js-theme/extension-js/chromium/events.ndjson +2 -0
  35. package/dist/extension-js-theme/extension-js/chromium/ready.json +16 -0
  36. package/dist/extension-js-theme/extension-js/edge/events.ndjson +2 -0
  37. package/dist/extension-js-theme/extension-js/edge/ready.json +16 -0
  38. package/dist/extension-js-theme/extension-js/firefox/events.ndjson +4 -0
  39. package/dist/extension-js-theme/extension-js/firefox/ready.json +16 -0
  40. package/dist/feature-scripts-content-script-wrapper.js +19 -2
  41. package/dist/feature-scripts-content-script-wrapper.mjs +19 -2
  42. package/package.json +14 -5
  43. package/runtime/process-shim.cjs +49 -0
@@ -0,0 +1,228 @@
1
+ import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
2
+ import { WebSocket } from "ws";
3
+ import { CONTROL_WS_PATH } from "./45.mjs";
4
+ import * as __rspack_external_fs from "fs";
5
+ import * as __rspack_external_path from "path";
6
+ function readReadyContract(projectPath, browser = 'chrome') {
7
+ const readyPath = __rspack_external_path.resolve(projectPath, 'dist', 'extension-js', browser, 'ready.json');
8
+ try {
9
+ const c = JSON.parse(__rspack_external_fs.readFileSync(readyPath, 'utf-8'));
10
+ if ('number' != typeof c.controlPort || !c.instanceId) return null;
11
+ return {
12
+ controlPort: c.controlPort,
13
+ instanceId: String(c.instanceId),
14
+ runId: String(c.runId || ''),
15
+ logsPath: c.logsPath,
16
+ status: c.status
17
+ };
18
+ } catch {
19
+ return null;
20
+ }
21
+ }
22
+ class BridgeConsumer {
23
+ opts;
24
+ socket = null;
25
+ backoff = 250;
26
+ maxBackoff = 5000;
27
+ closed = false;
28
+ timer = null;
29
+ constructor(options){
30
+ this.opts = options;
31
+ }
32
+ start() {
33
+ this.closed = false;
34
+ this.connect();
35
+ }
36
+ close() {
37
+ this.closed = true;
38
+ if (this.timer) clearTimeout(this.timer);
39
+ try {
40
+ this.socket?.close();
41
+ } catch {}
42
+ this.socket = null;
43
+ }
44
+ url() {
45
+ const host = this.opts.host ?? '127.0.0.1';
46
+ const p = this.opts.path ?? CONTROL_WS_PATH;
47
+ return `ws://${host}:${this.opts.controlPort}${p}`;
48
+ }
49
+ connect() {
50
+ if (this.closed) return;
51
+ let socket;
52
+ try {
53
+ socket = new WebSocket(this.url());
54
+ } catch {
55
+ this.scheduleReconnect();
56
+ return;
57
+ }
58
+ this.socket = socket;
59
+ socket.on('open', ()=>{
60
+ this.backoff = 250;
61
+ try {
62
+ socket.send(JSON.stringify({
63
+ type: 'hello',
64
+ v: 1,
65
+ role: 'consumer',
66
+ instanceId: this.opts.instanceId
67
+ }));
68
+ } catch {}
69
+ });
70
+ socket.on('message', (data)=>{
71
+ let frame;
72
+ try {
73
+ frame = JSON.parse(data.toString());
74
+ } catch {
75
+ return;
76
+ }
77
+ if ('ready' === frame.type) this.opts.onReady?.(frame);
78
+ else if ('log' === frame.type) this.opts.onLog?.(frame.event);
79
+ else if ('gap' === frame.type) this.opts.onGap?.(frame);
80
+ });
81
+ socket.on('close', ()=>{
82
+ this.socket = null;
83
+ this.opts.onClose?.();
84
+ if (this.opts.reconnect) this.scheduleReconnect();
85
+ });
86
+ socket.on('error', ()=>{
87
+ try {
88
+ socket.close();
89
+ } catch {}
90
+ });
91
+ }
92
+ scheduleReconnect() {
93
+ if (this.closed || !this.opts.reconnect) return;
94
+ const delay = this.backoff;
95
+ this.backoff = Math.min(2 * this.backoff, this.maxBackoff);
96
+ this.timer = setTimeout(()=>this.connect(), delay);
97
+ }
98
+ }
99
+ const DEFAULT_CONNECT_TIMEOUT_MS = 10000;
100
+ let cmdSeq = 0;
101
+ class BridgeController {
102
+ opts;
103
+ socket = null;
104
+ ready = null;
105
+ connectPromise = null;
106
+ pending = new Map();
107
+ constructor(options){
108
+ this.opts = options;
109
+ }
110
+ get capabilities() {
111
+ return this.ready?.capabilities;
112
+ }
113
+ connect() {
114
+ if (this.connectPromise) return this.connectPromise;
115
+ const host = this.opts.host ?? '127.0.0.1';
116
+ const wsPath = this.opts.path ?? CONTROL_WS_PATH;
117
+ const url = `ws://${host}:${this.opts.controlPort}${wsPath}`;
118
+ this.connectPromise = new Promise((resolve, reject)=>{
119
+ let settled = false;
120
+ const connectTimer = setTimeout(()=>{
121
+ if (settled) return;
122
+ settled = true;
123
+ this.close();
124
+ reject(new Error(`control channel handshake timed out at ${url}`));
125
+ }, this.opts.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS);
126
+ let socket;
127
+ try {
128
+ socket = new WebSocket(url);
129
+ } catch (err) {
130
+ clearTimeout(connectTimer);
131
+ reject(err instanceof Error ? err : new Error(String(err)));
132
+ return;
133
+ }
134
+ this.socket = socket;
135
+ socket.on('open', ()=>{
136
+ socket.send(JSON.stringify({
137
+ type: 'hello',
138
+ v: 1,
139
+ role: 'controller',
140
+ instanceId: this.opts.instanceId,
141
+ ...this.opts.token ? {
142
+ token: this.opts.token
143
+ } : {}
144
+ }));
145
+ });
146
+ socket.on('message', (data)=>{
147
+ let frame;
148
+ try {
149
+ frame = JSON.parse(data.toString());
150
+ } catch {
151
+ return;
152
+ }
153
+ if ('ready' === frame.type) {
154
+ this.ready = frame;
155
+ if (!settled) {
156
+ settled = true;
157
+ clearTimeout(connectTimer);
158
+ resolve(this.ready);
159
+ }
160
+ return;
161
+ }
162
+ if ('result' === frame.type) this.resolveResult(frame);
163
+ });
164
+ socket.on('close', (code, reasonBuf)=>{
165
+ const reason = reasonBuf?.toString() || '';
166
+ if (!settled) {
167
+ settled = true;
168
+ clearTimeout(connectTimer);
169
+ reject(new Error(`control channel refused the controller (code ${code}${reason ? `: ${reason}` : ''}). Is the session started with --allow-control?`));
170
+ }
171
+ this.failAllPending(new Error(`control channel closed (code ${code})`));
172
+ this.socket = null;
173
+ });
174
+ socket.on('error', ()=>{});
175
+ });
176
+ return this.connectPromise;
177
+ }
178
+ async command(input) {
179
+ await this.connect();
180
+ const socket = this.socket;
181
+ if (!socket || socket.readyState !== WebSocket.OPEN) throw new Error('control channel is not open');
182
+ const cmdId = `c-${Date.now()}-${++cmdSeq}`;
183
+ const timeoutMs = input.timeoutMs ?? 5000;
184
+ const backstopMs = Math.min(timeoutMs, 30000) + 2000;
185
+ return new Promise((resolve, reject)=>{
186
+ const timer = setTimeout(()=>{
187
+ this.pending.delete(cmdId);
188
+ reject(new Error(`command ${input.op} timed out after ${backstopMs}ms`));
189
+ }, backstopMs);
190
+ this.pending.set(cmdId, {
191
+ resolve,
192
+ reject,
193
+ timer
194
+ });
195
+ socket.send(JSON.stringify({
196
+ type: 'command',
197
+ cmdId,
198
+ op: input.op,
199
+ target: input.target,
200
+ args: input.args,
201
+ timeoutMs
202
+ }));
203
+ });
204
+ }
205
+ close() {
206
+ this.failAllPending(new Error('controller closed'));
207
+ try {
208
+ this.socket?.close();
209
+ } catch {}
210
+ this.socket = null;
211
+ }
212
+ resolveResult(result) {
213
+ const p = this.pending.get(result.cmdId);
214
+ if (!p) return;
215
+ clearTimeout(p.timer);
216
+ this.pending.delete(result.cmdId);
217
+ p.resolve(result);
218
+ }
219
+ failAllPending(err) {
220
+ for (const [, p] of this.pending){
221
+ clearTimeout(p.timer);
222
+ p.reject(err);
223
+ }
224
+ this.pending.clear();
225
+ }
226
+ }
227
+ export { controlTokenPath, readControlToken } from "./45.mjs";
228
+ export { BridgeConsumer, BridgeController, readReadyContract };