fumadocs-mdx 11.6.8 → 11.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-VC3Y6FLZ.js → chunk-64MMPGML.js} +12 -2
- package/dist/chunk-6PDS7MUA.js +49 -0
- package/dist/{chunk-KTLWF7GN.js → chunk-AVMO2SRO.js} +1 -1
- package/dist/chunk-KVWX6THC.js +19 -0
- package/dist/config/index.cjs +19 -30
- package/dist/config/index.d.cts +3 -2
- package/dist/config/index.d.ts +3 -2
- package/dist/config/index.js +6 -6
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/loader-mdx.cjs +145 -183
- package/dist/loader-mdx.js +9 -56
- package/dist/next/index.cjs +33 -40
- package/dist/next/index.js +28 -14
- package/dist/runtime/async.cjs +9 -30
- package/dist/runtime/async.d.cts +5 -5
- package/dist/runtime/async.d.ts +5 -5
- package/dist/runtime/async.js +2 -2
- package/dist/{types-BYJBKH4G.d.ts → types-Dk7DhSKZ.d.ts} +2 -15
- package/dist/{define-uoePrCQ_.d.ts → types-DvTNxAvo.d.cts} +67 -54
- package/dist/{define-uoePrCQ_.d.cts → types-DvTNxAvo.d.ts} +67 -54
- package/dist/{types-BsJd_P5O.d.cts → types-ZwLebhOl.d.cts} +2 -15
- package/dist/vite/index.cjs +384 -0
- package/dist/vite/index.d.cts +8 -0
- package/dist/vite/index.d.ts +8 -0
- package/dist/vite/index.js +71 -0
- package/package.json +19 -6
- package/dist/chunk-MXACIHNJ.js +0 -40
- package/dist/mdx-options-YGL3EP3M.js +0 -6
package/dist/loader-mdx.cjs
CHANGED
|
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
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
8
|
var __export = (target, all) => {
|
|
12
9
|
for (var name in all)
|
|
13
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,133 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
27
|
));
|
|
31
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
29
|
|
|
33
|
-
// src/mdx-plugins/remark-exports.ts
|
|
34
|
-
function remarkMdxExport({ values }) {
|
|
35
|
-
return (tree, vfile) => {
|
|
36
|
-
for (const name of values) {
|
|
37
|
-
if (!(name in vfile.data)) return;
|
|
38
|
-
tree.children.unshift(getMdastExport(name, vfile.data[name]));
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function getMdastExport(name, value) {
|
|
43
|
-
return {
|
|
44
|
-
type: "mdxjsEsm",
|
|
45
|
-
value: "",
|
|
46
|
-
data: {
|
|
47
|
-
estree: {
|
|
48
|
-
type: "Program",
|
|
49
|
-
sourceType: "module",
|
|
50
|
-
body: [
|
|
51
|
-
{
|
|
52
|
-
type: "ExportNamedDeclaration",
|
|
53
|
-
specifiers: [],
|
|
54
|
-
source: null,
|
|
55
|
-
declaration: {
|
|
56
|
-
type: "VariableDeclaration",
|
|
57
|
-
kind: "let",
|
|
58
|
-
declarations: [
|
|
59
|
-
{
|
|
60
|
-
type: "VariableDeclarator",
|
|
61
|
-
id: {
|
|
62
|
-
type: "Identifier",
|
|
63
|
-
name
|
|
64
|
-
},
|
|
65
|
-
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
var import_estree_util_value_to_estree;
|
|
76
|
-
var init_remark_exports = __esm({
|
|
77
|
-
"src/mdx-plugins/remark-exports.ts"() {
|
|
78
|
-
"use strict";
|
|
79
|
-
import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// src/utils/mdx-options.ts
|
|
84
|
-
var mdx_options_exports = {};
|
|
85
|
-
__export(mdx_options_exports, {
|
|
86
|
-
getDefaultMDXOptions: () => getDefaultMDXOptions
|
|
87
|
-
});
|
|
88
|
-
function pluginOption(def, options = []) {
|
|
89
|
-
const list = def(Array.isArray(options) ? options : []).filter(
|
|
90
|
-
Boolean
|
|
91
|
-
);
|
|
92
|
-
if (typeof options === "function") {
|
|
93
|
-
return options(list);
|
|
94
|
-
}
|
|
95
|
-
return list;
|
|
96
|
-
}
|
|
97
|
-
function getDefaultMDXOptions({
|
|
98
|
-
valueToExport = [],
|
|
99
|
-
rehypeCodeOptions,
|
|
100
|
-
remarkImageOptions,
|
|
101
|
-
remarkHeadingOptions,
|
|
102
|
-
remarkStructureOptions,
|
|
103
|
-
remarkCodeTabOptions,
|
|
104
|
-
...mdxOptions
|
|
105
|
-
}) {
|
|
106
|
-
const mdxExports = [
|
|
107
|
-
"structuredData",
|
|
108
|
-
"frontmatter",
|
|
109
|
-
"lastModified",
|
|
110
|
-
...valueToExport
|
|
111
|
-
];
|
|
112
|
-
const remarkPlugins = pluginOption(
|
|
113
|
-
(v) => [
|
|
114
|
-
plugins.remarkGfm,
|
|
115
|
-
[
|
|
116
|
-
plugins.remarkHeading,
|
|
117
|
-
{
|
|
118
|
-
generateToc: false,
|
|
119
|
-
...remarkHeadingOptions
|
|
120
|
-
}
|
|
121
|
-
],
|
|
122
|
-
remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
|
|
123
|
-
// Fumadocs 14 compatibility
|
|
124
|
-
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
125
|
-
plugins.remarkCodeTab,
|
|
126
|
-
remarkCodeTabOptions
|
|
127
|
-
],
|
|
128
|
-
...v,
|
|
129
|
-
remarkStructureOptions !== false && [
|
|
130
|
-
plugins.remarkStructure,
|
|
131
|
-
remarkStructureOptions
|
|
132
|
-
],
|
|
133
|
-
[remarkMdxExport, { values: mdxExports }]
|
|
134
|
-
],
|
|
135
|
-
mdxOptions.remarkPlugins
|
|
136
|
-
);
|
|
137
|
-
const rehypePlugins = pluginOption(
|
|
138
|
-
(v) => [
|
|
139
|
-
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
140
|
-
...v,
|
|
141
|
-
plugins.rehypeToc
|
|
142
|
-
],
|
|
143
|
-
mdxOptions.rehypePlugins
|
|
144
|
-
);
|
|
145
|
-
return {
|
|
146
|
-
...mdxOptions,
|
|
147
|
-
remarkPlugins,
|
|
148
|
-
rehypePlugins
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
var plugins;
|
|
152
|
-
var init_mdx_options = __esm({
|
|
153
|
-
"src/utils/mdx-options.ts"() {
|
|
154
|
-
"use strict";
|
|
155
|
-
plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
156
|
-
init_remark_exports();
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
|
|
160
30
|
// src/loader-mdx.ts
|
|
161
31
|
var loader_mdx_exports = {};
|
|
162
32
|
__export(loader_mdx_exports, {
|
|
@@ -263,37 +133,16 @@ var path2 = __toESM(require("path"), 1);
|
|
|
263
133
|
var fs2 = __toESM(require("fs/promises"), 1);
|
|
264
134
|
|
|
265
135
|
// src/utils/fuma-matter.ts
|
|
266
|
-
var import_lru_cache = require("lru-cache");
|
|
267
136
|
var import_js_yaml = require("js-yaml");
|
|
268
|
-
var
|
|
269
|
-
max: 200
|
|
270
|
-
});
|
|
137
|
+
var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
|
|
271
138
|
function fumaMatter(input) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const cached = cache2.get(input);
|
|
276
|
-
if (cached) return cached;
|
|
277
|
-
const result = parseMatter(input);
|
|
278
|
-
cache2.set(input, result);
|
|
279
|
-
return structuredClone(result);
|
|
280
|
-
}
|
|
281
|
-
var delimiter = "---";
|
|
282
|
-
function parseMatter(str) {
|
|
283
|
-
const output = { matter: "", data: {}, content: str };
|
|
284
|
-
const open = delimiter + "\n";
|
|
285
|
-
const close = "\n" + delimiter;
|
|
286
|
-
if (!str.startsWith(open)) {
|
|
139
|
+
const output = { matter: "", data: {}, content: input };
|
|
140
|
+
const match = regex.exec(input);
|
|
141
|
+
if (!match) {
|
|
287
142
|
return output;
|
|
288
143
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
let closeIdx = str.indexOf(close);
|
|
292
|
-
if (closeIdx === -1) {
|
|
293
|
-
closeIdx = len;
|
|
294
|
-
}
|
|
295
|
-
output.matter = str.slice(0, closeIdx);
|
|
296
|
-
output.content = str.slice(closeIdx + close.length);
|
|
144
|
+
output.matter = match[1];
|
|
145
|
+
output.content = input.slice(match[0].length);
|
|
297
146
|
const loaded = (0, import_js_yaml.load)(output.matter);
|
|
298
147
|
output.data = loaded ?? {};
|
|
299
148
|
return output;
|
|
@@ -371,7 +220,7 @@ ${e instanceof Error ? e.message : String(e)}`
|
|
|
371
220
|
}
|
|
372
221
|
|
|
373
222
|
// src/utils/build-mdx.ts
|
|
374
|
-
var
|
|
223
|
+
var cache2 = /* @__PURE__ */ new Map();
|
|
375
224
|
async function buildMDX(cacheKey, source, options) {
|
|
376
225
|
const { filePath, frontmatter, data, ...rest } = options;
|
|
377
226
|
let format = options.format;
|
|
@@ -380,16 +229,15 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
380
229
|
}
|
|
381
230
|
format ??= "mdx";
|
|
382
231
|
const key = `${cacheKey}:${format}`;
|
|
383
|
-
let cached =
|
|
384
|
-
if (cached
|
|
232
|
+
let cached = cache2.get(key);
|
|
233
|
+
if (!cached) {
|
|
385
234
|
cached = (0, import_mdx.createProcessor)({
|
|
386
235
|
outputFormat: "program",
|
|
387
|
-
development: process.env.NODE_ENV === "development",
|
|
388
236
|
...rest,
|
|
389
237
|
remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
|
|
390
238
|
format
|
|
391
239
|
});
|
|
392
|
-
|
|
240
|
+
cache2.set(key, cached);
|
|
393
241
|
}
|
|
394
242
|
return cached.process({
|
|
395
243
|
value: source,
|
|
@@ -405,9 +253,9 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
405
253
|
// src/utils/git-timestamp.ts
|
|
406
254
|
var import_node_path = __toESM(require("path"), 1);
|
|
407
255
|
var import_tinyexec = require("tinyexec");
|
|
408
|
-
var
|
|
256
|
+
var cache3 = /* @__PURE__ */ new Map();
|
|
409
257
|
async function getGitTimestamp(file) {
|
|
410
|
-
const cached =
|
|
258
|
+
const cached = cache3.get(file);
|
|
411
259
|
if (cached) return cached;
|
|
412
260
|
try {
|
|
413
261
|
const out = await (0, import_tinyexec.x)(
|
|
@@ -418,7 +266,7 @@ async function getGitTimestamp(file) {
|
|
|
418
266
|
}
|
|
419
267
|
);
|
|
420
268
|
const time = new Date(out.stdout);
|
|
421
|
-
|
|
269
|
+
cache3.set(file, time);
|
|
422
270
|
return time;
|
|
423
271
|
} catch {
|
|
424
272
|
return;
|
|
@@ -480,6 +328,137 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
480
328
|
return data;
|
|
481
329
|
}
|
|
482
330
|
|
|
331
|
+
// src/utils/count-lines.ts
|
|
332
|
+
function countLines(s) {
|
|
333
|
+
let num = 0;
|
|
334
|
+
for (const c of s) {
|
|
335
|
+
if (c === "\n") num++;
|
|
336
|
+
}
|
|
337
|
+
return num;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// src/utils/mdx-options.ts
|
|
341
|
+
var plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
342
|
+
|
|
343
|
+
// src/mdx-plugins/remark-exports.ts
|
|
344
|
+
var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
345
|
+
function remarkMdxExport({ values }) {
|
|
346
|
+
return (tree, vfile) => {
|
|
347
|
+
for (const name of values) {
|
|
348
|
+
if (!(name in vfile.data)) return;
|
|
349
|
+
tree.children.unshift(getMdastExport(name, vfile.data[name]));
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function getMdastExport(name, value) {
|
|
354
|
+
return {
|
|
355
|
+
type: "mdxjsEsm",
|
|
356
|
+
value: "",
|
|
357
|
+
data: {
|
|
358
|
+
estree: {
|
|
359
|
+
type: "Program",
|
|
360
|
+
sourceType: "module",
|
|
361
|
+
body: [
|
|
362
|
+
{
|
|
363
|
+
type: "ExportNamedDeclaration",
|
|
364
|
+
specifiers: [],
|
|
365
|
+
source: null,
|
|
366
|
+
declaration: {
|
|
367
|
+
type: "VariableDeclaration",
|
|
368
|
+
kind: "let",
|
|
369
|
+
declarations: [
|
|
370
|
+
{
|
|
371
|
+
type: "VariableDeclarator",
|
|
372
|
+
id: {
|
|
373
|
+
type: "Identifier",
|
|
374
|
+
name
|
|
375
|
+
},
|
|
376
|
+
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
377
|
+
}
|
|
378
|
+
]
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
]
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// src/utils/mdx-options.ts
|
|
388
|
+
function pluginOption(def, options = []) {
|
|
389
|
+
const list = def(Array.isArray(options) ? options : []).filter(
|
|
390
|
+
Boolean
|
|
391
|
+
);
|
|
392
|
+
if (typeof options === "function") {
|
|
393
|
+
return options(list);
|
|
394
|
+
}
|
|
395
|
+
return list;
|
|
396
|
+
}
|
|
397
|
+
function getDefaultMDXOptions({
|
|
398
|
+
valueToExport = [],
|
|
399
|
+
rehypeCodeOptions,
|
|
400
|
+
remarkImageOptions,
|
|
401
|
+
remarkHeadingOptions,
|
|
402
|
+
remarkStructureOptions,
|
|
403
|
+
remarkCodeTabOptions,
|
|
404
|
+
remarkNpmOptions,
|
|
405
|
+
...mdxOptions
|
|
406
|
+
}) {
|
|
407
|
+
const mdxExports = [
|
|
408
|
+
"structuredData",
|
|
409
|
+
"frontmatter",
|
|
410
|
+
"lastModified",
|
|
411
|
+
...valueToExport
|
|
412
|
+
];
|
|
413
|
+
const remarkPlugins = pluginOption(
|
|
414
|
+
(v) => [
|
|
415
|
+
plugins.remarkGfm,
|
|
416
|
+
[
|
|
417
|
+
plugins.remarkHeading,
|
|
418
|
+
{
|
|
419
|
+
generateToc: false,
|
|
420
|
+
...remarkHeadingOptions
|
|
421
|
+
}
|
|
422
|
+
],
|
|
423
|
+
remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
|
|
424
|
+
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
425
|
+
plugins.remarkCodeTab,
|
|
426
|
+
remarkCodeTabOptions
|
|
427
|
+
],
|
|
428
|
+
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
429
|
+
...v,
|
|
430
|
+
remarkStructureOptions !== false && [
|
|
431
|
+
plugins.remarkStructure,
|
|
432
|
+
remarkStructureOptions
|
|
433
|
+
],
|
|
434
|
+
[remarkMdxExport, { values: mdxExports }]
|
|
435
|
+
],
|
|
436
|
+
mdxOptions.remarkPlugins
|
|
437
|
+
);
|
|
438
|
+
const rehypePlugins = pluginOption(
|
|
439
|
+
(v) => [
|
|
440
|
+
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
441
|
+
...v,
|
|
442
|
+
plugins.rehypeToc
|
|
443
|
+
],
|
|
444
|
+
mdxOptions.rehypePlugins
|
|
445
|
+
);
|
|
446
|
+
return {
|
|
447
|
+
...mdxOptions,
|
|
448
|
+
remarkPlugins,
|
|
449
|
+
rehypePlugins
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
async function loadDefaultOptions(config) {
|
|
453
|
+
const input = config.global?.mdxOptions;
|
|
454
|
+
config._mdx_loader ??= {};
|
|
455
|
+
const mdxLoader = config._mdx_loader;
|
|
456
|
+
if (!mdxLoader.cachedOptions) {
|
|
457
|
+
mdxLoader.cachedOptions = typeof input === "function" ? getDefaultMDXOptions(await input()) : getDefaultMDXOptions(input ?? {});
|
|
458
|
+
}
|
|
459
|
+
return mdxLoader.cachedOptions;
|
|
460
|
+
}
|
|
461
|
+
|
|
483
462
|
// src/loader-mdx.ts
|
|
484
463
|
async function loader(source, callback) {
|
|
485
464
|
this.cacheable(true);
|
|
@@ -523,7 +502,7 @@ async function loader(source, callback) {
|
|
|
523
502
|
}
|
|
524
503
|
try {
|
|
525
504
|
const lineOffset = "\n".repeat(
|
|
526
|
-
this.mode === "development" ?
|
|
505
|
+
this.mode === "development" ? countLines(matter.matter) : 0
|
|
527
506
|
);
|
|
528
507
|
const file = await buildMDX(
|
|
529
508
|
`${configHash}:${collectionId ?? "global"}`,
|
|
@@ -547,20 +526,3 @@ async function loader(source, callback) {
|
|
|
547
526
|
callback(error);
|
|
548
527
|
}
|
|
549
528
|
}
|
|
550
|
-
async function loadDefaultOptions(config) {
|
|
551
|
-
const input = config.global?.mdxOptions;
|
|
552
|
-
config._mdx_loader ??= {};
|
|
553
|
-
const mdxLoader = config._mdx_loader;
|
|
554
|
-
if (!mdxLoader.cachedOptions) {
|
|
555
|
-
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
|
|
556
|
-
mdxLoader.cachedOptions = typeof input === "function" ? getDefaultMDXOptions2(await input()) : getDefaultMDXOptions2(input ?? {});
|
|
557
|
-
}
|
|
558
|
-
return mdxLoader.cachedOptions;
|
|
559
|
-
}
|
|
560
|
-
function lines(s) {
|
|
561
|
-
let num = 0;
|
|
562
|
-
for (const c of s) {
|
|
563
|
-
if (c === "\n") num++;
|
|
564
|
-
}
|
|
565
|
-
return num;
|
|
566
|
-
}
|
package/dist/loader-mdx.js
CHANGED
|
@@ -8,51 +8,21 @@ import {
|
|
|
8
8
|
validate
|
|
9
9
|
} from "./chunk-OTM6WYMS.js";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
buildMDX,
|
|
12
|
+
countLines
|
|
13
|
+
} from "./chunk-6PDS7MUA.js";
|
|
14
|
+
import {
|
|
15
|
+
loadDefaultOptions
|
|
16
|
+
} from "./chunk-64MMPGML.js";
|
|
17
|
+
import "./chunk-AVMO2SRO.js";
|
|
13
18
|
import "./chunk-DRVUBK5B.js";
|
|
14
19
|
import {
|
|
15
20
|
fumaMatter
|
|
16
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-KVWX6THC.js";
|
|
17
22
|
|
|
18
23
|
// src/loader-mdx.ts
|
|
19
24
|
import * as path from "path";
|
|
20
25
|
import { parse } from "querystring";
|
|
21
|
-
|
|
22
|
-
// src/utils/build-mdx.ts
|
|
23
|
-
import { createProcessor } from "@mdx-js/mdx";
|
|
24
|
-
var cache = /* @__PURE__ */ new Map();
|
|
25
|
-
async function buildMDX(cacheKey, source, options) {
|
|
26
|
-
const { filePath, frontmatter, data, ...rest } = options;
|
|
27
|
-
let format = options.format;
|
|
28
|
-
if (!format && filePath) {
|
|
29
|
-
format = filePath.endsWith(".mdx") ? "mdx" : "md";
|
|
30
|
-
}
|
|
31
|
-
format ??= "mdx";
|
|
32
|
-
const key = `${cacheKey}:${format}`;
|
|
33
|
-
let cached = cache.get(key);
|
|
34
|
-
if (cached === void 0) {
|
|
35
|
-
cached = createProcessor({
|
|
36
|
-
outputFormat: "program",
|
|
37
|
-
development: process.env.NODE_ENV === "development",
|
|
38
|
-
...rest,
|
|
39
|
-
remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
|
|
40
|
-
format
|
|
41
|
-
});
|
|
42
|
-
cache.set(key, cached);
|
|
43
|
-
}
|
|
44
|
-
return cached.process({
|
|
45
|
-
value: source,
|
|
46
|
-
path: filePath,
|
|
47
|
-
data: {
|
|
48
|
-
...data,
|
|
49
|
-
frontmatter,
|
|
50
|
-
_compiler: options._compiler
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/loader-mdx.ts
|
|
56
26
|
async function loader(source, callback) {
|
|
57
27
|
this.cacheable(true);
|
|
58
28
|
const context = this.context;
|
|
@@ -95,7 +65,7 @@ async function loader(source, callback) {
|
|
|
95
65
|
}
|
|
96
66
|
try {
|
|
97
67
|
const lineOffset = "\n".repeat(
|
|
98
|
-
this.mode === "development" ?
|
|
68
|
+
this.mode === "development" ? countLines(matter.matter) : 0
|
|
99
69
|
);
|
|
100
70
|
const file = await buildMDX(
|
|
101
71
|
`${configHash}:${collectionId ?? "global"}`,
|
|
@@ -119,23 +89,6 @@ async function loader(source, callback) {
|
|
|
119
89
|
callback(error);
|
|
120
90
|
}
|
|
121
91
|
}
|
|
122
|
-
async function loadDefaultOptions(config) {
|
|
123
|
-
const input = config.global?.mdxOptions;
|
|
124
|
-
config._mdx_loader ??= {};
|
|
125
|
-
const mdxLoader = config._mdx_loader;
|
|
126
|
-
if (!mdxLoader.cachedOptions) {
|
|
127
|
-
const { getDefaultMDXOptions } = await import("./mdx-options-YGL3EP3M.js");
|
|
128
|
-
mdxLoader.cachedOptions = typeof input === "function" ? getDefaultMDXOptions(await input()) : getDefaultMDXOptions(input ?? {});
|
|
129
|
-
}
|
|
130
|
-
return mdxLoader.cachedOptions;
|
|
131
|
-
}
|
|
132
|
-
function lines(s) {
|
|
133
|
-
let num = 0;
|
|
134
|
-
for (const c of s) {
|
|
135
|
-
if (c === "\n") num++;
|
|
136
|
-
}
|
|
137
|
-
return num;
|
|
138
|
-
}
|
|
139
92
|
export {
|
|
140
93
|
loader as default
|
|
141
94
|
};
|
package/dist/next/index.cjs
CHANGED
|
@@ -281,37 +281,16 @@ async function getGitTimestamp(file) {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
// src/utils/fuma-matter.ts
|
|
284
|
-
var import_lru_cache2 = require("lru-cache");
|
|
285
284
|
var import_js_yaml = require("js-yaml");
|
|
286
|
-
var
|
|
287
|
-
max: 200
|
|
288
|
-
});
|
|
285
|
+
var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
|
|
289
286
|
function fumaMatter(input) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const cached = cache3.get(input);
|
|
294
|
-
if (cached) return cached;
|
|
295
|
-
const result = parseMatter(input);
|
|
296
|
-
cache3.set(input, result);
|
|
297
|
-
return structuredClone(result);
|
|
298
|
-
}
|
|
299
|
-
var delimiter = "---";
|
|
300
|
-
function parseMatter(str) {
|
|
301
|
-
const output = { matter: "", data: {}, content: str };
|
|
302
|
-
const open = delimiter + "\n";
|
|
303
|
-
const close = "\n" + delimiter;
|
|
304
|
-
if (!str.startsWith(open)) {
|
|
287
|
+
const output = { matter: "", data: {}, content: input };
|
|
288
|
+
const match = regex.exec(input);
|
|
289
|
+
if (!match) {
|
|
305
290
|
return output;
|
|
306
291
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
let closeIdx = str.indexOf(close);
|
|
310
|
-
if (closeIdx === -1) {
|
|
311
|
-
closeIdx = len;
|
|
312
|
-
}
|
|
313
|
-
output.matter = str.slice(0, closeIdx);
|
|
314
|
-
output.content = str.slice(closeIdx + close.length);
|
|
292
|
+
output.matter = match[1];
|
|
293
|
+
output.content = input.slice(match[0].length);
|
|
315
294
|
const loaded = (0, import_js_yaml.load)(output.matter);
|
|
316
295
|
output.data = loaded ?? {};
|
|
317
296
|
return output;
|
|
@@ -323,8 +302,7 @@ async function readFileWithCache(file) {
|
|
|
323
302
|
if (cached) return cached;
|
|
324
303
|
return (await fs2.readFile(file)).toString();
|
|
325
304
|
}
|
|
326
|
-
async function generateJS(configPath, config,
|
|
327
|
-
const outDir = path3.dirname(outputPath);
|
|
305
|
+
async function generateJS(configPath, config, importPath, configHash = false) {
|
|
328
306
|
let asyncInit = false;
|
|
329
307
|
const lines = [
|
|
330
308
|
getImportCode({
|
|
@@ -334,7 +312,7 @@ async function generateJS(configPath, config, outputPath, configHash) {
|
|
|
334
312
|
}),
|
|
335
313
|
getImportCode({
|
|
336
314
|
type: "namespace",
|
|
337
|
-
specifier: toImportPath(configPath,
|
|
315
|
+
specifier: toImportPath(configPath, importPath),
|
|
338
316
|
name: "_source"
|
|
339
317
|
})
|
|
340
318
|
];
|
|
@@ -342,11 +320,15 @@ async function generateJS(configPath, config, outputPath, configHash) {
|
|
|
342
320
|
async function getDocEntries(collectionName, files) {
|
|
343
321
|
const items = files.map(async (file, i) => {
|
|
344
322
|
const importId = `${collectionName}_${i}`;
|
|
323
|
+
const params = [`collection=${collectionName}`];
|
|
324
|
+
if (configHash) {
|
|
325
|
+
params.push(`hash=${configHash}`);
|
|
326
|
+
}
|
|
345
327
|
lines.unshift(
|
|
346
328
|
getImportCode({
|
|
347
329
|
type: "namespace",
|
|
348
330
|
name: importId,
|
|
349
|
-
specifier: `${toImportPath(file.absolutePath,
|
|
331
|
+
specifier: `${toImportPath(file.absolutePath, importPath)}?${params.join("&")}`
|
|
350
332
|
})
|
|
351
333
|
);
|
|
352
334
|
return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
|
|
@@ -476,14 +458,17 @@ function getImportCode(info) {
|
|
|
476
458
|
}
|
|
477
459
|
return `import ${specifier}`;
|
|
478
460
|
}
|
|
479
|
-
function toImportPath(file,
|
|
461
|
+
function toImportPath(file, config) {
|
|
480
462
|
const ext = path3.extname(file);
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
463
|
+
const filename = ext === ".ts" ? file.substring(0, file.length - ext.length) : file;
|
|
464
|
+
let importPath;
|
|
465
|
+
if ("relativeTo" in config) {
|
|
466
|
+
importPath = path3.relative(config.relativeTo, filename);
|
|
467
|
+
if (!path3.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
468
|
+
importPath = `./${importPath}`;
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
importPath = path3.resolve(filename);
|
|
487
472
|
}
|
|
488
473
|
return importPath.replaceAll(path3.sep, "/");
|
|
489
474
|
}
|
|
@@ -510,7 +495,12 @@ async function start(dev, configPath, outDir) {
|
|
|
510
495
|
try {
|
|
511
496
|
await fs3.writeFile(
|
|
512
497
|
outPath,
|
|
513
|
-
await generateJS(
|
|
498
|
+
await generateJS(
|
|
499
|
+
configPath,
|
|
500
|
+
config,
|
|
501
|
+
{ relativeTo: outDir },
|
|
502
|
+
configHash
|
|
503
|
+
)
|
|
514
504
|
);
|
|
515
505
|
} catch (err) {
|
|
516
506
|
if (err instanceof ValidationError) {
|
|
@@ -615,7 +605,10 @@ async function postInstall(configPath = findConfigFile(), outDir = ".source") {
|
|
|
615
605
|
const config = await loadConfig(configPath, outDir, hash, true);
|
|
616
606
|
await fs4.rm(path5.dirname(jsOut), { recursive: true });
|
|
617
607
|
await fs4.mkdir(path5.dirname(jsOut), { recursive: true });
|
|
618
|
-
await fs4.writeFile(
|
|
608
|
+
await fs4.writeFile(
|
|
609
|
+
jsOut,
|
|
610
|
+
await generateJS(configPath, config, { relativeTo: outDir }, hash)
|
|
611
|
+
);
|
|
619
612
|
console.log("[MDX] types generated");
|
|
620
613
|
}
|
|
621
614
|
// Annotate the CommonJS export names for ESM import in node:
|