@hanzo/docs-mdx 14.1.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/LICENSE +21 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +16 -0
- package/dist/build-mdx-LN7FEKIP.js +8 -0
- package/dist/build-mdx-RXJZQXGA.js +8 -0
- package/dist/bun/index.d.ts +25 -0
- package/dist/bun/index.js +52 -0
- package/dist/chunk-4JSFLXXT.js +8 -0
- package/dist/chunk-5OBUOALK.js +141 -0
- package/dist/chunk-72JS4QVZ.js +17 -0
- package/dist/chunk-7I4W7XGI.js +179 -0
- package/dist/chunk-7W73RILB.js +173 -0
- package/dist/chunk-A3YIGE7S.js +334 -0
- package/dist/chunk-AOTZP2TV.js +152 -0
- package/dist/chunk-AXJB5MGS.js +173 -0
- package/dist/chunk-DMIIE3XZ.js +179 -0
- package/dist/chunk-DTFUANSF.js +40 -0
- package/dist/chunk-JWZR25CW.js +116 -0
- package/dist/chunk-K7N6GD4M.js +17 -0
- package/dist/chunk-LXB7WYAF.js +334 -0
- package/dist/chunk-MYAVS2LD.js +116 -0
- package/dist/chunk-OLD35ARB.js +116 -0
- package/dist/chunk-PW2AZGGD.js +125 -0
- package/dist/chunk-RGBNABKS.js +334 -0
- package/dist/chunk-RPUM7REY.js +40 -0
- package/dist/chunk-RR2X6AE6.js +274 -0
- package/dist/chunk-S7KOJHHO.js +89 -0
- package/dist/chunk-STUCUTJQ.js +334 -0
- package/dist/chunk-T6G5VOED.js +116 -0
- package/dist/chunk-U5YPLCO5.js +89 -0
- package/dist/chunk-UB55AMXC.js +274 -0
- package/dist/chunk-VITVHHR6.js +334 -0
- package/dist/chunk-VKSHE52K.js +274 -0
- package/dist/chunk-VWJKRQZR.js +19 -0
- package/dist/chunk-WAAWFNDX.js +179 -0
- package/dist/chunk-WGXYJGSZ.js +141 -0
- package/dist/chunk-WLJ6EKOZ.js +17 -0
- package/dist/chunk-WMYYALAS.js +334 -0
- package/dist/chunk-Y7ISNZ7X.js +216 -0
- package/dist/chunk-YKRCQ42E.js +216 -0
- package/dist/chunk-ZAYZWFWP.js +89 -0
- package/dist/config/index.d.ts +18 -0
- package/dist/config/index.js +63 -0
- package/dist/core-BQcKaqmC.d.ts +350 -0
- package/dist/core-BhWOtait.d.ts +350 -0
- package/dist/core-CV8uFMUa.d.ts +350 -0
- package/dist/core-DAQ64Hkq.d.ts +350 -0
- package/dist/core-DZtRjhds.d.ts +350 -0
- package/dist/core-De5K4ixv.d.ts +350 -0
- package/dist/core-X5ggQtBM.d.ts +350 -0
- package/dist/index-BqkSNsGO.d.ts +8 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +0 -0
- package/dist/load-from-file-FHW724YY.js +8 -0
- package/dist/load-from-file-S5CQ4H6T.js +8 -0
- package/dist/next/index.cjs +1165 -0
- package/dist/next/index.d.ts +33 -0
- package/dist/next/index.js +181 -0
- package/dist/node/loader.d.ts +5 -0
- package/dist/node/loader.js +41 -0
- package/dist/plugins/index-file.d.ts +14 -0
- package/dist/plugins/index-file.js +8 -0
- package/dist/plugins/json-schema.d.ts +31 -0
- package/dist/plugins/json-schema.js +80 -0
- package/dist/plugins/last-modified.d.ts +40 -0
- package/dist/plugins/last-modified.js +89 -0
- package/dist/runtime/browser.d.ts +53 -0
- package/dist/runtime/browser.js +67 -0
- package/dist/runtime/dynamic.d.ts +27 -0
- package/dist/runtime/dynamic.js +79 -0
- package/dist/runtime/server.d.ts +14 -0
- package/dist/runtime/server.js +8 -0
- package/dist/runtime/types.d.ts +61 -0
- package/dist/runtime/types.js +0 -0
- package/dist/vite/index.d.ts +44 -0
- package/dist/vite/index.js +122 -0
- package/dist/webpack/mdx.d.ts +6 -0
- package/dist/webpack/mdx.js +37 -0
- package/dist/webpack/meta.d.ts +6 -0
- package/dist/webpack/meta.js +40 -0
- package/loader-mdx.cjs +7 -0
- package/loader-meta.cjs +7 -0
- package/package.json +137 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Fuma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/bin.ts
|
|
4
|
+
import { existsSync } from "fs";
|
|
5
|
+
async function start() {
|
|
6
|
+
const [configPath, outDir] = process.argv.slice(2);
|
|
7
|
+
const isNext = existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.mts") || existsSync("next.config.ts");
|
|
8
|
+
if (isNext) {
|
|
9
|
+
const { postInstall } = await import("./next/index.js");
|
|
10
|
+
await postInstall({ configPath, outDir });
|
|
11
|
+
} else {
|
|
12
|
+
const { postInstall } = await import("./vite/index.js");
|
|
13
|
+
await postInstall({ configPath, outDir });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
void start();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BunPlugin } from 'bun';
|
|
2
|
+
import { C as CoreOptions } from '../core-BhWOtait.js';
|
|
3
|
+
import '@mdx-js/mdx';
|
|
4
|
+
import '@standard-schema/spec';
|
|
5
|
+
import 'unified';
|
|
6
|
+
import '@hanzo/docs-core/mdx-plugins';
|
|
7
|
+
import '@hanzo/docs-core/source/schema';
|
|
8
|
+
import 'chokidar';
|
|
9
|
+
import 'vfile';
|
|
10
|
+
import '@hanzo/docs-core/source';
|
|
11
|
+
import '../runtime/types.js';
|
|
12
|
+
import '@hanzo/docs-core/mdx-plugins/remark-structure';
|
|
13
|
+
import '@hanzo/docs-core/toc';
|
|
14
|
+
import 'mdast';
|
|
15
|
+
import 'mdx/types';
|
|
16
|
+
|
|
17
|
+
interface MdxPluginOptions extends Partial<CoreOptions> {
|
|
18
|
+
/**
|
|
19
|
+
* Skip meta file transformation step
|
|
20
|
+
*/
|
|
21
|
+
disableMetaFile?: boolean;
|
|
22
|
+
}
|
|
23
|
+
declare function createMdxPlugin(options?: MdxPluginOptions): BunPlugin;
|
|
24
|
+
|
|
25
|
+
export { type MdxPluginOptions, createMdxPlugin };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMdxLoader
|
|
3
|
+
} from "../chunk-JWZR25CW.js";
|
|
4
|
+
import {
|
|
5
|
+
createMetaLoader
|
|
6
|
+
} from "../chunk-ZAYZWFWP.js";
|
|
7
|
+
import {
|
|
8
|
+
createIntegratedConfigLoader,
|
|
9
|
+
toBun
|
|
10
|
+
} from "../chunk-DMIIE3XZ.js";
|
|
11
|
+
import "../chunk-4JSFLXXT.js";
|
|
12
|
+
import {
|
|
13
|
+
buildConfig
|
|
14
|
+
} from "../chunk-MYAVS2LD.js";
|
|
15
|
+
import "../chunk-U5YPLCO5.js";
|
|
16
|
+
import {
|
|
17
|
+
_Defaults,
|
|
18
|
+
createCore
|
|
19
|
+
} from "../chunk-RR2X6AE6.js";
|
|
20
|
+
import "../chunk-PW2AZGGD.js";
|
|
21
|
+
import "../chunk-VWJKRQZR.js";
|
|
22
|
+
|
|
23
|
+
// src/bun/index.ts
|
|
24
|
+
import { pathToFileURL } from "url";
|
|
25
|
+
function createMdxPlugin(options = {}) {
|
|
26
|
+
const {
|
|
27
|
+
environment = "bun",
|
|
28
|
+
outDir = _Defaults.outDir,
|
|
29
|
+
configPath = _Defaults.configPath,
|
|
30
|
+
disableMetaFile = false
|
|
31
|
+
} = options;
|
|
32
|
+
return {
|
|
33
|
+
name: "bun-plugin-hanzo-docs-mdx",
|
|
34
|
+
async setup(build) {
|
|
35
|
+
const importPath = pathToFileURL(configPath).href;
|
|
36
|
+
const core = createCore({
|
|
37
|
+
environment,
|
|
38
|
+
outDir,
|
|
39
|
+
configPath
|
|
40
|
+
});
|
|
41
|
+
await core.init({
|
|
42
|
+
config: buildConfig(await import(importPath))
|
|
43
|
+
});
|
|
44
|
+
const configLoader = createIntegratedConfigLoader(core);
|
|
45
|
+
toBun(createMdxLoader(configLoader))(build);
|
|
46
|
+
if (!disableMetaFile) toBun(createMetaLoader(configLoader))(build);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
createMdxPlugin
|
|
52
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// src/runtime/server.ts
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
function server(options = {}) {
|
|
4
|
+
const { doc: { passthroughs: docPassthroughs = [] } = {} } = options;
|
|
5
|
+
function fileInfo(file, base) {
|
|
6
|
+
if (file.startsWith("./")) {
|
|
7
|
+
file = file.slice(2);
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
path: file,
|
|
11
|
+
fullPath: path.join(base, file)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function mapDocData(entry) {
|
|
15
|
+
const data = {
|
|
16
|
+
body: entry.default,
|
|
17
|
+
toc: entry.toc,
|
|
18
|
+
structuredData: entry.structuredData,
|
|
19
|
+
_exports: entry
|
|
20
|
+
};
|
|
21
|
+
for (const key of docPassthroughs) {
|
|
22
|
+
data[key] = entry[key];
|
|
23
|
+
}
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
async doc(_name, base, glob) {
|
|
28
|
+
const out = await Promise.all(
|
|
29
|
+
Object.entries(glob).map(async ([k, v]) => {
|
|
30
|
+
const data = typeof v === "function" ? await v() : v;
|
|
31
|
+
return {
|
|
32
|
+
...mapDocData(data),
|
|
33
|
+
...data.frontmatter,
|
|
34
|
+
...createDocMethods(fileInfo(k, base), () => data)
|
|
35
|
+
};
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
return out;
|
|
39
|
+
},
|
|
40
|
+
async docLazy(_name, base, head, body) {
|
|
41
|
+
const out = await Promise.all(
|
|
42
|
+
Object.entries(head).map(async ([k, v]) => {
|
|
43
|
+
const data = typeof v === "function" ? await v() : v;
|
|
44
|
+
const content = body[k];
|
|
45
|
+
return {
|
|
46
|
+
...data,
|
|
47
|
+
...createDocMethods(fileInfo(k, base), content),
|
|
48
|
+
async load() {
|
|
49
|
+
return mapDocData(await content());
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
return out;
|
|
55
|
+
},
|
|
56
|
+
async meta(_name, base, glob) {
|
|
57
|
+
const out = await Promise.all(
|
|
58
|
+
Object.entries(glob).map(async ([k, v]) => {
|
|
59
|
+
const data = typeof v === "function" ? await v() : v;
|
|
60
|
+
return {
|
|
61
|
+
info: fileInfo(k, base),
|
|
62
|
+
...data
|
|
63
|
+
};
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
return out;
|
|
67
|
+
},
|
|
68
|
+
async docs(name, base, metaGlob, docGlob) {
|
|
69
|
+
const entry = {
|
|
70
|
+
docs: await this.doc(name, base, docGlob),
|
|
71
|
+
meta: await this.meta(name, base, metaGlob),
|
|
72
|
+
toFumadocsSource() {
|
|
73
|
+
return toFumadocsSource(this.docs, this.meta);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return entry;
|
|
77
|
+
},
|
|
78
|
+
async docsLazy(name, base, metaGlob, docHeadGlob, docBodyGlob) {
|
|
79
|
+
const entry = {
|
|
80
|
+
docs: await this.docLazy(name, base, docHeadGlob, docBodyGlob),
|
|
81
|
+
meta: await this.meta(name, base, metaGlob),
|
|
82
|
+
toFumadocsSource() {
|
|
83
|
+
return toFumadocsSource(this.docs, this.meta);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return entry;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function toFumadocsSource(pages, metas) {
|
|
91
|
+
const files = [];
|
|
92
|
+
for (const entry of pages) {
|
|
93
|
+
files.push({
|
|
94
|
+
type: "page",
|
|
95
|
+
path: entry.info.path,
|
|
96
|
+
absolutePath: entry.info.fullPath,
|
|
97
|
+
data: entry
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
for (const entry of metas) {
|
|
101
|
+
files.push({
|
|
102
|
+
type: "meta",
|
|
103
|
+
path: entry.info.path,
|
|
104
|
+
absolutePath: entry.info.fullPath,
|
|
105
|
+
data: entry
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
files
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function createDocMethods(info, load) {
|
|
113
|
+
return {
|
|
114
|
+
info,
|
|
115
|
+
async getText(type) {
|
|
116
|
+
if (type === "raw") {
|
|
117
|
+
const fs = await import("fs/promises");
|
|
118
|
+
return (await fs.readFile(info.fullPath)).toString();
|
|
119
|
+
}
|
|
120
|
+
const data = await load();
|
|
121
|
+
if (typeof data._markdown !== "string")
|
|
122
|
+
throw new Error(
|
|
123
|
+
"getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
|
|
124
|
+
);
|
|
125
|
+
return data._markdown;
|
|
126
|
+
},
|
|
127
|
+
async getMDAST() {
|
|
128
|
+
const data = await load();
|
|
129
|
+
if (!data._mdast)
|
|
130
|
+
throw new Error(
|
|
131
|
+
"getMDAST() requires `includeMDAST` to be enabled in your collection config."
|
|
132
|
+
);
|
|
133
|
+
return JSON.parse(data._mdast);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export {
|
|
139
|
+
server,
|
|
140
|
+
toFumadocsSource
|
|
141
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCore
|
|
3
|
+
} from "./chunk-UB55AMXC.js";
|
|
4
|
+
|
|
5
|
+
// src/webpack/index.ts
|
|
6
|
+
var core;
|
|
7
|
+
function getCore(options) {
|
|
8
|
+
return core ??= createCore({
|
|
9
|
+
environment: "webpack",
|
|
10
|
+
outDir: options.outDir,
|
|
11
|
+
configPath: options.configPath
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
getCore
|
|
17
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ValidationError
|
|
3
|
+
} from "./chunk-UB55AMXC.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
|
+
import { readFileSync } from "fs";
|
|
11
|
+
function toNode(loader) {
|
|
12
|
+
return async (url, _context, nextLoad) => {
|
|
13
|
+
if (url.startsWith("file:///") && (!loader.test || loader.test.test(url))) {
|
|
14
|
+
const parsedUrl = new URL(url);
|
|
15
|
+
const filePath = fileURLToPath(parsedUrl);
|
|
16
|
+
const result = await loader.load({
|
|
17
|
+
filePath,
|
|
18
|
+
query: Object.fromEntries(parsedUrl.searchParams.entries()),
|
|
19
|
+
async getSource() {
|
|
20
|
+
return (await fs.readFile(filePath)).toString();
|
|
21
|
+
},
|
|
22
|
+
development: false,
|
|
23
|
+
compiler: {
|
|
24
|
+
addDependency() {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (result) {
|
|
29
|
+
return {
|
|
30
|
+
source: result.code,
|
|
31
|
+
format: "module",
|
|
32
|
+
shortCircuit: true
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return nextLoad(url);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function toVite(loader) {
|
|
40
|
+
return {
|
|
41
|
+
filter(id) {
|
|
42
|
+
return !loader.test || loader.test.test(id);
|
|
43
|
+
},
|
|
44
|
+
async transform(value, id) {
|
|
45
|
+
const [file, query = ""] = id.split("?", 2);
|
|
46
|
+
const result = await loader.load({
|
|
47
|
+
filePath: file,
|
|
48
|
+
query: parse(query),
|
|
49
|
+
getSource() {
|
|
50
|
+
return value;
|
|
51
|
+
},
|
|
52
|
+
development: this.environment.mode === "dev",
|
|
53
|
+
compiler: {
|
|
54
|
+
addDependency: (file2) => {
|
|
55
|
+
this.addWatchFile(file2);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
if (result === null) return null;
|
|
60
|
+
return {
|
|
61
|
+
code: result.code,
|
|
62
|
+
map: result.map
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function toWebpack(loader) {
|
|
68
|
+
return async function(source, callback) {
|
|
69
|
+
try {
|
|
70
|
+
const result = await loader.load({
|
|
71
|
+
filePath: this.resourcePath,
|
|
72
|
+
query: parse(this.resourceQuery.slice(1)),
|
|
73
|
+
getSource() {
|
|
74
|
+
return source;
|
|
75
|
+
},
|
|
76
|
+
development: this.mode === "development",
|
|
77
|
+
compiler: this
|
|
78
|
+
});
|
|
79
|
+
if (result === null) {
|
|
80
|
+
callback(void 0, source);
|
|
81
|
+
} else {
|
|
82
|
+
callback(void 0, result.code, result.map);
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof ValidationError) {
|
|
86
|
+
return callback(new Error(await error.toStringFormatted()));
|
|
87
|
+
}
|
|
88
|
+
if (!(error instanceof Error)) throw error;
|
|
89
|
+
const fpath = path.relative(this.context, this.resourcePath);
|
|
90
|
+
error.message = `${fpath}:${error.name}: ${error.message}`;
|
|
91
|
+
callback(error);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function toBun(loader) {
|
|
96
|
+
function toResult(output) {
|
|
97
|
+
if (!output) return;
|
|
98
|
+
return {
|
|
99
|
+
contents: output.code,
|
|
100
|
+
loader: "js"
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return (build) => {
|
|
104
|
+
build.onLoad({ filter: loader.test ?? /.+/ }, (args) => {
|
|
105
|
+
const [filePath, query = ""] = args.path.split("?", 2);
|
|
106
|
+
const input = {
|
|
107
|
+
async getSource() {
|
|
108
|
+
return Bun.file(filePath).text();
|
|
109
|
+
},
|
|
110
|
+
query: parse(query),
|
|
111
|
+
filePath,
|
|
112
|
+
development: false,
|
|
113
|
+
compiler: {
|
|
114
|
+
addDependency() {
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
if (loader.bun?.load) {
|
|
119
|
+
return loader.bun.load(readFileSync(filePath).toString(), input);
|
|
120
|
+
}
|
|
121
|
+
const result = loader.load(input);
|
|
122
|
+
if (result instanceof Promise) {
|
|
123
|
+
return result.then(toResult);
|
|
124
|
+
}
|
|
125
|
+
return toResult(result);
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/loaders/config.ts
|
|
131
|
+
import fs2 from "fs/promises";
|
|
132
|
+
function createStandaloneConfigLoader({
|
|
133
|
+
core,
|
|
134
|
+
buildConfig,
|
|
135
|
+
mode
|
|
136
|
+
}) {
|
|
137
|
+
let prev;
|
|
138
|
+
async function getConfigHash() {
|
|
139
|
+
if (mode === "production") return "static";
|
|
140
|
+
const stats = await fs2.stat(core.getOptions().configPath).catch(() => {
|
|
141
|
+
throw new Error("Cannot find config file");
|
|
142
|
+
});
|
|
143
|
+
return stats.mtime.getTime().toString();
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
async getCore() {
|
|
147
|
+
const hash = await getConfigHash();
|
|
148
|
+
if (!prev || hash !== prev.hash) {
|
|
149
|
+
prev = {
|
|
150
|
+
hash,
|
|
151
|
+
init: (async () => {
|
|
152
|
+
const { loadConfig } = await import("./load-from-file-S5CQ4H6T.js");
|
|
153
|
+
await core.init({
|
|
154
|
+
config: loadConfig(core, buildConfig)
|
|
155
|
+
});
|
|
156
|
+
})()
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
await prev.init;
|
|
160
|
+
return core;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function createIntegratedConfigLoader(core) {
|
|
165
|
+
return {
|
|
166
|
+
async getCore() {
|
|
167
|
+
return core;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export {
|
|
173
|
+
toNode,
|
|
174
|
+
toVite,
|
|
175
|
+
toWebpack,
|
|
176
|
+
toBun,
|
|
177
|
+
createStandaloneConfigLoader,
|
|
178
|
+
createIntegratedConfigLoader
|
|
179
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import {
|
|
2
|
+
flattenNode,
|
|
3
|
+
remarkInclude
|
|
4
|
+
} from "./chunk-Y7ISNZ7X.js";
|
|
5
|
+
|
|
6
|
+
// src/loaders/mdx/build-mdx.ts
|
|
7
|
+
import { createProcessor } from "@mdx-js/mdx";
|
|
8
|
+
import { VFile } from "vfile";
|
|
9
|
+
|
|
10
|
+
// src/loaders/mdx/remark-postprocess.ts
|
|
11
|
+
import { visit } from "unist-util-visit";
|
|
12
|
+
import { toMarkdown } from "mdast-util-to-markdown";
|
|
13
|
+
import { valueToEstree } from "estree-util-value-to-estree";
|
|
14
|
+
import { removePosition } from "unist-util-remove-position";
|
|
15
|
+
import remarkMdx from "remark-mdx";
|
|
16
|
+
function remarkPostprocess({
|
|
17
|
+
_format,
|
|
18
|
+
includeProcessedMarkdown = false,
|
|
19
|
+
includeMDAST = false,
|
|
20
|
+
extractLinkReferences = false,
|
|
21
|
+
valueToExport = []
|
|
22
|
+
}) {
|
|
23
|
+
let _stringifyProcessor;
|
|
24
|
+
const getStringifyProcessor = () => {
|
|
25
|
+
return _stringifyProcessor ??= _format === "mdx" ? this : (
|
|
26
|
+
// force Markdown processor to stringify MDX nodes
|
|
27
|
+
this().use(remarkMdx).freeze()
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
return (tree, file) => {
|
|
31
|
+
const frontmatter = file.data.frontmatter ??= {};
|
|
32
|
+
if (!frontmatter.title) {
|
|
33
|
+
visit(tree, "heading", (node) => {
|
|
34
|
+
if (node.depth === 1) {
|
|
35
|
+
frontmatter.title = flattenNode(node);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
file.data["mdx-export"] ??= [];
|
|
41
|
+
file.data["mdx-export"].push({
|
|
42
|
+
name: "frontmatter",
|
|
43
|
+
value: frontmatter
|
|
44
|
+
});
|
|
45
|
+
if (extractLinkReferences) {
|
|
46
|
+
const urls = [];
|
|
47
|
+
visit(tree, "link", (node) => {
|
|
48
|
+
urls.push({
|
|
49
|
+
href: node.url
|
|
50
|
+
});
|
|
51
|
+
return "skip";
|
|
52
|
+
});
|
|
53
|
+
file.data["mdx-export"].push({
|
|
54
|
+
name: "extractedReferences",
|
|
55
|
+
value: urls
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (includeProcessedMarkdown) {
|
|
59
|
+
const processor = getStringifyProcessor();
|
|
60
|
+
const markdown = toMarkdown(tree, {
|
|
61
|
+
...processor.data("settings"),
|
|
62
|
+
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
63
|
+
extensions: processor.data("toMarkdownExtensions") || []
|
|
64
|
+
});
|
|
65
|
+
file.data["mdx-export"].push({
|
|
66
|
+
name: "_markdown",
|
|
67
|
+
value: markdown
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (includeMDAST) {
|
|
71
|
+
const options = includeMDAST === true ? {} : includeMDAST;
|
|
72
|
+
const mdast = JSON.stringify(
|
|
73
|
+
options.removePosition ? removePosition(structuredClone(tree)) : tree
|
|
74
|
+
);
|
|
75
|
+
file.data["mdx-export"].push({
|
|
76
|
+
name: "_mdast",
|
|
77
|
+
value: mdast
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
for (const { name, value } of file.data["mdx-export"]) {
|
|
81
|
+
tree.children.unshift(getMdastExport(name, value));
|
|
82
|
+
}
|
|
83
|
+
file.data["mdx-export"] = [];
|
|
84
|
+
for (const name of valueToExport) {
|
|
85
|
+
if (!(name in file.data)) continue;
|
|
86
|
+
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function getMdastExport(name, value) {
|
|
91
|
+
return {
|
|
92
|
+
type: "mdxjsEsm",
|
|
93
|
+
value: "",
|
|
94
|
+
data: {
|
|
95
|
+
estree: {
|
|
96
|
+
type: "Program",
|
|
97
|
+
sourceType: "module",
|
|
98
|
+
body: [
|
|
99
|
+
{
|
|
100
|
+
type: "ExportNamedDeclaration",
|
|
101
|
+
attributes: [],
|
|
102
|
+
specifiers: [],
|
|
103
|
+
source: null,
|
|
104
|
+
declaration: {
|
|
105
|
+
type: "VariableDeclaration",
|
|
106
|
+
kind: "let",
|
|
107
|
+
declarations: [
|
|
108
|
+
{
|
|
109
|
+
type: "VariableDeclarator",
|
|
110
|
+
id: {
|
|
111
|
+
type: "Identifier",
|
|
112
|
+
name
|
|
113
|
+
},
|
|
114
|
+
init: valueToEstree(value)
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/loaders/mdx/build-mdx.ts
|
|
126
|
+
async function buildMDX(core, collection, {
|
|
127
|
+
filePath,
|
|
128
|
+
frontmatter,
|
|
129
|
+
source,
|
|
130
|
+
_compiler,
|
|
131
|
+
environment,
|
|
132
|
+
isDevelopment
|
|
133
|
+
}) {
|
|
134
|
+
const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);
|
|
135
|
+
function getProcessor(format) {
|
|
136
|
+
const cache = core.cache;
|
|
137
|
+
const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
|
|
138
|
+
let processor = cache.get(key);
|
|
139
|
+
if (!processor) {
|
|
140
|
+
const postprocessOptions = {
|
|
141
|
+
_format: format,
|
|
142
|
+
...collection?.postprocess
|
|
143
|
+
};
|
|
144
|
+
processor = createProcessor({
|
|
145
|
+
outputFormat: "program",
|
|
146
|
+
development: isDevelopment,
|
|
147
|
+
...mdxOptions,
|
|
148
|
+
remarkPlugins: [
|
|
149
|
+
remarkInclude,
|
|
150
|
+
...mdxOptions.remarkPlugins ?? [],
|
|
151
|
+
[remarkPostprocess, postprocessOptions]
|
|
152
|
+
],
|
|
153
|
+
format
|
|
154
|
+
});
|
|
155
|
+
cache.set(key, processor);
|
|
156
|
+
}
|
|
157
|
+
return processor;
|
|
158
|
+
}
|
|
159
|
+
let vfile = new VFile({
|
|
160
|
+
value: source,
|
|
161
|
+
path: filePath,
|
|
162
|
+
cwd: collection?.cwd,
|
|
163
|
+
data: { frontmatter, _compiler, _getProcessor: getProcessor }
|
|
164
|
+
});
|
|
165
|
+
if (collection) {
|
|
166
|
+
vfile = await core.transformVFile({ collection, filePath, source }, vfile);
|
|
167
|
+
}
|
|
168
|
+
return getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md").process(vfile);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
buildMDX
|
|
173
|
+
};
|