fumadocs-mdx 13.0.3 → 13.0.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/bin.cjs +353 -273
- package/dist/bin.js +1 -1
- package/dist/{build-mdx-TtQzmq6W.d.cts → build-mdx-BjXOmv0b.d.cts} +1 -1
- package/dist/{build-mdx--WI4tf2-.d.ts → build-mdx-CY5UldCO.d.ts} +1 -1
- package/dist/bun/index.cjs +177 -57
- package/dist/bun/index.d.cts +2 -2
- package/dist/bun/index.d.ts +2 -2
- package/dist/bun/index.js +26 -34
- package/dist/chunk-2HXTGJBI.js +101 -0
- package/dist/chunk-4JSFLXXT.js +8 -0
- package/dist/{chunk-JVZFH6ND.js → chunk-QXHN25N3.js} +2 -2
- package/dist/{chunk-EELYB2XC.js → chunk-TZ5EQBFW.js} +9 -103
- package/dist/chunk-VUEZTR2H.js +26 -0
- package/dist/{chunk-XQ5O7IPO.js → chunk-XYGORKQA.js} +5 -3
- package/dist/chunk-YAIPHUCZ.js +56 -0
- package/dist/chunk-ZNVPB2IR.js +170 -0
- package/dist/config/index.d.cts +2 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/{core-DhfmVKRA.d.cts → core-DB7TdlyC.d.cts} +21 -7
- package/dist/{core-DhfmVKRA.d.ts → core-DB7TdlyC.d.ts} +21 -7
- package/dist/index-D7s7kCc2.d.cts +7 -0
- package/dist/index-D7s7kCc2.d.ts +7 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/load-from-file-AVYOFOI7.js +7 -0
- package/dist/next/index.cjs +145 -139
- package/dist/next/index.js +56 -36
- package/dist/node/loader.cjs +242 -128
- package/dist/node/loader.d.cts +2 -2
- package/dist/node/loader.d.ts +2 -2
- package/dist/node/loader.js +29 -16
- package/dist/plugins/json-schema.cjs +22 -70
- package/dist/plugins/json-schema.d.cts +2 -2
- package/dist/plugins/json-schema.d.ts +2 -2
- package/dist/plugins/json-schema.js +19 -14
- package/dist/runtime/next/async.cjs +56 -11
- package/dist/runtime/next/async.d.cts +4 -6
- package/dist/runtime/next/async.d.ts +4 -6
- package/dist/runtime/next/async.js +3 -6
- package/dist/runtime/next/index.d.cts +5 -5
- package/dist/runtime/next/index.d.ts +5 -5
- package/dist/runtime/vite/browser.d.cts +3 -3
- package/dist/runtime/vite/browser.d.ts +3 -3
- package/dist/runtime/vite/server.d.cts +3 -3
- package/dist/runtime/vite/server.d.ts +3 -3
- package/dist/{types-zrV4v6mp.d.cts → types-Bnh9n7mj.d.cts} +2 -2
- package/dist/{types-CMva20Zp.d.ts → types-ey1AZqrg.d.ts} +2 -2
- package/dist/vite/index.cjs +238 -159
- package/dist/vite/index.js +113 -118
- package/dist/webpack/{index.cjs → mdx.cjs} +126 -104
- package/dist/webpack/mdx.d.cts +6 -0
- package/dist/webpack/mdx.d.ts +6 -0
- package/dist/webpack/{index.js → mdx.js} +12 -14
- package/dist/webpack/meta.cjs +528 -0
- package/dist/webpack/meta.d.cts +6 -0
- package/dist/webpack/meta.d.ts +6 -0
- package/dist/webpack/meta.js +42 -0
- package/loader-mdx.cjs +1 -1
- package/loader-meta.cjs +7 -0
- package/package.json +6 -3
- package/dist/chunk-U4MQ44TS.js +0 -53
- package/dist/chunk-XZY2AWJI.js +0 -81
- package/dist/chunk-YVCR6FUH.js +0 -82
- package/dist/load-MNG3CLET.js +0 -7
- package/dist/webpack/index.d.cts +0 -15
- package/dist/webpack/index.d.ts +0 -15
package/dist/next/index.cjs
CHANGED
|
@@ -117,36 +117,97 @@ var init_preset = __esm({
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
// src/next/index.ts
|
|
121
|
+
var next_exports = {};
|
|
122
|
+
__export(next_exports, {
|
|
123
|
+
createMDX: () => createMDX,
|
|
124
|
+
postInstall: () => postInstall
|
|
125
|
+
});
|
|
126
|
+
module.exports = __toCommonJS(next_exports);
|
|
127
|
+
var path7 = __toESM(require("path"), 1);
|
|
128
|
+
|
|
129
|
+
// src/config/load-from-file.ts
|
|
130
|
+
var path = __toESM(require("path"), 1);
|
|
131
|
+
var import_node_url = require("url");
|
|
132
|
+
|
|
120
133
|
// src/config/build.ts
|
|
134
|
+
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
135
|
+
var SupportedFormats = {
|
|
136
|
+
doc: ["mdx", "md"],
|
|
137
|
+
meta: ["json", "yaml"]
|
|
138
|
+
};
|
|
139
|
+
function buildCollection(name, config) {
|
|
140
|
+
if (config.type === "docs") {
|
|
141
|
+
return {
|
|
142
|
+
...config,
|
|
143
|
+
name,
|
|
144
|
+
meta: buildPrimitiveCollection(name, config.meta),
|
|
145
|
+
docs: buildPrimitiveCollection(name, config.docs)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return buildPrimitiveCollection(name, config);
|
|
149
|
+
}
|
|
150
|
+
function buildPrimitiveCollection(name, { files, ...config }) {
|
|
151
|
+
const supportedFormats = SupportedFormats[config.type];
|
|
152
|
+
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
153
|
+
let matchers;
|
|
154
|
+
return {
|
|
155
|
+
...config,
|
|
156
|
+
name,
|
|
157
|
+
patterns,
|
|
158
|
+
isFileSupported(filePath) {
|
|
159
|
+
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
160
|
+
},
|
|
161
|
+
hasFile(filePath) {
|
|
162
|
+
matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
|
|
163
|
+
(dir) => (0, import_picomatch.default)(patterns, {
|
|
164
|
+
cwd: dir
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
121
171
|
function buildConfig(config) {
|
|
122
172
|
const collections = /* @__PURE__ */ new Map();
|
|
123
|
-
|
|
173
|
+
const loaded = {};
|
|
124
174
|
for (const [k, v] of Object.entries(config)) {
|
|
125
175
|
if (!v) {
|
|
126
176
|
continue;
|
|
127
177
|
}
|
|
128
178
|
if (typeof v === "object" && "type" in v) {
|
|
129
179
|
if (v.type === "docs") {
|
|
130
|
-
collections.set(k, v);
|
|
180
|
+
collections.set(k, buildCollection(k, v));
|
|
131
181
|
continue;
|
|
132
182
|
}
|
|
133
183
|
if (v.type === "doc" || v.type === "meta") {
|
|
134
|
-
collections.set(
|
|
184
|
+
collections.set(
|
|
185
|
+
k,
|
|
186
|
+
buildCollection(k, v)
|
|
187
|
+
);
|
|
135
188
|
continue;
|
|
136
189
|
}
|
|
137
190
|
}
|
|
138
191
|
if (k === "default" && v) {
|
|
139
|
-
|
|
192
|
+
Object.assign(loaded, v);
|
|
140
193
|
continue;
|
|
141
194
|
}
|
|
142
195
|
throw new Error(
|
|
143
196
|
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
144
197
|
);
|
|
145
198
|
}
|
|
199
|
+
if (loaded.collections) {
|
|
200
|
+
for (const [k, v] of Object.entries(loaded.collections)) {
|
|
201
|
+
collections.set(k, buildCollection(k, v));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
146
204
|
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
147
205
|
return {
|
|
148
|
-
global:
|
|
149
|
-
collections,
|
|
206
|
+
global: loaded,
|
|
207
|
+
collectionList: Array.from(collections.values()),
|
|
208
|
+
getCollection(name) {
|
|
209
|
+
return collections.get(name);
|
|
210
|
+
},
|
|
150
211
|
async getDefaultMDXOptions(mode = "default") {
|
|
151
212
|
const cached = mdxOptionsCache.get(mode);
|
|
152
213
|
if (cached) return cached;
|
|
@@ -166,13 +227,8 @@ function buildConfig(config) {
|
|
|
166
227
|
}
|
|
167
228
|
};
|
|
168
229
|
}
|
|
169
|
-
var init_build = __esm({
|
|
170
|
-
"src/config/build.ts"() {
|
|
171
|
-
"use strict";
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
230
|
|
|
175
|
-
// src/
|
|
231
|
+
// src/config/load-from-file.ts
|
|
176
232
|
async function compileConfig(configPath, outDir) {
|
|
177
233
|
const { build } = await import("esbuild");
|
|
178
234
|
const transformed = await build({
|
|
@@ -195,52 +251,24 @@ async function compileConfig(configPath, outDir) {
|
|
|
195
251
|
}
|
|
196
252
|
async function loadConfig(configPath, outDir, build = false) {
|
|
197
253
|
if (build) await compileConfig(configPath, outDir);
|
|
198
|
-
const url = (0, import_node_url.pathToFileURL)(
|
|
254
|
+
const url = (0, import_node_url.pathToFileURL)(path.resolve(outDir, "source.config.mjs"));
|
|
199
255
|
url.searchParams.set("hash", Date.now().toString());
|
|
200
256
|
const config = import(url.href).then(
|
|
201
257
|
(loaded) => buildConfig(loaded)
|
|
202
258
|
);
|
|
203
259
|
return await config;
|
|
204
260
|
}
|
|
205
|
-
var path2, import_node_url;
|
|
206
|
-
var init_load = __esm({
|
|
207
|
-
"src/loaders/config/load.ts"() {
|
|
208
|
-
"use strict";
|
|
209
|
-
path2 = __toESM(require("path"), 1);
|
|
210
|
-
import_node_url = require("url");
|
|
211
|
-
init_build();
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
// src/next/index.ts
|
|
216
|
-
var next_exports = {};
|
|
217
|
-
__export(next_exports, {
|
|
218
|
-
createMDX: () => createMDX,
|
|
219
|
-
postInstall: () => postInstall
|
|
220
|
-
});
|
|
221
|
-
module.exports = __toCommonJS(next_exports);
|
|
222
|
-
|
|
223
|
-
// src/loaders/config/index.ts
|
|
224
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
225
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
226
|
-
function findConfigFile() {
|
|
227
|
-
return import_node_path.default.resolve("source.config.ts");
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// src/next/index.ts
|
|
231
|
-
var path9 = __toESM(require("path"), 1);
|
|
232
|
-
init_load();
|
|
233
261
|
|
|
234
262
|
// src/next/file-cache.ts
|
|
235
263
|
var import_lru_cache = require("lru-cache");
|
|
236
|
-
var
|
|
237
|
-
var
|
|
264
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
265
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
238
266
|
var map = new import_lru_cache.LRUCache({
|
|
239
267
|
max: 100
|
|
240
268
|
});
|
|
241
269
|
function toFullPath(file) {
|
|
242
|
-
if (
|
|
243
|
-
return
|
|
270
|
+
if (import_node_path.default.isAbsolute(file)) {
|
|
271
|
+
return import_node_path.default.relative(process.cwd(), file);
|
|
244
272
|
}
|
|
245
273
|
return file;
|
|
246
274
|
}
|
|
@@ -248,7 +276,7 @@ async function readFileWithCache(file) {
|
|
|
248
276
|
const fullPath = toFullPath(file);
|
|
249
277
|
const cached = map.get(fullPath);
|
|
250
278
|
if (cached) return cached;
|
|
251
|
-
const read =
|
|
279
|
+
const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
|
|
252
280
|
map.set(fullPath, read);
|
|
253
281
|
return read;
|
|
254
282
|
}
|
|
@@ -295,12 +323,11 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
295
323
|
}
|
|
296
324
|
|
|
297
325
|
// src/plugins/next.ts
|
|
298
|
-
var
|
|
326
|
+
var path5 = __toESM(require("path"), 1);
|
|
299
327
|
var import_node_crypto = require("crypto");
|
|
300
|
-
var import_js_yaml2 = require("js-yaml");
|
|
301
328
|
|
|
302
329
|
// src/utils/git-timestamp.ts
|
|
303
|
-
var
|
|
330
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
304
331
|
var import_tinyexec = require("tinyexec");
|
|
305
332
|
var cache = /* @__PURE__ */ new Map();
|
|
306
333
|
async function getGitTimestamp(file) {
|
|
@@ -309,7 +336,7 @@ async function getGitTimestamp(file) {
|
|
|
309
336
|
try {
|
|
310
337
|
const out = await (0, import_tinyexec.x)(
|
|
311
338
|
"git",
|
|
312
|
-
["log", "-1", '--pretty="%ai"',
|
|
339
|
+
["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
|
|
313
340
|
{
|
|
314
341
|
throwOnError: true
|
|
315
342
|
}
|
|
@@ -339,7 +366,7 @@ function fumaMatter(input) {
|
|
|
339
366
|
}
|
|
340
367
|
|
|
341
368
|
// src/utils/import-formatter.ts
|
|
342
|
-
var
|
|
369
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
343
370
|
function getImportCode(info) {
|
|
344
371
|
const specifier = JSON.stringify(info.specifier);
|
|
345
372
|
if (info.type === "default") return `import ${info.name} from ${specifier}`;
|
|
@@ -354,7 +381,7 @@ function getImportCode(info) {
|
|
|
354
381
|
return `import ${specifier}`;
|
|
355
382
|
}
|
|
356
383
|
function toImportPath(file, config) {
|
|
357
|
-
const ext =
|
|
384
|
+
const ext = import_node_path3.default.extname(file);
|
|
358
385
|
let filename;
|
|
359
386
|
if (ext === ".ts" && config.jsExtension) {
|
|
360
387
|
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
@@ -365,56 +392,18 @@ function toImportPath(file, config) {
|
|
|
365
392
|
}
|
|
366
393
|
let importPath;
|
|
367
394
|
if ("relativeTo" in config) {
|
|
368
|
-
importPath =
|
|
369
|
-
if (!
|
|
395
|
+
importPath = import_node_path3.default.relative(config.relativeTo, filename);
|
|
396
|
+
if (!import_node_path3.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
370
397
|
importPath = `./${importPath}`;
|
|
371
398
|
}
|
|
372
399
|
} else {
|
|
373
|
-
importPath =
|
|
400
|
+
importPath = import_node_path3.default.resolve(filename);
|
|
374
401
|
}
|
|
375
|
-
return importPath.replaceAll(
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// src/utils/collections.ts
|
|
379
|
-
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
380
|
-
var import_tinyglobby = require("tinyglobby");
|
|
381
|
-
var import_node_path5 = __toESM(require("path"), 1);
|
|
382
|
-
var SupportedFormats = {
|
|
383
|
-
doc: ["mdx", "md"],
|
|
384
|
-
meta: ["json", "yaml"]
|
|
385
|
-
};
|
|
386
|
-
function getGlobPatterns(collection) {
|
|
387
|
-
if (collection.files) return collection.files;
|
|
388
|
-
return [`**/*.{${SupportedFormats[collection.type].join(",")}}`];
|
|
389
|
-
}
|
|
390
|
-
function isFileSupported(filePath, collection) {
|
|
391
|
-
return SupportedFormats[collection.type].some(
|
|
392
|
-
(format) => filePath.endsWith(`.${format}`)
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
async function getCollectionFiles(collection) {
|
|
396
|
-
const files = /* @__PURE__ */ new Map();
|
|
397
|
-
const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
|
|
398
|
-
const patterns = getGlobPatterns(collection);
|
|
399
|
-
await Promise.all(
|
|
400
|
-
dirs.map(async (dir) => {
|
|
401
|
-
const result = await (0, import_tinyglobby.glob)(patterns, {
|
|
402
|
-
cwd: import_node_path5.default.resolve(dir)
|
|
403
|
-
});
|
|
404
|
-
for (const item of result) {
|
|
405
|
-
if (!isFileSupported(item, collection)) continue;
|
|
406
|
-
const fullPath = import_node_path5.default.join(dir, item);
|
|
407
|
-
files.set(fullPath, {
|
|
408
|
-
path: item,
|
|
409
|
-
fullPath
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
})
|
|
413
|
-
);
|
|
414
|
-
return Array.from(files.values());
|
|
402
|
+
return importPath.replaceAll(import_node_path3.default.sep, "/");
|
|
415
403
|
}
|
|
416
404
|
|
|
417
405
|
// src/plugins/next.ts
|
|
406
|
+
var import_js_yaml2 = require("js-yaml");
|
|
418
407
|
function next() {
|
|
419
408
|
let config;
|
|
420
409
|
let shouldEmitOnChange = false;
|
|
@@ -422,11 +411,9 @@ function next() {
|
|
|
422
411
|
name: "next",
|
|
423
412
|
config(v) {
|
|
424
413
|
config = v;
|
|
425
|
-
shouldEmitOnChange =
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
);
|
|
414
|
+
shouldEmitOnChange = config.collectionList.some((collection) => {
|
|
415
|
+
return collection.type === "doc" && collection.async || collection.type === "docs" || collection.type === "meta";
|
|
416
|
+
});
|
|
430
417
|
},
|
|
431
418
|
configureServer(server) {
|
|
432
419
|
if (!server.watcher) return;
|
|
@@ -449,7 +436,7 @@ function next() {
|
|
|
449
436
|
}
|
|
450
437
|
};
|
|
451
438
|
}
|
|
452
|
-
async function indexFile(configPath, config, importPath
|
|
439
|
+
async function indexFile(configPath, config, importPath) {
|
|
453
440
|
let asyncInit = false;
|
|
454
441
|
const lines = [
|
|
455
442
|
getImportCode({
|
|
@@ -463,14 +450,10 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
463
450
|
name: "_source"
|
|
464
451
|
})
|
|
465
452
|
];
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
-
const params = [`collection=${collectionName}`];
|
|
471
|
-
if (configHash) {
|
|
472
|
-
params.push(`hash=${configHash}`);
|
|
473
|
-
}
|
|
453
|
+
function getDocEntries(collection, files) {
|
|
454
|
+
return files.map((file, i) => {
|
|
455
|
+
const importId = `d_${collection.name}_${i}`;
|
|
456
|
+
const params = [`collection=${collection.name}`];
|
|
474
457
|
lines.unshift(
|
|
475
458
|
getImportCode({
|
|
476
459
|
type: "namespace",
|
|
@@ -480,7 +463,6 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
480
463
|
);
|
|
481
464
|
return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
|
|
482
465
|
});
|
|
483
|
-
return Promise.all(items);
|
|
484
466
|
}
|
|
485
467
|
async function getMetaEntries(collection, files) {
|
|
486
468
|
const items = files.map(async (file) => {
|
|
@@ -521,7 +503,7 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
521
503
|
);
|
|
522
504
|
asyncInit = true;
|
|
523
505
|
}
|
|
524
|
-
const
|
|
506
|
+
const entries = files.map(async (file) => {
|
|
525
507
|
const content = await readFileWithCache(file.fullPath).catch(() => "");
|
|
526
508
|
const parsed = fumaMatter(content);
|
|
527
509
|
let data = parsed.data;
|
|
@@ -547,12 +529,13 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
547
529
|
);
|
|
548
530
|
return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
|
|
549
531
|
});
|
|
550
|
-
return Promise.all(
|
|
532
|
+
return Promise.all(entries);
|
|
551
533
|
}
|
|
552
|
-
const declares =
|
|
534
|
+
const declares = config.collectionList.map(async (collection) => {
|
|
535
|
+
const k = collection.name;
|
|
553
536
|
if (collection.type === "docs") {
|
|
554
|
-
const docs = await
|
|
555
|
-
const metas = await
|
|
537
|
+
const docs = await globCollectionFiles(collection.docs);
|
|
538
|
+
const metas = await globCollectionFiles(collection.meta);
|
|
556
539
|
const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
|
|
557
540
|
", "
|
|
558
541
|
);
|
|
@@ -562,14 +545,17 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
562
545
|
);
|
|
563
546
|
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
|
|
564
547
|
}
|
|
565
|
-
const docsEntries =
|
|
548
|
+
const docsEntries = getDocEntries(collection.docs, docs).join(", ");
|
|
566
549
|
return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
|
|
567
550
|
}
|
|
568
|
-
const files = await
|
|
569
|
-
if (collection.type === "
|
|
551
|
+
const files = await globCollectionFiles(collection);
|
|
552
|
+
if (collection.type === "meta") {
|
|
553
|
+
return `export const ${k} = _runtime.meta<typeof _source.${k}>([${(await getMetaEntries(collection, files)).join(", ")}]);`;
|
|
554
|
+
}
|
|
555
|
+
if (collection.async) {
|
|
570
556
|
return `export const ${k} = _runtimeAsync.doc<typeof _source.${k}>([${(await getAsyncEntries(collection, files)).join(", ")}], "${k}", _sourceConfig)`;
|
|
571
557
|
}
|
|
572
|
-
return `export const ${k} = _runtime
|
|
558
|
+
return `export const ${k} = _runtime.doc<typeof _source.${k}>([${getDocEntries(collection, files).join(", ")}]);`;
|
|
573
559
|
});
|
|
574
560
|
const resolvedDeclares = await Promise.all(declares);
|
|
575
561
|
return [
|
|
@@ -579,7 +565,7 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
579
565
|
].join("\n");
|
|
580
566
|
}
|
|
581
567
|
function parseMetaEntry(file, content) {
|
|
582
|
-
const extname2 =
|
|
568
|
+
const extname2 = path5.extname(file);
|
|
583
569
|
try {
|
|
584
570
|
if (extname2 === ".json") return JSON.parse(content);
|
|
585
571
|
if (extname2 === ".yaml") return (0, import_js_yaml2.load)(content);
|
|
@@ -590,10 +576,34 @@ function parseMetaEntry(file, content) {
|
|
|
590
576
|
}
|
|
591
577
|
throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
|
|
592
578
|
}
|
|
579
|
+
async function globCollectionFiles(collection) {
|
|
580
|
+
const { glob } = await import("tinyglobby");
|
|
581
|
+
const files = /* @__PURE__ */ new Map();
|
|
582
|
+
const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
|
|
583
|
+
await Promise.all(
|
|
584
|
+
dirs.map(async (dir) => {
|
|
585
|
+
const result = await glob(collection.patterns, {
|
|
586
|
+
cwd: path5.resolve(dir)
|
|
587
|
+
});
|
|
588
|
+
for (const item of result) {
|
|
589
|
+
if (!collection.isFileSupported(item)) continue;
|
|
590
|
+
const fullPath = path5.join(dir, item);
|
|
591
|
+
files.set(fullPath, {
|
|
592
|
+
path: item,
|
|
593
|
+
fullPath
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
})
|
|
597
|
+
);
|
|
598
|
+
return Array.from(files.values());
|
|
599
|
+
}
|
|
593
600
|
|
|
594
601
|
// src/core.ts
|
|
595
|
-
var
|
|
596
|
-
var
|
|
602
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
603
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
604
|
+
function findConfigFile() {
|
|
605
|
+
return import_node_path4.default.resolve("source.config.ts");
|
|
606
|
+
}
|
|
597
607
|
function createCore(options, defaultPlugins = []) {
|
|
598
608
|
let config;
|
|
599
609
|
let plugins2;
|
|
@@ -630,13 +640,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
630
640
|
getConfig() {
|
|
631
641
|
return config;
|
|
632
642
|
},
|
|
633
|
-
creatConfigLoader() {
|
|
634
|
-
return {
|
|
635
|
-
getConfig() {
|
|
636
|
-
return config;
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
},
|
|
640
643
|
async initServer(server) {
|
|
641
644
|
for (const plugin of plugins2) {
|
|
642
645
|
await plugin.configureServer?.call(this.getPluginContext(), server);
|
|
@@ -654,9 +657,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
654
657
|
);
|
|
655
658
|
await Promise.all(
|
|
656
659
|
out.flat().map(async (entry) => {
|
|
657
|
-
const file =
|
|
658
|
-
await
|
|
659
|
-
await
|
|
660
|
+
const file = import_node_path4.default.join(options.outDir, entry.path);
|
|
661
|
+
await import_promises2.default.mkdir(import_node_path4.default.dirname(file), { recursive: true });
|
|
662
|
+
await import_promises2.default.writeFile(file, entry.content);
|
|
660
663
|
})
|
|
661
664
|
);
|
|
662
665
|
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
@@ -664,6 +667,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
664
667
|
};
|
|
665
668
|
}
|
|
666
669
|
|
|
670
|
+
// src/loaders/index.ts
|
|
671
|
+
var mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
672
|
+
|
|
667
673
|
// src/next/index.ts
|
|
668
674
|
var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
|
|
669
675
|
function createMDX(createOptions = {}) {
|
|
@@ -674,7 +680,7 @@ function createMDX(createOptions = {}) {
|
|
|
674
680
|
void init(isDev, options);
|
|
675
681
|
}
|
|
676
682
|
return (nextConfig = {}) => {
|
|
677
|
-
const
|
|
683
|
+
const loaderOptions = {
|
|
678
684
|
...options,
|
|
679
685
|
isDev
|
|
680
686
|
};
|
|
@@ -686,7 +692,7 @@ function createMDX(createOptions = {}) {
|
|
|
686
692
|
loaders: [
|
|
687
693
|
{
|
|
688
694
|
loader: "fumadocs-mdx/loader-mdx",
|
|
689
|
-
options:
|
|
695
|
+
options: loaderOptions
|
|
690
696
|
}
|
|
691
697
|
],
|
|
692
698
|
as: "*.js"
|
|
@@ -702,12 +708,12 @@ function createMDX(createOptions = {}) {
|
|
|
702
708
|
config.module ||= {};
|
|
703
709
|
config.module.rules ||= [];
|
|
704
710
|
config.module.rules.push({
|
|
705
|
-
test:
|
|
711
|
+
test: mdxLoaderGlob,
|
|
706
712
|
use: [
|
|
707
713
|
options2.defaultLoaders.babel,
|
|
708
714
|
{
|
|
709
715
|
loader: "fumadocs-mdx/loader-mdx",
|
|
710
|
-
options:
|
|
716
|
+
options: loaderOptions
|
|
711
717
|
}
|
|
712
718
|
]
|
|
713
719
|
});
|
|
@@ -733,7 +739,7 @@ async function init(dev, options) {
|
|
|
733
739
|
ignored: [options.outDir]
|
|
734
740
|
});
|
|
735
741
|
watcher.add(options.configPath);
|
|
736
|
-
for (const collection of core.getConfig().
|
|
742
|
+
for (const collection of core.getConfig().collectionList) {
|
|
737
743
|
if (collection.type === "docs") {
|
|
738
744
|
watcher.add(collection.docs.dir);
|
|
739
745
|
watcher.add(collection.meta.dir);
|
|
@@ -745,9 +751,9 @@ async function init(dev, options) {
|
|
|
745
751
|
console.log("[MDX] started dev server");
|
|
746
752
|
});
|
|
747
753
|
watcher.on("all", async (event, file) => {
|
|
748
|
-
const absolutePath =
|
|
754
|
+
const absolutePath = path7.resolve(file);
|
|
749
755
|
if (event === "change") removeFileCache(absolutePath);
|
|
750
|
-
if (absolutePath ===
|
|
756
|
+
if (absolutePath === path7.resolve(options.configPath)) {
|
|
751
757
|
watcher.removeAllListeners();
|
|
752
758
|
await watcher.close();
|
|
753
759
|
await initOrReload();
|