fumadocs-mdx 14.0.4 → 14.1.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.
Files changed (42) hide show
  1. package/dist/{build-mdx-W3233QBZ.js → build-mdx-RXJZQXGA.js} +2 -2
  2. package/dist/bun/index.d.ts +2 -2
  3. package/dist/bun/index.js +6 -6
  4. package/dist/{chunk-KOPLIEVQ.js → chunk-7W73RILB.js} +2 -1
  5. package/dist/{chunk-LPX7ZO66.js → chunk-DTFUANSF.js} +1 -1
  6. package/dist/{chunk-CGGDM5F3.js → chunk-K7N6GD4M.js} +1 -1
  7. package/dist/{chunk-6RPNS75C.js → chunk-OLD35ARB.js} +43 -31
  8. package/dist/{chunk-WBIHDYMN.js → chunk-PW2AZGGD.js} +3 -4
  9. package/dist/{chunk-USWQVJWR.js → chunk-T6G5VOED.js} +21 -12
  10. package/dist/{chunk-ED3ON275.js → chunk-VITVHHR6.js} +85 -81
  11. package/dist/{chunk-K4KWUM3J.js → chunk-VKSHE52K.js} +83 -34
  12. package/dist/{chunk-NKIL543T.js → chunk-WAAWFNDX.js} +18 -20
  13. package/dist/{chunk-FBLMK4RS.js → chunk-Y7ISNZ7X.js} +22 -16
  14. package/dist/{chunk-TYJDYTKH.js → chunk-ZAYZWFWP.js} +10 -6
  15. package/dist/config/index.d.ts +2 -2
  16. package/dist/config/index.js +6 -5
  17. package/dist/{core-C3QZSdEx.d.ts → core-X5ggQtBM.d.ts} +50 -41
  18. package/dist/index-BqkSNsGO.d.ts +8 -0
  19. package/dist/index.d.ts +2 -2
  20. package/dist/{load-from-file-OZ5N7DXU.js → load-from-file-FHW724YY.js} +2 -2
  21. package/dist/next/index.cjs +251 -201
  22. package/dist/next/index.d.ts +2 -2
  23. package/dist/next/index.js +21 -36
  24. package/dist/node/loader.js +5 -5
  25. package/dist/plugins/index-file.d.ts +2 -2
  26. package/dist/plugins/index-file.js +2 -2
  27. package/dist/plugins/json-schema.d.ts +2 -2
  28. package/dist/plugins/json-schema.js +4 -7
  29. package/dist/plugins/last-modified.d.ts +2 -2
  30. package/dist/plugins/last-modified.js +20 -13
  31. package/dist/runtime/browser.d.ts +2 -2
  32. package/dist/runtime/dynamic.d.ts +2 -2
  33. package/dist/runtime/dynamic.js +6 -6
  34. package/dist/runtime/server.d.ts +2 -2
  35. package/dist/vite/index.d.ts +2 -2
  36. package/dist/vite/index.js +16 -18
  37. package/dist/webpack/mdx.d.ts +1 -15
  38. package/dist/webpack/mdx.js +5 -5
  39. package/dist/webpack/meta.d.ts +1 -15
  40. package/dist/webpack/meta.js +5 -5
  41. package/package.json +12 -13
  42. package/dist/index-DG1I0CwF.d.ts +0 -8
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ident
3
- } from "./chunk-WBIHDYMN.js";
3
+ } from "./chunk-PW2AZGGD.js";
4
4
 
5
5
  // src/utils/validation.ts
6
6
  var ValidationError = class extends Error {
@@ -57,9 +57,10 @@ async function getPlugins(pluginOptions) {
57
57
  }
58
58
  return plugins;
59
59
  }
60
- function createCore(options, defaultPlugins = []) {
60
+ function createCore(options) {
61
61
  let config;
62
62
  let plugins;
63
+ const workspaces = /* @__PURE__ */ new Map();
63
64
  async function transformMetadata({
64
65
  collection,
65
66
  filePath,
@@ -75,7 +76,7 @@ function createCore(options, defaultPlugins = []) {
75
76
  }
76
77
  return data;
77
78
  }
78
- const core = {
79
+ return {
79
80
  /**
80
81
  * Convenient cache store, reset when config changes
81
82
  */
@@ -83,15 +84,36 @@ function createCore(options, defaultPlugins = []) {
83
84
  async init({ config: newConfig }) {
84
85
  config = await newConfig;
85
86
  this.cache.clear();
87
+ workspaces.clear();
86
88
  plugins = await getPlugins([
87
89
  postprocessPlugin(),
88
- ...defaultPlugins,
89
- ...config.global.plugins ?? []
90
+ options.plugins,
91
+ config.global.plugins
90
92
  ]);
91
93
  for (const plugin of plugins) {
92
- const out = await plugin.config?.call(pluginContext, config);
94
+ const out = await plugin.config?.call(this.getPluginContext(), config);
93
95
  if (out) config = out;
94
96
  }
97
+ if (!options.workspace) {
98
+ await Promise.all(
99
+ Object.entries(config.workspaces).map(async ([name, workspace]) => {
100
+ const core = createCore({
101
+ ...options,
102
+ outDir: path.join(options.outDir, name),
103
+ workspace: {
104
+ name,
105
+ parent: this,
106
+ dir: workspace.dir
107
+ }
108
+ });
109
+ await core.init({ config: workspace.config });
110
+ workspaces.set(name, core);
111
+ })
112
+ );
113
+ }
114
+ },
115
+ getWorkspaces() {
116
+ return workspaces;
95
117
  },
96
118
  getOptions() {
97
119
  return options;
@@ -108,37 +130,69 @@ function createCore(options, defaultPlugins = []) {
108
130
  getPlugins() {
109
131
  return plugins;
110
132
  },
133
+ getCollections() {
134
+ return Array.from(config.collections.values());
135
+ },
136
+ getCollection(name) {
137
+ return config.collections.get(name);
138
+ },
111
139
  getPluginContext() {
112
- return pluginContext;
140
+ return {
141
+ core: this
142
+ };
113
143
  },
114
144
  async initServer(server) {
145
+ const ctx = this.getPluginContext();
115
146
  for (const plugin of plugins) {
116
- await plugin.configureServer?.call(pluginContext, server);
147
+ await plugin.configureServer?.call(ctx, server);
148
+ }
149
+ for (const workspace of workspaces.values()) {
150
+ await workspace.initServer(server);
117
151
  }
118
152
  },
119
- async emit({ filterPlugin = () => true } = {}) {
120
- return (await Promise.all(
121
- plugins.map((plugin) => {
122
- if (!filterPlugin(plugin) || !plugin.emit) return [];
123
- return plugin.emit.call(pluginContext);
124
- })
125
- )).flat();
126
- },
127
- async emitAndWrite(emitOptions) {
153
+ async emit(emitOptions = {}) {
154
+ const { filterPlugin, filterWorkspace, write = false } = emitOptions;
128
155
  const start = performance.now();
129
- const out = await this.emit(emitOptions);
130
- await Promise.all(
131
- out.map(async (entry) => {
132
- const file = path.join(options.outDir, entry.path);
133
- await fs.mkdir(path.dirname(file), { recursive: true });
134
- await fs.writeFile(file, entry.content);
156
+ const ctx = this.getPluginContext();
157
+ const added = /* @__PURE__ */ new Set();
158
+ const out = {
159
+ entries: [],
160
+ workspaces: {}
161
+ };
162
+ for (const li of await Promise.all(
163
+ plugins.map((plugin) => {
164
+ if (filterPlugin && !filterPlugin(plugin) || !plugin.emit) return;
165
+ return plugin.emit.call(ctx);
135
166
  })
136
- );
137
- console.log(`[MDX] generated files in ${performance.now() - start}ms`);
167
+ )) {
168
+ if (!li) continue;
169
+ for (const item of li) {
170
+ if (added.has(item.path)) continue;
171
+ out.entries.push(item);
172
+ added.add(item.path);
173
+ }
174
+ }
175
+ if (write) {
176
+ await Promise.all(
177
+ out.entries.map(async (entry) => {
178
+ const file = path.join(options.outDir, entry.path);
179
+ await fs.mkdir(path.dirname(file), { recursive: true });
180
+ await fs.writeFile(file, entry.content);
181
+ })
182
+ );
183
+ console.log(
184
+ options.workspace ? `[MDX: ${options.workspace.name}] generated files in ${performance.now() - start}ms` : `[MDX] generated files in ${performance.now() - start}ms`
185
+ );
186
+ }
187
+ for (const [name, workspace] of workspaces) {
188
+ if (filterWorkspace && !filterWorkspace(name)) continue;
189
+ out.workspaces[name] = (await workspace.emit(emitOptions)).entries;
190
+ }
191
+ return out;
138
192
  },
139
193
  async transformMeta(options2, data) {
140
194
  const ctx = {
141
- ...pluginContext,
195
+ ...this.getPluginContext(),
142
196
  ...options2
143
197
  };
144
198
  data = await transformMetadata(options2, data);
@@ -150,7 +204,7 @@ function createCore(options, defaultPlugins = []) {
150
204
  },
151
205
  async transformFrontmatter(options2, data) {
152
206
  const ctx = {
153
- ...pluginContext,
207
+ ...this.getPluginContext(),
154
208
  ...options2
155
209
  };
156
210
  data = await transformMetadata(options2, data);
@@ -162,7 +216,7 @@ function createCore(options, defaultPlugins = []) {
162
216
  },
163
217
  async transformVFile(options2, file) {
164
218
  const ctx = {
165
- ...pluginContext,
219
+ ...this.getPluginContext(),
166
220
  ...options2
167
221
  };
168
222
  for (const plugin of plugins) {
@@ -172,11 +226,6 @@ function createCore(options, defaultPlugins = []) {
172
226
  return file;
173
227
  }
174
228
  };
175
- const pluginContext = {
176
- core,
177
- ...options
178
- };
179
- return core;
180
229
  }
181
230
  function postprocessPlugin() {
182
231
  const LinkReferenceTypes = `{
@@ -191,7 +240,7 @@ function postprocessPlugin() {
191
240
  const lines = [];
192
241
  lines.push("{");
193
242
  lines.push(" DocData: {");
194
- for (const collection of this.core.getConfig().collectionList) {
243
+ for (const collection of this.core.getCollections()) {
195
244
  let postprocessOptions;
196
245
  switch (collection.type) {
197
246
  case "doc":
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ValidationError
3
- } from "./chunk-K4KWUM3J.js";
3
+ } from "./chunk-VKSHE52K.js";
4
4
 
5
5
  // src/loaders/adapter.ts
6
6
  import { fileURLToPath } from "url";
@@ -134,7 +134,7 @@ function createStandaloneConfigLoader({
134
134
  buildConfig,
135
135
  mode
136
136
  }) {
137
- let loaded;
137
+ let prev;
138
138
  async function getConfigHash() {
139
139
  if (mode === "production") return "static";
140
140
  const stats = await fs2.stat(core.getOptions().configPath).catch(() => {
@@ -142,31 +142,29 @@ function createStandaloneConfigLoader({
142
142
  });
143
143
  return stats.mtime.getTime().toString();
144
144
  }
145
- async function newConfig() {
146
- const { loadConfig } = await import("./load-from-file-OZ5N7DXU.js");
147
- await core.init({
148
- config: loadConfig(core, buildConfig)
149
- });
150
- return core.getConfig();
151
- }
152
145
  return {
153
- core,
154
- async getConfig() {
146
+ async getCore() {
155
147
  const hash = await getConfigHash();
156
- if (loaded && loaded.hash === hash) return loaded.config;
157
- loaded = {
158
- hash,
159
- config: newConfig()
160
- };
161
- return loaded.config;
148
+ if (!prev || hash !== prev.hash) {
149
+ prev = {
150
+ hash,
151
+ init: (async () => {
152
+ const { loadConfig } = await import("./load-from-file-FHW724YY.js");
153
+ await core.init({
154
+ config: loadConfig(core, buildConfig)
155
+ });
156
+ })()
157
+ };
158
+ }
159
+ await prev.init;
160
+ return core;
162
161
  }
163
162
  };
164
163
  }
165
164
  function createIntegratedConfigLoader(core) {
166
165
  return {
167
- core,
168
- getConfig() {
169
- return core.getConfig();
166
+ async getCore() {
167
+ return core;
170
168
  }
171
169
  };
172
170
  }
@@ -8,6 +8,7 @@ import { visit as visit2 } from "unist-util-visit";
8
8
  import * as path from "path";
9
9
  import * as fs from "fs/promises";
10
10
  import { remarkHeading } from "fumadocs-core/mdx-plugins";
11
+ import { VFile } from "vfile";
11
12
 
12
13
  // src/loaders/mdx/remark-unravel.ts
13
14
  import { visit } from "unist-util-visit";
@@ -127,19 +128,20 @@ function extractSection(root, section) {
127
128
  }
128
129
  function remarkInclude() {
129
130
  const TagName = "include";
130
- const embedContent = async (file, heading, params, data) => {
131
+ const embedContent = async (targetPath, heading, params, parent) => {
132
+ const { _getProcessor = () => this, _compiler } = parent.data;
131
133
  let content;
132
134
  try {
133
- content = (await fs.readFile(file)).toString();
135
+ content = (await fs.readFile(targetPath)).toString();
134
136
  } catch (e) {
135
137
  throw new Error(
136
- `failed to read file ${file}
138
+ `failed to read file ${targetPath}
137
139
  ${e instanceof Error ? e.message : String(e)}`,
138
140
  { cause: e }
139
141
  );
140
142
  }
141
- const ext = path.extname(file);
142
- data._compiler?.addDependency(file);
143
+ const ext = path.extname(targetPath);
144
+ _compiler?.addDependency(targetPath);
143
145
  if (params.lang || ext !== ".md" && ext !== ".mdx") {
144
146
  const lang = params.lang ?? ext.slice(1);
145
147
  return {
@@ -150,13 +152,17 @@ ${e instanceof Error ? e.message : String(e)}`,
150
152
  data: {}
151
153
  };
152
154
  }
153
- const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
155
+ const parser = _getProcessor(ext === ".mdx" ? "mdx" : "md");
154
156
  const parsed = fumaMatter(content);
155
- let mdast = parser.parse({
156
- path: file,
157
+ const targetFile = new VFile({
158
+ path: targetPath,
157
159
  value: parsed.content,
158
- data: { frontmatter: parsed.data }
160
+ data: {
161
+ ...parent.data,
162
+ frontmatter: parsed.data
163
+ }
159
164
  });
165
+ let mdast = parser.parse(targetFile);
160
166
  const baseProcessor = unified().use(remarkMarkAndUnravel);
161
167
  if (heading) {
162
168
  const extracted = extractSection(
@@ -165,16 +171,16 @@ ${e instanceof Error ? e.message : String(e)}`,
165
171
  );
166
172
  if (!extracted)
167
173
  throw new Error(
168
- `Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
174
+ `Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
169
175
  );
170
176
  mdast = extracted;
171
177
  } else {
172
178
  mdast = await baseProcessor.run(mdast);
173
179
  }
174
- await update(mdast, path.dirname(file), data);
180
+ await update(mdast, targetFile);
175
181
  return mdast;
176
182
  };
177
- async function update(tree, directory, data) {
183
+ async function update(tree, file) {
178
184
  const queue = [];
179
185
  visit2(tree, ElementLikeTypes, (_node, _, parent) => {
180
186
  const node = _node;
@@ -183,12 +189,12 @@ ${e instanceof Error ? e.message : String(e)}`,
183
189
  if (specifier.length === 0) return "skip";
184
190
  const attributes = parseElementAttributes(node);
185
191
  const { file: relativePath, section } = parseSpecifier(specifier);
186
- const file = path.resolve(
187
- "cwd" in attributes ? process.cwd() : directory,
192
+ const targetPath = path.resolve(
193
+ "cwd" in attributes ? file.cwd : file.dirname,
188
194
  relativePath
189
195
  );
190
196
  queue.push(
191
- embedContent(file, section, attributes, data).then((replace) => {
197
+ embedContent(targetPath, section, attributes, file).then((replace) => {
192
198
  Object.assign(
193
199
  parent && parent.type === "paragraph" ? parent : node,
194
200
  replace
@@ -200,7 +206,7 @@ ${e instanceof Error ? e.message : String(e)}`,
200
206
  await Promise.all(queue);
201
207
  }
202
208
  return async (tree, file) => {
203
- await update(tree, path.dirname(file.path), file.data);
209
+ await update(tree, file);
204
210
  };
205
211
  }
206
212
 
@@ -6,9 +6,10 @@ import {
6
6
  import { dump, load } from "js-yaml";
7
7
  import { z } from "zod";
8
8
  var querySchema = z.object({
9
- collection: z.string().optional()
9
+ collection: z.string().optional(),
10
+ workspace: z.string().optional()
10
11
  }).loose();
11
- function createMetaLoader(configLoader, resolve = {}) {
12
+ function createMetaLoader({ getCore }, resolve = {}) {
12
13
  const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve;
13
14
  function parse(filePath, source) {
14
15
  try {
@@ -22,10 +23,13 @@ function createMetaLoader(configLoader, resolve = {}) {
22
23
  function onMeta(source, { filePath, query }) {
23
24
  const parsed = querySchema.safeParse(query);
24
25
  if (!parsed.success || !parsed.data.collection) return null;
25
- const collectionName = parsed.data.collection;
26
+ const { collection: collectionName, workspace } = parsed.data;
26
27
  return async () => {
27
- const config = await configLoader.getConfig();
28
- const collection = config.getCollection(collectionName);
28
+ let core = await getCore();
29
+ if (workspace) {
30
+ core = core.getWorkspaces().get(workspace) ?? core;
31
+ }
32
+ const collection = core.getCollection(collectionName);
29
33
  let metaCollection;
30
34
  switch (collection?.type) {
31
35
  case "meta":
@@ -37,7 +41,7 @@ function createMetaLoader(configLoader, resolve = {}) {
37
41
  }
38
42
  const data = parse(filePath, source);
39
43
  if (!metaCollection) return data;
40
- return configLoader.core.transformMeta(
44
+ return core.transformMeta(
41
45
  {
42
46
  collection: metaCollection,
43
47
  filePath,
@@ -1,10 +1,10 @@
1
- export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, f as DefaultMDXOptions, D as DocCollection, b as DocsCollection, G as GlobalConfig, g as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, h as applyMdxPreset, d as defineCollections, e as defineConfig, c as defineDocs, i as frontmatterSchema, m as metaSchema } from '../core-C3QZSdEx.js';
1
+ export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, f as DefaultMDXOptions, D as DocCollection, b as DocsCollection, G as GlobalConfig, g as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, h as applyMdxPreset, d as defineCollections, e as defineConfig, c as defineDocs } from '../core-X5ggQtBM.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
+ export { pageSchema as frontmatterSchema, metaSchema } from 'fumadocs-core/source/schema';
4
5
  import '@mdx-js/mdx';
5
6
  import '@standard-schema/spec';
6
7
  import 'fumadocs-core/mdx-plugins';
7
- import 'zod';
8
8
  import 'chokidar';
9
9
  import 'vfile';
10
10
  import 'fumadocs-core/source';
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  remarkInclude
3
- } from "../chunk-FBLMK4RS.js";
3
+ } from "../chunk-Y7ISNZ7X.js";
4
4
  import {
5
5
  applyMdxPreset
6
6
  } from "../chunk-S7KOJHHO.js";
7
7
  import "../chunk-VWJKRQZR.js";
8
8
 
9
- // src/config/zod-4.ts
9
+ // ../core/dist/source/schema.js
10
10
  import { z } from "zod";
11
11
  var metaSchema = z.object({
12
12
  title: z.string().optional(),
@@ -14,9 +14,10 @@ var metaSchema = z.object({
14
14
  description: z.string().optional(),
15
15
  root: z.boolean().optional(),
16
16
  defaultOpen: z.boolean().optional(),
17
+ collapsible: z.boolean().optional(),
17
18
  icon: z.string().optional()
18
19
  });
19
- var frontmatterSchema = z.object({
20
+ var pageSchema = z.object({
20
21
  title: z.string(),
21
22
  description: z.string().optional(),
22
23
  icon: z.string().optional(),
@@ -37,7 +38,7 @@ function defineDocs(options) {
37
38
  docs: defineCollections({
38
39
  type: "doc",
39
40
  dir,
40
- schema: frontmatterSchema,
41
+ schema: pageSchema,
41
42
  ...options?.docs
42
43
  }),
43
44
  meta: defineCollections({
@@ -56,7 +57,7 @@ export {
56
57
  defineCollections,
57
58
  defineConfig,
58
59
  defineDocs,
59
- frontmatterSchema,
60
+ pageSchema as frontmatterSchema,
60
61
  metaSchema,
61
62
  remarkInclude
62
63
  };
@@ -2,7 +2,7 @@ import { ProcessorOptions } from '@mdx-js/mdx';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Pluggable } from 'unified';
4
4
  import * as Plugins from 'fumadocs-core/mdx-plugins';
5
- import { z } from 'zod';
5
+ import { pageSchema, metaSchema } from 'fumadocs-core/source/schema';
6
6
  import { FSWatcher } from 'chokidar';
7
7
  import { VFile } from 'vfile';
8
8
  import { PageData, MetaData, Source } from 'fumadocs-core/source';
@@ -33,28 +33,6 @@ type MDXPresetOptions = ({
33
33
  */
34
34
  declare function applyMdxPreset(options?: MDXPresetOptions): (environment: BuildEnvironment) => Promise<ProcessorOptions>;
35
35
 
36
- /**
37
- * Zod 4 schema
38
- */
39
- declare const metaSchema: z.ZodObject<{
40
- title: z.ZodOptional<z.ZodString>;
41
- pages: z.ZodOptional<z.ZodArray<z.ZodString>>;
42
- description: z.ZodOptional<z.ZodString>;
43
- root: z.ZodOptional<z.ZodBoolean>;
44
- defaultOpen: z.ZodOptional<z.ZodBoolean>;
45
- icon: z.ZodOptional<z.ZodString>;
46
- }, z.core.$strip>;
47
- /**
48
- * Zod 4 schema
49
- */
50
- declare const frontmatterSchema: z.ZodObject<{
51
- title: z.ZodString;
52
- description: z.ZodOptional<z.ZodString>;
53
- icon: z.ZodOptional<z.ZodString>;
54
- full: z.ZodOptional<z.ZodBoolean>;
55
- _openapi: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
56
- }, z.core.$strip>;
57
-
58
36
  interface ExtractedReference {
59
37
  href: string;
60
38
  }
@@ -128,10 +106,12 @@ interface GlobalConfig {
128
106
  plugins?: PluginOption[];
129
107
  /**
130
108
  * Configure global MDX options
131
- *
132
- * @remarks `MDXPresetOptions`
133
109
  */
134
110
  mdxOptions?: MDXPresetOptions | (() => Promise<MDXPresetOptions>);
111
+ workspaces?: Record<string, {
112
+ dir: string;
113
+ config: Record<string, unknown>;
114
+ }>;
135
115
  /**
136
116
  * specify a directory to access & store cache (disabled during development mode).
137
117
  *
@@ -141,7 +121,7 @@ interface GlobalConfig {
141
121
  }
142
122
  declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: DocCollection<Schema>): DocCollection<Schema>;
143
123
  declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: MetaCollection<Schema>): MetaCollection<Schema>;
144
- declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmatterSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema>(options: {
124
+ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof pageSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema>(options: {
145
125
  /**
146
126
  * The content directory to scan files
147
127
  *
@@ -155,25 +135,31 @@ declare function defineConfig(config?: GlobalConfig): GlobalConfig;
155
135
 
156
136
  type BuildEnvironment = 'bundler' | 'runtime';
157
137
  interface LoadedConfig {
158
- collectionList: CollectionItem[];
159
- getCollection(name: string): CollectionItem | undefined;
138
+ collections: Map<string, CollectionItem>;
160
139
  global: GlobalConfig;
161
140
  getMDXOptions(collection?: DocCollectionItem, environment?: BuildEnvironment): ProcessorOptions | Promise<ProcessorOptions>;
141
+ workspaces: Record<string, {
142
+ dir: string;
143
+ config: LoadedConfig;
144
+ }>;
162
145
  }
163
146
  type CollectionItem = MetaCollectionItem | DocCollectionItem | DocsCollectionItem;
164
- type PrimitiveCollectionItem<T extends DocCollection | MetaCollection> = Omit<T, 'files'> & {
147
+ interface PrimitiveCollectionItem {
165
148
  name: string;
149
+ cwd: string;
150
+ /**
151
+ * content directory (absolute)
152
+ */
153
+ dir: string;
166
154
  hasFile: (filePath: string) => boolean;
167
155
  isFileSupported: (filePath: string) => boolean;
168
156
  patterns: string[];
169
- };
170
- type MetaCollectionItem = PrimitiveCollectionItem<MetaCollection>;
171
- type DocCollectionItem = PrimitiveCollectionItem<DocCollection>;
172
- interface DocsCollectionItem extends DocsCollection {
173
- name: string;
157
+ }
158
+ type MetaCollectionItem = PrimitiveCollectionItem & Omit<MetaCollection, 'files' | 'dir'>;
159
+ type DocCollectionItem = PrimitiveCollectionItem & Omit<DocCollection, 'files' | 'dir'>;
160
+ interface DocsCollectionItem extends Omit<DocsCollection, 'dir' | 'meta' | 'docs'>, Omit<PrimitiveCollectionItem, 'patterns'> {
174
161
  meta: MetaCollectionItem;
175
162
  docs: DocCollectionItem;
176
- hasFile: (filePath: string) => boolean;
177
163
  }
178
164
 
179
165
  type MetaCollectionEntry<Data> = Data & MetaMethods;
@@ -249,7 +235,7 @@ interface EmitEntry {
249
235
  path: string;
250
236
  content: string;
251
237
  }
252
- interface PluginContext extends CoreOptions {
238
+ interface PluginContext {
253
239
  core: Core;
254
240
  }
255
241
  type CompilationContext<Collection> = PluginContext & TransformOptions<Collection>;
@@ -289,7 +275,7 @@ interface Plugin extends IndexFilePlugin {
289
275
  vfile?: (this: CompilationContext<DocCollectionItem>, file: VFile) => Awaitable<VFile | void>;
290
276
  };
291
277
  }
292
- type PluginOption = Awaitable<Plugin | PluginOption[] | false>;
278
+ type PluginOption = Awaitable<Plugin | PluginOption[] | false | undefined>;
293
279
  interface ServerContext {
294
280
  /**
295
281
  * the file watcher, by default all content files are watched, along with other files.
@@ -302,18 +288,39 @@ interface CoreOptions {
302
288
  environment: string;
303
289
  configPath: string;
304
290
  outDir: string;
291
+ plugins?: PluginOption[];
292
+ /**
293
+ * the workspace info if this instance is created as a workspace
294
+ */
295
+ workspace?: {
296
+ parent: Core;
297
+ name: string;
298
+ dir: string;
299
+ };
305
300
  }
306
301
  interface EmitOptions {
307
302
  /**
308
303
  * filter the plugins to run emit
309
304
  */
310
305
  filterPlugin?: (plugin: Plugin) => boolean;
306
+ /**
307
+ * filter the workspaces to run emit
308
+ */
309
+ filterWorkspace?: (workspace: string) => boolean;
310
+ /**
311
+ * write files
312
+ */
313
+ write?: boolean;
314
+ }
315
+ interface EmitOutput {
316
+ entries: EmitEntry[];
317
+ workspaces: Record<string, EmitEntry[]>;
311
318
  }
312
319
  declare const _Defaults: {
313
320
  configPath: string;
314
321
  outDir: string;
315
322
  };
316
- declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[]): {
323
+ declare function createCore(options: CoreOptions): {
317
324
  /**
318
325
  * Convenient cache store, reset when config changes
319
326
  */
@@ -321,6 +328,7 @@ declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[
321
328
  init({ config: newConfig }: {
322
329
  config: Awaitable<LoadedConfig>;
323
330
  }): Promise<void>;
331
+ getWorkspaces(): Map<string, /*elided*/ any>;
324
332
  getOptions(): CoreOptions;
325
333
  getConfig(): LoadedConfig;
326
334
  /**
@@ -328,14 +336,15 @@ declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[
328
336
  */
329
337
  getCompiledConfigPath(): string;
330
338
  getPlugins(): Plugin[];
339
+ getCollections(): CollectionItem[];
340
+ getCollection(name: string): CollectionItem | undefined;
331
341
  getPluginContext(): PluginContext;
332
342
  initServer(server: ServerContext): Promise<void>;
333
- emit({ filterPlugin }?: EmitOptions): Promise<EmitEntry[]>;
334
- emitAndWrite(emitOptions?: EmitOptions): Promise<void>;
343
+ emit(emitOptions?: EmitOptions): Promise<EmitOutput>;
335
344
  transformMeta(options: TransformOptions<MetaCollectionItem>, data: unknown): Promise<unknown>;
336
345
  transformFrontmatter(options: TransformOptions<DocCollectionItem>, data: Record<string, unknown>): Promise<Record<string, unknown>>;
337
346
  transformVFile(options: TransformOptions<DocCollectionItem>, file: VFile): Promise<VFile>;
338
347
  };
339
348
  type Core = ReturnType<typeof createCore>;
340
349
 
341
- export { type AnyCollection as A, type BaseCollection as B, type CoreOptions as C, type DocCollection as D, type ExtractedReference as E, toFumadocsSource as F, type GlobalConfig as G, indexFile as H, type IndexFilePluginOptions as I, type IndexFilePlugin as J, type MetaCollection as M, type PostprocessOptions as P, type ServerOptions as S, type TransformOptions as T, _Defaults as _, type CollectionSchema as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, type DefaultMDXOptions as f, type MDXPresetOptions as g, applyMdxPreset as h, frontmatterSchema as i, type Plugin as j, type AsyncDocCollectionEntry as k, type AsyncDocsCollectionEntry as l, metaSchema as m, type EmitEntry as n, type PluginContext as o, type CompilationContext as p, type PluginOption as q, type ServerContext as r, type EmitOptions as s, createCore as t, type Core as u, type MetaCollectionEntry as v, type DocCollectionEntry as w, type DocsCollectionEntry as x, type ServerCreate as y, server as z };
350
+ export { type AnyCollection as A, type BaseCollection as B, type CoreOptions as C, type DocCollection as D, type ExtractedReference as E, indexFile as F, type GlobalConfig as G, type IndexFilePlugin as H, type IndexFilePluginOptions as I, type MetaCollection as M, type PostprocessOptions as P, type ServerOptions as S, type TransformOptions as T, _Defaults as _, type CollectionSchema as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, type DefaultMDXOptions as f, type MDXPresetOptions as g, applyMdxPreset as h, type Plugin as i, type AsyncDocCollectionEntry as j, type AsyncDocsCollectionEntry as k, type EmitEntry as l, type PluginContext as m, type CompilationContext as n, type PluginOption as o, type ServerContext as p, type EmitOptions as q, type EmitOutput as r, createCore as s, type Core as t, type MetaCollectionEntry as u, type DocCollectionEntry as v, type DocsCollectionEntry as w, type ServerCreate as x, server as y, toFumadocsSource as z };
@@ -0,0 +1,8 @@
1
+ interface WebpackLoaderOptions {
2
+ absoluteCompiledConfigPath: string;
3
+ configPath: string;
4
+ outDir: string;
5
+ isDev: boolean;
6
+ }
7
+
8
+ export type { WebpackLoaderOptions as W };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { p as CompilationContext, u as Core, C as CoreOptions, n as EmitEntry, s as EmitOptions, E as ExtractedReference, j as Plugin, o as PluginContext, q as PluginOption, r as ServerContext, T as TransformOptions, _ as _Defaults, t as createCore } from './core-C3QZSdEx.js';
1
+ export { n as CompilationContext, t as Core, C as CoreOptions, l as EmitEntry, q as EmitOptions, r as EmitOutput, E as ExtractedReference, i as Plugin, m as PluginContext, o as PluginOption, p as ServerContext, T as TransformOptions, _ as _Defaults, s as createCore } from './core-X5ggQtBM.js';
2
2
  import { createProcessor } from '@mdx-js/mdx';
3
3
  import { StructuredData } from 'fumadocs-core/mdx-plugins';
4
4
  import { TOCItemType } from 'fumadocs-core/toc';
@@ -6,7 +6,7 @@ import { FC } from 'react';
6
6
  import { MDXProps } from 'mdx/types';
7
7
  import '@standard-schema/spec';
8
8
  import 'unified';
9
- import 'zod';
9
+ import 'fumadocs-core/source/schema';
10
10
  import 'chokidar';
11
11
  import 'vfile';
12
12
  import 'fumadocs-core/source';