fumadocs-mdx 11.9.1 → 11.10.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.
- package/dist/bin.cjs +1063 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +16 -0
- package/dist/{browser-CyU2Yl7A.d.cts → browser-B2G8uAF2.d.cts} +1 -1
- package/dist/{browser-DEsQvNRx.d.ts → browser-DrH7tKRi.d.ts} +1 -1
- package/dist/bun/index.cjs +669 -0
- package/dist/bun/index.d.cts +8 -0
- package/dist/bun/index.d.ts +8 -0
- package/dist/bun/index.js +53 -0
- package/dist/chunk-6Y5JDZHD.js +65 -0
- package/dist/chunk-CNKI574E.js +82 -0
- package/dist/{chunk-GX3THK2Q.js → chunk-IQAEAI4P.js} +25 -25
- package/dist/chunk-QJCCVMBJ.js +151 -0
- package/dist/{chunk-NUDEC6C5.js → chunk-UOOPSLFY.js} +1 -1
- package/dist/{chunk-COQ4VMK2.js → chunk-XXSKWWMB.js} +28 -61
- package/dist/config/index.d.cts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/zod-3.d.cts +1 -1
- package/dist/config/zod-3.d.ts +1 -1
- package/dist/{define-DnJzAZrj.d.cts → define-BH4bnHQl.d.cts} +6 -0
- package/dist/{define-DnJzAZrj.d.ts → define-BH4bnHQl.d.ts} +6 -0
- package/dist/loader-mdx.cjs +345 -265
- package/dist/loader-mdx.js +12 -80
- package/dist/next/index.cjs +15 -130
- package/dist/next/index.js +15 -33
- package/dist/node/loader.cjs +748 -0
- package/dist/node/loader.d.cts +5 -0
- package/dist/node/loader.d.ts +5 -0
- package/dist/node/loader.js +24 -0
- package/dist/postinstall-XV4WSHZP.js +9 -0
- package/dist/runtime/{async.cjs → next/async.cjs} +4 -4
- package/dist/runtime/{async.d.cts → next/async.d.cts} +3 -3
- package/dist/runtime/{async.d.ts → next/async.d.ts} +3 -3
- package/dist/runtime/{async.js → next/async.js} +6 -6
- package/dist/{index.cjs → runtime/next/index.cjs} +4 -6
- package/dist/{index.d.cts → runtime/next/index.d.cts} +3 -3
- package/dist/{index.d.ts → runtime/next/index.d.ts} +3 -3
- package/dist/{index.js → runtime/next/index.js} +1 -1
- package/dist/runtime/vite/browser.d.cts +2 -2
- package/dist/runtime/vite/browser.d.ts +2 -2
- package/dist/runtime/vite/server.d.cts +3 -3
- package/dist/runtime/vite/server.d.ts +3 -3
- package/dist/{types-WSHJKA8L.d.ts → types-DN9KrG7R.d.ts} +1 -1
- package/dist/{types-BmVgoqsr.d.cts → types-DT83Ijs6.d.cts} +1 -1
- package/dist/vite/index.cjs +440 -276
- package/dist/vite/index.d.cts +4 -1
- package/dist/vite/index.d.ts +4 -1
- package/dist/vite/index.js +19 -81
- package/package.json +24 -17
- package/bin.js +0 -5
- package/dist/chunk-UCY7OBZG.js +0 -12
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMdxLoader,
|
|
3
|
+
resolvedConfig
|
|
4
|
+
} from "../chunk-QJCCVMBJ.js";
|
|
5
|
+
import "../chunk-QQWCBFFE.js";
|
|
6
|
+
import "../chunk-SVTXMVLQ.js";
|
|
7
|
+
import "../chunk-IQAEAI4P.js";
|
|
8
|
+
import {
|
|
9
|
+
findConfigFile
|
|
10
|
+
} from "../chunk-766EAFX6.js";
|
|
11
|
+
import {
|
|
12
|
+
buildConfig
|
|
13
|
+
} from "../chunk-QVZ7JH4H.js";
|
|
14
|
+
import "../chunk-VWJKRQZR.js";
|
|
15
|
+
|
|
16
|
+
// src/bun/index.ts
|
|
17
|
+
import { parse } from "querystring";
|
|
18
|
+
import { pathToFileURL } from "url";
|
|
19
|
+
function createMdxPlugin(options = {}) {
|
|
20
|
+
const { configPath = findConfigFile() } = options;
|
|
21
|
+
async function getMdxLoader() {
|
|
22
|
+
const importPath = pathToFileURL(configPath).href;
|
|
23
|
+
const out = buildConfig(await import(importPath));
|
|
24
|
+
return createMdxLoader(resolvedConfig(out));
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
name: "bun-plugin-fumadocs-mdx",
|
|
28
|
+
setup(build) {
|
|
29
|
+
const mdxLoader = getMdxLoader();
|
|
30
|
+
build.onLoad({ filter: /\.mdx(\?.+?)?$/ }, async (args) => {
|
|
31
|
+
const [filePath, query] = args.path.split("?", 2);
|
|
32
|
+
const content = await Bun.file(filePath).text();
|
|
33
|
+
const result = await (await mdxLoader)({
|
|
34
|
+
source: content,
|
|
35
|
+
query: parse(query),
|
|
36
|
+
filePath,
|
|
37
|
+
development: false,
|
|
38
|
+
compiler: {
|
|
39
|
+
addDependency() {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
contents: result.code,
|
|
45
|
+
loader: "js"
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
createMdxPlugin
|
|
53
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/utils/import-formatter.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
function getImportCode(info) {
|
|
4
|
+
const specifier = JSON.stringify(info.specifier);
|
|
5
|
+
if (info.type === "default") return `import ${info.name} from ${specifier}`;
|
|
6
|
+
if (info.type === "namespace")
|
|
7
|
+
return `import * as ${info.name} from ${specifier}`;
|
|
8
|
+
if (info.type === "named") {
|
|
9
|
+
const names = info.names.map(
|
|
10
|
+
(name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
|
|
11
|
+
);
|
|
12
|
+
return `import { ${names.join(", ")} } from ${specifier}`;
|
|
13
|
+
}
|
|
14
|
+
return `import ${specifier}`;
|
|
15
|
+
}
|
|
16
|
+
function toImportPath(file, config) {
|
|
17
|
+
const ext = path.extname(file);
|
|
18
|
+
let filename;
|
|
19
|
+
if (ext === ".ts" && config.jsExtension) {
|
|
20
|
+
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
21
|
+
} else if (ext === ".ts") {
|
|
22
|
+
filename = file.substring(0, file.length - ext.length);
|
|
23
|
+
} else {
|
|
24
|
+
filename = file;
|
|
25
|
+
}
|
|
26
|
+
let importPath;
|
|
27
|
+
if ("relativeTo" in config) {
|
|
28
|
+
importPath = path.relative(config.relativeTo, filename);
|
|
29
|
+
if (!path.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
30
|
+
importPath = `./${importPath}`;
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
importPath = path.resolve(filename);
|
|
34
|
+
}
|
|
35
|
+
return importPath.replaceAll(path.sep, "/");
|
|
36
|
+
}
|
|
37
|
+
function ident(code, tab = 1) {
|
|
38
|
+
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/utils/collections.ts
|
|
42
|
+
function getSupportedFormats(collection) {
|
|
43
|
+
return {
|
|
44
|
+
doc: ["mdx", "md"],
|
|
45
|
+
meta: ["json", "yaml"]
|
|
46
|
+
}[collection.type];
|
|
47
|
+
}
|
|
48
|
+
function getGlobPatterns(collection) {
|
|
49
|
+
if (collection.files) return collection.files;
|
|
50
|
+
return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
|
|
51
|
+
}
|
|
52
|
+
function isFileSupported(filePath, collection) {
|
|
53
|
+
for (const format of getSupportedFormats(collection)) {
|
|
54
|
+
if (filePath.endsWith(`.${format}`)) return true;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
getImportCode,
|
|
61
|
+
toImportPath,
|
|
62
|
+
ident,
|
|
63
|
+
getGlobPatterns,
|
|
64
|
+
isFileSupported
|
|
65
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ValidationError
|
|
3
|
+
} from "./chunk-IQAEAI4P.js";
|
|
4
|
+
|
|
5
|
+
// src/loaders/adapter.ts
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import fs from "fs/promises";
|
|
8
|
+
import { parse } from "querystring";
|
|
9
|
+
import path from "path";
|
|
10
|
+
function toNode(loader, filterByPath) {
|
|
11
|
+
return async (url, _context, nextLoad) => {
|
|
12
|
+
if (!url.startsWith("file:///")) return nextLoad(url);
|
|
13
|
+
const parsedUrl = new URL(url);
|
|
14
|
+
const filePath = fileURLToPath(parsedUrl);
|
|
15
|
+
if (filterByPath(filePath)) {
|
|
16
|
+
const source = (await fs.readFile(filePath)).toString();
|
|
17
|
+
const result = await loader({
|
|
18
|
+
filePath,
|
|
19
|
+
query: Object.fromEntries(parsedUrl.searchParams.entries()),
|
|
20
|
+
source,
|
|
21
|
+
development: false,
|
|
22
|
+
compiler: {
|
|
23
|
+
addDependency() {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
source: result.code,
|
|
29
|
+
format: "module",
|
|
30
|
+
shortCircuit: true
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return nextLoad(url);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function toVite(loader) {
|
|
37
|
+
return async function(file, query, value) {
|
|
38
|
+
const result = await loader({
|
|
39
|
+
filePath: file,
|
|
40
|
+
query: parse(query),
|
|
41
|
+
source: value,
|
|
42
|
+
development: this.environment.mode === "dev",
|
|
43
|
+
compiler: {
|
|
44
|
+
addDependency: (file2) => {
|
|
45
|
+
this.addWatchFile(file2);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
code: result.code,
|
|
51
|
+
map: result.map
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function toWebpack(loader) {
|
|
56
|
+
return async function(source, callback) {
|
|
57
|
+
try {
|
|
58
|
+
const result = await loader({
|
|
59
|
+
filePath: this.resourcePath,
|
|
60
|
+
query: parse(this.resourceQuery),
|
|
61
|
+
source,
|
|
62
|
+
development: this.mode === "development",
|
|
63
|
+
compiler: this
|
|
64
|
+
});
|
|
65
|
+
callback(void 0, result.code, result.map);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error instanceof ValidationError) {
|
|
68
|
+
return callback(new Error(error.toStringFormatted()));
|
|
69
|
+
}
|
|
70
|
+
if (!(error instanceof Error)) throw error;
|
|
71
|
+
const fpath = path.relative(this.context, this.resourcePath);
|
|
72
|
+
error.message = `${fpath}:${error.name}: ${error.message}`;
|
|
73
|
+
callback(error);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
toNode,
|
|
80
|
+
toVite,
|
|
81
|
+
toWebpack
|
|
82
|
+
};
|
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
// src/utils/git-timestamp.ts
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { x } from "tinyexec";
|
|
4
|
-
var cache = /* @__PURE__ */ new Map();
|
|
5
|
-
async function getGitTimestamp(file) {
|
|
6
|
-
const cached = cache.get(file);
|
|
7
|
-
if (cached) return cached;
|
|
8
|
-
try {
|
|
9
|
-
const out = await x(
|
|
10
|
-
"git",
|
|
11
|
-
["log", "-1", '--pretty="%ai"', path.relative(process.cwd(), file)],
|
|
12
|
-
{
|
|
13
|
-
throwOnError: true
|
|
14
|
-
}
|
|
15
|
-
);
|
|
16
|
-
const time = new Date(out.stdout);
|
|
17
|
-
cache.set(file, time);
|
|
18
|
-
return time;
|
|
19
|
-
} catch {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
1
|
// src/utils/validation.ts
|
|
25
2
|
import picocolors from "picocolors";
|
|
26
3
|
var ValidationError = class extends Error {
|
|
@@ -59,8 +36,31 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
59
36
|
return data;
|
|
60
37
|
}
|
|
61
38
|
|
|
39
|
+
// src/utils/git-timestamp.ts
|
|
40
|
+
import path from "path";
|
|
41
|
+
import { x } from "tinyexec";
|
|
42
|
+
var cache = /* @__PURE__ */ new Map();
|
|
43
|
+
async function getGitTimestamp(file) {
|
|
44
|
+
const cached = cache.get(file);
|
|
45
|
+
if (cached) return cached;
|
|
46
|
+
try {
|
|
47
|
+
const out = await x(
|
|
48
|
+
"git",
|
|
49
|
+
["log", "-1", '--pretty="%ai"', path.relative(process.cwd(), file)],
|
|
50
|
+
{
|
|
51
|
+
throwOnError: true
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
const time = new Date(out.stdout);
|
|
55
|
+
cache.set(file, time);
|
|
56
|
+
return time;
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
62
|
export {
|
|
63
|
-
getGitTimestamp,
|
|
64
63
|
ValidationError,
|
|
65
|
-
validate
|
|
64
|
+
validate,
|
|
65
|
+
getGitTimestamp
|
|
66
66
|
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildMDX
|
|
3
|
+
} from "./chunk-QQWCBFFE.js";
|
|
4
|
+
import {
|
|
5
|
+
getGitTimestamp,
|
|
6
|
+
validate
|
|
7
|
+
} from "./chunk-IQAEAI4P.js";
|
|
8
|
+
import {
|
|
9
|
+
getConfigHash,
|
|
10
|
+
loadConfig
|
|
11
|
+
} from "./chunk-766EAFX6.js";
|
|
12
|
+
import {
|
|
13
|
+
fumaMatter
|
|
14
|
+
} from "./chunk-VWJKRQZR.js";
|
|
15
|
+
|
|
16
|
+
// src/utils/count-lines.ts
|
|
17
|
+
function countLines(s) {
|
|
18
|
+
let num = 0;
|
|
19
|
+
for (const c of s) {
|
|
20
|
+
if (c === "\n") num++;
|
|
21
|
+
}
|
|
22
|
+
return num;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/loaders/mdx.ts
|
|
26
|
+
import { z } from "zod";
|
|
27
|
+
import fs from "fs/promises";
|
|
28
|
+
import path from "path";
|
|
29
|
+
import { createHash } from "crypto";
|
|
30
|
+
var querySchema = z.object({
|
|
31
|
+
only: z.literal(["frontmatter", "all"]).default("all"),
|
|
32
|
+
collection: z.string().optional(),
|
|
33
|
+
hash: z.string().describe(
|
|
34
|
+
"the hash of config, used for revalidation on Turbopack/Webpack."
|
|
35
|
+
).optional()
|
|
36
|
+
}).loose();
|
|
37
|
+
var cacheEntry = z.object({
|
|
38
|
+
code: z.string(),
|
|
39
|
+
map: z.any().optional(),
|
|
40
|
+
hash: z.string().optional()
|
|
41
|
+
});
|
|
42
|
+
function createMdxLoader(configLoader) {
|
|
43
|
+
return async ({
|
|
44
|
+
source: value,
|
|
45
|
+
development: isDevelopment,
|
|
46
|
+
query,
|
|
47
|
+
compiler,
|
|
48
|
+
filePath
|
|
49
|
+
}) => {
|
|
50
|
+
const matter = fumaMatter(value);
|
|
51
|
+
const parsed = querySchema.parse(query);
|
|
52
|
+
const loaded = await configLoader.getConfig(parsed.hash);
|
|
53
|
+
const cacheDir = isDevelopment ? void 0 : loaded.global.experimentalBuildCache;
|
|
54
|
+
const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
|
|
55
|
+
if (cacheDir) {
|
|
56
|
+
const cached = await fs.readFile(path.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
|
|
57
|
+
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
58
|
+
}
|
|
59
|
+
const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
|
|
60
|
+
let schema;
|
|
61
|
+
let mdxOptions;
|
|
62
|
+
switch (collection?.type) {
|
|
63
|
+
case "doc":
|
|
64
|
+
mdxOptions = collection.mdxOptions;
|
|
65
|
+
schema = collection.schema;
|
|
66
|
+
break;
|
|
67
|
+
case "docs":
|
|
68
|
+
mdxOptions = collection.docs.mdxOptions;
|
|
69
|
+
schema = collection.docs.schema;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (schema) {
|
|
73
|
+
matter.data = await validate(
|
|
74
|
+
schema,
|
|
75
|
+
matter.data,
|
|
76
|
+
{
|
|
77
|
+
source: value,
|
|
78
|
+
path: filePath
|
|
79
|
+
},
|
|
80
|
+
`invalid frontmatter in ${filePath}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (parsed.only === "frontmatter") {
|
|
84
|
+
return {
|
|
85
|
+
code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
|
|
86
|
+
map: null
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const data = {};
|
|
90
|
+
if (loaded.global.lastModifiedTime === "git") {
|
|
91
|
+
data.lastModified = (await getGitTimestamp(filePath))?.getTime();
|
|
92
|
+
}
|
|
93
|
+
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
94
|
+
const compiled = await buildMDX(
|
|
95
|
+
`${parsed.hash ?? ""}:${parsed.collection ?? "global"}`,
|
|
96
|
+
"\n".repeat(lineOffset) + matter.content,
|
|
97
|
+
{
|
|
98
|
+
development: isDevelopment,
|
|
99
|
+
...mdxOptions ?? await loaded.getDefaultMDXOptions(),
|
|
100
|
+
data,
|
|
101
|
+
filePath,
|
|
102
|
+
frontmatter: matter.data,
|
|
103
|
+
_compiler: compiler
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
const out = {
|
|
107
|
+
code: String(compiled.value),
|
|
108
|
+
map: compiled.map
|
|
109
|
+
};
|
|
110
|
+
if (cacheDir) {
|
|
111
|
+
await fs.mkdir(cacheDir, { recursive: true });
|
|
112
|
+
await fs.writeFile(
|
|
113
|
+
path.join(cacheDir, cacheKey),
|
|
114
|
+
JSON.stringify({
|
|
115
|
+
...out,
|
|
116
|
+
hash: generateCacheHash(value)
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function generateCacheHash(input) {
|
|
124
|
+
return createHash("md5").update(input).digest("hex");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/loaders/config-loader.ts
|
|
128
|
+
function resolvedConfig(loaded) {
|
|
129
|
+
return {
|
|
130
|
+
getConfig() {
|
|
131
|
+
return loaded;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function dynamicConfig(configPath, outDir) {
|
|
136
|
+
return {
|
|
137
|
+
async getConfig(hash) {
|
|
138
|
+
return loadConfig(
|
|
139
|
+
configPath,
|
|
140
|
+
outDir,
|
|
141
|
+
hash ?? await getConfigHash(configPath)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
createMdxLoader,
|
|
149
|
+
resolvedConfig,
|
|
150
|
+
dynamicConfig
|
|
151
|
+
};
|
|
@@ -1,42 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
getGlobPatterns,
|
|
3
|
+
ident,
|
|
4
|
+
toImportPath
|
|
5
|
+
} from "./chunk-6Y5JDZHD.js";
|
|
6
|
+
import {
|
|
7
|
+
findConfigFile,
|
|
8
|
+
loadConfig
|
|
9
|
+
} from "./chunk-766EAFX6.js";
|
|
10
|
+
|
|
11
|
+
// src/vite/postinstall.ts
|
|
12
|
+
import fs from "fs/promises";
|
|
2
13
|
import path from "path";
|
|
3
|
-
function getImportCode(info) {
|
|
4
|
-
const specifier = JSON.stringify(info.specifier);
|
|
5
|
-
if (info.type === "default") return `import ${info.name} from ${specifier}`;
|
|
6
|
-
if (info.type === "namespace")
|
|
7
|
-
return `import * as ${info.name} from ${specifier}`;
|
|
8
|
-
if (info.type === "named") {
|
|
9
|
-
const names = info.names.map(
|
|
10
|
-
(name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
|
|
11
|
-
);
|
|
12
|
-
return `import { ${names.join(", ")} } from ${specifier}`;
|
|
13
|
-
}
|
|
14
|
-
return `import ${specifier}`;
|
|
15
|
-
}
|
|
16
|
-
function toImportPath(file, config) {
|
|
17
|
-
const ext = path.extname(file);
|
|
18
|
-
let filename;
|
|
19
|
-
if (ext === ".ts" && config.jsExtension) {
|
|
20
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
21
|
-
} else if (ext === ".ts") {
|
|
22
|
-
filename = file.substring(0, file.length - ext.length);
|
|
23
|
-
} else {
|
|
24
|
-
filename = file;
|
|
25
|
-
}
|
|
26
|
-
let importPath;
|
|
27
|
-
if ("relativeTo" in config) {
|
|
28
|
-
importPath = path.relative(config.relativeTo, filename);
|
|
29
|
-
if (!path.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
30
|
-
importPath = `./${importPath}`;
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
importPath = path.resolve(filename);
|
|
34
|
-
}
|
|
35
|
-
return importPath.replaceAll(path.sep, "/");
|
|
36
|
-
}
|
|
37
|
-
function ident(code, tab = 1) {
|
|
38
|
-
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
39
|
-
}
|
|
40
14
|
|
|
41
15
|
// src/vite/generate-glob.ts
|
|
42
16
|
function generateGlob(name, patterns, globOptions) {
|
|
@@ -69,24 +43,6 @@ function getGlobBase(collection) {
|
|
|
69
43
|
return enforceRelative(dir);
|
|
70
44
|
}
|
|
71
45
|
|
|
72
|
-
// src/utils/collections.ts
|
|
73
|
-
function getSupportedFormats(collection) {
|
|
74
|
-
return {
|
|
75
|
-
doc: ["mdx", "md"],
|
|
76
|
-
meta: ["json", "yaml"]
|
|
77
|
-
}[collection.type];
|
|
78
|
-
}
|
|
79
|
-
function getGlobPatterns(collection) {
|
|
80
|
-
if (collection.files) return collection.files;
|
|
81
|
-
return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
|
|
82
|
-
}
|
|
83
|
-
function isFileSupported(filePath, collection) {
|
|
84
|
-
for (const format of getSupportedFormats(collection)) {
|
|
85
|
-
if (filePath.endsWith(`.${format}`)) return true;
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
46
|
// src/vite/generate.ts
|
|
91
47
|
function docs(name, collection) {
|
|
92
48
|
const obj = [
|
|
@@ -149,10 +105,21 @@ function entry(configPath, config, outDir, jsExtension) {
|
|
|
149
105
|
return lines.join("\n");
|
|
150
106
|
}
|
|
151
107
|
|
|
108
|
+
// src/vite/postinstall.ts
|
|
109
|
+
async function postInstall(configPath = findConfigFile(), outDir, addJsExtension = false) {
|
|
110
|
+
const config = await loadConfig(configPath, "node_modules", void 0, true);
|
|
111
|
+
const outFile = "source.generated.ts";
|
|
112
|
+
if (outDir) {
|
|
113
|
+
await fs.mkdir(outDir, { recursive: true });
|
|
114
|
+
}
|
|
115
|
+
await fs.writeFile(
|
|
116
|
+
outDir ? path.join(outDir, outFile) : outFile,
|
|
117
|
+
entry(configPath, config, outDir ?? process.cwd(), addJsExtension)
|
|
118
|
+
);
|
|
119
|
+
console.log("[MDX] types generated");
|
|
120
|
+
}
|
|
121
|
+
|
|
152
122
|
export {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
getGlobPatterns,
|
|
156
|
-
isFileSupported,
|
|
157
|
-
entry
|
|
123
|
+
entry,
|
|
124
|
+
postInstall
|
|
158
125
|
};
|
package/dist/config/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-
|
|
1
|
+
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-BH4bnHQl.cjs';
|
|
2
2
|
import { Processor, Transformer } from 'unified';
|
|
3
3
|
import { Root } from 'mdast';
|
|
4
4
|
import '@standard-schema/spec';
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-
|
|
1
|
+
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-BH4bnHQl.js';
|
|
2
2
|
import { Processor, Transformer } from 'unified';
|
|
3
3
|
import { Root } from 'mdast';
|
|
4
4
|
import '@standard-schema/spec';
|
package/dist/config/zod-3.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v3';
|
|
2
|
-
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-
|
|
2
|
+
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-BH4bnHQl.cjs';
|
|
3
3
|
export { Params, remarkInclude } from './index.cjs';
|
|
4
4
|
import '@standard-schema/spec';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
package/dist/config/zod-3.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v3';
|
|
2
|
-
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-
|
|
2
|
+
export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-BH4bnHQl.js';
|
|
3
3
|
export { Params, remarkInclude } from './index.js';
|
|
4
4
|
import '@standard-schema/spec';
|
|
5
5
|
import 'fumadocs-core/mdx-plugins';
|
|
@@ -92,6 +92,12 @@ interface GlobalConfig {
|
|
|
92
92
|
* @defaultValue 'none'
|
|
93
93
|
*/
|
|
94
94
|
lastModifiedTime?: 'git' | 'none';
|
|
95
|
+
/**
|
|
96
|
+
* specify a directory to access & store cache (disabled during development mode).
|
|
97
|
+
*
|
|
98
|
+
* The cache will never be updated, delete the cache folder to clean.
|
|
99
|
+
*/
|
|
100
|
+
experimentalBuildCache?: string;
|
|
95
101
|
}
|
|
96
102
|
declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = false>(options: DocCollection<Schema, Async>): DocCollection<Schema, Async>;
|
|
97
103
|
declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: MetaCollection<Schema>): MetaCollection<Schema>;
|
|
@@ -92,6 +92,12 @@ interface GlobalConfig {
|
|
|
92
92
|
* @defaultValue 'none'
|
|
93
93
|
*/
|
|
94
94
|
lastModifiedTime?: 'git' | 'none';
|
|
95
|
+
/**
|
|
96
|
+
* specify a directory to access & store cache (disabled during development mode).
|
|
97
|
+
*
|
|
98
|
+
* The cache will never be updated, delete the cache folder to clean.
|
|
99
|
+
*/
|
|
100
|
+
experimentalBuildCache?: string;
|
|
95
101
|
}
|
|
96
102
|
declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = false>(options: DocCollection<Schema, Async>): DocCollection<Schema, Async>;
|
|
97
103
|
declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: MetaCollection<Schema>): MetaCollection<Schema>;
|