fumadocs-mdx 14.0.4 → 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 +6 -6
- package/dist/{chunk-KOPLIEVQ.js → chunk-7W73RILB.js} +2 -1
- package/dist/{chunk-LPX7ZO66.js → chunk-DTFUANSF.js} +1 -1
- package/dist/{chunk-CGGDM5F3.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-ED3ON275.js → chunk-VITVHHR6.js} +85 -81
- package/dist/{chunk-K4KWUM3J.js → chunk-VKSHE52K.js} +83 -34
- package/dist/{chunk-NKIL543T.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 +251 -201
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.js +21 -36
- 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 +2 -2
- package/dist/plugins/last-modified.js +20 -13
- package/dist/runtime/browser.d.ts +2 -2
- package/dist/runtime/dynamic.d.ts +2 -2
- package/dist/runtime/dynamic.js +6 -6
- package/dist/runtime/server.d.ts +2 -2
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +16 -18
- 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 +12 -13
- 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) {
|
|
@@ -295,12 +311,8 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
295
311
|
return data;
|
|
296
312
|
}
|
|
297
313
|
|
|
298
|
-
// src/core.ts
|
|
299
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
300
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
301
|
-
|
|
302
314
|
// src/utils/codegen.ts
|
|
303
|
-
var
|
|
315
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
304
316
|
var import_tinyglobby = require("tinyglobby");
|
|
305
317
|
function createCodegen({
|
|
306
318
|
target = "default",
|
|
@@ -340,7 +352,7 @@ function createCodegen({
|
|
|
340
352
|
);
|
|
341
353
|
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
342
354
|
{
|
|
343
|
-
base: normalizeViteGlobPath(
|
|
355
|
+
base: normalizeViteGlobPath(import_node_path2.default.relative(outDir, base)),
|
|
344
356
|
...rest
|
|
345
357
|
},
|
|
346
358
|
null,
|
|
@@ -363,10 +375,10 @@ function createCodegen({
|
|
|
363
375
|
}
|
|
364
376
|
let code = "{";
|
|
365
377
|
for (const item of await files) {
|
|
366
|
-
const fullPath =
|
|
378
|
+
const fullPath = import_node_path2.default.join(base, item);
|
|
367
379
|
const searchParams = new URLSearchParams();
|
|
368
380
|
for (const [k, v] of Object.entries(query)) {
|
|
369
|
-
searchParams.set(k, v);
|
|
381
|
+
if (v !== void 0) searchParams.set(k, v);
|
|
370
382
|
}
|
|
371
383
|
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
372
384
|
if (eager) {
|
|
@@ -387,16 +399,15 @@ function createCodegen({
|
|
|
387
399
|
return code;
|
|
388
400
|
},
|
|
389
401
|
formatImportPath(file) {
|
|
390
|
-
const ext =
|
|
402
|
+
const ext = import_node_path2.default.extname(file);
|
|
391
403
|
let filename;
|
|
392
|
-
if (ext === ".ts"
|
|
393
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
394
|
-
} else if (ext === ".ts") {
|
|
404
|
+
if (ext === ".ts") {
|
|
395
405
|
filename = file.substring(0, file.length - ext.length);
|
|
406
|
+
if (jsExtension) filename += ".js";
|
|
396
407
|
} else {
|
|
397
408
|
filename = file;
|
|
398
409
|
}
|
|
399
|
-
const importPath = slash(
|
|
410
|
+
const importPath = slash(import_node_path2.default.relative(outDir, filename));
|
|
400
411
|
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
401
412
|
},
|
|
402
413
|
toString() {
|
|
@@ -410,12 +421,12 @@ function normalizeViteGlobPath(file) {
|
|
|
410
421
|
if (file.startsWith("/")) return `.${file}`;
|
|
411
422
|
return `./${file}`;
|
|
412
423
|
}
|
|
413
|
-
function slash(
|
|
414
|
-
const isExtendedLengthPath =
|
|
424
|
+
function slash(path7) {
|
|
425
|
+
const isExtendedLengthPath = path7.startsWith("\\\\?\\");
|
|
415
426
|
if (isExtendedLengthPath) {
|
|
416
|
-
return
|
|
427
|
+
return path7;
|
|
417
428
|
}
|
|
418
|
-
return
|
|
429
|
+
return path7.replaceAll("\\", "/");
|
|
419
430
|
}
|
|
420
431
|
function ident(code, tab = 1) {
|
|
421
432
|
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
@@ -435,9 +446,10 @@ async function getPlugins(pluginOptions) {
|
|
|
435
446
|
}
|
|
436
447
|
return plugins;
|
|
437
448
|
}
|
|
438
|
-
function createCore(options
|
|
449
|
+
function createCore(options) {
|
|
439
450
|
let config;
|
|
440
451
|
let plugins;
|
|
452
|
+
const workspaces = /* @__PURE__ */ new Map();
|
|
441
453
|
async function transformMetadata({
|
|
442
454
|
collection,
|
|
443
455
|
filePath,
|
|
@@ -453,7 +465,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
453
465
|
}
|
|
454
466
|
return data;
|
|
455
467
|
}
|
|
456
|
-
|
|
468
|
+
return {
|
|
457
469
|
/**
|
|
458
470
|
* Convenient cache store, reset when config changes
|
|
459
471
|
*/
|
|
@@ -461,15 +473,36 @@ function createCore(options, defaultPlugins = []) {
|
|
|
461
473
|
async init({ config: newConfig }) {
|
|
462
474
|
config = await newConfig;
|
|
463
475
|
this.cache.clear();
|
|
476
|
+
workspaces.clear();
|
|
464
477
|
plugins = await getPlugins([
|
|
465
478
|
postprocessPlugin(),
|
|
466
|
-
|
|
467
|
-
|
|
479
|
+
options.plugins,
|
|
480
|
+
config.global.plugins
|
|
468
481
|
]);
|
|
469
482
|
for (const plugin of plugins) {
|
|
470
|
-
const out = await plugin.config?.call(
|
|
483
|
+
const out = await plugin.config?.call(this.getPluginContext(), config);
|
|
471
484
|
if (out) config = out;
|
|
472
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;
|
|
473
506
|
},
|
|
474
507
|
getOptions() {
|
|
475
508
|
return options;
|
|
@@ -481,42 +514,74 @@ function createCore(options, defaultPlugins = []) {
|
|
|
481
514
|
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
482
515
|
*/
|
|
483
516
|
getCompiledConfigPath() {
|
|
484
|
-
return
|
|
517
|
+
return import_node_path3.default.join(options.outDir, "source.config.mjs");
|
|
485
518
|
},
|
|
486
519
|
getPlugins() {
|
|
487
520
|
return plugins;
|
|
488
521
|
},
|
|
522
|
+
getCollections() {
|
|
523
|
+
return Array.from(config.collections.values());
|
|
524
|
+
},
|
|
525
|
+
getCollection(name) {
|
|
526
|
+
return config.collections.get(name);
|
|
527
|
+
},
|
|
489
528
|
getPluginContext() {
|
|
490
|
-
return
|
|
529
|
+
return {
|
|
530
|
+
core: this
|
|
531
|
+
};
|
|
491
532
|
},
|
|
492
533
|
async initServer(server) {
|
|
534
|
+
const ctx = this.getPluginContext();
|
|
493
535
|
for (const plugin of plugins) {
|
|
494
|
-
await plugin.configureServer?.call(
|
|
536
|
+
await plugin.configureServer?.call(ctx, server);
|
|
537
|
+
}
|
|
538
|
+
for (const workspace of workspaces.values()) {
|
|
539
|
+
await workspace.initServer(server);
|
|
495
540
|
}
|
|
496
541
|
},
|
|
497
|
-
async emit(
|
|
498
|
-
|
|
499
|
-
plugins.map((plugin) => {
|
|
500
|
-
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
501
|
-
return plugin.emit.call(pluginContext);
|
|
502
|
-
})
|
|
503
|
-
)).flat();
|
|
504
|
-
},
|
|
505
|
-
async emitAndWrite(emitOptions) {
|
|
542
|
+
async emit(emitOptions = {}) {
|
|
543
|
+
const { filterPlugin, filterWorkspace, write = false } = emitOptions;
|
|
506
544
|
const start = performance.now();
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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);
|
|
513
555
|
})
|
|
514
|
-
)
|
|
515
|
-
|
|
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;
|
|
516
581
|
},
|
|
517
582
|
async transformMeta(options2, data) {
|
|
518
583
|
const ctx = {
|
|
519
|
-
...
|
|
584
|
+
...this.getPluginContext(),
|
|
520
585
|
...options2
|
|
521
586
|
};
|
|
522
587
|
data = await transformMetadata(options2, data);
|
|
@@ -528,7 +593,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
528
593
|
},
|
|
529
594
|
async transformFrontmatter(options2, data) {
|
|
530
595
|
const ctx = {
|
|
531
|
-
...
|
|
596
|
+
...this.getPluginContext(),
|
|
532
597
|
...options2
|
|
533
598
|
};
|
|
534
599
|
data = await transformMetadata(options2, data);
|
|
@@ -540,7 +605,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
540
605
|
},
|
|
541
606
|
async transformVFile(options2, file) {
|
|
542
607
|
const ctx = {
|
|
543
|
-
...
|
|
608
|
+
...this.getPluginContext(),
|
|
544
609
|
...options2
|
|
545
610
|
};
|
|
546
611
|
for (const plugin of plugins) {
|
|
@@ -550,11 +615,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
550
615
|
return file;
|
|
551
616
|
}
|
|
552
617
|
};
|
|
553
|
-
const pluginContext = {
|
|
554
|
-
core,
|
|
555
|
-
...options
|
|
556
|
-
};
|
|
557
|
-
return core;
|
|
558
618
|
}
|
|
559
619
|
function postprocessPlugin() {
|
|
560
620
|
const LinkReferenceTypes = `{
|
|
@@ -569,7 +629,7 @@ function postprocessPlugin() {
|
|
|
569
629
|
const lines = [];
|
|
570
630
|
lines.push("{");
|
|
571
631
|
lines.push(" DocData: {");
|
|
572
|
-
for (const collection of this.core.
|
|
632
|
+
for (const collection of this.core.getCollections()) {
|
|
573
633
|
let postprocessOptions;
|
|
574
634
|
switch (collection.type) {
|
|
575
635
|
case "doc":
|
|
@@ -605,29 +665,30 @@ var import_path = __toESM(require("path"), 1);
|
|
|
605
665
|
var import_tinyglobby2 = require("tinyglobby");
|
|
606
666
|
|
|
607
667
|
// src/utils/fs-cache.ts
|
|
608
|
-
var import_lru_cache = require("lru-cache");
|
|
609
668
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
610
|
-
var
|
|
611
|
-
var map = new
|
|
612
|
-
|
|
613
|
-
|
|
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
|
+
}
|
|
614
686
|
function toFullPath(file) {
|
|
615
|
-
if (
|
|
616
|
-
return
|
|
687
|
+
if (import_node_path4.default.isAbsolute(file)) {
|
|
688
|
+
return import_node_path4.default.relative(process.cwd(), file);
|
|
617
689
|
}
|
|
618
690
|
return file;
|
|
619
691
|
}
|
|
620
|
-
function readFileWithCache(file) {
|
|
621
|
-
const fullPath = toFullPath(file);
|
|
622
|
-
const cached = map.get(fullPath);
|
|
623
|
-
if (cached) return cached;
|
|
624
|
-
const read = import_promises2.default.readFile(fullPath).then((s) => s.toString());
|
|
625
|
-
map.set(fullPath, read);
|
|
626
|
-
return read;
|
|
627
|
-
}
|
|
628
|
-
function removeFileCache(file) {
|
|
629
|
-
map.delete(toFullPath(file));
|
|
630
|
-
}
|
|
631
692
|
|
|
632
693
|
// src/plugins/index-file.ts
|
|
633
694
|
var import_crypto = require("crypto");
|
|
@@ -649,6 +710,7 @@ function fumaMatter(input) {
|
|
|
649
710
|
}
|
|
650
711
|
|
|
651
712
|
// src/plugins/index-file.ts
|
|
713
|
+
var indexFileCache = createFSCache();
|
|
652
714
|
function indexFile(options = {}) {
|
|
653
715
|
const {
|
|
654
716
|
target = "default",
|
|
@@ -656,7 +718,6 @@ function indexFile(options = {}) {
|
|
|
656
718
|
browser = true,
|
|
657
719
|
dynamic = true
|
|
658
720
|
} = options;
|
|
659
|
-
let config;
|
|
660
721
|
let dynamicCollections;
|
|
661
722
|
function isDynamic(collection) {
|
|
662
723
|
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
@@ -671,8 +732,8 @@ function indexFile(options = {}) {
|
|
|
671
732
|
const indexFilePlugin = plugin["index-file"];
|
|
672
733
|
if (!indexFilePlugin) continue;
|
|
673
734
|
indexFilePlugin.serverOptions?.call(ctx, serverOptions);
|
|
674
|
-
const
|
|
675
|
-
if (
|
|
735
|
+
const config = indexFilePlugin.generateTypeConfig?.call(ctx);
|
|
736
|
+
if (config) typeConfigs.push(config);
|
|
676
737
|
}
|
|
677
738
|
return {
|
|
678
739
|
serverOptions,
|
|
@@ -681,38 +742,38 @@ function indexFile(options = {}) {
|
|
|
681
742
|
}
|
|
682
743
|
return {
|
|
683
744
|
name: "index-file",
|
|
684
|
-
config(
|
|
685
|
-
|
|
686
|
-
dynamicCollections = config.collectionList.filter(isDynamic);
|
|
745
|
+
config() {
|
|
746
|
+
dynamicCollections = this.core.getCollections().filter(isDynamic);
|
|
687
747
|
},
|
|
688
748
|
configureServer(server) {
|
|
689
749
|
if (!server.watcher) return;
|
|
690
750
|
server.watcher.on("all", async (event, file) => {
|
|
691
|
-
|
|
751
|
+
indexFileCache.delete(file);
|
|
692
752
|
if (dynamicCollections.length === 0) {
|
|
693
753
|
if (target === "vite") return;
|
|
694
754
|
if (target === "default" && event === "change") return;
|
|
695
755
|
}
|
|
696
|
-
const updatedCollection =
|
|
697
|
-
(collection) => collection.hasFile(file)
|
|
698
|
-
);
|
|
756
|
+
const updatedCollection = this.core.getCollections().find((collection) => collection.hasFile(file));
|
|
699
757
|
if (!updatedCollection) return;
|
|
700
758
|
if (!isDynamic(updatedCollection)) {
|
|
701
759
|
if (target === "vite") return;
|
|
702
760
|
if (target === "default" && event === "change") return;
|
|
703
761
|
}
|
|
704
|
-
await this.core.
|
|
705
|
-
filterPlugin: (plugin) => plugin.name === "index-file"
|
|
762
|
+
await this.core.emit({
|
|
763
|
+
filterPlugin: (plugin) => plugin.name === "index-file",
|
|
764
|
+
filterWorkspace: () => false,
|
|
765
|
+
write: true
|
|
706
766
|
});
|
|
707
767
|
});
|
|
708
768
|
},
|
|
709
769
|
async emit() {
|
|
710
770
|
const globCache = /* @__PURE__ */ new Map();
|
|
771
|
+
const { workspace, outDir } = this.core.getOptions();
|
|
711
772
|
const { serverOptions, tc } = generateConfigs(this.core);
|
|
712
|
-
const toEmitEntry = async (
|
|
773
|
+
const toEmitEntry = async (path7, content) => {
|
|
713
774
|
const codegen = createCodegen({
|
|
714
775
|
target,
|
|
715
|
-
outDir
|
|
776
|
+
outDir,
|
|
716
777
|
jsExtension: addJsExtension,
|
|
717
778
|
globCache
|
|
718
779
|
});
|
|
@@ -720,10 +781,11 @@ function indexFile(options = {}) {
|
|
|
720
781
|
core: this.core,
|
|
721
782
|
codegen,
|
|
722
783
|
serverOptions,
|
|
723
|
-
tc
|
|
784
|
+
tc,
|
|
785
|
+
workspace: workspace?.name
|
|
724
786
|
});
|
|
725
787
|
return {
|
|
726
|
-
path:
|
|
788
|
+
path: path7,
|
|
727
789
|
content: codegen.toString()
|
|
728
790
|
};
|
|
729
791
|
};
|
|
@@ -738,12 +800,8 @@ function indexFile(options = {}) {
|
|
|
738
800
|
}
|
|
739
801
|
};
|
|
740
802
|
}
|
|
741
|
-
async function generateServerIndexFile({
|
|
742
|
-
core,
|
|
743
|
-
codegen,
|
|
744
|
-
serverOptions,
|
|
745
|
-
tc
|
|
746
|
-
}) {
|
|
803
|
+
async function generateServerIndexFile(ctx) {
|
|
804
|
+
const { core, codegen, serverOptions, tc } = ctx;
|
|
747
805
|
codegen.lines.push(
|
|
748
806
|
`import { server } from 'fumadocs-mdx/runtime/server';`,
|
|
749
807
|
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
@@ -751,51 +809,48 @@ async function generateServerIndexFile({
|
|
|
751
809
|
`const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
|
|
752
810
|
);
|
|
753
811
|
async function generateCollectionObject(collection) {
|
|
812
|
+
const base = getBase(collection);
|
|
754
813
|
switch (collection.type) {
|
|
755
814
|
case "docs": {
|
|
756
815
|
if (collection.docs.dynamic) return;
|
|
757
816
|
if (collection.docs.async) {
|
|
758
817
|
const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
|
|
759
|
-
generateMetaCollectionGlob(
|
|
760
|
-
generateDocCollectionFrontmatterGlob(
|
|
761
|
-
|
|
762
|
-
collection.docs,
|
|
763
|
-
true
|
|
764
|
-
),
|
|
765
|
-
generateDocCollectionGlob(codegen, collection.docs)
|
|
818
|
+
generateMetaCollectionGlob(ctx, collection.meta, true),
|
|
819
|
+
generateDocCollectionFrontmatterGlob(ctx, collection.docs, true),
|
|
820
|
+
generateDocCollectionGlob(ctx, collection.docs)
|
|
766
821
|
]);
|
|
767
|
-
return `await create.docsLazy("${collection.name}", "${
|
|
822
|
+
return `await create.docsLazy("${collection.name}", "${base}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
|
|
768
823
|
}
|
|
769
824
|
const [metaGlob, docGlob] = await Promise.all([
|
|
770
|
-
generateMetaCollectionGlob(
|
|
771
|
-
generateDocCollectionGlob(
|
|
825
|
+
generateMetaCollectionGlob(ctx, collection.meta, true),
|
|
826
|
+
generateDocCollectionGlob(ctx, collection.docs, true)
|
|
772
827
|
]);
|
|
773
|
-
return `await create.docs("${collection.name}", "${
|
|
828
|
+
return `await create.docs("${collection.name}", "${base}", ${metaGlob}, ${docGlob})`;
|
|
774
829
|
}
|
|
775
830
|
case "doc":
|
|
776
831
|
if (collection.dynamic) return;
|
|
777
832
|
if (collection.async) {
|
|
778
833
|
const [headGlob, bodyGlob] = await Promise.all([
|
|
779
|
-
generateDocCollectionFrontmatterGlob(
|
|
780
|
-
generateDocCollectionGlob(
|
|
834
|
+
generateDocCollectionFrontmatterGlob(ctx, collection, true),
|
|
835
|
+
generateDocCollectionGlob(ctx, collection)
|
|
781
836
|
]);
|
|
782
|
-
return `await create.docLazy("${collection.name}", "${
|
|
837
|
+
return `await create.docLazy("${collection.name}", "${base}", ${headGlob}, ${bodyGlob})`;
|
|
783
838
|
}
|
|
784
|
-
return `await create.doc("${collection.name}", "${
|
|
785
|
-
|
|
839
|
+
return `await create.doc("${collection.name}", "${base}", ${await generateDocCollectionGlob(
|
|
840
|
+
ctx,
|
|
786
841
|
collection,
|
|
787
842
|
true
|
|
788
843
|
)})`;
|
|
789
844
|
case "meta":
|
|
790
|
-
return `await create.meta("${collection.name}", "${
|
|
791
|
-
|
|
845
|
+
return `await create.meta("${collection.name}", "${base}", ${await generateMetaCollectionGlob(
|
|
846
|
+
ctx,
|
|
792
847
|
collection,
|
|
793
848
|
true
|
|
794
849
|
)})`;
|
|
795
850
|
}
|
|
796
851
|
}
|
|
797
852
|
await codegen.pushAsync(
|
|
798
|
-
core.
|
|
853
|
+
core.getCollections().map(async (collection) => {
|
|
799
854
|
const obj = await generateCollectionObject(collection);
|
|
800
855
|
if (!obj) return;
|
|
801
856
|
return `
|
|
@@ -803,22 +858,23 @@ export const ${collection.name} = ${obj};`;
|
|
|
803
858
|
})
|
|
804
859
|
);
|
|
805
860
|
}
|
|
806
|
-
async function generateDynamicIndexFile({
|
|
807
|
-
core,
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
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
|
+
};
|
|
813
869
|
codegen.lines.push(
|
|
814
870
|
`import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
815
871
|
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
816
872
|
"",
|
|
817
|
-
`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)});`
|
|
818
874
|
);
|
|
819
|
-
async function generateCollectionObjectEntry(collection,
|
|
820
|
-
const fullPath = import_path.default.
|
|
821
|
-
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(() => "");
|
|
822
878
|
const parsed = fumaMatter(content);
|
|
823
879
|
const data = await core.transformFrontmatter(
|
|
824
880
|
{
|
|
@@ -836,7 +892,7 @@ async function generateDynamicIndexFile({
|
|
|
836
892
|
for (const [k, v] of Object.entries({
|
|
837
893
|
info: {
|
|
838
894
|
fullPath,
|
|
839
|
-
path:
|
|
895
|
+
path: import_path.default.relative(collection.dir, absolutePath)
|
|
840
896
|
},
|
|
841
897
|
data,
|
|
842
898
|
hash
|
|
@@ -851,7 +907,8 @@ async function generateDynamicIndexFile({
|
|
|
851
907
|
else if (parent.type === "docs") collection = parent.docs;
|
|
852
908
|
if (!collection || !collection.dynamic) return;
|
|
853
909
|
const files = await (0, import_tinyglobby2.glob)(collection.patterns, {
|
|
854
|
-
cwd: collection.dir
|
|
910
|
+
cwd: collection.dir,
|
|
911
|
+
absolute: true
|
|
855
912
|
});
|
|
856
913
|
const entries = await Promise.all(
|
|
857
914
|
files.map((file) => generateCollectionObjectEntry(collection, file))
|
|
@@ -859,18 +916,18 @@ async function generateDynamicIndexFile({
|
|
|
859
916
|
switch (parent.type) {
|
|
860
917
|
case "docs": {
|
|
861
918
|
const metaGlob = await generateMetaCollectionGlob(
|
|
862
|
-
|
|
919
|
+
ctx,
|
|
863
920
|
parent.meta,
|
|
864
921
|
true
|
|
865
922
|
);
|
|
866
|
-
return `await create.docs("${parent.name}", "${parent
|
|
923
|
+
return `await create.docs("${parent.name}", "${getBase(parent)}", ${metaGlob}, ${entries.join(", ")})`;
|
|
867
924
|
}
|
|
868
925
|
case "doc":
|
|
869
|
-
return `await create.doc("${collection.name}", "${collection
|
|
926
|
+
return `await create.doc("${collection.name}", "${getBase(collection)}", ${entries.join(", ")})`;
|
|
870
927
|
}
|
|
871
928
|
}
|
|
872
929
|
await codegen.pushAsync(
|
|
873
|
-
core.
|
|
930
|
+
core.getCollections().map(async (collection) => {
|
|
874
931
|
const obj = await generateCollectionObject(collection);
|
|
875
932
|
if (!obj) return;
|
|
876
933
|
return `
|
|
@@ -878,7 +935,8 @@ export const ${collection.name} = ${obj};`;
|
|
|
878
935
|
})
|
|
879
936
|
);
|
|
880
937
|
}
|
|
881
|
-
async function generateBrowserIndexFile(
|
|
938
|
+
async function generateBrowserIndexFile(ctx) {
|
|
939
|
+
const { core, codegen, tc } = ctx;
|
|
882
940
|
codegen.lines.push(
|
|
883
941
|
`import { browser } from 'fumadocs-mdx/runtime/browser';`,
|
|
884
942
|
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
@@ -893,12 +951,12 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
|
893
951
|
}
|
|
894
952
|
case "doc":
|
|
895
953
|
if (collection.dynamic) return;
|
|
896
|
-
return `create.doc("${collection.name}", ${await generateDocCollectionGlob(
|
|
954
|
+
return `create.doc("${collection.name}", ${await generateDocCollectionGlob(ctx, collection)})`;
|
|
897
955
|
}
|
|
898
956
|
}
|
|
899
957
|
codegen.lines.push("const browserCollections = {");
|
|
900
958
|
await codegen.pushAsync(
|
|
901
|
-
core.
|
|
959
|
+
core.getCollections().map(async (collection) => {
|
|
902
960
|
const obj = await generateCollectionObject(collection);
|
|
903
961
|
if (!obj) return;
|
|
904
962
|
return ident(`${collection.name}: ${obj},`);
|
|
@@ -906,30 +964,36 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
|
906
964
|
);
|
|
907
965
|
codegen.lines.push("};", "export default browserCollections;");
|
|
908
966
|
}
|
|
909
|
-
function
|
|
967
|
+
function getBase(collection) {
|
|
968
|
+
return import_path.default.relative(process.cwd(), collection.dir);
|
|
969
|
+
}
|
|
970
|
+
function generateDocCollectionFrontmatterGlob({ codegen, workspace }, collection, eager = false) {
|
|
910
971
|
return codegen.generateGlobImport(collection.patterns, {
|
|
911
972
|
query: {
|
|
912
973
|
collection: collection.name,
|
|
913
|
-
only: "frontmatter"
|
|
974
|
+
only: "frontmatter",
|
|
975
|
+
workspace
|
|
914
976
|
},
|
|
915
977
|
import: "frontmatter",
|
|
916
978
|
base: collection.dir,
|
|
917
979
|
eager
|
|
918
980
|
});
|
|
919
981
|
}
|
|
920
|
-
function generateDocCollectionGlob(codegen, collection, eager = false) {
|
|
982
|
+
function generateDocCollectionGlob({ codegen, workspace }, collection, eager = false) {
|
|
921
983
|
return codegen.generateGlobImport(collection.patterns, {
|
|
922
984
|
query: {
|
|
923
|
-
collection: collection.name
|
|
985
|
+
collection: collection.name,
|
|
986
|
+
workspace
|
|
924
987
|
},
|
|
925
988
|
base: collection.dir,
|
|
926
989
|
eager
|
|
927
990
|
});
|
|
928
991
|
}
|
|
929
|
-
function generateMetaCollectionGlob(codegen, collection, eager = false) {
|
|
992
|
+
function generateMetaCollectionGlob({ codegen, workspace }, collection, eager = false) {
|
|
930
993
|
return codegen.generateGlobImport(collection.patterns, {
|
|
931
994
|
query: {
|
|
932
|
-
collection: collection.name
|
|
995
|
+
collection: collection.name,
|
|
996
|
+
workspace
|
|
933
997
|
},
|
|
934
998
|
import: "default",
|
|
935
999
|
base: collection.dir,
|
|
@@ -947,9 +1011,11 @@ function createMDX(createOptions = {}) {
|
|
|
947
1011
|
void init(isDev, core);
|
|
948
1012
|
}
|
|
949
1013
|
return (nextConfig = {}) => {
|
|
1014
|
+
const { configPath, outDir } = core.getOptions();
|
|
950
1015
|
const loaderOptions = {
|
|
951
|
-
|
|
952
|
-
|
|
1016
|
+
configPath,
|
|
1017
|
+
outDir,
|
|
1018
|
+
absoluteCompiledConfigPath: path6.resolve(core.getCompiledConfigPath()),
|
|
953
1019
|
isDev
|
|
954
1020
|
};
|
|
955
1021
|
const turbopack = {
|
|
@@ -1026,7 +1092,7 @@ async function init(dev, core) {
|
|
|
1026
1092
|
await core.init({
|
|
1027
1093
|
config: loadConfig(core, true)
|
|
1028
1094
|
});
|
|
1029
|
-
await core.
|
|
1095
|
+
await core.emit({ write: true });
|
|
1030
1096
|
}
|
|
1031
1097
|
async function devServer() {
|
|
1032
1098
|
const { FSWatcher } = await import("chokidar");
|
|
@@ -1037,20 +1103,20 @@ async function init(dev, core) {
|
|
|
1037
1103
|
ignored: [outDir]
|
|
1038
1104
|
});
|
|
1039
1105
|
watcher.add(configPath);
|
|
1040
|
-
for (const collection of core.
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
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()) {
|
|
1045
1111
|
watcher.add(collection.dir);
|
|
1046
1112
|
}
|
|
1047
1113
|
}
|
|
1048
1114
|
watcher.on("ready", () => {
|
|
1049
1115
|
console.log("[MDX] started dev server");
|
|
1050
1116
|
});
|
|
1051
|
-
const absoluteConfigPath =
|
|
1117
|
+
const absoluteConfigPath = path6.resolve(configPath);
|
|
1052
1118
|
watcher.on("all", async (_event, file) => {
|
|
1053
|
-
if (
|
|
1119
|
+
if (path6.resolve(file) === absoluteConfigPath) {
|
|
1054
1120
|
watcher.removeAllListeners();
|
|
1055
1121
|
await watcher.close();
|
|
1056
1122
|
await initOrReload();
|
|
@@ -1075,7 +1141,7 @@ async function postInstall(options) {
|
|
|
1075
1141
|
await core.init({
|
|
1076
1142
|
config: loadConfig(core, true)
|
|
1077
1143
|
});
|
|
1078
|
-
await core.
|
|
1144
|
+
await core.emit({ write: true });
|
|
1079
1145
|
}
|
|
1080
1146
|
function applyDefaults(options) {
|
|
1081
1147
|
return {
|
|
@@ -1085,28 +1151,12 @@ function applyDefaults(options) {
|
|
|
1085
1151
|
};
|
|
1086
1152
|
}
|
|
1087
1153
|
function createNextCore(options) {
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
[options.index && indexFile(options.index)]
|
|
1095
|
-
);
|
|
1096
|
-
return {
|
|
1097
|
-
...core,
|
|
1098
|
-
async emitAndWrite(...args) {
|
|
1099
|
-
try {
|
|
1100
|
-
await core.emitAndWrite(...args);
|
|
1101
|
-
} catch (err) {
|
|
1102
|
-
if (err instanceof ValidationError) {
|
|
1103
|
-
console.error(await err.toStringFormatted());
|
|
1104
|
-
} else {
|
|
1105
|
-
console.error(err);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1154
|
+
return createCore({
|
|
1155
|
+
environment: "next",
|
|
1156
|
+
outDir: options.outDir,
|
|
1157
|
+
configPath: options.configPath,
|
|
1158
|
+
plugins: [options.index && indexFile(options.index)]
|
|
1159
|
+
});
|
|
1110
1160
|
}
|
|
1111
1161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1112
1162
|
0 && (module.exports = {
|