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,8 @@
1
1
  import {
2
2
  createCodegen,
3
- ident
4
- } from "./chunk-WBIHDYMN.js";
3
+ ident,
4
+ slash
5
+ } from "./chunk-2PY3JUIC.js";
5
6
  import {
6
7
  fumaMatter
7
8
  } from "./chunk-VWJKRQZR.js";
@@ -11,32 +12,34 @@ import path2 from "path";
11
12
  import { glob } from "tinyglobby";
12
13
 
13
14
  // src/utils/fs-cache.ts
14
- import { LRUCache } from "lru-cache";
15
15
  import fs from "fs/promises";
16
16
  import path from "path";
17
- var map = new LRUCache({
18
- max: 100
19
- });
17
+ var map = /* @__PURE__ */ new Map();
18
+ function createFSCache() {
19
+ return {
20
+ read(file) {
21
+ const fullPath = toFullPath(file);
22
+ const cached = map.get(fullPath);
23
+ if (cached) return cached;
24
+ const read = fs.readFile(fullPath).then((s) => s.toString());
25
+ map.set(fullPath, read);
26
+ return read;
27
+ },
28
+ delete(file) {
29
+ map.delete(toFullPath(file));
30
+ }
31
+ };
32
+ }
20
33
  function toFullPath(file) {
21
34
  if (path.isAbsolute(file)) {
22
35
  return path.relative(process.cwd(), file);
23
36
  }
24
37
  return file;
25
38
  }
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
39
 
38
40
  // src/plugins/index-file.ts
39
41
  import { createHash } from "crypto";
42
+ var indexFileCache = createFSCache();
40
43
  function indexFile(options = {}) {
41
44
  const {
42
45
  target = "default",
@@ -44,7 +47,6 @@ function indexFile(options = {}) {
44
47
  browser = true,
45
48
  dynamic = true
46
49
  } = options;
47
- let config;
48
50
  let dynamicCollections;
49
51
  function isDynamic(collection) {
50
52
  return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
@@ -59,8 +61,8 @@ function indexFile(options = {}) {
59
61
  const indexFilePlugin = plugin["index-file"];
60
62
  if (!indexFilePlugin) continue;
61
63
  indexFilePlugin.serverOptions?.call(ctx, serverOptions);
62
- const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
63
- if (config2) typeConfigs.push(config2);
64
+ const config = indexFilePlugin.generateTypeConfig?.call(ctx);
65
+ if (config) typeConfigs.push(config);
64
66
  }
65
67
  return {
66
68
  serverOptions,
@@ -69,38 +71,38 @@ function indexFile(options = {}) {
69
71
  }
70
72
  return {
71
73
  name: "index-file",
72
- config(v) {
73
- config = v;
74
- dynamicCollections = config.collectionList.filter(isDynamic);
74
+ config() {
75
+ dynamicCollections = this.core.getCollections().filter(isDynamic);
75
76
  },
76
77
  configureServer(server) {
77
78
  if (!server.watcher) return;
78
79
  server.watcher.on("all", async (event, file) => {
79
- removeFileCache(file);
80
+ indexFileCache.delete(file);
80
81
  if (dynamicCollections.length === 0) {
81
82
  if (target === "vite") return;
82
83
  if (target === "default" && event === "change") return;
83
84
  }
84
- const updatedCollection = config.collectionList.find(
85
- (collection) => collection.hasFile(file)
86
- );
85
+ const updatedCollection = this.core.getCollections().find((collection) => collection.hasFile(file));
87
86
  if (!updatedCollection) return;
88
87
  if (!isDynamic(updatedCollection)) {
89
88
  if (target === "vite") return;
90
89
  if (target === "default" && event === "change") return;
91
90
  }
92
- await this.core.emitAndWrite({
93
- filterPlugin: (plugin) => plugin.name === "index-file"
91
+ await this.core.emit({
92
+ filterPlugin: (plugin) => plugin.name === "index-file",
93
+ filterWorkspace: () => false,
94
+ write: true
94
95
  });
95
96
  });
96
97
  },
97
98
  async emit() {
98
99
  const globCache = /* @__PURE__ */ new Map();
100
+ const { workspace, outDir } = this.core.getOptions();
99
101
  const { serverOptions, tc } = generateConfigs(this.core);
100
102
  const toEmitEntry = async (path3, content) => {
101
103
  const codegen = createCodegen({
102
104
  target,
103
- outDir: this.outDir,
105
+ outDir,
104
106
  jsExtension: addJsExtension,
105
107
  globCache
106
108
  });
@@ -108,7 +110,8 @@ function indexFile(options = {}) {
108
110
  core: this.core,
109
111
  codegen,
110
112
  serverOptions,
111
- tc
113
+ tc,
114
+ workspace: workspace?.name
112
115
  });
113
116
  return {
114
117
  path: path3,
@@ -126,12 +129,8 @@ function indexFile(options = {}) {
126
129
  }
127
130
  };
128
131
  }
129
- async function generateServerIndexFile({
130
- core,
131
- codegen,
132
- serverOptions,
133
- tc
134
- }) {
132
+ async function generateServerIndexFile(ctx) {
133
+ const { core, codegen, serverOptions, tc } = ctx;
135
134
  codegen.lines.push(
136
135
  `import { server } from 'fumadocs-mdx/runtime/server';`,
137
136
  `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
@@ -139,51 +138,48 @@ async function generateServerIndexFile({
139
138
  `const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
140
139
  );
141
140
  async function generateCollectionObject(collection) {
141
+ const base = getBase(collection);
142
142
  switch (collection.type) {
143
143
  case "docs": {
144
144
  if (collection.docs.dynamic) return;
145
145
  if (collection.docs.async) {
146
146
  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)
147
+ generateMetaCollectionGlob(ctx, collection.meta, true),
148
+ generateDocCollectionFrontmatterGlob(ctx, collection.docs, true),
149
+ generateDocCollectionGlob(ctx, collection.docs)
154
150
  ]);
155
- return `await create.docsLazy("${collection.name}", "${collection.dir}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
151
+ return `await create.docsLazy("${collection.name}", "${base}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
156
152
  }
157
153
  const [metaGlob, docGlob] = await Promise.all([
158
- generateMetaCollectionGlob(codegen, collection.meta, true),
159
- generateDocCollectionGlob(codegen, collection.docs, true)
154
+ generateMetaCollectionGlob(ctx, collection.meta, true),
155
+ generateDocCollectionGlob(ctx, collection.docs, true)
160
156
  ]);
161
- return `await create.docs("${collection.name}", "${collection.dir}", ${metaGlob}, ${docGlob})`;
157
+ return `await create.docs("${collection.name}", "${base}", ${metaGlob}, ${docGlob})`;
162
158
  }
163
159
  case "doc":
164
160
  if (collection.dynamic) return;
165
161
  if (collection.async) {
166
162
  const [headGlob, bodyGlob] = await Promise.all([
167
- generateDocCollectionFrontmatterGlob(codegen, collection, true),
168
- generateDocCollectionGlob(codegen, collection)
163
+ generateDocCollectionFrontmatterGlob(ctx, collection, true),
164
+ generateDocCollectionGlob(ctx, collection)
169
165
  ]);
170
- return `await create.docLazy("${collection.name}", "${collection.dir}", ${headGlob}, ${bodyGlob})`;
166
+ return `await create.docLazy("${collection.name}", "${base}", ${headGlob}, ${bodyGlob})`;
171
167
  }
172
- return `await create.doc("${collection.name}", "${collection.dir}", ${await generateDocCollectionGlob(
173
- codegen,
168
+ return `await create.doc("${collection.name}", "${base}", ${await generateDocCollectionGlob(
169
+ ctx,
174
170
  collection,
175
171
  true
176
172
  )})`;
177
173
  case "meta":
178
- return `await create.meta("${collection.name}", "${collection.dir}", ${await generateMetaCollectionGlob(
179
- codegen,
174
+ return `await create.meta("${collection.name}", "${base}", ${await generateMetaCollectionGlob(
175
+ ctx,
180
176
  collection,
181
177
  true
182
178
  )})`;
183
179
  }
184
180
  }
185
181
  await codegen.pushAsync(
186
- core.getConfig().collectionList.map(async (collection) => {
182
+ core.getCollections().map(async (collection) => {
187
183
  const obj = await generateCollectionObject(collection);
188
184
  if (!obj) return;
189
185
  return `
@@ -191,22 +187,23 @@ export const ${collection.name} = ${obj};`;
191
187
  })
192
188
  );
193
189
  }
194
- async function generateDynamicIndexFile({
195
- core,
196
- codegen,
197
- serverOptions,
198
- tc
199
- }) {
200
- const { configPath } = core.getOptions();
190
+ async function generateDynamicIndexFile(ctx) {
191
+ const { core, codegen, serverOptions, tc } = ctx;
192
+ const { configPath, environment, outDir } = core.getOptions();
193
+ const partialOptions = {
194
+ configPath,
195
+ environment,
196
+ outDir
197
+ };
201
198
  codegen.lines.push(
202
199
  `import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
203
200
  `import * as Config from '${codegen.formatImportPath(configPath)}';`,
204
201
  "",
205
- `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
202
+ `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(partialOptions)}, ${JSON.stringify(serverOptions)});`
206
203
  );
207
- async function generateCollectionObjectEntry(collection, file) {
208
- const fullPath = path2.join(collection.dir, file);
209
- const content = await readFileWithCache(fullPath).catch(() => "");
204
+ async function generateCollectionObjectEntry(collection, absolutePath) {
205
+ const fullPath = path2.relative(process.cwd(), absolutePath);
206
+ const content = await indexFileCache.read(fullPath).catch(() => "");
210
207
  const parsed = fumaMatter(content);
211
208
  const data = await core.transformFrontmatter(
212
209
  {
@@ -224,7 +221,7 @@ async function generateDynamicIndexFile({
224
221
  for (const [k, v] of Object.entries({
225
222
  info: {
226
223
  fullPath,
227
- path: file
224
+ path: path2.relative(collection.dir, absolutePath)
228
225
  },
229
226
  data,
230
227
  hash
@@ -239,7 +236,8 @@ async function generateDynamicIndexFile({
239
236
  else if (parent.type === "docs") collection = parent.docs;
240
237
  if (!collection || !collection.dynamic) return;
241
238
  const files = await glob(collection.patterns, {
242
- cwd: collection.dir
239
+ cwd: collection.dir,
240
+ absolute: true
243
241
  });
244
242
  const entries = await Promise.all(
245
243
  files.map((file) => generateCollectionObjectEntry(collection, file))
@@ -247,18 +245,18 @@ async function generateDynamicIndexFile({
247
245
  switch (parent.type) {
248
246
  case "docs": {
249
247
  const metaGlob = await generateMetaCollectionGlob(
250
- codegen,
248
+ ctx,
251
249
  parent.meta,
252
250
  true
253
251
  );
254
- return `await create.docs("${parent.name}", "${parent.dir}", ${metaGlob}, ${entries.join(", ")})`;
252
+ return `await create.docs("${parent.name}", "${getBase(parent)}", ${metaGlob}, ${entries.join(", ")})`;
255
253
  }
256
254
  case "doc":
257
- return `await create.doc("${collection.name}", "${collection.dir}", ${entries.join(", ")})`;
255
+ return `await create.doc("${collection.name}", "${getBase(collection)}", ${entries.join(", ")})`;
258
256
  }
259
257
  }
260
258
  await codegen.pushAsync(
261
- core.getConfig().collectionList.map(async (collection) => {
259
+ core.getCollections().map(async (collection) => {
262
260
  const obj = await generateCollectionObject(collection);
263
261
  if (!obj) return;
264
262
  return `
@@ -266,7 +264,8 @@ export const ${collection.name} = ${obj};`;
266
264
  })
267
265
  );
268
266
  }
269
- async function generateBrowserIndexFile({ core, codegen, tc }) {
267
+ async function generateBrowserIndexFile(ctx) {
268
+ const { core, codegen, tc } = ctx;
270
269
  codegen.lines.push(
271
270
  `import { browser } from 'fumadocs-mdx/runtime/browser';`,
272
271
  `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
@@ -281,12 +280,12 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
281
280
  }
282
281
  case "doc":
283
282
  if (collection.dynamic) return;
284
- return `create.doc("${collection.name}", ${await generateDocCollectionGlob(codegen, collection)})`;
283
+ return `create.doc("${collection.name}", ${await generateDocCollectionGlob(ctx, collection)})`;
285
284
  }
286
285
  }
287
286
  codegen.lines.push("const browserCollections = {");
288
287
  await codegen.pushAsync(
289
- core.getConfig().collectionList.map(async (collection) => {
288
+ core.getCollections().map(async (collection) => {
290
289
  const obj = await generateCollectionObject(collection);
291
290
  if (!obj) return;
292
291
  return ident(`${collection.name}: ${obj},`);
@@ -294,30 +293,36 @@ async function generateBrowserIndexFile({ core, codegen, tc }) {
294
293
  );
295
294
  codegen.lines.push("};", "export default browserCollections;");
296
295
  }
297
- function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
296
+ function getBase(collection) {
297
+ return slash(path2.relative(process.cwd(), collection.dir));
298
+ }
299
+ function generateDocCollectionFrontmatterGlob({ codegen, workspace }, collection, eager = false) {
298
300
  return codegen.generateGlobImport(collection.patterns, {
299
301
  query: {
300
302
  collection: collection.name,
301
- only: "frontmatter"
303
+ only: "frontmatter",
304
+ workspace
302
305
  },
303
306
  import: "frontmatter",
304
307
  base: collection.dir,
305
308
  eager
306
309
  });
307
310
  }
308
- function generateDocCollectionGlob(codegen, collection, eager = false) {
311
+ function generateDocCollectionGlob({ codegen, workspace }, collection, eager = false) {
309
312
  return codegen.generateGlobImport(collection.patterns, {
310
313
  query: {
311
- collection: collection.name
314
+ collection: collection.name,
315
+ workspace
312
316
  },
313
317
  base: collection.dir,
314
318
  eager
315
319
  });
316
320
  }
317
- function generateMetaCollectionGlob(codegen, collection, eager = false) {
321
+ function generateMetaCollectionGlob({ codegen, workspace }, collection, eager = false) {
318
322
  return codegen.generateGlobImport(collection.patterns, {
319
323
  query: {
320
- collection: collection.name
324
+ collection: collection.name,
325
+ workspace
321
326
  },
322
327
  import: "default",
323
328
  base: collection.dir,
@@ -12,14 +12,15 @@ import path from "path";
12
12
  import { createHash } from "crypto";
13
13
  var querySchema = z.object({
14
14
  only: z.literal(["frontmatter", "all"]).default("all"),
15
- collection: z.string().optional()
15
+ collection: z.string().optional(),
16
+ workspace: z.string().optional()
16
17
  }).loose();
17
18
  var cacheEntry = z.object({
18
19
  code: z.string(),
19
20
  map: z.any().optional(),
20
21
  hash: z.string().optional()
21
22
  });
22
- function createMdxLoader(configLoader) {
23
+ function createMdxLoader({ getCore }) {
23
24
  return {
24
25
  test: mdxLoaderGlob,
25
26
  async load({
@@ -29,14 +30,22 @@ function createMdxLoader(configLoader) {
29
30
  compiler,
30
31
  filePath
31
32
  }) {
32
- const config = await configLoader.getConfig();
33
+ let core = await getCore();
33
34
  const value = await getSource();
34
35
  const matter = fumaMatter(value);
35
- const parsed = querySchema.parse(query);
36
+ const {
37
+ collection: collectionName,
38
+ workspace,
39
+ only
40
+ } = querySchema.parse(query);
41
+ if (workspace) {
42
+ core = core.getWorkspaces().get(workspace) ?? core;
43
+ }
36
44
  let after;
37
- if (!isDevelopment && config.global.experimentalBuildCache) {
38
- const cacheDir = config.global.experimentalBuildCache;
39
- const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
45
+ const { experimentalBuildCache = false } = core.getConfig().global;
46
+ if (!isDevelopment && experimentalBuildCache) {
47
+ const cacheDir = experimentalBuildCache;
48
+ const cacheKey = `${collectionName ?? "global"}_${generateCacheHash(filePath)}`;
40
49
  const cached = await fs.readFile(path.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
41
50
  if (cached && cached.hash === generateCacheHash(value)) return cached;
42
51
  after = async () => {
@@ -50,7 +59,7 @@ function createMdxLoader(configLoader) {
50
59
  );
51
60
  };
52
61
  }
53
- const collection = parsed.collection ? config.getCollection(parsed.collection) : void 0;
62
+ const collection = collectionName ? core.getCollection(collectionName) : void 0;
54
63
  let docCollection;
55
64
  switch (collection?.type) {
56
65
  case "doc":
@@ -61,20 +70,20 @@ function createMdxLoader(configLoader) {
61
70
  break;
62
71
  }
63
72
  if (docCollection) {
64
- matter.data = await configLoader.core.transformFrontmatter(
73
+ matter.data = await core.transformFrontmatter(
65
74
  { collection: docCollection, filePath, source: value },
66
75
  matter.data
67
76
  );
68
77
  }
69
- if (parsed.only === "frontmatter") {
78
+ if (only === "frontmatter") {
70
79
  return {
71
80
  code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
72
81
  map: null
73
82
  };
74
83
  }
75
84
  const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
76
- const { buildMDX } = await import("./build-mdx-W3233QBZ.js");
77
- const compiled = await buildMDX(configLoader.core, docCollection, {
85
+ const { buildMDX } = await import("./build-mdx-RXJZQXGA.js");
86
+ const compiled = await buildMDX(core, docCollection, {
78
87
  isDevelopment,
79
88
  source: "\n".repeat(lineOffset) + matter.content,
80
89
  filePath,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ValidationError
3
- } from "./chunk-K4KWUM3J.js";
3
+ } from "./chunk-KWSETXYC.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, C as CollectionSchema, e as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, f as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, g as applyMdxPreset, d as defineCollections, c as defineConfig, b as defineDocs } from '../core-nagEel33.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';