fumadocs-mdx 11.5.7 → 11.5.8

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.
@@ -29,10 +29,7 @@ function buildConfig(config) {
29
29
  null,
30
30
  {
31
31
  global: globalConfig,
32
- collections,
33
- _runtime: {
34
- files: /* @__PURE__ */ new Map()
35
- }
32
+ collections
36
33
  }
37
34
  ];
38
35
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildConfig
3
- } from "./chunk-SLCPEEMF.js";
3
+ } from "./chunk-DRVUBK5B.js";
4
4
 
5
5
  // src/utils/config.ts
6
6
  import * as fs from "node:fs/promises";
@@ -0,0 +1,75 @@
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(
17
+ tree,
18
+ ["mdxJsxFlowElement", "mdxJsxTextElement"],
19
+ (node, _, parent) => {
20
+ let specifier;
21
+ const params = {};
22
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
23
+ const value = flattenNode(node);
24
+ if (value.length > 0) {
25
+ for (const attr of node.attributes) {
26
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
27
+ params[attr.name] = attr.value;
28
+ }
29
+ }
30
+ specifier = value;
31
+ }
32
+ }
33
+ if (!specifier) return;
34
+ const targetPath = path.resolve(
35
+ "cwd" in params ? process.cwd() : path.dirname(file),
36
+ specifier
37
+ );
38
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
39
+ queue.push(
40
+ fs.readFile(targetPath).then(async (content) => {
41
+ compiler?.addDependency(targetPath);
42
+ if (asCode) {
43
+ const lang = params.lang ?? path.extname(specifier).slice(1);
44
+ Object.assign(node, {
45
+ type: "code",
46
+ lang,
47
+ meta: params.meta,
48
+ value: content.toString(),
49
+ data: {}
50
+ });
51
+ return;
52
+ }
53
+ const parsed = processor.parse(matter(content).content);
54
+ await update(parsed, targetPath, processor, compiler);
55
+ Object.assign(
56
+ parent && parent.type === "paragraph" ? parent : node,
57
+ parsed
58
+ );
59
+ }).catch((e) => {
60
+ console.warn(`failed to read file: ${targetPath}`, e);
61
+ })
62
+ );
63
+ return "skip";
64
+ }
65
+ );
66
+ await Promise.all(queue);
67
+ }
68
+ return async (tree, file) => {
69
+ await update(tree, file.path, this, file.data._compiler);
70
+ };
71
+ }
72
+
73
+ export {
74
+ remarkInclude
75
+ };
@@ -34,21 +34,15 @@ var _runtime = {
34
34
  };
35
35
  function createMDXSource(docs, meta = []) {
36
36
  return {
37
- files: (rootDir) => resolveFiles({
37
+ files: () => resolveFiles({
38
38
  docs,
39
- meta,
40
- rootDir
39
+ meta
41
40
  })
42
41
  };
43
42
  }
44
- function resolveFiles({
45
- docs,
46
- meta,
47
- rootDir = ""
48
- }) {
43
+ function resolveFiles({ docs, meta }) {
49
44
  const outputs = [];
50
45
  for (const entry of docs) {
51
- if (!entry._file.path.startsWith(rootDir)) continue;
52
46
  outputs.push({
53
47
  type: "page",
54
48
  path: entry._file.path,
@@ -219,49 +219,56 @@ function remarkInclude() {
219
219
  const TagName = "include";
220
220
  async function update(tree, file, processor, compiler) {
221
221
  const queue = [];
222
- (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
223
- let specifier;
224
- const params = {};
225
- if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
226
- const value = flattenNode(node);
227
- if (value.length > 0) {
228
- for (const attr of node.attributes) {
229
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
230
- params[attr.name] = attr.value;
222
+ (0, import_unist_util_visit.visit)(
223
+ tree,
224
+ ["mdxJsxFlowElement", "mdxJsxTextElement"],
225
+ (node, _, parent) => {
226
+ let specifier;
227
+ const params = {};
228
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
229
+ const value = flattenNode(node);
230
+ if (value.length > 0) {
231
+ for (const attr of node.attributes) {
232
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
233
+ params[attr.name] = attr.value;
234
+ }
231
235
  }
236
+ specifier = value;
232
237
  }
233
- specifier = value;
234
238
  }
239
+ if (!specifier) return;
240
+ const targetPath = path.resolve(
241
+ "cwd" in params ? process.cwd() : path.dirname(file),
242
+ specifier
243
+ );
244
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
245
+ queue.push(
246
+ fs.readFile(targetPath).then(async (content) => {
247
+ compiler?.addDependency(targetPath);
248
+ if (asCode) {
249
+ const lang = params.lang ?? path.extname(specifier).slice(1);
250
+ Object.assign(node, {
251
+ type: "code",
252
+ lang,
253
+ meta: params.meta,
254
+ value: content.toString(),
255
+ data: {}
256
+ });
257
+ return;
258
+ }
259
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
260
+ await update(parsed, targetPath, processor, compiler);
261
+ Object.assign(
262
+ parent && parent.type === "paragraph" ? parent : node,
263
+ parsed
264
+ );
265
+ }).catch((e) => {
266
+ console.warn(`failed to read file: ${targetPath}`, e);
267
+ })
268
+ );
269
+ return "skip";
235
270
  }
236
- if (!specifier) return;
237
- const targetPath = path.resolve(
238
- "cwd" in params ? process.cwd() : path.dirname(file),
239
- specifier
240
- );
241
- const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
242
- queue.push(
243
- fs.readFile(targetPath).then(async (content) => {
244
- compiler?.addDependency(targetPath);
245
- if (asCode) {
246
- const lang = params.lang ?? path.extname(specifier).slice(1);
247
- Object.assign(node, {
248
- type: "code",
249
- lang,
250
- meta: params.meta,
251
- value: content.toString(),
252
- data: {}
253
- });
254
- return;
255
- }
256
- const parsed = processor.parse((0, import_gray_matter.default)(content).content);
257
- await update(parsed, targetPath, processor, compiler);
258
- Object.assign(node, parsed);
259
- }).catch((e) => {
260
- console.warn(`failed to read file: ${targetPath}`, e);
261
- })
262
- );
263
- return "skip";
264
- });
271
+ );
265
272
  await Promise.all(queue);
266
273
  }
267
274
  return async (tree, file) => {
@@ -1,4 +1,4 @@
1
- export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-P0QTVn7W.cjs';
1
+ export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-CGHfrlrJ.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@mdx-js/mdx';
@@ -1,4 +1,4 @@
1
- export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-P0QTVn7W.js';
1
+ export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-CGHfrlrJ.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@mdx-js/mdx';
@@ -4,7 +4,7 @@ import {
4
4
  } from "../chunk-KGLACICA.js";
5
5
  import {
6
6
  remarkInclude
7
- } from "../chunk-ITGWT23S.js";
7
+ } from "../chunk-MK7EXW7O.js";
8
8
  import {
9
9
  getDefaultMDXOptions
10
10
  } from "../chunk-IOENRFUX.js";
@@ -161,7 +161,7 @@ interface DocsCollection<DocSchema extends StandardSchemaV1 = StandardSchemaV1,
161
161
  docs: DocCollection<DocSchema, Async>;
162
162
  meta: MetaCollection<MetaSchema>;
163
163
  }
164
- declare function defineCollections<T extends 'doc' | 'meta', Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = false>(options: {
164
+ declare function defineCollections<T extends 'doc' | 'meta', Schema extends StandardSchemaV1 = StandardSchemaV1<unknown, any>, Async extends boolean = false>(options: {
165
165
  type: T;
166
166
  } & (T extends 'doc' ? DocCollection<Schema, Async> : MetaCollection<Schema>)): {
167
167
  type: T;
@@ -161,7 +161,7 @@ interface DocsCollection<DocSchema extends StandardSchemaV1 = StandardSchemaV1,
161
161
  docs: DocCollection<DocSchema, Async>;
162
162
  meta: MetaCollection<MetaSchema>;
163
163
  }
164
- declare function defineCollections<T extends 'doc' | 'meta', Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = false>(options: {
164
+ declare function defineCollections<T extends 'doc' | 'meta', Schema extends StandardSchemaV1 = StandardSchemaV1<unknown, any>, Async extends boolean = false>(options: {
165
165
  type: T;
166
166
  } & (T extends 'doc' ? DocCollection<Schema, Async> : MetaCollection<Schema>)): {
167
167
  type: T;
package/dist/index.cjs CHANGED
@@ -62,21 +62,15 @@ var _runtime = {
62
62
  };
63
63
  function createMDXSource(docs, meta = []) {
64
64
  return {
65
- files: (rootDir) => resolveFiles({
65
+ files: () => resolveFiles({
66
66
  docs,
67
- meta,
68
- rootDir
67
+ meta
69
68
  })
70
69
  };
71
70
  }
72
- function resolveFiles({
73
- docs,
74
- meta,
75
- rootDir = ""
76
- }) {
71
+ function resolveFiles({ docs, meta }) {
77
72
  const outputs = [];
78
73
  for (const entry of docs) {
79
- if (!entry._file.path.startsWith(rootDir)) continue;
80
74
  outputs.push({
81
75
  type: "page",
82
76
  path: entry._file.path,
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { B as BaseCollectionEntry } from './define-P0QTVn7W.cjs';
3
- import { R as Runtime } from './types-bWXuqsw9.cjs';
4
- export { a as RuntimeFile } from './types-bWXuqsw9.cjs';
2
+ import { B as BaseCollectionEntry } from './define-CGHfrlrJ.cjs';
3
+ import { R as Runtime } from './types-DCyuz-WB.cjs';
4
+ export { a as RuntimeFile } from './types-DCyuz-WB.cjs';
5
5
  import '@mdx-js/mdx';
6
6
  import 'mdx/types';
7
7
  import 'fumadocs-core/mdx-plugins';
@@ -22,6 +22,6 @@ interface ResolveOptions {
22
22
  meta: BaseCollectionEntry[];
23
23
  rootDir?: string;
24
24
  }
25
- declare function resolveFiles({ docs, meta, rootDir, }: ResolveOptions): VirtualFile[];
25
+ declare function resolveFiles({ docs, meta }: ResolveOptions): VirtualFile[];
26
26
 
27
27
  export { _runtime, createMDXSource, resolveFiles };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { B as BaseCollectionEntry } from './define-P0QTVn7W.js';
3
- import { R as Runtime } from './types-CJRGJLAg.js';
4
- export { a as RuntimeFile } from './types-CJRGJLAg.js';
2
+ import { B as BaseCollectionEntry } from './define-CGHfrlrJ.js';
3
+ import { R as Runtime } from './types-DfVJrYH1.js';
4
+ export { a as RuntimeFile } from './types-DfVJrYH1.js';
5
5
  import '@mdx-js/mdx';
6
6
  import 'mdx/types';
7
7
  import 'fumadocs-core/mdx-plugins';
@@ -22,6 +22,6 @@ interface ResolveOptions {
22
22
  meta: BaseCollectionEntry[];
23
23
  rootDir?: string;
24
24
  }
25
- declare function resolveFiles({ docs, meta, rootDir, }: ResolveOptions): VirtualFile[];
25
+ declare function resolveFiles({ docs, meta }: ResolveOptions): VirtualFile[];
26
26
 
27
27
  export { _runtime, createMDXSource, resolveFiles };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  _runtime,
3
3
  createMDXSource,
4
4
  resolveFiles
5
- } from "./chunk-IZURUUPO.js";
5
+ } from "./chunk-VFALQK6O.js";
6
6
  export {
7
7
  _runtime,
8
8
  createMDXSource,
@@ -200,10 +200,7 @@ function buildConfig(config) {
200
200
  null,
201
201
  {
202
202
  global: globalConfig,
203
- collections,
204
- _runtime: {
205
- files: /* @__PURE__ */ new Map()
206
- }
203
+ collections
207
204
  }
208
205
  ];
209
206
  }
@@ -273,49 +270,56 @@ function remarkInclude() {
273
270
  const TagName = "include";
274
271
  async function update(tree, file, processor, compiler) {
275
272
  const queue = [];
276
- (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
277
- let specifier;
278
- const params = {};
279
- if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
280
- const value = flattenNode(node);
281
- if (value.length > 0) {
282
- for (const attr of node.attributes) {
283
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
284
- params[attr.name] = attr.value;
273
+ (0, import_unist_util_visit.visit)(
274
+ tree,
275
+ ["mdxJsxFlowElement", "mdxJsxTextElement"],
276
+ (node, _, parent) => {
277
+ let specifier;
278
+ const params = {};
279
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
280
+ const value = flattenNode(node);
281
+ if (value.length > 0) {
282
+ for (const attr of node.attributes) {
283
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
284
+ params[attr.name] = attr.value;
285
+ }
285
286
  }
287
+ specifier = value;
286
288
  }
287
- specifier = value;
288
289
  }
290
+ if (!specifier) return;
291
+ const targetPath = path2.resolve(
292
+ "cwd" in params ? process.cwd() : path2.dirname(file),
293
+ specifier
294
+ );
295
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
296
+ queue.push(
297
+ fs2.readFile(targetPath).then(async (content) => {
298
+ compiler?.addDependency(targetPath);
299
+ if (asCode) {
300
+ const lang = params.lang ?? path2.extname(specifier).slice(1);
301
+ Object.assign(node, {
302
+ type: "code",
303
+ lang,
304
+ meta: params.meta,
305
+ value: content.toString(),
306
+ data: {}
307
+ });
308
+ return;
309
+ }
310
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
311
+ await update(parsed, targetPath, processor, compiler);
312
+ Object.assign(
313
+ parent && parent.type === "paragraph" ? parent : node,
314
+ parsed
315
+ );
316
+ }).catch((e) => {
317
+ console.warn(`failed to read file: ${targetPath}`, e);
318
+ })
319
+ );
320
+ return "skip";
289
321
  }
290
- if (!specifier) return;
291
- const targetPath = path2.resolve(
292
- "cwd" in params ? process.cwd() : path2.dirname(file),
293
- specifier
294
- );
295
- const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
296
- queue.push(
297
- fs2.readFile(targetPath).then(async (content) => {
298
- compiler?.addDependency(targetPath);
299
- if (asCode) {
300
- const lang = params.lang ?? path2.extname(specifier).slice(1);
301
- Object.assign(node, {
302
- type: "code",
303
- lang,
304
- meta: params.meta,
305
- value: content.toString(),
306
- data: {}
307
- });
308
- return;
309
- }
310
- const parsed = processor.parse((0, import_gray_matter.default)(content).content);
311
- await update(parsed, targetPath, processor, compiler);
312
- Object.assign(node, parsed);
313
- }).catch((e) => {
314
- console.warn(`failed to read file: ${targetPath}`, e);
315
- })
316
- );
317
- return "skip";
318
- });
322
+ );
319
323
  await Promise.all(queue);
320
324
  }
321
325
  return async (tree, file) => {
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  getConfigHash,
3
3
  loadConfig
4
- } from "./chunk-R6U7CJLB.js";
4
+ } from "./chunk-HFLDWPJA.js";
5
5
  import {
6
6
  validate
7
7
  } from "./chunk-KGLACICA.js";
8
8
  import {
9
9
  remarkInclude
10
- } from "./chunk-ITGWT23S.js";
11
- import "./chunk-SLCPEEMF.js";
10
+ } from "./chunk-MK7EXW7O.js";
11
+ import "./chunk-DRVUBK5B.js";
12
12
 
13
13
  // src/loader-mdx.ts
14
14
  import * as path2 from "node:path";
@@ -110,10 +110,7 @@ function buildConfig(config) {
110
110
  null,
111
111
  {
112
112
  global: globalConfig,
113
- collections,
114
- _runtime: {
115
- files: /* @__PURE__ */ new Map()
116
- }
113
+ collections
117
114
  }
118
115
  ];
119
116
  }
@@ -226,7 +223,10 @@ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`;
226
223
  }
227
224
 
228
225
  // src/map/file-cache.ts
229
- var map = /* @__PURE__ */ new Map();
226
+ var import_lru_cache = require("lru-cache");
227
+ var map = new import_lru_cache.LRUCache({
228
+ max: 200
229
+ });
230
230
  var fileCache = {
231
231
  read(namespace, path6) {
232
232
  return map.get(`${namespace}.${path6}`);
@@ -298,11 +298,9 @@ async function generateJS(configPath, config, outputPath, configHash) {
298
298
  name: "_source"
299
299
  })
300
300
  ];
301
- config._runtime.files.clear();
302
301
  const entries = Array.from(config.collections.entries());
303
302
  async function getEntries(collectionName, collection, files) {
304
303
  const items = files.map(async (file, i) => {
305
- config._runtime.files.set(file.absolutePath, collectionName);
306
304
  if (collection.type === "meta") {
307
305
  const cached = fileCache.read("generate-js", file.absolutePath);
308
306
  if (cached) return cached;
@@ -2,11 +2,11 @@ import {
2
2
  findConfigFile,
3
3
  getConfigHash,
4
4
  loadConfig
5
- } from "../chunk-R6U7CJLB.js";
5
+ } from "../chunk-HFLDWPJA.js";
6
6
  import {
7
7
  validate
8
8
  } from "../chunk-KGLACICA.js";
9
- import "../chunk-SLCPEEMF.js";
9
+ import "../chunk-DRVUBK5B.js";
10
10
 
11
11
  // src/next/create.ts
12
12
  import path3 from "node:path";
@@ -31,7 +31,10 @@ function getTypeFromPath(path5) {
31
31
  }
32
32
 
33
33
  // src/map/file-cache.ts
34
- var map = /* @__PURE__ */ new Map();
34
+ import { LRUCache } from "lru-cache";
35
+ var map = new LRUCache({
36
+ max: 200
37
+ });
35
38
  var fileCache = {
36
39
  read(namespace, path5) {
37
40
  return map.get(`${namespace}.${path5}`);
@@ -103,11 +106,9 @@ async function generateJS(configPath, config, outputPath, configHash) {
103
106
  name: "_source"
104
107
  })
105
108
  ];
106
- config._runtime.files.clear();
107
109
  const entries = Array.from(config.collections.entries());
108
110
  async function getEntries(collectionName, collection, files) {
109
111
  const items = files.map(async (file, i) => {
110
- config._runtime.files.set(file.absolutePath, collectionName);
111
112
  if (collection.type === "meta") {
112
113
  const cached = fileCache.read("generate-js", file.absolutePath);
113
114
  if (cached) return cached;
@@ -52,49 +52,56 @@ function remarkInclude() {
52
52
  const TagName = "include";
53
53
  async function update(tree, file, processor, compiler) {
54
54
  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;
55
+ (0, import_unist_util_visit.visit)(
56
+ tree,
57
+ ["mdxJsxFlowElement", "mdxJsxTextElement"],
58
+ (node, _, parent) => {
59
+ let specifier;
60
+ const params = {};
61
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
62
+ const value = flattenNode(node);
63
+ if (value.length > 0) {
64
+ for (const attr of node.attributes) {
65
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
66
+ params[attr.name] = attr.value;
67
+ }
64
68
  }
69
+ specifier = value;
65
70
  }
66
- specifier = value;
67
71
  }
72
+ if (!specifier) return;
73
+ const targetPath = path.resolve(
74
+ "cwd" in params ? process.cwd() : path.dirname(file),
75
+ specifier
76
+ );
77
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
78
+ queue.push(
79
+ fs.readFile(targetPath).then(async (content) => {
80
+ compiler?.addDependency(targetPath);
81
+ if (asCode) {
82
+ const lang = params.lang ?? path.extname(specifier).slice(1);
83
+ Object.assign(node, {
84
+ type: "code",
85
+ lang,
86
+ meta: params.meta,
87
+ value: content.toString(),
88
+ data: {}
89
+ });
90
+ return;
91
+ }
92
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
93
+ await update(parsed, targetPath, processor, compiler);
94
+ Object.assign(
95
+ parent && parent.type === "paragraph" ? parent : node,
96
+ parsed
97
+ );
98
+ }).catch((e) => {
99
+ console.warn(`failed to read file: ${targetPath}`, e);
100
+ })
101
+ );
102
+ return "skip";
68
103
  }
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
- });
104
+ );
98
105
  await Promise.all(queue);
99
106
  }
100
107
  return async (tree, file) => {
@@ -141,21 +148,15 @@ var _runtime = {
141
148
  };
142
149
  function createMDXSource(docs, meta = []) {
143
150
  return {
144
- files: (rootDir) => resolveFiles({
151
+ files: () => resolveFiles({
145
152
  docs,
146
- meta,
147
- rootDir
153
+ meta
148
154
  })
149
155
  };
150
156
  }
151
- function resolveFiles({
152
- docs,
153
- meta,
154
- rootDir = ""
155
- }) {
157
+ function resolveFiles({ docs, meta }) {
156
158
  const outputs = [];
157
159
  for (const entry of docs) {
158
- if (!entry._file.path.startsWith(rootDir)) continue;
159
160
  outputs.push({
160
161
  type: "page",
161
162
  path: entry._file.path,
@@ -203,10 +204,7 @@ function buildConfig(config) {
203
204
  null,
204
205
  {
205
206
  global: globalConfig,
206
- collections,
207
- _runtime: {
208
- files: /* @__PURE__ */ new Map()
209
- }
207
+ collections
210
208
  }
211
209
  ];
212
210
  }
@@ -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, b as RuntimeAsync } from '../types-DCyuz-WB.cjs';
2
+ import '../define-CGHfrlrJ.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, b as RuntimeAsync } from '../types-DfVJrYH1.js';
2
+ import '../define-CGHfrlrJ.js';
3
3
  import '@mdx-js/mdx';
4
4
  import 'mdx/types';
5
5
  import 'fumadocs-core/mdx-plugins';
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  _runtime,
3
3
  createMDXSource
4
- } from "../chunk-IZURUUPO.js";
4
+ } from "../chunk-VFALQK6O.js";
5
5
  import {
6
6
  remarkInclude
7
- } from "../chunk-ITGWT23S.js";
7
+ } from "../chunk-MK7EXW7O.js";
8
8
  import {
9
9
  buildConfig
10
- } from "../chunk-SLCPEEMF.js";
10
+ } from "../chunk-DRVUBK5B.js";
11
11
 
12
12
  // src/runtime/async.ts
13
13
  import { createCompiler } from "@fumadocs/mdx-remote";
@@ -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, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-CGHfrlrJ.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
  };
@@ -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, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-CGHfrlrJ.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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.5.7",
3
+ "version": "11.5.8",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -46,10 +46,11 @@
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",
49
+ "esbuild": "^0.25.2",
50
50
  "estree-util-value-to-estree": "^3.3.2",
51
51
  "fast-glob": "^3.3.3",
52
52
  "gray-matter": "^4.0.3",
53
+ "lru-cache": "^11.1.0",
53
54
  "unist-util-visit": "^5.0.0",
54
55
  "zod": "^3.24.2"
55
56
  },
@@ -57,15 +58,15 @@
57
58
  "@types/cross-spawn": "^6.0.6",
58
59
  "@types/mdast": "^4.0.3",
59
60
  "@types/mdx": "^2.0.13",
60
- "@types/react": "^19.0.11",
61
+ "@types/react": "^19.1.0",
61
62
  "mdast-util-mdx-jsx": "^3.2.0",
62
- "next": "^15.2.3",
63
+ "next": "^15.2.4",
63
64
  "unified": "^11.0.5",
64
65
  "vfile": "^6.0.3",
65
66
  "webpack": "^5.97.1",
66
- "@fumadocs/mdx-remote": "1.2.1",
67
+ "@fumadocs/mdx-remote": "1.3.0",
67
68
  "eslint-config-custom": "0.0.0",
68
- "fumadocs-core": "15.1.1",
69
+ "fumadocs-core": "15.2.4",
69
70
  "tsconfig": "0.0.0"
70
71
  },
71
72
  "peerDependencies": {
@@ -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
- };