fumadocs-mdx 12.0.0 → 12.0.2
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 +103 -85
- package/dist/bin.js +1 -1
- package/dist/{browser-D5lvL8vv.d.ts → browser-BupUnhpC.d.ts} +1 -1
- package/dist/{browser-DjWADqp8.d.cts → browser-R0x9IPaQ.d.cts} +1 -1
- package/dist/bun/index.cjs +156 -130
- package/dist/bun/index.js +10 -10
- package/dist/chunk-ADR6R7HM.js +29 -0
- package/dist/{chunk-3M4SHY6K.js → chunk-FSZMKRVH.js} +1 -1
- package/dist/{chunk-POXTQZ4D.js → chunk-LGYVNESJ.js} +2 -6
- package/dist/chunk-LMG6UWCL.js +167 -0
- package/dist/{chunk-SWNOXPYJ.js → chunk-QAUWMR5D.js} +6 -6
- package/dist/{chunk-KGUBBRL6.js → chunk-RMDXSZYE.js} +11 -39
- package/dist/{chunk-YC25YEBF.js → chunk-U4MQ44TS.js} +1 -1
- package/dist/chunk-XMFLD5J6.js +30 -0
- package/dist/{chunk-TLD6JMT6.js → chunk-ZX7TM4AR.js} +4 -2
- package/dist/config/index.cjs +84 -56
- package/dist/config/index.d.cts +2 -6
- package/dist/config/index.d.ts +2 -6
- package/dist/config/index.js +2 -2
- package/dist/{define--6HQ1ehX.d.cts → define-DJbJduHy.d.cts} +15 -15
- package/dist/{define--6HQ1ehX.d.ts → define-DJbJduHy.d.ts} +15 -15
- package/dist/index.cjs +127 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +11 -0
- package/dist/load-UUXLUBHL.js +9 -0
- package/dist/loader-mdx.cjs +217 -174
- package/dist/loader-mdx.js +7 -7
- package/dist/next/index.cjs +129 -109
- package/dist/next/index.js +40 -54
- package/dist/node/loader.cjs +152 -109
- package/dist/node/loader.js +6 -7
- package/dist/postinstall-SCSXM4IM.js +10 -0
- package/dist/{preset-WFEORCAB.js → preset-ZMP6U62C.js} +1 -1
- package/dist/runtime/next/async.cjs +117 -65
- package/dist/runtime/next/async.d.cts +3 -3
- package/dist/runtime/next/async.d.ts +3 -3
- package/dist/runtime/next/async.js +15 -8
- package/dist/runtime/next/index.d.cts +8 -8
- package/dist/runtime/next/index.d.ts +8 -8
- package/dist/runtime/vite/browser.d.cts +2 -2
- package/dist/runtime/vite/browser.d.ts +2 -2
- package/dist/runtime/vite/server.d.cts +5 -5
- package/dist/runtime/vite/server.d.ts +5 -5
- package/dist/{shared-CqgMnt9h.d.cts → shared-Cnm1afPW.d.cts} +3 -2
- package/dist/{shared-0QIuV0XZ.d.ts → shared-DpXxElc1.d.ts} +3 -2
- package/dist/{types-DLIAvrgC.d.ts → types-CbLt05Gc.d.cts} +7 -8
- package/dist/{types-Dl8HLbm5.d.cts → types-Ci6BA1tA.d.ts} +7 -8
- package/dist/vite/index.cjs +177 -145
- package/dist/vite/index.d.cts +1 -0
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.js +15 -20
- package/dist/{watcher-4NDMOH4R.js → watcher-HGOH3APP.js} +1 -1
- package/package.json +23 -15
- package/dist/chunk-KTDVTBMH.js +0 -139
- package/dist/postinstall-U7VROOY7.js +0 -9
package/dist/next/index.cjs
CHANGED
|
@@ -30,7 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
// src/mdx/preset.ts
|
|
33
|
+
// src/loaders/mdx/preset.ts
|
|
34
34
|
var preset_exports = {};
|
|
35
35
|
__export(preset_exports, {
|
|
36
36
|
getDefaultMDXOptions: () => getDefaultMDXOptions
|
|
@@ -111,56 +111,12 @@ function getDefaultMDXOptions({
|
|
|
111
111
|
}
|
|
112
112
|
var plugins;
|
|
113
113
|
var init_preset = __esm({
|
|
114
|
-
"src/mdx/preset.ts"() {
|
|
114
|
+
"src/loaders/mdx/preset.ts"() {
|
|
115
115
|
"use strict";
|
|
116
116
|
plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
-
// src/map/watcher.ts
|
|
121
|
-
var watcher_exports = {};
|
|
122
|
-
__export(watcher_exports, {
|
|
123
|
-
watcher: () => watcher
|
|
124
|
-
});
|
|
125
|
-
function watcher(configPath, config, ignored) {
|
|
126
|
-
const watcher2 = new import_chokidar.FSWatcher({
|
|
127
|
-
ignoreInitial: true,
|
|
128
|
-
persistent: true,
|
|
129
|
-
ignored
|
|
130
|
-
});
|
|
131
|
-
watcher2.add(configPath);
|
|
132
|
-
for (const collection of config.collections.values()) {
|
|
133
|
-
if (collection.type === "docs") {
|
|
134
|
-
watcher2.add(collection.docs.dir);
|
|
135
|
-
watcher2.add(collection.meta.dir);
|
|
136
|
-
} else {
|
|
137
|
-
watcher2.add(collection.dir);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return watcher2;
|
|
141
|
-
}
|
|
142
|
-
var import_chokidar;
|
|
143
|
-
var init_watcher = __esm({
|
|
144
|
-
"src/map/watcher.ts"() {
|
|
145
|
-
"use strict";
|
|
146
|
-
import_chokidar = require("chokidar");
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// src/next/index.ts
|
|
151
|
-
var next_exports = {};
|
|
152
|
-
__export(next_exports, {
|
|
153
|
-
createMDX: () => createMDX,
|
|
154
|
-
postInstall: () => postInstall,
|
|
155
|
-
start: () => start
|
|
156
|
-
});
|
|
157
|
-
module.exports = __toCommonJS(next_exports);
|
|
158
|
-
|
|
159
|
-
// src/utils/config.ts
|
|
160
|
-
var fs = __toESM(require("fs/promises"), 1);
|
|
161
|
-
var path = __toESM(require("path"), 1);
|
|
162
|
-
var import_node_url = require("url");
|
|
163
|
-
|
|
164
120
|
// src/config/build.ts
|
|
165
121
|
function buildConfig(config) {
|
|
166
122
|
const collections = /* @__PURE__ */ new Map();
|
|
@@ -210,12 +166,13 @@ function buildConfig(config) {
|
|
|
210
166
|
}
|
|
211
167
|
};
|
|
212
168
|
}
|
|
169
|
+
var init_build = __esm({
|
|
170
|
+
"src/config/build.ts"() {
|
|
171
|
+
"use strict";
|
|
172
|
+
}
|
|
173
|
+
});
|
|
213
174
|
|
|
214
|
-
// src/
|
|
215
|
-
function findConfigFile() {
|
|
216
|
-
return path.resolve("source.config.ts");
|
|
217
|
-
}
|
|
218
|
-
var cache = null;
|
|
175
|
+
// src/loaders/config/load.ts
|
|
219
176
|
async function compileConfig(configPath, outDir) {
|
|
220
177
|
const { build } = await import("esbuild");
|
|
221
178
|
const transformed = await build({
|
|
@@ -258,14 +215,63 @@ async function getConfigHash(configPath) {
|
|
|
258
215
|
}
|
|
259
216
|
throw new Error("Cannot find config file");
|
|
260
217
|
}
|
|
218
|
+
var fs, path, import_node_url, cache;
|
|
219
|
+
var init_load = __esm({
|
|
220
|
+
"src/loaders/config/load.ts"() {
|
|
221
|
+
"use strict";
|
|
222
|
+
fs = __toESM(require("fs/promises"), 1);
|
|
223
|
+
path = __toESM(require("path"), 1);
|
|
224
|
+
import_node_url = require("url");
|
|
225
|
+
init_build();
|
|
226
|
+
cache = null;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// src/next/map/watcher.ts
|
|
231
|
+
var watcher_exports = {};
|
|
232
|
+
__export(watcher_exports, {
|
|
233
|
+
watcher: () => watcher
|
|
234
|
+
});
|
|
235
|
+
function watcher(configPath, config, ignored) {
|
|
236
|
+
const watcher2 = new import_chokidar.FSWatcher({
|
|
237
|
+
ignoreInitial: true,
|
|
238
|
+
persistent: true,
|
|
239
|
+
ignored
|
|
240
|
+
});
|
|
241
|
+
watcher2.add(configPath);
|
|
242
|
+
for (const collection of config.collections.values()) {
|
|
243
|
+
if (collection.type === "docs") {
|
|
244
|
+
watcher2.add(collection.docs.dir);
|
|
245
|
+
watcher2.add(collection.meta.dir);
|
|
246
|
+
} else {
|
|
247
|
+
watcher2.add(collection.dir);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return watcher2;
|
|
251
|
+
}
|
|
252
|
+
var import_chokidar;
|
|
253
|
+
var init_watcher = __esm({
|
|
254
|
+
"src/next/map/watcher.ts"() {
|
|
255
|
+
"use strict";
|
|
256
|
+
import_chokidar = require("chokidar");
|
|
257
|
+
}
|
|
258
|
+
});
|
|
261
259
|
|
|
262
260
|
// src/next/index.ts
|
|
263
|
-
var
|
|
264
|
-
|
|
261
|
+
var next_exports = {};
|
|
262
|
+
__export(next_exports, {
|
|
263
|
+
createMDX: () => createMDX,
|
|
264
|
+
postInstall: () => postInstall,
|
|
265
|
+
start: () => start
|
|
266
|
+
});
|
|
267
|
+
module.exports = __toCommonJS(next_exports);
|
|
268
|
+
init_load();
|
|
269
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
270
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
265
271
|
|
|
266
|
-
// src/map/generate.ts
|
|
267
|
-
var
|
|
268
|
-
var
|
|
272
|
+
// src/next/map/generate.ts
|
|
273
|
+
var path5 = __toESM(require("path"), 1);
|
|
274
|
+
var import_node_crypto = require("crypto");
|
|
269
275
|
var import_tinyglobby = require("tinyglobby");
|
|
270
276
|
|
|
271
277
|
// src/utils/validation.ts
|
|
@@ -306,31 +312,36 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
306
312
|
return data;
|
|
307
313
|
}
|
|
308
314
|
|
|
309
|
-
// src/map/file-cache.ts
|
|
315
|
+
// src/next/map/file-cache.ts
|
|
310
316
|
var import_lru_cache = require("lru-cache");
|
|
317
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
318
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
311
319
|
var map = new import_lru_cache.LRUCache({
|
|
312
|
-
max:
|
|
320
|
+
max: 100
|
|
313
321
|
});
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return
|
|
317
|
-
},
|
|
318
|
-
write(namespace, path7, data) {
|
|
319
|
-
map.set(`${namespace}.${path7}`, data);
|
|
320
|
-
},
|
|
321
|
-
removeCache(path7) {
|
|
322
|
-
for (const key of map.keys()) {
|
|
323
|
-
const keyPath = key.slice(key.indexOf(".") + 1);
|
|
324
|
-
if (keyPath === path7) map.delete(key);
|
|
325
|
-
}
|
|
322
|
+
function toFullPath(file) {
|
|
323
|
+
if (import_node_path.default.isAbsolute(file)) {
|
|
324
|
+
return import_node_path.default.relative(process.cwd(), file);
|
|
326
325
|
}
|
|
327
|
-
|
|
326
|
+
return file;
|
|
327
|
+
}
|
|
328
|
+
async function readFileWithCache(file) {
|
|
329
|
+
const fullPath = toFullPath(file);
|
|
330
|
+
const cached = map.get(fullPath);
|
|
331
|
+
if (cached) return cached;
|
|
332
|
+
const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
|
|
333
|
+
map.set(fullPath, read);
|
|
334
|
+
return read;
|
|
335
|
+
}
|
|
336
|
+
function removeFileCache(file) {
|
|
337
|
+
map.delete(toFullPath(file));
|
|
338
|
+
}
|
|
328
339
|
|
|
329
|
-
// src/map/generate.ts
|
|
340
|
+
// src/next/map/generate.ts
|
|
330
341
|
var import_js_yaml2 = require("js-yaml");
|
|
331
342
|
|
|
332
343
|
// src/utils/git-timestamp.ts
|
|
333
|
-
var
|
|
344
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
334
345
|
var import_tinyexec = require("tinyexec");
|
|
335
346
|
var cache2 = /* @__PURE__ */ new Map();
|
|
336
347
|
async function getGitTimestamp(file) {
|
|
@@ -339,7 +350,7 @@ async function getGitTimestamp(file) {
|
|
|
339
350
|
try {
|
|
340
351
|
const out = await (0, import_tinyexec.x)(
|
|
341
352
|
"git",
|
|
342
|
-
["log", "-1", '--pretty="%ai"',
|
|
353
|
+
["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
|
|
343
354
|
{
|
|
344
355
|
throwOnError: true
|
|
345
356
|
}
|
|
@@ -369,7 +380,7 @@ function fumaMatter(input) {
|
|
|
369
380
|
}
|
|
370
381
|
|
|
371
382
|
// src/utils/import-formatter.ts
|
|
372
|
-
var
|
|
383
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
373
384
|
function getImportCode(info) {
|
|
374
385
|
const specifier = JSON.stringify(info.specifier);
|
|
375
386
|
if (info.type === "default") return `import ${info.name} from ${specifier}`;
|
|
@@ -384,7 +395,7 @@ function getImportCode(info) {
|
|
|
384
395
|
return `import ${specifier}`;
|
|
385
396
|
}
|
|
386
397
|
function toImportPath(file, config) {
|
|
387
|
-
const ext =
|
|
398
|
+
const ext = import_node_path3.default.extname(file);
|
|
388
399
|
let filename;
|
|
389
400
|
if (ext === ".ts" && config.jsExtension) {
|
|
390
401
|
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
@@ -395,14 +406,14 @@ function toImportPath(file, config) {
|
|
|
395
406
|
}
|
|
396
407
|
let importPath;
|
|
397
408
|
if ("relativeTo" in config) {
|
|
398
|
-
importPath =
|
|
399
|
-
if (!
|
|
409
|
+
importPath = import_node_path3.default.relative(config.relativeTo, filename);
|
|
410
|
+
if (!import_node_path3.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
400
411
|
importPath = `./${importPath}`;
|
|
401
412
|
}
|
|
402
413
|
} else {
|
|
403
|
-
importPath =
|
|
414
|
+
importPath = import_node_path3.default.resolve(filename);
|
|
404
415
|
}
|
|
405
|
-
return importPath.replaceAll(
|
|
416
|
+
return importPath.replaceAll(import_node_path3.default.sep, "/");
|
|
406
417
|
}
|
|
407
418
|
|
|
408
419
|
// src/utils/collections.ts
|
|
@@ -423,19 +434,14 @@ function isFileSupported(filePath, collection) {
|
|
|
423
434
|
return false;
|
|
424
435
|
}
|
|
425
436
|
|
|
426
|
-
// src/map/generate.ts
|
|
427
|
-
async function readFileWithCache(file) {
|
|
428
|
-
const cached = fileCache.read("read-file", file);
|
|
429
|
-
if (cached) return cached;
|
|
430
|
-
return (await fs2.readFile(file)).toString();
|
|
431
|
-
}
|
|
437
|
+
// src/next/map/generate.ts
|
|
432
438
|
async function generateJS(configPath, config, importPath, configHash = false) {
|
|
433
439
|
let asyncInit = false;
|
|
434
440
|
const lines = [
|
|
435
441
|
getImportCode({
|
|
436
442
|
type: "named",
|
|
437
443
|
names: ["_runtime"],
|
|
438
|
-
specifier: "fumadocs-mdx"
|
|
444
|
+
specifier: "fumadocs-mdx/runtime/next"
|
|
439
445
|
}),
|
|
440
446
|
getImportCode({
|
|
441
447
|
type: "namespace",
|
|
@@ -492,14 +498,18 @@ async function generateJS(configPath, config, importPath, configHash = false) {
|
|
|
492
498
|
specifier: "fumadocs-mdx/runtime/async",
|
|
493
499
|
names: ["_runtimeAsync", "buildConfig"]
|
|
494
500
|
}),
|
|
495
|
-
"const _sourceConfig = buildConfig(_source)"
|
|
501
|
+
"const _sourceConfig = buildConfig(_source)",
|
|
502
|
+
getImportCode({
|
|
503
|
+
type: "default",
|
|
504
|
+
name: "path",
|
|
505
|
+
specifier: "node:path"
|
|
506
|
+
})
|
|
496
507
|
);
|
|
497
508
|
asyncInit = true;
|
|
498
509
|
}
|
|
499
510
|
const entries2 = files.map(async (file) => {
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
);
|
|
511
|
+
const content = await readFileWithCache(file.fullPath).catch(() => "");
|
|
512
|
+
const parsed = fumaMatter(content);
|
|
503
513
|
let data = parsed.data;
|
|
504
514
|
if (collection.schema) {
|
|
505
515
|
data = await validate(
|
|
@@ -513,12 +523,15 @@ async function generateJS(configPath, config, importPath, configHash = false) {
|
|
|
513
523
|
if (config.global?.lastModifiedTime === "git") {
|
|
514
524
|
lastModified = await getGitTimestamp(file.fullPath);
|
|
515
525
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
526
|
+
const hash = (0, import_node_crypto.createHash)("md5").update(content).digest("hex");
|
|
527
|
+
const infoStr = [];
|
|
528
|
+
for (const [k, v] of Object.entries({ ...file, hash })) {
|
|
529
|
+
infoStr.push(`${k}: ${JSON.stringify(v)}`);
|
|
530
|
+
}
|
|
531
|
+
infoStr.push(
|
|
532
|
+
`absolutePath: path.resolve(${JSON.stringify(file.fullPath)})`
|
|
533
|
+
);
|
|
534
|
+
return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
|
|
522
535
|
});
|
|
523
536
|
return Promise.all(entries2);
|
|
524
537
|
}
|
|
@@ -558,11 +571,11 @@ async function getCollectionFiles(collection) {
|
|
|
558
571
|
await Promise.all(
|
|
559
572
|
dirs.map(async (dir) => {
|
|
560
573
|
const result = await (0, import_tinyglobby.glob)(patterns, {
|
|
561
|
-
cwd:
|
|
574
|
+
cwd: path5.resolve(dir)
|
|
562
575
|
});
|
|
563
576
|
for (const item of result) {
|
|
564
577
|
if (!isFileSupported(item, collection)) continue;
|
|
565
|
-
const fullPath =
|
|
578
|
+
const fullPath = path5.join(dir, item);
|
|
566
579
|
files.set(fullPath, {
|
|
567
580
|
path: item,
|
|
568
581
|
fullPath
|
|
@@ -573,7 +586,7 @@ async function getCollectionFiles(collection) {
|
|
|
573
586
|
return Array.from(files.values());
|
|
574
587
|
}
|
|
575
588
|
function parseMetaEntry(file, content) {
|
|
576
|
-
const extname2 =
|
|
589
|
+
const extname2 = path5.extname(file);
|
|
577
590
|
try {
|
|
578
591
|
if (extname2 === ".json") return JSON.parse(content);
|
|
579
592
|
if (extname2 === ".yaml") return (0, import_js_yaml2.load)(content);
|
|
@@ -585,13 +598,20 @@ function parseMetaEntry(file, content) {
|
|
|
585
598
|
throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
|
|
586
599
|
}
|
|
587
600
|
|
|
588
|
-
// src/
|
|
589
|
-
var
|
|
601
|
+
// src/loaders/config/index.ts
|
|
602
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
603
|
+
function findConfigFile() {
|
|
604
|
+
return import_node_path4.default.resolve("source.config.ts");
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// src/next/map/index.ts
|
|
608
|
+
var path7 = __toESM(require("path"), 1);
|
|
590
609
|
var fs3 = __toESM(require("fs/promises"), 1);
|
|
610
|
+
init_load();
|
|
591
611
|
async function start(dev, configPath, outDir) {
|
|
592
612
|
let configHash = await getConfigHash(configPath);
|
|
593
613
|
let config = await loadConfig(configPath, outDir, configHash, true);
|
|
594
|
-
const outPath =
|
|
614
|
+
const outPath = path7.resolve(outDir, `index.ts`);
|
|
595
615
|
async function updateMapFile() {
|
|
596
616
|
const start2 = performance.now();
|
|
597
617
|
try {
|
|
@@ -622,14 +642,14 @@ async function start(dev, configPath, outDir) {
|
|
|
622
642
|
});
|
|
623
643
|
instance.on("all", (event, file) => {
|
|
624
644
|
if (typeof file !== "string") return;
|
|
625
|
-
const absolutePath =
|
|
645
|
+
const absolutePath = path7.resolve(file);
|
|
626
646
|
const onUpdate = async () => {
|
|
627
647
|
const isConfigFile = absolutePath === configPath;
|
|
628
648
|
if (isConfigFile) {
|
|
629
649
|
configHash = await getConfigHash(configPath);
|
|
630
650
|
config = await loadConfig(configPath, outDir, configHash, true);
|
|
631
651
|
}
|
|
632
|
-
if (event === "change")
|
|
652
|
+
if (event === "change") removeFileCache(absolutePath);
|
|
633
653
|
await updateMapFile();
|
|
634
654
|
};
|
|
635
655
|
void onUpdate();
|
|
@@ -715,11 +735,11 @@ function createMDX({
|
|
|
715
735
|
// src/next/index.ts
|
|
716
736
|
async function postInstall(configPath = findConfigFile(), outDir = ".source") {
|
|
717
737
|
const config = await loadConfig(configPath, outDir, void 0, true);
|
|
718
|
-
const outPath =
|
|
719
|
-
await
|
|
720
|
-
await
|
|
738
|
+
const outPath = import_node_path5.default.join(outDir, "index.ts");
|
|
739
|
+
await import_promises2.default.rm(outDir, { recursive: true });
|
|
740
|
+
await import_promises2.default.mkdir(outDir, { recursive: true });
|
|
721
741
|
const hash = await getConfigHash(configPath);
|
|
722
|
-
await
|
|
742
|
+
await import_promises2.default.writeFile(
|
|
723
743
|
outPath,
|
|
724
744
|
await generateJS(configPath, config, { relativeTo: outDir }, hash)
|
|
725
745
|
);
|
package/dist/next/index.js
CHANGED
|
@@ -1,67 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readFileWithCache,
|
|
3
|
+
removeFileCache
|
|
4
|
+
} from "../chunk-ADR6R7HM.js";
|
|
1
5
|
import {
|
|
2
6
|
getGlobPatterns,
|
|
3
7
|
getImportCode,
|
|
4
8
|
isFileSupported,
|
|
5
9
|
toImportPath
|
|
6
10
|
} from "../chunk-6Y5JDZHD.js";
|
|
11
|
+
import {
|
|
12
|
+
getConfigHash,
|
|
13
|
+
loadConfig
|
|
14
|
+
} from "../chunk-LGYVNESJ.js";
|
|
15
|
+
import "../chunk-U4MQ44TS.js";
|
|
7
16
|
import {
|
|
8
17
|
ValidationError,
|
|
9
18
|
getGitTimestamp,
|
|
10
19
|
validate
|
|
11
20
|
} from "../chunk-IQAEAI4P.js";
|
|
12
21
|
import {
|
|
13
|
-
findConfigFile
|
|
14
|
-
|
|
15
|
-
loadConfig
|
|
16
|
-
} from "../chunk-POXTQZ4D.js";
|
|
17
|
-
import "../chunk-YC25YEBF.js";
|
|
22
|
+
findConfigFile
|
|
23
|
+
} from "../chunk-XMFLD5J6.js";
|
|
18
24
|
import {
|
|
19
25
|
fumaMatter
|
|
20
26
|
} from "../chunk-VWJKRQZR.js";
|
|
21
27
|
|
|
22
28
|
// src/next/index.ts
|
|
23
29
|
import path3 from "path";
|
|
24
|
-
import
|
|
30
|
+
import fs2 from "fs/promises";
|
|
25
31
|
|
|
26
|
-
// src/map/generate.ts
|
|
32
|
+
// src/next/map/generate.ts
|
|
27
33
|
import * as path from "path";
|
|
28
|
-
import
|
|
34
|
+
import { createHash } from "crypto";
|
|
29
35
|
import { glob } from "tinyglobby";
|
|
30
|
-
|
|
31
|
-
// src/map/file-cache.ts
|
|
32
|
-
import { LRUCache } from "lru-cache";
|
|
33
|
-
var map = new LRUCache({
|
|
34
|
-
max: 200
|
|
35
|
-
});
|
|
36
|
-
var fileCache = {
|
|
37
|
-
read(namespace, path4) {
|
|
38
|
-
return map.get(`${namespace}.${path4}`);
|
|
39
|
-
},
|
|
40
|
-
write(namespace, path4, data) {
|
|
41
|
-
map.set(`${namespace}.${path4}`, data);
|
|
42
|
-
},
|
|
43
|
-
removeCache(path4) {
|
|
44
|
-
for (const key of map.keys()) {
|
|
45
|
-
const keyPath = key.slice(key.indexOf(".") + 1);
|
|
46
|
-
if (keyPath === path4) map.delete(key);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// src/map/generate.ts
|
|
52
36
|
import { load } from "js-yaml";
|
|
53
|
-
async function readFileWithCache(file) {
|
|
54
|
-
const cached = fileCache.read("read-file", file);
|
|
55
|
-
if (cached) return cached;
|
|
56
|
-
return (await fs.readFile(file)).toString();
|
|
57
|
-
}
|
|
58
37
|
async function generateJS(configPath, config, importPath, configHash = false) {
|
|
59
38
|
let asyncInit = false;
|
|
60
39
|
const lines = [
|
|
61
40
|
getImportCode({
|
|
62
41
|
type: "named",
|
|
63
42
|
names: ["_runtime"],
|
|
64
|
-
specifier: "fumadocs-mdx"
|
|
43
|
+
specifier: "fumadocs-mdx/runtime/next"
|
|
65
44
|
}),
|
|
66
45
|
getImportCode({
|
|
67
46
|
type: "namespace",
|
|
@@ -118,14 +97,18 @@ async function generateJS(configPath, config, importPath, configHash = false) {
|
|
|
118
97
|
specifier: "fumadocs-mdx/runtime/async",
|
|
119
98
|
names: ["_runtimeAsync", "buildConfig"]
|
|
120
99
|
}),
|
|
121
|
-
"const _sourceConfig = buildConfig(_source)"
|
|
100
|
+
"const _sourceConfig = buildConfig(_source)",
|
|
101
|
+
getImportCode({
|
|
102
|
+
type: "default",
|
|
103
|
+
name: "path",
|
|
104
|
+
specifier: "node:path"
|
|
105
|
+
})
|
|
122
106
|
);
|
|
123
107
|
asyncInit = true;
|
|
124
108
|
}
|
|
125
109
|
const entries2 = files.map(async (file) => {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
);
|
|
110
|
+
const content = await readFileWithCache(file.fullPath).catch(() => "");
|
|
111
|
+
const parsed = fumaMatter(content);
|
|
129
112
|
let data = parsed.data;
|
|
130
113
|
if (collection.schema) {
|
|
131
114
|
data = await validate(
|
|
@@ -139,12 +122,15 @@ async function generateJS(configPath, config, importPath, configHash = false) {
|
|
|
139
122
|
if (config.global?.lastModifiedTime === "git") {
|
|
140
123
|
lastModified = await getGitTimestamp(file.fullPath);
|
|
141
124
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
125
|
+
const hash = createHash("md5").update(content).digest("hex");
|
|
126
|
+
const infoStr = [];
|
|
127
|
+
for (const [k, v] of Object.entries({ ...file, hash })) {
|
|
128
|
+
infoStr.push(`${k}: ${JSON.stringify(v)}`);
|
|
129
|
+
}
|
|
130
|
+
infoStr.push(
|
|
131
|
+
`absolutePath: path.resolve(${JSON.stringify(file.fullPath)})`
|
|
132
|
+
);
|
|
133
|
+
return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
|
|
148
134
|
});
|
|
149
135
|
return Promise.all(entries2);
|
|
150
136
|
}
|
|
@@ -211,9 +197,9 @@ function parseMetaEntry(file, content) {
|
|
|
211
197
|
throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
|
|
212
198
|
}
|
|
213
199
|
|
|
214
|
-
// src/map/index.ts
|
|
200
|
+
// src/next/map/index.ts
|
|
215
201
|
import * as path2 from "path";
|
|
216
|
-
import * as
|
|
202
|
+
import * as fs from "fs/promises";
|
|
217
203
|
async function start(dev, configPath, outDir) {
|
|
218
204
|
let configHash = await getConfigHash(configPath);
|
|
219
205
|
let config = await loadConfig(configPath, outDir, configHash, true);
|
|
@@ -221,7 +207,7 @@ async function start(dev, configPath, outDir) {
|
|
|
221
207
|
async function updateMapFile() {
|
|
222
208
|
const start2 = performance.now();
|
|
223
209
|
try {
|
|
224
|
-
await
|
|
210
|
+
await fs.writeFile(
|
|
225
211
|
outPath,
|
|
226
212
|
await generateJS(
|
|
227
213
|
configPath,
|
|
@@ -241,7 +227,7 @@ async function start(dev, configPath, outDir) {
|
|
|
241
227
|
}
|
|
242
228
|
await updateMapFile();
|
|
243
229
|
if (dev) {
|
|
244
|
-
const { watcher } = await import("../watcher-
|
|
230
|
+
const { watcher } = await import("../watcher-HGOH3APP.js");
|
|
245
231
|
const instance = watcher(configPath, config, [outPath]);
|
|
246
232
|
instance.on("ready", () => {
|
|
247
233
|
console.log("[MDX] started dev server");
|
|
@@ -255,7 +241,7 @@ async function start(dev, configPath, outDir) {
|
|
|
255
241
|
configHash = await getConfigHash(configPath);
|
|
256
242
|
config = await loadConfig(configPath, outDir, configHash, true);
|
|
257
243
|
}
|
|
258
|
-
if (event === "change")
|
|
244
|
+
if (event === "change") removeFileCache(absolutePath);
|
|
259
245
|
await updateMapFile();
|
|
260
246
|
};
|
|
261
247
|
void onUpdate();
|
|
@@ -342,10 +328,10 @@ function createMDX({
|
|
|
342
328
|
async function postInstall(configPath = findConfigFile(), outDir = ".source") {
|
|
343
329
|
const config = await loadConfig(configPath, outDir, void 0, true);
|
|
344
330
|
const outPath = path3.join(outDir, "index.ts");
|
|
345
|
-
await
|
|
346
|
-
await
|
|
331
|
+
await fs2.rm(outDir, { recursive: true });
|
|
332
|
+
await fs2.mkdir(outDir, { recursive: true });
|
|
347
333
|
const hash = await getConfigHash(configPath);
|
|
348
|
-
await
|
|
334
|
+
await fs2.writeFile(
|
|
349
335
|
outPath,
|
|
350
336
|
await generateJS(configPath, config, { relativeTo: outDir }, hash)
|
|
351
337
|
);
|