fumadocs-mdx 13.0.0 → 13.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.
Files changed (55) hide show
  1. package/dist/bin.cjs +272 -240
  2. package/dist/{build-mdx-CzrQDBRZ.d.ts → build-mdx-CCNr86q6.d.ts} +1 -1
  3. package/dist/{build-mdx-BHG-_uxo.d.cts → build-mdx-D-r3_eQL.d.cts} +1 -1
  4. package/dist/bun/index.cjs +114 -34
  5. package/dist/bun/index.d.cts +8 -3
  6. package/dist/bun/index.d.ts +8 -3
  7. package/dist/bun/index.js +20 -10
  8. package/dist/{chunk-6Y5JDZHD.js → chunk-CXA4JO4Z.js} +1 -21
  9. package/dist/chunk-EELYB2XC.js +207 -0
  10. package/dist/{chunk-CEA6MYJU.js → chunk-XQ5O7IPO.js} +29 -27
  11. package/dist/chunk-XZY2AWJI.js +81 -0
  12. package/dist/{chunk-XV5Z4BFL.js → chunk-YVCR6FUH.js} +1 -1
  13. package/dist/config/index.d.cts +2 -2
  14. package/dist/config/index.d.ts +2 -2
  15. package/dist/{define-BCNh3n4O.d.cts → core-B6j6Fxse.d.cts} +101 -38
  16. package/dist/{define-bck_EB4t.d.ts → core-B6j6Fxse.d.ts} +101 -38
  17. package/dist/index.d.cts +7 -2
  18. package/dist/index.d.ts +7 -2
  19. package/dist/next/index.cjs +195 -163
  20. package/dist/next/index.js +79 -71
  21. package/dist/node/loader.cjs +120 -35
  22. package/dist/node/loader.js +10 -5
  23. package/dist/plugins/json-schema.cjs +103 -2
  24. package/dist/plugins/json-schema.d.cts +12 -4
  25. package/dist/plugins/json-schema.d.ts +12 -4
  26. package/dist/plugins/json-schema.js +40 -2
  27. package/dist/runtime/next/async.d.cts +4 -4
  28. package/dist/runtime/next/async.d.ts +4 -4
  29. package/dist/runtime/next/async.js +3 -3
  30. package/dist/runtime/next/index.d.cts +5 -5
  31. package/dist/runtime/next/index.d.ts +5 -5
  32. package/dist/runtime/vite/browser.d.cts +3 -3
  33. package/dist/runtime/vite/browser.d.ts +3 -3
  34. package/dist/runtime/vite/server.d.cts +3 -3
  35. package/dist/runtime/vite/server.d.ts +3 -3
  36. package/dist/{types-1cCFEzWt.d.ts → types-AGzTfBmf.d.ts} +1 -1
  37. package/dist/{types-D5NhXTJY.d.cts → types-DKGMoay5.d.cts} +1 -1
  38. package/dist/vite/index.cjs +123 -91
  39. package/dist/vite/index.js +30 -27
  40. package/dist/{loader-mdx.cjs → webpack/index.cjs} +151 -58
  41. package/dist/webpack/index.js +44 -0
  42. package/loader-mdx.cjs +1 -1
  43. package/package.json +4 -3
  44. package/dist/chunk-4MAYA5QX.js +0 -44
  45. package/dist/chunk-HI62EXSB.js +0 -127
  46. package/dist/loader-mdx.js +0 -39
  47. package/dist/plugins/index.cjs +0 -78
  48. package/dist/plugins/index.d.cts +0 -7
  49. package/dist/plugins/index.d.ts +0 -7
  50. package/dist/plugins/index.js +0 -6
  51. package/dist/remark-postprocess-K233ZVBK.d.cts +0 -22
  52. package/dist/remark-postprocess-K233ZVBK.d.ts +0 -22
  53. package/dist/watcher-WXJDWRZY.js +0 -22
  54. /package/dist/{loader-mdx.d.cts → webpack/index.d.cts} +0 -0
  55. /package/dist/{loader-mdx.d.ts → webpack/index.d.ts} +0 -0
@@ -1,16 +1,54 @@
1
+ import {
2
+ createCollectionMatcher
3
+ } from "../chunk-XZY2AWJI.js";
4
+
1
5
  // src/plugins/json-schema.ts
2
6
  import { z } from "zod";
3
- function jsonSchema() {
7
+ import fs from "fs/promises";
8
+ import path from "path";
9
+ function jsonSchema({
10
+ insert = false
11
+ } = {}) {
4
12
  let config;
13
+ function getSchemaPath(name) {
14
+ return `json-schema/${name}.json`;
15
+ }
5
16
  return {
6
17
  config(v) {
7
18
  config = v;
8
19
  },
20
+ configureServer(server) {
21
+ if (!server.watcher || !insert) return;
22
+ const matcher = createCollectionMatcher(this.core);
23
+ server.watcher.on("add", async (file) => {
24
+ const match = matcher.getFileCollection(file);
25
+ if (!match || match.collection.type !== "meta") return;
26
+ const { name } = match;
27
+ const parent = config.collections.get(name);
28
+ let obj;
29
+ try {
30
+ const content = (await fs.readFile(file)).toString();
31
+ obj = content.length > 0 ? JSON.parse(content) : {};
32
+ } catch {
33
+ return;
34
+ }
35
+ if ("$schema" in obj) return;
36
+ const schemaPath = path.join(
37
+ this.outDir,
38
+ getSchemaPath(parent?.type === "docs" ? `${name}.meta` : name)
39
+ );
40
+ const updated = {
41
+ $schema: path.relative(path.dirname(file), schemaPath),
42
+ ...obj
43
+ };
44
+ await fs.writeFile(file, JSON.stringify(updated, null, 2));
45
+ });
46
+ },
9
47
  emit() {
10
48
  const files = [];
11
49
  function onSchema(name, schema) {
12
50
  files.push({
13
- path: `json-schema/${name}.json`,
51
+ path: getSchemaPath(name),
14
52
  content: JSON.stringify(
15
53
  z.toJSONSchema(schema, {
16
54
  io: "input",
@@ -1,18 +1,18 @@
1
- import { c as RuntimeAsync } from '../../types-D5NhXTJY.cjs';
2
- import { L as LoadedConfig } from '../../define-BCNh3n4O.cjs';
1
+ import { c as RuntimeAsync } from '../../types-DKGMoay5.cjs';
2
+ import { L as LoadedConfig } from '../../core-B6j6Fxse.cjs';
3
3
  import '@standard-schema/spec';
4
4
  import 'fumadocs-core/source';
5
5
  import '../../index.cjs';
6
6
  import 'fumadocs-core/mdx-plugins';
7
7
  import 'fumadocs-core/toc';
8
8
  import 'mdx/types';
9
- import '../../remark-postprocess-K233ZVBK.cjs';
10
9
  import 'mdast';
11
- import '../../build-mdx-BHG-_uxo.cjs';
10
+ import '../../build-mdx-D-r3_eQL.cjs';
12
11
  import '@mdx-js/mdx';
13
12
  import 'react';
14
13
  import 'unified';
15
14
  import 'zod';
15
+ import 'chokidar';
16
16
 
17
17
  declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
18
18
 
@@ -1,18 +1,18 @@
1
- import { c as RuntimeAsync } from '../../types-1cCFEzWt.js';
2
- import { L as LoadedConfig } from '../../define-bck_EB4t.js';
1
+ import { c as RuntimeAsync } from '../../types-AGzTfBmf.js';
2
+ import { L as LoadedConfig } from '../../core-B6j6Fxse.js';
3
3
  import '@standard-schema/spec';
4
4
  import 'fumadocs-core/source';
5
5
  import '../../index.js';
6
6
  import 'fumadocs-core/mdx-plugins';
7
7
  import 'fumadocs-core/toc';
8
8
  import 'mdx/types';
9
- import '../../remark-postprocess-K233ZVBK.js';
10
9
  import 'mdast';
11
- import '../../build-mdx-CzrQDBRZ.js';
10
+ import '../../build-mdx-CCNr86q6.js';
12
11
  import '@mdx-js/mdx';
13
12
  import 'react';
14
13
  import 'unified';
15
14
  import 'zod';
15
+ import 'chokidar';
16
16
 
17
17
  declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
18
18
 
@@ -5,13 +5,13 @@ import {
5
5
  import {
6
6
  createDocMethods
7
7
  } from "../../chunk-NVRDCY6Z.js";
8
+ import {
9
+ buildConfig
10
+ } from "../../chunk-U4MQ44TS.js";
8
11
  import {
9
12
  buildMDX
10
13
  } from "../../chunk-3J3WL7WN.js";
11
14
  import "../../chunk-K5ZLPEIQ.js";
12
- import {
13
- buildConfig
14
- } from "../../chunk-U4MQ44TS.js";
15
15
  import {
16
16
  fumaMatter
17
17
  } from "../../chunk-VWJKRQZR.js";
@@ -1,18 +1,18 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime } from '../../types-D5NhXTJY.cjs';
3
- export { b as AsyncDocOut, A as AsyncRuntimeFile, D as DocOut, M as MetaOut, c as RuntimeAsync, a as RuntimeFile } from '../../types-D5NhXTJY.cjs';
2
+ import { R as Runtime } from '../../types-DKGMoay5.cjs';
3
+ export { b as AsyncDocOut, A as AsyncRuntimeFile, D as DocOut, M as MetaOut, c as RuntimeAsync, a as RuntimeFile } from '../../types-DKGMoay5.cjs';
4
4
  import { FileInfo } from '../../index.cjs';
5
5
  import '@standard-schema/spec';
6
- import '../../define-BCNh3n4O.cjs';
6
+ import '../../core-B6j6Fxse.cjs';
7
7
  import 'fumadocs-core/mdx-plugins';
8
8
  import '@mdx-js/mdx';
9
9
  import 'unified';
10
10
  import 'zod';
11
- import '../../remark-postprocess-K233ZVBK.cjs';
11
+ import 'chokidar';
12
12
  import 'fumadocs-core/toc';
13
13
  import 'mdx/types';
14
14
  import 'mdast';
15
- import '../../build-mdx-BHG-_uxo.cjs';
15
+ import '../../build-mdx-D-r3_eQL.cjs';
16
16
  import 'react';
17
17
 
18
18
  declare const _runtime: Runtime;
@@ -1,18 +1,18 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime } from '../../types-1cCFEzWt.js';
3
- export { b as AsyncDocOut, A as AsyncRuntimeFile, D as DocOut, M as MetaOut, c as RuntimeAsync, a as RuntimeFile } from '../../types-1cCFEzWt.js';
2
+ import { R as Runtime } from '../../types-AGzTfBmf.js';
3
+ export { b as AsyncDocOut, A as AsyncRuntimeFile, D as DocOut, M as MetaOut, c as RuntimeAsync, a as RuntimeFile } from '../../types-AGzTfBmf.js';
4
4
  import { FileInfo } from '../../index.js';
5
5
  import '@standard-schema/spec';
6
- import '../../define-bck_EB4t.js';
6
+ import '../../core-B6j6Fxse.js';
7
7
  import 'fumadocs-core/mdx-plugins';
8
8
  import '@mdx-js/mdx';
9
9
  import 'unified';
10
10
  import 'zod';
11
- import '../../remark-postprocess-K233ZVBK.js';
11
+ import 'chokidar';
12
12
  import 'fumadocs-core/toc';
13
13
  import 'mdx/types';
14
14
  import 'mdast';
15
- import '../../build-mdx-CzrQDBRZ.js';
15
+ import '../../build-mdx-CCNr86q6.js';
16
16
  import 'react';
17
17
 
18
18
  declare const _runtime: Runtime;
@@ -1,12 +1,12 @@
1
- import { a as DocCollection, b as DocsCollection, M as MetaCollection } from '../../define-BCNh3n4O.cjs';
1
+ import { b as DocCollection, c as DocsCollection, M as MetaCollection } from '../../core-B6j6Fxse.cjs';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
- import { C as CompiledMDXProperties } from '../../build-mdx-BHG-_uxo.cjs';
3
+ import { C as CompiledMDXProperties } from '../../build-mdx-D-r3_eQL.cjs';
4
4
  import { ReactNode, FC } from 'react';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import '../../remark-postprocess-K233ZVBK.cjs';
9
+ import 'chokidar';
10
10
  import 'fumadocs-core/toc';
11
11
  import 'mdx/types';
12
12
 
@@ -1,12 +1,12 @@
1
- import { a as DocCollection, b as DocsCollection, M as MetaCollection } from '../../define-bck_EB4t.js';
1
+ import { b as DocCollection, c as DocsCollection, M as MetaCollection } from '../../core-B6j6Fxse.js';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
- import { C as CompiledMDXProperties } from '../../build-mdx-CzrQDBRZ.js';
3
+ import { C as CompiledMDXProperties } from '../../build-mdx-CCNr86q6.js';
4
4
  import { ReactNode, FC } from 'react';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import '../../remark-postprocess-K233ZVBK.js';
9
+ import 'chokidar';
10
10
  import 'fumadocs-core/toc';
11
11
  import 'mdx/types';
12
12
 
@@ -2,14 +2,14 @@ import { PageData, MetaData, Source } from 'fumadocs-core/source';
2
2
  import { BaseCreate, DocMap, MetaMap, LazyDocMap } from './browser.cjs';
3
3
  export { ClientLoader, ClientLoaderOptions, CompiledMDXFile, createClientLoader, fromConfig as fromConfigBase, toClientRenderer } from './browser.cjs';
4
4
  import { DocCollectionEntry, MetaCollectionEntry, AsyncDocCollectionEntry } from '../../index.cjs';
5
- import '../../define-BCNh3n4O.cjs';
5
+ import '../../core-B6j6Fxse.cjs';
6
6
  import '@standard-schema/spec';
7
7
  import 'fumadocs-core/mdx-plugins';
8
8
  import '@mdx-js/mdx';
9
9
  import 'unified';
10
10
  import 'zod';
11
- import '../../remark-postprocess-K233ZVBK.cjs';
12
- import '../../build-mdx-BHG-_uxo.cjs';
11
+ import 'chokidar';
12
+ import '../../build-mdx-D-r3_eQL.cjs';
13
13
  import 'fumadocs-core/toc';
14
14
  import 'react';
15
15
  import 'mdx/types';
@@ -2,14 +2,14 @@ import { PageData, MetaData, Source } from 'fumadocs-core/source';
2
2
  import { BaseCreate, DocMap, MetaMap, LazyDocMap } from './browser.js';
3
3
  export { ClientLoader, ClientLoaderOptions, CompiledMDXFile, createClientLoader, fromConfig as fromConfigBase, toClientRenderer } from './browser.js';
4
4
  import { DocCollectionEntry, MetaCollectionEntry, AsyncDocCollectionEntry } from '../../index.js';
5
- import '../../define-bck_EB4t.js';
5
+ import '../../core-B6j6Fxse.js';
6
6
  import '@standard-schema/spec';
7
7
  import 'fumadocs-core/mdx-plugins';
8
8
  import '@mdx-js/mdx';
9
9
  import 'unified';
10
10
  import 'zod';
11
- import '../../remark-postprocess-K233ZVBK.js';
12
- import '../../build-mdx-CzrQDBRZ.js';
11
+ import 'chokidar';
12
+ import '../../build-mdx-CCNr86q6.js';
13
13
  import 'fumadocs-core/toc';
14
14
  import 'react';
15
15
  import 'mdx/types';
@@ -1,6 +1,6 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
3
- import { L as LoadedConfig, a as DocCollection, b as DocsCollection, M as MetaCollection } from './define-bck_EB4t.js';
3
+ import { L as LoadedConfig, b as DocCollection, c as DocsCollection, M as MetaCollection } from './core-B6j6Fxse.js';
4
4
  import { FileInfo, AsyncDocCollectionEntry, MetaCollectionEntry, DocCollectionEntry } from './index.js';
5
5
 
6
6
  interface RuntimeFile {
@@ -1,6 +1,6 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
3
- import { L as LoadedConfig, a as DocCollection, b as DocsCollection, M as MetaCollection } from './define-BCNh3n4O.cjs';
3
+ import { L as LoadedConfig, b as DocCollection, c as DocsCollection, M as MetaCollection } from './core-B6j6Fxse.cjs';
4
4
  import { FileInfo, AsyncDocCollectionEntry, MetaCollectionEntry, DocCollectionEntry } from './index.cjs';
5
5
 
6
6
  interface RuntimeFile {
@@ -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)(path10.resolve(outDir, "source.config.mjs"));
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 path10, import_node_url3;
209
+ var path11, import_node_url3;
210
210
  var init_load = __esm({
211
211
  "src/loaders/config/load.ts"() {
212
212
  "use strict";
213
- path10 = __toESM(require("path"), 1);
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 path11 = __toESM(require("path"), 1);
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 loaded = await configLoader.getConfig();
697
- const cacheDir = isDevelopment ? void 0 : loaded.global.experimentalBuildCache;
698
- const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
699
- if (cacheDir) {
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 ? loaded.collections.get(parsed.collection) : void 0;
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 (loaded.global.lastModifiedTime === "git") {
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(loaded)}:${parsed.collection ?? "global"}`,
739
+ `${getConfigHash(config)}:${parsed.collection ?? "global"}`,
737
740
  "\n".repeat(lineOffset) + matter.content,
738
741
  {
739
742
  development: isDevelopment,
740
- ...docCollection?.mdxOptions ?? await loaded.getDefaultMDXOptions(),
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
- if (cacheDir) {
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
- function getSupportedFormats(collection) {
844
- return {
845
- doc: ["mdx", "md"],
846
- meta: ["json", "yaml"]
847
- }[collection.type];
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 [`**/*.{${getSupportedFormats(collection).join(",")}}`];
847
+ return [`**/*.{${SupportedFormats[collection.type].join(",")}}`];
852
848
  }
853
849
 
854
850
  // src/utils/glob-import.ts
855
- var import_tinyglobby = require("tinyglobby");
856
- var import_node_path6 = __toESM(require("path"), 1);
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, import_tinyglobby.globSync)(patterns, {
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 = import_node_path6.default.join(options.base, item);
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 import_node_path7 = __toESM(require("path"), 1);
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",
@@ -957,7 +952,7 @@ ${obj}
957
952
  return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
958
953
  {
959
954
  ...options2,
960
- base: import_node_path7.default.relative(outDir, options2.base)
955
+ base: import_node_path8.default.relative(outDir, options2.base)
961
956
  },
962
957
  null,
963
958
  2
@@ -998,43 +993,75 @@ function getGlobBase(collection) {
998
993
  return enforceRelative(dir);
999
994
  }
1000
995
 
1001
- // src/plugins/index.ts
1002
- var import_node_path8 = __toESM(require("path"), 1);
996
+ // src/core.ts
997
+ var import_node_path9 = __toESM(require("path"), 1);
1003
998
  var import_promises4 = __toESM(require("fs/promises"), 1);
1004
- function createPluginHandler(context, defaultPlugins = []) {
1005
- const plugins2 = [];
1006
- async function write(entry) {
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
- }
999
+ function createCore(options, defaultPlugins = []) {
1000
+ let config;
1001
+ let plugins2;
1011
1002
  return {
1012
- async init(config) {
1013
- if (config.global.plugins) {
1014
- defaultPlugins.push(...config.global.plugins);
1015
- }
1016
- for await (const option of defaultPlugins) {
1003
+ _options: options,
1004
+ getPluginContext() {
1005
+ return {
1006
+ core: this,
1007
+ ...options
1008
+ };
1009
+ },
1010
+ /**
1011
+ * Convenient cache store, reset when config changes
1012
+ */
1013
+ cache: /* @__PURE__ */ new Map(),
1014
+ async init({ config: newConfig }) {
1015
+ config = await newConfig;
1016
+ this.cache.clear();
1017
+ plugins2 = [];
1018
+ for await (const option of [
1019
+ ...defaultPlugins,
1020
+ ...config.global.plugins ?? []
1021
+ ]) {
1017
1022
  if (!option) continue;
1018
1023
  if (Array.isArray(option)) plugins2.push(...option);
1019
1024
  else plugins2.push(option);
1020
1025
  }
1021
1026
  for (const plugin of plugins2) {
1022
- const out = await plugin.config?.call(context, config);
1027
+ const out = await plugin.config?.call(this.getPluginContext(), config);
1023
1028
  if (out) config = out;
1024
1029
  }
1030
+ return this;
1031
+ },
1032
+ getConfig() {
1025
1033
  return config;
1026
1034
  },
1027
- async emit() {
1035
+ creatConfigLoader() {
1036
+ return {
1037
+ getConfig() {
1038
+ return config;
1039
+ }
1040
+ };
1041
+ },
1042
+ async initServer(server) {
1043
+ for (const plugin of plugins2) {
1044
+ await plugin.configureServer?.call(this.getPluginContext(), server);
1045
+ }
1046
+ },
1047
+ async emitAndWrite({
1048
+ filterPlugin = () => true
1049
+ } = {}) {
1050
+ const start = performance.now();
1028
1051
  const out = await Promise.all(
1029
1052
  plugins2.map((plugin) => {
1030
- return plugin.emit?.call(context) ?? [];
1053
+ if (!filterPlugin(plugin) || !plugin.emit) return [];
1054
+ return plugin.emit.call(this.getPluginContext());
1031
1055
  })
1032
1056
  );
1033
- return out.flat();
1034
- },
1035
- async emitAndWrite() {
1036
- const entries = await this.emit();
1037
- await Promise.all(entries.map(write));
1057
+ await Promise.all(
1058
+ out.flat().map(async (entry) => {
1059
+ const file = import_node_path9.default.join(options.outDir, entry.path);
1060
+ await import_promises4.default.mkdir(import_node_path9.default.dirname(file), { recursive: true });
1061
+ await import_promises4.default.writeFile(file, entry.content);
1062
+ })
1063
+ );
1064
+ console.log(`[MDX] generated files in ${performance.now() - start}ms`);
1038
1065
  }
1039
1066
  };
1040
1067
  }
@@ -1043,14 +1070,14 @@ function createPluginHandler(context, defaultPlugins = []) {
1043
1070
  var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
1044
1071
  async function mdx(config, pluginOptions = {}) {
1045
1072
  const options = applyDefaults(pluginOptions);
1046
- const { updateViteConfig } = options;
1047
- const pluginHandler = createVitePluginHandler(options);
1048
- const loaded = await pluginHandler.init(buildConfig(config));
1049
- const mdxLoader = toVite(createMdxLoader(resolvedConfig(loaded)));
1050
- async function transformMeta(path12, query, value) {
1051
- const isJson = path12.endsWith(".json");
1073
+ const core = await createViteCore(options).init({
1074
+ config: buildConfig(config)
1075
+ });
1076
+ const mdxLoader = toVite(createMdxLoader(core.creatConfigLoader()));
1077
+ async function transformMeta(path13, query, value) {
1078
+ const isJson = path13.endsWith(".json");
1052
1079
  const parsed = (0, import_node_querystring2.parse)(query);
1053
- const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
1080
+ const collection = parsed.collection ? core.getConfig().collections.get(parsed.collection) : void 0;
1054
1081
  if (!collection) return null;
1055
1082
  let schema;
1056
1083
  switch (collection.type) {
@@ -1071,8 +1098,8 @@ async function mdx(config, pluginOptions = {}) {
1071
1098
  const out = await validate(
1072
1099
  schema,
1073
1100
  data,
1074
- { path: path12, source: value },
1075
- `invalid data in ${path12}`
1101
+ { path: path13, source: value },
1102
+ `invalid data in ${path13}`
1076
1103
  );
1077
1104
  return {
1078
1105
  code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
@@ -1084,7 +1111,7 @@ async function mdx(config, pluginOptions = {}) {
1084
1111
  // needed, otherwise other plugins will be executed before our `transform`.
1085
1112
  enforce: "pre",
1086
1113
  config(config2) {
1087
- if (!updateViteConfig) return config2;
1114
+ if (!options.updateViteConfig) return config2;
1088
1115
  return (0, import_vite.mergeConfig)(config2, {
1089
1116
  optimizeDeps: {
1090
1117
  exclude: FumadocsDeps
@@ -1096,11 +1123,16 @@ async function mdx(config, pluginOptions = {}) {
1096
1123
  });
1097
1124
  },
1098
1125
  async buildStart() {
1099
- await pluginHandler.emitAndWrite();
1126
+ await core.emitAndWrite();
1127
+ },
1128
+ async configureServer(server) {
1129
+ await core.initServer({
1130
+ watcher: server.watcher
1131
+ });
1100
1132
  },
1101
1133
  async transform(value, id) {
1102
1134
  const [file, query = ""] = id.split("?");
1103
- const ext = path11.extname(file);
1135
+ const ext = path12.extname(file);
1104
1136
  try {
1105
1137
  if ([".yaml", ".json"].includes(ext))
1106
1138
  return await transformMeta(file, query, value);
@@ -1118,17 +1150,17 @@ async function mdx(config, pluginOptions = {}) {
1118
1150
  async function postInstall(configPath = findConfigFile(), pluginOptions = {}) {
1119
1151
  const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load(), load_exports));
1120
1152
  const options = applyDefaults(pluginOptions);
1121
- const pluginHandler = createVitePluginHandler(options);
1122
- await pluginHandler.init(await loadConfig2(configPath, options.outDir, true));
1123
- await pluginHandler.emitAndWrite();
1124
- console.log("[MDX] types generated");
1153
+ const core = await createViteCore(options).init({
1154
+ config: loadConfig2(configPath, options.outDir, true)
1155
+ });
1156
+ await core.emitAndWrite();
1125
1157
  }
1126
- function createVitePluginHandler({
1158
+ function createViteCore({
1127
1159
  configPath,
1128
1160
  outDir,
1129
1161
  generateIndexFile
1130
1162
  }) {
1131
- return createPluginHandler(
1163
+ return createCore(
1132
1164
  {
1133
1165
  environment: "vite",
1134
1166
  configPath,