@clarify-labs/cli 0.11.3 → 0.11.4

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-6WmOk7xk.cjs");
2
+ const require_engine = require("./engine-Cgc71w13.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 deserializeSearchIndex, c as cliPackageVersionWithCaret, i as createClarifyTempDir, l as createViteAdapter, n as createClarifyEngine, o as searchMcpIndex, r as createClarifyRuntimeAliases, s as cliPackageVersion } from "./engine-CrYRJRZT.js";
2
+ import { a as deserializeSearchIndex, c as cliPackageVersionWithCaret, i as createClarifyTempDir, l as createViteAdapter, n as createClarifyEngine, o as searchMcpIndex, r as createClarifyRuntimeAliases, s as cliPackageVersion } from "./engine-CJmXVTo5.js";
3
3
  import { dirname, extname, isAbsolute, join, normalize, relative, resolve } from "node:path";
4
4
  import { lstat, mkdir, readFile, stat, writeFile } from "node:fs/promises";
5
5
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
@@ -85,7 +85,7 @@ function createContentCompileDiagnostic(options) {
85
85
  return createContentDiagnostic({
86
86
  kind: format,
87
87
  title: `${label} ${phase} error`,
88
- message: phase === "syntax" ? "This page could not be compiled. Fix the MDX syntax or component usage above, then reload the route." : `This page could not be compiled. Fix the ${label} syntax or plugin error below, then reload the route.`,
88
+ message: phase === "syntax" ? `This page could not be compiled. Fix the ${label} syntax or component usage above, then reload the route.` : `This page could not be compiled. Fix the ${label} syntax or plugin error below, then reload the route.`,
89
89
  error,
90
90
  filePath,
91
91
  projectRoot,
@@ -98,19 +98,24 @@ function createContentCompileDiagnostic(options) {
98
98
  *
99
99
  * `rehypePlugins` includes `rehypeShiki`, which loads grammar/WASM assets and
100
100
  * is expensive. The real highlighting happens at Vite build time via the
101
- * `@mdx-js/rollup` plugins (see `createMarkdownPlugin` and `createMdxPlugin`
102
- * in `core/adapters.ts`), which
103
- * runs the full remark + rehype pipeline. Re-running it here, during route
104
- * discovery (Phase 3), would compile every `.mdx` file twice and invoke Shiki
105
- * once per file per `engine.refresh()` — see ARCHITECTURE.md §2.2 which states
106
- * "不应在 core 中执行代码高亮".
101
+ * `@mdx-js/rollup` plugin (see `createContentCompilerPlugin` in
102
+ * `core/adapters.ts`), which runs the full remark + rehype pipeline.
103
+ * Re-running it here, during route discovery (Phase 3), would compile every
104
+ * `.mdx` file twice and invoke Shiki once per file per `engine.refresh()` -
105
+ * see ARCHITECTURE.md §2.2 which states "不应在 core 中执行代码高亮".
107
106
  *
108
107
  * The remark pipeline still runs (shared with the Vite plugin via
109
- * `remarkPlugins`), so MDX/JSX syntax errors — the only class of error this
110
- * diagnostic is meant to surface ahead of the Vite build — are caught. The
108
+ * `remarkPlugins`), so MDX/JSX syntax errors - the only class of error this
109
+ * diagnostic is meant to surface ahead of the Vite build - are caught. The
111
110
  * output is discarded; only the thrown error is used.
111
+ *
112
+ * `.md` files are handled by `compileMarkdownContent` in `markdown.ts`, which
113
+ * mirrors the adapter's markdown compiler semantics (`format: 'md'`, raw HTML
114
+ * allowed). Keep the two compilers separate so each format can evolve its own
115
+ * diagnostic rules without contaminating the other.
112
116
  */
113
- async function compileMdxContent(content, filePath, projectRoot) {
117
+ async function compileMdxContent(content, options = {}) {
118
+ const { filePath, projectRoot } = options;
114
119
  try {
115
120
  await compile(content, {
116
121
  jsx: true,
@@ -241,6 +246,54 @@ function createProjectContentProcessor(plugins, ctx) {
241
246
  return createContentProcessor((input) => runHooks(plugins, "content:transform", input, ctx));
242
247
  }
243
248
  //#endregion
249
+ //#region source/parsers/markdown/markdown.ts
250
+ /**
251
+ * Validate Markdown content for diagnostics WITHOUT running the build-time
252
+ * rehype pipeline (Shiki highlighting, slug injection, code-block parsing).
253
+ *
254
+ * `rehypePlugins` includes `rehypeShiki`, which loads grammar/WASM assets and
255
+ * is expensive. The real highlighting happens at Vite build time via the
256
+ * `@mdx-js/rollup` plugin (see `createContentCompilerPlugin` in
257
+ * `core/adapters.ts`), which runs the full remark + rehype pipeline.
258
+ * Re-running it here, during route discovery (Phase 3), would compile every
259
+ * `.md` file twice and invoke Shiki once per file per `engine.refresh()` -
260
+ * see ARCHITECTURE.md §2.2 which states "不应在 core 中执行代码高亮".
261
+ *
262
+ * `format: 'md'` mirrors the adapter's markdown compiler semantics (no JSX,
263
+ * raw HTML allowed via `remarkRehypeOptions`), so the same class of syntax
264
+ * errors that would break the Vite build is surfaced as a diagnostic here
265
+ * instead of leaking out as an opaque
266
+ * `Failed to fetch dynamically imported module` at runtime.
267
+ *
268
+ * MDX files are handled by `compileMdxContent` in `mdx.ts`. Keep the two
269
+ * compilers separate so each format can evolve its own diagnostic rules
270
+ * without contaminating the other.
271
+ */
272
+ async function compileMarkdownContent(content, options = {}) {
273
+ const { filePath, projectRoot } = options;
274
+ try {
275
+ await compile(content, {
276
+ format: "md",
277
+ jsx: true,
278
+ providerImportSource: "@clarify-labs/renderer",
279
+ remarkPlugins,
280
+ remarkRehypeOptions: { allowDangerousHtml: true }
281
+ });
282
+ return { ok: true };
283
+ } catch (error) {
284
+ return {
285
+ ok: false,
286
+ diagnostic: createContentCompileDiagnostic({
287
+ format: "markdown",
288
+ phase: "syntax",
289
+ error,
290
+ filePath,
291
+ projectRoot
292
+ })
293
+ };
294
+ }
295
+ }
296
+ //#endregion
244
297
  //#region source/parsers/routes/routes.ts
245
298
  function kebabToTitle(str) {
246
299
  return str.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
@@ -249,8 +302,10 @@ function parseMdxTree(content) {
249
302
  return remark.parse(content);
250
303
  }
251
304
  async function compileRouteDiagnostic(content, filePath, baseDir) {
252
- if (extname(filePath).toLowerCase() !== ".mdx") return void 0;
253
- const result = await compileMdxContent(content, filePath, baseDir);
305
+ const result = await (extname(filePath).toLowerCase() === ".md" ? compileMarkdownContent : compileMdxContent)(content, {
306
+ filePath,
307
+ projectRoot: baseDir
308
+ });
254
309
  return result.ok ? void 0 : result.diagnostic;
255
310
  }
256
311
  /** 从内容中提取第一个 H1 标题 */
@@ -955,18 +1010,16 @@ var clarifyThemeConfigSchema = z.object({
955
1010
  tokens: clarifyThemeTokensConfigSchema.optional(),
956
1011
  layout: clarifyThemeLayoutConfigSchema.optional()
957
1012
  }).strict();
958
- function featureSchema(shape, defaults) {
1013
+ function featureSchema(shape, defaults, enabledByDefault = true) {
1014
+ const resolvedDefaults = {
1015
+ enabled: enabledByDefault,
1016
+ ...defaults
1017
+ };
959
1018
  const objectSchema = z.object({
960
- enabled: z.boolean().default(true),
1019
+ enabled: z.boolean().default(enabledByDefault),
961
1020
  ...shape
962
- }).strict().default({
963
- enabled: true,
964
- ...defaults
965
- });
966
- return z.union([z.boolean(), objectSchema]).default({
967
- enabled: true,
968
- ...defaults
969
- }).transform((value) => typeof value === "boolean" ? {
1021
+ }).strict().default(resolvedDefaults);
1022
+ return z.union([z.boolean(), objectSchema]).default(resolvedDefaults).transform((value) => typeof value === "boolean" ? {
970
1023
  enabled: value,
971
1024
  ...defaults
972
1025
  } : value);
@@ -974,7 +1027,7 @@ function featureSchema(shape, defaults) {
974
1027
  var clarifyFeaturesConfigSchema = z.object({
975
1028
  search: featureSchema({ mcp: z.boolean().default(true) }, { mcp: true }),
976
1029
  repository: featureSchema(clarifyRepositoryConfigSchema.shape, {}),
977
- themeEditor: featureSchema({}, {}),
1030
+ themeEditor: featureSchema({}, {}, false),
978
1031
  openapi: featureSchema({ playground: z.boolean().default(true) }, { playground: true })
979
1032
  }).strict();
980
1033
  var clarifyProjectConfigSchema = z.object({
@@ -1558,7 +1611,7 @@ function createViteAdapter(engine) {
1558
1611
  }
1559
1612
  var cliPackageVersion = {
1560
1613
  name: "@clarify-labs/cli",
1561
- version: "0.11.3",
1614
+ version: "0.11.4",
1562
1615
  license: "AGPL-3.0-only",
1563
1616
  type: "module",
1564
1617
  repository: {
@@ -3788,4 +3841,4 @@ function createClarifyEngine(options = {}) {
3788
3841
  //#endregion
3789
3842
  export { deserializeSearchIndex as a, cliPackageVersionWithCaret as c, createClarifyTempDir as i, createViteAdapter as l, createClarifyEngine as n, searchMcpIndex as o, createClarifyRuntimeAliases as r, cliPackageVersion as s, ClarifyEngine as t, defineConfig as u };
3790
3843
 
3791
- //# sourceMappingURL=engine-CrYRJRZT.js.map
3844
+ //# sourceMappingURL=engine-CJmXVTo5.js.map