fumadocs-mdx 11.2.0 → 11.2.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.
@@ -74,4 +74,32 @@ type GetOutput<C extends {
74
74
  };
75
75
  }> = CollectionEntry<C>[];
76
76
 
77
- export { type BaseCollectionEntry as B, type CollectionEntry as C, type DefaultMDXOptions as D, type FileInfo as F, type GlobalConfig as G, type InferSchema as I, type MarkdownProps as M, type InferSchemaType as a, type GetOutput as b, getDefaultMDXOptions as g };
77
+ interface MDXOptions extends ProcessorOptions {
78
+ /**
79
+ * Name of collection
80
+ */
81
+ collection?: string;
82
+ /**
83
+ * Specify a file path for source
84
+ */
85
+ filePath?: string;
86
+ frontmatter?: Record<string, unknown>;
87
+ /**
88
+ * Custom Vfile data
89
+ */
90
+ data?: Record<string, unknown>;
91
+ _compiler?: CompilerOptions;
92
+ }
93
+ interface CompilerOptions {
94
+ addDependency: (file: string) => void;
95
+ }
96
+ declare module 'vfile' {
97
+ interface DataMap {
98
+ /**
99
+ * The compiler object from loader
100
+ */
101
+ _compiler?: CompilerOptions;
102
+ }
103
+ }
104
+
105
+ export { type BaseCollectionEntry as B, type CollectionEntry as C, type DefaultMDXOptions as D, type FileInfo as F, type GlobalConfig as G, type InferSchema as I, type MarkdownProps as M, type MDXOptions as a, type InferSchemaType as b, type GetOutput as c, getDefaultMDXOptions as g };
@@ -4,39 +4,25 @@ import {
4
4
 
5
5
  // src/config/cached.ts
6
6
  import { createHash } from "node:crypto";
7
- import fs from "node:fs";
7
+ import * as fs from "node:fs";
8
8
 
9
9
  // src/config/load.ts
10
10
  import * as path from "node:path";
11
11
  import { pathToFileURL } from "node:url";
12
- import { build } from "esbuild";
12
+ import { createJiti } from "jiti";
13
13
  function findConfigFile() {
14
14
  return path.resolve("source.config.ts");
15
15
  }
16
+ var jiti = createJiti(import.meta.url, {
17
+ moduleCache: false
18
+ });
16
19
  async function loadConfig(configPath) {
17
- const outputPath = path.resolve(".source/source.config.mjs");
18
- const transformed = await build({
19
- entryPoints: [{ in: configPath, out: "source.config" }],
20
- bundle: true,
21
- outdir: ".source",
22
- target: "node18",
23
- write: true,
24
- platform: "node",
25
- format: "esm",
26
- packages: "external",
27
- outExtension: {
28
- ".js": ".mjs"
29
- },
30
- allowOverwrite: true,
31
- splitting: true
20
+ const imported = await jiti.import(pathToFileURL(configPath).href).catch((e) => {
21
+ throw new Error("failed to compile configuration file", e);
32
22
  });
33
- if (transformed.errors.length > 0) {
34
- throw new Error("failed to compile configuration file");
35
- }
36
- const url = pathToFileURL(outputPath);
37
23
  const [err, config] = buildConfig(
38
24
  // every call to `loadConfig` will cause the previous cache to be ignored
39
- await import(`${url.toString()}?hash=${Date.now().toString()}`)
25
+ imported
40
26
  );
41
27
  if (err !== null) throw new Error(err);
42
28
  return config;
@@ -89,7 +75,7 @@ async function loadConfigCached(configPath, hash) {
89
75
  return await config;
90
76
  }
91
77
  async function getConfigHash(configPath) {
92
- const hash = createHash("sha256");
78
+ const hash = createHash("md5");
93
79
  const rs = fs.createReadStream(configPath);
94
80
  for await (const chunk of rs) {
95
81
  hash.update(chunk);
@@ -98,8 +84,8 @@ async function getConfigHash(configPath) {
98
84
  }
99
85
 
100
86
  // src/map/manifest.ts
101
- import fs2 from "node:fs";
102
- import path2 from "node:path";
87
+ import * as fs2 from "node:fs";
88
+ import * as path2 from "node:path";
103
89
 
104
90
  // src/utils/get-type-from-path.ts
105
91
  import { extname } from "node:path";
@@ -0,0 +1,41 @@
1
+ // src/mdx-plugins/remark-include.ts
2
+ import { visit } from "unist-util-visit";
3
+ import * as path from "node:path";
4
+ import * as fs from "node:fs/promises";
5
+ import matter from "gray-matter";
6
+ function remarkInclude() {
7
+ return async (tree, file) => {
8
+ const queue = [];
9
+ visit(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
10
+ let specifier;
11
+ if (node.type === "paragraph" && node.children.length === 3) {
12
+ const [open, content, closure] = node.children;
13
+ if (open.type === "html" && open.value === "<include>" && content.type === "text" && closure.type === "html" && closure.value === "</include>") {
14
+ specifier = content.value.trim();
15
+ }
16
+ }
17
+ if (node.type === "mdxJsxFlowElement" && node.name === "include") {
18
+ const child = node.children.at(0);
19
+ if (!child || child.type !== "text") return;
20
+ specifier = child.value;
21
+ }
22
+ if (!specifier) return "skip";
23
+ const targetPath = path.resolve(path.dirname(file.path), specifier);
24
+ queue.push(
25
+ fs.readFile(targetPath).then((content) => {
26
+ const parsed = this.parse(matter(content).content);
27
+ if (file.data._compiler) {
28
+ file.data._compiler.addDependency(targetPath);
29
+ }
30
+ Object.assign(node, parsed);
31
+ })
32
+ );
33
+ return "skip";
34
+ });
35
+ await Promise.all(queue);
36
+ };
37
+ }
38
+
39
+ export {
40
+ remarkInclude
41
+ };
@@ -1,31 +1,12 @@
1
- import { F as FileInfo, G as GlobalConfig, M as MarkdownProps, B as BaseCollectionEntry } from '../types-BOXkLY5B.js';
2
- export { C as CollectionEntry, D as DefaultMDXOptions, b as GetOutput, I as InferSchema, a as InferSchemaType, g as getDefaultMDXOptions } from '../types-BOXkLY5B.js';
1
+ import { F as FileInfo, G as GlobalConfig, M as MarkdownProps, a as MDXOptions, B as BaseCollectionEntry } from '../build-mdx-SZwWfZMp.js';
2
+ export { C as CollectionEntry, D as DefaultMDXOptions, c as GetOutput, I as InferSchema, b as InferSchemaType, g as getDefaultMDXOptions } from '../build-mdx-SZwWfZMp.js';
3
3
  import { z, ZodTypeAny } from 'zod';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
5
+ import { Processor, Transformer } from 'unified';
6
+ import { Root } from 'mdast';
5
7
  import 'mdx/types';
6
8
  import 'fumadocs-core/mdx-plugins';
7
9
  import 'fumadocs-core/server';
8
- import 'unified';
9
-
10
- interface MDXOptions extends ProcessorOptions {
11
- /**
12
- * Name of collection
13
- */
14
- collection?: string;
15
- /**
16
- * Specify a file path for source
17
- */
18
- filePath?: string;
19
- frontmatter?: Record<string, unknown>;
20
- /**
21
- * Custom Vfile data
22
- */
23
- data?: Record<string, unknown>;
24
- _compiler?: CompilerOptions;
25
- }
26
- interface CompilerOptions {
27
- addDependency: (file: string) => void;
28
- }
29
10
 
30
11
  declare const metaSchema: z.ZodObject<{
31
12
  title: z.ZodOptional<z.ZodString>;
@@ -148,4 +129,6 @@ declare function defineDocs<DocData extends ZodTypeAny = typeof frontmatterSchem
148
129
  };
149
130
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
150
131
 
151
- export { type BaseCollection, BaseCollectionEntry, type DocCollection, FileInfo, GlobalConfig, MarkdownProps, type MetaCollection, type TransformContext, defineCollections, defineConfig, defineDocs, frontmatterSchema, metaSchema };
132
+ declare function remarkInclude(this: Processor): Transformer<Root, Root>;
133
+
134
+ export { type BaseCollection, BaseCollectionEntry, type DocCollection, FileInfo, GlobalConfig, MarkdownProps, type MetaCollection, type TransformContext, defineCollections, defineConfig, defineDocs, frontmatterSchema, metaSchema, remarkInclude };
@@ -1,3 +1,6 @@
1
+ import {
2
+ remarkInclude
3
+ } from "../chunk-GUHWD47S.js";
1
4
  import {
2
5
  getDefaultMDXOptions
3
6
  } from "../chunk-MKWJLEE7.js";
@@ -56,5 +59,6 @@ export {
56
59
  defineDocs,
57
60
  frontmatterSchema,
58
61
  getDefaultMDXOptions,
59
- metaSchema
62
+ metaSchema,
63
+ remarkInclude
60
64
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PageData, MetaData, Source } from 'fumadocs-core/source';
2
- import { F as FileInfo, B as BaseCollectionEntry } from './types-BOXkLY5B.js';
2
+ import { F as FileInfo, B as BaseCollectionEntry } from './build-mdx-SZwWfZMp.js';
3
3
  import { MetaFile } from './loader-mdx.js';
4
4
  import 'zod';
5
5
  import 'mdx/types';
@@ -11,7 +11,7 @@ import 'webpack';
11
11
 
12
12
  declare function toRuntime(type: 'doc' | 'meta', file: Record<string, unknown>, info: FileInfo): unknown;
13
13
  declare function toRuntimeAsync(frontmatter: Record<string, unknown>, load: () => Promise<Record<string, unknown>>, info: FileInfo): unknown;
14
- declare function createMDXSource<Doc extends PageData & BaseCollectionEntry, Meta extends MetaData & BaseCollectionEntry>(docs: Doc[], meta: Meta[]): Source<{
14
+ declare function createMDXSource<Doc extends PageData & BaseCollectionEntry, Meta extends MetaData & BaseCollectionEntry>(docs: Doc[], meta?: Meta[]): Source<{
15
15
  pageData: Doc;
16
16
  metaData: Meta;
17
17
  }>;
package/dist/index.js CHANGED
@@ -53,7 +53,7 @@ function toRuntimeAsync(frontmatter, load, info) {
53
53
  _file: info
54
54
  };
55
55
  }
56
- function createMDXSource(docs, meta) {
56
+ function createMDXSource(docs, meta = []) {
57
57
  return {
58
58
  files: (rootDir) => resolveFiles({
59
59
  docs,
@@ -1,43 +1,25 @@
1
+ import {
2
+ remarkInclude
3
+ } from "./chunk-GUHWD47S.js";
1
4
  import {
2
5
  getConfigHash,
3
6
  getManifestEntryPath,
4
7
  loadConfigCached
5
- } from "./chunk-BP4S5VOB.js";
8
+ } from "./chunk-2KEQHW7J.js";
6
9
  import "./chunk-MKWJLEE7.js";
7
10
 
8
11
  // src/loader-mdx.ts
9
- import * as path3 from "node:path";
12
+ import * as path2 from "node:path";
10
13
  import * as fs2 from "node:fs/promises";
11
14
  import { parse } from "node:querystring";
12
15
  import grayMatter from "gray-matter";
13
16
 
14
17
  // src/utils/build-mdx.ts
15
18
  import { createProcessor } from "@mdx-js/mdx";
16
- import { visit } from "unist-util-visit";
17
- import { readFileSync } from "node:fs";
18
- import * as path from "node:path";
19
- import matter from "gray-matter";
20
19
  var cache = /* @__PURE__ */ new Map();
21
20
  function cacheKey(group, format) {
22
21
  return `${group}:${format}`;
23
22
  }
24
- function remarkInclude(options) {
25
- return (tree, file) => {
26
- visit(tree, "mdxJsxFlowElement", (node) => {
27
- if (node.name === "include") {
28
- const child = node.children.at(0);
29
- if (!child || child.type !== "text") return;
30
- const specifier = child.value;
31
- const targetPath = path.resolve(path.dirname(file.path), specifier);
32
- const content = readFileSync(targetPath);
33
- const parsed = this.parse(matter(content).content);
34
- options.addDependency(targetPath);
35
- Object.assign(node, parsed);
36
- }
37
- return "skip";
38
- });
39
- };
40
- }
41
23
  function buildMDX(group, configHash, source, options = {}) {
42
24
  const { filePath, frontmatter, data, ...rest } = options;
43
25
  let format = options.format;
@@ -53,10 +35,7 @@ function buildMDX(group, configHash, source, options = {}) {
53
35
  outputFormat: "program",
54
36
  development: process.env.NODE_ENV === "development",
55
37
  ...rest,
56
- remarkPlugins: [
57
- options._compiler ? [remarkInclude, options._compiler] : null,
58
- ...rest.remarkPlugins ?? []
59
- ],
38
+ remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
60
39
  format
61
40
  }),
62
41
  configHash
@@ -68,7 +47,8 @@ function buildMDX(group, configHash, source, options = {}) {
68
47
  path: filePath,
69
48
  data: {
70
49
  ...data,
71
- frontmatter
50
+ frontmatter,
51
+ _compiler: options._compiler
72
52
  }
73
53
  });
74
54
  }
@@ -92,20 +72,20 @@ function formatError(file, error) {
92
72
  }
93
73
 
94
74
  // src/utils/git-timestamp.ts
95
- import path2 from "node:path";
75
+ import path from "node:path";
96
76
  import fs from "node:fs";
97
77
  import { spawn } from "cross-spawn";
98
78
  var cache2 = /* @__PURE__ */ new Map();
99
79
  function getGitTimestamp(file) {
100
80
  const cachedTimestamp = cache2.get(file);
101
81
  if (cachedTimestamp) return Promise.resolve(cachedTimestamp);
102
- return new Promise((resolve3, reject) => {
103
- const cwd = path2.dirname(file);
82
+ return new Promise((resolve, reject) => {
83
+ const cwd = path.dirname(file);
104
84
  if (!fs.existsSync(cwd)) {
105
- resolve3(void 0);
85
+ resolve(void 0);
106
86
  return;
107
87
  }
108
- const fileName = path2.basename(file);
88
+ const fileName = path.basename(file);
109
89
  const child = spawn("git", ["log", "-1", '--pretty="%ai"', fileName], {
110
90
  cwd
111
91
  });
@@ -113,7 +93,7 @@ function getGitTimestamp(file) {
113
93
  child.stdout.on("data", (d) => output = new Date(String(d)));
114
94
  child.on("close", () => {
115
95
  if (output) cache2.set(file, output);
116
- resolve3(output);
96
+ resolve(output);
117
97
  });
118
98
  child.on("error", reject);
119
99
  });
@@ -134,7 +114,7 @@ async function loader(source, callback) {
134
114
  const context = this.context;
135
115
  const filePath = this.resourcePath;
136
116
  const { _ctx } = this.getOptions();
137
- const matter2 = grayMatter(source);
117
+ const matter = grayMatter(source);
138
118
  const {
139
119
  hash: configHash = await getConfigHash(_ctx.configPath),
140
120
  collection: collectionId
@@ -145,7 +125,7 @@ async function loader(source, callback) {
145
125
  collection = void 0;
146
126
  }
147
127
  const mdxOptions = collection?.mdxOptions ?? config.defaultMdxOptions;
148
- let frontmatter = matter2.data;
128
+ let frontmatter = matter.data;
149
129
  if (collection?.schema) {
150
130
  let schema = collection.schema;
151
131
  if (typeof schema === "function") {
@@ -170,12 +150,6 @@ async function loader(source, callback) {
170
150
  }
171
151
  frontmatter = result.data;
172
152
  }
173
- const props = matter2.data._mdx ?? {};
174
- if (props.mirror) {
175
- const mirrorPath = path3.resolve(path3.dirname(filePath), props.mirror);
176
- this.addDependency(mirrorPath);
177
- matter2.content = await fs2.readFile(mirrorPath).then((res) => grayMatter(res.toString()).content);
178
- }
179
153
  let timestamp;
180
154
  if (config.global?.lastModifiedTime === "git")
181
155
  timestamp = (await getGitTimestamp(filePath))?.getTime();
@@ -183,7 +157,7 @@ async function loader(source, callback) {
183
157
  const file = await buildMDX(
184
158
  collectionId ?? "global",
185
159
  configHash,
186
- matter2.content,
160
+ matter.content,
187
161
  {
188
162
  development: this.mode === "development",
189
163
  ...mdxOptions,
@@ -208,7 +182,7 @@ async function loader(source, callback) {
208
182
  }
209
183
  } catch (error) {
210
184
  if (!(error instanceof Error)) throw error;
211
- const fpath = path3.relative(context, filePath);
185
+ const fpath = path2.relative(context, filePath);
212
186
  error.message = `${fpath}:${error.name}: ${error.message}`;
213
187
  callback(error);
214
188
  }
@@ -5,15 +5,15 @@ import {
5
5
  loadConfig,
6
6
  loadConfigCached,
7
7
  writeManifest
8
- } from "../chunk-BP4S5VOB.js";
8
+ } from "../chunk-2KEQHW7J.js";
9
9
  import "../chunk-MKWJLEE7.js";
10
10
 
11
11
  // src/next/create.ts
12
12
  import path3 from "node:path";
13
13
 
14
14
  // src/map/index.ts
15
- import path2 from "node:path";
16
- import fs from "node:fs";
15
+ import * as path2 from "node:path";
16
+ import * as fs from "node:fs";
17
17
  import { readFile, writeFile } from "node:fs/promises";
18
18
  import grayMatter from "gray-matter";
19
19
 
@@ -75,13 +75,13 @@ async function getCollectionFiles(collection) {
75
75
  cwd: path.resolve(dir),
76
76
  absolute: true
77
77
  });
78
- result.forEach((item) => {
79
- if (getTypeFromPath(item) !== collection.type) return;
78
+ for (const item of result) {
79
+ if (getTypeFromPath(item) !== collection.type) continue;
80
80
  files.set(item, {
81
81
  path: path.relative(dir, item),
82
82
  absolutePath: item
83
83
  });
84
- });
84
+ }
85
85
  })
86
86
  );
87
87
  return Array.from(files.values());
@@ -253,8 +253,8 @@ function createMDX({
253
253
  }
254
254
 
255
255
  // src/postinstall.ts
256
- import path4 from "node:path";
257
- import fs2 from "node:fs";
256
+ import * as path4 from "node:path";
257
+ import * as fs2 from "node:fs";
258
258
  async function postInstall(configPath = findConfigFile()) {
259
259
  const typeOut = path4.resolve(".source/index.d.ts");
260
260
  const config = await loadConfig(configPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.2.0",
3
+ "version": "11.2.2",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -38,10 +38,10 @@
38
38
  "@mdx-js/mdx": "^3.1.0",
39
39
  "chokidar": "^4.0.3",
40
40
  "cross-spawn": "^7.0.6",
41
- "esbuild": "^0.24.2",
42
41
  "estree-util-value-to-estree": "^3.2.1",
43
42
  "fast-glob": "^3.3.1",
44
43
  "gray-matter": "^4.0.3",
44
+ "jiti": "^2.4.2",
45
45
  "micromatch": "^4.0.8",
46
46
  "unist-util-visit": "^5.0.0",
47
47
  "zod": "^3.24.1"
@@ -53,12 +53,12 @@
53
53
  "@types/micromatch": "^4.0.9",
54
54
  "@types/react": "^19.0.2",
55
55
  "mdast-util-mdx-jsx": "^3.1.3",
56
- "next": "^15.1.2",
56
+ "next": "^15.1.3",
57
57
  "unified": "^11.0.5",
58
58
  "vfile": "^6.0.3",
59
59
  "webpack": "^5.97.1",
60
60
  "eslint-config-custom": "0.0.0",
61
- "fumadocs-core": "14.6.3",
61
+ "fumadocs-core": "14.7.0",
62
62
  "tsconfig": "0.0.0"
63
63
  },
64
64
  "peerDependencies": {