fumadocs-mdx 11.5.7 → 11.6.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.
@@ -35,7 +35,6 @@ __export(async_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(async_exports);
37
37
  var import_mdx_remote = require("@fumadocs/mdx-remote");
38
- var fs2 = __toESM(require("fs/promises"), 1);
39
38
 
40
39
  // src/mdx-plugins/remark-include.ts
41
40
  var import_unist_util_visit = require("unist-util-visit");
@@ -52,49 +51,56 @@ function remarkInclude() {
52
51
  const TagName = "include";
53
52
  async function update(tree, file, processor, compiler) {
54
53
  const queue = [];
55
- (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
56
- let specifier;
57
- const params = {};
58
- if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
59
- const value = flattenNode(node);
60
- if (value.length > 0) {
61
- for (const attr of node.attributes) {
62
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
63
- params[attr.name] = attr.value;
54
+ (0, import_unist_util_visit.visit)(
55
+ tree,
56
+ ["mdxJsxFlowElement", "mdxJsxTextElement"],
57
+ (node, _, parent) => {
58
+ let specifier;
59
+ const params = {};
60
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
61
+ const value = flattenNode(node);
62
+ if (value.length > 0) {
63
+ for (const attr of node.attributes) {
64
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
65
+ params[attr.name] = attr.value;
66
+ }
64
67
  }
68
+ specifier = value;
65
69
  }
66
- specifier = value;
67
70
  }
71
+ if (!specifier) return;
72
+ const targetPath = path.resolve(
73
+ "cwd" in params ? process.cwd() : path.dirname(file),
74
+ specifier
75
+ );
76
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
77
+ queue.push(
78
+ fs.readFile(targetPath).then(async (content) => {
79
+ compiler?.addDependency(targetPath);
80
+ if (asCode) {
81
+ const lang = params.lang ?? path.extname(specifier).slice(1);
82
+ Object.assign(node, {
83
+ type: "code",
84
+ lang,
85
+ meta: params.meta,
86
+ value: content.toString(),
87
+ data: {}
88
+ });
89
+ return;
90
+ }
91
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
92
+ await update(parsed, targetPath, processor, compiler);
93
+ Object.assign(
94
+ parent && parent.type === "paragraph" ? parent : node,
95
+ parsed
96
+ );
97
+ }).catch((e) => {
98
+ console.warn(`failed to read file: ${targetPath}`, e);
99
+ })
100
+ );
101
+ return "skip";
68
102
  }
69
- if (!specifier) return;
70
- const targetPath = path.resolve(
71
- "cwd" in params ? process.cwd() : path.dirname(file),
72
- specifier
73
- );
74
- const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
75
- queue.push(
76
- fs.readFile(targetPath).then(async (content) => {
77
- compiler?.addDependency(targetPath);
78
- if (asCode) {
79
- const lang = params.lang ?? path.extname(specifier).slice(1);
80
- Object.assign(node, {
81
- type: "code",
82
- lang,
83
- meta: params.meta,
84
- value: content.toString(),
85
- data: {}
86
- });
87
- return;
88
- }
89
- const parsed = processor.parse((0, import_gray_matter.default)(content).content);
90
- await update(parsed, targetPath, processor, compiler);
91
- Object.assign(node, parsed);
92
- }).catch((e) => {
93
- console.warn(`failed to read file: ${targetPath}`, e);
94
- })
95
- );
96
- return "skip";
97
- });
103
+ );
98
104
  await Promise.all(queue);
99
105
  }
100
106
  return async (tree, file) => {
@@ -141,21 +147,15 @@ var _runtime = {
141
147
  };
142
148
  function createMDXSource(docs, meta = []) {
143
149
  return {
144
- files: (rootDir) => resolveFiles({
150
+ files: () => resolveFiles({
145
151
  docs,
146
- meta,
147
- rootDir
152
+ meta
148
153
  })
149
154
  };
150
155
  }
151
- function resolveFiles({
152
- docs,
153
- meta,
154
- rootDir = ""
155
- }) {
156
+ function resolveFiles({ docs, meta }) {
156
157
  const outputs = [];
157
158
  for (const entry of docs) {
158
- if (!entry._file.path.startsWith(rootDir)) continue;
159
159
  outputs.push({
160
160
  type: "page",
161
161
  path: entry._file.path,
@@ -203,10 +203,7 @@ function buildConfig(config) {
203
203
  null,
204
204
  {
205
205
  global: globalConfig,
206
- collections,
207
- _runtime: {
208
- files: /* @__PURE__ */ new Map()
209
- }
206
+ collections
210
207
  }
211
208
  ];
212
209
  }
@@ -232,14 +229,15 @@ async function initCompiler(config, collection) {
232
229
  var _runtimeAsync = {
233
230
  doc(files, collection, config) {
234
231
  const init = initCompiler(config, collection);
235
- return files.map(({ info: file, data: frontmatter }) => {
232
+ return files.map(({ info: file, data, content }) => {
236
233
  return {
237
- ...frontmatter,
234
+ ...data,
238
235
  _file: file,
236
+ content,
239
237
  async load() {
240
238
  const compiler = await init;
241
239
  const out = await compiler.compile({
242
- source: (await fs2.readFile(file.absolutePath)).toString(),
240
+ source: content,
243
241
  filePath: file.absolutePath
244
242
  });
245
243
  return {
@@ -1,5 +1,5 @@
1
- import { L as LoadedConfig, b as RuntimeAsync } from '../types-bWXuqsw9.cjs';
2
- import '../define-P0QTVn7W.cjs';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../types-BNrQHCj5.cjs';
2
+ import '../define-BaW0PQDJ.cjs';
3
3
  import '@mdx-js/mdx';
4
4
  import 'mdx/types';
5
5
  import 'fumadocs-core/mdx-plugins';
@@ -1,5 +1,5 @@
1
- import { L as LoadedConfig, b as RuntimeAsync } from '../types-CJRGJLAg.js';
2
- import '../define-P0QTVn7W.js';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../types-DEduCvIT.js';
2
+ import '../define-BaW0PQDJ.js';
3
3
  import '@mdx-js/mdx';
4
4
  import 'mdx/types';
5
5
  import 'fumadocs-core/mdx-plugins';
@@ -1,17 +1,16 @@
1
1
  import {
2
2
  _runtime,
3
3
  createMDXSource
4
- } from "../chunk-IZURUUPO.js";
5
- import {
6
- remarkInclude
7
- } from "../chunk-ITGWT23S.js";
4
+ } from "../chunk-VFALQK6O.js";
8
5
  import {
9
6
  buildConfig
10
- } from "../chunk-SLCPEEMF.js";
7
+ } from "../chunk-DRVUBK5B.js";
8
+ import {
9
+ remarkInclude
10
+ } from "../chunk-MK7EXW7O.js";
11
11
 
12
12
  // src/runtime/async.ts
13
13
  import { createCompiler } from "@fumadocs/mdx-remote";
14
- import * as fs from "node:fs/promises";
15
14
  import {
16
15
  remarkStructure
17
16
  } from "fumadocs-core/mdx-plugins";
@@ -35,14 +34,15 @@ async function initCompiler(config, collection) {
35
34
  var _runtimeAsync = {
36
35
  doc(files, collection, config) {
37
36
  const init = initCompiler(config, collection);
38
- return files.map(({ info: file, data: frontmatter }) => {
37
+ return files.map(({ info: file, data, content }) => {
39
38
  return {
40
- ...frontmatter,
39
+ ...data,
41
40
  _file: file,
41
+ content,
42
42
  async load() {
43
43
  const compiler = await init;
44
44
  const out = await compiler.compile({
45
- source: (await fs.readFile(file.absolutePath)).toString(),
45
+ source: content,
46
46
  filePath: file.absolutePath
47
47
  });
48
48
  return {
@@ -1,4 +1,4 @@
1
- import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-P0QTVn7W.js';
1
+ import { D as DocCollection, M as MetaCollection, a as DocsCollection, G as GlobalConfig, F as FileInfo, b as MarkdownProps, B as BaseCollectionEntry } from './define-BaW0PQDJ.cjs';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
@@ -7,12 +7,6 @@ import { MDXOptions } from '@fumadocs/mdx-remote';
7
7
  interface LoadedConfig {
8
8
  collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
9
9
  global?: GlobalConfig;
10
- _runtime: {
11
- /**
12
- * Absolute file path and their associated collections
13
- */
14
- files: Map<string, string>;
15
- };
16
10
  _mdx_loader?: {
17
11
  cachedProcessorOptions?: ProcessorOptions;
18
12
  };
@@ -25,6 +19,11 @@ interface RuntimeFile {
25
19
  info: FileInfo;
26
20
  data: Record<string, unknown>;
27
21
  }
22
+ interface AsyncRuntimeFile {
23
+ info: FileInfo;
24
+ data: Record<string, unknown>;
25
+ content: string;
26
+ }
28
27
  type DocOut<Schema extends StandardSchemaV1> = Omit<MarkdownProps, keyof StandardSchemaV1.InferOutput<Schema>> & StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
29
28
  type MetaOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
30
29
  interface Runtime {
@@ -64,16 +63,17 @@ interface Runtime {
64
63
  } : never;
65
64
  }
66
65
  type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry & {
66
+ content: string;
67
67
  load: () => Promise<MarkdownProps>;
68
68
  };
69
69
  interface RuntimeAsync {
70
- doc: <C>(files: RuntimeFile[], collection: string, config: LoadedConfig) => C extends {
70
+ doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends {
71
71
  type: 'doc';
72
72
  _type: {
73
73
  schema: infer Schema extends StandardSchemaV1;
74
74
  };
75
75
  } ? AsyncDocOut<Schema>[] : never;
76
- docs: <C>(docs: RuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends {
76
+ docs: <C>(docs: AsyncRuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends {
77
77
  type: 'docs';
78
78
  docs: {
79
79
  type: 'doc';
@@ -97,4 +97,4 @@ interface RuntimeAsync {
97
97
  } : never;
98
98
  }
99
99
 
100
- export type { LoadedConfig as L, Runtime as R, RuntimeFile as a, RuntimeAsync as b };
100
+ export type { LoadedConfig as L, Runtime as R, RuntimeAsync as a };
@@ -1,4 +1,4 @@
1
- import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-P0QTVn7W.cjs';
1
+ import { D as DocCollection, M as MetaCollection, a as DocsCollection, G as GlobalConfig, F as FileInfo, b as MarkdownProps, B as BaseCollectionEntry } from './define-BaW0PQDJ.js';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
@@ -7,12 +7,6 @@ import { MDXOptions } from '@fumadocs/mdx-remote';
7
7
  interface LoadedConfig {
8
8
  collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
9
9
  global?: GlobalConfig;
10
- _runtime: {
11
- /**
12
- * Absolute file path and their associated collections
13
- */
14
- files: Map<string, string>;
15
- };
16
10
  _mdx_loader?: {
17
11
  cachedProcessorOptions?: ProcessorOptions;
18
12
  };
@@ -25,6 +19,11 @@ interface RuntimeFile {
25
19
  info: FileInfo;
26
20
  data: Record<string, unknown>;
27
21
  }
22
+ interface AsyncRuntimeFile {
23
+ info: FileInfo;
24
+ data: Record<string, unknown>;
25
+ content: string;
26
+ }
28
27
  type DocOut<Schema extends StandardSchemaV1> = Omit<MarkdownProps, keyof StandardSchemaV1.InferOutput<Schema>> & StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
29
28
  type MetaOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
30
29
  interface Runtime {
@@ -64,16 +63,17 @@ interface Runtime {
64
63
  } : never;
65
64
  }
66
65
  type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry & {
66
+ content: string;
67
67
  load: () => Promise<MarkdownProps>;
68
68
  };
69
69
  interface RuntimeAsync {
70
- doc: <C>(files: RuntimeFile[], collection: string, config: LoadedConfig) => C extends {
70
+ doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends {
71
71
  type: 'doc';
72
72
  _type: {
73
73
  schema: infer Schema extends StandardSchemaV1;
74
74
  };
75
75
  } ? AsyncDocOut<Schema>[] : never;
76
- docs: <C>(docs: RuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends {
76
+ docs: <C>(docs: AsyncRuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends {
77
77
  type: 'docs';
78
78
  docs: {
79
79
  type: 'doc';
@@ -97,4 +97,4 @@ interface RuntimeAsync {
97
97
  } : never;
98
98
  }
99
99
 
100
- export type { LoadedConfig as L, Runtime as R, RuntimeFile as a, RuntimeAsync as b };
100
+ export type { LoadedConfig as L, Runtime as R, RuntimeAsync as a };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.5.7",
3
+ "version": "11.6.0",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -46,10 +46,12 @@
46
46
  "@standard-schema/spec": "^1.0.0",
47
47
  "chokidar": "^4.0.3",
48
48
  "cross-spawn": "^7.0.6",
49
- "esbuild": "^0.25.0",
50
- "estree-util-value-to-estree": "^3.3.2",
49
+ "esbuild": "^0.25.2",
50
+ "estree-util-value-to-estree": "^3.3.3",
51
51
  "fast-glob": "^3.3.3",
52
52
  "gray-matter": "^4.0.3",
53
+ "lru-cache": "^11.1.0",
54
+ "picocolors": "^1.1.1",
53
55
  "unist-util-visit": "^5.0.0",
54
56
  "zod": "^3.24.2"
55
57
  },
@@ -57,21 +59,21 @@
57
59
  "@types/cross-spawn": "^6.0.6",
58
60
  "@types/mdast": "^4.0.3",
59
61
  "@types/mdx": "^2.0.13",
60
- "@types/react": "^19.0.11",
62
+ "@types/react": "^19.1.0",
61
63
  "mdast-util-mdx-jsx": "^3.2.0",
62
- "next": "^15.2.3",
64
+ "next": "^15.3.0",
63
65
  "unified": "^11.0.5",
64
66
  "vfile": "^6.0.3",
65
- "webpack": "^5.97.1",
66
- "@fumadocs/mdx-remote": "1.2.1",
67
+ "webpack": "^5.99.5",
68
+ "@fumadocs/mdx-remote": "1.3.0",
67
69
  "eslint-config-custom": "0.0.0",
68
- "fumadocs-core": "15.1.1",
70
+ "fumadocs-core": "15.2.7",
69
71
  "tsconfig": "0.0.0"
70
72
  },
71
73
  "peerDependencies": {
72
74
  "@fumadocs/mdx-remote": "^1.2.0",
73
75
  "fumadocs-core": "^14.0.0 || ^15.0.0",
74
- "next": "14.x.x || 15.x.x"
76
+ "next": "^15.3.0"
75
77
  },
76
78
  "peerDependenciesMeta": {
77
79
  "@fumadocs/mdx-remote": {
@@ -1,68 +0,0 @@
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 flattenNode(node) {
7
- if ("children" in node)
8
- return node.children.map((child) => flattenNode(child)).join("");
9
- if ("value" in node) return node.value;
10
- return "";
11
- }
12
- function remarkInclude() {
13
- const TagName = "include";
14
- async function update(tree, file, processor, compiler) {
15
- const queue = [];
16
- visit(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
17
- let specifier;
18
- const params = {};
19
- if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
20
- const value = flattenNode(node);
21
- if (value.length > 0) {
22
- for (const attr of node.attributes) {
23
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
24
- params[attr.name] = attr.value;
25
- }
26
- }
27
- specifier = value;
28
- }
29
- }
30
- if (!specifier) return;
31
- const targetPath = path.resolve(
32
- "cwd" in params ? process.cwd() : path.dirname(file),
33
- specifier
34
- );
35
- const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
36
- queue.push(
37
- fs.readFile(targetPath).then(async (content) => {
38
- compiler?.addDependency(targetPath);
39
- if (asCode) {
40
- const lang = params.lang ?? path.extname(specifier).slice(1);
41
- Object.assign(node, {
42
- type: "code",
43
- lang,
44
- meta: params.meta,
45
- value: content.toString(),
46
- data: {}
47
- });
48
- return;
49
- }
50
- const parsed = processor.parse(matter(content).content);
51
- await update(parsed, targetPath, processor, compiler);
52
- Object.assign(node, parsed);
53
- }).catch((e) => {
54
- console.warn(`failed to read file: ${targetPath}`, e);
55
- })
56
- );
57
- return "skip";
58
- });
59
- await Promise.all(queue);
60
- }
61
- return async (tree, file) => {
62
- await update(tree, file.path, this, file.data._compiler);
63
- };
64
- }
65
-
66
- export {
67
- remarkInclude
68
- };