fumadocs-mdx 13.0.2 → 13.0.4
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.
- package/dist/bin.cjs +381 -279
- package/dist/{build-mdx-D-r3_eQL.d.cts → build-mdx-BjXOmv0b.d.cts} +1 -1
- package/dist/{build-mdx-CCNr86q6.d.ts → build-mdx-CY5UldCO.d.ts} +1 -1
- package/dist/bun/index.cjs +177 -57
- package/dist/bun/index.d.cts +2 -2
- package/dist/bun/index.d.ts +2 -2
- package/dist/bun/index.js +26 -34
- package/dist/chunk-2HXTGJBI.js +101 -0
- package/dist/chunk-4JSFLXXT.js +8 -0
- package/dist/{chunk-JVZFH6ND.js → chunk-QXHN25N3.js} +2 -2
- package/dist/{chunk-EELYB2XC.js → chunk-TZ5EQBFW.js} +9 -103
- package/dist/chunk-VUEZTR2H.js +26 -0
- package/dist/{chunk-XQ5O7IPO.js → chunk-XYGORKQA.js} +5 -3
- package/dist/chunk-YAIPHUCZ.js +56 -0
- package/dist/chunk-ZNVPB2IR.js +170 -0
- package/dist/config/index.d.cts +2 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/{core-B6j6Fxse.d.cts → core-DB7TdlyC.d.cts} +23 -7
- package/dist/{core-B6j6Fxse.d.ts → core-DB7TdlyC.d.ts} +23 -7
- package/dist/index-D7s7kCc2.d.cts +7 -0
- package/dist/index-D7s7kCc2.d.ts +7 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/load-from-file-AVYOFOI7.js +7 -0
- package/dist/next/index.cjs +147 -142
- package/dist/next/index.js +58 -39
- package/dist/node/loader.cjs +242 -128
- package/dist/node/loader.d.cts +2 -2
- package/dist/node/loader.d.ts +2 -2
- package/dist/node/loader.js +29 -16
- package/dist/plugins/json-schema.cjs +22 -70
- package/dist/plugins/json-schema.d.cts +2 -2
- package/dist/plugins/json-schema.d.ts +2 -2
- package/dist/plugins/json-schema.js +19 -14
- package/dist/runtime/next/async.cjs +56 -11
- package/dist/runtime/next/async.d.cts +4 -6
- package/dist/runtime/next/async.d.ts +4 -6
- package/dist/runtime/next/async.js +3 -6
- package/dist/runtime/next/index.d.cts +5 -5
- package/dist/runtime/next/index.d.ts +5 -5
- package/dist/runtime/vite/browser.d.cts +3 -3
- package/dist/runtime/vite/browser.d.ts +3 -3
- package/dist/runtime/vite/server.d.cts +3 -3
- package/dist/runtime/vite/server.d.ts +3 -3
- package/dist/{types-DKGMoay5.d.cts → types-Bnh9n7mj.d.cts} +2 -2
- package/dist/{types-AGzTfBmf.d.ts → types-ey1AZqrg.d.ts} +2 -2
- package/dist/vite/index.cjs +265 -163
- package/dist/vite/index.d.cts +4 -0
- package/dist/vite/index.d.ts +4 -0
- package/dist/vite/index.js +140 -122
- package/dist/webpack/{index.cjs → mdx.cjs} +126 -104
- package/dist/webpack/mdx.d.cts +6 -0
- package/dist/webpack/mdx.d.ts +6 -0
- package/dist/webpack/{index.js → mdx.js} +12 -14
- package/dist/webpack/meta.cjs +528 -0
- package/dist/webpack/meta.d.cts +6 -0
- package/dist/webpack/meta.d.ts +6 -0
- package/dist/webpack/meta.js +42 -0
- package/loader-mdx.cjs +1 -1
- package/loader-meta.cjs +7 -0
- package/package.json +11 -8
- package/dist/chunk-U4MQ44TS.js +0 -53
- package/dist/chunk-XZY2AWJI.js +0 -81
- package/dist/chunk-YVCR6FUH.js +0 -82
- package/dist/load-MNG3CLET.js +0 -7
- package/dist/webpack/index.d.cts +0 -15
- package/dist/webpack/index.d.ts +0 -15
package/dist/vite/index.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ interface IndexFileOptions {
|
|
|
13
13
|
* add `.js` extensions to imports, needed for ESM without bundler resolution
|
|
14
14
|
*/
|
|
15
15
|
addJsExtension?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Generate entry point for browser environment
|
|
18
|
+
*/
|
|
19
|
+
browser?: boolean;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
interface PluginOptions {
|
package/dist/vite/index.js
CHANGED
|
@@ -4,33 +4,33 @@ import {
|
|
|
4
4
|
} from "../chunk-CXA4JO4Z.js";
|
|
5
5
|
import {
|
|
6
6
|
buildConfig
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import {
|
|
9
|
-
toVite
|
|
10
|
-
} from "../chunk-YVCR6FUH.js";
|
|
7
|
+
} from "../chunk-2HXTGJBI.js";
|
|
11
8
|
import {
|
|
12
9
|
createMdxLoader
|
|
13
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-XYGORKQA.js";
|
|
11
|
+
import {
|
|
12
|
+
createMetaLoader
|
|
13
|
+
} from "../chunk-YAIPHUCZ.js";
|
|
14
|
+
import {
|
|
15
|
+
createIntegratedConfigLoader,
|
|
16
|
+
toVite
|
|
17
|
+
} from "../chunk-ZNVPB2IR.js";
|
|
14
18
|
import "../chunk-3J3WL7WN.js";
|
|
15
19
|
import "../chunk-K5ZLPEIQ.js";
|
|
20
|
+
import {
|
|
21
|
+
mdxLoaderGlob,
|
|
22
|
+
metaLoaderGlob
|
|
23
|
+
} from "../chunk-4JSFLXXT.js";
|
|
24
|
+
import "../chunk-VUEZTR2H.js";
|
|
16
25
|
import {
|
|
17
26
|
ValidationError,
|
|
18
27
|
createCore,
|
|
19
|
-
findConfigFile
|
|
20
|
-
|
|
21
|
-
} from "../chunk-EELYB2XC.js";
|
|
28
|
+
findConfigFile
|
|
29
|
+
} from "../chunk-TZ5EQBFW.js";
|
|
22
30
|
import "../chunk-VWJKRQZR.js";
|
|
23
|
-
import {
|
|
24
|
-
getGlobPatterns
|
|
25
|
-
} from "../chunk-XZY2AWJI.js";
|
|
26
31
|
|
|
27
32
|
// src/vite/index.ts
|
|
28
|
-
import {
|
|
29
|
-
mergeConfig
|
|
30
|
-
} from "vite";
|
|
31
|
-
import { parse } from "querystring";
|
|
32
|
-
import * as path3 from "path";
|
|
33
|
-
import { load } from "js-yaml";
|
|
33
|
+
import { mergeConfig } from "vite";
|
|
34
34
|
|
|
35
35
|
// src/utils/glob-import.ts
|
|
36
36
|
import { globSync } from "tinyglobby";
|
|
@@ -59,27 +59,73 @@ function generateGlobImport(patterns, options) {
|
|
|
59
59
|
|
|
60
60
|
// src/plugins/vite.ts
|
|
61
61
|
import path2 from "path";
|
|
62
|
-
function vite(
|
|
62
|
+
function vite({
|
|
63
|
+
index
|
|
64
|
+
}) {
|
|
63
65
|
let config;
|
|
66
|
+
let indexOptions;
|
|
67
|
+
if (index === false) indexOptions = false;
|
|
68
|
+
else indexOptions = applyDefaults(index === true ? {} : index);
|
|
64
69
|
return {
|
|
70
|
+
name: "vite",
|
|
65
71
|
config(v) {
|
|
66
72
|
config = v;
|
|
67
73
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
configureServer(server) {
|
|
75
|
+
if (!server.watcher || indexOptions === false || indexOptions.runtime === false)
|
|
76
|
+
return;
|
|
77
|
+
server.watcher.on("all", (event, file) => {
|
|
78
|
+
if (event === "change") return;
|
|
79
|
+
const isUpdated = config.collectionList.some((collection) => {
|
|
80
|
+
if (collection.type === "docs")
|
|
81
|
+
return collection.docs.hasFile(file) || collection.meta.hasFile(file);
|
|
82
|
+
return collection.hasFile(file);
|
|
83
|
+
});
|
|
84
|
+
if (isUpdated) {
|
|
85
|
+
this.core.emitAndWrite({
|
|
86
|
+
filterPlugin: (plugin) => plugin.name === "vite"
|
|
87
|
+
});
|
|
73
88
|
}
|
|
74
|
-
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
emit() {
|
|
92
|
+
const out = [];
|
|
93
|
+
if (indexOptions === false) return out;
|
|
94
|
+
if (indexOptions.browser) {
|
|
95
|
+
out.push({
|
|
96
|
+
path: "browser.ts",
|
|
97
|
+
content: indexFile(this, config, indexOptions, "browser")
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
out.push({
|
|
101
|
+
path: "index.ts",
|
|
102
|
+
content: indexFile(
|
|
103
|
+
this,
|
|
104
|
+
config,
|
|
105
|
+
indexOptions,
|
|
106
|
+
indexOptions.browser ? "server" : "all"
|
|
107
|
+
)
|
|
108
|
+
});
|
|
109
|
+
return out;
|
|
75
110
|
}
|
|
76
111
|
};
|
|
77
112
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
113
|
+
function applyDefaults(options) {
|
|
114
|
+
return {
|
|
115
|
+
addJsExtension: options.addJsExtension ?? false,
|
|
116
|
+
browser: options.browser ?? false,
|
|
117
|
+
runtime: options.runtime ?? false
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function indexFile({ configPath, outDir }, config, { addJsExtension, runtime }, environment) {
|
|
121
|
+
const runtimePath = {
|
|
122
|
+
all: "fumadocs-mdx/runtime/vite",
|
|
123
|
+
server: "fumadocs-mdx/runtime/vite.server",
|
|
124
|
+
browser: "fumadocs-mdx/runtime/vite.browser"
|
|
125
|
+
}[environment];
|
|
80
126
|
const lines = [
|
|
81
127
|
'/// <reference types="vite/client" />',
|
|
82
|
-
`import { fromConfig } from '
|
|
128
|
+
`import { fromConfig } from '${runtimePath}';`,
|
|
83
129
|
`import type * as Config from '${toImportPath(configPath, {
|
|
84
130
|
relativeTo: outDir,
|
|
85
131
|
jsExtension: addJsExtension
|
|
@@ -87,74 +133,68 @@ function indexFile(configPath, outDir, config, options) {
|
|
|
87
133
|
"",
|
|
88
134
|
`export const create = fromConfig<typeof Config>();`
|
|
89
135
|
];
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
136
|
+
function generateCollectionGlob(collection) {
|
|
137
|
+
if (collection.type === "docs") {
|
|
138
|
+
const obj = [
|
|
139
|
+
ident(`doc: ${generateCollectionGlob(collection.docs)}`),
|
|
140
|
+
ident(`meta: ${generateCollectionGlob(collection.meta)}`)
|
|
141
|
+
].join(",\n");
|
|
142
|
+
return `{
|
|
96
143
|
${obj}
|
|
97
144
|
}`;
|
|
98
|
-
|
|
99
|
-
function doc(name, collection) {
|
|
100
|
-
const patterns = getGlobPatterns(collection);
|
|
145
|
+
}
|
|
101
146
|
const dir = getCollectionDir(collection);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
collection: name
|
|
105
|
-
},
|
|
106
|
-
base: dir
|
|
107
|
-
});
|
|
108
|
-
if (collection.async) {
|
|
109
|
-
const headBlob = generateGlob(patterns, {
|
|
147
|
+
if (collection.type === "doc") {
|
|
148
|
+
const docGlob = generateGlob(collection.patterns, {
|
|
110
149
|
query: {
|
|
111
|
-
|
|
112
|
-
collection: name
|
|
150
|
+
collection: collection.name
|
|
113
151
|
},
|
|
114
|
-
import: "frontmatter",
|
|
115
152
|
base: dir
|
|
116
153
|
});
|
|
117
|
-
|
|
154
|
+
if (collection.async) {
|
|
155
|
+
const headBlob = generateGlob(collection.patterns, {
|
|
156
|
+
query: {
|
|
157
|
+
only: "frontmatter",
|
|
158
|
+
collection: collection.name
|
|
159
|
+
},
|
|
160
|
+
import: "frontmatter",
|
|
161
|
+
base: dir
|
|
162
|
+
});
|
|
163
|
+
return `create.docLazy("${collection.name}", "${dir}", ${headBlob}, ${docGlob})`;
|
|
164
|
+
}
|
|
165
|
+
return `create.doc("${collection.name}", "${dir}", ${docGlob})`;
|
|
118
166
|
}
|
|
119
|
-
return `create.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
query: {
|
|
128
|
-
collection: name
|
|
167
|
+
return `create.meta("${collection.name}", "${dir}", ${generateGlob(
|
|
168
|
+
collection.patterns,
|
|
169
|
+
{
|
|
170
|
+
import: "default",
|
|
171
|
+
base: dir,
|
|
172
|
+
query: {
|
|
173
|
+
collection: collection.name
|
|
174
|
+
}
|
|
129
175
|
}
|
|
130
|
-
|
|
176
|
+
)})`;
|
|
131
177
|
}
|
|
132
|
-
function generateGlob(patterns,
|
|
178
|
+
function generateGlob(patterns, options) {
|
|
133
179
|
patterns = patterns.map(normalizeGlobPath);
|
|
134
180
|
if (runtime === "node" || runtime === "bun") {
|
|
135
|
-
return generateGlobImport(patterns,
|
|
181
|
+
return generateGlobImport(patterns, options);
|
|
136
182
|
} else {
|
|
137
183
|
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
138
184
|
{
|
|
139
|
-
...
|
|
140
|
-
base: normalizeGlobPath(path2.relative(outDir,
|
|
185
|
+
...options,
|
|
186
|
+
base: normalizeGlobPath(path2.relative(outDir, options.base))
|
|
141
187
|
},
|
|
142
188
|
null,
|
|
143
189
|
2
|
|
144
190
|
)})`;
|
|
145
191
|
}
|
|
146
192
|
}
|
|
147
|
-
for (const
|
|
148
|
-
let body;
|
|
149
|
-
if (collection.type === "docs") {
|
|
150
|
-
body = docs(name, collection);
|
|
151
|
-
} else if (collection.type === "meta") {
|
|
152
|
-
body = meta(name, collection);
|
|
153
|
-
} else {
|
|
154
|
-
body = doc(name, collection);
|
|
155
|
-
}
|
|
193
|
+
for (const collection of config.collectionList) {
|
|
156
194
|
lines.push("");
|
|
157
|
-
lines.push(
|
|
195
|
+
lines.push(
|
|
196
|
+
`export const ${collection.name} = ${generateCollectionGlob(collection)};`
|
|
197
|
+
);
|
|
158
198
|
}
|
|
159
199
|
return lines.join("\n");
|
|
160
200
|
}
|
|
@@ -164,8 +204,7 @@ function normalizeGlobPath(file) {
|
|
|
164
204
|
if (file.startsWith("/")) return `.${file}`;
|
|
165
205
|
return `./${file}`;
|
|
166
206
|
}
|
|
167
|
-
function getCollectionDir(
|
|
168
|
-
const dir = collection.dir;
|
|
207
|
+
function getCollectionDir({ dir }) {
|
|
169
208
|
if (Array.isArray(dir)) {
|
|
170
209
|
if (dir.length !== 1)
|
|
171
210
|
throw new Error(
|
|
@@ -175,54 +214,29 @@ function getCollectionDir(collection) {
|
|
|
175
214
|
}
|
|
176
215
|
return dir;
|
|
177
216
|
}
|
|
178
|
-
function slash(
|
|
179
|
-
const isExtendedLengthPath =
|
|
217
|
+
function slash(path3) {
|
|
218
|
+
const isExtendedLengthPath = path3.startsWith("\\\\?\\");
|
|
180
219
|
if (isExtendedLengthPath) {
|
|
181
|
-
return
|
|
220
|
+
return path3;
|
|
182
221
|
}
|
|
183
|
-
return
|
|
222
|
+
return path3.replaceAll("\\", "/");
|
|
184
223
|
}
|
|
185
224
|
|
|
186
225
|
// src/vite/index.ts
|
|
187
226
|
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
188
227
|
async function mdx(config, pluginOptions = {}) {
|
|
189
|
-
const options =
|
|
228
|
+
const options = applyDefaults2(pluginOptions);
|
|
190
229
|
const core = await createViteCore(options).init({
|
|
191
230
|
config: buildConfig(config)
|
|
192
231
|
});
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
case "meta":
|
|
202
|
-
schema = collection.schema;
|
|
203
|
-
break;
|
|
204
|
-
case "docs":
|
|
205
|
-
schema = collection.meta.schema;
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
if (!schema) return null;
|
|
209
|
-
let data;
|
|
210
|
-
try {
|
|
211
|
-
data = isJson ? JSON.parse(value) : load(value);
|
|
212
|
-
} catch {
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
const out = await validate(
|
|
216
|
-
schema,
|
|
217
|
-
data,
|
|
218
|
-
{ path: path4, source: value },
|
|
219
|
-
`invalid data in ${path4}`
|
|
220
|
-
);
|
|
221
|
-
return {
|
|
222
|
-
code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
|
|
223
|
-
map: null
|
|
224
|
-
};
|
|
225
|
-
}
|
|
232
|
+
const configLoader = createIntegratedConfigLoader(core);
|
|
233
|
+
const mdxLoader = toVite(createMdxLoader(configLoader));
|
|
234
|
+
const metaLoader = toVite(
|
|
235
|
+
createMetaLoader(configLoader, {
|
|
236
|
+
// vite has built-in plugin for JSON files
|
|
237
|
+
json: "json"
|
|
238
|
+
})
|
|
239
|
+
);
|
|
226
240
|
return {
|
|
227
241
|
name: "fumadocs-mdx",
|
|
228
242
|
// needed, otherwise other plugins will be executed before our `transform`.
|
|
@@ -248,13 +262,15 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
248
262
|
});
|
|
249
263
|
},
|
|
250
264
|
async transform(value, id) {
|
|
251
|
-
const [file, query = ""] = id.split("?");
|
|
252
|
-
const ext = path3.extname(file);
|
|
253
265
|
try {
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
266
|
+
if (metaLoaderGlob.test(id)) {
|
|
267
|
+
const [file, query = ""] = id.split("?", 2);
|
|
268
|
+
return await metaLoader.call(this, file, query, value);
|
|
269
|
+
}
|
|
270
|
+
if (mdxLoaderGlob.test(id)) {
|
|
271
|
+
const [file, query = ""] = id.split("?", 2);
|
|
257
272
|
return await mdxLoader.call(this, file, query, value);
|
|
273
|
+
}
|
|
258
274
|
} catch (e) {
|
|
259
275
|
if (e instanceof ValidationError) {
|
|
260
276
|
throw new Error(e.toStringFormatted());
|
|
@@ -265,8 +281,8 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
265
281
|
};
|
|
266
282
|
}
|
|
267
283
|
async function postInstall(configPath = findConfigFile(), pluginOptions = {}) {
|
|
268
|
-
const { loadConfig } = await import("../load-
|
|
269
|
-
const options =
|
|
284
|
+
const { loadConfig } = await import("../load-from-file-AVYOFOI7.js");
|
|
285
|
+
const options = applyDefaults2(pluginOptions);
|
|
270
286
|
const core = await createViteCore(options).init({
|
|
271
287
|
config: loadConfig(configPath, options.outDir, true)
|
|
272
288
|
});
|
|
@@ -284,11 +300,13 @@ function createViteCore({
|
|
|
284
300
|
outDir
|
|
285
301
|
},
|
|
286
302
|
[
|
|
287
|
-
|
|
303
|
+
vite({
|
|
304
|
+
index: generateIndexFile
|
|
305
|
+
})
|
|
288
306
|
]
|
|
289
307
|
);
|
|
290
308
|
}
|
|
291
|
-
function
|
|
309
|
+
function applyDefaults2(options) {
|
|
292
310
|
return {
|
|
293
311
|
updateViteConfig: options.updateViteConfig ?? true,
|
|
294
312
|
generateIndexFile: options.generateIndexFile ?? true,
|