fumadocs-mdx 14.0.3 → 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 +9 -9
  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-Q5OSGLJL.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-DKA3EWZH.js → chunk-VITVHHR6.js} +88 -84
  11. package/dist/{chunk-GB4W3YCZ.js → chunk-VKSHE52K.js} +85 -35
  12. package/dist/{chunk-OLL7FM7W.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 +253 -202
  22. package/dist/next/index.d.ts +2 -2
  23. package/dist/next/index.js +22 -37
  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 +3 -3
  30. package/dist/plugins/last-modified.js +23 -15
  31. package/dist/runtime/browser.d.ts +2 -2
  32. package/dist/runtime/dynamic.d.ts +2 -2
  33. package/dist/runtime/dynamic.js +7 -7
  34. package/dist/runtime/server.d.ts +2 -2
  35. package/dist/vite/index.d.ts +2 -2
  36. package/dist/vite/index.js +19 -21
  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 +13 -14
  42. package/dist/index-DG1I0CwF.d.ts +0 -8
@@ -1,42 +1,44 @@
1
- import {
2
- fumaMatter
3
- } from "./chunk-VWJKRQZR.js";
4
1
  import {
5
2
  createCodegen,
6
3
  ident
7
- } from "./chunk-WBIHDYMN.js";
4
+ } from "./chunk-PW2AZGGD.js";
5
+ import {
6
+ fumaMatter
7
+ } from "./chunk-VWJKRQZR.js";
8
8
 
9
9
  // src/plugins/index-file.ts
10
10
  import path2 from "path";
11
11
  import { glob } from "tinyglobby";
12
12
 
13
13
  // src/utils/fs-cache.ts
14
- import { LRUCache } from "lru-cache";
15
14
  import fs from "fs/promises";
16
15
  import path from "path";
17
- var map = new LRUCache({
18
- max: 100
19
- });
16
+ var map = /* @__PURE__ */ new Map();
17
+ function createFSCache() {
18
+ return {
19
+ read(file) {
20
+ const fullPath = toFullPath(file);
21
+ const cached = map.get(fullPath);
22
+ if (cached) return cached;
23
+ const read = fs.readFile(fullPath).then((s) => s.toString());
24
+ map.set(fullPath, read);
25
+ return read;
26
+ },
27
+ delete(file) {
28
+ map.delete(toFullPath(file));
29
+ }
30
+ };
31
+ }
20
32
  function toFullPath(file) {
21
33
  if (path.isAbsolute(file)) {
22
34
  return path.relative(process.cwd(), file);
23
35
  }
24
36
  return file;
25
37
  }
26
- function readFileWithCache(file) {
27
- const fullPath = toFullPath(file);
28
- const cached = map.get(fullPath);
29
- if (cached) return cached;
30
- const read = fs.readFile(fullPath).then((s) => s.toString());
31
- map.set(fullPath, read);
32
- return read;
33
- }
34
- function removeFileCache(file) {
35
- map.delete(toFullPath(file));
36
- }
37
38
 
38
39
  // src/plugins/index-file.ts
39
40
  import { createHash } from "crypto";
41
+ var indexFileCache = createFSCache();
40
42
  function indexFile(options = {}) {
41
43
  const {
42
44
  target = "default",
@@ -44,7 +46,6 @@ function indexFile(options = {}) {
44
46
  browser = true,
45
47
  dynamic = true
46
48
  } = options;
47
- let config;
48
49
  let dynamicCollections;
49
50
  function isDynamic(collection) {
50
51
  return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
@@ -59,8 +60,8 @@ function indexFile(options = {}) {
59
60
  const indexFilePlugin = plugin["index-file"];
60
61
  if (!indexFilePlugin) continue;
61
62
  indexFilePlugin.serverOptions?.call(ctx, serverOptions);
62
- const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
63
- if (config2) typeConfigs.push(config2);
63
+ const config = indexFilePlugin.generateTypeConfig?.call(ctx);
64
+ if (config) typeConfigs.push(config);
64
65
  }
65
66
  return {
66
67
  serverOptions,
@@ -69,38 +70,38 @@ function indexFile(options = {}) {
69
70
  }
70
71
  return {
71
72
  name: "index-file",
72
- config(v) {
73
- config = v;
74
- dynamicCollections = config.collectionList.filter(isDynamic);
73
+ config() {
74
+ dynamicCollections = this.core.getCollections().filter(isDynamic);
75
75
  },
76
76
  configureServer(server) {
77
77
  if (!server.watcher) return;
78
78
  server.watcher.on("all", async (event, file) => {
79
- removeFileCache(file);
79
+ indexFileCache.delete(file);
80
80
  if (dynamicCollections.length === 0) {
81
81
  if (target === "vite") return;
82
82
  if (target === "default" && event === "change") return;
83
83
  }
84
- const updatedCollection = config.collectionList.find(
85
- (collection) => collection.hasFile(file)
86
- );
84
+ const updatedCollection = this.core.getCollections().find((collection) => collection.hasFile(file));
87
85
  if (!updatedCollection) return;
88
86
  if (!isDynamic(updatedCollection)) {
89
87
  if (target === "vite") return;
90
88
  if (target === "default" && event === "change") return;
91
89
  }
92
- await this.core.emitAndWrite({
93
- filterPlugin: (plugin) => plugin.name === "index-file"
90
+ await this.core.emit({
91
+ filterPlugin: (plugin) => plugin.name === "index-file",
92
+ filterWorkspace: () => false,
93
+ write: true
94
94
  });
95
95
  });
96
96
  },
97
97
  async emit() {
98
98
  const globCache = /* @__PURE__ */ new Map();
99
+ const { workspace, outDir } = this.core.getOptions();
99
100
  const { serverOptions, tc } = generateConfigs(this.core);
100
101
  const toEmitEntry = async (path3, content) => {
101
102
  const codegen = createCodegen({
102
103
  target,
103
- outDir: this.outDir,
104
+ outDir,
104
105
  jsExtension: addJsExtension,
105
106
  globCache
106
107
  });
@@ -108,7 +109,8 @@ function indexFile(options = {}) {
108
109
  core: this.core,
109
110
  codegen,
110
111
  serverOptions,
111
- tc
112
+ tc,
113
+ workspace: workspace?.name
112
114
  });
113
115
  return {
114
116
  path: path3,
@@ -126,12 +128,8 @@ function indexFile(options = {}) {
126
128
  }
127
129
  };
128
130
  }
129
- async function generateServerIndexFile({
130
- core,
131
- codegen,
132
- serverOptions,
133
- tc
134
- }) {
131
+ async function generateServerIndexFile(ctx) {
132
+ const { core, codegen, serverOptions, tc } = ctx;
135
133
  codegen.lines.push(
136
134
  `import { server } from 'fumadocs-mdx/runtime/server';`,
137
135
  `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
@@ -139,51 +137,48 @@ async function generateServerIndexFile({
139
137
  `const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
140
138
  );
141
139
  async function generateCollectionObject(collection) {
140
+ const base = getBase(collection);
142
141
  switch (collection.type) {
143
142
  case "docs": {
144
143
  if (collection.docs.dynamic) return;
145
144
  if (collection.docs.async) {
146
145
  const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
147
- generateMetaCollectionGlob(codegen, collection.meta, true),
148
- generateDocCollectionFrontmatterGlob(
149
- codegen,
150
- collection.docs,
151
- true
152
- ),
153
- generateDocCollectionGlob(codegen, collection.docs)
146
+ generateMetaCollectionGlob(ctx, collection.meta, true),
147
+ generateDocCollectionFrontmatterGlob(ctx, collection.docs, true),
148
+ generateDocCollectionGlob(ctx, collection.docs)
154
149
  ]);
155
- return `await create.docsLazy("${collection.name}", "${collection.dir}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
150
+ return `await create.docsLazy("${collection.name}", "${base}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
156
151
  }
157
152
  const [metaGlob, docGlob] = await Promise.all([
158
- generateMetaCollectionGlob(codegen, collection.meta, true),
159
- generateDocCollectionGlob(codegen, collection.docs, true)
153
+ generateMetaCollectionGlob(ctx, collection.meta, true),
154
+ generateDocCollectionGlob(ctx, collection.docs, true)
160
155
  ]);
161
- return `await create.docs("${collection.name}", "${collection.dir}", ${metaGlob}, ${docGlob})`;
156
+ return `await create.docs("${collection.name}", "${base}", ${metaGlob}, ${docGlob})`;
162
157
  }
163
158
  case "doc":
164
159
  if (collection.dynamic) return;
165
160
  if (collection.async) {
166
161
  const [headGlob, bodyGlob] = await Promise.all([
167
- generateDocCollectionFrontmatterGlob(codegen, collection, true),
168
- generateDocCollectionGlob(codegen, collection)
162
+ generateDocCollectionFrontmatterGlob(ctx, collection, true),
163
+ generateDocCollectionGlob(ctx, collection)
169
164
  ]);
170
- return `await create.docLazy("${collection.name}", "${collection.dir}", ${headGlob}, ${bodyGlob})`;
165
+ return `await create.docLazy("${collection.name}", "${base}", ${headGlob}, ${bodyGlob})`;
171
166
  }
172
- return `await create.doc("${collection.name}", "${collection.dir}", ${await generateDocCollectionGlob(
173
- codegen,
167
+ return `await create.doc("${collection.name}", "${base}", ${await generateDocCollectionGlob(
168
+ ctx,
174
169
  collection,
175
170
  true
176
171
  )})`;
177
172
  case "meta":
178
- return `await create.meta("${collection.name}", "${collection.dir}", ${await generateMetaCollectionGlob(
179
- codegen,
173
+ return `await create.meta("${collection.name}", "${base}", ${await generateMetaCollectionGlob(
174
+ ctx,
180
175
  collection,
181
176
  true
182
177
  )})`;
183
178
  }
184
179
  }
185
180
  await codegen.pushAsync(
186
- core.getConfig().collectionList.map(async (collection) => {
181
+ core.getCollections().map(async (collection) => {
187
182
  const obj = await generateCollectionObject(collection);
188
183
  if (!obj) return;
189
184
  return `
@@ -191,22 +186,23 @@ export const ${collection.name} = ${obj};`;
191
186
  })
192
187
  );
193
188
  }
194
- async function generateDynamicIndexFile({
195
- core,
196
- codegen,
197
- serverOptions,
198
- tc
199
- }) {
200
- const { configPath } = core.getOptions();
189
+ async function generateDynamicIndexFile(ctx) {
190
+ const { core, codegen, serverOptions, tc } = ctx;
191
+ const { configPath, environment, outDir } = core.getOptions();
192
+ const partialOptions = {
193
+ configPath,
194
+ environment,
195
+ outDir
196
+ };
201
197
  codegen.lines.push(
202
198
  `import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
203
199
  `import * as Config from '${codegen.formatImportPath(configPath)}';`,
204
200
  "",
205
- `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
201
+ `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(partialOptions)}, ${JSON.stringify(serverOptions)});`
206
202
  );
207
- async function generateCollectionObjectEntry(collection, file) {
208
- const fullPath = path2.join(collection.dir, file);
209
- const content = await readFileWithCache(fullPath).catch(() => "");
203
+ async function generateCollectionObjectEntry(collection, absolutePath) {
204
+ const fullPath = path2.relative(process.cwd(), absolutePath);
205
+ const content = await indexFileCache.read(fullPath).catch(() => "");
210
206
  const parsed = fumaMatter(content);
211
207
  const data = await core.transformFrontmatter(
212
208
  {
@@ -224,7 +220,7 @@ async function generateDynamicIndexFile({
224
220
  for (const [k, v] of Object.entries({
225
221
  info: {
226
222
  fullPath,
227
- path: file
223
+ path: path2.relative(collection.dir, absolutePath)
228
224
  },
229
225
  data,
230
226
  hash
@@ -239,7 +235,8 @@ async function generateDynamicIndexFile({
239
235
  else if (parent.type === "docs") collection = parent.docs;
240
236
  if (!collection || !collection.dynamic) return;
241
237
  const files = await glob(collection.patterns, {
242
- cwd: collection.dir
238
+ cwd: collection.dir,
239
+ absolute: true
243
240
  });
244
241
  const entries = await Promise.all(
245
242
  files.map((file) => generateCollectionObjectEntry(collection, file))
@@ -247,18 +244,18 @@ async function generateDynamicIndexFile({
247
244
  switch (parent.type) {
248
245
  case "docs": {
249
246
  const metaGlob = await generateMetaCollectionGlob(
250
- codegen,
247
+ ctx,
251
248
  parent.meta,
252
249
  true
253
250
  );
254
- return `await create.docs("${parent.name}", "${parent.dir}", ${metaGlob}, ${entries.join(", ")})`;
251
+ return `await create.docs("${parent.name}", "${getBase(parent)}", ${metaGlob}, ${entries.join(", ")})`;
255
252
  }
256
253
  case "doc":
257
- return `await create.doc("${collection.name}", "${collection.dir}", ${entries.join(", ")})`;
254
+ return `await create.doc("${collection.name}", "${getBase(collection)}", ${entries.join(", ")})`;
258
255
  }
259
256
  }
260
257
  await codegen.pushAsync(
261
- core.getConfig().collectionList.map(async (collection) => {
258
+ core.getCollections().map(async (collection) => {
262
259
  const obj = await generateCollectionObject(collection);
263
260
  if (!obj) return;
264
261
  return `
@@ -266,7 +263,8 @@ export const ${collection.name} = ${obj};`;
266
263
  })
267
264
  );
268
265
  }
269
- async function generateBrowserIndexFile({ core, codegen, tc }) {
266
+ async function generateBrowserIndexFile(ctx) {
267
+ const { core, codegen, tc } = ctx;
270
268
  codegen.lines.push(
271
269
  `import { browser } from 'fumadocs-mdx/runtime/browser';`,
272
270
  `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
@@ -281,12 +279,12 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
281
279
  }
282
280
  case "doc":
283
281
  if (collection.dynamic) return;
284
- return `create.doc("${collection.name}", ${await generateDocCollectionGlob(codegen, collection)})`;
282
+ return `create.doc("${collection.name}", ${await generateDocCollectionGlob(ctx, collection)})`;
285
283
  }
286
284
  }
287
285
  codegen.lines.push("const browserCollections = {");
288
286
  await codegen.pushAsync(
289
- core.getConfig().collectionList.map(async (collection) => {
287
+ core.getCollections().map(async (collection) => {
290
288
  const obj = await generateCollectionObject(collection);
291
289
  if (!obj) return;
292
290
  return ident(`${collection.name}: ${obj},`);
@@ -294,30 +292,36 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
294
292
  );
295
293
  codegen.lines.push("};", "export default browserCollections;");
296
294
  }
297
- function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
295
+ function getBase(collection) {
296
+ return path2.relative(process.cwd(), collection.dir);
297
+ }
298
+ function generateDocCollectionFrontmatterGlob({ codegen, workspace }, collection, eager = false) {
298
299
  return codegen.generateGlobImport(collection.patterns, {
299
300
  query: {
300
301
  collection: collection.name,
301
- only: "frontmatter"
302
+ only: "frontmatter",
303
+ workspace
302
304
  },
303
305
  import: "frontmatter",
304
306
  base: collection.dir,
305
307
  eager
306
308
  });
307
309
  }
308
- function generateDocCollectionGlob(codegen, collection, eager = false) {
310
+ function generateDocCollectionGlob({ codegen, workspace }, collection, eager = false) {
309
311
  return codegen.generateGlobImport(collection.patterns, {
310
312
  query: {
311
- collection: collection.name
313
+ collection: collection.name,
314
+ workspace
312
315
  },
313
316
  base: collection.dir,
314
317
  eager
315
318
  });
316
319
  }
317
- function generateMetaCollectionGlob(codegen, collection, eager = false) {
320
+ function generateMetaCollectionGlob({ codegen, workspace }, collection, eager = false) {
318
321
  return codegen.generateGlobImport(collection.patterns, {
319
322
  query: {
320
- collection: collection.name
323
+ collection: collection.name,
324
+ workspace
321
325
  },
322
326
  import: "default",
323
327
  base: collection.dir,
@@ -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 {
@@ -13,7 +13,8 @@ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
13
13
  this.issues = issues;
14
14
  }
15
15
  async toStringFormatted() {
16
- const picocolors = await import("picocolors");
16
+ const picocolorsModule = await import("picocolors");
17
+ const picocolors = picocolorsModule.default ?? picocolorsModule;
17
18
  return [
18
19
  picocolors.bold(`[MDX] ${this.title}:`),
19
20
  ...this.issues.map(
@@ -56,9 +57,10 @@ async function getPlugins(pluginOptions) {
56
57
  }
57
58
  return plugins;
58
59
  }
59
- function createCore(options, defaultPlugins = []) {
60
+ function createCore(options) {
60
61
  let config;
61
62
  let plugins;
63
+ const workspaces = /* @__PURE__ */ new Map();
62
64
  async function transformMetadata({
63
65
  collection,
64
66
  filePath,
@@ -74,7 +76,7 @@ function createCore(options, defaultPlugins = []) {
74
76
  }
75
77
  return data;
76
78
  }
77
- const core = {
79
+ return {
78
80
  /**
79
81
  * Convenient cache store, reset when config changes
80
82
  */
@@ -82,15 +84,36 @@ function createCore(options, defaultPlugins = []) {
82
84
  async init({ config: newConfig }) {
83
85
  config = await newConfig;
84
86
  this.cache.clear();
87
+ workspaces.clear();
85
88
  plugins = await getPlugins([
86
89
  postprocessPlugin(),
87
- ...defaultPlugins,
88
- ...config.global.plugins ?? []
90
+ options.plugins,
91
+ config.global.plugins
89
92
  ]);
90
93
  for (const plugin of plugins) {
91
- const out = await plugin.config?.call(pluginContext, config);
94
+ const out = await plugin.config?.call(this.getPluginContext(), config);
92
95
  if (out) config = out;
93
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;
94
117
  },
95
118
  getOptions() {
96
119
  return options;
@@ -107,37 +130,69 @@ function createCore(options, defaultPlugins = []) {
107
130
  getPlugins() {
108
131
  return plugins;
109
132
  },
133
+ getCollections() {
134
+ return Array.from(config.collections.values());
135
+ },
136
+ getCollection(name) {
137
+ return config.collections.get(name);
138
+ },
110
139
  getPluginContext() {
111
- return pluginContext;
140
+ return {
141
+ core: this
142
+ };
112
143
  },
113
144
  async initServer(server) {
145
+ const ctx = this.getPluginContext();
114
146
  for (const plugin of plugins) {
115
- 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);
116
151
  }
117
152
  },
118
- async emit({ filterPlugin = () => true } = {}) {
119
- return (await Promise.all(
120
- plugins.map((plugin) => {
121
- if (!filterPlugin(plugin) || !plugin.emit) return [];
122
- return plugin.emit.call(pluginContext);
123
- })
124
- )).flat();
125
- },
126
- async emitAndWrite(emitOptions) {
153
+ async emit(emitOptions = {}) {
154
+ const { filterPlugin, filterWorkspace, write = false } = emitOptions;
127
155
  const start = performance.now();
128
- const out = await this.emit(emitOptions);
129
- await Promise.all(
130
- out.map(async (entry) => {
131
- const file = path.join(options.outDir, entry.path);
132
- await fs.mkdir(path.dirname(file), { recursive: true });
133
- 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);
134
166
  })
135
- );
136
- 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;
137
192
  },
138
193
  async transformMeta(options2, data) {
139
194
  const ctx = {
140
- ...pluginContext,
195
+ ...this.getPluginContext(),
141
196
  ...options2
142
197
  };
143
198
  data = await transformMetadata(options2, data);
@@ -149,7 +204,7 @@ function createCore(options, defaultPlugins = []) {
149
204
  },
150
205
  async transformFrontmatter(options2, data) {
151
206
  const ctx = {
152
- ...pluginContext,
207
+ ...this.getPluginContext(),
153
208
  ...options2
154
209
  };
155
210
  data = await transformMetadata(options2, data);
@@ -161,7 +216,7 @@ function createCore(options, defaultPlugins = []) {
161
216
  },
162
217
  async transformVFile(options2, file) {
163
218
  const ctx = {
164
- ...pluginContext,
219
+ ...this.getPluginContext(),
165
220
  ...options2
166
221
  };
167
222
  for (const plugin of plugins) {
@@ -171,11 +226,6 @@ function createCore(options, defaultPlugins = []) {
171
226
  return file;
172
227
  }
173
228
  };
174
- const pluginContext = {
175
- core,
176
- ...options
177
- };
178
- return core;
179
229
  }
180
230
  function postprocessPlugin() {
181
231
  const LinkReferenceTypes = `{
@@ -190,7 +240,7 @@ function postprocessPlugin() {
190
240
  const lines = [];
191
241
  lines.push("{");
192
242
  lines.push(" DocData: {");
193
- for (const collection of this.core.getConfig().collectionList) {
243
+ for (const collection of this.core.getCollections()) {
194
244
  let postprocessOptions;
195
245
  switch (collection.type) {
196
246
  case "doc":
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ValidationError
3
- } from "./chunk-GB4W3YCZ.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
  }