fumadocs-mdx 11.5.2 → 11.5.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.
- package/dist/{chunk-USWGH3VH.js → chunk-2FUWXPXA.js} +4 -5
- package/dist/{chunk-3PXNPJQ2.js → chunk-IZURUUPO.js} +1 -1
- package/dist/chunk-KGLACICA.js +43 -0
- package/dist/config/index.d.cts +2 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +4 -19
- package/dist/{define-B4aTedg-.d.cts → define-DxwgTgV6.d.cts} +15 -20
- package/dist/{define-B4aTedg-.d.ts → define-DxwgTgV6.d.ts} +15 -20
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/loader-mdx.cjs +49 -38
- package/dist/loader-mdx.js +11 -34
- package/dist/next/index.cjs +143 -84
- package/dist/next/index.js +105 -80
- package/dist/runtime/async.cjs +1 -1
- package/dist/runtime/async.d.cts +3 -3
- package/dist/runtime/async.d.ts +3 -3
- package/dist/runtime/async.js +1 -1
- package/dist/{types-qPYo6njm.d.ts → types-8ecOBKxa.d.cts} +3 -3
- package/dist/{types-C214DTNR.d.cts → types-BQ1vyPw8.d.ts} +3 -3
- package/package.json +4 -6
package/dist/next/index.cjs
CHANGED
|
@@ -259,7 +259,7 @@ function buildConfig(config) {
|
|
|
259
259
|
function findConfigFile() {
|
|
260
260
|
return path.resolve("source.config.ts");
|
|
261
261
|
}
|
|
262
|
-
var cache =
|
|
262
|
+
var cache = null;
|
|
263
263
|
async function compileConfig(configPath) {
|
|
264
264
|
const { build } = await import("esbuild");
|
|
265
265
|
const transformed = await build({
|
|
@@ -281,9 +281,8 @@ async function compileConfig(configPath) {
|
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
async function loadConfig(configPath, hash, build = false) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return await cached.config;
|
|
284
|
+
if (cache && cache.hash === hash) {
|
|
285
|
+
return await cache.config;
|
|
287
286
|
}
|
|
288
287
|
if (build) await compileConfig(configPath);
|
|
289
288
|
const url = (0, import_node_url.pathToFileURL)(path.resolve(".source/source.config.mjs"));
|
|
@@ -295,7 +294,7 @@ async function loadConfig(configPath, hash, build = false) {
|
|
|
295
294
|
if (err !== null) throw new Error(err);
|
|
296
295
|
return config2;
|
|
297
296
|
});
|
|
298
|
-
cache
|
|
297
|
+
cache = { config, hash };
|
|
299
298
|
return await config;
|
|
300
299
|
}
|
|
301
300
|
async function getConfigHash(configPath) {
|
|
@@ -309,10 +308,11 @@ async function getConfigHash(configPath) {
|
|
|
309
308
|
|
|
310
309
|
// src/map/index.ts
|
|
311
310
|
var path3 = __toESM(require("path"), 1);
|
|
312
|
-
var
|
|
311
|
+
var fs4 = __toESM(require("fs/promises"), 1);
|
|
313
312
|
|
|
314
313
|
// src/map/generate.ts
|
|
315
314
|
var path2 = __toESM(require("path"), 1);
|
|
315
|
+
var fs3 = __toESM(require("fs/promises"), 1);
|
|
316
316
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
317
317
|
|
|
318
318
|
// src/utils/get-type-from-path.ts
|
|
@@ -325,8 +325,103 @@ function getTypeFromPath(path6) {
|
|
|
325
325
|
if (metaTypes.includes(ext)) return "meta";
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
+
// src/utils/schema.ts
|
|
329
|
+
var import_zod = require("zod");
|
|
330
|
+
var metaSchema = import_zod.z.object({
|
|
331
|
+
title: import_zod.z.string().optional(),
|
|
332
|
+
pages: import_zod.z.array(import_zod.z.string()).optional(),
|
|
333
|
+
description: import_zod.z.string().optional(),
|
|
334
|
+
root: import_zod.z.boolean().optional(),
|
|
335
|
+
defaultOpen: import_zod.z.boolean().optional(),
|
|
336
|
+
icon: import_zod.z.string().optional()
|
|
337
|
+
});
|
|
338
|
+
var frontmatterSchema = import_zod.z.object({
|
|
339
|
+
title: import_zod.z.string(),
|
|
340
|
+
description: import_zod.z.string().optional(),
|
|
341
|
+
icon: import_zod.z.string().optional(),
|
|
342
|
+
full: import_zod.z.boolean().optional(),
|
|
343
|
+
// Fumadocs OpenAPI generated
|
|
344
|
+
_openapi: import_zod.z.object({}).passthrough().optional()
|
|
345
|
+
});
|
|
346
|
+
async function validate(schema, data, context, errorMessage) {
|
|
347
|
+
if (typeof schema === "function" && !("~standard" in schema)) {
|
|
348
|
+
schema = schema(context);
|
|
349
|
+
}
|
|
350
|
+
if ("~standard" in schema) {
|
|
351
|
+
const result = await schema["~standard"].validate(
|
|
352
|
+
data
|
|
353
|
+
);
|
|
354
|
+
if (result.issues) {
|
|
355
|
+
throw new Error(formatError(errorMessage, result.issues));
|
|
356
|
+
}
|
|
357
|
+
return result.value;
|
|
358
|
+
}
|
|
359
|
+
return data;
|
|
360
|
+
}
|
|
361
|
+
function formatError(message, issues) {
|
|
362
|
+
return `${message}:
|
|
363
|
+
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/map/file-cache.ts
|
|
367
|
+
var map = /* @__PURE__ */ new Map();
|
|
368
|
+
var fileCache = {
|
|
369
|
+
read(namespace, path6) {
|
|
370
|
+
return map.get(`${namespace}.${path6}}`);
|
|
371
|
+
},
|
|
372
|
+
write(namespace, path6, data) {
|
|
373
|
+
map.set(`${namespace}.${path6}}`, data);
|
|
374
|
+
},
|
|
375
|
+
removeCache(path6) {
|
|
376
|
+
for (const key of map.keys()) {
|
|
377
|
+
const keyPath = key.slice(key.indexOf(".") + 1);
|
|
378
|
+
if (keyPath === path6) map.delete(key);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// src/utils/read-frontmatter.ts
|
|
384
|
+
var fs2 = __toESM(require("fs"), 1);
|
|
385
|
+
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
386
|
+
async function readFrontmatter(file) {
|
|
387
|
+
const readStream = fs2.createReadStream(file, {
|
|
388
|
+
highWaterMark: 250
|
|
389
|
+
});
|
|
390
|
+
return new Promise((res, rej) => {
|
|
391
|
+
let idx = 0;
|
|
392
|
+
let str = "";
|
|
393
|
+
readStream.on("data", (_chunk) => {
|
|
394
|
+
const chunk = _chunk.toString();
|
|
395
|
+
if (idx === 0 && !chunk.startsWith("---")) {
|
|
396
|
+
res({});
|
|
397
|
+
readStream.close();
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
str += chunk;
|
|
401
|
+
idx++;
|
|
402
|
+
if (str.includes("\n---")) {
|
|
403
|
+
res(
|
|
404
|
+
(0, import_gray_matter.default)({
|
|
405
|
+
content: str
|
|
406
|
+
}).data
|
|
407
|
+
);
|
|
408
|
+
readStream.close();
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
readStream.on("end", () => res({}));
|
|
412
|
+
readStream.on("error", (e) => rej(e));
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
328
416
|
// src/map/generate.ts
|
|
329
|
-
async function
|
|
417
|
+
async function readFrontmatterWithCache(file) {
|
|
418
|
+
const cached = fileCache.read("read-frontmatter", file);
|
|
419
|
+
if (cached) return cached;
|
|
420
|
+
const res = await readFrontmatter(file);
|
|
421
|
+
fileCache.write("read-frontmatter", file, res);
|
|
422
|
+
return res;
|
|
423
|
+
}
|
|
424
|
+
async function generateJS(configPath, config, outputPath, configHash) {
|
|
330
425
|
const outDir2 = path2.dirname(outputPath);
|
|
331
426
|
let asyncInit = false;
|
|
332
427
|
const lines = [
|
|
@@ -346,7 +441,27 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
346
441
|
async function getEntries(collectionName, collection, files) {
|
|
347
442
|
const items = files.map(async (file, i) => {
|
|
348
443
|
config._runtime.files.set(file.absolutePath, collectionName);
|
|
349
|
-
|
|
444
|
+
if (collection.type === "meta") {
|
|
445
|
+
const cached = fileCache.read("generate-js", file.absolutePath);
|
|
446
|
+
if (cached) return cached;
|
|
447
|
+
const source = (await fs3.readFile(file.absolutePath)).toString();
|
|
448
|
+
let data = JSON.parse(source);
|
|
449
|
+
if (collection?.schema) {
|
|
450
|
+
data = await validate(
|
|
451
|
+
collection.schema,
|
|
452
|
+
data,
|
|
453
|
+
{
|
|
454
|
+
source,
|
|
455
|
+
path: file.absolutePath
|
|
456
|
+
},
|
|
457
|
+
`invalid data in ${file.absolutePath}:`
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
const entry = `{ info: ${JSON.stringify(file)}, data: ${JSON.stringify(data)} }`;
|
|
461
|
+
fileCache.write("generate-js", file.absolutePath, entry);
|
|
462
|
+
return entry;
|
|
463
|
+
}
|
|
464
|
+
const importId = `${collectionName}_${i}`;
|
|
350
465
|
lines.unshift(
|
|
351
466
|
getImportCode({
|
|
352
467
|
type: "namespace",
|
|
@@ -372,10 +487,9 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
372
487
|
asyncInit = true;
|
|
373
488
|
}
|
|
374
489
|
const entries2 = files.map(async (file) => {
|
|
375
|
-
const frontmatter = await getFrontmatter(file.absolutePath);
|
|
376
490
|
return JSON.stringify({
|
|
377
491
|
info: file,
|
|
378
|
-
data:
|
|
492
|
+
data: await readFrontmatterWithCache(file.absolutePath)
|
|
379
493
|
});
|
|
380
494
|
});
|
|
381
495
|
return Promise.all(entries2);
|
|
@@ -384,19 +498,16 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
384
498
|
if (collection.type === "docs") {
|
|
385
499
|
const docs = await getCollectionFiles(collection.docs);
|
|
386
500
|
const metas = await getCollectionFiles(collection.meta);
|
|
501
|
+
const metaEntries = (await getEntries(k, collection.meta, metas)).join(
|
|
502
|
+
", "
|
|
503
|
+
);
|
|
387
504
|
if (collection.docs.async) {
|
|
388
505
|
const docsEntries2 = (await getAsyncEntries(docs)).join(", ");
|
|
389
|
-
const
|
|
390
|
-
", "
|
|
391
|
-
);
|
|
392
|
-
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries2}], "${k}", _sourceConfig)`;
|
|
506
|
+
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
|
|
393
507
|
}
|
|
394
508
|
const docsEntries = (await getEntries(k, collection.docs, docs)).join(
|
|
395
509
|
", "
|
|
396
510
|
);
|
|
397
|
-
const metaEntries = (await getEntries(k, collection.meta, metas)).join(
|
|
398
|
-
", "
|
|
399
|
-
);
|
|
400
511
|
return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
|
|
401
512
|
}
|
|
402
513
|
const files = await getCollectionFiles(collection);
|
|
@@ -457,72 +568,23 @@ function toImportPath(file, dir) {
|
|
|
457
568
|
return importPath.replaceAll(path2.sep, "/");
|
|
458
569
|
}
|
|
459
570
|
|
|
460
|
-
// src/utils/read-frontmatter.ts
|
|
461
|
-
var fs2 = __toESM(require("fs"), 1);
|
|
462
|
-
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
463
|
-
async function readFrontmatter(file) {
|
|
464
|
-
const readStream = fs2.createReadStream(file, {
|
|
465
|
-
highWaterMark: 250
|
|
466
|
-
});
|
|
467
|
-
return new Promise((res, rej) => {
|
|
468
|
-
let idx = 0;
|
|
469
|
-
let str = "";
|
|
470
|
-
readStream.on("data", (_chunk) => {
|
|
471
|
-
const chunk = _chunk.toString();
|
|
472
|
-
if (idx === 0 && !chunk.startsWith("---")) {
|
|
473
|
-
res({});
|
|
474
|
-
readStream.close();
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
str += chunk;
|
|
478
|
-
idx++;
|
|
479
|
-
if (str.includes("\n---")) {
|
|
480
|
-
res(
|
|
481
|
-
(0, import_gray_matter.default)({
|
|
482
|
-
content: str
|
|
483
|
-
}).data
|
|
484
|
-
);
|
|
485
|
-
readStream.close();
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
readStream.on("end", () => res({}));
|
|
489
|
-
readStream.on("error", (e) => rej(e));
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
|
|
493
571
|
// src/map/index.ts
|
|
494
572
|
async function start(dev, configPath, outDir2) {
|
|
495
|
-
void
|
|
496
|
-
void
|
|
497
|
-
await
|
|
573
|
+
void fs4.rm(path3.resolve(outDir2, `index.js`), { force: true });
|
|
574
|
+
void fs4.rm(path3.resolve(outDir2, `index.d.ts`), { force: true });
|
|
575
|
+
await fs4.mkdir(outDir2, { recursive: true });
|
|
498
576
|
let configHash = await getConfigHash(configPath);
|
|
499
577
|
let config = await loadConfig(configPath, configHash, true);
|
|
500
578
|
const outPath = path3.resolve(outDir2, `index.ts`);
|
|
501
|
-
const frontmatterCache = /* @__PURE__ */ new Map();
|
|
502
|
-
let hookUpdate = false;
|
|
503
|
-
async function readFrontmatterWithCache(file) {
|
|
504
|
-
hookUpdate = true;
|
|
505
|
-
const cached = frontmatterCache.get(file);
|
|
506
|
-
if (cached) return cached;
|
|
507
|
-
const res = await readFrontmatter(file);
|
|
508
|
-
frontmatterCache.set(file, res);
|
|
509
|
-
return res;
|
|
510
|
-
}
|
|
511
579
|
async function updateMapFile() {
|
|
512
|
-
|
|
580
|
+
console.time(`[MDX] update map file`);
|
|
581
|
+
await fs4.writeFile(
|
|
513
582
|
outPath,
|
|
514
|
-
await generateJS(
|
|
515
|
-
configPath,
|
|
516
|
-
config,
|
|
517
|
-
outPath,
|
|
518
|
-
configHash,
|
|
519
|
-
readFrontmatterWithCache
|
|
520
|
-
)
|
|
583
|
+
await generateJS(configPath, config, outPath, configHash)
|
|
521
584
|
);
|
|
585
|
+
console.timeEnd(`[MDX] update map file`);
|
|
522
586
|
}
|
|
523
|
-
console.time(`[MDX] initialize map file`);
|
|
524
587
|
await updateMapFile();
|
|
525
|
-
console.timeEnd(`[MDX] initialize map file`);
|
|
526
588
|
if (dev) {
|
|
527
589
|
const { watcher: watcher2 } = await Promise.resolve().then(() => (init_watcher(), watcher_exports));
|
|
528
590
|
const instance = watcher2(configPath, config);
|
|
@@ -531,17 +593,15 @@ async function start(dev, configPath, outDir2) {
|
|
|
531
593
|
});
|
|
532
594
|
instance.on("all", (event, file) => {
|
|
533
595
|
if (typeof file !== "string") return;
|
|
596
|
+
const absolutePath = path3.resolve(file);
|
|
534
597
|
const onUpdate = async () => {
|
|
535
|
-
const isConfigFile =
|
|
598
|
+
const isConfigFile = absolutePath === configPath;
|
|
536
599
|
if (isConfigFile) {
|
|
537
600
|
configHash = await getConfigHash(configPath);
|
|
538
601
|
config = await loadConfig(configPath, configHash, true);
|
|
539
602
|
}
|
|
540
|
-
if (
|
|
541
|
-
|
|
542
|
-
await updateMapFile();
|
|
543
|
-
console.log("[MDX] Updated map file");
|
|
544
|
-
}
|
|
603
|
+
if (event === "change") fileCache.removeCache(absolutePath);
|
|
604
|
+
await updateMapFile();
|
|
545
605
|
};
|
|
546
606
|
void onUpdate();
|
|
547
607
|
});
|
|
@@ -615,20 +675,19 @@ function createMDX({
|
|
|
615
675
|
|
|
616
676
|
// src/postinstall.ts
|
|
617
677
|
var path5 = __toESM(require("path"), 1);
|
|
618
|
-
var
|
|
678
|
+
var fs5 = __toESM(require("fs"), 1);
|
|
619
679
|
async function postInstall(configPath = findConfigFile()) {
|
|
620
680
|
const jsOut = path5.resolve(".source/index.ts");
|
|
621
681
|
const hash = await getConfigHash(configPath);
|
|
622
682
|
const config = await loadConfig(configPath, hash, true);
|
|
623
|
-
|
|
624
|
-
|
|
683
|
+
fs5.mkdirSync(path5.dirname(jsOut), { recursive: true });
|
|
684
|
+
fs5.writeFileSync(
|
|
625
685
|
jsOut,
|
|
626
686
|
await generateJS(
|
|
627
687
|
configPath,
|
|
628
688
|
config,
|
|
629
689
|
path5.resolve(".source/index.ts"),
|
|
630
|
-
hash
|
|
631
|
-
readFrontmatter
|
|
690
|
+
hash
|
|
632
691
|
)
|
|
633
692
|
);
|
|
634
693
|
console.log("[MDX] types generated");
|
package/dist/next/index.js
CHANGED
|
@@ -2,7 +2,10 @@ import {
|
|
|
2
2
|
findConfigFile,
|
|
3
3
|
getConfigHash,
|
|
4
4
|
loadConfig
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-2FUWXPXA.js";
|
|
6
|
+
import {
|
|
7
|
+
validate
|
|
8
|
+
} from "../chunk-KGLACICA.js";
|
|
6
9
|
import "../chunk-6ZVE73IT.js";
|
|
7
10
|
|
|
8
11
|
// src/next/create.ts
|
|
@@ -10,10 +13,11 @@ import path3 from "node:path";
|
|
|
10
13
|
|
|
11
14
|
// src/map/index.ts
|
|
12
15
|
import * as path2 from "node:path";
|
|
13
|
-
import * as
|
|
16
|
+
import * as fs3 from "node:fs/promises";
|
|
14
17
|
|
|
15
18
|
// src/map/generate.ts
|
|
16
19
|
import * as path from "node:path";
|
|
20
|
+
import * as fs2 from "node:fs/promises";
|
|
17
21
|
import fg from "fast-glob";
|
|
18
22
|
|
|
19
23
|
// src/utils/get-type-from-path.ts
|
|
@@ -26,8 +30,65 @@ function getTypeFromPath(path5) {
|
|
|
26
30
|
if (metaTypes.includes(ext)) return "meta";
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
// src/map/file-cache.ts
|
|
34
|
+
var map = /* @__PURE__ */ new Map();
|
|
35
|
+
var fileCache = {
|
|
36
|
+
read(namespace, path5) {
|
|
37
|
+
return map.get(`${namespace}.${path5}}`);
|
|
38
|
+
},
|
|
39
|
+
write(namespace, path5, data) {
|
|
40
|
+
map.set(`${namespace}.${path5}}`, data);
|
|
41
|
+
},
|
|
42
|
+
removeCache(path5) {
|
|
43
|
+
for (const key of map.keys()) {
|
|
44
|
+
const keyPath = key.slice(key.indexOf(".") + 1);
|
|
45
|
+
if (keyPath === path5) map.delete(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/utils/read-frontmatter.ts
|
|
51
|
+
import * as fs from "node:fs";
|
|
52
|
+
import grayMatter from "gray-matter";
|
|
53
|
+
async function readFrontmatter(file) {
|
|
54
|
+
const readStream = fs.createReadStream(file, {
|
|
55
|
+
highWaterMark: 250
|
|
56
|
+
});
|
|
57
|
+
return new Promise((res, rej) => {
|
|
58
|
+
let idx = 0;
|
|
59
|
+
let str = "";
|
|
60
|
+
readStream.on("data", (_chunk) => {
|
|
61
|
+
const chunk = _chunk.toString();
|
|
62
|
+
if (idx === 0 && !chunk.startsWith("---")) {
|
|
63
|
+
res({});
|
|
64
|
+
readStream.close();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
str += chunk;
|
|
68
|
+
idx++;
|
|
69
|
+
if (str.includes("\n---")) {
|
|
70
|
+
res(
|
|
71
|
+
grayMatter({
|
|
72
|
+
content: str
|
|
73
|
+
}).data
|
|
74
|
+
);
|
|
75
|
+
readStream.close();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
readStream.on("end", () => res({}));
|
|
79
|
+
readStream.on("error", (e) => rej(e));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
29
83
|
// src/map/generate.ts
|
|
30
|
-
async function
|
|
84
|
+
async function readFrontmatterWithCache(file) {
|
|
85
|
+
const cached = fileCache.read("read-frontmatter", file);
|
|
86
|
+
if (cached) return cached;
|
|
87
|
+
const res = await readFrontmatter(file);
|
|
88
|
+
fileCache.write("read-frontmatter", file, res);
|
|
89
|
+
return res;
|
|
90
|
+
}
|
|
91
|
+
async function generateJS(configPath, config, outputPath, configHash) {
|
|
31
92
|
const outDir2 = path.dirname(outputPath);
|
|
32
93
|
let asyncInit = false;
|
|
33
94
|
const lines = [
|
|
@@ -47,7 +108,27 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
47
108
|
async function getEntries(collectionName, collection, files) {
|
|
48
109
|
const items = files.map(async (file, i) => {
|
|
49
110
|
config._runtime.files.set(file.absolutePath, collectionName);
|
|
50
|
-
|
|
111
|
+
if (collection.type === "meta") {
|
|
112
|
+
const cached = fileCache.read("generate-js", file.absolutePath);
|
|
113
|
+
if (cached) return cached;
|
|
114
|
+
const source = (await fs2.readFile(file.absolutePath)).toString();
|
|
115
|
+
let data = JSON.parse(source);
|
|
116
|
+
if (collection?.schema) {
|
|
117
|
+
data = await validate(
|
|
118
|
+
collection.schema,
|
|
119
|
+
data,
|
|
120
|
+
{
|
|
121
|
+
source,
|
|
122
|
+
path: file.absolutePath
|
|
123
|
+
},
|
|
124
|
+
`invalid data in ${file.absolutePath}:`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
const entry = `{ info: ${JSON.stringify(file)}, data: ${JSON.stringify(data)} }`;
|
|
128
|
+
fileCache.write("generate-js", file.absolutePath, entry);
|
|
129
|
+
return entry;
|
|
130
|
+
}
|
|
131
|
+
const importId = `${collectionName}_${i}`;
|
|
51
132
|
lines.unshift(
|
|
52
133
|
getImportCode({
|
|
53
134
|
type: "namespace",
|
|
@@ -73,10 +154,9 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
73
154
|
asyncInit = true;
|
|
74
155
|
}
|
|
75
156
|
const entries2 = files.map(async (file) => {
|
|
76
|
-
const frontmatter = await getFrontmatter(file.absolutePath);
|
|
77
157
|
return JSON.stringify({
|
|
78
158
|
info: file,
|
|
79
|
-
data:
|
|
159
|
+
data: await readFrontmatterWithCache(file.absolutePath)
|
|
80
160
|
});
|
|
81
161
|
});
|
|
82
162
|
return Promise.all(entries2);
|
|
@@ -85,19 +165,16 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
85
165
|
if (collection.type === "docs") {
|
|
86
166
|
const docs = await getCollectionFiles(collection.docs);
|
|
87
167
|
const metas = await getCollectionFiles(collection.meta);
|
|
168
|
+
const metaEntries = (await getEntries(k, collection.meta, metas)).join(
|
|
169
|
+
", "
|
|
170
|
+
);
|
|
88
171
|
if (collection.docs.async) {
|
|
89
172
|
const docsEntries2 = (await getAsyncEntries(docs)).join(", ");
|
|
90
|
-
const
|
|
91
|
-
", "
|
|
92
|
-
);
|
|
93
|
-
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries2}], "${k}", _sourceConfig)`;
|
|
173
|
+
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
|
|
94
174
|
}
|
|
95
175
|
const docsEntries = (await getEntries(k, collection.docs, docs)).join(
|
|
96
176
|
", "
|
|
97
177
|
);
|
|
98
|
-
const metaEntries = (await getEntries(k, collection.meta, metas)).join(
|
|
99
|
-
", "
|
|
100
|
-
);
|
|
101
178
|
return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
|
|
102
179
|
}
|
|
103
180
|
const files = await getCollectionFiles(collection);
|
|
@@ -158,72 +235,23 @@ function toImportPath(file, dir) {
|
|
|
158
235
|
return importPath.replaceAll(path.sep, "/");
|
|
159
236
|
}
|
|
160
237
|
|
|
161
|
-
// src/utils/read-frontmatter.ts
|
|
162
|
-
import * as fs from "node:fs";
|
|
163
|
-
import grayMatter from "gray-matter";
|
|
164
|
-
async function readFrontmatter(file) {
|
|
165
|
-
const readStream = fs.createReadStream(file, {
|
|
166
|
-
highWaterMark: 250
|
|
167
|
-
});
|
|
168
|
-
return new Promise((res, rej) => {
|
|
169
|
-
let idx = 0;
|
|
170
|
-
let str = "";
|
|
171
|
-
readStream.on("data", (_chunk) => {
|
|
172
|
-
const chunk = _chunk.toString();
|
|
173
|
-
if (idx === 0 && !chunk.startsWith("---")) {
|
|
174
|
-
res({});
|
|
175
|
-
readStream.close();
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
str += chunk;
|
|
179
|
-
idx++;
|
|
180
|
-
if (str.includes("\n---")) {
|
|
181
|
-
res(
|
|
182
|
-
grayMatter({
|
|
183
|
-
content: str
|
|
184
|
-
}).data
|
|
185
|
-
);
|
|
186
|
-
readStream.close();
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
readStream.on("end", () => res({}));
|
|
190
|
-
readStream.on("error", (e) => rej(e));
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
238
|
// src/map/index.ts
|
|
195
239
|
async function start(dev, configPath, outDir2) {
|
|
196
|
-
void
|
|
197
|
-
void
|
|
198
|
-
await
|
|
240
|
+
void fs3.rm(path2.resolve(outDir2, `index.js`), { force: true });
|
|
241
|
+
void fs3.rm(path2.resolve(outDir2, `index.d.ts`), { force: true });
|
|
242
|
+
await fs3.mkdir(outDir2, { recursive: true });
|
|
199
243
|
let configHash = await getConfigHash(configPath);
|
|
200
244
|
let config = await loadConfig(configPath, configHash, true);
|
|
201
245
|
const outPath = path2.resolve(outDir2, `index.ts`);
|
|
202
|
-
const frontmatterCache = /* @__PURE__ */ new Map();
|
|
203
|
-
let hookUpdate = false;
|
|
204
|
-
async function readFrontmatterWithCache(file) {
|
|
205
|
-
hookUpdate = true;
|
|
206
|
-
const cached = frontmatterCache.get(file);
|
|
207
|
-
if (cached) return cached;
|
|
208
|
-
const res = await readFrontmatter(file);
|
|
209
|
-
frontmatterCache.set(file, res);
|
|
210
|
-
return res;
|
|
211
|
-
}
|
|
212
246
|
async function updateMapFile() {
|
|
213
|
-
|
|
247
|
+
console.time(`[MDX] update map file`);
|
|
248
|
+
await fs3.writeFile(
|
|
214
249
|
outPath,
|
|
215
|
-
await generateJS(
|
|
216
|
-
configPath,
|
|
217
|
-
config,
|
|
218
|
-
outPath,
|
|
219
|
-
configHash,
|
|
220
|
-
readFrontmatterWithCache
|
|
221
|
-
)
|
|
250
|
+
await generateJS(configPath, config, outPath, configHash)
|
|
222
251
|
);
|
|
252
|
+
console.timeEnd(`[MDX] update map file`);
|
|
223
253
|
}
|
|
224
|
-
console.time(`[MDX] initialize map file`);
|
|
225
254
|
await updateMapFile();
|
|
226
|
-
console.timeEnd(`[MDX] initialize map file`);
|
|
227
255
|
if (dev) {
|
|
228
256
|
const { watcher } = await import("../watcher-IAZDSTU7.js");
|
|
229
257
|
const instance = watcher(configPath, config);
|
|
@@ -232,17 +260,15 @@ async function start(dev, configPath, outDir2) {
|
|
|
232
260
|
});
|
|
233
261
|
instance.on("all", (event, file) => {
|
|
234
262
|
if (typeof file !== "string") return;
|
|
263
|
+
const absolutePath = path2.resolve(file);
|
|
235
264
|
const onUpdate = async () => {
|
|
236
|
-
const isConfigFile =
|
|
265
|
+
const isConfigFile = absolutePath === configPath;
|
|
237
266
|
if (isConfigFile) {
|
|
238
267
|
configHash = await getConfigHash(configPath);
|
|
239
268
|
config = await loadConfig(configPath, configHash, true);
|
|
240
269
|
}
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
await updateMapFile();
|
|
244
|
-
console.log("[MDX] Updated map file");
|
|
245
|
-
}
|
|
270
|
+
if (event === "change") fileCache.removeCache(absolutePath);
|
|
271
|
+
await updateMapFile();
|
|
246
272
|
};
|
|
247
273
|
void onUpdate();
|
|
248
274
|
});
|
|
@@ -316,20 +342,19 @@ function createMDX({
|
|
|
316
342
|
|
|
317
343
|
// src/postinstall.ts
|
|
318
344
|
import * as path4 from "node:path";
|
|
319
|
-
import * as
|
|
345
|
+
import * as fs4 from "node:fs";
|
|
320
346
|
async function postInstall(configPath = findConfigFile()) {
|
|
321
347
|
const jsOut = path4.resolve(".source/index.ts");
|
|
322
348
|
const hash = await getConfigHash(configPath);
|
|
323
349
|
const config = await loadConfig(configPath, hash, true);
|
|
324
|
-
|
|
325
|
-
|
|
350
|
+
fs4.mkdirSync(path4.dirname(jsOut), { recursive: true });
|
|
351
|
+
fs4.writeFileSync(
|
|
326
352
|
jsOut,
|
|
327
353
|
await generateJS(
|
|
328
354
|
configPath,
|
|
329
355
|
config,
|
|
330
356
|
path4.resolve(".source/index.ts"),
|
|
331
|
-
hash
|
|
332
|
-
readFrontmatter
|
|
357
|
+
hash
|
|
333
358
|
)
|
|
334
359
|
);
|
|
335
360
|
console.log("[MDX] types generated");
|
package/dist/runtime/async.cjs
CHANGED
package/dist/runtime/async.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { L as LoadedConfig, b as RuntimeAsync } from '../types-
|
|
2
|
-
import '../define-
|
|
1
|
+
import { L as LoadedConfig, b as RuntimeAsync } from '../types-8ecOBKxa.cjs';
|
|
2
|
+
import '../define-DxwgTgV6.cjs';
|
|
3
3
|
import '@mdx-js/mdx';
|
|
4
4
|
import 'mdx/types';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
|
6
6
|
import 'fumadocs-core/server';
|
|
7
7
|
import 'unified';
|
|
8
8
|
import 'react';
|
|
9
|
-
import '@standard-schema/spec';
|
|
10
9
|
import 'zod';
|
|
10
|
+
import '@standard-schema/spec';
|
|
11
11
|
import 'fumadocs-core/source';
|
|
12
12
|
|
|
13
13
|
declare function buildConfig(config: Record<string, unknown>): [err: string, value: null] | [err: null, value: LoadedConfig];
|
package/dist/runtime/async.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { L as LoadedConfig, b as RuntimeAsync } from '../types-
|
|
2
|
-
import '../define-
|
|
1
|
+
import { L as LoadedConfig, b as RuntimeAsync } from '../types-BQ1vyPw8.js';
|
|
2
|
+
import '../define-DxwgTgV6.js';
|
|
3
3
|
import '@mdx-js/mdx';
|
|
4
4
|
import 'mdx/types';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
|
6
6
|
import 'fumadocs-core/server';
|
|
7
7
|
import 'unified';
|
|
8
8
|
import 'react';
|
|
9
|
-
import '@standard-schema/spec';
|
|
10
9
|
import 'zod';
|
|
10
|
+
import '@standard-schema/spec';
|
|
11
11
|
import 'fumadocs-core/source';
|
|
12
12
|
|
|
13
13
|
declare function buildConfig(config: Record<string, unknown>): [err: string, value: null] | [err: null, value: LoadedConfig];
|