fumadocs-mdx 14.0.1 → 14.0.3
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 +1 -1
- package/dist/bun/index.js +8 -8
- package/dist/{chunk-ZY6UZ7NH.js → chunk-6RPNS75C.js} +1 -1
- package/dist/{chunk-7UKSZSPY.js → chunk-DKA3EWZH.js} +6 -7
- package/dist/{chunk-BEBCWQC7.js → chunk-GB4W3YCZ.js} +1 -1
- package/dist/{chunk-SLY7WXTX.js → chunk-KOPLIEVQ.js} +5 -6
- package/dist/{chunk-MTTISKQJ.js → chunk-LPX7ZO66.js} +1 -1
- package/dist/{chunk-K6HCOGOX.js → chunk-OLL7FM7W.js} +2 -2
- package/dist/{chunk-IQGEFL2B.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/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/{core-B9ZoS6sA.d.ts → core-C3QZSdEx.d.ts} +1 -1
- package/dist/{index-BD8Woo4m.d.cts → index-DG1I0CwF.d.ts} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/load-from-file-OZ5N7DXU.js +8 -0
- package/dist/next/index.cjs +10 -8
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +8 -8
- package/dist/node/loader.js +4 -4
- package/dist/plugins/index-file.d.ts +1 -1
- package/dist/plugins/index-file.js +2 -2
- package/dist/plugins/json-schema.d.ts +1 -1
- package/dist/plugins/last-modified.d.ts +5 -2
- package/dist/plugins/last-modified.js +10 -3
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/dynamic.d.ts +1 -1
- package/dist/runtime/dynamic.js +5 -5
- package/dist/runtime/server.d.ts +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +10 -10
- package/dist/webpack/mdx.d.ts +2 -2
- package/dist/webpack/mdx.js +6 -6
- package/dist/webpack/meta.d.ts +2 -2
- package/dist/webpack/meta.js +4 -4
- package/package.json +4 -6
- package/dist/bin.cjs +0 -1958
- package/dist/bin.d.cts +0 -1
- package/dist/bun/index.cjs +0 -1147
- package/dist/bun/index.d.cts +0 -25
- package/dist/config/index.cjs +0 -400
- package/dist/config/index.d.cts +0 -18
- package/dist/core-DTuP23zu.d.cts +0 -341
- package/dist/index-CNOvhtOn.d.ts +0 -8
- package/dist/index.cjs +0 -18
- package/dist/index.d.cts +0 -61
- package/dist/load-from-file-5HUQN36V.js +0 -8
- package/dist/next/index.d.cts +0 -33
- package/dist/node/loader.cjs +0 -1200
- package/dist/node/loader.d.cts +0 -5
- package/dist/plugins/index-file.cjs +0 -495
- package/dist/plugins/index-file.d.cts +0 -14
- package/dist/plugins/json-schema.cjs +0 -114
- package/dist/plugins/json-schema.d.cts +0 -31
- package/dist/plugins/last-modified.cjs +0 -110
- package/dist/plugins/last-modified.d.cts +0 -37
- package/dist/runtime/browser.cjs +0 -93
- package/dist/runtime/browser.d.cts +0 -53
- package/dist/runtime/dynamic.cjs +0 -1023
- package/dist/runtime/dynamic.d.cts +0 -27
- package/dist/runtime/server.cjs +0 -176
- package/dist/runtime/server.d.cts +0 -14
- package/dist/runtime/types.cjs +0 -18
- package/dist/runtime/types.d.cts +0 -61
- package/dist/vite/index.cjs +0 -1687
- package/dist/vite/index.d.cts +0 -44
- package/dist/webpack/mdx.cjs +0 -1124
- package/dist/webpack/mdx.d.cts +0 -20
- package/dist/webpack/meta.cjs +0 -684
- package/dist/webpack/meta.d.cts +0 -20
package/dist/webpack/mdx.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { LoaderContext } from 'webpack';
|
|
2
|
-
import { W as WebpackLoaderOptions } from '../index-BD8Woo4m.cjs';
|
|
3
|
-
import '../core-DTuP23zu.cjs';
|
|
4
|
-
import '@mdx-js/mdx';
|
|
5
|
-
import '@standard-schema/spec';
|
|
6
|
-
import 'unified';
|
|
7
|
-
import 'fumadocs-core/mdx-plugins';
|
|
8
|
-
import 'zod';
|
|
9
|
-
import 'chokidar';
|
|
10
|
-
import 'vfile';
|
|
11
|
-
import 'fumadocs-core/source';
|
|
12
|
-
import '../runtime/types.cjs';
|
|
13
|
-
import 'fumadocs-core/mdx-plugins/remark-structure';
|
|
14
|
-
import 'fumadocs-core/toc';
|
|
15
|
-
import 'mdast';
|
|
16
|
-
import 'mdx/types';
|
|
17
|
-
|
|
18
|
-
declare function loader(this: LoaderContext<WebpackLoaderOptions>, source: string, callback: LoaderContext<WebpackLoaderOptions>['callback']): Promise<void>;
|
|
19
|
-
|
|
20
|
-
export { loader as default };
|
package/dist/webpack/meta.cjs
DELETED
|
@@ -1,684 +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/config/preset.ts
|
|
34
|
-
function pluginOption(def, options = []) {
|
|
35
|
-
const list = def(Array.isArray(options) ? options : []).filter(
|
|
36
|
-
Boolean
|
|
37
|
-
);
|
|
38
|
-
if (typeof options === "function") {
|
|
39
|
-
return options(list);
|
|
40
|
-
}
|
|
41
|
-
return list;
|
|
42
|
-
}
|
|
43
|
-
function applyMdxPreset(options = {}) {
|
|
44
|
-
return async (environment = "bundler") => {
|
|
45
|
-
if (options.preset === "minimal") return options;
|
|
46
|
-
const plugins = await import("fumadocs-core/mdx-plugins");
|
|
47
|
-
const {
|
|
48
|
-
valueToExport = [],
|
|
49
|
-
rehypeCodeOptions,
|
|
50
|
-
remarkImageOptions,
|
|
51
|
-
remarkHeadingOptions,
|
|
52
|
-
remarkStructureOptions,
|
|
53
|
-
remarkCodeTabOptions,
|
|
54
|
-
remarkNpmOptions,
|
|
55
|
-
...mdxOptions
|
|
56
|
-
} = options;
|
|
57
|
-
const remarkPlugins = pluginOption(
|
|
58
|
-
(v) => [
|
|
59
|
-
plugins.remarkGfm,
|
|
60
|
-
[
|
|
61
|
-
plugins.remarkHeading,
|
|
62
|
-
{
|
|
63
|
-
generateToc: false,
|
|
64
|
-
...remarkHeadingOptions
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
remarkImageOptions !== false && [
|
|
68
|
-
plugins.remarkImage,
|
|
69
|
-
{
|
|
70
|
-
...remarkImageOptions,
|
|
71
|
-
useImport: remarkImageOptions?.useImport ?? environment === "bundler"
|
|
72
|
-
}
|
|
73
|
-
],
|
|
74
|
-
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
75
|
-
plugins.remarkCodeTab,
|
|
76
|
-
remarkCodeTabOptions
|
|
77
|
-
],
|
|
78
|
-
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
79
|
-
...v,
|
|
80
|
-
remarkStructureOptions !== false && [
|
|
81
|
-
plugins.remarkStructure,
|
|
82
|
-
remarkStructureOptions
|
|
83
|
-
],
|
|
84
|
-
valueToExport.length > 0 && (() => {
|
|
85
|
-
return (_, file) => {
|
|
86
|
-
file.data["mdx-export"] ??= [];
|
|
87
|
-
for (const name of valueToExport) {
|
|
88
|
-
if (!(name in file.data)) continue;
|
|
89
|
-
file.data["mdx-export"].push({
|
|
90
|
-
name,
|
|
91
|
-
value: file.data[name]
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
})
|
|
96
|
-
],
|
|
97
|
-
mdxOptions.remarkPlugins
|
|
98
|
-
);
|
|
99
|
-
const rehypePlugins = pluginOption(
|
|
100
|
-
(v) => [
|
|
101
|
-
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
102
|
-
...v,
|
|
103
|
-
plugins.rehypeToc
|
|
104
|
-
],
|
|
105
|
-
mdxOptions.rehypePlugins
|
|
106
|
-
);
|
|
107
|
-
return {
|
|
108
|
-
...mdxOptions,
|
|
109
|
-
outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
|
|
110
|
-
remarkPlugins,
|
|
111
|
-
rehypePlugins
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
var init_preset = __esm({
|
|
116
|
-
"src/config/preset.ts"() {
|
|
117
|
-
"use strict";
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// src/config/build.ts
|
|
122
|
-
function buildCollection(name, config) {
|
|
123
|
-
if (config.type === "docs") {
|
|
124
|
-
return {
|
|
125
|
-
...config,
|
|
126
|
-
name,
|
|
127
|
-
meta: buildPrimitiveCollection(name, config.meta),
|
|
128
|
-
docs: buildPrimitiveCollection(name, config.docs),
|
|
129
|
-
hasFile(filePath) {
|
|
130
|
-
return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
return buildPrimitiveCollection(name, config);
|
|
135
|
-
}
|
|
136
|
-
function buildPrimitiveCollection(name, { files, ...config }) {
|
|
137
|
-
const supportedFormats = SupportedFormats[config.type];
|
|
138
|
-
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
139
|
-
let matchers;
|
|
140
|
-
return {
|
|
141
|
-
...config,
|
|
142
|
-
name,
|
|
143
|
-
patterns,
|
|
144
|
-
isFileSupported(filePath) {
|
|
145
|
-
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
146
|
-
},
|
|
147
|
-
hasFile(filePath) {
|
|
148
|
-
matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
|
|
149
|
-
(dir) => (0, import_picomatch.default)(patterns, {
|
|
150
|
-
cwd: dir
|
|
151
|
-
})
|
|
152
|
-
);
|
|
153
|
-
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
function buildConfig(config) {
|
|
158
|
-
const collections = /* @__PURE__ */ new Map();
|
|
159
|
-
const loaded = {};
|
|
160
|
-
for (const [k, v] of Object.entries(config)) {
|
|
161
|
-
if (!v) {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (typeof v === "object" && "type" in v) {
|
|
165
|
-
if (v.type === "docs") {
|
|
166
|
-
collections.set(k, buildCollection(k, v));
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if (v.type === "doc" || v.type === "meta") {
|
|
170
|
-
collections.set(
|
|
171
|
-
k,
|
|
172
|
-
buildCollection(k, v)
|
|
173
|
-
);
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (k === "default" && v) {
|
|
178
|
-
Object.assign(loaded, v);
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
throw new Error(
|
|
182
|
-
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
186
|
-
return {
|
|
187
|
-
global: loaded,
|
|
188
|
-
collectionList: Array.from(collections.values()),
|
|
189
|
-
getCollection(name) {
|
|
190
|
-
return collections.get(name);
|
|
191
|
-
},
|
|
192
|
-
getMDXOptions(collection, environment = "bundler") {
|
|
193
|
-
const key = collection ? `${environment}:${collection.name}` : environment;
|
|
194
|
-
const cached = mdxOptionsCache.get(key);
|
|
195
|
-
if (cached) return cached;
|
|
196
|
-
let result;
|
|
197
|
-
if (collection?.mdxOptions) {
|
|
198
|
-
const optionsFn = collection.mdxOptions;
|
|
199
|
-
result = typeof optionsFn === "function" ? optionsFn(environment) : optionsFn;
|
|
200
|
-
} else {
|
|
201
|
-
result = (async () => {
|
|
202
|
-
const optionsFn = this.global.mdxOptions;
|
|
203
|
-
const options = typeof optionsFn === "function" ? await optionsFn() : optionsFn;
|
|
204
|
-
return applyMdxPreset(options)(environment);
|
|
205
|
-
})();
|
|
206
|
-
}
|
|
207
|
-
mdxOptionsCache.set(key, result);
|
|
208
|
-
return result;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
var import_picomatch, SupportedFormats;
|
|
213
|
-
var init_build = __esm({
|
|
214
|
-
"src/config/build.ts"() {
|
|
215
|
-
"use strict";
|
|
216
|
-
import_picomatch = __toESM(require("picomatch"), 1);
|
|
217
|
-
init_preset();
|
|
218
|
-
SupportedFormats = {
|
|
219
|
-
doc: ["mdx", "md"],
|
|
220
|
-
meta: ["json", "yaml"]
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// src/config/load-from-file.ts
|
|
226
|
-
var load_from_file_exports = {};
|
|
227
|
-
__export(load_from_file_exports, {
|
|
228
|
-
loadConfig: () => loadConfig
|
|
229
|
-
});
|
|
230
|
-
async function compileConfig(core2) {
|
|
231
|
-
const { build } = await import("esbuild");
|
|
232
|
-
const { configPath, outDir } = core2.getOptions();
|
|
233
|
-
const transformed = await build({
|
|
234
|
-
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
235
|
-
bundle: true,
|
|
236
|
-
outdir: outDir,
|
|
237
|
-
target: "node20",
|
|
238
|
-
write: true,
|
|
239
|
-
platform: "node",
|
|
240
|
-
format: "esm",
|
|
241
|
-
packages: "external",
|
|
242
|
-
outExtension: {
|
|
243
|
-
".js": ".mjs"
|
|
244
|
-
},
|
|
245
|
-
allowOverwrite: true
|
|
246
|
-
});
|
|
247
|
-
if (transformed.errors.length > 0) {
|
|
248
|
-
throw new Error("failed to compile configuration file");
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
async function loadConfig(core2, build = false) {
|
|
252
|
-
if (build) await compileConfig(core2);
|
|
253
|
-
const url = (0, import_node_url2.pathToFileURL)(core2.getCompiledConfigPath());
|
|
254
|
-
url.searchParams.set("hash", Date.now().toString());
|
|
255
|
-
const config = import(url.href).then(
|
|
256
|
-
(loaded) => buildConfig(loaded)
|
|
257
|
-
);
|
|
258
|
-
return await config;
|
|
259
|
-
}
|
|
260
|
-
var import_node_url2;
|
|
261
|
-
var init_load_from_file = __esm({
|
|
262
|
-
"src/config/load-from-file.ts"() {
|
|
263
|
-
"use strict";
|
|
264
|
-
import_node_url2 = require("url");
|
|
265
|
-
init_build();
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// src/webpack/meta.ts
|
|
270
|
-
var meta_exports = {};
|
|
271
|
-
__export(meta_exports, {
|
|
272
|
-
default: () => loader
|
|
273
|
-
});
|
|
274
|
-
module.exports = __toCommonJS(meta_exports);
|
|
275
|
-
|
|
276
|
-
// src/loaders/adapter.ts
|
|
277
|
-
var import_node_url = require("url");
|
|
278
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
279
|
-
var import_node_querystring = require("querystring");
|
|
280
|
-
|
|
281
|
-
// src/utils/validation.ts
|
|
282
|
-
var ValidationError = class extends Error {
|
|
283
|
-
constructor(message, issues) {
|
|
284
|
-
super(
|
|
285
|
-
`${message}:
|
|
286
|
-
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
|
|
287
|
-
);
|
|
288
|
-
this.title = message;
|
|
289
|
-
this.issues = issues;
|
|
290
|
-
}
|
|
291
|
-
async toStringFormatted() {
|
|
292
|
-
const picocolors = await import("picocolors");
|
|
293
|
-
return [
|
|
294
|
-
picocolors.bold(`[MDX] ${this.title}:`),
|
|
295
|
-
...this.issues.map(
|
|
296
|
-
(issue) => picocolors.redBright(
|
|
297
|
-
`- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
|
|
298
|
-
)
|
|
299
|
-
)
|
|
300
|
-
].join("\n");
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
async function validate(schema, data, context, errorMessage) {
|
|
304
|
-
if (typeof schema === "function" && !("~standard" in schema)) {
|
|
305
|
-
schema = schema(context);
|
|
306
|
-
}
|
|
307
|
-
if ("~standard" in schema) {
|
|
308
|
-
const result = await schema["~standard"].validate(
|
|
309
|
-
data
|
|
310
|
-
);
|
|
311
|
-
if (result.issues) {
|
|
312
|
-
throw new ValidationError(errorMessage, result.issues);
|
|
313
|
-
}
|
|
314
|
-
return result.value;
|
|
315
|
-
}
|
|
316
|
-
return data;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// src/loaders/adapter.ts
|
|
320
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
321
|
-
var import_node_fs = require("fs");
|
|
322
|
-
function toWebpack(loader2) {
|
|
323
|
-
return async function(source, callback) {
|
|
324
|
-
try {
|
|
325
|
-
const result = await loader2.load({
|
|
326
|
-
filePath: this.resourcePath,
|
|
327
|
-
query: (0, import_node_querystring.parse)(this.resourceQuery.slice(1)),
|
|
328
|
-
getSource() {
|
|
329
|
-
return source;
|
|
330
|
-
},
|
|
331
|
-
development: this.mode === "development",
|
|
332
|
-
compiler: this
|
|
333
|
-
});
|
|
334
|
-
if (result === null) {
|
|
335
|
-
callback(void 0, source);
|
|
336
|
-
} else {
|
|
337
|
-
callback(void 0, result.code, result.map);
|
|
338
|
-
}
|
|
339
|
-
} catch (error) {
|
|
340
|
-
if (error instanceof ValidationError) {
|
|
341
|
-
return callback(new Error(await error.toStringFormatted()));
|
|
342
|
-
}
|
|
343
|
-
if (!(error instanceof Error)) throw error;
|
|
344
|
-
const fpath = import_node_path.default.relative(this.context, this.resourcePath);
|
|
345
|
-
error.message = `${fpath}:${error.name}: ${error.message}`;
|
|
346
|
-
callback(error);
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// src/loaders/config.ts
|
|
352
|
-
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
353
|
-
function createStandaloneConfigLoader({
|
|
354
|
-
core: core2,
|
|
355
|
-
buildConfig: buildConfig2,
|
|
356
|
-
mode
|
|
357
|
-
}) {
|
|
358
|
-
let loaded;
|
|
359
|
-
async function getConfigHash() {
|
|
360
|
-
if (mode === "production") return "static";
|
|
361
|
-
const stats = await import_promises2.default.stat(core2.getOptions().configPath).catch(() => {
|
|
362
|
-
throw new Error("Cannot find config file");
|
|
363
|
-
});
|
|
364
|
-
return stats.mtime.getTime().toString();
|
|
365
|
-
}
|
|
366
|
-
async function newConfig() {
|
|
367
|
-
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load_from_file(), load_from_file_exports));
|
|
368
|
-
await core2.init({
|
|
369
|
-
config: loadConfig2(core2, buildConfig2)
|
|
370
|
-
});
|
|
371
|
-
return core2.getConfig();
|
|
372
|
-
}
|
|
373
|
-
return {
|
|
374
|
-
core: core2,
|
|
375
|
-
async getConfig() {
|
|
376
|
-
const hash = await getConfigHash();
|
|
377
|
-
if (loaded && loaded.hash === hash) return loaded.config;
|
|
378
|
-
loaded = {
|
|
379
|
-
hash,
|
|
380
|
-
config: newConfig()
|
|
381
|
-
};
|
|
382
|
-
return loaded.config;
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// src/loaders/meta.ts
|
|
388
|
-
var import_js_yaml = require("js-yaml");
|
|
389
|
-
var import_zod = require("zod");
|
|
390
|
-
|
|
391
|
-
// src/loaders/index.ts
|
|
392
|
-
var metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
|
|
393
|
-
|
|
394
|
-
// src/loaders/meta.ts
|
|
395
|
-
var querySchema = import_zod.z.object({
|
|
396
|
-
collection: import_zod.z.string().optional()
|
|
397
|
-
}).loose();
|
|
398
|
-
function createMetaLoader(configLoader, resolve = {}) {
|
|
399
|
-
const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve;
|
|
400
|
-
function parse2(filePath, source) {
|
|
401
|
-
try {
|
|
402
|
-
if (filePath.endsWith(".json")) return JSON.parse(source);
|
|
403
|
-
if (filePath.endsWith(".yaml")) return (0, import_js_yaml.load)(source);
|
|
404
|
-
} catch (e) {
|
|
405
|
-
throw new Error(`invalid data in ${filePath}`, { cause: e });
|
|
406
|
-
}
|
|
407
|
-
throw new Error("Unknown file type " + filePath);
|
|
408
|
-
}
|
|
409
|
-
function onMeta(source, { filePath, query }) {
|
|
410
|
-
const parsed = querySchema.safeParse(query);
|
|
411
|
-
if (!parsed.success || !parsed.data.collection) return null;
|
|
412
|
-
const collectionName = parsed.data.collection;
|
|
413
|
-
return async () => {
|
|
414
|
-
const config = await configLoader.getConfig();
|
|
415
|
-
const collection = config.getCollection(collectionName);
|
|
416
|
-
let metaCollection;
|
|
417
|
-
switch (collection?.type) {
|
|
418
|
-
case "meta":
|
|
419
|
-
metaCollection = collection;
|
|
420
|
-
break;
|
|
421
|
-
case "docs":
|
|
422
|
-
metaCollection = collection.meta;
|
|
423
|
-
break;
|
|
424
|
-
}
|
|
425
|
-
const data = parse2(filePath, source);
|
|
426
|
-
if (!metaCollection) return data;
|
|
427
|
-
return configLoader.core.transformMeta(
|
|
428
|
-
{
|
|
429
|
-
collection: metaCollection,
|
|
430
|
-
filePath,
|
|
431
|
-
source
|
|
432
|
-
},
|
|
433
|
-
data
|
|
434
|
-
);
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
return {
|
|
438
|
-
test: metaLoaderGlob,
|
|
439
|
-
async load(input) {
|
|
440
|
-
const result = onMeta(await input.getSource(), input);
|
|
441
|
-
if (result === null) return null;
|
|
442
|
-
const data = await result();
|
|
443
|
-
if (input.filePath.endsWith(".json")) {
|
|
444
|
-
return {
|
|
445
|
-
code: resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`
|
|
446
|
-
};
|
|
447
|
-
} else {
|
|
448
|
-
return {
|
|
449
|
-
code: resolveYaml === "yaml" ? (0, import_js_yaml.dump)(data) : `export default ${JSON.stringify(data)}`
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
},
|
|
453
|
-
bun: {
|
|
454
|
-
load(source, input) {
|
|
455
|
-
const result = onMeta(source, input);
|
|
456
|
-
if (result === null)
|
|
457
|
-
return {
|
|
458
|
-
loader: "object",
|
|
459
|
-
exports: parse2(input.filePath, source)
|
|
460
|
-
};
|
|
461
|
-
return result().then((data) => ({
|
|
462
|
-
loader: "object",
|
|
463
|
-
exports: { default: data }
|
|
464
|
-
}));
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// src/core.ts
|
|
471
|
-
var import_node_path3 = __toESM(require("path"), 1);
|
|
472
|
-
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
473
|
-
|
|
474
|
-
// src/utils/codegen.ts
|
|
475
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
476
|
-
var import_tinyglobby = require("tinyglobby");
|
|
477
|
-
function ident(code, tab = 1) {
|
|
478
|
-
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// src/core.ts
|
|
482
|
-
async function getPlugins(pluginOptions) {
|
|
483
|
-
const plugins = [];
|
|
484
|
-
for await (const option of pluginOptions) {
|
|
485
|
-
if (!option) continue;
|
|
486
|
-
if (Array.isArray(option)) plugins.push(...await getPlugins(option));
|
|
487
|
-
else plugins.push(option);
|
|
488
|
-
}
|
|
489
|
-
return plugins;
|
|
490
|
-
}
|
|
491
|
-
function createCore(options, defaultPlugins = []) {
|
|
492
|
-
let config;
|
|
493
|
-
let plugins;
|
|
494
|
-
async function transformMetadata({
|
|
495
|
-
collection,
|
|
496
|
-
filePath,
|
|
497
|
-
source
|
|
498
|
-
}, data) {
|
|
499
|
-
if (collection.schema) {
|
|
500
|
-
data = await validate(
|
|
501
|
-
collection.schema,
|
|
502
|
-
data,
|
|
503
|
-
{ path: filePath, source },
|
|
504
|
-
collection.type === "doc" ? `invalid frontmatter in ${filePath}` : `invalid data in ${filePath}`
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
return data;
|
|
508
|
-
}
|
|
509
|
-
const core2 = {
|
|
510
|
-
/**
|
|
511
|
-
* Convenient cache store, reset when config changes
|
|
512
|
-
*/
|
|
513
|
-
cache: /* @__PURE__ */ new Map(),
|
|
514
|
-
async init({ config: newConfig }) {
|
|
515
|
-
config = await newConfig;
|
|
516
|
-
this.cache.clear();
|
|
517
|
-
plugins = await getPlugins([
|
|
518
|
-
postprocessPlugin(),
|
|
519
|
-
...defaultPlugins,
|
|
520
|
-
...config.global.plugins ?? []
|
|
521
|
-
]);
|
|
522
|
-
for (const plugin of plugins) {
|
|
523
|
-
const out = await plugin.config?.call(pluginContext, config);
|
|
524
|
-
if (out) config = out;
|
|
525
|
-
}
|
|
526
|
-
},
|
|
527
|
-
getOptions() {
|
|
528
|
-
return options;
|
|
529
|
-
},
|
|
530
|
-
getConfig() {
|
|
531
|
-
return config;
|
|
532
|
-
},
|
|
533
|
-
/**
|
|
534
|
-
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
535
|
-
*/
|
|
536
|
-
getCompiledConfigPath() {
|
|
537
|
-
return import_node_path3.default.join(options.outDir, "source.config.mjs");
|
|
538
|
-
},
|
|
539
|
-
getPlugins() {
|
|
540
|
-
return plugins;
|
|
541
|
-
},
|
|
542
|
-
getPluginContext() {
|
|
543
|
-
return pluginContext;
|
|
544
|
-
},
|
|
545
|
-
async initServer(server) {
|
|
546
|
-
for (const plugin of plugins) {
|
|
547
|
-
await plugin.configureServer?.call(pluginContext, server);
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
|
-
async emit({ filterPlugin = () => true } = {}) {
|
|
551
|
-
return (await Promise.all(
|
|
552
|
-
plugins.map((plugin) => {
|
|
553
|
-
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
554
|
-
return plugin.emit.call(pluginContext);
|
|
555
|
-
})
|
|
556
|
-
)).flat();
|
|
557
|
-
},
|
|
558
|
-
async emitAndWrite(emitOptions) {
|
|
559
|
-
const start = performance.now();
|
|
560
|
-
const out = await this.emit(emitOptions);
|
|
561
|
-
await Promise.all(
|
|
562
|
-
out.map(async (entry) => {
|
|
563
|
-
const file = import_node_path3.default.join(options.outDir, entry.path);
|
|
564
|
-
await import_promises3.default.mkdir(import_node_path3.default.dirname(file), { recursive: true });
|
|
565
|
-
await import_promises3.default.writeFile(file, entry.content);
|
|
566
|
-
})
|
|
567
|
-
);
|
|
568
|
-
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
569
|
-
},
|
|
570
|
-
async transformMeta(options2, data) {
|
|
571
|
-
const ctx = {
|
|
572
|
-
...pluginContext,
|
|
573
|
-
...options2
|
|
574
|
-
};
|
|
575
|
-
data = await transformMetadata(options2, data);
|
|
576
|
-
for (const plugin of plugins) {
|
|
577
|
-
if (plugin.meta?.transform)
|
|
578
|
-
data = await plugin.meta.transform.call(ctx, data) ?? data;
|
|
579
|
-
}
|
|
580
|
-
return data;
|
|
581
|
-
},
|
|
582
|
-
async transformFrontmatter(options2, data) {
|
|
583
|
-
const ctx = {
|
|
584
|
-
...pluginContext,
|
|
585
|
-
...options2
|
|
586
|
-
};
|
|
587
|
-
data = await transformMetadata(options2, data);
|
|
588
|
-
for (const plugin of plugins) {
|
|
589
|
-
if (plugin.doc?.frontmatter)
|
|
590
|
-
data = await plugin.doc.frontmatter.call(ctx, data) ?? data;
|
|
591
|
-
}
|
|
592
|
-
return data;
|
|
593
|
-
},
|
|
594
|
-
async transformVFile(options2, file) {
|
|
595
|
-
const ctx = {
|
|
596
|
-
...pluginContext,
|
|
597
|
-
...options2
|
|
598
|
-
};
|
|
599
|
-
for (const plugin of plugins) {
|
|
600
|
-
if (plugin.doc?.vfile)
|
|
601
|
-
file = await plugin.doc.vfile.call(ctx, file) ?? file;
|
|
602
|
-
}
|
|
603
|
-
return file;
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
const pluginContext = {
|
|
607
|
-
core: core2,
|
|
608
|
-
...options
|
|
609
|
-
};
|
|
610
|
-
return core2;
|
|
611
|
-
}
|
|
612
|
-
function postprocessPlugin() {
|
|
613
|
-
const LinkReferenceTypes = `{
|
|
614
|
-
/**
|
|
615
|
-
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
616
|
-
*/
|
|
617
|
-
extractedReferences?: import('fumadocs-mdx').ExtractedReference[];
|
|
618
|
-
}`;
|
|
619
|
-
return {
|
|
620
|
-
"index-file": {
|
|
621
|
-
generateTypeConfig() {
|
|
622
|
-
const lines = [];
|
|
623
|
-
lines.push("{");
|
|
624
|
-
lines.push(" DocData: {");
|
|
625
|
-
for (const collection of this.core.getConfig().collectionList) {
|
|
626
|
-
let postprocessOptions;
|
|
627
|
-
switch (collection.type) {
|
|
628
|
-
case "doc":
|
|
629
|
-
postprocessOptions = collection.postprocess;
|
|
630
|
-
break;
|
|
631
|
-
case "docs":
|
|
632
|
-
postprocessOptions = collection.docs.postprocess;
|
|
633
|
-
break;
|
|
634
|
-
}
|
|
635
|
-
if (postprocessOptions?.extractLinkReferences) {
|
|
636
|
-
lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
lines.push(" }");
|
|
640
|
-
lines.push("}");
|
|
641
|
-
return lines.join("\n");
|
|
642
|
-
},
|
|
643
|
-
serverOptions(options) {
|
|
644
|
-
options.doc ??= {};
|
|
645
|
-
options.doc.passthroughs ??= [];
|
|
646
|
-
options.doc.passthroughs.push("extractedReferences");
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// src/webpack/index.ts
|
|
653
|
-
var core;
|
|
654
|
-
function getCore(options) {
|
|
655
|
-
return core ??= createCore({
|
|
656
|
-
environment: "webpack",
|
|
657
|
-
outDir: options.outDir,
|
|
658
|
-
configPath: options.configPath
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// src/webpack/meta.ts
|
|
663
|
-
var instance;
|
|
664
|
-
async function loader(source, callback) {
|
|
665
|
-
const options = this.getOptions();
|
|
666
|
-
this.cacheable(true);
|
|
667
|
-
this.addDependency(options.compiledConfigPath);
|
|
668
|
-
if (!instance) {
|
|
669
|
-
instance = toWebpack(
|
|
670
|
-
createMetaLoader(
|
|
671
|
-
createStandaloneConfigLoader({
|
|
672
|
-
core: getCore(options),
|
|
673
|
-
buildConfig: false,
|
|
674
|
-
mode: options.isDev ? "dev" : "production"
|
|
675
|
-
}),
|
|
676
|
-
{
|
|
677
|
-
json: "json",
|
|
678
|
-
yaml: "js"
|
|
679
|
-
}
|
|
680
|
-
)
|
|
681
|
-
);
|
|
682
|
-
}
|
|
683
|
-
await instance.call(this, source, callback);
|
|
684
|
-
}
|