fumadocs-mdx 11.8.3 → 11.9.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 (36) hide show
  1. package/dist/browser-CyU2Yl7A.d.cts +51 -0
  2. package/dist/browser-DEsQvNRx.d.ts +51 -0
  3. package/dist/chunk-46UPKP5R.js +77 -0
  4. package/dist/{chunk-BWRDVK5L.js → chunk-766EAFX6.js} +1 -1
  5. package/dist/chunk-COQ4VMK2.js +158 -0
  6. package/dist/config/index.d.cts +1 -1
  7. package/dist/config/index.d.ts +1 -1
  8. package/dist/config/zod-3.d.cts +1 -1
  9. package/dist/config/zod-3.d.ts +1 -1
  10. package/dist/{define-DAZmbu3U.d.cts → define-DnJzAZrj.d.cts} +1 -1
  11. package/dist/{define-DAZmbu3U.d.ts → define-DnJzAZrj.d.ts} +1 -1
  12. package/dist/index.d.cts +2 -2
  13. package/dist/index.d.ts +2 -2
  14. package/dist/loader-mdx.cjs +1 -1
  15. package/dist/loader-mdx.js +2 -2
  16. package/dist/next/index.cjs +126 -11
  17. package/dist/next/index.js +27 -9
  18. package/dist/runtime/async.d.cts +2 -2
  19. package/dist/runtime/async.d.ts +2 -2
  20. package/dist/runtime/async.js +1 -1
  21. package/dist/runtime/vite/browser.cjs +103 -0
  22. package/dist/runtime/vite/browser.d.cts +11 -0
  23. package/dist/runtime/vite/browser.d.ts +11 -0
  24. package/dist/runtime/vite/browser.js +10 -0
  25. package/dist/runtime/{vite.cjs → vite/server.cjs} +89 -61
  26. package/dist/runtime/vite/server.d.cts +41 -0
  27. package/dist/runtime/vite/server.d.ts +41 -0
  28. package/dist/runtime/{vite.js → vite/server.js} +14 -64
  29. package/dist/{types-B2kQsHs7.d.cts → types-BmVgoqsr.d.cts} +1 -1
  30. package/dist/{types-CkmezNbX.d.ts → types-WSHJKA8L.d.ts} +1 -1
  31. package/dist/vite/index.cjs +99 -84
  32. package/dist/vite/index.js +13 -93
  33. package/package.json +12 -11
  34. package/dist/chunk-6Y5JDZHD.js +0 -65
  35. package/dist/runtime/vite.d.cts +0 -72
  36. package/dist/runtime/vite.d.ts +0 -72
@@ -0,0 +1,51 @@
1
+ import { C as CompiledMDXProperties } from './build-mdx-DnC1jKvn.cjs';
2
+ import { ReactNode, FC } from 'react';
3
+ import { a as DocCollection, b as DocsCollection, M as MetaCollection } from './define-DnJzAZrj.cjs';
4
+ import { StandardSchemaV1 } from '@standard-schema/spec';
5
+
6
+ type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
7
+ type DocMap<Frontmatter> = Record<string, (() => Promise<CompiledMDXFile<Frontmatter>>) & {
8
+ base: string;
9
+ }>;
10
+ type MetaMap<Data> = Record<string, (() => Promise<Data>) & {
11
+ base: string;
12
+ }>;
13
+ interface LazyDocMap<Frontmatter> {
14
+ base: string;
15
+ head: Record<string, () => Promise<Frontmatter>>;
16
+ body: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>;
17
+ }
18
+
19
+ interface BaseCreate<Config> {
20
+ doc: <Name extends keyof Config>(name: Name, base: string, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? DocMap<StandardSchemaV1.InferOutput<Schema>> : never;
21
+ docLazy: <Name extends keyof Config>(name: Name, base: string, headGlob: Record<string, () => Promise<unknown>>, bodyGlob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? LazyDocMap<StandardSchemaV1.InferOutput<Schema>> : never;
22
+ meta: <Name extends keyof Config>(name: Name, base: string, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends MetaCollection<infer Schema> | DocsCollection<StandardSchemaV1, infer Schema> ? MetaMap<StandardSchemaV1.InferOutput<Schema>> : never;
23
+ }
24
+ declare function fromConfigBase<Config>(): BaseCreate<Config>;
25
+
26
+ interface ClientLoaderOptions<Frontmatter, Props> {
27
+ /**
28
+ * Loader ID (usually your collection name)
29
+ *
30
+ * The code splitting strategy of frameworks like Tanstack Start may duplicate `createClientLoader()` into different chunks.
31
+ *
32
+ * We use loader ID to share cache between multiple instances of client loader.
33
+ *
34
+ * @defaultValue ''
35
+ */
36
+ id?: string;
37
+ component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode;
38
+ }
39
+ type ClientRenderer<Props> = Record<string, FC<Props>>;
40
+ interface ClientLoader<Frontmatter, Props> {
41
+ preload: (path: string) => Promise<CompiledMDXFile<Frontmatter>>;
42
+ /**
43
+ * Get a component that renders content with `React.lazy`
44
+ */
45
+ getComponent: (path: string) => FC<Props>;
46
+ getRenderer: () => ClientRenderer<Props>;
47
+ }
48
+ declare function createClientLoader<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
49
+ declare function toClientRenderer<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode): ClientRenderer<Props>;
50
+
51
+ export { type BaseCreate as B, type CompiledMDXFile as C, type DocMap as D, type LazyDocMap as L, type MetaMap as M, type ClientLoader as a, type ClientLoaderOptions as b, createClientLoader as c, fromConfigBase as f, toClientRenderer as t };
@@ -0,0 +1,51 @@
1
+ import { C as CompiledMDXProperties } from './build-mdx-DnC1jKvn.js';
2
+ import { ReactNode, FC } from 'react';
3
+ import { a as DocCollection, b as DocsCollection, M as MetaCollection } from './define-DnJzAZrj.js';
4
+ import { StandardSchemaV1 } from '@standard-schema/spec';
5
+
6
+ type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
7
+ type DocMap<Frontmatter> = Record<string, (() => Promise<CompiledMDXFile<Frontmatter>>) & {
8
+ base: string;
9
+ }>;
10
+ type MetaMap<Data> = Record<string, (() => Promise<Data>) & {
11
+ base: string;
12
+ }>;
13
+ interface LazyDocMap<Frontmatter> {
14
+ base: string;
15
+ head: Record<string, () => Promise<Frontmatter>>;
16
+ body: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>;
17
+ }
18
+
19
+ interface BaseCreate<Config> {
20
+ doc: <Name extends keyof Config>(name: Name, base: string, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? DocMap<StandardSchemaV1.InferOutput<Schema>> : never;
21
+ docLazy: <Name extends keyof Config>(name: Name, base: string, headGlob: Record<string, () => Promise<unknown>>, bodyGlob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? LazyDocMap<StandardSchemaV1.InferOutput<Schema>> : never;
22
+ meta: <Name extends keyof Config>(name: Name, base: string, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends MetaCollection<infer Schema> | DocsCollection<StandardSchemaV1, infer Schema> ? MetaMap<StandardSchemaV1.InferOutput<Schema>> : never;
23
+ }
24
+ declare function fromConfigBase<Config>(): BaseCreate<Config>;
25
+
26
+ interface ClientLoaderOptions<Frontmatter, Props> {
27
+ /**
28
+ * Loader ID (usually your collection name)
29
+ *
30
+ * The code splitting strategy of frameworks like Tanstack Start may duplicate `createClientLoader()` into different chunks.
31
+ *
32
+ * We use loader ID to share cache between multiple instances of client loader.
33
+ *
34
+ * @defaultValue ''
35
+ */
36
+ id?: string;
37
+ component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode;
38
+ }
39
+ type ClientRenderer<Props> = Record<string, FC<Props>>;
40
+ interface ClientLoader<Frontmatter, Props> {
41
+ preload: (path: string) => Promise<CompiledMDXFile<Frontmatter>>;
42
+ /**
43
+ * Get a component that renders content with `React.lazy`
44
+ */
45
+ getComponent: (path: string) => FC<Props>;
46
+ getRenderer: () => ClientRenderer<Props>;
47
+ }
48
+ declare function createClientLoader<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
49
+ declare function toClientRenderer<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode): ClientRenderer<Props>;
50
+
51
+ export { type BaseCreate as B, type CompiledMDXFile as C, type DocMap as D, type LazyDocMap as L, type MetaMap as M, type ClientLoader as a, type ClientLoaderOptions as b, createClientLoader as c, fromConfigBase as f, toClientRenderer as t };
@@ -0,0 +1,77 @@
1
+ // src/runtime/vite/browser.ts
2
+ import { createElement, lazy } from "react";
3
+
4
+ // src/runtime/vite/base.ts
5
+ function fromConfigBase() {
6
+ function normalize(entries, base) {
7
+ const out = {};
8
+ for (const k in entries) {
9
+ const mappedK = k.startsWith("./") ? k.slice(2) : k;
10
+ if (base) Object.assign(entries[k], { base });
11
+ out[mappedK] = entries[k];
12
+ }
13
+ return out;
14
+ }
15
+ return {
16
+ doc(_, base, glob) {
17
+ return normalize(glob, base);
18
+ },
19
+ meta(_, base, glob) {
20
+ return normalize(glob, base);
21
+ },
22
+ docLazy(_, base, head, body) {
23
+ return {
24
+ base,
25
+ head: normalize(head),
26
+ body: normalize(body)
27
+ };
28
+ }
29
+ };
30
+ }
31
+
32
+ // src/runtime/vite/browser.ts
33
+ var loaderStore = /* @__PURE__ */ new Map();
34
+ function createClientLoader(files, options) {
35
+ const { id = "", component } = options;
36
+ let renderer;
37
+ const store = loaderStore.get(id) ?? {
38
+ preloaded: /* @__PURE__ */ new Map()
39
+ };
40
+ loaderStore.set(id, store);
41
+ function getRenderer() {
42
+ if (renderer) return renderer;
43
+ renderer = {};
44
+ for (const k in files) {
45
+ const OnDemand = lazy(async () => {
46
+ const loaded = await files[k]();
47
+ return { default: (props) => component(loaded, props) };
48
+ });
49
+ renderer[k] = (props) => {
50
+ const cached = store.preloaded.get(k);
51
+ if (!cached) return createElement(OnDemand, props);
52
+ return component(cached, props);
53
+ };
54
+ }
55
+ return renderer;
56
+ }
57
+ return {
58
+ async preload(path) {
59
+ const loaded = await files[path]();
60
+ store.preloaded.set(path, loaded);
61
+ return loaded;
62
+ },
63
+ getRenderer,
64
+ getComponent(path) {
65
+ return getRenderer()[path];
66
+ }
67
+ };
68
+ }
69
+ function toClientRenderer(files, component) {
70
+ return createClientLoader(files, { component }).getRenderer();
71
+ }
72
+
73
+ export {
74
+ fromConfigBase,
75
+ createClientLoader,
76
+ toClientRenderer
77
+ };
@@ -72,7 +72,7 @@ async function loadConfig(configPath, outDir, hash, build = false) {
72
72
  loaded
73
73
  );
74
74
  });
75
- cache = { config, hash };
75
+ if (hash) cache = { config, hash };
76
76
  return await config;
77
77
  }
78
78
  async function getConfigHash(configPath) {
@@ -0,0 +1,158 @@
1
+ // src/utils/import-formatter.ts
2
+ import path from "path";
3
+ function getImportCode(info) {
4
+ const specifier = JSON.stringify(info.specifier);
5
+ if (info.type === "default") return `import ${info.name} from ${specifier}`;
6
+ if (info.type === "namespace")
7
+ return `import * as ${info.name} from ${specifier}`;
8
+ if (info.type === "named") {
9
+ const names = info.names.map(
10
+ (name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
11
+ );
12
+ return `import { ${names.join(", ")} } from ${specifier}`;
13
+ }
14
+ return `import ${specifier}`;
15
+ }
16
+ function toImportPath(file, config) {
17
+ const ext = path.extname(file);
18
+ let filename;
19
+ if (ext === ".ts" && config.jsExtension) {
20
+ filename = file.substring(0, file.length - ext.length) + ".js";
21
+ } else if (ext === ".ts") {
22
+ filename = file.substring(0, file.length - ext.length);
23
+ } else {
24
+ filename = file;
25
+ }
26
+ let importPath;
27
+ if ("relativeTo" in config) {
28
+ importPath = path.relative(config.relativeTo, filename);
29
+ if (!path.isAbsolute(importPath) && !importPath.startsWith(".")) {
30
+ importPath = `./${importPath}`;
31
+ }
32
+ } else {
33
+ importPath = path.resolve(filename);
34
+ }
35
+ return importPath.replaceAll(path.sep, "/");
36
+ }
37
+ function ident(code, tab = 1) {
38
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
39
+ }
40
+
41
+ // src/vite/generate-glob.ts
42
+ function generateGlob(name, patterns, globOptions) {
43
+ const options = {
44
+ ...globOptions,
45
+ query: {
46
+ ...globOptions?.query,
47
+ collection: name
48
+ }
49
+ };
50
+ return `import.meta.glob(${JSON.stringify(mapGlobPatterns(patterns))}, ${JSON.stringify(options, null, 2)})`;
51
+ }
52
+ function mapGlobPatterns(patterns) {
53
+ return patterns.map(enforceRelative);
54
+ }
55
+ function enforceRelative(file) {
56
+ if (file.startsWith("./")) return file;
57
+ if (file.startsWith("/")) return `.${file}`;
58
+ return `./${file}`;
59
+ }
60
+ function getGlobBase(collection) {
61
+ let dir = collection.dir;
62
+ if (Array.isArray(dir)) {
63
+ if (dir.length !== 1)
64
+ throw new Error(
65
+ `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
66
+ );
67
+ dir = dir[0];
68
+ }
69
+ return enforceRelative(dir);
70
+ }
71
+
72
+ // src/utils/collections.ts
73
+ function getSupportedFormats(collection) {
74
+ return {
75
+ doc: ["mdx", "md"],
76
+ meta: ["json", "yaml"]
77
+ }[collection.type];
78
+ }
79
+ function getGlobPatterns(collection) {
80
+ if (collection.files) return collection.files;
81
+ return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
82
+ }
83
+ function isFileSupported(filePath, collection) {
84
+ for (const format of getSupportedFormats(collection)) {
85
+ if (filePath.endsWith(`.${format}`)) return true;
86
+ }
87
+ return false;
88
+ }
89
+
90
+ // src/vite/generate.ts
91
+ function docs(name, collection) {
92
+ const obj = [
93
+ ident(`doc: ${doc(name, collection.docs)}`),
94
+ ident(`meta: ${meta(name, collection.meta)}`)
95
+ ].join(",\n");
96
+ return `{
97
+ ${obj}
98
+ }`;
99
+ }
100
+ function doc(name, collection) {
101
+ const patterns = getGlobPatterns(collection);
102
+ const base = getGlobBase(collection);
103
+ const docGlob = generateGlob(name, patterns, {
104
+ base
105
+ });
106
+ if (collection.async) {
107
+ const headBlob = generateGlob(name, patterns, {
108
+ query: {
109
+ only: "frontmatter"
110
+ },
111
+ import: "frontmatter",
112
+ base
113
+ });
114
+ return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
115
+ }
116
+ return `create.doc("${name}", "${base}", ${docGlob})`;
117
+ }
118
+ function meta(name, collection) {
119
+ const patterns = getGlobPatterns(collection);
120
+ const base = getGlobBase(collection);
121
+ return `create.meta("${name}", "${base}", ${generateGlob(name, patterns, {
122
+ import: "default",
123
+ base
124
+ })})`;
125
+ }
126
+ function entry(configPath, config, outDir, jsExtension) {
127
+ const lines = [
128
+ '/// <reference types="vite/client" />',
129
+ `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
130
+ `import type * as Config from '${toImportPath(configPath, {
131
+ relativeTo: outDir,
132
+ jsExtension
133
+ })}';`,
134
+ "",
135
+ `export const create = fromConfig<typeof Config>();`
136
+ ];
137
+ for (const [name, collection] of config.collections.entries()) {
138
+ let body;
139
+ if (collection.type === "docs") {
140
+ body = docs(name, collection);
141
+ } else if (collection.type === "meta") {
142
+ body = meta(name, collection);
143
+ } else {
144
+ body = doc(name, collection);
145
+ }
146
+ lines.push("");
147
+ lines.push(`export const ${name} = ${body};`);
148
+ }
149
+ return lines.join("\n");
150
+ }
151
+
152
+ export {
153
+ getImportCode,
154
+ toImportPath,
155
+ getGlobPatterns,
156
+ isFileSupported,
157
+ entry
158
+ };
@@ -1,4 +1,4 @@
1
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, b as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-DAZmbu3U.cjs';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-DnJzAZrj.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@standard-schema/spec';
@@ -1,4 +1,4 @@
1
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, b as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-DAZmbu3U.js';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-DnJzAZrj.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@standard-schema/spec';
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod/v3';
2
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, b as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-DAZmbu3U.cjs';
2
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-DnJzAZrj.cjs';
3
3
  export { Params, remarkInclude } from './index.cjs';
4
4
  import '@standard-schema/spec';
5
5
  import 'fumadocs-core/mdx-plugins';
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod/v3';
2
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, b as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-DAZmbu3U.js';
2
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-DnJzAZrj.js';
3
3
  export { Params, remarkInclude } from './index.js';
4
4
  import '@standard-schema/spec';
5
5
  import 'fumadocs-core/mdx-plugins';
@@ -107,4 +107,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
107
107
  }): DocsCollection<DocSchema, MetaSchema, Async>;
108
108
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
109
109
 
110
- export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DocCollection as D, type GlobalConfig as G, type MetaCollection as M, type DocsCollection as a, type DefaultMDXOptions as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
110
+ export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type GlobalConfig as G, type MetaCollection as M, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
@@ -107,4 +107,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
107
107
  }): DocsCollection<DocSchema, MetaSchema, Async>;
108
108
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
109
109
 
110
- export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DocCollection as D, type GlobalConfig as G, type MetaCollection as M, type DocsCollection as a, type DefaultMDXOptions as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
110
+ export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type GlobalConfig as G, type MetaCollection as M, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime, B as BaseCollectionEntry } from './types-B2kQsHs7.cjs';
2
+ import { R as Runtime, B as BaseCollectionEntry } from './types-BmVgoqsr.cjs';
3
3
  import '@standard-schema/spec';
4
- import './define-DAZmbu3U.cjs';
4
+ import './define-DnJzAZrj.cjs';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime, B as BaseCollectionEntry } from './types-CkmezNbX.js';
2
+ import { R as Runtime, B as BaseCollectionEntry } from './types-WSHJKA8L.js';
3
3
  import '@standard-schema/spec';
4
- import './define-DAZmbu3U.js';
4
+ import './define-DnJzAZrj.js';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
@@ -325,7 +325,7 @@ async function loadConfig(configPath, outDir, hash, build = false) {
325
325
  loaded
326
326
  );
327
327
  });
328
- cache = { config, hash };
328
+ if (hash) cache = { config, hash };
329
329
  return await config;
330
330
  }
331
331
  async function getConfigHash(configPath) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getConfigHash,
3
3
  loadConfig
4
- } from "./chunk-BWRDVK5L.js";
4
+ } from "./chunk-766EAFX6.js";
5
5
  import {
6
6
  countLines
7
7
  } from "./chunk-UCY7OBZG.js";
@@ -13,8 +13,8 @@ import {
13
13
  import {
14
14
  buildMDX
15
15
  } from "./chunk-QQWCBFFE.js";
16
- import "./chunk-QVZ7JH4H.js";
17
16
  import "./chunk-SVTXMVLQ.js";
17
+ import "./chunk-QVZ7JH4H.js";
18
18
  import {
19
19
  fumaMatter
20
20
  } from "./chunk-VWJKRQZR.js";
@@ -358,7 +358,7 @@ async function loadConfig(configPath, outDir, hash, build = false) {
358
358
  loaded
359
359
  );
360
360
  });
361
- cache = { config, hash };
361
+ if (hash) cache = { config, hash };
362
362
  return await config;
363
363
  }
364
364
  async function getConfigHash(configPath) {
@@ -514,6 +514,9 @@ function toImportPath(file, config) {
514
514
  }
515
515
  return importPath.replaceAll(import_node_path2.default.sep, "/");
516
516
  }
517
+ function ident(code, tab = 1) {
518
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
519
+ }
517
520
 
518
521
  // src/utils/collections.ts
519
522
  function getSupportedFormats(collection) {
@@ -634,18 +637,18 @@ async function generateJS(configPath, config, importPath, configHash = false) {
634
637
  }
635
638
  const declares = entries.map(async ([k, collection]) => {
636
639
  if (collection.type === "docs") {
637
- const docs = await getCollectionFiles(collection.docs);
640
+ const docs2 = await getCollectionFiles(collection.docs);
638
641
  const metas = await getCollectionFiles(collection.meta);
639
642
  const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
640
643
  ", "
641
644
  );
642
645
  if (collection.docs.async) {
643
- const docsEntries2 = (await getAsyncEntries(collection.docs, docs)).join(
646
+ const docsEntries2 = (await getAsyncEntries(collection.docs, docs2)).join(
644
647
  ", "
645
648
  );
646
649
  return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
647
650
  }
648
- const docsEntries = (await getDocEntries(k, docs)).join(", ");
651
+ const docsEntries = (await getDocEntries(k, docs2)).join(", ");
649
652
  return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
650
653
  }
651
654
  const files = await getCollectionFiles(collection);
@@ -823,17 +826,129 @@ function createMDX({
823
826
  // src/postinstall.ts
824
827
  var path6 = __toESM(require("path"), 1);
825
828
  var fs4 = __toESM(require("fs/promises"), 1);
826
- async function postInstall(configPath = findConfigFile(), outDir = ".source") {
827
- const jsOut = path6.resolve(outDir, "index.ts");
829
+ var import_node_fs2 = require("fs");
830
+
831
+ // src/vite/generate-glob.ts
832
+ function generateGlob(name, patterns, globOptions) {
833
+ const options = {
834
+ ...globOptions,
835
+ query: {
836
+ ...globOptions?.query,
837
+ collection: name
838
+ }
839
+ };
840
+ return `import.meta.glob(${JSON.stringify(mapGlobPatterns(patterns))}, ${JSON.stringify(options, null, 2)})`;
841
+ }
842
+ function mapGlobPatterns(patterns) {
843
+ return patterns.map(enforceRelative);
844
+ }
845
+ function enforceRelative(file) {
846
+ if (file.startsWith("./")) return file;
847
+ if (file.startsWith("/")) return `.${file}`;
848
+ return `./${file}`;
849
+ }
850
+ function getGlobBase(collection) {
851
+ let dir = collection.dir;
852
+ if (Array.isArray(dir)) {
853
+ if (dir.length !== 1)
854
+ throw new Error(
855
+ `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
856
+ );
857
+ dir = dir[0];
858
+ }
859
+ return enforceRelative(dir);
860
+ }
861
+
862
+ // src/vite/generate.ts
863
+ function docs(name, collection) {
864
+ const obj = [
865
+ ident(`doc: ${doc(name, collection.docs)}`),
866
+ ident(`meta: ${meta(name, collection.meta)}`)
867
+ ].join(",\n");
868
+ return `{
869
+ ${obj}
870
+ }`;
871
+ }
872
+ function doc(name, collection) {
873
+ const patterns = getGlobPatterns(collection);
874
+ const base = getGlobBase(collection);
875
+ const docGlob = generateGlob(name, patterns, {
876
+ base
877
+ });
878
+ if (collection.async) {
879
+ const headBlob = generateGlob(name, patterns, {
880
+ query: {
881
+ only: "frontmatter"
882
+ },
883
+ import: "frontmatter",
884
+ base
885
+ });
886
+ return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
887
+ }
888
+ return `create.doc("${name}", "${base}", ${docGlob})`;
889
+ }
890
+ function meta(name, collection) {
891
+ const patterns = getGlobPatterns(collection);
892
+ const base = getGlobBase(collection);
893
+ return `create.meta("${name}", "${base}", ${generateGlob(name, patterns, {
894
+ import: "default",
895
+ base
896
+ })})`;
897
+ }
898
+ function entry(configPath, config, outDir, jsExtension) {
899
+ const lines = [
900
+ '/// <reference types="vite/client" />',
901
+ `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
902
+ `import type * as Config from '${toImportPath(configPath, {
903
+ relativeTo: outDir,
904
+ jsExtension
905
+ })}';`,
906
+ "",
907
+ `export const create = fromConfig<typeof Config>();`
908
+ ];
909
+ for (const [name, collection] of config.collections.entries()) {
910
+ let body;
911
+ if (collection.type === "docs") {
912
+ body = docs(name, collection);
913
+ } else if (collection.type === "meta") {
914
+ body = meta(name, collection);
915
+ } else {
916
+ body = doc(name, collection);
917
+ }
918
+ lines.push("");
919
+ lines.push(`export const ${name} = ${body};`);
920
+ }
921
+ return lines.join("\n");
922
+ }
923
+
924
+ // src/postinstall.ts
925
+ async function postInstall(configPath = findConfigFile(), outDir) {
926
+ const isNext = (0, import_node_fs2.existsSync)("next.config.js") || (0, import_node_fs2.existsSync)("next.config.mjs") || (0, import_node_fs2.existsSync)("next.config.ts");
927
+ if (isNext) {
928
+ await onNext(configPath, outDir ?? ".source");
929
+ } else {
930
+ await onVite(configPath, outDir ?? process.cwd());
931
+ }
932
+ console.log("[MDX] types generated");
933
+ }
934
+ async function onNext(configPath, outDir) {
935
+ const config = await loadConfig(configPath, outDir, void 0, true);
936
+ const outPath = path6.join(outDir, "index.ts");
937
+ await fs4.rm(outDir, { recursive: true });
938
+ await fs4.mkdir(outDir, { recursive: true });
828
939
  const hash = await getConfigHash(configPath);
829
- const config = await loadConfig(configPath, outDir, hash, true);
830
- await fs4.rm(path6.dirname(jsOut), { recursive: true });
831
- await fs4.mkdir(path6.dirname(jsOut), { recursive: true });
832
940
  await fs4.writeFile(
833
- jsOut,
941
+ outPath,
834
942
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
835
943
  );
836
- console.log("[MDX] types generated");
944
+ }
945
+ async function onVite(configPath, outDir, addJsExtension) {
946
+ const config = await loadConfig(configPath, "node_modules", void 0, true);
947
+ const outFile = "source.generated.ts";
948
+ await fs4.writeFile(
949
+ path6.join(outDir, outFile),
950
+ entry(configPath, config, outDir, addJsExtension)
951
+ );
837
952
  }
838
953
  // Annotate the CommonJS export names for ESM import in node:
839
954
  0 && (module.exports = {