fumadocs-mdx 14.0.1 → 14.0.3

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 (72) hide show
  1. package/dist/{build-mdx-6UAK5FF5.js → build-mdx-W3233QBZ.js} +1 -1
  2. package/dist/bun/index.d.ts +1 -1
  3. package/dist/bun/index.js +8 -8
  4. package/dist/{chunk-ZY6UZ7NH.js → chunk-6RPNS75C.js} +1 -1
  5. package/dist/{chunk-7UKSZSPY.js → chunk-DKA3EWZH.js} +6 -7
  6. package/dist/{chunk-BEBCWQC7.js → chunk-GB4W3YCZ.js} +1 -1
  7. package/dist/{chunk-SLY7WXTX.js → chunk-KOPLIEVQ.js} +5 -6
  8. package/dist/{chunk-MTTISKQJ.js → chunk-LPX7ZO66.js} +1 -1
  9. package/dist/{chunk-K6HCOGOX.js → chunk-OLL7FM7W.js} +2 -2
  10. package/dist/{chunk-IQGEFL2B.js → chunk-Q5OSGLJL.js} +1 -1
  11. package/dist/{chunk-E5DJTSIM.js → chunk-S7KOJHHO.js} +4 -1
  12. package/dist/{chunk-6NISOLQ6.js → chunk-USWQVJWR.js} +1 -1
  13. package/dist/config/index.d.ts +1 -1
  14. package/dist/config/index.js +1 -1
  15. package/dist/{core-B9ZoS6sA.d.ts → core-C3QZSdEx.d.ts} +1 -1
  16. package/dist/{index-BD8Woo4m.d.cts → index-DG1I0CwF.d.ts} +2 -2
  17. package/dist/index.d.ts +1 -1
  18. package/dist/load-from-file-OZ5N7DXU.js +8 -0
  19. package/dist/next/index.cjs +10 -8
  20. package/dist/next/index.d.ts +1 -1
  21. package/dist/next/index.js +8 -8
  22. package/dist/node/loader.js +4 -4
  23. package/dist/plugins/index-file.d.ts +1 -1
  24. package/dist/plugins/index-file.js +2 -2
  25. package/dist/plugins/json-schema.d.ts +1 -1
  26. package/dist/plugins/last-modified.d.ts +5 -2
  27. package/dist/plugins/last-modified.js +10 -3
  28. package/dist/runtime/browser.d.ts +1 -1
  29. package/dist/runtime/dynamic.d.ts +1 -1
  30. package/dist/runtime/dynamic.js +5 -5
  31. package/dist/runtime/server.d.ts +1 -1
  32. package/dist/vite/index.d.ts +1 -1
  33. package/dist/vite/index.js +10 -10
  34. package/dist/webpack/mdx.d.ts +2 -2
  35. package/dist/webpack/mdx.js +6 -6
  36. package/dist/webpack/meta.d.ts +2 -2
  37. package/dist/webpack/meta.js +4 -4
  38. package/package.json +4 -6
  39. package/dist/bin.cjs +0 -1958
  40. package/dist/bin.d.cts +0 -1
  41. package/dist/bun/index.cjs +0 -1147
  42. package/dist/bun/index.d.cts +0 -25
  43. package/dist/config/index.cjs +0 -400
  44. package/dist/config/index.d.cts +0 -18
  45. package/dist/core-DTuP23zu.d.cts +0 -341
  46. package/dist/index-CNOvhtOn.d.ts +0 -8
  47. package/dist/index.cjs +0 -18
  48. package/dist/index.d.cts +0 -61
  49. package/dist/load-from-file-5HUQN36V.js +0 -8
  50. package/dist/next/index.d.cts +0 -33
  51. package/dist/node/loader.cjs +0 -1200
  52. package/dist/node/loader.d.cts +0 -5
  53. package/dist/plugins/index-file.cjs +0 -495
  54. package/dist/plugins/index-file.d.cts +0 -14
  55. package/dist/plugins/json-schema.cjs +0 -114
  56. package/dist/plugins/json-schema.d.cts +0 -31
  57. package/dist/plugins/last-modified.cjs +0 -110
  58. package/dist/plugins/last-modified.d.cts +0 -37
  59. package/dist/runtime/browser.cjs +0 -93
  60. package/dist/runtime/browser.d.cts +0 -53
  61. package/dist/runtime/dynamic.cjs +0 -1023
  62. package/dist/runtime/dynamic.d.cts +0 -27
  63. package/dist/runtime/server.cjs +0 -176
  64. package/dist/runtime/server.d.cts +0 -14
  65. package/dist/runtime/types.cjs +0 -18
  66. package/dist/runtime/types.d.cts +0 -61
  67. package/dist/vite/index.cjs +0 -1687
  68. package/dist/vite/index.d.cts +0 -44
  69. package/dist/webpack/mdx.cjs +0 -1124
  70. package/dist/webpack/mdx.d.cts +0 -20
  71. package/dist/webpack/meta.cjs +0 -684
  72. package/dist/webpack/meta.d.cts +0 -20
@@ -1,5 +0,0 @@
1
- import { LoadHook } from 'node:module';
2
-
3
- declare const load: LoadHook;
4
-
5
- export { load };
@@ -1,495 +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.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/fs-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
- 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
- function removeFileCache(file) {
185
- map.delete(toFullPath(file));
186
- }
187
-
188
- // src/plugins/index-file.ts
189
- var import_crypto = require("crypto");
190
-
191
- // src/utils/fuma-matter.ts
192
- var import_js_yaml = require("js-yaml");
193
- var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
194
- function fumaMatter(input) {
195
- const output = { matter: "", data: {}, content: input };
196
- const match = regex.exec(input);
197
- if (!match) {
198
- return output;
199
- }
200
- output.matter = match[0];
201
- output.content = input.slice(match[0].length);
202
- const loaded = (0, import_js_yaml.load)(match[1]);
203
- output.data = loaded ?? {};
204
- return output;
205
- }
206
-
207
- // src/plugins/index-file.ts
208
- function indexFile(options = {}) {
209
- const {
210
- target = "default",
211
- addJsExtension,
212
- browser = true,
213
- dynamic = true
214
- } = options;
215
- let config;
216
- let dynamicCollections;
217
- function isDynamic(collection) {
218
- return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
219
- }
220
- function generateConfigs(core) {
221
- const serverOptions = {};
222
- const typeConfigs = [];
223
- const ctx = core.getPluginContext();
224
- for (const plugin of core.getPlugins()) {
225
- const indexFilePlugin = plugin["index-file"];
226
- if (!indexFilePlugin) continue;
227
- indexFilePlugin.serverOptions?.call(ctx, serverOptions);
228
- const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
229
- if (config2) typeConfigs.push(config2);
230
- }
231
- if (typeConfigs.length === 0) {
232
- typeConfigs.push("{ DocData: {} }");
233
- }
234
- return {
235
- serverOptions,
236
- tc: typeConfigs.join(" & ")
237
- };
238
- }
239
- return {
240
- name: "index-file",
241
- config(v) {
242
- config = v;
243
- dynamicCollections = config.collectionList.filter(isDynamic);
244
- },
245
- configureServer(server) {
246
- if (!server.watcher) return;
247
- server.watcher.on("all", async (event, file) => {
248
- removeFileCache(file);
249
- if (dynamicCollections.length === 0) {
250
- if (target === "vite") return;
251
- if (target === "default" && event === "change") return;
252
- }
253
- const updatedCollection = config.collectionList.find(
254
- (collection) => collection.hasFile(file)
255
- );
256
- if (!updatedCollection) return;
257
- if (!isDynamic(updatedCollection)) {
258
- if (target === "vite") return;
259
- if (target === "default" && event === "change") return;
260
- }
261
- await this.core.emitAndWrite({
262
- filterPlugin: (plugin) => plugin.name === "index-file"
263
- });
264
- });
265
- },
266
- async emit() {
267
- const globCache = /* @__PURE__ */ new Map();
268
- const { serverOptions, tc } = generateConfigs(this.core);
269
- const toEmitEntry = async (path4, content) => {
270
- const codegen = createCodegen({
271
- target,
272
- outDir: this.outDir,
273
- jsExtension: addJsExtension,
274
- globCache
275
- });
276
- await content({
277
- core: this.core,
278
- codegen,
279
- serverOptions,
280
- tc
281
- });
282
- return {
283
- path: path4,
284
- content: codegen.toString()
285
- };
286
- };
287
- const out = [
288
- toEmitEntry("server.ts", generateServerIndexFile)
289
- ];
290
- if (dynamic)
291
- out.push(toEmitEntry("dynamic.ts", generateDynamicIndexFile));
292
- if (browser)
293
- out.push(toEmitEntry("browser.ts", generateBrowserIndexFile));
294
- return await Promise.all(out);
295
- }
296
- };
297
- }
298
- async function generateServerIndexFile({
299
- core,
300
- codegen,
301
- serverOptions,
302
- tc
303
- }) {
304
- codegen.lines.push(
305
- `import { server } from 'fumadocs-mdx/runtime/server';`,
306
- `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
307
- "",
308
- `const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
309
- );
310
- async function generateCollectionObject(collection) {
311
- switch (collection.type) {
312
- case "docs": {
313
- if (collection.docs.dynamic) return;
314
- if (collection.docs.async) {
315
- const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
316
- generateMetaCollectionGlob(codegen, collection.meta, true),
317
- generateDocCollectionFrontmatterGlob(
318
- codegen,
319
- collection.docs,
320
- true
321
- ),
322
- generateDocCollectionGlob(codegen, collection.docs)
323
- ]);
324
- return `await create.docsLazy("${collection.name}", "${collection.dir}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
325
- }
326
- const [metaGlob, docGlob] = await Promise.all([
327
- generateMetaCollectionGlob(codegen, collection.meta, true),
328
- generateDocCollectionGlob(codegen, collection.docs, true)
329
- ]);
330
- return `await create.docs("${collection.name}", "${collection.dir}", ${metaGlob}, ${docGlob})`;
331
- }
332
- case "doc":
333
- if (collection.dynamic) return;
334
- if (collection.async) {
335
- const [headGlob, bodyGlob] = await Promise.all([
336
- generateDocCollectionFrontmatterGlob(codegen, collection, true),
337
- generateDocCollectionGlob(codegen, collection)
338
- ]);
339
- return `await create.docLazy("${collection.name}", "${collection.dir}", ${headGlob}, ${bodyGlob})`;
340
- }
341
- return `await create.doc("${collection.name}", "${collection.dir}", ${await generateDocCollectionGlob(
342
- codegen,
343
- collection,
344
- true
345
- )})`;
346
- case "meta":
347
- return `await create.meta("${collection.name}", "${collection.dir}", ${await generateMetaCollectionGlob(
348
- codegen,
349
- collection,
350
- true
351
- )})`;
352
- }
353
- }
354
- await codegen.pushAsync(
355
- core.getConfig().collectionList.map(async (collection) => {
356
- const obj = await generateCollectionObject(collection);
357
- if (!obj) return;
358
- return `
359
- export const ${collection.name} = ${obj};`;
360
- })
361
- );
362
- }
363
- async function generateDynamicIndexFile({
364
- core,
365
- codegen,
366
- serverOptions,
367
- tc
368
- }) {
369
- const { configPath } = core.getOptions();
370
- codegen.lines.push(
371
- `import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
372
- `import * as Config from '${codegen.formatImportPath(configPath)}';`,
373
- "",
374
- `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
375
- );
376
- async function generateCollectionObjectEntry(collection, file) {
377
- const fullPath = import_path.default.join(collection.dir, file);
378
- const content = await readFileWithCache(fullPath).catch(() => "");
379
- const parsed = fumaMatter(content);
380
- const data = await core.transformFrontmatter(
381
- {
382
- collection,
383
- filePath: fullPath,
384
- source: content
385
- },
386
- parsed.data
387
- );
388
- const hash = (0, import_crypto.createHash)("md5").update(content).digest("hex");
389
- const infoStr = [
390
- // make sure it's included in vercel/nft
391
- `absolutePath: path.resolve(${JSON.stringify(fullPath)})`
392
- ];
393
- for (const [k, v] of Object.entries({
394
- info: {
395
- fullPath,
396
- path: file
397
- },
398
- data,
399
- hash
400
- })) {
401
- infoStr.push(`${k}: ${JSON.stringify(v)}`);
402
- }
403
- return `{ ${infoStr.join(", ")} }`;
404
- }
405
- async function generateCollectionObject(parent) {
406
- let collection;
407
- if (parent.type === "doc") collection = parent;
408
- else if (parent.type === "docs") collection = parent.docs;
409
- if (!collection || !collection.dynamic) return;
410
- const files = await (0, import_tinyglobby2.glob)(collection.patterns, {
411
- cwd: collection.dir
412
- });
413
- const entries = await Promise.all(
414
- files.map((file) => generateCollectionObjectEntry(collection, file))
415
- );
416
- switch (parent.type) {
417
- case "docs": {
418
- const metaGlob = await generateMetaCollectionGlob(
419
- codegen,
420
- parent.meta,
421
- true
422
- );
423
- return `await create.docs("${parent.name}", "${parent.dir}", ${metaGlob}, ${entries.join(", ")})`;
424
- }
425
- case "doc":
426
- return `await create.doc("${collection.name}", "${collection.dir}", ${entries.join(", ")})`;
427
- }
428
- }
429
- await codegen.pushAsync(
430
- core.getConfig().collectionList.map(async (collection) => {
431
- const obj = await generateCollectionObject(collection);
432
- if (!obj) return;
433
- return `
434
- export const ${collection.name} = ${obj};`;
435
- })
436
- );
437
- }
438
- async function generateBrowserIndexFile({ core, codegen, tc }) {
439
- codegen.lines.push(
440
- `import { browser } from 'fumadocs-mdx/runtime/browser';`,
441
- `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
442
- "",
443
- `const create = browser<typeof Config, ${tc}>();`
444
- );
445
- async function generateCollectionObject(collection) {
446
- switch (collection.type) {
447
- case "docs": {
448
- if (collection.docs.dynamic) return;
449
- return generateCollectionObject(collection.docs);
450
- }
451
- case "doc":
452
- if (collection.dynamic) return;
453
- return `create.doc("${collection.name}", ${await generateDocCollectionGlob(codegen, collection)})`;
454
- }
455
- }
456
- codegen.lines.push("const browserCollections = {");
457
- await codegen.pushAsync(
458
- core.getConfig().collectionList.map(async (collection) => {
459
- const obj = await generateCollectionObject(collection);
460
- if (!obj) return;
461
- return ident(`${collection.name}: ${obj},`);
462
- })
463
- );
464
- codegen.lines.push("};", "export default browserCollections;");
465
- }
466
- function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
467
- return codegen.generateGlobImport(collection.patterns, {
468
- query: {
469
- collection: collection.name,
470
- only: "frontmatter"
471
- },
472
- import: "frontmatter",
473
- base: collection.dir,
474
- eager
475
- });
476
- }
477
- function generateDocCollectionGlob(codegen, collection, eager = false) {
478
- return codegen.generateGlobImport(collection.patterns, {
479
- query: {
480
- collection: collection.name
481
- },
482
- base: collection.dir,
483
- eager
484
- });
485
- }
486
- function generateMetaCollectionGlob(codegen, collection, eager = false) {
487
- return codegen.generateGlobImport(collection.patterns, {
488
- query: {
489
- collection: collection.name
490
- },
491
- import: "default",
492
- base: collection.dir,
493
- eager
494
- });
495
- }
@@ -1,14 +0,0 @@
1
- export { J as IndexFilePlugin, I as IndexFilePluginOptions, H as default } from '../core-DTuP23zu.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
- import 'fumadocs-core/source';
10
- import '../runtime/types.cjs';
11
- import 'fumadocs-core/mdx-plugins/remark-structure';
12
- import 'fumadocs-core/toc';
13
- import 'mdast';
14
- import 'mdx/types';
@@ -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,31 +0,0 @@
1
- import { j as Plugin } from '../core-DTuP23zu.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
- import 'fumadocs-core/source';
10
- import '../runtime/types.cjs';
11
- import 'fumadocs-core/mdx-plugins/remark-structure';
12
- import 'fumadocs-core/toc';
13
- import 'mdast';
14
- import 'mdx/types';
15
-
16
- interface JSONSchemaOptions {
17
- /**
18
- * insert `$schema` field to JSON files on creation.
19
- *
20
- * @defaultValue false
21
- */
22
- insert?: boolean;
23
- }
24
- /**
25
- * Generate JSON schemas locally for collection schemas
26
- *
27
- * note: **it only works with Zod**
28
- */
29
- declare function jsonSchema({ insert, }?: JSONSchemaOptions): Plugin;
30
-
31
- export { type JSONSchemaOptions, jsonSchema as default };