fuma-content 0.0.2 → 1.0.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.
Files changed (74) hide show
  1. package/dist/bin.d.ts +1 -0
  2. package/dist/bin.js +18 -0
  3. package/dist/build-mdx-Q4RMDWYK.js +8 -0
  4. package/dist/bun/index.d.ts +16 -0
  5. package/dist/bun/index.js +36 -0
  6. package/dist/bun-DMNX4PBC.js +40 -0
  7. package/dist/chunk-3VQS3KSP.js +39 -0
  8. package/dist/chunk-4RMSJCK2.js +50 -0
  9. package/dist/chunk-6XDQG2GV.js +17 -0
  10. package/dist/chunk-AMBGM4OK.js +412 -0
  11. package/dist/chunk-BTRE6MOX.js +16 -0
  12. package/dist/chunk-E4HRKSP4.js +24 -0
  13. package/dist/chunk-ERBMAQYP.js +33 -0
  14. package/dist/chunk-IGLM4N4P.js +34 -0
  15. package/dist/chunk-LDBQ66H3.js +38 -0
  16. package/dist/chunk-M72VQL5M.js +40 -0
  17. package/dist/chunk-OUJENWQ4.js +45 -0
  18. package/dist/chunk-PNA5UGSL.js +104 -0
  19. package/dist/chunk-RMSV4HP6.js +85 -0
  20. package/dist/chunk-RXR7OL76.js +37 -0
  21. package/dist/chunk-VWJKRQZR.js +19 -0
  22. package/dist/chunk-Z7KHD7MS.js +368 -0
  23. package/dist/collections/handlers/fs.d.ts +10 -0
  24. package/dist/collections/handlers/fs.js +6 -0
  25. package/dist/collections/index.d.ts +10 -0
  26. package/dist/collections/index.js +6 -0
  27. package/dist/collections/mdx/loader-webpack.d.ts +17 -0
  28. package/dist/collections/mdx/loader-webpack.js +38 -0
  29. package/dist/collections/mdx/runtime-browser.d.ts +44 -0
  30. package/dist/collections/mdx/runtime-browser.js +74 -0
  31. package/dist/collections/mdx/runtime-dynamic.d.ts +42 -0
  32. package/dist/collections/mdx/runtime-dynamic.js +94 -0
  33. package/dist/collections/mdx/runtime.d.ts +69 -0
  34. package/dist/collections/mdx/runtime.js +45 -0
  35. package/dist/collections/mdx.d.ts +10 -0
  36. package/dist/collections/mdx.js +287 -0
  37. package/dist/collections/meta/loader-webpack.d.ts +17 -0
  38. package/dist/collections/meta/loader-webpack.js +41 -0
  39. package/dist/collections/meta/runtime.d.ts +19 -0
  40. package/dist/collections/meta/runtime.js +18 -0
  41. package/dist/collections/meta.d.ts +10 -0
  42. package/dist/collections/meta.js +166 -0
  43. package/dist/collections/runtime/file-store.d.ts +19 -0
  44. package/dist/collections/runtime/file-store.js +7 -0
  45. package/dist/collections/runtime/store.d.ts +28 -0
  46. package/dist/collections/runtime/store.js +6 -0
  47. package/dist/config/index.d.ts +10 -0
  48. package/dist/config/index.js +7 -0
  49. package/dist/core-DxnSmTRe.d.ts +411 -0
  50. package/dist/index.d.ts +13 -31
  51. package/dist/index.js +0 -51
  52. package/dist/load-from-file-MLL4WQ5J.js +7 -0
  53. package/dist/loader-T756NSCS.js +7 -0
  54. package/dist/loader-VGDLYG4T.js +7 -0
  55. package/dist/next/index.cjs +571 -0
  56. package/dist/next/index.d.ts +27 -0
  57. package/dist/next/index.js +99 -0
  58. package/dist/node/loader.d.ts +5 -0
  59. package/dist/node/loader.js +46 -0
  60. package/dist/node-DCMYL4DL.js +34 -0
  61. package/dist/plugins/git.d.ts +10 -0
  62. package/dist/plugins/git.js +70 -0
  63. package/dist/plugins/json-schema.d.ts +10 -0
  64. package/dist/plugins/json-schema.js +59 -0
  65. package/dist/plugins/with-loader/index.d.ts +61 -0
  66. package/dist/plugins/with-loader/index.js +6 -0
  67. package/dist/plugins/with-loader/webpack.d.ts +27 -0
  68. package/dist/plugins/with-loader/webpack.js +11 -0
  69. package/dist/vite/index.d.ts +33 -0
  70. package/dist/vite/index.js +60 -0
  71. package/dist/vite-QCUPZHHB.js +32 -0
  72. package/package.json +103 -36
  73. package/dist/internal.d.ts +0 -114
  74. package/dist/internal.js +0 -420
@@ -0,0 +1,33 @@
1
+ // src/plugins/with-loader/index.ts
2
+ function withLoader(plugin, { test, createLoader }) {
3
+ let loader;
4
+ return {
5
+ bun: {
6
+ async build(build) {
7
+ const { toBun } = await import("./bun-DMNX4PBC.js");
8
+ toBun(test, await (loader ??= createLoader.call(this, "bun")))(build);
9
+ }
10
+ },
11
+ node: {
12
+ async createLoad() {
13
+ const { toNode } = await import("./node-DCMYL4DL.js");
14
+ return toNode(test, await (loader ??= createLoader.call(this, "node")));
15
+ }
16
+ },
17
+ vite: {
18
+ async createPlugin() {
19
+ const { toVite } = await import("./vite-QCUPZHHB.js");
20
+ return toVite(
21
+ plugin.name,
22
+ test,
23
+ await (loader ??= createLoader.call(this, "vite"))
24
+ );
25
+ }
26
+ },
27
+ ...plugin
28
+ };
29
+ }
30
+
31
+ export {
32
+ withLoader
33
+ };
@@ -0,0 +1,34 @@
1
+ // src/config/build.ts
2
+ function buildConfig(config, workspace) {
3
+ const collections = /* @__PURE__ */ new Map();
4
+ const loaded = {};
5
+ const globalConfig = config.default ?? config;
6
+ if (globalConfig.collections) {
7
+ for (const [name, collection] of Object.entries(globalConfig.collections)) {
8
+ collection.init?.({ name, workspace });
9
+ collections.set(name, collection);
10
+ }
11
+ }
12
+ return {
13
+ ...globalConfig,
14
+ collections,
15
+ workspaces: Object.fromEntries(
16
+ Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
17
+ return [
18
+ key,
19
+ {
20
+ dir: value.dir,
21
+ config: buildConfig(value.config, {
22
+ ...value,
23
+ name: key
24
+ })
25
+ }
26
+ ];
27
+ })
28
+ )
29
+ };
30
+ }
31
+
32
+ export {
33
+ buildConfig
34
+ };
@@ -0,0 +1,38 @@
1
+ // src/config/dynamic.ts
2
+ import fs from "fs/promises";
3
+ function createDynamicCore({
4
+ core,
5
+ buildConfig,
6
+ mode
7
+ }) {
8
+ let prev;
9
+ async function getConfigHash() {
10
+ if (mode === "production") return "static";
11
+ const stats = await fs.stat(core.getOptions().configPath).catch(() => {
12
+ throw new Error("Cannot find config file");
13
+ });
14
+ return stats.mtime.getTime().toString();
15
+ }
16
+ return {
17
+ async getCore() {
18
+ const hash = await getConfigHash();
19
+ if (!prev || hash !== prev.hash) {
20
+ prev = {
21
+ hash,
22
+ init: (async () => {
23
+ const { loadConfig } = await import("./load-from-file-MLL4WQ5J.js");
24
+ await core.init({
25
+ config: loadConfig(core, buildConfig)
26
+ });
27
+ })()
28
+ };
29
+ }
30
+ await prev.init;
31
+ return core;
32
+ }
33
+ };
34
+ }
35
+
36
+ export {
37
+ createDynamicCore
38
+ };
@@ -0,0 +1,40 @@
1
+ import {
2
+ buildConfig
3
+ } from "./chunk-IGLM4N4P.js";
4
+
5
+ // src/config/load-from-file.ts
6
+ import { pathToFileURL } from "url";
7
+ async function compileConfig(core) {
8
+ const { build } = await import("esbuild");
9
+ const { configPath, outDir } = core.getOptions();
10
+ const transformed = await build({
11
+ entryPoints: [{ in: configPath, out: "content.config" }],
12
+ bundle: true,
13
+ outdir: outDir,
14
+ target: "node20",
15
+ write: true,
16
+ platform: "node",
17
+ format: "esm",
18
+ packages: "external",
19
+ outExtension: {
20
+ ".js": ".mjs"
21
+ },
22
+ allowOverwrite: true
23
+ });
24
+ if (transformed.errors.length > 0) {
25
+ throw new Error("failed to compile configuration file");
26
+ }
27
+ }
28
+ async function loadConfig(core, build = false) {
29
+ if (build) await compileConfig(core);
30
+ const url = pathToFileURL(core.getCompiledConfigPath());
31
+ url.searchParams.set("hash", Date.now().toString());
32
+ const config = import(url.href).then(
33
+ (loaded) => buildConfig(loaded)
34
+ );
35
+ return await config;
36
+ }
37
+
38
+ export {
39
+ loadConfig
40
+ };
@@ -0,0 +1,45 @@
1
+ // src/utils/validation.ts
2
+ var ValidationError = class extends Error {
3
+ title;
4
+ issues;
5
+ constructor(message, issues) {
6
+ super(
7
+ `${message}:
8
+ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
9
+ );
10
+ this.title = message;
11
+ this.issues = issues;
12
+ }
13
+ async toStringFormatted() {
14
+ const picocolorsModule = await import("picocolors");
15
+ const picocolors = picocolorsModule.default ?? picocolorsModule;
16
+ return [
17
+ picocolors.bold(`[MDX] ${this.title}:`),
18
+ ...this.issues.map(
19
+ (issue) => picocolors.redBright(
20
+ `- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
21
+ )
22
+ )
23
+ ].join("\n");
24
+ }
25
+ };
26
+ async function validate(schema, data, context, errorMessage) {
27
+ if (typeof schema === "function" && !("~standard" in schema)) {
28
+ schema = schema(context);
29
+ }
30
+ if ("~standard" in schema) {
31
+ const result = await schema["~standard"].validate(
32
+ data
33
+ );
34
+ if (result.issues) {
35
+ throw new ValidationError(errorMessage, result.issues);
36
+ }
37
+ return result.value;
38
+ }
39
+ return data;
40
+ }
41
+
42
+ export {
43
+ ValidationError,
44
+ validate
45
+ };
@@ -0,0 +1,104 @@
1
+ import {
2
+ fumaMatter
3
+ } from "./chunk-VWJKRQZR.js";
4
+
5
+ // src/collections/mdx/loader.ts
6
+ import { z } from "zod";
7
+ import fs from "fs/promises";
8
+ import path from "path";
9
+ import { createHash } from "crypto";
10
+ var querySchema = z.object({
11
+ only: z.literal(["frontmatter", "all"]).default("all"),
12
+ collection: z.string().optional(),
13
+ workspace: z.string().optional()
14
+ }).loose();
15
+ var cacheEntry = z.object({
16
+ code: z.string(),
17
+ map: z.any().optional(),
18
+ hash: z.string().optional()
19
+ });
20
+ function createMdxLoader({ getCore }) {
21
+ return {
22
+ async load({
23
+ getSource,
24
+ development: isDevelopment,
25
+ query,
26
+ compiler,
27
+ filePath
28
+ }) {
29
+ let core = await getCore();
30
+ const value = await getSource();
31
+ const matter = fumaMatter(value);
32
+ const {
33
+ collection: collectionName,
34
+ workspace,
35
+ only
36
+ } = querySchema.parse(query);
37
+ if (workspace) {
38
+ core = core.getWorkspaces().get(workspace) ?? core;
39
+ }
40
+ let after;
41
+ const { experimentalBuildCache = false } = core.getConfig();
42
+ if (!isDevelopment && experimentalBuildCache) {
43
+ const cacheDir = experimentalBuildCache;
44
+ const cacheKey = `${collectionName ?? "global"}_${generateCacheHash(filePath)}`;
45
+ const cached = await fs.readFile(path.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
46
+ if (cached && cached.hash === generateCacheHash(value)) return cached;
47
+ after = async () => {
48
+ await fs.mkdir(cacheDir, { recursive: true });
49
+ await fs.writeFile(
50
+ path.join(cacheDir, cacheKey),
51
+ JSON.stringify({
52
+ ...out,
53
+ hash: generateCacheHash(value)
54
+ })
55
+ );
56
+ };
57
+ }
58
+ const collection = collectionName ? core.getCollection(collectionName) : void 0;
59
+ const handler = collection?.handlers.mdx;
60
+ if (collection && handler?.frontmatter) {
61
+ matter.data = await handler.frontmatter.call(
62
+ { collection, filePath, source: value },
63
+ matter.data
64
+ );
65
+ }
66
+ if (only === "frontmatter") {
67
+ return {
68
+ code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
69
+ map: null
70
+ };
71
+ }
72
+ const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
73
+ const { buildMDX } = await import("./build-mdx-Q4RMDWYK.js");
74
+ const compiled = await buildMDX(core, collection, {
75
+ isDevelopment,
76
+ source: "\n".repeat(lineOffset) + matter.content,
77
+ filePath,
78
+ frontmatter: matter.data,
79
+ _compiler: compiler,
80
+ environment: "bundler"
81
+ });
82
+ const out = {
83
+ code: String(compiled.value),
84
+ map: compiled.map
85
+ };
86
+ await after?.();
87
+ return out;
88
+ }
89
+ };
90
+ }
91
+ function generateCacheHash(input) {
92
+ return createHash("md5").update(input).digest("hex");
93
+ }
94
+ function countLines(s) {
95
+ let num = 0;
96
+ for (const c of s) {
97
+ if (c === "\n") num++;
98
+ }
99
+ return num;
100
+ }
101
+
102
+ export {
103
+ createMdxLoader
104
+ };
@@ -0,0 +1,85 @@
1
+ import {
2
+ validate
3
+ } from "./chunk-OUJENWQ4.js";
4
+
5
+ // src/collections/meta/loader.ts
6
+ import { dump, load } from "js-yaml";
7
+ import { z } from "zod";
8
+ var querySchema = z.object({
9
+ collection: z.string().optional(),
10
+ workspace: z.string().optional()
11
+ }).loose();
12
+ function createMetaLoader({ getCore }, resolve = {}) {
13
+ const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve;
14
+ function parse(filePath, source) {
15
+ try {
16
+ if (filePath.endsWith(".json")) return JSON.parse(source);
17
+ if (filePath.endsWith(".yaml")) return load(source);
18
+ } catch (e) {
19
+ throw new Error(`invalid data in ${filePath}`, { cause: e });
20
+ }
21
+ throw new Error(`Unknown file type ${filePath}`);
22
+ }
23
+ function onMeta(source, { filePath, query }) {
24
+ const parsed = querySchema.safeParse(query);
25
+ if (!parsed.success || !parsed.data.collection) return null;
26
+ const { collection: collectionName, workspace } = parsed.data;
27
+ return async () => {
28
+ let core = await getCore();
29
+ if (workspace) {
30
+ core = core.getWorkspaces().get(workspace) ?? core;
31
+ }
32
+ const collection = core.getCollection(collectionName);
33
+ const handler = collection?.handlers.meta;
34
+ let data = parse(filePath, source);
35
+ if (!handler) return data;
36
+ const context = {
37
+ path: filePath,
38
+ source
39
+ };
40
+ if (handler.schema) {
41
+ data = await validate(
42
+ handler.schema,
43
+ data,
44
+ context,
45
+ `invalid data in ${filePath}`
46
+ );
47
+ }
48
+ return handler.transform?.call(context, data);
49
+ };
50
+ }
51
+ return {
52
+ async load(input) {
53
+ const result = onMeta(await input.getSource(), input);
54
+ if (result === null) return null;
55
+ const data = await result();
56
+ if (input.filePath.endsWith(".json")) {
57
+ return {
58
+ code: resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`
59
+ };
60
+ } else {
61
+ return {
62
+ code: resolveYaml === "yaml" ? dump(data) : `export default ${JSON.stringify(data)}`
63
+ };
64
+ }
65
+ },
66
+ bun: {
67
+ load(source, input) {
68
+ const result = onMeta(source, input);
69
+ if (result === null)
70
+ return {
71
+ loader: "object",
72
+ exports: parse(input.filePath, source)
73
+ };
74
+ return result().then((data) => ({
75
+ loader: "object",
76
+ exports: { default: data }
77
+ }));
78
+ }
79
+ }
80
+ };
81
+ }
82
+
83
+ export {
84
+ createMetaLoader
85
+ };
@@ -0,0 +1,37 @@
1
+ import {
2
+ SimpleCollectionStore
3
+ } from "./chunk-3VQS3KSP.js";
4
+
5
+ // src/collections/runtime/file-store.ts
6
+ import path from "path";
7
+ function fileInfo(base, globKey) {
8
+ if (globKey.startsWith("./")) {
9
+ globKey = globKey.slice(2);
10
+ }
11
+ return {
12
+ path: globKey,
13
+ fullPath: path.join(base, globKey)
14
+ };
15
+ }
16
+ var FileCollectionStore = class extends SimpleCollectionStore {
17
+ constructor(base, glob) {
18
+ const data = /* @__PURE__ */ new Map();
19
+ for (const [key, value] of Object.entries(glob)) {
20
+ data.set(key, {
21
+ ...value,
22
+ ...fileInfo(base, key)
23
+ });
24
+ }
25
+ super(data);
26
+ }
27
+ transform(fn) {
28
+ return super.transform(fn);
29
+ }
30
+ $data(_cast) {
31
+ return super.$data(_cast);
32
+ }
33
+ };
34
+
35
+ export {
36
+ FileCollectionStore
37
+ };
@@ -0,0 +1,19 @@
1
+ // src/utils/fuma-matter.ts
2
+ import { load } from "js-yaml";
3
+ var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
4
+ function fumaMatter(input) {
5
+ const output = { matter: "", data: {}, content: input };
6
+ const match = regex.exec(input);
7
+ if (!match) {
8
+ return output;
9
+ }
10
+ output.matter = match[0];
11
+ output.content = input.slice(match[0].length);
12
+ const loaded = load(match[1]);
13
+ output.data = loaded ?? {};
14
+ return output;
15
+ }
16
+
17
+ export {
18
+ fumaMatter
19
+ };