fumadocs-mdx 13.0.8 → 14.0.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.
- package/dist/bin.cjs +924 -901
- package/dist/bin.js +3 -3
- package/dist/build-mdx-6UAK5FF5.js +8 -0
- package/dist/bun/index.cjs +578 -471
- package/dist/bun/index.d.cts +3 -2
- package/dist/bun/index.d.ts +3 -2
- package/dist/bun/index.js +12 -12
- package/dist/chunk-4JSFLXXT.js +8 -0
- package/dist/chunk-5UMZCWKV.js +17 -0
- package/dist/chunk-5YXP7JLN.js +138 -0
- package/dist/{chunk-2E2JCOSO.js → chunk-6NISOLQ6.js} +16 -44
- package/dist/chunk-7L2KNF6B.js +180 -0
- package/dist/chunk-E5DJTSIM.js +86 -0
- package/dist/{chunk-K5ZLPEIQ.js → chunk-FBLMK4RS.js} +9 -6
- package/dist/{chunk-QXHN25N3.js → chunk-OXSRIWQW.js} +7 -8
- package/dist/chunk-PKI7ZDA5.js +29 -0
- package/dist/{chunk-3J3WL7WN.js → chunk-SLY7WXTX.js} +71 -58
- package/dist/{chunk-5FTSWCB4.js → chunk-SRSRFOVI.js} +8 -10
- package/dist/chunk-TYJDYTKH.js +85 -0
- package/dist/chunk-XHJCLBZ4.js +406 -0
- package/dist/{chunk-2HXTGJBI.js → chunk-ZY6UZ7NH.js} +22 -19
- package/dist/config/index.cjs +79 -71
- package/dist/config/index.d.cts +2 -1
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +5 -5
- package/dist/index-BlVBvy-z.d.ts +8 -0
- package/dist/{core-DB7TdlyC.d.cts → index-D7JdSMpp.d.cts} +99 -61
- package/dist/{core-DB7TdlyC.d.ts → index-D7JdSMpp.d.ts} +99 -61
- package/dist/index-P2NNUkHn.d.cts +8 -0
- package/dist/index.d.cts +3 -74
- package/dist/index.d.ts +3 -74
- package/dist/load-from-file-I3ALLIVB.js +8 -0
- package/dist/next/index.cjs +698 -476
- package/dist/next/index.d.cts +11 -1
- package/dist/next/index.d.ts +11 -1
- package/dist/next/index.js +78 -281
- package/dist/node/loader.cjs +704 -602
- package/dist/node/loader.js +10 -11
- package/dist/plugins/index-file.cjs +471 -0
- package/dist/plugins/index-file.d.cts +29 -0
- package/dist/plugins/index-file.d.ts +29 -0
- package/dist/plugins/index-file.js +8 -0
- package/dist/plugins/json-schema.d.cts +3 -2
- package/dist/plugins/json-schema.d.ts +3 -2
- package/dist/plugins/last-modified.cjs +75 -0
- package/dist/plugins/last-modified.d.cts +27 -0
- package/dist/plugins/last-modified.d.ts +27 -0
- package/dist/plugins/last-modified.js +44 -0
- package/dist/runtime/{vite/browser.cjs → browser.cjs} +40 -53
- package/dist/runtime/browser.d.cts +50 -0
- package/dist/runtime/browser.d.ts +50 -0
- package/dist/runtime/browser.js +68 -0
- package/dist/runtime/dynamic.cjs +985 -0
- package/dist/runtime/dynamic.d.cts +27 -0
- package/dist/runtime/dynamic.d.ts +27 -0
- package/dist/runtime/dynamic.js +78 -0
- package/dist/runtime/server.cjs +173 -0
- package/dist/runtime/server.d.cts +161 -0
- package/dist/runtime/server.d.ts +161 -0
- package/dist/runtime/server.js +8 -0
- package/dist/vite/index.cjs +934 -638
- package/dist/vite/index.d.cts +12 -22
- package/dist/vite/index.d.ts +12 -22
- package/dist/vite/index.js +30 -221
- package/dist/webpack/mdx.cjs +613 -515
- package/dist/webpack/mdx.d.cts +9 -1
- package/dist/webpack/mdx.d.ts +9 -1
- package/dist/webpack/mdx.js +12 -17
- package/dist/webpack/meta.cjs +327 -233
- package/dist/webpack/meta.d.cts +9 -1
- package/dist/webpack/meta.d.ts +9 -1
- package/dist/webpack/meta.js +13 -15
- package/package.json +15 -32
- package/dist/build-mdx-BjXOmv0b.d.cts +0 -53
- package/dist/build-mdx-CY5UldCO.d.ts +0 -53
- package/dist/chunk-2AQRQXSO.js +0 -119
- package/dist/chunk-CXA4JO4Z.js +0 -45
- package/dist/chunk-DMJ6I4C3.js +0 -76
- package/dist/chunk-FSZMKRVH.js +0 -80
- package/dist/chunk-II3H5ZVZ.js +0 -77
- package/dist/chunk-KILFIBVW.js +0 -75
- package/dist/chunk-NVRDCY6Z.js +0 -30
- package/dist/chunk-VUEZTR2H.js +0 -26
- package/dist/index-D7s7kCc2.d.cts +0 -7
- package/dist/index-D7s7kCc2.d.ts +0 -7
- package/dist/load-from-file-AVYOFOI7.js +0 -7
- package/dist/preset-ZMP6U62C.js +0 -6
- package/dist/runtime/next/async.cjs +0 -760
- package/dist/runtime/next/async.d.cts +0 -19
- package/dist/runtime/next/async.d.ts +0 -19
- package/dist/runtime/next/async.js +0 -86
- package/dist/runtime/next/index.cjs +0 -136
- package/dist/runtime/next/index.d.cts +0 -33
- package/dist/runtime/next/index.d.ts +0 -33
- package/dist/runtime/next/index.js +0 -11
- package/dist/runtime/vite/browser.d.cts +0 -59
- package/dist/runtime/vite/browser.d.ts +0 -59
- package/dist/runtime/vite/browser.js +0 -11
- package/dist/runtime/vite/server.cjs +0 -243
- package/dist/runtime/vite/server.d.cts +0 -30
- package/dist/runtime/vite/server.d.ts +0 -30
- package/dist/runtime/vite/server.js +0 -111
- package/dist/types-Bnh9n7mj.d.cts +0 -45
- package/dist/types-ey1AZqrg.d.ts +0 -45
package/dist/next/index.d.cts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { NextConfig } from 'next';
|
|
2
|
+
import { IndexFilePluginOptions } from '../plugins/index-file.cjs';
|
|
3
|
+
import '../index-D7JdSMpp.cjs';
|
|
4
|
+
import '@mdx-js/mdx';
|
|
5
|
+
import '@standard-schema/spec';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'fumadocs-core/mdx-plugins';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import 'chokidar';
|
|
10
|
+
import 'vfile';
|
|
2
11
|
|
|
3
12
|
interface CreateMDXOptions {
|
|
4
13
|
/**
|
|
@@ -11,8 +20,9 @@ interface CreateMDXOptions {
|
|
|
11
20
|
* @defaultValue '.source'
|
|
12
21
|
*/
|
|
13
22
|
outDir?: string;
|
|
23
|
+
index?: IndexFilePluginOptions | false;
|
|
14
24
|
}
|
|
15
25
|
declare function createMDX(createOptions?: CreateMDXOptions): (nextConfig?: NextConfig) => NextConfig;
|
|
16
|
-
declare function postInstall(
|
|
26
|
+
declare function postInstall(options: CreateMDXOptions): Promise<void>;
|
|
17
27
|
|
|
18
28
|
export { type CreateMDXOptions, createMDX, postInstall };
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { NextConfig } from 'next';
|
|
2
|
+
import { IndexFilePluginOptions } from '../plugins/index-file.js';
|
|
3
|
+
import '../index-D7JdSMpp.js';
|
|
4
|
+
import '@mdx-js/mdx';
|
|
5
|
+
import '@standard-schema/spec';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'fumadocs-core/mdx-plugins';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import 'chokidar';
|
|
10
|
+
import 'vfile';
|
|
2
11
|
|
|
3
12
|
interface CreateMDXOptions {
|
|
4
13
|
/**
|
|
@@ -11,8 +20,9 @@ interface CreateMDXOptions {
|
|
|
11
20
|
* @defaultValue '.source'
|
|
12
21
|
*/
|
|
13
22
|
outDir?: string;
|
|
23
|
+
index?: IndexFilePluginOptions | false;
|
|
14
24
|
}
|
|
15
25
|
declare function createMDX(createOptions?: CreateMDXOptions): (nextConfig?: NextConfig) => NextConfig;
|
|
16
|
-
declare function postInstall(
|
|
26
|
+
declare function postInstall(options: CreateMDXOptions): Promise<void>;
|
|
17
27
|
|
|
18
28
|
export { type CreateMDXOptions, createMDX, postInstall };
|
package/dist/next/index.js
CHANGED
|
@@ -1,263 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadConfig
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-OXSRIWQW.js";
|
|
4
|
+
import "../chunk-ZY6UZ7NH.js";
|
|
5
|
+
import "../chunk-E5DJTSIM.js";
|
|
4
6
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-2HXTGJBI.js";
|
|
9
|
-
import {
|
|
10
|
-
getGitTimestamp
|
|
11
|
-
} from "../chunk-VUEZTR2H.js";
|
|
7
|
+
mdxLoaderGlob,
|
|
8
|
+
metaLoaderGlob
|
|
9
|
+
} from "../chunk-4JSFLXXT.js";
|
|
12
10
|
import {
|
|
13
11
|
ValidationError,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
validate
|
|
18
|
-
} from "../chunk-2AQRQXSO.js";
|
|
12
|
+
_Defaults,
|
|
13
|
+
createCore
|
|
14
|
+
} from "../chunk-7L2KNF6B.js";
|
|
19
15
|
import {
|
|
20
|
-
|
|
21
|
-
} from "../chunk-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import * as path3 from "path";
|
|
25
|
-
|
|
26
|
-
// src/next/file-cache.ts
|
|
27
|
-
import { LRUCache } from "lru-cache";
|
|
28
|
-
import fs from "fs/promises";
|
|
29
|
-
import path from "path";
|
|
30
|
-
var map = new LRUCache({
|
|
31
|
-
max: 100
|
|
32
|
-
});
|
|
33
|
-
function toFullPath(file) {
|
|
34
|
-
if (path.isAbsolute(file)) {
|
|
35
|
-
return path.relative(process.cwd(), file);
|
|
36
|
-
}
|
|
37
|
-
return file;
|
|
38
|
-
}
|
|
39
|
-
async function readFileWithCache(file) {
|
|
40
|
-
const fullPath = toFullPath(file);
|
|
41
|
-
const cached = map.get(fullPath);
|
|
42
|
-
if (cached) return cached;
|
|
43
|
-
const read = fs.readFile(fullPath).then((s) => s.toString());
|
|
44
|
-
map.set(fullPath, read);
|
|
45
|
-
return read;
|
|
46
|
-
}
|
|
47
|
-
function removeFileCache(file) {
|
|
48
|
-
map.delete(toFullPath(file));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/plugins/next.ts
|
|
52
|
-
import * as path2 from "path";
|
|
53
|
-
import { createHash } from "crypto";
|
|
54
|
-
import { load } from "js-yaml";
|
|
55
|
-
function next() {
|
|
56
|
-
let config;
|
|
57
|
-
let shouldEmitOnChange = false;
|
|
58
|
-
return {
|
|
59
|
-
name: "next",
|
|
60
|
-
config(v) {
|
|
61
|
-
config = v;
|
|
62
|
-
shouldEmitOnChange = config.collectionList.some((collection) => {
|
|
63
|
-
return collection.type === "doc" && collection.async || collection.type === "docs" || collection.type === "meta";
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
configureServer(server) {
|
|
67
|
-
if (!server.watcher) return;
|
|
68
|
-
server.watcher.on("all", async (event) => {
|
|
69
|
-
if (event === "change" && !shouldEmitOnChange) return;
|
|
70
|
-
await this.core.emitAndWrite({
|
|
71
|
-
filterPlugin: (plugin) => plugin.name === "next"
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
async emit() {
|
|
76
|
-
return [
|
|
77
|
-
{
|
|
78
|
-
path: "index.ts",
|
|
79
|
-
content: await indexFile(this.configPath, config, {
|
|
80
|
-
relativeTo: this.outDir
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
async function indexFile(configPath, config, importPath) {
|
|
88
|
-
let asyncInit = false;
|
|
89
|
-
const lines = [
|
|
90
|
-
getImportCode({
|
|
91
|
-
type: "named",
|
|
92
|
-
names: ["_runtime"],
|
|
93
|
-
specifier: "fumadocs-mdx/runtime/next"
|
|
94
|
-
}),
|
|
95
|
-
getImportCode({
|
|
96
|
-
type: "namespace",
|
|
97
|
-
specifier: toImportPath(configPath, importPath),
|
|
98
|
-
name: "_source"
|
|
99
|
-
})
|
|
100
|
-
];
|
|
101
|
-
function getDocEntries(collection, files) {
|
|
102
|
-
return files.map((file, i) => {
|
|
103
|
-
const importId = `d_${collection.name}_${i}`;
|
|
104
|
-
const params = [`collection=${collection.name}`];
|
|
105
|
-
lines.unshift(
|
|
106
|
-
getImportCode({
|
|
107
|
-
type: "namespace",
|
|
108
|
-
name: importId,
|
|
109
|
-
specifier: `${toImportPath(file.fullPath, importPath)}?${params.join("&")}`
|
|
110
|
-
})
|
|
111
|
-
);
|
|
112
|
-
return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
async function getMetaEntries(collection, files) {
|
|
116
|
-
const items = files.map(async (file) => {
|
|
117
|
-
const source = await readFileWithCache(file.fullPath).catch(() => "");
|
|
118
|
-
let data = source.length === 0 ? {} : parseMetaEntry(file.fullPath, source);
|
|
119
|
-
if (collection?.schema) {
|
|
120
|
-
data = await validate(
|
|
121
|
-
collection.schema,
|
|
122
|
-
data,
|
|
123
|
-
{
|
|
124
|
-
source,
|
|
125
|
-
path: file.fullPath
|
|
126
|
-
},
|
|
127
|
-
`invalid data in ${file.fullPath}`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
return JSON.stringify({
|
|
131
|
-
info: file,
|
|
132
|
-
data
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
return Promise.all(items);
|
|
136
|
-
}
|
|
137
|
-
async function getAsyncEntries(collection, files) {
|
|
138
|
-
if (!asyncInit) {
|
|
139
|
-
lines.unshift(
|
|
140
|
-
getImportCode({
|
|
141
|
-
type: "named",
|
|
142
|
-
specifier: "fumadocs-mdx/runtime/async",
|
|
143
|
-
names: ["_runtimeAsync", "buildConfig"]
|
|
144
|
-
}),
|
|
145
|
-
"const _sourceConfig = buildConfig(_source)",
|
|
146
|
-
getImportCode({
|
|
147
|
-
type: "default",
|
|
148
|
-
name: "path",
|
|
149
|
-
specifier: "node:path"
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
asyncInit = true;
|
|
153
|
-
}
|
|
154
|
-
const entries = files.map(async (file) => {
|
|
155
|
-
const content = await readFileWithCache(file.fullPath).catch(() => "");
|
|
156
|
-
const parsed = fumaMatter(content);
|
|
157
|
-
let data = parsed.data;
|
|
158
|
-
if (collection.schema) {
|
|
159
|
-
data = await validate(
|
|
160
|
-
collection.schema,
|
|
161
|
-
parsed.data,
|
|
162
|
-
{ path: file.fullPath, source: parsed.content },
|
|
163
|
-
`invalid frontmatter in ${file.fullPath}`
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
let lastModified;
|
|
167
|
-
if (config.global?.lastModifiedTime === "git") {
|
|
168
|
-
lastModified = await getGitTimestamp(file.fullPath);
|
|
169
|
-
}
|
|
170
|
-
const hash = createHash("md5").update(content).digest("hex");
|
|
171
|
-
const infoStr = [];
|
|
172
|
-
for (const [k, v] of Object.entries({ ...file, hash })) {
|
|
173
|
-
infoStr.push(`${k}: ${JSON.stringify(v)}`);
|
|
174
|
-
}
|
|
175
|
-
infoStr.push(
|
|
176
|
-
`absolutePath: path.resolve(${JSON.stringify(file.fullPath)})`
|
|
177
|
-
);
|
|
178
|
-
return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
|
|
179
|
-
});
|
|
180
|
-
return Promise.all(entries);
|
|
181
|
-
}
|
|
182
|
-
const declares = config.collectionList.map(async (collection) => {
|
|
183
|
-
const k = collection.name;
|
|
184
|
-
if (collection.type === "docs") {
|
|
185
|
-
const docs = await globCollectionFiles(collection.docs);
|
|
186
|
-
const metas = await globCollectionFiles(collection.meta);
|
|
187
|
-
const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
|
|
188
|
-
", "
|
|
189
|
-
);
|
|
190
|
-
if (collection.docs.async) {
|
|
191
|
-
const docsEntries2 = (await getAsyncEntries(collection.docs, docs)).join(
|
|
192
|
-
", "
|
|
193
|
-
);
|
|
194
|
-
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
|
|
195
|
-
}
|
|
196
|
-
const docsEntries = getDocEntries(collection.docs, docs).join(", ");
|
|
197
|
-
return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
|
|
198
|
-
}
|
|
199
|
-
const files = await globCollectionFiles(collection);
|
|
200
|
-
if (collection.type === "meta") {
|
|
201
|
-
return `export const ${k} = _runtime.meta<typeof _source.${k}>([${(await getMetaEntries(collection, files)).join(", ")}]);`;
|
|
202
|
-
}
|
|
203
|
-
if (collection.async) {
|
|
204
|
-
return `export const ${k} = _runtimeAsync.doc<typeof _source.${k}>([${(await getAsyncEntries(collection, files)).join(", ")}], "${k}", _sourceConfig)`;
|
|
205
|
-
}
|
|
206
|
-
return `export const ${k} = _runtime.doc<typeof _source.${k}>([${getDocEntries(collection, files).join(", ")}]);`;
|
|
207
|
-
});
|
|
208
|
-
const resolvedDeclares = await Promise.all(declares);
|
|
209
|
-
return [
|
|
210
|
-
`// @ts-nocheck -- skip type checking`,
|
|
211
|
-
...lines,
|
|
212
|
-
...resolvedDeclares
|
|
213
|
-
].join("\n");
|
|
214
|
-
}
|
|
215
|
-
function parseMetaEntry(file, content) {
|
|
216
|
-
const extname2 = path2.extname(file);
|
|
217
|
-
try {
|
|
218
|
-
if (extname2 === ".json") return JSON.parse(content);
|
|
219
|
-
if (extname2 === ".yaml") return load(content);
|
|
220
|
-
} catch (e) {
|
|
221
|
-
throw new Error(`Failed to parse meta file: ${file}.`, {
|
|
222
|
-
cause: e
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
|
|
226
|
-
}
|
|
227
|
-
async function globCollectionFiles(collection) {
|
|
228
|
-
const { glob } = await import("tinyglobby");
|
|
229
|
-
const files = /* @__PURE__ */ new Map();
|
|
230
|
-
const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
|
|
231
|
-
await Promise.all(
|
|
232
|
-
dirs.map(async (dir) => {
|
|
233
|
-
const result = await glob(collection.patterns, {
|
|
234
|
-
cwd: path2.resolve(dir)
|
|
235
|
-
});
|
|
236
|
-
for (const item of result) {
|
|
237
|
-
if (!collection.isFileSupported(item)) continue;
|
|
238
|
-
const fullPath = path2.join(dir, item);
|
|
239
|
-
files.set(fullPath, {
|
|
240
|
-
path: item,
|
|
241
|
-
fullPath
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
})
|
|
245
|
-
);
|
|
246
|
-
return Array.from(files.values());
|
|
247
|
-
}
|
|
16
|
+
indexFile
|
|
17
|
+
} from "../chunk-XHJCLBZ4.js";
|
|
18
|
+
import "../chunk-PKI7ZDA5.js";
|
|
19
|
+
import "../chunk-VWJKRQZR.js";
|
|
248
20
|
|
|
249
21
|
// src/next/index.ts
|
|
22
|
+
import * as path from "path";
|
|
250
23
|
var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
|
|
251
24
|
function createMDX(createOptions = {}) {
|
|
252
|
-
const
|
|
25
|
+
const core = createNextCore(applyDefaults(createOptions));
|
|
253
26
|
const isDev = process.env.NODE_ENV === "development";
|
|
254
27
|
if (process.env._FUMADOCS_MDX !== "1") {
|
|
255
28
|
process.env._FUMADOCS_MDX = "1";
|
|
256
|
-
void init(isDev,
|
|
29
|
+
void init(isDev, core);
|
|
257
30
|
}
|
|
258
31
|
return (nextConfig = {}) => {
|
|
259
32
|
const loaderOptions = {
|
|
260
|
-
...
|
|
33
|
+
...core._options,
|
|
34
|
+
compiledConfigPath: core.getCompiledConfigPath(),
|
|
261
35
|
isDev
|
|
262
36
|
};
|
|
263
37
|
const turbopack = {
|
|
@@ -272,6 +46,24 @@ function createMDX(createOptions = {}) {
|
|
|
272
46
|
}
|
|
273
47
|
],
|
|
274
48
|
as: "*.js"
|
|
49
|
+
},
|
|
50
|
+
"*.json": {
|
|
51
|
+
loaders: [
|
|
52
|
+
{
|
|
53
|
+
loader: "fumadocs-mdx/loader-meta",
|
|
54
|
+
options: loaderOptions
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
as: "*.json"
|
|
58
|
+
},
|
|
59
|
+
"*.yaml": {
|
|
60
|
+
loaders: [
|
|
61
|
+
{
|
|
62
|
+
loader: "fumadocs-mdx/loader-meta",
|
|
63
|
+
options: loaderOptions
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
as: "*.js"
|
|
275
67
|
}
|
|
276
68
|
}
|
|
277
69
|
};
|
|
@@ -279,31 +71,42 @@ function createMDX(createOptions = {}) {
|
|
|
279
71
|
...nextConfig,
|
|
280
72
|
turbopack,
|
|
281
73
|
pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
|
|
282
|
-
webpack: (config,
|
|
74
|
+
webpack: (config, options) => {
|
|
283
75
|
config.resolve ||= {};
|
|
284
76
|
config.module ||= {};
|
|
285
77
|
config.module.rules ||= [];
|
|
286
|
-
config.module.rules.push(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
78
|
+
config.module.rules.push(
|
|
79
|
+
{
|
|
80
|
+
test: mdxLoaderGlob,
|
|
81
|
+
use: [
|
|
82
|
+
options.defaultLoaders.babel,
|
|
83
|
+
{
|
|
84
|
+
loader: "fumadocs-mdx/loader-mdx",
|
|
85
|
+
options: loaderOptions
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
test: metaLoaderGlob,
|
|
91
|
+
use: [
|
|
92
|
+
options.defaultLoaders.babel,
|
|
93
|
+
{
|
|
94
|
+
loader: "fumadocs-mdx/loader-meta",
|
|
95
|
+
options: loaderOptions
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
);
|
|
296
100
|
config.plugins ||= [];
|
|
297
|
-
return nextConfig.webpack?.(config,
|
|
101
|
+
return nextConfig.webpack?.(config, options) ?? config;
|
|
298
102
|
}
|
|
299
103
|
};
|
|
300
104
|
};
|
|
301
105
|
}
|
|
302
|
-
async function init(dev,
|
|
303
|
-
const core = createNextCore(options);
|
|
106
|
+
async function init(dev, core) {
|
|
304
107
|
async function initOrReload() {
|
|
305
108
|
await core.init({
|
|
306
|
-
config: loadConfig(
|
|
109
|
+
config: loadConfig(core, true)
|
|
307
110
|
});
|
|
308
111
|
await core.emitAndWrite();
|
|
309
112
|
}
|
|
@@ -312,9 +115,9 @@ async function init(dev, options) {
|
|
|
312
115
|
const watcher = new FSWatcher({
|
|
313
116
|
ignoreInitial: true,
|
|
314
117
|
persistent: true,
|
|
315
|
-
ignored: [
|
|
118
|
+
ignored: [core._options.outDir]
|
|
316
119
|
});
|
|
317
|
-
watcher.add(
|
|
120
|
+
watcher.add(core._options.configPath);
|
|
318
121
|
for (const collection of core.getConfig().collectionList) {
|
|
319
122
|
if (collection.type === "docs") {
|
|
320
123
|
watcher.add(collection.docs.dir);
|
|
@@ -326,10 +129,8 @@ async function init(dev, options) {
|
|
|
326
129
|
watcher.on("ready", () => {
|
|
327
130
|
console.log("[MDX] started dev server");
|
|
328
131
|
});
|
|
329
|
-
watcher.on("all", async (
|
|
330
|
-
|
|
331
|
-
if (event === "change") removeFileCache(absolutePath);
|
|
332
|
-
if (absolutePath === path3.resolve(options.configPath)) {
|
|
132
|
+
watcher.on("all", async (_event, file) => {
|
|
133
|
+
if (path.resolve(file) === path.resolve(core._options.configPath)) {
|
|
333
134
|
watcher.removeAllListeners();
|
|
334
135
|
await watcher.close();
|
|
335
136
|
await initOrReload();
|
|
@@ -349,32 +150,28 @@ async function init(dev, options) {
|
|
|
349
150
|
await devServer();
|
|
350
151
|
}
|
|
351
152
|
}
|
|
352
|
-
async function postInstall(
|
|
353
|
-
const core =
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}).init({
|
|
357
|
-
config: loadConfig(configPath, outDir, true)
|
|
153
|
+
async function postInstall(options) {
|
|
154
|
+
const core = createNextCore(applyDefaults(options));
|
|
155
|
+
await core.init({
|
|
156
|
+
config: loadConfig(core, true)
|
|
358
157
|
});
|
|
359
158
|
await core.emitAndWrite();
|
|
360
159
|
}
|
|
361
160
|
function applyDefaults(options) {
|
|
362
161
|
return {
|
|
363
|
-
|
|
364
|
-
|
|
162
|
+
index: {},
|
|
163
|
+
outDir: options.outDir ?? _Defaults.outDir,
|
|
164
|
+
configPath: options.configPath ?? _Defaults.configPath
|
|
365
165
|
};
|
|
366
166
|
}
|
|
367
|
-
function createNextCore({
|
|
368
|
-
outDir,
|
|
369
|
-
configPath
|
|
370
|
-
}) {
|
|
167
|
+
function createNextCore(options) {
|
|
371
168
|
const core = createCore(
|
|
372
169
|
{
|
|
373
170
|
environment: "next",
|
|
374
|
-
outDir,
|
|
375
|
-
configPath
|
|
171
|
+
outDir: options.outDir,
|
|
172
|
+
configPath: options.configPath
|
|
376
173
|
},
|
|
377
|
-
[
|
|
174
|
+
[options.index && indexFile(options.index)]
|
|
378
175
|
);
|
|
379
176
|
return {
|
|
380
177
|
...core,
|
|
@@ -383,7 +180,7 @@ function createNextCore({
|
|
|
383
180
|
await core.emitAndWrite(...args);
|
|
384
181
|
} catch (err) {
|
|
385
182
|
if (err instanceof ValidationError) {
|
|
386
|
-
console.error(err.toStringFormatted());
|
|
183
|
+
console.error(await err.toStringFormatted());
|
|
387
184
|
} else {
|
|
388
185
|
console.error(err);
|
|
389
186
|
}
|