fumadocs-mdx 13.0.3 → 13.0.5
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 +353 -273
- package/dist/bin.js +1 -1
- package/dist/{build-mdx-TtQzmq6W.d.cts → build-mdx-BjXOmv0b.d.cts} +1 -1
- package/dist/{build-mdx--WI4tf2-.d.ts → build-mdx-CY5UldCO.d.ts} +1 -1
- package/dist/bun/index.cjs +177 -57
- package/dist/bun/index.d.cts +2 -2
- package/dist/bun/index.d.ts +2 -2
- package/dist/bun/index.js +26 -34
- package/dist/chunk-2HXTGJBI.js +101 -0
- package/dist/chunk-4JSFLXXT.js +8 -0
- package/dist/{chunk-JVZFH6ND.js → chunk-QXHN25N3.js} +2 -2
- package/dist/{chunk-EELYB2XC.js → chunk-TZ5EQBFW.js} +9 -103
- package/dist/chunk-VUEZTR2H.js +26 -0
- package/dist/{chunk-XQ5O7IPO.js → chunk-XYGORKQA.js} +5 -3
- package/dist/chunk-YAIPHUCZ.js +56 -0
- package/dist/chunk-ZNVPB2IR.js +170 -0
- package/dist/config/index.d.cts +2 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/{core-DhfmVKRA.d.cts → core-DB7TdlyC.d.cts} +21 -7
- package/dist/{core-DhfmVKRA.d.ts → core-DB7TdlyC.d.ts} +21 -7
- package/dist/index-D7s7kCc2.d.cts +7 -0
- package/dist/index-D7s7kCc2.d.ts +7 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/load-from-file-AVYOFOI7.js +7 -0
- package/dist/next/index.cjs +145 -139
- package/dist/next/index.js +56 -36
- package/dist/node/loader.cjs +242 -128
- package/dist/node/loader.d.cts +2 -2
- package/dist/node/loader.d.ts +2 -2
- package/dist/node/loader.js +29 -16
- package/dist/plugins/json-schema.cjs +22 -70
- package/dist/plugins/json-schema.d.cts +2 -2
- package/dist/plugins/json-schema.d.ts +2 -2
- package/dist/plugins/json-schema.js +19 -14
- package/dist/runtime/next/async.cjs +56 -11
- package/dist/runtime/next/async.d.cts +4 -6
- package/dist/runtime/next/async.d.ts +4 -6
- package/dist/runtime/next/async.js +3 -6
- package/dist/runtime/next/index.d.cts +5 -5
- package/dist/runtime/next/index.d.ts +5 -5
- package/dist/runtime/vite/browser.d.cts +3 -3
- package/dist/runtime/vite/browser.d.ts +3 -3
- package/dist/runtime/vite/server.d.cts +3 -3
- package/dist/runtime/vite/server.d.ts +3 -3
- package/dist/{types-zrV4v6mp.d.cts → types-Bnh9n7mj.d.cts} +2 -2
- package/dist/{types-CMva20Zp.d.ts → types-ey1AZqrg.d.ts} +2 -2
- package/dist/vite/index.cjs +238 -159
- package/dist/vite/index.js +113 -118
- package/dist/webpack/{index.cjs → mdx.cjs} +126 -104
- package/dist/webpack/mdx.d.cts +6 -0
- package/dist/webpack/mdx.d.ts +6 -0
- package/dist/webpack/{index.js → mdx.js} +12 -14
- package/dist/webpack/meta.cjs +528 -0
- package/dist/webpack/meta.d.cts +6 -0
- package/dist/webpack/meta.d.ts +6 -0
- package/dist/webpack/meta.js +42 -0
- package/loader-mdx.cjs +1 -1
- package/loader-meta.cjs +7 -0
- package/package.json +6 -3
- package/dist/chunk-U4MQ44TS.js +0 -53
- package/dist/chunk-XZY2AWJI.js +0 -81
- package/dist/chunk-YVCR6FUH.js +0 -82
- package/dist/load-MNG3CLET.js +0 -7
- package/dist/webpack/index.d.cts +0 -15
- package/dist/webpack/index.d.ts +0 -15
package/dist/bin.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { existsSync } from "fs";
|
|
5
5
|
async function start() {
|
|
6
6
|
const [configPath] = process.argv.slice(2);
|
|
7
|
-
const isNext = existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.ts");
|
|
7
|
+
const isNext = existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.mts") || existsSync("next.config.ts");
|
|
8
8
|
if (isNext) {
|
|
9
9
|
const { postInstall } = await import("./next/index.js");
|
|
10
10
|
await postInstall(configPath);
|
|
@@ -3,7 +3,7 @@ import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
|
3
3
|
import { TOCItemType } from 'fumadocs-core/toc';
|
|
4
4
|
import { FC } from 'react';
|
|
5
5
|
import { MDXProps } from 'mdx/types';
|
|
6
|
-
import { E as ExtractedReference } from './core-
|
|
6
|
+
import { E as ExtractedReference } from './core-DB7TdlyC.cjs';
|
|
7
7
|
|
|
8
8
|
type Processor = ReturnType<typeof createProcessor>;
|
|
9
9
|
interface CompilerOptions {
|
|
@@ -3,7 +3,7 @@ import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
|
3
3
|
import { TOCItemType } from 'fumadocs-core/toc';
|
|
4
4
|
import { FC } from 'react';
|
|
5
5
|
import { MDXProps } from 'mdx/types';
|
|
6
|
-
import { E as ExtractedReference } from './core-
|
|
6
|
+
import { E as ExtractedReference } from './core-DB7TdlyC.js';
|
|
7
7
|
|
|
8
8
|
type Processor = ReturnType<typeof createProcessor>;
|
|
9
9
|
interface CompilerOptions {
|
package/dist/bun/index.cjs
CHANGED
|
@@ -118,35 +118,78 @@ var init_preset = __esm({
|
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
// src/config/build.ts
|
|
121
|
+
function buildCollection(name, config) {
|
|
122
|
+
if (config.type === "docs") {
|
|
123
|
+
return {
|
|
124
|
+
...config,
|
|
125
|
+
name,
|
|
126
|
+
meta: buildPrimitiveCollection(name, config.meta),
|
|
127
|
+
docs: buildPrimitiveCollection(name, config.docs)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return buildPrimitiveCollection(name, config);
|
|
131
|
+
}
|
|
132
|
+
function buildPrimitiveCollection(name, { files, ...config }) {
|
|
133
|
+
const supportedFormats = SupportedFormats[config.type];
|
|
134
|
+
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
135
|
+
let matchers;
|
|
136
|
+
return {
|
|
137
|
+
...config,
|
|
138
|
+
name,
|
|
139
|
+
patterns,
|
|
140
|
+
isFileSupported(filePath) {
|
|
141
|
+
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
142
|
+
},
|
|
143
|
+
hasFile(filePath) {
|
|
144
|
+
matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
|
|
145
|
+
(dir) => (0, import_picomatch.default)(patterns, {
|
|
146
|
+
cwd: dir
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
121
153
|
function buildConfig(config) {
|
|
122
154
|
const collections = /* @__PURE__ */ new Map();
|
|
123
|
-
|
|
155
|
+
const loaded = {};
|
|
124
156
|
for (const [k, v] of Object.entries(config)) {
|
|
125
157
|
if (!v) {
|
|
126
158
|
continue;
|
|
127
159
|
}
|
|
128
160
|
if (typeof v === "object" && "type" in v) {
|
|
129
161
|
if (v.type === "docs") {
|
|
130
|
-
collections.set(k, v);
|
|
162
|
+
collections.set(k, buildCollection(k, v));
|
|
131
163
|
continue;
|
|
132
164
|
}
|
|
133
165
|
if (v.type === "doc" || v.type === "meta") {
|
|
134
|
-
collections.set(
|
|
166
|
+
collections.set(
|
|
167
|
+
k,
|
|
168
|
+
buildCollection(k, v)
|
|
169
|
+
);
|
|
135
170
|
continue;
|
|
136
171
|
}
|
|
137
172
|
}
|
|
138
173
|
if (k === "default" && v) {
|
|
139
|
-
|
|
174
|
+
Object.assign(loaded, v);
|
|
140
175
|
continue;
|
|
141
176
|
}
|
|
142
177
|
throw new Error(
|
|
143
178
|
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
144
179
|
);
|
|
145
180
|
}
|
|
181
|
+
if (loaded.collections) {
|
|
182
|
+
for (const [k, v] of Object.entries(loaded.collections)) {
|
|
183
|
+
collections.set(k, buildCollection(k, v));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
146
186
|
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
147
187
|
return {
|
|
148
|
-
global:
|
|
149
|
-
collections,
|
|
188
|
+
global: loaded,
|
|
189
|
+
collectionList: Array.from(collections.values()),
|
|
190
|
+
getCollection(name) {
|
|
191
|
+
return collections.get(name);
|
|
192
|
+
},
|
|
150
193
|
async getDefaultMDXOptions(mode = "default") {
|
|
151
194
|
const cached = mdxOptionsCache.get(mode);
|
|
152
195
|
if (cached) return cached;
|
|
@@ -166,9 +209,15 @@ function buildConfig(config) {
|
|
|
166
209
|
}
|
|
167
210
|
};
|
|
168
211
|
}
|
|
212
|
+
var import_picomatch, SupportedFormats;
|
|
169
213
|
var init_build = __esm({
|
|
170
214
|
"src/config/build.ts"() {
|
|
171
215
|
"use strict";
|
|
216
|
+
import_picomatch = __toESM(require("picomatch"), 1);
|
|
217
|
+
SupportedFormats = {
|
|
218
|
+
doc: ["mdx", "md"],
|
|
219
|
+
meta: ["json", "yaml"]
|
|
220
|
+
};
|
|
172
221
|
}
|
|
173
222
|
});
|
|
174
223
|
|
|
@@ -651,7 +700,7 @@ function createMdxLoader(configLoader) {
|
|
|
651
700
|
);
|
|
652
701
|
};
|
|
653
702
|
}
|
|
654
|
-
const collection = parsed.collection ? config.
|
|
703
|
+
const collection = parsed.collection ? config.getCollection(parsed.collection) : void 0;
|
|
655
704
|
let docCollection;
|
|
656
705
|
switch (collection?.type) {
|
|
657
706
|
case "doc":
|
|
@@ -723,21 +772,16 @@ function countLines(s) {
|
|
|
723
772
|
return num;
|
|
724
773
|
}
|
|
725
774
|
|
|
726
|
-
// src/
|
|
775
|
+
// src/bun/index.ts
|
|
776
|
+
init_build();
|
|
777
|
+
var import_node_url2 = require("url");
|
|
778
|
+
|
|
779
|
+
// src/core.ts
|
|
727
780
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
728
781
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
729
782
|
function findConfigFile() {
|
|
730
783
|
return import_node_path3.default.resolve("source.config.ts");
|
|
731
784
|
}
|
|
732
|
-
|
|
733
|
-
// src/bun/index.ts
|
|
734
|
-
init_build();
|
|
735
|
-
var import_node_querystring = require("querystring");
|
|
736
|
-
var import_node_url = require("url");
|
|
737
|
-
|
|
738
|
-
// src/core.ts
|
|
739
|
-
var import_node_path4 = __toESM(require("path"), 1);
|
|
740
|
-
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
741
785
|
function createCore(options, defaultPlugins = []) {
|
|
742
786
|
let config;
|
|
743
787
|
let plugins2;
|
|
@@ -774,13 +818,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
774
818
|
getConfig() {
|
|
775
819
|
return config;
|
|
776
820
|
},
|
|
777
|
-
creatConfigLoader() {
|
|
778
|
-
return {
|
|
779
|
-
getConfig() {
|
|
780
|
-
return config;
|
|
781
|
-
}
|
|
782
|
-
};
|
|
783
|
-
},
|
|
784
821
|
async initServer(server) {
|
|
785
822
|
for (const plugin of plugins2) {
|
|
786
823
|
await plugin.configureServer?.call(this.getPluginContext(), server);
|
|
@@ -798,9 +835,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
798
835
|
);
|
|
799
836
|
await Promise.all(
|
|
800
837
|
out.flat().map(async (entry) => {
|
|
801
|
-
const file =
|
|
802
|
-
await
|
|
803
|
-
await
|
|
838
|
+
const file = import_node_path3.default.join(options.outDir, entry.path);
|
|
839
|
+
await import_promises2.default.mkdir(import_node_path3.default.dirname(file), { recursive: true });
|
|
840
|
+
await import_promises2.default.writeFile(file, entry.content);
|
|
804
841
|
})
|
|
805
842
|
);
|
|
806
843
|
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
@@ -808,6 +845,108 @@ function createCore(options, defaultPlugins = []) {
|
|
|
808
845
|
};
|
|
809
846
|
}
|
|
810
847
|
|
|
848
|
+
// src/loaders/config.ts
|
|
849
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
850
|
+
function createIntegratedConfigLoader(core) {
|
|
851
|
+
return {
|
|
852
|
+
getConfig() {
|
|
853
|
+
return core.getConfig();
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// src/loaders/meta.ts
|
|
859
|
+
var import_js_yaml2 = require("js-yaml");
|
|
860
|
+
var import_zod2 = require("zod");
|
|
861
|
+
var querySchema2 = import_zod2.z.object({
|
|
862
|
+
collection: import_zod2.z.string().optional()
|
|
863
|
+
}).loose();
|
|
864
|
+
function createMetaLoader(configLoader, resolve2 = {}) {
|
|
865
|
+
const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve2;
|
|
866
|
+
return async ({ filePath, query, source }) => {
|
|
867
|
+
const isJson = filePath.endsWith(".json");
|
|
868
|
+
const parsed = querySchema2.parse(query);
|
|
869
|
+
const collection = parsed.collection ? (await configLoader.getConfig()).getCollection(parsed.collection) : void 0;
|
|
870
|
+
if (!collection) return null;
|
|
871
|
+
let data;
|
|
872
|
+
try {
|
|
873
|
+
data = isJson ? JSON.parse(source) : (0, import_js_yaml2.load)(source);
|
|
874
|
+
} catch (e) {
|
|
875
|
+
throw new Error(`invalid data in ${filePath}`, { cause: e });
|
|
876
|
+
}
|
|
877
|
+
let schema;
|
|
878
|
+
switch (collection?.type) {
|
|
879
|
+
case "meta":
|
|
880
|
+
schema = collection.schema;
|
|
881
|
+
break;
|
|
882
|
+
case "docs":
|
|
883
|
+
schema = collection.meta.schema;
|
|
884
|
+
break;
|
|
885
|
+
}
|
|
886
|
+
if (schema) {
|
|
887
|
+
data = await validate(
|
|
888
|
+
schema,
|
|
889
|
+
data,
|
|
890
|
+
{ path: filePath, source },
|
|
891
|
+
`invalid data in ${filePath}`
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
let code;
|
|
895
|
+
if (isJson) {
|
|
896
|
+
code = resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`;
|
|
897
|
+
} else {
|
|
898
|
+
code = resolveYaml === "yaml" ? (0, import_js_yaml2.dump)(data) : `export default ${JSON.stringify(data)}`;
|
|
899
|
+
}
|
|
900
|
+
return {
|
|
901
|
+
code,
|
|
902
|
+
map: null
|
|
903
|
+
};
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
// src/loaders/adapter.ts
|
|
908
|
+
var import_node_url = require("url");
|
|
909
|
+
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
910
|
+
var import_node_querystring = require("querystring");
|
|
911
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
912
|
+
function toBun(loader, test) {
|
|
913
|
+
return (build) => {
|
|
914
|
+
const queryData = /* @__PURE__ */ new Map();
|
|
915
|
+
build.onResolve({ filter: test }, (args) => {
|
|
916
|
+
const [filePath, query = ""] = args.path.split("?", 2);
|
|
917
|
+
queryData.set(filePath, (0, import_node_querystring.parse)(query));
|
|
918
|
+
return null;
|
|
919
|
+
});
|
|
920
|
+
build.onLoad({ filter: test }, async (args) => {
|
|
921
|
+
const content = await Bun.file(args.path).text();
|
|
922
|
+
const result = await loader({
|
|
923
|
+
source: content,
|
|
924
|
+
query: queryData.get(args.path) ?? {},
|
|
925
|
+
filePath: args.path,
|
|
926
|
+
development: false,
|
|
927
|
+
compiler: {
|
|
928
|
+
addDependency() {
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
if (result === null) {
|
|
933
|
+
return {
|
|
934
|
+
contents: content,
|
|
935
|
+
loader: args.loader
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
return {
|
|
939
|
+
contents: result.code,
|
|
940
|
+
loader: "js"
|
|
941
|
+
};
|
|
942
|
+
});
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// src/loaders/index.ts
|
|
947
|
+
var metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
|
|
948
|
+
var mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
949
|
+
|
|
811
950
|
// src/bun/index.ts
|
|
812
951
|
function createMdxPlugin(options = {}) {
|
|
813
952
|
const {
|
|
@@ -815,39 +954,20 @@ function createMdxPlugin(options = {}) {
|
|
|
815
954
|
outDir = ".source",
|
|
816
955
|
configPath = findConfigFile()
|
|
817
956
|
} = options;
|
|
818
|
-
async function getMdxLoader() {
|
|
819
|
-
const importPath = (0, import_node_url.pathToFileURL)(configPath).href;
|
|
820
|
-
const core = await createCore({
|
|
821
|
-
environment,
|
|
822
|
-
outDir,
|
|
823
|
-
configPath
|
|
824
|
-
}).init({
|
|
825
|
-
config: buildConfig(await import(importPath))
|
|
826
|
-
});
|
|
827
|
-
return createMdxLoader(core.creatConfigLoader());
|
|
828
|
-
}
|
|
829
957
|
return {
|
|
830
958
|
name: "bun-plugin-fumadocs-mdx",
|
|
831
|
-
setup(build) {
|
|
832
|
-
const
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
filePath,
|
|
840
|
-
development: false,
|
|
841
|
-
compiler: {
|
|
842
|
-
addDependency() {
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
});
|
|
846
|
-
return {
|
|
847
|
-
contents: result.code,
|
|
848
|
-
loader: "js"
|
|
849
|
-
};
|
|
959
|
+
async setup(build) {
|
|
960
|
+
const importPath = (0, import_node_url2.pathToFileURL)(configPath).href;
|
|
961
|
+
const core = await createCore({
|
|
962
|
+
environment,
|
|
963
|
+
outDir,
|
|
964
|
+
configPath
|
|
965
|
+
}).init({
|
|
966
|
+
config: buildConfig(await import(importPath))
|
|
850
967
|
});
|
|
968
|
+
const configLoader = createIntegratedConfigLoader(core);
|
|
969
|
+
toBun(createMdxLoader(configLoader), mdxLoaderGlob)(build);
|
|
970
|
+
toBun(createMetaLoader(configLoader), metaLoaderGlob)(build);
|
|
851
971
|
}
|
|
852
972
|
};
|
|
853
973
|
}
|
package/dist/bun/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BunPlugin } from 'bun';
|
|
2
|
-
import { C as CoreOptions } from '../core-
|
|
2
|
+
import { C as CoreOptions } from '../core-DB7TdlyC.cjs';
|
|
3
|
+
import '@mdx-js/mdx';
|
|
3
4
|
import '@standard-schema/spec';
|
|
4
5
|
import 'fumadocs-core/mdx-plugins';
|
|
5
|
-
import '@mdx-js/mdx';
|
|
6
6
|
import 'unified';
|
|
7
7
|
import 'zod';
|
|
8
8
|
import 'chokidar';
|
package/dist/bun/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BunPlugin } from 'bun';
|
|
2
|
-
import { C as CoreOptions } from '../core-
|
|
2
|
+
import { C as CoreOptions } from '../core-DB7TdlyC.js';
|
|
3
|
+
import '@mdx-js/mdx';
|
|
3
4
|
import '@standard-schema/spec';
|
|
4
5
|
import 'fumadocs-core/mdx-plugins';
|
|
5
|
-
import '@mdx-js/mdx';
|
|
6
6
|
import 'unified';
|
|
7
7
|
import 'zod';
|
|
8
8
|
import 'chokidar';
|
package/dist/bun/index.js
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildConfig
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-2HXTGJBI.js";
|
|
4
4
|
import {
|
|
5
5
|
createMdxLoader
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-XYGORKQA.js";
|
|
7
|
+
import {
|
|
8
|
+
createMetaLoader
|
|
9
|
+
} from "../chunk-YAIPHUCZ.js";
|
|
10
|
+
import {
|
|
11
|
+
createIntegratedConfigLoader,
|
|
12
|
+
toBun
|
|
13
|
+
} from "../chunk-ZNVPB2IR.js";
|
|
7
14
|
import "../chunk-3J3WL7WN.js";
|
|
8
15
|
import "../chunk-K5ZLPEIQ.js";
|
|
16
|
+
import {
|
|
17
|
+
mdxLoaderGlob,
|
|
18
|
+
metaLoaderGlob
|
|
19
|
+
} from "../chunk-4JSFLXXT.js";
|
|
20
|
+
import "../chunk-VUEZTR2H.js";
|
|
9
21
|
import {
|
|
10
22
|
createCore,
|
|
11
23
|
findConfigFile
|
|
12
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-TZ5EQBFW.js";
|
|
13
25
|
import "../chunk-VWJKRQZR.js";
|
|
14
26
|
|
|
15
27
|
// src/bun/index.ts
|
|
16
|
-
import { parse } from "querystring";
|
|
17
28
|
import { pathToFileURL } from "url";
|
|
18
29
|
function createMdxPlugin(options = {}) {
|
|
19
30
|
const {
|
|
@@ -21,39 +32,20 @@ function createMdxPlugin(options = {}) {
|
|
|
21
32
|
outDir = ".source",
|
|
22
33
|
configPath = findConfigFile()
|
|
23
34
|
} = options;
|
|
24
|
-
async function getMdxLoader() {
|
|
25
|
-
const importPath = pathToFileURL(configPath).href;
|
|
26
|
-
const core = await createCore({
|
|
27
|
-
environment,
|
|
28
|
-
outDir,
|
|
29
|
-
configPath
|
|
30
|
-
}).init({
|
|
31
|
-
config: buildConfig(await import(importPath))
|
|
32
|
-
});
|
|
33
|
-
return createMdxLoader(core.creatConfigLoader());
|
|
34
|
-
}
|
|
35
35
|
return {
|
|
36
36
|
name: "bun-plugin-fumadocs-mdx",
|
|
37
|
-
setup(build) {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
filePath,
|
|
46
|
-
development: false,
|
|
47
|
-
compiler: {
|
|
48
|
-
addDependency() {
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return {
|
|
53
|
-
contents: result.code,
|
|
54
|
-
loader: "js"
|
|
55
|
-
};
|
|
37
|
+
async setup(build) {
|
|
38
|
+
const importPath = pathToFileURL(configPath).href;
|
|
39
|
+
const core = await createCore({
|
|
40
|
+
environment,
|
|
41
|
+
outDir,
|
|
42
|
+
configPath
|
|
43
|
+
}).init({
|
|
44
|
+
config: buildConfig(await import(importPath))
|
|
56
45
|
});
|
|
46
|
+
const configLoader = createIntegratedConfigLoader(core);
|
|
47
|
+
toBun(createMdxLoader(configLoader), mdxLoaderGlob)(build);
|
|
48
|
+
toBun(createMetaLoader(configLoader), metaLoaderGlob)(build);
|
|
57
49
|
}
|
|
58
50
|
};
|
|
59
51
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// src/config/build.ts
|
|
2
|
+
import picomatch from "picomatch";
|
|
3
|
+
var SupportedFormats = {
|
|
4
|
+
doc: ["mdx", "md"],
|
|
5
|
+
meta: ["json", "yaml"]
|
|
6
|
+
};
|
|
7
|
+
function buildCollection(name, config) {
|
|
8
|
+
if (config.type === "docs") {
|
|
9
|
+
return {
|
|
10
|
+
...config,
|
|
11
|
+
name,
|
|
12
|
+
meta: buildPrimitiveCollection(name, config.meta),
|
|
13
|
+
docs: buildPrimitiveCollection(name, config.docs)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return buildPrimitiveCollection(name, config);
|
|
17
|
+
}
|
|
18
|
+
function buildPrimitiveCollection(name, { files, ...config }) {
|
|
19
|
+
const supportedFormats = SupportedFormats[config.type];
|
|
20
|
+
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
21
|
+
let matchers;
|
|
22
|
+
return {
|
|
23
|
+
...config,
|
|
24
|
+
name,
|
|
25
|
+
patterns,
|
|
26
|
+
isFileSupported(filePath) {
|
|
27
|
+
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
28
|
+
},
|
|
29
|
+
hasFile(filePath) {
|
|
30
|
+
matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
|
|
31
|
+
(dir) => picomatch(patterns, {
|
|
32
|
+
cwd: dir
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function buildConfig(config) {
|
|
40
|
+
const collections = /* @__PURE__ */ new Map();
|
|
41
|
+
const loaded = {};
|
|
42
|
+
for (const [k, v] of Object.entries(config)) {
|
|
43
|
+
if (!v) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (typeof v === "object" && "type" in v) {
|
|
47
|
+
if (v.type === "docs") {
|
|
48
|
+
collections.set(k, buildCollection(k, v));
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (v.type === "doc" || v.type === "meta") {
|
|
52
|
+
collections.set(
|
|
53
|
+
k,
|
|
54
|
+
buildCollection(k, v)
|
|
55
|
+
);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (k === "default" && v) {
|
|
60
|
+
Object.assign(loaded, v);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
if (loaded.collections) {
|
|
68
|
+
for (const [k, v] of Object.entries(loaded.collections)) {
|
|
69
|
+
collections.set(k, buildCollection(k, v));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
73
|
+
return {
|
|
74
|
+
global: loaded,
|
|
75
|
+
collectionList: Array.from(collections.values()),
|
|
76
|
+
getCollection(name) {
|
|
77
|
+
return collections.get(name);
|
|
78
|
+
},
|
|
79
|
+
async getDefaultMDXOptions(mode = "default") {
|
|
80
|
+
const cached = mdxOptionsCache.get(mode);
|
|
81
|
+
if (cached) return cached;
|
|
82
|
+
const input = this.global.mdxOptions;
|
|
83
|
+
async function uncached() {
|
|
84
|
+
const options = typeof input === "function" ? await input() : input;
|
|
85
|
+
const { getDefaultMDXOptions } = await import("./preset-ZMP6U62C.js");
|
|
86
|
+
if (options?.preset === "minimal") return options;
|
|
87
|
+
return getDefaultMDXOptions({
|
|
88
|
+
...options,
|
|
89
|
+
_withoutBundler: mode === "remote"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const result = uncached();
|
|
93
|
+
mdxOptionsCache.set(mode, result);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
buildConfig
|
|
101
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildConfig
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2HXTGJBI.js";
|
|
4
4
|
|
|
5
|
-
// src/
|
|
5
|
+
// src/config/load-from-file.ts
|
|
6
6
|
import * as path from "path";
|
|
7
7
|
import { pathToFileURL } from "url";
|
|
8
8
|
async function compileConfig(configPath, outDir) {
|