fuma-content 0.0.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/bin.d.ts +1 -0
  2. package/dist/bin.js +18 -0
  3. package/dist/build-mdx-I4NROXCF.js +8 -0
  4. package/dist/bun/index.d.ts +16 -0
  5. package/dist/bun/index.js +37 -0
  6. package/dist/bun-DMNX4PBC.js +40 -0
  7. package/dist/chunk-3VQS3KSP.js +39 -0
  8. package/dist/chunk-BTRE6MOX.js +16 -0
  9. package/dist/chunk-E4HRKSP4.js +24 -0
  10. package/dist/chunk-ERBMAQYP.js +33 -0
  11. package/dist/chunk-GGL4EF6H.js +38 -0
  12. package/dist/chunk-JBZTQ55D.js +30 -0
  13. package/dist/chunk-KH5GT2Y5.js +104 -0
  14. package/dist/chunk-LUM7SIZN.js +40 -0
  15. package/dist/chunk-MT7RY65Y.js +167 -0
  16. package/dist/chunk-NRZ4GE5O.js +207 -0
  17. package/dist/chunk-OQQNA7L7.js +412 -0
  18. package/dist/chunk-OUJENWQ4.js +45 -0
  19. package/dist/chunk-RMSV4HP6.js +85 -0
  20. package/dist/chunk-RXR7OL76.js +37 -0
  21. package/dist/chunk-VWJKRQZR.js +19 -0
  22. package/dist/chunk-W6HENTK7.js +44 -0
  23. package/dist/chunk-XR5N6ZXJ.js +50 -0
  24. package/dist/collections/handlers/fs.d.ts +10 -0
  25. package/dist/collections/handlers/fs.js +6 -0
  26. package/dist/collections/index.d.ts +10 -0
  27. package/dist/collections/index.js +6 -0
  28. package/dist/collections/mdx/loader-webpack.d.ts +17 -0
  29. package/dist/collections/mdx/loader-webpack.js +39 -0
  30. package/dist/collections/mdx/runtime-browser.d.ts +55 -0
  31. package/dist/collections/mdx/runtime-browser.js +82 -0
  32. package/dist/collections/mdx/runtime-dynamic.d.ts +43 -0
  33. package/dist/collections/mdx/runtime-dynamic.js +96 -0
  34. package/dist/collections/mdx/runtime.d.ts +70 -0
  35. package/dist/collections/mdx/runtime.js +45 -0
  36. package/dist/collections/mdx.d.ts +10 -0
  37. package/dist/collections/mdx.js +291 -0
  38. package/dist/collections/meta/loader-webpack.d.ts +17 -0
  39. package/dist/collections/meta/loader-webpack.js +42 -0
  40. package/dist/collections/meta/runtime.d.ts +19 -0
  41. package/dist/collections/meta/runtime.js +18 -0
  42. package/dist/collections/meta.d.ts +10 -0
  43. package/dist/collections/meta.js +170 -0
  44. package/dist/collections/runtime/file-store.d.ts +19 -0
  45. package/dist/collections/runtime/file-store.js +7 -0
  46. package/dist/collections/runtime/store.d.ts +28 -0
  47. package/dist/collections/runtime/store.js +6 -0
  48. package/dist/config/index.d.ts +10 -0
  49. package/dist/config/index.js +7 -0
  50. package/dist/core-Bo8KaWQz.d.ts +411 -0
  51. package/dist/index.d.ts +15 -31
  52. package/dist/index.js +6 -49
  53. package/dist/load-from-file-HL2VEY3M.js +7 -0
  54. package/dist/loader-NFSL6P5I.js +7 -0
  55. package/dist/loader-T756NSCS.js +7 -0
  56. package/dist/next/index.cjs +594 -0
  57. package/dist/next/index.d.ts +27 -0
  58. package/dist/next/index.js +100 -0
  59. package/dist/node/loader.d.ts +5 -0
  60. package/dist/node/loader.js +47 -0
  61. package/dist/node-DCMYL4DL.js +34 -0
  62. package/dist/plugins/git.d.ts +10 -0
  63. package/dist/plugins/git.js +70 -0
  64. package/dist/plugins/json-schema.d.ts +10 -0
  65. package/dist/plugins/json-schema.js +59 -0
  66. package/dist/plugins/with-loader/index.d.ts +61 -0
  67. package/dist/plugins/with-loader/index.js +6 -0
  68. package/dist/plugins/with-loader/webpack.d.ts +27 -0
  69. package/dist/plugins/with-loader/webpack.js +12 -0
  70. package/dist/vite/index.d.ts +33 -0
  71. package/dist/vite/index.js +61 -0
  72. package/dist/vite-QCUPZHHB.js +32 -0
  73. package/package.json +104 -36
  74. package/dist/internal.d.ts +0 -114
  75. package/dist/internal.js +0 -420
@@ -0,0 +1,594 @@
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/next/index.ts
31
+ var next_exports = {};
32
+ __export(next_exports, {
33
+ createContent: () => createContent,
34
+ createStandaloneCore: () => createStandaloneCore
35
+ });
36
+ module.exports = __toCommonJS(next_exports);
37
+ var path3 = __toESM(require("path"), 1);
38
+
39
+ // src/config/load-from-file.ts
40
+ var import_node_url = require("url");
41
+
42
+ // src/config/build.ts
43
+ function buildConfig(config, workspace) {
44
+ const collections = /* @__PURE__ */ new Map();
45
+ const loaded = {};
46
+ let globalConfig;
47
+ if ("default" in config) {
48
+ globalConfig = config.default;
49
+ for (const [k, v] of Object.entries(config)) {
50
+ if (k === "default") continue;
51
+ globalConfig.collections ??= {};
52
+ globalConfig.collections[k] = v;
53
+ }
54
+ } else {
55
+ globalConfig = config;
56
+ }
57
+ if (globalConfig.collections) {
58
+ for (const [name, collection] of Object.entries(globalConfig.collections)) {
59
+ collection.init?.({ name, workspace });
60
+ collections.set(name, collection);
61
+ }
62
+ }
63
+ return {
64
+ ...globalConfig,
65
+ collections,
66
+ workspaces: Object.fromEntries(
67
+ Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
68
+ return [
69
+ key,
70
+ {
71
+ dir: value.dir,
72
+ config: buildConfig(value.config, {
73
+ ...value,
74
+ name: key
75
+ })
76
+ }
77
+ ];
78
+ })
79
+ )
80
+ };
81
+ }
82
+
83
+ // src/config/load-from-file.ts
84
+ async function compileConfig(core) {
85
+ const { build } = await import("esbuild");
86
+ const { configPath, outDir } = core.getOptions();
87
+ const transformed = await build({
88
+ entryPoints: [{ in: configPath, out: "content.config" }],
89
+ bundle: true,
90
+ outdir: outDir,
91
+ target: "node20",
92
+ write: true,
93
+ platform: "node",
94
+ format: "esm",
95
+ packages: "external",
96
+ outExtension: {
97
+ ".js": ".mjs"
98
+ },
99
+ allowOverwrite: true
100
+ });
101
+ if (transformed.errors.length > 0) {
102
+ throw new Error("failed to compile configuration file");
103
+ }
104
+ }
105
+ async function loadConfig(core, build = false) {
106
+ if (build) await compileConfig(core);
107
+ const url = (0, import_node_url.pathToFileURL)(core.getCompiledConfigPath());
108
+ url.searchParams.set("hash", Date.now().toString());
109
+ const config = import(url.href).then(
110
+ (loaded) => buildConfig(loaded)
111
+ );
112
+ return await config;
113
+ }
114
+
115
+ // src/core.ts
116
+ var import_node_path2 = __toESM(require("path"), 1);
117
+ var import_promises = __toESM(require("fs/promises"), 1);
118
+
119
+ // src/utils/code-generator.ts
120
+ var import_node_path = __toESM(require("path"), 1);
121
+ var import_tinyglobby = require("tinyglobby");
122
+
123
+ // src/utils/async-cache.ts
124
+ function createCache(store = /* @__PURE__ */ new Map()) {
125
+ return {
126
+ cached(key, fn) {
127
+ let cached = store.get(key);
128
+ if (cached) return cached;
129
+ cached = fn();
130
+ if (cached instanceof Promise) {
131
+ cached = cached.then((out) => {
132
+ if (store.has(key)) {
133
+ store.set(key, out);
134
+ }
135
+ return out;
136
+ });
137
+ }
138
+ store.set(key, cached);
139
+ return cached;
140
+ },
141
+ invalidate(key) {
142
+ store.delete(key);
143
+ },
144
+ $value() {
145
+ return this;
146
+ }
147
+ };
148
+ }
149
+
150
+ // src/utils/code-generator.ts
151
+ function importInfo() {
152
+ return {
153
+ named: /* @__PURE__ */ new Map(),
154
+ namespaces: /* @__PURE__ */ new Set(),
155
+ isUsed: /* @__PURE__ */ new Set()
156
+ };
157
+ }
158
+ var CodeGenerator = class {
159
+ lines = [];
160
+ globCache;
161
+ // specifier -> imported members/info
162
+ importInfos = /* @__PURE__ */ new Map();
163
+ eagerImportId = 0;
164
+ options;
165
+ constructor({
166
+ target = "default",
167
+ jsExtension = false,
168
+ globCache = /* @__PURE__ */ new Map(),
169
+ outDir = ""
170
+ }) {
171
+ this.options = {
172
+ target,
173
+ jsExtension,
174
+ globCache,
175
+ outDir
176
+ };
177
+ this.globCache = createCache(globCache);
178
+ }
179
+ addNamespaceImport(namespace, specifier, types = false) {
180
+ const info = this.importInfos.get(specifier) ?? importInfo();
181
+ this.importInfos.set(specifier, info);
182
+ if (!types) info.isUsed.add(namespace);
183
+ info.namespaces.add(namespace);
184
+ }
185
+ addNamedImport(names, specifier, types = false) {
186
+ const info = this.importInfos.get(specifier) ?? importInfo();
187
+ this.importInfos.set(specifier, info);
188
+ for (const name of names) {
189
+ const [memberName, importName = memberName] = name.split(/\s+as\s+/, 2);
190
+ info.named.set(importName, memberName);
191
+ if (!types) info.isUsed.add(importName);
192
+ }
193
+ }
194
+ push(...insert) {
195
+ this.lines.push(...insert);
196
+ }
197
+ async pushAsync(insert) {
198
+ for (const line of await Promise.all(insert)) {
199
+ if (line === void 0) continue;
200
+ this.lines.push(line);
201
+ }
202
+ }
203
+ async generateGlobImport(patterns, options) {
204
+ if (this.options.target === "vite") {
205
+ return this.generateViteGlobImport(patterns, options);
206
+ }
207
+ return this.generateNodeGlobImport(patterns, options);
208
+ }
209
+ generateViteGlobImport(patterns, { base, ...rest }) {
210
+ patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
211
+ normalizeViteGlobPath
212
+ );
213
+ return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
214
+ {
215
+ base: normalizeViteGlobPath(import_node_path.default.relative(this.options.outDir, base)),
216
+ ...rest
217
+ },
218
+ null,
219
+ 2
220
+ )})`;
221
+ }
222
+ async generateNodeGlobImport(patterns, { base, eager = false, query = {}, import: importName }) {
223
+ const files = await this.globCache.cached(
224
+ JSON.stringify({ patterns, base }),
225
+ () => (0, import_tinyglobby.glob)(patterns, {
226
+ cwd: base
227
+ })
228
+ );
229
+ let code = "{";
230
+ for (const item of files) {
231
+ const fullPath = import_node_path.default.join(base, item);
232
+ const searchParams = new URLSearchParams();
233
+ for (const [k, v] of Object.entries(query)) {
234
+ if (v !== void 0) searchParams.set(k, v);
235
+ }
236
+ const importPath = `${this.formatImportPath(fullPath)}?${searchParams.toString()}`;
237
+ if (eager) {
238
+ const name = `__fd_glob_${this.eagerImportId++}`;
239
+ this.lines.unshift(
240
+ importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
241
+ );
242
+ code += `${JSON.stringify(item)}: ${name}, `;
243
+ } else {
244
+ let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
245
+ if (importName) {
246
+ line += `.then(mod => mod.${importName})`;
247
+ }
248
+ code += `${line}, `;
249
+ }
250
+ }
251
+ code += "}";
252
+ return code;
253
+ }
254
+ formatImportPath(file) {
255
+ const ext = import_node_path.default.extname(file);
256
+ let filename;
257
+ if (ext === ".ts") {
258
+ filename = file.substring(0, file.length - ext.length);
259
+ if (this.options.jsExtension) filename += ".js";
260
+ } else {
261
+ filename = file;
262
+ }
263
+ const importPath = slash(import_node_path.default.relative(this.options.outDir, filename));
264
+ return importPath.startsWith(".") ? importPath : `./${importPath}`;
265
+ }
266
+ toString() {
267
+ const final = ["// @ts-nocheck"];
268
+ if (this.options.target === "vite") {
269
+ final.push('/// <reference types="vite/client" />');
270
+ }
271
+ for (const [specifier, info] of this.importInfos) {
272
+ const { namespaces, named, isUsed } = info;
273
+ for (const namespace of namespaces) {
274
+ final.push(
275
+ isUsed.has(namespace) ? `import * as ${namespace} from "${specifier}";` : `import type * as ${namespace} from "${specifier}";`
276
+ );
277
+ }
278
+ const namedImports = [];
279
+ for (const [importName, memberName] of named) {
280
+ const item = importName === memberName ? importName : `${memberName} as ${importName}`;
281
+ namedImports.push(isUsed.has(importName) ? item : `type ${item}`);
282
+ }
283
+ if (namedImports.length > 0) {
284
+ final.push(
285
+ `import { ${namedImports.join(", ")} } from "${specifier}";`
286
+ );
287
+ }
288
+ }
289
+ final.push(...this.lines);
290
+ return final.join("\n");
291
+ }
292
+ };
293
+ function normalizeViteGlobPath(file) {
294
+ file = slash(file);
295
+ if (file.startsWith("./")) return file;
296
+ if (file.startsWith("/")) return `.${file}`;
297
+ return `./${file}`;
298
+ }
299
+ function slash(path4) {
300
+ const isExtendedLengthPath = path4.startsWith("\\\\?\\");
301
+ if (isExtendedLengthPath) {
302
+ return path4;
303
+ }
304
+ return path4.replaceAll("\\", "/");
305
+ }
306
+
307
+ // src/core.ts
308
+ async function getPlugins(pluginOptions) {
309
+ const plugins = [];
310
+ for (const option of await Promise.all(pluginOptions)) {
311
+ if (!option) continue;
312
+ if (Array.isArray(option)) plugins.push(...await getPlugins(option));
313
+ else plugins.push(option);
314
+ }
315
+ return plugins;
316
+ }
317
+ var Core = class _Core {
318
+ workspaces = /* @__PURE__ */ new Map();
319
+ options;
320
+ plugins = [];
321
+ config;
322
+ static defaultOptions = {
323
+ configPath: "content.config.ts",
324
+ outDir: ".content"
325
+ };
326
+ /**
327
+ * Convenient cache store, reset when config changes.
328
+ *
329
+ * You can group namespaces in cache key with ":", like `my-plugin:data`
330
+ */
331
+ cache = /* @__PURE__ */ new Map();
332
+ constructor(options) {
333
+ this.options = options;
334
+ }
335
+ async init({ config: newConfig }) {
336
+ this.config = await newConfig;
337
+ this.cache.clear();
338
+ this.workspaces.clear();
339
+ const loadedCollectionTypeIds = /* @__PURE__ */ new Set();
340
+ this.plugins = await getPlugins([
341
+ this.options.plugins,
342
+ this.config.plugins,
343
+ ...this.config.collections.values().map(({ typeInfo }) => {
344
+ if (loadedCollectionTypeIds.has(typeInfo.id)) return false;
345
+ loadedCollectionTypeIds.add(typeInfo.id);
346
+ return typeInfo.plugins;
347
+ })
348
+ ]);
349
+ const ctx = this.getPluginContext();
350
+ for (const plugin of this.plugins) {
351
+ const out = await plugin.config?.call(ctx, this.config);
352
+ if (out) this.config = out;
353
+ }
354
+ const { workspace, outDir } = this.options;
355
+ if (!workspace) {
356
+ await Promise.all(
357
+ Object.entries(this.config.workspaces).map(
358
+ async ([name, workspace2]) => {
359
+ const child = new _Core({
360
+ ...this.options,
361
+ outDir: import_node_path2.default.join(outDir, name),
362
+ workspace: {
363
+ name,
364
+ parent: this,
365
+ dir: workspace2.dir
366
+ }
367
+ });
368
+ await child.init({ config: workspace2.config });
369
+ this.workspaces.set(name, child);
370
+ }
371
+ )
372
+ );
373
+ }
374
+ await Promise.all(
375
+ this.config.collections.values().map(async (collection) => {
376
+ for (const plugin of this.plugins) {
377
+ await plugin.collection?.call(ctx, collection);
378
+ }
379
+ })
380
+ );
381
+ }
382
+ getWorkspaces() {
383
+ return this.workspaces;
384
+ }
385
+ getOptions() {
386
+ return this.options;
387
+ }
388
+ getConfig() {
389
+ return this.config;
390
+ }
391
+ /**
392
+ * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
393
+ */
394
+ getCompiledConfigPath() {
395
+ return import_node_path2.default.join(this.options.outDir, "content.config.mjs");
396
+ }
397
+ getPlugins(workspace = false) {
398
+ if (workspace) {
399
+ const plugins = [...this.plugins];
400
+ for (const workspace2 of this.workspaces.values()) {
401
+ plugins.push(...workspace2.plugins);
402
+ }
403
+ return plugins;
404
+ }
405
+ return this.plugins;
406
+ }
407
+ getCollections(workspace = false) {
408
+ const list = Array.from(this.config.collections.values());
409
+ if (workspace) {
410
+ for (const workspace2 of this.workspaces.values()) {
411
+ list.push(...workspace2.getCollections());
412
+ }
413
+ }
414
+ return list;
415
+ }
416
+ getCollection(name) {
417
+ return this.config.collections.get(name);
418
+ }
419
+ getPluginContext() {
420
+ return {
421
+ core: this
422
+ };
423
+ }
424
+ async initServer(server) {
425
+ const ctx = this.getPluginContext();
426
+ const promises = [];
427
+ for (const plugin of this.plugins) {
428
+ promises.push(plugin.configureServer?.call(ctx, server));
429
+ }
430
+ for (const workspace of this.workspaces.values()) {
431
+ promises.push(workspace.initServer(server));
432
+ }
433
+ await Promise.all(promises);
434
+ }
435
+ async emit(emitOptions = {}) {
436
+ const {
437
+ workspace,
438
+ outDir,
439
+ emit: { target, jsExtension } = {}
440
+ } = this.options;
441
+ const { filterPlugin, filterWorkspace, write = false } = emitOptions;
442
+ const start = performance.now();
443
+ const globCache = /* @__PURE__ */ new Map();
444
+ const ctx = {
445
+ ...this.getPluginContext(),
446
+ createCodeGenerator: async (path4, content) => {
447
+ const codegen = new CodeGenerator({
448
+ target,
449
+ outDir,
450
+ jsExtension,
451
+ globCache
452
+ });
453
+ await content({
454
+ core: this,
455
+ codegen,
456
+ workspace: workspace?.name
457
+ });
458
+ return {
459
+ path: path4,
460
+ content: codegen.toString()
461
+ };
462
+ }
463
+ };
464
+ const added = /* @__PURE__ */ new Set();
465
+ const out = {
466
+ entries: [],
467
+ workspaces: {}
468
+ };
469
+ for (const li of await Promise.all(
470
+ this.plugins.map((plugin) => {
471
+ if (filterPlugin && !filterPlugin(plugin) || !plugin.emit)
472
+ return null;
473
+ return plugin.emit.call(ctx);
474
+ })
475
+ )) {
476
+ if (!li) continue;
477
+ for (const item of li) {
478
+ if (added.has(item.path)) continue;
479
+ out.entries.push(item);
480
+ added.add(item.path);
481
+ }
482
+ }
483
+ if (write) {
484
+ await Promise.all(
485
+ out.entries.map(async (entry) => {
486
+ const file = import_node_path2.default.join(outDir, entry.path);
487
+ await import_promises.default.mkdir(import_node_path2.default.dirname(file), { recursive: true });
488
+ await import_promises.default.writeFile(file, entry.content);
489
+ })
490
+ );
491
+ console.log(
492
+ workspace ? `[MDX: ${workspace.name}] generated files in ${performance.now() - start}ms` : `[MDX] generated files in ${performance.now() - start}ms`
493
+ );
494
+ }
495
+ await Promise.all(
496
+ this.workspaces.entries().map(async ([name, workspace2]) => {
497
+ if (filterWorkspace && !filterWorkspace(name)) return;
498
+ out.workspaces[name] = (await workspace2.emit(emitOptions)).entries;
499
+ })
500
+ );
501
+ return out;
502
+ }
503
+ };
504
+
505
+ // src/next/index.ts
506
+ async function createContent(nextOptions = {}) {
507
+ const core = createNextCore(applyDefaults(nextOptions));
508
+ await core.init({
509
+ config: loadConfig(core, true)
510
+ });
511
+ if (process.env._FUMADOCS_MDX !== "1") {
512
+ process.env._FUMADOCS_MDX = "1";
513
+ await core.emit({ write: true });
514
+ await init(process.env.NODE_ENV === "development", core);
515
+ }
516
+ return (nextConfig = {}) => {
517
+ const ctx = core.getPluginContext();
518
+ for (const plugin of core.getPlugins(true)) {
519
+ nextConfig = plugin.next?.config?.call(ctx, nextConfig) ?? nextConfig;
520
+ }
521
+ return nextConfig;
522
+ };
523
+ }
524
+ async function init(dev, core) {
525
+ if (!dev) return;
526
+ const { FSWatcher } = await import("chokidar");
527
+ const { configPath, outDir } = core.getOptions();
528
+ const absoluteConfigPath = path3.resolve(configPath);
529
+ let watcher;
530
+ async function devServer() {
531
+ if (watcher && !watcher.closed) {
532
+ await watcher.close();
533
+ }
534
+ watcher = new FSWatcher({
535
+ ignoreInitial: true,
536
+ persistent: true,
537
+ ignored: [outDir]
538
+ });
539
+ watcher.add(configPath);
540
+ for (const collection of core.getCollections(true)) {
541
+ const handler = collection.handlers.fs;
542
+ if (handler) {
543
+ watcher.add(handler.dir);
544
+ }
545
+ }
546
+ watcher.once("ready", () => {
547
+ console.log("[MDX] started dev server");
548
+ });
549
+ watcher.on("all", (_event, file) => {
550
+ if (path3.resolve(file) === absoluteConfigPath) {
551
+ console.log("[MDX] restarting dev server");
552
+ watcher?.removeAllListeners();
553
+ void (async () => {
554
+ await core.init({
555
+ config: loadConfig(core, true)
556
+ });
557
+ await devServer();
558
+ await core.emit({ write: true });
559
+ })();
560
+ }
561
+ });
562
+ await core.initServer({ watcher });
563
+ }
564
+ process.on("exit", () => {
565
+ if (!watcher || watcher.closed) return;
566
+ console.log("[MDX] closing dev server");
567
+ void watcher.close();
568
+ });
569
+ await devServer();
570
+ }
571
+ async function createStandaloneCore(options) {
572
+ const core = createNextCore(applyDefaults(options));
573
+ await core.init({
574
+ config: loadConfig(core, true)
575
+ });
576
+ return core;
577
+ }
578
+ function applyDefaults(options) {
579
+ return {
580
+ outDir: options.outDir ?? Core.defaultOptions.outDir,
581
+ configPath: options.configPath ?? Core.defaultOptions.configPath
582
+ };
583
+ }
584
+ function createNextCore(options) {
585
+ return new Core({
586
+ outDir: options.outDir,
587
+ configPath: options.configPath
588
+ });
589
+ }
590
+ // Annotate the CommonJS export names for ESM import in node:
591
+ 0 && (module.exports = {
592
+ createContent,
593
+ createStandaloneCore
594
+ });
@@ -0,0 +1,27 @@
1
+ import { NextConfig } from 'next';
2
+ import { a as Core } from '../core-Bo8KaWQz.js';
3
+ import 'chokidar';
4
+ import '@mdx-js/mdx';
5
+ import 'vfile';
6
+ import '@standard-schema/spec';
7
+ import 'unified';
8
+ import 'mdast';
9
+ import 'vite';
10
+ import 'node:module';
11
+
12
+ interface NextOptions {
13
+ /**
14
+ * Path to source configuration file
15
+ */
16
+ configPath?: string;
17
+ /**
18
+ * Directory for output files
19
+ *
20
+ * @defaultValue '.content'
21
+ */
22
+ outDir?: string;
23
+ }
24
+ declare function createContent(nextOptions?: NextOptions): Promise<(nextConfig?: NextConfig) => NextConfig>;
25
+ declare function createStandaloneCore(options: NextOptions): Promise<Core>;
26
+
27
+ export { type NextOptions, createContent, createStandaloneCore };
@@ -0,0 +1,100 @@
1
+ import {
2
+ loadConfig
3
+ } from "../chunk-LUM7SIZN.js";
4
+ import "../chunk-W6HENTK7.js";
5
+ import {
6
+ Core
7
+ } from "../chunk-NRZ4GE5O.js";
8
+ import "../chunk-MT7RY65Y.js";
9
+ import "../chunk-JBZTQ55D.js";
10
+
11
+ // src/next/index.ts
12
+ import * as path from "path";
13
+ async function createContent(nextOptions = {}) {
14
+ const core = createNextCore(applyDefaults(nextOptions));
15
+ await core.init({
16
+ config: loadConfig(core, true)
17
+ });
18
+ if (process.env._FUMADOCS_MDX !== "1") {
19
+ process.env._FUMADOCS_MDX = "1";
20
+ await core.emit({ write: true });
21
+ await init(process.env.NODE_ENV === "development", core);
22
+ }
23
+ return (nextConfig = {}) => {
24
+ const ctx = core.getPluginContext();
25
+ for (const plugin of core.getPlugins(true)) {
26
+ nextConfig = plugin.next?.config?.call(ctx, nextConfig) ?? nextConfig;
27
+ }
28
+ return nextConfig;
29
+ };
30
+ }
31
+ async function init(dev, core) {
32
+ if (!dev) return;
33
+ const { FSWatcher } = await import("chokidar");
34
+ const { configPath, outDir } = core.getOptions();
35
+ const absoluteConfigPath = path.resolve(configPath);
36
+ let watcher;
37
+ async function devServer() {
38
+ if (watcher && !watcher.closed) {
39
+ await watcher.close();
40
+ }
41
+ watcher = new FSWatcher({
42
+ ignoreInitial: true,
43
+ persistent: true,
44
+ ignored: [outDir]
45
+ });
46
+ watcher.add(configPath);
47
+ for (const collection of core.getCollections(true)) {
48
+ const handler = collection.handlers.fs;
49
+ if (handler) {
50
+ watcher.add(handler.dir);
51
+ }
52
+ }
53
+ watcher.once("ready", () => {
54
+ console.log("[MDX] started dev server");
55
+ });
56
+ watcher.on("all", (_event, file) => {
57
+ if (path.resolve(file) === absoluteConfigPath) {
58
+ console.log("[MDX] restarting dev server");
59
+ watcher?.removeAllListeners();
60
+ void (async () => {
61
+ await core.init({
62
+ config: loadConfig(core, true)
63
+ });
64
+ await devServer();
65
+ await core.emit({ write: true });
66
+ })();
67
+ }
68
+ });
69
+ await core.initServer({ watcher });
70
+ }
71
+ process.on("exit", () => {
72
+ if (!watcher || watcher.closed) return;
73
+ console.log("[MDX] closing dev server");
74
+ void watcher.close();
75
+ });
76
+ await devServer();
77
+ }
78
+ async function createStandaloneCore(options) {
79
+ const core = createNextCore(applyDefaults(options));
80
+ await core.init({
81
+ config: loadConfig(core, true)
82
+ });
83
+ return core;
84
+ }
85
+ function applyDefaults(options) {
86
+ return {
87
+ outDir: options.outDir ?? Core.defaultOptions.outDir,
88
+ configPath: options.configPath ?? Core.defaultOptions.configPath
89
+ };
90
+ }
91
+ function createNextCore(options) {
92
+ return new Core({
93
+ outDir: options.outDir,
94
+ configPath: options.configPath
95
+ });
96
+ }
97
+ export {
98
+ createContent,
99
+ createStandaloneCore
100
+ };