fumadocs-mdx 11.3.1 → 11.4.0

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.
@@ -0,0 +1,106 @@
1
+ import { z, ZodTypeAny } from 'zod';
2
+ import { ProcessorOptions } from '@mdx-js/mdx';
3
+ import { c as MDXOptions, B as BaseCollectionEntry, M as MarkdownProps, G as GlobalConfig } from './build-mdx-o0kbHSlp.cjs';
4
+
5
+ declare const metaSchema: z.ZodObject<{
6
+ title: z.ZodOptional<z.ZodString>;
7
+ pages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
8
+ description: z.ZodOptional<z.ZodString>;
9
+ root: z.ZodOptional<z.ZodBoolean>;
10
+ defaultOpen: z.ZodOptional<z.ZodBoolean>;
11
+ icon: z.ZodOptional<z.ZodString>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ root?: boolean | undefined;
14
+ title?: string | undefined;
15
+ icon?: string | undefined;
16
+ pages?: string[] | undefined;
17
+ description?: string | undefined;
18
+ defaultOpen?: boolean | undefined;
19
+ }, {
20
+ root?: boolean | undefined;
21
+ title?: string | undefined;
22
+ icon?: string | undefined;
23
+ pages?: string[] | undefined;
24
+ description?: string | undefined;
25
+ defaultOpen?: boolean | undefined;
26
+ }>;
27
+ declare const frontmatterSchema: z.ZodObject<{
28
+ title: z.ZodString;
29
+ description: z.ZodOptional<z.ZodString>;
30
+ icon: z.ZodOptional<z.ZodString>;
31
+ full: z.ZodOptional<z.ZodBoolean>;
32
+ _openapi: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
33
+ }, "strip", z.ZodTypeAny, {
34
+ title: string;
35
+ icon?: string | undefined;
36
+ description?: string | undefined;
37
+ full?: boolean | undefined;
38
+ _openapi?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
39
+ }, {
40
+ title: string;
41
+ icon?: string | undefined;
42
+ description?: string | undefined;
43
+ full?: boolean | undefined;
44
+ _openapi?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
45
+ }>;
46
+
47
+ interface TransformContext {
48
+ path: string;
49
+ source: string;
50
+ /**
51
+ * Compile MDX to JavaScript
52
+ */
53
+ buildMDX: (source: string, options?: ProcessorOptions) => Promise<string>;
54
+ }
55
+ interface BaseCollection<Schema> {
56
+ /**
57
+ * Directories to scan
58
+ */
59
+ dir: string | string[];
60
+ /**
61
+ * what files to include/exclude (glob patterns)
62
+ *
63
+ * Include all files if not specified
64
+ */
65
+ files?: string[];
66
+ schema?: Schema | ((ctx: TransformContext) => Schema);
67
+ }
68
+ interface MetaCollection<Schema extends ZodTypeAny = ZodTypeAny> extends BaseCollection<Schema> {
69
+ type: 'meta';
70
+ }
71
+ interface DocCollection<Schema extends ZodTypeAny = ZodTypeAny, Async extends boolean = boolean> extends BaseCollection<Schema> {
72
+ type: 'doc';
73
+ mdxOptions?: MDXOptions;
74
+ /**
75
+ * Load files with async
76
+ */
77
+ async?: Async;
78
+ }
79
+ declare function defineCollections<T extends 'doc' | 'meta', Schema extends ZodTypeAny = ZodTypeAny, Async extends boolean = false>(options: {
80
+ type: T;
81
+ } & (T extends 'doc' ? DocCollection<Schema, Async> : MetaCollection<Schema>)): {
82
+ _doc: 'collections';
83
+ type: T;
84
+ _type: {
85
+ async: Async;
86
+ runtime: T extends 'doc' ? Async extends true ? z.infer<Schema> & BaseCollectionEntry & {
87
+ load: () => Promise<MarkdownProps>;
88
+ } : Omit<MarkdownProps, keyof z.infer<Schema>> & z.infer<Schema> & BaseCollectionEntry : typeof options extends MetaCollection ? z.infer<Schema> & BaseCollectionEntry : never;
89
+ };
90
+ };
91
+ declare function defineDocs<DocData extends ZodTypeAny = typeof frontmatterSchema, MetaData extends ZodTypeAny = typeof metaSchema, DocAsync extends boolean = false>(options?: {
92
+ /**
93
+ * The directory to scan files
94
+ *
95
+ * @defaultValue 'content/docs'
96
+ */
97
+ dir?: string | string[];
98
+ docs?: Partial<DocCollection<DocData, DocAsync>>;
99
+ meta?: Partial<MetaCollection<MetaData>>;
100
+ }): {
101
+ docs: ReturnType<typeof defineCollections<'doc', DocData, DocAsync>>;
102
+ meta: ReturnType<typeof defineCollections<'meta', MetaData, false>>;
103
+ };
104
+ declare function defineConfig(config?: GlobalConfig): GlobalConfig;
105
+
106
+ export { type BaseCollection as B, type DocCollection as D, type MetaCollection as M, type TransformContext as T, defineDocs as a, defineConfig as b, defineCollections as d, frontmatterSchema as f, metaSchema as m };
@@ -0,0 +1,106 @@
1
+ import { z, ZodTypeAny } from 'zod';
2
+ import { ProcessorOptions } from '@mdx-js/mdx';
3
+ import { c as MDXOptions, B as BaseCollectionEntry, M as MarkdownProps, G as GlobalConfig } from './build-mdx-o0kbHSlp.js';
4
+
5
+ declare const metaSchema: z.ZodObject<{
6
+ title: z.ZodOptional<z.ZodString>;
7
+ pages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
8
+ description: z.ZodOptional<z.ZodString>;
9
+ root: z.ZodOptional<z.ZodBoolean>;
10
+ defaultOpen: z.ZodOptional<z.ZodBoolean>;
11
+ icon: z.ZodOptional<z.ZodString>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ root?: boolean | undefined;
14
+ title?: string | undefined;
15
+ icon?: string | undefined;
16
+ pages?: string[] | undefined;
17
+ description?: string | undefined;
18
+ defaultOpen?: boolean | undefined;
19
+ }, {
20
+ root?: boolean | undefined;
21
+ title?: string | undefined;
22
+ icon?: string | undefined;
23
+ pages?: string[] | undefined;
24
+ description?: string | undefined;
25
+ defaultOpen?: boolean | undefined;
26
+ }>;
27
+ declare const frontmatterSchema: z.ZodObject<{
28
+ title: z.ZodString;
29
+ description: z.ZodOptional<z.ZodString>;
30
+ icon: z.ZodOptional<z.ZodString>;
31
+ full: z.ZodOptional<z.ZodBoolean>;
32
+ _openapi: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
33
+ }, "strip", z.ZodTypeAny, {
34
+ title: string;
35
+ icon?: string | undefined;
36
+ description?: string | undefined;
37
+ full?: boolean | undefined;
38
+ _openapi?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
39
+ }, {
40
+ title: string;
41
+ icon?: string | undefined;
42
+ description?: string | undefined;
43
+ full?: boolean | undefined;
44
+ _openapi?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
45
+ }>;
46
+
47
+ interface TransformContext {
48
+ path: string;
49
+ source: string;
50
+ /**
51
+ * Compile MDX to JavaScript
52
+ */
53
+ buildMDX: (source: string, options?: ProcessorOptions) => Promise<string>;
54
+ }
55
+ interface BaseCollection<Schema> {
56
+ /**
57
+ * Directories to scan
58
+ */
59
+ dir: string | string[];
60
+ /**
61
+ * what files to include/exclude (glob patterns)
62
+ *
63
+ * Include all files if not specified
64
+ */
65
+ files?: string[];
66
+ schema?: Schema | ((ctx: TransformContext) => Schema);
67
+ }
68
+ interface MetaCollection<Schema extends ZodTypeAny = ZodTypeAny> extends BaseCollection<Schema> {
69
+ type: 'meta';
70
+ }
71
+ interface DocCollection<Schema extends ZodTypeAny = ZodTypeAny, Async extends boolean = boolean> extends BaseCollection<Schema> {
72
+ type: 'doc';
73
+ mdxOptions?: MDXOptions;
74
+ /**
75
+ * Load files with async
76
+ */
77
+ async?: Async;
78
+ }
79
+ declare function defineCollections<T extends 'doc' | 'meta', Schema extends ZodTypeAny = ZodTypeAny, Async extends boolean = false>(options: {
80
+ type: T;
81
+ } & (T extends 'doc' ? DocCollection<Schema, Async> : MetaCollection<Schema>)): {
82
+ _doc: 'collections';
83
+ type: T;
84
+ _type: {
85
+ async: Async;
86
+ runtime: T extends 'doc' ? Async extends true ? z.infer<Schema> & BaseCollectionEntry & {
87
+ load: () => Promise<MarkdownProps>;
88
+ } : Omit<MarkdownProps, keyof z.infer<Schema>> & z.infer<Schema> & BaseCollectionEntry : typeof options extends MetaCollection ? z.infer<Schema> & BaseCollectionEntry : never;
89
+ };
90
+ };
91
+ declare function defineDocs<DocData extends ZodTypeAny = typeof frontmatterSchema, MetaData extends ZodTypeAny = typeof metaSchema, DocAsync extends boolean = false>(options?: {
92
+ /**
93
+ * The directory to scan files
94
+ *
95
+ * @defaultValue 'content/docs'
96
+ */
97
+ dir?: string | string[];
98
+ docs?: Partial<DocCollection<DocData, DocAsync>>;
99
+ meta?: Partial<MetaCollection<MetaData>>;
100
+ }): {
101
+ docs: ReturnType<typeof defineCollections<'doc', DocData, DocAsync>>;
102
+ meta: ReturnType<typeof defineCollections<'meta', MetaData, false>>;
103
+ };
104
+ declare function defineConfig(config?: GlobalConfig): GlobalConfig;
105
+
106
+ export { type BaseCollection as B, type DocCollection as D, type MetaCollection as M, type TransformContext as T, defineDocs as a, defineConfig as b, defineCollections as d, frontmatterSchema as f, metaSchema as m };
package/dist/index.cjs CHANGED
@@ -21,36 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  createMDXSource: () => createMDXSource,
24
- toRuntime: () => toRuntime,
25
- toRuntimeAsync: () => toRuntimeAsync
24
+ resolveFiles: () => resolveFiles,
25
+ toRuntime: () => toRuntime
26
26
  });
27
27
  module.exports = __toCommonJS(index_exports);
28
28
 
29
- // src/runtime/resolve-files.ts
30
- function resolveFiles({
31
- docs,
32
- meta,
33
- rootDir = ""
34
- }) {
35
- const outputs = [];
36
- for (const entry of docs) {
37
- if (!entry._file.path.startsWith(rootDir)) continue;
38
- outputs.push({
39
- type: "page",
40
- path: entry._file.path,
41
- data: entry
42
- });
43
- }
44
- for (const entry of meta) {
45
- outputs.push({
46
- type: "meta",
47
- path: entry._file.path,
48
- data: entry
49
- });
50
- }
51
- return outputs;
52
- }
53
-
54
29
  // src/runtime/index.ts
55
30
  function toRuntime(type, file, info) {
56
31
  if (type === "doc") {
@@ -68,19 +43,6 @@ function toRuntime(type, file, info) {
68
43
  _file: info
69
44
  };
70
45
  }
71
- function toRuntimeAsync(frontmatter, load, info) {
72
- return {
73
- async load() {
74
- const { default: body, ...res } = await load();
75
- return {
76
- body,
77
- ...res
78
- };
79
- },
80
- ...frontmatter,
81
- _file: info
82
- };
83
- }
84
46
  function createMDXSource(docs, meta = []) {
85
47
  return {
86
48
  files: (rootDir) => resolveFiles({
@@ -90,9 +52,32 @@ function createMDXSource(docs, meta = []) {
90
52
  })
91
53
  };
92
54
  }
55
+ function resolveFiles({
56
+ docs,
57
+ meta,
58
+ rootDir = ""
59
+ }) {
60
+ const outputs = [];
61
+ for (const entry of docs) {
62
+ if (!entry._file.path.startsWith(rootDir)) continue;
63
+ outputs.push({
64
+ type: "page",
65
+ path: entry._file.path,
66
+ data: entry
67
+ });
68
+ }
69
+ for (const entry of meta) {
70
+ outputs.push({
71
+ type: "meta",
72
+ path: entry._file.path,
73
+ data: entry
74
+ });
75
+ }
76
+ return outputs;
77
+ }
93
78
  // Annotate the CommonJS export names for ESM import in node:
94
79
  0 && (module.exports = {
95
80
  createMDXSource,
96
- toRuntime,
97
- toRuntimeAsync
81
+ resolveFiles,
82
+ toRuntime
98
83
  });
package/dist/index.d.cts CHANGED
@@ -1,17 +1,23 @@
1
- import { PageData, MetaData, Source } from 'fumadocs-core/source';
2
- import { F as FileInfo, B as BaseCollectionEntry } from './build-mdx-C2hor32E.cjs';
1
+ import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
+ import { F as FileInfo, B as BaseCollectionEntry } from './build-mdx-o0kbHSlp.cjs';
3
3
  import 'zod';
4
4
  import 'mdx/types';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import 'fumadocs-core/server';
7
7
  import '@mdx-js/mdx';
8
8
  import 'unified';
9
+ import 'react';
9
10
 
10
11
  declare function toRuntime(type: 'doc' | 'meta', file: Record<string, unknown>, info: FileInfo): unknown;
11
- declare function toRuntimeAsync(frontmatter: Record<string, unknown>, load: () => Promise<Record<string, unknown>>, info: FileInfo): unknown;
12
12
  declare function createMDXSource<Doc extends PageData & BaseCollectionEntry, Meta extends MetaData & BaseCollectionEntry>(docs: Doc[], meta?: Meta[]): Source<{
13
13
  pageData: Doc;
14
14
  metaData: Meta;
15
15
  }>;
16
+ interface ResolveOptions {
17
+ docs: BaseCollectionEntry[];
18
+ meta: BaseCollectionEntry[];
19
+ rootDir?: string;
20
+ }
21
+ declare function resolveFiles({ docs, meta, rootDir, }: ResolveOptions): VirtualFile[];
16
22
 
17
- export { createMDXSource, toRuntime, toRuntimeAsync };
23
+ export { createMDXSource, resolveFiles, toRuntime };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,23 @@
1
- import { PageData, MetaData, Source } from 'fumadocs-core/source';
2
- import { F as FileInfo, B as BaseCollectionEntry } from './build-mdx-C2hor32E.js';
1
+ import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
+ import { F as FileInfo, B as BaseCollectionEntry } from './build-mdx-o0kbHSlp.js';
3
3
  import 'zod';
4
4
  import 'mdx/types';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import 'fumadocs-core/server';
7
7
  import '@mdx-js/mdx';
8
8
  import 'unified';
9
+ import 'react';
9
10
 
10
11
  declare function toRuntime(type: 'doc' | 'meta', file: Record<string, unknown>, info: FileInfo): unknown;
11
- declare function toRuntimeAsync(frontmatter: Record<string, unknown>, load: () => Promise<Record<string, unknown>>, info: FileInfo): unknown;
12
12
  declare function createMDXSource<Doc extends PageData & BaseCollectionEntry, Meta extends MetaData & BaseCollectionEntry>(docs: Doc[], meta?: Meta[]): Source<{
13
13
  pageData: Doc;
14
14
  metaData: Meta;
15
15
  }>;
16
+ interface ResolveOptions {
17
+ docs: BaseCollectionEntry[];
18
+ meta: BaseCollectionEntry[];
19
+ rootDir?: string;
20
+ }
21
+ declare function resolveFiles({ docs, meta, rootDir, }: ResolveOptions): VirtualFile[];
16
22
 
17
- export { createMDXSource, toRuntime, toRuntimeAsync };
23
+ export { createMDXSource, resolveFiles, toRuntime };
package/dist/index.js CHANGED
@@ -1,28 +1,3 @@
1
- // src/runtime/resolve-files.ts
2
- function resolveFiles({
3
- docs,
4
- meta,
5
- rootDir = ""
6
- }) {
7
- const outputs = [];
8
- for (const entry of docs) {
9
- if (!entry._file.path.startsWith(rootDir)) continue;
10
- outputs.push({
11
- type: "page",
12
- path: entry._file.path,
13
- data: entry
14
- });
15
- }
16
- for (const entry of meta) {
17
- outputs.push({
18
- type: "meta",
19
- path: entry._file.path,
20
- data: entry
21
- });
22
- }
23
- return outputs;
24
- }
25
-
26
1
  // src/runtime/index.ts
27
2
  function toRuntime(type, file, info) {
28
3
  if (type === "doc") {
@@ -40,19 +15,6 @@ function toRuntime(type, file, info) {
40
15
  _file: info
41
16
  };
42
17
  }
43
- function toRuntimeAsync(frontmatter, load, info) {
44
- return {
45
- async load() {
46
- const { default: body, ...res } = await load();
47
- return {
48
- body,
49
- ...res
50
- };
51
- },
52
- ...frontmatter,
53
- _file: info
54
- };
55
- }
56
18
  function createMDXSource(docs, meta = []) {
57
19
  return {
58
20
  files: (rootDir) => resolveFiles({
@@ -62,8 +24,31 @@ function createMDXSource(docs, meta = []) {
62
24
  })
63
25
  };
64
26
  }
27
+ function resolveFiles({
28
+ docs,
29
+ meta,
30
+ rootDir = ""
31
+ }) {
32
+ const outputs = [];
33
+ for (const entry of docs) {
34
+ if (!entry._file.path.startsWith(rootDir)) continue;
35
+ outputs.push({
36
+ type: "page",
37
+ path: entry._file.path,
38
+ data: entry
39
+ });
40
+ }
41
+ for (const entry of meta) {
42
+ outputs.push({
43
+ type: "meta",
44
+ path: entry._file.path,
45
+ data: entry
46
+ });
47
+ }
48
+ return outputs;
49
+ }
65
50
  export {
66
51
  createMDXSource,
67
- toRuntime,
68
- toRuntimeAsync
52
+ resolveFiles,
53
+ toRuntime
69
54
  };
@@ -100,6 +100,7 @@ function getDefaultMDXOptions({
100
100
  remarkImageOptions,
101
101
  remarkHeadingOptions,
102
102
  remarkStructureOptions,
103
+ remarkCodeTabOptions,
103
104
  ...mdxOptions
104
105
  }) {
105
106
  const mdxExports = [
@@ -110,18 +111,20 @@ function getDefaultMDXOptions({
110
111
  ];
111
112
  const remarkPlugins = pluginOption(
112
113
  (v) => [
113
- import_mdx_plugins.remarkGfm,
114
+ plugins.remarkGfm,
114
115
  [
115
- import_mdx_plugins.remarkHeading,
116
+ plugins.remarkHeading,
116
117
  {
117
118
  generateToc: false,
118
119
  ...remarkHeadingOptions
119
120
  }
120
121
  ],
121
- remarkImageOptions !== false && [import_mdx_plugins.remarkImage, remarkImageOptions],
122
+ remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
123
+ // Fumadocs 14 compatibility
124
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && plugins.remarkCodeTab,
122
125
  ...v,
123
126
  remarkStructureOptions !== false && [
124
- import_mdx_plugins.remarkStructure,
127
+ plugins.remarkStructure,
125
128
  remarkStructureOptions
126
129
  ],
127
130
  [remarkMdxExport, { values: mdxExports }]
@@ -130,9 +133,9 @@ function getDefaultMDXOptions({
130
133
  );
131
134
  const rehypePlugins = pluginOption(
132
135
  (v) => [
133
- rehypeCodeOptions !== false && [import_mdx_plugins.rehypeCode, rehypeCodeOptions],
136
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
134
137
  ...v,
135
- [import_mdx_plugins.rehypeToc]
138
+ [plugins.rehypeToc]
136
139
  ],
137
140
  mdxOptions.rehypePlugins
138
141
  );
@@ -142,11 +145,11 @@ function getDefaultMDXOptions({
142
145
  rehypePlugins
143
146
  };
144
147
  }
145
- var import_mdx_plugins;
148
+ var plugins;
146
149
  var init_mdx_options = __esm({
147
150
  "src/utils/mdx-options.ts"() {
148
151
  "use strict";
149
- import_mdx_plugins = require("fumadocs-core/mdx-plugins");
152
+ plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
150
153
  init_remark_exports();
151
154
  }
152
155
  });
@@ -161,41 +164,15 @@ var path4 = __toESM(require("path"), 1);
161
164
  var import_node_querystring = require("querystring");
162
165
  var import_gray_matter2 = __toESM(require("gray-matter"), 1);
163
166
 
164
- // src/config/cached.ts
167
+ // src/utils/config-cache.ts
165
168
  var import_node_crypto = require("crypto");
166
169
  var fs = __toESM(require("fs"), 1);
167
170
 
168
- // src/config/load.ts
171
+ // src/utils/load-config.ts
169
172
  var path = __toESM(require("path"), 1);
170
173
  var import_node_url = require("url");
171
- async function loadConfig(configPath) {
172
- const { build } = await import("esbuild");
173
- const url = (0, import_node_url.pathToFileURL)(path.resolve(".source/source.config.mjs"));
174
- const transformed = await build({
175
- entryPoints: [{ in: configPath, out: "source.config" }],
176
- bundle: true,
177
- outdir: ".source",
178
- target: "node18",
179
- write: true,
180
- platform: "node",
181
- format: "esm",
182
- packages: "external",
183
- outExtension: {
184
- ".js": ".mjs"
185
- },
186
- allowOverwrite: true
187
- });
188
- if (transformed.errors.length > 0) {
189
- throw new Error("failed to compile configuration file");
190
- }
191
- const loaded = await import(`${url.href}?hash=${Date.now().toString()}`);
192
- const [err, config] = buildConfig(
193
- // every call to `loadConfig` will cause the previous cache to be ignored
194
- loaded
195
- );
196
- if (err !== null) throw new Error(err);
197
- return config;
198
- }
174
+
175
+ // src/config/build.ts
199
176
  function buildConfig(config) {
200
177
  const collections = /* @__PURE__ */ new Map();
201
178
  let globalConfig;
@@ -243,7 +220,37 @@ function buildConfig(config) {
243
220
  ];
244
221
  }
245
222
 
246
- // src/config/cached.ts
223
+ // src/utils/load-config.ts
224
+ async function loadConfig(configPath) {
225
+ const { build } = await import("esbuild");
226
+ const url = (0, import_node_url.pathToFileURL)(path.resolve(".source/source.config.mjs"));
227
+ const transformed = await build({
228
+ entryPoints: [{ in: configPath, out: "source.config" }],
229
+ bundle: true,
230
+ outdir: ".source",
231
+ target: "node18",
232
+ write: true,
233
+ platform: "node",
234
+ format: "esm",
235
+ packages: "external",
236
+ outExtension: {
237
+ ".js": ".mjs"
238
+ },
239
+ allowOverwrite: true
240
+ });
241
+ if (transformed.errors.length > 0) {
242
+ throw new Error("failed to compile configuration file");
243
+ }
244
+ const loaded = await import(`${url.href}?hash=${Date.now().toString()}`);
245
+ const [err, config] = buildConfig(
246
+ // every call to `loadConfig` will cause the previous cache to be ignored
247
+ loaded
248
+ );
249
+ if (err !== null) throw new Error(err);
250
+ return config;
251
+ }
252
+
253
+ // src/utils/config-cache.ts
247
254
  var cache = /* @__PURE__ */ new Map();
248
255
  async function loadConfigCached(configPath, hash) {
249
256
  const cached = cache.get(configPath);
@@ -356,11 +363,11 @@ function buildMDX(group, configHash, source, options = {}) {
356
363
 
357
364
  // src/utils/format-error.ts
358
365
  function formatError(message, error) {
359
- const lines = [];
366
+ const lines2 = [];
360
367
  function walk(key, { _errors, ...rest }, padStart = 0) {
361
368
  if (key !== void 0 || _errors.length > 0) {
362
369
  const text = key ? `${key}: ${_errors.join("\n ")}` : _errors.join("\n");
363
- lines.push(
370
+ lines2.push(
364
371
  text.split("\n").map((line) => `${" ".repeat(padStart)}${line}`).join("\n")
365
372
  );
366
373
  }
@@ -369,7 +376,7 @@ function formatError(message, error) {
369
376
  }
370
377
  }
371
378
  walk(void 0, error.format());
372
- return [message, ...lines].join("\n");
379
+ return [message, ...lines2].join("\n");
373
380
  }
374
381
 
375
382
  // src/utils/git-timestamp.ts
@@ -426,7 +433,6 @@ async function loader(source, callback) {
426
433
  collection = void 0;
427
434
  }
428
435
  const mdxOptions = collection?.mdxOptions ?? await config.getDefaultMDXOptions();
429
- let frontmatter = matter2.data;
430
436
  if (collection?.schema) {
431
437
  let schema = collection.schema;
432
438
  if (typeof schema === "function") {
@@ -444,7 +450,7 @@ async function loader(source, callback) {
444
450
  path: filePath
445
451
  });
446
452
  }
447
- const result = await schema.safeParseAsync(frontmatter);
453
+ const result = await schema.safeParseAsync(matter2.data);
448
454
  if (result.error) {
449
455
  callback(
450
456
  new Error(
@@ -453,21 +459,24 @@ async function loader(source, callback) {
453
459
  );
454
460
  return;
455
461
  }
456
- frontmatter = result.data;
462
+ matter2.data = result.data;
457
463
  }
458
464
  let timestamp;
459
465
  if (config.global?.lastModifiedTime === "git")
460
466
  timestamp = (await getGitTimestamp(filePath))?.getTime();
461
467
  try {
468
+ const lineOffset = "\n".repeat(
469
+ this.mode === "development" ? lines(source) - lines(matter2.content) : 0
470
+ );
462
471
  const file = await buildMDX(
463
472
  collectionId ?? "global",
464
473
  configHash,
465
- matter2.content,
474
+ lineOffset + matter2.content,
466
475
  {
467
476
  development: this.mode === "development",
468
477
  ...mdxOptions,
469
478
  filePath,
470
- frontmatter,
479
+ frontmatter: matter2.data,
471
480
  data: {
472
481
  lastModified: timestamp
473
482
  },
@@ -482,3 +491,10 @@ async function loader(source, callback) {
482
491
  callback(error);
483
492
  }
484
493
  }
494
+ function lines(s) {
495
+ let num = 0;
496
+ for (const c of s) {
497
+ if (c === "\n") num++;
498
+ }
499
+ return num;
500
+ }