ssqch 0.7.1 → 0.9.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 (155) hide show
  1. package/README.md +8 -4
  2. package/bin/ssqch.js +14 -48
  3. package/bundled/README.md +1314 -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 +540 -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-jekyll.md +79 -0
  81. package/bundled/trailheads/from-mkdocs.md +45 -0
  82. package/bundled/trailheads/from-zola.md +71 -0
  83. package/lib/assets.js +235 -3
  84. package/lib/chunk-3A647I3N.js +384 -0
  85. package/lib/chunk-3GYLOC6Y.js +1017 -0
  86. package/lib/chunk-3K3ANWZ2.js +118 -0
  87. package/lib/chunk-3NYSSA2C.js +22 -0
  88. package/lib/chunk-47P4YREZ.js +1287 -0
  89. package/lib/chunk-4Q6WMTER.js +32 -0
  90. package/lib/chunk-76NTVE34.js +338 -0
  91. package/lib/chunk-7PWCYHTJ.js +1350 -0
  92. package/lib/chunk-7RDRZHJD.js +217 -0
  93. package/lib/chunk-7SD7K567.js +57 -0
  94. package/lib/chunk-7XLK2GEG.js +54 -0
  95. package/lib/chunk-AD3HAW3W.js +10 -0
  96. package/lib/chunk-BEGC7YP6.js +502 -0
  97. package/lib/chunk-CMUWRPSQ.js +113 -0
  98. package/lib/chunk-CZ4XQC56.js +999 -0
  99. package/lib/chunk-D2XE2GTY.js +71 -0
  100. package/lib/chunk-DDV6JEC2.js +46 -0
  101. package/lib/chunk-DELWRJAO.js +37409 -0
  102. package/lib/chunk-DELWRJAO.js.LEGAL.txt +27 -0
  103. package/lib/chunk-F65YUXZ7.js +334 -0
  104. package/lib/chunk-FVZ5JBRI.js +115 -0
  105. package/lib/chunk-GRWMGC7D.js +4435 -0
  106. package/lib/chunk-GRWMGC7D.js.LEGAL.txt +41 -0
  107. package/lib/chunk-GUKSZ2XM.js +207 -0
  108. package/lib/chunk-HPXAZ2HU.js +251 -0
  109. package/lib/chunk-HXCLCXRT.js +20 -0
  110. package/lib/chunk-I3PS26CI.js +48 -0
  111. package/lib/chunk-IAFM5ITE.js +11 -0
  112. package/lib/chunk-II5DEH3Q.js +209 -0
  113. package/lib/chunk-IJWHOFRP.js +44 -0
  114. package/lib/chunk-LPHNACE4.js +29 -0
  115. package/lib/chunk-MI6EJWA2.js +175 -0
  116. package/lib/chunk-NCWFYT74.js +1541 -0
  117. package/lib/chunk-NKXEPHRZ.js +136 -0
  118. package/lib/chunk-NNUKIGOO.js +160 -0
  119. package/lib/chunk-R7K3D5W5.js +3957 -0
  120. package/lib/chunk-RNJFPFXE.js +29 -0
  121. package/lib/chunk-SF4I6Z7S.js +25 -0
  122. package/lib/chunk-SURPOAW7.js +44 -0
  123. package/lib/chunk-SXMJ52IK.js +572 -0
  124. package/lib/chunk-TICWN55Z.js +20 -0
  125. package/lib/chunk-TVU3OPPK.js +146 -0
  126. package/lib/chunk-UU43WIZG.js +29 -0
  127. package/lib/chunk-VJWQSYEG.js +119 -0
  128. package/lib/chunk-XMXBHXZR.js +75 -0
  129. package/lib/chunk-YTHQBMDJ.js +211 -0
  130. package/lib/cli.js +547 -0
  131. package/lib/elements.js +180 -3
  132. package/lib/image.js +27 -3
  133. package/lib/links.js +464 -3
  134. package/lib/minify.js +69 -3
  135. package/lib/redirects.js +152 -3
  136. package/lib/rss.js +139 -3
  137. package/lib/sass.js +256 -3
  138. package/lib/sitemap.js +113 -3
  139. package/lib/ssqch.js +28 -0
  140. package/package.json +83 -80
  141. package/src/serve/live.js +174 -0
  142. package/src/serve/not-found.html +31 -0
  143. package/types/globals.d.ts +3 -2
  144. package/types/image.d.ts +7 -3
  145. package/types/index.d.ts +28 -9
  146. package/types/links.d.ts +1 -1
  147. package/types/minify.d.ts +1 -1
  148. package/types/rss.d.ts +1 -1
  149. package/types/sass.d.ts +1 -1
  150. package/types/sitemap.d.ts +2 -0
  151. package/wasm/markdown.wasm +0 -0
  152. package/wasm/minify.wasm +0 -0
  153. package/wasm/sass.wasm +0 -0
  154. package/lib/index.js +0 -3
  155. package/platforms.json +0 -6
@@ -0,0 +1,32 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ isDir
5
+ } from "./chunk-VJWQSYEG.js";
6
+
7
+ // src/command-line.ts
8
+ import os from "node:os";
9
+ import path from "node:path";
10
+ function toolPath(root) {
11
+ const bins = [];
12
+ for (let dir = path.resolve(root); ; dir = path.dirname(dir)) {
13
+ const bin = path.join(dir, "node_modules", ".bin");
14
+ if (isDir(bin)) bins.push(bin);
15
+ if (path.dirname(dir) === dir) break;
16
+ }
17
+ const rest = (process.env.PATH ?? process.env.Path ?? "").split(path.delimiter).filter(Boolean);
18
+ return [...bins, ...rest].join(path.delimiter);
19
+ }
20
+ function commandLine(command, root, vars) {
21
+ const env = { ...process.env, ...vars };
22
+ if (env.UV_THREADPOOL_SIZE === String(os.availableParallelism() + 4)) delete env.UV_THREADPOOL_SIZE;
23
+ for (const key of Object.keys(env)) if (key.toUpperCase() === "PATH") delete env[key];
24
+ env.PATH = toolPath(root);
25
+ if (process.platform !== "win32") return { file: "/bin/sh", args: ["-c", command], options: { cwd: root, env } };
26
+ return { file: process.env.ComSpec ?? "cmd.exe", args: ["/s", "/c", `"${command}"`], options: { cwd: root, env, windowsVerbatimArguments: true } };
27
+ }
28
+
29
+ export {
30
+ toolPath,
31
+ commandLine
32
+ };
@@ -0,0 +1,338 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ BuildError
5
+ } from "./chunk-GRWMGC7D.js";
6
+ import {
7
+ realPath
8
+ } from "./chunk-VJWQSYEG.js";
9
+
10
+ // src/modules.ts
11
+ import fs from "node:fs";
12
+ import path from "node:path";
13
+ import { execFileSync } from "node:child_process";
14
+ import os from "node:os";
15
+ import { registerHooks } from "node:module";
16
+ import { fileURLToPath, pathToFileURL } from "node:url";
17
+ var SELF = path.dirname(path.dirname(fileURLToPath(new URL("../src/modules.ts", import.meta.url).href)));
18
+ var BUILT_IN = ["ssqch/image", "ssqch/rss", "ssqch/assets", "ssqch/links", "ssqch/sitemap", "ssqch/redirects", "ssqch/sass", "ssqch/elements", "ssqch/minify"];
19
+ var COMPILED = fs.existsSync(path.join(SELF, "lib", "ssqch.js"));
20
+ var API = COMPILED ? pathToFileURL(path.join(SELF, "lib", "ssqch.js")).href : new URL("./exports/ssqch.ts", new URL("../src/modules.ts", import.meta.url).href).href;
21
+ var builtInUrl = (specifier) => COMPILED ? pathToFileURL(path.join(SELF, "lib", `${specifier.slice(6)}.js`)) : new URL(`./exports/${specifier.slice(6)}.ts`, new URL("../src/modules.ts", import.meta.url).href);
22
+ var loadedFiles = /* @__PURE__ */ new Set();
23
+ var isSiteUrl = (url) => {
24
+ if (!url?.startsWith("file:")) return false;
25
+ const file = fileURLToPath(url);
26
+ return !file.startsWith(SELF + path.sep) && !file.split(path.sep).includes("node_modules");
27
+ };
28
+ var ENDINGS = [".js", ".mjs", ".cjs", ".ts", ".mts", ".json", "/index.js", "/index.mjs", "/index.cjs", "/index.ts"];
29
+ var hooked = false;
30
+ function hookModules() {
31
+ if (hooked) return;
32
+ hooked = true;
33
+ const note = (resolved) => {
34
+ if (isSiteUrl(resolved.url)) loadedFiles.add(fileURLToPath(resolved.url));
35
+ return resolved;
36
+ };
37
+ registerHooks({
38
+ resolve(specifier, context, next) {
39
+ return note(resolveFor(specifier, context, next));
40
+ }
41
+ });
42
+ function resolveFor(...[specifier, context, next]) {
43
+ if (specifier.startsWith("file:") && specifier.endsWith(FORCE_ESM)) return { ...next(specifier, context), format: "module" };
44
+ if (specifier === "ssqch") return { url: API, shortCircuit: true };
45
+ if (specifier.startsWith("ssqch/")) {
46
+ const url = builtInUrl(specifier);
47
+ if (BUILT_IN.includes(specifier) && fs.existsSync(url)) return { url: url.href, shortCircuit: true };
48
+ }
49
+ const fromSite = isSiteUrl(context.parentURL);
50
+ const attempt = (name) => {
51
+ if (fromSite && /\.json(\?.*)?$/i.test(name) && !context.importAttributes?.type) {
52
+ const importAttributes = { ...context.importAttributes, type: "json" };
53
+ return { ...next(name, { ...context, importAttributes }), importAttributes };
54
+ }
55
+ return next(name, context);
56
+ };
57
+ const withEndings = (name) => {
58
+ const [bare, query = ""] = name.split(/(?=\?)/, 2);
59
+ try {
60
+ return attempt(name);
61
+ } catch {
62
+ }
63
+ for (const ending of ENDINGS) {
64
+ try {
65
+ return attempt(bare.replace(/\/$/, "") + ending + query);
66
+ } catch {
67
+ }
68
+ }
69
+ return void 0;
70
+ };
71
+ try {
72
+ return attempt(specifier);
73
+ } catch (e) {
74
+ const hashAlias = specifier.startsWith("#") && ["ERR_PACKAGE_IMPORT_NOT_DEFINED", "ERR_INVALID_MODULE_SPECIFIER"].includes(e?.code);
75
+ if (!fromSite || !hashAlias && !["ERR_MODULE_NOT_FOUND", "ERR_UNSUPPORTED_DIR_IMPORT"].includes(e?.code)) throw e;
76
+ const relative = specifier.startsWith("./") || specifier.startsWith("../") || path.isAbsolute(specifier) || specifier.startsWith("file:");
77
+ if (relative) return withEndings(specifier) ?? (() => {
78
+ throw e;
79
+ })();
80
+ for (const file of aliasTargets(specifier, path.dirname(fileURLToPath(context.parentURL)))) {
81
+ const found = withEndings(pathToFileURL(file).href);
82
+ if (found) return found;
83
+ }
84
+ throw e;
85
+ }
86
+ }
87
+ }
88
+ var aliasesByDir = /* @__PURE__ */ new Map();
89
+ function parseJsonc(text) {
90
+ let out = "";
91
+ for (let i = 0; i < text.length; i++) {
92
+ const c = text[i];
93
+ if (c === '"') {
94
+ const end = /^"(?:[^"\\]|\\.)*"/.exec(text.slice(i))?.[0] ?? c;
95
+ out += end;
96
+ i += end.length - 1;
97
+ } else if (c === "/" && text[i + 1] === "/") {
98
+ while (i < text.length && text[i] !== "\n") i++;
99
+ out += "\n";
100
+ } else if (c === "/" && text[i + 1] === "*") {
101
+ const end = text.indexOf("*/", i + 2);
102
+ i = end === -1 ? text.length : end + 1;
103
+ } else out += c;
104
+ }
105
+ return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
106
+ }
107
+ function readAliases(file, seen = /* @__PURE__ */ new Set()) {
108
+ if (seen.has(file)) return null;
109
+ seen.add(file);
110
+ let json;
111
+ try {
112
+ json = parseJsonc(fs.readFileSync(file, "utf8"));
113
+ } catch {
114
+ return null;
115
+ }
116
+ const dir = path.dirname(file);
117
+ const options = json?.compilerOptions ?? {};
118
+ if (options.paths && typeof options.paths === "object") {
119
+ const base = typeof options.baseUrl === "string" ? path.resolve(dir, options.baseUrl) : dir;
120
+ const paths = Object.entries(options.paths).filter((e) => Array.isArray(e[1])).map(([k, v]) => [k, v.filter((t) => typeof t === "string")]);
121
+ return { base, paths };
122
+ }
123
+ const parents = (Array.isArray(json?.extends) ? json.extends : [json?.extends]).filter((x) => typeof x === "string" && (x.startsWith("./") || x.startsWith("../")));
124
+ for (const parent of parents) {
125
+ const found = readAliases(path.resolve(dir, parent.endsWith(".json") ? parent : `${parent}.json`), seen);
126
+ if (found) return found;
127
+ }
128
+ return null;
129
+ }
130
+ function aliasesFor(dir) {
131
+ if (aliasesByDir.has(dir)) return aliasesByDir.get(dir);
132
+ let found = null;
133
+ for (const name of ["tsconfig.json", "jsconfig.json"]) {
134
+ const file = path.join(dir, name);
135
+ if (fs.existsSync(file)) {
136
+ found = readAliases(file);
137
+ break;
138
+ }
139
+ }
140
+ if (!found && !fs.existsSync(path.join(dir, "tsconfig.json")) && !fs.existsSync(path.join(dir, "jsconfig.json"))) {
141
+ const up = path.dirname(dir);
142
+ if (up !== dir) found = aliasesFor(up);
143
+ }
144
+ aliasesByDir.set(dir, found);
145
+ return found;
146
+ }
147
+ function aliasTargets(specifier, fromDir) {
148
+ const aliases = aliasesFor(fromDir);
149
+ if (!aliases) return [];
150
+ let best;
151
+ for (const [pattern, targets] of aliases.paths) {
152
+ const at = pattern.indexOf("*");
153
+ if (at === -1) {
154
+ if (pattern === specifier) return targets.map((t) => path.resolve(aliases.base, t));
155
+ continue;
156
+ }
157
+ const prefix = pattern.slice(0, at), suffix = pattern.slice(at + 1);
158
+ if (!specifier.startsWith(prefix) || !specifier.endsWith(suffix) || specifier.length < prefix.length + suffix.length) continue;
159
+ if (best && prefix.length <= best.pattern.indexOf("*")) continue;
160
+ best = { pattern, star: specifier.slice(prefix.length, specifier.length - suffix.length), targets };
161
+ }
162
+ return best ? best.targets.map((t) => path.resolve(aliases.base, t.replace("*", best.star))) : [];
163
+ }
164
+ var versions = /* @__PURE__ */ new Map();
165
+ async function importFile(file) {
166
+ hookModules();
167
+ const mtimeMs = fs.statSync(file).mtimeMs;
168
+ let entry = versions.get(file);
169
+ if (!entry) versions.set(file, entry = { mtimeMs, version: 0 });
170
+ else if (entry.mtimeMs !== mtimeMs) {
171
+ entry.mtimeMs = mtimeMs;
172
+ entry.version++;
173
+ }
174
+ const url = pathToFileURL(file).href + (entry.version ? `?v=${entry.version}` : "");
175
+ try {
176
+ return await watchSettle(import(url));
177
+ } catch (e) {
178
+ if (!(e instanceof SyntaxError) || !failedAsCommonJS(e, file) || !MODULE_SYNTAX.test(fs.readFileSync(file, "utf8"))) throw e;
179
+ return watchSettle(import(url + (url.includes("?") ? "&" : "?") + FORCE_ESM));
180
+ }
181
+ }
182
+ var FORCE_ESM = "ssqch-esm";
183
+ var MODULE_SYNTAX = /(?:^|[;{}()\s])(?:export\s|import\s*[\w{*'"]|import\.meta)/m;
184
+ function failedAsCommonJS(e, file) {
185
+ const named = /^(.+):\d+\r?\n/.exec(e.stack ?? "")?.[1];
186
+ return named !== void 0 && (named === file || named === realPath(file));
187
+ }
188
+ var waiting = [];
189
+ var watching = false;
190
+ function watchSettle(promise) {
191
+ if (!watching) {
192
+ watching = true;
193
+ process.on("beforeExit", () => {
194
+ const reject = waiting.pop();
195
+ reject?.(new BuildError("a Promise never settled (nothing was left to resolve it: no timers or requests were pending)"));
196
+ });
197
+ }
198
+ return new Promise((resolve, reject) => {
199
+ waiting.push(reject);
200
+ const done = () => {
201
+ const i = waiting.lastIndexOf(reject);
202
+ if (i !== -1) waiting.splice(i, 1);
203
+ };
204
+ promise.then((v) => {
205
+ done();
206
+ resolve(v);
207
+ }, (e) => {
208
+ done();
209
+ reject(e);
210
+ });
211
+ });
212
+ }
213
+ function settle(value) {
214
+ return value instanceof Promise ? watchSettle(value) : value;
215
+ }
216
+ function shownPath(file, root) {
217
+ const rel = path.relative(realPath(root), realPath(file));
218
+ return rel.startsWith("..") || path.isAbsolute(rel) ? file : rel.split(path.sep).join("/");
219
+ }
220
+ function describeThrown(e, root) {
221
+ if (e instanceof BuildError) return e.message;
222
+ if (!(e instanceof Error)) return `uncaught ${typeof e === "string" ? e : safeString(e)}`;
223
+ const message = packageMessage(e, root) ?? e.message;
224
+ const frames = e instanceof SyntaxError ? syntaxFrames(e, root) : [];
225
+ frames.push(...siteFrames(e.stack ?? "", root));
226
+ return frames.length ? `${message}
227
+ ${frames.join("\n")}` : message;
228
+ }
229
+ function packageMessage(e, root) {
230
+ const code = e.code;
231
+ const notInstalled = (name) => `package "${name}" isn't installed (no node_modules/${name} folder here or in a parent folder; run npm install)`;
232
+ const packageOf = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
233
+ if (code === "ERR_MODULE_NOT_FOUND") {
234
+ const found = /^Cannot find package '([^']+)'/.exec(e.message);
235
+ if (found) return notInstalled(packageOf(found[1]));
236
+ }
237
+ if (code === "MODULE_NOT_FOUND") {
238
+ const found = /^Cannot find module '([^']+)'\nRequire stack:\n- ([^\n]+)/.exec(e.message);
239
+ if (found) {
240
+ const [, specifier, from] = found;
241
+ const bare = !specifier.startsWith(".") && !path.isAbsolute(specifier);
242
+ return `Cannot find module '${specifier}' from '${shownPath(from, root)}': ${bare ? notInstalled(packageOf(specifier)) : "file not found"}`;
243
+ }
244
+ }
245
+ if (code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
246
+ const found = /^Package subpath '([^']+)' is not defined by "exports" in (.+?)[\\/]package\.json/.exec(e.message);
247
+ if (found) {
248
+ const name = found[2].split(/[\\/]node_modules[\\/]/).pop().replaceAll("\\", "/");
249
+ const required = /\n\s+at (?:Module\.)?require \(/.test(e.stack ?? "") || /\n\s+at Module\._resolveFilename/.test(e.stack ?? "");
250
+ return `package "${name}" doesn't export "${found[1]}" for ${required ? "require" : "import"} (see the "exports" in its package.json)`;
251
+ }
252
+ }
253
+ return void 0;
254
+ }
255
+ var safeString = (v) => {
256
+ try {
257
+ return String(v);
258
+ } catch {
259
+ return "a non-Error value";
260
+ }
261
+ };
262
+ function frameOf(line) {
263
+ const at = /^\s+at /.exec(line);
264
+ if (!at) return void 0;
265
+ let rest = line.slice(at[0].length);
266
+ let name;
267
+ if (rest.endsWith(")")) {
268
+ let depth = 0;
269
+ let open = -1;
270
+ for (let i = rest.length - 1; i >= 0; i--) {
271
+ if (rest[i] === ")") depth++;
272
+ else if (rest[i] === "(" && --depth === 0) {
273
+ open = i;
274
+ break;
275
+ }
276
+ }
277
+ if (open <= 0 || rest[open - 1] !== " ") return void 0;
278
+ name = rest.slice(0, open - 1);
279
+ rest = rest.slice(open + 1, -1);
280
+ }
281
+ const place = /^((?:file:\/\/|\/|[A-Za-z]:[\\/]).*?):(\d+):(\d+)$/.exec(rest);
282
+ return place ? [name, place[1], place[2], place[3]] : void 0;
283
+ }
284
+ function siteFrames(stack, root) {
285
+ const out = [];
286
+ for (const line of stack.split("\n")) {
287
+ const found = frameOf(line);
288
+ if (!found) continue;
289
+ const [name, where, row, column] = found;
290
+ let file;
291
+ try {
292
+ file = where.startsWith("file:") ? fileURLToPath(where.split("?")[0]) : where;
293
+ } catch {
294
+ continue;
295
+ }
296
+ if (file.startsWith(SELF + path.sep)) continue;
297
+ const plain = name?.replace(/^async /, "").replace(/ \[as [^\]]+\]$/, "").replace(/^(Object|Module)\./, "");
298
+ out.push(` at ${plain || "<anonymous>"} (${shownPath(file, root)}:${row}:${column})`);
299
+ }
300
+ return out;
301
+ }
302
+ function syntaxFrames(e, root) {
303
+ const first = /^(.+):(\d+)\n/.exec(e.stack ?? "");
304
+ if (first && fs.existsSync(first[1])) return [` at ${shownPath(first[1], root)}:${first[2]}:1`];
305
+ let tmp;
306
+ try {
307
+ tmp = fs.mkdtempSync(path.join(os.tmpdir(), "ssqch-check-"));
308
+ for (const file of [...loadedFiles].reverse().slice(0, 8)) {
309
+ const ext = /\.(m|c)?ts$/.test(file) ? ".mts" : ".mjs";
310
+ const copy = path.join(tmp, `check${ext}`);
311
+ fs.copyFileSync(file, copy);
312
+ try {
313
+ execFileSync(process.execPath, ["--check", copy], { stdio: ["ignore", "ignore", "pipe"], encoding: "utf8", timeout: 2e4 });
314
+ } catch (failed) {
315
+ const lines = String(failed.stderr ?? "").split("\n");
316
+ const at = lines.findIndex((l) => /[\\/]check\.m[jt]s:\d+$/.test(l.trimEnd()));
317
+ const row = at === -1 ? void 0 : /:(\d+)$/.exec(lines[at].trimEnd())?.[1];
318
+ if (row === void 0) continue;
319
+ const caret = lines[at + 2]?.indexOf("^") ?? -1;
320
+ return [` at ${shownPath(file, root)}:${row}:${caret === -1 ? 1 : caret + 1}`];
321
+ }
322
+ }
323
+ } catch {
324
+ } finally {
325
+ if (tmp) fs.rmSync(tmp, { recursive: true, force: true });
326
+ }
327
+ return [];
328
+ }
329
+
330
+ export {
331
+ loadedFiles,
332
+ hookModules,
333
+ importFile,
334
+ watchSettle,
335
+ settle,
336
+ shownPath,
337
+ describeThrown
338
+ };