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/locate.js
CHANGED
|
@@ -1,194 +1,152 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Locating and version-checking the typst binary: the configured path, then
|
|
3
|
+
* PATH, then common install locations, then the login shell (version
|
|
4
|
+
* managers). Ported from the ZCode typst-workbench server (0.2.0)
|
|
5
|
+
* `src/typst/locate.ts`. Host half only.
|
|
6
|
+
* @module dsh-typst/typst/locate
|
|
7
|
+
*/
|
|
8
|
+
import { isAbsolute, join, resolve, sep } from "node:path";
|
|
4
9
|
import { MIN_TYPST } from "../constants.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
import { findExecutable, isExecutable } from "../host/which.js";
|
|
11
|
+
/** Parse `typst 0.13.1`-style version output. */
|
|
12
|
+
export function parseVersion(text) {
|
|
13
|
+
const match = /(?:^|\s)typst\s+v?(\d+)\.(\d+)\.(\d+)/i.exec(text) ??
|
|
14
|
+
/(\d+)\.(\d+)\.(\d+)/.exec(text);
|
|
15
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
8
16
|
}
|
|
9
|
-
function compareVersion(a, b) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
export function compareVersion(a, b) {
|
|
18
|
+
for (let index = 0; index < 3; index++) {
|
|
19
|
+
if (a[index] !== b[index])
|
|
20
|
+
return a[index] - b[index];
|
|
21
|
+
}
|
|
22
|
+
return 0;
|
|
14
23
|
}
|
|
15
|
-
const versionText = (version) => version.join(".");
|
|
16
|
-
function atLeast(version, required) {
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
export const versionText = (version) => version.join(".");
|
|
25
|
+
export function atLeast(version, required) {
|
|
26
|
+
const parsed = version ? parseVersion(version) : null;
|
|
27
|
+
return !!parsed && compareVersion(parsed, required) >= 0;
|
|
19
28
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
/** Common typst install directories per platform. */
|
|
30
|
+
export function commonDirs(platform, env, home) {
|
|
31
|
+
if (platform === "win32") {
|
|
32
|
+
const local = env.LOCALAPPDATA ?? join(home, "AppData", "Local");
|
|
33
|
+
return [
|
|
34
|
+
join(local, "Microsoft", "WinGet", "Links"),
|
|
35
|
+
join(local, "Programs", "typst"),
|
|
36
|
+
join(home, ".cargo", "bin"),
|
|
37
|
+
join(home, "scoop", "shims"),
|
|
38
|
+
join(env.ProgramData ?? "C:\\ProgramData", "chocolatey", "bin"),
|
|
39
|
+
];
|
|
40
|
+
}
|
|
23
41
|
return [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
"/opt/homebrew/bin",
|
|
43
|
+
"/usr/local/bin",
|
|
44
|
+
join(home, ".cargo", "bin"),
|
|
45
|
+
join(home, ".local", "bin"),
|
|
46
|
+
join(home, "bin"),
|
|
47
|
+
join(home, ".nix-profile", "bin"),
|
|
48
|
+
"/run/current-system/sw/bin",
|
|
49
|
+
"/nix/var/nix/profiles/default/bin",
|
|
50
|
+
"/snap/bin",
|
|
51
|
+
"/usr/bin",
|
|
29
52
|
];
|
|
30
|
-
}
|
|
31
|
-
return [
|
|
32
|
-
"/opt/homebrew/bin",
|
|
33
|
-
"/usr/local/bin",
|
|
34
|
-
join(home, ".cargo", "bin"),
|
|
35
|
-
join(home, ".local", "bin"),
|
|
36
|
-
join(home, "bin"),
|
|
37
|
-
join(home, ".nix-profile", "bin"),
|
|
38
|
-
"/run/current-system/sw/bin",
|
|
39
|
-
"/nix/var/nix/profiles/default/bin",
|
|
40
|
-
"/snap/bin",
|
|
41
|
-
"/usr/bin"
|
|
42
|
-
];
|
|
43
53
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
/**
|
|
55
|
+
* The directories the lookup covers, in report order (for the setup page's
|
|
56
|
+
* "where we looked" list), `~`-abbreviated.
|
|
57
|
+
*/
|
|
58
|
+
export function searchedDirs(platform, env, home, arch = process.arch) {
|
|
59
|
+
const dirs = commonDirs(platform, env, home);
|
|
60
|
+
const first = platform === "win32"
|
|
61
|
+
? [dirs[0], join(home, ".cargo", "bin")]
|
|
62
|
+
: platform === "darwin"
|
|
63
|
+
? [
|
|
64
|
+
arch === "arm64" ? "/opt/homebrew/bin" : "/usr/local/bin",
|
|
65
|
+
join(home, ".cargo", "bin"),
|
|
66
|
+
]
|
|
67
|
+
: [join(home, ".cargo", "bin"), join(home, ".local", "bin")];
|
|
68
|
+
const ordered = [...new Set([...first, ...dirs])];
|
|
69
|
+
return ordered.map((dir) => home && dir.startsWith(home + sep) ? `~${dir.slice(home.length)}` : dir);
|
|
54
70
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
if (!
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let child;
|
|
74
|
-
try {
|
|
75
|
-
child = spawn(command, args, {
|
|
76
|
-
cwd: options.cwd,
|
|
77
|
-
env: options.env ?? process.env,
|
|
78
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
79
|
-
windowsHide: true
|
|
80
|
-
});
|
|
81
|
-
} catch (error) {
|
|
82
|
-
resolve({
|
|
83
|
-
code: null,
|
|
84
|
-
stdout,
|
|
85
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
86
|
-
timedOut
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
71
|
+
/** Ask the login shell where typst is (mise/asdf and friends). */
|
|
72
|
+
async function fromShell(env, runner, cwd) {
|
|
73
|
+
const shell = env.SHELL;
|
|
74
|
+
if (!shell || process.platform === "win32")
|
|
75
|
+
return null;
|
|
76
|
+
for (const flags of ["-lc", "-ilc"]) {
|
|
77
|
+
const result = await runner.run([shell, flags, "command -v typst"], {
|
|
78
|
+
cwd,
|
|
79
|
+
env: { SHELL: shell },
|
|
80
|
+
timeoutMs: 4_000,
|
|
81
|
+
});
|
|
82
|
+
const line = result.stdout
|
|
83
|
+
.split(/\r?\n/)
|
|
84
|
+
.map((entry) => entry.trim())
|
|
85
|
+
.reverse()
|
|
86
|
+
.find((entry) => isAbsolute(entry));
|
|
87
|
+
if (line && (await isExecutable(line)))
|
|
88
|
+
return line;
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
timedOut = true;
|
|
92
|
-
child.kill("SIGKILL");
|
|
93
|
-
}, options.timeoutMs ?? 1e4);
|
|
94
|
-
child.stdout?.on("data", (chunk) => {
|
|
95
|
-
stdout += chunk;
|
|
96
|
-
});
|
|
97
|
-
child.stderr?.on("data", (chunk) => {
|
|
98
|
-
stderr += chunk;
|
|
99
|
-
});
|
|
100
|
-
child.on("error", (error) => {
|
|
101
|
-
stderr += error.message;
|
|
102
|
-
});
|
|
103
|
-
child.on("close", (code) => {
|
|
104
|
-
clearTimeout(timer);
|
|
105
|
-
resolve({ code, stdout, stderr, timedOut });
|
|
106
|
-
});
|
|
107
|
-
});
|
|
90
|
+
return null;
|
|
108
91
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Locate a usable typst and check its version.
|
|
94
|
+
* @returns the toolchain state; `ready` carries path/source/version.
|
|
95
|
+
*/
|
|
96
|
+
export async function locateTypst(options) {
|
|
97
|
+
const env = options.env ?? process.env;
|
|
98
|
+
const platform = options.platform ?? process.platform;
|
|
99
|
+
const home = options.home ?? env.HOME ?? env.USERPROFILE ?? "";
|
|
100
|
+
let found = null;
|
|
101
|
+
if (options.setting) {
|
|
102
|
+
// A relative setting means "relative to this workspace", the directory
|
|
103
|
+
// the typst child runs in, not to whatever cwd the Host process started in.
|
|
104
|
+
const setting = isAbsolute(options.setting)
|
|
105
|
+
? options.setting
|
|
106
|
+
: resolve(options.cwd ?? process.cwd(), options.setting);
|
|
107
|
+
if (!(await isExecutable(setting, platform))) {
|
|
108
|
+
return {
|
|
109
|
+
state: "error",
|
|
110
|
+
path: setting,
|
|
111
|
+
source: "setting",
|
|
112
|
+
error: `The Typst path in the plugin settings (${setting}) is not an executable file.`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
found = { path: setting, source: "setting" };
|
|
116
|
+
}
|
|
117
|
+
const search = async (dirs, source) => {
|
|
118
|
+
const path = await findExecutable("typst", dirs, { env, platform });
|
|
119
|
+
return path === null ? null : { path, source };
|
|
120
|
+
};
|
|
121
|
+
found ??= await search([], "path");
|
|
122
|
+
found ??= await search(options.common ?? commonDirs(platform, env, home), "common");
|
|
123
|
+
if (!found && options.shell !== false) {
|
|
124
|
+
const path = await fromShell(env, options.process, options.cwd ?? process.cwd());
|
|
125
|
+
if (path)
|
|
126
|
+
found = { path, source: "shell" };
|
|
127
|
+
}
|
|
128
|
+
if (!found)
|
|
129
|
+
return { state: "missing" };
|
|
130
|
+
const result = await options.process.run([found.path, "--version"], {
|
|
131
|
+
cwd: options.cwd ?? process.cwd(),
|
|
132
|
+
timeoutMs: 10_000,
|
|
116
133
|
});
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const platform = options.platform ?? process.platform;
|
|
125
|
-
const home = options.home ?? env.HOME ?? env.USERPROFILE ?? "";
|
|
126
|
-
const names = platform === "win32" ? ["typst.exe", "typst.cmd", "typst"] : ["typst"];
|
|
127
|
-
let found = null;
|
|
128
|
-
if (options.setting) {
|
|
129
|
-
if (!await executable(options.setting)) {
|
|
130
|
-
return {
|
|
131
|
-
state: "error",
|
|
132
|
-
path: options.setting,
|
|
133
|
-
source: "setting",
|
|
134
|
-
error: `The Typst path in the plugin settings (${options.setting}) is not an executable file.`
|
|
135
|
-
};
|
|
134
|
+
const version = parseVersion(`${result.stdout}\n${result.stderr}`);
|
|
135
|
+
if (result.code !== 0 || !version) {
|
|
136
|
+
return {
|
|
137
|
+
state: "error",
|
|
138
|
+
...found,
|
|
139
|
+
error: `\`${found.path} --version\` failed: ${(result.stderr || result.stdout).trim().slice(0, 300) || `exit code ${result.code}`}`,
|
|
140
|
+
};
|
|
136
141
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
142
|
+
if (compareVersion(version, MIN_TYPST) < 0) {
|
|
143
|
+
return {
|
|
144
|
+
state: "too_old",
|
|
145
|
+
...found,
|
|
146
|
+
version: versionText(version),
|
|
147
|
+
error: `Typst ${versionText(version)} is older than ${versionText(MIN_TYPST)}.`,
|
|
148
|
+
};
|
|
145
149
|
}
|
|
146
|
-
return
|
|
147
|
-
};
|
|
148
|
-
found ??= await search(
|
|
149
|
-
(env.PATH ?? env.Path ?? "").split(delimiter).filter(Boolean),
|
|
150
|
-
"path"
|
|
151
|
-
);
|
|
152
|
-
found ??= await search(
|
|
153
|
-
options.common ?? commonDirs(platform, env, home),
|
|
154
|
-
"common"
|
|
155
|
-
);
|
|
156
|
-
if (!found && options.shell !== false) {
|
|
157
|
-
const path = await fromShell(env);
|
|
158
|
-
if (path) found = { path, source: "shell" };
|
|
159
|
-
}
|
|
160
|
-
if (!found) return { state: "missing" };
|
|
161
|
-
const result = await run(found.path, ["--version"], {
|
|
162
|
-
env,
|
|
163
|
-
timeoutMs: 1e4
|
|
164
|
-
});
|
|
165
|
-
const version = parseVersion(`${result.stdout}
|
|
166
|
-
${result.stderr}`);
|
|
167
|
-
if (result.code !== 0 || !version) {
|
|
168
|
-
return {
|
|
169
|
-
state: "error",
|
|
170
|
-
...found,
|
|
171
|
-
error: `\`${found.path} --version\` failed: ${(result.stderr || result.stdout).trim().slice(0, 300) || `exit code ${result.code}`}`
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
if (compareVersion(version, MIN_TYPST) < 0) {
|
|
175
|
-
return {
|
|
176
|
-
state: "too_old",
|
|
177
|
-
...found,
|
|
178
|
-
version: versionText(version),
|
|
179
|
-
error: `Typst ${versionText(version)} is older than ${versionText(MIN_TYPST)}.`
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
return { state: "ready", ...found, version: versionText(version) };
|
|
150
|
+
return { state: "ready", ...found, version: versionText(version) };
|
|
183
151
|
}
|
|
184
|
-
|
|
185
|
-
atLeast,
|
|
186
|
-
commonDirs,
|
|
187
|
-
compareVersion,
|
|
188
|
-
locateTypst,
|
|
189
|
-
parseVersion,
|
|
190
|
-
run,
|
|
191
|
-
searchedDirs,
|
|
192
|
-
versionText
|
|
193
|
-
};
|
|
194
|
-
//# sourceMappingURL=locate.js.map
|
|
152
|
+
//# sourceMappingURL=locate.js.map
|
package/lib/typst/locate.js.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/typst/locate.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Locating and version-checking the typst binary: the configured path, then\n * PATH, then common install locations, then the login shell (version\n * managers). Ported from the ZCode typst-workbench server (0.2.0)\n * `src/typst/locate.ts`. Host half only.\n * @module dsh-typst/typst/locate\n */\n\nimport { spawn } from \"node:child_process\";\nimport { access, constants, stat } from \"node:fs/promises\";\nimport { delimiter, isAbsolute, join, sep } from \"node:path\";\nimport { MIN_TYPST } from \"../constants.js\";\nimport type { TypstSource } from \"../contract.js\";\n\n/** Parse `typst 0.13.1`-style version output. */\nexport function parseVersion(text: string): [number, number, number] | null {\n const match =\n /(?:^|\\s)typst\\s+v?(\\d+)\\.(\\d+)\\.(\\d+)/i.exec(text) ??\n /(\\d+)\\.(\\d+)\\.(\\d+)/.exec(text);\n return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;\n}\n\nexport function compareVersion(\n a: readonly number[],\n b: readonly number[],\n): number {\n for (let index = 0; index < 3; index++) {\n if (a[index] !== b[index]) return a[index] - b[index];\n }\n return 0;\n}\n\nexport const versionText = (version: readonly number[]): string =>\n version.join(\".\");\n\nexport function atLeast(version: string, required: readonly number[]): boolean {\n const parsed = version ? parseVersion(version) : null;\n return !!parsed && compareVersion(parsed, required) >= 0;\n}\n\n/** Common typst install directories per platform. */\nexport function commonDirs(\n platform: string,\n env: NodeJS.ProcessEnv,\n home: string,\n): string[] {\n if (platform === \"win32\") {\n const local = env.LOCALAPPDATA ?? join(home, \"AppData\", \"Local\");\n return [\n join(local, \"Microsoft\", \"WinGet\", \"Links\"),\n join(local, \"Programs\", \"typst\"),\n join(home, \".cargo\", \"bin\"),\n join(home, \"scoop\", \"shims\"),\n join(env.ProgramData ?? \"C:\\\\ProgramData\", \"chocolatey\", \"bin\"),\n ];\n }\n return [\n \"/opt/homebrew/bin\",\n \"/usr/local/bin\",\n join(home, \".cargo\", \"bin\"),\n join(home, \".local\", \"bin\"),\n join(home, \"bin\"),\n join(home, \".nix-profile\", \"bin\"),\n \"/run/current-system/sw/bin\",\n \"/nix/var/nix/profiles/default/bin\",\n \"/snap/bin\",\n \"/usr/bin\",\n ];\n}\n\n/**\n * The directories the lookup covers, in report order (for the setup page's\n * \"where we looked\" list), `~`-abbreviated.\n */\nexport function searchedDirs(\n platform: string,\n env: NodeJS.ProcessEnv,\n home: string,\n arch: string = process.arch,\n): string[] {\n const dirs = commonDirs(platform, env, home);\n const first =\n platform === \"win32\"\n ? [dirs[0], join(home, \".cargo\", \"bin\")]\n : platform === \"darwin\"\n ? [\n arch === \"arm64\" ? \"/opt/homebrew/bin\" : \"/usr/local/bin\",\n join(home, \".cargo\", \"bin\"),\n ]\n : [join(home, \".cargo\", \"bin\"), join(home, \".local\", \"bin\")];\n const ordered = [...new Set([...first, ...dirs])];\n return ordered.map((dir) =>\n home && dir.startsWith(home + sep) ? `~${dir.slice(home.length)}` : dir,\n );\n}\n\nasync function executable(path: string): Promise<boolean> {\n try {\n const info = await stat(path);\n if (!info.isFile()) return false;\n await access(\n path,\n process.platform === \"win32\" ? constants.F_OK : constants.X_OK,\n );\n return true;\n } catch {\n return false;\n }\n}\n\nexport interface RunResult {\n code: number | null;\n stdout: string;\n stderr: string;\n timedOut: boolean;\n}\n\n/** Run a short-lived command to completion, capturing both streams. */\nexport function run(\n command: string,\n args: string[],\n options: { cwd?: string; env?: NodeJS.ProcessEnv; timeoutMs?: number } = {},\n): Promise<RunResult> {\n return new Promise((resolve) => {\n let stdout = \"\";\n let stderr = \"\";\n let timedOut = false;\n let child: import(\"node:child_process\").ChildProcess;\n try {\n child = spawn(command, args, {\n cwd: options.cwd,\n env: options.env ?? process.env,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n windowsHide: true,\n });\n } catch (error) {\n resolve({\n code: null,\n stdout,\n stderr: error instanceof Error ? error.message : String(error),\n timedOut,\n });\n return;\n }\n const timer = setTimeout(() => {\n timedOut = true;\n child.kill(\"SIGKILL\");\n }, options.timeoutMs ?? 10_000);\n child.stdout?.on(\"data\", (chunk: Buffer) => {\n stdout += chunk;\n });\n child.stderr?.on(\"data\", (chunk: Buffer) => {\n stderr += chunk;\n });\n child.on(\"error\", (error: Error) => {\n stderr += error.message;\n });\n child.on(\"close\", (code) => {\n clearTimeout(timer);\n resolve({ code, stdout, stderr, timedOut });\n });\n });\n}\n\n/** Ask the login shell where typst is (mise/asdf and friends). */\nasync function fromShell(env: NodeJS.ProcessEnv): Promise<string | null> {\n const shell = env.SHELL;\n if (!shell || process.platform === \"win32\") return null;\n for (const flags of [\"-lc\", \"-ilc\"]) {\n const result = await run(shell, [flags, \"command -v typst\"], {\n env,\n timeoutMs: 4_000,\n });\n const line = result.stdout\n .split(/\\r?\\n/)\n .map((entry) => entry.trim())\n .reverse()\n .find((entry) => isAbsolute(entry));\n if (line && (await executable(line))) return line;\n }\n return null;\n}\n\nexport type Toolchain =\n | { state: \"ready\"; path: string; source: TypstSource; version: string }\n | { state: \"missing\" }\n | {\n state: \"too_old\";\n path: string;\n source: TypstSource;\n version: string;\n error: string;\n }\n | { state: \"error\"; path?: string; source?: TypstSource; error: string };\n\nexport interface LocateOptions {\n /** The configured \"Typst path\" setting; wins when executable. */\n setting?: string;\n env?: NodeJS.ProcessEnv;\n platform?: string;\n home?: string;\n /** Directory list overriding the common defaults (tests). */\n common?: string[];\n /** Skip the login-shell probe (the panel's periodic recheck does). */\n shell?: boolean;\n}\n\n/**\n * Locate a usable typst and check its version.\n * @returns the toolchain state; `ready` carries path/source/version.\n */\nexport async function locateTypst(\n options: LocateOptions = {},\n): Promise<Toolchain> {\n const env = options.env ?? process.env;\n const platform = options.platform ?? process.platform;\n const home = options.home ?? env.HOME ?? env.USERPROFILE ?? \"\";\n const names =\n platform === \"win32\" ? [\"typst.exe\", \"typst.cmd\", \"typst\"] : [\"typst\"];\n let found: { path: string; source: TypstSource } | null = null;\n if (options.setting) {\n if (!(await executable(options.setting))) {\n return {\n state: \"error\",\n path: options.setting,\n source: \"setting\",\n error: `The Typst path in the plugin settings (${options.setting}) is not an executable file.`,\n };\n }\n found = { path: options.setting, source: \"setting\" };\n }\n const search = async (\n dirs: string[],\n source: TypstSource,\n ): Promise<typeof found> => {\n for (const dir of dirs) {\n for (const name of names) {\n const path = join(dir, name);\n if (dir && (await executable(path))) return { path, source };\n }\n }\n return null;\n };\n found ??= await search(\n (env.PATH ?? env.Path ?? \"\").split(delimiter).filter(Boolean),\n \"path\",\n );\n found ??= await search(\n options.common ?? commonDirs(platform, env, home),\n \"common\",\n );\n if (!found && options.shell !== false) {\n const path = await fromShell(env);\n if (path) found = { path, source: \"shell\" };\n }\n if (!found) return { state: \"missing\" };\n const result = await run(found.path, [\"--version\"], {\n env,\n timeoutMs: 10_000,\n });\n const version = parseVersion(`${result.stdout}\\n${result.stderr}`);\n if (result.code !== 0 || !version) {\n return {\n state: \"error\",\n ...found,\n error: `\\`${found.path} --version\\` failed: ${(result.stderr || result.stdout).trim().slice(0, 300) || `exit code ${result.code}`}`,\n };\n }\n if (compareVersion(version, MIN_TYPST) < 0) {\n return {\n state: \"too_old\",\n ...found,\n version: versionText(version),\n error: `Typst ${versionText(version)} is older than ${versionText(MIN_TYPST)}.`,\n };\n }\n return { state: \"ready\", ...found, version: versionText(version) };\n}\n"],
|
|
5
|
-
"mappings": "AAQA,SAAS,aAAa;AACtB,SAAS,QAAQ,WAAW,YAAY;AACxC,SAAS,WAAW,YAAY,MAAM,WAAW;AACjD,SAAS,iBAAiB;AAInB,SAAS,aAAa,MAA+C;AAC1E,QAAM,QACJ,yCAAyC,KAAK,IAAI,KAClD,sBAAsB,KAAK,IAAI;AACjC,SAAO,QAAQ,CAAC,OAAO,MAAM,CAAC,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI;AAC1E;AAE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an the workspace for `.typ` files and pick the one
|
|
3
3
|
* the user would pass to `typst compile`. Ported from the ZCode
|
|
4
4
|
* typst-workbench server (0.2.0) `src/domain/project.ts`. Host half only.
|
|
5
|
+
*
|
|
6
|
+
* The index is bounded (directories, entries, realpath-visited directories)
|
|
7
|
+
* and yields per-directory additions instead of ever-growing copies. A
|
|
8
|
+
* symlinked directory is followed once when its real target is inside the
|
|
9
|
+
* workspace; a symlinked `.typ` file is a candidate only when its real target
|
|
10
|
+
* is inside the workspace, so an external link cannot become a candidate.
|
|
5
11
|
* @module dsh-typst/typst/mainfile
|
|
6
12
|
*/
|
|
7
13
|
/**
|
|
@@ -12,10 +18,23 @@
|
|
|
12
18
|
* @param remembered - the previously chosen main file for this workspace.
|
|
13
19
|
*/
|
|
14
20
|
export declare function chooseMain(candidates: string[], remembered: string | null): string | null;
|
|
15
|
-
/**
|
|
16
|
-
export
|
|
17
|
-
files
|
|
21
|
+
/** One directory's contribution to the index. */
|
|
22
|
+
export interface IndexBatch {
|
|
23
|
+
/** `.typ` files discovered in this directory. */
|
|
24
|
+
added: string[];
|
|
25
|
+
/** Entries inspected so far. */
|
|
18
26
|
visited: number;
|
|
27
|
+
/** Read errors so far (directory-relative). */
|
|
19
28
|
errors: string[];
|
|
20
|
-
|
|
29
|
+
/** True on the final batch (budget reached or the tree is exhausted). */
|
|
30
|
+
done: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Cancellable, bounded complete index.
|
|
34
|
+
* @param root - workspace root to scan.
|
|
35
|
+
* @param includeExcluded - reveal hidden directories and every skipped name.
|
|
36
|
+
* @param signal - aborts the scan when the session is closed or superseded.
|
|
37
|
+
* @param excludeDirs - extra directory names to skip, matched without case at any depth.
|
|
38
|
+
*/
|
|
39
|
+
export declare function indexTypFiles(root: string, includeExcluded: boolean, signal: AbortSignal, excludeDirs?: readonly string[]): AsyncIterable<IndexBatch>;
|
|
21
40
|
//# sourceMappingURL=mainfile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mainfile.d.ts","sourceRoot":"","sources":["../../src/typst/mainfile.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mainfile.d.ts","sourceRoot":"","sources":["../../src/typst/mainfile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAmBH;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,UAAU,EAAE,MAAM,EAAE,EACpB,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,MAAM,GAAG,IAAI,CAiBf;AAED,iDAAiD;AACjD,MAAM,WAAW,UAAU;IACzB,iDAAiD;IACjD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,yEAAyE;IACzE,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAuB,aAAa,CAClC,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,OAAO,EACxB,MAAM,EAAE,WAAW,EACnB,WAAW,GAAE,SAAS,MAAM,EAAO,GAClC,aAAa,CAAC,UAAU,CAAC,CA0E3B"}
|
package/lib/typst/mainfile.js
CHANGED
|
@@ -1,64 +1,136 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Main-file discovery: scan the workspace for `.typ` files and pick the one
|
|
3
|
+
* the user would pass to `typst compile`. Ported from the ZCode
|
|
4
|
+
* typst-workbench server (0.2.0) `src/domain/project.ts`. Host half only.
|
|
5
|
+
*
|
|
6
|
+
* The index is bounded (directories, entries, realpath-visited directories)
|
|
7
|
+
* and yields per-directory additions instead of ever-growing copies. A
|
|
8
|
+
* symlinked directory is followed once when its real target is inside the
|
|
9
|
+
* workspace; a symlinked `.typ` file is a candidate only when its real target
|
|
10
|
+
* is inside the workspace, so an external link cannot become a candidate.
|
|
11
|
+
* @module dsh-typst/typst/mainfile
|
|
12
|
+
*/
|
|
13
|
+
import { readdir, realpath, stat } from "node:fs/promises";
|
|
2
14
|
import { join } from "node:path";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
import { isWithin } from "../workspace/containment.js";
|
|
16
|
+
const SKIP = new Set([
|
|
17
|
+
"node_modules",
|
|
18
|
+
"target",
|
|
19
|
+
"__pycache__",
|
|
20
|
+
"venv",
|
|
21
|
+
"build",
|
|
22
|
+
"dist",
|
|
10
23
|
]);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
signal.throwIfAborted();
|
|
36
|
-
const current = queue.shift();
|
|
37
|
-
let entries;
|
|
38
|
-
try {
|
|
39
|
-
entries = await readdir(current.dir, { withFileTypes: true });
|
|
40
|
-
} catch (error) {
|
|
41
|
-
errors.push(`${current.rel || "."}: ${String(error)}`);
|
|
42
|
-
yield { files: [...files], visited, errors: [...errors] };
|
|
43
|
-
continue;
|
|
24
|
+
/** Directory and entry budgets; a pathological tree stops with `truncated`. */
|
|
25
|
+
const MAX_DIRS = 5_000;
|
|
26
|
+
const MAX_ENTRIES = 100_000;
|
|
27
|
+
/**
|
|
28
|
+
* Pick the main file: a remembered choice, `main.typ`, the only top-level
|
|
29
|
+
* file, the shallowest `main.typ`, or — when there is exactly one candidate —
|
|
30
|
+
* that file. `null` means the panel should ask.
|
|
31
|
+
* @param candidates - workspace-relative `.typ` paths.
|
|
32
|
+
* @param remembered - the previously chosen main file for this workspace.
|
|
33
|
+
*/
|
|
34
|
+
export function chooseMain(candidates, remembered) {
|
|
35
|
+
if (remembered && candidates.includes(remembered))
|
|
36
|
+
return remembered;
|
|
37
|
+
if (candidates.includes("main.typ"))
|
|
38
|
+
return "main.typ";
|
|
39
|
+
const top = candidates.filter((path) => !path.includes("/"));
|
|
40
|
+
if (top.length === 1)
|
|
41
|
+
return top[0];
|
|
42
|
+
const mains = candidates.filter((path) => path.split("/").pop() === "main.typ");
|
|
43
|
+
if (mains.length) {
|
|
44
|
+
const shallowest = Math.min(...mains.map((path) => path.split("/").length));
|
|
45
|
+
const atDepth = mains.filter((path) => path.split("/").length === shallowest);
|
|
46
|
+
if (atDepth.length === 1)
|
|
47
|
+
return atDepth[0];
|
|
44
48
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
if (candidates.length === 1)
|
|
50
|
+
return candidates[0];
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Cancellable, bounded complete index.
|
|
55
|
+
* @param root - workspace root to scan.
|
|
56
|
+
* @param includeExcluded - reveal hidden directories and every skipped name.
|
|
57
|
+
* @param signal - aborts the scan when the session is closed or superseded.
|
|
58
|
+
* @param excludeDirs - extra directory names to skip, matched without case at any depth.
|
|
59
|
+
*/
|
|
60
|
+
export async function* indexTypFiles(root, includeExcluded, signal, excludeDirs = []) {
|
|
61
|
+
const realRoot = await realpath(root).catch(() => root);
|
|
62
|
+
const skipped = new Set([
|
|
63
|
+
...SKIP,
|
|
64
|
+
...excludeDirs.map((name) => name.toLowerCase()),
|
|
65
|
+
]);
|
|
66
|
+
const excluded = (name) => !includeExcluded &&
|
|
67
|
+
(name.startsWith(".") || skipped.has(name.toLowerCase()));
|
|
68
|
+
const visitedDirs = new Set();
|
|
69
|
+
const errors = [];
|
|
70
|
+
const queue = [{ dir: root, rel: "" }];
|
|
71
|
+
let head = 0;
|
|
72
|
+
let visited = 0;
|
|
73
|
+
let truncated = false;
|
|
74
|
+
while (head < queue.length) {
|
|
75
|
+
signal.throwIfAborted();
|
|
76
|
+
if (queue.length > MAX_DIRS) {
|
|
77
|
+
truncated = true;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
const current = queue[head++];
|
|
81
|
+
const realDir = await realpath(current.dir).catch(() => current.dir);
|
|
82
|
+
if (visitedDirs.has(realDir))
|
|
83
|
+
continue;
|
|
84
|
+
visitedDirs.add(realDir);
|
|
85
|
+
let entries;
|
|
86
|
+
try {
|
|
87
|
+
entries = await readdir(current.dir, { withFileTypes: true });
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
errors.push(`${current.rel || "."}: ${String(error)}`);
|
|
91
|
+
yield { added: [], visited, errors: [...errors], done: false };
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
95
|
+
const added = [];
|
|
96
|
+
for (const entry of entries) {
|
|
97
|
+
signal.throwIfAborted();
|
|
98
|
+
visited++;
|
|
99
|
+
if (visited > MAX_ENTRIES) {
|
|
100
|
+
truncated = true;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const path = current.rel ? `${current.rel}/${entry.name}` : entry.name;
|
|
104
|
+
const absolute = join(current.dir, entry.name);
|
|
105
|
+
if (entry.isDirectory()) {
|
|
106
|
+
if (!excluded(entry.name))
|
|
107
|
+
queue.push({ dir: absolute, rel: path });
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (entry.isSymbolicLink()) {
|
|
111
|
+
const target = await stat(absolute).catch(() => null);
|
|
112
|
+
const real = await realpath(absolute).catch(() => null);
|
|
113
|
+
if (target?.isDirectory()) {
|
|
114
|
+
if (real !== null &&
|
|
115
|
+
isWithin(realRoot, real) &&
|
|
116
|
+
!excluded(entry.name))
|
|
117
|
+
queue.push({ dir: absolute, rel: path });
|
|
118
|
+
}
|
|
119
|
+
else if (target?.isFile() &&
|
|
120
|
+
entry.name.endsWith(".typ") &&
|
|
121
|
+
real !== null &&
|
|
122
|
+
isWithin(realRoot, real)) {
|
|
123
|
+
added.push(path);
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (entry.isFile() && entry.name.endsWith(".typ"))
|
|
128
|
+
added.push(path);
|
|
129
|
+
}
|
|
130
|
+
yield { added, visited, errors: [...errors], done: truncated };
|
|
131
|
+
if (truncated)
|
|
132
|
+
return;
|
|
56
133
|
}
|
|
57
|
-
yield {
|
|
58
|
-
}
|
|
134
|
+
yield { added: [], visited, errors: [...errors], done: true };
|
|
59
135
|
}
|
|
60
|
-
|
|
61
|
-
chooseMain,
|
|
62
|
-
indexTypFiles
|
|
63
|
-
};
|
|
64
|
-
//# sourceMappingURL=mainfile.js.map
|
|
136
|
+
//# sourceMappingURL=mainfile.js.map
|