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.
- package/dist/bin.cjs +353 -273
- package/dist/bin.js +1 -1
- package/dist/{build-mdx-TtQzmq6W.d.cts → build-mdx-BjXOmv0b.d.cts} +1 -1
- package/dist/{build-mdx--WI4tf2-.d.ts → build-mdx-CY5UldCO.d.ts} +1 -1
- package/dist/bun/index.cjs +177 -57
- package/dist/bun/index.d.cts +2 -2
- package/dist/bun/index.d.ts +2 -2
- package/dist/bun/index.js +26 -34
- package/dist/chunk-2HXTGJBI.js +101 -0
- package/dist/chunk-4JSFLXXT.js +8 -0
- package/dist/{chunk-JVZFH6ND.js → chunk-QXHN25N3.js} +2 -2
- package/dist/{chunk-EELYB2XC.js → chunk-TZ5EQBFW.js} +9 -103
- package/dist/chunk-VUEZTR2H.js +26 -0
- package/dist/{chunk-XQ5O7IPO.js → chunk-XYGORKQA.js} +5 -3
- package/dist/chunk-YAIPHUCZ.js +56 -0
- package/dist/chunk-ZNVPB2IR.js +170 -0
- package/dist/config/index.d.cts +2 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/{core-DhfmVKRA.d.cts → core-DB7TdlyC.d.cts} +21 -7
- package/dist/{core-DhfmVKRA.d.ts → core-DB7TdlyC.d.ts} +21 -7
- package/dist/index-D7s7kCc2.d.cts +7 -0
- package/dist/index-D7s7kCc2.d.ts +7 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/load-from-file-AVYOFOI7.js +7 -0
- package/dist/next/index.cjs +145 -139
- package/dist/next/index.js +56 -36
- package/dist/node/loader.cjs +242 -128
- package/dist/node/loader.d.cts +2 -2
- package/dist/node/loader.d.ts +2 -2
- package/dist/node/loader.js +29 -16
- package/dist/plugins/json-schema.cjs +22 -70
- package/dist/plugins/json-schema.d.cts +2 -2
- package/dist/plugins/json-schema.d.ts +2 -2
- package/dist/plugins/json-schema.js +19 -14
- package/dist/runtime/next/async.cjs +56 -11
- package/dist/runtime/next/async.d.cts +4 -6
- package/dist/runtime/next/async.d.ts +4 -6
- package/dist/runtime/next/async.js +3 -6
- package/dist/runtime/next/index.d.cts +5 -5
- package/dist/runtime/next/index.d.ts +5 -5
- package/dist/runtime/vite/browser.d.cts +3 -3
- package/dist/runtime/vite/browser.d.ts +3 -3
- package/dist/runtime/vite/server.d.cts +3 -3
- package/dist/runtime/vite/server.d.ts +3 -3
- package/dist/{types-zrV4v6mp.d.cts → types-Bnh9n7mj.d.cts} +2 -2
- package/dist/{types-CMva20Zp.d.ts → types-ey1AZqrg.d.ts} +2 -2
- package/dist/vite/index.cjs +238 -159
- package/dist/vite/index.js +113 -118
- package/dist/webpack/{index.cjs → mdx.cjs} +126 -104
- package/dist/webpack/mdx.d.cts +6 -0
- package/dist/webpack/mdx.d.ts +6 -0
- package/dist/webpack/{index.js → mdx.js} +12 -14
- package/dist/webpack/meta.cjs +528 -0
- package/dist/webpack/meta.d.cts +6 -0
- package/dist/webpack/meta.d.ts +6 -0
- package/dist/webpack/meta.js +42 -0
- package/loader-mdx.cjs +1 -1
- package/loader-meta.cjs +7 -0
- package/package.json +6 -3
- package/dist/chunk-U4MQ44TS.js +0 -53
- package/dist/chunk-XZY2AWJI.js +0 -81
- package/dist/chunk-YVCR6FUH.js +0 -82
- package/dist/load-MNG3CLET.js +0 -7
- package/dist/webpack/index.d.cts +0 -15
- package/dist/webpack/index.d.ts +0 -15
package/dist/vite/index.js
CHANGED
|
@@ -4,33 +4,33 @@ import {
|
|
|
4
4
|
} from "../chunk-CXA4JO4Z.js";
|
|
5
5
|
import {
|
|
6
6
|
buildConfig
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import {
|
|
9
|
-
toVite
|
|
10
|
-
} from "../chunk-YVCR6FUH.js";
|
|
7
|
+
} from "../chunk-2HXTGJBI.js";
|
|
11
8
|
import {
|
|
12
9
|
createMdxLoader
|
|
13
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-XYGORKQA.js";
|
|
11
|
+
import {
|
|
12
|
+
createMetaLoader
|
|
13
|
+
} from "../chunk-YAIPHUCZ.js";
|
|
14
|
+
import {
|
|
15
|
+
createIntegratedConfigLoader,
|
|
16
|
+
toVite
|
|
17
|
+
} from "../chunk-ZNVPB2IR.js";
|
|
14
18
|
import "../chunk-3J3WL7WN.js";
|
|
15
19
|
import "../chunk-K5ZLPEIQ.js";
|
|
20
|
+
import {
|
|
21
|
+
mdxLoaderGlob,
|
|
22
|
+
metaLoaderGlob
|
|
23
|
+
} from "../chunk-4JSFLXXT.js";
|
|
24
|
+
import "../chunk-VUEZTR2H.js";
|
|
16
25
|
import {
|
|
17
26
|
ValidationError,
|
|
18
27
|
createCore,
|
|
19
|
-
findConfigFile
|
|
20
|
-
|
|
21
|
-
} from "../chunk-EELYB2XC.js";
|
|
28
|
+
findConfigFile
|
|
29
|
+
} from "../chunk-TZ5EQBFW.js";
|
|
22
30
|
import "../chunk-VWJKRQZR.js";
|
|
23
|
-
import {
|
|
24
|
-
getGlobPatterns
|
|
25
|
-
} from "../chunk-XZY2AWJI.js";
|
|
26
31
|
|
|
27
32
|
// 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";
|
|
33
|
+
import { mergeConfig } from "vite";
|
|
34
34
|
|
|
35
35
|
// src/utils/glob-import.ts
|
|
36
36
|
import { globSync } from "tinyglobby";
|
|
@@ -63,16 +63,35 @@ function vite({
|
|
|
63
63
|
index
|
|
64
64
|
}) {
|
|
65
65
|
let config;
|
|
66
|
+
let indexOptions;
|
|
67
|
+
if (index === false) indexOptions = false;
|
|
68
|
+
else indexOptions = applyDefaults(index === true ? {} : index);
|
|
66
69
|
return {
|
|
70
|
+
name: "vite",
|
|
67
71
|
config(v) {
|
|
68
72
|
config = v;
|
|
69
73
|
},
|
|
74
|
+
configureServer(server) {
|
|
75
|
+
if (!server.watcher || indexOptions === false || indexOptions.runtime === false)
|
|
76
|
+
return;
|
|
77
|
+
server.watcher.on("all", (event, file) => {
|
|
78
|
+
if (event === "change") return;
|
|
79
|
+
const isUpdated = config.collectionList.some((collection) => {
|
|
80
|
+
if (collection.type === "docs")
|
|
81
|
+
return collection.docs.hasFile(file) || collection.meta.hasFile(file);
|
|
82
|
+
return collection.hasFile(file);
|
|
83
|
+
});
|
|
84
|
+
if (isUpdated) {
|
|
85
|
+
this.core.emitAndWrite({
|
|
86
|
+
filterPlugin: (plugin) => plugin.name === "vite"
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
},
|
|
70
91
|
emit() {
|
|
71
92
|
const out = [];
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
const { browser = false } = indexOptions;
|
|
75
|
-
if (browser) {
|
|
93
|
+
if (indexOptions === false) return out;
|
|
94
|
+
if (indexOptions.browser) {
|
|
76
95
|
out.push({
|
|
77
96
|
path: "browser.ts",
|
|
78
97
|
content: indexFile(this, config, indexOptions, "browser")
|
|
@@ -84,15 +103,21 @@ function vite({
|
|
|
84
103
|
this,
|
|
85
104
|
config,
|
|
86
105
|
indexOptions,
|
|
87
|
-
browser ? "server" : "all"
|
|
106
|
+
indexOptions.browser ? "server" : "all"
|
|
88
107
|
)
|
|
89
108
|
});
|
|
90
109
|
return out;
|
|
91
110
|
}
|
|
92
111
|
};
|
|
93
112
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
113
|
+
function applyDefaults(options) {
|
|
114
|
+
return {
|
|
115
|
+
addJsExtension: options.addJsExtension ?? false,
|
|
116
|
+
browser: options.browser ?? false,
|
|
117
|
+
runtime: options.runtime ?? false
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function indexFile({ configPath, outDir }, config, { addJsExtension, runtime }, environment) {
|
|
96
121
|
const runtimePath = {
|
|
97
122
|
all: "fumadocs-mdx/runtime/vite",
|
|
98
123
|
server: "fumadocs-mdx/runtime/vite.server",
|
|
@@ -108,74 +133,68 @@ function indexFile({ configPath, outDir }, config, options, environment) {
|
|
|
108
133
|
"",
|
|
109
134
|
`export const create = fromConfig<typeof Config>();`
|
|
110
135
|
];
|
|
111
|
-
function
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
136
|
+
function generateCollectionGlob(collection) {
|
|
137
|
+
if (collection.type === "docs") {
|
|
138
|
+
const obj = [
|
|
139
|
+
ident(`doc: ${generateCollectionGlob(collection.docs)}`),
|
|
140
|
+
ident(`meta: ${generateCollectionGlob(collection.meta)}`)
|
|
141
|
+
].join(",\n");
|
|
142
|
+
return `{
|
|
117
143
|
${obj}
|
|
118
144
|
}`;
|
|
119
|
-
|
|
120
|
-
function doc(name, collection) {
|
|
121
|
-
const patterns = getGlobPatterns(collection);
|
|
145
|
+
}
|
|
122
146
|
const dir = getCollectionDir(collection);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
collection: name
|
|
126
|
-
},
|
|
127
|
-
base: dir
|
|
128
|
-
});
|
|
129
|
-
if (collection.async) {
|
|
130
|
-
const headBlob = generateGlob(patterns, {
|
|
147
|
+
if (collection.type === "doc") {
|
|
148
|
+
const docGlob = generateGlob(collection.patterns, {
|
|
131
149
|
query: {
|
|
132
|
-
|
|
133
|
-
collection: name
|
|
150
|
+
collection: collection.name
|
|
134
151
|
},
|
|
135
|
-
import: "frontmatter",
|
|
136
152
|
base: dir
|
|
137
153
|
});
|
|
138
|
-
|
|
154
|
+
if (collection.async) {
|
|
155
|
+
const headBlob = generateGlob(collection.patterns, {
|
|
156
|
+
query: {
|
|
157
|
+
only: "frontmatter",
|
|
158
|
+
collection: collection.name
|
|
159
|
+
},
|
|
160
|
+
import: "frontmatter",
|
|
161
|
+
base: dir
|
|
162
|
+
});
|
|
163
|
+
return `create.docLazy("${collection.name}", "${dir}", ${headBlob}, ${docGlob})`;
|
|
164
|
+
}
|
|
165
|
+
return `create.doc("${collection.name}", "${dir}", ${docGlob})`;
|
|
139
166
|
}
|
|
140
|
-
return `create.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
query: {
|
|
149
|
-
collection: name
|
|
167
|
+
return `create.meta("${collection.name}", "${dir}", ${generateGlob(
|
|
168
|
+
collection.patterns,
|
|
169
|
+
{
|
|
170
|
+
import: "default",
|
|
171
|
+
base: dir,
|
|
172
|
+
query: {
|
|
173
|
+
collection: collection.name
|
|
174
|
+
}
|
|
150
175
|
}
|
|
151
|
-
|
|
176
|
+
)})`;
|
|
152
177
|
}
|
|
153
|
-
function generateGlob(patterns,
|
|
178
|
+
function generateGlob(patterns, options) {
|
|
154
179
|
patterns = patterns.map(normalizeGlobPath);
|
|
155
180
|
if (runtime === "node" || runtime === "bun") {
|
|
156
|
-
return generateGlobImport(patterns,
|
|
181
|
+
return generateGlobImport(patterns, options);
|
|
157
182
|
} else {
|
|
158
183
|
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
159
184
|
{
|
|
160
|
-
...
|
|
161
|
-
base: normalizeGlobPath(path2.relative(outDir,
|
|
185
|
+
...options,
|
|
186
|
+
base: normalizeGlobPath(path2.relative(outDir, options.base))
|
|
162
187
|
},
|
|
163
188
|
null,
|
|
164
189
|
2
|
|
165
190
|
)})`;
|
|
166
191
|
}
|
|
167
192
|
}
|
|
168
|
-
for (const
|
|
169
|
-
let body;
|
|
170
|
-
if (collection.type === "docs") {
|
|
171
|
-
body = docs(name, collection);
|
|
172
|
-
} else if (collection.type === "meta") {
|
|
173
|
-
body = meta(name, collection);
|
|
174
|
-
} else {
|
|
175
|
-
body = doc(name, collection);
|
|
176
|
-
}
|
|
193
|
+
for (const collection of config.collectionList) {
|
|
177
194
|
lines.push("");
|
|
178
|
-
lines.push(
|
|
195
|
+
lines.push(
|
|
196
|
+
`export const ${collection.name} = ${generateCollectionGlob(collection)};`
|
|
197
|
+
);
|
|
179
198
|
}
|
|
180
199
|
return lines.join("\n");
|
|
181
200
|
}
|
|
@@ -185,8 +204,7 @@ function normalizeGlobPath(file) {
|
|
|
185
204
|
if (file.startsWith("/")) return `.${file}`;
|
|
186
205
|
return `./${file}`;
|
|
187
206
|
}
|
|
188
|
-
function getCollectionDir(
|
|
189
|
-
const dir = collection.dir;
|
|
207
|
+
function getCollectionDir({ dir }) {
|
|
190
208
|
if (Array.isArray(dir)) {
|
|
191
209
|
if (dir.length !== 1)
|
|
192
210
|
throw new Error(
|
|
@@ -196,54 +214,29 @@ function getCollectionDir(collection) {
|
|
|
196
214
|
}
|
|
197
215
|
return dir;
|
|
198
216
|
}
|
|
199
|
-
function slash(
|
|
200
|
-
const isExtendedLengthPath =
|
|
217
|
+
function slash(path3) {
|
|
218
|
+
const isExtendedLengthPath = path3.startsWith("\\\\?\\");
|
|
201
219
|
if (isExtendedLengthPath) {
|
|
202
|
-
return
|
|
220
|
+
return path3;
|
|
203
221
|
}
|
|
204
|
-
return
|
|
222
|
+
return path3.replaceAll("\\", "/");
|
|
205
223
|
}
|
|
206
224
|
|
|
207
225
|
// src/vite/index.ts
|
|
208
226
|
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
209
227
|
async function mdx(config, pluginOptions = {}) {
|
|
210
|
-
const options =
|
|
228
|
+
const options = applyDefaults2(pluginOptions);
|
|
211
229
|
const core = await createViteCore(options).init({
|
|
212
230
|
config: buildConfig(config)
|
|
213
231
|
});
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
case "meta":
|
|
223
|
-
schema = collection.schema;
|
|
224
|
-
break;
|
|
225
|
-
case "docs":
|
|
226
|
-
schema = collection.meta.schema;
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
if (!schema) return null;
|
|
230
|
-
let data;
|
|
231
|
-
try {
|
|
232
|
-
data = isJson ? JSON.parse(value) : load(value);
|
|
233
|
-
} catch {
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
const out = await validate(
|
|
237
|
-
schema,
|
|
238
|
-
data,
|
|
239
|
-
{ path: path4, source: value },
|
|
240
|
-
`invalid data in ${path4}`
|
|
241
|
-
);
|
|
242
|
-
return {
|
|
243
|
-
code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
|
|
244
|
-
map: null
|
|
245
|
-
};
|
|
246
|
-
}
|
|
232
|
+
const configLoader = createIntegratedConfigLoader(core);
|
|
233
|
+
const mdxLoader = toVite(createMdxLoader(configLoader));
|
|
234
|
+
const metaLoader = toVite(
|
|
235
|
+
createMetaLoader(configLoader, {
|
|
236
|
+
// vite has built-in plugin for JSON files
|
|
237
|
+
json: "json"
|
|
238
|
+
})
|
|
239
|
+
);
|
|
247
240
|
return {
|
|
248
241
|
name: "fumadocs-mdx",
|
|
249
242
|
// needed, otherwise other plugins will be executed before our `transform`.
|
|
@@ -269,13 +262,15 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
269
262
|
});
|
|
270
263
|
},
|
|
271
264
|
async transform(value, id) {
|
|
272
|
-
const [file, query = ""] = id.split("?");
|
|
273
|
-
const ext = path3.extname(file);
|
|
274
265
|
try {
|
|
275
|
-
if (
|
|
276
|
-
|
|
277
|
-
|
|
266
|
+
if (metaLoaderGlob.test(id)) {
|
|
267
|
+
const [file, query = ""] = id.split("?", 2);
|
|
268
|
+
return await metaLoader.call(this, file, query, value);
|
|
269
|
+
}
|
|
270
|
+
if (mdxLoaderGlob.test(id)) {
|
|
271
|
+
const [file, query = ""] = id.split("?", 2);
|
|
278
272
|
return await mdxLoader.call(this, file, query, value);
|
|
273
|
+
}
|
|
279
274
|
} catch (e) {
|
|
280
275
|
if (e instanceof ValidationError) {
|
|
281
276
|
throw new Error(e.toStringFormatted());
|
|
@@ -286,8 +281,8 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
286
281
|
};
|
|
287
282
|
}
|
|
288
283
|
async function postInstall(configPath = findConfigFile(), pluginOptions = {}) {
|
|
289
|
-
const { loadConfig } = await import("../load-
|
|
290
|
-
const options =
|
|
284
|
+
const { loadConfig } = await import("../load-from-file-AVYOFOI7.js");
|
|
285
|
+
const options = applyDefaults2(pluginOptions);
|
|
291
286
|
const core = await createViteCore(options).init({
|
|
292
287
|
config: loadConfig(configPath, options.outDir, true)
|
|
293
288
|
});
|
|
@@ -311,7 +306,7 @@ function createViteCore({
|
|
|
311
306
|
]
|
|
312
307
|
);
|
|
313
308
|
}
|
|
314
|
-
function
|
|
309
|
+
function applyDefaults2(options) {
|
|
315
310
|
return {
|
|
316
311
|
updateViteConfig: options.updateViteConfig ?? true,
|
|
317
312
|
generateIndexFile: options.generateIndexFile ?? true,
|