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