fumadocs-mdx 11.3.1 → 11.4.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.
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // src/mdx-plugins/remark-exports.ts
34
+ function remarkMdxExport({ values }) {
35
+ return (tree, vfile) => {
36
+ for (const name of values) {
37
+ if (!(name in vfile.data)) return;
38
+ tree.children.unshift(getMdastExport(name, vfile.data[name]));
39
+ }
40
+ };
41
+ }
42
+ function getMdastExport(name, value) {
43
+ return {
44
+ type: "mdxjsEsm",
45
+ value: "",
46
+ data: {
47
+ estree: {
48
+ type: "Program",
49
+ sourceType: "module",
50
+ body: [
51
+ {
52
+ type: "ExportNamedDeclaration",
53
+ specifiers: [],
54
+ source: null,
55
+ declaration: {
56
+ type: "VariableDeclaration",
57
+ kind: "let",
58
+ declarations: [
59
+ {
60
+ type: "VariableDeclarator",
61
+ id: {
62
+ type: "Identifier",
63
+ name
64
+ },
65
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ };
74
+ }
75
+ var import_estree_util_value_to_estree;
76
+ var init_remark_exports = __esm({
77
+ "src/mdx-plugins/remark-exports.ts"() {
78
+ "use strict";
79
+ import_estree_util_value_to_estree = require("estree-util-value-to-estree");
80
+ }
81
+ });
82
+
83
+ // src/utils/mdx-options.ts
84
+ var mdx_options_exports = {};
85
+ __export(mdx_options_exports, {
86
+ getDefaultMDXOptions: () => getDefaultMDXOptions
87
+ });
88
+ function pluginOption(def, options = []) {
89
+ const list = def(Array.isArray(options) ? options : []).filter(
90
+ Boolean
91
+ );
92
+ if (typeof options === "function") {
93
+ return options(list);
94
+ }
95
+ return list;
96
+ }
97
+ function getDefaultMDXOptions({
98
+ valueToExport = [],
99
+ rehypeCodeOptions,
100
+ remarkImageOptions,
101
+ remarkHeadingOptions,
102
+ remarkStructureOptions,
103
+ remarkCodeTabOptions,
104
+ ...mdxOptions
105
+ }) {
106
+ const mdxExports = [
107
+ "structuredData",
108
+ "frontmatter",
109
+ "lastModified",
110
+ ...valueToExport
111
+ ];
112
+ const remarkPlugins = pluginOption(
113
+ (v) => [
114
+ plugins.remarkGfm,
115
+ [
116
+ plugins.remarkHeading,
117
+ {
118
+ generateToc: false,
119
+ ...remarkHeadingOptions
120
+ }
121
+ ],
122
+ remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
123
+ // Fumadocs 14 compatibility
124
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && plugins.remarkCodeTab,
125
+ ...v,
126
+ remarkStructureOptions !== false && [
127
+ plugins.remarkStructure,
128
+ remarkStructureOptions
129
+ ],
130
+ [remarkMdxExport, { values: mdxExports }]
131
+ ],
132
+ mdxOptions.remarkPlugins
133
+ );
134
+ const rehypePlugins = pluginOption(
135
+ (v) => [
136
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
137
+ ...v,
138
+ [plugins.rehypeToc]
139
+ ],
140
+ mdxOptions.rehypePlugins
141
+ );
142
+ return {
143
+ ...mdxOptions,
144
+ remarkPlugins,
145
+ rehypePlugins
146
+ };
147
+ }
148
+ var plugins;
149
+ var init_mdx_options = __esm({
150
+ "src/utils/mdx-options.ts"() {
151
+ "use strict";
152
+ plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
153
+ init_remark_exports();
154
+ }
155
+ });
156
+
157
+ // src/runtime/async.ts
158
+ var async_exports = {};
159
+ __export(async_exports, {
160
+ asyncFiles: () => asyncFiles,
161
+ buildConfig: () => buildConfig
162
+ });
163
+ module.exports = __toCommonJS(async_exports);
164
+ var import_mdx_remote = require("@fumadocs/mdx-remote");
165
+ var fs2 = __toESM(require("fs/promises"), 1);
166
+
167
+ // src/mdx-plugins/remark-include.ts
168
+ var import_unist_util_visit = require("unist-util-visit");
169
+ var path = __toESM(require("path"), 1);
170
+ var fs = __toESM(require("fs/promises"), 1);
171
+ var import_gray_matter = __toESM(require("gray-matter"), 1);
172
+ function remarkInclude() {
173
+ const TagName = "include";
174
+ async function update(tree, file, processor, compiler) {
175
+ const queue = [];
176
+ (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
177
+ let specifier;
178
+ if (node.type === "paragraph" && node.children.length === 3) {
179
+ const [open, content, closure] = node.children;
180
+ if (open.type === "html" && open.value === `<${TagName}>` && content.type === "text" && closure.type === "html" && closure.value === `</${TagName}>`) {
181
+ specifier = content.value.trim();
182
+ }
183
+ } else if (node.type === "paragraph" && node.children.length === 1) {
184
+ const child = node.children[0];
185
+ if (child.type === "mdxJsxTextElement" && child.name === TagName) {
186
+ const text = child.children.at(0);
187
+ if (text && text.type === "text") {
188
+ specifier = text.value;
189
+ }
190
+ }
191
+ }
192
+ if (node.type === "mdxJsxFlowElement" && node.name === TagName) {
193
+ const child = node.children.at(0);
194
+ if (child && child.type === "text") {
195
+ specifier = child.value;
196
+ }
197
+ }
198
+ if (!specifier) return;
199
+ const targetPath = path.resolve(path.dirname(file), specifier);
200
+ queue.push(
201
+ fs.readFile(targetPath).then(async (content) => {
202
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
203
+ compiler?.addDependency(targetPath);
204
+ await update(parsed, targetPath, processor, compiler);
205
+ Object.assign(node, parsed);
206
+ })
207
+ );
208
+ return "skip";
209
+ });
210
+ await Promise.all(queue);
211
+ }
212
+ return async (tree, file) => {
213
+ await update(tree, file.path, this, file.data._compiler);
214
+ };
215
+ }
216
+
217
+ // src/runtime/async.ts
218
+ var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
219
+
220
+ // src/config/build.ts
221
+ function buildConfig(config) {
222
+ const collections = /* @__PURE__ */ new Map();
223
+ let globalConfig;
224
+ for (const [k, v] of Object.entries(config)) {
225
+ if (!v) {
226
+ continue;
227
+ }
228
+ if (typeof v === "object" && "_doc" in v && v._doc === "collections") {
229
+ collections.set(
230
+ k,
231
+ v
232
+ );
233
+ continue;
234
+ }
235
+ if (k === "default") {
236
+ globalConfig = v;
237
+ continue;
238
+ }
239
+ return [
240
+ `Unknown export "${k}", you can only export collections from source configuration file.`,
241
+ null
242
+ ];
243
+ }
244
+ let cachedMdxOptions;
245
+ return [
246
+ null,
247
+ {
248
+ global: globalConfig,
249
+ collections,
250
+ async getDefaultMDXOptions() {
251
+ if (cachedMdxOptions) return cachedMdxOptions;
252
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
253
+ const mdxOptions = globalConfig?.mdxOptions ?? {};
254
+ if (typeof mdxOptions === "function") {
255
+ cachedMdxOptions = getDefaultMDXOptions2(await mdxOptions());
256
+ } else {
257
+ cachedMdxOptions = getDefaultMDXOptions2(mdxOptions);
258
+ }
259
+ return cachedMdxOptions;
260
+ },
261
+ _runtime: {
262
+ files: /* @__PURE__ */ new Map()
263
+ }
264
+ }
265
+ ];
266
+ }
267
+
268
+ // src/runtime/async.ts
269
+ function asyncFiles(files, collection, config) {
270
+ async function init() {
271
+ const col = config.collections.get(collection);
272
+ let mdxOptions;
273
+ if (col?.type === "doc" && col.mdxOptions) {
274
+ mdxOptions = col.mdxOptions;
275
+ } else {
276
+ const options = typeof config.global?.mdxOptions === "function" ? await config.global.mdxOptions() : config.global?.mdxOptions;
277
+ const remarkPlugins = options?.remarkPlugins ?? [];
278
+ mdxOptions = {
279
+ ...options,
280
+ remarkPlugins: (v) => typeof remarkPlugins === "function" ? [remarkInclude, ...remarkPlugins(v), import_mdx_plugins.remarkStructure] : [remarkInclude, ...v, ...remarkPlugins, import_mdx_plugins.remarkStructure]
281
+ };
282
+ }
283
+ return (0, import_mdx_remote.createCompiler)(mdxOptions);
284
+ }
285
+ const initCompiler = init();
286
+ return files.map(({ file, frontmatter }) => {
287
+ return {
288
+ ...frontmatter,
289
+ _file: file,
290
+ async load() {
291
+ const compiler = await initCompiler;
292
+ const out = await compiler.compile({
293
+ source: (await fs2.readFile(file.absolutePath)).toString(),
294
+ filePath: file.absolutePath
295
+ });
296
+ return {
297
+ body: out.body,
298
+ toc: out.toc,
299
+ structuredData: out.vfile.data.structuredData,
300
+ _exports: out.exports ?? {}
301
+ };
302
+ }
303
+ };
304
+ });
305
+ }
306
+ // Annotate the CommonJS export names for ESM import in node:
307
+ 0 && (module.exports = {
308
+ asyncFiles,
309
+ buildConfig
310
+ });
@@ -0,0 +1,35 @@
1
+ import { G as GlobalConfig, F as FileInfo } from '../build-mdx-o0kbHSlp.cjs';
2
+ import { D as DocCollection, M as MetaCollection } from '../define-BB9hRiTI.cjs';
3
+ import { ProcessorOptions } from '@mdx-js/mdx';
4
+ import 'zod';
5
+ import 'mdx/types';
6
+ import 'fumadocs-core/mdx-plugins';
7
+ import 'fumadocs-core/server';
8
+ import 'unified';
9
+ import 'react';
10
+
11
+ interface LoadedConfig {
12
+ collections: Map<string, InternalDocCollection | InternalMetaCollection>;
13
+ getDefaultMDXOptions: () => Promise<ProcessorOptions>;
14
+ global?: GlobalConfig;
15
+ _runtime: {
16
+ /**
17
+ * Absolute file path and their associated collections
18
+ */
19
+ files: Map<string, string>;
20
+ };
21
+ }
22
+ type InternalDocCollection = DocCollection;
23
+ type InternalMetaCollection = MetaCollection;
24
+
25
+ declare function buildConfig(config: Record<string, unknown>): [err: string, value: null] | [err: null, value: LoadedConfig];
26
+
27
+ /**
28
+ * @internal
29
+ */
30
+ declare function asyncFiles(files: {
31
+ file: FileInfo;
32
+ frontmatter: Record<string, unknown>;
33
+ }[], collection: string, config: LoadedConfig): unknown[];
34
+
35
+ export { asyncFiles, buildConfig };
@@ -0,0 +1,35 @@
1
+ import { G as GlobalConfig, F as FileInfo } from '../build-mdx-o0kbHSlp.js';
2
+ import { D as DocCollection, M as MetaCollection } from '../define-D3l733EX.js';
3
+ import { ProcessorOptions } from '@mdx-js/mdx';
4
+ import 'zod';
5
+ import 'mdx/types';
6
+ import 'fumadocs-core/mdx-plugins';
7
+ import 'fumadocs-core/server';
8
+ import 'unified';
9
+ import 'react';
10
+
11
+ interface LoadedConfig {
12
+ collections: Map<string, InternalDocCollection | InternalMetaCollection>;
13
+ getDefaultMDXOptions: () => Promise<ProcessorOptions>;
14
+ global?: GlobalConfig;
15
+ _runtime: {
16
+ /**
17
+ * Absolute file path and their associated collections
18
+ */
19
+ files: Map<string, string>;
20
+ };
21
+ }
22
+ type InternalDocCollection = DocCollection;
23
+ type InternalMetaCollection = MetaCollection;
24
+
25
+ declare function buildConfig(config: Record<string, unknown>): [err: string, value: null] | [err: null, value: LoadedConfig];
26
+
27
+ /**
28
+ * @internal
29
+ */
30
+ declare function asyncFiles(files: {
31
+ file: FileInfo;
32
+ frontmatter: Record<string, unknown>;
33
+ }[], collection: string, config: LoadedConfig): unknown[];
34
+
35
+ export { asyncFiles, buildConfig };
@@ -0,0 +1,54 @@
1
+ import {
2
+ remarkInclude
3
+ } from "../chunk-PY2KKTR2.js";
4
+ import {
5
+ buildConfig
6
+ } from "../chunk-2DJQ3DOD.js";
7
+
8
+ // src/runtime/async.ts
9
+ import { createCompiler } from "@fumadocs/mdx-remote";
10
+ import * as fs from "node:fs/promises";
11
+ import {
12
+ remarkStructure
13
+ } from "fumadocs-core/mdx-plugins";
14
+ function asyncFiles(files, collection, config) {
15
+ async function init() {
16
+ const col = config.collections.get(collection);
17
+ let mdxOptions;
18
+ if (col?.type === "doc" && col.mdxOptions) {
19
+ mdxOptions = col.mdxOptions;
20
+ } else {
21
+ const options = typeof config.global?.mdxOptions === "function" ? await config.global.mdxOptions() : config.global?.mdxOptions;
22
+ const remarkPlugins = options?.remarkPlugins ?? [];
23
+ mdxOptions = {
24
+ ...options,
25
+ remarkPlugins: (v) => typeof remarkPlugins === "function" ? [remarkInclude, ...remarkPlugins(v), remarkStructure] : [remarkInclude, ...v, ...remarkPlugins, remarkStructure]
26
+ };
27
+ }
28
+ return createCompiler(mdxOptions);
29
+ }
30
+ const initCompiler = init();
31
+ return files.map(({ file, frontmatter }) => {
32
+ return {
33
+ ...frontmatter,
34
+ _file: file,
35
+ async load() {
36
+ const compiler = await initCompiler;
37
+ const out = await compiler.compile({
38
+ source: (await fs.readFile(file.absolutePath)).toString(),
39
+ filePath: file.absolutePath
40
+ });
41
+ return {
42
+ body: out.body,
43
+ toc: out.toc,
44
+ structuredData: out.vfile.data.structuredData,
45
+ _exports: out.exports ?? {}
46
+ };
47
+ }
48
+ };
49
+ });
50
+ }
51
+ export {
52
+ asyncFiles,
53
+ buildConfig
54
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.3.1",
3
+ "version": "11.4.0",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -23,6 +23,10 @@
23
23
  "types": "./dist/next/index.d.ts",
24
24
  "require": "./dist/next/index.cjs"
25
25
  },
26
+ "./runtime/async": {
27
+ "import": "./dist/runtime/async.js",
28
+ "types": "./dist/runtime/async.d.ts"
29
+ },
26
30
  ".": {
27
31
  "import": "./dist/index.js",
28
32
  "types": "./dist/index.d.ts",
@@ -54,19 +58,26 @@
54
58
  "@types/mdast": "^4.0.3",
55
59
  "@types/mdx": "^2.0.13",
56
60
  "@types/micromatch": "^4.0.9",
57
- "@types/react": "^19.0.7",
61
+ "@types/react": "^19.0.8",
58
62
  "mdast-util-mdx-jsx": "^3.2.0",
59
- "next": "^15.1.4",
63
+ "next": "^15.1.6",
60
64
  "unified": "^11.0.5",
61
65
  "vfile": "^6.0.3",
62
66
  "webpack": "^5.97.1",
67
+ "@fumadocs/mdx-remote": "1.1.3",
63
68
  "eslint-config-custom": "0.0.0",
64
- "fumadocs-core": "14.7.4",
69
+ "fumadocs-core": "15.0.1",
65
70
  "tsconfig": "0.0.0"
66
71
  },
67
72
  "peerDependencies": {
68
- "fumadocs-core": "^14.0.0",
69
- "next": "14.x.x || 15.x.x"
73
+ "fumadocs-core": "^14.0.0 || ^15.0.0",
74
+ "next": "14.x.x || 15.x.x",
75
+ "@fumadocs/mdx-remote": "1.1.3"
76
+ },
77
+ "peerDependenciesMeta": {
78
+ "@fumadocs/mdx-remote": {
79
+ "optional": true
80
+ }
70
81
  },
71
82
  "publishConfig": {
72
83
  "access": "public"