@jobshimo/browser-link 0.43.0 → 0.44.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/README.md +26 -2
- package/dist/bridge/ws-bridge.d.ts +6 -2
- package/dist/bridge/ws-bridge.js +34 -27
- package/dist/bridge/ws-bridge.js.map +1 -1
- package/dist/cdp/inpage/observer.d.ts +2 -2
- package/dist/cdp/inpage/observer.js +11 -4
- package/dist/cdp/inpage/observer.js.map +1 -1
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +32 -7
- package/dist/cli.js.map +1 -1
- package/dist/commands/config.d.ts +15 -0
- package/dist/commands/config.js +55 -5
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/doctor.d.ts +20 -1
- package/dist/commands/doctor.js +41 -19
- package/dist/commands/doctor.js.map +1 -1
- package/dist/config.d.ts +20 -0
- package/dist/config.js +20 -0
- package/dist/config.js.map +1 -1
- package/dist/downloads.d.ts +10 -3
- package/dist/downloads.js +23 -4
- package/dist/downloads.js.map +1 -1
- package/dist/extension/inpage/observer.d.ts +2 -2
- package/dist/extension/inpage/observer.js +11 -4
- package/dist/extension/inpage/observer.js.map +1 -1
- package/dist/extension/manifest.json +1 -1
- package/dist/lifecycle/election.d.ts +16 -5
- package/dist/lifecycle/election.js +21 -4
- package/dist/lifecycle/election.js.map +1 -1
- package/dist/lifecycle/processes.d.ts +18 -0
- package/dist/lifecycle/processes.js +40 -7
- package/dist/lifecycle/processes.js.map +1 -1
- package/dist/lifecycle/repair.d.ts +15 -3
- package/dist/lifecycle/repair.js +41 -8
- package/dist/lifecycle/repair.js.map +1 -1
- package/dist/lifecycle/version-endpoint.d.ts +8 -3
- package/dist/lifecycle/version-endpoint.js +19 -4
- package/dist/lifecycle/version-endpoint.js.map +1 -1
- package/dist/manual/refresh.js +6 -0
- package/dist/manual/refresh.js.map +1 -1
- package/dist/permissions.js +6 -0
- package/dist/permissions.js.map +1 -1
- package/dist/server.js +8 -4
- package/dist/server.js.map +1 -1
- package/dist/tools/browser-definitions.js +6 -1
- package/dist/tools/browser-definitions.js.map +1 -1
- package/dist/tools/browser-dispatch.js +28 -4
- package/dist/tools/browser-dispatch.js.map +1 -1
- package/package.json +1 -1
|
@@ -62,8 +62,8 @@ export interface ObserverInstallOpts {
|
|
|
62
62
|
* the live node with `reresolved: false`, else the element with the same role,
|
|
63
63
|
* name and tag-only path when exactly one exists, rebinding the ref to it
|
|
64
64
|
* (`reresolved: true`); zero or several candidates give `null` (sibling
|
|
65
|
-
* indices are kept in the key as data but never pick among candidates). Candidates come from the document, every open shadow root
|
|
66
|
-
* from it, and every root the `attachShadow` patch observed (closed ones
|
|
65
|
+
* indices are kept in the key as data but never pick among candidates). Candidates come from the document, every open shadow root and
|
|
66
|
+
* same-origin iframe document reachable from it, and every root the `attachShadow` patch observed (closed ones
|
|
67
67
|
* included); closed roots attached before install are not reachable.
|
|
68
68
|
* `resolveRef(ref)` is `resolveRefDetailed(ref)?.el ?? null`. `keyForRef(ref)`
|
|
69
69
|
* returns a copy of the stored key or `null`. None of these throws.
|
|
@@ -61,8 +61,8 @@ function clampInt(value, fallback, min, max) {
|
|
|
61
61
|
* the live node with `reresolved: false`, else the element with the same role,
|
|
62
62
|
* name and tag-only path when exactly one exists, rebinding the ref to it
|
|
63
63
|
* (`reresolved: true`); zero or several candidates give `null` (sibling
|
|
64
|
-
* indices are kept in the key as data but never pick among candidates). Candidates come from the document, every open shadow root
|
|
65
|
-
* from it, and every root the `attachShadow` patch observed (closed ones
|
|
64
|
+
* indices are kept in the key as data but never pick among candidates). Candidates come from the document, every open shadow root and
|
|
65
|
+
* same-origin iframe document reachable from it, and every root the `attachShadow` patch observed (closed ones
|
|
66
66
|
* included); closed roots attached before install are not reachable.
|
|
67
67
|
* `resolveRef(ref)` is `resolveRefDetailed(ref)?.el ?? null`. `keyForRef(ref)`
|
|
68
68
|
* returns a copy of the stored key or `null`. None of these throws.
|
|
@@ -434,8 +434,10 @@ export function buildObserverInstallJs(opts = {}) {
|
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
-
// The document, every open shadow root
|
|
438
|
-
//
|
|
437
|
+
// The document, every open shadow root and same-origin iframe document
|
|
438
|
+
// reachable from it (nested either way, the roots browser.find({ key })
|
|
439
|
+
// searches), and every root the attachShadow patch observed (closed ones
|
|
440
|
+
// included) whose host is connected. A cross-origin frame is skipped.
|
|
439
441
|
function searchRoots() {
|
|
440
442
|
const roots = [document];
|
|
441
443
|
const seen = new Set(roots);
|
|
@@ -451,6 +453,11 @@ export function buildObserverInstallJs(opts = {}) {
|
|
|
451
453
|
try { all = roots[i].querySelectorAll('*'); } catch (e) { continue; }
|
|
452
454
|
for (const el of all) {
|
|
453
455
|
if (el.shadowRoot) add(el.shadowRoot);
|
|
456
|
+
if (tagOf(el) === 'iframe') {
|
|
457
|
+
let doc = null;
|
|
458
|
+
try { doc = el.contentDocument; } catch (e) { doc = null; }
|
|
459
|
+
add(doc);
|
|
460
|
+
}
|
|
454
461
|
}
|
|
455
462
|
}
|
|
456
463
|
return roots;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observer.js","sourceRoot":"","sources":["../../src/inpage/observer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,oFAAoF;AACpF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,sFAAsF;AACtF,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAEvD,oEAAoE;AACpE,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAElD,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,aAAa,GAAG,IAAI,CAAC;AAa3B,SAAS,QAAQ,CAAC,KAAc,EAAE,QAAgB,EAAE,GAAW,EAAE,GA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,CAAC;AACN,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "browser-link",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.44.0",
|
|
5
5
|
"description": "Bridge between Chrome and an MCP client (Claude Code, OpenCode, GitHub Copilot CLI, …). Per-tab manual activation.",
|
|
6
6
|
"permissions": [
|
|
7
7
|
"debugger",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ExecFileLike } from './processes.js';
|
|
1
|
+
import { type ExecFileLike, type ProcessEntry } from './processes.js';
|
|
2
2
|
/**
|
|
3
3
|
* Version-aware primary election.
|
|
4
4
|
*
|
|
@@ -11,7 +11,11 @@ import { type ExecFileLike } from './processes.js';
|
|
|
11
11
|
* (b) remote answers HTTP but has no `/version` (a primary older than
|
|
12
12
|
* 0.41.0) and its process started before the installed code was last
|
|
13
13
|
* written: it is necessarily running stale code → take over;
|
|
14
|
-
* (c)
|
|
14
|
+
* (c) same version and `repairing: true` (the primary is handing
|
|
15
|
+
* the port over to a successor it spawned, i.e. this process)
|
|
16
|
+
* → await the
|
|
17
|
+
* hand-off: keep retrying the bind, never step it down;
|
|
18
|
+
* (d) anything else (same or newer version, unknown start
|
|
15
19
|
* time, nothing answering HTTP) → defer.
|
|
16
20
|
*
|
|
17
21
|
* Deferring is the existing behaviour: proxy mode with multi-agent on, the
|
|
@@ -29,6 +33,9 @@ export interface VersionInfo {
|
|
|
29
33
|
pid: number;
|
|
30
34
|
startedAt: string;
|
|
31
35
|
installedVersion: string | null;
|
|
36
|
+
/** Since 0.44.0: a popup repair is handing the port over. Absent on older
|
|
37
|
+
* primaries. */
|
|
38
|
+
repairing?: boolean;
|
|
32
39
|
}
|
|
33
40
|
export type VersionProbe =
|
|
34
41
|
/** The primary answered `/version`. */
|
|
@@ -44,7 +51,7 @@ export type VersionProbe =
|
|
|
44
51
|
| {
|
|
45
52
|
kind: 'unreachable';
|
|
46
53
|
};
|
|
47
|
-
export type ElectionDecision = 'take-over' | 'defer';
|
|
54
|
+
export type ElectionDecision = 'take-over' | 'await-handoff' | 'defer';
|
|
48
55
|
export interface ElectionOutcome {
|
|
49
56
|
decision: ElectionDecision;
|
|
50
57
|
/** The process stepped down (take-over) or that would have been. */
|
|
@@ -58,7 +65,7 @@ export interface DecideInput {
|
|
|
58
65
|
ownerStartedAt: number | null;
|
|
59
66
|
installedCodeMtime: number | null;
|
|
60
67
|
}
|
|
61
|
-
/** The pure decision table (a)
|
|
68
|
+
/** The pure decision table (a)–(d) above. */
|
|
62
69
|
export declare function decideElection(input: DecideInput): ElectionOutcome;
|
|
63
70
|
export interface ElectionDeps {
|
|
64
71
|
localVersion: string;
|
|
@@ -86,7 +93,9 @@ export declare function retryBind<T>(bind: () => Promise<T>, opts: {
|
|
|
86
93
|
export declare const STEP_DOWN_GRACE_MS = 3000;
|
|
87
94
|
/**
|
|
88
95
|
* Stop a process: Windows `taskkill /PID n /F`; Unix `SIGTERM`, wait up to
|
|
89
|
-
* 3 s for it to exit, then `SIGKILL`. Throws when the kill itself fails
|
|
96
|
+
* 3 s for it to exit, then `SIGKILL`. Throws when the kill itself fails, and
|
|
97
|
+
* before killing anything when `pid` is this process or one of its
|
|
98
|
+
* ancestors (the shell or MCP client that launched it).
|
|
90
99
|
*/
|
|
91
100
|
export declare function stepDownProcess(pid: number, deps?: {
|
|
92
101
|
os?: NodeJS.Platform;
|
|
@@ -95,4 +104,6 @@ export declare function stepDownProcess(pid: number, deps?: {
|
|
|
95
104
|
isAlive?: (pid: number) => boolean;
|
|
96
105
|
sleep?: (ms: number) => Promise<void>;
|
|
97
106
|
now?: () => number;
|
|
107
|
+
selfPid?: number;
|
|
108
|
+
listProcesses?: () => ProcessEntry[];
|
|
98
109
|
}): Promise<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { request } from 'node:http';
|
|
2
2
|
import { platform } from 'node:os';
|
|
3
3
|
import { compareSemver } from '../utils/semver.js';
|
|
4
|
-
import { defaultExecFile } from './processes.js';
|
|
5
|
-
/** The pure decision table (a)
|
|
4
|
+
import { defaultExecFile, listProcesses as listProcessesReal, selfAndAncestors, } from './processes.js';
|
|
5
|
+
/** The pure decision table (a)–(d) above. */
|
|
6
6
|
export function decideElection(input) {
|
|
7
7
|
const { probe } = input;
|
|
8
8
|
if (probe.kind === 'version') {
|
|
@@ -14,6 +14,13 @@ export function decideElection(input) {
|
|
|
14
14
|
reason: `running primary ${remote} is older than ${input.local}`,
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
if (probe.info.repairing === true && compareSemver(remote, input.local) === 0) {
|
|
18
|
+
return {
|
|
19
|
+
decision: 'await-handoff',
|
|
20
|
+
pid: probe.info.pid,
|
|
21
|
+
reason: `running primary ${remote} is handing the port over (repair)`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
17
24
|
return {
|
|
18
25
|
decision: 'defer',
|
|
19
26
|
pid: probe.info.pid,
|
|
@@ -87,7 +94,8 @@ function isVersionInfo(v) {
|
|
|
87
94
|
Number.isInteger(o.pid) &&
|
|
88
95
|
o.pid > 0 &&
|
|
89
96
|
typeof o.startedAt === 'string' &&
|
|
90
|
-
(o.installedVersion === null || typeof o.installedVersion === 'string')
|
|
97
|
+
(o.installedVersion === null || typeof o.installedVersion === 'string') &&
|
|
98
|
+
(o.repairing === undefined || typeof o.repairing === 'boolean'));
|
|
91
99
|
}
|
|
92
100
|
/** `GET http://<host>:<port>/version`. Never rejects. */
|
|
93
101
|
export function probeVersion(port, timeoutMs = 1000, host = '127.0.0.1') {
|
|
@@ -160,10 +168,19 @@ function isAliveReal(pid) {
|
|
|
160
168
|
}
|
|
161
169
|
/**
|
|
162
170
|
* Stop a process: Windows `taskkill /PID n /F`; Unix `SIGTERM`, wait up to
|
|
163
|
-
* 3 s for it to exit, then `SIGKILL`. Throws when the kill itself fails
|
|
171
|
+
* 3 s for it to exit, then `SIGKILL`. Throws when the kill itself fails, and
|
|
172
|
+
* before killing anything when `pid` is this process or one of its
|
|
173
|
+
* ancestors (the shell or MCP client that launched it).
|
|
164
174
|
*/
|
|
165
175
|
export async function stepDownProcess(pid, deps = {}) {
|
|
166
176
|
const os = deps.os ?? platform();
|
|
177
|
+
const selfPid = deps.selfPid ?? process.pid;
|
|
178
|
+
// The direct checks need no process scan; the ancestor chain does.
|
|
179
|
+
if (pid === selfPid ||
|
|
180
|
+
(deps.selfPid === undefined && pid === process.ppid) ||
|
|
181
|
+
selfAndAncestors((deps.listProcesses ?? (() => listProcessesReal(os, deps.execFile ?? defaultExecFile)))(), selfPid).has(pid)) {
|
|
182
|
+
throw new Error(`refusing to step down PID ${pid}: it is this process or one of its ancestors`);
|
|
183
|
+
}
|
|
167
184
|
if (os === 'win32') {
|
|
168
185
|
(deps.execFile ?? defaultExecFile)('taskkill', ['/PID', String(pid), '/F'], {
|
|
169
186
|
timeout: 5000,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"election.js","sourceRoot":"","sources":["../../src/lifecycle/election.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"election.js","sourceRoot":"","sources":["../../src/lifecycle/election.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,eAAe,EACf,aAAa,IAAI,iBAAiB,EAClC,gBAAgB,GAGjB,MAAM,gBAAgB,CAAC;AAmExB,6CAA6C;AAC7C,MAAM,UAAU,cAAc,CAAC,KAAkB;IAC/C,MAAM,EAAE,KAAK,EAAE,GAAG,K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AK,GAAG,IAAI,CAAC,KAAK,IAAI,SAAS,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IACjC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACrB,MAAM,QAAQ,GAAG,GAAG,EAAE,GAAG,kBAAkB,CAAC;IAC5C,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,IAAI,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;YACtB,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QACD,MAAM,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
export type ExecFileLike = (file: string, args: readonly string[], options: {
|
|
18
18
|
timeout: number;
|
|
19
19
|
}) => string;
|
|
20
|
+
/** Asynchronous `ExecFileLike`: same argv and timeout, stdout resolved. Used
|
|
21
|
+
* where the listing runs alongside other probes (`doctor`), so the slow WMI
|
|
22
|
+
* scan does not block the event loop. */
|
|
23
|
+
export type ExecFileAsyncLike = (file: string, args: readonly string[], options: {
|
|
24
|
+
timeout: number;
|
|
25
|
+
}) => Promise<string>;
|
|
20
26
|
/** One row of the OS process table. `startedAt` is epoch milliseconds, or
|
|
21
27
|
* `null` when the OS did not report a usable start time. */
|
|
22
28
|
export interface ProcessEntry {
|
|
@@ -26,6 +32,7 @@ export interface ProcessEntry {
|
|
|
26
32
|
command: string;
|
|
27
33
|
}
|
|
28
34
|
export declare const defaultExecFile: ExecFileLike;
|
|
35
|
+
export declare const defaultExecFileAsync: ExecFileAsyncLike;
|
|
29
36
|
/**
|
|
30
37
|
* Parse a process start time in any of the forms the OS tools print:
|
|
31
38
|
* PowerShell 5.1's JSON `/Date(ms)/`, ISO 8601 (PowerShell 7 JSON,
|
|
@@ -40,6 +47,8 @@ export declare function parseWindowsProcessList(stdout: string): ProcessEntry[];
|
|
|
40
47
|
export declare function parseUnixProcessList(stdout: string): ProcessEntry[];
|
|
41
48
|
/** The whole process table, or `[]` when it cannot be read. */
|
|
42
49
|
export declare function listProcesses(os?: NodeJS.Platform, exec?: ExecFileLike): ProcessEntry[];
|
|
50
|
+
/** `listProcesses` without blocking the event loop. Never rejects. */
|
|
51
|
+
export declare function listProcessesAsync(os?: NodeJS.Platform, exec?: ExecFileAsyncLike): Promise<ProcessEntry[]>;
|
|
43
52
|
/** Start time of one process (epoch ms), or `null` when unknown. */
|
|
44
53
|
export declare function readProcessStartTime(pid: number, opts?: {
|
|
45
54
|
os?: NodeJS.Platform;
|
|
@@ -55,6 +64,8 @@ export declare function readProcessStartTime(pid: number, opts?: {
|
|
|
55
64
|
export declare function matchBrowserLinkCommand(command: string): {
|
|
56
65
|
subcommand: string | null;
|
|
57
66
|
} | null;
|
|
67
|
+
/** `selfPid` and every ancestor reachable through `ppid` in `list`. */
|
|
68
|
+
export declare function selfAndAncestors(list: readonly ProcessEntry[], selfPid: number): Set<number>;
|
|
58
69
|
/** Live browser-link bridges in `list`, excluding `selfPid`, its ancestor
|
|
59
70
|
* chain (the shell or client that launched it) and non-bridge commands. */
|
|
60
71
|
export declare function findBridgeProcesses(list: readonly ProcessEntry[], selfPid: number): ProcessEntry[];
|
|
@@ -63,5 +74,12 @@ export declare function listBridgeProcesses(opts?: {
|
|
|
63
74
|
exec?: ExecFileLike;
|
|
64
75
|
selfPid?: number;
|
|
65
76
|
}): ProcessEntry[];
|
|
77
|
+
/** `listBridgeProcesses` without blocking the event loop, so `doctor` runs
|
|
78
|
+
* it concurrently with its other probes. Never rejects. */
|
|
79
|
+
export declare function listBridgeProcessesAsync(opts?: {
|
|
80
|
+
os?: NodeJS.Platform;
|
|
81
|
+
exec?: ExecFileAsyncLike;
|
|
82
|
+
selfPid?: number;
|
|
83
|
+
}): Promise<ProcessEntry[]>;
|
|
66
84
|
/** Short, display-only form: runtime name, `browser-link`, then arguments. */
|
|
67
85
|
export declare function shortCommand(command: string, max?: number): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process';
|
|
1
|
+
import { execFile, execFileSync } from 'node:child_process';
|
|
2
2
|
import { platform } from 'node:os';
|
|
3
3
|
/** WMI cold starts are slow: same budget `silent-debugger.ts` documents. */
|
|
4
4
|
const LIST_TIMEOUT_MS = 5000;
|
|
@@ -10,6 +10,19 @@ export const defaultExecFile = (file, args, options) => execFileSync(file, args,
|
|
|
10
10
|
// `ps` prints lstart in the C locale only when told so.
|
|
11
11
|
env: { ...process.env, LC_ALL: 'C' },
|
|
12
12
|
});
|
|
13
|
+
export const defaultExecFileAsync = (file, args, options) => new Promise((resolve, reject) => {
|
|
14
|
+
execFile(file, [...args], {
|
|
15
|
+
encoding: 'utf8',
|
|
16
|
+
windowsHide: true,
|
|
17
|
+
timeout: options.timeout,
|
|
18
|
+
env: { ...process.env, LC_ALL: 'C' },
|
|
19
|
+
}, (err, stdout) => {
|
|
20
|
+
if (err)
|
|
21
|
+
reject(new Error(err.message));
|
|
22
|
+
else
|
|
23
|
+
resolve(stdout);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
13
26
|
/**
|
|
14
27
|
* Parse a process start time in any of the forms the OS tools print:
|
|
15
28
|
* PowerShell 5.1's JSON `/Date(ms)/`, ISO 8601 (PowerShell 7 JSON,
|
|
@@ -85,14 +98,29 @@ const WINDOWS_LIST_SCRIPT = 'Get-CimInstance Win32_Process | ' +
|
|
|
85
98
|
function powershell(script) {
|
|
86
99
|
return ['powershell', ['-NoProfile', '-NonInteractive', '-Command', script]];
|
|
87
100
|
}
|
|
101
|
+
/** The OS command that lists the whole process table, and its parser. */
|
|
102
|
+
function processListCommand(os) {
|
|
103
|
+
if (os === 'win32') {
|
|
104
|
+
const [file, args] = powershell(WINDOWS_LIST_SCRIPT);
|
|
105
|
+
return { file, args, parse: parseWindowsProcessList };
|
|
106
|
+
}
|
|
107
|
+
return { file: 'ps', args: ['-axo', 'pid=,ppid=,lstart=,command='], parse: parseUnixProcessList };
|
|
108
|
+
}
|
|
88
109
|
/** The whole process table, or `[]` when it cannot be read. */
|
|
89
110
|
export function listProcesses(os = platform(), exec = defaultExecFile) {
|
|
90
111
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return
|
|
112
|
+
const { file, args, parse } = processListCommand(os);
|
|
113
|
+
return parse(exec(file, args, { timeout: LIST_TIMEOUT_MS }));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** `listProcesses` without blocking the event loop. Never rejects. */
|
|
120
|
+
export async function listProcessesAsync(os = platform(), exec = defaultExecFileAsync) {
|
|
121
|
+
try {
|
|
122
|
+
const { file, args, parse } = processListCommand(os);
|
|
123
|
+
return parse(await exec(file, args, { timeout: LIST_TIMEOUT_MS }));
|
|
96
124
|
}
|
|
97
125
|
catch {
|
|
98
126
|
return [];
|
|
@@ -199,7 +227,7 @@ function isBridgeSubcommand(subcommand) {
|
|
|
199
227
|
return subcommand === null || subcommand === 'start';
|
|
200
228
|
}
|
|
201
229
|
/** `selfPid` and every ancestor reachable through `ppid` in `list`. */
|
|
202
|
-
function selfAndAncestors(list, selfPid) {
|
|
230
|
+
export function selfAndAncestors(list, selfPid) {
|
|
203
231
|
const byPid = new Map(list.map((p) => [p.pid, p]));
|
|
204
232
|
const out = new Set();
|
|
205
233
|
let pid = selfPid;
|
|
@@ -223,6 +251,11 @@ export function findBridgeProcesses(list, selfPid) {
|
|
|
223
251
|
export function listBridgeProcesses(opts = {}) {
|
|
224
252
|
return findBridgeProcesses(listProcesses(opts.os, opts.exec), opts.selfPid ?? process.pid);
|
|
225
253
|
}
|
|
254
|
+
/** `listBridgeProcesses` without blocking the event loop, so `doctor` runs
|
|
255
|
+
* it concurrently with its other probes. Never rejects. */
|
|
256
|
+
export async function listBridgeProcessesAsync(opts = {}) {
|
|
257
|
+
return findBridgeProcesses(await listProcessesAsync(opts.os, opts.exec), opts.selfPid ?? process.pid);
|
|
258
|
+
}
|
|
226
259
|
/** Short, display-only form: runtime name, `browser-link`, then arguments. */
|
|
227
260
|
export function shortCommand(command, max = 80) {
|
|
228
261
|
const tokens = tokenize(command);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processes.js","sourceRoot":"","sources":["../../src/lifecycle/processes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"processes.js","sourceRoot":"","sources":["../../src/lifecycle/processes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AA2CnC,4EAA4E;AAC5E,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B,MAAM,CAAC,MAAM,eAAe,GAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CACnE,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE;IACvB,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC;IACnC,WAAW,EAAE,IAAI;IACjB,OAAO,EAAE,OAAO,CAAC,OAAO;IACxB,wDAAwD;IACxD,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;CACrC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,oBAAoB,GAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAC7E,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,QAAQ,CACN,IAAI,EACJ,CAAC,GAAG,IAAI,CAAC,EACT;QACE,QAAQ,EAAE,MAAM;QAChB,WAAW,EAA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B,MAAM,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAC5C,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAC5B,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,GAAG,GAAG,EAAE;IACpD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAChC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACtD,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AACjE,CAAC"}
|
|
@@ -20,9 +20,7 @@ export interface RepairDeps {
|
|
|
20
20
|
detached: true;
|
|
21
21
|
stdio: 'ignore';
|
|
22
22
|
windowsHide: true;
|
|
23
|
-
}) =>
|
|
24
|
-
unref(): void;
|
|
25
|
-
};
|
|
23
|
+
}) => RepairChild;
|
|
26
24
|
terminateSockets: () => void;
|
|
27
25
|
stopIpc: () => Promise<void>;
|
|
28
26
|
exit: (code: number) => void;
|
|
@@ -30,11 +28,25 @@ export interface RepairDeps {
|
|
|
30
28
|
delay: (ms: number) => Promise<void>;
|
|
31
29
|
log?: (msg: string) => void;
|
|
32
30
|
}
|
|
31
|
+
/** The slice of Node's `ChildProcess` the repair uses. A spawn can fail
|
|
32
|
+
* asynchronously (`error` after `spawn()` returned, e.g. EACCES); `spawn`
|
|
33
|
+
* is emitted once the child really started. */
|
|
34
|
+
export interface RepairChild {
|
|
35
|
+
unref(): void;
|
|
36
|
+
on(event: 'spawn' | 'error', listener: (err?: Error) => void): unknown;
|
|
37
|
+
}
|
|
33
38
|
/** Time given to the `bridge.repair.result` frame before sockets die. */
|
|
34
39
|
export declare const REPAIR_FLUSH_DELAY_MS = 150;
|
|
40
|
+
/** Longest wait for the child's `spawn`/`error` event. Node emits one of
|
|
41
|
+
* them within a tick or two; past this the child is assumed started. */
|
|
42
|
+
export declare const REPAIR_SPAWN_CONFIRM_MS = 2000;
|
|
35
43
|
export interface RepairController {
|
|
36
44
|
/** Start the restart (once). Returns whether it is (now) in progress. */
|
|
37
45
|
start(): boolean;
|
|
46
|
+
/** True from `start()` until the process exits, or until a failed spawn
|
|
47
|
+
* gave up. `/version` reports it as `repairing` so the successor waits for
|
|
48
|
+
* the port instead of deferring to a same-version primary. */
|
|
49
|
+
readonly inProgress: boolean;
|
|
38
50
|
/** Settles when the current restart attempt finished (tests). */
|
|
39
51
|
readonly done: Promise<void>;
|
|
40
52
|
}
|
package/dist/lifecycle/repair.js
CHANGED
|
@@ -1,26 +1,56 @@
|
|
|
1
1
|
/** Time given to the `bridge.repair.result` frame before sockets die. */
|
|
2
2
|
export const REPAIR_FLUSH_DELAY_MS = 150;
|
|
3
|
+
/** Longest wait for the child's `spawn`/`error` event. Node emits one of
|
|
4
|
+
* them within a tick or two; past this the child is assumed started. */
|
|
5
|
+
export const REPAIR_SPAWN_CONFIRM_MS = 2000;
|
|
3
6
|
export function createRepairController(deps) {
|
|
4
7
|
let inProgress = false;
|
|
5
8
|
let done = Promise.resolve();
|
|
9
|
+
const giveUp = (err) => {
|
|
10
|
+
// Without a successor, exiting would leave no server at all: keep
|
|
11
|
+
// serving and let the user fall back to `browser-link stop`.
|
|
12
|
+
inProgress = false;
|
|
13
|
+
deps.log?.(`Repair: could not start the installed server (${err instanceof Error ? err.message : String(err)}); still serving.`);
|
|
14
|
+
};
|
|
6
15
|
const run = async () => {
|
|
7
16
|
await deps.delay(REPAIR_FLUSH_DELAY_MS);
|
|
17
|
+
let child;
|
|
8
18
|
try {
|
|
9
|
-
deps
|
|
10
|
-
.spawn(deps.execPath, [deps.cliPath], {
|
|
19
|
+
child = deps.spawn(deps.execPath, [deps.cliPath], {
|
|
11
20
|
detached: true,
|
|
12
21
|
stdio: 'ignore',
|
|
13
22
|
windowsHide: true,
|
|
14
|
-
})
|
|
15
|
-
.unref();
|
|
23
|
+
});
|
|
16
24
|
}
|
|
17
25
|
catch (err) {
|
|
18
|
-
|
|
19
|
-
// serving and let the user fall back to `browser-link stop`.
|
|
20
|
-
inProgress = false;
|
|
21
|
-
deps.log?.(`Repair: could not start the installed server (${err instanceof Error ? err.message : String(err)}); still serving.`);
|
|
26
|
+
giveUp(err);
|
|
22
27
|
return;
|
|
23
28
|
}
|
|
29
|
+
// Wait for the child to really start before handing anything over: an
|
|
30
|
+
// asynchronous spawn failure arrives as an `error` event, which would
|
|
31
|
+
// also crash this process if nobody listened. The listener stays
|
|
32
|
+
// attached for the rest of the process's life for the same reason.
|
|
33
|
+
const started = await new Promise((resolve) => {
|
|
34
|
+
const timer = setTimeout(() => {
|
|
35
|
+
resolve(true);
|
|
36
|
+
}, REPAIR_SPAWN_CONFIRM_MS);
|
|
37
|
+
timer.unref();
|
|
38
|
+
child.on('spawn', () => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
resolve(true);
|
|
41
|
+
});
|
|
42
|
+
child.on('error', (err) => {
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
const error = err ?? new Error('spawn failed');
|
|
45
|
+
deps.log?.(`Repair: installed server error: ${error.message}`);
|
|
46
|
+
resolve(error);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
if (started !== true) {
|
|
50
|
+
giveUp(started);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
child.unref();
|
|
24
54
|
deps.log?.('Repair: installed server started; handing over the port.');
|
|
25
55
|
deps.terminateSockets();
|
|
26
56
|
try {
|
|
@@ -42,6 +72,9 @@ export function createRepairController(deps) {
|
|
|
42
72
|
get done() {
|
|
43
73
|
return done;
|
|
44
74
|
},
|
|
75
|
+
get inProgress() {
|
|
76
|
+
return inProgress;
|
|
77
|
+
},
|
|
45
78
|
};
|
|
46
79
|
}
|
|
47
80
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repair.js","sourceRoot":"","sources":["../../src/lifecycle/repair.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"repair.js","sourceRoot":"","sources":["../../src/lifecycle/repair.ts"],"names":[],"mappings":"AAyCA,yEAAyE;AACzE,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAEzC;wEACwE;AACxE,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAa5C,MAAM,UAAU,sBAAsB,CAAC,IAAgB;IACrD,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,IAAI,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAE5C,MAAM,MAAM,GAAG,CAAC,GAAY,EAAQ,EAAE;QACpC,kEAAkE;QAClE,6DAA6D;QAC7D,UAAU,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,EAAE,CACR,iDAAiD,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAmB,CACrH,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,GAAG,GAAG,KAAK,IAAmB,EAAE;QACpC,MAAM,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACxC,IAAI,K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CodeMtime(path?: string): number | null;
|
|
12
12
|
/** Approximate wall-clock start of this process, epoch ms. */
|
|
13
13
|
export declare const PROCESS_STARTED_AT: number;
|
|
14
|
-
export declare function buildVersionInfo(version: string, pid?: number, startedAt?: number, installed?: () => string | null): VersionInfo;
|
|
15
|
-
/**
|
|
16
|
-
|
|
14
|
+
export declare function buildVersionInfo(version: string, pid?: number, startedAt?: number, installed?: () => string | null, repairing?: boolean): VersionInfo;
|
|
15
|
+
/** Whether a request's `Host` header names this machine's loopback. A web
|
|
16
|
+
* page reaching the port through DNS rebinding carries its own host name,
|
|
17
|
+
* so it never reads the pid and versions. */
|
|
18
|
+
export declare function isLoopbackHost(host: string | undefined): boolean;
|
|
19
|
+
/** The bridge's plain-HTTP handler: `/version` (loopback `Host` only, else
|
|
20
|
+
* 403) or 404. `isRepairing` reports a repair hand-off in progress. */
|
|
21
|
+
export declare function handleBridgeHttpRequest(req: IncomingMessage, res: ServerResponse, version: string, isRepairing?: () => boolean): void;
|
|
@@ -27,21 +27,36 @@ export function readInstalledCodeMtime(path = INSTALLED_CLI_PATH) {
|
|
|
27
27
|
}
|
|
28
28
|
/** Approximate wall-clock start of this process, epoch ms. */
|
|
29
29
|
export const PROCESS_STARTED_AT = Date.now() - Math.round(process.uptime() * 1000);
|
|
30
|
-
export function buildVersionInfo(version, pid = process.pid, startedAt = PROCESS_STARTED_AT, installed = readInstalledVersion) {
|
|
30
|
+
export function buildVersionInfo(version, pid = process.pid, startedAt = PROCESS_STARTED_AT, installed = readInstalledVersion, repairing = false) {
|
|
31
31
|
return {
|
|
32
32
|
name: PACKAGE_NAME,
|
|
33
33
|
version,
|
|
34
34
|
pid,
|
|
35
35
|
startedAt: new Date(startedAt).toISOString(),
|
|
36
36
|
installedVersion: installed(),
|
|
37
|
+
repairing,
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
|
-
/**
|
|
40
|
-
|
|
40
|
+
/** `127.0.0.1`, `localhost` or `[::1]`, each with an optional port. */
|
|
41
|
+
const LOOPBACK_HOST = /^(?:127\.0\.0\.1|localhost|\[::1\])(?::\d{1,5})?$/i;
|
|
42
|
+
/** Whether a request's `Host` header names this machine's loopback. A web
|
|
43
|
+
* page reaching the port through DNS rebinding carries its own host name,
|
|
44
|
+
* so it never reads the pid and versions. */
|
|
45
|
+
export function isLoopbackHost(host) {
|
|
46
|
+
return host !== undefined && LOOPBACK_HOST.test(host);
|
|
47
|
+
}
|
|
48
|
+
/** The bridge's plain-HTTP handler: `/version` (loopback `Host` only, else
|
|
49
|
+
* 403) or 404. `isRepairing` reports a repair hand-off in progress. */
|
|
50
|
+
export function handleBridgeHttpRequest(req, res, version, isRepairing = () => false) {
|
|
41
51
|
const path = (req.url ?? '').split('?')[0];
|
|
42
52
|
if (req.method === 'GET' && path === '/version') {
|
|
53
|
+
if (!isLoopbackHost(req.headers.host)) {
|
|
54
|
+
res.writeHead(403, { 'content-type': 'text/plain' });
|
|
55
|
+
res.end('Forbidden');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
43
58
|
res.writeHead(200, { 'content-type': 'application/json' });
|
|
44
|
-
res.end(JSON.stringify(buildVersionInfo(version)));
|
|
59
|
+
res.end(JSON.stringify(buildVersionInfo(version, undefined, undefined, undefined, isRepairing())));
|
|
45
60
|
return;
|
|
46
61
|
}
|
|
47
62
|
res.writeHead(404, { 'content-type': 'text/plain' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-endpoint.js","sourceRoot":"","sources":["../../src/lifecycle/version-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGnE;;;;;GAKG;AAEH,MAAM,IAAI,GAAG,OAAO,CAAC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AAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAC;YACrD,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QACD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAC3D,GAAG,CAAC,GAAG,CACL,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC,CAC1F,CAAC;QACF,OAAO;IACT,CAAC;IACD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAC;IACrD,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AACvB,CAAC"}
|
package/dist/manual/refresh.js
CHANGED
|
@@ -22,6 +22,12 @@ export function refreshOutdatedBlocks(input) {
|
|
|
22
22
|
if (installer === undefined)
|
|
23
23
|
return s;
|
|
24
24
|
try {
|
|
25
|
+
// Re-read right before writing: the status may be stale (read at
|
|
26
|
+
// connect time). Only a block that is still ours and still outdated
|
|
27
|
+
// is rewritten; a block the user removed is never re-added.
|
|
28
|
+
const current = installer.detect().state;
|
|
29
|
+
if (current.kind !== 'installed-outdated')
|
|
30
|
+
return { ...s, state: current };
|
|
25
31
|
installer.install();
|
|
26
32
|
const after = { ...s, state: installer.detect().state };
|
|
27
33
|
refreshed.push(after);
|