fumadocs-mdx 14.0.4 → 14.1.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 (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-CGGDM5F3.js → chunk-257RZJEQ.js} +1 -1
  5. package/dist/{chunk-WBIHDYMN.js → chunk-2PY3JUIC.js} +4 -4
  6. package/dist/{chunk-KOPLIEVQ.js → chunk-7W73RILB.js} +2 -1
  7. package/dist/{chunk-LPX7ZO66.js → chunk-DTFUANSF.js} +1 -1
  8. package/dist/{chunk-K4KWUM3J.js → chunk-KWSETXYC.js} +83 -34
  9. package/dist/{chunk-6RPNS75C.js → chunk-OLD35ARB.js} +43 -31
  10. package/dist/{chunk-ED3ON275.js → chunk-STLEUNK7.js} +87 -82
  11. package/dist/{chunk-USWQVJWR.js → chunk-T6G5VOED.js} +21 -12
  12. package/dist/{chunk-NKIL543T.js → chunk-WSQ23PNV.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-nagEel33.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 +14 -15
  42. package/dist/index-DG1I0CwF.d.ts +0 -8
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  buildMDX
3
- } from "./chunk-KOPLIEVQ.js";
4
- import "./chunk-FBLMK4RS.js";
3
+ } from "./chunk-7W73RILB.js";
4
+ import "./chunk-Y7ISNZ7X.js";
5
5
  import "./chunk-VWJKRQZR.js";
6
6
  export {
7
7
  buildMDX
@@ -1,10 +1,10 @@
1
1
  import { BunPlugin } from 'bun';
2
- import { C as CoreOptions } from '../core-C3QZSdEx.js';
2
+ import { h as CoreOptions } from '../core-nagEel33.js';
3
3
  import '@mdx-js/mdx';
4
4
  import '@standard-schema/spec';
5
5
  import 'unified';
6
6
  import 'fumadocs-core/mdx-plugins';
7
- import 'zod';
7
+ import 'fumadocs-core/source/schema';
8
8
  import 'chokidar';
9
9
  import 'vfile';
10
10
  import 'fumadocs-core/source';
package/dist/bun/index.js CHANGED
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  buildConfig
3
- } from "../chunk-6RPNS75C.js";
3
+ } from "../chunk-OLD35ARB.js";
4
4
  import "../chunk-S7KOJHHO.js";
5
5
  import {
6
6
  createMdxLoader
7
- } from "../chunk-USWQVJWR.js";
7
+ } from "../chunk-T6G5VOED.js";
8
8
  import {
9
9
  createMetaLoader
10
- } from "../chunk-TYJDYTKH.js";
10
+ } from "../chunk-ZAYZWFWP.js";
11
11
  import {
12
12
  createIntegratedConfigLoader,
13
13
  toBun
14
- } from "../chunk-NKIL543T.js";
14
+ } from "../chunk-WSQ23PNV.js";
15
15
  import "../chunk-4JSFLXXT.js";
16
16
  import {
17
17
  _Defaults,
18
18
  createCore
19
- } from "../chunk-K4KWUM3J.js";
20
- import "../chunk-WBIHDYMN.js";
19
+ } from "../chunk-KWSETXYC.js";
20
+ import "../chunk-2PY3JUIC.js";
21
21
  import "../chunk-VWJKRQZR.js";
22
22
 
23
23
  // src/bun/index.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createCore
3
- } from "./chunk-K4KWUM3J.js";
3
+ } from "./chunk-KWSETXYC.js";
4
4
 
5
5
  // src/webpack/index.ts
6
6
  var core;
@@ -65,7 +65,7 @@ function createCodegen({
65
65
  const fullPath = path.join(base, item);
66
66
  const searchParams = new URLSearchParams();
67
67
  for (const [k, v] of Object.entries(query)) {
68
- searchParams.set(k, v);
68
+ if (v !== void 0) searchParams.set(k, v);
69
69
  }
70
70
  const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
71
71
  if (eager) {
@@ -88,10 +88,9 @@ function createCodegen({
88
88
  formatImportPath(file) {
89
89
  const ext = path.extname(file);
90
90
  let filename;
91
- if (ext === ".ts" && jsExtension) {
92
- filename = file.substring(0, file.length - ext.length) + ".js";
93
- } else if (ext === ".ts") {
91
+ if (ext === ".ts") {
94
92
  filename = file.substring(0, file.length - ext.length);
93
+ if (jsExtension) filename += ".js";
95
94
  } else {
96
95
  filename = file;
97
96
  }
@@ -122,5 +121,6 @@ function ident(code, tab = 1) {
122
121
 
123
122
  export {
124
123
  createCodegen,
124
+ slash,
125
125
  ident
126
126
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  flattenNode,
3
3
  remarkInclude
4
- } from "./chunk-FBLMK4RS.js";
4
+ } from "./chunk-Y7ISNZ7X.js";
5
5
 
6
6
  // src/loaders/mdx/build-mdx.ts
7
7
  import { createProcessor } from "@mdx-js/mdx";
@@ -159,6 +159,7 @@ async function buildMDX(core, collection, {
159
159
  let vfile = new VFile({
160
160
  value: source,
161
161
  path: filePath,
162
+ cwd: collection?.cwd,
162
163
  data: { frontmatter, _compiler, _getProcessor: getProcessor }
163
164
  });
164
165
  if (collection) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildConfig
3
- } from "./chunk-6RPNS75C.js";
3
+ } from "./chunk-OLD35ARB.js";
4
4
 
5
5
  // src/config/load-from-file.ts
6
6
  import { pathToFileURL } from "url";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ident
3
- } from "./chunk-WBIHDYMN.js";
3
+ } from "./chunk-2PY3JUIC.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":
@@ -4,46 +4,57 @@ import {
4
4
 
5
5
  // src/config/build.ts
6
6
  import picomatch from "picomatch";
7
+ import path from "path";
7
8
  var SupportedFormats = {
8
9
  doc: ["mdx", "md"],
9
10
  meta: ["json", "yaml"]
10
11
  };
11
- function buildCollection(name, config) {
12
- if (config.type === "docs") {
12
+ function buildCollection(name, collection, cwd) {
13
+ if (collection.type === "docs") {
13
14
  return {
14
- ...config,
15
+ ...collection,
16
+ type: "docs",
17
+ get dir() {
18
+ return this.docs.dir;
19
+ },
15
20
  name,
16
- meta: buildPrimitiveCollection(name, config.meta),
17
- docs: buildPrimitiveCollection(name, config.docs),
21
+ meta: buildCollection(name, collection.meta, cwd),
22
+ docs: buildCollection(name, collection.docs, cwd),
18
23
  hasFile(filePath) {
19
24
  return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
20
- }
25
+ },
26
+ isFileSupported(filePath) {
27
+ return this.docs.isFileSupported(filePath) || this.meta.isFileSupported(filePath);
28
+ },
29
+ cwd
21
30
  };
22
31
  }
23
- return buildPrimitiveCollection(name, config);
32
+ return {
33
+ ...collection,
34
+ ...buildPrimitiveCollection(name, collection, cwd)
35
+ };
24
36
  }
25
- function buildPrimitiveCollection(name, { files, ...config }) {
37
+ function buildPrimitiveCollection(name, config, cwd) {
26
38
  const supportedFormats = SupportedFormats[config.type];
27
- const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
28
- let matchers;
39
+ const patterns = config.files ?? [`**/*.{${supportedFormats.join(",")}}`];
40
+ let matcher;
29
41
  return {
30
- ...config,
42
+ dir: path.resolve(cwd, config.dir),
43
+ cwd,
31
44
  name,
32
45
  patterns,
33
46
  isFileSupported(filePath) {
34
47
  return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
35
48
  },
36
49
  hasFile(filePath) {
37
- matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
38
- (dir) => picomatch(patterns, {
39
- cwd: dir
40
- })
41
- );
42
- return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
50
+ if (!this.isFileSupported(filePath)) return false;
51
+ const relativePath = path.relative(this.dir, filePath);
52
+ if (relativePath.startsWith(`..${path.sep}`)) return false;
53
+ return (matcher ??= picomatch(patterns))(relativePath);
43
54
  }
44
55
  };
45
56
  }
46
- function buildConfig(config) {
57
+ function buildConfig(config, cwd = process.cwd()) {
47
58
  const collections = /* @__PURE__ */ new Map();
48
59
  const loaded = {};
49
60
  for (const [k, v] of Object.entries(config)) {
@@ -51,15 +62,8 @@ function buildConfig(config) {
51
62
  continue;
52
63
  }
53
64
  if (typeof v === "object" && "type" in v) {
54
- if (v.type === "docs") {
55
- collections.set(k, buildCollection(k, v));
56
- continue;
57
- }
58
- if (v.type === "doc" || v.type === "meta") {
59
- collections.set(
60
- k,
61
- buildCollection(k, v)
62
- );
65
+ if (v.type === "docs" || v.type === "doc" || v.type === "meta") {
66
+ collections.set(k, buildCollection(k, v, cwd));
63
67
  continue;
64
68
  }
65
69
  }
@@ -74,10 +78,18 @@ function buildConfig(config) {
74
78
  const mdxOptionsCache = /* @__PURE__ */ new Map();
75
79
  return {
76
80
  global: loaded,
77
- collectionList: Array.from(collections.values()),
78
- getCollection(name) {
79
- return collections.get(name);
80
- },
81
+ collections,
82
+ workspaces: Object.fromEntries(
83
+ Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
84
+ return [
85
+ key,
86
+ {
87
+ dir: value.dir,
88
+ config: buildConfig(value.config, path.resolve(cwd, value.dir))
89
+ }
90
+ ];
91
+ })
92
+ ),
81
93
  getMDXOptions(collection, environment = "bundler") {
82
94
  const key = collection ? `${environment}:${collection.name}` : environment;
83
95
  const cached = mdxOptionsCache.get(key);