fumadocs-mdx 14.2.3 → 14.2.5
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/adapter-DI4cexsC.js +145 -0
- package/dist/adapter-DI4cexsC.js.map +1 -0
- package/dist/bin.d.ts +1 -1
- package/dist/bin.js +21 -12
- package/dist/bin.js.map +1 -0
- package/dist/build-BTTNEFmV.js +100 -0
- package/dist/build-BTTNEFmV.js.map +1 -0
- package/dist/build-mdx-10MrLupc.d.ts +53 -0
- package/dist/build-mdx-10MrLupc.d.ts.map +1 -0
- package/dist/build-mdx-BVeBo4jT.js +153 -0
- package/dist/build-mdx-BVeBo4jT.js.map +1 -0
- package/dist/build-mdx-ChjP7zAn.js +5 -0
- package/dist/bun/index.d.ts +10 -21
- package/dist/bun/index.d.ts.map +1 -0
- package/dist/bun/index.js +30 -49
- package/dist/bun/index.js.map +1 -0
- package/dist/codegen-DleOVLNr.js +101 -0
- package/dist/codegen-DleOVLNr.js.map +1 -0
- package/dist/config/index.d.ts +2 -18
- package/dist/config/index.js +50 -53
- package/dist/config/index.js.map +1 -0
- package/dist/core-DG43f_AU.d.ts +364 -0
- package/dist/core-DG43f_AU.d.ts.map +1 -0
- package/dist/core-DjldE3H9.js +212 -0
- package/dist/core-DjldE3H9.js.map +1 -0
- package/dist/fuma-matter-CHgJa_-B.js +27 -0
- package/dist/fuma-matter-CHgJa_-B.js.map +1 -0
- package/dist/index-Bc_4I1HE.d.ts +12 -0
- package/dist/index-Bc_4I1HE.d.ts.map +1 -0
- package/dist/index-file-D9HsrWU_.js +264 -0
- package/dist/index-file-D9HsrWU_.js.map +1 -0
- package/dist/index.d.ts +3 -61
- package/dist/index.js +1 -0
- package/dist/load-from-file-B7Rswy9i.js +5 -0
- package/dist/load-from-file-Doc98oEB.js +38 -0
- package/dist/load-from-file-Doc98oEB.js.map +1 -0
- package/dist/loaders-BVwYfelL.js +7 -0
- package/dist/loaders-BVwYfelL.js.map +1 -0
- package/dist/mdx-CRT-jSh5.js +91 -0
- package/dist/mdx-CRT-jSh5.js.map +1 -0
- package/dist/meta-BKBx8Gab.js +81 -0
- package/dist/meta-BKBx8Gab.js.map +1 -0
- package/dist/next/index.cjs +863 -1076
- package/dist/next/index.d.ts +17 -28
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +141 -170
- package/dist/next/index.js.map +1 -0
- package/dist/node/loader.d.ts +4 -2
- package/dist/node/loader.d.ts.map +1 -0
- package/dist/node/loader.js +26 -38
- package/dist/node/loader.js.map +1 -0
- package/dist/plugins/index-file.d.ts +2 -14
- package/dist/plugins/index-file.js +5 -8
- package/dist/plugins/json-schema.d.ts +14 -23
- package/dist/plugins/json-schema.d.ts.map +1 -0
- package/dist/plugins/json-schema.js +70 -78
- package/dist/plugins/json-schema.js.map +1 -0
- package/dist/plugins/last-modified.d.ts +21 -32
- package/dist/plugins/last-modified.d.ts.map +1 -0
- package/dist/plugins/last-modified.js +70 -78
- package/dist/plugins/last-modified.js.map +1 -0
- package/dist/preset-gmDZnBcg.js +61 -0
- package/dist/preset-gmDZnBcg.js.map +1 -0
- package/dist/remark-include-D3G3mAnv.js +247 -0
- package/dist/remark-include-D3G3mAnv.js.map +1 -0
- package/dist/runtime/browser.d.ts +33 -42
- package/dist/runtime/browser.d.ts.map +1 -0
- package/dist/runtime/browser.js +54 -63
- package/dist/runtime/browser.js.map +1 -0
- package/dist/runtime/dynamic.d.ts +13 -21
- package/dist/runtime/dynamic.d.ts.map +1 -0
- package/dist/runtime/dynamic.js +64 -76
- package/dist/runtime/dynamic.js.map +1 -0
- package/dist/runtime/server.d.ts +2 -14
- package/dist/runtime/server.js +111 -8
- package/dist/runtime/server.js.map +1 -0
- package/dist/runtime/types.d.ts +2 -61
- package/dist/runtime/types.js +1 -0
- package/dist/types-B6myALSk.d.ts +63 -0
- package/dist/types-B6myALSk.d.ts.map +1 -0
- package/dist/vite/index.d.ts +28 -39
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +79 -122
- package/dist/vite/index.js.map +1 -0
- package/dist/webpack/mdx.d.ts +6 -3
- package/dist/webpack/mdx.d.ts.map +1 -0
- package/dist/webpack/mdx.js +21 -34
- package/dist/webpack/mdx.js.map +1 -0
- package/dist/webpack/meta.d.ts +6 -3
- package/dist/webpack/meta.d.ts.map +1 -0
- package/dist/webpack/meta.js +23 -37
- package/dist/webpack/meta.js.map +1 -0
- package/dist/webpack--VSEE6Zp.js +15 -0
- package/dist/webpack--VSEE6Zp.js.map +1 -0
- package/loader-mdx.cjs +1 -3
- package/loader-meta.cjs +1 -3
- package/package.json +40 -40
- package/dist/build-mdx-5XLFMP5P.js +0 -8
- package/dist/chunk-257RZJEQ.js +0 -17
- package/dist/chunk-2PY3JUIC.js +0 -126
- package/dist/chunk-4EUH5CD2.js +0 -173
- package/dist/chunk-4JSFLXXT.js +0 -8
- package/dist/chunk-5OBUOALK.js +0 -141
- package/dist/chunk-DTFUANSF.js +0 -40
- package/dist/chunk-KWSETXYC.js +0 -274
- package/dist/chunk-OLD35ARB.js +0 -116
- package/dist/chunk-RSASAHLX.js +0 -91
- package/dist/chunk-S7KOJHHO.js +0 -89
- package/dist/chunk-STLEUNK7.js +0 -335
- package/dist/chunk-USQZ5OLE.js +0 -116
- package/dist/chunk-VWJKRQZR.js +0 -19
- package/dist/chunk-WFDF56IJ.js +0 -290
- package/dist/chunk-XYVVDDIF.js +0 -180
- package/dist/core-X5ggQtBM.d.ts +0 -350
- package/dist/index-BqkSNsGO.d.ts +0 -8
- package/dist/load-from-file-FHW724YY.js +0 -8
package/dist/chunk-WFDF56IJ.js
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fumaMatter
|
|
3
|
-
} from "./chunk-VWJKRQZR.js";
|
|
4
|
-
|
|
5
|
-
// src/loaders/mdx/remark-include.ts
|
|
6
|
-
import { unified } from "unified";
|
|
7
|
-
import { visit as visit2 } from "unist-util-visit";
|
|
8
|
-
import * as path from "path";
|
|
9
|
-
import * as fs from "fs/promises";
|
|
10
|
-
import { remarkHeading } from "fumadocs-core/mdx-plugins";
|
|
11
|
-
import { VFile } from "vfile";
|
|
12
|
-
|
|
13
|
-
// src/loaders/mdx/remark-unravel.ts
|
|
14
|
-
import { visit } from "unist-util-visit";
|
|
15
|
-
function remarkMarkAndUnravel() {
|
|
16
|
-
return (tree) => {
|
|
17
|
-
visit(tree, function(node, index, parent) {
|
|
18
|
-
let offset = -1;
|
|
19
|
-
let all = true;
|
|
20
|
-
let oneOrMore = false;
|
|
21
|
-
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
22
|
-
const children = node.children;
|
|
23
|
-
while (++offset < children.length) {
|
|
24
|
-
const child = children[offset];
|
|
25
|
-
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
|
|
26
|
-
oneOrMore = true;
|
|
27
|
-
} else if (child.type === "text" && child.value.trim().length === 0) {
|
|
28
|
-
} else {
|
|
29
|
-
all = false;
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (all && oneOrMore) {
|
|
34
|
-
offset = -1;
|
|
35
|
-
const newChildren = [];
|
|
36
|
-
while (++offset < children.length) {
|
|
37
|
-
const child = children[offset];
|
|
38
|
-
if (child.type === "mdxJsxTextElement") {
|
|
39
|
-
child.type = "mdxJsxFlowElement";
|
|
40
|
-
}
|
|
41
|
-
if (child.type === "mdxTextExpression") {
|
|
42
|
-
child.type = "mdxFlowExpression";
|
|
43
|
-
}
|
|
44
|
-
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
|
|
45
|
-
} else {
|
|
46
|
-
newChildren.push(child);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
parent.children.splice(index, 1, ...newChildren);
|
|
50
|
-
return index;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/loaders/mdx/mdast-utils.ts
|
|
58
|
-
function flattenNode(node) {
|
|
59
|
-
if ("children" in node)
|
|
60
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
61
|
-
if ("value" in node) return node.value;
|
|
62
|
-
return "";
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/loaders/mdx/remark-include.ts
|
|
66
|
-
var REGION_MARKERS = [
|
|
67
|
-
{
|
|
68
|
-
start: /^\s*\/\/\s*#?region\b\s*(.*?)\s*$/,
|
|
69
|
-
end: /^\s*\/\/\s*#?endregion\b\s*(.*?)\s*$/
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
start: /^\s*<!--\s*#?region\b\s*(.*?)\s*-->/,
|
|
73
|
-
end: /^\s*<!--\s*#?endregion\b\s*(.*?)\s*-->/
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
start: /^\s*\/\*\s*#region\b\s*(.*?)\s*\*\//,
|
|
77
|
-
end: /^\s*\/\*\s*#endregion\b\s*(.*?)\s*\*\//
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
start: /^\s*#[rR]egion\b\s*(.*?)\s*$/,
|
|
81
|
-
end: /^\s*#[eE]nd ?[rR]egion\b\s*(.*?)\s*$/
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
start: /^\s*#\s*#?region\b\s*(.*?)\s*$/,
|
|
85
|
-
end: /^\s*#\s*#?endregion\b\s*(.*?)\s*$/
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
start: /^\s*(?:--|::|@?REM)\s*#region\b\s*(.*?)\s*$/,
|
|
89
|
-
end: /^\s*(?:--|::|@?REM)\s*#endregion\b\s*(.*?)\s*$/
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
start: /^\s*#pragma\s+region\b\s*(.*?)\s*$/,
|
|
93
|
-
end: /^\s*#pragma\s+endregion\b\s*(.*?)\s*$/
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
start: /^\s*\(\*\s*#region\b\s*(.*?)\s*\*\)/,
|
|
97
|
-
end: /^\s*\(\*\s*#endregion\b\s*(.*?)\s*\*\)/
|
|
98
|
-
}
|
|
99
|
-
];
|
|
100
|
-
function dedent(lines) {
|
|
101
|
-
const minIndent = lines.reduce((min, line) => {
|
|
102
|
-
const match = line.match(/^(\s*)\S/);
|
|
103
|
-
return match ? Math.min(min, match[1].length) : min;
|
|
104
|
-
}, Infinity);
|
|
105
|
-
return minIndent === Infinity ? lines.join("\n") : lines.map((l) => l.slice(minIndent)).join("\n");
|
|
106
|
-
}
|
|
107
|
-
function extractCodeRegion(content, regionName) {
|
|
108
|
-
const lines = content.split("\n");
|
|
109
|
-
for (let i = 0; i < lines.length; i++) {
|
|
110
|
-
for (const re of REGION_MARKERS) {
|
|
111
|
-
let match = re.start.exec(lines[i]);
|
|
112
|
-
if (match?.[1] !== regionName) continue;
|
|
113
|
-
let depth = 1;
|
|
114
|
-
const extractedLines = [];
|
|
115
|
-
for (let j = i + 1; j < lines.length; j++) {
|
|
116
|
-
match = re.start.exec(lines[j]);
|
|
117
|
-
if (match) {
|
|
118
|
-
depth++;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
match = re.end.exec(lines[j]);
|
|
122
|
-
if (match) {
|
|
123
|
-
if (match[1] === regionName) depth = 0;
|
|
124
|
-
else if (match[1] === "") depth--;
|
|
125
|
-
else continue;
|
|
126
|
-
if (depth > 0) continue;
|
|
127
|
-
return dedent(extractedLines);
|
|
128
|
-
} else {
|
|
129
|
-
extractedLines.push(lines[j]);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
throw new Error(`Region "${regionName}" not found`);
|
|
135
|
-
}
|
|
136
|
-
var ElementLikeTypes = [
|
|
137
|
-
"mdxJsxFlowElement",
|
|
138
|
-
"mdxJsxTextElement",
|
|
139
|
-
"containerDirective",
|
|
140
|
-
"textDirective",
|
|
141
|
-
"leafDirective"
|
|
142
|
-
];
|
|
143
|
-
function isElementLike(node) {
|
|
144
|
-
return ElementLikeTypes.includes(node.type);
|
|
145
|
-
}
|
|
146
|
-
function parseElementAttributes(element) {
|
|
147
|
-
if (Array.isArray(element.attributes)) {
|
|
148
|
-
const attributes = {};
|
|
149
|
-
for (const attr of element.attributes) {
|
|
150
|
-
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
151
|
-
attributes[attr.name] = attr.value;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return attributes;
|
|
155
|
-
}
|
|
156
|
-
return element.attributes ?? {};
|
|
157
|
-
}
|
|
158
|
-
function parseSpecifier(specifier) {
|
|
159
|
-
const idx = specifier.lastIndexOf("#");
|
|
160
|
-
if (idx === -1) return { file: specifier };
|
|
161
|
-
return {
|
|
162
|
-
file: specifier.slice(0, idx),
|
|
163
|
-
section: specifier.slice(idx + 1)
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
function extractSection(root, section) {
|
|
167
|
-
let nodes;
|
|
168
|
-
let capturingHeadingContent = false;
|
|
169
|
-
visit2(root, (node) => {
|
|
170
|
-
if (node.type === "heading") {
|
|
171
|
-
if (capturingHeadingContent) {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
if (node.data?.hProperties?.id === section) {
|
|
175
|
-
capturingHeadingContent = true;
|
|
176
|
-
nodes = [node];
|
|
177
|
-
return "skip";
|
|
178
|
-
}
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (capturingHeadingContent) {
|
|
182
|
-
nodes?.push(node);
|
|
183
|
-
return "skip";
|
|
184
|
-
}
|
|
185
|
-
if (isElementLike(node) && node.name === "section") {
|
|
186
|
-
const attributes = parseElementAttributes(node);
|
|
187
|
-
if (attributes.id === section) {
|
|
188
|
-
nodes = node.children;
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
if (nodes)
|
|
194
|
-
return {
|
|
195
|
-
type: "root",
|
|
196
|
-
children: nodes
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
function remarkInclude() {
|
|
200
|
-
const TagName = "include";
|
|
201
|
-
const embedContent = async (targetPath, heading, params, parent) => {
|
|
202
|
-
const { _getProcessor = () => this, _compiler } = parent.data;
|
|
203
|
-
let content;
|
|
204
|
-
try {
|
|
205
|
-
content = (await fs.readFile(targetPath)).toString();
|
|
206
|
-
} catch (e) {
|
|
207
|
-
throw new Error(
|
|
208
|
-
`failed to read file ${targetPath}
|
|
209
|
-
${e instanceof Error ? e.message : String(e)}`,
|
|
210
|
-
{ cause: e }
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
const ext = path.extname(targetPath);
|
|
214
|
-
_compiler?.addDependency(targetPath);
|
|
215
|
-
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
216
|
-
const lang = params.lang ?? ext.slice(1);
|
|
217
|
-
let value = content;
|
|
218
|
-
if (heading) {
|
|
219
|
-
value = extractCodeRegion(content, heading.trim());
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
type: "code",
|
|
223
|
-
lang,
|
|
224
|
-
meta: params.meta,
|
|
225
|
-
value,
|
|
226
|
-
data: {}
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
const parser = _getProcessor(ext === ".mdx" ? "mdx" : "md");
|
|
230
|
-
const parsed = fumaMatter(content);
|
|
231
|
-
const targetFile = new VFile({
|
|
232
|
-
path: targetPath,
|
|
233
|
-
value: parsed.content,
|
|
234
|
-
data: {
|
|
235
|
-
...parent.data,
|
|
236
|
-
frontmatter: parsed.data
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
let mdast = parser.parse(targetFile);
|
|
240
|
-
const baseProcessor = unified().use(remarkMarkAndUnravel);
|
|
241
|
-
if (heading) {
|
|
242
|
-
const extracted = extractSection(
|
|
243
|
-
await baseProcessor.use(remarkHeading).run(mdast),
|
|
244
|
-
heading
|
|
245
|
-
);
|
|
246
|
-
if (!extracted)
|
|
247
|
-
throw new Error(
|
|
248
|
-
`Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
|
|
249
|
-
);
|
|
250
|
-
mdast = extracted;
|
|
251
|
-
} else {
|
|
252
|
-
mdast = await baseProcessor.run(mdast);
|
|
253
|
-
}
|
|
254
|
-
await update(mdast, targetFile);
|
|
255
|
-
return mdast;
|
|
256
|
-
};
|
|
257
|
-
async function update(tree, file) {
|
|
258
|
-
const queue = [];
|
|
259
|
-
visit2(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
260
|
-
const node = _node;
|
|
261
|
-
if (node.name !== TagName) return;
|
|
262
|
-
const specifier = flattenNode(node);
|
|
263
|
-
if (specifier.length === 0) return "skip";
|
|
264
|
-
const attributes = parseElementAttributes(node);
|
|
265
|
-
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
266
|
-
const targetPath = path.resolve(
|
|
267
|
-
"cwd" in attributes ? file.cwd : file.dirname,
|
|
268
|
-
relativePath
|
|
269
|
-
);
|
|
270
|
-
queue.push(
|
|
271
|
-
embedContent(targetPath, section, attributes, file).then((replace) => {
|
|
272
|
-
Object.assign(
|
|
273
|
-
parent && parent.type === "paragraph" ? parent : node,
|
|
274
|
-
replace
|
|
275
|
-
);
|
|
276
|
-
})
|
|
277
|
-
);
|
|
278
|
-
return "skip";
|
|
279
|
-
});
|
|
280
|
-
await Promise.all(queue);
|
|
281
|
-
}
|
|
282
|
-
return async (tree, file) => {
|
|
283
|
-
await update(tree, file);
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
export {
|
|
288
|
-
flattenNode,
|
|
289
|
-
remarkInclude
|
|
290
|
-
};
|
package/dist/chunk-XYVVDDIF.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ValidationError
|
|
3
|
-
} from "./chunk-KWSETXYC.js";
|
|
4
|
-
|
|
5
|
-
// src/loaders/adapter.ts
|
|
6
|
-
import { fileURLToPath } from "url";
|
|
7
|
-
import fs from "fs/promises";
|
|
8
|
-
import { parse } from "querystring";
|
|
9
|
-
import path from "path";
|
|
10
|
-
import { readFileSync } from "fs";
|
|
11
|
-
function toNode(loader) {
|
|
12
|
-
return async (url, _context, nextLoad) => {
|
|
13
|
-
if (url.startsWith("file:///") && (!loader.test || loader.test.test(url))) {
|
|
14
|
-
const parsedUrl = new URL(url);
|
|
15
|
-
const filePath = fileURLToPath(parsedUrl);
|
|
16
|
-
const result = await loader.load({
|
|
17
|
-
filePath,
|
|
18
|
-
query: Object.fromEntries(parsedUrl.searchParams.entries()),
|
|
19
|
-
async getSource() {
|
|
20
|
-
return (await fs.readFile(filePath)).toString();
|
|
21
|
-
},
|
|
22
|
-
development: false,
|
|
23
|
-
compiler: {
|
|
24
|
-
addDependency() {
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
if (result) {
|
|
29
|
-
return {
|
|
30
|
-
source: result.code,
|
|
31
|
-
format: "module",
|
|
32
|
-
shortCircuit: true
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return nextLoad(url);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function toVite(loader) {
|
|
40
|
-
return {
|
|
41
|
-
filter(id) {
|
|
42
|
-
return !loader.test || loader.test.test(id);
|
|
43
|
-
},
|
|
44
|
-
async transform(value, id) {
|
|
45
|
-
const [file, query = ""] = id.split("?", 2);
|
|
46
|
-
const result = await loader.load({
|
|
47
|
-
filePath: file,
|
|
48
|
-
query: parse(query),
|
|
49
|
-
getSource() {
|
|
50
|
-
return value;
|
|
51
|
-
},
|
|
52
|
-
development: this.environment.mode === "dev",
|
|
53
|
-
compiler: {
|
|
54
|
-
addDependency: (file2) => {
|
|
55
|
-
this.addWatchFile(file2);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
if (result === null) return null;
|
|
60
|
-
return {
|
|
61
|
-
code: result.code,
|
|
62
|
-
map: result.map,
|
|
63
|
-
moduleType: result.moduleType
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function toWebpack(loader) {
|
|
69
|
-
return async function(source, callback) {
|
|
70
|
-
try {
|
|
71
|
-
const result = await loader.load({
|
|
72
|
-
filePath: this.resourcePath,
|
|
73
|
-
query: parse(this.resourceQuery.slice(1)),
|
|
74
|
-
getSource() {
|
|
75
|
-
return source;
|
|
76
|
-
},
|
|
77
|
-
development: this.mode === "development",
|
|
78
|
-
compiler: this
|
|
79
|
-
});
|
|
80
|
-
if (result === null) {
|
|
81
|
-
callback(void 0, source);
|
|
82
|
-
} else {
|
|
83
|
-
callback(void 0, result.code, result.map);
|
|
84
|
-
}
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (error instanceof ValidationError) {
|
|
87
|
-
return callback(new Error(await error.toStringFormatted()));
|
|
88
|
-
}
|
|
89
|
-
if (!(error instanceof Error)) throw error;
|
|
90
|
-
const fpath = path.relative(this.context, this.resourcePath);
|
|
91
|
-
error.message = `${fpath}:${error.name}: ${error.message}`;
|
|
92
|
-
callback(error);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function toBun(loader) {
|
|
97
|
-
function toResult(output) {
|
|
98
|
-
if (!output) return;
|
|
99
|
-
return {
|
|
100
|
-
contents: output.code,
|
|
101
|
-
loader: output.moduleType ?? "js"
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
return (build) => {
|
|
105
|
-
build.onLoad({ filter: loader.test ?? /.+/ }, (args) => {
|
|
106
|
-
const [filePath, query = ""] = args.path.split("?", 2);
|
|
107
|
-
const input = {
|
|
108
|
-
async getSource() {
|
|
109
|
-
return Bun.file(filePath).text();
|
|
110
|
-
},
|
|
111
|
-
query: parse(query),
|
|
112
|
-
filePath,
|
|
113
|
-
development: false,
|
|
114
|
-
compiler: {
|
|
115
|
-
addDependency() {
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
if (loader.bun?.load) {
|
|
120
|
-
return loader.bun.load(readFileSync(filePath).toString(), input);
|
|
121
|
-
}
|
|
122
|
-
const result = loader.load(input);
|
|
123
|
-
if (result instanceof Promise) {
|
|
124
|
-
return result.then(toResult);
|
|
125
|
-
}
|
|
126
|
-
return toResult(result);
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// src/loaders/config.ts
|
|
132
|
-
import fs2 from "fs/promises";
|
|
133
|
-
function createStandaloneConfigLoader({
|
|
134
|
-
core,
|
|
135
|
-
buildConfig,
|
|
136
|
-
mode
|
|
137
|
-
}) {
|
|
138
|
-
let prev;
|
|
139
|
-
async function getConfigHash() {
|
|
140
|
-
if (mode === "production") return "static";
|
|
141
|
-
const stats = await fs2.stat(core.getOptions().configPath).catch(() => {
|
|
142
|
-
throw new Error("Cannot find config file");
|
|
143
|
-
});
|
|
144
|
-
return stats.mtime.getTime().toString();
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
async getCore() {
|
|
148
|
-
const hash = await getConfigHash();
|
|
149
|
-
if (!prev || hash !== prev.hash) {
|
|
150
|
-
prev = {
|
|
151
|
-
hash,
|
|
152
|
-
init: (async () => {
|
|
153
|
-
const { loadConfig } = await import("./load-from-file-FHW724YY.js");
|
|
154
|
-
await core.init({
|
|
155
|
-
config: loadConfig(core, buildConfig)
|
|
156
|
-
});
|
|
157
|
-
})()
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
await prev.init;
|
|
161
|
-
return core;
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function createIntegratedConfigLoader(core) {
|
|
166
|
-
return {
|
|
167
|
-
async getCore() {
|
|
168
|
-
return core;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export {
|
|
174
|
-
toNode,
|
|
175
|
-
toVite,
|
|
176
|
-
toWebpack,
|
|
177
|
-
toBun,
|
|
178
|
-
createStandaloneConfigLoader,
|
|
179
|
-
createIntegratedConfigLoader
|
|
180
|
-
};
|