fumadocs-mdx 11.5.3 → 11.5.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/{chunk-USWGH3VH.js → chunk-2FUWXPXA.js} +4 -5
- package/dist/{chunk-3PXNPJQ2.js → chunk-IZURUUPO.js} +1 -1
- package/dist/chunk-KGLACICA.js +43 -0
- package/dist/config/index.d.cts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +4 -19
- package/dist/{define-BUjajTka.d.cts → define-DxwgTgV6.d.cts} +13 -13
- package/dist/{define-BUjajTka.d.ts → define-DxwgTgV6.d.ts} +13 -13
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/loader-mdx.cjs +49 -38
- package/dist/loader-mdx.js +11 -34
- package/dist/next/index.cjs +143 -84
- package/dist/next/index.js +105 -80
- package/dist/runtime/async.cjs +1 -1
- package/dist/runtime/async.d.cts +2 -2
- package/dist/runtime/async.d.ts +2 -2
- package/dist/runtime/async.js +1 -1
- package/dist/{types-Dh6jLIT1.d.cts → types-8ecOBKxa.d.cts} +1 -1
- package/dist/{types-CvzwQDWV.d.ts → types-BQ1vyPw8.d.ts} +1 -1
- package/package.json +5 -5
|
@@ -10,7 +10,7 @@ import { pathToFileURL } from "node:url";
|
|
|
10
10
|
function findConfigFile() {
|
|
11
11
|
return path.resolve("source.config.ts");
|
|
12
12
|
}
|
|
13
|
-
var cache =
|
|
13
|
+
var cache = null;
|
|
14
14
|
async function compileConfig(configPath) {
|
|
15
15
|
const { build } = await import("esbuild");
|
|
16
16
|
const transformed = await build({
|
|
@@ -32,9 +32,8 @@ async function compileConfig(configPath) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
async function loadConfig(configPath, hash, build = false) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return await cached.config;
|
|
35
|
+
if (cache && cache.hash === hash) {
|
|
36
|
+
return await cache.config;
|
|
38
37
|
}
|
|
39
38
|
if (build) await compileConfig(configPath);
|
|
40
39
|
const url = pathToFileURL(path.resolve(".source/source.config.mjs"));
|
|
@@ -46,7 +45,7 @@ async function loadConfig(configPath, hash, build = false) {
|
|
|
46
45
|
if (err !== null) throw new Error(err);
|
|
47
46
|
return config2;
|
|
48
47
|
});
|
|
49
|
-
cache
|
|
48
|
+
cache = { config, hash };
|
|
50
49
|
return await config;
|
|
51
50
|
}
|
|
52
51
|
async function getConfigHash(configPath) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/utils/schema.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var metaSchema = z.object({
|
|
4
|
+
title: z.string().optional(),
|
|
5
|
+
pages: z.array(z.string()).optional(),
|
|
6
|
+
description: z.string().optional(),
|
|
7
|
+
root: z.boolean().optional(),
|
|
8
|
+
defaultOpen: z.boolean().optional(),
|
|
9
|
+
icon: z.string().optional()
|
|
10
|
+
});
|
|
11
|
+
var frontmatterSchema = z.object({
|
|
12
|
+
title: z.string(),
|
|
13
|
+
description: z.string().optional(),
|
|
14
|
+
icon: z.string().optional(),
|
|
15
|
+
full: z.boolean().optional(),
|
|
16
|
+
// Fumadocs OpenAPI generated
|
|
17
|
+
_openapi: z.object({}).passthrough().optional()
|
|
18
|
+
});
|
|
19
|
+
async function validate(schema, data, context, errorMessage) {
|
|
20
|
+
if (typeof schema === "function" && !("~standard" in schema)) {
|
|
21
|
+
schema = schema(context);
|
|
22
|
+
}
|
|
23
|
+
if ("~standard" in schema) {
|
|
24
|
+
const result = await schema["~standard"].validate(
|
|
25
|
+
data
|
|
26
|
+
);
|
|
27
|
+
if (result.issues) {
|
|
28
|
+
throw new Error(formatError(errorMessage, result.issues));
|
|
29
|
+
}
|
|
30
|
+
return result.value;
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
function formatError(message, issues) {
|
|
35
|
+
return `${message}:
|
|
36
|
+
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
metaSchema,
|
|
41
|
+
frontmatterSchema,
|
|
42
|
+
validate
|
|
43
|
+
};
|
package/dist/config/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as BaseCollection, B as BaseCollectionEntry, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection,
|
|
1
|
+
export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-DxwgTgV6.cjs';
|
|
2
2
|
import { Processor, Transformer } from 'unified';
|
|
3
3
|
import { Root } from 'mdast';
|
|
4
4
|
import '@mdx-js/mdx';
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as BaseCollection, B as BaseCollectionEntry, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection,
|
|
1
|
+
export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-DxwgTgV6.js';
|
|
2
2
|
import { Processor, Transformer } from 'unified';
|
|
3
3
|
import { Root } from 'mdast';
|
|
4
4
|
import '@mdx-js/mdx';
|
package/dist/config/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
frontmatterSchema,
|
|
3
|
+
metaSchema
|
|
4
|
+
} from "../chunk-KGLACICA.js";
|
|
1
5
|
import {
|
|
2
6
|
remarkInclude
|
|
3
7
|
} from "../chunk-PY2KKTR2.js";
|
|
@@ -5,25 +9,6 @@ import {
|
|
|
5
9
|
getDefaultMDXOptions
|
|
6
10
|
} from "../chunk-IOENRFUX.js";
|
|
7
11
|
|
|
8
|
-
// src/utils/schema.ts
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
var metaSchema = z.object({
|
|
11
|
-
title: z.string().optional(),
|
|
12
|
-
pages: z.array(z.string()).optional(),
|
|
13
|
-
description: z.string().optional(),
|
|
14
|
-
root: z.boolean().optional(),
|
|
15
|
-
defaultOpen: z.boolean().optional(),
|
|
16
|
-
icon: z.string().optional()
|
|
17
|
-
});
|
|
18
|
-
var frontmatterSchema = z.object({
|
|
19
|
-
title: z.string(),
|
|
20
|
-
description: z.string().optional(),
|
|
21
|
-
icon: z.string().optional(),
|
|
22
|
-
full: z.boolean().optional(),
|
|
23
|
-
// Fumadocs OpenAPI generated
|
|
24
|
-
_openapi: z.object({}).passthrough().optional()
|
|
25
|
-
});
|
|
26
|
-
|
|
27
12
|
// src/config/define.ts
|
|
28
13
|
function defineCollections(options) {
|
|
29
14
|
return {
|
|
@@ -130,15 +130,8 @@ declare const frontmatterSchema: z.ZodObject<{
|
|
|
130
130
|
_openapi?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
131
131
|
}>;
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
source: string;
|
|
136
|
-
/**
|
|
137
|
-
* Compile MDX to JavaScript
|
|
138
|
-
*/
|
|
139
|
-
buildMDX: (source: string, options?: ProcessorOptions) => Promise<string>;
|
|
140
|
-
}
|
|
141
|
-
interface BaseCollection<Schema> {
|
|
133
|
+
type CollectionSchema<Schema extends StandardSchemaV1, Context> = Schema | ((ctx: Context) => Schema);
|
|
134
|
+
interface BaseCollection {
|
|
142
135
|
/**
|
|
143
136
|
* Directories to scan
|
|
144
137
|
*/
|
|
@@ -149,18 +142,25 @@ interface BaseCollection<Schema> {
|
|
|
149
142
|
* Include all files if not specified
|
|
150
143
|
*/
|
|
151
144
|
files?: string[];
|
|
152
|
-
schema?: Schema | ((ctx: TransformContext) => Schema);
|
|
153
145
|
}
|
|
154
|
-
interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> extends BaseCollection
|
|
146
|
+
interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> extends BaseCollection {
|
|
155
147
|
type: 'meta';
|
|
148
|
+
schema?: CollectionSchema<Schema, {
|
|
149
|
+
path: string;
|
|
150
|
+
source: string;
|
|
151
|
+
}>;
|
|
156
152
|
}
|
|
157
|
-
interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection
|
|
153
|
+
interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
|
|
158
154
|
type: 'doc';
|
|
159
155
|
mdxOptions?: MDXOptions;
|
|
160
156
|
/**
|
|
161
157
|
* Load files with async
|
|
162
158
|
*/
|
|
163
159
|
async?: Async;
|
|
160
|
+
schema?: CollectionSchema<Schema, {
|
|
161
|
+
path: string;
|
|
162
|
+
source: string;
|
|
163
|
+
}>;
|
|
164
164
|
}
|
|
165
165
|
interface DocsCollection<DocSchema extends StandardSchemaV1 = StandardSchemaV1, MetaSchema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> {
|
|
166
166
|
type: 'docs';
|
|
@@ -205,4 +205,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
|
|
|
205
205
|
};
|
|
206
206
|
declare function defineConfig(config?: GlobalConfig): GlobalConfig;
|
|
207
207
|
|
|
208
|
-
export { type BaseCollectionEntry as B, type DocCollection as D, type FileInfo as F, type GlobalConfig as G, type MarkdownProps as M, type
|
|
208
|
+
export { type BaseCollectionEntry as B, type CollectionSchema as C, type DocCollection as D, type FileInfo as F, type GlobalConfig as G, type MarkdownProps as M, type BaseCollection as a, type MetaCollection as b, type DocsCollection as c, defineCollections as d, defineDocs as e, frontmatterSchema as f, defineConfig as g, type DefaultMDXOptions as h, getDefaultMDXOptions as i, metaSchema as m };
|
|
@@ -130,15 +130,8 @@ declare const frontmatterSchema: z.ZodObject<{
|
|
|
130
130
|
_openapi?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
131
131
|
}>;
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
source: string;
|
|
136
|
-
/**
|
|
137
|
-
* Compile MDX to JavaScript
|
|
138
|
-
*/
|
|
139
|
-
buildMDX: (source: string, options?: ProcessorOptions) => Promise<string>;
|
|
140
|
-
}
|
|
141
|
-
interface BaseCollection<Schema> {
|
|
133
|
+
type CollectionSchema<Schema extends StandardSchemaV1, Context> = Schema | ((ctx: Context) => Schema);
|
|
134
|
+
interface BaseCollection {
|
|
142
135
|
/**
|
|
143
136
|
* Directories to scan
|
|
144
137
|
*/
|
|
@@ -149,18 +142,25 @@ interface BaseCollection<Schema> {
|
|
|
149
142
|
* Include all files if not specified
|
|
150
143
|
*/
|
|
151
144
|
files?: string[];
|
|
152
|
-
schema?: Schema | ((ctx: TransformContext) => Schema);
|
|
153
145
|
}
|
|
154
|
-
interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> extends BaseCollection
|
|
146
|
+
interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> extends BaseCollection {
|
|
155
147
|
type: 'meta';
|
|
148
|
+
schema?: CollectionSchema<Schema, {
|
|
149
|
+
path: string;
|
|
150
|
+
source: string;
|
|
151
|
+
}>;
|
|
156
152
|
}
|
|
157
|
-
interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection
|
|
153
|
+
interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
|
|
158
154
|
type: 'doc';
|
|
159
155
|
mdxOptions?: MDXOptions;
|
|
160
156
|
/**
|
|
161
157
|
* Load files with async
|
|
162
158
|
*/
|
|
163
159
|
async?: Async;
|
|
160
|
+
schema?: CollectionSchema<Schema, {
|
|
161
|
+
path: string;
|
|
162
|
+
source: string;
|
|
163
|
+
}>;
|
|
164
164
|
}
|
|
165
165
|
interface DocsCollection<DocSchema extends StandardSchemaV1 = StandardSchemaV1, MetaSchema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> {
|
|
166
166
|
type: 'docs';
|
|
@@ -205,4 +205,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
|
|
|
205
205
|
};
|
|
206
206
|
declare function defineConfig(config?: GlobalConfig): GlobalConfig;
|
|
207
207
|
|
|
208
|
-
export { type BaseCollectionEntry as B, type DocCollection as D, type FileInfo as F, type GlobalConfig as G, type MarkdownProps as M, type
|
|
208
|
+
export { type BaseCollectionEntry as B, type CollectionSchema as C, type DocCollection as D, type FileInfo as F, type GlobalConfig as G, type MarkdownProps as M, type BaseCollection as a, type MetaCollection as b, type DocsCollection as c, defineCollections as d, defineDocs as e, frontmatterSchema as f, defineConfig as g, type DefaultMDXOptions as h, getDefaultMDXOptions as i, metaSchema as m };
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
|
|
2
|
-
import { B as BaseCollectionEntry } from './define-
|
|
3
|
-
import { R as Runtime } from './types-
|
|
4
|
-
export { a as RuntimeFile } from './types-
|
|
2
|
+
import { B as BaseCollectionEntry } from './define-DxwgTgV6.cjs';
|
|
3
|
+
import { R as Runtime } from './types-8ecOBKxa.cjs';
|
|
4
|
+
export { a as RuntimeFile } from './types-8ecOBKxa.cjs';
|
|
5
5
|
import '@mdx-js/mdx';
|
|
6
6
|
import 'mdx/types';
|
|
7
7
|
import 'fumadocs-core/mdx-plugins';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
|
|
2
|
-
import { B as BaseCollectionEntry } from './define-
|
|
3
|
-
import { R as Runtime } from './types-
|
|
4
|
-
export { a as RuntimeFile } from './types-
|
|
2
|
+
import { B as BaseCollectionEntry } from './define-DxwgTgV6.js';
|
|
3
|
+
import { R as Runtime } from './types-BQ1vyPw8.js';
|
|
4
|
+
export { a as RuntimeFile } from './types-BQ1vyPw8.js';
|
|
5
5
|
import '@mdx-js/mdx';
|
|
6
6
|
import 'mdx/types';
|
|
7
7
|
import 'fumadocs-core/mdx-plugins';
|
package/dist/index.js
CHANGED
package/dist/loader-mdx.cjs
CHANGED
|
@@ -222,7 +222,7 @@ function buildConfig(config) {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
// src/utils/config.ts
|
|
225
|
-
var cache =
|
|
225
|
+
var cache = null;
|
|
226
226
|
async function compileConfig(configPath) {
|
|
227
227
|
const { build } = await import("esbuild");
|
|
228
228
|
const transformed = await build({
|
|
@@ -244,9 +244,8 @@ async function compileConfig(configPath) {
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
async function loadConfig(configPath, hash, build = false) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return await cached.config;
|
|
247
|
+
if (cache && cache.hash === hash) {
|
|
248
|
+
return await cache.config;
|
|
250
249
|
}
|
|
251
250
|
if (build) await compileConfig(configPath);
|
|
252
251
|
const url = (0, import_node_url.pathToFileURL)(path.resolve(".source/source.config.mjs"));
|
|
@@ -258,7 +257,7 @@ async function loadConfig(configPath, hash, build = false) {
|
|
|
258
257
|
if (err !== null) throw new Error(err);
|
|
259
258
|
return config2;
|
|
260
259
|
});
|
|
261
|
-
cache
|
|
260
|
+
cache = { config, hash };
|
|
262
261
|
return await config;
|
|
263
262
|
}
|
|
264
263
|
async function getConfigHash(configPath) {
|
|
@@ -355,12 +354,6 @@ async function buildMDX(cacheKey, source, options = {}) {
|
|
|
355
354
|
});
|
|
356
355
|
}
|
|
357
356
|
|
|
358
|
-
// src/utils/format-error.ts
|
|
359
|
-
function formatError(message, issues) {
|
|
360
|
-
return `${message}:
|
|
361
|
-
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
357
|
// src/utils/git-timestamp.ts
|
|
365
358
|
var import_node_path = __toESM(require("path"), 1);
|
|
366
359
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
@@ -389,6 +382,44 @@ function getGitTimestamp(file) {
|
|
|
389
382
|
});
|
|
390
383
|
}
|
|
391
384
|
|
|
385
|
+
// src/utils/schema.ts
|
|
386
|
+
var import_zod = require("zod");
|
|
387
|
+
var metaSchema = import_zod.z.object({
|
|
388
|
+
title: import_zod.z.string().optional(),
|
|
389
|
+
pages: import_zod.z.array(import_zod.z.string()).optional(),
|
|
390
|
+
description: import_zod.z.string().optional(),
|
|
391
|
+
root: import_zod.z.boolean().optional(),
|
|
392
|
+
defaultOpen: import_zod.z.boolean().optional(),
|
|
393
|
+
icon: import_zod.z.string().optional()
|
|
394
|
+
});
|
|
395
|
+
var frontmatterSchema = import_zod.z.object({
|
|
396
|
+
title: import_zod.z.string(),
|
|
397
|
+
description: import_zod.z.string().optional(),
|
|
398
|
+
icon: import_zod.z.string().optional(),
|
|
399
|
+
full: import_zod.z.boolean().optional(),
|
|
400
|
+
// Fumadocs OpenAPI generated
|
|
401
|
+
_openapi: import_zod.z.object({}).passthrough().optional()
|
|
402
|
+
});
|
|
403
|
+
async function validate(schema, data, context, errorMessage) {
|
|
404
|
+
if (typeof schema === "function" && !("~standard" in schema)) {
|
|
405
|
+
schema = schema(context);
|
|
406
|
+
}
|
|
407
|
+
if ("~standard" in schema) {
|
|
408
|
+
const result = await schema["~standard"].validate(
|
|
409
|
+
data
|
|
410
|
+
);
|
|
411
|
+
if (result.issues) {
|
|
412
|
+
throw new Error(formatError(errorMessage, result.issues));
|
|
413
|
+
}
|
|
414
|
+
return result.value;
|
|
415
|
+
}
|
|
416
|
+
return data;
|
|
417
|
+
}
|
|
418
|
+
function formatError(message, issues) {
|
|
419
|
+
return `${message}:
|
|
420
|
+
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`;
|
|
421
|
+
}
|
|
422
|
+
|
|
392
423
|
// src/loader-mdx.ts
|
|
393
424
|
function parseQuery(query) {
|
|
394
425
|
let collection;
|
|
@@ -417,35 +448,15 @@ async function loader(source, callback) {
|
|
|
417
448
|
}
|
|
418
449
|
const mdxOptions = collection?.mdxOptions ?? await config.getDefaultMDXOptions();
|
|
419
450
|
if (collection?.schema) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const res = await buildMDX(
|
|
425
|
-
`${configHash}:${collectionId ?? "global"}`,
|
|
426
|
-
v,
|
|
427
|
-
options
|
|
428
|
-
);
|
|
429
|
-
return String(res.value);
|
|
430
|
-
},
|
|
451
|
+
matter2.data = await validate(
|
|
452
|
+
collection.schema,
|
|
453
|
+
matter2.data,
|
|
454
|
+
{
|
|
431
455
|
source,
|
|
432
456
|
path: filePath
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const result = await schema["~standard"].validate(
|
|
437
|
-
matter2.data
|
|
438
|
-
);
|
|
439
|
-
if (result.issues) {
|
|
440
|
-
callback(
|
|
441
|
-
new Error(
|
|
442
|
-
formatError(`invalid frontmatter in ${filePath}:`, result.issues)
|
|
443
|
-
)
|
|
444
|
-
);
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
matter2.data = result.value;
|
|
448
|
-
}
|
|
457
|
+
},
|
|
458
|
+
`invalid frontmatter in ${filePath}:`
|
|
459
|
+
);
|
|
449
460
|
}
|
|
450
461
|
let timestamp;
|
|
451
462
|
if (config.global?.lastModifiedTime === "git")
|
package/dist/loader-mdx.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getConfigHash,
|
|
3
3
|
loadConfig
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2FUWXPXA.js";
|
|
5
|
+
import {
|
|
6
|
+
validate
|
|
7
|
+
} from "./chunk-KGLACICA.js";
|
|
5
8
|
import {
|
|
6
9
|
remarkInclude
|
|
7
10
|
} from "./chunk-PY2KKTR2.js";
|
|
@@ -45,12 +48,6 @@ async function buildMDX(cacheKey, source, options = {}) {
|
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
// src/utils/format-error.ts
|
|
49
|
-
function formatError(message, issues) {
|
|
50
|
-
return `${message}:
|
|
51
|
-
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
51
|
// src/utils/git-timestamp.ts
|
|
55
52
|
import path from "node:path";
|
|
56
53
|
import fs from "node:fs";
|
|
@@ -107,35 +104,15 @@ async function loader(source, callback) {
|
|
|
107
104
|
}
|
|
108
105
|
const mdxOptions = collection?.mdxOptions ?? await config.getDefaultMDXOptions();
|
|
109
106
|
if (collection?.schema) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const res = await buildMDX(
|
|
115
|
-
`${configHash}:${collectionId ?? "global"}`,
|
|
116
|
-
v,
|
|
117
|
-
options
|
|
118
|
-
);
|
|
119
|
-
return String(res.value);
|
|
120
|
-
},
|
|
107
|
+
matter.data = await validate(
|
|
108
|
+
collection.schema,
|
|
109
|
+
matter.data,
|
|
110
|
+
{
|
|
121
111
|
source,
|
|
122
112
|
path: filePath
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const result = await schema["~standard"].validate(
|
|
127
|
-
matter.data
|
|
128
|
-
);
|
|
129
|
-
if (result.issues) {
|
|
130
|
-
callback(
|
|
131
|
-
new Error(
|
|
132
|
-
formatError(`invalid frontmatter in ${filePath}:`, result.issues)
|
|
133
|
-
)
|
|
134
|
-
);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
matter.data = result.value;
|
|
138
|
-
}
|
|
113
|
+
},
|
|
114
|
+
`invalid frontmatter in ${filePath}:`
|
|
115
|
+
);
|
|
139
116
|
}
|
|
140
117
|
let timestamp;
|
|
141
118
|
if (config.global?.lastModifiedTime === "git")
|
package/dist/next/index.cjs
CHANGED
|
@@ -259,7 +259,7 @@ function buildConfig(config) {
|
|
|
259
259
|
function findConfigFile() {
|
|
260
260
|
return path.resolve("source.config.ts");
|
|
261
261
|
}
|
|
262
|
-
var cache =
|
|
262
|
+
var cache = null;
|
|
263
263
|
async function compileConfig(configPath) {
|
|
264
264
|
const { build } = await import("esbuild");
|
|
265
265
|
const transformed = await build({
|
|
@@ -281,9 +281,8 @@ async function compileConfig(configPath) {
|
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
async function loadConfig(configPath, hash, build = false) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return await cached.config;
|
|
284
|
+
if (cache && cache.hash === hash) {
|
|
285
|
+
return await cache.config;
|
|
287
286
|
}
|
|
288
287
|
if (build) await compileConfig(configPath);
|
|
289
288
|
const url = (0, import_node_url.pathToFileURL)(path.resolve(".source/source.config.mjs"));
|
|
@@ -295,7 +294,7 @@ async function loadConfig(configPath, hash, build = false) {
|
|
|
295
294
|
if (err !== null) throw new Error(err);
|
|
296
295
|
return config2;
|
|
297
296
|
});
|
|
298
|
-
cache
|
|
297
|
+
cache = { config, hash };
|
|
299
298
|
return await config;
|
|
300
299
|
}
|
|
301
300
|
async function getConfigHash(configPath) {
|
|
@@ -309,10 +308,11 @@ async function getConfigHash(configPath) {
|
|
|
309
308
|
|
|
310
309
|
// src/map/index.ts
|
|
311
310
|
var path3 = __toESM(require("path"), 1);
|
|
312
|
-
var
|
|
311
|
+
var fs4 = __toESM(require("fs/promises"), 1);
|
|
313
312
|
|
|
314
313
|
// src/map/generate.ts
|
|
315
314
|
var path2 = __toESM(require("path"), 1);
|
|
315
|
+
var fs3 = __toESM(require("fs/promises"), 1);
|
|
316
316
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
317
317
|
|
|
318
318
|
// src/utils/get-type-from-path.ts
|
|
@@ -325,8 +325,103 @@ function getTypeFromPath(path6) {
|
|
|
325
325
|
if (metaTypes.includes(ext)) return "meta";
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
+
// src/utils/schema.ts
|
|
329
|
+
var import_zod = require("zod");
|
|
330
|
+
var metaSchema = import_zod.z.object({
|
|
331
|
+
title: import_zod.z.string().optional(),
|
|
332
|
+
pages: import_zod.z.array(import_zod.z.string()).optional(),
|
|
333
|
+
description: import_zod.z.string().optional(),
|
|
334
|
+
root: import_zod.z.boolean().optional(),
|
|
335
|
+
defaultOpen: import_zod.z.boolean().optional(),
|
|
336
|
+
icon: import_zod.z.string().optional()
|
|
337
|
+
});
|
|
338
|
+
var frontmatterSchema = import_zod.z.object({
|
|
339
|
+
title: import_zod.z.string(),
|
|
340
|
+
description: import_zod.z.string().optional(),
|
|
341
|
+
icon: import_zod.z.string().optional(),
|
|
342
|
+
full: import_zod.z.boolean().optional(),
|
|
343
|
+
// Fumadocs OpenAPI generated
|
|
344
|
+
_openapi: import_zod.z.object({}).passthrough().optional()
|
|
345
|
+
});
|
|
346
|
+
async function validate(schema, data, context, errorMessage) {
|
|
347
|
+
if (typeof schema === "function" && !("~standard" in schema)) {
|
|
348
|
+
schema = schema(context);
|
|
349
|
+
}
|
|
350
|
+
if ("~standard" in schema) {
|
|
351
|
+
const result = await schema["~standard"].validate(
|
|
352
|
+
data
|
|
353
|
+
);
|
|
354
|
+
if (result.issues) {
|
|
355
|
+
throw new Error(formatError(errorMessage, result.issues));
|
|
356
|
+
}
|
|
357
|
+
return result.value;
|
|
358
|
+
}
|
|
359
|
+
return data;
|
|
360
|
+
}
|
|
361
|
+
function formatError(message, issues) {
|
|
362
|
+
return `${message}:
|
|
363
|
+
${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/map/file-cache.ts
|
|
367
|
+
var map = /* @__PURE__ */ new Map();
|
|
368
|
+
var fileCache = {
|
|
369
|
+
read(namespace, path6) {
|
|
370
|
+
return map.get(`${namespace}.${path6}}`);
|
|
371
|
+
},
|
|
372
|
+
write(namespace, path6, data) {
|
|
373
|
+
map.set(`${namespace}.${path6}}`, data);
|
|
374
|
+
},
|
|
375
|
+
removeCache(path6) {
|
|
376
|
+
for (const key of map.keys()) {
|
|
377
|
+
const keyPath = key.slice(key.indexOf(".") + 1);
|
|
378
|
+
if (keyPath === path6) map.delete(key);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// src/utils/read-frontmatter.ts
|
|
384
|
+
var fs2 = __toESM(require("fs"), 1);
|
|
385
|
+
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
386
|
+
async function readFrontmatter(file) {
|
|
387
|
+
const readStream = fs2.createReadStream(file, {
|
|
388
|
+
highWaterMark: 250
|
|
389
|
+
});
|
|
390
|
+
return new Promise((res, rej) => {
|
|
391
|
+
let idx = 0;
|
|
392
|
+
let str = "";
|
|
393
|
+
readStream.on("data", (_chunk) => {
|
|
394
|
+
const chunk = _chunk.toString();
|
|
395
|
+
if (idx === 0 && !chunk.startsWith("---")) {
|
|
396
|
+
res({});
|
|
397
|
+
readStream.close();
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
str += chunk;
|
|
401
|
+
idx++;
|
|
402
|
+
if (str.includes("\n---")) {
|
|
403
|
+
res(
|
|
404
|
+
(0, import_gray_matter.default)({
|
|
405
|
+
content: str
|
|
406
|
+
}).data
|
|
407
|
+
);
|
|
408
|
+
readStream.close();
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
readStream.on("end", () => res({}));
|
|
412
|
+
readStream.on("error", (e) => rej(e));
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
328
416
|
// src/map/generate.ts
|
|
329
|
-
async function
|
|
417
|
+
async function readFrontmatterWithCache(file) {
|
|
418
|
+
const cached = fileCache.read("read-frontmatter", file);
|
|
419
|
+
if (cached) return cached;
|
|
420
|
+
const res = await readFrontmatter(file);
|
|
421
|
+
fileCache.write("read-frontmatter", file, res);
|
|
422
|
+
return res;
|
|
423
|
+
}
|
|
424
|
+
async function generateJS(configPath, config, outputPath, configHash) {
|
|
330
425
|
const outDir2 = path2.dirname(outputPath);
|
|
331
426
|
let asyncInit = false;
|
|
332
427
|
const lines = [
|
|
@@ -346,7 +441,27 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
346
441
|
async function getEntries(collectionName, collection, files) {
|
|
347
442
|
const items = files.map(async (file, i) => {
|
|
348
443
|
config._runtime.files.set(file.absolutePath, collectionName);
|
|
349
|
-
|
|
444
|
+
if (collection.type === "meta") {
|
|
445
|
+
const cached = fileCache.read("generate-js", file.absolutePath);
|
|
446
|
+
if (cached) return cached;
|
|
447
|
+
const source = (await fs3.readFile(file.absolutePath)).toString();
|
|
448
|
+
let data = JSON.parse(source);
|
|
449
|
+
if (collection?.schema) {
|
|
450
|
+
data = await validate(
|
|
451
|
+
collection.schema,
|
|
452
|
+
data,
|
|
453
|
+
{
|
|
454
|
+
source,
|
|
455
|
+
path: file.absolutePath
|
|
456
|
+
},
|
|
457
|
+
`invalid data in ${file.absolutePath}:`
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
const entry = `{ info: ${JSON.stringify(file)}, data: ${JSON.stringify(data)} }`;
|
|
461
|
+
fileCache.write("generate-js", file.absolutePath, entry);
|
|
462
|
+
return entry;
|
|
463
|
+
}
|
|
464
|
+
const importId = `${collectionName}_${i}`;
|
|
350
465
|
lines.unshift(
|
|
351
466
|
getImportCode({
|
|
352
467
|
type: "namespace",
|
|
@@ -372,10 +487,9 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
372
487
|
asyncInit = true;
|
|
373
488
|
}
|
|
374
489
|
const entries2 = files.map(async (file) => {
|
|
375
|
-
const frontmatter = await getFrontmatter(file.absolutePath);
|
|
376
490
|
return JSON.stringify({
|
|
377
491
|
info: file,
|
|
378
|
-
data:
|
|
492
|
+
data: await readFrontmatterWithCache(file.absolutePath)
|
|
379
493
|
});
|
|
380
494
|
});
|
|
381
495
|
return Promise.all(entries2);
|
|
@@ -384,19 +498,16 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
384
498
|
if (collection.type === "docs") {
|
|
385
499
|
const docs = await getCollectionFiles(collection.docs);
|
|
386
500
|
const metas = await getCollectionFiles(collection.meta);
|
|
501
|
+
const metaEntries = (await getEntries(k, collection.meta, metas)).join(
|
|
502
|
+
", "
|
|
503
|
+
);
|
|
387
504
|
if (collection.docs.async) {
|
|
388
505
|
const docsEntries2 = (await getAsyncEntries(docs)).join(", ");
|
|
389
|
-
const
|
|
390
|
-
", "
|
|
391
|
-
);
|
|
392
|
-
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries2}], "${k}", _sourceConfig)`;
|
|
506
|
+
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
|
|
393
507
|
}
|
|
394
508
|
const docsEntries = (await getEntries(k, collection.docs, docs)).join(
|
|
395
509
|
", "
|
|
396
510
|
);
|
|
397
|
-
const metaEntries = (await getEntries(k, collection.meta, metas)).join(
|
|
398
|
-
", "
|
|
399
|
-
);
|
|
400
511
|
return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
|
|
401
512
|
}
|
|
402
513
|
const files = await getCollectionFiles(collection);
|
|
@@ -457,72 +568,23 @@ function toImportPath(file, dir) {
|
|
|
457
568
|
return importPath.replaceAll(path2.sep, "/");
|
|
458
569
|
}
|
|
459
570
|
|
|
460
|
-
// src/utils/read-frontmatter.ts
|
|
461
|
-
var fs2 = __toESM(require("fs"), 1);
|
|
462
|
-
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
463
|
-
async function readFrontmatter(file) {
|
|
464
|
-
const readStream = fs2.createReadStream(file, {
|
|
465
|
-
highWaterMark: 250
|
|
466
|
-
});
|
|
467
|
-
return new Promise((res, rej) => {
|
|
468
|
-
let idx = 0;
|
|
469
|
-
let str = "";
|
|
470
|
-
readStream.on("data", (_chunk) => {
|
|
471
|
-
const chunk = _chunk.toString();
|
|
472
|
-
if (idx === 0 && !chunk.startsWith("---")) {
|
|
473
|
-
res({});
|
|
474
|
-
readStream.close();
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
str += chunk;
|
|
478
|
-
idx++;
|
|
479
|
-
if (str.includes("\n---")) {
|
|
480
|
-
res(
|
|
481
|
-
(0, import_gray_matter.default)({
|
|
482
|
-
content: str
|
|
483
|
-
}).data
|
|
484
|
-
);
|
|
485
|
-
readStream.close();
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
readStream.on("end", () => res({}));
|
|
489
|
-
readStream.on("error", (e) => rej(e));
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
|
|
493
571
|
// src/map/index.ts
|
|
494
572
|
async function start(dev, configPath, outDir2) {
|
|
495
|
-
void
|
|
496
|
-
void
|
|
497
|
-
await
|
|
573
|
+
void fs4.rm(path3.resolve(outDir2, `index.js`), { force: true });
|
|
574
|
+
void fs4.rm(path3.resolve(outDir2, `index.d.ts`), { force: true });
|
|
575
|
+
await fs4.mkdir(outDir2, { recursive: true });
|
|
498
576
|
let configHash = await getConfigHash(configPath);
|
|
499
577
|
let config = await loadConfig(configPath, configHash, true);
|
|
500
578
|
const outPath = path3.resolve(outDir2, `index.ts`);
|
|
501
|
-
const frontmatterCache = /* @__PURE__ */ new Map();
|
|
502
|
-
let hookUpdate = false;
|
|
503
|
-
async function readFrontmatterWithCache(file) {
|
|
504
|
-
hookUpdate = true;
|
|
505
|
-
const cached = frontmatterCache.get(file);
|
|
506
|
-
if (cached) return cached;
|
|
507
|
-
const res = await readFrontmatter(file);
|
|
508
|
-
frontmatterCache.set(file, res);
|
|
509
|
-
return res;
|
|
510
|
-
}
|
|
511
579
|
async function updateMapFile() {
|
|
512
|
-
|
|
580
|
+
console.time(`[MDX] update map file`);
|
|
581
|
+
await fs4.writeFile(
|
|
513
582
|
outPath,
|
|
514
|
-
await generateJS(
|
|
515
|
-
configPath,
|
|
516
|
-
config,
|
|
517
|
-
outPath,
|
|
518
|
-
configHash,
|
|
519
|
-
readFrontmatterWithCache
|
|
520
|
-
)
|
|
583
|
+
await generateJS(configPath, config, outPath, configHash)
|
|
521
584
|
);
|
|
585
|
+
console.timeEnd(`[MDX] update map file`);
|
|
522
586
|
}
|
|
523
|
-
console.time(`[MDX] initialize map file`);
|
|
524
587
|
await updateMapFile();
|
|
525
|
-
console.timeEnd(`[MDX] initialize map file`);
|
|
526
588
|
if (dev) {
|
|
527
589
|
const { watcher: watcher2 } = await Promise.resolve().then(() => (init_watcher(), watcher_exports));
|
|
528
590
|
const instance = watcher2(configPath, config);
|
|
@@ -531,17 +593,15 @@ async function start(dev, configPath, outDir2) {
|
|
|
531
593
|
});
|
|
532
594
|
instance.on("all", (event, file) => {
|
|
533
595
|
if (typeof file !== "string") return;
|
|
596
|
+
const absolutePath = path3.resolve(file);
|
|
534
597
|
const onUpdate = async () => {
|
|
535
|
-
const isConfigFile =
|
|
598
|
+
const isConfigFile = absolutePath === configPath;
|
|
536
599
|
if (isConfigFile) {
|
|
537
600
|
configHash = await getConfigHash(configPath);
|
|
538
601
|
config = await loadConfig(configPath, configHash, true);
|
|
539
602
|
}
|
|
540
|
-
if (
|
|
541
|
-
|
|
542
|
-
await updateMapFile();
|
|
543
|
-
console.log("[MDX] Updated map file");
|
|
544
|
-
}
|
|
603
|
+
if (event === "change") fileCache.removeCache(absolutePath);
|
|
604
|
+
await updateMapFile();
|
|
545
605
|
};
|
|
546
606
|
void onUpdate();
|
|
547
607
|
});
|
|
@@ -615,20 +675,19 @@ function createMDX({
|
|
|
615
675
|
|
|
616
676
|
// src/postinstall.ts
|
|
617
677
|
var path5 = __toESM(require("path"), 1);
|
|
618
|
-
var
|
|
678
|
+
var fs5 = __toESM(require("fs"), 1);
|
|
619
679
|
async function postInstall(configPath = findConfigFile()) {
|
|
620
680
|
const jsOut = path5.resolve(".source/index.ts");
|
|
621
681
|
const hash = await getConfigHash(configPath);
|
|
622
682
|
const config = await loadConfig(configPath, hash, true);
|
|
623
|
-
|
|
624
|
-
|
|
683
|
+
fs5.mkdirSync(path5.dirname(jsOut), { recursive: true });
|
|
684
|
+
fs5.writeFileSync(
|
|
625
685
|
jsOut,
|
|
626
686
|
await generateJS(
|
|
627
687
|
configPath,
|
|
628
688
|
config,
|
|
629
689
|
path5.resolve(".source/index.ts"),
|
|
630
|
-
hash
|
|
631
|
-
readFrontmatter
|
|
690
|
+
hash
|
|
632
691
|
)
|
|
633
692
|
);
|
|
634
693
|
console.log("[MDX] types generated");
|
package/dist/next/index.js
CHANGED
|
@@ -2,7 +2,10 @@ import {
|
|
|
2
2
|
findConfigFile,
|
|
3
3
|
getConfigHash,
|
|
4
4
|
loadConfig
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-2FUWXPXA.js";
|
|
6
|
+
import {
|
|
7
|
+
validate
|
|
8
|
+
} from "../chunk-KGLACICA.js";
|
|
6
9
|
import "../chunk-6ZVE73IT.js";
|
|
7
10
|
|
|
8
11
|
// src/next/create.ts
|
|
@@ -10,10 +13,11 @@ import path3 from "node:path";
|
|
|
10
13
|
|
|
11
14
|
// src/map/index.ts
|
|
12
15
|
import * as path2 from "node:path";
|
|
13
|
-
import * as
|
|
16
|
+
import * as fs3 from "node:fs/promises";
|
|
14
17
|
|
|
15
18
|
// src/map/generate.ts
|
|
16
19
|
import * as path from "node:path";
|
|
20
|
+
import * as fs2 from "node:fs/promises";
|
|
17
21
|
import fg from "fast-glob";
|
|
18
22
|
|
|
19
23
|
// src/utils/get-type-from-path.ts
|
|
@@ -26,8 +30,65 @@ function getTypeFromPath(path5) {
|
|
|
26
30
|
if (metaTypes.includes(ext)) return "meta";
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
// src/map/file-cache.ts
|
|
34
|
+
var map = /* @__PURE__ */ new Map();
|
|
35
|
+
var fileCache = {
|
|
36
|
+
read(namespace, path5) {
|
|
37
|
+
return map.get(`${namespace}.${path5}}`);
|
|
38
|
+
},
|
|
39
|
+
write(namespace, path5, data) {
|
|
40
|
+
map.set(`${namespace}.${path5}}`, data);
|
|
41
|
+
},
|
|
42
|
+
removeCache(path5) {
|
|
43
|
+
for (const key of map.keys()) {
|
|
44
|
+
const keyPath = key.slice(key.indexOf(".") + 1);
|
|
45
|
+
if (keyPath === path5) map.delete(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/utils/read-frontmatter.ts
|
|
51
|
+
import * as fs from "node:fs";
|
|
52
|
+
import grayMatter from "gray-matter";
|
|
53
|
+
async function readFrontmatter(file) {
|
|
54
|
+
const readStream = fs.createReadStream(file, {
|
|
55
|
+
highWaterMark: 250
|
|
56
|
+
});
|
|
57
|
+
return new Promise((res, rej) => {
|
|
58
|
+
let idx = 0;
|
|
59
|
+
let str = "";
|
|
60
|
+
readStream.on("data", (_chunk) => {
|
|
61
|
+
const chunk = _chunk.toString();
|
|
62
|
+
if (idx === 0 && !chunk.startsWith("---")) {
|
|
63
|
+
res({});
|
|
64
|
+
readStream.close();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
str += chunk;
|
|
68
|
+
idx++;
|
|
69
|
+
if (str.includes("\n---")) {
|
|
70
|
+
res(
|
|
71
|
+
grayMatter({
|
|
72
|
+
content: str
|
|
73
|
+
}).data
|
|
74
|
+
);
|
|
75
|
+
readStream.close();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
readStream.on("end", () => res({}));
|
|
79
|
+
readStream.on("error", (e) => rej(e));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
29
83
|
// src/map/generate.ts
|
|
30
|
-
async function
|
|
84
|
+
async function readFrontmatterWithCache(file) {
|
|
85
|
+
const cached = fileCache.read("read-frontmatter", file);
|
|
86
|
+
if (cached) return cached;
|
|
87
|
+
const res = await readFrontmatter(file);
|
|
88
|
+
fileCache.write("read-frontmatter", file, res);
|
|
89
|
+
return res;
|
|
90
|
+
}
|
|
91
|
+
async function generateJS(configPath, config, outputPath, configHash) {
|
|
31
92
|
const outDir2 = path.dirname(outputPath);
|
|
32
93
|
let asyncInit = false;
|
|
33
94
|
const lines = [
|
|
@@ -47,7 +108,27 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
47
108
|
async function getEntries(collectionName, collection, files) {
|
|
48
109
|
const items = files.map(async (file, i) => {
|
|
49
110
|
config._runtime.files.set(file.absolutePath, collectionName);
|
|
50
|
-
|
|
111
|
+
if (collection.type === "meta") {
|
|
112
|
+
const cached = fileCache.read("generate-js", file.absolutePath);
|
|
113
|
+
if (cached) return cached;
|
|
114
|
+
const source = (await fs2.readFile(file.absolutePath)).toString();
|
|
115
|
+
let data = JSON.parse(source);
|
|
116
|
+
if (collection?.schema) {
|
|
117
|
+
data = await validate(
|
|
118
|
+
collection.schema,
|
|
119
|
+
data,
|
|
120
|
+
{
|
|
121
|
+
source,
|
|
122
|
+
path: file.absolutePath
|
|
123
|
+
},
|
|
124
|
+
`invalid data in ${file.absolutePath}:`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
const entry = `{ info: ${JSON.stringify(file)}, data: ${JSON.stringify(data)} }`;
|
|
128
|
+
fileCache.write("generate-js", file.absolutePath, entry);
|
|
129
|
+
return entry;
|
|
130
|
+
}
|
|
131
|
+
const importId = `${collectionName}_${i}`;
|
|
51
132
|
lines.unshift(
|
|
52
133
|
getImportCode({
|
|
53
134
|
type: "namespace",
|
|
@@ -73,10 +154,9 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
73
154
|
asyncInit = true;
|
|
74
155
|
}
|
|
75
156
|
const entries2 = files.map(async (file) => {
|
|
76
|
-
const frontmatter = await getFrontmatter(file.absolutePath);
|
|
77
157
|
return JSON.stringify({
|
|
78
158
|
info: file,
|
|
79
|
-
data:
|
|
159
|
+
data: await readFrontmatterWithCache(file.absolutePath)
|
|
80
160
|
});
|
|
81
161
|
});
|
|
82
162
|
return Promise.all(entries2);
|
|
@@ -85,19 +165,16 @@ async function generateJS(configPath, config, outputPath, configHash, getFrontma
|
|
|
85
165
|
if (collection.type === "docs") {
|
|
86
166
|
const docs = await getCollectionFiles(collection.docs);
|
|
87
167
|
const metas = await getCollectionFiles(collection.meta);
|
|
168
|
+
const metaEntries = (await getEntries(k, collection.meta, metas)).join(
|
|
169
|
+
", "
|
|
170
|
+
);
|
|
88
171
|
if (collection.docs.async) {
|
|
89
172
|
const docsEntries2 = (await getAsyncEntries(docs)).join(", ");
|
|
90
|
-
const
|
|
91
|
-
", "
|
|
92
|
-
);
|
|
93
|
-
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries2}], "${k}", _sourceConfig)`;
|
|
173
|
+
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
|
|
94
174
|
}
|
|
95
175
|
const docsEntries = (await getEntries(k, collection.docs, docs)).join(
|
|
96
176
|
", "
|
|
97
177
|
);
|
|
98
|
-
const metaEntries = (await getEntries(k, collection.meta, metas)).join(
|
|
99
|
-
", "
|
|
100
|
-
);
|
|
101
178
|
return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
|
|
102
179
|
}
|
|
103
180
|
const files = await getCollectionFiles(collection);
|
|
@@ -158,72 +235,23 @@ function toImportPath(file, dir) {
|
|
|
158
235
|
return importPath.replaceAll(path.sep, "/");
|
|
159
236
|
}
|
|
160
237
|
|
|
161
|
-
// src/utils/read-frontmatter.ts
|
|
162
|
-
import * as fs from "node:fs";
|
|
163
|
-
import grayMatter from "gray-matter";
|
|
164
|
-
async function readFrontmatter(file) {
|
|
165
|
-
const readStream = fs.createReadStream(file, {
|
|
166
|
-
highWaterMark: 250
|
|
167
|
-
});
|
|
168
|
-
return new Promise((res, rej) => {
|
|
169
|
-
let idx = 0;
|
|
170
|
-
let str = "";
|
|
171
|
-
readStream.on("data", (_chunk) => {
|
|
172
|
-
const chunk = _chunk.toString();
|
|
173
|
-
if (idx === 0 && !chunk.startsWith("---")) {
|
|
174
|
-
res({});
|
|
175
|
-
readStream.close();
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
str += chunk;
|
|
179
|
-
idx++;
|
|
180
|
-
if (str.includes("\n---")) {
|
|
181
|
-
res(
|
|
182
|
-
grayMatter({
|
|
183
|
-
content: str
|
|
184
|
-
}).data
|
|
185
|
-
);
|
|
186
|
-
readStream.close();
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
readStream.on("end", () => res({}));
|
|
190
|
-
readStream.on("error", (e) => rej(e));
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
238
|
// src/map/index.ts
|
|
195
239
|
async function start(dev, configPath, outDir2) {
|
|
196
|
-
void
|
|
197
|
-
void
|
|
198
|
-
await
|
|
240
|
+
void fs3.rm(path2.resolve(outDir2, `index.js`), { force: true });
|
|
241
|
+
void fs3.rm(path2.resolve(outDir2, `index.d.ts`), { force: true });
|
|
242
|
+
await fs3.mkdir(outDir2, { recursive: true });
|
|
199
243
|
let configHash = await getConfigHash(configPath);
|
|
200
244
|
let config = await loadConfig(configPath, configHash, true);
|
|
201
245
|
const outPath = path2.resolve(outDir2, `index.ts`);
|
|
202
|
-
const frontmatterCache = /* @__PURE__ */ new Map();
|
|
203
|
-
let hookUpdate = false;
|
|
204
|
-
async function readFrontmatterWithCache(file) {
|
|
205
|
-
hookUpdate = true;
|
|
206
|
-
const cached = frontmatterCache.get(file);
|
|
207
|
-
if (cached) return cached;
|
|
208
|
-
const res = await readFrontmatter(file);
|
|
209
|
-
frontmatterCache.set(file, res);
|
|
210
|
-
return res;
|
|
211
|
-
}
|
|
212
246
|
async function updateMapFile() {
|
|
213
|
-
|
|
247
|
+
console.time(`[MDX] update map file`);
|
|
248
|
+
await fs3.writeFile(
|
|
214
249
|
outPath,
|
|
215
|
-
await generateJS(
|
|
216
|
-
configPath,
|
|
217
|
-
config,
|
|
218
|
-
outPath,
|
|
219
|
-
configHash,
|
|
220
|
-
readFrontmatterWithCache
|
|
221
|
-
)
|
|
250
|
+
await generateJS(configPath, config, outPath, configHash)
|
|
222
251
|
);
|
|
252
|
+
console.timeEnd(`[MDX] update map file`);
|
|
223
253
|
}
|
|
224
|
-
console.time(`[MDX] initialize map file`);
|
|
225
254
|
await updateMapFile();
|
|
226
|
-
console.timeEnd(`[MDX] initialize map file`);
|
|
227
255
|
if (dev) {
|
|
228
256
|
const { watcher } = await import("../watcher-IAZDSTU7.js");
|
|
229
257
|
const instance = watcher(configPath, config);
|
|
@@ -232,17 +260,15 @@ async function start(dev, configPath, outDir2) {
|
|
|
232
260
|
});
|
|
233
261
|
instance.on("all", (event, file) => {
|
|
234
262
|
if (typeof file !== "string") return;
|
|
263
|
+
const absolutePath = path2.resolve(file);
|
|
235
264
|
const onUpdate = async () => {
|
|
236
|
-
const isConfigFile =
|
|
265
|
+
const isConfigFile = absolutePath === configPath;
|
|
237
266
|
if (isConfigFile) {
|
|
238
267
|
configHash = await getConfigHash(configPath);
|
|
239
268
|
config = await loadConfig(configPath, configHash, true);
|
|
240
269
|
}
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
await updateMapFile();
|
|
244
|
-
console.log("[MDX] Updated map file");
|
|
245
|
-
}
|
|
270
|
+
if (event === "change") fileCache.removeCache(absolutePath);
|
|
271
|
+
await updateMapFile();
|
|
246
272
|
};
|
|
247
273
|
void onUpdate();
|
|
248
274
|
});
|
|
@@ -316,20 +342,19 @@ function createMDX({
|
|
|
316
342
|
|
|
317
343
|
// src/postinstall.ts
|
|
318
344
|
import * as path4 from "node:path";
|
|
319
|
-
import * as
|
|
345
|
+
import * as fs4 from "node:fs";
|
|
320
346
|
async function postInstall(configPath = findConfigFile()) {
|
|
321
347
|
const jsOut = path4.resolve(".source/index.ts");
|
|
322
348
|
const hash = await getConfigHash(configPath);
|
|
323
349
|
const config = await loadConfig(configPath, hash, true);
|
|
324
|
-
|
|
325
|
-
|
|
350
|
+
fs4.mkdirSync(path4.dirname(jsOut), { recursive: true });
|
|
351
|
+
fs4.writeFileSync(
|
|
326
352
|
jsOut,
|
|
327
353
|
await generateJS(
|
|
328
354
|
configPath,
|
|
329
355
|
config,
|
|
330
356
|
path4.resolve(".source/index.ts"),
|
|
331
|
-
hash
|
|
332
|
-
readFrontmatter
|
|
357
|
+
hash
|
|
333
358
|
)
|
|
334
359
|
);
|
|
335
360
|
console.log("[MDX] types generated");
|
package/dist/runtime/async.cjs
CHANGED
package/dist/runtime/async.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LoadedConfig, b as RuntimeAsync } from '../types-
|
|
2
|
-
import '../define-
|
|
1
|
+
import { L as LoadedConfig, b as RuntimeAsync } from '../types-8ecOBKxa.cjs';
|
|
2
|
+
import '../define-DxwgTgV6.cjs';
|
|
3
3
|
import '@mdx-js/mdx';
|
|
4
4
|
import 'mdx/types';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
package/dist/runtime/async.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LoadedConfig, b as RuntimeAsync } from '../types-
|
|
2
|
-
import '../define-
|
|
1
|
+
import { L as LoadedConfig, b as RuntimeAsync } from '../types-BQ1vyPw8.js';
|
|
2
|
+
import '../define-DxwgTgV6.js';
|
|
3
3
|
import '@mdx-js/mdx';
|
|
4
4
|
import 'mdx/types';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
package/dist/runtime/async.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-
|
|
1
|
+
import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-DxwgTgV6.cjs';
|
|
2
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
import { Source, PageData, MetaData } from 'fumadocs-core/source';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-
|
|
1
|
+
import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-DxwgTgV6.js';
|
|
2
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
import { Source, PageData, MetaData } from 'fumadocs-core/source';
|
|
4
4
|
import { ProcessorOptions } from '@mdx-js/mdx';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-mdx",
|
|
3
|
-
"version": "11.5.
|
|
3
|
+
"version": "11.5.4",
|
|
4
4
|
"description": "The built-in source for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@standard-schema/spec": "^1.0.0",
|
|
47
47
|
"chokidar": "^4.0.3",
|
|
48
48
|
"cross-spawn": "^7.0.6",
|
|
49
|
-
"esbuild": "^0.
|
|
49
|
+
"esbuild": "^0.25.0",
|
|
50
50
|
"estree-util-value-to-estree": "^3.3.2",
|
|
51
51
|
"fast-glob": "^3.3.3",
|
|
52
52
|
"gray-matter": "^4.0.3",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"vfile": "^6.0.3",
|
|
65
65
|
"webpack": "^5.97.1",
|
|
66
66
|
"@fumadocs/mdx-remote": "1.2.0",
|
|
67
|
-
"
|
|
68
|
-
"fumadocs-core": "15.0.
|
|
69
|
-
"
|
|
67
|
+
"eslint-config-custom": "0.0.0",
|
|
68
|
+
"fumadocs-core": "15.0.7",
|
|
69
|
+
"tsconfig": "0.0.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@fumadocs/mdx-remote": "^1.2.0",
|