fumadocs-mdx 14.0.0 → 14.0.2

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 (77) hide show
  1. package/dist/{build-mdx-6UAK5FF5.js → build-mdx-W3233QBZ.js} +1 -1
  2. package/dist/bun/index.d.ts +7 -1
  3. package/dist/bun/index.js +9 -8
  4. package/dist/{chunk-5YXP7JLN.js → chunk-5OBUOALK.js} +8 -5
  5. package/dist/{chunk-ZY6UZ7NH.js → chunk-6RPNS75C.js} +1 -1
  6. package/dist/{chunk-XHJCLBZ4.js → chunk-ED3ON275.js} +86 -162
  7. package/dist/{chunk-7L2KNF6B.js → chunk-GB4W3YCZ.js} +51 -7
  8. package/dist/{chunk-SLY7WXTX.js → chunk-KOPLIEVQ.js} +5 -6
  9. package/dist/{chunk-OXSRIWQW.js → chunk-LPX7ZO66.js} +4 -3
  10. package/dist/{chunk-SRSRFOVI.js → chunk-OLL7FM7W.js} +3 -3
  11. package/dist/{chunk-5UMZCWKV.js → chunk-Q5OSGLJL.js} +1 -1
  12. package/dist/{chunk-E5DJTSIM.js → chunk-S7KOJHHO.js} +4 -1
  13. package/dist/{chunk-6NISOLQ6.js → chunk-USWQVJWR.js} +1 -1
  14. package/dist/chunk-WBIHDYMN.js +126 -0
  15. package/dist/config/index.d.ts +6 -1
  16. package/dist/config/index.js +1 -1
  17. package/dist/{index-D7JdSMpp.d.cts → core-C3QZSdEx.d.ts} +73 -4
  18. package/dist/{index-BlVBvy-z.d.ts → index-RVIZxMZG.d.ts} +1 -1
  19. package/dist/index.d.ts +56 -3
  20. package/dist/load-from-file-OZ5N7DXU.js +8 -0
  21. package/dist/next/index.cjs +263 -193
  22. package/dist/next/index.d.ts +7 -2
  23. package/dist/next/index.js +12 -10
  24. package/dist/node/loader.js +4 -4
  25. package/dist/plugins/index-file.d.ts +7 -22
  26. package/dist/plugins/index-file.js +2 -2
  27. package/dist/plugins/json-schema.d.ts +7 -1
  28. package/dist/plugins/last-modified.d.ts +15 -2
  29. package/dist/plugins/last-modified.js +43 -6
  30. package/dist/runtime/browser.d.ts +22 -19
  31. package/dist/runtime/browser.js +5 -6
  32. package/dist/runtime/dynamic.d.ts +12 -12
  33. package/dist/runtime/dynamic.js +12 -11
  34. package/dist/runtime/server.d.ts +10 -157
  35. package/dist/runtime/server.js +3 -3
  36. package/dist/runtime/types.d.ts +61 -0
  37. package/dist/runtime/types.js +0 -0
  38. package/dist/vite/index.d.ts +7 -2
  39. package/dist/vite/index.js +10 -9
  40. package/dist/webpack/mdx.d.ts +8 -2
  41. package/dist/webpack/mdx.js +5 -5
  42. package/dist/webpack/meta.d.ts +8 -2
  43. package/dist/webpack/meta.js +4 -4
  44. package/package.json +4 -6
  45. package/dist/bin.cjs +0 -1889
  46. package/dist/bin.d.cts +0 -1
  47. package/dist/bun/index.cjs +0 -1112
  48. package/dist/bun/index.d.cts +0 -19
  49. package/dist/chunk-PKI7ZDA5.js +0 -29
  50. package/dist/config/index.cjs +0 -400
  51. package/dist/config/index.d.cts +0 -13
  52. package/dist/index-D7JdSMpp.d.ts +0 -272
  53. package/dist/index-P2NNUkHn.d.cts +0 -8
  54. package/dist/index.cjs +0 -18
  55. package/dist/index.d.cts +0 -8
  56. package/dist/load-from-file-I3ALLIVB.js +0 -8
  57. package/dist/next/index.d.cts +0 -28
  58. package/dist/node/loader.cjs +0 -1165
  59. package/dist/node/loader.d.cts +0 -5
  60. package/dist/plugins/index-file.cjs +0 -471
  61. package/dist/plugins/index-file.d.cts +0 -29
  62. package/dist/plugins/json-schema.cjs +0 -114
  63. package/dist/plugins/json-schema.d.cts +0 -25
  64. package/dist/plugins/last-modified.cjs +0 -75
  65. package/dist/plugins/last-modified.d.cts +0 -27
  66. package/dist/runtime/browser.cjs +0 -94
  67. package/dist/runtime/browser.d.cts +0 -50
  68. package/dist/runtime/dynamic.cjs +0 -985
  69. package/dist/runtime/dynamic.d.cts +0 -27
  70. package/dist/runtime/server.cjs +0 -173
  71. package/dist/runtime/server.d.cts +0 -161
  72. package/dist/vite/index.cjs +0 -1620
  73. package/dist/vite/index.d.cts +0 -39
  74. package/dist/webpack/mdx.cjs +0 -1089
  75. package/dist/webpack/mdx.d.cts +0 -14
  76. package/dist/webpack/meta.cjs +0 -649
  77. package/dist/webpack/meta.d.cts +0 -14
@@ -1,5 +0,0 @@
1
- import { LoadHook } from 'node:module';
2
-
3
- declare const load: LoadHook;
4
-
5
- export { load };
@@ -1,471 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/plugins/index-file.ts
31
- var index_file_exports = {};
32
- __export(index_file_exports, {
33
- default: () => indexFile
34
- });
35
- module.exports = __toCommonJS(index_file_exports);
36
- var import_path = __toESM(require("path"), 1);
37
-
38
- // src/utils/codegen/index.ts
39
- var import_node_path = __toESM(require("path"), 1);
40
- var import_tinyglobby = require("tinyglobby");
41
- function createCodegen({
42
- target = "default",
43
- outDir = "",
44
- jsExtension = false,
45
- globCache = /* @__PURE__ */ new Map()
46
- }) {
47
- let eagerImportId = 0;
48
- const banner = ["// @ts-nocheck"];
49
- if (target === "vite") {
50
- banner.push('/// <reference types="vite/client" />');
51
- }
52
- return {
53
- options: {
54
- target,
55
- outDir
56
- },
57
- lines: [],
58
- addImport(statement) {
59
- this.lines.unshift(statement);
60
- },
61
- async pushAsync(insert) {
62
- for (const line of await Promise.all(insert)) {
63
- if (line === void 0) continue;
64
- this.lines.push(line);
65
- }
66
- },
67
- async generateGlobImport(patterns, options) {
68
- if (target === "vite") {
69
- return this.generateViteGlobImport(patterns, options);
70
- }
71
- return this.generateNodeGlobImport(patterns, options);
72
- },
73
- generateViteGlobImport(patterns, { base, ...rest }) {
74
- patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
75
- normalizeViteGlobPath
76
- );
77
- return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
78
- {
79
- base: normalizeViteGlobPath(import_node_path.default.relative(outDir, base)),
80
- ...rest
81
- },
82
- null,
83
- 2
84
- )})`;
85
- },
86
- async generateNodeGlobImport(patterns, {
87
- base,
88
- eager = false,
89
- query = {},
90
- import: importName
91
- }) {
92
- const cacheKey = JSON.stringify({ patterns, base });
93
- let files = globCache.get(cacheKey);
94
- if (!files) {
95
- files = (0, import_tinyglobby.glob)(patterns, {
96
- cwd: base
97
- });
98
- globCache.set(cacheKey, files);
99
- }
100
- let code = "{";
101
- for (const item of await files) {
102
- const fullPath = import_node_path.default.join(base, item);
103
- const searchParams = new URLSearchParams();
104
- for (const [k, v] of Object.entries(query)) {
105
- searchParams.set(k, v);
106
- }
107
- const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
108
- if (eager) {
109
- const name = `__fd_glob_${eagerImportId++}`;
110
- this.lines.unshift(
111
- importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
112
- );
113
- code += `${JSON.stringify(item)}: ${name}, `;
114
- } else {
115
- let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
116
- if (importName) {
117
- line += `.then(mod => mod.${importName})`;
118
- }
119
- code += `${line}, `;
120
- }
121
- }
122
- code += "}";
123
- return code;
124
- },
125
- formatImportPath(file) {
126
- const ext = import_node_path.default.extname(file);
127
- let filename;
128
- if (ext === ".ts" && jsExtension) {
129
- filename = file.substring(0, file.length - ext.length) + ".js";
130
- } else if (ext === ".ts") {
131
- filename = file.substring(0, file.length - ext.length);
132
- } else {
133
- filename = file;
134
- }
135
- const importPath = slash(import_node_path.default.relative(outDir, filename));
136
- return importPath.startsWith(".") ? importPath : `./${importPath}`;
137
- },
138
- toString() {
139
- return [...banner, ...this.lines].join("\n");
140
- }
141
- };
142
- }
143
- function normalizeViteGlobPath(file) {
144
- file = slash(file);
145
- if (file.startsWith("./")) return file;
146
- if (file.startsWith("/")) return `.${file}`;
147
- return `./${file}`;
148
- }
149
- function slash(path4) {
150
- const isExtendedLengthPath = path4.startsWith("\\\\?\\");
151
- if (isExtendedLengthPath) {
152
- return path4;
153
- }
154
- return path4.replaceAll("\\", "/");
155
- }
156
- function ident(code, tab = 1) {
157
- return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
158
- }
159
-
160
- // src/plugins/index-file.ts
161
- var import_tinyglobby2 = require("tinyglobby");
162
-
163
- // src/utils/codegen/cache.ts
164
- var import_lru_cache = require("lru-cache");
165
- var import_promises = __toESM(require("fs/promises"), 1);
166
- var import_node_path2 = __toESM(require("path"), 1);
167
- var map = new import_lru_cache.LRUCache({
168
- max: 100
169
- });
170
- function toFullPath(file) {
171
- if (import_node_path2.default.isAbsolute(file)) {
172
- return import_node_path2.default.relative(process.cwd(), file);
173
- }
174
- return file;
175
- }
176
- async function readFileWithCache(file) {
177
- const fullPath = toFullPath(file);
178
- const cached = map.get(fullPath);
179
- if (cached) return cached;
180
- const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
181
- map.set(fullPath, read);
182
- return read;
183
- }
184
-
185
- // src/plugins/index-file.ts
186
- var import_crypto = require("crypto");
187
-
188
- // src/utils/fuma-matter.ts
189
- var import_js_yaml = require("js-yaml");
190
- var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
191
- function fumaMatter(input) {
192
- const output = { matter: "", data: {}, content: input };
193
- const match = regex.exec(input);
194
- if (!match) {
195
- return output;
196
- }
197
- output.matter = match[0];
198
- output.content = input.slice(match[0].length);
199
- const loaded = (0, import_js_yaml.load)(match[1]);
200
- output.data = loaded ?? {};
201
- return output;
202
- }
203
-
204
- // src/plugins/index-file.ts
205
- function indexFile(options = {}) {
206
- const {
207
- target = "default",
208
- addJsExtension,
209
- browser = true,
210
- dynamic = true
211
- } = options;
212
- let config;
213
- let dynamicCollections;
214
- function isDynamic(collection) {
215
- return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
216
- }
217
- return {
218
- name: "index-file",
219
- config(v) {
220
- config = v;
221
- dynamicCollections = config.collectionList.filter(isDynamic);
222
- },
223
- configureServer(server) {
224
- if (!server.watcher) return;
225
- server.watcher.on("all", async (event, file) => {
226
- if (dynamicCollections.length === 0) {
227
- if (target === "vite") return;
228
- if (target === "default" && event === "change") return;
229
- }
230
- const updatedCollection = config.collectionList.find(
231
- (collection) => collection.hasFile(file)
232
- );
233
- if (!updatedCollection) return;
234
- if (!isDynamic(updatedCollection)) {
235
- if (target === "vite") return;
236
- if (target === "default" && event === "change") return;
237
- }
238
- await this.core.emitAndWrite({
239
- filterPlugin: (plugin) => plugin.name === "index-file"
240
- });
241
- });
242
- },
243
- async emit() {
244
- const globCache = /* @__PURE__ */ new Map();
245
- const makeCodeGen = () => createCodegen({
246
- target,
247
- outDir: this.outDir,
248
- jsExtension: addJsExtension,
249
- globCache
250
- });
251
- async function toEmitEntry(path4, content) {
252
- return {
253
- path: path4,
254
- content: await content
255
- };
256
- }
257
- const out = [
258
- toEmitEntry(
259
- "server.ts",
260
- generateServerIndexFile(makeCodeGen(), config, this.configPath)
261
- )
262
- ];
263
- if (dynamic)
264
- out.push(
265
- toEmitEntry(
266
- "dynamic.ts",
267
- generateDynamicIndexFile(this.core, makeCodeGen())
268
- )
269
- );
270
- if (browser)
271
- out.push(
272
- toEmitEntry(
273
- "browser.ts",
274
- generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
275
- )
276
- );
277
- return await Promise.all(out);
278
- }
279
- };
280
- }
281
- async function generateServerIndexFile(codegen, config, configPath) {
282
- codegen.lines.push(
283
- `import { fromConfig } from 'fumadocs-mdx/runtime/server';`,
284
- `import type * as Config from '${codegen.formatImportPath(configPath)}';`,
285
- "",
286
- `const create = fromConfig<typeof Config>();`
287
- );
288
- async function generateCollectionObject(collection) {
289
- switch (collection.type) {
290
- case "docs": {
291
- if (collection.docs.dynamic) return;
292
- if (collection.docs.async) {
293
- const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
294
- generateMetaCollectionGlob(codegen, collection.meta, true),
295
- generateDocCollectionFrontmatterGlob(
296
- codegen,
297
- collection.docs,
298
- true
299
- ),
300
- generateDocCollectionGlob(codegen, collection.docs)
301
- ]);
302
- return `await create.docsLazy("${collection.name}", "${collection.dir}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
303
- }
304
- const [metaGlob, docGlob] = await Promise.all([
305
- generateMetaCollectionGlob(codegen, collection.meta, true),
306
- generateDocCollectionGlob(codegen, collection.docs, true)
307
- ]);
308
- return `await create.docs("${collection.name}", "${collection.dir}", ${metaGlob}, ${docGlob})`;
309
- }
310
- case "doc":
311
- if (collection.dynamic) return;
312
- if (collection.async) {
313
- const [headGlob, bodyGlob] = await Promise.all([
314
- generateDocCollectionFrontmatterGlob(codegen, collection, true),
315
- generateDocCollectionGlob(codegen, collection)
316
- ]);
317
- return `await create.docLazy("${collection.name}", "${collection.dir}", ${headGlob}, ${bodyGlob})`;
318
- }
319
- return `await create.doc("${collection.name}", "${collection.dir}", ${await generateDocCollectionGlob(
320
- codegen,
321
- collection,
322
- true
323
- )})`;
324
- case "meta":
325
- return `await create.meta("${collection.name}", "${collection.dir}", ${await generateMetaCollectionGlob(
326
- codegen,
327
- collection,
328
- true
329
- )})`;
330
- }
331
- }
332
- await codegen.pushAsync(
333
- config.collectionList.map(async (collection) => {
334
- const obj = await generateCollectionObject(collection);
335
- if (!obj) return;
336
- return `
337
- export const ${collection.name} = ${obj};`;
338
- })
339
- );
340
- return codegen.toString();
341
- }
342
- async function generateDynamicIndexFile(core, codegen) {
343
- const { configPath } = core._options;
344
- codegen.lines.push(
345
- `import { fromConfigDynamic } from 'fumadocs-mdx/runtime/dynamic';`,
346
- `import * as Config from '${codegen.formatImportPath(configPath)}';`,
347
- "",
348
- `const create = await fromConfigDynamic(Config);`
349
- );
350
- async function generateCollectionObjectEntry(collection, file) {
351
- const fullPath = import_path.default.join(collection.dir, file);
352
- const content = await readFileWithCache(fullPath).catch(() => "");
353
- const parsed = fumaMatter(content);
354
- const data = await core.transformFrontmatter(
355
- {
356
- collection,
357
- filePath: fullPath,
358
- source: content
359
- },
360
- parsed.data
361
- );
362
- const hash = (0, import_crypto.createHash)("md5").update(content).digest("hex");
363
- const infoStr = [
364
- // make sure it's included in vercel/nft
365
- `absolutePath: path.resolve(${JSON.stringify(fullPath)})`
366
- ];
367
- for (const [k, v] of Object.entries({
368
- info: {
369
- fullPath,
370
- path: file
371
- },
372
- data,
373
- hash
374
- })) {
375
- infoStr.push(`${k}: ${JSON.stringify(v)}`);
376
- }
377
- return `{ ${infoStr.join(", ")} }`;
378
- }
379
- async function generateCollectionObject(parent) {
380
- let collection;
381
- if (parent.type === "doc") collection = parent;
382
- else if (parent.type === "docs") collection = parent.docs;
383
- if (!collection || !collection.dynamic) return;
384
- const files = await (0, import_tinyglobby2.glob)(collection.patterns, {
385
- cwd: collection.dir
386
- });
387
- const entries = await Promise.all(
388
- files.map((file) => generateCollectionObjectEntry(collection, file))
389
- );
390
- switch (parent.type) {
391
- case "docs": {
392
- const metaGlob = await generateMetaCollectionGlob(
393
- codegen,
394
- parent.meta,
395
- true
396
- );
397
- return `await create.docs("${parent.name}", "${parent.dir}", ${metaGlob}, ${entries.join(", ")})`;
398
- }
399
- case "doc":
400
- return `await create.doc("${collection.name}", "${collection.dir}", ${entries.join(", ")})`;
401
- }
402
- }
403
- await codegen.pushAsync(
404
- core.getConfig().collectionList.map(async (collection) => {
405
- const obj = await generateCollectionObject(collection);
406
- if (!obj) return;
407
- return `
408
- export const ${collection.name} = ${obj};`;
409
- })
410
- );
411
- return codegen.toString();
412
- }
413
- async function generateBrowserIndexFile(codegen, config, configPath) {
414
- codegen.lines.push(
415
- `import { fromConfig } from 'fumadocs-mdx/runtime/browser';`,
416
- `import type * as Config from '${codegen.formatImportPath(configPath)}';`,
417
- "",
418
- `const create = fromConfig<typeof Config>();`
419
- );
420
- async function generateCollectionObject(collection) {
421
- switch (collection.type) {
422
- case "docs": {
423
- if (collection.docs.dynamic) return;
424
- return generateCollectionObject(collection.docs);
425
- }
426
- case "doc":
427
- if (collection.dynamic) return;
428
- return `create.doc("${collection.name}", ${await generateDocCollectionGlob(codegen, collection)})`;
429
- }
430
- }
431
- codegen.lines.push("const browserCollections = {");
432
- await codegen.pushAsync(
433
- config.collectionList.map(async (collection) => {
434
- const obj = await generateCollectionObject(collection);
435
- if (!obj) return;
436
- return ident(`${collection.name}: ${obj},`);
437
- })
438
- );
439
- codegen.lines.push("};", "export default browserCollections;");
440
- return codegen.toString();
441
- }
442
- function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
443
- return codegen.generateGlobImport(collection.patterns, {
444
- query: {
445
- collection: collection.name,
446
- only: "frontmatter"
447
- },
448
- import: "frontmatter",
449
- base: collection.dir,
450
- eager
451
- });
452
- }
453
- function generateDocCollectionGlob(codegen, collection, eager = false) {
454
- return codegen.generateGlobImport(collection.patterns, {
455
- query: {
456
- collection: collection.name
457
- },
458
- base: collection.dir,
459
- eager
460
- });
461
- }
462
- function generateMetaCollectionGlob(codegen, collection, eager = false) {
463
- return codegen.generateGlobImport(collection.patterns, {
464
- query: {
465
- collection: collection.name
466
- },
467
- import: "default",
468
- base: collection.dir,
469
- eager
470
- });
471
- }
@@ -1,29 +0,0 @@
1
- import { j as Plugin } from '../index-D7JdSMpp.cjs';
2
- import '@mdx-js/mdx';
3
- import '@standard-schema/spec';
4
- import 'unified';
5
- import 'fumadocs-core/mdx-plugins';
6
- import 'zod';
7
- import 'chokidar';
8
- import 'vfile';
9
-
10
- interface IndexFilePluginOptions {
11
- target?: 'default' | 'vite';
12
- /**
13
- * add `.js` extensions to imports, needed for ESM without bundler resolution
14
- */
15
- addJsExtension?: boolean;
16
- /**
17
- * Generate entry point for browser
18
- * @defaultValue true
19
- */
20
- browser?: boolean;
21
- /**
22
- * Generate entry point for dynamic compilation
23
- * @defaultValue true
24
- */
25
- dynamic?: boolean;
26
- }
27
- declare function indexFile(options?: IndexFilePluginOptions): Plugin;
28
-
29
- export { type IndexFilePluginOptions, indexFile as default };
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/plugins/json-schema.ts
31
- var json_schema_exports = {};
32
- __export(json_schema_exports, {
33
- default: () => jsonSchema
34
- });
35
- module.exports = __toCommonJS(json_schema_exports);
36
- var import_zod = require("zod");
37
- var import_promises = __toESM(require("fs/promises"), 1);
38
- var import_node_path = __toESM(require("path"), 1);
39
- function jsonSchema({
40
- insert = false
41
- } = {}) {
42
- let config;
43
- function getSchemaPath(name) {
44
- return `json-schema/${name}.json`;
45
- }
46
- return {
47
- config(v) {
48
- config = v;
49
- },
50
- configureServer(server) {
51
- if (!server.watcher || !insert) return;
52
- server.watcher.on("add", async (file) => {
53
- let parent;
54
- let match;
55
- for (const collection of config.collectionList) {
56
- if (collection.type === "meta" && collection.hasFile(file)) {
57
- match = collection;
58
- break;
59
- }
60
- if (collection.type === "docs" && collection.meta.hasFile(file)) {
61
- parent = collection;
62
- match = collection.meta;
63
- break;
64
- }
65
- }
66
- if (!match) return;
67
- let obj;
68
- try {
69
- const content = (await import_promises.default.readFile(file)).toString();
70
- obj = content.length > 0 ? JSON.parse(content) : {};
71
- } catch {
72
- return;
73
- }
74
- if ("$schema" in obj) return;
75
- const schemaPath = import_node_path.default.join(
76
- this.outDir,
77
- getSchemaPath(parent ? `${parent.name}.meta` : match.name)
78
- );
79
- const updated = {
80
- $schema: import_node_path.default.relative(import_node_path.default.dirname(file), schemaPath),
81
- ...obj
82
- };
83
- await import_promises.default.writeFile(file, JSON.stringify(updated, null, 2));
84
- });
85
- },
86
- emit() {
87
- const files = [];
88
- function onSchema(name, schema) {
89
- files.push({
90
- path: getSchemaPath(name),
91
- content: JSON.stringify(
92
- import_zod.z.toJSONSchema(schema, {
93
- io: "input",
94
- unrepresentable: "any"
95
- })
96
- )
97
- });
98
- }
99
- for (const collection of config.collectionList) {
100
- if (collection.type === "docs") {
101
- if (collection.meta.schema instanceof import_zod.z.ZodType) {
102
- onSchema(`${collection.name}.meta`, collection.meta.schema);
103
- }
104
- if (collection.docs.schema instanceof import_zod.z.ZodType) {
105
- onSchema(`${collection.name}.docs`, collection.docs.schema);
106
- }
107
- } else if (collection.schema instanceof import_zod.z.ZodType) {
108
- onSchema(collection.name, collection.schema);
109
- }
110
- }
111
- return files;
112
- }
113
- };
114
- }
@@ -1,25 +0,0 @@
1
- import { j as Plugin } from '../index-D7JdSMpp.cjs';
2
- import '@mdx-js/mdx';
3
- import '@standard-schema/spec';
4
- import 'unified';
5
- import 'fumadocs-core/mdx-plugins';
6
- import 'zod';
7
- import 'chokidar';
8
- import 'vfile';
9
-
10
- interface JSONSchemaOptions {
11
- /**
12
- * insert `$schema` field to JSON files on creation.
13
- *
14
- * @defaultValue false
15
- */
16
- insert?: boolean;
17
- }
18
- /**
19
- * Generate JSON schemas locally for collection schemas
20
- *
21
- * note: **it only works with Zod**
22
- */
23
- declare function jsonSchema({ insert, }?: JSONSchemaOptions): Plugin;
24
-
25
- export { type JSONSchemaOptions, jsonSchema as default };