fumadocs-mdx 13.0.0 → 13.0.2
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 +294 -257
- package/dist/{build-mdx-CzrQDBRZ.d.ts → build-mdx-CCNr86q6.d.ts} +1 -1
- package/dist/{build-mdx-BHG-_uxo.d.cts → build-mdx-D-r3_eQL.d.cts} +1 -1
- package/dist/bun/index.cjs +114 -34
- package/dist/bun/index.d.cts +8 -3
- package/dist/bun/index.d.ts +8 -3
- package/dist/bun/index.js +20 -10
- package/dist/{chunk-6Y5JDZHD.js → chunk-CXA4JO4Z.js} +1 -21
- package/dist/chunk-EELYB2XC.js +207 -0
- package/dist/{chunk-CEA6MYJU.js → chunk-XQ5O7IPO.js} +29 -27
- package/dist/chunk-XZY2AWJI.js +81 -0
- package/dist/{chunk-XV5Z4BFL.js → chunk-YVCR6FUH.js} +1 -1
- package/dist/config/index.d.cts +2 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/{define-BCNh3n4O.d.cts → core-B6j6Fxse.d.cts} +101 -38
- package/dist/{define-bck_EB4t.d.ts → core-B6j6Fxse.d.ts} +101 -38
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/next/index.cjs +195 -163
- package/dist/next/index.js +79 -71
- package/dist/node/loader.cjs +120 -35
- package/dist/node/loader.js +10 -5
- package/dist/plugins/json-schema.cjs +103 -2
- package/dist/plugins/json-schema.d.cts +12 -4
- package/dist/plugins/json-schema.d.ts +12 -4
- package/dist/plugins/json-schema.js +40 -2
- package/dist/runtime/next/async.d.cts +4 -4
- package/dist/runtime/next/async.d.ts +4 -4
- package/dist/runtime/next/async.js +3 -3
- package/dist/runtime/next/index.d.cts +5 -5
- package/dist/runtime/next/index.d.ts +5 -5
- package/dist/runtime/vite/browser.d.cts +3 -3
- package/dist/runtime/vite/browser.d.ts +3 -3
- package/dist/runtime/vite/server.d.cts +3 -3
- package/dist/runtime/vite/server.d.ts +3 -3
- package/dist/{types-1cCFEzWt.d.ts → types-AGzTfBmf.d.ts} +1 -1
- package/dist/{types-D5NhXTJY.d.cts → types-DKGMoay5.d.cts} +1 -1
- package/dist/vite/index.cjs +145 -108
- package/dist/vite/index.js +53 -45
- package/dist/{loader-mdx.cjs → webpack/index.cjs} +151 -58
- package/dist/webpack/index.js +44 -0
- package/loader-mdx.cjs +1 -1
- package/package.json +4 -3
- package/dist/chunk-4MAYA5QX.js +0 -44
- package/dist/chunk-HI62EXSB.js +0 -127
- package/dist/loader-mdx.js +0 -39
- package/dist/plugins/index.cjs +0 -78
- package/dist/plugins/index.d.cts +0 -7
- package/dist/plugins/index.d.ts +0 -7
- package/dist/plugins/index.js +0 -6
- package/dist/remark-postprocess-K233ZVBK.d.cts +0 -22
- package/dist/remark-postprocess-K233ZVBK.d.ts +0 -22
- package/dist/watcher-WXJDWRZY.js +0 -22
- /package/dist/{loader-mdx.d.cts → webpack/index.d.cts} +0 -0
- /package/dist/{loader-mdx.d.ts → webpack/index.d.ts} +0 -0
package/dist/vite/index.cjs
CHANGED
|
@@ -199,18 +199,18 @@ async function compileConfig(configPath, outDir) {
|
|
|
199
199
|
}
|
|
200
200
|
async function loadConfig(configPath, outDir, build = false) {
|
|
201
201
|
if (build) await compileConfig(configPath, outDir);
|
|
202
|
-
const url = (0, import_node_url3.pathToFileURL)(
|
|
202
|
+
const url = (0, import_node_url3.pathToFileURL)(path11.resolve(outDir, "source.config.mjs"));
|
|
203
203
|
url.searchParams.set("hash", Date.now().toString());
|
|
204
204
|
const config = import(url.href).then(
|
|
205
205
|
(loaded) => buildConfig(loaded)
|
|
206
206
|
);
|
|
207
207
|
return await config;
|
|
208
208
|
}
|
|
209
|
-
var
|
|
209
|
+
var path11, import_node_url3;
|
|
210
210
|
var init_load = __esm({
|
|
211
211
|
"src/loaders/config/load.ts"() {
|
|
212
212
|
"use strict";
|
|
213
|
-
|
|
213
|
+
path11 = __toESM(require("path"), 1);
|
|
214
214
|
import_node_url3 = require("url");
|
|
215
215
|
init_build();
|
|
216
216
|
}
|
|
@@ -266,7 +266,7 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
// src/vite/index.ts
|
|
269
|
-
var
|
|
269
|
+
var path12 = __toESM(require("path"), 1);
|
|
270
270
|
var import_js_yaml2 = require("js-yaml");
|
|
271
271
|
|
|
272
272
|
// src/utils/fuma-matter.ts
|
|
@@ -675,14 +675,6 @@ var cacheEntry = import_zod.z.object({
|
|
|
675
675
|
map: import_zod.z.any().optional(),
|
|
676
676
|
hash: import_zod.z.string().optional()
|
|
677
677
|
});
|
|
678
|
-
var hashes = /* @__PURE__ */ new WeakMap();
|
|
679
|
-
function getConfigHash(config) {
|
|
680
|
-
let hash = hashes.get(config);
|
|
681
|
-
if (hash) return hash;
|
|
682
|
-
hash = Date.now().toString();
|
|
683
|
-
hashes.set(config, hash);
|
|
684
|
-
return hash;
|
|
685
|
-
}
|
|
686
678
|
function createMdxLoader(configLoader) {
|
|
687
679
|
return async ({
|
|
688
680
|
source: value,
|
|
@@ -693,14 +685,25 @@ function createMdxLoader(configLoader) {
|
|
|
693
685
|
}) => {
|
|
694
686
|
const matter = fumaMatter(value);
|
|
695
687
|
const parsed = querySchema.parse(query);
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
688
|
+
const config = await configLoader.getConfig();
|
|
689
|
+
let after;
|
|
690
|
+
if (!isDevelopment && config.global.experimentalBuildCache) {
|
|
691
|
+
const cacheDir = config.global.experimentalBuildCache;
|
|
692
|
+
const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
|
|
700
693
|
const cached = await import_promises.default.readFile(import_node_path2.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
|
|
701
694
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
695
|
+
after = async () => {
|
|
696
|
+
await import_promises.default.mkdir(cacheDir, { recursive: true });
|
|
697
|
+
await import_promises.default.writeFile(
|
|
698
|
+
import_node_path2.default.join(cacheDir, cacheKey),
|
|
699
|
+
JSON.stringify({
|
|
700
|
+
...out,
|
|
701
|
+
hash: generateCacheHash(value)
|
|
702
|
+
})
|
|
703
|
+
);
|
|
704
|
+
};
|
|
702
705
|
}
|
|
703
|
-
const collection = parsed.collection ?
|
|
706
|
+
const collection = parsed.collection ? config.collections.get(parsed.collection) : void 0;
|
|
704
707
|
let docCollection;
|
|
705
708
|
switch (collection?.type) {
|
|
706
709
|
case "doc":
|
|
@@ -728,16 +731,16 @@ function createMdxLoader(configLoader) {
|
|
|
728
731
|
};
|
|
729
732
|
}
|
|
730
733
|
const data = {};
|
|
731
|
-
if (
|
|
734
|
+
if (config.global.lastModifiedTime === "git") {
|
|
732
735
|
data.lastModified = (await getGitTimestamp(filePath))?.getTime();
|
|
733
736
|
}
|
|
734
737
|
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
735
738
|
const compiled = await buildMDX(
|
|
736
|
-
`${getConfigHash(
|
|
739
|
+
`${getConfigHash(config)}:${parsed.collection ?? "global"}`,
|
|
737
740
|
"\n".repeat(lineOffset) + matter.content,
|
|
738
741
|
{
|
|
739
742
|
development: isDevelopment,
|
|
740
|
-
...docCollection?.mdxOptions ?? await
|
|
743
|
+
...docCollection?.mdxOptions ?? await config.getDefaultMDXOptions(),
|
|
741
744
|
postprocess: docCollection?.postprocess,
|
|
742
745
|
data,
|
|
743
746
|
filePath,
|
|
@@ -749,19 +752,18 @@ function createMdxLoader(configLoader) {
|
|
|
749
752
|
code: String(compiled.value),
|
|
750
753
|
map: compiled.map
|
|
751
754
|
};
|
|
752
|
-
|
|
753
|
-
await import_promises.default.mkdir(cacheDir, { recursive: true });
|
|
754
|
-
await import_promises.default.writeFile(
|
|
755
|
-
import_node_path2.default.join(cacheDir, cacheKey),
|
|
756
|
-
JSON.stringify({
|
|
757
|
-
...out,
|
|
758
|
-
hash: generateCacheHash(value)
|
|
759
|
-
})
|
|
760
|
-
);
|
|
761
|
-
}
|
|
755
|
+
await after?.();
|
|
762
756
|
return out;
|
|
763
757
|
};
|
|
764
758
|
}
|
|
759
|
+
var hashes = /* @__PURE__ */ new WeakMap();
|
|
760
|
+
function getConfigHash(config) {
|
|
761
|
+
let hash = hashes.get(config);
|
|
762
|
+
if (hash) return hash;
|
|
763
|
+
hash = Date.now().toString();
|
|
764
|
+
hashes.set(config, hash);
|
|
765
|
+
return hash;
|
|
766
|
+
}
|
|
765
767
|
function generateCacheHash(input) {
|
|
766
768
|
return (0, import_node_crypto.createHash)("md5").update(input).digest("hex");
|
|
767
769
|
}
|
|
@@ -779,13 +781,6 @@ var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
|
779
781
|
function findConfigFile() {
|
|
780
782
|
return import_node_path3.default.resolve("source.config.ts");
|
|
781
783
|
}
|
|
782
|
-
function resolvedConfig(loaded) {
|
|
783
|
-
return {
|
|
784
|
-
getConfig() {
|
|
785
|
-
return loaded;
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
784
|
|
|
790
785
|
// src/loaders/adapter.ts
|
|
791
786
|
var import_node_url = require("url");
|
|
@@ -840,28 +835,29 @@ function ident(code, tab = 1) {
|
|
|
840
835
|
}
|
|
841
836
|
|
|
842
837
|
// src/utils/collections.ts
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
838
|
+
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
839
|
+
var import_tinyglobby = require("tinyglobby");
|
|
840
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
841
|
+
var SupportedFormats = {
|
|
842
|
+
doc: ["mdx", "md"],
|
|
843
|
+
meta: ["json", "yaml"]
|
|
844
|
+
};
|
|
849
845
|
function getGlobPatterns(collection) {
|
|
850
846
|
if (collection.files) return collection.files;
|
|
851
|
-
return [`**/*.{${
|
|
847
|
+
return [`**/*.{${SupportedFormats[collection.type].join(",")}}`];
|
|
852
848
|
}
|
|
853
849
|
|
|
854
850
|
// src/utils/glob-import.ts
|
|
855
|
-
var
|
|
856
|
-
var
|
|
851
|
+
var import_tinyglobby2 = require("tinyglobby");
|
|
852
|
+
var import_node_path7 = __toESM(require("path"), 1);
|
|
857
853
|
var import_node_url2 = require("url");
|
|
858
854
|
function generateGlobImport(patterns, options) {
|
|
859
855
|
let code = "{";
|
|
860
|
-
const result = (0,
|
|
856
|
+
const result = (0, import_tinyglobby2.globSync)(patterns, {
|
|
861
857
|
cwd: options.base
|
|
862
858
|
});
|
|
863
859
|
for (const item of result) {
|
|
864
|
-
const fullPath =
|
|
860
|
+
const fullPath = import_node_path7.default.join(options.base, item);
|
|
865
861
|
const url = (0, import_node_url2.pathToFileURL)(fullPath);
|
|
866
862
|
for (const [k, v] of Object.entries(options.query ?? {})) {
|
|
867
863
|
url.searchParams.set(k, v);
|
|
@@ -877,7 +873,7 @@ function generateGlobImport(patterns, options) {
|
|
|
877
873
|
}
|
|
878
874
|
|
|
879
875
|
// src/plugins/vite.ts
|
|
880
|
-
var
|
|
876
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
881
877
|
function vite(options) {
|
|
882
878
|
let config;
|
|
883
879
|
return {
|
|
@@ -885,7 +881,6 @@ function vite(options) {
|
|
|
885
881
|
config = v;
|
|
886
882
|
},
|
|
887
883
|
emit() {
|
|
888
|
-
console.log("[Fumadocs MDX] Generating index files");
|
|
889
884
|
return [
|
|
890
885
|
{
|
|
891
886
|
path: "index.ts",
|
|
@@ -918,12 +913,12 @@ ${obj}
|
|
|
918
913
|
}
|
|
919
914
|
function doc(name, collection) {
|
|
920
915
|
const patterns = getGlobPatterns(collection);
|
|
921
|
-
const
|
|
916
|
+
const dir = getCollectionDir(collection);
|
|
922
917
|
const docGlob = generateGlob(patterns, {
|
|
923
918
|
query: {
|
|
924
919
|
collection: name
|
|
925
920
|
},
|
|
926
|
-
base
|
|
921
|
+
base: dir
|
|
927
922
|
});
|
|
928
923
|
if (collection.async) {
|
|
929
924
|
const headBlob = generateGlob(patterns, {
|
|
@@ -932,32 +927,32 @@ ${obj}
|
|
|
932
927
|
collection: name
|
|
933
928
|
},
|
|
934
929
|
import: "frontmatter",
|
|
935
|
-
base
|
|
930
|
+
base: dir
|
|
936
931
|
});
|
|
937
|
-
return `create.docLazy("${name}", "${
|
|
932
|
+
return `create.docLazy("${name}", "${dir}", ${headBlob}, ${docGlob})`;
|
|
938
933
|
}
|
|
939
|
-
return `create.doc("${name}", "${
|
|
934
|
+
return `create.doc("${name}", "${dir}", ${docGlob})`;
|
|
940
935
|
}
|
|
941
936
|
function meta(name, collection) {
|
|
942
937
|
const patterns = getGlobPatterns(collection);
|
|
943
|
-
const
|
|
944
|
-
return `create.meta("${name}", "${
|
|
938
|
+
const dir = getCollectionDir(collection);
|
|
939
|
+
return `create.meta("${name}", "${dir}", ${generateGlob(patterns, {
|
|
945
940
|
import: "default",
|
|
946
|
-
base,
|
|
941
|
+
base: dir,
|
|
947
942
|
query: {
|
|
948
943
|
collection: name
|
|
949
944
|
}
|
|
950
945
|
})})`;
|
|
951
946
|
}
|
|
952
947
|
function generateGlob(patterns, options2) {
|
|
953
|
-
patterns =
|
|
948
|
+
patterns = patterns.map(normalizeGlobPath);
|
|
954
949
|
if (runtime === "node" || runtime === "bun") {
|
|
955
950
|
return generateGlobImport(patterns, options2);
|
|
956
951
|
} else {
|
|
957
952
|
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
958
953
|
{
|
|
959
954
|
...options2,
|
|
960
|
-
base:
|
|
955
|
+
base: normalizeGlobPath(import_node_path8.default.relative(outDir, options2.base))
|
|
961
956
|
},
|
|
962
957
|
null,
|
|
963
958
|
2
|
|
@@ -978,63 +973,100 @@ ${obj}
|
|
|
978
973
|
}
|
|
979
974
|
return lines.join("\n");
|
|
980
975
|
}
|
|
981
|
-
function
|
|
982
|
-
|
|
983
|
-
}
|
|
984
|
-
function enforceRelative(file) {
|
|
976
|
+
function normalizeGlobPath(file) {
|
|
977
|
+
file = slash(file);
|
|
985
978
|
if (file.startsWith("./")) return file;
|
|
986
979
|
if (file.startsWith("/")) return `.${file}`;
|
|
987
980
|
return `./${file}`;
|
|
988
981
|
}
|
|
989
|
-
function
|
|
990
|
-
|
|
982
|
+
function getCollectionDir(collection) {
|
|
983
|
+
const dir = collection.dir;
|
|
991
984
|
if (Array.isArray(dir)) {
|
|
992
985
|
if (dir.length !== 1)
|
|
993
986
|
throw new Error(
|
|
994
987
|
`[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
|
|
995
988
|
);
|
|
996
|
-
|
|
989
|
+
return dir[0];
|
|
990
|
+
}
|
|
991
|
+
return dir;
|
|
992
|
+
}
|
|
993
|
+
function slash(path13) {
|
|
994
|
+
const isExtendedLengthPath = path13.startsWith("\\\\?\\");
|
|
995
|
+
if (isExtendedLengthPath) {
|
|
996
|
+
return path13;
|
|
997
997
|
}
|
|
998
|
-
return
|
|
998
|
+
return path13.replaceAll("\\", "/");
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
|
-
// src/
|
|
1002
|
-
var
|
|
1001
|
+
// src/core.ts
|
|
1002
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
1003
1003
|
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
1004
|
-
function
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
const file = import_node_path8.default.join(context.outDir, entry.path);
|
|
1008
|
-
await import_promises4.default.mkdir(import_node_path8.default.dirname(file), { recursive: true });
|
|
1009
|
-
await import_promises4.default.writeFile(file, entry.content);
|
|
1010
|
-
}
|
|
1004
|
+
function createCore(options, defaultPlugins = []) {
|
|
1005
|
+
let config;
|
|
1006
|
+
let plugins2;
|
|
1011
1007
|
return {
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1008
|
+
_options: options,
|
|
1009
|
+
getPluginContext() {
|
|
1010
|
+
return {
|
|
1011
|
+
core: this,
|
|
1012
|
+
...options
|
|
1013
|
+
};
|
|
1014
|
+
},
|
|
1015
|
+
/**
|
|
1016
|
+
* Convenient cache store, reset when config changes
|
|
1017
|
+
*/
|
|
1018
|
+
cache: /* @__PURE__ */ new Map(),
|
|
1019
|
+
async init({ config: newConfig }) {
|
|
1020
|
+
config = await newConfig;
|
|
1021
|
+
this.cache.clear();
|
|
1022
|
+
plugins2 = [];
|
|
1023
|
+
for await (const option of [
|
|
1024
|
+
...defaultPlugins,
|
|
1025
|
+
...config.global.plugins ?? []
|
|
1026
|
+
]) {
|
|
1017
1027
|
if (!option) continue;
|
|
1018
1028
|
if (Array.isArray(option)) plugins2.push(...option);
|
|
1019
1029
|
else plugins2.push(option);
|
|
1020
1030
|
}
|
|
1021
1031
|
for (const plugin of plugins2) {
|
|
1022
|
-
const out = await plugin.config?.call(
|
|
1032
|
+
const out = await plugin.config?.call(this.getPluginContext(), config);
|
|
1023
1033
|
if (out) config = out;
|
|
1024
1034
|
}
|
|
1035
|
+
return this;
|
|
1036
|
+
},
|
|
1037
|
+
getConfig() {
|
|
1025
1038
|
return config;
|
|
1026
1039
|
},
|
|
1027
|
-
|
|
1040
|
+
creatConfigLoader() {
|
|
1041
|
+
return {
|
|
1042
|
+
getConfig() {
|
|
1043
|
+
return config;
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
},
|
|
1047
|
+
async initServer(server) {
|
|
1048
|
+
for (const plugin of plugins2) {
|
|
1049
|
+
await plugin.configureServer?.call(this.getPluginContext(), server);
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1052
|
+
async emitAndWrite({
|
|
1053
|
+
filterPlugin = () => true
|
|
1054
|
+
} = {}) {
|
|
1055
|
+
const start = performance.now();
|
|
1028
1056
|
const out = await Promise.all(
|
|
1029
1057
|
plugins2.map((plugin) => {
|
|
1030
|
-
|
|
1058
|
+
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
1059
|
+
return plugin.emit.call(this.getPluginContext());
|
|
1031
1060
|
})
|
|
1032
1061
|
);
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1062
|
+
await Promise.all(
|
|
1063
|
+
out.flat().map(async (entry) => {
|
|
1064
|
+
const file = import_node_path9.default.join(options.outDir, entry.path);
|
|
1065
|
+
await import_promises4.default.mkdir(import_node_path9.default.dirname(file), { recursive: true });
|
|
1066
|
+
await import_promises4.default.writeFile(file, entry.content);
|
|
1067
|
+
})
|
|
1068
|
+
);
|
|
1069
|
+
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
1038
1070
|
}
|
|
1039
1071
|
};
|
|
1040
1072
|
}
|
|
@@ -1043,14 +1075,14 @@ function createPluginHandler(context, defaultPlugins = []) {
|
|
|
1043
1075
|
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
1044
1076
|
async function mdx(config, pluginOptions = {}) {
|
|
1045
1077
|
const options = applyDefaults(pluginOptions);
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
const mdxLoader = toVite(createMdxLoader(
|
|
1050
|
-
async function transformMeta(
|
|
1051
|
-
const isJson =
|
|
1078
|
+
const core = await createViteCore(options).init({
|
|
1079
|
+
config: buildConfig(config)
|
|
1080
|
+
});
|
|
1081
|
+
const mdxLoader = toVite(createMdxLoader(core.creatConfigLoader()));
|
|
1082
|
+
async function transformMeta(path13, query, value) {
|
|
1083
|
+
const isJson = path13.endsWith(".json");
|
|
1052
1084
|
const parsed = (0, import_node_querystring2.parse)(query);
|
|
1053
|
-
const collection = parsed.collection ?
|
|
1085
|
+
const collection = parsed.collection ? core.getConfig().collections.get(parsed.collection) : void 0;
|
|
1054
1086
|
if (!collection) return null;
|
|
1055
1087
|
let schema;
|
|
1056
1088
|
switch (collection.type) {
|
|
@@ -1071,8 +1103,8 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
1071
1103
|
const out = await validate(
|
|
1072
1104
|
schema,
|
|
1073
1105
|
data,
|
|
1074
|
-
{ path:
|
|
1075
|
-
`invalid data in ${
|
|
1106
|
+
{ path: path13, source: value },
|
|
1107
|
+
`invalid data in ${path13}`
|
|
1076
1108
|
);
|
|
1077
1109
|
return {
|
|
1078
1110
|
code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
|
|
@@ -1084,7 +1116,7 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
1084
1116
|
// needed, otherwise other plugins will be executed before our `transform`.
|
|
1085
1117
|
enforce: "pre",
|
|
1086
1118
|
config(config2) {
|
|
1087
|
-
if (!updateViteConfig) return config2;
|
|
1119
|
+
if (!options.updateViteConfig) return config2;
|
|
1088
1120
|
return (0, import_vite.mergeConfig)(config2, {
|
|
1089
1121
|
optimizeDeps: {
|
|
1090
1122
|
exclude: FumadocsDeps
|
|
@@ -1096,11 +1128,16 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
1096
1128
|
});
|
|
1097
1129
|
},
|
|
1098
1130
|
async buildStart() {
|
|
1099
|
-
await
|
|
1131
|
+
await core.emitAndWrite();
|
|
1132
|
+
},
|
|
1133
|
+
async configureServer(server) {
|
|
1134
|
+
await core.initServer({
|
|
1135
|
+
watcher: server.watcher
|
|
1136
|
+
});
|
|
1100
1137
|
},
|
|
1101
1138
|
async transform(value, id) {
|
|
1102
1139
|
const [file, query = ""] = id.split("?");
|
|
1103
|
-
const ext =
|
|
1140
|
+
const ext = path12.extname(file);
|
|
1104
1141
|
try {
|
|
1105
1142
|
if ([".yaml", ".json"].includes(ext))
|
|
1106
1143
|
return await transformMeta(file, query, value);
|
|
@@ -1118,17 +1155,17 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
1118
1155
|
async function postInstall(configPath = findConfigFile(), pluginOptions = {}) {
|
|
1119
1156
|
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load(), load_exports));
|
|
1120
1157
|
const options = applyDefaults(pluginOptions);
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1158
|
+
const core = await createViteCore(options).init({
|
|
1159
|
+
config: loadConfig2(configPath, options.outDir, true)
|
|
1160
|
+
});
|
|
1161
|
+
await core.emitAndWrite();
|
|
1125
1162
|
}
|
|
1126
|
-
function
|
|
1163
|
+
function createViteCore({
|
|
1127
1164
|
configPath,
|
|
1128
1165
|
outDir,
|
|
1129
1166
|
generateIndexFile
|
|
1130
1167
|
}) {
|
|
1131
|
-
return
|
|
1168
|
+
return createCore(
|
|
1132
1169
|
{
|
|
1133
1170
|
environment: "vite",
|
|
1134
1171
|
configPath,
|
package/dist/vite/index.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
toVite
|
|
3
|
-
} from "../chunk-XV5Z4BFL.js";
|
|
4
|
-
import {
|
|
5
|
-
getGlobPatterns,
|
|
6
2
|
ident,
|
|
7
3
|
toImportPath
|
|
8
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-CXA4JO4Z.js";
|
|
5
|
+
import {
|
|
6
|
+
buildConfig
|
|
7
|
+
} from "../chunk-U4MQ44TS.js";
|
|
8
|
+
import {
|
|
9
|
+
toVite
|
|
10
|
+
} from "../chunk-YVCR6FUH.js";
|
|
9
11
|
import {
|
|
10
12
|
createMdxLoader
|
|
11
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-XQ5O7IPO.js";
|
|
12
14
|
import "../chunk-3J3WL7WN.js";
|
|
13
15
|
import "../chunk-K5ZLPEIQ.js";
|
|
14
|
-
import {
|
|
15
|
-
buildConfig
|
|
16
|
-
} from "../chunk-U4MQ44TS.js";
|
|
17
16
|
import {
|
|
18
17
|
ValidationError,
|
|
18
|
+
createCore,
|
|
19
19
|
findConfigFile,
|
|
20
|
-
resolvedConfig,
|
|
21
20
|
validate
|
|
22
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-EELYB2XC.js";
|
|
23
22
|
import "../chunk-VWJKRQZR.js";
|
|
24
23
|
import {
|
|
25
|
-
|
|
26
|
-
} from "../chunk-
|
|
24
|
+
getGlobPatterns
|
|
25
|
+
} from "../chunk-XZY2AWJI.js";
|
|
27
26
|
|
|
28
27
|
// src/vite/index.ts
|
|
29
28
|
import {
|
|
@@ -67,7 +66,6 @@ function vite(options) {
|
|
|
67
66
|
config = v;
|
|
68
67
|
},
|
|
69
68
|
emit() {
|
|
70
|
-
console.log("[Fumadocs MDX] Generating index files");
|
|
71
69
|
return [
|
|
72
70
|
{
|
|
73
71
|
path: "index.ts",
|
|
@@ -100,12 +98,12 @@ ${obj}
|
|
|
100
98
|
}
|
|
101
99
|
function doc(name, collection) {
|
|
102
100
|
const patterns = getGlobPatterns(collection);
|
|
103
|
-
const
|
|
101
|
+
const dir = getCollectionDir(collection);
|
|
104
102
|
const docGlob = generateGlob(patterns, {
|
|
105
103
|
query: {
|
|
106
104
|
collection: name
|
|
107
105
|
},
|
|
108
|
-
base
|
|
106
|
+
base: dir
|
|
109
107
|
});
|
|
110
108
|
if (collection.async) {
|
|
111
109
|
const headBlob = generateGlob(patterns, {
|
|
@@ -114,32 +112,32 @@ ${obj}
|
|
|
114
112
|
collection: name
|
|
115
113
|
},
|
|
116
114
|
import: "frontmatter",
|
|
117
|
-
base
|
|
115
|
+
base: dir
|
|
118
116
|
});
|
|
119
|
-
return `create.docLazy("${name}", "${
|
|
117
|
+
return `create.docLazy("${name}", "${dir}", ${headBlob}, ${docGlob})`;
|
|
120
118
|
}
|
|
121
|
-
return `create.doc("${name}", "${
|
|
119
|
+
return `create.doc("${name}", "${dir}", ${docGlob})`;
|
|
122
120
|
}
|
|
123
121
|
function meta(name, collection) {
|
|
124
122
|
const patterns = getGlobPatterns(collection);
|
|
125
|
-
const
|
|
126
|
-
return `create.meta("${name}", "${
|
|
123
|
+
const dir = getCollectionDir(collection);
|
|
124
|
+
return `create.meta("${name}", "${dir}", ${generateGlob(patterns, {
|
|
127
125
|
import: "default",
|
|
128
|
-
base,
|
|
126
|
+
base: dir,
|
|
129
127
|
query: {
|
|
130
128
|
collection: name
|
|
131
129
|
}
|
|
132
130
|
})})`;
|
|
133
131
|
}
|
|
134
132
|
function generateGlob(patterns, options2) {
|
|
135
|
-
patterns =
|
|
133
|
+
patterns = patterns.map(normalizeGlobPath);
|
|
136
134
|
if (runtime === "node" || runtime === "bun") {
|
|
137
135
|
return generateGlobImport(patterns, options2);
|
|
138
136
|
} else {
|
|
139
137
|
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
140
138
|
{
|
|
141
139
|
...options2,
|
|
142
|
-
base: path2.relative(outDir, options2.base)
|
|
140
|
+
base: normalizeGlobPath(path2.relative(outDir, options2.base))
|
|
143
141
|
},
|
|
144
142
|
null,
|
|
145
143
|
2
|
|
@@ -160,38 +158,43 @@ ${obj}
|
|
|
160
158
|
}
|
|
161
159
|
return lines.join("\n");
|
|
162
160
|
}
|
|
163
|
-
function
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
function enforceRelative(file) {
|
|
161
|
+
function normalizeGlobPath(file) {
|
|
162
|
+
file = slash(file);
|
|
167
163
|
if (file.startsWith("./")) return file;
|
|
168
164
|
if (file.startsWith("/")) return `.${file}`;
|
|
169
165
|
return `./${file}`;
|
|
170
166
|
}
|
|
171
|
-
function
|
|
172
|
-
|
|
167
|
+
function getCollectionDir(collection) {
|
|
168
|
+
const dir = collection.dir;
|
|
173
169
|
if (Array.isArray(dir)) {
|
|
174
170
|
if (dir.length !== 1)
|
|
175
171
|
throw new Error(
|
|
176
172
|
`[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
|
|
177
173
|
);
|
|
178
|
-
|
|
174
|
+
return dir[0];
|
|
175
|
+
}
|
|
176
|
+
return dir;
|
|
177
|
+
}
|
|
178
|
+
function slash(path4) {
|
|
179
|
+
const isExtendedLengthPath = path4.startsWith("\\\\?\\");
|
|
180
|
+
if (isExtendedLengthPath) {
|
|
181
|
+
return path4;
|
|
179
182
|
}
|
|
180
|
-
return
|
|
183
|
+
return path4.replaceAll("\\", "/");
|
|
181
184
|
}
|
|
182
185
|
|
|
183
186
|
// src/vite/index.ts
|
|
184
187
|
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
185
188
|
async function mdx(config, pluginOptions = {}) {
|
|
186
189
|
const options = applyDefaults(pluginOptions);
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const mdxLoader = toVite(createMdxLoader(
|
|
190
|
+
const core = await createViteCore(options).init({
|
|
191
|
+
config: buildConfig(config)
|
|
192
|
+
});
|
|
193
|
+
const mdxLoader = toVite(createMdxLoader(core.creatConfigLoader()));
|
|
191
194
|
async function transformMeta(path4, query, value) {
|
|
192
195
|
const isJson = path4.endsWith(".json");
|
|
193
196
|
const parsed = parse(query);
|
|
194
|
-
const collection = parsed.collection ?
|
|
197
|
+
const collection = parsed.collection ? core.getConfig().collections.get(parsed.collection) : void 0;
|
|
195
198
|
if (!collection) return null;
|
|
196
199
|
let schema;
|
|
197
200
|
switch (collection.type) {
|
|
@@ -225,7 +228,7 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
225
228
|
// needed, otherwise other plugins will be executed before our `transform`.
|
|
226
229
|
enforce: "pre",
|
|
227
230
|
config(config2) {
|
|
228
|
-
if (!updateViteConfig) return config2;
|
|
231
|
+
if (!options.updateViteConfig) return config2;
|
|
229
232
|
return mergeConfig(config2, {
|
|
230
233
|
optimizeDeps: {
|
|
231
234
|
exclude: FumadocsDeps
|
|
@@ -237,7 +240,12 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
237
240
|
});
|
|
238
241
|
},
|
|
239
242
|
async buildStart() {
|
|
240
|
-
await
|
|
243
|
+
await core.emitAndWrite();
|
|
244
|
+
},
|
|
245
|
+
async configureServer(server) {
|
|
246
|
+
await core.initServer({
|
|
247
|
+
watcher: server.watcher
|
|
248
|
+
});
|
|
241
249
|
},
|
|
242
250
|
async transform(value, id) {
|
|
243
251
|
const [file, query = ""] = id.split("?");
|
|
@@ -259,17 +267,17 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
259
267
|
async function postInstall(configPath = findConfigFile(), pluginOptions = {}) {
|
|
260
268
|
const { loadConfig } = await import("../load-MNG3CLET.js");
|
|
261
269
|
const options = applyDefaults(pluginOptions);
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
270
|
+
const core = await createViteCore(options).init({
|
|
271
|
+
config: loadConfig(configPath, options.outDir, true)
|
|
272
|
+
});
|
|
273
|
+
await core.emitAndWrite();
|
|
266
274
|
}
|
|
267
|
-
function
|
|
275
|
+
function createViteCore({
|
|
268
276
|
configPath,
|
|
269
277
|
outDir,
|
|
270
278
|
generateIndexFile
|
|
271
279
|
}) {
|
|
272
|
-
return
|
|
280
|
+
return createCore(
|
|
273
281
|
{
|
|
274
282
|
environment: "vite",
|
|
275
283
|
configPath,
|