saturndocs 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/{auth-NKYU6ZSC.js → auth-3MLMF5Q3.js} +4 -4
  2. package/dist/broken-links-4AGMC2MO.js +275 -0
  3. package/dist/build-MHVOQFLW.js +139 -0
  4. package/dist/{chunk-BRC7CU3J.js → chunk-4Y6MLUWG.js} +2 -2
  5. package/dist/{chunk-N66SXAI5.js → chunk-5MPSOIDR.js} +3 -3
  6. package/dist/{chunk-KEZAO7P5.js → chunk-5UES2U73.js} +1 -1
  7. package/dist/{chunk-BB32XQJB.js → chunk-5USJZ6NW.js} +3 -3
  8. package/dist/{chunk-ZHYL7FYA.js → chunk-6YU3R6KT.js} +22 -61
  9. package/dist/{chunk-EH6E45H4.js → chunk-73NLPKNN.js} +83 -12
  10. package/dist/{chunk-22WNRYB7.js → chunk-76LHDHYT.js} +7 -7
  11. package/dist/chunk-AJ2ZMY42.js +62 -0
  12. package/dist/{chunk-QMA7433F.js → chunk-APABCEY4.js} +3 -3
  13. package/dist/chunk-DEHR3XUP.js +259 -0
  14. package/dist/{chunk-2GBM6W4I.js → chunk-E4GSFRKL.js} +3 -3
  15. package/dist/{chunk-TRQCW5CZ.js → chunk-EG5W7EGK.js} +2 -2
  16. package/dist/chunk-GZWCWTWW.js +1652 -0
  17. package/dist/chunk-IKQ7AGQF.js +65 -0
  18. package/dist/{chunk-6JJEMNSP.js → chunk-K5VTXKBR.js} +4 -4
  19. package/dist/{chunk-QF5ELRAU.js → chunk-KBVOLS2Y.js} +102 -121
  20. package/dist/{chunk-3JUP4HIA.js → chunk-KTQKLRHK.js} +2 -2
  21. package/dist/chunk-LDE53VKA.js +146 -0
  22. package/dist/{chunk-UXCORL5H.js → chunk-MRM7F2AG.js} +3 -3
  23. package/dist/{chunk-GLB47CSE.js → chunk-NYNPT2QB.js} +7 -7
  24. package/dist/chunk-OWKBGNGZ.js +72 -0
  25. package/dist/{chunk-4B6PUKF5.js → chunk-TFUZHZYD.js} +3 -3
  26. package/dist/{chunk-ZXJ3Z3PR.js → chunk-VAQXCTVC.js} +2 -2
  27. package/dist/{chunk-HJ7HRIAT.js → chunk-YT6RV4YV.js} +1 -1
  28. package/dist/{chunk-HHRZ3Y55.js → chunk-ZNLLNDCO.js} +168 -70
  29. package/dist/cli.js +3 -3
  30. package/dist/{coverage-IUQLC2H6.js → coverage-N6W4AASU.js} +4 -4
  31. package/dist/dev-QPQMWQQS.js +251 -0
  32. package/dist/{dist-LZ5BC7HG.js → dist-HWVPEW6T.js} +12 -2
  33. package/dist/index.d.ts +8 -15
  34. package/dist/index.js +62 -109
  35. package/dist/{init-EFZZRZZM.js → init-HAGN6VFO.js} +4 -4
  36. package/dist/{lint-N7ENEJVU.js → lint-UXAQS37W.js} +2 -2
  37. package/dist/{login-34OM3PJ2.js → login-PYPRPZKQ.js} +4 -4
  38. package/dist/{manage-2AOOCZE2.js → manage-WI3VBXEU.js} +4 -4
  39. package/dist/{nav-DKCGLENP.js → nav-OGQ6A4T6.js} +4 -4
  40. package/dist/{openapiCheck-KEHPUZOD.js → openapiCheck-IUYQOHOT.js} +2 -2
  41. package/dist/pages-KNXVBA6S.js +16 -0
  42. package/dist/{read-UGXFNEGJ.js → read-5JX2VT5I.js} +5 -5
  43. package/dist/{read-TQSSS7EJ.js → read-OIAJVVWF.js} +5 -5
  44. package/dist/renderer-76D7VFQ3.js +441 -0
  45. package/dist/requests-HBN7JHUH.js +13 -0
  46. package/dist/{schema-3I6XJSCY.js → schema-Q7AE5RAW.js} +3 -3
  47. package/dist/{sites-6HKU6JP7.js → sites-J6VTPRTR.js} +5 -5
  48. package/dist/{status-DFAYOCC4.js → status-YB26LFPN.js} +4 -4
  49. package/dist/{suggestions-JSTWOWRY.js → suggestions-3WG7NIQQ.js} +7 -7
  50. package/dist/validate-JVRDLMND.js +12 -0
  51. package/package.json +7 -1
  52. package/dist/chunk-KWEWL4MJ.js +0 -53
  53. package/dist/pages-E73CUM6I.js +0 -16
  54. package/dist/requests-OLCBRUAW.js +0 -13
  55. package/dist/unavailable-HVN65Q7D.js +0 -40
  56. package/dist/validate-6RIKQWMI.js +0 -11
@@ -3,11 +3,11 @@ import {
3
3
  authStatusOf,
4
4
  registerAuth,
5
5
  savedLoginStatusOf
6
- } from "./chunk-ZXJ3Z3PR.js";
7
- import "./chunk-4B6PUKF5.js";
8
- import "./chunk-HJ7HRIAT.js";
6
+ } from "./chunk-VAQXCTVC.js";
7
+ import "./chunk-TFUZHZYD.js";
9
8
  import "./chunk-M2BZEDAS.js";
10
- import "./chunk-EH6E45H4.js";
9
+ import "./chunk-YT6RV4YV.js";
10
+ import "./chunk-73NLPKNN.js";
11
11
  export {
12
12
  AUTH_METADATA,
13
13
  authStatusOf,
@@ -0,0 +1,275 @@
1
+ import {
2
+ documentLinks
3
+ } from "./chunk-OWKBGNGZ.js";
4
+ import {
5
+ releaseRoute,
6
+ siteRoutes
7
+ } from "./chunk-DEHR3XUP.js";
8
+ import {
9
+ buildGeneration
10
+ } from "./chunk-GZWCWTWW.js";
11
+ import "./chunk-KBVOLS2Y.js";
12
+ import "./chunk-ZNLLNDCO.js";
13
+ import {
14
+ isRedirectPattern
15
+ } from "./chunk-6YU3R6KT.js";
16
+ import {
17
+ createResultWriter,
18
+ failureResult,
19
+ invalidInput2 as invalidInput,
20
+ resolveGlobalOptions,
21
+ successResult
22
+ } from "./chunk-73NLPKNN.js";
23
+
24
+ // src/lib/preview/check-links.ts
25
+ import { mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync } from "fs";
26
+ import { tmpdir } from "os";
27
+ import { join, relative, sep } from "path";
28
+
29
+ // ../release-abi/src/canonical.ts
30
+ var textEncoder = new TextEncoder();
31
+ function isWellFormedUnicode(value) {
32
+ for (let index = 0; index < value.length; index += 1) {
33
+ const code = value.charCodeAt(index);
34
+ if (code >= 55296 && code <= 56319) {
35
+ const next = value.charCodeAt(index + 1);
36
+ if (!Number.isInteger(next) || next < 56320 || next > 57343) return false;
37
+ index += 1;
38
+ } else if (code >= 56320 && code <= 57343) {
39
+ return false;
40
+ }
41
+ }
42
+ return true;
43
+ }
44
+ function utf8(value) {
45
+ const encoded = textEncoder.encode(value);
46
+ const copy = new Uint8Array(encoded.byteLength);
47
+ copy.set(encoded);
48
+ return copy;
49
+ }
50
+ function lowercaseHex(bytes) {
51
+ return Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
52
+ }
53
+
54
+ // ../release-abi/src/nav-variant.ts
55
+ var NAV_VARIANT_DIRECTORY = "__gs-variants";
56
+ var NAV_VARIANT_INDEX_FILE = `${NAV_VARIANT_DIRECTORY}/index.json`;
57
+ var VARIANT_KEY_PATTERN = /^[0-9a-f]{64}$/;
58
+ function compareGroupNames(left, right) {
59
+ if (left < right) return -1;
60
+ if (left > right) return 1;
61
+ return 0;
62
+ }
63
+ function isSortedGroupList(groups) {
64
+ for (let index = 1; index < groups.length; index += 1) {
65
+ if (compareGroupNames(groups[index - 1], groups[index]) >= 0) return false;
66
+ }
67
+ return true;
68
+ }
69
+ async function variantKey(groups) {
70
+ const digest = await crypto.subtle.digest("SHA-256", utf8(JSON.stringify([...groups])));
71
+ return lowercaseHex(digest);
72
+ }
73
+ async function parseVariantIndex(text) {
74
+ let value;
75
+ try {
76
+ value = JSON.parse(text);
77
+ } catch {
78
+ return { error: "variant index is not valid JSON" };
79
+ }
80
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
81
+ return { error: "variant index must be an object" };
82
+ }
83
+ const record = value;
84
+ const keys = Object.keys(record).sort();
85
+ if (keys.length !== 3 || keys[0] !== "groups" || keys[1] !== "variants" || keys[2] !== "version") {
86
+ return { error: "variant index must contain exactly version, groups, and variants" };
87
+ }
88
+ if (record.version !== 1) return { error: "variant index version must be 1" };
89
+ const groups = groupList(record.groups);
90
+ if (typeof groups === "string") return { error: `variant index groups are invalid: ${groups}` };
91
+ if (!Array.isArray(record.variants)) return { error: "variant index variants must be an array" };
92
+ const known = new Set(groups);
93
+ const seen = /* @__PURE__ */ new Set();
94
+ const variants = [];
95
+ for (const entry of record.variants) {
96
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) {
97
+ return { error: "variant index entry must be an object" };
98
+ }
99
+ const variant = entry;
100
+ const entryKeys = Object.keys(variant).sort();
101
+ if (entryKeys.length !== 2 || entryKeys[0] !== "groups" || entryKeys[1] !== "key") {
102
+ return { error: "variant index entry must contain exactly key and groups" };
103
+ }
104
+ if (typeof variant.key !== "string" || !VARIANT_KEY_PATTERN.test(variant.key)) {
105
+ return { error: "variant key must be 64 lowercase hexadecimal characters" };
106
+ }
107
+ const entryGroups = groupList(variant.groups);
108
+ if (typeof entryGroups === "string") {
109
+ return { error: `variant ${variant.key} groups are invalid: ${entryGroups}` };
110
+ }
111
+ if (entryGroups.length === 0) {
112
+ return { error: `variant ${variant.key} must name at least one group` };
113
+ }
114
+ for (const group of entryGroups) {
115
+ if (!known.has(group)) {
116
+ return { error: `variant ${variant.key} names a group the index does not declare` };
117
+ }
118
+ }
119
+ if (await variantKey(entryGroups) !== variant.key) {
120
+ return { error: `variant ${variant.key} does not hash its own groups` };
121
+ }
122
+ if (seen.has(variant.key)) return { error: `variant ${variant.key} is listed twice` };
123
+ seen.add(variant.key);
124
+ variants.push({ key: variant.key, groups: entryGroups });
125
+ }
126
+ return { version: 1, groups, variants };
127
+ }
128
+ function resolveVariantFile(relativePath, index) {
129
+ if (relativePath === "" || relativePath.startsWith("/")) {
130
+ return { error: `dist path is invalid: ${relativePath}` };
131
+ }
132
+ if (relativePath !== NAV_VARIANT_DIRECTORY && !relativePath.startsWith(`${NAV_VARIANT_DIRECTORY}/`)) {
133
+ return { canonicalPath: relativePath };
134
+ }
135
+ const rest = relativePath.slice(`${NAV_VARIANT_DIRECTORY}/`.length);
136
+ const separator = rest.indexOf("/");
137
+ const key = separator === -1 ? "" : rest.slice(0, separator);
138
+ const canonicalPath = separator === -1 ? "" : rest.slice(separator + 1);
139
+ if (!VARIANT_KEY_PATTERN.test(key) || canonicalPath === "") {
140
+ return { error: `navigation variant path is malformed: ${relativePath}` };
141
+ }
142
+ if (canonicalPath === NAV_VARIANT_DIRECTORY || canonicalPath.startsWith(`${NAV_VARIANT_DIRECTORY}/`)) {
143
+ return { error: `navigation variant path is nested: ${relativePath}` };
144
+ }
145
+ if (index === null) {
146
+ return { error: `navigation variant index is missing for ${relativePath}` };
147
+ }
148
+ const variant = index.variants.find((entry) => entry.key === key);
149
+ if (variant === void 0) {
150
+ return { error: `navigation variant key is not in the index: ${key}` };
151
+ }
152
+ return { canonicalPath, navVariant: [...variant.groups] };
153
+ }
154
+ function groupList(value) {
155
+ if (!Array.isArray(value)) return "expected an array of group names";
156
+ const groups = [];
157
+ for (const group of value) {
158
+ if (typeof group !== "string" || group === "") return "expected non-empty group names";
159
+ if (!isWellFormedUnicode(group)) return "expected well-formed Unicode without lone surrogates";
160
+ groups.push(group);
161
+ }
162
+ if (!isSortedGroupList(groups)) return "expected sorted, unique group names";
163
+ return groups;
164
+ }
165
+
166
+ // src/lib/preview/check-links.ts
167
+ function diagnostic({ source, href }, reason) {
168
+ return { file: source, link: href, reason };
169
+ }
170
+ function leavesRoot(raw, base) {
171
+ const path = decodeURIComponent(raw.split(/[?#]/, 1)[0]).replace(/^(?:[a-z][a-z0-9+.-]*:)?\/\/[^/]*/i, "");
172
+ let depth = path.startsWith("/") ? 0 : base.pathname.split("/").slice(1, -1).length;
173
+ for (const segment of path.split("/")) {
174
+ if (segment === "..") {
175
+ if (--depth < 0) return true;
176
+ } else if (segment && segment !== ".") depth++;
177
+ }
178
+ return path.includes("\\") || path.includes("\0");
179
+ }
180
+ async function scanRenderedSite(site, policy, siteUrl) {
181
+ const misses = [];
182
+ let routes;
183
+ try {
184
+ routes = siteRoutes(site, policy);
185
+ } catch (error) {
186
+ return [diagnostic({ source: "site/", href: "" }, String(error))];
187
+ }
188
+ const origin = new URL(siteUrl).origin;
189
+ const documents = [...routes.files].filter(([, f]) => f.type === "text/html").map(([route, f]) => ({ route, file: f.file, source: f.path }));
190
+ const variantDir = join(site, "__gs-variants");
191
+ let entries;
192
+ try {
193
+ entries = readdirSync(variantDir, { recursive: true, withFileTypes: true });
194
+ } catch (error) {
195
+ if (error.code !== "ENOENT") throw error;
196
+ }
197
+ if (entries) {
198
+ const index = await parseVariantIndex(readFileSync(join(site, NAV_VARIANT_INDEX_FILE), "utf8"));
199
+ if ("error" in index) return [{ file: NAV_VARIANT_INDEX_FILE, link: "", reason: index.error }];
200
+ for (const entry of entries.filter((e) => e.isFile() && e.name.endsWith(".html"))) {
201
+ const file = join(entry.parentPath, entry.name);
202
+ const source = relative(site, file).split(sep).join("/");
203
+ const variant = resolveVariantFile(source, index);
204
+ if ("error" in variant) return [{ file: source, link: "", reason: variant.error }];
205
+ const route = releaseRoute(variant.canonicalPath);
206
+ if (!routes.files.has(route)) return [{ file: source, link: route, reason: "Missing base route for variant" }];
207
+ documents.push({ route, source, file });
208
+ }
209
+ }
210
+ function check(href, base) {
211
+ if (!href || href.startsWith("#")) return;
212
+ const visited = /* @__PURE__ */ new Set();
213
+ for (; ; ) {
214
+ let target;
215
+ try {
216
+ target = new URL(href, base);
217
+ if (target.protocol === "file:") return "Target is outside the build";
218
+ if (target.origin !== origin) return;
219
+ if (leavesRoot(href, base)) return "Target is outside the build";
220
+ } catch {
221
+ return "Invalid URL";
222
+ }
223
+ if (visited.has(target.pathname)) return "Redirect cycle";
224
+ visited.add(target.pathname);
225
+ const hit = routes.resolve(target.pathname, target.search);
226
+ if (!hit) return "No generated route, asset, or Worker handler";
227
+ if (!hit.redirect) return;
228
+ href = hit.redirect.headers.get("location");
229
+ base = target;
230
+ }
231
+ }
232
+ for (const { source, destination } of policy.redirects) {
233
+ if (isRedirectPattern(source)) continue;
234
+ const reason = check(destination, new URL(source, origin));
235
+ if (reason) misses.push(diagnostic({ source, href: destination }, reason));
236
+ }
237
+ for (const { source, route, file } of documents) {
238
+ for (const href of documentLinks(readFileSync(file, "utf8"))) {
239
+ const reason = check(href, new URL(route, origin));
240
+ if (reason) misses.push(diagnostic({ source, href }, reason));
241
+ }
242
+ }
243
+ return misses;
244
+ }
245
+ async function checkLinks(docs, cache, provide, siteUrl) {
246
+ const dir = mkdtempSync(join(tmpdir(), "saturndocs-links-"));
247
+ try {
248
+ const generation = await buildGeneration(realpathSync(docs), dir, cache, await provide({}), siteUrl, void 0, void 0, "rendered");
249
+ const diagnostics = await scanRenderedSite(generation.out, generation.policy, generation.report.site_url);
250
+ return { ...generation.report, diagnostics };
251
+ } finally {
252
+ rmSync(dir, { recursive: true, force: true });
253
+ }
254
+ }
255
+
256
+ // src/commands/broken-links.ts
257
+ function registerBrokenLinks(program, provide, cache) {
258
+ program.command("broken-links [docs-dir]").option("--site-url <url>", "Override the production site URL").action(async (dir, options, self) => {
259
+ const writer = createResultWriter({ json: resolveGlobalOptions(self).json });
260
+ const context = { command: "broken-links", siteId: null };
261
+ try {
262
+ const report = await checkLinks(dir ?? process.cwd(), cache, provide, options.siteUrl);
263
+ if (report.diagnostics.length) {
264
+ const message = report.diagnostics.map((d) => `${d.file}: ${d.link} \u2014 ${d.reason}`).join("\n");
265
+ throw invalidInput(message, { data: report });
266
+ }
267
+ process.exitCode = writer.write(successResult(context, report), { text: "Author preview has no broken internal links." });
268
+ } catch (error) {
269
+ process.exitCode = writer.write(failureResult(error, context));
270
+ }
271
+ });
272
+ }
273
+ export {
274
+ registerBrokenLinks
275
+ };
@@ -0,0 +1,139 @@
1
+ import {
2
+ cachePath
3
+ } from "./chunk-LDE53VKA.js";
4
+ import {
5
+ buildGeneration
6
+ } from "./chunk-GZWCWTWW.js";
7
+ import "./chunk-KBVOLS2Y.js";
8
+ import "./chunk-ZNLLNDCO.js";
9
+ import "./chunk-6YU3R6KT.js";
10
+ import {
11
+ createResultWriter,
12
+ failureResult,
13
+ resolveGlobalOptions,
14
+ successResult
15
+ } from "./chunk-73NLPKNN.js";
16
+
17
+ // src/lib/preview/output.ts
18
+ import { createHash, randomUUID } from "crypto";
19
+ import { lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, writeFileSync } from "fs";
20
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "path";
21
+ var marker = ".saturndocs-author-preview";
22
+ function canonical(file) {
23
+ try {
24
+ return realpathSync(file);
25
+ } catch (error) {
26
+ if (error.code !== "ENOENT") throw error;
27
+ return join(canonical(dirname(file)), basename(file));
28
+ }
29
+ }
30
+ function contains(left, right) {
31
+ const path = relative(left.toLowerCase(), right.toLowerCase());
32
+ return path === "" || !isAbsolute(path) && path !== ".." && !path.startsWith(".." + sep);
33
+ }
34
+ function identity(path, out) {
35
+ const info = lstatSync(path, { bigint: true });
36
+ return JSON.stringify({ out, dev: String(info.dev), ino: String(info.ino), birth: String(info.birthtimeNs) });
37
+ }
38
+ function owned(out, record, directory = out) {
39
+ const info = lstatSync(directory, { throwIfNoEntry: false });
40
+ if (!info) return false;
41
+ if (info.isDirectory() && lstatSync(record, { throwIfNoEntry: false })?.isFile() && readFileSync(record, "utf8") === identity(directory, out)) return true;
42
+ throw new Error(`Output is not owned by the CLI: ${out}. Choose a new directory.`);
43
+ }
44
+ function repositoryRoot(start) {
45
+ for (let dir = start; ; dir = dirname(dir)) {
46
+ if (lstatSync(join(dir, ".git"), { throwIfNoEntry: false })) return dir;
47
+ if (dirname(dir) === dir) return null;
48
+ }
49
+ }
50
+ function rejectProjectSymlinks(requested, docs) {
51
+ const repository = repositoryRoot(docs);
52
+ const roots = [docs, realpathSync(process.cwd()), ...repository ? [repository] : []];
53
+ for (let path = requested; dirname(path) !== path; path = dirname(path)) {
54
+ if (lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink() && roots.some((root) => contains(root, canonical(dirname(path))))) {
55
+ throw new Error(`Output crosses a project symlink: ${path}`);
56
+ }
57
+ }
58
+ }
59
+ async function exportBuild(docsDir, outDir, siteUrl, cacheDir, provide) {
60
+ const docs = realpathSync(resolve(docsDir));
61
+ const requested = resolve(outDir);
62
+ rejectProjectSymlinks(requested, docs);
63
+ const out = join(canonical(dirname(requested)), basename(requested));
64
+ const destinations = [requested, out, canonical(requested)];
65
+ const site = new URL(siteUrl);
66
+ if (!["https:", "http:"].includes(site.protocol) || site.username || site.password) throw new Error("Expected an HTTP(S) site URL");
67
+ const renderer = await provide({});
68
+ for (const dir of [resolve(docsDir), docs, resolve(cacheDir), canonical(resolve(cacheDir)), resolve(renderer.root), realpathSync(renderer.root)]) {
69
+ if (destinations.some((path) => contains(dir, path) || contains(path, dir))) throw new Error(`Output overlaps protected directory: ${dir}`);
70
+ }
71
+ if (contains(docs, canonical(resolve(cacheDir)))) throw new Error("Preview cache overlaps the docs directory.");
72
+ const state = await cachePath(cacheDir, ["output-ownership"]);
73
+ const record = join(state, createHash("sha256").update(out).digest("hex"));
74
+ owned(out, record);
75
+ mkdirSync(dirname(out), { recursive: true });
76
+ const controller = new AbortController();
77
+ const interrupt = () => controller.abort(new Error("Build interrupted"));
78
+ process.on("SIGTERM", interrupt);
79
+ process.on("SIGINT", interrupt);
80
+ const stage = mkdtempSync(join(dirname(out), ".saturndocs-build-"));
81
+ try {
82
+ const { report, out: siteDir } = await buildGeneration(docs, stage, cacheDir, renderer, site.href, void 0, controller.signal);
83
+ controller.signal.throwIfAborted();
84
+ writeFileSync(join(siteDir, marker), JSON.stringify({ version: 1, out }), { flag: "wx" });
85
+ const lock = out + ".saturndocs-lock";
86
+ mkdirSync(lock, { mode: 448 });
87
+ try {
88
+ const backup = join(lock, "previous");
89
+ const replace = owned(out, record);
90
+ const pending = record + "." + randomUUID();
91
+ writeFileSync(pending, identity(siteDir, out), { flag: "wx", mode: 384 });
92
+ try {
93
+ if (replace) {
94
+ renameSync(out, backup);
95
+ owned(out, record, backup);
96
+ }
97
+ renameSync(siteDir, out);
98
+ try {
99
+ renameSync(pending, record);
100
+ } catch (error) {
101
+ renameSync(out, siteDir);
102
+ throw error;
103
+ }
104
+ } catch (error) {
105
+ if (lstatSync(backup, { throwIfNoEntry: false })) renameSync(backup, out);
106
+ throw error;
107
+ } finally {
108
+ rmSync(pending, { force: true });
109
+ }
110
+ if (replace) rmSync(backup, { recursive: true });
111
+ } finally {
112
+ if (!lstatSync(join(lock, "previous"), { throwIfNoEntry: false })) rmdirSync(lock);
113
+ }
114
+ return { ...report, output_path: out };
115
+ } finally {
116
+ process.off("SIGTERM", interrupt);
117
+ process.off("SIGINT", interrupt);
118
+ rmSync(stage, { recursive: true, force: true });
119
+ }
120
+ }
121
+
122
+ // src/commands/build.ts
123
+ function registerBuild(program, provider, cache) {
124
+ program.command("build [docs-dir]").requiredOption("--out-dir <path>").option("--site-url <url>", "Site URL", "http://localhost").action(async (dir, options, self) => {
125
+ const writer = createResultWriter({ json: resolveGlobalOptions(self).json });
126
+ const context = { command: "build", siteId: null };
127
+ try {
128
+ const report = await exportBuild(dir ?? process.cwd(), options.outDir, options.siteUrl, cache, provider);
129
+ process.exitCode = writer.write(successResult(context, report), {
130
+ text: [`Built author preview at ${report.output_path}`, ...report.warnings].join("\n")
131
+ });
132
+ } catch (error) {
133
+ process.exitCode = writer.write(failureResult(error, context));
134
+ }
135
+ });
136
+ }
137
+ export {
138
+ registerBuild
139
+ };
@@ -24,7 +24,7 @@ import {
24
24
  windowsUnsupported,
25
25
  withCredentialLock,
26
26
  withPollLock
27
- } from "./chunk-4B6PUKF5.js";
27
+ } from "./chunk-TFUZHZYD.js";
28
28
  import {
29
29
  applyCommandHelp
30
30
  } from "./chunk-M2BZEDAS.js";
@@ -37,7 +37,7 @@ import {
37
37
  parseOrigin,
38
38
  resolveGlobalOptions,
39
39
  successResult
40
- } from "./chunk-EH6E45H4.js";
40
+ } from "./chunk-73NLPKNN.js";
41
41
 
42
42
  // src/commands/login.ts
43
43
  import { execFile } from "child_process";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  SITES_CREATE_METADATA,
3
3
  registerSitesCreate
4
- } from "./chunk-BRC7CU3J.js";
4
+ } from "./chunk-4Y6MLUWG.js";
5
5
  import {
6
6
  asCliError,
7
7
  clientFor
8
- } from "./chunk-4B6PUKF5.js";
8
+ } from "./chunk-TFUZHZYD.js";
9
9
  import {
10
10
  applyCommandHelp
11
11
  } from "./chunk-M2BZEDAS.js";
@@ -21,7 +21,7 @@ import {
21
21
  resolveGlobalOptions,
22
22
  resolveTarget,
23
23
  successResult
24
- } from "./chunk-EH6E45H4.js";
24
+ } from "./chunk-73NLPKNN.js";
25
25
 
26
26
  // src/commands/sites.ts
27
27
  var SITES_METADATA = Object.freeze([
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  invalidInput2 as invalidInput
3
- } from "./chunk-EH6E45H4.js";
3
+ } from "./chunk-73NLPKNN.js";
4
4
 
5
5
  // src/adapter/input.ts
6
6
  import { readFile } from "fs/promises";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  requestedSite
3
- } from "./chunk-N66SXAI5.js";
3
+ } from "./chunk-5MPSOIDR.js";
4
4
  import {
5
5
  asCliError,
6
6
  clientFor
7
- } from "./chunk-4B6PUKF5.js";
7
+ } from "./chunk-TFUZHZYD.js";
8
8
  import {
9
9
  applyCommandHelp
10
10
  } from "./chunk-M2BZEDAS.js";
@@ -20,7 +20,7 @@ import {
20
20
  resolveGlobalOptions,
21
21
  resolveTarget,
22
22
  successResult
23
- } from "./chunk-EH6E45H4.js";
23
+ } from "./chunk-73NLPKNN.js";
24
24
 
25
25
  // src/commands/pages.ts
26
26
  import { InvalidArgumentError } from "commander";
@@ -860,56 +860,6 @@ async function loadDocsConfig(filePath) {
860
860
  }
861
861
  return parseDocsConfig(parsed);
862
862
  }
863
- async function loadModelsConfig(filePath) {
864
- let raw;
865
- try {
866
- raw = await readFile(filePath, "utf8");
867
- } catch (cause) {
868
- throw new Error(`Could not read models.toml at ${filePath}: ${errorMessage(cause)}`);
869
- }
870
- return parseModelsConfigValue(raw, `models.toml at ${filePath}`);
871
- }
872
- function parseModelsConfig(toml, platformApiBase) {
873
- return parseModelsConfigValue(toml, "models.toml", platformApiBase);
874
- }
875
- function parseModelsConfigValue(toml, label, platformApiBase) {
876
- let parsed;
877
- try {
878
- parsed = parseToml(toml);
879
- } catch (cause) {
880
- throw new Error(`${label} is not valid TOML: ${errorMessage(cause)}`);
881
- }
882
- const result = modelsConfigSchema.safeParse(parsed);
883
- if (!result.success) {
884
- throw new Error(formatZodError(result.error, "models.toml"));
885
- }
886
- return applyModelsDefaults(result.data, platformApiBase);
887
- }
888
- var HOSTED_MODEL_API_BASE = "https://openrouter.ai/api/v1";
889
- var HOSTED_MODEL_KEY_ENV = "OPENROUTER_API_KEY";
890
- function applyModelsDefaults(config, platformApiBase) {
891
- const endpoint = config.endpoint ?? {};
892
- const behavior = config.behavior ?? {};
893
- return {
894
- ...config,
895
- models: {
896
- synthesis: config.models.synthesis,
897
- suggestion: config.models.suggestion ?? config.models.synthesis
898
- },
899
- endpoint: {
900
- api_base: endpoint.api_base ?? platformModelApiBase(platformApiBase),
901
- api_key_env: endpoint.api_key_env ?? HOSTED_MODEL_KEY_ENV
902
- },
903
- behavior: {
904
- cache: behavior.cache ?? true,
905
- max_iterations: behavior.max_iterations ?? 4
906
- }
907
- };
908
- }
909
- function platformModelApiBase(platformApiBase) {
910
- const trimmed = platformApiBase?.trim() ?? "";
911
- return trimmed === "" ? HOSTED_MODEL_API_BASE : trimmed;
912
- }
913
863
  function errorMessage(cause) {
914
864
  return cause instanceof Error ? cause.message : String(cause);
915
865
  }
@@ -1004,13 +954,20 @@ function splitRef(ref) {
1004
954
  function isHttpRef(ref) {
1005
955
  return /^https?:\/\//i.test(ref);
1006
956
  }
957
+ var WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/;
958
+ function toSlashes(path) {
959
+ return WINDOWS_DRIVE.test(path) ? path.replace(/\\/g, "/") : path;
960
+ }
1007
961
  function isAbsolutePath(path) {
1008
- return path.startsWith("/");
962
+ return path.startsWith("/") || WINDOWS_DRIVE.test(path);
1009
963
  }
1010
- function normalizePath(path) {
1011
- const absolute = isAbsolutePath(path);
964
+ function normalizePath(input) {
965
+ const path = toSlashes(input);
966
+ const drive = WINDOWS_DRIVE.test(path) ? path.slice(0, 2) : "";
967
+ const rest = path.slice(drive.length);
968
+ const absolute = drive !== "" || rest.startsWith("/");
1012
969
  const parts = [];
1013
- for (const part of path.split("/")) {
970
+ for (const part of rest.split("/")) {
1014
971
  if (part === "" || part === ".") continue;
1015
972
  if (part === "..") {
1016
973
  if (parts.length > 0 && parts[parts.length - 1] !== "..") {
@@ -1023,26 +980,28 @@ function normalizePath(path) {
1023
980
  parts.push(part);
1024
981
  }
1025
982
  const normalized = parts.join("/");
1026
- if (absolute) return `/${normalized}`;
983
+ if (absolute) return `${drive}/${normalized}`;
1027
984
  return normalized || ".";
1028
985
  }
1029
986
  function resolvePath(...paths) {
1030
987
  let out = "";
1031
- for (const path of paths) {
1032
- if (!path) continue;
988
+ for (const raw of paths) {
989
+ if (!raw) continue;
990
+ const path = toSlashes(raw);
1033
991
  if (isAbsolutePath(path)) {
1034
992
  out = path;
1035
993
  } else {
1036
994
  out = out ? `${out}/${path}` : path;
1037
995
  }
1038
996
  }
1039
- if (!isAbsolutePath(out)) out = `${process.cwd()}/${out}`;
997
+ if (!isAbsolutePath(out)) out = `${toSlashes(process.cwd())}/${out}`;
1040
998
  return normalizePath(out);
1041
999
  }
1042
1000
  function dirnamePath(path) {
1043
1001
  const normalized = normalizePath(path);
1002
+ const root = WINDOWS_DRIVE.test(normalized) ? normalized.slice(0, 3) : "/";
1044
1003
  const index = normalized.lastIndexOf("/");
1045
- if (index <= 0) return isAbsolutePath(normalized) ? "/" : ".";
1004
+ if (index < root.length) return isAbsolutePath(normalized) ? root : ".";
1046
1005
  return normalized.slice(0, index);
1047
1006
  }
1048
1007
  function relativePath(from, to) {
@@ -1515,10 +1474,14 @@ async function parseOpenApiFile(filePath, options = {}) {
1515
1474
 
1516
1475
  export {
1517
1476
  BuildRuleError,
1477
+ NAV_VARIANT_DIRECTORY,
1478
+ NAV_VARIANT_SOURCE_DIRECTORY,
1518
1479
  knownGroups,
1519
1480
  assertGroupCapacity,
1520
1481
  reservedPageClash,
1521
1482
  normalizedRedirectPath,
1483
+ isRedirectPattern,
1484
+ compileRedirects,
1522
1485
  resolveRootRedirectDestination,
1523
1486
  openApiPublicationCollision,
1524
1487
  ungatedOpenApiSpecPaths,
@@ -1528,8 +1491,6 @@ export {
1528
1491
  navigationIconRefs,
1529
1492
  navigationGroups,
1530
1493
  loadDocsConfig,
1531
- loadModelsConfig,
1532
- parseModelsConfig,
1533
1494
  configuredAssetHref,
1534
1495
  assetPathname,
1535
1496
  parseOpenApi,