fumadocs-mdx 14.0.3 → 14.1.0
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-W3233QBZ.js → build-mdx-RXJZQXGA.js} +2 -2
- package/dist/bun/index.d.ts +2 -2
- package/dist/bun/index.js +9 -9
- package/dist/{chunk-KOPLIEVQ.js → chunk-7W73RILB.js} +2 -1
- package/dist/{chunk-LPX7ZO66.js → chunk-DTFUANSF.js} +1 -1
- package/dist/{chunk-Q5OSGLJL.js → chunk-K7N6GD4M.js} +1 -1
- package/dist/{chunk-6RPNS75C.js → chunk-OLD35ARB.js} +43 -31
- package/dist/{chunk-WBIHDYMN.js → chunk-PW2AZGGD.js} +3 -4
- package/dist/{chunk-USWQVJWR.js → chunk-T6G5VOED.js} +21 -12
- package/dist/{chunk-DKA3EWZH.js → chunk-VITVHHR6.js} +88 -84
- package/dist/{chunk-GB4W3YCZ.js → chunk-VKSHE52K.js} +85 -35
- package/dist/{chunk-OLL7FM7W.js → chunk-WAAWFNDX.js} +18 -20
- package/dist/{chunk-FBLMK4RS.js → chunk-Y7ISNZ7X.js} +22 -16
- package/dist/{chunk-TYJDYTKH.js → chunk-ZAYZWFWP.js} +10 -6
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +6 -5
- package/dist/{core-C3QZSdEx.d.ts → core-X5ggQtBM.d.ts} +50 -41
- package/dist/index-BqkSNsGO.d.ts +8 -0
- package/dist/index.d.ts +2 -2
- package/dist/{load-from-file-OZ5N7DXU.js → load-from-file-FHW724YY.js} +2 -2
- package/dist/next/index.cjs +253 -202
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +22 -37
- package/dist/node/loader.js +5 -5
- package/dist/plugins/index-file.d.ts +2 -2
- package/dist/plugins/index-file.js +2 -2
- package/dist/plugins/json-schema.d.ts +2 -2
- package/dist/plugins/json-schema.js +4 -7
- package/dist/plugins/last-modified.d.ts +3 -3
- package/dist/plugins/last-modified.js +23 -15
- package/dist/runtime/browser.d.ts +2 -2
- package/dist/runtime/dynamic.d.ts +2 -2
- package/dist/runtime/dynamic.js +7 -7
- package/dist/runtime/server.d.ts +2 -2
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +19 -21
- package/dist/webpack/mdx.d.ts +1 -15
- package/dist/webpack/mdx.js +5 -5
- package/dist/webpack/meta.d.ts +1 -15
- package/dist/webpack/meta.js +5 -5
- package/package.json +13 -14
- package/dist/index-DG1I0CwF.d.ts +0 -8
package/dist/next/index.cjs
CHANGED
|
@@ -34,7 +34,7 @@ __export(next_exports, {
|
|
|
34
34
|
postInstall: () => postInstall
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(next_exports);
|
|
37
|
-
var
|
|
37
|
+
var path6 = __toESM(require("path"), 1);
|
|
38
38
|
|
|
39
39
|
// src/config/load-from-file.ts
|
|
40
40
|
var import_node_url = require("url");
|
|
@@ -129,46 +129,57 @@ function applyMdxPreset(options = {}) {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
// src/config/build.ts
|
|
132
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
132
133
|
var SupportedFormats = {
|
|
133
134
|
doc: ["mdx", "md"],
|
|
134
135
|
meta: ["json", "yaml"]
|
|
135
136
|
};
|
|
136
|
-
function buildCollection(name,
|
|
137
|
-
if (
|
|
137
|
+
function buildCollection(name, collection, cwd) {
|
|
138
|
+
if (collection.type === "docs") {
|
|
138
139
|
return {
|
|
139
|
-
...
|
|
140
|
+
...collection,
|
|
141
|
+
type: "docs",
|
|
142
|
+
get dir() {
|
|
143
|
+
return this.docs.dir;
|
|
144
|
+
},
|
|
140
145
|
name,
|
|
141
|
-
meta:
|
|
142
|
-
docs:
|
|
146
|
+
meta: buildCollection(name, collection.meta, cwd),
|
|
147
|
+
docs: buildCollection(name, collection.docs, cwd),
|
|
143
148
|
hasFile(filePath) {
|
|
144
149
|
return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
|
|
145
|
-
}
|
|
150
|
+
},
|
|
151
|
+
isFileSupported(filePath) {
|
|
152
|
+
return this.docs.isFileSupported(filePath) || this.meta.isFileSupported(filePath);
|
|
153
|
+
},
|
|
154
|
+
cwd
|
|
146
155
|
};
|
|
147
156
|
}
|
|
148
|
-
return
|
|
157
|
+
return {
|
|
158
|
+
...collection,
|
|
159
|
+
...buildPrimitiveCollection(name, collection, cwd)
|
|
160
|
+
};
|
|
149
161
|
}
|
|
150
|
-
function buildPrimitiveCollection(name,
|
|
162
|
+
function buildPrimitiveCollection(name, config, cwd) {
|
|
151
163
|
const supportedFormats = SupportedFormats[config.type];
|
|
152
|
-
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
153
|
-
let
|
|
164
|
+
const patterns = config.files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
165
|
+
let matcher;
|
|
154
166
|
return {
|
|
155
|
-
|
|
167
|
+
dir: import_node_path.default.resolve(cwd, config.dir),
|
|
168
|
+
cwd,
|
|
156
169
|
name,
|
|
157
170
|
patterns,
|
|
158
171
|
isFileSupported(filePath) {
|
|
159
172
|
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
160
173
|
},
|
|
161
174
|
hasFile(filePath) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
);
|
|
167
|
-
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
175
|
+
if (!this.isFileSupported(filePath)) return false;
|
|
176
|
+
const relativePath = import_node_path.default.relative(this.dir, filePath);
|
|
177
|
+
if (relativePath.startsWith(`..${import_node_path.default.sep}`)) return false;
|
|
178
|
+
return (matcher ??= (0, import_picomatch.default)(patterns))(relativePath);
|
|
168
179
|
}
|
|
169
180
|
};
|
|
170
181
|
}
|
|
171
|
-
function buildConfig(config) {
|
|
182
|
+
function buildConfig(config, cwd = process.cwd()) {
|
|
172
183
|
const collections = /* @__PURE__ */ new Map();
|
|
173
184
|
const loaded = {};
|
|
174
185
|
for (const [k, v] of Object.entries(config)) {
|
|
@@ -176,15 +187,8 @@ function buildConfig(config) {
|
|
|
176
187
|
continue;
|
|
177
188
|
}
|
|
178
189
|
if (typeof v === "object" && "type" in v) {
|
|
179
|
-
if (v.type === "docs") {
|
|
180
|
-
collections.set(k, buildCollection(k, v));
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
if (v.type === "doc" || v.type === "meta") {
|
|
184
|
-
collections.set(
|
|
185
|
-
k,
|
|
186
|
-
buildCollection(k, v)
|
|
187
|
-
);
|
|
190
|
+
if (v.type === "docs" || v.type === "doc" || v.type === "meta") {
|
|
191
|
+
collections.set(k, buildCollection(k, v, cwd));
|
|
188
192
|
continue;
|
|
189
193
|
}
|
|
190
194
|
}
|
|
@@ -199,10 +203,18 @@ function buildConfig(config) {
|
|
|
199
203
|
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
200
204
|
return {
|
|
201
205
|
global: loaded,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
+
collections,
|
|
207
|
+
workspaces: Object.fromEntries(
|
|
208
|
+
Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
|
|
209
|
+
return [
|
|
210
|
+
key,
|
|
211
|
+
{
|
|
212
|
+
dir: value.dir,
|
|
213
|
+
config: buildConfig(value.config, import_node_path.default.resolve(cwd, value.dir))
|
|
214
|
+
}
|
|
215
|
+
];
|
|
216
|
+
})
|
|
217
|
+
),
|
|
206
218
|
getMDXOptions(collection, environment = "bundler") {
|
|
207
219
|
const key = collection ? `${environment}:${collection.name}` : environment;
|
|
208
220
|
const cached = mdxOptionsCache.get(key);
|
|
@@ -256,6 +268,10 @@ async function loadConfig(core, build = false) {
|
|
|
256
268
|
return await config;
|
|
257
269
|
}
|
|
258
270
|
|
|
271
|
+
// src/core.ts
|
|
272
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
273
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
274
|
+
|
|
259
275
|
// src/utils/validation.ts
|
|
260
276
|
var ValidationError = class extends Error {
|
|
261
277
|
constructor(message, issues) {
|
|
@@ -267,7 +283,8 @@ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
|
|
|
267
283
|
this.issues = issues;
|
|
268
284
|
}
|
|
269
285
|
async toStringFormatted() {
|
|
270
|
-
const
|
|
286
|
+
const picocolorsModule = await import("picocolors");
|
|
287
|
+
const picocolors = picocolorsModule.default ?? picocolorsModule;
|
|
271
288
|
return [
|
|
272
289
|
picocolors.bold(`[MDX] ${this.title}:`),
|
|
273
290
|
...this.issues.map(
|
|
@@ -294,12 +311,8 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
294
311
|
return data;
|
|
295
312
|
}
|
|
296
313
|
|
|
297
|
-
// src/core.ts
|
|
298
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
299
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
300
|
-
|
|
301
314
|
// src/utils/codegen.ts
|
|
302
|
-
var
|
|
315
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
303
316
|
var import_tinyglobby = require("tinyglobby");
|
|
304
317
|
function createCodegen({
|
|
305
318
|
target = "default",
|
|
@@ -339,7 +352,7 @@ function createCodegen({
|
|
|
339
352
|
);
|
|
340
353
|
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
341
354
|
{
|
|
342
|
-
base: normalizeViteGlobPath(
|
|
355
|
+
base: normalizeViteGlobPath(import_node_path2.default.relative(outDir, base)),
|
|
343
356
|
...rest
|
|
344
357
|
},
|
|
345
358
|
null,
|
|
@@ -362,10 +375,10 @@ function createCodegen({
|
|
|
362
375
|
}
|
|
363
376
|
let code = "{";
|
|
364
377
|
for (const item of await files) {
|
|
365
|
-
const fullPath =
|
|
378
|
+
const fullPath = import_node_path2.default.join(base, item);
|
|
366
379
|
const searchParams = new URLSearchParams();
|
|
367
380
|
for (const [k, v] of Object.entries(query)) {
|
|
368
|
-
searchParams.set(k, v);
|
|
381
|
+
if (v !== void 0) searchParams.set(k, v);
|
|
369
382
|
}
|
|
370
383
|
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
371
384
|
if (eager) {
|
|
@@ -386,16 +399,15 @@ function createCodegen({
|
|
|
386
399
|
return code;
|
|
387
400
|
},
|
|
388
401
|
formatImportPath(file) {
|
|
389
|
-
const ext =
|
|
402
|
+
const ext = import_node_path2.default.extname(file);
|
|
390
403
|
let filename;
|
|
391
|
-
if (ext === ".ts"
|
|
392
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
393
|
-
} else if (ext === ".ts") {
|
|
404
|
+
if (ext === ".ts") {
|
|
394
405
|
filename = file.substring(0, file.length - ext.length);
|
|
406
|
+
if (jsExtension) filename += ".js";
|
|
395
407
|
} else {
|
|
396
408
|
filename = file;
|
|
397
409
|
}
|
|
398
|
-
const importPath = slash(
|
|
410
|
+
const importPath = slash(import_node_path2.default.relative(outDir, filename));
|
|
399
411
|
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
400
412
|
},
|
|
401
413
|
toString() {
|
|
@@ -409,12 +421,12 @@ function normalizeViteGlobPath(file) {
|
|
|
409
421
|
if (file.startsWith("/")) return `.${file}`;
|
|
410
422
|
return `./${file}`;
|
|
411
423
|
}
|
|
412
|
-
function slash(
|
|
413
|
-
const isExtendedLengthPath =
|
|
424
|
+
function slash(path7) {
|
|
425
|
+
const isExtendedLengthPath = path7.startsWith("\\\\?\\");
|
|
414
426
|
if (isExtendedLengthPath) {
|
|
415
|
-
return
|
|
427
|
+
return path7;
|
|
416
428
|
}
|
|
417
|
-
return
|
|
429
|
+
return path7.replaceAll("\\", "/");
|
|
418
430
|
}
|
|
419
431
|
function ident(code, tab = 1) {
|
|
420
432
|
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
@@ -434,9 +446,10 @@ async function getPlugins(pluginOptions) {
|
|
|
434
446
|
}
|
|
435
447
|
return plugins;
|
|
436
448
|
}
|
|
437
|
-
function createCore(options
|
|
449
|
+
function createCore(options) {
|
|
438
450
|
let config;
|
|
439
451
|
let plugins;
|
|
452
|
+
const workspaces = /* @__PURE__ */ new Map();
|
|
440
453
|
async function transformMetadata({
|
|
441
454
|
collection,
|
|
442
455
|
filePath,
|
|
@@ -452,7 +465,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
452
465
|
}
|
|
453
466
|
return data;
|
|
454
467
|
}
|
|
455
|
-
|
|
468
|
+
return {
|
|
456
469
|
/**
|
|
457
470
|
* Convenient cache store, reset when config changes
|
|
458
471
|
*/
|
|
@@ -460,15 +473,36 @@ function createCore(options, defaultPlugins = []) {
|
|
|
460
473
|
async init({ config: newConfig }) {
|
|
461
474
|
config = await newConfig;
|
|
462
475
|
this.cache.clear();
|
|
476
|
+
workspaces.clear();
|
|
463
477
|
plugins = await getPlugins([
|
|
464
478
|
postprocessPlugin(),
|
|
465
|
-
|
|
466
|
-
|
|
479
|
+
options.plugins,
|
|
480
|
+
config.global.plugins
|
|
467
481
|
]);
|
|
468
482
|
for (const plugin of plugins) {
|
|
469
|
-
const out = await plugin.config?.call(
|
|
483
|
+
const out = await plugin.config?.call(this.getPluginContext(), config);
|
|
470
484
|
if (out) config = out;
|
|
471
485
|
}
|
|
486
|
+
if (!options.workspace) {
|
|
487
|
+
await Promise.all(
|
|
488
|
+
Object.entries(config.workspaces).map(async ([name, workspace]) => {
|
|
489
|
+
const core = createCore({
|
|
490
|
+
...options,
|
|
491
|
+
outDir: import_node_path3.default.join(options.outDir, name),
|
|
492
|
+
workspace: {
|
|
493
|
+
name,
|
|
494
|
+
parent: this,
|
|
495
|
+
dir: workspace.dir
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
await core.init({ config: workspace.config });
|
|
499
|
+
workspaces.set(name, core);
|
|
500
|
+
})
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
},
|
|
504
|
+
getWorkspaces() {
|
|
505
|
+
return workspaces;
|
|
472
506
|
},
|
|
473
507
|
getOptions() {
|
|
474
508
|
return options;
|
|
@@ -480,42 +514,74 @@ function createCore(options, defaultPlugins = []) {
|
|
|
480
514
|
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
481
515
|
*/
|
|
482
516
|
getCompiledConfigPath() {
|
|
483
|
-
return
|
|
517
|
+
return import_node_path3.default.join(options.outDir, "source.config.mjs");
|
|
484
518
|
},
|
|
485
519
|
getPlugins() {
|
|
486
520
|
return plugins;
|
|
487
521
|
},
|
|
522
|
+
getCollections() {
|
|
523
|
+
return Array.from(config.collections.values());
|
|
524
|
+
},
|
|
525
|
+
getCollection(name) {
|
|
526
|
+
return config.collections.get(name);
|
|
527
|
+
},
|
|
488
528
|
getPluginContext() {
|
|
489
|
-
return
|
|
529
|
+
return {
|
|
530
|
+
core: this
|
|
531
|
+
};
|
|
490
532
|
},
|
|
491
533
|
async initServer(server) {
|
|
534
|
+
const ctx = this.getPluginContext();
|
|
492
535
|
for (const plugin of plugins) {
|
|
493
|
-
await plugin.configureServer?.call(
|
|
536
|
+
await plugin.configureServer?.call(ctx, server);
|
|
537
|
+
}
|
|
538
|
+
for (const workspace of workspaces.values()) {
|
|
539
|
+
await workspace.initServer(server);
|
|
494
540
|
}
|
|
495
541
|
},
|
|
496
|
-
async emit(
|
|
497
|
-
|
|
498
|
-
plugins.map((plugin) => {
|
|
499
|
-
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
500
|
-
return plugin.emit.call(pluginContext);
|
|
501
|
-
})
|
|
502
|
-
)).flat();
|
|
503
|
-
},
|
|
504
|
-
async emitAndWrite(emitOptions) {
|
|
542
|
+
async emit(emitOptions = {}) {
|
|
543
|
+
const { filterPlugin, filterWorkspace, write = false } = emitOptions;
|
|
505
544
|
const start = performance.now();
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
545
|
+
const ctx = this.getPluginContext();
|
|
546
|
+
const added = /* @__PURE__ */ new Set();
|
|
547
|
+
const out = {
|
|
548
|
+
entries: [],
|
|
549
|
+
workspaces: {}
|
|
550
|
+
};
|
|
551
|
+
for (const li of await Promise.all(
|
|
552
|
+
plugins.map((plugin) => {
|
|
553
|
+
if (filterPlugin && !filterPlugin(plugin) || !plugin.emit) return;
|
|
554
|
+
return plugin.emit.call(ctx);
|
|
512
555
|
})
|
|
513
|
-
)
|
|
514
|
-
|
|
556
|
+
)) {
|
|
557
|
+
if (!li) continue;
|
|
558
|
+
for (const item of li) {
|
|
559
|
+
if (added.has(item.path)) continue;
|
|
560
|
+
out.entries.push(item);
|
|
561
|
+
added.add(item.path);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (write) {
|
|
565
|
+
await Promise.all(
|
|
566
|
+
out.entries.map(async (entry) => {
|
|
567
|
+
const file = import_node_path3.default.join(options.outDir, entry.path);
|
|
568
|
+
await import_promises.default.mkdir(import_node_path3.default.dirname(file), { recursive: true });
|
|
569
|
+
await import_promises.default.writeFile(file, entry.content);
|
|
570
|
+
})
|
|
571
|
+
);
|
|
572
|
+
console.log(
|
|
573
|
+
options.workspace ? `[MDX: ${options.workspace.name}] generated files in ${performance.now() - start}ms` : `[MDX] generated files in ${performance.now() - start}ms`
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
for (const [name, workspace] of workspaces) {
|
|
577
|
+
if (filterWorkspace && !filterWorkspace(name)) continue;
|
|
578
|
+
out.workspaces[name] = (await workspace.emit(emitOptions)).entries;
|
|
579
|
+
}
|
|
580
|
+
return out;
|
|
515
581
|
},
|
|
516
582
|
async transformMeta(options2, data) {
|
|
517
583
|
const ctx = {
|
|
518
|
-
...
|
|
584
|
+
...this.getPluginContext(),
|
|
519
585
|
...options2
|
|
520
586
|
};
|
|
521
587
|
data = await transformMetadata(options2, data);
|
|
@@ -527,7 +593,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
527
593
|
},
|
|
528
594
|
async transformFrontmatter(options2, data) {
|
|
529
595
|
const ctx = {
|
|
530
|
-
...
|
|
596
|
+
...this.getPluginContext(),
|
|
531
597
|
...options2
|
|
532
598
|
};
|
|
533
599
|
data = await transformMetadata(options2, data);
|
|
@@ -539,7 +605,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
539
605
|
},
|
|
540
606
|
async transformVFile(options2, file) {
|
|
541
607
|
const ctx = {
|
|
542
|
-
...
|
|
608
|
+
...this.getPluginContext(),
|
|
543
609
|
...options2
|
|
544
610
|
};
|
|
545
611
|
for (const plugin of plugins) {
|
|
@@ -549,11 +615,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
549
615
|
return file;
|
|
550
616
|
}
|
|
551
617
|
};
|
|
552
|
-
const pluginContext = {
|
|
553
|
-
core,
|
|
554
|
-
...options
|
|
555
|
-
};
|
|
556
|
-
return core;
|
|
557
618
|
}
|
|
558
619
|
function postprocessPlugin() {
|
|
559
620
|
const LinkReferenceTypes = `{
|
|
@@ -568,7 +629,7 @@ function postprocessPlugin() {
|
|
|
568
629
|
const lines = [];
|
|
569
630
|
lines.push("{");
|
|
570
631
|
lines.push(" DocData: {");
|
|
571
|
-
for (const collection of this.core.
|
|
632
|
+
for (const collection of this.core.getCollections()) {
|
|
572
633
|
let postprocessOptions;
|
|
573
634
|
switch (collection.type) {
|
|
574
635
|
case "doc":
|
|
@@ -604,29 +665,30 @@ var import_path = __toESM(require("path"), 1);
|
|
|
604
665
|
var import_tinyglobby2 = require("tinyglobby");
|
|
605
666
|
|
|
606
667
|
// src/utils/fs-cache.ts
|
|
607
|
-
var import_lru_cache = require("lru-cache");
|
|
608
668
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
609
|
-
var
|
|
610
|
-
var map = new
|
|
611
|
-
|
|
612
|
-
|
|
669
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
670
|
+
var map = /* @__PURE__ */ new Map();
|
|
671
|
+
function createFSCache() {
|
|
672
|
+
return {
|
|
673
|
+
read(file) {
|
|
674
|
+
const fullPath = toFullPath(file);
|
|
675
|
+
const cached = map.get(fullPath);
|
|
676
|
+
if (cached) return cached;
|
|
677
|
+
const read = import_promises2.default.readFile(fullPath).then((s) => s.toString());
|
|
678
|
+
map.set(fullPath, read);
|
|
679
|
+
return read;
|
|
680
|
+
},
|
|
681
|
+
delete(file) {
|
|
682
|
+
map.delete(toFullPath(file));
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
}
|
|
613
686
|
function toFullPath(file) {
|
|
614
|
-
if (
|
|
615
|
-
return
|
|
687
|
+
if (import_node_path4.default.isAbsolute(file)) {
|
|
688
|
+
return import_node_path4.default.relative(process.cwd(), file);
|
|
616
689
|
}
|
|
617
690
|
return file;
|
|
618
691
|
}
|
|
619
|
-
function readFileWithCache(file) {
|
|
620
|
-
const fullPath = toFullPath(file);
|
|
621
|
-
const cached = map.get(fullPath);
|
|
622
|
-
if (cached) return cached;
|
|
623
|
-
const read = import_promises2.default.readFile(fullPath).then((s) => s.toString());
|
|
624
|
-
map.set(fullPath, read);
|
|
625
|
-
return read;
|
|
626
|
-
}
|
|
627
|
-
function removeFileCache(file) {
|
|
628
|
-
map.delete(toFullPath(file));
|
|
629
|
-
}
|
|
630
692
|
|
|
631
693
|
// src/plugins/index-file.ts
|
|
632
694
|
var import_crypto = require("crypto");
|
|
@@ -648,6 +710,7 @@ function fumaMatter(input) {
|
|
|
648
710
|
}
|
|
649
711
|
|
|
650
712
|
// src/plugins/index-file.ts
|
|
713
|
+
var indexFileCache = createFSCache();
|
|
651
714
|
function indexFile(options = {}) {
|
|
652
715
|
const {
|
|
653
716
|
target = "default",
|
|
@@ -655,7 +718,6 @@ function indexFile(options = {}) {
|
|
|
655
718
|
browser = true,
|
|
656
719
|
dynamic = true
|
|
657
720
|
} = options;
|
|
658
|
-
let config;
|
|
659
721
|
let dynamicCollections;
|
|
660
722
|
function isDynamic(collection) {
|
|
661
723
|
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
@@ -670,8 +732,8 @@ function indexFile(options = {}) {
|
|
|
670
732
|
const indexFilePlugin = plugin["index-file"];
|
|
671
733
|
if (!indexFilePlugin) continue;
|
|
672
734
|
indexFilePlugin.serverOptions?.call(ctx, serverOptions);
|
|
673
|
-
const
|
|
674
|
-
if (
|
|
735
|
+
const config = indexFilePlugin.generateTypeConfig?.call(ctx);
|
|
736
|
+
if (config) typeConfigs.push(config);
|
|
675
737
|
}
|
|
676
738
|
return {
|
|
677
739
|
serverOptions,
|
|
@@ -680,38 +742,38 @@ function indexFile(options = {}) {
|
|
|
680
742
|
}
|
|
681
743
|
return {
|
|
682
744
|
name: "index-file",
|
|
683
|
-
config(
|
|
684
|
-
|
|
685
|
-
dynamicCollections = config.collectionList.filter(isDynamic);
|
|
745
|
+
config() {
|
|
746
|
+
dynamicCollections = this.core.getCollections().filter(isDynamic);
|
|
686
747
|
},
|
|
687
748
|
configureServer(server) {
|
|
688
749
|
if (!server.watcher) return;
|
|
689
750
|
server.watcher.on("all", async (event, file) => {
|
|
690
|
-
|
|
751
|
+
indexFileCache.delete(file);
|
|
691
752
|
if (dynamicCollections.length === 0) {
|
|
692
753
|
if (target === "vite") return;
|
|
693
754
|
if (target === "default" && event === "change") return;
|
|
694
755
|
}
|
|
695
|
-
const updatedCollection =
|
|
696
|
-
(collection) => collection.hasFile(file)
|
|
697
|
-
);
|
|
756
|
+
const updatedCollection = this.core.getCollections().find((collection) => collection.hasFile(file));
|
|
698
757
|
if (!updatedCollection) return;
|
|
699
758
|
if (!isDynamic(updatedCollection)) {
|
|
700
759
|
if (target === "vite") return;
|
|
701
760
|
if (target === "default" && event === "change") return;
|
|
702
761
|
}
|
|
703
|
-
await this.core.
|
|
704
|
-
filterPlugin: (plugin) => plugin.name === "index-file"
|
|
762
|
+
await this.core.emit({
|
|
763
|
+
filterPlugin: (plugin) => plugin.name === "index-file",
|
|
764
|
+
filterWorkspace: () => false,
|
|
765
|
+
write: true
|
|
705
766
|
});
|
|
706
767
|
});
|
|
707
768
|
},
|
|
708
769
|
async emit() {
|
|
709
770
|
const globCache = /* @__PURE__ */ new Map();
|
|
771
|
+
const { workspace, outDir } = this.core.getOptions();
|
|
710
772
|
const { serverOptions, tc } = generateConfigs(this.core);
|
|
711
|
-
const toEmitEntry = async (
|
|
773
|
+
const toEmitEntry = async (path7, content) => {
|
|
712
774
|
const codegen = createCodegen({
|
|
713
775
|
target,
|
|
714
|
-
outDir
|
|
776
|
+
outDir,
|
|
715
777
|
jsExtension: addJsExtension,
|
|
716
778
|
globCache
|
|
717
779
|
});
|
|
@@ -719,10 +781,11 @@ function indexFile(options = {}) {
|
|
|
719
781
|
core: this.core,
|
|
720
782
|
codegen,
|
|
721
783
|
serverOptions,
|
|
722
|
-
tc
|
|
784
|
+
tc,
|
|
785
|
+
workspace: workspace?.name
|
|
723
786
|
});
|
|
724
787
|
return {
|
|
725
|
-
path:
|
|
788
|
+
path: path7,
|
|
726
789
|
content: codegen.toString()
|
|
727
790
|
};
|
|
728
791
|
};
|
|
@@ -737,12 +800,8 @@ function indexFile(options = {}) {
|
|
|
737
800
|
}
|
|
738
801
|
};
|
|
739
802
|
}
|
|
740
|
-
async function generateServerIndexFile({
|
|
741
|
-
core,
|
|
742
|
-
codegen,
|
|
743
|
-
serverOptions,
|
|
744
|
-
tc
|
|
745
|
-
}) {
|
|
803
|
+
async function generateServerIndexFile(ctx) {
|
|
804
|
+
const { core, codegen, serverOptions, tc } = ctx;
|
|
746
805
|
codegen.lines.push(
|
|
747
806
|
`import { server } from 'fumadocs-mdx/runtime/server';`,
|
|
748
807
|
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
@@ -750,51 +809,48 @@ async function generateServerIndexFile({
|
|
|
750
809
|
`const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
|
|
751
810
|
);
|
|
752
811
|
async function generateCollectionObject(collection) {
|
|
812
|
+
const base = getBase(collection);
|
|
753
813
|
switch (collection.type) {
|
|
754
814
|
case "docs": {
|
|
755
815
|
if (collection.docs.dynamic) return;
|
|
756
816
|
if (collection.docs.async) {
|
|
757
817
|
const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
|
|
758
|
-
generateMetaCollectionGlob(
|
|
759
|
-
generateDocCollectionFrontmatterGlob(
|
|
760
|
-
|
|
761
|
-
collection.docs,
|
|
762
|
-
true
|
|
763
|
-
),
|
|
764
|
-
generateDocCollectionGlob(codegen, collection.docs)
|
|
818
|
+
generateMetaCollectionGlob(ctx, collection.meta, true),
|
|
819
|
+
generateDocCollectionFrontmatterGlob(ctx, collection.docs, true),
|
|
820
|
+
generateDocCollectionGlob(ctx, collection.docs)
|
|
765
821
|
]);
|
|
766
|
-
return `await create.docsLazy("${collection.name}", "${
|
|
822
|
+
return `await create.docsLazy("${collection.name}", "${base}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
|
|
767
823
|
}
|
|
768
824
|
const [metaGlob, docGlob] = await Promise.all([
|
|
769
|
-
generateMetaCollectionGlob(
|
|
770
|
-
generateDocCollectionGlob(
|
|
825
|
+
generateMetaCollectionGlob(ctx, collection.meta, true),
|
|
826
|
+
generateDocCollectionGlob(ctx, collection.docs, true)
|
|
771
827
|
]);
|
|
772
|
-
return `await create.docs("${collection.name}", "${
|
|
828
|
+
return `await create.docs("${collection.name}", "${base}", ${metaGlob}, ${docGlob})`;
|
|
773
829
|
}
|
|
774
830
|
case "doc":
|
|
775
831
|
if (collection.dynamic) return;
|
|
776
832
|
if (collection.async) {
|
|
777
833
|
const [headGlob, bodyGlob] = await Promise.all([
|
|
778
|
-
generateDocCollectionFrontmatterGlob(
|
|
779
|
-
generateDocCollectionGlob(
|
|
834
|
+
generateDocCollectionFrontmatterGlob(ctx, collection, true),
|
|
835
|
+
generateDocCollectionGlob(ctx, collection)
|
|
780
836
|
]);
|
|
781
|
-
return `await create.docLazy("${collection.name}", "${
|
|
837
|
+
return `await create.docLazy("${collection.name}", "${base}", ${headGlob}, ${bodyGlob})`;
|
|
782
838
|
}
|
|
783
|
-
return `await create.doc("${collection.name}", "${
|
|
784
|
-
|
|
839
|
+
return `await create.doc("${collection.name}", "${base}", ${await generateDocCollectionGlob(
|
|
840
|
+
ctx,
|
|
785
841
|
collection,
|
|
786
842
|
true
|
|
787
843
|
)})`;
|
|
788
844
|
case "meta":
|
|
789
|
-
return `await create.meta("${collection.name}", "${
|
|
790
|
-
|
|
845
|
+
return `await create.meta("${collection.name}", "${base}", ${await generateMetaCollectionGlob(
|
|
846
|
+
ctx,
|
|
791
847
|
collection,
|
|
792
848
|
true
|
|
793
849
|
)})`;
|
|
794
850
|
}
|
|
795
851
|
}
|
|
796
852
|
await codegen.pushAsync(
|
|
797
|
-
core.
|
|
853
|
+
core.getCollections().map(async (collection) => {
|
|
798
854
|
const obj = await generateCollectionObject(collection);
|
|
799
855
|
if (!obj) return;
|
|
800
856
|
return `
|
|
@@ -802,22 +858,23 @@ export const ${collection.name} = ${obj};`;
|
|
|
802
858
|
})
|
|
803
859
|
);
|
|
804
860
|
}
|
|
805
|
-
async function generateDynamicIndexFile({
|
|
806
|
-
core,
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
861
|
+
async function generateDynamicIndexFile(ctx) {
|
|
862
|
+
const { core, codegen, serverOptions, tc } = ctx;
|
|
863
|
+
const { configPath, environment, outDir } = core.getOptions();
|
|
864
|
+
const partialOptions = {
|
|
865
|
+
configPath,
|
|
866
|
+
environment,
|
|
867
|
+
outDir
|
|
868
|
+
};
|
|
812
869
|
codegen.lines.push(
|
|
813
870
|
`import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
814
871
|
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
815
872
|
"",
|
|
816
|
-
`const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(
|
|
873
|
+
`const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(partialOptions)}, ${JSON.stringify(serverOptions)});`
|
|
817
874
|
);
|
|
818
|
-
async function generateCollectionObjectEntry(collection,
|
|
819
|
-
const fullPath = import_path.default.
|
|
820
|
-
const content = await
|
|
875
|
+
async function generateCollectionObjectEntry(collection, absolutePath) {
|
|
876
|
+
const fullPath = import_path.default.relative(process.cwd(), absolutePath);
|
|
877
|
+
const content = await indexFileCache.read(fullPath).catch(() => "");
|
|
821
878
|
const parsed = fumaMatter(content);
|
|
822
879
|
const data = await core.transformFrontmatter(
|
|
823
880
|
{
|
|
@@ -835,7 +892,7 @@ async function generateDynamicIndexFile({
|
|
|
835
892
|
for (const [k, v] of Object.entries({
|
|
836
893
|
info: {
|
|
837
894
|
fullPath,
|
|
838
|
-
path:
|
|
895
|
+
path: import_path.default.relative(collection.dir, absolutePath)
|
|
839
896
|
},
|
|
840
897
|
data,
|
|
841
898
|
hash
|
|
@@ -850,7 +907,8 @@ async function generateDynamicIndexFile({
|
|
|
850
907
|
else if (parent.type === "docs") collection = parent.docs;
|
|
851
908
|
if (!collection || !collection.dynamic) return;
|
|
852
909
|
const files = await (0, import_tinyglobby2.glob)(collection.patterns, {
|
|
853
|
-
cwd: collection.dir
|
|
910
|
+
cwd: collection.dir,
|
|
911
|
+
absolute: true
|
|
854
912
|
});
|
|
855
913
|
const entries = await Promise.all(
|
|
856
914
|
files.map((file) => generateCollectionObjectEntry(collection, file))
|
|
@@ -858,18 +916,18 @@ async function generateDynamicIndexFile({
|
|
|
858
916
|
switch (parent.type) {
|
|
859
917
|
case "docs": {
|
|
860
918
|
const metaGlob = await generateMetaCollectionGlob(
|
|
861
|
-
|
|
919
|
+
ctx,
|
|
862
920
|
parent.meta,
|
|
863
921
|
true
|
|
864
922
|
);
|
|
865
|
-
return `await create.docs("${parent.name}", "${parent
|
|
923
|
+
return `await create.docs("${parent.name}", "${getBase(parent)}", ${metaGlob}, ${entries.join(", ")})`;
|
|
866
924
|
}
|
|
867
925
|
case "doc":
|
|
868
|
-
return `await create.doc("${collection.name}", "${collection
|
|
926
|
+
return `await create.doc("${collection.name}", "${getBase(collection)}", ${entries.join(", ")})`;
|
|
869
927
|
}
|
|
870
928
|
}
|
|
871
929
|
await codegen.pushAsync(
|
|
872
|
-
core.
|
|
930
|
+
core.getCollections().map(async (collection) => {
|
|
873
931
|
const obj = await generateCollectionObject(collection);
|
|
874
932
|
if (!obj) return;
|
|
875
933
|
return `
|
|
@@ -877,7 +935,8 @@ export const ${collection.name} = ${obj};`;
|
|
|
877
935
|
})
|
|
878
936
|
);
|
|
879
937
|
}
|
|
880
|
-
async function generateBrowserIndexFile(
|
|
938
|
+
async function generateBrowserIndexFile(ctx) {
|
|
939
|
+
const { core, codegen, tc } = ctx;
|
|
881
940
|
codegen.lines.push(
|
|
882
941
|
`import { browser } from 'fumadocs-mdx/runtime/browser';`,
|
|
883
942
|
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
@@ -892,12 +951,12 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
|
892
951
|
}
|
|
893
952
|
case "doc":
|
|
894
953
|
if (collection.dynamic) return;
|
|
895
|
-
return `create.doc("${collection.name}", ${await generateDocCollectionGlob(
|
|
954
|
+
return `create.doc("${collection.name}", ${await generateDocCollectionGlob(ctx, collection)})`;
|
|
896
955
|
}
|
|
897
956
|
}
|
|
898
957
|
codegen.lines.push("const browserCollections = {");
|
|
899
958
|
await codegen.pushAsync(
|
|
900
|
-
core.
|
|
959
|
+
core.getCollections().map(async (collection) => {
|
|
901
960
|
const obj = await generateCollectionObject(collection);
|
|
902
961
|
if (!obj) return;
|
|
903
962
|
return ident(`${collection.name}: ${obj},`);
|
|
@@ -905,30 +964,36 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
|
905
964
|
);
|
|
906
965
|
codegen.lines.push("};", "export default browserCollections;");
|
|
907
966
|
}
|
|
908
|
-
function
|
|
967
|
+
function getBase(collection) {
|
|
968
|
+
return import_path.default.relative(process.cwd(), collection.dir);
|
|
969
|
+
}
|
|
970
|
+
function generateDocCollectionFrontmatterGlob({ codegen, workspace }, collection, eager = false) {
|
|
909
971
|
return codegen.generateGlobImport(collection.patterns, {
|
|
910
972
|
query: {
|
|
911
973
|
collection: collection.name,
|
|
912
|
-
only: "frontmatter"
|
|
974
|
+
only: "frontmatter",
|
|
975
|
+
workspace
|
|
913
976
|
},
|
|
914
977
|
import: "frontmatter",
|
|
915
978
|
base: collection.dir,
|
|
916
979
|
eager
|
|
917
980
|
});
|
|
918
981
|
}
|
|
919
|
-
function generateDocCollectionGlob(codegen, collection, eager = false) {
|
|
982
|
+
function generateDocCollectionGlob({ codegen, workspace }, collection, eager = false) {
|
|
920
983
|
return codegen.generateGlobImport(collection.patterns, {
|
|
921
984
|
query: {
|
|
922
|
-
collection: collection.name
|
|
985
|
+
collection: collection.name,
|
|
986
|
+
workspace
|
|
923
987
|
},
|
|
924
988
|
base: collection.dir,
|
|
925
989
|
eager
|
|
926
990
|
});
|
|
927
991
|
}
|
|
928
|
-
function generateMetaCollectionGlob(codegen, collection, eager = false) {
|
|
992
|
+
function generateMetaCollectionGlob({ codegen, workspace }, collection, eager = false) {
|
|
929
993
|
return codegen.generateGlobImport(collection.patterns, {
|
|
930
994
|
query: {
|
|
931
|
-
collection: collection.name
|
|
995
|
+
collection: collection.name,
|
|
996
|
+
workspace
|
|
932
997
|
},
|
|
933
998
|
import: "default",
|
|
934
999
|
base: collection.dir,
|
|
@@ -946,9 +1011,11 @@ function createMDX(createOptions = {}) {
|
|
|
946
1011
|
void init(isDev, core);
|
|
947
1012
|
}
|
|
948
1013
|
return (nextConfig = {}) => {
|
|
1014
|
+
const { configPath, outDir } = core.getOptions();
|
|
949
1015
|
const loaderOptions = {
|
|
950
|
-
|
|
951
|
-
|
|
1016
|
+
configPath,
|
|
1017
|
+
outDir,
|
|
1018
|
+
absoluteCompiledConfigPath: path6.resolve(core.getCompiledConfigPath()),
|
|
952
1019
|
isDev
|
|
953
1020
|
};
|
|
954
1021
|
const turbopack = {
|
|
@@ -1025,7 +1092,7 @@ async function init(dev, core) {
|
|
|
1025
1092
|
await core.init({
|
|
1026
1093
|
config: loadConfig(core, true)
|
|
1027
1094
|
});
|
|
1028
|
-
await core.
|
|
1095
|
+
await core.emit({ write: true });
|
|
1029
1096
|
}
|
|
1030
1097
|
async function devServer() {
|
|
1031
1098
|
const { FSWatcher } = await import("chokidar");
|
|
@@ -1036,20 +1103,20 @@ async function init(dev, core) {
|
|
|
1036
1103
|
ignored: [outDir]
|
|
1037
1104
|
});
|
|
1038
1105
|
watcher.add(configPath);
|
|
1039
|
-
for (const collection of core.
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1106
|
+
for (const collection of core.getCollections()) {
|
|
1107
|
+
watcher.add(collection.dir);
|
|
1108
|
+
}
|
|
1109
|
+
for (const workspace of core.getWorkspaces().values()) {
|
|
1110
|
+
for (const collection of workspace.getCollections()) {
|
|
1044
1111
|
watcher.add(collection.dir);
|
|
1045
1112
|
}
|
|
1046
1113
|
}
|
|
1047
1114
|
watcher.on("ready", () => {
|
|
1048
1115
|
console.log("[MDX] started dev server");
|
|
1049
1116
|
});
|
|
1050
|
-
const absoluteConfigPath =
|
|
1117
|
+
const absoluteConfigPath = path6.resolve(configPath);
|
|
1051
1118
|
watcher.on("all", async (_event, file) => {
|
|
1052
|
-
if (
|
|
1119
|
+
if (path6.resolve(file) === absoluteConfigPath) {
|
|
1053
1120
|
watcher.removeAllListeners();
|
|
1054
1121
|
await watcher.close();
|
|
1055
1122
|
await initOrReload();
|
|
@@ -1074,7 +1141,7 @@ async function postInstall(options) {
|
|
|
1074
1141
|
await core.init({
|
|
1075
1142
|
config: loadConfig(core, true)
|
|
1076
1143
|
});
|
|
1077
|
-
await core.
|
|
1144
|
+
await core.emit({ write: true });
|
|
1078
1145
|
}
|
|
1079
1146
|
function applyDefaults(options) {
|
|
1080
1147
|
return {
|
|
@@ -1084,28 +1151,12 @@ function applyDefaults(options) {
|
|
|
1084
1151
|
};
|
|
1085
1152
|
}
|
|
1086
1153
|
function createNextCore(options) {
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
[options.index && indexFile(options.index)]
|
|
1094
|
-
);
|
|
1095
|
-
return {
|
|
1096
|
-
...core,
|
|
1097
|
-
async emitAndWrite(...args) {
|
|
1098
|
-
try {
|
|
1099
|
-
await core.emitAndWrite(...args);
|
|
1100
|
-
} catch (err) {
|
|
1101
|
-
if (err instanceof ValidationError) {
|
|
1102
|
-
console.error(await err.toStringFormatted());
|
|
1103
|
-
} else {
|
|
1104
|
-
console.error(err);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1154
|
+
return createCore({
|
|
1155
|
+
environment: "next",
|
|
1156
|
+
outDir: options.outDir,
|
|
1157
|
+
configPath: options.configPath,
|
|
1158
|
+
plugins: [options.index && indexFile(options.index)]
|
|
1159
|
+
});
|
|
1109
1160
|
}
|
|
1110
1161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1111
1162
|
0 && (module.exports = {
|