fumadocs-mdx 14.0.0 → 14.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/{build-mdx-6UAK5FF5.js → build-mdx-W3233QBZ.js} +1 -1
- package/dist/bun/index.d.ts +7 -1
- package/dist/bun/index.js +9 -8
- package/dist/{chunk-5YXP7JLN.js → chunk-5OBUOALK.js} +8 -5
- package/dist/{chunk-ZY6UZ7NH.js → chunk-6RPNS75C.js} +1 -1
- package/dist/{chunk-XHJCLBZ4.js → chunk-ED3ON275.js} +86 -162
- package/dist/{chunk-7L2KNF6B.js → chunk-GB4W3YCZ.js} +51 -7
- package/dist/{chunk-SLY7WXTX.js → chunk-KOPLIEVQ.js} +5 -6
- package/dist/{chunk-OXSRIWQW.js → chunk-LPX7ZO66.js} +4 -3
- package/dist/{chunk-SRSRFOVI.js → chunk-OLL7FM7W.js} +3 -3
- package/dist/{chunk-5UMZCWKV.js → chunk-Q5OSGLJL.js} +1 -1
- package/dist/{chunk-E5DJTSIM.js → chunk-S7KOJHHO.js} +4 -1
- package/dist/{chunk-6NISOLQ6.js → chunk-USWQVJWR.js} +1 -1
- package/dist/chunk-WBIHDYMN.js +126 -0
- package/dist/config/index.d.ts +6 -1
- package/dist/config/index.js +1 -1
- package/dist/{index-D7JdSMpp.d.cts → core-C3QZSdEx.d.ts} +73 -4
- package/dist/{index-BlVBvy-z.d.ts → index-RVIZxMZG.d.ts} +1 -1
- package/dist/index.d.ts +56 -3
- package/dist/load-from-file-OZ5N7DXU.js +8 -0
- package/dist/next/index.cjs +263 -193
- package/dist/next/index.d.ts +7 -2
- package/dist/next/index.js +12 -10
- package/dist/node/loader.js +4 -4
- package/dist/plugins/index-file.d.ts +7 -22
- package/dist/plugins/index-file.js +2 -2
- package/dist/plugins/json-schema.d.ts +7 -1
- package/dist/plugins/last-modified.d.ts +15 -2
- package/dist/plugins/last-modified.js +43 -6
- package/dist/runtime/browser.d.ts +22 -19
- package/dist/runtime/browser.js +5 -6
- package/dist/runtime/dynamic.d.ts +12 -12
- package/dist/runtime/dynamic.js +12 -11
- package/dist/runtime/server.d.ts +10 -157
- package/dist/runtime/server.js +3 -3
- package/dist/runtime/types.d.ts +61 -0
- package/dist/runtime/types.js +0 -0
- package/dist/vite/index.d.ts +7 -2
- package/dist/vite/index.js +10 -9
- package/dist/webpack/mdx.d.ts +8 -2
- package/dist/webpack/mdx.js +5 -5
- package/dist/webpack/meta.d.ts +8 -2
- package/dist/webpack/meta.js +4 -4
- package/package.json +4 -6
- package/dist/bin.cjs +0 -1889
- package/dist/bin.d.cts +0 -1
- package/dist/bun/index.cjs +0 -1112
- package/dist/bun/index.d.cts +0 -19
- package/dist/chunk-PKI7ZDA5.js +0 -29
- package/dist/config/index.cjs +0 -400
- package/dist/config/index.d.cts +0 -13
- package/dist/index-D7JdSMpp.d.ts +0 -272
- package/dist/index-P2NNUkHn.d.cts +0 -8
- package/dist/index.cjs +0 -18
- package/dist/index.d.cts +0 -8
- package/dist/load-from-file-I3ALLIVB.js +0 -8
- package/dist/next/index.d.cts +0 -28
- package/dist/node/loader.cjs +0 -1165
- package/dist/node/loader.d.cts +0 -5
- package/dist/plugins/index-file.cjs +0 -471
- package/dist/plugins/index-file.d.cts +0 -29
- package/dist/plugins/json-schema.cjs +0 -114
- package/dist/plugins/json-schema.d.cts +0 -25
- package/dist/plugins/last-modified.cjs +0 -75
- package/dist/plugins/last-modified.d.cts +0 -27
- package/dist/runtime/browser.cjs +0 -94
- package/dist/runtime/browser.d.cts +0 -50
- package/dist/runtime/dynamic.cjs +0 -985
- package/dist/runtime/dynamic.d.cts +0 -27
- package/dist/runtime/server.cjs +0 -173
- package/dist/runtime/server.d.cts +0 -161
- package/dist/vite/index.cjs +0 -1620
- package/dist/vite/index.d.cts +0 -39
- package/dist/webpack/mdx.cjs +0 -1089
- package/dist/webpack/mdx.d.cts +0 -14
- package/dist/webpack/meta.cjs +0 -649
- package/dist/webpack/meta.d.cts +0 -14
package/dist/webpack/mdx.cjs
DELETED
|
@@ -1,1089 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esm = (fn, res) => function __init() {
|
|
9
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
-
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
|
|
33
|
-
// src/utils/fuma-matter.ts
|
|
34
|
-
function fumaMatter(input) {
|
|
35
|
-
const output = { matter: "", data: {}, content: input };
|
|
36
|
-
const match = regex.exec(input);
|
|
37
|
-
if (!match) {
|
|
38
|
-
return output;
|
|
39
|
-
}
|
|
40
|
-
output.matter = match[0];
|
|
41
|
-
output.content = input.slice(match[0].length);
|
|
42
|
-
const loaded = (0, import_js_yaml.load)(match[1]);
|
|
43
|
-
output.data = loaded ?? {};
|
|
44
|
-
return output;
|
|
45
|
-
}
|
|
46
|
-
var import_js_yaml, regex;
|
|
47
|
-
var init_fuma_matter = __esm({
|
|
48
|
-
"src/utils/fuma-matter.ts"() {
|
|
49
|
-
"use strict";
|
|
50
|
-
import_js_yaml = require("js-yaml");
|
|
51
|
-
regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// src/loaders/mdx/remark-unravel.ts
|
|
56
|
-
function remarkMarkAndUnravel() {
|
|
57
|
-
return (tree) => {
|
|
58
|
-
(0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
|
|
59
|
-
let offset = -1;
|
|
60
|
-
let all = true;
|
|
61
|
-
let oneOrMore = false;
|
|
62
|
-
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
63
|
-
const children = node.children;
|
|
64
|
-
while (++offset < children.length) {
|
|
65
|
-
const child = children[offset];
|
|
66
|
-
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
|
|
67
|
-
oneOrMore = true;
|
|
68
|
-
} else if (child.type === "text" && child.value.trim().length === 0) {
|
|
69
|
-
} else {
|
|
70
|
-
all = false;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (all && oneOrMore) {
|
|
75
|
-
offset = -1;
|
|
76
|
-
const newChildren = [];
|
|
77
|
-
while (++offset < children.length) {
|
|
78
|
-
const child = children[offset];
|
|
79
|
-
if (child.type === "mdxJsxTextElement") {
|
|
80
|
-
child.type = "mdxJsxFlowElement";
|
|
81
|
-
}
|
|
82
|
-
if (child.type === "mdxTextExpression") {
|
|
83
|
-
child.type = "mdxFlowExpression";
|
|
84
|
-
}
|
|
85
|
-
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
|
|
86
|
-
} else {
|
|
87
|
-
newChildren.push(child);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
parent.children.splice(index, 1, ...newChildren);
|
|
91
|
-
return index;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
var import_unist_util_visit;
|
|
98
|
-
var init_remark_unravel = __esm({
|
|
99
|
-
"src/loaders/mdx/remark-unravel.ts"() {
|
|
100
|
-
"use strict";
|
|
101
|
-
import_unist_util_visit = require("unist-util-visit");
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// src/loaders/mdx/mdast-utils.ts
|
|
106
|
-
function flattenNode(node) {
|
|
107
|
-
if ("children" in node)
|
|
108
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
109
|
-
if ("value" in node) return node.value;
|
|
110
|
-
return "";
|
|
111
|
-
}
|
|
112
|
-
var init_mdast_utils = __esm({
|
|
113
|
-
"src/loaders/mdx/mdast-utils.ts"() {
|
|
114
|
-
"use strict";
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// src/loaders/mdx/remark-include.ts
|
|
119
|
-
function isElementLike(node) {
|
|
120
|
-
return ElementLikeTypes.includes(node.type);
|
|
121
|
-
}
|
|
122
|
-
function parseElementAttributes(element) {
|
|
123
|
-
if (Array.isArray(element.attributes)) {
|
|
124
|
-
const attributes = {};
|
|
125
|
-
for (const attr of element.attributes) {
|
|
126
|
-
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
127
|
-
attributes[attr.name] = attr.value;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return attributes;
|
|
131
|
-
}
|
|
132
|
-
return element.attributes ?? {};
|
|
133
|
-
}
|
|
134
|
-
function parseSpecifier(specifier) {
|
|
135
|
-
const idx = specifier.lastIndexOf("#");
|
|
136
|
-
if (idx === -1) return { file: specifier };
|
|
137
|
-
return {
|
|
138
|
-
file: specifier.slice(0, idx),
|
|
139
|
-
section: specifier.slice(idx + 1)
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function extractSection(root, section) {
|
|
143
|
-
let nodes;
|
|
144
|
-
let capturingHeadingContent = false;
|
|
145
|
-
(0, import_unist_util_visit2.visit)(root, (node) => {
|
|
146
|
-
if (node.type === "heading") {
|
|
147
|
-
if (capturingHeadingContent) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
if (node.data?.hProperties?.id === section) {
|
|
151
|
-
capturingHeadingContent = true;
|
|
152
|
-
nodes = [node];
|
|
153
|
-
return "skip";
|
|
154
|
-
}
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (capturingHeadingContent) {
|
|
158
|
-
nodes?.push(node);
|
|
159
|
-
return "skip";
|
|
160
|
-
}
|
|
161
|
-
if (isElementLike(node) && node.name === "section") {
|
|
162
|
-
const attributes = parseElementAttributes(node);
|
|
163
|
-
if (attributes.id === section) {
|
|
164
|
-
nodes = node.children;
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
if (nodes)
|
|
170
|
-
return {
|
|
171
|
-
type: "root",
|
|
172
|
-
children: nodes
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function remarkInclude() {
|
|
176
|
-
const TagName = "include";
|
|
177
|
-
const embedContent = async (file, heading, params, data) => {
|
|
178
|
-
let content;
|
|
179
|
-
try {
|
|
180
|
-
content = (await fs.readFile(file)).toString();
|
|
181
|
-
} catch (e) {
|
|
182
|
-
throw new Error(
|
|
183
|
-
`failed to read file ${file}
|
|
184
|
-
${e instanceof Error ? e.message : String(e)}`,
|
|
185
|
-
{ cause: e }
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
const ext = path.extname(file);
|
|
189
|
-
data._compiler?.addDependency(file);
|
|
190
|
-
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
191
|
-
const lang = params.lang ?? ext.slice(1);
|
|
192
|
-
return {
|
|
193
|
-
type: "code",
|
|
194
|
-
lang,
|
|
195
|
-
meta: params.meta,
|
|
196
|
-
value: content,
|
|
197
|
-
data: {}
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
|
|
201
|
-
const parsed = fumaMatter(content);
|
|
202
|
-
let mdast = parser.parse({
|
|
203
|
-
path: file,
|
|
204
|
-
value: parsed.content,
|
|
205
|
-
data: { frontmatter: parsed.data }
|
|
206
|
-
});
|
|
207
|
-
const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
|
|
208
|
-
if (heading) {
|
|
209
|
-
const extracted = extractSection(
|
|
210
|
-
await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
|
|
211
|
-
heading
|
|
212
|
-
);
|
|
213
|
-
if (!extracted)
|
|
214
|
-
throw new Error(
|
|
215
|
-
`Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
|
|
216
|
-
);
|
|
217
|
-
mdast = extracted;
|
|
218
|
-
} else {
|
|
219
|
-
mdast = await baseProcessor.run(mdast);
|
|
220
|
-
}
|
|
221
|
-
await update(mdast, path.dirname(file), data);
|
|
222
|
-
return mdast;
|
|
223
|
-
};
|
|
224
|
-
async function update(tree, directory, data) {
|
|
225
|
-
const queue = [];
|
|
226
|
-
(0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
227
|
-
const node = _node;
|
|
228
|
-
if (node.name !== TagName) return;
|
|
229
|
-
const specifier = flattenNode(node);
|
|
230
|
-
if (specifier.length === 0) return "skip";
|
|
231
|
-
const attributes = parseElementAttributes(node);
|
|
232
|
-
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
233
|
-
const file = path.resolve(
|
|
234
|
-
"cwd" in attributes ? process.cwd() : directory,
|
|
235
|
-
relativePath
|
|
236
|
-
);
|
|
237
|
-
queue.push(
|
|
238
|
-
embedContent(file, section, attributes, data).then((replace) => {
|
|
239
|
-
Object.assign(
|
|
240
|
-
parent && parent.type === "paragraph" ? parent : node,
|
|
241
|
-
replace
|
|
242
|
-
);
|
|
243
|
-
})
|
|
244
|
-
);
|
|
245
|
-
return "skip";
|
|
246
|
-
});
|
|
247
|
-
await Promise.all(queue);
|
|
248
|
-
}
|
|
249
|
-
return async (tree, file) => {
|
|
250
|
-
await update(tree, path.dirname(file.path), file.data);
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
var import_unified, import_unist_util_visit2, path, fs, import_mdx_plugins, ElementLikeTypes;
|
|
254
|
-
var init_remark_include = __esm({
|
|
255
|
-
"src/loaders/mdx/remark-include.ts"() {
|
|
256
|
-
"use strict";
|
|
257
|
-
import_unified = require("unified");
|
|
258
|
-
import_unist_util_visit2 = require("unist-util-visit");
|
|
259
|
-
path = __toESM(require("path"), 1);
|
|
260
|
-
fs = __toESM(require("fs/promises"), 1);
|
|
261
|
-
init_fuma_matter();
|
|
262
|
-
import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
263
|
-
init_remark_unravel();
|
|
264
|
-
init_mdast_utils();
|
|
265
|
-
ElementLikeTypes = [
|
|
266
|
-
"mdxJsxFlowElement",
|
|
267
|
-
"mdxJsxTextElement",
|
|
268
|
-
"containerDirective",
|
|
269
|
-
"textDirective",
|
|
270
|
-
"leafDirective"
|
|
271
|
-
];
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
// src/loaders/mdx/remark-postprocess.ts
|
|
276
|
-
function remarkPostprocess({
|
|
277
|
-
_format,
|
|
278
|
-
includeProcessedMarkdown = false,
|
|
279
|
-
includeMDAST = false,
|
|
280
|
-
extractLinkReferences = false,
|
|
281
|
-
valueToExport = []
|
|
282
|
-
}) {
|
|
283
|
-
let _stringifyProcessor;
|
|
284
|
-
const getStringifyProcessor = () => {
|
|
285
|
-
return _stringifyProcessor ??= _format === "mdx" ? this : (
|
|
286
|
-
// force Markdown processor to stringify MDX nodes
|
|
287
|
-
this().use(import_remark_mdx.default).freeze()
|
|
288
|
-
);
|
|
289
|
-
};
|
|
290
|
-
return (tree, file) => {
|
|
291
|
-
const frontmatter = file.data.frontmatter ??= {};
|
|
292
|
-
if (!frontmatter.title) {
|
|
293
|
-
(0, import_unist_util_visit3.visit)(tree, "heading", (node) => {
|
|
294
|
-
if (node.depth === 1) {
|
|
295
|
-
frontmatter.title = flattenNode(node);
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
file.data["mdx-export"] ??= [];
|
|
301
|
-
if (extractLinkReferences) {
|
|
302
|
-
const urls = [];
|
|
303
|
-
(0, import_unist_util_visit3.visit)(tree, "link", (node) => {
|
|
304
|
-
urls.push({
|
|
305
|
-
href: node.url
|
|
306
|
-
});
|
|
307
|
-
return "skip";
|
|
308
|
-
});
|
|
309
|
-
file.data["mdx-export"].push({
|
|
310
|
-
name: "extractedReferences",
|
|
311
|
-
value: urls
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
if (includeProcessedMarkdown) {
|
|
315
|
-
const processor = getStringifyProcessor();
|
|
316
|
-
const markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
|
|
317
|
-
...processor.data("settings"),
|
|
318
|
-
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
319
|
-
extensions: processor.data("toMarkdownExtensions") || []
|
|
320
|
-
});
|
|
321
|
-
file.data["mdx-export"].push({
|
|
322
|
-
name: "_markdown",
|
|
323
|
-
value: markdown
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
if (includeMDAST) {
|
|
327
|
-
const options = includeMDAST === true ? {} : includeMDAST;
|
|
328
|
-
const mdast = JSON.stringify(
|
|
329
|
-
options.removePosition ? (0, import_unist_util_remove_position.removePosition)(structuredClone(tree)) : tree
|
|
330
|
-
);
|
|
331
|
-
file.data["mdx-export"].push({
|
|
332
|
-
name: "_mdast",
|
|
333
|
-
value: mdast
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
for (const { name, value } of file.data["mdx-export"]) {
|
|
337
|
-
tree.children.unshift(getMdastExport(name, value));
|
|
338
|
-
}
|
|
339
|
-
file.data["mdx-export"] = [];
|
|
340
|
-
for (const name of valueToExport) {
|
|
341
|
-
if (!(name in file.data)) continue;
|
|
342
|
-
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
function getMdastExport(name, value) {
|
|
347
|
-
return {
|
|
348
|
-
type: "mdxjsEsm",
|
|
349
|
-
value: "",
|
|
350
|
-
data: {
|
|
351
|
-
estree: {
|
|
352
|
-
type: "Program",
|
|
353
|
-
sourceType: "module",
|
|
354
|
-
body: [
|
|
355
|
-
{
|
|
356
|
-
type: "ExportNamedDeclaration",
|
|
357
|
-
attributes: [],
|
|
358
|
-
specifiers: [],
|
|
359
|
-
source: null,
|
|
360
|
-
declaration: {
|
|
361
|
-
type: "VariableDeclaration",
|
|
362
|
-
kind: "let",
|
|
363
|
-
declarations: [
|
|
364
|
-
{
|
|
365
|
-
type: "VariableDeclarator",
|
|
366
|
-
id: {
|
|
367
|
-
type: "Identifier",
|
|
368
|
-
name
|
|
369
|
-
},
|
|
370
|
-
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
371
|
-
}
|
|
372
|
-
]
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
]
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
var import_unist_util_visit3, import_mdast_util_to_markdown, import_estree_util_value_to_estree, import_unist_util_remove_position, import_remark_mdx;
|
|
381
|
-
var init_remark_postprocess = __esm({
|
|
382
|
-
"src/loaders/mdx/remark-postprocess.ts"() {
|
|
383
|
-
"use strict";
|
|
384
|
-
import_unist_util_visit3 = require("unist-util-visit");
|
|
385
|
-
import_mdast_util_to_markdown = require("mdast-util-to-markdown");
|
|
386
|
-
import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
387
|
-
import_unist_util_remove_position = require("unist-util-remove-position");
|
|
388
|
-
import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
389
|
-
init_mdast_utils();
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
// src/loaders/mdx/build-mdx.ts
|
|
394
|
-
var build_mdx_exports = {};
|
|
395
|
-
__export(build_mdx_exports, {
|
|
396
|
-
buildMDX: () => buildMDX
|
|
397
|
-
});
|
|
398
|
-
async function buildMDX(core2, collection, {
|
|
399
|
-
filePath,
|
|
400
|
-
frontmatter,
|
|
401
|
-
source,
|
|
402
|
-
_compiler,
|
|
403
|
-
environment,
|
|
404
|
-
isDevelopment
|
|
405
|
-
}) {
|
|
406
|
-
const mdxOptions = await core2.getConfig().getMDXOptions(collection, environment);
|
|
407
|
-
function getProcessor(format) {
|
|
408
|
-
const cache = core2.cache;
|
|
409
|
-
const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
|
|
410
|
-
let processor = cache.get(key);
|
|
411
|
-
if (!processor) {
|
|
412
|
-
const postprocessOptions = {
|
|
413
|
-
_format: format,
|
|
414
|
-
...collection?.postprocess,
|
|
415
|
-
valueToExport: [
|
|
416
|
-
...collection?.postprocess?.valueToExport ?? [],
|
|
417
|
-
"structuredData",
|
|
418
|
-
"frontmatter"
|
|
419
|
-
]
|
|
420
|
-
};
|
|
421
|
-
processor = (0, import_mdx.createProcessor)({
|
|
422
|
-
outputFormat: "program",
|
|
423
|
-
development: isDevelopment,
|
|
424
|
-
...mdxOptions,
|
|
425
|
-
remarkPlugins: [
|
|
426
|
-
remarkInclude,
|
|
427
|
-
...mdxOptions.remarkPlugins ?? [],
|
|
428
|
-
[remarkPostprocess, postprocessOptions]
|
|
429
|
-
],
|
|
430
|
-
format
|
|
431
|
-
});
|
|
432
|
-
cache.set(key, processor);
|
|
433
|
-
}
|
|
434
|
-
return processor;
|
|
435
|
-
}
|
|
436
|
-
let vfile = new import_vfile.VFile({
|
|
437
|
-
value: source,
|
|
438
|
-
path: filePath,
|
|
439
|
-
data: { frontmatter, _compiler, _getProcessor: getProcessor }
|
|
440
|
-
});
|
|
441
|
-
if (collection) {
|
|
442
|
-
vfile = await core2.transformVFile({ collection, filePath, source }, vfile);
|
|
443
|
-
}
|
|
444
|
-
return getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md").process(vfile);
|
|
445
|
-
}
|
|
446
|
-
var import_mdx, import_vfile;
|
|
447
|
-
var init_build_mdx = __esm({
|
|
448
|
-
"src/loaders/mdx/build-mdx.ts"() {
|
|
449
|
-
"use strict";
|
|
450
|
-
import_mdx = require("@mdx-js/mdx");
|
|
451
|
-
import_vfile = require("vfile");
|
|
452
|
-
init_remark_include();
|
|
453
|
-
init_remark_postprocess();
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
// src/config/preset.ts
|
|
458
|
-
function pluginOption(def, options = []) {
|
|
459
|
-
const list = def(Array.isArray(options) ? options : []).filter(
|
|
460
|
-
Boolean
|
|
461
|
-
);
|
|
462
|
-
if (typeof options === "function") {
|
|
463
|
-
return options(list);
|
|
464
|
-
}
|
|
465
|
-
return list;
|
|
466
|
-
}
|
|
467
|
-
function applyMdxPreset(options = {}) {
|
|
468
|
-
return async (environment = "bundler") => {
|
|
469
|
-
if (options.preset === "minimal") return options;
|
|
470
|
-
const plugins = await import("fumadocs-core/mdx-plugins");
|
|
471
|
-
const {
|
|
472
|
-
valueToExport = [],
|
|
473
|
-
rehypeCodeOptions,
|
|
474
|
-
remarkImageOptions,
|
|
475
|
-
remarkHeadingOptions,
|
|
476
|
-
remarkStructureOptions,
|
|
477
|
-
remarkCodeTabOptions,
|
|
478
|
-
remarkNpmOptions,
|
|
479
|
-
...mdxOptions
|
|
480
|
-
} = options;
|
|
481
|
-
const remarkPlugins = pluginOption(
|
|
482
|
-
(v) => [
|
|
483
|
-
plugins.remarkGfm,
|
|
484
|
-
[
|
|
485
|
-
plugins.remarkHeading,
|
|
486
|
-
{
|
|
487
|
-
generateToc: false,
|
|
488
|
-
...remarkHeadingOptions
|
|
489
|
-
}
|
|
490
|
-
],
|
|
491
|
-
remarkImageOptions !== false && [
|
|
492
|
-
plugins.remarkImage,
|
|
493
|
-
{
|
|
494
|
-
...remarkImageOptions,
|
|
495
|
-
useImport: remarkImageOptions?.useImport ?? environment === "bundler"
|
|
496
|
-
}
|
|
497
|
-
],
|
|
498
|
-
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
499
|
-
plugins.remarkCodeTab,
|
|
500
|
-
remarkCodeTabOptions
|
|
501
|
-
],
|
|
502
|
-
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
503
|
-
...v,
|
|
504
|
-
remarkStructureOptions !== false && [
|
|
505
|
-
plugins.remarkStructure,
|
|
506
|
-
remarkStructureOptions
|
|
507
|
-
],
|
|
508
|
-
valueToExport.length > 0 && (() => {
|
|
509
|
-
return (_, file) => {
|
|
510
|
-
file.data["mdx-export"] ??= [];
|
|
511
|
-
for (const name of valueToExport) {
|
|
512
|
-
if (!(name in file.data)) continue;
|
|
513
|
-
file.data["mdx-export"].push({
|
|
514
|
-
name,
|
|
515
|
-
value: file.data[name]
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
})
|
|
520
|
-
],
|
|
521
|
-
mdxOptions.remarkPlugins
|
|
522
|
-
);
|
|
523
|
-
const rehypePlugins = pluginOption(
|
|
524
|
-
(v) => [
|
|
525
|
-
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
526
|
-
...v,
|
|
527
|
-
plugins.rehypeToc
|
|
528
|
-
],
|
|
529
|
-
mdxOptions.rehypePlugins
|
|
530
|
-
);
|
|
531
|
-
return {
|
|
532
|
-
...mdxOptions,
|
|
533
|
-
outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
|
|
534
|
-
remarkPlugins,
|
|
535
|
-
rehypePlugins
|
|
536
|
-
};
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
var init_preset = __esm({
|
|
540
|
-
"src/config/preset.ts"() {
|
|
541
|
-
"use strict";
|
|
542
|
-
}
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
// src/config/build.ts
|
|
546
|
-
function buildCollection(name, config) {
|
|
547
|
-
if (config.type === "docs") {
|
|
548
|
-
return {
|
|
549
|
-
...config,
|
|
550
|
-
name,
|
|
551
|
-
meta: buildPrimitiveCollection(name, config.meta),
|
|
552
|
-
docs: buildPrimitiveCollection(name, config.docs),
|
|
553
|
-
hasFile(filePath) {
|
|
554
|
-
return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
return buildPrimitiveCollection(name, config);
|
|
559
|
-
}
|
|
560
|
-
function buildPrimitiveCollection(name, { files, ...config }) {
|
|
561
|
-
const supportedFormats = SupportedFormats[config.type];
|
|
562
|
-
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
563
|
-
let matchers;
|
|
564
|
-
return {
|
|
565
|
-
...config,
|
|
566
|
-
name,
|
|
567
|
-
patterns,
|
|
568
|
-
isFileSupported(filePath) {
|
|
569
|
-
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
570
|
-
},
|
|
571
|
-
hasFile(filePath) {
|
|
572
|
-
matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
|
|
573
|
-
(dir) => (0, import_picomatch.default)(patterns, {
|
|
574
|
-
cwd: dir
|
|
575
|
-
})
|
|
576
|
-
);
|
|
577
|
-
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
function buildConfig(config) {
|
|
582
|
-
const collections = /* @__PURE__ */ new Map();
|
|
583
|
-
const loaded = {};
|
|
584
|
-
for (const [k, v] of Object.entries(config)) {
|
|
585
|
-
if (!v) {
|
|
586
|
-
continue;
|
|
587
|
-
}
|
|
588
|
-
if (typeof v === "object" && "type" in v) {
|
|
589
|
-
if (v.type === "docs") {
|
|
590
|
-
collections.set(k, buildCollection(k, v));
|
|
591
|
-
continue;
|
|
592
|
-
}
|
|
593
|
-
if (v.type === "doc" || v.type === "meta") {
|
|
594
|
-
collections.set(
|
|
595
|
-
k,
|
|
596
|
-
buildCollection(k, v)
|
|
597
|
-
);
|
|
598
|
-
continue;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
if (k === "default" && v) {
|
|
602
|
-
Object.assign(loaded, v);
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
throw new Error(
|
|
606
|
-
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
607
|
-
);
|
|
608
|
-
}
|
|
609
|
-
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
610
|
-
return {
|
|
611
|
-
global: loaded,
|
|
612
|
-
collectionList: Array.from(collections.values()),
|
|
613
|
-
getCollection(name) {
|
|
614
|
-
return collections.get(name);
|
|
615
|
-
},
|
|
616
|
-
getMDXOptions(collection, environment = "bundler") {
|
|
617
|
-
const key = collection ? `${environment}:${collection.name}` : environment;
|
|
618
|
-
const cached = mdxOptionsCache.get(key);
|
|
619
|
-
if (cached) return cached;
|
|
620
|
-
let result;
|
|
621
|
-
if (collection?.mdxOptions) {
|
|
622
|
-
const optionsFn = collection.mdxOptions;
|
|
623
|
-
result = typeof optionsFn === "function" ? optionsFn(environment) : optionsFn;
|
|
624
|
-
} else {
|
|
625
|
-
result = (async () => {
|
|
626
|
-
const optionsFn = this.global.mdxOptions;
|
|
627
|
-
const options = typeof optionsFn === "function" ? await optionsFn() : optionsFn;
|
|
628
|
-
return applyMdxPreset(options)(environment);
|
|
629
|
-
})();
|
|
630
|
-
}
|
|
631
|
-
mdxOptionsCache.set(key, result);
|
|
632
|
-
return result;
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
var import_picomatch, SupportedFormats;
|
|
637
|
-
var init_build = __esm({
|
|
638
|
-
"src/config/build.ts"() {
|
|
639
|
-
"use strict";
|
|
640
|
-
import_picomatch = __toESM(require("picomatch"), 1);
|
|
641
|
-
init_preset();
|
|
642
|
-
SupportedFormats = {
|
|
643
|
-
doc: ["mdx", "md"],
|
|
644
|
-
meta: ["json", "yaml"]
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
});
|
|
648
|
-
|
|
649
|
-
// src/config/load-from-file.ts
|
|
650
|
-
var load_from_file_exports = {};
|
|
651
|
-
__export(load_from_file_exports, {
|
|
652
|
-
loadConfig: () => loadConfig
|
|
653
|
-
});
|
|
654
|
-
async function compileConfig(core2) {
|
|
655
|
-
const { build } = await import("esbuild");
|
|
656
|
-
const transformed = await build({
|
|
657
|
-
entryPoints: [{ in: core2._options.configPath, out: "source.config" }],
|
|
658
|
-
bundle: true,
|
|
659
|
-
outdir: core2._options.outDir,
|
|
660
|
-
target: "node20",
|
|
661
|
-
write: true,
|
|
662
|
-
platform: "node",
|
|
663
|
-
format: "esm",
|
|
664
|
-
packages: "external",
|
|
665
|
-
outExtension: {
|
|
666
|
-
".js": ".mjs"
|
|
667
|
-
},
|
|
668
|
-
allowOverwrite: true
|
|
669
|
-
});
|
|
670
|
-
if (transformed.errors.length > 0) {
|
|
671
|
-
throw new Error("failed to compile configuration file");
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
async function loadConfig(core2, build = false) {
|
|
675
|
-
if (build) await compileConfig(core2);
|
|
676
|
-
const url = (0, import_node_url2.pathToFileURL)(core2.getCompiledConfigPath());
|
|
677
|
-
url.searchParams.set("hash", Date.now().toString());
|
|
678
|
-
const config = import(url.href).then(
|
|
679
|
-
(loaded) => buildConfig(loaded)
|
|
680
|
-
);
|
|
681
|
-
return await config;
|
|
682
|
-
}
|
|
683
|
-
var import_node_url2;
|
|
684
|
-
var init_load_from_file = __esm({
|
|
685
|
-
"src/config/load-from-file.ts"() {
|
|
686
|
-
"use strict";
|
|
687
|
-
import_node_url2 = require("url");
|
|
688
|
-
init_build();
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
// src/webpack/mdx.ts
|
|
693
|
-
var mdx_exports = {};
|
|
694
|
-
__export(mdx_exports, {
|
|
695
|
-
default: () => loader
|
|
696
|
-
});
|
|
697
|
-
module.exports = __toCommonJS(mdx_exports);
|
|
698
|
-
|
|
699
|
-
// src/loaders/mdx/index.ts
|
|
700
|
-
init_fuma_matter();
|
|
701
|
-
var import_zod = require("zod");
|
|
702
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
703
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
704
|
-
var import_node_crypto = require("crypto");
|
|
705
|
-
|
|
706
|
-
// src/loaders/index.ts
|
|
707
|
-
var mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
708
|
-
|
|
709
|
-
// src/loaders/mdx/index.ts
|
|
710
|
-
var querySchema = import_zod.z.object({
|
|
711
|
-
only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
|
|
712
|
-
collection: import_zod.z.string().optional()
|
|
713
|
-
}).loose();
|
|
714
|
-
var cacheEntry = import_zod.z.object({
|
|
715
|
-
code: import_zod.z.string(),
|
|
716
|
-
map: import_zod.z.any().optional(),
|
|
717
|
-
hash: import_zod.z.string().optional()
|
|
718
|
-
});
|
|
719
|
-
function createMdxLoader(configLoader) {
|
|
720
|
-
return {
|
|
721
|
-
test: mdxLoaderGlob,
|
|
722
|
-
async load({
|
|
723
|
-
getSource,
|
|
724
|
-
development: isDevelopment,
|
|
725
|
-
query,
|
|
726
|
-
compiler,
|
|
727
|
-
filePath
|
|
728
|
-
}) {
|
|
729
|
-
const config = await configLoader.getConfig();
|
|
730
|
-
const value = await getSource();
|
|
731
|
-
const matter = fumaMatter(value);
|
|
732
|
-
const parsed = querySchema.parse(query);
|
|
733
|
-
let after;
|
|
734
|
-
if (!isDevelopment && config.global.experimentalBuildCache) {
|
|
735
|
-
const cacheDir = config.global.experimentalBuildCache;
|
|
736
|
-
const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
|
|
737
|
-
const cached = await import_promises.default.readFile(import_node_path.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
|
|
738
|
-
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
739
|
-
after = async () => {
|
|
740
|
-
await import_promises.default.mkdir(cacheDir, { recursive: true });
|
|
741
|
-
await import_promises.default.writeFile(
|
|
742
|
-
import_node_path.default.join(cacheDir, cacheKey),
|
|
743
|
-
JSON.stringify({
|
|
744
|
-
...out,
|
|
745
|
-
hash: generateCacheHash(value)
|
|
746
|
-
})
|
|
747
|
-
);
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
const collection = parsed.collection ? config.getCollection(parsed.collection) : void 0;
|
|
751
|
-
let docCollection;
|
|
752
|
-
switch (collection?.type) {
|
|
753
|
-
case "doc":
|
|
754
|
-
docCollection = collection;
|
|
755
|
-
break;
|
|
756
|
-
case "docs":
|
|
757
|
-
docCollection = collection.docs;
|
|
758
|
-
break;
|
|
759
|
-
}
|
|
760
|
-
if (docCollection) {
|
|
761
|
-
matter.data = await configLoader.core.transformFrontmatter(
|
|
762
|
-
{ collection: docCollection, filePath, source: value },
|
|
763
|
-
matter.data
|
|
764
|
-
);
|
|
765
|
-
}
|
|
766
|
-
if (parsed.only === "frontmatter") {
|
|
767
|
-
return {
|
|
768
|
-
code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
|
|
769
|
-
map: null
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
773
|
-
const { buildMDX: buildMDX2 } = await Promise.resolve().then(() => (init_build_mdx(), build_mdx_exports));
|
|
774
|
-
const compiled = await buildMDX2(configLoader.core, docCollection, {
|
|
775
|
-
isDevelopment,
|
|
776
|
-
source: "\n".repeat(lineOffset) + matter.content,
|
|
777
|
-
filePath,
|
|
778
|
-
frontmatter: matter.data,
|
|
779
|
-
_compiler: compiler,
|
|
780
|
-
environment: "bundler"
|
|
781
|
-
});
|
|
782
|
-
const out = {
|
|
783
|
-
code: String(compiled.value),
|
|
784
|
-
map: compiled.map
|
|
785
|
-
};
|
|
786
|
-
await after?.();
|
|
787
|
-
return out;
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
function generateCacheHash(input) {
|
|
792
|
-
return (0, import_node_crypto.createHash)("md5").update(input).digest("hex");
|
|
793
|
-
}
|
|
794
|
-
function countLines(s) {
|
|
795
|
-
let num = 0;
|
|
796
|
-
for (const c of s) {
|
|
797
|
-
if (c === "\n") num++;
|
|
798
|
-
}
|
|
799
|
-
return num;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
// src/loaders/adapter.ts
|
|
803
|
-
var import_node_url = require("url");
|
|
804
|
-
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
805
|
-
var import_node_querystring = require("querystring");
|
|
806
|
-
|
|
807
|
-
// src/utils/validation.ts
|
|
808
|
-
var ValidationError = class extends Error {
|
|
809
|
-
constructor(message, issues) {
|
|
810
|
-
super(
|
|
811
|
-
`${message}:
|
|
812
|
-
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
|
|
813
|
-
);
|
|
814
|
-
this.title = message;
|
|
815
|
-
this.issues = issues;
|
|
816
|
-
}
|
|
817
|
-
async toStringFormatted() {
|
|
818
|
-
const picocolors = await import("picocolors");
|
|
819
|
-
return [
|
|
820
|
-
picocolors.bold(`[MDX] ${this.title}:`),
|
|
821
|
-
...this.issues.map(
|
|
822
|
-
(issue) => picocolors.redBright(
|
|
823
|
-
`- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
|
|
824
|
-
)
|
|
825
|
-
)
|
|
826
|
-
].join("\n");
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
async function validate(schema, data, context, errorMessage) {
|
|
830
|
-
if (typeof schema === "function" && !("~standard" in schema)) {
|
|
831
|
-
schema = schema(context);
|
|
832
|
-
}
|
|
833
|
-
if ("~standard" in schema) {
|
|
834
|
-
const result = await schema["~standard"].validate(
|
|
835
|
-
data
|
|
836
|
-
);
|
|
837
|
-
if (result.issues) {
|
|
838
|
-
throw new ValidationError(errorMessage, result.issues);
|
|
839
|
-
}
|
|
840
|
-
return result.value;
|
|
841
|
-
}
|
|
842
|
-
return data;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
// src/loaders/adapter.ts
|
|
846
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
847
|
-
var import_node_fs = require("fs");
|
|
848
|
-
function toWebpack(loader2) {
|
|
849
|
-
return async function(source, callback) {
|
|
850
|
-
try {
|
|
851
|
-
const result = await loader2.load({
|
|
852
|
-
filePath: this.resourcePath,
|
|
853
|
-
query: (0, import_node_querystring.parse)(this.resourceQuery.slice(1)),
|
|
854
|
-
getSource() {
|
|
855
|
-
return source;
|
|
856
|
-
},
|
|
857
|
-
development: this.mode === "development",
|
|
858
|
-
compiler: this
|
|
859
|
-
});
|
|
860
|
-
if (result === null) {
|
|
861
|
-
callback(void 0, source);
|
|
862
|
-
} else {
|
|
863
|
-
callback(void 0, result.code, result.map);
|
|
864
|
-
}
|
|
865
|
-
} catch (error) {
|
|
866
|
-
if (error instanceof ValidationError) {
|
|
867
|
-
return callback(new Error(await error.toStringFormatted()));
|
|
868
|
-
}
|
|
869
|
-
if (!(error instanceof Error)) throw error;
|
|
870
|
-
const fpath = import_node_path2.default.relative(this.context, this.resourcePath);
|
|
871
|
-
error.message = `${fpath}:${error.name}: ${error.message}`;
|
|
872
|
-
callback(error);
|
|
873
|
-
}
|
|
874
|
-
};
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
// src/loaders/config.ts
|
|
878
|
-
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
879
|
-
function createStandaloneConfigLoader({
|
|
880
|
-
core: core2,
|
|
881
|
-
buildConfig: buildConfig2,
|
|
882
|
-
mode
|
|
883
|
-
}) {
|
|
884
|
-
let loaded;
|
|
885
|
-
async function getConfigHash() {
|
|
886
|
-
if (mode === "production") return "static";
|
|
887
|
-
const stats = await import_promises3.default.stat(core2._options.configPath).catch(() => {
|
|
888
|
-
throw new Error("Cannot find config file");
|
|
889
|
-
});
|
|
890
|
-
return stats.mtime.getTime().toString();
|
|
891
|
-
}
|
|
892
|
-
async function newConfig() {
|
|
893
|
-
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load_from_file(), load_from_file_exports));
|
|
894
|
-
await core2.init({
|
|
895
|
-
config: loadConfig2(core2, buildConfig2)
|
|
896
|
-
});
|
|
897
|
-
return core2.getConfig();
|
|
898
|
-
}
|
|
899
|
-
return {
|
|
900
|
-
core: core2,
|
|
901
|
-
async getConfig() {
|
|
902
|
-
const hash = await getConfigHash();
|
|
903
|
-
if (loaded && loaded.hash === hash) return loaded.config;
|
|
904
|
-
loaded = {
|
|
905
|
-
hash,
|
|
906
|
-
config: newConfig()
|
|
907
|
-
};
|
|
908
|
-
return loaded.config;
|
|
909
|
-
}
|
|
910
|
-
};
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
// src/core.ts
|
|
914
|
-
var import_node_path4 = __toESM(require("path"), 1);
|
|
915
|
-
var import_promises5 = __toESM(require("fs/promises"), 1);
|
|
916
|
-
|
|
917
|
-
// src/utils/codegen/cache.ts
|
|
918
|
-
var import_lru_cache = require("lru-cache");
|
|
919
|
-
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
920
|
-
var import_node_path3 = __toESM(require("path"), 1);
|
|
921
|
-
var map = new import_lru_cache.LRUCache({
|
|
922
|
-
max: 100
|
|
923
|
-
});
|
|
924
|
-
function toFullPath(file) {
|
|
925
|
-
if (import_node_path3.default.isAbsolute(file)) {
|
|
926
|
-
return import_node_path3.default.relative(process.cwd(), file);
|
|
927
|
-
}
|
|
928
|
-
return file;
|
|
929
|
-
}
|
|
930
|
-
function removeFileCache(file) {
|
|
931
|
-
map.delete(toFullPath(file));
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
// src/core.ts
|
|
935
|
-
async function getPlugins(pluginOptions) {
|
|
936
|
-
const plugins = [];
|
|
937
|
-
for await (const option of pluginOptions) {
|
|
938
|
-
if (!option) continue;
|
|
939
|
-
if (Array.isArray(option)) plugins.push(...await getPlugins(option));
|
|
940
|
-
else plugins.push(option);
|
|
941
|
-
}
|
|
942
|
-
return plugins;
|
|
943
|
-
}
|
|
944
|
-
function createCore(options, defaultPlugins = []) {
|
|
945
|
-
let config;
|
|
946
|
-
let plugins;
|
|
947
|
-
async function transformMetadata({
|
|
948
|
-
collection,
|
|
949
|
-
filePath,
|
|
950
|
-
source
|
|
951
|
-
}, data) {
|
|
952
|
-
if (collection.schema) {
|
|
953
|
-
data = await validate(
|
|
954
|
-
collection.schema,
|
|
955
|
-
data,
|
|
956
|
-
{ path: filePath, source },
|
|
957
|
-
collection.type === "doc" ? `invalid frontmatter in ${filePath}` : `invalid data in ${filePath}`
|
|
958
|
-
);
|
|
959
|
-
}
|
|
960
|
-
return data;
|
|
961
|
-
}
|
|
962
|
-
const core2 = {
|
|
963
|
-
_options: options,
|
|
964
|
-
/**
|
|
965
|
-
* Convenient cache store, reset when config changes
|
|
966
|
-
*/
|
|
967
|
-
cache: /* @__PURE__ */ new Map(),
|
|
968
|
-
async init({ config: newConfig }) {
|
|
969
|
-
config = await newConfig;
|
|
970
|
-
this.cache.clear();
|
|
971
|
-
plugins = await getPlugins([
|
|
972
|
-
...defaultPlugins,
|
|
973
|
-
...config.global.plugins ?? []
|
|
974
|
-
]);
|
|
975
|
-
for (const plugin of plugins) {
|
|
976
|
-
const out = await plugin.config?.call(pluginContext, config);
|
|
977
|
-
if (out) config = out;
|
|
978
|
-
}
|
|
979
|
-
return this;
|
|
980
|
-
},
|
|
981
|
-
getConfig() {
|
|
982
|
-
return config;
|
|
983
|
-
},
|
|
984
|
-
/**
|
|
985
|
-
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
986
|
-
*/
|
|
987
|
-
getCompiledConfigPath() {
|
|
988
|
-
return import_node_path4.default.join(options.outDir, "source.config.mjs");
|
|
989
|
-
},
|
|
990
|
-
async initServer(server) {
|
|
991
|
-
server.watcher?.on("all", async (event, file) => {
|
|
992
|
-
if (event === "change") removeFileCache(file);
|
|
993
|
-
});
|
|
994
|
-
for (const plugin of plugins) {
|
|
995
|
-
await plugin.configureServer?.call(pluginContext, server);
|
|
996
|
-
}
|
|
997
|
-
},
|
|
998
|
-
async emit({ filterPlugin = () => true } = {}) {
|
|
999
|
-
return (await Promise.all(
|
|
1000
|
-
plugins.map((plugin) => {
|
|
1001
|
-
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
1002
|
-
return plugin.emit.call(pluginContext);
|
|
1003
|
-
})
|
|
1004
|
-
)).flat();
|
|
1005
|
-
},
|
|
1006
|
-
async emitAndWrite(emitOptions) {
|
|
1007
|
-
const start = performance.now();
|
|
1008
|
-
const out = await this.emit(emitOptions);
|
|
1009
|
-
await Promise.all(
|
|
1010
|
-
out.map(async (entry) => {
|
|
1011
|
-
const file = import_node_path4.default.join(options.outDir, entry.path);
|
|
1012
|
-
await import_promises5.default.mkdir(import_node_path4.default.dirname(file), { recursive: true });
|
|
1013
|
-
await import_promises5.default.writeFile(file, entry.content);
|
|
1014
|
-
})
|
|
1015
|
-
);
|
|
1016
|
-
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
1017
|
-
},
|
|
1018
|
-
async transformMeta(options2, data) {
|
|
1019
|
-
const ctx = {
|
|
1020
|
-
...pluginContext,
|
|
1021
|
-
...options2
|
|
1022
|
-
};
|
|
1023
|
-
data = await transformMetadata(options2, data);
|
|
1024
|
-
for (const plugin of plugins) {
|
|
1025
|
-
if (plugin.meta?.transform)
|
|
1026
|
-
data = await plugin.meta.transform.call(ctx, data) ?? data;
|
|
1027
|
-
}
|
|
1028
|
-
return data;
|
|
1029
|
-
},
|
|
1030
|
-
async transformFrontmatter(options2, data) {
|
|
1031
|
-
const ctx = {
|
|
1032
|
-
...pluginContext,
|
|
1033
|
-
...options2
|
|
1034
|
-
};
|
|
1035
|
-
data = await transformMetadata(options2, data);
|
|
1036
|
-
for (const plugin of plugins) {
|
|
1037
|
-
if (plugin.doc?.frontmatter)
|
|
1038
|
-
data = await plugin.doc.frontmatter.call(ctx, data) ?? data;
|
|
1039
|
-
}
|
|
1040
|
-
return data;
|
|
1041
|
-
},
|
|
1042
|
-
async transformVFile(options2, file) {
|
|
1043
|
-
const ctx = {
|
|
1044
|
-
...pluginContext,
|
|
1045
|
-
...options2
|
|
1046
|
-
};
|
|
1047
|
-
for (const plugin of plugins) {
|
|
1048
|
-
if (plugin.doc?.vfile)
|
|
1049
|
-
file = await plugin.doc.vfile.call(ctx, file) ?? file;
|
|
1050
|
-
}
|
|
1051
|
-
return file;
|
|
1052
|
-
}
|
|
1053
|
-
};
|
|
1054
|
-
const pluginContext = {
|
|
1055
|
-
core: core2,
|
|
1056
|
-
...options
|
|
1057
|
-
};
|
|
1058
|
-
return core2;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
// src/webpack/index.ts
|
|
1062
|
-
var core;
|
|
1063
|
-
function getCore(options) {
|
|
1064
|
-
return core ??= createCore({
|
|
1065
|
-
environment: "webpack",
|
|
1066
|
-
outDir: options.outDir,
|
|
1067
|
-
configPath: options.configPath
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
// src/webpack/mdx.ts
|
|
1072
|
-
var instance;
|
|
1073
|
-
async function loader(source, callback) {
|
|
1074
|
-
const options = this.getOptions();
|
|
1075
|
-
this.cacheable(true);
|
|
1076
|
-
this.addDependency(options.compiledConfigPath);
|
|
1077
|
-
if (!instance) {
|
|
1078
|
-
instance = toWebpack(
|
|
1079
|
-
createMdxLoader(
|
|
1080
|
-
createStandaloneConfigLoader({
|
|
1081
|
-
core: getCore(options),
|
|
1082
|
-
buildConfig: false,
|
|
1083
|
-
mode: options.isDev ? "dev" : "production"
|
|
1084
|
-
})
|
|
1085
|
-
)
|
|
1086
|
-
);
|
|
1087
|
-
}
|
|
1088
|
-
await instance.call(this, source, callback);
|
|
1089
|
-
}
|