fumadocs-mdx 11.6.0 → 13.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.
- package/dist/bin.cjs +1728 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +16 -0
- package/dist/build-mdx-CCNr86q6.d.ts +53 -0
- package/dist/build-mdx-D-r3_eQL.d.cts +53 -0
- package/dist/bun/index.cjs +857 -0
- package/dist/bun/index.d.cts +13 -0
- package/dist/bun/index.d.ts +13 -0
- package/dist/bun/index.js +62 -0
- package/dist/chunk-3J3WL7WN.js +160 -0
- package/dist/chunk-CXA4JO4Z.js +45 -0
- package/dist/chunk-EELYB2XC.js +207 -0
- package/dist/chunk-FSZMKRVH.js +80 -0
- package/dist/chunk-II3H5ZVZ.js +77 -0
- package/dist/chunk-JVZFH6ND.js +40 -0
- package/dist/chunk-K5ZLPEIQ.js +207 -0
- package/dist/{chunk-VFALQK6O.js → chunk-KILFIBVW.js} +21 -12
- package/dist/chunk-NVRDCY6Z.js +30 -0
- package/dist/chunk-U4MQ44TS.js +53 -0
- package/dist/chunk-VWJKRQZR.js +19 -0
- package/dist/chunk-XQ5O7IPO.js +128 -0
- package/dist/chunk-XZY2AWJI.js +81 -0
- package/dist/chunk-YVCR6FUH.js +82 -0
- package/dist/config/index.cjs +232 -128
- package/dist/config/index.d.cts +4 -6
- package/dist/config/index.d.ts +4 -6
- package/dist/config/index.js +26 -19
- package/dist/core-B6j6Fxse.d.cts +218 -0
- package/dist/core-B6j6Fxse.d.ts +218 -0
- package/dist/index.cjs +0 -76
- package/dist/index.d.cts +73 -20
- package/dist/index.d.ts +73 -20
- package/dist/index.js +0 -10
- package/dist/load-MNG3CLET.js +7 -0
- package/dist/next/index.cjs +567 -314
- package/dist/next/index.d.cts +9 -12
- package/dist/next/index.d.ts +9 -12
- package/dist/next/index.js +238 -211
- package/dist/node/loader.cjs +922 -0
- package/dist/node/loader.d.cts +5 -0
- package/dist/node/loader.d.ts +5 -0
- package/dist/node/loader.js +33 -0
- package/dist/plugins/json-schema.cjs +162 -0
- package/dist/plugins/json-schema.d.cts +24 -0
- package/dist/plugins/json-schema.d.ts +24 -0
- package/dist/plugins/json-schema.js +78 -0
- package/dist/{mdx-options-CAU273O3.js → preset-ZMP6U62C.js} +1 -1
- package/dist/runtime/next/async.cjs +715 -0
- package/dist/runtime/next/async.d.cts +21 -0
- package/dist/runtime/next/async.d.ts +21 -0
- package/dist/runtime/next/async.js +89 -0
- package/dist/runtime/next/index.cjs +136 -0
- package/dist/runtime/next/index.d.cts +33 -0
- package/dist/runtime/next/index.d.ts +33 -0
- package/dist/runtime/next/index.js +11 -0
- package/dist/runtime/vite/browser.cjs +107 -0
- package/dist/runtime/vite/browser.d.cts +59 -0
- package/dist/runtime/vite/browser.d.ts +59 -0
- package/dist/runtime/vite/browser.js +11 -0
- package/dist/runtime/vite/server.cjs +243 -0
- package/dist/runtime/vite/server.d.cts +30 -0
- package/dist/runtime/vite/server.d.ts +30 -0
- package/dist/runtime/vite/server.js +111 -0
- package/dist/types-AGzTfBmf.d.ts +45 -0
- package/dist/types-DKGMoay5.d.cts +45 -0
- package/dist/vite/index.cjs +1185 -0
- package/dist/vite/index.d.cts +45 -0
- package/dist/vite/index.d.ts +45 -0
- package/dist/vite/index.js +297 -0
- package/dist/webpack/index.cjs +957 -0
- package/dist/{loader-mdx.d.cts → webpack/index.d.cts} +3 -6
- package/dist/{loader-mdx.d.ts → webpack/index.d.ts} +3 -6
- package/dist/webpack/index.js +44 -0
- package/loader-mdx.cjs +1 -1
- package/package.json +86 -29
- package/bin.js +0 -5
- package/dist/chunk-2ZOW45YZ.js +0 -63
- package/dist/chunk-DRVUBK5B.js +0 -39
- package/dist/chunk-HFLDWPJA.js +0 -62
- package/dist/chunk-IOENRFUX.js +0 -112
- package/dist/chunk-MK7EXW7O.js +0 -75
- package/dist/define-BaW0PQDJ.d.cts +0 -201
- package/dist/define-BaW0PQDJ.d.ts +0 -201
- package/dist/loader-mdx.cjs +0 -527
- package/dist/loader-mdx.js +0 -162
- package/dist/runtime/async.cjs +0 -269
- package/dist/runtime/async.d.cts +0 -18
- package/dist/runtime/async.d.ts +0 -18
- package/dist/runtime/async.js +0 -73
- package/dist/types-BNrQHCj5.d.cts +0 -100
- package/dist/types-DEduCvIT.d.ts +0 -100
- package/dist/watcher-IAZDSTU7.js +0 -24
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
|
|
18
|
+
interface PluginOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Automatically generate index files for accessing files with `import.meta.glob`.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue true
|
|
23
|
+
*/
|
|
24
|
+
generateIndexFile?: boolean | IndexFileOptions;
|
|
25
|
+
/**
|
|
26
|
+
* @defaultValue source.config.ts
|
|
27
|
+
*/
|
|
28
|
+
configPath?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Update Vite config to fix module resolution of Fumadocs
|
|
31
|
+
*
|
|
32
|
+
* @defaultValue true
|
|
33
|
+
*/
|
|
34
|
+
updateViteConfig?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Output directory of generated files
|
|
37
|
+
*
|
|
38
|
+
* @defaultValue '.source'
|
|
39
|
+
*/
|
|
40
|
+
outDir?: string;
|
|
41
|
+
}
|
|
42
|
+
declare function mdx(config: Record<string, unknown>, pluginOptions?: PluginOptions): Promise<Plugin>;
|
|
43
|
+
declare function postInstall(configPath?: string, pluginOptions?: PluginOptions): Promise<void>;
|
|
44
|
+
|
|
45
|
+
export { type PluginOptions, mdx as default, postInstall };
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
|
|
18
|
+
interface PluginOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Automatically generate index files for accessing files with `import.meta.glob`.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue true
|
|
23
|
+
*/
|
|
24
|
+
generateIndexFile?: boolean | IndexFileOptions;
|
|
25
|
+
/**
|
|
26
|
+
* @defaultValue source.config.ts
|
|
27
|
+
*/
|
|
28
|
+
configPath?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Update Vite config to fix module resolution of Fumadocs
|
|
31
|
+
*
|
|
32
|
+
* @defaultValue true
|
|
33
|
+
*/
|
|
34
|
+
updateViteConfig?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Output directory of generated files
|
|
37
|
+
*
|
|
38
|
+
* @defaultValue '.source'
|
|
39
|
+
*/
|
|
40
|
+
outDir?: string;
|
|
41
|
+
}
|
|
42
|
+
declare function mdx(config: Record<string, unknown>, pluginOptions?: PluginOptions): Promise<Plugin>;
|
|
43
|
+
declare function postInstall(configPath?: string, pluginOptions?: PluginOptions): Promise<void>;
|
|
44
|
+
|
|
45
|
+
export { type PluginOptions, mdx as default, postInstall };
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ident,
|
|
3
|
+
toImportPath
|
|
4
|
+
} from "../chunk-CXA4JO4Z.js";
|
|
5
|
+
import {
|
|
6
|
+
buildConfig
|
|
7
|
+
} from "../chunk-U4MQ44TS.js";
|
|
8
|
+
import {
|
|
9
|
+
toVite
|
|
10
|
+
} from "../chunk-YVCR6FUH.js";
|
|
11
|
+
import {
|
|
12
|
+
createMdxLoader
|
|
13
|
+
} from "../chunk-XQ5O7IPO.js";
|
|
14
|
+
import "../chunk-3J3WL7WN.js";
|
|
15
|
+
import "../chunk-K5ZLPEIQ.js";
|
|
16
|
+
import {
|
|
17
|
+
ValidationError,
|
|
18
|
+
createCore,
|
|
19
|
+
findConfigFile,
|
|
20
|
+
validate
|
|
21
|
+
} from "../chunk-EELYB2XC.js";
|
|
22
|
+
import "../chunk-VWJKRQZR.js";
|
|
23
|
+
import {
|
|
24
|
+
getGlobPatterns
|
|
25
|
+
} from "../chunk-XZY2AWJI.js";
|
|
26
|
+
|
|
27
|
+
// src/vite/index.ts
|
|
28
|
+
import {
|
|
29
|
+
mergeConfig
|
|
30
|
+
} from "vite";
|
|
31
|
+
import { parse } from "querystring";
|
|
32
|
+
import * as path3 from "path";
|
|
33
|
+
import { load } from "js-yaml";
|
|
34
|
+
|
|
35
|
+
// src/utils/glob-import.ts
|
|
36
|
+
import { globSync } from "tinyglobby";
|
|
37
|
+
import path from "path";
|
|
38
|
+
import { pathToFileURL } from "url";
|
|
39
|
+
function generateGlobImport(patterns, options) {
|
|
40
|
+
let code = "{";
|
|
41
|
+
const result = globSync(patterns, {
|
|
42
|
+
cwd: options.base
|
|
43
|
+
});
|
|
44
|
+
for (const item of result) {
|
|
45
|
+
const fullPath = path.join(options.base, item);
|
|
46
|
+
const url = pathToFileURL(fullPath);
|
|
47
|
+
for (const [k, v] of Object.entries(options.query ?? {})) {
|
|
48
|
+
url.searchParams.set(k, v);
|
|
49
|
+
}
|
|
50
|
+
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(url.href)})`;
|
|
51
|
+
if (options.import) {
|
|
52
|
+
line += `.then(mod => mod[${JSON.stringify(options.import)}])`;
|
|
53
|
+
}
|
|
54
|
+
code += `${line}, `;
|
|
55
|
+
}
|
|
56
|
+
code += "}";
|
|
57
|
+
return code;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/plugins/vite.ts
|
|
61
|
+
import path2 from "path";
|
|
62
|
+
function vite(options) {
|
|
63
|
+
let config;
|
|
64
|
+
return {
|
|
65
|
+
config(v) {
|
|
66
|
+
config = v;
|
|
67
|
+
},
|
|
68
|
+
emit() {
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
path: "index.ts",
|
|
72
|
+
content: indexFile(this.configPath, this.outDir, config, options)
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function indexFile(configPath, outDir, config, options) {
|
|
79
|
+
const { addJsExtension = false, runtime } = options;
|
|
80
|
+
const lines = [
|
|
81
|
+
'/// <reference types="vite/client" />',
|
|
82
|
+
`import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
|
|
83
|
+
`import type * as Config from '${toImportPath(configPath, {
|
|
84
|
+
relativeTo: outDir,
|
|
85
|
+
jsExtension: addJsExtension
|
|
86
|
+
})}';`,
|
|
87
|
+
"",
|
|
88
|
+
`export const create = fromConfig<typeof Config>();`
|
|
89
|
+
];
|
|
90
|
+
function docs(name, collection) {
|
|
91
|
+
const obj = [
|
|
92
|
+
ident(`doc: ${doc(name, collection.docs)}`),
|
|
93
|
+
ident(`meta: ${meta(name, collection.meta)}`)
|
|
94
|
+
].join(",\n");
|
|
95
|
+
return `{
|
|
96
|
+
${obj}
|
|
97
|
+
}`;
|
|
98
|
+
}
|
|
99
|
+
function doc(name, collection) {
|
|
100
|
+
const patterns = getGlobPatterns(collection);
|
|
101
|
+
const base = getGlobBase(collection);
|
|
102
|
+
const docGlob = generateGlob(patterns, {
|
|
103
|
+
query: {
|
|
104
|
+
collection: name
|
|
105
|
+
},
|
|
106
|
+
base
|
|
107
|
+
});
|
|
108
|
+
if (collection.async) {
|
|
109
|
+
const headBlob = generateGlob(patterns, {
|
|
110
|
+
query: {
|
|
111
|
+
only: "frontmatter",
|
|
112
|
+
collection: name
|
|
113
|
+
},
|
|
114
|
+
import: "frontmatter",
|
|
115
|
+
base
|
|
116
|
+
});
|
|
117
|
+
return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
|
|
118
|
+
}
|
|
119
|
+
return `create.doc("${name}", "${base}", ${docGlob})`;
|
|
120
|
+
}
|
|
121
|
+
function meta(name, collection) {
|
|
122
|
+
const patterns = getGlobPatterns(collection);
|
|
123
|
+
const base = getGlobBase(collection);
|
|
124
|
+
return `create.meta("${name}", "${base}", ${generateGlob(patterns, {
|
|
125
|
+
import: "default",
|
|
126
|
+
base,
|
|
127
|
+
query: {
|
|
128
|
+
collection: name
|
|
129
|
+
}
|
|
130
|
+
})})`;
|
|
131
|
+
}
|
|
132
|
+
function generateGlob(patterns, options2) {
|
|
133
|
+
patterns = mapGlobPatterns(patterns);
|
|
134
|
+
if (runtime === "node" || runtime === "bun") {
|
|
135
|
+
return generateGlobImport(patterns, options2);
|
|
136
|
+
} else {
|
|
137
|
+
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
138
|
+
{
|
|
139
|
+
...options2,
|
|
140
|
+
base: path2.relative(outDir, options2.base)
|
|
141
|
+
},
|
|
142
|
+
null,
|
|
143
|
+
2
|
|
144
|
+
)})`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
for (const [name, collection] of config.collections.entries()) {
|
|
148
|
+
let body;
|
|
149
|
+
if (collection.type === "docs") {
|
|
150
|
+
body = docs(name, collection);
|
|
151
|
+
} else if (collection.type === "meta") {
|
|
152
|
+
body = meta(name, collection);
|
|
153
|
+
} else {
|
|
154
|
+
body = doc(name, collection);
|
|
155
|
+
}
|
|
156
|
+
lines.push("");
|
|
157
|
+
lines.push(`export const ${name} = ${body};`);
|
|
158
|
+
}
|
|
159
|
+
return lines.join("\n");
|
|
160
|
+
}
|
|
161
|
+
function mapGlobPatterns(patterns) {
|
|
162
|
+
return patterns.map(enforceRelative);
|
|
163
|
+
}
|
|
164
|
+
function enforceRelative(file) {
|
|
165
|
+
if (file.startsWith("./")) return file;
|
|
166
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
167
|
+
return `./${file}`;
|
|
168
|
+
}
|
|
169
|
+
function getGlobBase(collection) {
|
|
170
|
+
let dir = collection.dir;
|
|
171
|
+
if (Array.isArray(dir)) {
|
|
172
|
+
if (dir.length !== 1)
|
|
173
|
+
throw new Error(
|
|
174
|
+
`[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
|
|
175
|
+
);
|
|
176
|
+
dir = dir[0];
|
|
177
|
+
}
|
|
178
|
+
return enforceRelative(dir);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/vite/index.ts
|
|
182
|
+
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
183
|
+
async function mdx(config, pluginOptions = {}) {
|
|
184
|
+
const options = applyDefaults(pluginOptions);
|
|
185
|
+
const core = await createViteCore(options).init({
|
|
186
|
+
config: buildConfig(config)
|
|
187
|
+
});
|
|
188
|
+
const mdxLoader = toVite(createMdxLoader(core.creatConfigLoader()));
|
|
189
|
+
async function transformMeta(path4, query, value) {
|
|
190
|
+
const isJson = path4.endsWith(".json");
|
|
191
|
+
const parsed = parse(query);
|
|
192
|
+
const collection = parsed.collection ? core.getConfig().collections.get(parsed.collection) : void 0;
|
|
193
|
+
if (!collection) return null;
|
|
194
|
+
let schema;
|
|
195
|
+
switch (collection.type) {
|
|
196
|
+
case "meta":
|
|
197
|
+
schema = collection.schema;
|
|
198
|
+
break;
|
|
199
|
+
case "docs":
|
|
200
|
+
schema = collection.meta.schema;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
if (!schema) return null;
|
|
204
|
+
let data;
|
|
205
|
+
try {
|
|
206
|
+
data = isJson ? JSON.parse(value) : load(value);
|
|
207
|
+
} catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const out = await validate(
|
|
211
|
+
schema,
|
|
212
|
+
data,
|
|
213
|
+
{ path: path4, source: value },
|
|
214
|
+
`invalid data in ${path4}`
|
|
215
|
+
);
|
|
216
|
+
return {
|
|
217
|
+
code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
|
|
218
|
+
map: null
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
name: "fumadocs-mdx",
|
|
223
|
+
// needed, otherwise other plugins will be executed before our `transform`.
|
|
224
|
+
enforce: "pre",
|
|
225
|
+
config(config2) {
|
|
226
|
+
if (!options.updateViteConfig) return config2;
|
|
227
|
+
return mergeConfig(config2, {
|
|
228
|
+
optimizeDeps: {
|
|
229
|
+
exclude: FumadocsDeps
|
|
230
|
+
},
|
|
231
|
+
resolve: {
|
|
232
|
+
noExternal: FumadocsDeps,
|
|
233
|
+
dedupe: FumadocsDeps
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
async buildStart() {
|
|
238
|
+
await core.emitAndWrite();
|
|
239
|
+
},
|
|
240
|
+
async configureServer(server) {
|
|
241
|
+
await core.initServer({
|
|
242
|
+
watcher: server.watcher
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
async transform(value, id) {
|
|
246
|
+
const [file, query = ""] = id.split("?");
|
|
247
|
+
const ext = path3.extname(file);
|
|
248
|
+
try {
|
|
249
|
+
if ([".yaml", ".json"].includes(ext))
|
|
250
|
+
return await transformMeta(file, query, value);
|
|
251
|
+
if ([".md", ".mdx"].includes(ext))
|
|
252
|
+
return await mdxLoader.call(this, file, query, value);
|
|
253
|
+
} catch (e) {
|
|
254
|
+
if (e instanceof ValidationError) {
|
|
255
|
+
throw new Error(e.toStringFormatted());
|
|
256
|
+
}
|
|
257
|
+
throw e;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
async function postInstall(configPath = findConfigFile(), pluginOptions = {}) {
|
|
263
|
+
const { loadConfig } = await import("../load-MNG3CLET.js");
|
|
264
|
+
const options = applyDefaults(pluginOptions);
|
|
265
|
+
const core = await createViteCore(options).init({
|
|
266
|
+
config: loadConfig(configPath, options.outDir, true)
|
|
267
|
+
});
|
|
268
|
+
await core.emitAndWrite();
|
|
269
|
+
}
|
|
270
|
+
function createViteCore({
|
|
271
|
+
configPath,
|
|
272
|
+
outDir,
|
|
273
|
+
generateIndexFile
|
|
274
|
+
}) {
|
|
275
|
+
return createCore(
|
|
276
|
+
{
|
|
277
|
+
environment: "vite",
|
|
278
|
+
configPath,
|
|
279
|
+
outDir
|
|
280
|
+
},
|
|
281
|
+
[
|
|
282
|
+
generateIndexFile !== false && vite(typeof generateIndexFile === "object" ? generateIndexFile : {})
|
|
283
|
+
]
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
function applyDefaults(options) {
|
|
287
|
+
return {
|
|
288
|
+
updateViteConfig: options.updateViteConfig ?? true,
|
|
289
|
+
generateIndexFile: options.generateIndexFile ?? true,
|
|
290
|
+
configPath: options.configPath ?? "source.config.ts",
|
|
291
|
+
outDir: options.outDir ?? ".source"
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
export {
|
|
295
|
+
mdx as default,
|
|
296
|
+
postInstall
|
|
297
|
+
};
|