fuma-content 1.0.2 → 1.0.3
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/{async-cache-BM9Yf4Nw.js → async-cache-C0J_pTbk.js} +1 -1
- package/dist/async-cache-C0J_pTbk.js.map +1 -0
- package/dist/build-mdx-CSrSOQxF.js +4 -0
- package/dist/{build-mdx-C1PZsGp2.js → build-mdx-DugsQ0sk.js} +5 -5
- package/dist/build-mdx-DugsQ0sk.js.map +1 -0
- package/dist/bun/index.d.ts +1 -1
- package/dist/bun/index.d.ts.map +1 -1
- package/dist/bun/index.js +5 -10
- package/dist/bun/index.js.map +1 -1
- package/dist/{bun-QKQnqgIi.js → bun-Br1ReMiq.js} +2 -2
- package/dist/bun-Br1ReMiq.js.map +1 -0
- package/dist/{code-generator-gPtrfZ6Q.js → code-generator-BvuyL0UO.js} +2 -2
- package/dist/code-generator-BvuyL0UO.js.map +1 -0
- package/dist/collections/handlers/fs.d.ts +1 -1
- package/dist/collections/handlers/fs.js +9 -6
- package/dist/collections/handlers/fs.js.map +1 -1
- package/dist/collections/index.d.ts +1 -1
- package/dist/collections/index.js.map +1 -1
- package/dist/collections/mdx/loader-webpack.d.ts +1 -1
- package/dist/collections/mdx/loader-webpack.js +6 -6
- package/dist/collections/mdx/loader-webpack.js.map +1 -1
- package/dist/collections/mdx/runtime-browser.d.ts +2 -2
- package/dist/collections/mdx/runtime-browser.d.ts.map +1 -1
- package/dist/collections/mdx/runtime-browser.js +2 -2
- package/dist/collections/mdx/runtime-browser.js.map +1 -1
- package/dist/collections/mdx/runtime-dynamic.d.ts +2 -2
- package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -1
- package/dist/collections/mdx/runtime-dynamic.js +7 -8
- package/dist/collections/mdx/runtime-dynamic.js.map +1 -1
- package/dist/collections/mdx/runtime.d.ts +2 -2
- package/dist/collections/mdx/runtime.d.ts.map +1 -1
- package/dist/collections/mdx/runtime.js.map +1 -1
- package/dist/collections/mdx.d.ts +1 -1
- package/dist/collections/mdx.js +16 -15
- package/dist/collections/mdx.js.map +1 -1
- package/dist/collections/meta/loader-webpack.d.ts +1 -1
- package/dist/collections/meta/loader-webpack.js +6 -9
- package/dist/collections/meta/loader-webpack.js.map +1 -1
- package/dist/collections/meta/runtime.d.ts +2 -2
- package/dist/collections/meta/runtime.js.map +1 -1
- package/dist/collections/meta.d.ts +1 -1
- package/dist/collections/meta.js +7 -10
- package/dist/collections/meta.js.map +1 -1
- package/dist/collections/runtime/file-store.d.ts +2 -2
- package/dist/collections/runtime/file-store.d.ts.map +1 -1
- package/dist/collections/runtime/file-store.js +1 -1
- package/dist/collections/runtime/file-store.js.map +1 -1
- package/dist/collections/runtime/store.d.ts +2 -2
- package/dist/collections/runtime/store.js +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/{core-Bkh-SI_3.d.ts → core-CRWvbE7W.d.ts} +78 -51
- package/dist/core-CRWvbE7W.d.ts.map +1 -0
- package/dist/{core-ZuoVBkeg.js → core-CnZQDCJ1.js} +49 -14
- package/dist/core-CnZQDCJ1.js.map +1 -0
- package/dist/dynamic.d.ts +24 -0
- package/dist/dynamic.d.ts.map +1 -0
- package/dist/{dynamic-B40uAtdo.js → dynamic.js} +4 -4
- package/dist/dynamic.js.map +1 -0
- package/dist/{fuma-matter-O4fA6nSx.js → fuma-matter-D3kkMkdj.js} +2 -2
- package/dist/fuma-matter-D3kkMkdj.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/load-from-file-BctwhOUd.js +3 -0
- package/dist/{load-from-file-1f4WaHsf.js → load-from-file-XiM8eZha.js} +2 -3
- package/dist/load-from-file-XiM8eZha.js.map +1 -0
- package/dist/loader-BHMDOncZ.js +4 -0
- package/dist/{loader-CXnMFuyE.js → loader-C7W_Rwj8.js} +4 -4
- package/dist/loader-C7W_Rwj8.js.map +1 -0
- package/dist/{loader-gk94iHf5.js → loader-DLSJPUiO.js} +9 -6
- package/dist/loader-DLSJPUiO.js.map +1 -0
- package/dist/loader-DkmGoUvo.js +4 -0
- package/dist/next/index.cjs +54 -59
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +6 -6
- package/dist/next/index.js.map +1 -1
- package/dist/node/loader.d.ts.map +1 -1
- package/dist/node/loader.js +5 -8
- package/dist/node/loader.js.map +1 -1
- package/dist/{node-CGIIJIcs.js → node-CVAU22o3.js} +1 -1
- package/dist/{node-CGIIJIcs.js.map → node-CVAU22o3.js.map} +1 -1
- package/dist/{pipe-5cnvE6KY.js → pipe-UEMV1mRg.js} +1 -1
- package/dist/pipe-UEMV1mRg.js.map +1 -0
- package/dist/plugins/git.d.ts +1 -1
- package/dist/plugins/git.js +3 -3
- package/dist/plugins/git.js.map +1 -1
- package/dist/plugins/json-schema.d.ts +1 -1
- package/dist/plugins/json-schema.js +2 -2
- package/dist/plugins/json-schema.js.map +1 -1
- package/dist/plugins/with-loader/index.d.ts +1 -1
- package/dist/plugins/with-loader/index.js +3 -3
- package/dist/plugins/with-loader/index.js.map +1 -1
- package/dist/plugins/with-loader/webpack.d.ts +1 -1
- package/dist/plugins/with-loader/webpack.js +3 -3
- package/dist/{store-DEjYYF6a.d.ts → store-BtGmZUAC.d.ts} +2 -2
- package/dist/store-BtGmZUAC.d.ts.map +1 -0
- package/dist/{store-0LQ2PlH6.js → store-D166MOLw.js} +1 -1
- package/dist/store-D166MOLw.js.map +1 -0
- package/dist/{validation-BOJKRAp5.js → validation-BYUzZIfc.js} +11 -2
- package/dist/validation-BYUzZIfc.js.map +1 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +22 -16
- package/dist/vite/index.js.map +1 -1
- package/dist/{vite-X-2Al8fq.js → vite-6awgG092.js} +3 -2
- package/dist/vite-6awgG092.js.map +1 -0
- package/package.json +44 -40
- package/dist/async-cache-BM9Yf4Nw.js.map +0 -1
- package/dist/build-D8A5ByFk.js +0 -42
- package/dist/build-D8A5ByFk.js.map +0 -1
- package/dist/build-mdx-C1PZsGp2.js.map +0 -1
- package/dist/build-mdx-DFndaVbS.js +0 -4
- package/dist/bun-QKQnqgIi.js.map +0 -1
- package/dist/code-generator-gPtrfZ6Q.js.map +0 -1
- package/dist/core-Bkh-SI_3.d.ts.map +0 -1
- package/dist/core-ZuoVBkeg.js.map +0 -1
- package/dist/dynamic-B40uAtdo.js.map +0 -1
- package/dist/fuma-matter-O4fA6nSx.js.map +0 -1
- package/dist/load-from-file-1f4WaHsf.js.map +0 -1
- package/dist/load-from-file-BTNnBu6f.js +0 -3
- package/dist/loader-80abXEHx.js +0 -4
- package/dist/loader-BFhPyg3z.js +0 -4
- package/dist/loader-CXnMFuyE.js.map +0 -1
- package/dist/loader-gk94iHf5.js.map +0 -1
- package/dist/pipe-5cnvE6KY.js.map +0 -1
- package/dist/store-0LQ2PlH6.js.map +0 -1
- package/dist/store-DEjYYF6a.d.ts.map +0 -1
- package/dist/validation-BOJKRAp5.js.map +0 -1
- package/dist/vite-X-2Al8fq.js.map +0 -1
package/dist/vite/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import "../code-generator-
|
|
2
|
-
import { t as Core } from "../core-
|
|
3
|
-
import { t as buildConfig } from "../build-D8A5ByFk.js";
|
|
1
|
+
import "../code-generator-BvuyL0UO.js";
|
|
2
|
+
import { t as Core } from "../core-CnZQDCJ1.js";
|
|
4
3
|
|
|
5
4
|
//#region src/vite/index.ts
|
|
6
5
|
async function content(config, pluginOptions = {}) {
|
|
7
|
-
const core =
|
|
8
|
-
await core.init({
|
|
6
|
+
const core = new Core(applyDefaults(pluginOptions));
|
|
7
|
+
await core.init({
|
|
8
|
+
config,
|
|
9
|
+
plugins: [vitePlugin()]
|
|
10
|
+
});
|
|
9
11
|
const ctx = core.getPluginContext();
|
|
10
12
|
return [...core.getPlugins(true).map((plugin) => plugin.vite?.createPlugin?.call(ctx)), {
|
|
11
13
|
name: "fuma-content",
|
|
@@ -18,20 +20,24 @@ async function content(config, pluginOptions = {}) {
|
|
|
18
20
|
}];
|
|
19
21
|
}
|
|
20
22
|
async function createStandaloneCore(pluginOptions = {}) {
|
|
21
|
-
const { loadConfig } = await import("../load-from-file-
|
|
22
|
-
const core =
|
|
23
|
-
await core.init({
|
|
23
|
+
const { loadConfig } = await import("../load-from-file-BctwhOUd.js");
|
|
24
|
+
const core = new Core(applyDefaults(pluginOptions));
|
|
25
|
+
await core.init({
|
|
26
|
+
config: loadConfig(core, true),
|
|
27
|
+
plugins: [vitePlugin()]
|
|
28
|
+
});
|
|
24
29
|
return core;
|
|
25
30
|
}
|
|
26
|
-
function
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
function vitePlugin() {
|
|
32
|
+
return {
|
|
33
|
+
name: "vite",
|
|
34
|
+
config(config) {
|
|
35
|
+
config.emit ??= {
|
|
36
|
+
target: "vite",
|
|
37
|
+
jsExtension: false
|
|
38
|
+
};
|
|
33
39
|
}
|
|
34
|
-
}
|
|
40
|
+
};
|
|
35
41
|
}
|
|
36
42
|
function applyDefaults(options) {
|
|
37
43
|
return {
|
package/dist/vite/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/vite/index.ts"],"sourcesContent":["import type { PluginOption } from \"vite\";\nimport
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/vite/index.ts"],"sourcesContent":["import type { PluginOption } from \"vite\";\nimport type { FSWatcher } from \"chokidar\";\nimport { Core, type Plugin } from \"@/core\";\n\nexport interface PluginOptions {\n /**\n * @defaultValue content.config.ts\n */\n configPath?: string;\n\n /**\n * Update Vite config to fix module resolution of Fumadocs\n *\n * @defaultValue true\n */\n updateViteConfig?: boolean;\n\n /**\n * Output directory of generated files\n *\n * @defaultValue '.content'\n */\n outDir?: string;\n}\n\nexport default async function content(\n config: Record<string, unknown>,\n pluginOptions: PluginOptions = {},\n): Promise<PluginOption[]> {\n const options = applyDefaults(pluginOptions);\n const core = new Core(options);\n await core.init({\n config,\n plugins: [vitePlugin()],\n });\n\n const ctx = core.getPluginContext();\n return [\n ...core.getPlugins(true).map((plugin) => plugin.vite?.createPlugin?.call(ctx)),\n {\n name: \"fuma-content\",\n async buildStart() {\n await core.emit({ write: true });\n },\n async configureServer(server) {\n await core.initServer({\n watcher: server.watcher as unknown as FSWatcher,\n });\n },\n },\n ];\n}\n\nexport async function createStandaloneCore(pluginOptions: PluginOptions = {}) {\n const { loadConfig } = await import(\"@/config/load-from-file\");\n const core = new Core(applyDefaults(pluginOptions));\n await core.init({\n config: loadConfig(core, true),\n plugins: [vitePlugin()],\n });\n return core;\n}\n\nfunction vitePlugin(): Plugin {\n return {\n name: \"vite\",\n config(config) {\n config.emit ??= {\n target: \"vite\",\n jsExtension: false,\n };\n },\n };\n}\n\nfunction applyDefaults(options: PluginOptions): Required<PluginOptions> {\n return {\n updateViteConfig: options.updateViteConfig ?? true,\n configPath: options.configPath ?? Core.defaultOptions.configPath,\n outDir: options.outDir ?? Core.defaultOptions.outDir,\n };\n}\n"],"mappings":";;;;AAyBA,eAA8B,QAC5B,QACA,gBAA+B,EAAE,EACR;CAEzB,MAAM,OAAO,IAAI,KADD,cAAc,cAAc,CACd;AAC9B,OAAM,KAAK,KAAK;EACd;EACA,SAAS,CAAC,YAAY,CAAC;EACxB,CAAC;CAEF,MAAM,MAAM,KAAK,kBAAkB;AACnC,QAAO,CACL,GAAG,KAAK,WAAW,KAAK,CAAC,KAAK,WAAW,OAAO,MAAM,cAAc,KAAK,IAAI,CAAC,EAC9E;EACE,MAAM;EACN,MAAM,aAAa;AACjB,SAAM,KAAK,KAAK,EAAE,OAAO,MAAM,CAAC;;EAElC,MAAM,gBAAgB,QAAQ;AAC5B,SAAM,KAAK,WAAW,EACpB,SAAS,OAAO,SACjB,CAAC;;EAEL,CACF;;AAGH,eAAsB,qBAAqB,gBAA+B,EAAE,EAAE;CAC5E,MAAM,EAAE,eAAe,MAAM,OAAO;CACpC,MAAM,OAAO,IAAI,KAAK,cAAc,cAAc,CAAC;AACnD,OAAM,KAAK,KAAK;EACd,QAAQ,WAAW,MAAM,KAAK;EAC9B,SAAS,CAAC,YAAY,CAAC;EACxB,CAAC;AACF,QAAO;;AAGT,SAAS,aAAqB;AAC5B,QAAO;EACL,MAAM;EACN,OAAO,QAAQ;AACb,UAAO,SAAS;IACd,QAAQ;IACR,aAAa;IACd;;EAEJ;;AAGH,SAAS,cAAc,SAAiD;AACtE,QAAO;EACL,kBAAkB,QAAQ,oBAAoB;EAC9C,YAAY,QAAQ,cAAc,KAAK,eAAe;EACtD,QAAQ,QAAQ,UAAU,KAAK,eAAe;EAC/C"}
|
|
@@ -21,7 +21,8 @@ function toVite(name, test, loader) {
|
|
|
21
21
|
if (result === null) return null;
|
|
22
22
|
return {
|
|
23
23
|
code: result.code,
|
|
24
|
-
map: result.map
|
|
24
|
+
map: result.map,
|
|
25
|
+
moduleType: result.moduleType
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
};
|
|
@@ -29,4 +30,4 @@ function toVite(name, test, loader) {
|
|
|
29
30
|
|
|
30
31
|
//#endregion
|
|
31
32
|
export { toVite };
|
|
32
|
-
//# sourceMappingURL=vite-
|
|
33
|
+
//# sourceMappingURL=vite-6awgG092.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-6awgG092.js","names":["file"],"sources":["../src/plugins/with-loader/vite.ts"],"sourcesContent":["import type { SourceMap } from \"rollup\";\nimport type { PluginOption } from \"vite\";\nimport { parse } from \"node:querystring\";\nimport type { Loader } from \"@/plugins/with-loader\";\n\nexport function toVite(name: string, test: RegExp | undefined, loader: Loader): PluginOption {\n return {\n name: `fuma-content:${name}`,\n async transform(value, id) {\n if (test && !test.test(id)) return;\n\n const [file, query = \"\"] = id.split(\"?\", 2);\n const result = await loader.load({\n filePath: file,\n query: parse(query),\n getSource() {\n return value;\n },\n development: this.environment.mode === \"dev\",\n compiler: {\n addDependency: (file) => {\n this.addWatchFile(file);\n },\n },\n });\n\n if (result === null) return null;\n return {\n code: result.code,\n map: result.map as SourceMap,\n moduleType: result.moduleType,\n };\n },\n };\n}\n"],"mappings":";;;AAKA,SAAgB,OAAO,MAAc,MAA0B,QAA8B;AAC3F,QAAO;EACL,MAAM,gBAAgB;EACtB,MAAM,UAAU,OAAO,IAAI;AACzB,OAAI,QAAQ,CAAC,KAAK,KAAK,GAAG,CAAE;GAE5B,MAAM,CAAC,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK,EAAE;GAC3C,MAAM,SAAS,MAAM,OAAO,KAAK;IAC/B,UAAU;IACV,OAAO,MAAM,MAAM;IACnB,YAAY;AACV,YAAO;;IAET,aAAa,KAAK,YAAY,SAAS;IACvC,UAAU,EACR,gBAAgB,WAAS;AACvB,UAAK,aAAaA,OAAK;OAE1B;IACF,CAAC;AAEF,OAAI,WAAW,KAAM,QAAO;AAC5B,UAAO;IACL,MAAM,OAAO;IACb,KAAK,OAAO;IACZ,YAAY,OAAO;IACpB;;EAEJ"}
|
package/package.json
CHANGED
|
@@ -1,68 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fuma-content",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "The content processing layer for your app.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"Contentlayer",
|
|
7
|
+
"Docs"
|
|
8
8
|
],
|
|
9
|
-
"
|
|
9
|
+
"homepage": "https://fuma-content.vercel.app",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"author": "Fuma Nama",
|
|
12
|
-
"
|
|
12
|
+
"repository": "github:fuma-nama/fuma-content",
|
|
13
|
+
"bin": "./dist/bin.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"loader-mdx.cjs",
|
|
16
|
+
"loader-meta.cjs",
|
|
17
|
+
"dist/*"
|
|
18
|
+
],
|
|
13
19
|
"type": "module",
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
14
22
|
"exports": {
|
|
15
23
|
"./config": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
24
|
+
"types": "./dist/config/index.d.ts",
|
|
25
|
+
"import": "./dist/config/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./dynamic": {
|
|
28
|
+
"types": "./dist/dynamic.d.ts",
|
|
29
|
+
"import": "./dist/dynamic.js"
|
|
18
30
|
},
|
|
19
31
|
"./next": {
|
|
20
|
-
"import": "./dist/next/index.js",
|
|
21
32
|
"types": "./dist/next/index.d.ts",
|
|
33
|
+
"import": "./dist/next/index.js",
|
|
22
34
|
"require": "./dist/next/index.cjs"
|
|
23
35
|
},
|
|
24
36
|
"./vite": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
37
|
+
"types": "./dist/vite/index.d.ts",
|
|
38
|
+
"import": "./dist/vite/index.js"
|
|
27
39
|
},
|
|
28
40
|
".": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"import": "./dist/index.js"
|
|
31
43
|
},
|
|
32
44
|
"./collections": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
45
|
+
"types": "./dist/collections/index.d.ts",
|
|
46
|
+
"import": "./dist/collections/index.js"
|
|
35
47
|
},
|
|
36
48
|
"./collections/*": {
|
|
37
|
-
"import": "./dist/collections/*.js",
|
|
38
49
|
"types": "./dist/collections/*.d.ts",
|
|
50
|
+
"import": "./dist/collections/*.js",
|
|
39
51
|
"default": "./dist/collections/*.js"
|
|
40
52
|
},
|
|
41
53
|
"./node/loader": {
|
|
42
|
-
"
|
|
43
|
-
"
|
|
54
|
+
"types": "./dist/node/loader.d.ts",
|
|
55
|
+
"import": "./dist/node/loader.js"
|
|
44
56
|
},
|
|
45
57
|
"./bun": {
|
|
46
|
-
"
|
|
47
|
-
"
|
|
58
|
+
"types": "./dist/bun/index.d.ts",
|
|
59
|
+
"import": "./dist/bun/index.js"
|
|
48
60
|
},
|
|
49
61
|
"./plugins/with-loader": {
|
|
50
|
-
"
|
|
51
|
-
"
|
|
62
|
+
"types": "./dist/plugins/with-loader/index.d.ts",
|
|
63
|
+
"import": "./dist/plugins/with-loader/index.js"
|
|
52
64
|
},
|
|
53
65
|
"./plugins/*": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
66
|
+
"types": "./dist/plugins/*.d.ts",
|
|
67
|
+
"import": "./dist/plugins/*.js"
|
|
56
68
|
}
|
|
57
69
|
},
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"files": [
|
|
62
|
-
"dist/*",
|
|
63
|
-
"loader-mdx.cjs",
|
|
64
|
-
"loader-meta.cjs"
|
|
65
|
-
],
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public"
|
|
72
|
+
},
|
|
66
73
|
"dependencies": {
|
|
67
74
|
"@mdx-js/mdx": "^3.1.1",
|
|
68
75
|
"@standard-schema/spec": "^1.1.0",
|
|
@@ -80,28 +87,28 @@
|
|
|
80
87
|
"unist-util-remove-position": "^5.0.0",
|
|
81
88
|
"unist-util-visit": "^5.0.0",
|
|
82
89
|
"vfile": "^6.0.3",
|
|
83
|
-
"zod": "^4.
|
|
90
|
+
"zod": "^4.3.5"
|
|
84
91
|
},
|
|
85
92
|
"devDependencies": {
|
|
86
93
|
"@types/bun": "^1.3.5",
|
|
87
94
|
"@types/js-yaml": "^4.0.9",
|
|
88
95
|
"@types/mdast": "^4.0.4",
|
|
89
96
|
"@types/mdx": "^2.0.13",
|
|
90
|
-
"@types/node": "^
|
|
97
|
+
"@types/node": "^25.0.3",
|
|
91
98
|
"@types/picomatch": "^4.0.2",
|
|
92
99
|
"@types/react": "^19.2.7",
|
|
93
|
-
"fumadocs-core": "^16.
|
|
100
|
+
"fumadocs-core": "^16.4.4",
|
|
94
101
|
"mdast-util-directive": "^3.1.0",
|
|
95
102
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
96
|
-
"next": "16.1.
|
|
103
|
+
"next": "16.1.1",
|
|
97
104
|
"react": "^19.2.3",
|
|
98
105
|
"remark": "^15.0.1",
|
|
99
106
|
"remark-directive": "^4.0.0",
|
|
100
107
|
"remark-stringify": "^11.0.0",
|
|
101
|
-
"rollup": "^4.
|
|
108
|
+
"rollup": "^4.55.1",
|
|
102
109
|
"tsdown": "^0.18.2",
|
|
103
110
|
"typescript": "^5.9.3",
|
|
104
|
-
"vite": "^7.3.
|
|
111
|
+
"vite": "^7.3.1",
|
|
105
112
|
"webpack": "^5.104.1",
|
|
106
113
|
"typescript-config": "0.0.0"
|
|
107
114
|
},
|
|
@@ -121,9 +128,6 @@
|
|
|
121
128
|
"optional": true
|
|
122
129
|
}
|
|
123
130
|
},
|
|
124
|
-
"publishConfig": {
|
|
125
|
-
"access": "public"
|
|
126
|
-
},
|
|
127
131
|
"scripts": {
|
|
128
132
|
"build": "tsdown",
|
|
129
133
|
"clean": "rimraf dist",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-cache-BM9Yf4Nw.js","names":[],"sources":["../src/utils/async-cache.ts"],"sourcesContent":["export interface AsyncCache<V> {\n cached: (key: string, fn: () => V | Promise<V>) => V | Promise<V>;\n $value: <T>() => AsyncCache<T>;\n invalidate: (key: string) => void;\n}\n\n/**\n * cache for async resources, finished promises will be resolved into original value, otherwise wrapped with a promise.\n */\nexport function createCache<V>(\n store = new Map<string, V | Promise<V>>(),\n): AsyncCache<V> {\n return {\n cached(key, fn) {\n let cached = store.get(key);\n if (cached) return cached;\n\n cached = fn();\n if (cached instanceof Promise) {\n cached = cached.then((out) => {\n // replace with resolved if still exists\n if (store.has(key)) {\n store.set(key, out);\n }\n\n return out;\n });\n }\n store.set(key, cached);\n return cached;\n },\n invalidate(key) {\n store.delete(key);\n },\n $value<T>() {\n return this as unknown as AsyncCache<T>;\n },\n };\n}\n"],"mappings":";;;;AASA,SAAgB,YACd,wBAAQ,IAAI,KAA6B,EAC1B;AACf,QAAO;EACL,OAAO,KAAK,IAAI;GACd,IAAI,SAAS,MAAM,IAAI,IAAI;AAC3B,OAAI,OAAQ,QAAO;AAEnB,YAAS,IAAI;AACb,OAAI,kBAAkB,QACpB,UAAS,OAAO,MAAM,QAAQ;AAE5B,QAAI,MAAM,IAAI,IAAI,CAChB,OAAM,IAAI,KAAK,IAAI;AAGrB,WAAO;KACP;AAEJ,SAAM,IAAI,KAAK,OAAO;AACtB,UAAO;;EAET,WAAW,KAAK;AACd,SAAM,OAAO,IAAI;;EAEnB,SAAY;AACV,UAAO;;EAEV"}
|
package/dist/build-D8A5ByFk.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//#region src/config/build.ts
|
|
2
|
-
/**
|
|
3
|
-
* @param config - either the default export or all exports of config file.
|
|
4
|
-
* @param workspace
|
|
5
|
-
*/
|
|
6
|
-
function buildConfig(config, workspace) {
|
|
7
|
-
const collections = /* @__PURE__ */ new Map();
|
|
8
|
-
const loaded = {};
|
|
9
|
-
let globalConfig;
|
|
10
|
-
if ("default" in config) {
|
|
11
|
-
globalConfig = config.default;
|
|
12
|
-
for (const [k, v] of Object.entries(config)) {
|
|
13
|
-
if (k === "default") continue;
|
|
14
|
-
globalConfig.collections ??= {};
|
|
15
|
-
globalConfig.collections[k] = v;
|
|
16
|
-
}
|
|
17
|
-
} else globalConfig = config;
|
|
18
|
-
if (globalConfig.collections) for (const [name, collection] of Object.entries(globalConfig.collections)) {
|
|
19
|
-
collection.init?.({
|
|
20
|
-
name,
|
|
21
|
-
workspace
|
|
22
|
-
});
|
|
23
|
-
collections.set(name, collection);
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
...globalConfig,
|
|
27
|
-
collections,
|
|
28
|
-
workspaces: Object.fromEntries(Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
|
|
29
|
-
return [key, {
|
|
30
|
-
dir: value.dir,
|
|
31
|
-
config: buildConfig(value.config, {
|
|
32
|
-
...value,
|
|
33
|
-
name: key
|
|
34
|
-
})
|
|
35
|
-
}];
|
|
36
|
-
}))
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
export { buildConfig as t };
|
|
42
|
-
//# sourceMappingURL=build-D8A5ByFk.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-D8A5ByFk.js","names":["loaded: GlobalConfig","globalConfig: GlobalConfig"],"sources":["../src/config/build.ts"],"sourcesContent":["import type { GlobalConfig, WorkspaceConfig } from \"@/config/index\";\nimport type { Collection } from \"@/collections\";\n\nexport interface LoadedConfig extends Omit<\n GlobalConfig,\n \"workspaces\" | \"collections\"\n> {\n collections: Map<string, Collection>;\n workspaces: Record<\n string,\n {\n dir: string;\n config: LoadedConfig;\n }\n >;\n}\n\n/**\n * @param config - either the default export or all exports of config file.\n * @param workspace\n */\nexport function buildConfig(\n config: Record<string, unknown>,\n workspace?: WorkspaceConfig,\n): LoadedConfig {\n const collections = new Map<string, Collection>();\n const loaded: GlobalConfig = {};\n let globalConfig: GlobalConfig;\n\n if (\"default\" in config) {\n globalConfig = config.default as GlobalConfig;\n for (const [k, v] of Object.entries(config)) {\n if (k === \"default\") continue;\n\n globalConfig.collections ??= {};\n globalConfig.collections[k] = v as Collection;\n }\n } else {\n globalConfig = config as GlobalConfig;\n }\n\n if (globalConfig.collections) {\n for (const [name, collection] of Object.entries(globalConfig.collections)) {\n collection.init?.({ name, workspace });\n collections.set(name, collection);\n }\n }\n\n return {\n ...globalConfig,\n collections,\n workspaces: Object.fromEntries(\n Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {\n return [\n key,\n {\n dir: value.dir,\n config: buildConfig(value.config as Record<string, unknown>, {\n ...value,\n name: key,\n }),\n },\n ];\n }),\n ),\n };\n}\n"],"mappings":";;;;;AAqBA,SAAgB,YACd,QACA,WACc;CACd,MAAM,8BAAc,IAAI,KAAyB;CACjD,MAAMA,SAAuB,EAAE;CAC/B,IAAIC;AAEJ,KAAI,aAAa,QAAQ;AACvB,iBAAe,OAAO;AACtB,OAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,OAAO,EAAE;AAC3C,OAAI,MAAM,UAAW;AAErB,gBAAa,gBAAgB,EAAE;AAC/B,gBAAa,YAAY,KAAK;;OAGhC,gBAAe;AAGjB,KAAI,aAAa,YACf,MAAK,MAAM,CAAC,MAAM,eAAe,OAAO,QAAQ,aAAa,YAAY,EAAE;AACzE,aAAW,OAAO;GAAE;GAAM;GAAW,CAAC;AACtC,cAAY,IAAI,MAAM,WAAW;;AAIrC,QAAO;EACL,GAAG;EACH;EACA,YAAY,OAAO,YACjB,OAAO,QAAQ,OAAO,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW;AAC5D,UAAO,CACL,KACA;IACE,KAAK,MAAM;IACX,QAAQ,YAAY,MAAM,QAAmC;KAC3D,GAAG;KACH,MAAM;KACP,CAAC;IACH,CACF;IACD,CACH;EACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-mdx-C1PZsGp2.js","names":["newChildren: RootContent[]","ElementLikeTypes: ElementLikeContent[\"type\"][]","attributes: Record<string, string | null>","nodes: RootContent[] | undefined","extractedLines: string[]","content: string","fs","path","queue: Promise<void>[]","_stringifyProcessor: Processor | undefined","urls: ExtractedReference[]","postprocessOptions: PostprocessOptions","remarkIncludeOptions: RemarkIncludeOptions"],"sources":["../src/collections/mdx/remark-unravel.ts","../src/collections/mdx/mdast-utils.ts","../src/collections/mdx/remark-include.ts","../src/collections/mdx/remark-postprocess.ts","../src/collections/mdx/remark-preprocess.ts","../src/collections/mdx/build-mdx.ts"],"sourcesContent":["// from internal remark plugins in https://github.com/mdx-js/mdx/blob/main/packages/mdx/lib/plugin/remark-mark-and-unravel.js\n// we need to ensure consistency with MDX.js when parsing embed content in `remark-include`\nimport { visit } from \"unist-util-visit\";\nimport type { Transformer } from \"unified\";\nimport type { Root, RootContent } from \"mdast\";\n\nexport function remarkMarkAndUnravel(): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, (node, index, parent) => {\n let offset = -1;\n let all = true;\n let oneOrMore = false;\n\n if (parent && typeof index === \"number\" && node.type === \"paragraph\") {\n const children = node.children;\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (\n child.type === \"mdxJsxTextElement\" ||\n child.type === \"mdxTextExpression\"\n ) {\n oneOrMore = true;\n } else if (child.type === \"text\" && child.value.trim().length === 0) {\n // Empty.\n } else {\n all = false;\n break;\n }\n }\n\n if (all && oneOrMore) {\n offset = -1;\n const newChildren: RootContent[] = [];\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (child.type === \"mdxJsxTextElement\") {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = \"mdxJsxFlowElement\";\n }\n\n if (child.type === \"mdxTextExpression\") {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = \"mdxFlowExpression\";\n }\n\n if (\n child.type === \"text\" &&\n /^[\\t\\r\\n ]+$/.test(String(child.value))\n ) {\n // Empty.\n } else {\n newChildren.push(child);\n }\n }\n\n parent.children.splice(index, 1, ...newChildren);\n return index;\n }\n }\n });\n };\n}\n","import type { RootContent } from \"mdast\";\n\nexport function flattenNode(node: RootContent): string {\n if (\"children\" in node)\n return node.children.map((child) => flattenNode(child)).join(\"\");\n\n if (\"value\" in node) return node.value;\n\n return \"\";\n}\n","import {\n type PluggableList,\n type Processor,\n type Transformer,\n unified,\n} from \"unified\";\nimport { visit } from \"unist-util-visit\";\nimport type { Code, Node, Root, RootContent } from \"mdast\";\nimport * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\nimport { fumaMatter } from \"@/utils/fuma-matter\";\nimport type { MdxJsxFlowElement, MdxJsxTextElement } from \"mdast-util-mdx-jsx\";\nimport { VFile } from \"vfile\";\nimport type { Directives } from \"mdast-util-directive\";\nimport { remarkMarkAndUnravel } from \"@/collections/mdx/remark-unravel\";\nimport { flattenNode } from \"./mdast-utils\";\n\nexport interface Params {\n lang?: string;\n meta?: string;\n}\n\nconst ElementLikeTypes: ElementLikeContent[\"type\"][] = [\n \"mdxJsxFlowElement\",\n \"mdxJsxTextElement\",\n \"containerDirective\",\n \"textDirective\",\n \"leafDirective\",\n];\ntype ElementLikeContent = MdxJsxFlowElement | MdxJsxTextElement | Directives;\n\nfunction isElementLike(node: Node): node is ElementLikeContent {\n return ElementLikeTypes.includes(node.type as ElementLikeContent[\"type\"]);\n}\n\nfunction parseElementAttributes(\n element: ElementLikeContent,\n): Record<string, string | null | undefined> {\n if (Array.isArray(element.attributes)) {\n const attributes: Record<string, string | null> = {};\n\n for (const attr of element.attributes) {\n if (\n attr.type === \"mdxJsxAttribute\" &&\n (typeof attr.value === \"string\" || attr.value === null)\n ) {\n attributes[attr.name] = attr.value;\n }\n }\n\n return attributes;\n }\n\n return element.attributes ?? {};\n}\n\nfunction parseSpecifier(specifier: string): {\n file: string;\n section?: string;\n} {\n const idx = specifier.lastIndexOf(\"#\");\n if (idx === -1) return { file: specifier };\n\n return {\n file: specifier.slice(0, idx),\n section: specifier.slice(idx + 1),\n };\n}\n\nfunction extractSection(root: Root, section: string): Root | undefined {\n let nodes: RootContent[] | undefined;\n let capturingHeadingContent = false;\n\n visit(root, (node) => {\n if (node.type === \"heading\") {\n if (capturingHeadingContent) {\n return false;\n }\n\n if (node.data?.hProperties?.id === section) {\n capturingHeadingContent = true;\n nodes = [node];\n return \"skip\";\n }\n\n return;\n }\n\n if (capturingHeadingContent) {\n nodes?.push(node as RootContent);\n return \"skip\";\n }\n\n if (isElementLike(node) && node.name === \"section\") {\n const attributes = parseElementAttributes(node);\n\n if (attributes.id === section) {\n nodes = node.children;\n return false;\n }\n }\n });\n\n if (nodes)\n return {\n type: \"root\",\n children: nodes,\n };\n}\n\n// region marker regexes\nconst REGION_MARKERS = [\n {\n start: /^\\s*\\/\\/\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*\\/\\/\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*<!--\\s*#?region\\b\\s*(.*?)\\s*-->/,\n end: /^\\s*<!--\\s*#?endregion\\b\\s*(.*?)\\s*-->/,\n },\n {\n start: /^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\//,\n end: /^\\s*\\/\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\//,\n },\n {\n start: /^\\s*#[rR]egion\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#[eE]nd ?[rR]egion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*(?:--|::|@?REM)\\s*#region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*(?:--|::|@?REM)\\s*#endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#pragma\\s+region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#pragma\\s+endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*\\(\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\)/,\n end: /^\\s*\\(\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\)/,\n },\n];\n\nfunction dedent(lines: string[]): string {\n const minIndent = lines.reduce((min, line) => {\n const match = line.match(/^(\\s*)\\S/);\n return match ? Math.min(min, match[1].length) : min;\n }, Infinity);\n\n return minIndent === Infinity\n ? lines.join(\"\\n\")\n : lines.map((l) => l.slice(minIndent)).join(\"\\n\");\n}\n\nfunction extractCodeRegion(content: string, regionName: string): string {\n const lines = content.split(\"\\n\");\n\n for (let i = 0; i < lines.length; i++) {\n for (const re of REGION_MARKERS) {\n let match = re.start.exec(lines[i]);\n if (match?.[1] !== regionName) continue;\n\n let depth = 1;\n const extractedLines: string[] = [];\n for (let j = i + 1; j < lines.length; j++) {\n match = re.start.exec(lines[j]);\n if (match) {\n depth++;\n continue;\n }\n\n match = re.end.exec(lines[j]);\n if (match) {\n if (match[1] === regionName) depth = 0;\n else if (match[1] === \"\") depth--;\n else continue;\n\n if (depth > 0) continue;\n return dedent(extractedLines);\n } else {\n extractedLines.push(lines[j]);\n }\n }\n }\n }\n throw new Error(`Region \"${regionName}\" not found`);\n}\n\nexport interface RemarkIncludeOptions {\n /**\n * remark plugins to preprocess the MDAST tree before scanning headings/sections.\n *\n * e.g. parse headings before extraction.\n */\n preprocess?: PluggableList;\n}\n\nexport function remarkInclude(\n this: Processor,\n { preprocess = [] }: RemarkIncludeOptions = {},\n): Transformer<Root, Root> {\n const TagName = \"include\";\n const preprocessor = unified().use(remarkMarkAndUnravel).use(preprocess);\n\n const embedContent = async (\n targetPath: string,\n heading: string | undefined,\n params: Params,\n parent: VFile,\n ) => {\n const { _getProcessor = () => this, _compiler } = parent.data;\n let content: string;\n try {\n content = (await fs.readFile(targetPath)).toString();\n } catch (e) {\n throw new Error(\n `failed to read file ${targetPath}\\n${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n );\n }\n\n const ext = path.extname(targetPath);\n _compiler?.addDependency(targetPath);\n if (params.lang || (ext !== \".md\" && ext !== \".mdx\")) {\n const lang = params.lang ?? ext.slice(1);\n\n return {\n type: \"code\",\n lang,\n meta: params.meta,\n value: heading ? extractCodeRegion(content, heading) : content,\n data: {},\n } satisfies Code;\n }\n\n const parser = await _getProcessor(ext === \".mdx\" ? \"mdx\" : \"md\");\n const parsed = fumaMatter(content);\n const targetFile = new VFile({\n path: targetPath,\n value: parsed.content,\n data: {\n ...parent.data,\n frontmatter: parsed.data as Record<string, unknown>,\n },\n });\n\n let mdast = await preprocessor.run(\n parser.parse(targetFile) as Root,\n targetFile,\n );\n\n if (heading) {\n const extracted = extractSection(mdast, heading);\n if (!extracted)\n throw new Error(\n `Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id=\"${heading}\"> tag, or a :::section directive with remark-directive configured.`,\n );\n\n mdast = extracted;\n }\n\n await update(mdast, targetFile);\n return mdast;\n };\n\n async function update(tree: Root, file: VFile) {\n const queue: Promise<void>[] = [];\n\n visit(tree, ElementLikeTypes, (_node, _, parent) => {\n const node = _node as ElementLikeContent;\n if (node.name !== TagName) return;\n\n const specifier = flattenNode(node);\n if (specifier.length === 0) return \"skip\";\n\n const attributes = parseElementAttributes(node);\n const { file: relativePath, section } = parseSpecifier(specifier);\n const targetPath = path.resolve(\n \"cwd\" in attributes ? file.cwd : (file.dirname ?? \"\"),\n relativePath,\n );\n\n queue.push(\n embedContent(targetPath, section, attributes, file).then((replace) => {\n Object.assign(\n parent && parent.type === \"paragraph\" ? parent : node,\n replace,\n );\n }),\n );\n\n return \"skip\";\n });\n\n await Promise.all(queue);\n }\n\n return async (tree, file) => {\n await update(tree, file);\n };\n}\n","import type { Processor, Transformer } from \"unified\";\nimport type { Root, RootContent } from \"mdast\";\nimport { visit } from \"unist-util-visit\";\nimport { toMarkdown } from \"mdast-util-to-markdown\";\nimport { valueToEstree } from \"estree-util-value-to-estree\";\nimport { removePosition } from \"unist-util-remove-position\";\nimport remarkMdx from \"remark-mdx\";\nimport { flattenNode } from \"./mdast-utils\";\n\nexport interface ExtractedReference {\n href: string;\n}\n\nexport interface PostprocessOptions {\n _format: \"md\" | \"mdx\";\n\n /**\n * Properties to export from `vfile.data`\n */\n valueToExport?: string[];\n\n /**\n * stringify MDAST and export via `_markdown`.\n */\n includeProcessedMarkdown?: boolean;\n\n /**\n * extract link references, export via `extractedReferences`.\n */\n extractLinkReferences?: boolean;\n\n /**\n * store MDAST and export via `_mdast`.\n */\n includeMDAST?:\n | boolean\n | {\n removePosition?: boolean;\n };\n}\n\n/**\n * - collect references\n * - write frontmatter (auto-title & description)\n */\nexport function remarkPostprocess(\n this: Processor,\n {\n _format,\n includeProcessedMarkdown = false,\n includeMDAST = false,\n extractLinkReferences = false,\n valueToExport = [],\n }: PostprocessOptions,\n): Transformer<Root, Root> {\n let _stringifyProcessor: Processor | undefined;\n const getStringifyProcessor = () => {\n return (_stringifyProcessor ??=\n _format === \"mdx\"\n ? this\n : // force Markdown processor to stringify MDX nodes\n this().use(remarkMdx).freeze());\n };\n\n return (tree, file) => {\n const frontmatter = (file.data.frontmatter ??= {});\n if (!frontmatter.title) {\n visit(tree, \"heading\", (node) => {\n if (node.depth === 1) {\n frontmatter.title = flattenNode(node);\n return false;\n }\n });\n }\n\n file.data[\"mdx-export\"] ??= [];\n file.data[\"mdx-export\"].push({\n name: \"frontmatter\",\n value: frontmatter,\n });\n\n if (extractLinkReferences) {\n const urls: ExtractedReference[] = [];\n\n visit(tree, \"link\", (node) => {\n urls.push({\n href: node.url,\n });\n return \"skip\";\n });\n\n file.data[\"mdx-export\"].push({\n name: \"extractedReferences\",\n value: urls,\n });\n }\n\n if (includeProcessedMarkdown) {\n const processor = getStringifyProcessor();\n const markdown = toMarkdown(tree, {\n ...processor.data(\"settings\"),\n // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js\n extensions: processor.data(\"toMarkdownExtensions\") || [],\n });\n\n file.data[\"mdx-export\"].push({\n name: \"_markdown\",\n value: markdown,\n });\n }\n\n if (includeMDAST) {\n const options = includeMDAST === true ? {} : includeMDAST;\n const mdast = JSON.stringify(\n options.removePosition ? removePosition(structuredClone(tree)) : tree,\n );\n\n file.data[\"mdx-export\"].push({\n name: \"_mdast\",\n value: mdast,\n });\n }\n\n for (const { name, value } of file.data[\"mdx-export\"]) {\n tree.children.unshift(getMdastExport(name, value));\n }\n\n // reset the data to reduce memory usage\n file.data[\"mdx-export\"] = [];\n\n for (const name of valueToExport) {\n if (!(name in file.data)) continue;\n\n tree.children.unshift(getMdastExport(name, file.data[name]));\n }\n };\n}\n\n/**\n * MDX.js first converts javascript (with esm support) into mdast nodes with remark-mdx, then handle the other remark plugins\n *\n * Therefore, if we want to inject an export, we must convert the object into AST, then add the mdast node\n */\nfunction getMdastExport(name: string, value: unknown): RootContent {\n return {\n type: \"mdxjsEsm\",\n value: \"\",\n data: {\n estree: {\n type: \"Program\",\n sourceType: \"module\",\n body: [\n {\n type: \"ExportNamedDeclaration\",\n specifiers: [],\n attributes: [],\n source: null,\n declaration: {\n type: \"VariableDeclaration\",\n kind: \"let\",\n declarations: [\n {\n type: \"VariableDeclarator\",\n id: {\n type: \"Identifier\",\n name,\n },\n init: valueToEstree(value),\n },\n ],\n },\n },\n ],\n },\n },\n };\n}\n","import type { Processor, Transformer } from \"unified\";\nimport type { Root } from \"mdast\";\n\nexport interface PreprocessOptions {\n preprocessor?: Processor<Root>;\n}\n\ndeclare module \"vfile\" {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extend data map\n interface DataMap {\n _preprocessed?: boolean;\n }\n}\n\nexport function remarkPreprocess(\n options?: PreprocessOptions,\n): Transformer<Root, Root> {\n return async (tree, file) => {\n if (file.data._preprocessed) return;\n file.data._preprocessed = true;\n\n if (options?.preprocessor) {\n return (await options.preprocessor.run(tree)) as Root;\n }\n };\n}\n","import { createProcessor } from \"@mdx-js/mdx\";\nimport { VFile } from \"vfile\";\nimport {\n remarkInclude,\n type RemarkIncludeOptions,\n} from \"@/collections/mdx/remark-include\";\nimport {\n type PostprocessOptions,\n remarkPostprocess,\n} from \"@/collections/mdx/remark-postprocess\";\nimport type { Core } from \"@/core\";\nimport { remarkPreprocess } from \"@/collections/mdx/remark-preprocess\";\nimport type { Pluggable } from \"unified\";\nimport type { Collection } from \"@/collections\";\nimport { createCache } from \"@/utils/async-cache\";\nimport type { CompilerOptions } from \"@/plugins/with-loader\";\nimport type { FC } from \"react\";\nimport type { MDXProps } from \"mdx/types\";\n\ntype MDXProcessor = ReturnType<typeof createProcessor>;\n\ninterface BuildMDXOptions {\n /**\n * Specify a file path for source\n */\n filePath: string;\n source: string;\n frontmatter?: Record<string, unknown>;\n\n environment: \"bundler\" | \"runtime\";\n isDevelopment: boolean;\n _compiler?: CompilerOptions;\n}\n\nexport interface FumaContentDataMap {\n /**\n * [Fuma Content] raw frontmatter, you can modify it\n */\n frontmatter?: Record<string, unknown>;\n\n /**\n * [Fuma Content] additional ESM exports to write\n */\n \"mdx-export\"?: { name: string; value: unknown }[];\n\n /**\n * [Fuma Content] The compiler object from loader\n */\n _compiler?: CompilerOptions;\n\n /**\n * [Fuma Content] get internal processor, do not use this on user land.\n */\n _getProcessor?: (\n format: \"md\" | \"mdx\",\n ) => MDXProcessor | Promise<MDXProcessor>;\n}\n\ndeclare module \"vfile\" {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extend data map\n interface DataMap extends FumaContentDataMap {}\n}\n\nexport type CompiledMDX<Frontmatter = Record<string, unknown>> = {\n frontmatter: Frontmatter;\n} & CompiledMDXData &\n Record<string, unknown>;\n\nexport interface CompiledMDXData {\n default: FC<MDXProps>;\n\n /**\n * Enable from `postprocess` option.\n */\n _markdown?: string;\n /**\n * Enable from `postprocess` option.\n */\n _mdast?: string;\n}\n\nexport async function buildMDX(\n core: Core,\n collection: Collection | undefined,\n {\n filePath,\n frontmatter,\n source,\n _compiler,\n environment,\n isDevelopment,\n }: BuildMDXOptions,\n): Promise<VFile> {\n const handler = collection?.handlers.mdx;\n const processorCache = createCache(core.cache).$value<MDXProcessor>();\n\n function getProcessor(format: \"md\" | \"mdx\") {\n const key = `build-mdx:${collection?.name ?? \"global\"}:${format}`;\n\n return processorCache.cached(key, async () => {\n const mdxOptions = await handler?.getMDXOptions?.(environment);\n const preprocessPlugin = [\n remarkPreprocess,\n handler?.preprocess,\n ] satisfies Pluggable;\n const postprocessOptions: PostprocessOptions = {\n _format: format,\n ...handler?.postprocess,\n };\n const remarkIncludeOptions: RemarkIncludeOptions = {\n preprocess: [preprocessPlugin],\n };\n\n return createProcessor({\n outputFormat: \"program\",\n development: isDevelopment,\n ...mdxOptions,\n remarkPlugins: [\n preprocessPlugin,\n [remarkInclude, remarkIncludeOptions],\n ...(mdxOptions?.remarkPlugins ?? []),\n [remarkPostprocess, postprocessOptions],\n ],\n format,\n });\n });\n }\n\n let vfile = new VFile({\n value: source,\n path: filePath,\n cwd: handler?.cwd,\n data: {\n frontmatter,\n _compiler,\n _getProcessor: getProcessor,\n },\n });\n\n if (collection && handler) {\n vfile = await handler.vfile.run(vfile, {\n collection,\n filePath,\n source,\n });\n }\n\n return (await getProcessor(filePath.endsWith(\".mdx\") ? \"mdx\" : \"md\")).process(\n vfile,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAMA,SAAgB,uBAAgD;AAC9D,SAAQ,SAAS;AACf,QAAM,OAAO,MAAM,OAAO,WAAW;GACnC,IAAI,SAAS;GACb,IAAI,MAAM;GACV,IAAI,YAAY;AAEhB,OAAI,UAAU,OAAO,UAAU,YAAY,KAAK,SAAS,aAAa;IACpE,MAAM,WAAW,KAAK;AAEtB,WAAO,EAAE,SAAS,SAAS,QAAQ;KACjC,MAAM,QAAQ,SAAS;AAEvB,SACE,MAAM,SAAS,uBACf,MAAM,SAAS,oBAEf,aAAY;cACH,MAAM,SAAS,UAAU,MAAM,MAAM,MAAM,CAAC,WAAW,GAAG,QAE9D;AACL,YAAM;AACN;;;AAIJ,QAAI,OAAO,WAAW;AACpB,cAAS;KACT,MAAMA,cAA6B,EAAE;AAErC,YAAO,EAAE,SAAS,SAAS,QAAQ;MACjC,MAAM,QAAQ,SAAS;AAEvB,UAAI,MAAM,SAAS,oBAEjB,OAAM,OAAO;AAGf,UAAI,MAAM,SAAS,oBAEjB,OAAM,OAAO;AAGf,UACE,MAAM,SAAS,UACf,eAAe,KAAK,OAAO,MAAM,MAAM,CAAC,EACxC,OAGA,aAAY,KAAK,MAAM;;AAI3B,YAAO,SAAS,OAAO,OAAO,GAAG,GAAG,YAAY;AAChD,YAAO;;;IAGX;;;;;;AC7DN,SAAgB,YAAY,MAA2B;AACrD,KAAI,cAAc,KAChB,QAAO,KAAK,SAAS,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Q,MAAM,QAAQ,aAAa,IAAI,KAAK;;;;;;AC2DlD,eAAsB,SACpB,MACA,YACA,EACE,UACA,aACA,QACA,WACA,aACA,iBAEc;CAChB,MAAM,UAAU,YAAY,SAAS;CACrC,MAAM,iBAAiB,YAAY,KAAK,MAAM,CAAC,QAAsB;CAErE,SAAS,aAAa,QAAsB;EAC1C,MAAM,MAAM,aAAa,YAAY,QAAQ,SAAS,GAAG;AAEzD,SAAO,eAAe,OAAO,KAAK,YAAY;GAC5C,MAAM,aAAa,MAAM,SAAS,gBAAgB,YAAY;GAC9D,MAAM,mBAAmB,CACvB,kBACA,SAAS,WACV;GACD,MAAMC,qBAAyC;IAC7C,SAAS;IACT,GAAG,SAAS;IACb;GACD,MAAMC,uBAA6C,EACjD,YAAY,CAAC,iBAAiB,EAC/B;AAED,UAAO,gBAAgB;IACrB,cAAc;IACd,aAAa;IACb,GAAG;IACH,eAAe;KACb;KACA,CAAC,eAAe,qBAAqB;KACrC,GAAI,YAAY,iBAAiB,EAAE;KACnC,CAAC,mBAAmB,mBAAmB;KACxC;IACD;IACD,CAAC;IACF;;CAGJ,IAAI,QAAQ,IAAI,MAAM;EACpB,OAAO;EACP,MAAM;EACN,KAAK,SAAS;EACd,MAAM;GACJ;GACA;GACA,eAAe;GAChB;EACF,CAAC;AAEF,KAAI,cAAc,QAChB,SAAQ,MAAM,QAAQ,MAAM,IAAI,OAAO;EACrC;EACA;EACA;EACD,CAAC;AAGJ,SAAQ,MAAM,aAAa,SAAS,SAAS,OAAO,GAAG,QAAQ,KAAK,EAAE,QACpE,MACD"}
|
package/dist/bun-QKQnqgIi.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bun-QKQnqgIi.js","names":["input: LoaderInput"],"sources":["../src/plugins/with-loader/bun.ts"],"sourcesContent":["import { parse } from \"node:querystring\";\nimport { readFileSync } from \"node:fs\";\nimport type { LoaderInput, Loader, LoaderOutput } from \"@/plugins/with-loader\";\n\nexport function toBun(test: RegExp = /.+/, loader: Loader) {\n function toResult(output: LoaderOutput | null): Bun.OnLoadResult {\n // it errors, treat this as an exception\n if (!output) return;\n\n return {\n contents: output.code,\n loader: \"js\",\n };\n }\n\n return (build: Bun.PluginBuilder): void => {\n // avoid using async here, because it will cause dynamic require() to fail\n build.onLoad({ filter: test }, (args) => {\n const [filePath, query = \"\"] = args.path.split(\"?\", 2);\n const input: LoaderInput = {\n async getSource() {\n return Bun.file(filePath).text();\n },\n query: parse(query),\n filePath,\n development: false,\n compiler: {\n addDependency() {},\n },\n };\n\n if (loader.bun?.load) {\n return loader.bun.load(readFileSync(filePath).toString(), input);\n }\n\n const result = loader.load(input);\n if (result instanceof Promise) {\n return result.then(toResult);\n }\n return toResult(result);\n });\n };\n}\n"],"mappings":";;;;AAIA,SAAgB,MAAM,OAAe,MAAM,QAAgB;CACzD,SAAS,SAAS,QAA+C;AAE/D,MAAI,CAAC,OAAQ;AAEb,SAAO;GACL,UAAU,OAAO;GACjB,QAAQ;GACT;;AAGH,SAAQ,UAAmC;AAEzC,QAAM,OAAO,EAAE,QAAQ,MAAM,GAAG,SAAS;GACvC,MAAM,CAAC,UAAU,QAAQ,MAAM,KAAK,KAAK,MAAM,KAAK,EAAE;GACtD,MAAMA,QAAqB;IACzB,MAAM,YAAY;AAChB,YAAO,IAAI,KAAK,SAAS,CAAC,MAAM;;IAElC,OAAO,MAAM,MAAM;IACnB;IACA,aAAa;IACb,UAAU,EACR,gBAAgB,IACjB;IACF;AAED,OAAI,OAAO,KAAK,KACd,QAAO,OAAO,IAAI,KAAK,aAAa,SAAS,CAAC,UAAU,EAAE,MAAM;GAGlE,MAAM,SAAS,OAAO,KAAK,MAAM;AACjC,OAAI,kBAAkB,QACpB,QAAO,OAAO,KAAK,SAAS;AAE9B,UAAO,SAAS,OAAO;IACvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code-generator-gPtrfZ6Q.js","names":["code: string","filename: string","final: string[]","namedImports: string[]","path"],"sources":["../src/utils/code-generator.ts"],"sourcesContent":["import path from \"node:path\";\nimport { glob } from \"tinyglobby\";\nimport { type AsyncCache, createCache } from \"@/utils/async-cache\";\n\nexport interface GlobImportOptions {\n base: string;\n query?: Record<string, string | undefined>;\n import?: string;\n eager?: boolean;\n}\n\nexport interface CodeGeneratorOptions {\n target: \"default\" | \"vite\";\n outDir: string;\n /**\n * add .js extenstion to imports\n */\n jsExtension: boolean;\n globCache: Map<string, Promise<string[]>>;\n}\n\ninterface ImportInfo {\n // import name -> member name\n named: Map<string, string>;\n namespaces: Set<string>;\n /**\n * a set of import names, the import is type-only if its name is missing in this set.\n */\n isUsed: Set<string>;\n}\n\nfunction importInfo(): ImportInfo {\n return {\n named: new Map(),\n namespaces: new Set(),\n isUsed: new Set(),\n };\n}\n\n/**\n * Code generator (one instance per file)\n */\nexport class CodeGenerator {\n private readonly lines: string[] = [];\n private readonly globCache: AsyncCache<string[]>;\n // specifier -> imported members/info\n private readonly importInfos = new Map<string, ImportInfo>();\n private eagerImportId = 0;\n\n readonly options: CodeGeneratorOptions;\n constructor({\n target = \"default\",\n jsExtension = false,\n globCache = new Map(),\n outDir = \"\",\n }: Partial<CodeGeneratorOptions>) {\n this.options = {\n target,\n jsExtension,\n globCache,\n outDir,\n };\n this.globCache = createCache(globCache);\n }\n\n addNamespaceImport(namespace: string, specifier: string, types = false) {\n const info = this.importInfos.get(specifier) ?? importInfo();\n this.importInfos.set(specifier, info);\n if (!types) info.isUsed.add(namespace);\n info.namespaces.add(namespace);\n }\n\n addNamedImport(names: string[], specifier: string, types = false) {\n const info = this.importInfos.get(specifier) ?? importInfo();\n this.importInfos.set(specifier, info);\n for (const name of names) {\n const [memberName, importName = memberName] = name.split(/\\s+as\\s+/, 2);\n info.named.set(importName, memberName);\n if (!types) info.isUsed.add(importName);\n }\n }\n\n push(...insert: string[]) {\n this.lines.push(...insert);\n }\n\n async pushAsync(insert: Promise<string | undefined>[]) {\n for (const line of await Promise.all(insert)) {\n if (line === undefined) continue;\n\n this.lines.push(line);\n }\n }\n\n async generateGlobImport(\n patterns: string | string[],\n options: GlobImportOptions,\n ): Promise<string> {\n if (this.options.target === \"vite\") {\n return this.generateViteGlobImport(patterns, options);\n }\n\n return this.generateNodeGlobImport(patterns, options);\n }\n\n private generateViteGlobImport(\n patterns: string | string[],\n { base, ...rest }: GlobImportOptions,\n ): string {\n patterns = (typeof patterns === \"string\" ? [patterns] : patterns).map(\n normalizeViteGlobPath,\n );\n\n return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(\n {\n base: normalizeViteGlobPath(path.relative(this.options.outDir, base)),\n ...rest,\n },\n null,\n 2,\n )})`;\n }\n\n private async generateNodeGlobImport(\n patterns: string | string[],\n { base, eager = false, query = {}, import: importName }: GlobImportOptions,\n ): Promise<string> {\n const files = await this.globCache.cached(\n JSON.stringify({ patterns, base }),\n () =>\n glob(patterns, {\n cwd: base,\n }),\n );\n\n let code: string = \"{\";\n for (const item of files) {\n const fullPath = path.join(base, item);\n const searchParams = new URLSearchParams();\n\n for (const [k, v] of Object.entries(query)) {\n if (v !== undefined) searchParams.set(k, v);\n }\n\n const importPath = `${this.formatImportPath(fullPath)}?${searchParams.toString()}`;\n if (eager) {\n const name = `__fd_glob_${this.eagerImportId++}`;\n this.lines.unshift(\n importName\n ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}`\n : `import * as ${name} from ${JSON.stringify(importPath)}`,\n );\n\n code += `${JSON.stringify(item)}: ${name}, `;\n } else {\n let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;\n if (importName) {\n line += `.then(mod => mod.${importName})`;\n }\n\n code += `${line}, `;\n }\n }\n\n code += \"}\";\n return code;\n }\n\n formatImportPath(file: string) {\n const ext = path.extname(file);\n let filename: string;\n\n if (ext === \".ts\") {\n filename = file.substring(0, file.length - ext.length);\n if (this.options.jsExtension) filename += \".js\";\n } else {\n filename = file;\n }\n\n const importPath = slash(path.relative(this.options.outDir, filename));\n return importPath.startsWith(\".\") ? importPath : `./${importPath}`;\n }\n\n toString() {\n const final: string[] = [\"// @ts-nocheck\"];\n if (this.options.target === \"vite\") {\n final.push('/// <reference types=\"vite/client\" />');\n }\n\n for (const [specifier, info] of this.importInfos) {\n const { namespaces, named, isUsed } = info;\n for (const namespace of namespaces) {\n final.push(\n isUsed.has(namespace)\n ? `import * as ${namespace} from \"${specifier}\";`\n : `import type * as ${namespace} from \"${specifier}\";`,\n );\n }\n\n const namedImports: string[] = [];\n for (const [importName, memberName] of named) {\n const item =\n importName === memberName\n ? importName\n : `${memberName} as ${importName}`;\n\n namedImports.push(isUsed.has(importName) ? item : `type ${item}`);\n }\n\n if (namedImports.length > 0) {\n final.push(\n `import { ${namedImports.join(\", \")} } from \"${specifier}\";`,\n );\n }\n }\n\n final.push(...this.lines);\n return final.join(\"\\n\");\n }\n}\n\n/**\n * convert into POSIX & relative file paths, such that Vite can accept it.\n */\nfunction normalizeViteGlobPath(file: string) {\n file = slash(file);\n if (file.startsWith(\"./\")) return file;\n if (file.startsWith(\"/\")) return `.${file}`;\n\n return `./${file}`;\n}\n\nexport function slash(path: string): string {\n const isExtendedLengthPath = path.startsWith(\"\\\\\\\\?\\\\\");\n\n if (isExtendedLengthPath) {\n return path;\n }\n\n return path.replaceAll(\"\\\\\", \"/\");\n}\n\nexport function ident(code: string, tab: number = 1) {\n return code\n .split(\"\\n\")\n .map((v) => \" \".repeat(tab) + v)\n .join(\"\\n\");\n}\n"],"mappings":";;;;;AA+BA,SAAS,aAAyB;AAChC,QAAO;EACL,uBAAO,IAAI,KAAK;EAChB,4BAAY,IAAI,KAAK;EACrB,wBAAQ,IAAI,KAAK;EAClB;;;;;AAMH,IAAa,gBAAb,MAA2B;CACzB,AAAiB,QAAkB,EAAE;CACrC,AAAiB;CAEjB,AAAiB,8BAAc,IAAI,KAAyB;CAC5D,AAAQ,gBAAgB;CAExB,AAAS;CACT,YAAY,EACV,SAAS,WACT,cAAc,OACd,4BAAY,IAAI,K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AAI,GAAG,aAAa,KAAK;;CAGxD,WAAW;EACT,MAAMC,QAAkB,CAAC,iBAAiB;AAC1C,MAAI,KAAK,QAAQ,WAAW,OAC1B,OAAM,KAAK,0CAAwC;AAGrD,OAAK,MAAM,CAAC,WAAW,SAAS,KAAK,aAAa;GAChD,MAAM,EAAE,YAAY,OAAO,WAAW;AACtC,QAAK,MAAM,aAAa,WACtB,OAAM,KACJ,OAAO,IAAI,UAAU,GACjB,eAAe,UAAU,SAAS,UAAU,MAC5C,oBAAoB,UAAU,SAAS,UAAU,IACtD;GAGH,MAAMC,eAAyB,EAAE;AACjC,QAAK,MAAM,CAAC,YAAY,eAAe,OAAO;IAC5C,MAAM,OACJ,eAAe,aACX,aACA,GAAG,WAAW,MAAM;AAE1B,iBAAa,KAAK,OAAO,IAAI,WAAW,GAAG,OAAO,QAAQ,OAAO;;AAGnE,OAAI,aAAa,SAAS,EACxB,OAAM,KACJ,YAAY,aAAa,KAAK,KAAK,CAAC,WAAW,UAAU,IAC1D;;AAIL,QAAM,KAAK,GAAG,KAAK,MAAM;AACzB,SAAO,MAAM,KAAK,KAAK;;;;;;AAO3B,SAAS,sBAAsB,MAAc;AAC3C,QAAO,MAAM,KAAK;AAClB,KAAI,KAAK,WAAW,KAAK,CAAE,QAAO;AAClC,KAAI,KAAK,WAAW,IAAI,CAAE,QAAO,IAAI;AAErC,QAAO,KAAK;;AAGd,SAAgB,MAAM,QAAsB;AAG1C,KAF6BC,OAAK,WAAW,UAAU,CAGrD,QAAOA;AAGT,QAAOA,OAAK,WAAW,MAAM,IAAI"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core-Bkh-SI_3.d.ts","names":[],"sources":["../src/plugins/json-schema.ts","../src/collections/handlers/fs.ts","../src/collections/mdx/remark-postprocess.ts","../src/collections/mdx/remark-preprocess.ts","../src/types.ts","../src/utils/pipe.ts","../src/plugins/with-loader/index.ts","../src/collections/mdx/build-mdx.ts","../src/collections/mdx.ts","../src/collections/meta.ts","../src/plugins/git.ts","../src/collections/index.ts","../src/config/index.ts","../src/config/build.ts","../src/utils/code-generator.ts","../src/core.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;UAIiB,iBAAA;;;;;;;;UASA,iBAAA;qCACoB;;;AAVrC;AASA;AAEC;;AASE,iBAFqB,UAAA,CAErB;EAAA;AAAA,CAAA,CAAA,EAAA,iBAAA,CAAA,EAAyB,MAAzB;;;UCpBc,iBAAA;;;;;;;;;;;;ADAjB;AASA;EASwB,gBAAU,CAAA,EAAA,MAAA,EAAA;;AAE/B,UCDc,qBAAA,CDCd;EAAyB;;;;;ECpBX,eAAA,EAAA,CAAA,QAAiB,EAAA,MAAA,EAAA,GAAA,OAAA;EAmBjB,QAAA,EAAA,MAAA,EAAA;AAUjB;AACc,iBADE,kBAAA,CACF,UAAA,EAAA,UAAA,EAAA,IAAA,EACN,WADM,EAAA,MAAA,EAEJ,iBAFI,CAAA,EAAA,IAAA;;;UCzBG,kBAAA;;;UAIA,kBAAA;;;;;;;;AFTjB;EASiB,wBAAiB,CAAA,EAAA,OACG;EAQb;;;EAEI,qBAAA,CAAA,EAAA,OAAA;EAAM;;;;ICpBjB,cAAA,CAAA,EAAiB,OAAA;EAmBjB,CAAA;AAUjB;;;UE9BiB,iBAAA;iBACA,UAAU;;;;;;;;;KCAf,mDACV,eAAe,OAAO,MAAM,cACxB,OAAO,QACP;WACa;IAEX,YAAY;KAGR,iBAAe,IAAI,YAAY;;;UCX1B;;;;;;oBAMG,eAAe,YAAY,SAAS,KAAK,MAAM;cACrD,eAAe,YAAY;;UAGxB;;;ALRjB;AASA;AAEC;EAQC,IAAA,EAAA,CAAA,EAAA,EAAA,CAAA,IAAA,EKJa,ILIb,EAAA,OAAA,EKJ4B,OLI5B,EAAA,GKJwC,WLIxC,CKJkD,ILIlD,CAAA,EAAA,GKHK,SLGL,CKHe,ILGf,EKHqB,OLGrB,CAAA;EACC,GAAA,EAAA,CAAA,IAAA,EKHW,ILGX,E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oVBkeg.js","names":["plugins: Plugin[]","workspace","promises: Awaitable<void>[]","ctx: EmitContext","out: EmitOutput"],"sources":["../src/core.ts"],"sourcesContent":["import type { LoadedConfig } from \"@/config/build\";\nimport path from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport type { FSWatcher } from \"chokidar\";\nimport type { Collection } from \"@/collections\";\nimport type * as Vite from \"vite\";\nimport type { NextConfig } from \"next\";\nimport type { LoadHook } from \"node:module\";\nimport { CodeGenerator } from \"@/utils/code-generator\";\nimport type { Awaitable } from \"@/types\";\n\nexport interface EmitEntry {\n /**\n * path relative to output directory\n */\n path: string;\n content: string;\n}\n\nexport interface PluginContext {\n core: Core;\n}\n\nexport interface EmitContext extends PluginContext {\n createCodeGenerator: (\n path: string,\n content: (ctx: EmitCodeGeneratorContext) => Promise<void>,\n ) => Promise<EmitEntry>;\n}\n\nexport interface EmitCodeGeneratorContext {\n core: Core;\n workspace?: string;\n codegen: CodeGenerator;\n}\n\nexport interface Plugin {\n /**\n * unique name for plugin\n *\n * @example `my-package:my-plugin`\n */\n name: string;\n\n /**\n * on config loaded/updated\n */\n config?: (\n this: PluginContext,\n config: LoadedConfig,\n ) => Awaitable<void | LoadedConfig>;\n\n collection?: (this: PluginContext, collection: Collection) => Awaitable<void>;\n\n /**\n * Generate files (e.g. types, index file, or JSON schemas)\n */\n emit?: (this: EmitContext) => Awaitable<EmitEntry[]>;\n\n /**\n * Configure Fumadocs dev server\n */\n configureServer?: (\n this: PluginContext,\n server: ServerContext,\n ) => Awaitable<void>;\n\n vite?: {\n createPlugin?: (this: PluginContext) => Vite.PluginOption;\n };\n\n bun?: {\n build?: (this: PluginContext, build: Bun.PluginBuilder) => Awaitable<void>;\n };\n\n next?: {\n config?: (this: PluginContext, config: NextConfig) => NextConfig;\n };\n\n node?: {\n createLoad?: (this: PluginContext) => Awaitable<LoadHook>;\n };\n}\n\nexport type PluginOption = Awaitable<\n Plugin | PluginOption[] | false | undefined\n>;\n\nexport interface ServerContext {\n /**\n * the file watcher, by default all content files are watched, along with other files.\n *\n * make sure to filter when listening to events\n */\n watcher?: FSWatcher;\n}\n\nexport interface CoreOptions {\n configPath: string;\n outDir: string;\n plugins?: PluginOption[];\n\n emit?: {\n target?: \"default\" | \"vite\";\n /**\n * add .js extenstion to imports\n */\n jsExtension?: boolean;\n };\n\n /**\n * the workspace info if this instance is created as a workspace\n */\n workspace?: {\n parent: Core;\n name: string;\n dir: string;\n };\n}\n\nexport interface EmitOptions {\n /**\n * filter the plugins to run emit\n */\n filterPlugin?: (plugin: Plugin) => boolean;\n\n /**\n * filter the workspaces to run emit\n */\n filterWorkspace?: (workspace: string) => boolean;\n\n /**\n * write files\n */\n write?: boolean;\n}\n\nexport interface EmitOutput {\n entries: EmitEntry[];\n workspaces: Record<string, EmitEntry[]>;\n}\n\nasync function getPlugins(pluginOptions: PluginOption[]): Promise<Plugin[]> {\n const plugins: Plugin[] = [];\n\n for (const option of await Promise.all(pluginOptions)) {\n if (!option) continue;\n if (Array.isArray(option)) plugins.push(...(await getPlugins(option)));\n else plugins.push(option);\n }\n\n return plugins;\n}\n\nexport class Core {\n private readonly workspaces = new Map<string, Core>();\n private readonly options: CoreOptions;\n private plugins: Plugin[] = [];\n private config!: LoadedConfig;\n static defaultOptions = {\n configPath: \"content.config.ts\",\n outDir: \".content\",\n };\n\n /**\n * Convenient cache store, reset when config changes.\n *\n * You can group namespaces in cache key with \":\", like `my-plugin:data`\n */\n readonly cache = new Map<string, unknown>();\n\n constructor(options: CoreOptions) {\n this.options = options;\n }\n\n async init({ config: newConfig }: { config: Awaitable<LoadedConfig> }) {\n this.config = await newConfig;\n this.cache.clear();\n this.workspaces.clear();\n const loadedCollectionTypeIds = new Set<string>();\n this.plugins = await getPlugins([\n this.options.plugins,\n this.config.plugins,\n ...this.config.collections.values().map(({ typeInfo }) => {\n if (loadedCollectionTypeIds.has(typeInfo.id)) return false;\n\n loadedCollectionTypeIds.add(typeInfo.id);\n return typeInfo.plugins;\n }),\n ]);\n\n const ctx = this.getPluginContext();\n for (const plugin of this.plugins) {\n const out = await plugin.config?.call(ctx, this.config);\n if (out) this.config = out;\n }\n\n const { workspace, outDir } = this.options;\n // only support workspaces with max depth 1\n if (!workspace) {\n await Promise.all(\n Object.entries(this.config.workspaces).map(\n async ([name, workspace]) => {\n const child = new Core({\n ...this.options,\n outDir: path.join(outDir, name),\n workspace: {\n name,\n parent: this,\n dir: workspace.dir,\n },\n });\n\n await child.init({ config: workspace.config });\n this.workspaces.set(name, child);\n },\n ),\n );\n }\n\n await Promise.all(\n this.config.collections.values().map(async (collection) => {\n for (const plugin of this.plugins) {\n await plugin.collection?.call(ctx, collection);\n }\n }),\n );\n }\n\n getWorkspaces() {\n return this.workspaces;\n }\n getOptions() {\n return this.options;\n }\n getConfig(): LoadedConfig {\n return this.config;\n }\n /**\n * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)\n */\n getCompiledConfigPath(): string {\n return path.join(this.options.outDir, \"content.config.mjs\");\n }\n getPlugins(workspace = false) {\n if (workspace) {\n const plugins = [...this.plugins];\n for (const workspace of this.workspaces.values()) {\n plugins.push(...workspace.plugins);\n }\n return plugins;\n }\n\n return this.plugins;\n }\n getCollections(workspace = false): Collection[] {\n const list = Array.from(this.config.collections.values());\n if (workspace) {\n for (const workspace of this.workspaces.values()) {\n list.push(...workspace.getCollections());\n }\n }\n return list;\n }\n getCollection(name: string): Collection | undefined {\n return this.config.collections.get(name);\n }\n getPluginContext(): PluginContext {\n return {\n core: this,\n };\n }\n async initServer(server: ServerContext) {\n const ctx = this.getPluginContext();\n const promises: Awaitable<void>[] = [];\n\n for (const plugin of this.plugins) {\n promises.push(plugin.configureServer?.call(ctx, server));\n }\n for (const workspace of this.workspaces.values()) {\n promises.push(workspace.initServer(server));\n }\n\n await Promise.all(promises);\n }\n\n async emit(emitOptions: EmitOptions = {}): Promise<EmitOutput> {\n const {\n workspace,\n outDir,\n emit: { target, jsExtension } = {},\n } = this.options;\n const { filterPlugin, filterWorkspace, write = false } = emitOptions;\n const start = performance.now();\n const globCache = new Map<string, Promise<string[]>>();\n const ctx: EmitContext = {\n ...this.getPluginContext(),\n createCodeGenerator: async (path, content) => {\n const codegen = new CodeGenerator({\n target,\n outDir,\n jsExtension,\n globCache,\n });\n await content({\n core: this,\n codegen,\n workspace: workspace?.name,\n });\n return {\n path,\n content: codegen.toString(),\n };\n },\n };\n\n const added = new Set<string>();\n const out: EmitOutput = {\n entries: [],\n workspaces: {},\n };\n\n for (const li of await Promise.all(\n this.plugins.map((plugin) => {\n if ((filterPlugin && !filterPlugin(plugin)) || !plugin.emit)\n return null;\n return plugin.emit.call(ctx);\n }),\n )) {\n if (!li) continue;\n for (const item of li) {\n if (added.has(item.path)) continue;\n out.entries.push(item);\n added.add(item.path);\n }\n }\n\n if (write) {\n await Promise.all(\n out.entries.map(async (entry) => {\n const file = path.join(outDir, entry.path);\n await fs.mkdir(path.dirname(file), { recursive: true });\n await fs.writeFile(file, entry.content);\n }),\n );\n\n console.log(\n workspace\n ? `[MDX: ${workspace.name}] generated files in ${performance.now() - start}ms`\n : `[MDX] generated files in ${performance.now() - start}ms`,\n );\n }\n\n await Promise.all(\n this.workspaces.entries().map(async ([name, workspace]) => {\n if (filterWorkspace && !filterWorkspace(name)) return;\n out.workspaces[name] = (await workspace.emit(emitOptions)).entries;\n }),\n );\n\n return out;\n }\n}\n"],"mappings":";;;;;AA8IA,eAAe,WAAW,eAAkD;CAC1E,MAAMA,UAAoB,EAAE;AAE5B,MAAK,MAAM,UAAU,MAAM,QAAQ,IAAI,cAAc,EAAE;AACrD,MAAI,CAAC,OAAQ;AACb,MAAI,MAAM,QAAQ,OAAO,CAAE,SAAQ,KAAK,GAAI,MAAM,WAAW,OAAO,CAAE;MACjE,SAAQ,KAAK,OAAO;;AAG3B,QAAO;;AAGT,IAAa,OAAb,MAAa,KAAK;CAChB,AAAiB,6BAAa,IAAI,KAAmB;CACrD,AAAiB;CACjB,AAAQ,UAAoB,EAAE;CAC9B,AAA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YAAU,KAAK,YAAY,EAAE;IAC3D,CACH;AAED,SAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-B40uAtdo.js","names":["prev:\n | {\n hash: string;\n init: Promise<void>;\n }\n | undefined"],"sources":["../src/config/dynamic.ts"],"sourcesContent":["import type { Core } from \"@/core\";\nimport fs from \"node:fs/promises\";\n\nexport interface DynamicCore {\n getCore(): Core | Promise<Core>;\n}\n\nexport function createDynamicCore({\n core,\n buildConfig,\n mode,\n}: {\n /**\n * core (not initialized)\n */\n core: Core;\n buildConfig: boolean;\n /**\n * In dev mode, the config file is dynamically re-loaded when it's updated.\n */\n mode: \"dev\" | \"production\";\n}): DynamicCore {\n let prev:\n | {\n hash: string;\n init: Promise<void>;\n }\n | undefined;\n\n async function getConfigHash(): Promise<string> {\n if (mode === \"production\") return \"static\";\n\n const stats = await fs.stat(core.getOptions().configPath).catch(() => {\n throw new Error(\"Cannot find config file\");\n });\n\n return stats.mtime.getTime().toString();\n }\n\n return {\n async getCore() {\n const hash = await getConfigHash();\n if (!prev || hash !== prev.hash) {\n prev = {\n hash,\n init: (async () => {\n const { loadConfig } = await import(\"../config/load-from-file\");\n\n await core.init({\n config: loadConfig(core, buildConfig),\n });\n })(),\n };\n }\n\n await prev.init;\n return core;\n },\n };\n}\n"],"mappings":";;;AAOA,SAAgB,kBAAkB,EAChC,MACA,aACA,QAWc;CACd,IAAIA;CAOJ,eAAe,gBAAiC;AAC9C,MAAI,SAAS,aAAc,QAAO;AAMlC,UAJc,MAAM,GAAG,KAAK,KAAK,YAAY,CAAC,WAAW,CAAC,YAAY;AACpE,SAAM,IAAI,MAAM,0BAA0B;IAC1C,EAEW,MAAM,SAAS,CAAC,UAAU;;AAGzC,QAAO,EACL,MAAM,UAAU;EACd,MAAM,OAAO,MAAM,eAAe;AAClC,MAAI,CAAC,QAAQ,SAAS,KAAK,KACzB,QAAO;GACL;GACA,OAAO,YAAY;IACjB,MAAM,EAAE,eAAe,MAAM,OAAO;AAEpC,UAAM,KAAK,KAAK,EACd,QAAQ,WAAW,MAAM,YAAY,EACtC,CAAC;OACA;GACL;AAGH,QAAM,KAAK;AACX,SAAO;IAEV"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fuma-matter-O4fA6nSx.js","names":["output: Output"],"sources":["../src/utils/fuma-matter.ts"],"sourcesContent":["/**\n * Inspired by https://github.com/jonschlinkert/gray-matter\n */\nimport { load } from \"js-yaml\";\n\ninterface Output {\n /**\n * The matter section, including the delimiter.\n */\n matter: string;\n content: string;\n data: unknown;\n}\n\nconst regex = /^---\\r?\\n(.+?)\\r?\\n---\\r?\\n/s;\n\n/**\n * parse frontmatter, it supports only yaml format\n */\nexport function fumaMatter(input: string): Output {\n const output: Output = { matter: \"\", data: {}, content: input };\n const match = regex.exec(input);\n if (!match) {\n return output;\n }\n\n // get the raw front-matter block\n output.matter = match[0];\n output.content = input.slice(match[0].length);\n\n const loaded = load(match[1]);\n output.data = loaded ?? {};\n\n return output;\n}\n"],"mappings":";;;;;;AAcA,MAAM,QAAQ;;;;AAKd,SAAgB,WAAW,OAAuB;CAChD,MAAMA,SAAiB;EAAE,QAAQ;EAAI,MAAM,EAAE;EAAE,SAAS;EAAO;CAC/D,MAAM,QAAQ,MAAM,KAAK,MAAM;AAC/B,KAAI,CAAC,MACH,QAAO;AAIT,QAAO,SAAS,MAAM;AACtB,QAAO,UAAU,MAAM,MAAM,MAAM,GAAG,OAAO;AAG7C,QAAO,OADQ,KAAK,MAAM,GAAG,IACL,EAAE;AAE1B,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-from-file-1f4WaHsf.js","names":[],"sources":["../src/config/load-from-file.ts"],"sourcesContent":["import { pathToFileURL } from \"node:url\";\nimport type { LoadedConfig } from \"@/config/build\";\nimport { buildConfig } from \"@/config/build\";\nimport type { Core } from \"@/core\";\n\nasync function compileConfig(core: Core) {\n const { build } = await import(\"esbuild\");\n const { configPath, outDir } = core.getOptions();\n\n const transformed = await build({\n entryPoints: [{ in: configPath, out: \"content.config\" }],\n bundle: true,\n outdir: outDir,\n target: \"node20\",\n write: true,\n platform: \"node\",\n format: \"esm\",\n packages: \"external\",\n outExtension: {\n \".js\": \".mjs\",\n },\n allowOverwrite: true,\n });\n\n if (transformed.errors.length > 0) {\n throw new Error(\"failed to compile configuration file\");\n }\n}\n\n/**\n * Load config\n *\n * @param build - By default, it assumes the config file has been compiled. Set this `true` to compile the config first.\n */\nexport async function loadConfig(\n core: Core,\n build = false,\n): Promise<LoadedConfig> {\n if (build) await compileConfig(core);\n\n const url = pathToFileURL(core.getCompiledConfigPath());\n // always return a new config\n url.searchParams.set(\"hash\", Date.now().toString());\n\n const config = import(url.href).then((loaded) =>\n buildConfig(loaded as Record<string, unknown>),\n );\n\n return await config;\n}\n"],"mappings":";;;;AAKA,eAAe,cAAc,MAAY;CACvC,MAAM,EAAE,UAAU,MAAM,OAAO;CAC/B,MAAM,EAAE,YAAY,WAAW,KAAK,YAAY;AAiBhD,MAfoB,MAAM,MAAM;EAC9B,aAAa,CAAC;GAAE,IAAI;GAAY,KAAK;GAAkB,CAAC;EACxD,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,UAAU;EACV,QAAQ;EACR,UAAU;EACV,cAAc,EACZ,OAAO,QACR;EACD,gBAAgB;EACjB,CAAC,EAEc,OAAO,SAAS,EAC9B,OAAM,IAAI,MAAM,uCAAuC;;;;;;;AAS3D,eAAsB,WACpB,MACA,QAAQ,OACe;AACvB,KAAI,MAAO,OAAM,cAAc,KAAK;CAEpC,MAAM,MAAM,cAAc,KAAK,uBAAuB,CAAC;AAEvD,KAAI,aAAa,IAAI,QAAQ,KAAK,KAAK,CAAC,UAAU,CAAC;AAMnD,QAAO,MAJQ,OAAO,IAAI,MAAM,MAAM,WACpC,YAAY,OAAkC,CAC/C"}
|
package/dist/loader-80abXEHx.js
DELETED
package/dist/loader-BFhPyg3z.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loader-CXnMFuyE.js","names":["after: (() => Promise<void>) | undefined"],"sources":["../src/collections/mdx/loader.ts"],"sourcesContent":["import { fumaMatter } from \"@/utils/fuma-matter\";\nimport type { SourceMap } from \"rollup\";\nimport { z } from \"zod\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createHash } from \"node:crypto\";\nimport type { Loader } from \"@/plugins/with-loader\";\nimport type { DynamicCore } from \"@/config/dynamic\";\n\nconst querySchema = z\n .object({\n only: z.literal([\"frontmatter\", \"all\"]).default(\"all\"),\n collection: z.string().optional(),\n workspace: z.string().optional(),\n })\n .loose();\n\nconst cacheEntry = z.object({\n code: z.string(),\n map: z.any().optional(),\n hash: z.string().optional(),\n});\n\ntype CacheEntry = z.infer<typeof cacheEntry>;\n\nexport function createMdxLoader({ getCore }: DynamicCore): Loader {\n return {\n async load({\n getSource,\n development: isDevelopment,\n query,\n compiler,\n filePath,\n }) {\n let core = await getCore();\n const value = await getSource();\n const matter = fumaMatter(value);\n const {\n collection: collectionName,\n workspace,\n only,\n } = querySchema.parse(query);\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n let after: (() => Promise<void>) | undefined;\n\n const { experimentalBuildCache = false } = core.getConfig();\n if (!isDevelopment && experimentalBuildCache) {\n const cacheDir = experimentalBuildCache;\n const cacheKey = `${collectionName ?? \"global\"}_${generateCacheHash(filePath)}`;\n\n const cached = await fs\n .readFile(path.join(cacheDir, cacheKey))\n .then((content) => cacheEntry.parse(JSON.parse(content.toString())))\n .catch(() => null);\n\n if (cached && cached.hash === generateCacheHash(value)) return cached;\n after = async () => {\n await fs.mkdir(cacheDir, { recursive: true });\n await fs.writeFile(\n path.join(cacheDir, cacheKey),\n JSON.stringify({\n ...out,\n hash: generateCacheHash(value),\n } satisfies CacheEntry),\n );\n };\n }\n\n const collection = collectionName\n ? core.getCollection(collectionName)\n : undefined;\n const handler = collection?.handlers.mdx;\n\n if (collection && handler?.frontmatter) {\n matter.data = await handler.frontmatter.run(\n matter.data as Record<string, unknown>,\n { collection, filePath, source: value },\n );\n }\n\n if (only === \"frontmatter\") {\n return {\n code: `export const frontmatter = ${JSON.stringify(matter.data)}`,\n map: null,\n };\n }\n\n // ensure the line number is correct in dev mode\n const lineOffset = isDevelopment ? countLines(matter.matter) : 0;\n\n const { buildMDX } = await import(\"@/collections/mdx/build-mdx\");\n const compiled = await buildMDX(core, collection, {\n isDevelopment,\n source: \"\\n\".repeat(lineOffset) + matter.content,\n filePath,\n frontmatter: matter.data as Record<string, unknown>,\n _compiler: compiler,\n environment: \"bundler\",\n });\n\n const out = {\n code: String(compiled.value),\n map: compiled.map as SourceMap,\n };\n\n await after?.();\n return out;\n },\n };\n}\n\nfunction generateCacheHash(input: string): string {\n return createHash(\"md5\").update(input).digest(\"hex\");\n}\n\nfunction countLines(s: string) {\n let num = 0;\n\n for (const c of s) {\n if (c === \"\\n\") num++;\n }\n\n return num;\n}\n"],"mappings":";;;;;;;AASA,MAAM,cAAc,EACjB,OAAO;CACN,MAAM,EAAE,QAAQ,CAAC,eAAe,MAAM,CAAC,CAAC,QAAQ,MAAM;CACtD,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC,CACD,OAAO;AAEV,MAAM,aAAa,EAAE,OAAO;CAC1B,MAAM,EAAE,QAAQ;CAChB,KAAK,EAAE,KAAK,CAAC,UAAU;CACvB,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC5B,CAAC;AAIF,SAAgB,gBAAgB,EAAE,WAAgC;AAChE,QAAO,EACL,MAAM,KAAK,EACT,WACA,aAAa,eACb,OACA,UACA,YACC;EACD,IAAI,OAAO,MAAM,SAAS;EAC1B,MAAM,QAAQ,MAAM,WAAW;EAC/B,MAAM,SAAS,WAAW,MAAM;EAChC,MAAM,EACJ,YAAY,gBACZ,WACA,SACE,YAAY,MAAM,MAAM;AA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S;GACf;AAED,QAAM,SAAS;AACf,SAAO;IAEV;;AAGH,SAAS,kBAAkB,OAAuB;AAChD,QAAO,WAAW,MAAM,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGtD,SAAS,WAAW,GAAW;CAC7B,IAAI,MAAM;AAEV,MAAK,MAAM,KAAK,EACd,KAAI,MAAM,KAAM;AAGlB,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loader-gk94iHf5.js","names":["data: unknown","context: MetaTransformationContext"],"sources":["../src/collections/meta/loader.ts"],"sourcesContent":["import type { Loader, LoaderInput } from \"@/plugins/with-loader\";\nimport { dump, load } from \"js-yaml\";\nimport { z } from \"zod\";\nimport { validate } from \"@/utils/validation\";\nimport type { MetaTransformationContext } from \"@/collections/meta\";\nimport type { DynamicCore } from \"@/config/dynamic\";\n\nconst querySchema = z\n .object({\n collection: z.string().optional(),\n workspace: z.string().optional(),\n })\n .loose();\n\n/**\n * load meta files, fallback to bundler's built-in plugins when ?collection is unspecified.\n */\nexport function createMetaLoader(\n { getCore }: DynamicCore,\n resolve: {\n json?: \"json\" | \"js\";\n yaml?: \"yaml\" | \"js\";\n } = {},\n): Loader {\n const { json: resolveJson = \"js\", yaml: resolveYaml = \"js\" } = resolve;\n\n function parse(filePath: string, source: string) {\n try {\n if (filePath.endsWith(\".json\")) return JSON.parse(source);\n if (filePath.endsWith(\".yaml\")) return load(source);\n } catch (e) {\n throw new Error(`invalid data in ${filePath}`, { cause: e });\n }\n\n throw new Error(`Unknown file type ${filePath}`);\n }\n\n function onMeta(source: string, { filePath, query }: LoaderInput) {\n const parsed = querySchema.safeParse(query);\n if (!parsed.success || !parsed.data.collection) return null;\n const { collection: collectionName, workspace } = parsed.data;\n\n return async (): Promise<unknown> => {\n let core = await getCore();\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n const collection = core.getCollection(collectionName);\n const handler = collection?.handlers.meta;\n let data: unknown = parse(filePath, source);\n if (!handler) return data;\n\n const context: MetaTransformationContext = {\n path: filePath,\n source,\n };\n\n if (handler.schema) {\n data = await validate(\n handler.schema,\n data,\n context,\n `invalid data in ${filePath}`,\n );\n }\n\n return handler.transform.run(data, context);\n };\n }\n\n return {\n async load(input) {\n const result = onMeta(await input.getSource(), input);\n if (result === null) return null;\n const data = await result();\n\n if (input.filePath.endsWith(\".json\")) {\n return {\n code:\n resolveJson === \"json\"\n ? JSON.stringify(data)\n : `export default ${JSON.stringify(data)}`,\n };\n } else {\n return {\n code:\n resolveYaml === \"yaml\"\n ? dump(data)\n : `export default ${JSON.stringify(data)}`,\n };\n }\n },\n bun: {\n load(source, input) {\n const result = onMeta(source, input);\n if (result === null)\n return {\n loader: \"object\",\n exports: parse(input.filePath, source),\n };\n\n return result().then((data) => ({\n loader: \"object\",\n exports: { default: data },\n }));\n },\n },\n };\n}\n"],"mappings":";;;;;AAOA,MAAM,cAAc,EACjB,OAAO;CACN,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC,CACD,OAAO;;;;AAKV,SAAgB,iBACd,EAAE,WACF,UAGI,EAAE,EACE;CACR,MAAM,EAAE,MAAM,cAAc,MAAM,MAAM,cAAc,SAAS;CAE/D,SAAS,MAAM,UAAkB,QAAgB;AAC/C,MAAI;AACF,OAAI,SAAS,SAAS,QAAQ,CAAE,QAAO,KAAK,MAAM,OAAO;AACzD,OAAI,SAAS,SAAS,QAAQ,CAAE,QAAO,KAAK,OAAO;WAC5C,GAAG;AACV,SAAM,IAAI,MAAM,mBAAmB,YAAY,EAAE,OAAO,GAAG,CAAC;;AAG9D,QAAM,IAAI,MAAM,qBAAqB,WAAW;;CAGlD,SAAS,OAAO,QAAgB,EAAE,UAAU,SAAsB;EAChE,MAAM,SAAS,YAAY,UAAU,MAAM;AAC3C,MAAI,CAAC,OAAO,WAAW,CAAC,OAAO,KAAK,WAAY,QAAO;EACvD,MAAM,EAAE,YAAY,gBAAgB,cAAc,OAAO;AAEzD,SAAO,YAA8B;GACnC,IAAI,OAAO,MAAM,SAAS;AAC1B,OAAI,UACF,QAAO,KAAK,eAAe,CAAC,IAAI,UAAU,IAAI;GAIhD,MAAM,UADa,KAAK,cAAc,eAAe,EACzB,SAAS;GACrC,IAAIA,OAAgB,MAAM,UAAU,OAAO;AAC3C,OAAI,CAAC,QAAS,QAAO;GAErB,MAAMC,UAAqC;IACzC,MAAM;IACN;IACD;AAED,OAAI,QAAQ,OACV,QAAO,MAAM,SACX,QAAQ,QACR,MACA,SACA,mBAAmB,WACpB;AAGH,UAAO,QAAQ,UAAU,IAAI,MAAM,QAAQ;;;AAI/C,QAAO;EACL,MAAM,KAAK,OAAO;GAChB,MAAM,SAAS,OAAO,MAAM,MAAM,WAAW,EAAE,MAAM;AACrD,OAAI,WAAW,KAAM,QAAO;GAC5B,MAAM,OAAO,MAAM,QAAQ;AAE3B,OAAI,MAAM,SAAS,SAAS,QAAQ,CAClC,QAAO,EACL,MACE,gBAAgB,SACZ,KAAK,UAAU,KAAK,GACpB,kBAAkB,KAAK,UAAU,KAAK,IAC7C;OAED,QAAO,EACL,MACE,gBAAgB,SACZ,KAAK,KAAK,GACV,kBAAkB,KAAK,UAAU,KAAK,IAC7C;;EAGL,KAAK,EACH,KAAK,QAAQ,OAAO;GAClB,MAAM,SAAS,OAAO,QAAQ,MAAM;AACpC,OAAI,WAAW,KACb,QAAO;IACL,QAAQ;IACR,SAAS,MAAM,MAAM,UAAU,OAAO;IACvC;AAEH,UAAO,QAAQ,CAAC,MAAM,UAAU;IAC9B,QAAQ;IACR,SAAS,EAAE,SAAS,MAAM;IAC3B,EAAE;KAEN;EACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pipe-5cnvE6KY.js","names":["steps: ((data: Data, context: Context) => Data)[]","steps: ((data: Data, context: Context) => Awaitable<Data>)[]"],"sources":["../src/utils/pipe.ts"],"sourcesContent":["import type { Awaitable } from \"@/types\";\n\nexport interface Pipe<Data, Context = undefined> {\n /**\n * add a transformation step\n *\n * @returns the same pipe instance\n */\n pipe: (fn: (data: Data, context: Context) => Data) => Pipe<Data, Context>;\n run: (data: Data, context: Context) => Data;\n}\n\nexport interface AsyncPipe<Data, Context = undefined> {\n /**\n * add a transformation step\n *\n * @returns the same pipe instance\n */\n pipe: (\n fn: (data: Data, context: Context) => Awaitable<Data>,\n ) => AsyncPipe<Data, Context>;\n run: (data: Data, context: Context) => Awaitable<Data>;\n}\n\nexport function pipe<Data, Context>(): Pipe<Data, Context> {\n const steps: ((data: Data, context: Context) => Data)[] = [];\n return {\n run(data, ctx) {\n for (const step of steps) {\n data = step(data, ctx);\n }\n return data;\n },\n pipe(fn) {\n steps.push(fn);\n return this;\n },\n };\n}\n\nexport function asyncPipe<Data, Context>(): AsyncPipe<Data, Context> {\n const steps: ((data: Data, context: Context) => Awaitable<Data>)[] = [];\n return {\n async run(data, ctx) {\n for (const step of steps) {\n data = await step(data, ctx);\n }\n return data;\n },\n pipe(fn) {\n steps.push(fn);\n return this;\n },\n };\n}\n"],"mappings":";AAwBA,SAAgB,OAA2C;CACzD,MAAMA,QAAoD,EAAE;AAC5D,QAAO;EACL,IAAI,MAAM,KAAK;AACb,QAAK,MAAM,QAAQ,MACjB,QAAO,KAAK,MAAM,IAAI;AAExB,UAAO;;EAET,KAAK,IAAI;AACP,SAAM,KAAK,GAAG;AACd,UAAO;;EAEV;;AAGH,SAAgB,YAAqD;CACnE,MAAMC,QAA+D,EAAE;AACvE,QAAO;EACL,MAAM,IAAI,MAAM,KAAK;AACnB,QAAK,MAAM,QAAQ,MACjB,QAAO,MAAM,KAAK,MAAM,IAAI;AAE9B,UAAO;;EAET,KAAK,IAAI;AACP,SAAM,KAAK,GAAG;AACd,UAAO;;EAEV"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-0LQ2PlH6.js","names":[],"sources":["../src/collections/runtime/store.ts"],"sourcesContent":["import type { Awaitable } from \"@/types\";\n\nexport interface CollectionStore<Id, Data> {\n /**\n * type-only operation to change data type, doesn't do any runtime transformation.\n */\n $data: <T>(_cast: (input: Data) => T) => CollectionStore<Id, T>;\n\n get: (id: Id) => Awaitable<Data | undefined>;\n list: () => Awaitable<Data[]>;\n\n /**\n * For typescript to infer data types, can be anything\n */\n $inferData: Data;\n}\n\nexport class SimpleCollectionStore<Data> implements CollectionStore<\n string,\n Data\n> {\n private readonly dataMap: Map<string, Data>;\n private readonly dataList: Data[];\n\n constructor(input: Map<string, Data>) {\n this.dataMap = input;\n this.dataList = Array.from(input.values());\n }\n\n get(id: string): Data | undefined {\n return this.dataMap.get(id);\n }\n\n list(): Data[] {\n return this.dataList;\n }\n\n $data<T>(_cast: (input: Data) => T): SimpleCollectionStore<T> {\n return this as unknown as SimpleCollectionStore<T>;\n }\n\n /**\n * in-place transformation on all data\n */\n transform<T>(fn: (input: Data) => T): SimpleCollectionStore<T> {\n this.dataList.length = 0;\n const dataMap = this.dataMap as unknown as Map<string, T>;\n const dataList = this.dataList as unknown as T[];\n\n for (const [k, v] of this.dataMap) {\n const updated = fn(v);\n dataMap.set(k, updated);\n dataList.push(updated);\n }\n\n return this as unknown as SimpleCollectionStore<T>;\n }\n\n get $inferData(): Data {\n return undefined as Data;\n }\n}\n"],"mappings":";AAiBA,IAAa,wBAAb,MAGE;CACA,AAAiB;CACjB,AAAiB;CAEjB,YAAY,OAA0B;AACpC,OAAK,UAAU;AACf,OAAK,WAAW,MAAM,KAAK,MAAM,QAAQ,CAAC;;CAG5C,IAAI,IAA8B;AAChC,SAAO,KAAK,QAAQ,IAAI,GAAG;;CAG7B,OAAe;AACb,SAAO,KAAK;;CAGd,MAAS,OAAqD;AAC5D,SAAO;;;;;CAMT,UAAa,IAAkD;AAC7D,OAAK,SAAS,SAAS;EACvB,MAAM,UAAU,KAAK;EACrB,MAAM,WAAW,KAAK;AAEtB,OAAK,MAAM,CAAC,GAAG,MAAM,KAAK,SAAS;GACjC,MAAM,U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 @@
|
|
|
1
|
-
{"version":3,"file":"validation-BOJKRAp5.js","names":[],"sources":["../src/utils/validation.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport class ValidationError extends Error {\n title: string;\n issues: readonly StandardSchemaV1.Issue[];\n\n constructor(message: string, issues: readonly StandardSchemaV1.Issue[]) {\n super(\n `${message}:\\n${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join(\"\\n\")}`,\n );\n\n this.title = message;\n this.issues = issues;\n }\n\n async toStringFormatted() {\n // Handle ESM/CJS interop: picocolors is a CJS module that exports via\n // module.exports = createColors(). When dynamically imported in ESM context\n // (e.g., Next.js 16 Turbopack), the exports are wrapped under .default\n const picocolorsModule = await import(\"picocolors\");\n const picocolors = picocolorsModule.default ?? picocolorsModule;\n\n return [\n picocolors.bold(`[Fuma Content] ${this.title}:`),\n ...this.issues.map((issue) =>\n picocolors.redBright(\n `- ${picocolors.bold(issue.path?.join(\".\") ?? \"*\")}: ${issue.message}`,\n ),\n ),\n ].join(\"\\n\");\n }\n}\n\nexport async function validate<Schema extends StandardSchemaV1, Context>(\n schema: StandardSchemaV1 | ((context: Context) => StandardSchemaV1),\n data: unknown,\n context: Context,\n errorMessage: string,\n): Promise<StandardSchemaV1.InferOutput<Schema>> {\n if (typeof schema === \"function\" && !(\"~standard\" in schema)) {\n schema = schema(context);\n }\n\n if (\"~standard\" in schema) {\n const result = await (schema as StandardSchemaV1)[\"~standard\"].validate(\n data,\n );\n\n if (result.issues) {\n throw new ValidationError(errorMessage, result.issues);\n }\n\n return result.value;\n }\n\n return data;\n}\n"],"mappings":";AAEA,IAAa,kBAAb,cAAqC,MAAM;CACzC;CACA;CAEA,YAAY,SAAiB,QAA2C;AACtE,QACE,GAAG,QAAQ,KAAK,OAAO,KAAK,UAAU,KAAK,MAAM,KAAK,IAAI,MAAM,UAAU,CAAC,KAAK,KAAK,GACtF;AAED,OAAK,QAAQ;AACb,OAAK,SAAS;;CAGhB,MAAM,oBAAoB;EAIxB,MAAM,mBAAmB,MAAM,OAAO;EACtC,MAAM,aAAa,iBAAiB,WAAW;AAE/C,SAAO,CACL,WAAW,KAAK,kBAAkB,KAAK,MAAM,GAAG,EAChD,GAAG,KAAK,OAAO,KAAK,UAClB,WAAW,UACT,KAAK,WAAW,KAAK,MAAM,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,MAAM,UAC9D,CACF,CACF,CAAC,KAAK,KAAK;;;AAIhB,eAAsB,SACpB,QACA,MACA,SACA,cAC+C;AAC/C,KAAI,OAAO,WAAW,cAAc,EAAE,eAAe,QACnD,UAAS,OAAO,QAAQ;AAG1B,KAAI,eAAe,QAAQ;EACzB,MAAM,SAAS,MAAO,OAA4B,aAAa,SAC7D,KACD;AAED,MAAI,OAAO,OACT,OAAM,IAAI,gBAAgB,cAAc,OAAO,OAAO;AAGxD,SAAO,OAAO;;AAGhB,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite-X-2Al8fq.js","names":["file"],"sources":["../src/plugins/with-loader/vite.ts"],"sourcesContent":["import type { SourceMap } from \"rollup\";\nimport type { PluginOption } from \"vite\";\nimport { parse } from \"node:querystring\";\nimport type { Loader } from \"@/plugins/with-loader\";\n\nexport function toVite(\n name: string,\n test: RegExp | undefined,\n loader: Loader,\n): PluginOption {\n return {\n name: `fuma-content:${name}`,\n async transform(value, id) {\n if (test && !test.test(id)) return;\n\n const [file, query = \"\"] = id.split(\"?\", 2);\n const result = await loader.load({\n filePath: file,\n query: parse(query),\n getSource() {\n return value;\n },\n development: this.environment.mode === \"dev\",\n compiler: {\n addDependency: (file) => {\n this.addWatchFile(file);\n },\n },\n });\n\n if (result === null) return null;\n return {\n code: result.code,\n map: result.map as SourceMap,\n };\n },\n };\n}\n"],"mappings":";;;AAKA,SAAgB,OACd,MACA,MACA,QACc;AACd,QAAO;EACL,MAAM,gBAAgB;EACtB,MAAM,UAAU,OAAO,IAAI;AACzB,OAAI,QAAQ,CAAC,KAAK,KAAK,GAAG,CAAE;GAE5B,MAAM,CAAC,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK,EAAE;GAC3C,MAAM,SAAS,MAAM,OAAO,KAAK;IAC/B,UAAU;IACV,OAAO,MAAM,MAAM;IACnB,YAAY;AACV,YAAO;;IAET,aAAa,KAAK,YAAY,SAAS;IACvC,UAAU,EACR,gBAAgB,WAAS;AACvB,UAAK,aAAaA,OAAK;OAE1B;IACF,CAAC;AAEF,OAAI,WAAW,KAAM,QAAO;AAC5B,UAAO;IACL,MAAM,OAAO;IACb,KAAK,OAAO;IACb;;EAEJ"}
|