fumadocs-mdx 13.0.3 → 13.0.5

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 (66) hide show
  1. package/dist/bin.cjs +353 -273
  2. package/dist/bin.js +1 -1
  3. package/dist/{build-mdx-TtQzmq6W.d.cts → build-mdx-BjXOmv0b.d.cts} +1 -1
  4. package/dist/{build-mdx--WI4tf2-.d.ts → build-mdx-CY5UldCO.d.ts} +1 -1
  5. package/dist/bun/index.cjs +177 -57
  6. package/dist/bun/index.d.cts +2 -2
  7. package/dist/bun/index.d.ts +2 -2
  8. package/dist/bun/index.js +26 -34
  9. package/dist/chunk-2HXTGJBI.js +101 -0
  10. package/dist/chunk-4JSFLXXT.js +8 -0
  11. package/dist/{chunk-JVZFH6ND.js → chunk-QXHN25N3.js} +2 -2
  12. package/dist/{chunk-EELYB2XC.js → chunk-TZ5EQBFW.js} +9 -103
  13. package/dist/chunk-VUEZTR2H.js +26 -0
  14. package/dist/{chunk-XQ5O7IPO.js → chunk-XYGORKQA.js} +5 -3
  15. package/dist/chunk-YAIPHUCZ.js +56 -0
  16. package/dist/chunk-ZNVPB2IR.js +170 -0
  17. package/dist/config/index.d.cts +2 -2
  18. package/dist/config/index.d.ts +2 -2
  19. package/dist/{core-DhfmVKRA.d.cts → core-DB7TdlyC.d.cts} +21 -7
  20. package/dist/{core-DhfmVKRA.d.ts → core-DB7TdlyC.d.ts} +21 -7
  21. package/dist/index-D7s7kCc2.d.cts +7 -0
  22. package/dist/index-D7s7kCc2.d.ts +7 -0
  23. package/dist/index.d.cts +4 -4
  24. package/dist/index.d.ts +4 -4
  25. package/dist/load-from-file-AVYOFOI7.js +7 -0
  26. package/dist/next/index.cjs +145 -139
  27. package/dist/next/index.js +56 -36
  28. package/dist/node/loader.cjs +242 -128
  29. package/dist/node/loader.d.cts +2 -2
  30. package/dist/node/loader.d.ts +2 -2
  31. package/dist/node/loader.js +29 -16
  32. package/dist/plugins/json-schema.cjs +22 -70
  33. package/dist/plugins/json-schema.d.cts +2 -2
  34. package/dist/plugins/json-schema.d.ts +2 -2
  35. package/dist/plugins/json-schema.js +19 -14
  36. package/dist/runtime/next/async.cjs +56 -11
  37. package/dist/runtime/next/async.d.cts +4 -6
  38. package/dist/runtime/next/async.d.ts +4 -6
  39. package/dist/runtime/next/async.js +3 -6
  40. package/dist/runtime/next/index.d.cts +5 -5
  41. package/dist/runtime/next/index.d.ts +5 -5
  42. package/dist/runtime/vite/browser.d.cts +3 -3
  43. package/dist/runtime/vite/browser.d.ts +3 -3
  44. package/dist/runtime/vite/server.d.cts +3 -3
  45. package/dist/runtime/vite/server.d.ts +3 -3
  46. package/dist/{types-zrV4v6mp.d.cts → types-Bnh9n7mj.d.cts} +2 -2
  47. package/dist/{types-CMva20Zp.d.ts → types-ey1AZqrg.d.ts} +2 -2
  48. package/dist/vite/index.cjs +238 -159
  49. package/dist/vite/index.js +113 -118
  50. package/dist/webpack/{index.cjs → mdx.cjs} +126 -104
  51. package/dist/webpack/mdx.d.cts +6 -0
  52. package/dist/webpack/mdx.d.ts +6 -0
  53. package/dist/webpack/{index.js → mdx.js} +12 -14
  54. package/dist/webpack/meta.cjs +528 -0
  55. package/dist/webpack/meta.d.cts +6 -0
  56. package/dist/webpack/meta.d.ts +6 -0
  57. package/dist/webpack/meta.js +42 -0
  58. package/loader-mdx.cjs +1 -1
  59. package/loader-meta.cjs +7 -0
  60. package/package.json +6 -3
  61. package/dist/chunk-U4MQ44TS.js +0 -53
  62. package/dist/chunk-XZY2AWJI.js +0 -81
  63. package/dist/chunk-YVCR6FUH.js +0 -82
  64. package/dist/load-MNG3CLET.js +0 -7
  65. package/dist/webpack/index.d.cts +0 -15
  66. package/dist/webpack/index.d.ts +0 -15
@@ -1,24 +1,26 @@
1
1
  import {
2
2
  loadConfig
3
- } from "../chunk-JVZFH6ND.js";
3
+ } from "../chunk-QXHN25N3.js";
4
4
  import {
5
5
  getImportCode,
6
6
  toImportPath
7
7
  } from "../chunk-CXA4JO4Z.js";
8
- import "../chunk-U4MQ44TS.js";
8
+ import "../chunk-2HXTGJBI.js";
9
+ import {
10
+ mdxLoaderGlob
11
+ } from "../chunk-4JSFLXXT.js";
12
+ import {
13
+ getGitTimestamp
14
+ } from "../chunk-VUEZTR2H.js";
9
15
  import {
10
16
  ValidationError,
11
17
  createCore,
12
18
  findConfigFile,
13
- getGitTimestamp,
14
19
  validate
15
- } from "../chunk-EELYB2XC.js";
20
+ } from "../chunk-TZ5EQBFW.js";
16
21
  import {
17
22
  fumaMatter
18
23
  } from "../chunk-VWJKRQZR.js";
19
- import {
20
- getCollectionFiles
21
- } from "../chunk-XZY2AWJI.js";
22
24
 
23
25
  // src/next/index.ts
24
26
  import * as path3 from "path";
@@ -59,11 +61,9 @@ function next() {
59
61
  name: "next",
60
62
  config(v) {
61
63
  config = v;
62
- shouldEmitOnChange = Array.from(config.collections.values()).some(
63
- (collection) => {
64
- return collection.type === "doc" && collection.async || collection.type === "docs" && collection.docs.async;
65
- }
66
- );
64
+ shouldEmitOnChange = config.collectionList.some((collection) => {
65
+ return collection.type === "doc" && collection.async || collection.type === "docs" || collection.type === "meta";
66
+ });
67
67
  },
68
68
  configureServer(server) {
69
69
  if (!server.watcher) return;
@@ -86,7 +86,7 @@ function next() {
86
86
  }
87
87
  };
88
88
  }
89
- async function indexFile(configPath, config, importPath, configHash = false) {
89
+ async function indexFile(configPath, config, importPath) {
90
90
  let asyncInit = false;
91
91
  const lines = [
92
92
  getImportCode({
@@ -100,14 +100,10 @@ async function indexFile(configPath, config, importPath, configHash = false) {
100
100
  name: "_source"
101
101
  })
102
102
  ];
103
- const entries = Array.from(config.collections.entries());
104
- async function getDocEntries(collectionName, files) {
105
- const items = files.map(async (file, i) => {
106
- const importId = `${collectionName}_${i}`;
107
- const params = [`collection=${collectionName}`];
108
- if (configHash) {
109
- params.push(`hash=${configHash}`);
110
- }
103
+ function getDocEntries(collection, files) {
104
+ return files.map((file, i) => {
105
+ const importId = `d_${collection.name}_${i}`;
106
+ const params = [`collection=${collection.name}`];
111
107
  lines.unshift(
112
108
  getImportCode({
113
109
  type: "namespace",
@@ -117,7 +113,6 @@ async function indexFile(configPath, config, importPath, configHash = false) {
117
113
  );
118
114
  return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
119
115
  });
120
- return Promise.all(items);
121
116
  }
122
117
  async function getMetaEntries(collection, files) {
123
118
  const items = files.map(async (file) => {
@@ -158,7 +153,7 @@ async function indexFile(configPath, config, importPath, configHash = false) {
158
153
  );
159
154
  asyncInit = true;
160
155
  }
161
- const entries2 = files.map(async (file) => {
156
+ const entries = files.map(async (file) => {
162
157
  const content = await readFileWithCache(file.fullPath).catch(() => "");
163
158
  const parsed = fumaMatter(content);
164
159
  let data = parsed.data;
@@ -184,12 +179,13 @@ async function indexFile(configPath, config, importPath, configHash = false) {
184
179
  );
185
180
  return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
186
181
  });
187
- return Promise.all(entries2);
182
+ return Promise.all(entries);
188
183
  }
189
- const declares = entries.map(async ([k, collection]) => {
184
+ const declares = config.collectionList.map(async (collection) => {
185
+ const k = collection.name;
190
186
  if (collection.type === "docs") {
191
- const docs = await getCollectionFiles(collection.docs);
192
- const metas = await getCollectionFiles(collection.meta);
187
+ const docs = await globCollectionFiles(collection.docs);
188
+ const metas = await globCollectionFiles(collection.meta);
193
189
  const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
194
190
  ", "
195
191
  );
@@ -199,14 +195,17 @@ async function indexFile(configPath, config, importPath, configHash = false) {
199
195
  );
200
196
  return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
201
197
  }
202
- const docsEntries = (await getDocEntries(k, docs)).join(", ");
198
+ const docsEntries = getDocEntries(collection.docs, docs).join(", ");
203
199
  return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
204
200
  }
205
- const files = await getCollectionFiles(collection);
206
- if (collection.type === "doc" && collection.async) {
201
+ const files = await globCollectionFiles(collection);
202
+ if (collection.type === "meta") {
203
+ return `export const ${k} = _runtime.meta<typeof _source.${k}>([${(await getMetaEntries(collection, files)).join(", ")}]);`;
204
+ }
205
+ if (collection.async) {
207
206
  return `export const ${k} = _runtimeAsync.doc<typeof _source.${k}>([${(await getAsyncEntries(collection, files)).join(", ")}], "${k}", _sourceConfig)`;
208
207
  }
209
- return `export const ${k} = _runtime.${collection.type}<typeof _source.${k}>([${(await getDocEntries(k, files)).join(", ")}]);`;
208
+ return `export const ${k} = _runtime.doc<typeof _source.${k}>([${getDocEntries(collection, files).join(", ")}]);`;
210
209
  });
211
210
  const resolvedDeclares = await Promise.all(declares);
212
211
  return [
@@ -227,6 +226,27 @@ function parseMetaEntry(file, content) {
227
226
  }
228
227
  throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
229
228
  }
229
+ async function globCollectionFiles(collection) {
230
+ const { glob } = await import("tinyglobby");
231
+ const files = /* @__PURE__ */ new Map();
232
+ const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
233
+ await Promise.all(
234
+ dirs.map(async (dir) => {
235
+ const result = await glob(collection.patterns, {
236
+ cwd: path2.resolve(dir)
237
+ });
238
+ for (const item of result) {
239
+ if (!collection.isFileSupported(item)) continue;
240
+ const fullPath = path2.join(dir, item);
241
+ files.set(fullPath, {
242
+ path: item,
243
+ fullPath
244
+ });
245
+ }
246
+ })
247
+ );
248
+ return Array.from(files.values());
249
+ }
230
250
 
231
251
  // src/next/index.ts
232
252
  var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
@@ -238,7 +258,7 @@ function createMDX(createOptions = {}) {
238
258
  void init(isDev, options);
239
259
  }
240
260
  return (nextConfig = {}) => {
241
- const mdxLoaderOptions = {
261
+ const loaderOptions = {
242
262
  ...options,
243
263
  isDev
244
264
  };
@@ -250,7 +270,7 @@ function createMDX(createOptions = {}) {
250
270
  loaders: [
251
271
  {
252
272
  loader: "fumadocs-mdx/loader-mdx",
253
- options: mdxLoaderOptions
273
+ options: loaderOptions
254
274
  }
255
275
  ],
256
276
  as: "*.js"
@@ -266,12 +286,12 @@ function createMDX(createOptions = {}) {
266
286
  config.module ||= {};
267
287
  config.module.rules ||= [];
268
288
  config.module.rules.push({
269
- test: /\.mdx?$/,
289
+ test: mdxLoaderGlob,
270
290
  use: [
271
291
  options2.defaultLoaders.babel,
272
292
  {
273
293
  loader: "fumadocs-mdx/loader-mdx",
274
- options: mdxLoaderOptions
294
+ options: loaderOptions
275
295
  }
276
296
  ]
277
297
  });
@@ -297,7 +317,7 @@ async function init(dev, options) {
297
317
  ignored: [options.outDir]
298
318
  });
299
319
  watcher.add(options.configPath);
300
- for (const collection of core.getConfig().collections.values()) {
320
+ for (const collection of core.getConfig().collectionList) {
301
321
  if (collection.type === "docs") {
302
322
  watcher.add(collection.docs.dir);
303
323
  watcher.add(collection.meta.dir);