fumadocs-mdx 14.0.0 → 14.0.1
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 +270 -201
- package/dist/bun/index.cjs +63 -28
- package/dist/bun/index.d.cts +7 -1
- package/dist/bun/index.d.ts +7 -1
- package/dist/bun/index.js +6 -5
- package/dist/{chunk-5YXP7JLN.js → chunk-5OBUOALK.js} +8 -5
- package/dist/{chunk-XHJCLBZ4.js → chunk-7UKSZSPY.js} +87 -162
- package/dist/{chunk-7L2KNF6B.js → chunk-BEBCWQC7.js} +51 -7
- package/dist/{chunk-5UMZCWKV.js → chunk-IQGEFL2B.js} +1 -1
- package/dist/{chunk-SRSRFOVI.js → chunk-K6HCOGOX.js} +3 -3
- package/dist/{chunk-OXSRIWQW.js → chunk-MTTISKQJ.js} +3 -2
- package/dist/chunk-WBIHDYMN.js +126 -0
- package/dist/config/index.d.cts +6 -1
- package/dist/config/index.d.ts +6 -1
- package/dist/{index-D7JdSMpp.d.cts → core-B9ZoS6sA.d.ts} +73 -4
- package/dist/{index-D7JdSMpp.d.ts → core-DTuP23zu.d.cts} +73 -4
- package/dist/{index-BlVBvy-z.d.ts → index-BD8Woo4m.d.cts} +1 -1
- package/dist/{index-P2NNUkHn.d.cts → index-CNOvhtOn.d.ts} +1 -1
- package/dist/index.d.cts +56 -3
- package/dist/index.d.ts +56 -3
- package/dist/{load-from-file-I3ALLIVB.js → load-from-file-5HUQN36V.js} +1 -1
- package/dist/next/index.cjs +260 -192
- package/dist/next/index.d.cts +7 -2
- package/dist/next/index.d.ts +7 -2
- package/dist/next/index.js +10 -8
- package/dist/node/loader.cjs +72 -37
- package/dist/node/loader.js +3 -3
- package/dist/plugins/index-file.cjs +69 -45
- package/dist/plugins/index-file.d.cts +7 -22
- package/dist/plugins/index-file.d.ts +7 -22
- package/dist/plugins/index-file.js +2 -2
- package/dist/plugins/json-schema.d.cts +7 -1
- package/dist/plugins/json-schema.d.ts +7 -1
- package/dist/plugins/last-modified.cjs +41 -6
- package/dist/plugins/last-modified.d.cts +11 -1
- package/dist/plugins/last-modified.d.ts +11 -1
- package/dist/plugins/last-modified.js +34 -4
- package/dist/runtime/browser.cjs +7 -8
- package/dist/runtime/browser.d.cts +22 -19
- package/dist/runtime/browser.d.ts +22 -19
- package/dist/runtime/browser.js +5 -6
- package/dist/runtime/dynamic.cjs +81 -43
- package/dist/runtime/dynamic.d.cts +12 -12
- package/dist/runtime/dynamic.d.ts +12 -12
- package/dist/runtime/dynamic.js +9 -8
- package/dist/runtime/server.cjs +9 -6
- package/dist/runtime/server.d.cts +10 -157
- package/dist/runtime/server.d.ts +10 -157
- package/dist/runtime/server.js +3 -3
- package/dist/runtime/types.cjs +18 -0
- package/dist/runtime/types.d.cts +61 -0
- package/dist/runtime/types.d.ts +61 -0
- package/dist/runtime/types.js +0 -0
- package/dist/vite/index.cjs +257 -190
- package/dist/vite/index.d.cts +7 -2
- package/dist/vite/index.d.ts +7 -2
- package/dist/vite/index.js +7 -6
- package/dist/webpack/mdx.cjs +60 -25
- package/dist/webpack/mdx.d.cts +8 -2
- package/dist/webpack/mdx.d.ts +8 -2
- package/dist/webpack/mdx.js +4 -4
- package/dist/webpack/meta.cjs +60 -25
- package/dist/webpack/meta.d.cts +8 -2
- package/dist/webpack/meta.d.ts +8 -2
- package/dist/webpack/meta.js +4 -4
- package/package.json +2 -2
- package/dist/chunk-PKI7ZDA5.js +0 -29
package/dist/vite/index.cjs
CHANGED
|
@@ -653,10 +653,11 @@ __export(load_from_file_exports, {
|
|
|
653
653
|
});
|
|
654
654
|
async function compileConfig(core) {
|
|
655
655
|
const { build } = await import("esbuild");
|
|
656
|
+
const { configPath, outDir } = core.getOptions();
|
|
656
657
|
const transformed = await build({
|
|
657
|
-
entryPoints: [{ in:
|
|
658
|
+
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
658
659
|
bundle: true,
|
|
659
|
-
outdir:
|
|
660
|
+
outdir: outDir,
|
|
660
661
|
target: "node20",
|
|
661
662
|
write: true,
|
|
662
663
|
platform: "node",
|
|
@@ -878,31 +879,128 @@ function toVite(loader) {
|
|
|
878
879
|
|
|
879
880
|
// src/core.ts
|
|
880
881
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
881
|
-
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
882
|
-
|
|
883
|
-
// src/utils/codegen/cache.ts
|
|
884
|
-
var import_lru_cache = require("lru-cache");
|
|
885
882
|
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
883
|
+
|
|
884
|
+
// src/utils/codegen.ts
|
|
886
885
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
887
|
-
var
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
886
|
+
var import_tinyglobby = require("tinyglobby");
|
|
887
|
+
function createCodegen({
|
|
888
|
+
target = "default",
|
|
889
|
+
outDir = "",
|
|
890
|
+
jsExtension = false,
|
|
891
|
+
globCache = /* @__PURE__ */ new Map()
|
|
892
|
+
}) {
|
|
893
|
+
let eagerImportId = 0;
|
|
894
|
+
const banner = ["// @ts-nocheck"];
|
|
895
|
+
if (target === "vite") {
|
|
896
|
+
banner.push('/// <reference types="vite/client" />');
|
|
893
897
|
}
|
|
894
|
-
return
|
|
898
|
+
return {
|
|
899
|
+
options: {
|
|
900
|
+
target,
|
|
901
|
+
outDir
|
|
902
|
+
},
|
|
903
|
+
lines: [],
|
|
904
|
+
addImport(statement) {
|
|
905
|
+
this.lines.unshift(statement);
|
|
906
|
+
},
|
|
907
|
+
async pushAsync(insert) {
|
|
908
|
+
for (const line of await Promise.all(insert)) {
|
|
909
|
+
if (line === void 0) continue;
|
|
910
|
+
this.lines.push(line);
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
async generateGlobImport(patterns, options) {
|
|
914
|
+
if (target === "vite") {
|
|
915
|
+
return this.generateViteGlobImport(patterns, options);
|
|
916
|
+
}
|
|
917
|
+
return this.generateNodeGlobImport(patterns, options);
|
|
918
|
+
},
|
|
919
|
+
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
920
|
+
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
921
|
+
normalizeViteGlobPath
|
|
922
|
+
);
|
|
923
|
+
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
924
|
+
{
|
|
925
|
+
base: normalizeViteGlobPath(import_node_path3.default.relative(outDir, base)),
|
|
926
|
+
...rest
|
|
927
|
+
},
|
|
928
|
+
null,
|
|
929
|
+
2
|
|
930
|
+
)})`;
|
|
931
|
+
},
|
|
932
|
+
async generateNodeGlobImport(patterns, {
|
|
933
|
+
base,
|
|
934
|
+
eager = false,
|
|
935
|
+
query = {},
|
|
936
|
+
import: importName
|
|
937
|
+
}) {
|
|
938
|
+
const cacheKey = JSON.stringify({ patterns, base });
|
|
939
|
+
let files = globCache.get(cacheKey);
|
|
940
|
+
if (!files) {
|
|
941
|
+
files = (0, import_tinyglobby.glob)(patterns, {
|
|
942
|
+
cwd: base
|
|
943
|
+
});
|
|
944
|
+
globCache.set(cacheKey, files);
|
|
945
|
+
}
|
|
946
|
+
let code = "{";
|
|
947
|
+
for (const item of await files) {
|
|
948
|
+
const fullPath = import_node_path3.default.join(base, item);
|
|
949
|
+
const searchParams = new URLSearchParams();
|
|
950
|
+
for (const [k, v] of Object.entries(query)) {
|
|
951
|
+
searchParams.set(k, v);
|
|
952
|
+
}
|
|
953
|
+
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
954
|
+
if (eager) {
|
|
955
|
+
const name = `__fd_glob_${eagerImportId++}`;
|
|
956
|
+
this.lines.unshift(
|
|
957
|
+
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
958
|
+
);
|
|
959
|
+
code += `${JSON.stringify(item)}: ${name}, `;
|
|
960
|
+
} else {
|
|
961
|
+
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
962
|
+
if (importName) {
|
|
963
|
+
line += `.then(mod => mod.${importName})`;
|
|
964
|
+
}
|
|
965
|
+
code += `${line}, `;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
code += "}";
|
|
969
|
+
return code;
|
|
970
|
+
},
|
|
971
|
+
formatImportPath(file) {
|
|
972
|
+
const ext = import_node_path3.default.extname(file);
|
|
973
|
+
let filename;
|
|
974
|
+
if (ext === ".ts" && jsExtension) {
|
|
975
|
+
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
976
|
+
} else if (ext === ".ts") {
|
|
977
|
+
filename = file.substring(0, file.length - ext.length);
|
|
978
|
+
} else {
|
|
979
|
+
filename = file;
|
|
980
|
+
}
|
|
981
|
+
const importPath = slash(import_node_path3.default.relative(outDir, filename));
|
|
982
|
+
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
983
|
+
},
|
|
984
|
+
toString() {
|
|
985
|
+
return [...banner, ...this.lines].join("\n");
|
|
986
|
+
}
|
|
987
|
+
};
|
|
895
988
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
if (
|
|
900
|
-
|
|
901
|
-
map.set(fullPath, read);
|
|
902
|
-
return read;
|
|
989
|
+
function normalizeViteGlobPath(file) {
|
|
990
|
+
file = slash(file);
|
|
991
|
+
if (file.startsWith("./")) return file;
|
|
992
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
993
|
+
return `./${file}`;
|
|
903
994
|
}
|
|
904
|
-
function
|
|
905
|
-
|
|
995
|
+
function slash(path8) {
|
|
996
|
+
const isExtendedLengthPath = path8.startsWith("\\\\?\\");
|
|
997
|
+
if (isExtendedLengthPath) {
|
|
998
|
+
return path8;
|
|
999
|
+
}
|
|
1000
|
+
return path8.replaceAll("\\", "/");
|
|
1001
|
+
}
|
|
1002
|
+
function ident(code, tab = 1) {
|
|
1003
|
+
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
906
1004
|
}
|
|
907
1005
|
|
|
908
1006
|
// src/core.ts
|
|
@@ -938,7 +1036,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
938
1036
|
return data;
|
|
939
1037
|
}
|
|
940
1038
|
const core = {
|
|
941
|
-
_options: options,
|
|
942
1039
|
/**
|
|
943
1040
|
* Convenient cache store, reset when config changes
|
|
944
1041
|
*/
|
|
@@ -947,6 +1044,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
947
1044
|
config = await newConfig;
|
|
948
1045
|
this.cache.clear();
|
|
949
1046
|
plugins = await getPlugins([
|
|
1047
|
+
postprocessPlugin(),
|
|
950
1048
|
...defaultPlugins,
|
|
951
1049
|
...config.global.plugins ?? []
|
|
952
1050
|
]);
|
|
@@ -954,7 +1052,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
954
1052
|
const out = await plugin.config?.call(pluginContext, config);
|
|
955
1053
|
if (out) config = out;
|
|
956
1054
|
}
|
|
957
|
-
|
|
1055
|
+
},
|
|
1056
|
+
getOptions() {
|
|
1057
|
+
return options;
|
|
958
1058
|
},
|
|
959
1059
|
getConfig() {
|
|
960
1060
|
return config;
|
|
@@ -965,10 +1065,13 @@ function createCore(options, defaultPlugins = []) {
|
|
|
965
1065
|
getCompiledConfigPath() {
|
|
966
1066
|
return import_node_path4.default.join(options.outDir, "source.config.mjs");
|
|
967
1067
|
},
|
|
1068
|
+
getPlugins() {
|
|
1069
|
+
return plugins;
|
|
1070
|
+
},
|
|
1071
|
+
getPluginContext() {
|
|
1072
|
+
return pluginContext;
|
|
1073
|
+
},
|
|
968
1074
|
async initServer(server) {
|
|
969
|
-
server.watcher?.on("all", async (event, file) => {
|
|
970
|
-
if (event === "change") removeFileCache(file);
|
|
971
|
-
});
|
|
972
1075
|
for (const plugin of plugins) {
|
|
973
1076
|
await plugin.configureServer?.call(pluginContext, server);
|
|
974
1077
|
}
|
|
@@ -987,8 +1090,8 @@ function createCore(options, defaultPlugins = []) {
|
|
|
987
1090
|
await Promise.all(
|
|
988
1091
|
out.map(async (entry) => {
|
|
989
1092
|
const file = import_node_path4.default.join(options.outDir, entry.path);
|
|
990
|
-
await
|
|
991
|
-
await
|
|
1093
|
+
await import_promises3.default.mkdir(import_node_path4.default.dirname(file), { recursive: true });
|
|
1094
|
+
await import_promises3.default.writeFile(file, entry.content);
|
|
992
1095
|
})
|
|
993
1096
|
);
|
|
994
1097
|
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
@@ -1035,9 +1138,48 @@ function createCore(options, defaultPlugins = []) {
|
|
|
1035
1138
|
};
|
|
1036
1139
|
return core;
|
|
1037
1140
|
}
|
|
1141
|
+
function postprocessPlugin() {
|
|
1142
|
+
const LinkReferenceTypes = `{
|
|
1143
|
+
/**
|
|
1144
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
1145
|
+
*/
|
|
1146
|
+
extractedReferences?: import('fumadocs-mdx').ExtractedReference[];
|
|
1147
|
+
}`;
|
|
1148
|
+
return {
|
|
1149
|
+
"index-file": {
|
|
1150
|
+
generateTypeConfig() {
|
|
1151
|
+
const lines = [];
|
|
1152
|
+
lines.push("{");
|
|
1153
|
+
lines.push(" DocData: {");
|
|
1154
|
+
for (const collection of this.core.getConfig().collectionList) {
|
|
1155
|
+
let postprocessOptions;
|
|
1156
|
+
switch (collection.type) {
|
|
1157
|
+
case "doc":
|
|
1158
|
+
postprocessOptions = collection.postprocess;
|
|
1159
|
+
break;
|
|
1160
|
+
case "docs":
|
|
1161
|
+
postprocessOptions = collection.docs.postprocess;
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
if (postprocessOptions?.extractLinkReferences) {
|
|
1165
|
+
lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
lines.push(" }");
|
|
1169
|
+
lines.push("}");
|
|
1170
|
+
return lines.join("\n");
|
|
1171
|
+
},
|
|
1172
|
+
serverOptions(options) {
|
|
1173
|
+
options.doc ??= {};
|
|
1174
|
+
options.doc.passthroughs ??= [];
|
|
1175
|
+
options.doc.passthroughs.push("extractedReferences");
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1038
1180
|
|
|
1039
1181
|
// src/loaders/config.ts
|
|
1040
|
-
var
|
|
1182
|
+
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
1041
1183
|
function createIntegratedConfigLoader(core) {
|
|
1042
1184
|
return {
|
|
1043
1185
|
core,
|
|
@@ -1127,131 +1269,34 @@ function createMetaLoader(configLoader, resolve2 = {}) {
|
|
|
1127
1269
|
|
|
1128
1270
|
// src/plugins/index-file.ts
|
|
1129
1271
|
var import_path = __toESM(require("path"), 1);
|
|
1272
|
+
var import_tinyglobby2 = require("tinyglobby");
|
|
1130
1273
|
|
|
1131
|
-
// src/utils/
|
|
1274
|
+
// src/utils/fs-cache.ts
|
|
1275
|
+
var import_lru_cache = require("lru-cache");
|
|
1276
|
+
var import_promises5 = __toESM(require("fs/promises"), 1);
|
|
1132
1277
|
var import_node_path5 = __toESM(require("path"), 1);
|
|
1133
|
-
var
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
}) {
|
|
1140
|
-
let eagerImportId = 0;
|
|
1141
|
-
const banner = ["// @ts-nocheck"];
|
|
1142
|
-
if (target === "vite") {
|
|
1143
|
-
banner.push('/// <reference types="vite/client" />');
|
|
1278
|
+
var map = new import_lru_cache.LRUCache({
|
|
1279
|
+
max: 100
|
|
1280
|
+
});
|
|
1281
|
+
function toFullPath(file) {
|
|
1282
|
+
if (import_node_path5.default.isAbsolute(file)) {
|
|
1283
|
+
return import_node_path5.default.relative(process.cwd(), file);
|
|
1144
1284
|
}
|
|
1145
|
-
return
|
|
1146
|
-
options: {
|
|
1147
|
-
target,
|
|
1148
|
-
outDir
|
|
1149
|
-
},
|
|
1150
|
-
lines: [],
|
|
1151
|
-
addImport(statement) {
|
|
1152
|
-
this.lines.unshift(statement);
|
|
1153
|
-
},
|
|
1154
|
-
async pushAsync(insert) {
|
|
1155
|
-
for (const line of await Promise.all(insert)) {
|
|
1156
|
-
if (line === void 0) continue;
|
|
1157
|
-
this.lines.push(line);
|
|
1158
|
-
}
|
|
1159
|
-
},
|
|
1160
|
-
async generateGlobImport(patterns, options) {
|
|
1161
|
-
if (target === "vite") {
|
|
1162
|
-
return this.generateViteGlobImport(patterns, options);
|
|
1163
|
-
}
|
|
1164
|
-
return this.generateNodeGlobImport(patterns, options);
|
|
1165
|
-
},
|
|
1166
|
-
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
1167
|
-
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
1168
|
-
normalizeViteGlobPath
|
|
1169
|
-
);
|
|
1170
|
-
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
1171
|
-
{
|
|
1172
|
-
base: normalizeViteGlobPath(import_node_path5.default.relative(outDir, base)),
|
|
1173
|
-
...rest
|
|
1174
|
-
},
|
|
1175
|
-
null,
|
|
1176
|
-
2
|
|
1177
|
-
)})`;
|
|
1178
|
-
},
|
|
1179
|
-
async generateNodeGlobImport(patterns, {
|
|
1180
|
-
base,
|
|
1181
|
-
eager = false,
|
|
1182
|
-
query = {},
|
|
1183
|
-
import: importName
|
|
1184
|
-
}) {
|
|
1185
|
-
const cacheKey = JSON.stringify({ patterns, base });
|
|
1186
|
-
let files = globCache.get(cacheKey);
|
|
1187
|
-
if (!files) {
|
|
1188
|
-
files = (0, import_tinyglobby.glob)(patterns, {
|
|
1189
|
-
cwd: base
|
|
1190
|
-
});
|
|
1191
|
-
globCache.set(cacheKey, files);
|
|
1192
|
-
}
|
|
1193
|
-
let code = "{";
|
|
1194
|
-
for (const item of await files) {
|
|
1195
|
-
const fullPath = import_node_path5.default.join(base, item);
|
|
1196
|
-
const searchParams = new URLSearchParams();
|
|
1197
|
-
for (const [k, v] of Object.entries(query)) {
|
|
1198
|
-
searchParams.set(k, v);
|
|
1199
|
-
}
|
|
1200
|
-
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
1201
|
-
if (eager) {
|
|
1202
|
-
const name = `__fd_glob_${eagerImportId++}`;
|
|
1203
|
-
this.lines.unshift(
|
|
1204
|
-
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
1205
|
-
);
|
|
1206
|
-
code += `${JSON.stringify(item)}: ${name}, `;
|
|
1207
|
-
} else {
|
|
1208
|
-
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
1209
|
-
if (importName) {
|
|
1210
|
-
line += `.then(mod => mod.${importName})`;
|
|
1211
|
-
}
|
|
1212
|
-
code += `${line}, `;
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
code += "}";
|
|
1216
|
-
return code;
|
|
1217
|
-
},
|
|
1218
|
-
formatImportPath(file) {
|
|
1219
|
-
const ext = import_node_path5.default.extname(file);
|
|
1220
|
-
let filename;
|
|
1221
|
-
if (ext === ".ts" && jsExtension) {
|
|
1222
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
1223
|
-
} else if (ext === ".ts") {
|
|
1224
|
-
filename = file.substring(0, file.length - ext.length);
|
|
1225
|
-
} else {
|
|
1226
|
-
filename = file;
|
|
1227
|
-
}
|
|
1228
|
-
const importPath = slash(import_node_path5.default.relative(outDir, filename));
|
|
1229
|
-
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
1230
|
-
},
|
|
1231
|
-
toString() {
|
|
1232
|
-
return [...banner, ...this.lines].join("\n");
|
|
1233
|
-
}
|
|
1234
|
-
};
|
|
1235
|
-
}
|
|
1236
|
-
function normalizeViteGlobPath(file) {
|
|
1237
|
-
file = slash(file);
|
|
1238
|
-
if (file.startsWith("./")) return file;
|
|
1239
|
-
if (file.startsWith("/")) return `.${file}`;
|
|
1240
|
-
return `./${file}`;
|
|
1285
|
+
return file;
|
|
1241
1286
|
}
|
|
1242
|
-
function
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1287
|
+
function readFileWithCache(file) {
|
|
1288
|
+
const fullPath = toFullPath(file);
|
|
1289
|
+
const cached = map.get(fullPath);
|
|
1290
|
+
if (cached) return cached;
|
|
1291
|
+
const read = import_promises5.default.readFile(fullPath).then((s) => s.toString());
|
|
1292
|
+
map.set(fullPath, read);
|
|
1293
|
+
return read;
|
|
1248
1294
|
}
|
|
1249
|
-
function
|
|
1250
|
-
|
|
1295
|
+
function removeFileCache(file) {
|
|
1296
|
+
map.delete(toFullPath(file));
|
|
1251
1297
|
}
|
|
1252
1298
|
|
|
1253
1299
|
// src/plugins/index-file.ts
|
|
1254
|
-
var import_tinyglobby2 = require("tinyglobby");
|
|
1255
1300
|
var import_crypto = require("crypto");
|
|
1256
1301
|
init_fuma_matter();
|
|
1257
1302
|
function indexFile(options = {}) {
|
|
@@ -1266,6 +1311,25 @@ function indexFile(options = {}) {
|
|
|
1266
1311
|
function isDynamic(collection) {
|
|
1267
1312
|
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
1268
1313
|
}
|
|
1314
|
+
function generateConfigs(core) {
|
|
1315
|
+
const serverOptions = {};
|
|
1316
|
+
const typeConfigs = [];
|
|
1317
|
+
const ctx = core.getPluginContext();
|
|
1318
|
+
for (const plugin of core.getPlugins()) {
|
|
1319
|
+
const indexFilePlugin = plugin["index-file"];
|
|
1320
|
+
if (!indexFilePlugin) continue;
|
|
1321
|
+
indexFilePlugin.serverOptions?.call(ctx, serverOptions);
|
|
1322
|
+
const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
|
|
1323
|
+
if (config2) typeConfigs.push(config2);
|
|
1324
|
+
}
|
|
1325
|
+
if (typeConfigs.length === 0) {
|
|
1326
|
+
typeConfigs.push("{ DocData: {} }");
|
|
1327
|
+
}
|
|
1328
|
+
return {
|
|
1329
|
+
serverOptions,
|
|
1330
|
+
tc: typeConfigs.join(" & ")
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1269
1333
|
return {
|
|
1270
1334
|
name: "index-file",
|
|
1271
1335
|
config(v) {
|
|
@@ -1275,6 +1339,7 @@ function indexFile(options = {}) {
|
|
|
1275
1339
|
configureServer(server) {
|
|
1276
1340
|
if (!server.watcher) return;
|
|
1277
1341
|
server.watcher.on("all", async (event, file) => {
|
|
1342
|
+
removeFileCache(file);
|
|
1278
1343
|
if (dynamicCollections.length === 0) {
|
|
1279
1344
|
if (target === "vite") return;
|
|
1280
1345
|
if (target === "default" && event === "change") return;
|
|
@@ -1294,48 +1359,47 @@ function indexFile(options = {}) {
|
|
|
1294
1359
|
},
|
|
1295
1360
|
async emit() {
|
|
1296
1361
|
const globCache = /* @__PURE__ */ new Map();
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1362
|
+
const { serverOptions, tc } = generateConfigs(this.core);
|
|
1363
|
+
const toEmitEntry = async (path8, content) => {
|
|
1364
|
+
const codegen = createCodegen({
|
|
1365
|
+
target,
|
|
1366
|
+
outDir: this.outDir,
|
|
1367
|
+
jsExtension: addJsExtension,
|
|
1368
|
+
globCache
|
|
1369
|
+
});
|
|
1370
|
+
await content({
|
|
1371
|
+
core: this.core,
|
|
1372
|
+
codegen,
|
|
1373
|
+
serverOptions,
|
|
1374
|
+
tc
|
|
1375
|
+
});
|
|
1304
1376
|
return {
|
|
1305
1377
|
path: path8,
|
|
1306
|
-
content:
|
|
1378
|
+
content: codegen.toString()
|
|
1307
1379
|
};
|
|
1308
|
-
}
|
|
1380
|
+
};
|
|
1309
1381
|
const out = [
|
|
1310
|
-
toEmitEntry(
|
|
1311
|
-
"server.ts",
|
|
1312
|
-
generateServerIndexFile(makeCodeGen(), config, this.configPath)
|
|
1313
|
-
)
|
|
1382
|
+
toEmitEntry("server.ts", generateServerIndexFile)
|
|
1314
1383
|
];
|
|
1315
1384
|
if (dynamic)
|
|
1316
|
-
out.push(
|
|
1317
|
-
toEmitEntry(
|
|
1318
|
-
"dynamic.ts",
|
|
1319
|
-
generateDynamicIndexFile(this.core, makeCodeGen())
|
|
1320
|
-
)
|
|
1321
|
-
);
|
|
1385
|
+
out.push(toEmitEntry("dynamic.ts", generateDynamicIndexFile));
|
|
1322
1386
|
if (browser)
|
|
1323
|
-
out.push(
|
|
1324
|
-
toEmitEntry(
|
|
1325
|
-
"browser.ts",
|
|
1326
|
-
generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
|
|
1327
|
-
)
|
|
1328
|
-
);
|
|
1387
|
+
out.push(toEmitEntry("browser.ts", generateBrowserIndexFile));
|
|
1329
1388
|
return await Promise.all(out);
|
|
1330
1389
|
}
|
|
1331
1390
|
};
|
|
1332
1391
|
}
|
|
1333
|
-
async function generateServerIndexFile(
|
|
1392
|
+
async function generateServerIndexFile({
|
|
1393
|
+
core,
|
|
1394
|
+
codegen,
|
|
1395
|
+
serverOptions,
|
|
1396
|
+
tc
|
|
1397
|
+
}) {
|
|
1334
1398
|
codegen.lines.push(
|
|
1335
|
-
`import {
|
|
1336
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
1399
|
+
`import { server } from 'fumadocs-mdx/runtime/server';`,
|
|
1400
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
1337
1401
|
"",
|
|
1338
|
-
`const create =
|
|
1402
|
+
`const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
|
|
1339
1403
|
);
|
|
1340
1404
|
async function generateCollectionObject(collection) {
|
|
1341
1405
|
switch (collection.type) {
|
|
@@ -1382,22 +1446,26 @@ async function generateServerIndexFile(codegen, config, configPath) {
|
|
|
1382
1446
|
}
|
|
1383
1447
|
}
|
|
1384
1448
|
await codegen.pushAsync(
|
|
1385
|
-
|
|
1449
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
1386
1450
|
const obj = await generateCollectionObject(collection);
|
|
1387
1451
|
if (!obj) return;
|
|
1388
1452
|
return `
|
|
1389
1453
|
export const ${collection.name} = ${obj};`;
|
|
1390
1454
|
})
|
|
1391
1455
|
);
|
|
1392
|
-
return codegen.toString();
|
|
1393
1456
|
}
|
|
1394
|
-
async function generateDynamicIndexFile(
|
|
1395
|
-
|
|
1457
|
+
async function generateDynamicIndexFile({
|
|
1458
|
+
core,
|
|
1459
|
+
codegen,
|
|
1460
|
+
serverOptions,
|
|
1461
|
+
tc
|
|
1462
|
+
}) {
|
|
1463
|
+
const { configPath } = core.getOptions();
|
|
1396
1464
|
codegen.lines.push(
|
|
1397
|
-
`import {
|
|
1465
|
+
`import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
1398
1466
|
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
1399
1467
|
"",
|
|
1400
|
-
`const create = await
|
|
1468
|
+
`const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
|
|
1401
1469
|
);
|
|
1402
1470
|
async function generateCollectionObjectEntry(collection, file) {
|
|
1403
1471
|
const fullPath = import_path.default.join(collection.dir, file);
|
|
@@ -1460,14 +1528,13 @@ async function generateDynamicIndexFile(core, codegen) {
|
|
|
1460
1528
|
export const ${collection.name} = ${obj};`;
|
|
1461
1529
|
})
|
|
1462
1530
|
);
|
|
1463
|
-
return codegen.toString();
|
|
1464
1531
|
}
|
|
1465
|
-
async function generateBrowserIndexFile(
|
|
1532
|
+
async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
1466
1533
|
codegen.lines.push(
|
|
1467
|
-
`import {
|
|
1468
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
1534
|
+
`import { browser } from 'fumadocs-mdx/runtime/browser';`,
|
|
1535
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
1469
1536
|
"",
|
|
1470
|
-
`const create =
|
|
1537
|
+
`const create = browser<typeof Config, ${tc}>();`
|
|
1471
1538
|
);
|
|
1472
1539
|
async function generateCollectionObject(collection) {
|
|
1473
1540
|
switch (collection.type) {
|
|
@@ -1482,14 +1549,13 @@ async function generateBrowserIndexFile(codegen, config, configPath) {
|
|
|
1482
1549
|
}
|
|
1483
1550
|
codegen.lines.push("const browserCollections = {");
|
|
1484
1551
|
await codegen.pushAsync(
|
|
1485
|
-
|
|
1552
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
1486
1553
|
const obj = await generateCollectionObject(collection);
|
|
1487
1554
|
if (!obj) return;
|
|
1488
1555
|
return ident(`${collection.name}: ${obj},`);
|
|
1489
1556
|
})
|
|
1490
1557
|
);
|
|
1491
1558
|
codegen.lines.push("};", "export default browserCollections;");
|
|
1492
|
-
return codegen.toString();
|
|
1493
1559
|
}
|
|
1494
1560
|
function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
|
|
1495
1561
|
return codegen.generateGlobImport(collection.patterns, {
|
|
@@ -1526,7 +1592,8 @@ function generateMetaCollectionGlob(codegen, collection, eager = false) {
|
|
|
1526
1592
|
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
1527
1593
|
async function mdx(config, pluginOptions = {}) {
|
|
1528
1594
|
const options = applyDefaults(pluginOptions);
|
|
1529
|
-
const core =
|
|
1595
|
+
const core = createViteCore(options);
|
|
1596
|
+
await core.init({
|
|
1530
1597
|
config: buildConfig(config)
|
|
1531
1598
|
});
|
|
1532
1599
|
const configLoader = createIntegratedConfigLoader(core);
|
package/dist/vite/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { IndexFilePluginOptions } from '../
|
|
3
|
-
import '../index-D7JdSMpp.cjs';
|
|
2
|
+
import { I as IndexFilePluginOptions } from '../core-DTuP23zu.cjs';
|
|
4
3
|
import '@mdx-js/mdx';
|
|
5
4
|
import '@standard-schema/spec';
|
|
6
5
|
import 'unified';
|
|
@@ -8,6 +7,12 @@ import 'fumadocs-core/mdx-plugins';
|
|
|
8
7
|
import 'zod';
|
|
9
8
|
import 'chokidar';
|
|
10
9
|
import 'vfile';
|
|
10
|
+
import 'fumadocs-core/source';
|
|
11
|
+
import '../runtime/types.cjs';
|
|
12
|
+
import 'fumadocs-core/mdx-plugins/remark-structure';
|
|
13
|
+
import 'fumadocs-core/toc';
|
|
14
|
+
import 'mdast';
|
|
15
|
+
import 'mdx/types';
|
|
11
16
|
|
|
12
17
|
interface PluginOptions {
|
|
13
18
|
/**
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
-
import { IndexFilePluginOptions } from '../
|
|
3
|
-
import '../index-D7JdSMpp.js';
|
|
2
|
+
import { I as IndexFilePluginOptions } from '../core-B9ZoS6sA.js';
|
|
4
3
|
import '@mdx-js/mdx';
|
|
5
4
|
import '@standard-schema/spec';
|
|
6
5
|
import 'unified';
|
|
@@ -8,6 +7,12 @@ import 'fumadocs-core/mdx-plugins';
|
|
|
8
7
|
import 'zod';
|
|
9
8
|
import 'chokidar';
|
|
10
9
|
import 'vfile';
|
|
10
|
+
import 'fumadocs-core/source';
|
|
11
|
+
import '../runtime/types.js';
|
|
12
|
+
import 'fumadocs-core/mdx-plugins/remark-structure';
|
|
13
|
+
import 'fumadocs-core/toc';
|
|
14
|
+
import 'mdast';
|
|
15
|
+
import 'mdx/types';
|
|
11
16
|
|
|
12
17
|
interface PluginOptions {
|
|
13
18
|
/**
|
package/dist/vite/index.js
CHANGED
|
@@ -11,17 +11,17 @@ import {
|
|
|
11
11
|
import {
|
|
12
12
|
createIntegratedConfigLoader,
|
|
13
13
|
toVite
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-K6HCOGOX.js";
|
|
15
15
|
import "../chunk-4JSFLXXT.js";
|
|
16
16
|
import {
|
|
17
17
|
ValidationError,
|
|
18
18
|
_Defaults,
|
|
19
19
|
createCore
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-BEBCWQC7.js";
|
|
21
21
|
import {
|
|
22
22
|
indexFile
|
|
23
|
-
} from "../chunk-
|
|
24
|
-
import "../chunk-
|
|
23
|
+
} from "../chunk-7UKSZSPY.js";
|
|
24
|
+
import "../chunk-WBIHDYMN.js";
|
|
25
25
|
import "../chunk-VWJKRQZR.js";
|
|
26
26
|
|
|
27
27
|
// src/vite/index.ts
|
|
@@ -29,7 +29,8 @@ import { mergeConfig } from "vite";
|
|
|
29
29
|
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
30
30
|
async function mdx(config, pluginOptions = {}) {
|
|
31
31
|
const options = applyDefaults(pluginOptions);
|
|
32
|
-
const core =
|
|
32
|
+
const core = createViteCore(options);
|
|
33
|
+
await core.init({
|
|
33
34
|
config: buildConfig(config)
|
|
34
35
|
});
|
|
35
36
|
const configLoader = createIntegratedConfigLoader(core);
|
|
@@ -82,7 +83,7 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
async function postInstall(pluginOptions = {}) {
|
|
85
|
-
const { loadConfig } = await import("../load-from-file-
|
|
86
|
+
const { loadConfig } = await import("../load-from-file-5HUQN36V.js");
|
|
86
87
|
const core = createViteCore(applyDefaults(pluginOptions));
|
|
87
88
|
await core.init({
|
|
88
89
|
config: loadConfig(core, true)
|