ssqch 0.7.1 → 0.8.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.
Files changed (153) hide show
  1. package/README.md +6 -4
  2. package/bin/ssqch.js +14 -48
  3. package/bundled/README.md +1247 -0
  4. package/bundled/completions/bash +840 -0
  5. package/bundled/completions/elvish +286 -0
  6. package/bundled/completions/fish +182 -0
  7. package/bundled/completions/powershell +318 -0
  8. package/bundled/completions/zsh +510 -0
  9. package/bundled/ssqch.d.ts +532 -0
  10. package/bundled/starter/engines/index.edge +11 -0
  11. package/bundled/starter/engines/index.ejs +11 -0
  12. package/bundled/starter/engines/index.hbs +11 -0
  13. package/bundled/starter/engines/index.liquid +11 -0
  14. package/bundled/starter/engines/layout.edge +35 -0
  15. package/bundled/starter/engines/layout.ejs +35 -0
  16. package/bundled/starter/engines/layout.hbs +35 -0
  17. package/bundled/starter/engines/layout.liquid +35 -0
  18. package/bundled/starter/gitignore +3 -0
  19. package/bundled/starter/jsconfig.json +11 -0
  20. package/bundled/starter/src/404.md +8 -0
  21. package/bundled/starter/src/_blueprints/posts.md +5 -0
  22. package/bundled/starter/src/_data/site.json +4 -0
  23. package/bundled/starter/src/_includes/layout.jinja +35 -0
  24. package/bundled/starter/src/index.jinja +11 -0
  25. package/bundled/starter/src/posts/i-know-what-i-saw.md +11 -0
  26. package/bundled/starter/src/posts/posts.json +4 -0
  27. package/bundled/starter/src/posts/raiders-of-the-lost-path.md +27 -0
  28. package/bundled/starter/src/posts/the-cache-of-the-wild.md +26 -0
  29. package/bundled/starter/src/posts/the-stump-has-moved.md +15 -0
  30. package/bundled/starter/src/posts/upon-further-review-a-stump.md +18 -0
  31. package/bundled/starter/ssqch.config.js +29 -0
  32. package/bundled/starter-docs/engines/edge/base.edge +41 -0
  33. package/bundled/starter-docs/engines/edge/containers/details.edge +5 -0
  34. package/bundled/starter-docs/engines/edge/containers/tab.edge +4 -0
  35. package/bundled/starter-docs/engines/edge/containers/tabs.edge +5 -0
  36. package/bundled/starter-docs/engines/edge/doc.edge +59 -0
  37. package/bundled/starter-docs/engines/edge/hooks/heading.edge +2 -0
  38. package/bundled/starter-docs/engines/ejs/base.ejs +41 -0
  39. package/bundled/starter-docs/engines/ejs/containers/details.ejs +5 -0
  40. package/bundled/starter-docs/engines/ejs/containers/tab.ejs +4 -0
  41. package/bundled/starter-docs/engines/ejs/containers/tabs.ejs +5 -0
  42. package/bundled/starter-docs/engines/ejs/doc.ejs +59 -0
  43. package/bundled/starter-docs/engines/ejs/hooks/heading.ejs +2 -0
  44. package/bundled/starter-docs/engines/hbs/base.hbs +41 -0
  45. package/bundled/starter-docs/engines/hbs/containers/details.hbs +5 -0
  46. package/bundled/starter-docs/engines/hbs/containers/tab.hbs +4 -0
  47. package/bundled/starter-docs/engines/hbs/containers/tabs.hbs +5 -0
  48. package/bundled/starter-docs/engines/hbs/doc.hbs +58 -0
  49. package/bundled/starter-docs/engines/hbs/hooks/heading.hbs +2 -0
  50. package/bundled/starter-docs/engines/liquid/base.liquid +41 -0
  51. package/bundled/starter-docs/engines/liquid/containers/details.liquid +5 -0
  52. package/bundled/starter-docs/engines/liquid/containers/tab.liquid +4 -0
  53. package/bundled/starter-docs/engines/liquid/containers/tabs.liquid +5 -0
  54. package/bundled/starter-docs/engines/liquid/doc.liquid +60 -0
  55. package/bundled/starter-docs/engines/liquid/hooks/heading.liquid +2 -0
  56. package/bundled/starter-docs/gitignore +4 -0
  57. package/bundled/starter-docs/src/404.md +12 -0
  58. package/bundled/starter-docs/src/_blueprints/docs.md +5 -0
  59. package/bundled/starter-docs/src/_data/nav.yml +10 -0
  60. package/bundled/starter-docs/src/_data/site.json +5 -0
  61. package/bundled/starter-docs/src/_includes/base.jinja +41 -0
  62. package/bundled/starter-docs/src/_includes/containers/details.jinja +5 -0
  63. package/bundled/starter-docs/src/_includes/containers/tab.jinja +4 -0
  64. package/bundled/starter-docs/src/_includes/containers/tabs.jinja +5 -0
  65. package/bundled/starter-docs/src/_includes/doc.jinja +59 -0
  66. package/bundled/starter-docs/src/_includes/hooks/heading.jinja +2 -0
  67. package/bundled/starter-docs/src/assets/docs.css +257 -0
  68. package/bundled/starter-docs/src/assets/docs.js +67 -0
  69. package/bundled/starter-docs/src/docs/docs.json +1 -0
  70. package/bundled/starter-docs/src/docs/guides/deploying.md +77 -0
  71. package/bundled/starter-docs/src/docs/guides/writing.md +65 -0
  72. package/bundled/starter-docs/src/docs/index.md +29 -0
  73. package/bundled/starter-docs/src/docs/install.md +42 -0
  74. package/bundled/starter-docs/src/index.md +13 -0
  75. package/bundled/starter-docs/ssqch.config.js +40 -0
  76. package/bundled/trailheads/from-component-frameworks.md +116 -0
  77. package/bundled/trailheads/from-docusaurus.md +55 -0
  78. package/bundled/trailheads/from-eleventy.md +140 -0
  79. package/bundled/trailheads/from-hexo.md +92 -0
  80. package/bundled/trailheads/from-mkdocs.md +45 -0
  81. package/bundled/trailheads/from-zola.md +71 -0
  82. package/lib/assets.js +235 -3
  83. package/lib/chunk-37KSIVNY.js +29 -0
  84. package/lib/chunk-3GYLOC6Y.js +1017 -0
  85. package/lib/chunk-3NYSSA2C.js +22 -0
  86. package/lib/chunk-3PHCFZEU.js +209 -0
  87. package/lib/chunk-4Q6WMTER.js +32 -0
  88. package/lib/chunk-6XYSFG6V.js +4423 -0
  89. package/lib/chunk-6XYSFG6V.js.LEGAL.txt +41 -0
  90. package/lib/chunk-AD3HAW3W.js +10 -0
  91. package/lib/chunk-AMBFWPZ4.js +118 -0
  92. package/lib/chunk-BOBPVAX2.js +37088 -0
  93. package/lib/chunk-BOBPVAX2.js.LEGAL.txt +27 -0
  94. package/lib/chunk-BRK4MXXO.js +565 -0
  95. package/lib/chunk-C35KIPAR.js +247 -0
  96. package/lib/chunk-CDEPYU7W.js +25 -0
  97. package/lib/chunk-CMUWRPSQ.js +113 -0
  98. package/lib/chunk-DDV6JEC2.js +46 -0
  99. package/lib/chunk-DHHQKW4F.js +71 -0
  100. package/lib/chunk-EIT4ZDT4.js +1485 -0
  101. package/lib/chunk-EZZUUPI4.js +20 -0
  102. package/lib/chunk-F65YUXZ7.js +334 -0
  103. package/lib/chunk-FVZ5JBRI.js +115 -0
  104. package/lib/chunk-FYGE634X.js +44 -0
  105. package/lib/chunk-GOE4ZSAB.js +75 -0
  106. package/lib/chunk-GSKVRAHF.js +44 -0
  107. package/lib/chunk-HR2RU2LY.js +999 -0
  108. package/lib/chunk-HXCLCXRT.js +20 -0
  109. package/lib/chunk-I3PS26CI.js +48 -0
  110. package/lib/chunk-IAFM5ITE.js +11 -0
  111. package/lib/chunk-IRHRK7XB.js +54 -0
  112. package/lib/chunk-JRT7TQQP.js +57 -0
  113. package/lib/chunk-JSPSMIJ2.js +217 -0
  114. package/lib/chunk-KBGE5MCY.js +175 -0
  115. package/lib/chunk-N5QTGQ5N.js +207 -0
  116. package/lib/chunk-NKXEPHRZ.js +136 -0
  117. package/lib/chunk-NUKCUDC4.js +146 -0
  118. package/lib/chunk-RI2L3VGO.js +376 -0
  119. package/lib/chunk-TDGBQNGW.js +251 -0
  120. package/lib/chunk-TN6EEDX2.js +3935 -0
  121. package/lib/chunk-TWCVHOKO.js +1229 -0
  122. package/lib/chunk-UGEGUUBT.js +29 -0
  123. package/lib/chunk-UU43WIZG.js +29 -0
  124. package/lib/chunk-VJWQSYEG.js +119 -0
  125. package/lib/chunk-VVPZ5PDP.js +160 -0
  126. package/lib/chunk-WMOVCQO6.js +1287 -0
  127. package/lib/chunk-WP3RPVUM.js +211 -0
  128. package/lib/chunk-YSH2NMIE.js +502 -0
  129. package/lib/cli.js +540 -0
  130. package/lib/elements.js +180 -3
  131. package/lib/image.js +27 -3
  132. package/lib/links.js +464 -3
  133. package/lib/minify.js +69 -3
  134. package/lib/redirects.js +152 -3
  135. package/lib/rss.js +139 -3
  136. package/lib/sass.js +221 -3
  137. package/lib/sitemap.js +88 -3
  138. package/lib/ssqch.js +28 -0
  139. package/package.json +83 -80
  140. package/src/serve/live.js +174 -0
  141. package/src/serve/not-found.html +31 -0
  142. package/types/globals.d.ts +3 -2
  143. package/types/image.d.ts +7 -3
  144. package/types/index.d.ts +18 -5
  145. package/types/links.d.ts +1 -1
  146. package/types/minify.d.ts +1 -1
  147. package/types/rss.d.ts +1 -1
  148. package/types/sass.d.ts +1 -1
  149. package/wasm/markdown.wasm +0 -0
  150. package/wasm/minify.wasm +0 -0
  151. package/wasm/sass.wasm +0 -0
  152. package/lib/index.js +0 -3
  153. package/platforms.json +0 -6
@@ -0,0 +1,20 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ bytes,
5
+ count,
6
+ duration,
7
+ fixed,
8
+ summary
9
+ } from "./chunk-NKXEPHRZ.js";
10
+ import "./chunk-DDV6JEC2.js";
11
+ import "./chunk-UU43WIZG.js";
12
+ import "./chunk-VJWQSYEG.js";
13
+ import "./chunk-I3PS26CI.js";
14
+ export {
15
+ bytes,
16
+ count,
17
+ duration,
18
+ fixed,
19
+ summary
20
+ };
@@ -0,0 +1,48 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __commonJS = (cb, mod) => function __require2() {
16
+ try {
17
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
+ } catch (e) {
19
+ throw mod = 0, e;
20
+ }
21
+ };
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
+ // If the importer is in node compatibility mode or this is not an ESM
36
+ // file that has been converted to a CommonJS file using a Babel-
37
+ // compatible transform (i.e. "__esModule" has not been set), then set
38
+ // "default" to the CommonJS "module.exports" for node compatibility.
39
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
+ mod
41
+ ));
42
+
43
+ export {
44
+ __require,
45
+ __commonJS,
46
+ __export,
47
+ __toESM
48
+ };
@@ -0,0 +1,11 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ RegexError,
5
+ rustRegExp
6
+ } from "./chunk-3GYLOC6Y.js";
7
+ import "./chunk-I3PS26CI.js";
8
+ export {
9
+ RegexError,
10
+ rustRegExp
11
+ };
@@ -0,0 +1,54 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ closest
5
+ } from "./chunk-FVZ5JBRI.js";
6
+ import {
7
+ quoted
8
+ } from "./chunk-CMUWRPSQ.js";
9
+ import {
10
+ bail
11
+ } from "./chunk-6XYSFG6V.js";
12
+
13
+ // src/budgets.ts
14
+ var BUDGETS = [
15
+ ["pages", "Pages"],
16
+ ["images", "Images"],
17
+ ["css", "CSS"],
18
+ ["javascript", "JavaScript"],
19
+ ["fonts", "Fonts"],
20
+ ["media", "Media"],
21
+ ["documents", "Documents"],
22
+ ["data", "Data and feeds"],
23
+ ["other", "Other"],
24
+ ["total", ""]
25
+ ];
26
+ function parseSize(text) {
27
+ const trimmed = text.trim();
28
+ const split = trimmed.search(/[A-Za-z]/);
29
+ const digits = (split === -1 ? trimmed : trimmed.slice(0, split)).trim();
30
+ if (!/^[+-]?(\d+\.?\d*|\.\d+)$/.test(digits) || !(Number(digits) >= 0)) return void 0;
31
+ const unit = { "": 1, B: 1, KB: 1e3, K: 1e3, MB: 1e6, M: 1e6, GB: 1e9, G: 1e9 }[(split === -1 ? "" : trimmed.slice(split)).trim().toUpperCase()];
32
+ if (unit === void 0) return void 0;
33
+ return Math.round(Number(digits) * unit);
34
+ }
35
+ function budget(name, given) {
36
+ const size = typeof given === "bigint" ? Number(given) : given;
37
+ const names = BUDGETS.map(([key]) => key);
38
+ if (!names.includes(name)) {
39
+ const near = closest(name, names);
40
+ bail(`budgets.${name} isn't a kind of file${near ? ` (did you mean \`${near}\`?)` : ""} (use ${names.join(", ")})`);
41
+ }
42
+ if (typeof size === "number" && size >= 0) return [name, Math.trunc(size)];
43
+ if (typeof size === "string") {
44
+ const bytes = parseSize(size);
45
+ if (bytes === void 0) bail(`budgets.${name}: ${quoted(size)} isn't a size (write it like "150 KB" or "1.5 MB")`);
46
+ return [name, bytes];
47
+ }
48
+ return bail(`budgets.${name} must be a size like "150 KB", not ${typeof size}`);
49
+ }
50
+
51
+ export {
52
+ BUDGETS,
53
+ budget
54
+ };
@@ -0,0 +1,57 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ closest
5
+ } from "./chunk-FVZ5JBRI.js";
6
+ import {
7
+ bail
8
+ } from "./chunk-6XYSFG6V.js";
9
+
10
+ // src/modules/options.ts
11
+ var Options = class {
12
+ map;
13
+ constructor(value, known) {
14
+ if (typeof value !== "object" || value === null || Array.isArray(value)) bail("options must be an object");
15
+ const map = Object.fromEntries(Object.entries(value).filter(([, v]) => v !== void 0));
16
+ const key = Object.keys(map).find((k) => !known.includes(k));
17
+ if (key !== void 0) {
18
+ if (known.length === 0) bail(`this plugin takes no options (got "${key}")`);
19
+ const meant = closest(key, known);
20
+ bail(`unknown option "${key}"${meant ? ` (did you mean "${meant}"?)` : ""} (options: ${known.join(", ")})`);
21
+ }
22
+ this.map = map;
23
+ }
24
+ /** An option's value, or `undefined` when it's missing or `null`. */
25
+ get(key) {
26
+ const v = this.map[key];
27
+ return v === null ? void 0 : v;
28
+ }
29
+ string(key) {
30
+ const v = this.get(key);
31
+ if (v === void 0) return void 0;
32
+ if (typeof v !== "string") bail(`${key} must be a string`);
33
+ return v;
34
+ }
35
+ number(key) {
36
+ const v = this.get(key);
37
+ if (v === void 0) return void 0;
38
+ if (typeof v !== "number" || !Number.isFinite(v)) bail(`${key} must be a number`);
39
+ return v;
40
+ }
41
+ bool(key) {
42
+ const v = this.get(key);
43
+ if (v === void 0) return void 0;
44
+ if (typeof v !== "boolean") bail(`${key} must be true or false`);
45
+ return v;
46
+ }
47
+ list(key) {
48
+ const v = this.get(key);
49
+ if (v === void 0) return void 0;
50
+ if (!Array.isArray(v) || v.some((i) => typeof i !== "string")) bail(`${key} must be an array of strings`);
51
+ return v;
52
+ }
53
+ };
54
+
55
+ export {
56
+ Options
57
+ };
@@ -0,0 +1,217 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ inspectPages
5
+ } from "./chunk-BOBPVAX2.js";
6
+ import "./chunk-4Q6WMTER.js";
7
+ import "./chunk-RI2L3VGO.js";
8
+ import "./chunk-3PHCFZEU.js";
9
+ import "./chunk-TN6EEDX2.js";
10
+ import "./chunk-IRHRK7XB.js";
11
+ import "./chunk-NKXEPHRZ.js";
12
+ import "./chunk-AD3HAW3W.js";
13
+ import "./chunk-DDV6JEC2.js";
14
+ import "./chunk-EIT4ZDT4.js";
15
+ import "./chunk-FVZ5JBRI.js";
16
+ import "./chunk-TDGBQNGW.js";
17
+ import "./chunk-UU43WIZG.js";
18
+ import "./chunk-C35KIPAR.js";
19
+ import {
20
+ charCount,
21
+ firstChars,
22
+ jsString,
23
+ padEnd,
24
+ prettyJson,
25
+ quoted,
26
+ toJsonValue
27
+ } from "./chunk-CMUWRPSQ.js";
28
+ import {
29
+ bail,
30
+ getPath
31
+ } from "./chunk-6XYSFG6V.js";
32
+ import {
33
+ comparePaths,
34
+ compareText,
35
+ realPath,
36
+ shown
37
+ } from "./chunk-VJWQSYEG.js";
38
+ import "./chunk-I3PS26CI.js";
39
+
40
+ // src/inspect.ts
41
+ import fs from "node:fs";
42
+ import path from "node:path";
43
+ var has = (data, key) => data !== null && typeof data === "object" && Object.prototype.hasOwnProperty.call(data, key);
44
+ var nullish = (v) => v === void 0 || v === null;
45
+ function globalOrigin(config, dirs, key) {
46
+ if (key === "ssqch") return "built in";
47
+ if (config.globalData.some((d) => d.name === key)) return "the config's `data`";
48
+ for (const dir of [dirs.data, ...config.themes.map((theme) => path.join(theme, "_data"))]) {
49
+ let names;
50
+ try {
51
+ names = fs.readdirSync(dir);
52
+ } catch {
53
+ continue;
54
+ }
55
+ const files = names.map((name) => path.join(dir, name)).sort(comparePaths);
56
+ const found = files.find((file) => {
57
+ const name = path.basename(file);
58
+ return name === key || name.slice(0, name.length - path.extname(name).length) === key;
59
+ });
60
+ if (found !== void 0) return shown(dirs.root, found);
61
+ }
62
+ return "global data";
63
+ }
64
+ function fieldsOf(config, dirs, global, page) {
65
+ const computed = page.data.computed !== null && typeof page.data.computed === "object" && !Array.isArray(page.data.computed) ? page.data.computed : {};
66
+ const pagination = page.data.pagination;
67
+ const alias = pagination === void 0 ? "" : jsString(nullish(pagination) ? void 0 : pagination.alias);
68
+ const out = [];
69
+ for (const [name, value] of Object.entries(page.data)) {
70
+ let setBy = [];
71
+ if (has(global, name)) setBy.push({ from: globalOrigin(config, dirs, name), value: global[name] });
72
+ for (const [from, layer] of page.layers) {
73
+ if (name === "layout" && from.startsWith("layout ")) continue;
74
+ if (has(layer, name)) setBy.push({ from, value: layer[name] });
75
+ }
76
+ if (name === "page") setBy = [{ from: "built in", value }];
77
+ else if (has(computed, name)) setBy.push({ from: "computed", value });
78
+ else if (name === alias) setBy.push({ from: "pagination (its `alias`)", value });
79
+ else if (name === "pagination") setBy.push({ from: "pagination (this page's items and links)", value });
80
+ out.push({ name, value, from: setBy.length ? setBy[setBy.length - 1].from : "the build", setBy });
81
+ }
82
+ return out;
83
+ }
84
+ async function inspect(config, target) {
85
+ const { dirs, global, pages } = await inspectPages(config);
86
+ const trim = (u) => {
87
+ const rest = u.endsWith("index.html") ? u.slice(0, -10) : void 0;
88
+ return (rest !== void 0 && rest.endsWith("/") ? rest : u).replace(/\/+$/, "");
89
+ };
90
+ const exact = pages.filter((p) => p.url === target);
91
+ const byUrl = exact.length ? exact : pages.filter((p) => p.url !== null && trim(p.url) === trim(target));
92
+ const wanted = [path.resolve(dirs.root, target), path.resolve(dirs.input, target)].map(realPath);
93
+ const names = new Set(wanted.map((w) => path.basename(w)));
94
+ const byFile = pages.filter((p) => names.has(path.basename(p.input)) && wanted.includes(realPath(p.input)));
95
+ let page;
96
+ if (target.startsWith("/") && byUrl.length) page = byUrl[0];
97
+ else if (byFile.length === 1) page = byFile[0];
98
+ else if (byFile.length === 0) {
99
+ const parts = target.replace(/\/+$/, "").split("/");
100
+ const last = asciiLower(parts[parts.length - 1].replace(/(\.md)+$/, ""));
101
+ const near = pages.flatMap((p) => p.url !== null && last !== "" && asciiLower(p.url).includes(last) ? [p.url] : []).slice(0, 5).sort(compareText);
102
+ bail(`no page at ${quoted(target)} (give a URL like /about/, or a template's path; the site has ${pages.length} pages).${near.length ? ` Close: ${near.join(", ")}` : ""}`);
103
+ } else {
104
+ const urls = byFile.flatMap((p) => p.url === null ? [] : [p.url]).slice(0, 8);
105
+ bail(`${target} makes ${byFile.length} pages; give the URL of one: ${urls.join(", ")}${byFile.length > 8 ? ", ..." : ""}`);
106
+ }
107
+ const setIn = (key) => [...page.layers].reverse().find(([, layer]) => has(layer, key) && !nullish(layer[key]))?.[0];
108
+ const computedDate = has(page.data, "computed") && !nullish(getPath(page.data.computed, "date"));
109
+ const dateFrom = computedDate ? "computed" : setIn("date") ?? (page.dateFromName ? "the file's name" : "the file's modification time");
110
+ const collections = [];
111
+ if (page.inCollections) {
112
+ collections.push("all");
113
+ if (Array.isArray(page.data.tags)) collections.push(...page.data.tags.map(jsString));
114
+ }
115
+ return {
116
+ url: page.url,
117
+ inputPath: shown(dirs.root, page.input),
118
+ outputPath: page.output === null ? null : shown(dirs.root, page.output),
119
+ engines: page.engines,
120
+ layouts: page.layouts,
121
+ date: page.date.toISOString().replace(/\.\d{3}Z$/, "Z"),
122
+ dateFrom,
123
+ collections,
124
+ fields: fieldsOf(config, dirs, global, page)
125
+ };
126
+ }
127
+ var asciiLower = (text) => text.replace(/[A-Z]/g, (c) => c.toLowerCase());
128
+ function brief(value) {
129
+ if (typeof value === "string") return `${quoted(firstChars(value, 48))}${charCount(value) > 48 ? "\u2026" : ""}`;
130
+ if (Array.isArray(value)) return `[${value.length} item${value.length === 1 ? "" : "s"}]`;
131
+ if (typeof value === "function") return "a function";
132
+ if (value === void 0) return "undefined";
133
+ if (value !== null && typeof value === "object" && !(value instanceof Date)) {
134
+ const all = Object.keys(value);
135
+ const keys = [];
136
+ for (const key of all.slice(0, 4)) {
137
+ if (keys.reduce((sum, k) => sum + charCount(k) + 2, 0) + charCount(key) > 44) break;
138
+ keys.push(key);
139
+ }
140
+ if (!keys.length) return `{${all.length} key${all.length === 1 ? "" : "s"}}`;
141
+ return `{${keys.join(", ")}${all.length > keys.length ? ", \u2026" : ""}}`;
142
+ }
143
+ return jsString(value);
144
+ }
145
+ function valueAt(value, key) {
146
+ const index = /^\+?\d+$/.test(key) ? Number(key) : void 0;
147
+ if (Array.isArray(value)) return key === "length" ? value.length : index === void 0 ? void 0 : value[index];
148
+ if (typeof value === "string") return key === "length" ? value.length : index === void 0 ? void 0 : [...value][index];
149
+ if (value instanceof Date || typeof value === "function") return void 0;
150
+ return has(value, key) ? value[key] : void 0;
151
+ }
152
+ function field(inspection, dotted) {
153
+ const at = dotted.indexOf(".");
154
+ const [top, rest] = at === -1 ? [dotted, ""] : [dotted.slice(0, at), dotted.slice(at + 1)];
155
+ const found = inspection.fields.find((f) => f.name === top);
156
+ if (!found || rest === "") return found;
157
+ const pathIn = (v) => rest.split(".").reduce(valueAt, v);
158
+ const setBy = found.setBy.filter((s) => !nullish(pathIn(s.value))).map((s) => ({ from: s.from, value: pathIn(s.value) }));
159
+ return { name: dotted, value: pathIn(found.value), from: setBy.length ? setBy[setBy.length - 1].from : found.from, setBy };
160
+ }
161
+ function inspectionText(inspection) {
162
+ let out = `${inspection.url ?? "(no URL: permalink is false)"}
163
+ `;
164
+ const row = (label, value) => {
165
+ out += ` ${padEnd(label, 12)}${value}
166
+ `;
167
+ };
168
+ row("From", `${inspection.inputPath} (${inspection.engines.length ? inspection.engines.join(", ") : "as it is"})`);
169
+ if (inspection.outputPath !== null) row("Writes", inspection.outputPath);
170
+ if (inspection.layouts.length) row("Layouts", inspection.layouts.join(" > "));
171
+ row("Date", `${inspection.date} (from ${inspection.dateFrom})`);
172
+ row("Collections", inspection.collections.length ? inspection.collections.join(", ") : "none");
173
+ out += "\n Data (name, value, and the level of the cascade that set it)\n";
174
+ const width = Math.min(24, Math.max(0, ...inspection.fields.map((f) => charCount(f.name))));
175
+ for (const f of inspection.fields) {
176
+ const overrides = f.setBy.length > 1 ? ` (over ${f.setBy.slice(0, -1).map((s) => s.from).join(", ")})` : "";
177
+ out += ` ${padEnd(f.name, width)} ${padEnd(brief(f.value), 52)} ${f.from}${overrides}
178
+ `;
179
+ }
180
+ return out;
181
+ }
182
+ var pretty = (v) => prettyJson(toJsonValue(v));
183
+ function fieldText(f) {
184
+ let out = `${f.name} = ${pretty(f.value)}
185
+ `;
186
+ if (!f.setBy.length) return `${out} Nothing in the cascade sets it.
187
+ `;
188
+ out += "\nSet by (the last one wins):\n";
189
+ f.setBy.forEach((set, i) => {
190
+ out += ` ${i + 1 === f.setBy.length ? ">" : " "} ${padEnd(set.from, 40)} ${brief(set.value)}
191
+ `;
192
+ });
193
+ return out;
194
+ }
195
+ var setByJson = (f) => f.setBy.map((s) => ({ from: s.from, value: toJsonValue(s.value) }));
196
+ function inspectionJson(inspection, one) {
197
+ const out = {
198
+ schemaVersion: 1,
199
+ url: inspection.url,
200
+ inputPath: inspection.inputPath,
201
+ outputPath: inspection.outputPath,
202
+ engines: inspection.engines,
203
+ layouts: inspection.layouts,
204
+ date: { value: inspection.date, from: inspection.dateFrom },
205
+ collections: inspection.collections
206
+ };
207
+ if (one) out.field = { name: one.name, value: toJsonValue(one.value), from: one.from, setBy: setByJson(one) };
208
+ else out.data = Object.fromEntries(inspection.fields.map((f) => [f.name, { value: toJsonValue(f.value), from: f.from, setBy: setByJson(f) }]));
209
+ return out;
210
+ }
211
+ export {
212
+ field,
213
+ fieldText,
214
+ inspect,
215
+ inspectionJson,
216
+ inspectionText
217
+ };
@@ -0,0 +1,175 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ red
5
+ } from "./chunk-6XYSFG6V.js";
6
+
7
+ // src/serve/builder.ts
8
+ import { fork } from "node:child_process";
9
+ import crypto from "node:crypto";
10
+ import fs from "node:fs";
11
+ var BUILDER = "__serve-builder";
12
+ function fileHash(file) {
13
+ try {
14
+ return crypto.hash("sha1", fs.readFileSync(file), "base64");
15
+ } catch {
16
+ return "-";
17
+ }
18
+ }
19
+ var builders = /* @__PURE__ */ new Set();
20
+ var stopping = false;
21
+ function stopBuilders() {
22
+ stopping = true;
23
+ for (const builder of [...builders]) builder.stop();
24
+ }
25
+ var never = () => new Promise(() => {
26
+ });
27
+ var Builder = class _Builder {
28
+ site;
29
+ /** The configuration's files, as of the last build. */
30
+ files = /* @__PURE__ */ new Set();
31
+ /** What the plugins read for the last build. */
32
+ read = /* @__PURE__ */ new Set();
33
+ /** Other generators' words noted so far. */
34
+ said = [];
35
+ args;
36
+ child;
37
+ waiting;
38
+ /** What each of the configuration's files held when it loaded (`State.loadedAs`). */
39
+ loadedAs = {};
40
+ /** A process that's starting in place of one that ended, until it has loaded (or hasn't). */
41
+ starting;
42
+ /** What the site's code threw after a build had reported, ending its process: the next build's error. */
43
+ crashed;
44
+ constructor(args) {
45
+ this.args = args;
46
+ }
47
+ /**
48
+ * Start a process that loads the configuration, with the command line's own arguments.
49
+ * Nothing when it doesn't load: the process has printed why.
50
+ */
51
+ static async start(args, start) {
52
+ const builder = new _Builder(args);
53
+ builder.said = start.said;
54
+ return await builder.spawn(start) ? builder : void 0;
55
+ }
56
+ /** Whether a process with this configuration is there to build, or starting. */
57
+ get alive() {
58
+ return this.child !== void 0 || this.starting !== void 0;
59
+ }
60
+ async spawn(start) {
61
+ const child = fork(process.argv[1], [BUILDER, JSON.stringify(start), ...this.args], { stdio: ["inherit", "inherit", "inherit", "ipc"], execArgv: process.execArgv });
62
+ this.child = child;
63
+ builders.add(this);
64
+ const current = () => this.child === child;
65
+ const lost = () => {
66
+ this.child = void 0;
67
+ builders.delete(this);
68
+ };
69
+ const replace = () => {
70
+ if (!stopping && this.site !== void 0) this.replace();
71
+ };
72
+ child.on("message", (message2) => {
73
+ if (!current()) return;
74
+ if (message2.type !== "crashed") return this.waiting?.(message2);
75
+ this.crashed = message2.error;
76
+ lost();
77
+ this.waiting?.(message2);
78
+ replace();
79
+ });
80
+ child.once("exit", () => {
81
+ if (!current()) return;
82
+ lost();
83
+ this.waiting?.(void 0);
84
+ replace();
85
+ });
86
+ child.once("error", () => {
87
+ if (!current()) return;
88
+ lost();
89
+ this.waiting?.(void 0);
90
+ });
91
+ const message = await this.next();
92
+ if (message?.type !== "loaded") {
93
+ this.stop();
94
+ return false;
95
+ }
96
+ this.site = message.site;
97
+ this.note(message);
98
+ return true;
99
+ }
100
+ /**
101
+ * Start a process in place of one that ended, when it would load the same configuration: the
102
+ * one that loaded last, whose files hold what they held then. Otherwise (they've changed
103
+ * since), the server reads them again for that change, and this has nothing to build with.
104
+ */
105
+ replace() {
106
+ if (this.starting || !Object.entries(this.loadedAs).every(([file, hash]) => fileHash(file) === hash)) return;
107
+ const starting = this.spawn({ reload: true, fallback: false, said: this.said });
108
+ this.starting = starting;
109
+ void starting.finally(() => {
110
+ if (this.starting === starting) this.starting = void 0;
111
+ });
112
+ }
113
+ next() {
114
+ return new Promise((resolve) => {
115
+ this.waiting = (message) => {
116
+ this.waiting = void 0;
117
+ resolve(message);
118
+ };
119
+ });
120
+ }
121
+ note(state) {
122
+ this.files = new Set(state.files);
123
+ this.loadedAs = state.loadedAs;
124
+ this.read = new Set(state.read);
125
+ this.said = state.said;
126
+ }
127
+ /** Says a build failed, and why. */
128
+ failed(error) {
129
+ process.stderr.write(`${red("Build failed:")} ${error}
130
+ `);
131
+ return { ok: false, error, assets: [] };
132
+ }
133
+ /** Build, and print the summary or the error. `recovered`: the last build failed, which the summary of one that works says. */
134
+ async build(recovered) {
135
+ if (stopping) return never();
136
+ if (this.starting) await this.starting;
137
+ if (this.crashed !== void 0) {
138
+ const error = this.crashed;
139
+ this.crashed = void 0;
140
+ return this.failed(error);
141
+ }
142
+ if (!this.child) this.replace();
143
+ if (this.starting) await this.starting;
144
+ if (stopping) return never();
145
+ if (!this.child) return { ok: false, error: "The configuration didn't load: its error is in the terminal.", assets: [] };
146
+ const child = this.child;
147
+ const answer = this.next();
148
+ child.send({ type: "build", recovered });
149
+ const message = await answer;
150
+ if (stopping) return never();
151
+ if (message?.type === "crashed") {
152
+ this.crashed = void 0;
153
+ return this.failed(message.error);
154
+ }
155
+ if (message?.type !== "built") {
156
+ const how = child.exitCode !== null ? `exit code ${child.exitCode}` : child.signalCode !== null ? `stopped by ${child.signalCode}` : "it stopped answering";
157
+ return this.failed(`The build's process ended before the build did (${how}). What it said is in the terminal.`);
158
+ }
159
+ this.note(message);
160
+ return { ok: message.ok, error: message.error, assets: message.assets };
161
+ }
162
+ stop() {
163
+ const child = this.child;
164
+ this.child = void 0;
165
+ builders.delete(this);
166
+ if (child && child.exitCode === null && child.signalCode === null) child.kill("SIGKILL");
167
+ }
168
+ };
169
+
170
+ export {
171
+ BUILDER,
172
+ fileHash,
173
+ stopBuilders,
174
+ Builder
175
+ };