fumadocs-mdx 11.10.1 → 12.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 +126 -218
- package/dist/bin.js +1 -1
- package/dist/{browser-B2G8uAF2.d.cts → browser-D5lvL8vv.d.ts} +51 -4
- package/dist/{browser-DrH7tKRi.d.ts → browser-DjWADqp8.d.cts} +51 -4
- package/dist/bun/index.cjs +274 -230
- package/dist/bun/index.js +8 -8
- package/dist/chunk-ADR6R7HM.js +29 -0
- package/dist/{chunk-UOOPSLFY.js → chunk-AUOOMFAI.js} +27 -21
- package/dist/chunk-FSZMKRVH.js +80 -0
- package/dist/{chunk-766EAFX6.js → chunk-LGYVNESJ.js} +2 -36
- package/dist/chunk-LMG6UWCL.js +167 -0
- package/dist/chunk-QAUWMR5D.js +142 -0
- package/dist/{chunk-QJCCVMBJ.js → chunk-SP7CHRTS.js} +17 -47
- package/dist/{chunk-QVZ7JH4H.js → chunk-U4MQ44TS.js} +1 -1
- package/dist/{chunk-CNKI574E.js → chunk-VXEBLM4X.js} +1 -1
- package/dist/chunk-XMFLD5J6.js +30 -0
- package/dist/chunk-ZLCSVXCD.js +10 -0
- package/dist/{chunk-XXSKWWMB.js → chunk-ZX7TM4AR.js} +4 -2
- package/dist/config/index.cjs +97 -148
- package/dist/config/index.d.cts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +48 -9
- package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.cts} +18 -3
- package/dist/{define-BH4bnHQl.d.cts → define--6HQ1ehX.d.ts} +18 -3
- package/dist/load-UUXLUBHL.js +9 -0
- package/dist/loader-mdx.cjs +336 -305
- package/dist/loader-mdx.js +8 -8
- package/dist/next/index.cjs +152 -242
- package/dist/next/index.js +52 -66
- package/dist/node/loader.cjs +274 -243
- package/dist/node/loader.js +7 -8
- package/dist/postinstall-SCSXM4IM.js +10 -0
- package/dist/{mdx-options-T73E4LQB.js → preset-ZMP6U62C.js} +1 -1
- package/dist/runtime/next/async.cjs +304 -204
- package/dist/runtime/next/async.d.cts +3 -3
- package/dist/runtime/next/async.d.ts +3 -3
- package/dist/runtime/next/async.js +59 -32
- package/dist/runtime/next/index.cjs +32 -21
- package/dist/runtime/next/index.d.cts +11 -7
- package/dist/runtime/next/index.d.ts +11 -7
- package/dist/runtime/next/index.js +2 -1
- package/dist/runtime/vite/browser.d.cts +2 -3
- package/dist/runtime/vite/browser.d.ts +2 -3
- package/dist/runtime/vite/server.cjs +67 -21
- package/dist/runtime/vite/server.d.cts +14 -28
- package/dist/runtime/vite/server.d.ts +14 -28
- package/dist/runtime/vite/server.js +61 -21
- package/dist/shared-0QIuV0XZ.d.ts +70 -0
- package/dist/shared-CqgMnt9h.d.cts +70 -0
- package/dist/{types-DN9KrG7R.d.ts → types-CFlQxTN8.d.ts} +10 -37
- package/dist/{types-DT83Ijs6.d.cts → types-DkGjw-Uo.d.cts} +10 -37
- package/dist/vite/index.cjs +299 -279
- 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 +16 -16
- package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
- package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
- package/dist/chunk-GBMFGEC7.js +0 -57
- package/dist/chunk-QQWCBFFE.js +0 -40
- package/dist/chunk-SMSNZ6N5.js +0 -155
- package/dist/chunk-SVTXMVLQ.js +0 -139
- package/dist/config/zod-3.cjs +0 -422
- package/dist/config/zod-3.d.cts +0 -53
- package/dist/config/zod-3.d.ts +0 -53
- package/dist/config/zod-3.js +0 -40
- package/dist/postinstall-XV4WSHZP.js +0 -9
package/dist/loader-mdx.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
toWebpack
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VXEBLM4X.js";
|
|
4
4
|
import {
|
|
5
|
-
createMdxLoader
|
|
6
|
-
|
|
7
|
-
} from "./chunk-QJCCVMBJ.js";
|
|
8
|
-
import "./chunk-QQWCBFFE.js";
|
|
9
|
-
import "./chunk-SVTXMVLQ.js";
|
|
5
|
+
createMdxLoader
|
|
6
|
+
} from "./chunk-SP7CHRTS.js";
|
|
10
7
|
import "./chunk-IQAEAI4P.js";
|
|
11
|
-
import
|
|
12
|
-
|
|
8
|
+
import {
|
|
9
|
+
dynamicConfig
|
|
10
|
+
} from "./chunk-XMFLD5J6.js";
|
|
11
|
+
import "./chunk-QAUWMR5D.js";
|
|
12
|
+
import "./chunk-LMG6UWCL.js";
|
|
13
13
|
import "./chunk-VWJKRQZR.js";
|
|
14
14
|
|
|
15
15
|
// src/loader-mdx.ts
|
package/dist/next/index.cjs
CHANGED
|
@@ -30,86 +30,9 @@ 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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}) {
|
|
37
|
-
return (tree, file) => {
|
|
38
|
-
let title;
|
|
39
|
-
const urls = [];
|
|
40
|
-
(0, import_unist_util_visit.visit)(tree, ["heading", "link"], (node) => {
|
|
41
|
-
if (node.type === "heading" && node.depth === 1) {
|
|
42
|
-
title = flattenNode(node);
|
|
43
|
-
}
|
|
44
|
-
if (node.type !== "link") return;
|
|
45
|
-
urls.push({
|
|
46
|
-
href: node.url
|
|
47
|
-
});
|
|
48
|
-
return "skip";
|
|
49
|
-
});
|
|
50
|
-
if (title) {
|
|
51
|
-
file.data.frontmatter ??= {};
|
|
52
|
-
if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
|
|
53
|
-
}
|
|
54
|
-
file.data.extractedReferences = urls;
|
|
55
|
-
for (const name of injectExports) {
|
|
56
|
-
if (!(name in file.data)) continue;
|
|
57
|
-
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function flattenNode(node) {
|
|
62
|
-
if ("children" in node)
|
|
63
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
64
|
-
if ("value" in node) return node.value;
|
|
65
|
-
return "";
|
|
66
|
-
}
|
|
67
|
-
function getMdastExport(name, value) {
|
|
68
|
-
return {
|
|
69
|
-
type: "mdxjsEsm",
|
|
70
|
-
value: "",
|
|
71
|
-
data: {
|
|
72
|
-
estree: {
|
|
73
|
-
type: "Program",
|
|
74
|
-
sourceType: "module",
|
|
75
|
-
body: [
|
|
76
|
-
{
|
|
77
|
-
type: "ExportNamedDeclaration",
|
|
78
|
-
attributes: [],
|
|
79
|
-
specifiers: [],
|
|
80
|
-
source: null,
|
|
81
|
-
declaration: {
|
|
82
|
-
type: "VariableDeclaration",
|
|
83
|
-
kind: "let",
|
|
84
|
-
declarations: [
|
|
85
|
-
{
|
|
86
|
-
type: "VariableDeclarator",
|
|
87
|
-
id: {
|
|
88
|
-
type: "Identifier",
|
|
89
|
-
name
|
|
90
|
-
},
|
|
91
|
-
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
var import_unist_util_visit, import_estree_util_value_to_estree;
|
|
102
|
-
var init_remark_postprocess = __esm({
|
|
103
|
-
"src/mdx-plugins/remark-postprocess.ts"() {
|
|
104
|
-
"use strict";
|
|
105
|
-
import_unist_util_visit = require("unist-util-visit");
|
|
106
|
-
import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// src/utils/mdx-options.ts
|
|
111
|
-
var mdx_options_exports = {};
|
|
112
|
-
__export(mdx_options_exports, {
|
|
33
|
+
// src/loaders/mdx/preset.ts
|
|
34
|
+
var preset_exports = {};
|
|
35
|
+
__export(preset_exports, {
|
|
113
36
|
getDefaultMDXOptions: () => getDefaultMDXOptions
|
|
114
37
|
});
|
|
115
38
|
function pluginOption(def, options = []) {
|
|
@@ -132,13 +55,6 @@ function getDefaultMDXOptions({
|
|
|
132
55
|
_withoutBundler = false,
|
|
133
56
|
...mdxOptions
|
|
134
57
|
}) {
|
|
135
|
-
const mdxExports = [
|
|
136
|
-
"structuredData",
|
|
137
|
-
"extractedReferences",
|
|
138
|
-
"frontmatter",
|
|
139
|
-
"lastModified",
|
|
140
|
-
...valueToExport
|
|
141
|
-
];
|
|
142
58
|
const remarkPlugins = pluginOption(
|
|
143
59
|
(v) => [
|
|
144
60
|
plugins.remarkGfm,
|
|
@@ -166,10 +82,15 @@ function getDefaultMDXOptions({
|
|
|
166
82
|
plugins.remarkStructure,
|
|
167
83
|
remarkStructureOptions
|
|
168
84
|
],
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
85
|
+
() => {
|
|
86
|
+
return (_, file) => {
|
|
87
|
+
file.data["mdx-export"] ??= [];
|
|
88
|
+
for (const name of valueToExport) {
|
|
89
|
+
if (name in file.data)
|
|
90
|
+
file.data["mdx-export"].push({ name, value: file.data[name] });
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
173
94
|
],
|
|
174
95
|
mdxOptions.remarkPlugins
|
|
175
96
|
);
|
|
@@ -189,58 +110,13 @@ function getDefaultMDXOptions({
|
|
|
189
110
|
};
|
|
190
111
|
}
|
|
191
112
|
var plugins;
|
|
192
|
-
var
|
|
193
|
-
"src/
|
|
113
|
+
var init_preset = __esm({
|
|
114
|
+
"src/loaders/mdx/preset.ts"() {
|
|
194
115
|
"use strict";
|
|
195
116
|
plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
196
|
-
init_remark_postprocess();
|
|
197
117
|
}
|
|
198
118
|
});
|
|
199
119
|
|
|
200
|
-
// src/map/watcher.ts
|
|
201
|
-
var watcher_exports = {};
|
|
202
|
-
__export(watcher_exports, {
|
|
203
|
-
watcher: () => watcher
|
|
204
|
-
});
|
|
205
|
-
function watcher(configPath, config, ignored) {
|
|
206
|
-
const watcher2 = new import_chokidar.FSWatcher({
|
|
207
|
-
ignoreInitial: true,
|
|
208
|
-
persistent: true,
|
|
209
|
-
ignored
|
|
210
|
-
});
|
|
211
|
-
watcher2.add(configPath);
|
|
212
|
-
for (const collection of config.collections.values()) {
|
|
213
|
-
if (collection.type === "docs") {
|
|
214
|
-
watcher2.add(collection.docs.dir);
|
|
215
|
-
watcher2.add(collection.meta.dir);
|
|
216
|
-
} else {
|
|
217
|
-
watcher2.add(collection.dir);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return watcher2;
|
|
221
|
-
}
|
|
222
|
-
var import_chokidar;
|
|
223
|
-
var init_watcher = __esm({
|
|
224
|
-
"src/map/watcher.ts"() {
|
|
225
|
-
"use strict";
|
|
226
|
-
import_chokidar = require("chokidar");
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
// src/next/index.ts
|
|
231
|
-
var next_exports = {};
|
|
232
|
-
__export(next_exports, {
|
|
233
|
-
createMDX: () => createMDX,
|
|
234
|
-
postInstall: () => postInstall,
|
|
235
|
-
start: () => start
|
|
236
|
-
});
|
|
237
|
-
module.exports = __toCommonJS(next_exports);
|
|
238
|
-
|
|
239
|
-
// src/utils/config.ts
|
|
240
|
-
var fs = __toESM(require("fs/promises"), 1);
|
|
241
|
-
var path = __toESM(require("path"), 1);
|
|
242
|
-
var import_node_url = require("url");
|
|
243
|
-
|
|
244
120
|
// src/config/build.ts
|
|
245
121
|
function buildConfig(config) {
|
|
246
122
|
const collections = /* @__PURE__ */ new Map();
|
|
@@ -277,7 +153,7 @@ function buildConfig(config) {
|
|
|
277
153
|
const input = this.global.mdxOptions;
|
|
278
154
|
async function uncached() {
|
|
279
155
|
const options = typeof input === "function" ? await input() : input;
|
|
280
|
-
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (
|
|
156
|
+
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
|
|
281
157
|
if (options?.preset === "minimal") return options;
|
|
282
158
|
return getDefaultMDXOptions2({
|
|
283
159
|
...options,
|
|
@@ -290,41 +166,13 @@ function buildConfig(config) {
|
|
|
290
166
|
}
|
|
291
167
|
};
|
|
292
168
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return path.resolve("source.config.ts");
|
|
297
|
-
}
|
|
298
|
-
var cache = null;
|
|
299
|
-
async function isZod3() {
|
|
300
|
-
try {
|
|
301
|
-
const content = JSON.parse(
|
|
302
|
-
(await fs.readFile("node_modules/zod/package.json")).toString()
|
|
303
|
-
);
|
|
304
|
-
const version = content.version;
|
|
305
|
-
return typeof version === "string" && version.startsWith("3.");
|
|
306
|
-
} catch {
|
|
307
|
-
return false;
|
|
169
|
+
var init_build = __esm({
|
|
170
|
+
"src/config/build.ts"() {
|
|
171
|
+
"use strict";
|
|
308
172
|
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
name: "replace-zod-import",
|
|
313
|
-
async setup(build) {
|
|
314
|
-
const usingZod3 = await isZod3();
|
|
315
|
-
if (!usingZod3) return;
|
|
316
|
-
console.warn(
|
|
317
|
-
"[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
|
|
318
|
-
);
|
|
319
|
-
build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
|
|
320
|
-
return {
|
|
321
|
-
path: "fumadocs-mdx/config/zod-3",
|
|
322
|
-
external: true
|
|
323
|
-
};
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// src/loaders/config/load.ts
|
|
328
176
|
async function compileConfig(configPath, outDir) {
|
|
329
177
|
const { build } = await import("esbuild");
|
|
330
178
|
const transformed = await build({
|
|
@@ -336,7 +184,6 @@ async function compileConfig(configPath, outDir) {
|
|
|
336
184
|
platform: "node",
|
|
337
185
|
format: "esm",
|
|
338
186
|
packages: "external",
|
|
339
|
-
plugins: [createCompatZodPlugin()],
|
|
340
187
|
outExtension: {
|
|
341
188
|
".js": ".mjs"
|
|
342
189
|
},
|
|
@@ -368,14 +215,63 @@ async function getConfigHash(configPath) {
|
|
|
368
215
|
}
|
|
369
216
|
throw new Error("Cannot find config file");
|
|
370
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
|
+
});
|
|
371
259
|
|
|
372
260
|
// src/next/index.ts
|
|
373
|
-
var
|
|
374
|
-
|
|
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);
|
|
375
271
|
|
|
376
|
-
// src/map/generate.ts
|
|
377
|
-
var
|
|
378
|
-
var
|
|
272
|
+
// src/next/map/generate.ts
|
|
273
|
+
var path5 = __toESM(require("path"), 1);
|
|
274
|
+
var import_node_crypto = require("crypto");
|
|
379
275
|
var import_tinyglobby = require("tinyglobby");
|
|
380
276
|
|
|
381
277
|
// src/utils/validation.ts
|
|
@@ -416,31 +312,36 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
416
312
|
return data;
|
|
417
313
|
}
|
|
418
314
|
|
|
419
|
-
// src/map/file-cache.ts
|
|
315
|
+
// src/next/map/file-cache.ts
|
|
420
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);
|
|
421
319
|
var map = new import_lru_cache.LRUCache({
|
|
422
|
-
max:
|
|
320
|
+
max: 100
|
|
423
321
|
});
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
return
|
|
427
|
-
},
|
|
428
|
-
write(namespace, path7, data) {
|
|
429
|
-
map.set(`${namespace}.${path7}`, data);
|
|
430
|
-
},
|
|
431
|
-
removeCache(path7) {
|
|
432
|
-
for (const key of map.keys()) {
|
|
433
|
-
const keyPath = key.slice(key.indexOf(".") + 1);
|
|
434
|
-
if (keyPath === path7) map.delete(key);
|
|
435
|
-
}
|
|
322
|
+
function toFullPath(file) {
|
|
323
|
+
if (import_node_path.default.isAbsolute(file)) {
|
|
324
|
+
return import_node_path.default.relative(process.cwd(), file);
|
|
436
325
|
}
|
|
437
|
-
|
|
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
|
+
}
|
|
438
339
|
|
|
439
|
-
// src/map/generate.ts
|
|
340
|
+
// src/next/map/generate.ts
|
|
440
341
|
var import_js_yaml2 = require("js-yaml");
|
|
441
342
|
|
|
442
343
|
// src/utils/git-timestamp.ts
|
|
443
|
-
var
|
|
344
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
444
345
|
var import_tinyexec = require("tinyexec");
|
|
445
346
|
var cache2 = /* @__PURE__ */ new Map();
|
|
446
347
|
async function getGitTimestamp(file) {
|
|
@@ -449,7 +350,7 @@ async function getGitTimestamp(file) {
|
|
|
449
350
|
try {
|
|
450
351
|
const out = await (0, import_tinyexec.x)(
|
|
451
352
|
"git",
|
|
452
|
-
["log", "-1", '--pretty="%ai"',
|
|
353
|
+
["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
|
|
453
354
|
{
|
|
454
355
|
throwOnError: true
|
|
455
356
|
}
|
|
@@ -479,7 +380,7 @@ function fumaMatter(input) {
|
|
|
479
380
|
}
|
|
480
381
|
|
|
481
382
|
// src/utils/import-formatter.ts
|
|
482
|
-
var
|
|
383
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
483
384
|
function getImportCode(info) {
|
|
484
385
|
const specifier = JSON.stringify(info.specifier);
|
|
485
386
|
if (info.type === "default") return `import ${info.name} from ${specifier}`;
|
|
@@ -494,7 +395,7 @@ function getImportCode(info) {
|
|
|
494
395
|
return `import ${specifier}`;
|
|
495
396
|
}
|
|
496
397
|
function toImportPath(file, config) {
|
|
497
|
-
const ext =
|
|
398
|
+
const ext = import_node_path3.default.extname(file);
|
|
498
399
|
let filename;
|
|
499
400
|
if (ext === ".ts" && config.jsExtension) {
|
|
500
401
|
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
@@ -505,14 +406,14 @@ function toImportPath(file, config) {
|
|
|
505
406
|
}
|
|
506
407
|
let importPath;
|
|
507
408
|
if ("relativeTo" in config) {
|
|
508
|
-
importPath =
|
|
509
|
-
if (!
|
|
409
|
+
importPath = import_node_path3.default.relative(config.relativeTo, filename);
|
|
410
|
+
if (!import_node_path3.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
510
411
|
importPath = `./${importPath}`;
|
|
511
412
|
}
|
|
512
413
|
} else {
|
|
513
|
-
importPath =
|
|
414
|
+
importPath = import_node_path3.default.resolve(filename);
|
|
514
415
|
}
|
|
515
|
-
return importPath.replaceAll(
|
|
416
|
+
return importPath.replaceAll(import_node_path3.default.sep, "/");
|
|
516
417
|
}
|
|
517
418
|
|
|
518
419
|
// src/utils/collections.ts
|
|
@@ -533,12 +434,7 @@ function isFileSupported(filePath, collection) {
|
|
|
533
434
|
return false;
|
|
534
435
|
}
|
|
535
436
|
|
|
536
|
-
// src/map/generate.ts
|
|
537
|
-
async function readFileWithCache(file) {
|
|
538
|
-
const cached = fileCache.read("read-file", file);
|
|
539
|
-
if (cached) return cached;
|
|
540
|
-
return (await fs2.readFile(file)).toString();
|
|
541
|
-
}
|
|
437
|
+
// src/next/map/generate.ts
|
|
542
438
|
async function generateJS(configPath, config, importPath, configHash = false) {
|
|
543
439
|
let asyncInit = false;
|
|
544
440
|
const lines = [
|
|
@@ -565,7 +461,7 @@ async function generateJS(configPath, config, importPath, configHash = false) {
|
|
|
565
461
|
getImportCode({
|
|
566
462
|
type: "namespace",
|
|
567
463
|
name: importId,
|
|
568
|
-
specifier: `${toImportPath(file.
|
|
464
|
+
specifier: `${toImportPath(file.fullPath, importPath)}?${params.join("&")}`
|
|
569
465
|
})
|
|
570
466
|
);
|
|
571
467
|
return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
|
|
@@ -574,17 +470,17 @@ async function generateJS(configPath, config, importPath, configHash = false) {
|
|
|
574
470
|
}
|
|
575
471
|
async function getMetaEntries(collection, files) {
|
|
576
472
|
const items = files.map(async (file) => {
|
|
577
|
-
const source = await readFileWithCache(file.
|
|
578
|
-
let data = source.length === 0 ? {} : parseMetaEntry(file.
|
|
473
|
+
const source = await readFileWithCache(file.fullPath).catch(() => "");
|
|
474
|
+
let data = source.length === 0 ? {} : parseMetaEntry(file.fullPath, source);
|
|
579
475
|
if (collection?.schema) {
|
|
580
476
|
data = await validate(
|
|
581
477
|
collection.schema,
|
|
582
478
|
data,
|
|
583
479
|
{
|
|
584
480
|
source,
|
|
585
|
-
path: file.
|
|
481
|
+
path: file.fullPath
|
|
586
482
|
},
|
|
587
|
-
`invalid data in ${file.
|
|
483
|
+
`invalid data in ${file.fullPath}`
|
|
588
484
|
);
|
|
589
485
|
}
|
|
590
486
|
return JSON.stringify({
|
|
@@ -602,33 +498,40 @@ async function generateJS(configPath, config, importPath, configHash = false) {
|
|
|
602
498
|
specifier: "fumadocs-mdx/runtime/async",
|
|
603
499
|
names: ["_runtimeAsync", "buildConfig"]
|
|
604
500
|
}),
|
|
605
|
-
"const _sourceConfig = buildConfig(_source)"
|
|
501
|
+
"const _sourceConfig = buildConfig(_source)",
|
|
502
|
+
getImportCode({
|
|
503
|
+
type: "default",
|
|
504
|
+
name: "path",
|
|
505
|
+
specifier: "node:path"
|
|
506
|
+
})
|
|
606
507
|
);
|
|
607
508
|
asyncInit = true;
|
|
608
509
|
}
|
|
609
510
|
const entries2 = files.map(async (file) => {
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
);
|
|
511
|
+
const content = await readFileWithCache(file.fullPath).catch(() => "");
|
|
512
|
+
const parsed = fumaMatter(content);
|
|
613
513
|
let data = parsed.data;
|
|
614
514
|
if (collection.schema) {
|
|
615
515
|
data = await validate(
|
|
616
516
|
collection.schema,
|
|
617
517
|
parsed.data,
|
|
618
|
-
{ path: file.
|
|
619
|
-
`invalid frontmatter in ${file.
|
|
518
|
+
{ path: file.fullPath, source: parsed.content },
|
|
519
|
+
`invalid frontmatter in ${file.fullPath}`
|
|
620
520
|
);
|
|
621
521
|
}
|
|
622
522
|
let lastModified;
|
|
623
523
|
if (config.global?.lastModifiedTime === "git") {
|
|
624
|
-
lastModified = await getGitTimestamp(file.
|
|
524
|
+
lastModified = await getGitTimestamp(file.fullPath);
|
|
625
525
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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)} }`;
|
|
632
535
|
});
|
|
633
536
|
return Promise.all(entries2);
|
|
634
537
|
}
|
|
@@ -668,14 +571,14 @@ async function getCollectionFiles(collection) {
|
|
|
668
571
|
await Promise.all(
|
|
669
572
|
dirs.map(async (dir) => {
|
|
670
573
|
const result = await (0, import_tinyglobby.glob)(patterns, {
|
|
671
|
-
cwd:
|
|
672
|
-
absolute: true
|
|
574
|
+
cwd: path5.resolve(dir)
|
|
673
575
|
});
|
|
674
576
|
for (const item of result) {
|
|
675
577
|
if (!isFileSupported(item, collection)) continue;
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
578
|
+
const fullPath = path5.join(dir, item);
|
|
579
|
+
files.set(fullPath, {
|
|
580
|
+
path: item,
|
|
581
|
+
fullPath
|
|
679
582
|
});
|
|
680
583
|
}
|
|
681
584
|
})
|
|
@@ -683,7 +586,7 @@ async function getCollectionFiles(collection) {
|
|
|
683
586
|
return Array.from(files.values());
|
|
684
587
|
}
|
|
685
588
|
function parseMetaEntry(file, content) {
|
|
686
|
-
const extname2 =
|
|
589
|
+
const extname2 = path5.extname(file);
|
|
687
590
|
try {
|
|
688
591
|
if (extname2 === ".json") return JSON.parse(content);
|
|
689
592
|
if (extname2 === ".yaml") return (0, import_js_yaml2.load)(content);
|
|
@@ -695,13 +598,20 @@ function parseMetaEntry(file, content) {
|
|
|
695
598
|
throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
|
|
696
599
|
}
|
|
697
600
|
|
|
698
|
-
// src/
|
|
699
|
-
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);
|
|
700
609
|
var fs3 = __toESM(require("fs/promises"), 1);
|
|
610
|
+
init_load();
|
|
701
611
|
async function start(dev, configPath, outDir) {
|
|
702
612
|
let configHash = await getConfigHash(configPath);
|
|
703
613
|
let config = await loadConfig(configPath, outDir, configHash, true);
|
|
704
|
-
const outPath =
|
|
614
|
+
const outPath = path7.resolve(outDir, `index.ts`);
|
|
705
615
|
async function updateMapFile() {
|
|
706
616
|
const start2 = performance.now();
|
|
707
617
|
try {
|
|
@@ -732,14 +642,14 @@ async function start(dev, configPath, outDir) {
|
|
|
732
642
|
});
|
|
733
643
|
instance.on("all", (event, file) => {
|
|
734
644
|
if (typeof file !== "string") return;
|
|
735
|
-
const absolutePath =
|
|
645
|
+
const absolutePath = path7.resolve(file);
|
|
736
646
|
const onUpdate = async () => {
|
|
737
647
|
const isConfigFile = absolutePath === configPath;
|
|
738
648
|
if (isConfigFile) {
|
|
739
649
|
configHash = await getConfigHash(configPath);
|
|
740
650
|
config = await loadConfig(configPath, outDir, configHash, true);
|
|
741
651
|
}
|
|
742
|
-
if (event === "change")
|
|
652
|
+
if (event === "change") removeFileCache(absolutePath);
|
|
743
653
|
await updateMapFile();
|
|
744
654
|
};
|
|
745
655
|
void onUpdate();
|
|
@@ -825,11 +735,11 @@ function createMDX({
|
|
|
825
735
|
// src/next/index.ts
|
|
826
736
|
async function postInstall(configPath = findConfigFile(), outDir = ".source") {
|
|
827
737
|
const config = await loadConfig(configPath, outDir, void 0, true);
|
|
828
|
-
const outPath =
|
|
829
|
-
await
|
|
830
|
-
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 });
|
|
831
741
|
const hash = await getConfigHash(configPath);
|
|
832
|
-
await
|
|
742
|
+
await import_promises2.default.writeFile(
|
|
833
743
|
outPath,
|
|
834
744
|
await generateJS(configPath, config, { relativeTo: outDir }, hash)
|
|
835
745
|
);
|