fumadocs-mdx 13.0.2 → 13.0.4
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 +381 -279
- package/dist/{build-mdx-D-r3_eQL.d.cts → build-mdx-BjXOmv0b.d.cts} +1 -1
- package/dist/{build-mdx-CCNr86q6.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-B6j6Fxse.d.cts → core-DB7TdlyC.d.cts} +23 -7
- package/dist/{core-B6j6Fxse.d.ts → core-DB7TdlyC.d.ts} +23 -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 +147 -142
- package/dist/next/index.js +58 -39
- 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-DKGMoay5.d.cts → types-Bnh9n7mj.d.cts} +2 -2
- package/dist/{types-AGzTfBmf.d.ts → types-ey1AZqrg.d.ts} +2 -2
- package/dist/vite/index.cjs +265 -163
- package/dist/vite/index.d.cts +4 -0
- package/dist/vite/index.d.ts +4 -0
- package/dist/vite/index.js +140 -122
- 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 +11 -8
- 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,17 +411,14 @@ function next() {
|
|
|
422
411
|
name: "next",
|
|
423
412
|
config(v) {
|
|
424
413
|
config = v;
|
|
425
|
-
shouldEmitOnChange =
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
shouldEmitOnChange = true;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
414
|
+
shouldEmitOnChange = config.collectionList.some((collection) => {
|
|
415
|
+
return collection.type === "doc" && collection.async || collection.type === "docs" || collection.type === "meta";
|
|
416
|
+
});
|
|
431
417
|
},
|
|
432
418
|
configureServer(server) {
|
|
433
419
|
if (!server.watcher) return;
|
|
434
|
-
server.watcher.on("all", async () => {
|
|
435
|
-
if (!shouldEmitOnChange) return;
|
|
420
|
+
server.watcher.on("all", async (event) => {
|
|
421
|
+
if (event === "change" && !shouldEmitOnChange) return;
|
|
436
422
|
await this.core.emitAndWrite({
|
|
437
423
|
filterPlugin: (plugin) => plugin.name === "next"
|
|
438
424
|
});
|
|
@@ -450,7 +436,7 @@ function next() {
|
|
|
450
436
|
}
|
|
451
437
|
};
|
|
452
438
|
}
|
|
453
|
-
async function indexFile(configPath, config, importPath
|
|
439
|
+
async function indexFile(configPath, config, importPath) {
|
|
454
440
|
let asyncInit = false;
|
|
455
441
|
const lines = [
|
|
456
442
|
getImportCode({
|
|
@@ -464,14 +450,10 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
464
450
|
name: "_source"
|
|
465
451
|
})
|
|
466
452
|
];
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
const params = [`collection=${collectionName}`];
|
|
472
|
-
if (configHash) {
|
|
473
|
-
params.push(`hash=${configHash}`);
|
|
474
|
-
}
|
|
453
|
+
function getDocEntries(collection, files) {
|
|
454
|
+
return files.map((file, i) => {
|
|
455
|
+
const importId = `d_${collection.name}_${i}`;
|
|
456
|
+
const params = [`collection=${collection.name}`];
|
|
475
457
|
lines.unshift(
|
|
476
458
|
getImportCode({
|
|
477
459
|
type: "namespace",
|
|
@@ -481,7 +463,6 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
481
463
|
);
|
|
482
464
|
return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
|
|
483
465
|
});
|
|
484
|
-
return Promise.all(items);
|
|
485
466
|
}
|
|
486
467
|
async function getMetaEntries(collection, files) {
|
|
487
468
|
const items = files.map(async (file) => {
|
|
@@ -522,7 +503,7 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
522
503
|
);
|
|
523
504
|
asyncInit = true;
|
|
524
505
|
}
|
|
525
|
-
const
|
|
506
|
+
const entries = files.map(async (file) => {
|
|
526
507
|
const content = await readFileWithCache(file.fullPath).catch(() => "");
|
|
527
508
|
const parsed = fumaMatter(content);
|
|
528
509
|
let data = parsed.data;
|
|
@@ -548,12 +529,13 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
548
529
|
);
|
|
549
530
|
return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
|
|
550
531
|
});
|
|
551
|
-
return Promise.all(
|
|
532
|
+
return Promise.all(entries);
|
|
552
533
|
}
|
|
553
|
-
const declares =
|
|
534
|
+
const declares = config.collectionList.map(async (collection) => {
|
|
535
|
+
const k = collection.name;
|
|
554
536
|
if (collection.type === "docs") {
|
|
555
|
-
const docs = await
|
|
556
|
-
const metas = await
|
|
537
|
+
const docs = await globCollectionFiles(collection.docs);
|
|
538
|
+
const metas = await globCollectionFiles(collection.meta);
|
|
557
539
|
const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
|
|
558
540
|
", "
|
|
559
541
|
);
|
|
@@ -563,14 +545,17 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
563
545
|
);
|
|
564
546
|
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
|
|
565
547
|
}
|
|
566
|
-
const docsEntries =
|
|
548
|
+
const docsEntries = getDocEntries(collection.docs, docs).join(", ");
|
|
567
549
|
return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
|
|
568
550
|
}
|
|
569
|
-
const files = await
|
|
570
|
-
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) {
|
|
571
556
|
return `export const ${k} = _runtimeAsync.doc<typeof _source.${k}>([${(await getAsyncEntries(collection, files)).join(", ")}], "${k}", _sourceConfig)`;
|
|
572
557
|
}
|
|
573
|
-
return `export const ${k} = _runtime
|
|
558
|
+
return `export const ${k} = _runtime.doc<typeof _source.${k}>([${getDocEntries(collection, files).join(", ")}]);`;
|
|
574
559
|
});
|
|
575
560
|
const resolvedDeclares = await Promise.all(declares);
|
|
576
561
|
return [
|
|
@@ -580,7 +565,7 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
580
565
|
].join("\n");
|
|
581
566
|
}
|
|
582
567
|
function parseMetaEntry(file, content) {
|
|
583
|
-
const extname2 =
|
|
568
|
+
const extname2 = path5.extname(file);
|
|
584
569
|
try {
|
|
585
570
|
if (extname2 === ".json") return JSON.parse(content);
|
|
586
571
|
if (extname2 === ".yaml") return (0, import_js_yaml2.load)(content);
|
|
@@ -591,10 +576,34 @@ function parseMetaEntry(file, content) {
|
|
|
591
576
|
}
|
|
592
577
|
throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
|
|
593
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
|
+
}
|
|
594
600
|
|
|
595
601
|
// src/core.ts
|
|
596
|
-
var
|
|
597
|
-
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
|
+
}
|
|
598
607
|
function createCore(options, defaultPlugins = []) {
|
|
599
608
|
let config;
|
|
600
609
|
let plugins2;
|
|
@@ -631,13 +640,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
631
640
|
getConfig() {
|
|
632
641
|
return config;
|
|
633
642
|
},
|
|
634
|
-
creatConfigLoader() {
|
|
635
|
-
return {
|
|
636
|
-
getConfig() {
|
|
637
|
-
return config;
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
},
|
|
641
643
|
async initServer(server) {
|
|
642
644
|
for (const plugin of plugins2) {
|
|
643
645
|
await plugin.configureServer?.call(this.getPluginContext(), server);
|
|
@@ -655,9 +657,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
655
657
|
);
|
|
656
658
|
await Promise.all(
|
|
657
659
|
out.flat().map(async (entry) => {
|
|
658
|
-
const file =
|
|
659
|
-
await
|
|
660
|
-
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);
|
|
661
663
|
})
|
|
662
664
|
);
|
|
663
665
|
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
@@ -665,6 +667,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
665
667
|
};
|
|
666
668
|
}
|
|
667
669
|
|
|
670
|
+
// src/loaders/index.ts
|
|
671
|
+
var mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
672
|
+
|
|
668
673
|
// src/next/index.ts
|
|
669
674
|
var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
|
|
670
675
|
function createMDX(createOptions = {}) {
|
|
@@ -675,7 +680,7 @@ function createMDX(createOptions = {}) {
|
|
|
675
680
|
void init(isDev, options);
|
|
676
681
|
}
|
|
677
682
|
return (nextConfig = {}) => {
|
|
678
|
-
const
|
|
683
|
+
const loaderOptions = {
|
|
679
684
|
...options,
|
|
680
685
|
isDev
|
|
681
686
|
};
|
|
@@ -687,7 +692,7 @@ function createMDX(createOptions = {}) {
|
|
|
687
692
|
loaders: [
|
|
688
693
|
{
|
|
689
694
|
loader: "fumadocs-mdx/loader-mdx",
|
|
690
|
-
options:
|
|
695
|
+
options: loaderOptions
|
|
691
696
|
}
|
|
692
697
|
],
|
|
693
698
|
as: "*.js"
|
|
@@ -703,12 +708,12 @@ function createMDX(createOptions = {}) {
|
|
|
703
708
|
config.module ||= {};
|
|
704
709
|
config.module.rules ||= [];
|
|
705
710
|
config.module.rules.push({
|
|
706
|
-
test:
|
|
711
|
+
test: mdxLoaderGlob,
|
|
707
712
|
use: [
|
|
708
713
|
options2.defaultLoaders.babel,
|
|
709
714
|
{
|
|
710
715
|
loader: "fumadocs-mdx/loader-mdx",
|
|
711
|
-
options:
|
|
716
|
+
options: loaderOptions
|
|
712
717
|
}
|
|
713
718
|
]
|
|
714
719
|
});
|
|
@@ -734,7 +739,7 @@ async function init(dev, options) {
|
|
|
734
739
|
ignored: [options.outDir]
|
|
735
740
|
});
|
|
736
741
|
watcher.add(options.configPath);
|
|
737
|
-
for (const collection of core.getConfig().
|
|
742
|
+
for (const collection of core.getConfig().collectionList) {
|
|
738
743
|
if (collection.type === "docs") {
|
|
739
744
|
watcher.add(collection.docs.dir);
|
|
740
745
|
watcher.add(collection.meta.dir);
|
|
@@ -746,9 +751,9 @@ async function init(dev, options) {
|
|
|
746
751
|
console.log("[MDX] started dev server");
|
|
747
752
|
});
|
|
748
753
|
watcher.on("all", async (event, file) => {
|
|
749
|
-
const absolutePath =
|
|
754
|
+
const absolutePath = path7.resolve(file);
|
|
750
755
|
if (event === "change") removeFileCache(absolutePath);
|
|
751
|
-
if (absolutePath ===
|
|
756
|
+
if (absolutePath === path7.resolve(options.configPath)) {
|
|
752
757
|
watcher.removeAllListeners();
|
|
753
758
|
await watcher.close();
|
|
754
759
|
await initOrReload();
|