@elumixor/devkit 0.12.1 → 0.12.3
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 +5 -1
- package/package.json +1 -1
- package/src/dev/board.tsx +93 -33
- package/src/dev/errors.ts +87 -0
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ at the top, the merged log below.
|
|
|
82
82
|
── all ─────────────────────────────────────────────────────────────────────────────
|
|
83
83
|
web:frontend │ VITE v8.3.0 ready in 1055 ms
|
|
84
84
|
web:backend │ [nitro] ✔ Nitro Server built in 521ms
|
|
85
|
-
1-2 focus a all o open r restart c clear jk ud gg G scroll v select y copy q quit
|
|
85
|
+
1-2 focus a all o open r restart c clear jk ud gg G scroll v select y copy e errors q quit
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
The log scrolls like `less`: `j`/`k` or arrows by a line, `u`/`d` by half a screen, PgUp/PgDn by a
|
|
@@ -91,6 +91,10 @@ row; move it with the same keys and `y` copies it to the clipboard, `y` alone co
|
|
|
91
91
|
Dragging with the mouse selects too, scrolling on its own while the pointer is above or below the log,
|
|
92
92
|
and copies on release; the wheel scrolls. Hold Option (macOS) or Shift for the terminal's own selection.
|
|
93
93
|
|
|
94
|
+
A printed error with a stack folds into one red summary row (its message, plus a database `detail`
|
|
95
|
+
when there is one). Click `[copy]` to copy the whole error, or the `[▸ N lines]` button to expand it;
|
|
96
|
+
`e` expands or folds every error.
|
|
97
|
+
|
|
94
98
|
A crashed process stays on the board until you restart it with `r`; the rest keep running. Anywhere
|
|
95
99
|
else (an agent's shell, CI, a pipe, or `--plain`) it prints prefixed lines instead: the URLs first,
|
|
96
100
|
then a `devkit` line for every ready, crash and exit, and one `all ready:` line listing every URL.
|
package/package.json
CHANGED
package/src/dev/board.tsx
CHANGED
|
@@ -5,8 +5,9 @@ import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "reac
|
|
|
5
5
|
import wrapAnsi from "wrap-ansi";
|
|
6
6
|
import { stripColor } from "../ansi.ts";
|
|
7
7
|
import { copyToClipboard } from "./clipboard.ts";
|
|
8
|
+
import { type ErrorBlock, foldErrors, type ShownEntry } from "./errors.ts";
|
|
8
9
|
import type { Service, ServiceState } from "./service.ts";
|
|
9
|
-
import { DEVKIT, type
|
|
10
|
+
import { DEVKIT, type Supervisor } from "./supervisor.ts";
|
|
10
11
|
|
|
11
12
|
const SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
12
13
|
const FRAME_MS = 80;
|
|
@@ -28,6 +29,10 @@ const WHEEL_DOWN = 65;
|
|
|
28
29
|
/** Button presses, drags and releases, reported as SGR coordinates. */
|
|
29
30
|
const MOUSE_ON = "\x1b[?1002h\x1b[?1006h";
|
|
30
31
|
const MOUSE_OFF = "\x1b[?1002l\x1b[?1006l";
|
|
32
|
+
/** The buttons ahead of an error's summary, and the columns they take after the log's gutter. */
|
|
33
|
+
const COPY_BUTTON = "[copy]";
|
|
34
|
+
const toggleButton = (error: ErrorBlock & { expanded: boolean }) =>
|
|
35
|
+
`[${error.expanded ? "▾" : "▸"} ${error.lines} lines]`;
|
|
31
36
|
|
|
32
37
|
const MARK: Record<ServiceState, { glyph: string; color: string }> = {
|
|
33
38
|
starting: { glyph: "", color: "yellow" },
|
|
@@ -60,6 +65,8 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
60
65
|
const frame = useFrame(supervisor.services.some((s) => s.state === "starting" || s.state === "stopping"));
|
|
61
66
|
|
|
62
67
|
const [focus, setFocus] = useState<number | null>(null);
|
|
68
|
+
/** `seq`s of the errors shown whole instead of as a summary. */
|
|
69
|
+
const [expanded, setExpanded] = useState<ReadonlySet<number>>(new Set());
|
|
63
70
|
/** `seq` the view ends before while scrolled back; `null` follows the newest line. */
|
|
64
71
|
const [end, setEnd] = useState<number | null>(null);
|
|
65
72
|
const [quitting, setQuitting] = useState(false);
|
|
@@ -95,8 +102,9 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
95
102
|
const textWidth = Math.max(MIN_LOG_WIDTH, cols - labelWidth - 3);
|
|
96
103
|
const halfPage = Math.max(1, Math.floor(logRows / 2));
|
|
97
104
|
|
|
98
|
-
const shown =
|
|
99
|
-
(entry) => focus == null || entry.source === focus || entry.source === DEVKIT,
|
|
105
|
+
const shown = foldErrors(
|
|
106
|
+
supervisor.entries.filter((entry) => focus == null || entry.source === focus || entry.source === DEVKIT),
|
|
107
|
+
expanded,
|
|
100
108
|
);
|
|
101
109
|
const endIndex = end == null ? shown.length : countBefore(shown, end);
|
|
102
110
|
const who = (source: number) =>
|
|
@@ -144,10 +152,27 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
144
152
|
if (resumeFollow.current) setEnd(null);
|
|
145
153
|
};
|
|
146
154
|
|
|
147
|
-
const yank = (entries: readonly
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
155
|
+
const yank = (entries: readonly ShownEntry[]) => {
|
|
156
|
+
// An expanded error's lines follow its summary, so the summary itself adds nothing.
|
|
157
|
+
const texts = entries.flatMap((entry) =>
|
|
158
|
+
entry.error ? (entry.error.expanded ? [] : [entry.error.text]) : [stripColor(entry.text)],
|
|
159
|
+
);
|
|
160
|
+
if (texts.length === 0) return;
|
|
161
|
+
copyToClipboard(texts.join("\n"), stdout);
|
|
162
|
+
const count = texts.join("\n").split("\n").length;
|
|
163
|
+
setFlash(`copied ${count} line${count === 1 ? "" : "s"}`);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const toggleError = (seq: number) => {
|
|
167
|
+
const next = new Set(expanded);
|
|
168
|
+
if (!next.delete(seq)) next.add(seq);
|
|
169
|
+
setExpanded(next);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/** Expands every error unless all already are, then folds them all. */
|
|
173
|
+
const toggleErrors = () => {
|
|
174
|
+
const errors = shown.flatMap((entry) => (entry.error ? [entry.error] : []));
|
|
175
|
+
setExpanded(errors.every((error) => error.expanded) ? new Set() : new Set(errors.map((error) => error.seq)));
|
|
151
176
|
};
|
|
152
177
|
|
|
153
178
|
const yankSelection = () => {
|
|
@@ -166,7 +191,7 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
166
191
|
void supervisor.stop().then(() => exit());
|
|
167
192
|
};
|
|
168
193
|
|
|
169
|
-
const onMouse = ({ button, row, release }: MouseEvent) => {
|
|
194
|
+
const onMouse = ({ button, row, col, release }: MouseEvent) => {
|
|
170
195
|
const at = row - logTop;
|
|
171
196
|
if (button === WHEEL_UP || button === WHEEL_DOWN) {
|
|
172
197
|
const by = button === WHEEL_UP ? -WHEEL_LINES : WHEEL_LINES;
|
|
@@ -179,6 +204,15 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
179
204
|
if (button === LEFT) {
|
|
180
205
|
const line = lines[at];
|
|
181
206
|
if (!line) return;
|
|
207
|
+
const x = col - 1 - (labelWidth + 3);
|
|
208
|
+
if (line.error && !visual) {
|
|
209
|
+
if (x >= 0 && x < COPY_BUTTON.length) {
|
|
210
|
+
copyToClipboard(line.error.text, stdout);
|
|
211
|
+
return setFlash(`copied error (${line.error.lines} lines)`);
|
|
212
|
+
}
|
|
213
|
+
const toggleAt = COPY_BUTTON.length + 1;
|
|
214
|
+
if (x >= toggleAt && x < toggleAt + toggleButton(line.error).length) return toggleError(line.error.seq);
|
|
215
|
+
}
|
|
182
216
|
startVisual(line.seq);
|
|
183
217
|
return setDragging(true);
|
|
184
218
|
}
|
|
@@ -223,6 +257,7 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
223
257
|
return last && startVisual(last.seq);
|
|
224
258
|
}
|
|
225
259
|
if (input === "y") return yank(shown.slice(firstVisible(shown, endIndex, logRows, textWidth), endIndex));
|
|
260
|
+
if (input === "e") return toggleErrors();
|
|
226
261
|
const digit = Number(input);
|
|
227
262
|
if (Number.isInteger(digit) && digit >= 1 && digit <= services.length) {
|
|
228
263
|
setFocus(focus === digit - 1 ? null : digit - 1);
|
|
@@ -279,18 +314,36 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
279
314
|
{lines.map((line) => {
|
|
280
315
|
const mark = markOf(line.seq);
|
|
281
316
|
return (
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
{
|
|
285
|
-
<Text color=
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
317
|
+
// One row each, the label and gutter never shrinking: a long row is cut, not wrapped.
|
|
318
|
+
<Box key={line.key} height={1}>
|
|
319
|
+
<Box flexShrink={0}>
|
|
320
|
+
<Text color={line.color}>{(line.first ? line.label : "").padEnd(labelWidth)}</Text>
|
|
321
|
+
{mark ? (
|
|
322
|
+
<Text color="yellow">{mark === "cursor" && line.first ? " ▶ " : " ┃ "}</Text>
|
|
323
|
+
) : (
|
|
324
|
+
<Text dimColor> │ </Text>
|
|
325
|
+
)}
|
|
326
|
+
</Box>
|
|
289
327
|
{/* Inverse on the plain text: a child's own colour resets would cut the highlight short. */}
|
|
290
|
-
{mark ? (
|
|
328
|
+
{line.error && !mark ? (
|
|
329
|
+
<>
|
|
330
|
+
<Box flexShrink={0}>
|
|
331
|
+
<Text>
|
|
332
|
+
<Text inverse>{COPY_BUTTON}</Text> <Text inverse>{toggleButton(line.error)}</Text>{" "}
|
|
333
|
+
</Text>
|
|
334
|
+
</Box>
|
|
335
|
+
<Text color="red" bold wrap="truncate-end">
|
|
336
|
+
{line.error.summary}
|
|
337
|
+
</Text>
|
|
338
|
+
</>
|
|
339
|
+
) : mark ? (
|
|
291
340
|
<Text inverse wrap="truncate-end">
|
|
292
341
|
{stripColor(line.text) || " "}
|
|
293
342
|
</Text>
|
|
343
|
+
) : line.failed ? (
|
|
344
|
+
<Text color="red" wrap="truncate-end">
|
|
345
|
+
{stripColor(line.text)}
|
|
346
|
+
</Text>
|
|
294
347
|
) : (
|
|
295
348
|
<Text wrap="truncate-end">{line.text}</Text>
|
|
296
349
|
)}
|
|
@@ -389,6 +442,7 @@ function Footer({
|
|
|
389
442
|
["jk ud gg G", "scroll"],
|
|
390
443
|
["v", "select"],
|
|
391
444
|
["y", "copy"],
|
|
445
|
+
["e", "errors"],
|
|
392
446
|
["q", "quit"],
|
|
393
447
|
]
|
|
394
448
|
: [
|
|
@@ -420,11 +474,13 @@ interface LogLine {
|
|
|
420
474
|
readonly text: string;
|
|
421
475
|
/** Only an entry's first wrapped row carries its label. */
|
|
422
476
|
readonly first: boolean;
|
|
477
|
+
readonly error?: ShownEntry["error"];
|
|
478
|
+
readonly failed?: boolean;
|
|
423
479
|
}
|
|
424
480
|
|
|
425
481
|
/** The last `count` screen rows of `entries[0, endIndex)`, wrapped to `width`. */
|
|
426
482
|
function tail(
|
|
427
|
-
entries: readonly
|
|
483
|
+
entries: readonly ShownEntry[],
|
|
428
484
|
endIndex: number,
|
|
429
485
|
count: number,
|
|
430
486
|
width: number,
|
|
@@ -432,57 +488,60 @@ function tail(
|
|
|
432
488
|
): LogLine[] {
|
|
433
489
|
const out: LogLine[] = [];
|
|
434
490
|
for (let i = endIndex - 1; i >= 0 && out.length < count; i--) {
|
|
435
|
-
const entry = entries[i] as
|
|
436
|
-
const rows = wrapAnsi(entry.text, width, { hard: true, trim: false }).split("\n");
|
|
491
|
+
const entry = entries[i] as ShownEntry;
|
|
492
|
+
const rows = entry.error ? [entry.text] : wrapAnsi(entry.text, width, { hard: true, trim: false }).split("\n");
|
|
437
493
|
for (let row = rows.length - 1; row >= 0 && out.length < count; row--)
|
|
438
494
|
out.push({
|
|
439
495
|
key: `${entry.seq}:${row}`,
|
|
440
496
|
seq: entry.seq,
|
|
441
497
|
text: rows[row] ?? "",
|
|
442
498
|
first: row === 0,
|
|
499
|
+
error: entry.error,
|
|
500
|
+
failed: entry.failed,
|
|
443
501
|
...who(entry.source),
|
|
444
502
|
});
|
|
445
503
|
}
|
|
446
504
|
return out.reverse();
|
|
447
505
|
}
|
|
448
506
|
|
|
449
|
-
|
|
450
|
-
|
|
507
|
+
/** An error's summary is one row, cut short rather than wrapped. */
|
|
508
|
+
const heightOf = (entry: ShownEntry, width: number) =>
|
|
509
|
+
entry.error ? 1 : wrapAnsi(entry.text, width, { hard: true, trim: false }).split("\n").length;
|
|
451
510
|
|
|
452
511
|
/** The fewest leading entries that fill the log — scrolling back further would only show blank rows. */
|
|
453
|
-
function firstFullScreen(entries: readonly
|
|
512
|
+
function firstFullScreen(entries: readonly ShownEntry[], rows: number, width: number) {
|
|
454
513
|
let filled = 0;
|
|
455
514
|
for (let i = 0; i < entries.length; i++) {
|
|
456
|
-
filled += heightOf(entries[i] as
|
|
515
|
+
filled += heightOf(entries[i] as ShownEntry, width);
|
|
457
516
|
if (filled >= rows) return i + 1;
|
|
458
517
|
}
|
|
459
518
|
return entries.length;
|
|
460
519
|
}
|
|
461
520
|
|
|
462
521
|
/** The first entry `entries[0, endIndex)` shows whole, so a cursor there needs no scrolling. */
|
|
463
|
-
function firstVisible(entries: readonly
|
|
522
|
+
function firstVisible(entries: readonly ShownEntry[], endIndex: number, rows: number, width: number) {
|
|
464
523
|
let filled = 0;
|
|
465
524
|
let i = endIndex;
|
|
466
|
-
while (i > 0 && filled < rows) filled += heightOf(entries[--i] as
|
|
525
|
+
while (i > 0 && filled < rows) filled += heightOf(entries[--i] as ShownEntry, width);
|
|
467
526
|
return Math.min(Math.max(0, endIndex - 1), filled > rows ? i + 1 : i);
|
|
468
527
|
}
|
|
469
528
|
|
|
470
529
|
/** Where a view must end to show `entries[start]` on its top row. */
|
|
471
|
-
function endFor(entries: readonly
|
|
530
|
+
function endFor(entries: readonly ShownEntry[], start: number, rows: number, width: number) {
|
|
472
531
|
let filled = 0;
|
|
473
532
|
let i = start;
|
|
474
|
-
while (i < entries.length && filled + heightOf(entries[i] as
|
|
475
|
-
filled += heightOf(entries[i++] as
|
|
533
|
+
while (i < entries.length && filled + heightOf(entries[i] as ShownEntry, width) <= rows)
|
|
534
|
+
filled += heightOf(entries[i++] as ShownEntry, width);
|
|
476
535
|
return Math.max(i, start + 1);
|
|
477
536
|
}
|
|
478
537
|
|
|
479
538
|
/** How many entries come before `seq` — entries are in `seq` order. */
|
|
480
|
-
function countBefore(entries: readonly
|
|
539
|
+
function countBefore(entries: readonly ShownEntry[], seq: number) {
|
|
481
540
|
let low = 0;
|
|
482
541
|
let high = entries.length;
|
|
483
542
|
while (low < high) {
|
|
484
543
|
const mid = (low + high) >> 1;
|
|
485
|
-
if ((entries[mid] as
|
|
544
|
+
if ((entries[mid] as ShownEntry).seq < seq) low = mid + 1;
|
|
486
545
|
else high = mid;
|
|
487
546
|
}
|
|
488
547
|
return low;
|
|
@@ -497,16 +556,17 @@ function openTarget(services: readonly Service[], focus: number | null) {
|
|
|
497
556
|
|
|
498
557
|
interface MouseEvent {
|
|
499
558
|
readonly button: number;
|
|
500
|
-
/** 1-based screen row. */
|
|
559
|
+
/** 1-based screen row and column. */
|
|
501
560
|
readonly row: number;
|
|
561
|
+
readonly col: number;
|
|
502
562
|
readonly release: boolean;
|
|
503
563
|
}
|
|
504
564
|
|
|
505
565
|
/** Ink hands an SGR mouse report to `useInput` whole, minus its escape. */
|
|
506
566
|
function parseMouse(input: string): MouseEvent | undefined {
|
|
507
|
-
const match = /^\[<(\d+)
|
|
567
|
+
const match = /^\[<(\d+);(\d+);(\d+)([Mm])$/.exec(input);
|
|
508
568
|
if (!match) return undefined;
|
|
509
|
-
return { button: Number(match[1]),
|
|
569
|
+
return { button: Number(match[1]), col: Number(match[2]), row: Number(match[3]), release: match[4] === "m" };
|
|
510
570
|
}
|
|
511
571
|
|
|
512
572
|
/**
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { stripColor } from "../ansi.ts";
|
|
2
|
+
import type { LogEntry } from "./supervisor.ts";
|
|
3
|
+
|
|
4
|
+
const FRAME = /^\s+at\s/;
|
|
5
|
+
const MORE = /^\s+\.\.\. \d+ (?:lines|more)/;
|
|
6
|
+
/** A line that reports a failure on its own, without a stack: `error: …`, `TypeError: …`. */
|
|
7
|
+
const FAILURE = /^\s*(?:\[[^\]]*\]\s*)?(?:error|\w*Error|\w*Exception)\b:?\s/i;
|
|
8
|
+
const DETAIL = /^\s*detail:\s*(['"`])(.*)\1,?$/;
|
|
9
|
+
|
|
10
|
+
/** A thrown error a service printed: its first line, its stack, and the properties Node dumps after it. */
|
|
11
|
+
export interface ErrorBlock {
|
|
12
|
+
/** `seq` of the error's first line. */
|
|
13
|
+
readonly seq: number;
|
|
14
|
+
/** The first line, plus a database driver's `detail` when it says what clashed. */
|
|
15
|
+
readonly summary: string;
|
|
16
|
+
readonly text: string;
|
|
17
|
+
readonly lines: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A log row: a printed line, or the one-line summary standing in for an error. */
|
|
21
|
+
export interface ShownEntry extends LogEntry {
|
|
22
|
+
readonly error?: ErrorBlock & { readonly expanded: boolean };
|
|
23
|
+
/** A line of an expanded error, or one that reports a failure by itself. */
|
|
24
|
+
readonly failed?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Folds every printed error into a summary row ahead of its lines, which stay only when `expanded`
|
|
29
|
+
* holds its `seq`. A line followed by a stack frame starts an error; frames, `... 3 more` and the
|
|
30
|
+
* `{ … }` property dump continue it. Each service's lines are folded apart, so interleaving is fine.
|
|
31
|
+
*/
|
|
32
|
+
export function foldErrors(entries: readonly LogEntry[], expanded: ReadonlySet<number>): ShownEntry[] {
|
|
33
|
+
const members = new Map<number, LogEntry[]>();
|
|
34
|
+
const open = new Map<number, { lines: LogEntry[]; depth: number }>();
|
|
35
|
+
const last = new Map<number, LogEntry>();
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
const plain = stripColor(entry.text);
|
|
38
|
+
const block = open.get(entry.source);
|
|
39
|
+
if (block && (block.depth > 0 || FRAME.test(plain) || MORE.test(plain))) {
|
|
40
|
+
block.lines.push(entry);
|
|
41
|
+
block.depth = Math.max(0, block.depth + depthChange(plain));
|
|
42
|
+
} else {
|
|
43
|
+
open.delete(entry.source);
|
|
44
|
+
const before = last.get(entry.source);
|
|
45
|
+
const beforePlain = before && stripColor(before.text);
|
|
46
|
+
if (before && beforePlain?.trim() && !FRAME.test(beforePlain) && FRAME.test(plain)) {
|
|
47
|
+
const lines = [before, entry];
|
|
48
|
+
members.set(before.seq, lines);
|
|
49
|
+
open.set(entry.source, { lines, depth: Math.max(0, depthChange(plain)) });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
last.set(entry.source, entry);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const hidden = new Set<number>();
|
|
56
|
+
const member = new Set<number>();
|
|
57
|
+
const starts = new Map<number, ShownEntry>();
|
|
58
|
+
for (const [seq, lines] of members) {
|
|
59
|
+
const text = lines.map((line) => stripColor(line.text)).join("\n");
|
|
60
|
+
const detail = lines.map((line) => DETAIL.exec(stripColor(line.text))?.[2]).find(Boolean);
|
|
61
|
+
const head = stripColor(lines[0]?.text ?? "").trim();
|
|
62
|
+
const isOpen = expanded.has(seq);
|
|
63
|
+
starts.set(seq, {
|
|
64
|
+
seq: seq - 0.5,
|
|
65
|
+
source: lines[0]?.source ?? 0,
|
|
66
|
+
text: head,
|
|
67
|
+
error: { seq, summary: detail ? `${head} — ${detail}` : head, text, lines: lines.length, expanded: isOpen },
|
|
68
|
+
});
|
|
69
|
+
for (const line of lines) (isOpen ? member : hidden).add(line.seq);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const out: ShownEntry[] = [];
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
const start = starts.get(entry.seq);
|
|
75
|
+
if (start) out.push(start);
|
|
76
|
+
if (hidden.has(entry.seq)) continue;
|
|
77
|
+
const failed = member.has(entry.seq) || FAILURE.test(stripColor(entry.text));
|
|
78
|
+
out.push(failed ? { ...entry, failed } : entry);
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Braces opened minus closed, outside quoted strings. */
|
|
84
|
+
function depthChange(line: string) {
|
|
85
|
+
const bare = line.replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g, "");
|
|
86
|
+
return (bare.match(/[{[]/g)?.length ?? 0) - (bare.match(/[}\]]/g)?.length ?? 0);
|
|
87
|
+
}
|