fumadocs-mdx 13.0.8 → 14.0.1

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 (111) hide show
  1. package/dist/bin.cjs +985 -893
  2. package/dist/bin.js +3 -3
  3. package/dist/build-mdx-6UAK5FF5.js +8 -0
  4. package/dist/bun/index.cjs +613 -471
  5. package/dist/bun/index.d.cts +9 -2
  6. package/dist/bun/index.d.ts +9 -2
  7. package/dist/bun/index.js +15 -14
  8. package/dist/chunk-4JSFLXXT.js +8 -0
  9. package/dist/chunk-5OBUOALK.js +141 -0
  10. package/dist/{chunk-2E2JCOSO.js → chunk-6NISOLQ6.js} +16 -44
  11. package/dist/chunk-7UKSZSPY.js +331 -0
  12. package/dist/chunk-BEBCWQC7.js +224 -0
  13. package/dist/chunk-E5DJTSIM.js +86 -0
  14. package/dist/{chunk-K5ZLPEIQ.js → chunk-FBLMK4RS.js} +9 -6
  15. package/dist/chunk-IQGEFL2B.js +17 -0
  16. package/dist/{chunk-5FTSWCB4.js → chunk-K6HCOGOX.js} +9 -11
  17. package/dist/{chunk-QXHN25N3.js → chunk-MTTISKQJ.js} +6 -6
  18. package/dist/{chunk-3J3WL7WN.js → chunk-SLY7WXTX.js} +71 -58
  19. package/dist/chunk-TYJDYTKH.js +85 -0
  20. package/dist/chunk-WBIHDYMN.js +126 -0
  21. package/dist/{chunk-2HXTGJBI.js → chunk-ZY6UZ7NH.js} +22 -19
  22. package/dist/config/index.cjs +79 -71
  23. package/dist/config/index.d.cts +7 -1
  24. package/dist/config/index.d.ts +7 -1
  25. package/dist/config/index.js +5 -5
  26. package/dist/core-B9ZoS6sA.d.ts +341 -0
  27. package/dist/core-DTuP23zu.d.cts +341 -0
  28. package/dist/index-BD8Woo4m.d.cts +8 -0
  29. package/dist/index-CNOvhtOn.d.ts +8 -0
  30. package/dist/index.d.cts +38 -56
  31. package/dist/index.d.ts +38 -56
  32. package/dist/load-from-file-5HUQN36V.js +8 -0
  33. package/dist/next/index.cjs +763 -473
  34. package/dist/next/index.d.cts +16 -1
  35. package/dist/next/index.d.ts +16 -1
  36. package/dist/next/index.js +80 -281
  37. package/dist/node/loader.cjs +764 -627
  38. package/dist/node/loader.js +10 -11
  39. package/dist/plugins/index-file.cjs +495 -0
  40. package/dist/plugins/index-file.d.cts +14 -0
  41. package/dist/plugins/index-file.d.ts +14 -0
  42. package/dist/plugins/index-file.js +8 -0
  43. package/dist/plugins/json-schema.d.cts +9 -2
  44. package/dist/plugins/json-schema.d.ts +9 -2
  45. package/dist/plugins/last-modified.cjs +110 -0
  46. package/dist/plugins/last-modified.d.cts +37 -0
  47. package/dist/plugins/last-modified.d.ts +37 -0
  48. package/dist/plugins/last-modified.js +74 -0
  49. package/dist/runtime/browser.cjs +93 -0
  50. package/dist/runtime/browser.d.cts +53 -0
  51. package/dist/runtime/browser.d.ts +53 -0
  52. package/dist/runtime/browser.js +67 -0
  53. package/dist/runtime/dynamic.cjs +1023 -0
  54. package/dist/runtime/dynamic.d.cts +27 -0
  55. package/dist/runtime/dynamic.d.ts +27 -0
  56. package/dist/runtime/dynamic.js +79 -0
  57. package/dist/runtime/server.cjs +176 -0
  58. package/dist/runtime/server.d.cts +14 -0
  59. package/dist/runtime/server.d.ts +14 -0
  60. package/dist/runtime/server.js +8 -0
  61. package/dist/runtime/types.cjs +18 -0
  62. package/dist/runtime/types.d.cts +61 -0
  63. package/dist/runtime/types.d.ts +61 -0
  64. package/dist/runtime/types.js +0 -0
  65. package/dist/vite/index.cjs +984 -621
  66. package/dist/vite/index.d.cts +17 -22
  67. package/dist/vite/index.d.ts +17 -22
  68. package/dist/vite/index.js +32 -222
  69. package/dist/webpack/mdx.cjs +647 -514
  70. package/dist/webpack/mdx.d.cts +15 -1
  71. package/dist/webpack/mdx.d.ts +15 -1
  72. package/dist/webpack/mdx.js +12 -17
  73. package/dist/webpack/meta.cjs +360 -231
  74. package/dist/webpack/meta.d.cts +15 -1
  75. package/dist/webpack/meta.d.ts +15 -1
  76. package/dist/webpack/meta.js +13 -15
  77. package/package.json +15 -32
  78. package/dist/build-mdx-BjXOmv0b.d.cts +0 -53
  79. package/dist/build-mdx-CY5UldCO.d.ts +0 -53
  80. package/dist/chunk-2AQRQXSO.js +0 -119
  81. package/dist/chunk-CXA4JO4Z.js +0 -45
  82. package/dist/chunk-DMJ6I4C3.js +0 -76
  83. package/dist/chunk-FSZMKRVH.js +0 -80
  84. package/dist/chunk-II3H5ZVZ.js +0 -77
  85. package/dist/chunk-KILFIBVW.js +0 -75
  86. package/dist/chunk-NVRDCY6Z.js +0 -30
  87. package/dist/chunk-VUEZTR2H.js +0 -26
  88. package/dist/core-DB7TdlyC.d.cts +0 -234
  89. package/dist/core-DB7TdlyC.d.ts +0 -234
  90. package/dist/index-D7s7kCc2.d.cts +0 -7
  91. package/dist/index-D7s7kCc2.d.ts +0 -7
  92. package/dist/load-from-file-AVYOFOI7.js +0 -7
  93. package/dist/preset-ZMP6U62C.js +0 -6
  94. package/dist/runtime/next/async.cjs +0 -760
  95. package/dist/runtime/next/async.d.cts +0 -19
  96. package/dist/runtime/next/async.d.ts +0 -19
  97. package/dist/runtime/next/async.js +0 -86
  98. package/dist/runtime/next/index.cjs +0 -136
  99. package/dist/runtime/next/index.d.cts +0 -33
  100. package/dist/runtime/next/index.d.ts +0 -33
  101. package/dist/runtime/next/index.js +0 -11
  102. package/dist/runtime/vite/browser.cjs +0 -107
  103. package/dist/runtime/vite/browser.d.cts +0 -59
  104. package/dist/runtime/vite/browser.d.ts +0 -59
  105. package/dist/runtime/vite/browser.js +0 -11
  106. package/dist/runtime/vite/server.cjs +0 -243
  107. package/dist/runtime/vite/server.d.cts +0 -30
  108. package/dist/runtime/vite/server.d.ts +0 -30
  109. package/dist/runtime/vite/server.js +0 -111
  110. package/dist/types-Bnh9n7mj.d.cts +0 -45
  111. package/dist/types-ey1AZqrg.d.ts +0 -45
@@ -1,31 +1,26 @@
1
1
  import { Plugin } from 'vite';
2
-
3
- interface IndexFileOptions {
4
- /**
5
- * Runtime compat fallbacks for Vite specific APIs
6
- *
7
- * - `bun`: use Bun-specific APIs.
8
- * - `node`: use Node.js APIs.
9
- * - `false` (default): no fallback.
10
- */
11
- runtime?: 'bun' | 'node' | false;
12
- /**
13
- * add `.js` extensions to imports, needed for ESM without bundler resolution
14
- */
15
- addJsExtension?: boolean;
16
- /**
17
- * Generate entry point for browser environment
18
- */
19
- browser?: boolean;
20
- }
2
+ import { I as IndexFilePluginOptions } from '../core-DTuP23zu.cjs';
3
+ import '@mdx-js/mdx';
4
+ import '@standard-schema/spec';
5
+ import 'unified';
6
+ import 'fumadocs-core/mdx-plugins';
7
+ import 'zod';
8
+ import 'chokidar';
9
+ import 'vfile';
10
+ import 'fumadocs-core/source';
11
+ import '../runtime/types.cjs';
12
+ import 'fumadocs-core/mdx-plugins/remark-structure';
13
+ import 'fumadocs-core/toc';
14
+ import 'mdast';
15
+ import 'mdx/types';
21
16
 
22
17
  interface PluginOptions {
23
18
  /**
24
- * Automatically generate index files for accessing files with `import.meta.glob`.
19
+ * Generate index files for accessing content.
25
20
  *
26
21
  * @defaultValue true
27
22
  */
28
- generateIndexFile?: boolean | IndexFileOptions;
23
+ index?: boolean | IndexFilePluginOptions;
29
24
  /**
30
25
  * @defaultValue source.config.ts
31
26
  */
@@ -44,6 +39,6 @@ interface PluginOptions {
44
39
  outDir?: string;
45
40
  }
46
41
  declare function mdx(config: Record<string, unknown>, pluginOptions?: PluginOptions): Promise<Plugin>;
47
- declare function postInstall(configPath?: string, pluginOptions?: PluginOptions): Promise<void>;
42
+ declare function postInstall(pluginOptions?: PluginOptions): Promise<void>;
48
43
 
49
44
  export { type PluginOptions, mdx as default, postInstall };
@@ -1,31 +1,26 @@
1
1
  import { Plugin } from 'vite';
2
-
3
- interface IndexFileOptions {
4
- /**
5
- * Runtime compat fallbacks for Vite specific APIs
6
- *
7
- * - `bun`: use Bun-specific APIs.
8
- * - `node`: use Node.js APIs.
9
- * - `false` (default): no fallback.
10
- */
11
- runtime?: 'bun' | 'node' | false;
12
- /**
13
- * add `.js` extensions to imports, needed for ESM without bundler resolution
14
- */
15
- addJsExtension?: boolean;
16
- /**
17
- * Generate entry point for browser environment
18
- */
19
- browser?: boolean;
20
- }
2
+ import { I as IndexFilePluginOptions } from '../core-B9ZoS6sA.js';
3
+ import '@mdx-js/mdx';
4
+ import '@standard-schema/spec';
5
+ import 'unified';
6
+ import 'fumadocs-core/mdx-plugins';
7
+ import 'zod';
8
+ import 'chokidar';
9
+ import 'vfile';
10
+ import 'fumadocs-core/source';
11
+ import '../runtime/types.js';
12
+ import 'fumadocs-core/mdx-plugins/remark-structure';
13
+ import 'fumadocs-core/toc';
14
+ import 'mdast';
15
+ import 'mdx/types';
21
16
 
22
17
  interface PluginOptions {
23
18
  /**
24
- * Automatically generate index files for accessing files with `import.meta.glob`.
19
+ * Generate index files for accessing content.
25
20
  *
26
21
  * @defaultValue true
27
22
  */
28
- generateIndexFile?: boolean | IndexFileOptions;
23
+ index?: boolean | IndexFilePluginOptions;
29
24
  /**
30
25
  * @defaultValue source.config.ts
31
26
  */
@@ -44,6 +39,6 @@ interface PluginOptions {
44
39
  outDir?: string;
45
40
  }
46
41
  declare function mdx(config: Record<string, unknown>, pluginOptions?: PluginOptions): Promise<Plugin>;
47
- declare function postInstall(configPath?: string, pluginOptions?: PluginOptions): Promise<void>;
42
+ declare function postInstall(pluginOptions?: PluginOptions): Promise<void>;
48
43
 
49
44
  export { type PluginOptions, mdx as default, postInstall };
@@ -1,228 +1,36 @@
1
- import {
2
- ident,
3
- toImportPath
4
- } from "../chunk-CXA4JO4Z.js";
5
1
  import {
6
2
  buildConfig
7
- } from "../chunk-2HXTGJBI.js";
3
+ } from "../chunk-ZY6UZ7NH.js";
4
+ import "../chunk-E5DJTSIM.js";
8
5
  import {
9
6
  createMdxLoader
10
- } from "../chunk-2E2JCOSO.js";
7
+ } from "../chunk-6NISOLQ6.js";
11
8
  import {
12
9
  createMetaLoader
13
- } from "../chunk-DMJ6I4C3.js";
10
+ } from "../chunk-TYJDYTKH.js";
14
11
  import {
15
12
  createIntegratedConfigLoader,
16
13
  toVite
17
- } from "../chunk-5FTSWCB4.js";
18
- import "../chunk-3J3WL7WN.js";
19
- import "../chunk-K5ZLPEIQ.js";
20
- import "../chunk-VUEZTR2H.js";
14
+ } from "../chunk-K6HCOGOX.js";
15
+ import "../chunk-4JSFLXXT.js";
21
16
  import {
22
17
  ValidationError,
23
- createCore,
24
- findConfigFile
25
- } from "../chunk-2AQRQXSO.js";
18
+ _Defaults,
19
+ createCore
20
+ } from "../chunk-BEBCWQC7.js";
21
+ import {
22
+ indexFile
23
+ } from "../chunk-7UKSZSPY.js";
24
+ import "../chunk-WBIHDYMN.js";
26
25
  import "../chunk-VWJKRQZR.js";
27
26
 
28
27
  // src/vite/index.ts
29
28
  import { mergeConfig } from "vite";
30
-
31
- // src/utils/glob-import.ts
32
- import { globSync } from "tinyglobby";
33
- import path from "path";
34
- import { pathToFileURL } from "url";
35
- function generateGlobImport(patterns, options) {
36
- let code = "{";
37
- const result = globSync(patterns, {
38
- cwd: options.base
39
- });
40
- for (const item of result) {
41
- const fullPath = path.join(options.base, item);
42
- const url = pathToFileURL(fullPath);
43
- for (const [k, v] of Object.entries(options.query ?? {})) {
44
- url.searchParams.set(k, v);
45
- }
46
- let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(url.href)})`;
47
- if (options.import) {
48
- line += `.then(mod => mod[${JSON.stringify(options.import)}])`;
49
- }
50
- code += `${line}, `;
51
- }
52
- code += "}";
53
- return code;
54
- }
55
-
56
- // src/plugins/vite.ts
57
- import path2 from "path";
58
- function vite({
59
- index
60
- }) {
61
- let config;
62
- let indexOptions;
63
- if (index === false) indexOptions = false;
64
- else indexOptions = applyDefaults(index === true ? {} : index);
65
- return {
66
- name: "vite",
67
- config(v) {
68
- config = v;
69
- },
70
- configureServer(server) {
71
- if (!server.watcher || indexOptions === false || indexOptions.runtime === false)
72
- return;
73
- server.watcher.on("all", (event, file) => {
74
- if (event === "change") return;
75
- const isUpdated = config.collectionList.some((collection) => {
76
- if (collection.type === "docs")
77
- return collection.docs.hasFile(file) || collection.meta.hasFile(file);
78
- return collection.hasFile(file);
79
- });
80
- if (isUpdated) {
81
- this.core.emitAndWrite({
82
- filterPlugin: (plugin) => plugin.name === "vite"
83
- });
84
- }
85
- });
86
- },
87
- emit() {
88
- const out = [];
89
- if (indexOptions === false) return out;
90
- if (indexOptions.browser) {
91
- out.push({
92
- path: "browser.ts",
93
- content: indexFile(this, config, indexOptions, "browser")
94
- });
95
- }
96
- out.push({
97
- path: "index.ts",
98
- content: indexFile(
99
- this,
100
- config,
101
- indexOptions,
102
- indexOptions.browser ? "server" : "all"
103
- )
104
- });
105
- return out;
106
- }
107
- };
108
- }
109
- function applyDefaults(options) {
110
- return {
111
- addJsExtension: options.addJsExtension ?? false,
112
- browser: options.browser ?? false,
113
- runtime: options.runtime ?? false
114
- };
115
- }
116
- function indexFile({ configPath, outDir }, config, { addJsExtension, runtime }, environment) {
117
- const runtimePath = {
118
- all: "fumadocs-mdx/runtime/vite",
119
- server: "fumadocs-mdx/runtime/vite.server",
120
- browser: "fumadocs-mdx/runtime/vite.browser"
121
- }[environment];
122
- const lines = [
123
- '/// <reference types="vite/client" />',
124
- `import { fromConfig } from '${runtimePath}';`,
125
- `import type * as Config from '${toImportPath(configPath, {
126
- relativeTo: outDir,
127
- jsExtension: addJsExtension
128
- })}';`,
129
- "",
130
- `export const create = fromConfig<typeof Config>();`
131
- ];
132
- function generateCollectionGlob(collection) {
133
- if (collection.type === "docs") {
134
- const obj = [
135
- ident(`doc: ${generateCollectionGlob(collection.docs)}`),
136
- ident(`meta: ${generateCollectionGlob(collection.meta)}`)
137
- ].join(",\n");
138
- return `{
139
- ${obj}
140
- }`;
141
- }
142
- const dir = getCollectionDir(collection);
143
- if (collection.type === "doc") {
144
- const docGlob = generateGlob(collection.patterns, {
145
- query: {
146
- collection: collection.name
147
- },
148
- base: dir
149
- });
150
- if (collection.async) {
151
- const headBlob = generateGlob(collection.patterns, {
152
- query: {
153
- only: "frontmatter",
154
- collection: collection.name
155
- },
156
- import: "frontmatter",
157
- base: dir
158
- });
159
- return `create.docLazy("${collection.name}", "${dir}", ${headBlob}, ${docGlob})`;
160
- }
161
- return `create.doc("${collection.name}", "${dir}", ${docGlob})`;
162
- }
163
- return `create.meta("${collection.name}", "${dir}", ${generateGlob(
164
- collection.patterns,
165
- {
166
- import: "default",
167
- base: dir,
168
- query: {
169
- collection: collection.name
170
- }
171
- }
172
- )})`;
173
- }
174
- function generateGlob(patterns, options) {
175
- patterns = patterns.map(normalizeGlobPath);
176
- if (runtime === "node" || runtime === "bun") {
177
- return generateGlobImport(patterns, options);
178
- } else {
179
- return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
180
- {
181
- ...options,
182
- base: normalizeGlobPath(path2.relative(outDir, options.base))
183
- },
184
- null,
185
- 2
186
- )})`;
187
- }
188
- }
189
- for (const collection of config.collectionList) {
190
- lines.push("");
191
- lines.push(
192
- `export const ${collection.name} = ${generateCollectionGlob(collection)};`
193
- );
194
- }
195
- return lines.join("\n");
196
- }
197
- function normalizeGlobPath(file) {
198
- file = slash(file);
199
- if (file.startsWith("./")) return file;
200
- if (file.startsWith("/")) return `.${file}`;
201
- return `./${file}`;
202
- }
203
- function getCollectionDir({ dir }) {
204
- if (Array.isArray(dir)) {
205
- if (dir.length !== 1)
206
- throw new Error(
207
- `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
208
- );
209
- return dir[0];
210
- }
211
- return dir;
212
- }
213
- function slash(path3) {
214
- const isExtendedLengthPath = path3.startsWith("\\\\?\\");
215
- if (isExtendedLengthPath) {
216
- return path3;
217
- }
218
- return path3.replaceAll("\\", "/");
219
- }
220
-
221
- // src/vite/index.ts
222
29
  var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
223
30
  async function mdx(config, pluginOptions = {}) {
224
- const options = applyDefaults2(pluginOptions);
225
- const core = await createViteCore(options).init({
31
+ const options = applyDefaults(pluginOptions);
32
+ const core = createViteCore(options);
33
+ await core.init({
226
34
  config: buildConfig(config)
227
35
  });
228
36
  const configLoader = createIntegratedConfigLoader(core);
@@ -267,26 +75,27 @@ async function mdx(config, pluginOptions = {}) {
267
75
  }
268
76
  } catch (e) {
269
77
  if (e instanceof ValidationError) {
270
- throw new Error(e.toStringFormatted());
78
+ throw new Error(await e.toStringFormatted());
271
79
  }
272
80
  throw e;
273
81
  }
274
82
  }
275
83
  };
276
84
  }
277
- async function postInstall(configPath = findConfigFile(), pluginOptions = {}) {
278
- const { loadConfig } = await import("../load-from-file-AVYOFOI7.js");
279
- const options = applyDefaults2(pluginOptions);
280
- const core = await createViteCore(options).init({
281
- config: loadConfig(configPath, options.outDir, true)
85
+ async function postInstall(pluginOptions = {}) {
86
+ const { loadConfig } = await import("../load-from-file-5HUQN36V.js");
87
+ const core = createViteCore(applyDefaults(pluginOptions));
88
+ await core.init({
89
+ config: loadConfig(core, true)
282
90
  });
283
91
  await core.emitAndWrite();
284
92
  }
285
93
  function createViteCore({
94
+ index,
286
95
  configPath,
287
- outDir,
288
- generateIndexFile
96
+ outDir
289
97
  }) {
98
+ if (index === true) index = {};
290
99
  return createCore(
291
100
  {
292
101
  environment: "vite",
@@ -294,18 +103,19 @@ function createViteCore({
294
103
  outDir
295
104
  },
296
105
  [
297
- vite({
298
- index: generateIndexFile
106
+ index && indexFile({
107
+ ...index,
108
+ target: index.target ?? "vite"
299
109
  })
300
110
  ]
301
111
  );
302
112
  }
303
- function applyDefaults2(options) {
113
+ function applyDefaults(options) {
304
114
  return {
305
115
  updateViteConfig: options.updateViteConfig ?? true,
306
- generateIndexFile: options.generateIndexFile ?? true,
307
- configPath: options.configPath ?? "source.config.ts",
308
- outDir: options.outDir ?? ".source"
116
+ index: options.index ?? true,
117
+ configPath: options.configPath ?? _Defaults.configPath,
118
+ outDir: options.outDir ?? _Defaults.outDir
309
119
  };
310
120
  }
311
121
  export {