fumadocs-mdx 13.0.3 → 13.0.4

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.
Files changed (65) hide show
  1. package/dist/bin.cjs +352 -272
  2. package/dist/{build-mdx-TtQzmq6W.d.cts → build-mdx-BjXOmv0b.d.cts} +1 -1
  3. package/dist/{build-mdx--WI4tf2-.d.ts → build-mdx-CY5UldCO.d.ts} +1 -1
  4. package/dist/bun/index.cjs +177 -57
  5. package/dist/bun/index.d.cts +2 -2
  6. package/dist/bun/index.d.ts +2 -2
  7. package/dist/bun/index.js +26 -34
  8. package/dist/chunk-2HXTGJBI.js +101 -0
  9. package/dist/chunk-4JSFLXXT.js +8 -0
  10. package/dist/{chunk-JVZFH6ND.js → chunk-QXHN25N3.js} +2 -2
  11. package/dist/{chunk-EELYB2XC.js → chunk-TZ5EQBFW.js} +9 -103
  12. package/dist/chunk-VUEZTR2H.js +26 -0
  13. package/dist/{chunk-XQ5O7IPO.js → chunk-XYGORKQA.js} +5 -3
  14. package/dist/chunk-YAIPHUCZ.js +56 -0
  15. package/dist/chunk-ZNVPB2IR.js +170 -0
  16. package/dist/config/index.d.cts +2 -2
  17. package/dist/config/index.d.ts +2 -2
  18. package/dist/{core-DhfmVKRA.d.cts → core-DB7TdlyC.d.cts} +21 -7
  19. package/dist/{core-DhfmVKRA.d.ts → core-DB7TdlyC.d.ts} +21 -7
  20. package/dist/index-D7s7kCc2.d.cts +7 -0
  21. package/dist/index-D7s7kCc2.d.ts +7 -0
  22. package/dist/index.d.cts +4 -4
  23. package/dist/index.d.ts +4 -4
  24. package/dist/load-from-file-AVYOFOI7.js +7 -0
  25. package/dist/next/index.cjs +145 -139
  26. package/dist/next/index.js +56 -36
  27. package/dist/node/loader.cjs +242 -128
  28. package/dist/node/loader.d.cts +2 -2
  29. package/dist/node/loader.d.ts +2 -2
  30. package/dist/node/loader.js +29 -16
  31. package/dist/plugins/json-schema.cjs +22 -70
  32. package/dist/plugins/json-schema.d.cts +2 -2
  33. package/dist/plugins/json-schema.d.ts +2 -2
  34. package/dist/plugins/json-schema.js +19 -14
  35. package/dist/runtime/next/async.cjs +56 -11
  36. package/dist/runtime/next/async.d.cts +4 -6
  37. package/dist/runtime/next/async.d.ts +4 -6
  38. package/dist/runtime/next/async.js +3 -6
  39. package/dist/runtime/next/index.d.cts +5 -5
  40. package/dist/runtime/next/index.d.ts +5 -5
  41. package/dist/runtime/vite/browser.d.cts +3 -3
  42. package/dist/runtime/vite/browser.d.ts +3 -3
  43. package/dist/runtime/vite/server.d.cts +3 -3
  44. package/dist/runtime/vite/server.d.ts +3 -3
  45. package/dist/{types-zrV4v6mp.d.cts → types-Bnh9n7mj.d.cts} +2 -2
  46. package/dist/{types-CMva20Zp.d.ts → types-ey1AZqrg.d.ts} +2 -2
  47. package/dist/vite/index.cjs +238 -159
  48. package/dist/vite/index.js +113 -118
  49. package/dist/webpack/{index.cjs → mdx.cjs} +126 -104
  50. package/dist/webpack/mdx.d.cts +6 -0
  51. package/dist/webpack/mdx.d.ts +6 -0
  52. package/dist/webpack/{index.js → mdx.js} +12 -14
  53. package/dist/webpack/meta.cjs +528 -0
  54. package/dist/webpack/meta.d.cts +6 -0
  55. package/dist/webpack/meta.d.ts +6 -0
  56. package/dist/webpack/meta.js +42 -0
  57. package/loader-mdx.cjs +1 -1
  58. package/loader-meta.cjs +7 -0
  59. package/package.json +6 -3
  60. package/dist/chunk-U4MQ44TS.js +0 -53
  61. package/dist/chunk-XZY2AWJI.js +0 -81
  62. package/dist/chunk-YVCR6FUH.js +0 -82
  63. package/dist/load-MNG3CLET.js +0 -7
  64. package/dist/webpack/index.d.cts +0 -15
  65. package/dist/webpack/index.d.ts +0 -15
@@ -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
- let globalConfig = {};
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(k, v);
166
+ collections.set(
167
+ k,
168
+ buildCollection(k, v)
169
+ );
135
170
  continue;
136
171
  }
137
172
  }
138
173
  if (k === "default" && v) {
139
- globalConfig = v;
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: globalConfig,
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,15 +209,21 @@ 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
 
175
- // src/loaders/config/load.ts
176
- var load_exports = {};
177
- __export(load_exports, {
224
+ // src/config/load-from-file.ts
225
+ var load_from_file_exports = {};
226
+ __export(load_from_file_exports, {
178
227
  loadConfig: () => loadConfig
179
228
  });
180
229
  async function compileConfig(configPath, outDir) {
@@ -199,29 +248,29 @@ async function compileConfig(configPath, outDir) {
199
248
  }
200
249
  async function loadConfig(configPath, outDir, build = false) {
201
250
  if (build) await compileConfig(configPath, outDir);
202
- const url = (0, import_node_url.pathToFileURL)(path4.resolve(outDir, "source.config.mjs"));
251
+ const url = (0, import_node_url2.pathToFileURL)(path6.resolve(outDir, "source.config.mjs"));
203
252
  url.searchParams.set("hash", Date.now().toString());
204
253
  const config = import(url.href).then(
205
254
  (loaded) => buildConfig(loaded)
206
255
  );
207
256
  return await config;
208
257
  }
209
- var path4, import_node_url;
210
- var init_load = __esm({
211
- "src/loaders/config/load.ts"() {
258
+ var path6, import_node_url2;
259
+ var init_load_from_file = __esm({
260
+ "src/config/load-from-file.ts"() {
212
261
  "use strict";
213
- path4 = __toESM(require("path"), 1);
214
- import_node_url = require("url");
262
+ path6 = __toESM(require("path"), 1);
263
+ import_node_url2 = require("url");
215
264
  init_build();
216
265
  }
217
266
  });
218
267
 
219
- // src/webpack/index.ts
220
- var webpack_exports = {};
221
- __export(webpack_exports, {
268
+ // src/webpack/mdx.ts
269
+ var mdx_exports = {};
270
+ __export(mdx_exports, {
222
271
  default: () => loader
223
272
  });
224
- module.exports = __toCommonJS(webpack_exports);
273
+ module.exports = __toCommonJS(mdx_exports);
225
274
 
226
275
  // src/utils/fuma-matter.ts
227
276
  var import_js_yaml = require("js-yaml");
@@ -695,7 +744,7 @@ function createMdxLoader(configLoader) {
695
744
  );
696
745
  };
697
746
  }
698
- const collection = parsed.collection ? config.collections.get(parsed.collection) : void 0;
747
+ const collection = parsed.collection ? config.getCollection(parsed.collection) : void 0;
699
748
  let docCollection;
700
749
  switch (collection?.type) {
701
750
  case "doc":
@@ -767,72 +816,11 @@ function countLines(s) {
767
816
  return num;
768
817
  }
769
818
 
770
- // src/loaders/config/index.ts
771
- var import_node_path3 = __toESM(require("path"), 1);
772
- var import_promises2 = __toESM(require("fs/promises"), 1);
773
- function staticConfig({
774
- core,
775
- buildConfig: buildConfig2
776
- }) {
777
- let cached;
778
- async function newConfig() {
779
- const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load(), load_exports));
780
- await core.init({
781
- config: loadConfig2(
782
- core._options.configPath,
783
- core._options.outDir,
784
- buildConfig2
785
- )
786
- });
787
- return core.getConfig();
788
- }
789
- return {
790
- async getConfig() {
791
- return cached ??= newConfig();
792
- }
793
- };
794
- }
795
- function dynamicConfig({
796
- core,
797
- buildConfig: buildConfig2
798
- }) {
799
- let loaded;
800
- async function getConfigHash2() {
801
- const stats = await import_promises2.default.stat(core._options.configPath).catch(() => void 0);
802
- if (stats) {
803
- return stats.mtime.getTime().toString();
804
- }
805
- throw new Error("Cannot find config file");
806
- }
807
- async function newConfig() {
808
- const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load(), load_exports));
809
- await core.init({
810
- config: loadConfig2(
811
- core._options.configPath,
812
- core._options.outDir,
813
- buildConfig2
814
- )
815
- });
816
- return core.getConfig();
817
- }
818
- return {
819
- async getConfig() {
820
- const hash = await getConfigHash2();
821
- if (loaded && loaded.hash === hash) return loaded.config;
822
- loaded = {
823
- hash,
824
- config: newConfig()
825
- };
826
- return loaded.config;
827
- }
828
- };
829
- }
830
-
831
819
  // src/loaders/adapter.ts
832
- var import_node_url2 = require("url");
833
- var import_promises3 = __toESM(require("fs/promises"), 1);
820
+ var import_node_url = require("url");
821
+ var import_promises2 = __toESM(require("fs/promises"), 1);
834
822
  var import_node_querystring = require("querystring");
835
- var import_node_path4 = __toESM(require("path"), 1);
823
+ var import_node_path3 = __toESM(require("path"), 1);
836
824
  function toWebpack(loader2) {
837
825
  return async function(source, callback) {
838
826
  try {
@@ -843,13 +831,17 @@ function toWebpack(loader2) {
843
831
  development: this.mode === "development",
844
832
  compiler: this
845
833
  });
846
- callback(void 0, result.code, result.map);
834
+ if (result === null) {
835
+ callback(void 0, source);
836
+ } else {
837
+ callback(void 0, result.code, result.map);
838
+ }
847
839
  } catch (error) {
848
840
  if (error instanceof ValidationError) {
849
841
  return callback(new Error(error.toStringFormatted()));
850
842
  }
851
843
  if (!(error instanceof Error)) throw error;
852
- const fpath = import_node_path4.default.relative(this.context, this.resourcePath);
844
+ const fpath = import_node_path3.default.relative(this.context, this.resourcePath);
853
845
  error.message = `${fpath}:${error.name}: ${error.message}`;
854
846
  callback(error);
855
847
  }
@@ -857,8 +849,8 @@ function toWebpack(loader2) {
857
849
  }
858
850
 
859
851
  // src/core.ts
860
- var import_node_path5 = __toESM(require("path"), 1);
861
- var import_promises4 = __toESM(require("fs/promises"), 1);
852
+ var import_node_path4 = __toESM(require("path"), 1);
853
+ var import_promises3 = __toESM(require("fs/promises"), 1);
862
854
  function createCore(options, defaultPlugins = []) {
863
855
  let config;
864
856
  let plugins2;
@@ -895,13 +887,6 @@ function createCore(options, defaultPlugins = []) {
895
887
  getConfig() {
896
888
  return config;
897
889
  },
898
- creatConfigLoader() {
899
- return {
900
- getConfig() {
901
- return config;
902
- }
903
- };
904
- },
905
890
  async initServer(server) {
906
891
  for (const plugin of plugins2) {
907
892
  await plugin.configureServer?.call(this.getPluginContext(), server);
@@ -919,9 +904,9 @@ function createCore(options, defaultPlugins = []) {
919
904
  );
920
905
  await Promise.all(
921
906
  out.flat().map(async (entry) => {
922
- const file = import_node_path5.default.join(options.outDir, entry.path);
923
- await import_promises4.default.mkdir(import_node_path5.default.dirname(file), { recursive: true });
924
- await import_promises4.default.writeFile(file, entry.content);
907
+ const file = import_node_path4.default.join(options.outDir, entry.path);
908
+ await import_promises3.default.mkdir(import_node_path4.default.dirname(file), { recursive: true });
909
+ await import_promises3.default.writeFile(file, entry.content);
925
910
  })
926
911
  );
927
912
  console.log(`[MDX] generated files in ${performance.now() - start}ms`);
@@ -929,7 +914,46 @@ function createCore(options, defaultPlugins = []) {
929
914
  };
930
915
  }
931
916
 
932
- // src/webpack/index.ts
917
+ // src/loaders/config.ts
918
+ var import_promises4 = __toESM(require("fs/promises"), 1);
919
+ function createStandaloneConfigLoader({
920
+ core,
921
+ buildConfig: buildConfig2,
922
+ mode
923
+ }) {
924
+ let loaded;
925
+ async function getConfigHash2() {
926
+ if (mode === "production") return "static";
927
+ const stats = await import_promises4.default.stat(core._options.configPath).catch(() => {
928
+ throw new Error("Cannot find config file");
929
+ });
930
+ return stats.mtime.getTime().toString();
931
+ }
932
+ async function newConfig() {
933
+ const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load_from_file(), load_from_file_exports));
934
+ await core.init({
935
+ config: loadConfig2(
936
+ core._options.configPath,
937
+ core._options.outDir,
938
+ buildConfig2
939
+ )
940
+ });
941
+ return core.getConfig();
942
+ }
943
+ return {
944
+ async getConfig() {
945
+ const hash = await getConfigHash2();
946
+ if (loaded && loaded.hash === hash) return loaded.config;
947
+ loaded = {
948
+ hash,
949
+ config: newConfig()
950
+ };
951
+ return loaded.config;
952
+ }
953
+ };
954
+ }
955
+
956
+ // src/webpack/mdx.ts
933
957
  var instance;
934
958
  async function loader(source, callback) {
935
959
  const { isDev, outDir, configPath } = this.getOptions();
@@ -943,12 +967,10 @@ async function loader(source, callback) {
943
967
  });
944
968
  instance = toWebpack(
945
969
  createMdxLoader(
946
- isDev ? dynamicConfig({
947
- core,
948
- buildConfig: false
949
- }) : staticConfig({
970
+ createStandaloneConfigLoader({
950
971
  core,
951
- buildConfig: false
972
+ buildConfig: false,
973
+ mode: isDev ? "dev" : "production"
952
974
  })
953
975
  )
954
976
  );
@@ -0,0 +1,6 @@
1
+ import { LoaderContext } from 'webpack';
2
+ import { W as WebpackLoaderOptions } from '../index-D7s7kCc2.cjs';
3
+
4
+ declare function loader(this: LoaderContext<WebpackLoaderOptions>, source: string, callback: LoaderContext<WebpackLoaderOptions>['callback']): Promise<void>;
5
+
6
+ export { loader as default };
@@ -0,0 +1,6 @@
1
+ import { LoaderContext } from 'webpack';
2
+ import { W as WebpackLoaderOptions } from '../index-D7s7kCc2.js';
3
+
4
+ declare function loader(this: LoaderContext<WebpackLoaderOptions>, source: string, callback: LoaderContext<WebpackLoaderOptions>['callback']): Promise<void>;
5
+
6
+ export { loader as default };
@@ -1,19 +1,19 @@
1
- import {
2
- toWebpack
3
- } from "../chunk-YVCR6FUH.js";
4
1
  import {
5
2
  createMdxLoader
6
- } from "../chunk-XQ5O7IPO.js";
3
+ } from "../chunk-XYGORKQA.js";
4
+ import {
5
+ createStandaloneConfigLoader,
6
+ toWebpack
7
+ } from "../chunk-ZNVPB2IR.js";
7
8
  import "../chunk-3J3WL7WN.js";
8
9
  import "../chunk-K5ZLPEIQ.js";
10
+ import "../chunk-VUEZTR2H.js";
9
11
  import {
10
- createCore,
11
- dynamicConfig,
12
- staticConfig
13
- } from "../chunk-EELYB2XC.js";
12
+ createCore
13
+ } from "../chunk-TZ5EQBFW.js";
14
14
  import "../chunk-VWJKRQZR.js";
15
15
 
16
- // src/webpack/index.ts
16
+ // src/webpack/mdx.ts
17
17
  var instance;
18
18
  async function loader(source, callback) {
19
19
  const { isDev, outDir, configPath } = this.getOptions();
@@ -27,12 +27,10 @@ async function loader(source, callback) {
27
27
  });
28
28
  instance = toWebpack(
29
29
  createMdxLoader(
30
- isDev ? dynamicConfig({
31
- core,
32
- buildConfig: false
33
- }) : staticConfig({
30
+ createStandaloneConfigLoader({
34
31
  core,
35
- buildConfig: false
32
+ buildConfig: false,
33
+ mode: isDev ? "dev" : "production"
36
34
  })
37
35
  )
38
36
  );