fumadocs-mdx 12.0.3 → 13.0.0
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 +1033 -308
- package/dist/bin.js +4 -4
- package/dist/build-mdx-BHG-_uxo.d.cts +53 -0
- package/dist/build-mdx-CzrQDBRZ.d.ts +53 -0
- package/dist/bun/index.cjs +92 -28
- package/dist/bun/index.js +6 -7
- package/dist/{chunk-QAUWMR5D.js → chunk-3J3WL7WN.js} +23 -5
- package/dist/chunk-4MAYA5QX.js +44 -0
- package/dist/{chunk-RMDXSZYE.js → chunk-CEA6MYJU.js} +13 -8
- package/dist/{chunk-IQAEAI4P.js → chunk-HI62EXSB.js} +63 -2
- package/dist/{chunk-46UPKP5R.js → chunk-II3H5ZVZ.js} +5 -5
- package/dist/{chunk-LGYVNESJ.js → chunk-JVZFH6ND.js} +6 -22
- package/dist/{chunk-LMG6UWCL.js → chunk-K5ZLPEIQ.js} +56 -16
- package/dist/{chunk-OMAMTKDE.js → chunk-KILFIBVW.js} +3 -12
- package/dist/chunk-NVRDCY6Z.js +30 -0
- package/dist/{chunk-VXEBLM4X.js → chunk-XV5Z4BFL.js} +1 -1
- package/dist/config/index.cjs +56 -16
- package/dist/config/index.d.cts +2 -1
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -1
- package/dist/{define-DJbJduHy.d.ts → define-BCNh3n4O.d.cts} +40 -16
- package/dist/{define-DJbJduHy.d.cts → define-bck_EB4t.d.ts} +40 -16
- package/dist/index.cjs +0 -109
- package/dist/index.d.cts +73 -12
- package/dist/index.d.ts +73 -12
- package/dist/index.js +0 -11
- package/dist/{load-UUXLUBHL.js → load-MNG3CLET.js} +1 -3
- package/dist/loader-mdx.cjs +153 -60
- package/dist/loader-mdx.d.cts +1 -0
- package/dist/loader-mdx.d.ts +1 -0
- package/dist/loader-mdx.js +23 -9
- package/dist/next/index.cjs +213 -181
- package/dist/next/index.d.cts +2 -11
- package/dist/next/index.d.ts +2 -11
- package/dist/next/index.js +145 -117
- package/dist/node/loader.cjs +128 -70
- package/dist/node/loader.js +14 -9
- package/dist/plugins/index.cjs +78 -0
- package/dist/plugins/index.d.cts +7 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/index.js +6 -0
- package/dist/plugins/json-schema.cjs +61 -0
- package/dist/plugins/json-schema.d.cts +16 -0
- package/dist/plugins/json-schema.d.ts +16 -0
- package/dist/plugins/json-schema.js +40 -0
- package/dist/remark-postprocess-K233ZVBK.d.cts +22 -0
- package/dist/remark-postprocess-K233ZVBK.d.ts +22 -0
- package/dist/runtime/next/async.cjs +108 -70
- package/dist/runtime/next/async.d.cts +9 -6
- package/dist/runtime/next/async.d.ts +9 -6
- package/dist/runtime/next/async.js +9 -19
- package/dist/runtime/next/index.cjs +25 -14
- package/dist/runtime/next/index.d.cts +11 -8
- package/dist/runtime/next/index.d.ts +11 -8
- package/dist/runtime/next/index.js +2 -2
- package/dist/runtime/vite/browser.cjs +7 -3
- package/dist/runtime/vite/browser.d.cts +56 -7
- package/dist/runtime/vite/browser.d.ts +56 -7
- package/dist/runtime/vite/browser.js +2 -1
- package/dist/runtime/vite/server.cjs +40 -34
- package/dist/runtime/vite/server.d.cts +13 -10
- package/dist/runtime/vite/server.d.ts +13 -10
- package/dist/runtime/vite/server.js +8 -23
- package/dist/{types-TeHjsmja.d.ts → types-1cCFEzWt.d.ts} +3 -10
- package/dist/{types-BRx1QsIJ.d.cts → types-D5NhXTJY.d.cts} +3 -10
- package/dist/vite/index.cjs +386 -224
- package/dist/vite/index.d.cts +23 -10
- package/dist/vite/index.d.ts +23 -10
- package/dist/vite/index.js +211 -37
- package/dist/{watcher-HGOH3APP.js → watcher-WXJDWRZY.js} +1 -1
- package/package.json +28 -15
- package/dist/browser-BupUnhpC.d.ts +0 -98
- package/dist/browser-R0x9IPaQ.d.cts +0 -98
- package/dist/chunk-ADR6R7HM.js +0 -29
- package/dist/chunk-XMFLD5J6.js +0 -30
- package/dist/chunk-ZLCSVXCD.js +0 -10
- package/dist/chunk-ZX7TM4AR.js +0 -127
- package/dist/postinstall-SCSXM4IM.js +0 -10
- package/dist/shared-CfiiRctw.d.ts +0 -70
- package/dist/shared-fFqiuWJC.d.cts +0 -70
package/dist/next/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
readFileWithCache,
|
|
3
|
-
removeFileCache
|
|
4
|
-
} from "../chunk-ADR6R7HM.js";
|
|
5
1
|
import {
|
|
6
2
|
getGlobPatterns,
|
|
7
3
|
getImportCode,
|
|
@@ -9,32 +5,74 @@ import {
|
|
|
9
5
|
toImportPath
|
|
10
6
|
} from "../chunk-6Y5JDZHD.js";
|
|
11
7
|
import {
|
|
12
|
-
getConfigHash,
|
|
13
8
|
loadConfig
|
|
14
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-JVZFH6ND.js";
|
|
15
10
|
import "../chunk-U4MQ44TS.js";
|
|
16
11
|
import {
|
|
17
12
|
ValidationError,
|
|
13
|
+
findConfigFile,
|
|
18
14
|
getGitTimestamp,
|
|
19
15
|
validate
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import {
|
|
22
|
-
findConfigFile
|
|
23
|
-
} from "../chunk-XMFLD5J6.js";
|
|
16
|
+
} from "../chunk-HI62EXSB.js";
|
|
24
17
|
import {
|
|
25
18
|
fumaMatter
|
|
26
19
|
} from "../chunk-VWJKRQZR.js";
|
|
20
|
+
import {
|
|
21
|
+
createPluginHandler
|
|
22
|
+
} from "../chunk-4MAYA5QX.js";
|
|
27
23
|
|
|
28
24
|
// src/next/index.ts
|
|
29
|
-
import path3 from "path";
|
|
30
|
-
import fs2 from "fs/promises";
|
|
25
|
+
import * as path3 from "path";
|
|
31
26
|
|
|
32
|
-
// src/next/
|
|
33
|
-
import
|
|
27
|
+
// src/next/file-cache.ts
|
|
28
|
+
import { LRUCache } from "lru-cache";
|
|
29
|
+
import fs from "fs/promises";
|
|
30
|
+
import path from "path";
|
|
31
|
+
var map = new LRUCache({
|
|
32
|
+
max: 100
|
|
33
|
+
});
|
|
34
|
+
function toFullPath(file) {
|
|
35
|
+
if (path.isAbsolute(file)) {
|
|
36
|
+
return path.relative(process.cwd(), file);
|
|
37
|
+
}
|
|
38
|
+
return file;
|
|
39
|
+
}
|
|
40
|
+
async function readFileWithCache(file) {
|
|
41
|
+
const fullPath = toFullPath(file);
|
|
42
|
+
const cached = map.get(fullPath);
|
|
43
|
+
if (cached) return cached;
|
|
44
|
+
const read = fs.readFile(fullPath).then((s) => s.toString());
|
|
45
|
+
map.set(fullPath, read);
|
|
46
|
+
return read;
|
|
47
|
+
}
|
|
48
|
+
function removeFileCache(file) {
|
|
49
|
+
map.delete(toFullPath(file));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/plugins/next.ts
|
|
53
|
+
import * as path2 from "path";
|
|
34
54
|
import { createHash } from "crypto";
|
|
35
55
|
import { glob } from "tinyglobby";
|
|
36
56
|
import { load } from "js-yaml";
|
|
37
|
-
|
|
57
|
+
function next() {
|
|
58
|
+
let config;
|
|
59
|
+
return {
|
|
60
|
+
config(v) {
|
|
61
|
+
config = v;
|
|
62
|
+
},
|
|
63
|
+
async emit() {
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
path: "index.ts",
|
|
67
|
+
content: await indexFile(this.configPath, config, {
|
|
68
|
+
relativeTo: this.outDir
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async function indexFile(configPath, config, importPath, configHash = false) {
|
|
38
76
|
let asyncInit = false;
|
|
39
77
|
const lines = [
|
|
40
78
|
getImportCode({
|
|
@@ -170,11 +208,11 @@ async function getCollectionFiles(collection) {
|
|
|
170
208
|
await Promise.all(
|
|
171
209
|
dirs.map(async (dir) => {
|
|
172
210
|
const result = await glob(patterns, {
|
|
173
|
-
cwd:
|
|
211
|
+
cwd: path2.resolve(dir)
|
|
174
212
|
});
|
|
175
213
|
for (const item of result) {
|
|
176
214
|
if (!isFileSupported(item, collection)) continue;
|
|
177
|
-
const fullPath =
|
|
215
|
+
const fullPath = path2.join(dir, item);
|
|
178
216
|
files.set(fullPath, {
|
|
179
217
|
path: item,
|
|
180
218
|
fullPath
|
|
@@ -185,7 +223,7 @@ async function getCollectionFiles(collection) {
|
|
|
185
223
|
return Array.from(files.values());
|
|
186
224
|
}
|
|
187
225
|
function parseMetaEntry(file, content) {
|
|
188
|
-
const extname2 =
|
|
226
|
+
const extname2 = path2.extname(file);
|
|
189
227
|
try {
|
|
190
228
|
if (extname2 === ".json") return JSON.parse(content);
|
|
191
229
|
if (extname2 === ".yaml") return load(content);
|
|
@@ -197,91 +235,23 @@ function parseMetaEntry(file, content) {
|
|
|
197
235
|
throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
|
|
198
236
|
}
|
|
199
237
|
|
|
200
|
-
// src/next/
|
|
201
|
-
import * as path2 from "path";
|
|
202
|
-
import * as fs from "fs/promises";
|
|
203
|
-
async function start(dev, configPath, outDir) {
|
|
204
|
-
let configHash = await getConfigHash(configPath);
|
|
205
|
-
let config = await loadConfig(configPath, outDir, configHash, true);
|
|
206
|
-
const outPath = path2.resolve(outDir, `index.ts`);
|
|
207
|
-
async function updateMapFile() {
|
|
208
|
-
const start2 = performance.now();
|
|
209
|
-
try {
|
|
210
|
-
await fs.writeFile(
|
|
211
|
-
outPath,
|
|
212
|
-
await generateJS(
|
|
213
|
-
configPath,
|
|
214
|
-
config,
|
|
215
|
-
{ relativeTo: outDir },
|
|
216
|
-
configHash
|
|
217
|
-
)
|
|
218
|
-
);
|
|
219
|
-
} catch (err) {
|
|
220
|
-
if (err instanceof ValidationError) {
|
|
221
|
-
console.error(err.toStringFormatted());
|
|
222
|
-
} else {
|
|
223
|
-
console.error(err);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
console.log(`[MDX] updated map file in ${performance.now() - start2}ms`);
|
|
227
|
-
}
|
|
228
|
-
await updateMapFile();
|
|
229
|
-
if (dev) {
|
|
230
|
-
const { watcher } = await import("../watcher-HGOH3APP.js");
|
|
231
|
-
const instance = watcher(configPath, config, [outPath]);
|
|
232
|
-
instance.on("ready", () => {
|
|
233
|
-
console.log("[MDX] started dev server");
|
|
234
|
-
});
|
|
235
|
-
instance.on("all", (event, file) => {
|
|
236
|
-
if (typeof file !== "string") return;
|
|
237
|
-
const absolutePath = path2.resolve(file);
|
|
238
|
-
const onUpdate = async () => {
|
|
239
|
-
const isConfigFile = absolutePath === configPath;
|
|
240
|
-
if (isConfigFile) {
|
|
241
|
-
configHash = await getConfigHash(configPath);
|
|
242
|
-
config = await loadConfig(configPath, outDir, configHash, true);
|
|
243
|
-
}
|
|
244
|
-
if (event === "change") removeFileCache(absolutePath);
|
|
245
|
-
await updateMapFile();
|
|
246
|
-
};
|
|
247
|
-
void onUpdate();
|
|
248
|
-
});
|
|
249
|
-
process.on("exit", () => {
|
|
250
|
-
console.log("[MDX] closing dev server");
|
|
251
|
-
void instance.close();
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// src/next/create.ts
|
|
257
|
-
import { readFileSync } from "fs";
|
|
238
|
+
// src/next/index.ts
|
|
258
239
|
var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
const version = JSON.parse(content).version;
|
|
263
|
-
isTurboExperimental = version.startsWith("15.0.") || version.startsWith("15.1.") || version.startsWith("15.2.");
|
|
264
|
-
} catch {
|
|
265
|
-
isTurboExperimental = false;
|
|
266
|
-
}
|
|
267
|
-
function createMDX({
|
|
268
|
-
configPath = findConfigFile(),
|
|
269
|
-
outDir = ".source"
|
|
270
|
-
} = {}) {
|
|
240
|
+
function createMDX(createOptions = {}) {
|
|
241
|
+
const options = applyDefaults(createOptions);
|
|
242
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
271
243
|
if (process.env._FUMADOCS_MDX !== "1") {
|
|
272
244
|
process.env._FUMADOCS_MDX = "1";
|
|
273
|
-
void
|
|
245
|
+
void init(isDev, options);
|
|
274
246
|
}
|
|
275
247
|
return (nextConfig = {}) => {
|
|
276
248
|
const mdxLoaderOptions = {
|
|
277
|
-
|
|
278
|
-
|
|
249
|
+
...options,
|
|
250
|
+
isDev
|
|
279
251
|
};
|
|
280
|
-
const
|
|
281
|
-
...nextConfig.experimental?.turbo,
|
|
252
|
+
const turbopack = {
|
|
282
253
|
...nextConfig.turbopack,
|
|
283
254
|
rules: {
|
|
284
|
-
...nextConfig.experimental?.turbo?.rules,
|
|
285
255
|
...nextConfig.turbopack?.rules,
|
|
286
256
|
"*.{md,mdx}": {
|
|
287
257
|
loaders: [
|
|
@@ -294,17 +264,18 @@ function createMDX({
|
|
|
294
264
|
}
|
|
295
265
|
}
|
|
296
266
|
};
|
|
297
|
-
|
|
267
|
+
return {
|
|
298
268
|
...nextConfig,
|
|
269
|
+
turbopack,
|
|
299
270
|
pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
|
|
300
|
-
webpack: (config,
|
|
271
|
+
webpack: (config, options2) => {
|
|
301
272
|
config.resolve ||= {};
|
|
302
273
|
config.module ||= {};
|
|
303
274
|
config.module.rules ||= [];
|
|
304
275
|
config.module.rules.push({
|
|
305
276
|
test: /\.mdx?$/,
|
|
306
277
|
use: [
|
|
307
|
-
|
|
278
|
+
options2.defaultLoaders.babel,
|
|
308
279
|
{
|
|
309
280
|
loader: "fumadocs-mdx/loader-mdx",
|
|
310
281
|
options: mdxLoaderOptions
|
|
@@ -312,33 +283,90 @@ function createMDX({
|
|
|
312
283
|
]
|
|
313
284
|
});
|
|
314
285
|
config.plugins ||= [];
|
|
315
|
-
return nextConfig.webpack?.(config,
|
|
286
|
+
return nextConfig.webpack?.(config, options2) ?? config;
|
|
316
287
|
}
|
|
317
288
|
};
|
|
318
|
-
if (isTurboExperimental) {
|
|
319
|
-
updated.experimental = { ...updated.experimental, turbo };
|
|
320
|
-
} else {
|
|
321
|
-
updated.turbopack = turbo;
|
|
322
|
-
}
|
|
323
|
-
return updated;
|
|
324
289
|
};
|
|
325
290
|
}
|
|
326
|
-
|
|
327
|
-
|
|
291
|
+
async function init(dev, options) {
|
|
292
|
+
const pluginHandler = createNextPluginHandler(options);
|
|
293
|
+
let config;
|
|
294
|
+
async function updateConfig() {
|
|
295
|
+
config = await pluginHandler.init(
|
|
296
|
+
await loadConfig(options.configPath, options.outDir, true)
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
async function emitFiles() {
|
|
300
|
+
const start = performance.now();
|
|
301
|
+
try {
|
|
302
|
+
await pluginHandler.emitAndWrite();
|
|
303
|
+
} catch (err) {
|
|
304
|
+
if (err instanceof ValidationError) {
|
|
305
|
+
console.error(err.toStringFormatted());
|
|
306
|
+
} else {
|
|
307
|
+
console.error(err);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
console.log(`[MDX] updated map file in ${performance.now() - start}ms`);
|
|
311
|
+
}
|
|
312
|
+
async function devServer() {
|
|
313
|
+
const { watcher } = await import("../watcher-WXJDWRZY.js");
|
|
314
|
+
const instance = watcher(options.configPath, config, [options.outDir]);
|
|
315
|
+
async function onUpdate(event, file) {
|
|
316
|
+
const absolutePath = path3.resolve(file);
|
|
317
|
+
if (event === "change") removeFileCache(absolutePath);
|
|
318
|
+
if (absolutePath === path3.resolve(options.configPath)) {
|
|
319
|
+
await updateConfig();
|
|
320
|
+
console.log("[MDX] restarting dev server");
|
|
321
|
+
await instance.close();
|
|
322
|
+
void devServer();
|
|
323
|
+
}
|
|
324
|
+
await emitFiles();
|
|
325
|
+
}
|
|
326
|
+
instance.on("ready", () => {
|
|
327
|
+
console.log("[MDX] started dev server");
|
|
328
|
+
});
|
|
329
|
+
instance.on("all", (event, file) => {
|
|
330
|
+
void onUpdate(event, file);
|
|
331
|
+
});
|
|
332
|
+
process.on("exit", () => {
|
|
333
|
+
console.log("[MDX] closing dev server");
|
|
334
|
+
void instance.close();
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
await updateConfig();
|
|
338
|
+
await emitFiles();
|
|
339
|
+
if (dev) void devServer();
|
|
340
|
+
}
|
|
328
341
|
async function postInstall(configPath = findConfigFile(), outDir = ".source") {
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
await
|
|
335
|
-
outPath,
|
|
336
|
-
await generateJS(configPath, config, { relativeTo: outDir }, hash)
|
|
337
|
-
);
|
|
342
|
+
const pluginHandler = createNextPluginHandler({
|
|
343
|
+
outDir,
|
|
344
|
+
configPath
|
|
345
|
+
});
|
|
346
|
+
await pluginHandler.init(await loadConfig(configPath, outDir, true));
|
|
347
|
+
await pluginHandler.emitAndWrite();
|
|
338
348
|
console.log("[MDX] types generated");
|
|
339
349
|
}
|
|
350
|
+
function applyDefaults(options) {
|
|
351
|
+
return {
|
|
352
|
+
outDir: options.outDir ?? ".source",
|
|
353
|
+
configPath: options.configPath ?? findConfigFile()
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function createNextPluginHandler({
|
|
357
|
+
outDir,
|
|
358
|
+
configPath
|
|
359
|
+
}) {
|
|
360
|
+
return createPluginHandler(
|
|
361
|
+
{
|
|
362
|
+
environment: "next",
|
|
363
|
+
outDir,
|
|
364
|
+
configPath
|
|
365
|
+
},
|
|
366
|
+
[next()]
|
|
367
|
+
);
|
|
368
|
+
}
|
|
340
369
|
export {
|
|
341
370
|
createMDX,
|
|
342
|
-
postInstall
|
|
343
|
-
start
|
|
371
|
+
postInstall
|
|
344
372
|
};
|