fuma-content 1.1.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{async-cache-Cce8lc9D.js → async-cache-C47yxLCv.js} +3 -4
- package/dist/{async-cache-Cce8lc9D.js.map → async-cache-C47yxLCv.js.map} +1 -1
- package/dist/bin.js +2 -3
- package/dist/bin.js.map +1 -1
- package/dist/build-mdx-C8u32vDa.js +158 -0
- package/dist/build-mdx-C8u32vDa.js.map +1 -0
- package/dist/bun/index.d.ts +1 -1
- package/dist/bun/index.js +2 -3
- package/dist/bun/index.js.map +1 -1
- package/dist/{bun-DsjsbVrx.js → bun-NahDFkhR.js} +3 -4
- package/dist/{bun-DsjsbVrx.js.map → bun-NahDFkhR.js.map} +1 -1
- package/dist/{code-generator-CHcOrCeM.js → code-generator-pLUE7Rk7.js} +2 -3
- package/dist/{code-generator-CHcOrCeM.js.map → code-generator-pLUE7Rk7.js.map} +1 -1
- package/dist/collections/data/runtime.d.ts +2 -3
- package/dist/collections/data/runtime.d.ts.map +1 -1
- package/dist/collections/data/runtime.js +1 -2
- package/dist/collections/data/runtime.js.map +1 -1
- package/dist/collections/data.d.ts +3 -4
- package/dist/collections/data.d.ts.map +1 -1
- package/dist/collections/data.js +5 -6
- package/dist/collections/data.js.map +1 -1
- package/dist/collections/fs.d.ts +2 -45
- package/dist/collections/fs.js +3 -4
- package/dist/collections/fs.js.map +1 -1
- package/dist/collections/index.d.ts +2 -37
- package/dist/collections/index.js +1 -37
- package/dist/collections/json/loader-webpack.d.ts +1 -3
- package/dist/collections/json/loader-webpack.js +4 -5
- package/dist/collections/json/loader-webpack.js.map +1 -1
- package/dist/collections/mdx/loader-webpack.d.ts +1 -3
- package/dist/collections/mdx/loader-webpack.js +4 -5
- package/dist/collections/mdx/loader-webpack.js.map +1 -1
- package/dist/collections/mdx/react.d.ts +2 -4
- package/dist/collections/mdx/react.d.ts.map +1 -1
- package/dist/collections/mdx/react.js +2 -3
- package/dist/collections/mdx/react.js.map +1 -1
- package/dist/collections/mdx/runtime-browser.d.ts +3 -25
- package/dist/collections/mdx/runtime-browser.js +2 -4
- package/dist/collections/mdx/runtime-browser.js.map +1 -1
- package/dist/collections/mdx/runtime-dynamic.d.ts +4 -5
- package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -1
- package/dist/collections/mdx/runtime-dynamic.js +6 -7
- package/dist/collections/mdx/runtime-dynamic.js.map +1 -1
- package/dist/collections/mdx/runtime.d.ts +2 -26
- package/dist/collections/mdx/runtime.js +1 -2
- package/dist/collections/mdx/runtime.js.map +1 -1
- package/dist/collections/mdx/vue.d.ts +27 -0
- package/dist/collections/mdx/vue.d.ts.map +1 -0
- package/dist/collections/mdx/vue.js +34 -0
- package/dist/collections/mdx/vue.js.map +1 -0
- package/dist/collections/mdx.d.ts +2 -59
- package/dist/collections/mdx.js +6 -7
- package/dist/collections/mdx.js.map +1 -1
- package/dist/collections/obsidian.d.ts +1 -3
- package/dist/collections/obsidian.d.ts.map +1 -1
- package/dist/collections/obsidian.js +164 -127
- package/dist/collections/obsidian.js.map +1 -1
- package/dist/collections/runtime/file-store.d.ts +2 -21
- package/dist/collections/runtime/file-store.js +1 -2
- package/dist/collections/runtime/file-store.js.map +1 -1
- package/dist/collections/runtime/store.d.ts +2 -31
- package/dist/collections/runtime/store.js +1 -1
- package/dist/collections/runtime/store.js.map +1 -1
- package/dist/collections/yaml/loader-webpack.d.ts +1 -3
- package/dist/collections/yaml/loader-webpack.js +4 -5
- package/dist/collections/yaml/loader-webpack.js.map +1 -1
- package/dist/{pipe-CvCqOpXX.js → collections-BuskUhft.js} +36 -4
- package/dist/collections-BuskUhft.js.map +1 -0
- package/dist/config/index.d.ts +2 -35
- package/dist/config/index.js +1 -1
- package/dist/{core-BuUsOElL.js → core-Buwp1MPi.js} +4 -5
- package/dist/{core-BuUsOElL.js.map → core-Buwp1MPi.js.map} +1 -1
- package/dist/{core-FjA_Xoho.d.ts → core-Cd_KERZa.d.ts} +65 -4
- package/dist/core-Cd_KERZa.d.ts.map +1 -0
- package/dist/dynamic-BaUDAMS6.d.ts +32 -0
- package/dist/dynamic-BaUDAMS6.d.ts.map +1 -0
- package/dist/dynamic.d.ts +2 -25
- package/dist/dynamic.js +2 -3
- package/dist/dynamic.js.map +1 -1
- package/dist/file-store-TyqUJE3V.d.ts +20 -0
- package/dist/file-store-TyqUJE3V.d.ts.map +1 -0
- package/dist/flatten-m0wfHxLH.js +10 -0
- package/dist/flatten-m0wfHxLH.js.map +1 -0
- package/dist/fs-BHzpv9Wl.d.ts +44 -0
- package/dist/fs-BHzpv9Wl.d.ts.map +1 -0
- package/dist/{fuma-matter-CCYGfgju.js → fuma-matter-E30PU53R.js} +2 -3
- package/dist/{fuma-matter-CCYGfgju.js.map → fuma-matter-E30PU53R.js.map} +1 -1
- package/dist/git-Kdo9j47k.d.ts +37 -0
- package/dist/git-Kdo9j47k.d.ts.map +1 -0
- package/dist/index-DZkwl_pd.d.ts +84 -0
- package/dist/index-DZkwl_pd.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -5
- package/dist/{is-promise-like-pBUIbRFy.js → is-promise-like-C04ERo2r.js} +2 -2
- package/dist/{is-promise-like-pBUIbRFy.js.map → is-promise-like-C04ERo2r.js.map} +1 -1
- package/dist/{load-from-file-B9ho46XM.js → load-from-file-C3CnD8mJ.js} +3 -4
- package/dist/{load-from-file-B9ho46XM.js.map → load-from-file-C3CnD8mJ.js.map} +1 -1
- package/dist/{loader-B3hZ0R4a.js → loader-CyhM9SLt.js} +5 -6
- package/dist/{loader-B3hZ0R4a.js.map → loader-CyhM9SLt.js.map} +1 -1
- package/dist/{loader-D2BD3e0R.js → loader-D_sKOzDc.js} +4 -5
- package/dist/{loader-D2BD3e0R.js.map → loader-D_sKOzDc.js.map} +1 -1
- package/dist/{loader-C5w-u-h2.js → loader-e2SkeDfY.js} +4 -5
- package/dist/{loader-C5w-u-h2.js.map → loader-e2SkeDfY.js.map} +1 -1
- package/dist/{loader-BFfzKD3u.js → loader-ol04zeoP.js} +3 -4
- package/dist/{loader-BFfzKD3u.js.map → loader-ol04zeoP.js.map} +1 -1
- package/dist/mdx-DY0zm9lN.d.ts +138 -0
- package/dist/mdx-DY0zm9lN.d.ts.map +1 -0
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +3 -4
- package/dist/next/index.js.map +1 -1
- package/dist/node/index.d.ts +0 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -2
- package/dist/node/index.js.map +1 -1
- package/dist/node/loader.d.ts +1 -1
- package/dist/node/loader.js +3 -4
- package/dist/node/loader.js.map +1 -1
- package/dist/{node-Cu5Pqxxo.js → node-Du4i4XDg.js} +2 -3
- package/dist/{node-Cu5Pqxxo.js.map → node-Du4i4XDg.js.map} +1 -1
- package/dist/plugins/git.d.ts +2 -38
- package/dist/plugins/git.js +3 -5
- package/dist/plugins/git.js.map +1 -1
- package/dist/plugins/json-schema.d.ts +1 -2
- package/dist/plugins/json-schema.d.ts.map +1 -1
- package/dist/plugins/json-schema.js +2 -3
- package/dist/plugins/json-schema.js.map +1 -1
- package/dist/plugins/loader/index.d.ts +2 -72
- package/dist/plugins/loader/index.js +6 -7
- package/dist/plugins/loader/index.js.map +1 -1
- package/dist/plugins/loader/webpack.d.ts +2 -21
- package/dist/plugins/loader/webpack.js +3 -4
- package/dist/plugins/loader/webpack.js.map +1 -1
- package/dist/plugins/remark/include.d.ts +23 -0
- package/dist/plugins/remark/include.d.ts.map +1 -0
- package/dist/{build-mdx-C210zpJN.js → plugins/remark/include.js} +5 -166
- package/dist/plugins/remark/include.js.map +1 -0
- package/dist/rolldown-runtime-CiIaOW0V.js +13 -0
- package/dist/runtime-DiDP9Ajm.d.ts +25 -0
- package/dist/runtime-DiDP9Ajm.d.ts.map +1 -0
- package/dist/runtime-browser-a0rQ1BCJ.d.ts +29 -0
- package/dist/runtime-browser-a0rQ1BCJ.d.ts.map +1 -0
- package/dist/store-C3RuJOrY.d.ts +31 -0
- package/dist/store-C3RuJOrY.d.ts.map +1 -0
- package/dist/{validation-C3kXuveD.js → validation-Bf_v2L3p.js} +2 -2
- package/dist/{validation-C3kXuveD.js.map → validation-Bf_v2L3p.js.map} +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +3 -4
- package/dist/vite/index.js.map +1 -1
- package/dist/{vite-CoJIMNWk.js → vite-DVIOnBqW.js} +2 -3
- package/dist/{vite-CoJIMNWk.js.map → vite-DVIOnBqW.js.map} +1 -1
- package/package.json +39 -58
- package/dist/async-cache-Ca5oMQss.d.ts +0 -11
- package/dist/async-cache-Ca5oMQss.d.ts.map +0 -1
- package/dist/build-mdx-C210zpJN.js.map +0 -1
- package/dist/build-mdx-DhXGp7I9.d.ts +0 -101
- package/dist/build-mdx-DhXGp7I9.d.ts.map +0 -1
- package/dist/collections/fs.d.ts.map +0 -1
- package/dist/collections/index.d.ts.map +0 -1
- package/dist/collections/index.js.map +0 -1
- package/dist/collections/mdx/runtime-browser.d.ts.map +0 -1
- package/dist/collections/mdx/runtime.d.ts.map +0 -1
- package/dist/collections/mdx.d.ts.map +0 -1
- package/dist/collections/runtime/file-store.d.ts.map +0 -1
- package/dist/collections/runtime/store.d.ts.map +0 -1
- package/dist/config/index.d.ts.map +0 -1
- package/dist/core-FjA_Xoho.d.ts.map +0 -1
- package/dist/dynamic.d.ts.map +0 -1
- package/dist/load-from-file-CIYdu-B5.d.ts +0 -10
- package/dist/load-from-file-CIYdu-B5.d.ts.map +0 -1
- package/dist/pipe-CvCqOpXX.js.map +0 -1
- package/dist/plugins/git.d.ts.map +0 -1
- package/dist/plugins/loader/index.d.ts.map +0 -1
- package/dist/plugins/loader/webpack.d.ts.map +0 -1
- package/dist/rolldown-runtime-CjeV3_4I.js +0 -18
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as isPromiseLike } from "./is-promise-like-
|
|
2
|
-
|
|
1
|
+
import { t as isPromiseLike } from "./is-promise-like-C04ERo2r.js";
|
|
3
2
|
//#region src/utils/async-cache.ts
|
|
4
3
|
/**
|
|
5
4
|
* cache for async resources, finished promises will be resolved into original value, otherwise wrapped with a promise.
|
|
@@ -25,7 +24,7 @@ function createCache(store = /* @__PURE__ */ new Map()) {
|
|
|
25
24
|
}
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
//#endregion
|
|
30
28
|
export { createCache as t };
|
|
31
|
-
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=async-cache-C47yxLCv.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-cache-
|
|
1
|
+
{"version":3,"file":"async-cache-C47yxLCv.js","names":[],"sources":["../src/utils/async-cache.ts"],"sourcesContent":["import { Awaitable } from \"@/types\";\nimport { isPromiseLike } from \"./is-promise-like\";\n\nexport interface AsyncCache<V> {\n cached: (key: string, fn: () => Awaitable<V>) => V | PromiseLike<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>(store = new Map<string, V | PromiseLike<V>>()): 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 (isPromiseLike(cached)) {\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":";;;;;AAYA,SAAgB,YAAe,wBAAQ,IAAI,KAAiC,EAAiB;AAC3F,QAAO;EACL,OAAO,KAAK,IAAI;GACd,IAAI,SAAS,MAAM,IAAI,IAAI;AAC3B,OAAI,OAAQ,QAAO;AAEnB,YAAS,IAAI;AACb,OAAI,cAAc,OAAO,CACvB,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/bin.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
|
|
4
3
|
//#region src/bin.ts
|
|
5
4
|
async function start() {
|
|
6
5
|
const [configPath, outDir] = process.argv.slice(2);
|
|
@@ -19,7 +18,7 @@ async function start() {
|
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
start();
|
|
22
|
-
|
|
23
21
|
//#endregion
|
|
24
|
-
export {
|
|
22
|
+
export {};
|
|
23
|
+
|
|
25
24
|
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { existsSync } from \"node:fs\";\n\nasync function start() {\n const [configPath, outDir] = process.argv.slice(2);\n const isNext =\n existsSync(\"next.config.js\") ||\n existsSync(\"next.config.mjs\") ||\n existsSync(\"next.config.mts\") ||\n existsSync(\"next.config.ts\");\n\n if (isNext) {\n const { createStandaloneCore } = await import(\"./next\");\n const core = await createStandaloneCore({ configPath, outDir });\n await core.emit({ write: true });\n } else {\n const { createStandaloneCore } = await import(\"./vite\");\n const core = await createStandaloneCore({ configPath, outDir });\n await core.emit({ write: true });\n }\n}\n\nvoid start();\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { existsSync } from \"node:fs\";\n\nasync function start() {\n const [configPath, outDir] = process.argv.slice(2);\n const isNext =\n existsSync(\"next.config.js\") ||\n existsSync(\"next.config.mjs\") ||\n existsSync(\"next.config.mts\") ||\n existsSync(\"next.config.ts\");\n\n if (isNext) {\n const { createStandaloneCore } = await import(\"./next\");\n const core = await createStandaloneCore({ configPath, outDir });\n await core.emit({ write: true });\n } else {\n const { createStandaloneCore } = await import(\"./vite\");\n const core = await createStandaloneCore({ configPath, outDir });\n await core.emit({ write: true });\n }\n}\n\nvoid start();\n"],"mappings":";;;AAIA,eAAe,QAAQ;CACrB,MAAM,CAAC,YAAY,UAAU,QAAQ,KAAK,MAAM,EAAE;AAOlD,KALE,WAAW,iBAAiB,IAC5B,WAAW,kBAAkB,IAC7B,WAAW,kBAAkB,IAC7B,WAAW,iBAAiB,EAElB;EACV,MAAM,EAAE,yBAAyB,MAAM,OAAO;AAE9C,SADa,MAAM,qBAAqB;GAAE;GAAY;GAAQ,CAAC,EACpD,KAAK,EAAE,OAAO,MAAM,CAAC;QAC3B;EACL,MAAM,EAAE,yBAAyB,MAAM,OAAO;AAE9C,SADa,MAAM,qBAAqB;GAAE;GAAY;GAAQ,CAAC,EACpD,KAAK,EAAE,OAAO,MAAM,CAAC;;;AAI/B,OAAO"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-CiIaOW0V.js";
|
|
2
|
+
import { t as createCache } from "./async-cache-C47yxLCv.js";
|
|
3
|
+
import { t as flattenNode } from "./flatten-m0wfHxLH.js";
|
|
4
|
+
import { visit } from "unist-util-visit";
|
|
5
|
+
import { VFile } from "vfile";
|
|
6
|
+
import { createProcessor } from "@mdx-js/mdx";
|
|
7
|
+
import { toMarkdown } from "mdast-util-to-markdown";
|
|
8
|
+
import { valueToEstree } from "estree-util-value-to-estree";
|
|
9
|
+
import { removePosition } from "unist-util-remove-position";
|
|
10
|
+
import { mdxToMarkdown } from "mdast-util-mdx";
|
|
11
|
+
//#region src/collections/mdx/remark-postprocess.ts
|
|
12
|
+
/**
|
|
13
|
+
* - collect references
|
|
14
|
+
* - write frontmatter (auto-title & description)
|
|
15
|
+
*/
|
|
16
|
+
function remarkPostprocess({ _format, processedMarkdown = false, mdast = false, linkReferences = false, valueToExport = [] }) {
|
|
17
|
+
return (tree, file) => {
|
|
18
|
+
const frontmatter = file.data.frontmatter ??= {};
|
|
19
|
+
if (!frontmatter.title) visit(tree, "heading", (node) => {
|
|
20
|
+
if (node.depth === 1) {
|
|
21
|
+
frontmatter.title = flattenNode(node);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
file.data["mdx-export"] ??= [];
|
|
26
|
+
file.data["mdx-export"].push({
|
|
27
|
+
name: "frontmatter",
|
|
28
|
+
value: frontmatter
|
|
29
|
+
});
|
|
30
|
+
if (linkReferences) {
|
|
31
|
+
const { as = "_linkReferences" } = linkReferences === true ? {} : linkReferences;
|
|
32
|
+
const urls = [];
|
|
33
|
+
visit(tree, "link", (node) => {
|
|
34
|
+
urls.push({ href: node.url });
|
|
35
|
+
return "skip";
|
|
36
|
+
});
|
|
37
|
+
file.data["mdx-export"].push({
|
|
38
|
+
name: as,
|
|
39
|
+
value: urls
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (processedMarkdown) {
|
|
43
|
+
const { as = "_markdown", headingIds = true } = processedMarkdown === true ? {} : processedMarkdown;
|
|
44
|
+
const extensions = this.data("toMarkdownExtensions") ?? [];
|
|
45
|
+
const markdown = toMarkdown(tree, {
|
|
46
|
+
...this.data("settings"),
|
|
47
|
+
extensions: _format === "md" ? [...extensions, mdxToMarkdown()] : extensions,
|
|
48
|
+
handlers: { heading(node) {
|
|
49
|
+
const id = node.data?.hProperties?.id;
|
|
50
|
+
const content = flattenNode(node);
|
|
51
|
+
return headingIds && id ? `${content} [#${id}]` : content;
|
|
52
|
+
} }
|
|
53
|
+
});
|
|
54
|
+
file.data["mdx-export"].push({
|
|
55
|
+
name: as,
|
|
56
|
+
value: markdown
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (mdast) {
|
|
60
|
+
const { as = "_mdast", removePosition: shouldRemovePosition = false } = mdast === true ? {} : mdast;
|
|
61
|
+
const stringified = JSON.stringify(shouldRemovePosition ? removePosition(structuredClone(tree)) : tree);
|
|
62
|
+
file.data["mdx-export"].push({
|
|
63
|
+
name: as,
|
|
64
|
+
value: stringified
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
for (const { name, value } of file.data["mdx-export"]) tree.children.unshift(getMdastExport(name, value));
|
|
68
|
+
file.data["mdx-export"] = [];
|
|
69
|
+
for (const name of valueToExport) {
|
|
70
|
+
if (!(name in file.data)) continue;
|
|
71
|
+
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* MDX.js first converts javascript (with esm support) into mdast nodes with remark-mdx, then handle the other remark plugins
|
|
77
|
+
*
|
|
78
|
+
* Therefore, if we want to inject an export, we must convert the object into AST, then add the mdast node
|
|
79
|
+
*/
|
|
80
|
+
function getMdastExport(name, value) {
|
|
81
|
+
return {
|
|
82
|
+
type: "mdxjsEsm",
|
|
83
|
+
value: "",
|
|
84
|
+
data: { estree: {
|
|
85
|
+
type: "Program",
|
|
86
|
+
sourceType: "module",
|
|
87
|
+
body: [{
|
|
88
|
+
type: "ExportNamedDeclaration",
|
|
89
|
+
specifiers: [],
|
|
90
|
+
attributes: [],
|
|
91
|
+
source: null,
|
|
92
|
+
declaration: {
|
|
93
|
+
type: "VariableDeclaration",
|
|
94
|
+
kind: "let",
|
|
95
|
+
declarations: [{
|
|
96
|
+
type: "VariableDeclarator",
|
|
97
|
+
id: {
|
|
98
|
+
type: "Identifier",
|
|
99
|
+
name
|
|
100
|
+
},
|
|
101
|
+
init: valueToEstree(value)
|
|
102
|
+
}]
|
|
103
|
+
}
|
|
104
|
+
}]
|
|
105
|
+
} }
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/utils/unified/pluggable.ts
|
|
110
|
+
function pluggable(plugin, ...params) {
|
|
111
|
+
return [plugin, ...params];
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/collections/mdx/build-mdx.ts
|
|
115
|
+
var build_mdx_exports = /* @__PURE__ */ __exportAll({ buildMDX: () => buildMDX });
|
|
116
|
+
async function buildMDX({ core, collection, filePath, frontmatter, source, compiler, environment, isDevelopment }) {
|
|
117
|
+
const processorCache = createCache(core.cache).$value();
|
|
118
|
+
function getProcessor(format) {
|
|
119
|
+
const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
|
|
120
|
+
return processorCache.cached(key, async () => {
|
|
121
|
+
const mdxOptions = await collection?.getMDXOptions?.(environment);
|
|
122
|
+
const postprocess = [pluggable(remarkPostprocess, {
|
|
123
|
+
_format: format,
|
|
124
|
+
...collection?.postprocess
|
|
125
|
+
})];
|
|
126
|
+
return createProcessor({
|
|
127
|
+
outputFormat: "program",
|
|
128
|
+
development: isDevelopment,
|
|
129
|
+
...mdxOptions,
|
|
130
|
+
remarkPlugins: typeof mdxOptions?.remarkPlugins === "function" ? mdxOptions.remarkPlugins({
|
|
131
|
+
preprocess: [],
|
|
132
|
+
postprocess
|
|
133
|
+
}) : [...mdxOptions?.remarkPlugins ?? [], ...postprocess],
|
|
134
|
+
format
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
let vfile = new VFile({
|
|
139
|
+
value: source,
|
|
140
|
+
path: filePath,
|
|
141
|
+
cwd: core.getOptions().cwd,
|
|
142
|
+
data: {
|
|
143
|
+
frontmatter,
|
|
144
|
+
_compiler: compiler,
|
|
145
|
+
_getProcessor: getProcessor
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
if (collection && collection) vfile = await collection.vfile.run(vfile, {
|
|
149
|
+
collection,
|
|
150
|
+
filePath,
|
|
151
|
+
source
|
|
152
|
+
});
|
|
153
|
+
return (await getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md")).process(vfile);
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
export { build_mdx_exports as n, buildMDX as t };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=build-mdx-C8u32vDa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-mdx-C8u32vDa.js","names":[],"sources":["../src/collections/mdx/remark-postprocess.ts","../src/utils/unified/pluggable.ts","../src/collections/mdx/build-mdx.ts"],"sourcesContent":["import type { Processor, Transformer } from \"unified\";\nimport type { Heading, 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 { flattenNode } from \"@/utils/mdast/flatten\";\nimport { mdxToMarkdown } from \"mdast-util-mdx\";\n\nexport interface LinkReference {\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 processedMarkdown?:\n | boolean\n | {\n as?: string;\n /**\n * include heading IDs into the processed markdown.\n */\n headingIds?: boolean;\n };\n\n /**\n * extract link references, export via `_linkReferences`.\n */\n linkReferences?:\n | boolean\n | {\n as?: string;\n };\n\n /**\n * store MDAST and export via `_mdast`.\n */\n mdast?:\n | boolean\n | {\n as?: string;\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 processedMarkdown = false,\n mdast = false,\n linkReferences = false,\n valueToExport = [],\n }: PostprocessOptions,\n): Transformer<Root, Root> {\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 (linkReferences) {\n const { as = \"_linkReferences\" } = linkReferences === true ? {} : linkReferences;\n const urls: LinkReference[] = [];\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: as,\n value: urls,\n });\n }\n\n if (processedMarkdown) {\n const { as = \"_markdown\", headingIds = true } =\n processedMarkdown === true ? {} : processedMarkdown;\n const extensions = this.data(\"toMarkdownExtensions\") ?? [];\n\n const markdown = toMarkdown(tree, {\n ...this.data(\"settings\"),\n extensions: _format === \"md\" ? [...extensions, mdxToMarkdown()] : extensions,\n handlers: {\n heading(node: Heading) {\n const id = node.data?.hProperties?.id;\n const content = flattenNode(node);\n return headingIds && id ? `${content} [#${id}]` : content;\n },\n },\n });\n\n file.data[\"mdx-export\"].push({\n name: as,\n value: markdown,\n });\n }\n\n if (mdast) {\n const { as = \"_mdast\", removePosition: shouldRemovePosition = false } =\n mdast === true ? {} : mdast;\n const stringified = JSON.stringify(\n shouldRemovePosition ? removePosition(structuredClone(tree)) : tree,\n );\n\n file.data[\"mdx-export\"].push({\n name: as,\n value: stringified,\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 { Pluggable, Plugin } from \"unified\";\n\nexport function pluggable<PluginParameters extends unknown[]>(\n plugin: Plugin<PluginParameters, any, any>,\n ...params: PluginParameters\n): Pluggable {\n return [plugin, ...params];\n}\n","import { createProcessor, type ProcessorOptions } from \"@mdx-js/mdx\";\nimport { VFile } from \"vfile\";\nimport { remarkPostprocess } from \"@/collections/mdx/remark-postprocess\";\nimport type { Core } from \"@/core\";\nimport { createCache } from \"@/utils/async-cache\";\nimport type { MDXContent } from \"mdx/types\";\nimport { MDXCollection } from \"../mdx\";\nimport type { PluggableList } from \"unified\";\nimport type { Awaitable } from \"@/types\";\nimport { pluggable } from \"@/utils/unified/pluggable\";\n\ntype MDXProcessor = ReturnType<typeof createProcessor>;\n\ninterface MDXCompilerContext {\n addDependency: (file: string) => void;\n collection: MDXCollection | undefined;\n core: Core;\n}\n\ninterface BuildMDXOptions {\n core: Core;\n collection: MDXCollection | undefined;\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: MDXCompilerContext;\n}\n\nexport interface FumaContentProcessorOptions extends Omit<ProcessorOptions, \"remarkPlugins\"> {\n remarkPlugins?:\n | PluggableList\n | ((plugins: { preprocess: PluggableList; postprocess: PluggableList }) => PluggableList)\n | null\n | undefined;\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 internal compiler info\n */\n _compiler?: MDXCompilerContext;\n\n /**\n * [Fuma Content] get internal processor, do not use this on user land.\n */\n _getProcessor?: (format: \"md\" | \"mdx\") => Awaitable<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 interface CompiledMDX<Frontmatter = Record<string, unknown>> extends Record<\n string,\n unknown\n> {\n frontmatter: Frontmatter;\n default: MDXContent;\n}\n\nexport async function buildMDX({\n core,\n collection,\n filePath,\n frontmatter,\n source,\n compiler,\n environment,\n isDevelopment,\n}: BuildMDXOptions): Promise<VFile> {\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 collection?.getMDXOptions?.(environment);\n const postprocess = [\n pluggable(remarkPostprocess, {\n _format: format,\n ...collection?.postprocess,\n }),\n ];\n\n return createProcessor({\n outputFormat: \"program\",\n development: isDevelopment,\n ...mdxOptions,\n remarkPlugins:\n typeof mdxOptions?.remarkPlugins === \"function\"\n ? mdxOptions.remarkPlugins({\n preprocess: [],\n postprocess,\n })\n : [...(mdxOptions?.remarkPlugins ?? []), ...postprocess],\n format,\n });\n });\n }\n\n let vfile = new VFile({\n value: source,\n path: filePath,\n cwd: core.getOptions().cwd,\n data: {\n frontmatter,\n _compiler: compiler,\n _getProcessor: getProcessor,\n },\n });\n\n if (collection && collection) {\n vfile = await collection.vfile.run(vfile, {\n collection,\n filePath,\n source,\n });\n }\n\n return (await getProcessor(filePath.endsWith(\".mdx\") ? \"mdx\" : \"md\")).process(vfile);\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0DA,SAAgB,kBAEd,EACE,SACA,oBAAoB,OACpB,QAAQ,OACR,iBAAiB,OACjB,gBAAgB,EAAE,IAEK;AACzB,SAAQ,MAAM,SAAS;EACrB,MAAM,cAAe,KAAK,KAAK,gBAAgB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BAAiB,EAAE,EAAG,GAAG,YAAY;IAC5D;IACD,CAAC;IACF;;CAGJ,IAAI,QAAQ,IAAI,MAAM;EACpB,OAAO;EACP,MAAM;EACN,KAAK,KAAK,YAAY,CAAC;EACvB,MAAM;GACJ;GACA,WAAW;GACX,eAAe;GAChB;EACF,CAAC;AAEF,KAAI,cAAc,WAChB,SAAQ,MAAM,WAAW,MAAM,IAAI,OAAO;EACxC;EACA;EACA;EACD,CAAC;AAGJ,SAAQ,MAAM,aAAa,SAAS,SAAS,OAAO,GAAG,QAAQ,KAAK,EAAE,QAAQ,MAAM"}
|
package/dist/bun/index.d.ts
CHANGED
package/dist/bun/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { t as Core } from "../core-
|
|
1
|
+
import { t as Core } from "../core-Buwp1MPi.js";
|
|
2
2
|
import { loaderPlugin } from "../plugins/loader/index.js";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
|
|
5
4
|
//#region src/bun/index.ts
|
|
6
5
|
async function createContent(options = {}) {
|
|
7
6
|
const core = new BunCore({
|
|
@@ -26,7 +25,7 @@ var BunCore = class extends Core {
|
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
27
|
};
|
|
29
|
-
|
|
30
28
|
//#endregion
|
|
31
29
|
export { BunCore, createContent };
|
|
30
|
+
|
|
32
31
|
//# sourceMappingURL=index.js.map
|
package/dist/bun/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/bun/index.ts"],"sourcesContent":["import type { BunPlugin } from \"bun\";\nimport { pathToFileURL } from \"node:url\";\nimport { type CoreOptions, Core } from \"@/core\";\nimport { loaderPlugin } from \"@/plugins/loader\";\n\nexport type BunOptions = Omit<CoreOptions, \"plugins\" | \"workspace\">;\n\nexport async function createContent(options: BunOptions = {}): Promise<BunCore> {\n const core = new BunCore({\n ...options,\n plugins: [loaderPlugin()],\n });\n const importPath = pathToFileURL(core.getOptions().configPath).href;\n\n await core.init({\n config: await import(importPath),\n });\n return core;\n}\n\nexport class BunCore extends Core {\n createBunPlugin(): BunPlugin {\n return {\n name: \"fuma-content\",\n setup: async (build) => {\n const ctx = this.getPluginContext();\n\n for (const plugin of this.getPlugins(true)) {\n const setup = plugin.bun?.setup;\n if (setup) await setup.call(ctx, build);\n }\n },\n };\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/bun/index.ts"],"sourcesContent":["import type { BunPlugin } from \"bun\";\nimport { pathToFileURL } from \"node:url\";\nimport { type CoreOptions, Core } from \"@/core\";\nimport { loaderPlugin } from \"@/plugins/loader\";\n\nexport type BunOptions = Omit<CoreOptions, \"plugins\" | \"workspace\">;\n\nexport async function createContent(options: BunOptions = {}): Promise<BunCore> {\n const core = new BunCore({\n ...options,\n plugins: [loaderPlugin()],\n });\n const importPath = pathToFileURL(core.getOptions().configPath).href;\n\n await core.init({\n config: await import(importPath),\n });\n return core;\n}\n\nexport class BunCore extends Core {\n createBunPlugin(): BunPlugin {\n return {\n name: \"fuma-content\",\n setup: async (build) => {\n const ctx = this.getPluginContext();\n\n for (const plugin of this.getPlugins(true)) {\n const setup = plugin.bun?.setup;\n if (setup) await setup.call(ctx, build);\n }\n },\n };\n }\n}\n"],"mappings":";;;;AAOA,eAAsB,cAAc,UAAsB,EAAE,EAAoB;CAC9E,MAAM,OAAO,IAAI,QAAQ;EACvB,GAAG;EACH,SAAS,CAAC,cAAc,CAAC;EAC1B,CAAC;CACF,MAAM,aAAa,cAAc,KAAK,YAAY,CAAC,WAAW,CAAC;AAE/D,OAAM,KAAK,KAAK,EACd,QAAQ,MAAM,OAAO,aACtB,CAAC;AACF,QAAO;;AAGT,IAAa,UAAb,cAA6B,KAAK;CAChC,kBAA6B;AAC3B,SAAO;GACL,MAAM;GACN,OAAO,OAAO,UAAU;IACtB,MAAM,MAAM,KAAK,kBAAkB;AAEnC,SAAK,MAAM,UAAU,KAAK,WAAW,KAAK,EAAE;KAC1C,MAAM,QAAQ,OAAO,KAAK;AAC1B,SAAI,MAAO,OAAM,MAAM,KAAK,KAAK,MAAM;;;GAG5C"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { t as isPromiseLike } from "./is-promise-like-
|
|
1
|
+
import { t as isPromiseLike } from "./is-promise-like-C04ERo2r.js";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { parse } from "node:querystring";
|
|
4
|
-
|
|
5
4
|
//#region src/plugins/loader/bun.ts
|
|
6
5
|
function toBun(test = /.+/, loader) {
|
|
7
6
|
function toResult(output) {
|
|
@@ -30,7 +29,7 @@ function toBun(test = /.+/, loader) {
|
|
|
30
29
|
});
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
//#endregion
|
|
35
33
|
export { toBun };
|
|
36
|
-
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=bun-NahDFkhR.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-
|
|
1
|
+
{"version":3,"file":"bun-NahDFkhR.js","names":[],"sources":["../src/plugins/loader/bun.ts"],"sourcesContent":["import { parse } from \"node:querystring\";\nimport { readFileSync } from \"node:fs\";\nimport type { LoaderInput, Loader, LoaderOutput } from \"@/plugins/loader\";\nimport { isPromiseLike } from \"@/utils/is-promise-like\";\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: output.moduleType ?? \"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 addDependency() {},\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 (isPromiseLike(result)) {\n return result.then(toResult);\n }\n return toResult(result);\n });\n };\n}\n"],"mappings":";;;;AAKA,SAAgB,MAAM,OAAe,MAAM,QAAgB;CACzD,SAAS,SAAS,QAA+C;AAE/D,MAAI,CAAC,OAAQ;AAEb,SAAO;GACL,UAAU,OAAO;GACjB,QAAQ,OAAO,cAAc;GAC9B;;AAGH,SAAQ,UAAmC;AAEzC,QAAM,OAAO,EAAE,QAAQ,MAAM,GAAG,SAAS;GACvC,MAAM,CAAC,UAAU,QAAQ,MAAM,KAAK,KAAK,MAAM,KAAK,EAAE;GACtD,MAAM,QAAqB;IACzB,MAAM,YAAY;AAChB,YAAO,IAAI,KAAK,SAAS,CAAC,MAAM;;IAElC,OAAO,MAAM,MAAM;IACnB;IACA,aAAa;IACb,gBAAgB;IACjB;AAED,OAAI,OAAO,KAAK,KACd,QAAO,OAAO,IAAI,KAAK,aAAa,SAAS,CAAC,UAAU,EAAE,MAAM;GAGlE,MAAM,SAAS,OAAO,KAAK,MAAM;AACjC,OAAI,cAAc,OAAO,CACvB,QAAO,OAAO,KAAK,SAAS;AAE9B,UAAO,SAAS,OAAO;IACvB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { URLSearchParams } from "node:url";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/code-generator.ts
|
|
5
4
|
/**
|
|
6
5
|
* Code generator (one instance per file)
|
|
@@ -100,7 +99,7 @@ function slash(path) {
|
|
|
100
99
|
if (path.startsWith("\\\\?\\")) return path;
|
|
101
100
|
return path.replaceAll("\\", "/");
|
|
102
101
|
}
|
|
103
|
-
|
|
104
102
|
//#endregion
|
|
105
103
|
export { slash as n, CodeGenerator as t };
|
|
106
|
-
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=code-generator-pLUE7Rk7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-generator-
|
|
1
|
+
{"version":3,"file":"code-generator-pLUE7Rk7.js","names":[],"sources":["../src/utils/code-generator.ts"],"sourcesContent":["import type { EmitConfig } from \"@/config\";\nimport path from \"node:path\";\nimport { URLSearchParams } from \"node:url\";\n\nexport interface CodeGeneratorOptions extends EmitConfig {\n outDir: string;\n}\n\ninterface ImportInfo {\n /**\n * import name -> member name\n */\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\n/**\n * Code generator (one instance per file)\n */\nexport class CodeGenerator {\n private readonly lines: 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({ jsExtension = false, outDir = \"\" }: Partial<CodeGeneratorOptions>) {\n this.options = {\n jsExtension,\n outDir,\n };\n }\n\n addNamespaceImport(namespace: string, specifier: string, typeOnly = false) {\n const info = this.importInfos.get(specifier) ?? {};\n this.importInfos.set(specifier, info);\n if (!typeOnly) {\n info.isUsed ??= new Set();\n info.isUsed.add(namespace);\n }\n\n info.namespaces ??= new Set();\n info.namespaces.add(namespace);\n }\n\n addNamedImport(names: string[], specifier: string, typeOnly = false) {\n const info = this.importInfos.get(specifier) ?? {};\n this.importInfos.set(specifier, info);\n info.named ??= new Map();\n\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 (!typeOnly) {\n info.isUsed ??= new Set();\n info.isUsed.add(importName);\n }\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 /** generate a random import name that is unique in file. */\n generateImportName(): string {\n return `__${this.eagerImportId++}`;\n }\n\n formatDynamicImport(specifier: string, mod?: string): string {\n let s = `import(\"${specifier}\")`;\n if (mod) s += `.then(mod => mod.${mod})`;\n return s;\n }\n\n formatQuery(query: Record<string, string | undefined>) {\n const params = new URLSearchParams();\n for (const k in query) {\n const value = query[k];\n if (typeof value === \"string\") params.set(k, value);\n }\n return params.toString();\n }\n\n formatImportPath(file: string) {\n const ext = path.extname(file);\n let filename: string;\n\n switch (ext) {\n case \".ts\":\n case \".tsx\":\n filename = file.substring(0, file.length - ext.length);\n if (this.options.jsExtension) filename += \".js\";\n break;\n default:\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\n for (const [specifier, { namespaces, isUsed, named }] of this.importInfos) {\n if (namespaces)\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 if (named && named.size > 0) {\n const namedImports: string[] = [];\n\n for (const [importName, memberName] of named) {\n const item = importName === memberName ? importName : `${memberName} as ${importName}`;\n\n namedImports.push(isUsed?.has(importName) ? item : `type ${item}`);\n }\n\n final.push(`import { ${namedImports.join(\", \")} } from \"${specifier}\";`);\n }\n }\n\n final.push(...this.lines);\n return final.join(\"\\n\");\n }\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":";;;;;;AAuBA,IAAa,gBAAb,MAA2B;CACzB,QAAmC,EAAE;CAErC,8BAA+B,IAAI,KAAyB;CAC5D,gBAAwB;CAExB;CACA,YAAY,EAAE,cAAc,OAAO,SAAS,MAAqC;AAC/E,OAAK,UAAU;GACb;GACA;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
|
|
4
|
-
import { FileCollectionStore } from "
|
|
3
|
+
import { t as FileCollectionStore } from "../../file-store-TyqUJE3V.js";
|
|
5
4
|
|
|
6
5
|
//#region src/collections/data/runtime.d.ts
|
|
7
6
|
declare function dataStore<Config, Name extends string>(_name: Name, base: string, input: Record<string, unknown>): FileCollectionStore<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","names":[],"sources":["../../../src/collections/data/runtime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","names":[],"sources":["../../../src/collections/data/runtime.ts"],"mappings":";;;;;iBAIgB,SAAA,6BAAA,CACd,KAAA,EAAO,IAAA,EACP,IAAA,UACA,KAAA,EAAO,MAAA,oBACN,mBAAA;EACD,IAAA,EAAM,mBAAA,CAAoB,MAAA,EAAQ,IAAA,UAAc,cAAA,GAC5C,mBAAA,CAAoB,MAAA,EAAQ,IAAA;AAAA"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { FileCollectionStore } from "../runtime/file-store.js";
|
|
2
|
-
|
|
3
2
|
//#region src/collections/data/runtime.ts
|
|
4
3
|
function dataStore(_name, base, input) {
|
|
5
4
|
const merged = {};
|
|
6
5
|
for (const [key, value] of Object.entries(input)) merged[key] = { data: value };
|
|
7
6
|
return new FileCollectionStore(base, merged);
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
//#endregion
|
|
11
9
|
export { dataStore };
|
|
10
|
+
|
|
12
11
|
//# sourceMappingURL=runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"sources":["../../../src/collections/data/runtime.ts"],"sourcesContent":["import type { GetCollectionConfig } from \"@/types\";\nimport { FileCollectionStore } from \"@/collections/runtime/file-store\";\nimport type { DataCollection } from \"@/collections/data\";\n\nexport function dataStore<Config, Name extends string>(\n _name: Name,\n base: string,\n input: Record<string, unknown>,\n): FileCollectionStore<{\n data: GetCollectionConfig<Config, Name> extends DataCollection\n ? GetCollectionConfig<Config, Name>[\"$inferOutput\"]\n : never;\n}> {\n type Data =\n GetCollectionConfig<Config, Name> extends DataCollection\n ? GetCollectionConfig<Config, Name>[\"$inferOutput\"]\n : never;\n const merged: Record<\n string,\n {\n data: Data;\n }\n > = {};\n\n for (const [key, value] of Object.entries(input)) {\n merged[key] = {\n data: value as Data,\n };\n }\n\n return new FileCollectionStore(base, merged);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.js","names":[],"sources":["../../../src/collections/data/runtime.ts"],"sourcesContent":["import type { GetCollectionConfig } from \"@/types\";\nimport { FileCollectionStore } from \"@/collections/runtime/file-store\";\nimport type { DataCollection } from \"@/collections/data\";\n\nexport function dataStore<Config, Name extends string>(\n _name: Name,\n base: string,\n input: Record<string, unknown>,\n): FileCollectionStore<{\n data: GetCollectionConfig<Config, Name> extends DataCollection\n ? GetCollectionConfig<Config, Name>[\"$inferOutput\"]\n : never;\n}> {\n type Data =\n GetCollectionConfig<Config, Name> extends DataCollection\n ? GetCollectionConfig<Config, Name>[\"$inferOutput\"]\n : never;\n const merged: Record<\n string,\n {\n data: Data;\n }\n > = {};\n\n for (const [key, value] of Object.entries(input)) {\n merged[key] = {\n data: value as Data,\n };\n }\n\n return new FileCollectionStore(base, merged);\n}\n"],"mappings":";;AAIA,SAAgB,UACd,OACA,MACA,OAKC;CAKD,MAAM,SAKF,EAAE;AAEN,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,CAC9C,QAAO,OAAO,EACZ,MAAM,OACP;AAGH,QAAO,IAAI,oBAAoB,MAAM,OAAO"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../
|
|
3
|
-
import {
|
|
4
|
-
import { FileSystemCollection, FileSystemCollectionConfig } from "./fs.js";
|
|
1
|
+
import { v as AsyncPipe } from "../core-Cd_KERZa.js";
|
|
2
|
+
import { n as LoaderConfig } from "../index-DZkwl_pd.js";
|
|
3
|
+
import { n as FileSystemCollectionConfig, t as FileSystemCollection } from "../fs-BHzpv9Wl.js";
|
|
5
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
5
|
|
|
7
6
|
//#region src/collections/data.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","names":[],"sources":["../../src/collections/data.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"data.d.ts","names":[],"sources":["../../src/collections/data.ts"],"mappings":";;;;;;UASiB,yBAAA;EACf,IAAA;EACA,MAAA;AAAA;AAAA,UAGQ,aAAA;EACR,IAAA;EACA,IAAA;EACA,MAAA,GAAS,MAAA,SAAe,YAAA;AAAA;AAAA,UAGT,oBAAA,gBAAoC,gBAAA,sBAAsC,IAAA,CACzF,0BAAA;EAGA,MAAA,GAAS,MAAA;;;;;;EAMT,OAAA,GAAU,aAAA;AAAA;AAAA,cAGC,cAAA,gBACI,gBAAA,eAA+B,gBAAA,sBACtC,oBAAA;EAAA;EACR,MAAA,GAAS,MAAA;EAhB0B;;;EAAA,SAoB1B,MAAA,EAAM,SAAA,UAAA,yBAAA;EACf,WAAA,EAAa,MAAA,SAAe,gBAAA,GAAmB,gBAAA,CAAiB,UAAA,CAAW,MAAA;EAE3E,YAAA,EAAc,MAAA,SAAe,gBAAA,GAAmB,gBAAA,CAAiB,WAAA,CAAY,MAAA;;IAG/D,GAAA;IAAK,KAAA;IAAO,OAAA,EAAS,cAAA;IAAqB;EAAA,GAAU,oBAAA,CAAqB,MAAA;AAAA;AAAA,iBA8DzE,cAAA,gBAA8B,gBAAA,yBAAA,CAC5C,MAAA,EAAQ,oBAAA,CAAqB,MAAA,IAAO,cAAA,CAAA,MAAA;AAAA,iBAKtB,UAAA,CAAA,GAAc,YAAA;AAAA,iBAuDd,UAAA,CAAA,GAAc,YAAA"}
|
package/dist/collections/data.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as slash } from "../code-generator-
|
|
1
|
+
import { r as asyncPipe } from "../collections-BuskUhft.js";
|
|
2
|
+
import { n as slash } from "../code-generator-pLUE7Rk7.js";
|
|
3
3
|
import { loaderHook } from "../plugins/loader/index.js";
|
|
4
4
|
import { FileSystemCollection } from "./fs.js";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
|
|
7
6
|
//#region src/collections/data.ts
|
|
8
7
|
var DataCollection = class extends FileSystemCollection {
|
|
9
8
|
schema;
|
|
@@ -102,7 +101,7 @@ function yamlLoader() {
|
|
|
102
101
|
};
|
|
103
102
|
},
|
|
104
103
|
async createLoader() {
|
|
105
|
-
const { createYamlLoader } = await import("../loader-
|
|
104
|
+
const { createYamlLoader } = await import("../loader-D_sKOzDc.js").then((n) => n.n);
|
|
106
105
|
const core = this.core;
|
|
107
106
|
return createYamlLoader({ getCore: () => core });
|
|
108
107
|
}
|
|
@@ -147,13 +146,13 @@ function jsonLoader() {
|
|
|
147
146
|
};
|
|
148
147
|
},
|
|
149
148
|
async createLoader(environment) {
|
|
150
|
-
const { createJsonLoader } = await import("../loader-
|
|
149
|
+
const { createJsonLoader } = await import("../loader-e2SkeDfY.js").then((n) => n.n);
|
|
151
150
|
const core = this.core;
|
|
152
151
|
return createJsonLoader({ getCore: () => core }, environment === "vite" ? "json" : "js");
|
|
153
152
|
}
|
|
154
153
|
};
|
|
155
154
|
}
|
|
156
|
-
|
|
157
155
|
//#endregion
|
|
158
156
|
export { DataCollection, dataCollection, jsonLoader, yamlLoader };
|
|
157
|
+
|
|
159
158
|
//# sourceMappingURL=data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","names":["#onEmitHandler"],"sources":["../../src/collections/data.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Configuration } from \"webpack\";\nimport { LoaderConfig, loaderHook } from \"@/plugins/loader\";\nimport type { TurbopackLoaderOptions } from \"next/dist/server/config-shared\";\nimport { asyncPipe } from \"@/utils/pipe\";\nimport { slash } from \"@/utils/code-generator\";\nimport { FileSystemCollection, FileSystemCollectionConfig } from \"./fs\";\nimport path from \"node:path\";\n\nexport interface DataTransformationContext {\n path: string;\n source: string;\n}\n\ninterface LoadersConfig {\n json?: boolean;\n yaml?: boolean;\n custom?: Record<string, LoaderConfig>;\n}\n\nexport interface DataCollectionConfig<Schema extends StandardSchemaV1 | undefined> extends Omit<\n FileSystemCollectionConfig,\n \"supportedFormats\"\n> {\n schema?: Schema;\n /**\n * Configurations for loaders to parse data files.\n *\n * By default, JSON and YAML are enabled.\n * */\n loaders?: LoadersConfig;\n}\n\nexport class DataCollection<\n Schema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined,\n> extends FileSystemCollection {\n schema?: Schema;\n /**\n * Transform data\n */\n readonly onLoad = asyncPipe<unknown, DataTransformationContext>();\n $inferInput: Schema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Schema> : unknown =\n undefined as never;\n $inferOutput: Schema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Schema> : unknown =\n undefined as never;\n\n constructor({ dir, files, loaders: _loadersConfig = {}, schema }: DataCollectionConfig<Schema>) {\n const loadersConfig: Record<string, LoaderConfig> = {\n ..._loadersConfig.custom,\n };\n if (_loadersConfig.json !== false) loadersConfig.json = jsonLoader();\n if (_loadersConfig.yaml !== false) loadersConfig.yaml = yamlLoader();\n\n super({ dir, files, supportedFormats: Object.keys(loadersConfig) });\n this.schema = schema;\n this.onServer.hook(({ core, server }) => {\n if (!server.watcher) return;\n\n server.watcher.on(\"all\", async (event, file) => {\n if (event === \"change\" || !this.hasFile(file)) return;\n\n await core.emit({\n filterCollection: (collection) => collection === this,\n filterWorkspace: () => false,\n write: true,\n });\n });\n });\n this.onEmit.pipe(this.#onEmitHandler.bind(this));\n this.pluginHook(loaderHook).loaders.push(...Object.values(loadersConfig));\n }\n\n #onEmitHandler: (typeof this)[\"onEmit\"][\"$inferHandler\"] = async (\n entries,\n { core, createCodeGenerator },\n ) => {\n entries.push(\n await createCodeGenerator(`${this.name}.ts`, async ({ codegen }) => {\n codegen.addNamedImport([\"dataStore\"], \"fuma-content/collections/data/runtime\");\n codegen.addNamespaceImport(\n \"Config\",\n codegen.formatImportPath(core.getOptions().configPath),\n true,\n );\n const base = slash(core._toRuntimePath(this.dir));\n let records = \"{\";\n const query = codegen.formatQuery({\n collection: this.name,\n workspace: core.getWorkspace()?.name,\n });\n\n for (const file of await this.getFiles()) {\n const fullPath = path.join(this.dir, file);\n const specifier = `${codegen.formatImportPath(fullPath)}?${query}`;\n const name = codegen.generateImportName();\n codegen.addNamedImport([`default as ${name}`], specifier);\n records += `\"${slash(file)}\": ${name},`;\n }\n records += \"}\";\n codegen.push(\n `export const ${this.name} = dataStore<typeof Config, \"${this.name}\">(\"${this.name}\", \"${base}\", ${records});`,\n );\n }),\n );\n return entries;\n };\n}\n\nexport function dataCollection<Schema extends StandardSchemaV1 | undefined = undefined>(\n config: DataCollectionConfig<Schema>,\n) {\n return new DataCollection(config);\n}\n\nexport function yamlLoader(): LoaderConfig {\n const test = /\\.yaml(\\?.+?)?$/;\n\n return {\n id: \"yaml\",\n test,\n configureNext(nextConfig) {\n const loaderPath = \"fuma-content/collections/yaml/loader-webpack\";\n const loaderOptions = this.getLoaderOptions();\n\n return {\n ...nextConfig,\n turbopack: {\n ...nextConfig.turbopack,\n rules: {\n ...nextConfig.turbopack?.rules,\n \"*.yaml\": {\n loaders: [\n {\n loader: loaderPath,\n options: loaderOptions as unknown as TurbopackLoaderOptions,\n },\n ],\n as: \"*.js\",\n },\n },\n },\n webpack(config: Configuration, options) {\n config.module ||= {};\n config.module.rules ||= [];\n config.module.rules.push({\n test,\n enforce: \"pre\",\n use: [\n {\n loader: loaderPath,\n options: loaderOptions,\n },\n ],\n });\n\n return nextConfig.webpack?.(config, options) ?? config;\n },\n };\n },\n async createLoader() {\n const { createYamlLoader } = await import(\"./yaml/loader\");\n const core = this.core;\n return createYamlLoader({\n getCore: () => core,\n });\n },\n };\n}\n\nexport function jsonLoader(): LoaderConfig {\n const test = /\\.json(\\?.+?)?$/;\n\n return {\n id: \"json\",\n test,\n configureNext(nextConfig) {\n const loaderPath = \"fuma-content/collections/json/loader-webpack\";\n const loaderOptions = this.getLoaderOptions();\n\n return {\n ...nextConfig,\n turbopack: {\n ...nextConfig.turbopack,\n rules: {\n ...nextConfig.turbopack?.rules,\n \"*.json\": {\n loaders: [\n {\n loader: loaderPath,\n options: loaderOptions as unknown as TurbopackLoaderOptions,\n },\n ],\n as: \"*.json\",\n },\n },\n },\n webpack(config: Configuration, options) {\n config.module ||= {};\n config.module.rules ||= [];\n config.module.rules.push({\n test,\n enforce: \"pre\",\n use: [\n {\n loader: loaderPath,\n options: loaderOptions,\n },\n ],\n });\n\n return nextConfig.webpack?.(config, options) ?? config;\n },\n };\n },\n async createLoader(environment) {\n const { createJsonLoader } = await import(\"./json/loader\");\n const core = this.core;\n return createJsonLoader(\n {\n getCore: () => core,\n },\n environment === \"vite\" ? \"json\" : \"js\",\n );\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"data.js","names":["#onEmitHandler"],"sources":["../../src/collections/data.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Configuration } from \"webpack\";\nimport { LoaderConfig, loaderHook } from \"@/plugins/loader\";\nimport type { TurbopackLoaderOptions } from \"next/dist/server/config-shared\";\nimport { asyncPipe } from \"@/utils/pipe\";\nimport { slash } from \"@/utils/code-generator\";\nimport { FileSystemCollection, FileSystemCollectionConfig } from \"./fs\";\nimport path from \"node:path\";\n\nexport interface DataTransformationContext {\n path: string;\n source: string;\n}\n\ninterface LoadersConfig {\n json?: boolean;\n yaml?: boolean;\n custom?: Record<string, LoaderConfig>;\n}\n\nexport interface DataCollectionConfig<Schema extends StandardSchemaV1 | undefined> extends Omit<\n FileSystemCollectionConfig,\n \"supportedFormats\"\n> {\n schema?: Schema;\n /**\n * Configurations for loaders to parse data files.\n *\n * By default, JSON and YAML are enabled.\n * */\n loaders?: LoadersConfig;\n}\n\nexport class DataCollection<\n Schema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined,\n> extends FileSystemCollection {\n schema?: Schema;\n /**\n * Transform data\n */\n readonly onLoad = asyncPipe<unknown, DataTransformationContext>();\n $inferInput: Schema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Schema> : unknown =\n undefined as never;\n $inferOutput: Schema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Schema> : unknown =\n undefined as never;\n\n constructor({ dir, files, loaders: _loadersConfig = {}, schema }: DataCollectionConfig<Schema>) {\n const loadersConfig: Record<string, LoaderConfig> = {\n ..._loadersConfig.custom,\n };\n if (_loadersConfig.json !== false) loadersConfig.json = jsonLoader();\n if (_loadersConfig.yaml !== false) loadersConfig.yaml = yamlLoader();\n\n super({ dir, files, supportedFormats: Object.keys(loadersConfig) });\n this.schema = schema;\n this.onServer.hook(({ core, server }) => {\n if (!server.watcher) return;\n\n server.watcher.on(\"all\", async (event, file) => {\n if (event === \"change\" || !this.hasFile(file)) return;\n\n await core.emit({\n filterCollection: (collection) => collection === this,\n filterWorkspace: () => false,\n write: true,\n });\n });\n });\n this.onEmit.pipe(this.#onEmitHandler.bind(this));\n this.pluginHook(loaderHook).loaders.push(...Object.values(loadersConfig));\n }\n\n #onEmitHandler: (typeof this)[\"onEmit\"][\"$inferHandler\"] = async (\n entries,\n { core, createCodeGenerator },\n ) => {\n entries.push(\n await createCodeGenerator(`${this.name}.ts`, async ({ codegen }) => {\n codegen.addNamedImport([\"dataStore\"], \"fuma-content/collections/data/runtime\");\n codegen.addNamespaceImport(\n \"Config\",\n codegen.formatImportPath(core.getOptions().configPath),\n true,\n );\n const base = slash(core._toRuntimePath(this.dir));\n let records = \"{\";\n const query = codegen.formatQuery({\n collection: this.name,\n workspace: core.getWorkspace()?.name,\n });\n\n for (const file of await this.getFiles()) {\n const fullPath = path.join(this.dir, file);\n const specifier = `${codegen.formatImportPath(fullPath)}?${query}`;\n const name = codegen.generateImportName();\n codegen.addNamedImport([`default as ${name}`], specifier);\n records += `\"${slash(file)}\": ${name},`;\n }\n records += \"}\";\n codegen.push(\n `export const ${this.name} = dataStore<typeof Config, \"${this.name}\">(\"${this.name}\", \"${base}\", ${records});`,\n );\n }),\n );\n return entries;\n };\n}\n\nexport function dataCollection<Schema extends StandardSchemaV1 | undefined = undefined>(\n config: DataCollectionConfig<Schema>,\n) {\n return new DataCollection(config);\n}\n\nexport function yamlLoader(): LoaderConfig {\n const test = /\\.yaml(\\?.+?)?$/;\n\n return {\n id: \"yaml\",\n test,\n configureNext(nextConfig) {\n const loaderPath = \"fuma-content/collections/yaml/loader-webpack\";\n const loaderOptions = this.getLoaderOptions();\n\n return {\n ...nextConfig,\n turbopack: {\n ...nextConfig.turbopack,\n rules: {\n ...nextConfig.turbopack?.rules,\n \"*.yaml\": {\n loaders: [\n {\n loader: loaderPath,\n options: loaderOptions as unknown as TurbopackLoaderOptions,\n },\n ],\n as: \"*.js\",\n },\n },\n },\n webpack(config: Configuration, options) {\n config.module ||= {};\n config.module.rules ||= [];\n config.module.rules.push({\n test,\n enforce: \"pre\",\n use: [\n {\n loader: loaderPath,\n options: loaderOptions,\n },\n ],\n });\n\n return nextConfig.webpack?.(config, options) ?? config;\n },\n };\n },\n async createLoader() {\n const { createYamlLoader } = await import(\"./yaml/loader\");\n const core = this.core;\n return createYamlLoader({\n getCore: () => core,\n });\n },\n };\n}\n\nexport function jsonLoader(): LoaderConfig {\n const test = /\\.json(\\?.+?)?$/;\n\n return {\n id: \"json\",\n test,\n configureNext(nextConfig) {\n const loaderPath = \"fuma-content/collections/json/loader-webpack\";\n const loaderOptions = this.getLoaderOptions();\n\n return {\n ...nextConfig,\n turbopack: {\n ...nextConfig.turbopack,\n rules: {\n ...nextConfig.turbopack?.rules,\n \"*.json\": {\n loaders: [\n {\n loader: loaderPath,\n options: loaderOptions as unknown as TurbopackLoaderOptions,\n },\n ],\n as: \"*.json\",\n },\n },\n },\n webpack(config: Configuration, options) {\n config.module ||= {};\n config.module.rules ||= [];\n config.module.rules.push({\n test,\n enforce: \"pre\",\n use: [\n {\n loader: loaderPath,\n options: loaderOptions,\n },\n ],\n });\n\n return nextConfig.webpack?.(config, options) ?? config;\n },\n };\n },\n async createLoader(environment) {\n const { createJsonLoader } = await import(\"./json/loader\");\n const core = this.core;\n return createJsonLoader(\n {\n getCore: () => core,\n },\n environment === \"vite\" ? \"json\" : \"js\",\n );\n },\n };\n}\n"],"mappings":";;;;;;AAiCA,IAAa,iBAAb,cAEU,qBAAqB;CAC7B;;;;CAIA,SAAkB,WAA+C;CACjE,cACE,KAAA;CACF,eACE,KAAA;CAEF,YAAY,EAAE,KAAK,OAAO,SAAS,iBAAiB,EAAE,EAAE,UAAwC;EAC9F,MAAM,gBAA8C,EAClD,GAAG,eAAe,QACnB;AACD,MAAI,eAAe,SAAS,MAAO,eAAc,OAAO,YAAY;AACpE,MAAI,eAAe,SAAS,MAAO,eAAc,OAAO,YAAY;AAEpE,QAAM;GAAE;GAAK;GAAO,kBAAkB,OAAO,KAAK,cAAc;GAAE,CAAC;AACnE,OAAK,SAAS;AACd,OAAK,SAAS,MAAM,EAAE,MAAM,aAAa;AACvC,OAAI,CAAC,OAAO,QAAS;AAErB,UAAO,QAAQ,GAAG,OAAO,OAAO,OAAO,SAAS;AAC9C,QAAI,UAAU,YAAY,CAAC,KAAK,QAAQ,KAAK,CAAE;AAE/C,UAAM,KAAK,KAAK;KACd,mBAAmB,eAAe,eAAe;KACjD,uBAAuB;KACvB,OAAO;KACR,CAAC;KACF;IACF;AACF,OAAK,OAAO,KAAK,MAAA,cAAoB,KAAK,KAAK,CAAC;AAChD,OAAK,WAAW,WAAW,CAAC,QAAQ,KAAK,GAAG,OAAO,OAAO,cAAc,CAAC;;CAG3E,iBAA2D,OACzD,SACA,EAAE,MAAM,0BACL;AACH,UAAQ,KACN,MAAM,oBAAoB,GAAG,KAAK,KAAK,MAAM,OAAO,EAAE,cAAc;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Q;OACR,SAAS;OACV,CACF;MACF,CAAC;AAEF,YAAO,WAAW,UAAU,QAAQ,QAAQ,IAAI;;IAEnD;;EAEH,MAAM,eAAe;GACnB,MAAM,EAAE,qBAAqB,MAAM,OAAO,yBAAA,MAAA,MAAA,EAAA,EAAA;GAC1C,MAAM,OAAO,KAAK;AAClB,UAAO,iBAAiB,EACtB,eAAe,MAChB,CAAC;;EAEL;;AAGH,SAAgB,aAA2B;CACzC,MAAM,OAAO;AAEb,QAAO;EACL,IAAI;EACJ;EACA,cAAc,YAAY;GACxB,MAAM,aAAa;GACnB,MAAM,gBAAgB,KAAK,kBAAkB;AAE7C,UAAO;IACL,GAAG;IACH,WAAW;KACT,GAAG,WAAW;KACd,OAAO;MACL,GAAG,WAAW,WAAW;MACzB,UAAU;OACR,SAAS,CACP;QACE,QAAQ;QACR,SAAS;QACV,CACF;OACD,IAAI;OACL;MACF;KACF;IACD,QAAQ,QAAuB,SAAS;AACtC,YAAO,WAAW,EAAE;AACpB,YAAO,OAAO,UAAU,EAAE;AAC1B,YAAO,OAAO,MAAM,KAAK;MACvB;MACA,SAAS;MACT,KAAK,CACH;OACE,QAAQ;OACR,SAAS;OACV,CACF;MACF,CAAC;AAEF,YAAO,WAAW,UAAU,QAAQ,QAAQ,IAAI;;IAEnD;;EAEH,MAAM,aAAa,aAAa;GAC9B,MAAM,EAAE,qBAAqB,MAAM,OAAO,yBAAA,MAAA,MAAA,EAAA,EAAA;GAC1C,MAAM,OAAO,KAAK;AAClB,UAAO,iBACL,EACE,eAAe,MAChB,EACD,gBAAgB,SAAS,SAAS,KACnC;;EAEJ"}
|
package/dist/collections/fs.d.ts
CHANGED
|
@@ -1,45 +1,2 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region src/collections/fs.d.ts
|
|
5
|
-
declare class FileSystemCollection extends Collection {
|
|
6
|
-
private matcher;
|
|
7
|
-
/**
|
|
8
|
-
* content directory (absolute)
|
|
9
|
-
*/
|
|
10
|
-
dir: string;
|
|
11
|
-
private readonly filesCache;
|
|
12
|
-
/** the glob patterns to match files in collection, this doesn't take `supportedFormats` into account. */
|
|
13
|
-
private readonly patterns;
|
|
14
|
-
readonly supportedFileFormats: string[] | undefined;
|
|
15
|
-
constructor(config: FileSystemCollectionConfig);
|
|
16
|
-
isFileSupported(filePath: string): boolean;
|
|
17
|
-
/**
|
|
18
|
-
* get all included files, relative to `dir`.
|
|
19
|
-
*
|
|
20
|
-
* the result is cached.
|
|
21
|
-
*/
|
|
22
|
-
getFiles(): Promise<string[]>;
|
|
23
|
-
hasFile(filePath: string): boolean;
|
|
24
|
-
invalidateCache(): void;
|
|
25
|
-
}
|
|
26
|
-
interface FileSystemCollectionConfig {
|
|
27
|
-
/**
|
|
28
|
-
* Directory to scan
|
|
29
|
-
*/
|
|
30
|
-
dir: string;
|
|
31
|
-
/**
|
|
32
|
-
* what files to include/exclude (glob patterns)
|
|
33
|
-
*
|
|
34
|
-
* Include all files if not specified
|
|
35
|
-
*/
|
|
36
|
-
files?: string[];
|
|
37
|
-
/**
|
|
38
|
-
* Restrict to a list of file extensions to include, e.g. `['js', 'ts']`.
|
|
39
|
-
*/
|
|
40
|
-
supportedFormats?: string[];
|
|
41
|
-
}
|
|
42
|
-
declare function fileSystemCollection(config: FileSystemCollectionConfig): FileSystemCollection;
|
|
43
|
-
//#endregion
|
|
44
|
-
export { FileSystemCollection, FileSystemCollectionConfig, fileSystemCollection };
|
|
45
|
-
//# sourceMappingURL=fs.d.ts.map
|
|
1
|
+
import { n as FileSystemCollectionConfig, r as fileSystemCollection, t as FileSystemCollection } from "../fs-BHzpv9Wl.js";
|
|
2
|
+
export { FileSystemCollection, FileSystemCollectionConfig, fileSystemCollection };
|
package/dist/collections/fs.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Collection } from "
|
|
2
|
-
import { t as createCache } from "../async-cache-
|
|
1
|
+
import { t as Collection } from "../collections-BuskUhft.js";
|
|
2
|
+
import { t as createCache } from "../async-cache-C47yxLCv.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import picomatch from "picomatch";
|
|
5
|
-
|
|
6
5
|
//#region src/collections/fs.ts
|
|
7
6
|
var FileSystemCollection = class extends Collection {
|
|
8
7
|
matcher;
|
|
@@ -60,7 +59,7 @@ var FileSystemCollection = class extends Collection {
|
|
|
60
59
|
function fileSystemCollection(config) {
|
|
61
60
|
return new FileSystemCollection(config);
|
|
62
61
|
}
|
|
63
|
-
|
|
64
62
|
//#endregion
|
|
65
63
|
export { FileSystemCollection, fileSystemCollection };
|
|
64
|
+
|
|
66
65
|
//# sourceMappingURL=fs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","names":[],"sources":["../../src/collections/fs.ts"],"sourcesContent":["import picomatch from \"picomatch\";\nimport path from \"node:path\";\nimport { Collection } from \".\";\nimport { createCache } from \"@/utils/async-cache\";\n\nexport class FileSystemCollection extends Collection {\n private matcher: picomatch.Matcher | undefined;\n /**\n * content directory (absolute)\n */\n dir: string;\n private readonly filesCache = createCache<string[]>();\n /** the glob patterns to match files in collection, this doesn't take `supportedFormats` into account. */\n private readonly patterns: string[];\n readonly supportedFileFormats: string[] | undefined;\n\n constructor(config: FileSystemCollectionConfig) {\n super();\n const { files, supportedFormats } = config;\n this.dir = config.dir;\n this.patterns = files ?? [supportedFormats ? `**/*.{${supportedFormats.join(\",\")}}` : `**/*`];\n this.supportedFileFormats = supportedFormats;\n this.onInit.hook(({ core }) => {\n this.dir = path.resolve(core.getOptions().cwd, this.dir);\n });\n this.onServer.hook(({ server }) => {\n if (!server.watcher) return;\n server.watcher.add(this.dir);\n server.watcher.on(\"all\", (event, file) => {\n if (event === \"change\" || !this.hasFile(file)) return;\n this.filesCache.invalidate(\"\");\n });\n });\n }\n\n isFileSupported(filePath: string) {\n if (!this.supportedFileFormats) return true;\n return this.supportedFileFormats.some((format) => filePath.endsWith(`.${format}`));\n }\n\n /**\n * get all included files, relative to `dir`.\n *\n * the result is cached.\n */\n async getFiles() {\n return this.filesCache.cached(\"\", async () => {\n const { glob } = await import(\"tinyglobby\");\n\n const out = await glob(this.patterns, { cwd: this.dir });\n return out.filter((v) => this.isFileSupported(v));\n });\n }\n\n hasFile(filePath: string) {\n if (!this.isFileSupported(filePath)) return false;\n\n const relativePath = path.relative(this.dir, filePath);\n if (relativePath.startsWith(`..${path.sep}`)) return false;\n\n return (this.matcher ??= picomatch(this.patterns))(relativePath);\n }\n\n invalidateCache() {\n this.filesCache.invalidate(\"\");\n }\n}\n\nexport interface FileSystemCollectionConfig {\n /**\n * Directory to scan\n */\n dir: string;\n\n /**\n * what files to include/exclude (glob patterns)\n *\n * Include all files if not specified\n */\n files?: string[];\n\n /**\n * Restrict to a list of file extensions to include, e.g. `['js', 'ts']`.\n */\n supportedFormats?: string[];\n}\n\nexport function fileSystemCollection(config: FileSystemCollectionConfig) {\n return new FileSystemCollection(config);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fs.js","names":[],"sources":["../../src/collections/fs.ts"],"sourcesContent":["import picomatch from \"picomatch\";\nimport path from \"node:path\";\nimport { Collection } from \".\";\nimport { createCache } from \"@/utils/async-cache\";\n\nexport class FileSystemCollection extends Collection {\n private matcher: picomatch.Matcher | undefined;\n /**\n * content directory (absolute)\n */\n dir: string;\n private readonly filesCache = createCache<string[]>();\n /** the glob patterns to match files in collection, this doesn't take `supportedFormats` into account. */\n private readonly patterns: string[];\n readonly supportedFileFormats: string[] | undefined;\n\n constructor(config: FileSystemCollectionConfig) {\n super();\n const { files, supportedFormats } = config;\n this.dir = config.dir;\n this.patterns = files ?? [supportedFormats ? `**/*.{${supportedFormats.join(\",\")}}` : `**/*`];\n this.supportedFileFormats = supportedFormats;\n this.onInit.hook(({ core }) => {\n this.dir = path.resolve(core.getOptions().cwd, this.dir);\n });\n this.onServer.hook(({ server }) => {\n if (!server.watcher) return;\n server.watcher.add(this.dir);\n server.watcher.on(\"all\", (event, file) => {\n if (event === \"change\" || !this.hasFile(file)) return;\n this.filesCache.invalidate(\"\");\n });\n });\n }\n\n isFileSupported(filePath: string) {\n if (!this.supportedFileFormats) return true;\n return this.supportedFileFormats.some((format) => filePath.endsWith(`.${format}`));\n }\n\n /**\n * get all included files, relative to `dir`.\n *\n * the result is cached.\n */\n async getFiles() {\n return this.filesCache.cached(\"\", async () => {\n const { glob } = await import(\"tinyglobby\");\n\n const out = await glob(this.patterns, { cwd: this.dir });\n return out.filter((v) => this.isFileSupported(v));\n });\n }\n\n hasFile(filePath: string) {\n if (!this.isFileSupported(filePath)) return false;\n\n const relativePath = path.relative(this.dir, filePath);\n if (relativePath.startsWith(`..${path.sep}`)) return false;\n\n return (this.matcher ??= picomatch(this.patterns))(relativePath);\n }\n\n invalidateCache() {\n this.filesCache.invalidate(\"\");\n }\n}\n\nexport interface FileSystemCollectionConfig {\n /**\n * Directory to scan\n */\n dir: string;\n\n /**\n * what files to include/exclude (glob patterns)\n *\n * Include all files if not specified\n */\n files?: string[];\n\n /**\n * Restrict to a list of file extensions to include, e.g. `['js', 'ts']`.\n */\n supportedFormats?: string[];\n}\n\nexport function fileSystemCollection(config: FileSystemCollectionConfig) {\n return new FileSystemCollection(config);\n}\n"],"mappings":";;;;;AAKA,IAAa,uBAAb,cAA0C,WAAW;CACnD;;;;CAIA;CACA,aAA8B,aAAuB;;CAErD;CACA;CAEA,YAAY,QAAoC;AAC9C,SAAO;EACP,MAAM,EAAE,OAAO,qBAAqB;AACpC,OAAK,MAAM,OAAO;AAClB,OAAK,WAAW,SAAS,CAAC,mBAAmB,SAAS,iBAAiB,KAAK,IAAI,CAAC,KAAK,OAAO;AAC7F,OAAK,uBAAuB;AAC5B,OAAK,OAAO,MAAM,EAAE,WAAW;AAC7B,QAAK,MAAM,KAAK,QAAQ,KAAK,YAAY,CAAC,KAAK,KAAK,IAAI;IACxD;AACF,OAAK,SAAS,MAAM,EAAE,aAAa;AACjC,OAAI,CAAC,OAAO,QAAS;AACrB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