fuma-content 1.0.1 → 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.
Files changed (147) hide show
  1. package/dist/async-cache-C0J_pTbk.js +29 -0
  2. package/dist/async-cache-C0J_pTbk.js.map +1 -0
  3. package/dist/bin.d.ts +1 -1
  4. package/dist/bin.js +21 -14
  5. package/dist/bin.js.map +1 -0
  6. package/dist/build-mdx-CSrSOQxF.js +4 -0
  7. package/dist/build-mdx-DugsQ0sk.js +395 -0
  8. package/dist/build-mdx-DugsQ0sk.js.map +1 -0
  9. package/dist/bun/index.d.ts +6 -13
  10. package/dist/bun/index.d.ts.map +1 -0
  11. package/dist/bun/index.js +18 -34
  12. package/dist/bun/index.js.map +1 -0
  13. package/dist/bun-Br1ReMiq.js +35 -0
  14. package/dist/bun-Br1ReMiq.js.map +1 -0
  15. package/dist/code-generator-BvuyL0UO.js +133 -0
  16. package/dist/code-generator-BvuyL0UO.js.map +1 -0
  17. package/dist/collections/handlers/fs.d.ts +2 -10
  18. package/dist/collections/handlers/fs.js +31 -6
  19. package/dist/collections/handlers/fs.js.map +1 -0
  20. package/dist/collections/index.d.ts +2 -10
  21. package/dist/collections/index.js +16 -6
  22. package/dist/collections/index.js.map +1 -0
  23. package/dist/collections/mdx/loader-webpack.d.ts +6 -14
  24. package/dist/collections/mdx/loader-webpack.d.ts.map +1 -0
  25. package/dist/collections/mdx/loader-webpack.js +23 -36
  26. package/dist/collections/mdx/loader-webpack.js.map +1 -0
  27. package/dist/collections/mdx/runtime-browser.d.ts +27 -37
  28. package/dist/collections/mdx/runtime-browser.d.ts.map +1 -0
  29. package/dist/collections/mdx/runtime-browser.js +57 -70
  30. package/dist/collections/mdx/runtime-browser.js.map +1 -0
  31. package/dist/collections/mdx/runtime-dynamic.d.ts +22 -30
  32. package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -0
  33. package/dist/collections/mdx/runtime-dynamic.js +62 -85
  34. package/dist/collections/mdx/runtime-dynamic.js.map +1 -0
  35. package/dist/collections/mdx/runtime.d.ts +31 -52
  36. package/dist/collections/mdx/runtime.d.ts.map +1 -0
  37. package/dist/collections/mdx/runtime.js +24 -34
  38. package/dist/collections/mdx/runtime.js.map +1 -0
  39. package/dist/collections/mdx.d.ts +2 -10
  40. package/dist/collections/mdx.js +241 -284
  41. package/dist/collections/mdx.js.map +1 -0
  42. package/dist/collections/meta/loader-webpack.d.ts +6 -14
  43. package/dist/collections/meta/loader-webpack.d.ts.map +1 -0
  44. package/dist/collections/meta/loader-webpack.js +22 -39
  45. package/dist/collections/meta/loader-webpack.js.map +1 -0
  46. package/dist/collections/meta/runtime.d.ts +7 -15
  47. package/dist/collections/meta/runtime.d.ts.map +1 -0
  48. package/dist/collections/meta/runtime.js +9 -15
  49. package/dist/collections/meta/runtime.js.map +1 -0
  50. package/dist/collections/meta.d.ts +2 -10
  51. package/dist/collections/meta.js +125 -164
  52. package/dist/collections/meta.js.map +1 -0
  53. package/dist/collections/runtime/file-store.d.ts +17 -14
  54. package/dist/collections/runtime/file-store.d.ts.map +1 -0
  55. package/dist/collections/runtime/file-store.js +30 -6
  56. package/dist/collections/runtime/file-store.js.map +1 -0
  57. package/dist/collections/runtime/store.d.ts +3 -28
  58. package/dist/collections/runtime/store.js +3 -6
  59. package/dist/config/index.d.ts +2 -10
  60. package/dist/config/index.js +6 -5
  61. package/dist/config/index.js.map +1 -0
  62. package/dist/core-CRWvbE7W.d.ts +588 -0
  63. package/dist/core-CRWvbE7W.d.ts.map +1 -0
  64. package/dist/core-CnZQDCJ1.js +205 -0
  65. package/dist/core-CnZQDCJ1.js.map +1 -0
  66. package/dist/dynamic.d.ts +24 -0
  67. package/dist/dynamic.d.ts.map +1 -0
  68. package/dist/dynamic.js +28 -0
  69. package/dist/dynamic.js.map +1 -0
  70. package/dist/fuma-matter-D3kkMkdj.js +27 -0
  71. package/dist/fuma-matter-D3kkMkdj.js.map +1 -0
  72. package/dist/index.d.ts +17 -16
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +6 -8
  75. package/dist/load-from-file-BctwhOUd.js +3 -0
  76. package/dist/load-from-file-XiM8eZha.js +37 -0
  77. package/dist/load-from-file-XiM8eZha.js.map +1 -0
  78. package/dist/loader-BHMDOncZ.js +4 -0
  79. package/dist/loader-C7W_Rwj8.js +80 -0
  80. package/dist/loader-C7W_Rwj8.js.map +1 -0
  81. package/dist/loader-DLSJPUiO.js +69 -0
  82. package/dist/loader-DLSJPUiO.js.map +1 -0
  83. package/dist/loader-DkmGoUvo.js +4 -0
  84. package/dist/next/index.cjs +457 -554
  85. package/dist/next/index.d.ts +16 -22
  86. package/dist/next/index.d.ts.map +1 -0
  87. package/dist/next/index.js +71 -89
  88. package/dist/next/index.js.map +1 -0
  89. package/dist/node/loader.d.ts +4 -2
  90. package/dist/node/loader.d.ts.map +1 -0
  91. package/dist/node/loader.js +29 -44
  92. package/dist/node/loader.js.map +1 -0
  93. package/dist/node-CVAU22o3.js +31 -0
  94. package/dist/node-CVAU22o3.js.map +1 -0
  95. package/dist/pipe-UEMV1mRg.js +31 -0
  96. package/dist/pipe-UEMV1mRg.js.map +1 -0
  97. package/dist/plugins/git.d.ts +2 -10
  98. package/dist/plugins/git.js +57 -65
  99. package/dist/plugins/git.js.map +1 -0
  100. package/dist/plugins/json-schema.d.ts +2 -10
  101. package/dist/plugins/json-schema.js +60 -58
  102. package/dist/plugins/json-schema.js.map +1 -0
  103. package/dist/plugins/with-loader/index.d.ts +2 -61
  104. package/dist/plugins/with-loader/index.js +28 -6
  105. package/dist/plugins/with-loader/index.js.map +1 -0
  106. package/dist/plugins/with-loader/webpack.d.ts +10 -18
  107. package/dist/plugins/with-loader/webpack.d.ts.map +1 -0
  108. package/dist/plugins/with-loader/webpack.js +43 -12
  109. package/dist/plugins/with-loader/webpack.js.map +1 -0
  110. package/dist/store-BtGmZUAC.d.ts +31 -0
  111. package/dist/store-BtGmZUAC.d.ts.map +1 -0
  112. package/dist/store-D166MOLw.js +37 -0
  113. package/dist/store-D166MOLw.js.map +1 -0
  114. package/dist/validation-BYUzZIfc.js +37 -0
  115. package/dist/validation-BYUzZIfc.js.map +1 -0
  116. package/dist/vite/index.d.ts +22 -28
  117. package/dist/vite/index.d.ts.map +1 -0
  118. package/dist/vite/index.js +44 -53
  119. package/dist/vite/index.js.map +1 -0
  120. package/dist/vite-6awgG092.js +33 -0
  121. package/dist/vite-6awgG092.js.map +1 -0
  122. package/package.json +47 -42
  123. package/dist/build-mdx-I4NROXCF.js +0 -8
  124. package/dist/bun-DMNX4PBC.js +0 -40
  125. package/dist/chunk-3VQS3KSP.js +0 -39
  126. package/dist/chunk-BTRE6MOX.js +0 -16
  127. package/dist/chunk-E4HRKSP4.js +0 -24
  128. package/dist/chunk-ERBMAQYP.js +0 -33
  129. package/dist/chunk-GGL4EF6H.js +0 -38
  130. package/dist/chunk-JBZTQ55D.js +0 -30
  131. package/dist/chunk-KH5GT2Y5.js +0 -104
  132. package/dist/chunk-LUM7SIZN.js +0 -40
  133. package/dist/chunk-MT7RY65Y.js +0 -167
  134. package/dist/chunk-NRZ4GE5O.js +0 -207
  135. package/dist/chunk-OQQNA7L7.js +0 -412
  136. package/dist/chunk-OUJENWQ4.js +0 -45
  137. package/dist/chunk-RMSV4HP6.js +0 -85
  138. package/dist/chunk-RXR7OL76.js +0 -37
  139. package/dist/chunk-VWJKRQZR.js +0 -19
  140. package/dist/chunk-W6HENTK7.js +0 -44
  141. package/dist/chunk-XR5N6ZXJ.js +0 -50
  142. package/dist/core-Bo8KaWQz.d.ts +0 -411
  143. package/dist/load-from-file-HL2VEY3M.js +0 -7
  144. package/dist/loader-NFSL6P5I.js +0 -7
  145. package/dist/loader-T756NSCS.js +0 -7
  146. package/dist/node-DCMYL4DL.js +0 -34
  147. package/dist/vite-QCUPZHHB.js +0 -32
@@ -1,412 +0,0 @@
1
- import {
2
- fumaMatter
3
- } from "./chunk-VWJKRQZR.js";
4
- import {
5
- createCache
6
- } from "./chunk-JBZTQ55D.js";
7
-
8
- // src/collections/mdx/build-mdx.ts
9
- import { createProcessor } from "@mdx-js/mdx";
10
- import { VFile as VFile2 } from "vfile";
11
-
12
- // src/collections/mdx/remark-include.ts
13
- import {
14
- unified
15
- } from "unified";
16
- import { visit as visit2 } from "unist-util-visit";
17
- import * as path from "path";
18
- import * as fs from "fs/promises";
19
- import { VFile } from "vfile";
20
-
21
- // src/collections/mdx/remark-unravel.ts
22
- import { visit } from "unist-util-visit";
23
- function remarkMarkAndUnravel() {
24
- return (tree) => {
25
- visit(tree, (node, index, parent) => {
26
- let offset = -1;
27
- let all = true;
28
- let oneOrMore = false;
29
- if (parent && typeof index === "number" && node.type === "paragraph") {
30
- const children = node.children;
31
- while (++offset < children.length) {
32
- const child = children[offset];
33
- if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
34
- oneOrMore = true;
35
- } else if (child.type === "text" && child.value.trim().length === 0) {
36
- } else {
37
- all = false;
38
- break;
39
- }
40
- }
41
- if (all && oneOrMore) {
42
- offset = -1;
43
- const newChildren = [];
44
- while (++offset < children.length) {
45
- const child = children[offset];
46
- if (child.type === "mdxJsxTextElement") {
47
- child.type = "mdxJsxFlowElement";
48
- }
49
- if (child.type === "mdxTextExpression") {
50
- child.type = "mdxFlowExpression";
51
- }
52
- if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
53
- } else {
54
- newChildren.push(child);
55
- }
56
- }
57
- parent.children.splice(index, 1, ...newChildren);
58
- return index;
59
- }
60
- }
61
- });
62
- };
63
- }
64
-
65
- // src/collections/mdx/mdast-utils.ts
66
- function flattenNode(node) {
67
- if ("children" in node)
68
- return node.children.map((child) => flattenNode(child)).join("");
69
- if ("value" in node) return node.value;
70
- return "";
71
- }
72
-
73
- // src/collections/mdx/remark-include.ts
74
- var ElementLikeTypes = [
75
- "mdxJsxFlowElement",
76
- "mdxJsxTextElement",
77
- "containerDirective",
78
- "textDirective",
79
- "leafDirective"
80
- ];
81
- function isElementLike(node) {
82
- return ElementLikeTypes.includes(node.type);
83
- }
84
- function parseElementAttributes(element) {
85
- if (Array.isArray(element.attributes)) {
86
- const attributes = {};
87
- for (const attr of element.attributes) {
88
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
89
- attributes[attr.name] = attr.value;
90
- }
91
- }
92
- return attributes;
93
- }
94
- return element.attributes ?? {};
95
- }
96
- function parseSpecifier(specifier) {
97
- const idx = specifier.lastIndexOf("#");
98
- if (idx === -1) return { file: specifier };
99
- return {
100
- file: specifier.slice(0, idx),
101
- section: specifier.slice(idx + 1)
102
- };
103
- }
104
- function extractSection(root, section) {
105
- let nodes;
106
- let capturingHeadingContent = false;
107
- visit2(root, (node) => {
108
- if (node.type === "heading") {
109
- if (capturingHeadingContent) {
110
- return false;
111
- }
112
- if (node.data?.hProperties?.id === section) {
113
- capturingHeadingContent = true;
114
- nodes = [node];
115
- return "skip";
116
- }
117
- return;
118
- }
119
- if (capturingHeadingContent) {
120
- nodes?.push(node);
121
- return "skip";
122
- }
123
- if (isElementLike(node) && node.name === "section") {
124
- const attributes = parseElementAttributes(node);
125
- if (attributes.id === section) {
126
- nodes = node.children;
127
- return false;
128
- }
129
- }
130
- });
131
- if (nodes)
132
- return {
133
- type: "root",
134
- children: nodes
135
- };
136
- }
137
- function remarkInclude({ preprocess = [] } = {}) {
138
- const TagName = "include";
139
- const preprocessor = unified().use(remarkMarkAndUnravel).use(preprocess);
140
- const embedContent = async (targetPath, heading, params, parent) => {
141
- const { _getProcessor = () => this, _compiler } = parent.data;
142
- let content;
143
- try {
144
- content = (await fs.readFile(targetPath)).toString();
145
- } catch (e) {
146
- throw new Error(
147
- `failed to read file ${targetPath}
148
- ${e instanceof Error ? e.message : String(e)}`,
149
- { cause: e }
150
- );
151
- }
152
- const ext = path.extname(targetPath);
153
- _compiler?.addDependency(targetPath);
154
- if (params.lang || ext !== ".md" && ext !== ".mdx") {
155
- const lang = params.lang ?? ext.slice(1);
156
- return {
157
- type: "code",
158
- lang,
159
- meta: params.meta,
160
- value: content,
161
- data: {}
162
- };
163
- }
164
- const parser = await _getProcessor(ext === ".mdx" ? "mdx" : "md");
165
- const parsed = fumaMatter(content);
166
- const targetFile = new VFile({
167
- path: targetPath,
168
- value: parsed.content,
169
- data: {
170
- ...parent.data,
171
- frontmatter: parsed.data
172
- }
173
- });
174
- let mdast = await preprocessor.run(
175
- parser.parse(targetFile),
176
- targetFile
177
- );
178
- if (heading) {
179
- const extracted = extractSection(mdast, heading);
180
- if (!extracted)
181
- throw new Error(
182
- `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.`
183
- );
184
- mdast = extracted;
185
- }
186
- await update(mdast, targetFile);
187
- return mdast;
188
- };
189
- async function update(tree, file) {
190
- const queue = [];
191
- visit2(tree, ElementLikeTypes, (_node, _, parent) => {
192
- const node = _node;
193
- if (node.name !== TagName) return;
194
- const specifier = flattenNode(node);
195
- if (specifier.length === 0) return "skip";
196
- const attributes = parseElementAttributes(node);
197
- const { file: relativePath, section } = parseSpecifier(specifier);
198
- const targetPath = path.resolve(
199
- "cwd" in attributes ? file.cwd : file.dirname ?? "",
200
- relativePath
201
- );
202
- queue.push(
203
- embedContent(targetPath, section, attributes, file).then((replace) => {
204
- Object.assign(
205
- parent && parent.type === "paragraph" ? parent : node,
206
- replace
207
- );
208
- })
209
- );
210
- return "skip";
211
- });
212
- await Promise.all(queue);
213
- }
214
- return async (tree, file) => {
215
- await update(tree, file);
216
- };
217
- }
218
-
219
- // src/collections/mdx/remark-postprocess.ts
220
- import { visit as visit3 } from "unist-util-visit";
221
- import { toMarkdown } from "mdast-util-to-markdown";
222
- import { valueToEstree } from "estree-util-value-to-estree";
223
- import { removePosition } from "unist-util-remove-position";
224
- import remarkMdx from "remark-mdx";
225
- function remarkPostprocess({
226
- _format,
227
- includeProcessedMarkdown = false,
228
- includeMDAST = false,
229
- extractLinkReferences = false,
230
- valueToExport = []
231
- }) {
232
- let _stringifyProcessor;
233
- const getStringifyProcessor = () => {
234
- return _stringifyProcessor ??= _format === "mdx" ? this : (
235
- // force Markdown processor to stringify MDX nodes
236
- this().use(remarkMdx).freeze()
237
- );
238
- };
239
- return (tree, file) => {
240
- const frontmatter = file.data.frontmatter ??= {};
241
- if (!frontmatter.title) {
242
- visit3(tree, "heading", (node) => {
243
- if (node.depth === 1) {
244
- frontmatter.title = flattenNode(node);
245
- return false;
246
- }
247
- });
248
- }
249
- file.data["mdx-export"] ??= [];
250
- file.data["mdx-export"].push({
251
- name: "frontmatter",
252
- value: frontmatter
253
- });
254
- if (extractLinkReferences) {
255
- const urls = [];
256
- visit3(tree, "link", (node) => {
257
- urls.push({
258
- href: node.url
259
- });
260
- return "skip";
261
- });
262
- file.data["mdx-export"].push({
263
- name: "extractedReferences",
264
- value: urls
265
- });
266
- }
267
- if (includeProcessedMarkdown) {
268
- const processor = getStringifyProcessor();
269
- const markdown = toMarkdown(tree, {
270
- ...processor.data("settings"),
271
- // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
272
- extensions: processor.data("toMarkdownExtensions") || []
273
- });
274
- file.data["mdx-export"].push({
275
- name: "_markdown",
276
- value: markdown
277
- });
278
- }
279
- if (includeMDAST) {
280
- const options = includeMDAST === true ? {} : includeMDAST;
281
- const mdast = JSON.stringify(
282
- options.removePosition ? removePosition(structuredClone(tree)) : tree
283
- );
284
- file.data["mdx-export"].push({
285
- name: "_mdast",
286
- value: mdast
287
- });
288
- }
289
- for (const { name, value } of file.data["mdx-export"]) {
290
- tree.children.unshift(getMdastExport(name, value));
291
- }
292
- file.data["mdx-export"] = [];
293
- for (const name of valueToExport) {
294
- if (!(name in file.data)) continue;
295
- tree.children.unshift(getMdastExport(name, file.data[name]));
296
- }
297
- };
298
- }
299
- function getMdastExport(name, value) {
300
- return {
301
- type: "mdxjsEsm",
302
- value: "",
303
- data: {
304
- estree: {
305
- type: "Program",
306
- sourceType: "module",
307
- body: [
308
- {
309
- type: "ExportNamedDeclaration",
310
- specifiers: [],
311
- attributes: [],
312
- source: null,
313
- declaration: {
314
- type: "VariableDeclaration",
315
- kind: "let",
316
- declarations: [
317
- {
318
- type: "VariableDeclarator",
319
- id: {
320
- type: "Identifier",
321
- name
322
- },
323
- init: valueToEstree(value)
324
- }
325
- ]
326
- }
327
- }
328
- ]
329
- }
330
- }
331
- };
332
- }
333
-
334
- // src/collections/mdx/remark-preprocess.ts
335
- function remarkPreprocess(options) {
336
- return async (tree, file) => {
337
- if (file.data._preprocessed) return;
338
- file.data._preprocessed = true;
339
- if (options?.preprocessor) {
340
- return await options.preprocessor.run(tree);
341
- }
342
- };
343
- }
344
-
345
- // src/collections/mdx/build-mdx.ts
346
- async function buildMDX(core, collection, {
347
- filePath,
348
- frontmatter,
349
- source,
350
- _compiler,
351
- environment,
352
- isDevelopment
353
- }) {
354
- const handler = collection?.handlers.mdx;
355
- const processorCache = createCache(core.cache);
356
- function getProcessor(format) {
357
- const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
358
- return processorCache.cached(key, async () => {
359
- const mdxOptions = await handler?.getMDXOptions?.(environment);
360
- const preprocessPlugin = [
361
- remarkPreprocess,
362
- handler?.preprocess
363
- ];
364
- const postprocessOptions = {
365
- _format: format,
366
- ...handler?.postprocess
367
- };
368
- const remarkIncludeOptions = {
369
- preprocess: [preprocessPlugin]
370
- };
371
- return createProcessor({
372
- outputFormat: "program",
373
- development: isDevelopment,
374
- ...mdxOptions,
375
- remarkPlugins: [
376
- preprocessPlugin,
377
- [remarkInclude, remarkIncludeOptions],
378
- ...mdxOptions?.remarkPlugins ?? [],
379
- [remarkPostprocess, postprocessOptions]
380
- ],
381
- format
382
- });
383
- });
384
- }
385
- let vfile = new VFile2({
386
- value: source,
387
- path: filePath,
388
- cwd: handler?.cwd,
389
- data: {
390
- frontmatter,
391
- _compiler,
392
- _getProcessor: getProcessor
393
- }
394
- });
395
- if (collection && handler?.vfile) {
396
- vfile = await handler.vfile.call(
397
- {
398
- collection,
399
- filePath,
400
- source
401
- },
402
- vfile
403
- );
404
- }
405
- return (await getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md")).process(
406
- vfile
407
- );
408
- }
409
-
410
- export {
411
- buildMDX
412
- };
@@ -1,45 +0,0 @@
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
- };
@@ -1,85 +0,0 @@
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
- };
@@ -1,37 +0,0 @@
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
- };
@@ -1,19 +0,0 @@
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
- };
@@ -1,44 +0,0 @@
1
- // src/config/build.ts
2
- function buildConfig(config, workspace) {
3
- const collections = /* @__PURE__ */ new Map();
4
- const loaded = {};
5
- let globalConfig;
6
- if ("default" in config) {
7
- globalConfig = config.default;
8
- for (const [k, v] of Object.entries(config)) {
9
- if (k === "default") continue;
10
- globalConfig.collections ??= {};
11
- globalConfig.collections[k] = v;
12
- }
13
- } else {
14
- globalConfig = config;
15
- }
16
- if (globalConfig.collections) {
17
- for (const [name, collection] of Object.entries(globalConfig.collections)) {
18
- collection.init?.({ name, workspace });
19
- collections.set(name, collection);
20
- }
21
- }
22
- return {
23
- ...globalConfig,
24
- collections,
25
- workspaces: Object.fromEntries(
26
- Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
27
- return [
28
- key,
29
- {
30
- dir: value.dir,
31
- config: buildConfig(value.config, {
32
- ...value,
33
- name: key
34
- })
35
- }
36
- ];
37
- })
38
- )
39
- };
40
- }
41
-
42
- export {
43
- buildConfig
44
- };
@@ -1,50 +0,0 @@
1
- import {
2
- ValidationError
3
- } from "./chunk-OUJENWQ4.js";
4
- import {
5
- Core
6
- } from "./chunk-NRZ4GE5O.js";
7
-
8
- // src/plugins/with-loader/webpack.ts
9
- import { parse } from "querystring";
10
- import path from "path";
11
- var core;
12
- function getCore(options) {
13
- return core ??= new Core({
14
- outDir: options.outDir,
15
- configPath: options.configPath
16
- });
17
- }
18
- function toWebpack(loader) {
19
- return async function(source, callback) {
20
- try {
21
- const result = await loader.load({
22
- filePath: this.resourcePath,
23
- query: parse(this.resourceQuery.slice(1)),
24
- getSource() {
25
- return source;
26
- },
27
- development: this.mode === "development",
28
- compiler: this
29
- });
30
- if (result === null) {
31
- callback(void 0, source);
32
- } else {
33
- callback(void 0, result.code, result.map);
34
- }
35
- } catch (error) {
36
- if (error instanceof ValidationError) {
37
- return callback(new Error(await error.toStringFormatted()));
38
- }
39
- if (!(error instanceof Error)) throw error;
40
- const fpath = path.relative(this.context, this.resourcePath);
41
- error.message = `${fpath}:${error.name}: ${error.message}`;
42
- callback(error);
43
- }
44
- };
45
- }
46
-
47
- export {
48
- getCore,
49
- toWebpack
50
- };