dsh-typst-plugin 0.1.0-alpha.0 → 0.1.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.en.md +86 -52
- package/README.md +93 -59
- package/cordis.patch.yml +1 -1
- package/docs/images/icon.png +0 -0
- package/lib/client.js +2088 -1136
- package/lib/client.js.map +4 -4
- package/lib/config.d.ts +66 -9
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +161 -25
- package/lib/config.js.map +1 -7
- package/lib/constants.d.ts +21 -2
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +83 -60
- package/lib/constants.js.map +1 -7
- package/lib/contract.d.ts +90 -6
- package/lib/contract.d.ts.map +1 -1
- package/lib/contract.js +9 -1
- package/lib/contract.js.map +1 -7
- package/lib/diagnostic-text.d.ts +13 -0
- package/lib/diagnostic-text.d.ts.map +1 -0
- package/lib/diagnostic-text.js +28 -0
- package/lib/diagnostic-text.js.map +1 -0
- package/lib/errors.d.ts +57 -15
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +154 -79
- package/lib/errors.js.map +1 -7
- package/lib/host/facts.d.ts.map +1 -1
- package/lib/host/facts.js +133 -139
- package/lib/host/facts.js.map +1 -7
- package/lib/host/which.d.ts +20 -0
- package/lib/host/which.d.ts.map +1 -0
- package/lib/host/which.js +50 -0
- package/lib/host/which.js.map +1 -0
- package/lib/index.js +2 -5
- package/lib/index.js.map +1 -7
- package/lib/remote.d.ts +5 -4
- package/lib/remote.d.ts.map +1 -1
- package/lib/remote.js +153 -143
- package/lib/remote.js.map +1 -7
- package/lib/service.d.ts +28 -4
- package/lib/service.d.ts.map +1 -1
- package/lib/service.js +202 -99
- package/lib/service.js.map +1 -7
- package/lib/skills/typst.js +74 -68
- package/lib/skills/typst.js.map +1 -7
- package/lib/status-codec.js +10 -5
- package/lib/status-codec.js.map +1 -7
- package/lib/tools/registration.d.ts +4 -3
- package/lib/tools/registration.d.ts.map +1 -1
- package/lib/tools/registration.js +726 -493
- package/lib/tools/registration.js.map +1 -7
- package/lib/tools/shared.d.ts +4 -5
- package/lib/tools/shared.d.ts.map +1 -1
- package/lib/tools/shared.js +73 -64
- package/lib/tools/shared.js.map +1 -7
- package/lib/typert.d.ts +5 -3
- package/lib/typert.d.ts.map +1 -1
- package/lib/typert.js +113 -64
- package/lib/typert.js.map +1 -7
- package/lib/typst/diagnostics.d.ts.map +1 -1
- package/lib/typst/diagnostics.js +218 -152
- package/lib/typst/diagnostics.js.map +1 -7
- package/lib/typst/flags.d.ts +8 -0
- package/lib/typst/flags.d.ts.map +1 -0
- package/lib/typst/flags.js +8 -0
- package/lib/typst/flags.js.map +1 -0
- package/lib/typst/locate.d.ts +6 -13
- package/lib/typst/locate.d.ts.map +1 -1
- package/lib/typst/locate.js +138 -180
- package/lib/typst/locate.js.map +1 -7
- package/lib/typst/mainfile.d.ts +23 -4
- package/lib/typst/mainfile.d.ts.map +1 -1
- package/lib/typst/mainfile.js +131 -59
- package/lib/typst/mainfile.js.map +1 -7
- package/lib/typst/match.d.ts +9 -1
- package/lib/typst/match.d.ts.map +1 -1
- package/lib/typst/match.js +213 -157
- package/lib/typst/match.js.map +1 -7
- package/lib/typst/oneshot.d.ts +8 -5
- package/lib/typst/oneshot.d.ts.map +1 -1
- package/lib/typst/oneshot.js +76 -66
- package/lib/typst/oneshot.js.map +1 -7
- package/lib/typst/owners.d.ts +28 -0
- package/lib/typst/owners.d.ts.map +1 -0
- package/lib/typst/owners.js +98 -0
- package/lib/typst/owners.js.map +1 -0
- package/lib/typst/pdf-extract.d.ts +1 -2
- package/lib/typst/pdf-extract.d.ts.map +1 -1
- package/lib/typst/pdf-extract.js +98 -74
- package/lib/typst/pdf-extract.js.map +1 -7
- package/lib/typst/process.d.ts +73 -0
- package/lib/typst/process.d.ts.map +1 -0
- package/lib/typst/process.js +147 -0
- package/lib/typst/process.js.map +1 -0
- package/lib/typst/text.d.ts +4 -7
- package/lib/typst/text.d.ts.map +1 -1
- package/lib/typst/text.js +258 -290
- package/lib/typst/text.js.map +1 -7
- package/lib/typst/watcher.d.ts +16 -17
- package/lib/typst/watcher.d.ts.map +1 -1
- package/lib/typst/watcher.js +199 -208
- package/lib/typst/watcher.js.map +1 -7
- package/lib/wire-schemas.d.ts +8 -153
- package/lib/wire-schemas.d.ts.map +1 -1
- package/lib/wire-schemas.js +405 -361
- package/lib/wire-schemas.js.map +1 -7
- package/lib/workspace/containment.d.ts +25 -0
- package/lib/workspace/containment.d.ts.map +1 -0
- package/lib/workspace/containment.js +54 -0
- package/lib/workspace/containment.js.map +1 -0
- package/lib/workspace/session.d.ts +73 -14
- package/lib/workspace/session.d.ts.map +1 -1
- package/lib/workspace/session.js +1516 -1172
- package/lib/workspace/session.js.map +1 -7
- package/locale/en.json +8 -2
- package/locale/zh.json +8 -2
- package/package.json +36 -179
- package/release-provenance.json +137 -0
- package/lib/typst/pdfjs-worker.d.js +0 -1
- package/lib/typst/pdfjs-worker.d.js.map +0 -7
package/lib/typst/diagnostics.js
CHANGED
|
@@ -1,171 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typst output parsing: one-shot diagnostics, the `typst watch` log stream,
|
|
3
|
+
* and make-deps files. Ported from the ZCode typst-workbench server
|
|
4
|
+
* (0.2.0) `src/typst/diagnostics.ts` and adjusted to this repository's
|
|
5
|
+
* domain error type. Host half only.
|
|
6
|
+
* @module dsh-typst/typst/diagnostics
|
|
7
|
+
*/
|
|
1
8
|
const ANSI = /\u001b\[[0-9;?]*[A-Za-z]/g;
|
|
2
9
|
const HEADER = /^(error|warning|help)(?:\[[^\]]*\])?: (.*)$/;
|
|
3
10
|
const LOCATION = /^\s*[┌╭]─+\s*(.+):(\d+):(\d+)\s*$/;
|
|
4
11
|
const NOTE = /^\s*= (?:(hint|note|help): )?(.*)$/;
|
|
12
|
+
/** typst's source trace line: ` while calling `f` at main.typ:2:11`. */
|
|
13
|
+
const TRACE = /^\s*while (calling|including|importing|exporting) `([^`]*)` at (.+):(\d+):(\d+)\s*$/;
|
|
5
14
|
const stripAnsi = (text) => text.replace(ANSI, "");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Parse the diagnostics block of one compile round (stderr of a one-shot
|
|
17
|
+
* compile, or the lines a `typst watch` round accumulated).
|
|
18
|
+
* @param text - raw output text.
|
|
19
|
+
* @param toFile - maps a path as typst printed it onto a display path.
|
|
20
|
+
* @returns the parsed diagnostics in order of appearance.
|
|
21
|
+
*/
|
|
22
|
+
export function parseDiagnostics(text, toFile = (path) => path) {
|
|
23
|
+
const diagnostics = [];
|
|
24
|
+
let target = null;
|
|
25
|
+
let current = null;
|
|
26
|
+
for (const raw of stripAnsi(text).split(/\r?\n/)) {
|
|
27
|
+
const line = raw.trimEnd();
|
|
28
|
+
const header = HEADER.exec(line);
|
|
29
|
+
if (header) {
|
|
30
|
+
const [, kind, message] = header;
|
|
31
|
+
if (kind === "help") {
|
|
32
|
+
if (current) {
|
|
33
|
+
const point = { message, location: null };
|
|
34
|
+
current.trace.push(point);
|
|
35
|
+
target = point;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
target = null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// The header grammar only admits error|warning|help, and help took
|
|
43
|
+
// the trace branch above, so the remaining kinds are exact.
|
|
44
|
+
current = {
|
|
45
|
+
severity: kind,
|
|
46
|
+
message,
|
|
47
|
+
location: null,
|
|
48
|
+
hints: [],
|
|
49
|
+
trace: [],
|
|
50
|
+
};
|
|
51
|
+
diagnostics.push(current);
|
|
52
|
+
target = current;
|
|
53
|
+
}
|
|
54
|
+
continue;
|
|
22
55
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
const location = LOCATION.exec(line);
|
|
57
|
+
if (location && target && !target.location) {
|
|
58
|
+
target.location = {
|
|
59
|
+
file: toFile(location[1]),
|
|
60
|
+
line: Number(location[2]),
|
|
61
|
+
column: Number(location[3]),
|
|
62
|
+
};
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const trace = TRACE.exec(line);
|
|
66
|
+
if (trace && current) {
|
|
67
|
+
const point = {
|
|
68
|
+
message: `while ${trace[1]} \`${trace[2]}\``,
|
|
69
|
+
location: {
|
|
70
|
+
file: toFile(trace[3]),
|
|
71
|
+
line: Number(trace[4]),
|
|
72
|
+
column: Number(trace[5]),
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
current.trace.push(point);
|
|
76
|
+
target = point;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const note = NOTE.exec(line);
|
|
80
|
+
if (note && current && /^\s*=/.test(line))
|
|
81
|
+
current.hints.push(note[2].trim());
|
|
44
82
|
}
|
|
45
|
-
|
|
46
|
-
if (note && current && /^\s*=/.test(line))
|
|
47
|
-
current.hints.push(note[2].trim());
|
|
48
|
-
}
|
|
49
|
-
return diagnostics;
|
|
83
|
+
return diagnostics;
|
|
50
84
|
}
|
|
51
|
-
const STAMP = String.raw`^(?:\[[^\]]*\]\s*)?`;
|
|
85
|
+
const STAMP = String.raw `^(?:\[[^\]]*\]\s*)?`;
|
|
52
86
|
const COMPILING = new RegExp(`${STAMP}compiling\\b`);
|
|
53
|
-
const FINISHED = new RegExp(
|
|
54
|
-
`${STAMP}compiled (successfully|with warnings|with errors)(?: in ([\\d.]+)\\s*(\xB5s|us|ms|s))?`
|
|
55
|
-
);
|
|
87
|
+
const FINISHED = new RegExp(`${STAMP}compiled (successfully|with warnings|with errors)(?: in ([\\d.]+)\\s*(\u00b5s|us|ms|s))?`);
|
|
56
88
|
function duration(value, unit) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
89
|
+
if (!value)
|
|
90
|
+
return undefined;
|
|
91
|
+
const number = Number(value);
|
|
92
|
+
if (!Number.isFinite(number))
|
|
93
|
+
return undefined;
|
|
94
|
+
return unit === "s" ? number * 1e3 : unit === "ms" ? number : number / 1e3;
|
|
61
95
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
let newline;
|
|
78
|
-
while ((newline = this.buffer.indexOf("\n")) >= 0) {
|
|
79
|
-
const line = stripAnsi(this.buffer.slice(0, newline)).replace(/\r$/, "");
|
|
80
|
-
this.buffer = this.buffer.slice(newline + 1);
|
|
81
|
-
this.line(line);
|
|
82
|
-
}
|
|
83
|
-
return this.pending !== null;
|
|
84
|
-
}
|
|
85
|
-
line(line) {
|
|
86
|
-
const trimmed = line.trim();
|
|
87
|
-
if (COMPILING.test(trimmed)) {
|
|
88
|
-
this.finalize();
|
|
89
|
-
this.emit({ kind: "compiling" });
|
|
90
|
-
return;
|
|
96
|
+
/**
|
|
97
|
+
* Incremental parser for `typst watch` stdout/stderr. Typst prints an
|
|
98
|
+
* ANSI-stamped `compiling` line per round, then `compiled …` plus any
|
|
99
|
+
* diagnostics. Rounds are finalized on the next marker or when the caller
|
|
100
|
+
* decides the output went quiet (`finalize`); a round with errors keeps
|
|
101
|
+
* accumulating help/hint lines until then.
|
|
102
|
+
*/
|
|
103
|
+
export class WatchLog {
|
|
104
|
+
emit;
|
|
105
|
+
toFile;
|
|
106
|
+
buffer = "";
|
|
107
|
+
pending = null;
|
|
108
|
+
constructor(emit, toFile = (path) => path) {
|
|
109
|
+
this.emit = emit;
|
|
110
|
+
this.toFile = toFile;
|
|
91
111
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Feed one output chunk.
|
|
114
|
+
* @returns whether a round is awaiting `finalize`.
|
|
115
|
+
*/
|
|
116
|
+
feed(chunk) {
|
|
117
|
+
this.buffer += chunk;
|
|
118
|
+
let newline;
|
|
119
|
+
while ((newline = this.buffer.indexOf("\n")) >= 0) {
|
|
120
|
+
const line = stripAnsi(this.buffer.slice(0, newline)).replace(/\r$/, "");
|
|
121
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
122
|
+
this.line(line);
|
|
123
|
+
}
|
|
124
|
+
return this.pending !== null;
|
|
103
125
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
126
|
+
line(line) {
|
|
127
|
+
const trimmed = line.trim();
|
|
128
|
+
if (COMPILING.test(trimmed)) {
|
|
129
|
+
this.finalize();
|
|
130
|
+
this.emit({ kind: "compiling" });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const finished = FINISHED.exec(trimmed);
|
|
134
|
+
if (finished) {
|
|
135
|
+
this.finalize();
|
|
136
|
+
const outcome = finished[1] === "successfully"
|
|
137
|
+
? "ok"
|
|
138
|
+
: finished[1] === "with warnings"
|
|
139
|
+
? "warnings"
|
|
140
|
+
: "error";
|
|
141
|
+
this.pending = {
|
|
142
|
+
outcome,
|
|
143
|
+
durationMs: duration(finished[2], finished[3]),
|
|
144
|
+
lines: [],
|
|
145
|
+
};
|
|
146
|
+
if (outcome === "ok")
|
|
147
|
+
this.finalize();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (/^watching\s/.test(trimmed) || /^writing to\s/.test(trimmed)) {
|
|
151
|
+
this.finalize();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (this.pending && trimmed === "") {
|
|
155
|
+
// A blank line ends a diagnostic block even when the pipe delivered the
|
|
156
|
+
// next block after the quiet window.
|
|
157
|
+
this.finalize();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (this.pending) {
|
|
161
|
+
this.pending.lines.push(line);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (trimmed.startsWith("error: "))
|
|
165
|
+
this.emit({ kind: "fatal", message: trimmed.slice(7) });
|
|
107
166
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
167
|
+
/** End the current round (next round started, or output went quiet). */
|
|
168
|
+
finalize() {
|
|
169
|
+
const pending = this.pending;
|
|
170
|
+
if (!pending)
|
|
171
|
+
return;
|
|
172
|
+
this.pending = null;
|
|
173
|
+
this.emit({
|
|
174
|
+
kind: "finished",
|
|
175
|
+
outcome: pending.outcome,
|
|
176
|
+
durationMs: pending.durationMs,
|
|
177
|
+
diagnostics: parseDiagnostics(pending.lines.join("\n"), this.toFile),
|
|
178
|
+
});
|
|
111
179
|
}
|
|
112
|
-
if (trimmed.startsWith("error: "))
|
|
113
|
-
this.emit({ kind: "fatal", message: trimmed.slice(7) });
|
|
114
|
-
}
|
|
115
|
-
/** End the current round (next round started, or output went quiet). */
|
|
116
|
-
finalize() {
|
|
117
|
-
const pending = this.pending;
|
|
118
|
-
if (!pending) return;
|
|
119
|
-
this.pending = null;
|
|
120
|
-
this.emit({
|
|
121
|
-
kind: "finished",
|
|
122
|
-
outcome: pending.outcome,
|
|
123
|
-
durationMs: pending.durationMs,
|
|
124
|
-
diagnostics: parseDiagnostics(pending.lines.join("\n"), this.toFile)
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
180
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Parse a deps file: typst ≥0.14 JSON (`{ inputs: [...] }`) or the classic
|
|
183
|
+
* make-deps grammar of `--make-deps`.
|
|
184
|
+
* @param text - the deps file content.
|
|
185
|
+
* @returns dependency paths in the order printed.
|
|
186
|
+
*/
|
|
187
|
+
export function parseDeps(text) {
|
|
188
|
+
const trimmed = text.trim();
|
|
189
|
+
if (!trimmed)
|
|
190
|
+
return [];
|
|
191
|
+
if (trimmed.startsWith("{")) {
|
|
192
|
+
try {
|
|
193
|
+
const value = JSON.parse(trimmed);
|
|
194
|
+
if (typeof value === "object" && value !== null && "inputs" in value) {
|
|
195
|
+
const inputs = value.inputs;
|
|
196
|
+
return Array.isArray(inputs)
|
|
197
|
+
? inputs.filter((entry) => typeof entry === "string")
|
|
198
|
+
: [];
|
|
199
|
+
}
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
141
205
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
206
|
+
const body = trimmed.replace(/\\\r?\n/g, " ");
|
|
207
|
+
const colon = body.search(/(?<!\\):(?=\s|$)/);
|
|
208
|
+
if (colon < 0)
|
|
209
|
+
return [];
|
|
210
|
+
const deps = [];
|
|
211
|
+
let currentDep = "";
|
|
212
|
+
const rest = body.slice(colon + 1);
|
|
213
|
+
for (let index = 0; index < rest.length; index++) {
|
|
214
|
+
const char = rest[index];
|
|
215
|
+
if (char === "\\" &&
|
|
216
|
+
index + 1 < rest.length &&
|
|
217
|
+
/[\s#\\:]/.test(rest[index + 1])) {
|
|
218
|
+
currentDep += rest[++index];
|
|
219
|
+
}
|
|
220
|
+
else if (char === "$" && rest[index + 1] === "$") {
|
|
221
|
+
currentDep += "$";
|
|
222
|
+
index++;
|
|
223
|
+
}
|
|
224
|
+
else if (/\s/.test(char)) {
|
|
225
|
+
if (currentDep)
|
|
226
|
+
deps.push(currentDep);
|
|
227
|
+
currentDep = "";
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
currentDep += char;
|
|
231
|
+
}
|
|
161
232
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
233
|
+
if (currentDep)
|
|
234
|
+
deps.push(currentDep);
|
|
235
|
+
return deps;
|
|
165
236
|
}
|
|
166
|
-
|
|
167
|
-
WatchLog,
|
|
168
|
-
parseDeps,
|
|
169
|
-
parseDiagnostics
|
|
170
|
-
};
|
|
171
|
-
//# sourceMappingURL=diagnostics.js.map
|
|
237
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/typst/diagnostics.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Typst output parsing: one-shot diagnostics, the `typst watch` log stream,\n * and make-deps files. Ported from the ZCode typst-workbench server\n * (0.2.0) `src/typst/diagnostics.ts` and adjusted to this repository's\n * domain error type. Host half only.\n * @module dsh-typst/typst/diagnostics\n */\n\nimport type {\n DiagnosticLocationView,\n DiagnosticPointView,\n DiagnosticView,\n} from \"../contract.js\";\n\nconst ANSI = /\\u001b\\[[0-9;?]*[A-Za-z]/g;\nconst HEADER = /^(error|warning|help)(?:\\[[^\\]]*\\])?: (.*)$/;\nconst LOCATION = /^\\s*[\u250C\u256D]\u2500+\\s*(.+):(\\d+):(\\d+)\\s*$/;\nconst NOTE = /^\\s*= (?:(hint|note|help): )?(.*)$/;\n\nconst stripAnsi = (text: string): string => text.replace(ANSI, \"\");\n\n/**\n * Parse the diagnostics block of one compile round (stderr of a one-shot\n * compile, or the lines a `typst watch` round accumulated).\n * @param text - raw output text.\n * @param toFile - maps a path as typst printed it onto a display path.\n * @returns the parsed diagnostics in order of appearance.\n */\nexport function parseDiagnostics(\n text: string,\n toFile: (path: string) => string = (path) => path,\n): DiagnosticView[] {\n const diagnostics: DiagnosticView[] = [];\n let target:\n { location: DiagnosticLocationView | null } | DiagnosticPointView | null =\n null;\n let current: DiagnosticView | null = null;\n for (const raw of stripAnsi(text).split(/\\r?\\n/)) {\n const line = raw.trimEnd();\n const header = HEADER.exec(line);\n if (header) {\n const [, kind, message] = header;\n if (kind === \"help\") {\n if (current) {\n const point: DiagnosticPointView = { message, location: null };\n current.trace.push(point);\n target = point;\n } else {\n target = null;\n }\n } else {\n // The header grammar only admits error|warning|help, and help took\n // the trace branch above, so the remaining kinds are exact.\n current = {\n severity: kind as DiagnosticView[\"severity\"],\n message,\n location: null,\n hints: [],\n trace: [],\n };\n diagnostics.push(current);\n target = current;\n }\n continue;\n }\n const location = LOCATION.exec(line);\n if (location && target && !target.location) {\n target.location = {\n file: toFile(location[1]),\n line: Number(location[2]),\n column: Number(location[3]),\n };\n continue;\n }\n const note = NOTE.exec(line);\n if (note && current && /^\\s*=/.test(line))\n current.hints.push(note[2].trim());\n }\n return diagnostics;\n}\n\nconst STAMP = String.raw`^(?:\\[[^\\]]*\\]\\s*)?`;\nconst COMPILING = new RegExp(`${STAMP}compiling\\\\b`);\nconst FINISHED = new RegExp(\n `${STAMP}compiled (successfully|with warnings|with errors)(?: in ([\\\\d.]+)\\\\s*(\\u00b5s|us|ms|s))?`,\n);\n\nfunction duration(\n value: string | undefined,\n unit: string | undefined,\n): number | undefined {\n if (!value) return undefined;\n const number = Number(value);\n if (!Number.isFinite(number)) return undefined;\n return unit === \"s\" ? number * 1e3 : unit === \"ms\" ? number : number / 1e3;\n}\n\n/** One event the watch log emits; the watcher serializes their handling. */\nexport type WatchEvent =\n | { kind: \"compiling\" }\n | {\n kind: \"finished\";\n outcome: \"ok\" | \"warnings\" | \"error\";\n durationMs?: number;\n diagnostics: DiagnosticView[];\n }\n | { kind: \"fatal\"; message: string };\n\n/**\n * Incremental parser for `typst watch` stdout/stderr. Typst prints an\n * ANSI-stamped `compiling` line per round, then `compiled \u2026` plus any\n * diagnostics. Rounds are finalized on the next marker or when the caller\n * decides the output went quiet (`finalize`); a round with errors keeps\n * accumulating help/hint lines until then.\n */\nexport class WatchLog {\n private buffer = \"\";\n private pending: {\n outcome: \"ok\" | \"warnings\" | \"error\";\n durationMs?: number;\n lines: string[];\n } | null = null;\n\n constructor(\n private readonly emit: (event: WatchEvent) => void,\n private readonly toFile: (path: string) => string = (path) => path,\n ) {}\n\n /**\n * Feed one output chunk.\n * @returns whether a round is awaiting `finalize`.\n */\n feed(chunk: string): boolean {\n this.buffer += chunk;\n let newline: number;\n while ((newline = this.buffer.indexOf(\"\\n\")) >= 0) {\n const line = stripAnsi(this.buffer.slice(0, newline)).replace(/\\r$/, \"\");\n this.buffer = this.buffer.slice(newline + 1);\n this.line(line);\n }\n return this.pending !== null;\n }\n\n private line(line: string): void {\n const trimmed = line.trim();\n if (COMPILING.test(trimmed)) {\n this.finalize();\n this.emit({ kind: \"compiling\" });\n return;\n }\n const finished = FINISHED.exec(trimmed);\n if (finished) {\n this.finalize();\n const outcome =\n finished[1] === \"successfully\"\n ? \"ok\"\n : finished[1] === \"with warnings\"\n ? \"warnings\"\n : \"error\";\n this.pending = {\n outcome,\n durationMs: duration(finished[2], finished[3]),\n lines: [],\n };\n if (outcome === \"ok\") this.finalize();\n return;\n }\n if (/^watching\\s/.test(trimmed) || /^writing to\\s/.test(trimmed)) {\n this.finalize();\n return;\n }\n if (this.pending) {\n this.pending.lines.push(line);\n return;\n }\n if (trimmed.startsWith(\"error: \"))\n this.emit({ kind: \"fatal\", message: trimmed.slice(7) });\n }\n\n /** End the current round (next round started, or output went quiet). */\n finalize(): void {\n const pending = this.pending;\n if (!pending) return;\n this.pending = null;\n this.emit({\n kind: \"finished\",\n outcome: pending.outcome,\n durationMs: pending.durationMs,\n diagnostics: parseDiagnostics(pending.lines.join(\"\\n\"), this.toFile),\n });\n }\n}\n\n/**\n * Parse a deps file: typst \u22650.14 JSON (`{ inputs: [...] }`) or the classic\n * make-deps grammar of `--make-deps`.\n * @param text - the deps file content.\n * @returns dependency paths in the order printed.\n */\nexport function parseDeps(text: string): string[] {\n const trimmed = text.trim();\n if (!trimmed) return [];\n if (trimmed.startsWith(\"{\")) {\n try {\n const value: unknown = JSON.parse(trimmed);\n if (typeof value === \"object\" && value !== null && \"inputs\" in value) {\n const inputs = (value as { inputs: unknown }).inputs;\n return Array.isArray(inputs)\n ? inputs.filter((entry): entry is string => typeof entry === \"string\")\n : [];\n }\n return [];\n } catch {\n return [];\n }\n }\n const body = trimmed.replace(/\\\\\\r?\\n/g, \" \");\n const colon = body.search(/(?<!\\\\):(?=\\s|$)/);\n if (colon < 0) return [];\n const deps: string[] = [];\n let currentDep = \"\";\n const rest = body.slice(colon + 1);\n for (let index = 0; index < rest.length; index++) {\n const char = rest[index];\n if (\n char === \"\\\\\" &&\n index + 1 < rest.length &&\n /[\\s#\\\\:]/.test(rest[index + 1])\n ) {\n currentDep += rest[++index];\n } else if (char === \"$\" && rest[index + 1] === \"$\") {\n currentDep += \"$\";\n index++;\n } else if (/\\s/.test(char)) {\n if (currentDep) deps.push(currentDep);\n currentDep = \"\";\n } else {\n currentDep += char;\n }\n }\n if (currentDep) deps.push(currentDep);\n return deps;\n}\n"],
|
|
5
|
-
"mappings": "AAcA,MAAM,OAAO;AACb,MAAM,SAAS;AACf,MAAM,WAAW;AACjB,MAAM,OAAO;AAEb,MAAM,YAAY,CAAC,SAAyB,KAAK,QAAQ,MAAM,EAAE;AAS1D,SAAS,iBACd,MACA,SAAmC,CAAC,SAAS,MAC3B;AAClB,QAAM,cA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2
|
+
export interface TypstFlagOptions {
|
|
3
|
+
root?: string;
|
|
4
|
+
fontPaths?: string[];
|
|
5
|
+
packagePath?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function typstFlags({ root, fontPaths, packagePath, }: TypstFlagOptions): string[];
|
|
8
|
+
//# sourceMappingURL=flags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../../src/typst/flags.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,UAAU,CAAC,EACzB,IAAI,EACJ,SAAS,EACT,WAAW,GACZ,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAM7B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function typstFlags({ root, fontPaths, packagePath, }) {
|
|
2
|
+
return [
|
|
3
|
+
...(root ? ["--root", root] : []),
|
|
4
|
+
...(fontPaths ?? []).flatMap((dir) => ["--font-path", dir]),
|
|
5
|
+
...(packagePath ? ["--package-path", packagePath] : []),
|
|
6
|
+
];
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../../src/typst/flags.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,UAAU,CAAC,EACzB,IAAI,EACJ,SAAS,EACT,WAAW,GACM;IACjB,OAAO;QACL,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAC3D,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KACxD,CAAC;AACJ,CAAC"}
|
package/lib/typst/locate.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @module dsh-typst/typst/locate
|
|
7
7
|
*/
|
|
8
8
|
import type { TypstSource } from "../contract.js";
|
|
9
|
+
import type { ProcessRunner } from "./process.js";
|
|
9
10
|
/** Parse `typst 0.13.1`-style version output. */
|
|
10
11
|
export declare function parseVersion(text: string): [number, number, number] | null;
|
|
11
12
|
export declare function compareVersion(a: readonly number[], b: readonly number[]): number;
|
|
@@ -18,18 +19,6 @@ export declare function commonDirs(platform: string, env: NodeJS.ProcessEnv, hom
|
|
|
18
19
|
* "where we looked" list), `~`-abbreviated.
|
|
19
20
|
*/
|
|
20
21
|
export declare function searchedDirs(platform: string, env: NodeJS.ProcessEnv, home: string, arch?: string): string[];
|
|
21
|
-
export interface RunResult {
|
|
22
|
-
code: number | null;
|
|
23
|
-
stdout: string;
|
|
24
|
-
stderr: string;
|
|
25
|
-
timedOut: boolean;
|
|
26
|
-
}
|
|
27
|
-
/** Run a short-lived command to completion, capturing both streams. */
|
|
28
|
-
export declare function run(command: string, args: string[], options?: {
|
|
29
|
-
cwd?: string;
|
|
30
|
-
env?: NodeJS.ProcessEnv;
|
|
31
|
-
timeoutMs?: number;
|
|
32
|
-
}): Promise<RunResult>;
|
|
33
22
|
export type Toolchain = {
|
|
34
23
|
state: "ready";
|
|
35
24
|
path: string;
|
|
@@ -59,10 +48,14 @@ export interface LocateOptions {
|
|
|
59
48
|
common?: string[];
|
|
60
49
|
/** Skip the login-shell probe (the panel's periodic recheck does). */
|
|
61
50
|
shell?: boolean;
|
|
51
|
+
/** The harness subprocess runner used for the version and login-shell probes. */
|
|
52
|
+
process: ProcessRunner;
|
|
53
|
+
/** Child working directory for those probes. */
|
|
54
|
+
cwd?: string;
|
|
62
55
|
}
|
|
63
56
|
/**
|
|
64
57
|
* Locate a usable typst and check its version.
|
|
65
58
|
* @returns the toolchain state; `ready` carries path/source/version.
|
|
66
59
|
*/
|
|
67
|
-
export declare function locateTypst(options
|
|
60
|
+
export declare function locateTypst(options: LocateOptions): Promise<Toolchain>;
|
|
68
61
|
//# sourceMappingURL=locate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locate.d.ts","sourceRoot":"","sources":["../../src/typst/locate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"locate.d.ts","sourceRoot":"","sources":["../../src/typst/locate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,iDAAiD;AACjD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAK1E;AAED,wBAAgB,cAAc,CAC5B,CAAC,EAAE,SAAS,MAAM,EAAE,EACpB,CAAC,EAAE,SAAS,MAAM,EAAE,GACnB,MAAM,CAKR;AAED,eAAO,MAAM,WAAW,GAAI,SAAS,SAAS,MAAM,EAAE,KAAG,MACtC,CAAC;AAEpB,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAG7E;AAED,qDAAqD;AACrD,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,IAAI,EAAE,MAAM,GACX,MAAM,EAAE,CAuBV;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,CAAC,UAAU,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