fumadocs-mdx 14.2.2 → 14.2.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.
Files changed (116) hide show
  1. package/dist/adapter-DG-viEbG.js +144 -0
  2. package/dist/adapter-DG-viEbG.js.map +1 -0
  3. package/dist/bin.d.ts +1 -1
  4. package/dist/bin.js +21 -12
  5. package/dist/bin.js.map +1 -0
  6. package/dist/build-BTTNEFmV.js +100 -0
  7. package/dist/build-BTTNEFmV.js.map +1 -0
  8. package/dist/build-mdx-10MrLupc.d.ts +53 -0
  9. package/dist/build-mdx-10MrLupc.d.ts.map +1 -0
  10. package/dist/build-mdx-BVeBo4jT.js +153 -0
  11. package/dist/build-mdx-BVeBo4jT.js.map +1 -0
  12. package/dist/build-mdx-ChjP7zAn.js +5 -0
  13. package/dist/bun/index.d.ts +10 -21
  14. package/dist/bun/index.d.ts.map +1 -0
  15. package/dist/bun/index.js +30 -49
  16. package/dist/bun/index.js.map +1 -0
  17. package/dist/codegen-DleOVLNr.js +101 -0
  18. package/dist/codegen-DleOVLNr.js.map +1 -0
  19. package/dist/config/index.d.ts +2 -18
  20. package/dist/config/index.js +50 -53
  21. package/dist/config/index.js.map +1 -0
  22. package/dist/core-DG43f_AU.d.ts +364 -0
  23. package/dist/core-DG43f_AU.d.ts.map +1 -0
  24. package/dist/core-DjldE3H9.js +212 -0
  25. package/dist/core-DjldE3H9.js.map +1 -0
  26. package/dist/fuma-matter-CHgJa_-B.js +27 -0
  27. package/dist/fuma-matter-CHgJa_-B.js.map +1 -0
  28. package/dist/index-Bc_4I1HE.d.ts +12 -0
  29. package/dist/index-Bc_4I1HE.d.ts.map +1 -0
  30. package/dist/index-file-D9HsrWU_.js +264 -0
  31. package/dist/index-file-D9HsrWU_.js.map +1 -0
  32. package/dist/index.d.ts +3 -61
  33. package/dist/index.js +1 -0
  34. package/dist/load-from-file-B7Rswy9i.js +5 -0
  35. package/dist/load-from-file-Doc98oEB.js +38 -0
  36. package/dist/load-from-file-Doc98oEB.js.map +1 -0
  37. package/dist/loaders-BVwYfelL.js +7 -0
  38. package/dist/loaders-BVwYfelL.js.map +1 -0
  39. package/dist/mdx-DMZ9tsAa.js +91 -0
  40. package/dist/mdx-DMZ9tsAa.js.map +1 -0
  41. package/dist/meta-DyieTM4Z.js +81 -0
  42. package/dist/meta-DyieTM4Z.js.map +1 -0
  43. package/dist/next/index.cjs +863 -1076
  44. package/dist/next/index.d.ts +17 -28
  45. package/dist/next/index.d.ts.map +1 -0
  46. package/dist/next/index.js +141 -170
  47. package/dist/next/index.js.map +1 -0
  48. package/dist/node/loader.d.ts +4 -2
  49. package/dist/node/loader.d.ts.map +1 -0
  50. package/dist/node/loader.js +26 -38
  51. package/dist/node/loader.js.map +1 -0
  52. package/dist/plugins/index-file.d.ts +2 -14
  53. package/dist/plugins/index-file.js +5 -8
  54. package/dist/plugins/json-schema.d.ts +14 -23
  55. package/dist/plugins/json-schema.d.ts.map +1 -0
  56. package/dist/plugins/json-schema.js +70 -78
  57. package/dist/plugins/json-schema.js.map +1 -0
  58. package/dist/plugins/last-modified.d.ts +21 -32
  59. package/dist/plugins/last-modified.d.ts.map +1 -0
  60. package/dist/plugins/last-modified.js +70 -78
  61. package/dist/plugins/last-modified.js.map +1 -0
  62. package/dist/preset-gmDZnBcg.js +61 -0
  63. package/dist/preset-gmDZnBcg.js.map +1 -0
  64. package/dist/remark-include-D3G3mAnv.js +247 -0
  65. package/dist/remark-include-D3G3mAnv.js.map +1 -0
  66. package/dist/runtime/browser.d.ts +32 -41
  67. package/dist/runtime/browser.d.ts.map +1 -0
  68. package/dist/runtime/browser.js +56 -63
  69. package/dist/runtime/browser.js.map +1 -0
  70. package/dist/runtime/dynamic.d.ts +13 -21
  71. package/dist/runtime/dynamic.d.ts.map +1 -0
  72. package/dist/runtime/dynamic.js +64 -76
  73. package/dist/runtime/dynamic.js.map +1 -0
  74. package/dist/runtime/server.d.ts +2 -14
  75. package/dist/runtime/server.js +111 -8
  76. package/dist/runtime/server.js.map +1 -0
  77. package/dist/runtime/types.d.ts +2 -61
  78. package/dist/runtime/types.js +1 -0
  79. package/dist/types-B6myALSk.d.ts +63 -0
  80. package/dist/types-B6myALSk.d.ts.map +1 -0
  81. package/dist/vite/index.d.ts +28 -39
  82. package/dist/vite/index.d.ts.map +1 -0
  83. package/dist/vite/index.js +79 -122
  84. package/dist/vite/index.js.map +1 -0
  85. package/dist/webpack/mdx.d.ts +6 -3
  86. package/dist/webpack/mdx.d.ts.map +1 -0
  87. package/dist/webpack/mdx.js +21 -34
  88. package/dist/webpack/mdx.js.map +1 -0
  89. package/dist/webpack/meta.d.ts +6 -3
  90. package/dist/webpack/meta.d.ts.map +1 -0
  91. package/dist/webpack/meta.js +23 -37
  92. package/dist/webpack/meta.js.map +1 -0
  93. package/dist/webpack--VSEE6Zp.js +15 -0
  94. package/dist/webpack--VSEE6Zp.js.map +1 -0
  95. package/loader-mdx.cjs +1 -3
  96. package/loader-meta.cjs +1 -3
  97. package/package.json +38 -38
  98. package/dist/build-mdx-5XLFMP5P.js +0 -8
  99. package/dist/chunk-257RZJEQ.js +0 -17
  100. package/dist/chunk-2PY3JUIC.js +0 -126
  101. package/dist/chunk-4EUH5CD2.js +0 -173
  102. package/dist/chunk-4JSFLXXT.js +0 -8
  103. package/dist/chunk-5OBUOALK.js +0 -141
  104. package/dist/chunk-DTFUANSF.js +0 -40
  105. package/dist/chunk-KWSETXYC.js +0 -274
  106. package/dist/chunk-OLD35ARB.js +0 -116
  107. package/dist/chunk-S7KOJHHO.js +0 -89
  108. package/dist/chunk-STLEUNK7.js +0 -335
  109. package/dist/chunk-USQZ5OLE.js +0 -116
  110. package/dist/chunk-VWJKRQZR.js +0 -19
  111. package/dist/chunk-WFDF56IJ.js +0 -290
  112. package/dist/chunk-WSQ23PNV.js +0 -179
  113. package/dist/chunk-ZAYZWFWP.js +0 -89
  114. package/dist/core-X5ggQtBM.d.ts +0 -350
  115. package/dist/index-BqkSNsGO.d.ts +0 -8
  116. package/dist/load-from-file-FHW724YY.js +0 -8
@@ -1,335 +0,0 @@
1
- import {
2
- createCodegen,
3
- ident,
4
- slash
5
- } from "./chunk-2PY3JUIC.js";
6
- import {
7
- fumaMatter
8
- } from "./chunk-VWJKRQZR.js";
9
-
10
- // src/plugins/index-file.ts
11
- import path2 from "path";
12
- import { glob } from "tinyglobby";
13
-
14
- // src/utils/fs-cache.ts
15
- import fs from "fs/promises";
16
- import path from "path";
17
- var map = /* @__PURE__ */ new Map();
18
- function createFSCache() {
19
- return {
20
- read(file) {
21
- const fullPath = toFullPath(file);
22
- const cached = map.get(fullPath);
23
- if (cached) return cached;
24
- const read = fs.readFile(fullPath).then((s) => s.toString());
25
- map.set(fullPath, read);
26
- return read;
27
- },
28
- delete(file) {
29
- map.delete(toFullPath(file));
30
- }
31
- };
32
- }
33
- function toFullPath(file) {
34
- if (path.isAbsolute(file)) {
35
- return path.relative(process.cwd(), file);
36
- }
37
- return file;
38
- }
39
-
40
- // src/plugins/index-file.ts
41
- import { createHash } from "crypto";
42
- var indexFileCache = createFSCache();
43
- function indexFile(options = {}) {
44
- const {
45
- target = "default",
46
- addJsExtension,
47
- browser = true,
48
- dynamic = true
49
- } = options;
50
- let dynamicCollections;
51
- function isDynamic(collection) {
52
- return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
53
- }
54
- function generateConfigs(core) {
55
- const serverOptions = {};
56
- const typeConfigs = [
57
- 'import("fumadocs-mdx/runtime/types").InternalTypeConfig'
58
- ];
59
- const ctx = core.getPluginContext();
60
- for (const plugin of core.getPlugins()) {
61
- const indexFilePlugin = plugin["index-file"];
62
- if (!indexFilePlugin) continue;
63
- indexFilePlugin.serverOptions?.call(ctx, serverOptions);
64
- const config = indexFilePlugin.generateTypeConfig?.call(ctx);
65
- if (config) typeConfigs.push(config);
66
- }
67
- return {
68
- serverOptions,
69
- tc: typeConfigs.join(" & ")
70
- };
71
- }
72
- return {
73
- name: "index-file",
74
- config() {
75
- dynamicCollections = this.core.getCollections().filter(isDynamic);
76
- },
77
- configureServer(server) {
78
- if (!server.watcher) return;
79
- server.watcher.on("all", async (event, file) => {
80
- indexFileCache.delete(file);
81
- if (dynamicCollections.length === 0) {
82
- if (target === "vite") return;
83
- if (target === "default" && event === "change") return;
84
- }
85
- const updatedCollection = this.core.getCollections().find((collection) => collection.hasFile(file));
86
- if (!updatedCollection) return;
87
- if (!isDynamic(updatedCollection)) {
88
- if (target === "vite") return;
89
- if (target === "default" && event === "change") return;
90
- }
91
- await this.core.emit({
92
- filterPlugin: (plugin) => plugin.name === "index-file",
93
- filterWorkspace: () => false,
94
- write: true
95
- });
96
- });
97
- },
98
- async emit() {
99
- const globCache = /* @__PURE__ */ new Map();
100
- const { workspace, outDir } = this.core.getOptions();
101
- const { serverOptions, tc } = generateConfigs(this.core);
102
- const toEmitEntry = async (path3, content) => {
103
- const codegen = createCodegen({
104
- target,
105
- outDir,
106
- jsExtension: addJsExtension,
107
- globCache
108
- });
109
- await content({
110
- core: this.core,
111
- codegen,
112
- serverOptions,
113
- tc,
114
- workspace: workspace?.name
115
- });
116
- return {
117
- path: path3,
118
- content: codegen.toString()
119
- };
120
- };
121
- const out = [
122
- toEmitEntry("server.ts", generateServerIndexFile)
123
- ];
124
- if (dynamic)
125
- out.push(toEmitEntry("dynamic.ts", generateDynamicIndexFile));
126
- if (browser)
127
- out.push(toEmitEntry("browser.ts", generateBrowserIndexFile));
128
- return await Promise.all(out);
129
- }
130
- };
131
- }
132
- async function generateServerIndexFile(ctx) {
133
- const { core, codegen, serverOptions, tc } = ctx;
134
- codegen.lines.push(
135
- `import { server } from 'fumadocs-mdx/runtime/server';`,
136
- `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
137
- "",
138
- `const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
139
- );
140
- async function generateCollectionObject(collection) {
141
- const base = getBase(collection);
142
- switch (collection.type) {
143
- case "docs": {
144
- if (collection.docs.dynamic) return;
145
- if (collection.docs.async) {
146
- const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
147
- generateMetaCollectionGlob(ctx, collection.meta, true),
148
- generateDocCollectionFrontmatterGlob(ctx, collection.docs, true),
149
- generateDocCollectionGlob(ctx, collection.docs)
150
- ]);
151
- return `await create.docsLazy("${collection.name}", "${base}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
152
- }
153
- const [metaGlob, docGlob] = await Promise.all([
154
- generateMetaCollectionGlob(ctx, collection.meta, true),
155
- generateDocCollectionGlob(ctx, collection.docs, true)
156
- ]);
157
- return `await create.docs("${collection.name}", "${base}", ${metaGlob}, ${docGlob})`;
158
- }
159
- case "doc":
160
- if (collection.dynamic) return;
161
- if (collection.async) {
162
- const [headGlob, bodyGlob] = await Promise.all([
163
- generateDocCollectionFrontmatterGlob(ctx, collection, true),
164
- generateDocCollectionGlob(ctx, collection)
165
- ]);
166
- return `await create.docLazy("${collection.name}", "${base}", ${headGlob}, ${bodyGlob})`;
167
- }
168
- return `await create.doc("${collection.name}", "${base}", ${await generateDocCollectionGlob(
169
- ctx,
170
- collection,
171
- true
172
- )})`;
173
- case "meta":
174
- return `await create.meta("${collection.name}", "${base}", ${await generateMetaCollectionGlob(
175
- ctx,
176
- collection,
177
- true
178
- )})`;
179
- }
180
- }
181
- await codegen.pushAsync(
182
- core.getCollections().map(async (collection) => {
183
- const obj = await generateCollectionObject(collection);
184
- if (!obj) return;
185
- return `
186
- export const ${collection.name} = ${obj};`;
187
- })
188
- );
189
- }
190
- async function generateDynamicIndexFile(ctx) {
191
- const { core, codegen, serverOptions, tc } = ctx;
192
- const { configPath, environment, outDir } = core.getOptions();
193
- const partialOptions = {
194
- configPath,
195
- environment,
196
- outDir
197
- };
198
- codegen.lines.push(
199
- `import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
200
- `import * as Config from '${codegen.formatImportPath(configPath)}';`,
201
- "",
202
- `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(partialOptions)}, ${JSON.stringify(serverOptions)});`
203
- );
204
- async function generateCollectionObjectEntry(collection, absolutePath) {
205
- const fullPath = path2.relative(process.cwd(), absolutePath);
206
- const content = await indexFileCache.read(fullPath).catch(() => "");
207
- const parsed = fumaMatter(content);
208
- const data = await core.transformFrontmatter(
209
- {
210
- collection,
211
- filePath: fullPath,
212
- source: content
213
- },
214
- parsed.data
215
- );
216
- const hash = createHash("md5").update(content).digest("hex");
217
- const infoStr = [
218
- // make sure it's included in vercel/nft
219
- `absolutePath: path.resolve(${JSON.stringify(fullPath)})`
220
- ];
221
- for (const [k, v] of Object.entries({
222
- info: {
223
- fullPath,
224
- path: path2.relative(collection.dir, absolutePath)
225
- },
226
- data,
227
- hash
228
- })) {
229
- infoStr.push(`${k}: ${JSON.stringify(v)}`);
230
- }
231
- return `{ ${infoStr.join(", ")} }`;
232
- }
233
- async function generateCollectionObject(parent) {
234
- let collection;
235
- if (parent.type === "doc") collection = parent;
236
- else if (parent.type === "docs") collection = parent.docs;
237
- if (!collection || !collection.dynamic) return;
238
- const files = await glob(collection.patterns, {
239
- cwd: collection.dir,
240
- absolute: true
241
- });
242
- const entries = await Promise.all(
243
- files.map((file) => generateCollectionObjectEntry(collection, file))
244
- );
245
- switch (parent.type) {
246
- case "docs": {
247
- const metaGlob = await generateMetaCollectionGlob(
248
- ctx,
249
- parent.meta,
250
- true
251
- );
252
- return `await create.docs("${parent.name}", "${getBase(parent)}", ${metaGlob}, ${entries.join(", ")})`;
253
- }
254
- case "doc":
255
- return `await create.doc("${collection.name}", "${getBase(collection)}", ${entries.join(", ")})`;
256
- }
257
- }
258
- await codegen.pushAsync(
259
- core.getCollections().map(async (collection) => {
260
- const obj = await generateCollectionObject(collection);
261
- if (!obj) return;
262
- return `
263
- export const ${collection.name} = ${obj};`;
264
- })
265
- );
266
- }
267
- async function generateBrowserIndexFile(ctx) {
268
- const { core, codegen, tc } = ctx;
269
- codegen.lines.push(
270
- `import { browser } from 'fumadocs-mdx/runtime/browser';`,
271
- `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
272
- "",
273
- `const create = browser<typeof Config, ${tc}>();`
274
- );
275
- async function generateCollectionObject(collection) {
276
- switch (collection.type) {
277
- case "docs": {
278
- if (collection.docs.dynamic) return;
279
- return generateCollectionObject(collection.docs);
280
- }
281
- case "doc":
282
- if (collection.dynamic) return;
283
- return `create.doc("${collection.name}", ${await generateDocCollectionGlob(ctx, collection)})`;
284
- }
285
- }
286
- codegen.lines.push("const browserCollections = {");
287
- await codegen.pushAsync(
288
- core.getCollections().map(async (collection) => {
289
- const obj = await generateCollectionObject(collection);
290
- if (!obj) return;
291
- return ident(`${collection.name}: ${obj},`);
292
- })
293
- );
294
- codegen.lines.push("};", "export default browserCollections;");
295
- }
296
- function getBase(collection) {
297
- return slash(path2.relative(process.cwd(), collection.dir));
298
- }
299
- function generateDocCollectionFrontmatterGlob({ codegen, workspace }, collection, eager = false) {
300
- return codegen.generateGlobImport(collection.patterns, {
301
- query: {
302
- collection: collection.name,
303
- only: "frontmatter",
304
- workspace
305
- },
306
- import: "frontmatter",
307
- base: collection.dir,
308
- eager
309
- });
310
- }
311
- function generateDocCollectionGlob({ codegen, workspace }, collection, eager = false) {
312
- return codegen.generateGlobImport(collection.patterns, {
313
- query: {
314
- collection: collection.name,
315
- workspace
316
- },
317
- base: collection.dir,
318
- eager
319
- });
320
- }
321
- function generateMetaCollectionGlob({ codegen, workspace }, collection, eager = false) {
322
- return codegen.generateGlobImport(collection.patterns, {
323
- query: {
324
- collection: collection.name,
325
- workspace
326
- },
327
- import: "default",
328
- base: collection.dir,
329
- eager
330
- });
331
- }
332
-
333
- export {
334
- indexFile
335
- };
@@ -1,116 +0,0 @@
1
- import {
2
- mdxLoaderGlob
3
- } from "./chunk-4JSFLXXT.js";
4
- import {
5
- fumaMatter
6
- } from "./chunk-VWJKRQZR.js";
7
-
8
- // src/loaders/mdx/index.ts
9
- import { z } from "zod";
10
- import fs from "fs/promises";
11
- import path from "path";
12
- import { createHash } from "crypto";
13
- var querySchema = z.object({
14
- only: z.literal(["frontmatter", "all"]).default("all"),
15
- collection: z.string().optional(),
16
- workspace: z.string().optional()
17
- }).loose();
18
- var cacheEntry = z.object({
19
- code: z.string(),
20
- map: z.any().optional(),
21
- hash: z.string().optional()
22
- });
23
- function createMdxLoader({ getCore }) {
24
- return {
25
- test: mdxLoaderGlob,
26
- async load({
27
- getSource,
28
- development: isDevelopment,
29
- query,
30
- compiler,
31
- filePath
32
- }) {
33
- let core = await getCore();
34
- const value = await getSource();
35
- const matter = fumaMatter(value);
36
- const {
37
- collection: collectionName,
38
- workspace,
39
- only
40
- } = querySchema.parse(query);
41
- if (workspace) {
42
- core = core.getWorkspaces().get(workspace) ?? core;
43
- }
44
- let after;
45
- const { experimentalBuildCache = false } = core.getConfig().global;
46
- if (!isDevelopment && experimentalBuildCache) {
47
- const cacheDir = experimentalBuildCache;
48
- const cacheKey = `${collectionName ?? "global"}_${generateCacheHash(filePath)}`;
49
- const cached = await fs.readFile(path.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
50
- if (cached && cached.hash === generateCacheHash(value)) return cached;
51
- after = async () => {
52
- await fs.mkdir(cacheDir, { recursive: true });
53
- await fs.writeFile(
54
- path.join(cacheDir, cacheKey),
55
- JSON.stringify({
56
- ...out,
57
- hash: generateCacheHash(value)
58
- })
59
- );
60
- };
61
- }
62
- const collection = collectionName ? core.getCollection(collectionName) : void 0;
63
- let docCollection;
64
- switch (collection?.type) {
65
- case "doc":
66
- docCollection = collection;
67
- break;
68
- case "docs":
69
- docCollection = collection.docs;
70
- break;
71
- }
72
- if (docCollection) {
73
- matter.data = await core.transformFrontmatter(
74
- { collection: docCollection, filePath, source: value },
75
- matter.data
76
- );
77
- }
78
- if (only === "frontmatter") {
79
- return {
80
- code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
81
- map: null
82
- };
83
- }
84
- const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
85
- const { buildMDX } = await import("./build-mdx-5XLFMP5P.js");
86
- const compiled = await buildMDX(core, docCollection, {
87
- isDevelopment,
88
- source: "\n".repeat(lineOffset) + matter.content,
89
- filePath,
90
- frontmatter: matter.data,
91
- _compiler: compiler,
92
- environment: "bundler"
93
- });
94
- const out = {
95
- code: String(compiled.value),
96
- map: compiled.map
97
- };
98
- await after?.();
99
- return out;
100
- }
101
- };
102
- }
103
- function generateCacheHash(input) {
104
- return createHash("md5").update(input).digest("hex");
105
- }
106
- function countLines(s) {
107
- let num = 0;
108
- for (const c of s) {
109
- if (c === "\n") num++;
110
- }
111
- return num;
112
- }
113
-
114
- export {
115
- createMdxLoader
116
- };
@@ -1,19 +0,0 @@
1
- // src/utils/fuma-matter.ts
2
- import { load } from "js-yaml";
3
- var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
4
- function fumaMatter(input) {
5
- const output = { matter: "", data: {}, content: input };
6
- const match = regex.exec(input);
7
- if (!match) {
8
- return output;
9
- }
10
- output.matter = match[0];
11
- output.content = input.slice(match[0].length);
12
- const loaded = load(match[1]);
13
- output.data = loaded ?? {};
14
- return output;
15
- }
16
-
17
- export {
18
- fumaMatter
19
- };