@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.
@@ -116,7 +116,7 @@ function createContentCompileDiagnostic(options) {
116
116
  return createContentDiagnostic({
117
117
  kind: format,
118
118
  title: `${label} ${phase} error`,
119
- 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.`,
119
+ 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.`,
120
120
  error,
121
121
  filePath,
122
122
  projectRoot,
@@ -129,19 +129,24 @@ function createContentCompileDiagnostic(options) {
129
129
  *
130
130
  * `rehypePlugins` includes `rehypeShiki`, which loads grammar/WASM assets and
131
131
  * is expensive. The real highlighting happens at Vite build time via the
132
- * `@mdx-js/rollup` plugins (see `createMarkdownPlugin` and `createMdxPlugin`
133
- * in `core/adapters.ts`), which
134
- * runs the full remark + rehype pipeline. Re-running it here, during route
135
- * discovery (Phase 3), would compile every `.mdx` file twice and invoke Shiki
136
- * once per file per `engine.refresh()` — see ARCHITECTURE.md §2.2 which states
137
- * "不应在 core 中执行代码高亮".
132
+ * `@mdx-js/rollup` plugin (see `createContentCompilerPlugin` in
133
+ * `core/adapters.ts`), which runs the full remark + rehype pipeline.
134
+ * Re-running it here, during route discovery (Phase 3), would compile every
135
+ * `.mdx` file twice and invoke Shiki once per file per `engine.refresh()` -
136
+ * see ARCHITECTURE.md §2.2 which states "不应在 core 中执行代码高亮".
138
137
  *
139
138
  * The remark pipeline still runs (shared with the Vite plugin via
140
- * `remarkPlugins`), so MDX/JSX syntax errors — the only class of error this
141
- * diagnostic is meant to surface ahead of the Vite build — are caught. The
139
+ * `remarkPlugins`), so MDX/JSX syntax errors - the only class of error this
140
+ * diagnostic is meant to surface ahead of the Vite build - are caught. The
142
141
  * output is discarded; only the thrown error is used.
142
+ *
143
+ * `.md` files are handled by `compileMarkdownContent` in `markdown.ts`, which
144
+ * mirrors the adapter's markdown compiler semantics (`format: 'md'`, raw HTML
145
+ * allowed). Keep the two compilers separate so each format can evolve its own
146
+ * diagnostic rules without contaminating the other.
143
147
  */
144
- async function compileMdxContent(content, filePath, projectRoot) {
148
+ async function compileMdxContent(content, options = {}) {
149
+ const { filePath, projectRoot } = options;
145
150
  try {
146
151
  await (0, _mdx_js_mdx.compile)(content, {
147
152
  jsx: true,
@@ -272,6 +277,54 @@ function createProjectContentProcessor(plugins, ctx) {
272
277
  return createContentProcessor((input) => runHooks(plugins, "content:transform", input, ctx));
273
278
  }
274
279
  //#endregion
280
+ //#region source/parsers/markdown/markdown.ts
281
+ /**
282
+ * Validate Markdown content for diagnostics WITHOUT running the build-time
283
+ * rehype pipeline (Shiki highlighting, slug injection, code-block parsing).
284
+ *
285
+ * `rehypePlugins` includes `rehypeShiki`, which loads grammar/WASM assets and
286
+ * is expensive. The real highlighting happens at Vite build time via the
287
+ * `@mdx-js/rollup` plugin (see `createContentCompilerPlugin` in
288
+ * `core/adapters.ts`), which runs the full remark + rehype pipeline.
289
+ * Re-running it here, during route discovery (Phase 3), would compile every
290
+ * `.md` file twice and invoke Shiki once per file per `engine.refresh()` -
291
+ * see ARCHITECTURE.md §2.2 which states "不应在 core 中执行代码高亮".
292
+ *
293
+ * `format: 'md'` mirrors the adapter's markdown compiler semantics (no JSX,
294
+ * raw HTML allowed via `remarkRehypeOptions`), so the same class of syntax
295
+ * errors that would break the Vite build is surfaced as a diagnostic here
296
+ * instead of leaking out as an opaque
297
+ * `Failed to fetch dynamically imported module` at runtime.
298
+ *
299
+ * MDX files are handled by `compileMdxContent` in `mdx.ts`. Keep the two
300
+ * compilers separate so each format can evolve its own diagnostic rules
301
+ * without contaminating the other.
302
+ */
303
+ async function compileMarkdownContent(content, options = {}) {
304
+ const { filePath, projectRoot } = options;
305
+ try {
306
+ await (0, _mdx_js_mdx.compile)(content, {
307
+ format: "md",
308
+ jsx: true,
309
+ providerImportSource: "@clarify-labs/renderer",
310
+ remarkPlugins,
311
+ remarkRehypeOptions: { allowDangerousHtml: true }
312
+ });
313
+ return { ok: true };
314
+ } catch (error) {
315
+ return {
316
+ ok: false,
317
+ diagnostic: createContentCompileDiagnostic({
318
+ format: "markdown",
319
+ phase: "syntax",
320
+ error,
321
+ filePath,
322
+ projectRoot
323
+ })
324
+ };
325
+ }
326
+ }
327
+ //#endregion
275
328
  //#region source/parsers/routes/routes.ts
276
329
  function kebabToTitle(str) {
277
330
  return str.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
@@ -280,8 +333,10 @@ function parseMdxTree(content) {
280
333
  return remark.remark.parse(content);
281
334
  }
282
335
  async function compileRouteDiagnostic(content, filePath, baseDir) {
283
- if ((0, node_path.extname)(filePath).toLowerCase() !== ".mdx") return void 0;
284
- const result = await compileMdxContent(content, filePath, baseDir);
336
+ const result = await ((0, node_path.extname)(filePath).toLowerCase() === ".md" ? compileMarkdownContent : compileMdxContent)(content, {
337
+ filePath,
338
+ projectRoot: baseDir
339
+ });
285
340
  return result.ok ? void 0 : result.diagnostic;
286
341
  }
287
342
  /** 从内容中提取第一个 H1 标题 */
@@ -986,18 +1041,16 @@ var clarifyThemeConfigSchema = zod.z.object({
986
1041
  tokens: clarifyThemeTokensConfigSchema.optional(),
987
1042
  layout: clarifyThemeLayoutConfigSchema.optional()
988
1043
  }).strict();
989
- function featureSchema(shape, defaults) {
1044
+ function featureSchema(shape, defaults, enabledByDefault = true) {
1045
+ const resolvedDefaults = {
1046
+ enabled: enabledByDefault,
1047
+ ...defaults
1048
+ };
990
1049
  const objectSchema = zod.z.object({
991
- enabled: zod.z.boolean().default(true),
1050
+ enabled: zod.z.boolean().default(enabledByDefault),
992
1051
  ...shape
993
- }).strict().default({
994
- enabled: true,
995
- ...defaults
996
- });
997
- return zod.z.union([zod.z.boolean(), objectSchema]).default({
998
- enabled: true,
999
- ...defaults
1000
- }).transform((value) => typeof value === "boolean" ? {
1052
+ }).strict().default(resolvedDefaults);
1053
+ return zod.z.union([zod.z.boolean(), objectSchema]).default(resolvedDefaults).transform((value) => typeof value === "boolean" ? {
1001
1054
  enabled: value,
1002
1055
  ...defaults
1003
1056
  } : value);
@@ -1005,7 +1058,7 @@ function featureSchema(shape, defaults) {
1005
1058
  var clarifyFeaturesConfigSchema = zod.z.object({
1006
1059
  search: featureSchema({ mcp: zod.z.boolean().default(true) }, { mcp: true }),
1007
1060
  repository: featureSchema(clarifyRepositoryConfigSchema.shape, {}),
1008
- themeEditor: featureSchema({}, {}),
1061
+ themeEditor: featureSchema({}, {}, false),
1009
1062
  openapi: featureSchema({ playground: zod.z.boolean().default(true) }, { playground: true })
1010
1063
  }).strict();
1011
1064
  var clarifyProjectConfigSchema = zod.z.object({
@@ -1589,7 +1642,7 @@ function createViteAdapter(engine) {
1589
1642
  }
1590
1643
  var cliPackageVersion = {
1591
1644
  name: "@clarify-labs/cli",
1592
- version: "0.11.3",
1645
+ version: "0.11.4",
1593
1646
  license: "AGPL-3.0-only",
1594
1647
  type: "module",
1595
1648
  repository: {
@@ -3878,4 +3931,4 @@ Object.defineProperty(exports, "searchMcpIndex", {
3878
3931
  }
3879
3932
  });
3880
3933
 
3881
- //# sourceMappingURL=engine-6WmOk7xk.cjs.map
3934
+ //# sourceMappingURL=engine-Cgc71w13.cjs.map