@clarify-labs/cli 0.10.1 → 0.10.2

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/output/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_engine = require("./engine-5bdNX2Oo.cjs");
2
+ const require_engine = require("./engine-qafLfnXQ.cjs");
3
3
  let node_path = require("node:path");
4
4
  let node_fs_promises = require("node:fs/promises");
5
5
  let node_fs = require("node:fs");
package/output/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as cliPackageVersion, i as createClarifyTempDir, n as createClarifyEngine, o as cliPackageVersionWithCaret, r as createClarifyRuntimeAliases, s as createViteAdapter } from "./engine-Ca_2MCj9.js";
2
+ import { a as cliPackageVersion, i as createClarifyTempDir, n as createClarifyEngine, o as cliPackageVersionWithCaret, r as createClarifyRuntimeAliases, s as createViteAdapter } from "./engine-CSSL_gGd.js";
3
3
  import { dirname, extname, isAbsolute, join, normalize, relative, resolve } from "node:path";
4
4
  import { lstat, readFile, stat, writeFile } from "node:fs/promises";
5
5
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
@@ -2,13 +2,16 @@ import { dirname, extname, isAbsolute, join, relative, resolve } from "node:path
2
2
  import mdxPlugin from "@mdx-js/rollup";
3
3
  import tailwindcss from "@tailwindcss/vite";
4
4
  import react from "@vitejs/plugin-react";
5
+ import rehypeRaw from "rehype-raw";
5
6
  import { compile } from "@mdx-js/mdx";
6
- import GithubSlugger, { slug } from "github-slugger";
7
- import { toString } from "mdast-util-to-string";
8
- import { bundledLanguages, createCssVariablesTheme, createHighlighter } from "shiki";
7
+ import rehypeShiki from "@shikijs/rehype";
8
+ import rehypeSlug from "rehype-slug";
9
+ import { createCssVariablesTheme } from "shiki";
9
10
  import { visit } from "unist-util-visit";
10
- import { markdownRemarkPlugins, themeBootstrapScript, themePresets } from "@clarify-labs/renderer";
11
+ import { markdownRemarkPlugins, parseCodeMeta, themeBootstrapScript, themePresets } from "@clarify-labs/renderer";
11
12
  import { readFile, readdir, stat } from "node:fs/promises";
13
+ import GithubSlugger, { slug } from "github-slugger";
14
+ import { toString } from "mdast-util-to-string";
12
15
  import { remark } from "remark";
13
16
  import matter from "gray-matter";
14
17
  import { createReadStream, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
@@ -19,38 +22,11 @@ import { fileURLToPath, pathToFileURL } from "node:url";
19
22
  import SwaggerParser from "@apidevtools/swagger-parser";
20
23
  import { tmpdir } from "node:os";
21
24
  import { createRequire } from "node:module";
22
- //#region source/parsers/markdown/utils.ts
23
- function escapeHtml(text) {
24
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
25
- }
26
- //#endregion
27
25
  //#region source/parsers/markdown/mdx.ts
28
26
  function getLanguage(className) {
29
27
  return (Array.isArray(className) ? className : typeof className === "string" ? className.split(/\s+/) : []).find((item) => typeof item === "string" && item.startsWith("language-"))?.replace(/^language-/, "") || "txt";
30
28
  }
31
- function getTextContent(node) {
32
- if (!node) return "";
33
- if (typeof node.value === "string") return node.value;
34
- return node.children?.map(getTextContent).join("") ?? "";
35
- }
36
- function renderPlainCode(code) {
37
- return code.split("\n").map((line) => `<span>${escapeHtml(line)}</span>`).join("\n");
38
- }
39
- function isBundledLanguage(language) {
40
- return language in bundledLanguages;
41
- }
42
- var highlighterPromise;
43
29
  var cssVariablesTheme = createCssVariablesTheme();
44
- async function getHighlighter() {
45
- highlighterPromise = highlighterPromise ?? createHighlighter({
46
- themes: [cssVariablesTheme],
47
- langs: []
48
- });
49
- return highlighterPromise;
50
- }
51
- function renderHighlightedCode(html) {
52
- return (/<code[^>]*>([\s\S]*?)<\/code>/.exec(html)?.[1] ?? html).split("\n").map((line) => line.trimStart().startsWith("<span") ? line : `<span>${line}</span>`).join("\n");
53
- }
54
30
  function rehypeParseCodeBlocks() {
55
31
  return (tree) => {
56
32
  visit(tree, "element", (node, _nodeIndex, parentNode) => {
@@ -68,61 +44,18 @@ function rehypeParseCodeBlocks() {
68
44
  });
69
45
  };
70
46
  }
71
- function rehypeShiki() {
72
- return async (tree) => {
73
- const shikiHighlighter = await getHighlighter();
74
- const languages = /* @__PURE__ */ new Set();
75
- visit(tree, "element", (node) => {
76
- if (node.tagName !== "pre") return;
77
- const codeNode = node.children?.[0];
78
- if (codeNode?.tagName !== "code") return;
79
- const language = typeof node.properties?.language === "string" ? node.properties.language : getLanguage(codeNode.properties?.className);
80
- if (language && language !== "txt" && isBundledLanguage(language)) languages.add(language);
81
- });
82
- if (languages.size > 0) await shikiHighlighter.loadLanguage(...languages);
83
- visit(tree, "element", (node) => {
84
- if (node.tagName !== "pre") return;
85
- const codeNode = node.children?.[0];
86
- if (codeNode?.tagName !== "code") return;
87
- node.properties = node.properties ?? {};
88
- codeNode.properties = codeNode.properties ?? {};
89
- const code = getTextContent(codeNode);
90
- const language = typeof node.properties.language === "string" ? node.properties.language : getLanguage(codeNode.properties.className);
91
- node.properties.code = code;
92
- codeNode.properties.code = code;
93
- codeNode.properties.language = language;
94
- let highlighted = renderPlainCode(code);
95
- if (language && language !== "txt") try {
96
- highlighted = renderHighlightedCode(shikiHighlighter.codeToHtml(code, {
97
- lang: language,
98
- theme: cssVariablesTheme
99
- }));
100
- } catch {
101
- highlighted = renderPlainCode(code);
102
- }
103
- codeNode.children = [{
104
- type: "text",
105
- value: highlighted
106
- }];
107
- });
108
- };
109
- }
110
- function rehypeSlugSections() {
111
- return (tree) => {
112
- const slugger = new GithubSlugger();
113
- visit(tree, "element", (node) => {
114
- if (node.tagName !== "h2" && node.tagName !== "h3") return;
115
- node.properties = node.properties ?? {};
116
- if (node.properties.id) return;
117
- node.properties.id = slugger.slug(toString(node));
118
- });
119
- };
120
- }
121
47
  var remarkPlugins = markdownRemarkPlugins;
122
48
  var rehypePlugins = [
123
- rehypeSlugSections,
49
+ rehypeSlug,
124
50
  rehypeParseCodeBlocks,
125
- rehypeShiki
51
+ [rehypeShiki, {
52
+ theme: cssVariablesTheme,
53
+ langs: [],
54
+ lazy: true,
55
+ addLanguageClass: true,
56
+ fallbackLanguage: "text",
57
+ parseMetaString: parseCodeMeta
58
+ }]
126
59
  ];
127
60
  function formatMdxDiagnostic(error) {
128
61
  if (error instanceof Error) return error.message;
@@ -134,7 +67,8 @@ function formatMdxDiagnostic(error) {
134
67
  *
135
68
  * `rehypePlugins` includes `rehypeShiki`, which loads grammar/WASM assets and
136
69
  * is expensive. The real highlighting happens at Vite build time via the
137
- * `@mdx-js/rollup` plugin (see `createMdxPlugin` in `core/adapters.ts`), which
70
+ * `@mdx-js/rollup` plugins (see `createMarkdownPlugin` and `createMdxPlugin`
71
+ * in `core/adapters.ts`), which
138
72
  * runs the full remark + rehype pipeline. Re-running it here, during route
139
73
  * discovery (Phase 3), would compile every `.mdx` file twice and invoke Shiki
140
74
  * once per file per `engine.refresh()` — see ARCHITECTURE.md §2.2 which states
@@ -283,6 +217,11 @@ function kebabToTitle(str) {
283
217
  function parseMdxTree(content) {
284
218
  return remark.parse(content);
285
219
  }
220
+ async function compileRouteDiagnostic(content, filePath, baseDir) {
221
+ if (extname(filePath).toLowerCase() !== ".mdx") return void 0;
222
+ const result = await compileMdxContent(content, filePath, baseDir);
223
+ return result.ok ? void 0 : result.diagnostic;
224
+ }
286
225
  /** 从内容中提取第一个 H1 标题 */
287
226
  function extractH1(content) {
288
227
  const tree = parseMdxTree(content);
@@ -377,7 +316,7 @@ async function findContentRoutes(dir, base = dir, options = {}) {
377
316
  frontmatter,
378
317
  content
379
318
  };
380
- const mdxResult = await compileMdxContent(page.content, fullPath, base);
319
+ const diagnostic = await compileRouteDiagnostic(page.content, fullPath, base);
381
320
  let title = typeof page.frontmatter.title === "string" ? page.frontmatter.title : "";
382
321
  if (!title) {
383
322
  const lastPart = pathParts[pathParts.length - 1] ?? "";
@@ -399,7 +338,7 @@ async function findContentRoutes(dir, base = dir, options = {}) {
399
338
  frontmatter: page.frontmatter,
400
339
  content: page.content
401
340
  },
402
- diagnostic: mdxResult.ok ? void 0 : mdxResult.diagnostic
341
+ diagnostic
403
342
  });
404
343
  }
405
344
  }
@@ -1330,9 +1269,9 @@ async function refreshDevServer(engine, server) {
1330
1269
  invalidateVirtualModules(engine, server);
1331
1270
  return hasDevStructureChanged(before, createDevStructureSnapshot(engine.routes, engine.navigation));
1332
1271
  }
1333
- function createNormalizedMdxContentPlugin(engine) {
1272
+ function createNormalizedContentPlugin(engine) {
1334
1273
  return {
1335
- name: "clarify:normalized-mdx-content",
1274
+ name: "clarify:normalized-content",
1336
1275
  enforce: "pre",
1337
1276
  transform(_code, id) {
1338
1277
  if (!/\.mdx?(?:\?|$)/.test(id)) return null;
@@ -1348,14 +1287,26 @@ function createNormalizedMdxContentPlugin(engine) {
1348
1287
  }
1349
1288
  function createMdxPlugin() {
1350
1289
  return mdxPlugin({
1351
- include: ["**/*.{md,mdx}"],
1290
+ include: ["**/*.mdx"],
1291
+ format: "mdx",
1352
1292
  jsxImportSource: "react",
1353
1293
  providerImportSource: "@clarify-labs/renderer",
1354
1294
  remarkPlugins,
1355
1295
  rehypePlugins
1356
1296
  });
1357
1297
  }
1358
- function createClarifyViteCorePlugin(engine, normalizedMdxContentPlugin, mdx) {
1298
+ function createMarkdownPlugin() {
1299
+ return mdxPlugin({
1300
+ include: ["**/*.md"],
1301
+ format: "md",
1302
+ jsxImportSource: "react",
1303
+ providerImportSource: "@clarify-labs/renderer",
1304
+ remarkPlugins,
1305
+ remarkRehypeOptions: { allowDangerousHtml: true },
1306
+ rehypePlugins: [rehypeRaw, ...rehypePlugins]
1307
+ });
1308
+ }
1309
+ function createClarifyViteCorePlugin(engine, normalizedContentPlugin, markdown, mdx) {
1359
1310
  let viteConfig;
1360
1311
  return {
1361
1312
  name: "clarify:core",
@@ -1457,7 +1408,8 @@ function createClarifyViteCorePlugin(engine, normalizedMdxContentPlugin, mdx) {
1457
1408
  outputDirectory: viteConfig.build.outDir,
1458
1409
  ssrPlugins: [
1459
1410
  engine.createSSGVirtualPlugin(),
1460
- normalizedMdxContentPlugin,
1411
+ normalizedContentPlugin,
1412
+ markdown,
1461
1413
  mdx
1462
1414
  ]
1463
1415
  });
@@ -1474,20 +1426,22 @@ function createClarifyViteCorePlugin(engine, normalizedMdxContentPlugin, mdx) {
1474
1426
  * site itself - it only bridges Vite lifecycle hooks to the engine.
1475
1427
  */
1476
1428
  function createViteAdapter(engine) {
1477
- const normalizedMdxContentPlugin = createNormalizedMdxContentPlugin(engine);
1429
+ const normalizedContentPlugin = createNormalizedContentPlugin(engine);
1430
+ const markdown = createMarkdownPlugin();
1478
1431
  const mdx = createMdxPlugin();
1479
1432
  const tailwind = tailwindcss();
1480
1433
  return [
1481
1434
  ...react(),
1482
1435
  ...Array.isArray(tailwind) ? tailwind : [tailwind],
1483
- normalizedMdxContentPlugin,
1484
- createClarifyViteCorePlugin(engine, normalizedMdxContentPlugin, mdx),
1436
+ normalizedContentPlugin,
1437
+ createClarifyViteCorePlugin(engine, normalizedContentPlugin, markdown, mdx),
1438
+ markdown,
1485
1439
  mdx
1486
1440
  ];
1487
1441
  }
1488
1442
  var cliPackageVersion = {
1489
1443
  name: "@clarify-labs/cli",
1490
- version: "0.10.1",
1444
+ version: "0.10.2",
1491
1445
  license: "AGPL-3.0-only",
1492
1446
  type: "module",
1493
1447
  repository: {
@@ -1528,6 +1482,7 @@ var cliPackageVersion = {
1528
1482
  "@clarify-labs/templates": "workspace:*",
1529
1483
  "@mdx-js/mdx": "^3.1.1",
1530
1484
  "@mdx-js/rollup": "^3.1.1",
1485
+ "@shikijs/rehype": "^4.3.0",
1531
1486
  "@tailwindcss/vite": "^4.3.2",
1532
1487
  "@vitejs/plugin-react": "^6.0.3",
1533
1488
  "cac": "^7.0.0",
@@ -1542,6 +1497,8 @@ var cliPackageVersion = {
1542
1497
  "react-router": "^7.0.0",
1543
1498
  "react-router-dom": "^7.0.0",
1544
1499
  "react-zoom-pan-pinch": "^4.0.3",
1500
+ "rehype-raw": "^7.0.0",
1501
+ "rehype-slug": "^6.0.0",
1545
1502
  "remark": "^15.0.1",
1546
1503
  "remark-gfm": "^4.0.1",
1547
1504
  "shiki": "4.3.0",
@@ -2686,6 +2643,11 @@ function writeClarifyEnvDts(projectRoot, plugins) {
2686
2643
  writeFileSync(filePath, next, "utf-8");
2687
2644
  }
2688
2645
  //#endregion
2646
+ //#region source/parsers/markdown/utils.ts
2647
+ function escapeHtml(text) {
2648
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
2649
+ }
2650
+ //#endregion
2689
2651
  //#region source/core/runtime/html-template.ts
2690
2652
  /**
2691
2653
  * HTML template manipulation helpers used during SSG.
@@ -3342,4 +3304,4 @@ function createClarifyEngine(options = {}) {
3342
3304
  //#endregion
3343
3305
  export { cliPackageVersion as a, defineConfig as c, createClarifyTempDir as i, createClarifyEngine as n, cliPackageVersionWithCaret as o, createClarifyRuntimeAliases as r, createViteAdapter as s, ClarifyEngine as t };
3344
3306
 
3345
- //# sourceMappingURL=engine-Ca_2MCj9.js.map
3307
+ //# sourceMappingURL=engine-CSSL_gGd.js.map