fuma-content 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/dist/{async-cache-C0J_pTbk.js → async-cache-U87GzQTb.js} +1 -1
  2. package/dist/{async-cache-C0J_pTbk.js.map → async-cache-U87GzQTb.js.map} +1 -1
  3. package/dist/{build-mdx-DugsQ0sk.js → build-mdx-BZxE8t2a.js} +14 -9
  4. package/dist/build-mdx-BZxE8t2a.js.map +1 -0
  5. package/dist/build-mdx-LhpFasX-.js +4 -0
  6. package/dist/bun/index.d.ts +7 -4
  7. package/dist/bun/index.d.ts.map +1 -1
  8. package/dist/bun/index.js +25 -14
  9. package/dist/bun/index.js.map +1 -1
  10. package/dist/{bun-Br1ReMiq.js → bun-CBROq3I0.js} +2 -2
  11. package/dist/bun-CBROq3I0.js.map +1 -0
  12. package/dist/code-generator-CjC4EEXg.js +102 -0
  13. package/dist/code-generator-CjC4EEXg.js.map +1 -0
  14. package/dist/collections/data/runtime.d.ts +15 -0
  15. package/dist/collections/data/runtime.d.ts.map +1 -0
  16. package/dist/collections/{meta → data}/runtime.js +4 -4
  17. package/dist/collections/data/runtime.js.map +1 -0
  18. package/dist/collections/data.d.ts +47 -0
  19. package/dist/collections/data.d.ts.map +1 -0
  20. package/dist/collections/data.js +5 -0
  21. package/dist/collections/fs.d.ts +3 -0
  22. package/dist/collections/fs.js +3 -0
  23. package/dist/collections/index.d.ts +2 -2
  24. package/dist/collections/index.js +2 -15
  25. package/dist/collections/json/loader-webpack.d.ts +9 -0
  26. package/dist/collections/json/loader-webpack.d.ts.map +1 -0
  27. package/dist/collections/json/loader-webpack.js +15 -0
  28. package/dist/collections/json/loader-webpack.js.map +1 -0
  29. package/dist/collections/mdx/loader-webpack.d.ts +5 -5
  30. package/dist/collections/mdx/loader-webpack.d.ts.map +1 -1
  31. package/dist/collections/mdx/loader-webpack.js +11 -21
  32. package/dist/collections/mdx/loader-webpack.js.map +1 -1
  33. package/dist/collections/mdx/react.d.ts +22 -0
  34. package/dist/collections/mdx/react.d.ts.map +1 -0
  35. package/dist/collections/mdx/react.js +35 -0
  36. package/dist/collections/mdx/react.js.map +1 -0
  37. package/dist/collections/mdx/runtime-browser.d.ts +11 -45
  38. package/dist/collections/mdx/runtime-browser.js +6 -44
  39. package/dist/collections/mdx/runtime-browser.js.map +1 -1
  40. package/dist/collections/mdx/runtime-dynamic.d.ts +16 -28
  41. package/dist/collections/mdx/runtime-dynamic.d.ts.map +1 -1
  42. package/dist/collections/mdx/runtime-dynamic.js +17 -20
  43. package/dist/collections/mdx/runtime-dynamic.js.map +1 -1
  44. package/dist/collections/mdx/runtime.d.ts +10 -49
  45. package/dist/collections/mdx/runtime.js +2 -11
  46. package/dist/collections/mdx/runtime.js.map +1 -1
  47. package/dist/collections/mdx.d.ts +6 -2
  48. package/dist/collections/mdx.js +6 -247
  49. package/dist/collections/runtime/file-store.d.ts +4 -22
  50. package/dist/collections/runtime/file-store.js +15 -14
  51. package/dist/collections/runtime/file-store.js.map +1 -1
  52. package/dist/collections/runtime/store.d.ts +3 -3
  53. package/dist/collections/runtime/store.js +2 -2
  54. package/dist/collections/yaml/loader-webpack.d.ts +9 -0
  55. package/dist/collections/yaml/loader-webpack.d.ts.map +1 -0
  56. package/dist/collections/yaml/loader-webpack.js +15 -0
  57. package/dist/collections/yaml/loader-webpack.js.map +1 -0
  58. package/dist/collections-DNFRdCuB.js +98 -0
  59. package/dist/collections-DNFRdCuB.js.map +1 -0
  60. package/dist/config/index.d.ts +1 -1
  61. package/dist/config/index.js.map +1 -1
  62. package/dist/core-BO3b8jMg.d.ts +313 -0
  63. package/dist/core-BO3b8jMg.d.ts.map +1 -0
  64. package/dist/{core-CnZQDCJ1.js → core-D5QHSKk6.js} +65 -47
  65. package/dist/core-D5QHSKk6.js.map +1 -0
  66. package/dist/data-9h98oZwj.js +158 -0
  67. package/dist/data-9h98oZwj.js.map +1 -0
  68. package/dist/dynamic-CTYYdl7_.d.ts +33 -0
  69. package/dist/dynamic-CTYYdl7_.d.ts.map +1 -0
  70. package/dist/dynamic-DhKTOrIl.js +29 -0
  71. package/dist/dynamic-DhKTOrIl.js.map +1 -0
  72. package/dist/dynamic.d.ts +3 -24
  73. package/dist/dynamic.js +2 -27
  74. package/dist/file-store-laO4IjvB.d.ts +21 -0
  75. package/dist/file-store-laO4IjvB.d.ts.map +1 -0
  76. package/dist/fs-D34Sztbh.d.ts +44 -0
  77. package/dist/fs-D34Sztbh.d.ts.map +1 -0
  78. package/dist/fs-WWbLA7Gx.js +66 -0
  79. package/dist/fs-WWbLA7Gx.js.map +1 -0
  80. package/dist/{fuma-matter-D3kkMkdj.js → fuma-matter-BuBO2w-p.js} +1 -1
  81. package/dist/{fuma-matter-D3kkMkdj.js.map → fuma-matter-BuBO2w-p.js.map} +1 -1
  82. package/dist/git-2CjUW3M5.d.ts +37 -0
  83. package/dist/git-2CjUW3M5.d.ts.map +1 -0
  84. package/dist/git-CQWA37-X.js +60 -0
  85. package/dist/git-CQWA37-X.js.map +1 -0
  86. package/dist/index-Da88Sj8w.d.ts +87 -0
  87. package/dist/index-Da88Sj8w.d.ts.map +1 -0
  88. package/dist/index.d.ts +2 -2
  89. package/dist/index.js +4 -5
  90. package/dist/load-from-file-BZxc_BhC.js +3 -0
  91. package/dist/{load-from-file-XiM8eZha.js → load-from-file-irx0JI6j.js} +4 -6
  92. package/dist/load-from-file-irx0JI6j.js.map +1 -0
  93. package/dist/loader-AIEwGc2f.js +9 -0
  94. package/dist/loader-BhXHF8vy.js +16 -0
  95. package/dist/loader-BhXHF8vy.js.map +1 -0
  96. package/dist/loader-BuR4gkKg.js +77 -0
  97. package/dist/loader-BuR4gkKg.js.map +1 -0
  98. package/dist/loader-BzQpSBvP.js +59 -0
  99. package/dist/loader-BzQpSBvP.js.map +1 -0
  100. package/dist/{loader-C7W_Rwj8.js → loader-D6StkShK.js} +7 -6
  101. package/dist/loader-D6StkShK.js.map +1 -0
  102. package/dist/loader-DCK4RwOh.js +8 -0
  103. package/dist/loader-DwpOcxgh.js +17 -0
  104. package/dist/loader-DwpOcxgh.js.map +1 -0
  105. package/dist/loader-zsTVgQjO.js +8 -0
  106. package/dist/mdx-Dt9hirUu.d.ts +144 -0
  107. package/dist/mdx-Dt9hirUu.d.ts.map +1 -0
  108. package/dist/mdx-iZ2uP27Z.js +303 -0
  109. package/dist/mdx-iZ2uP27Z.js.map +1 -0
  110. package/dist/next/index.d.ts +6 -10
  111. package/dist/next/index.d.ts.map +1 -1
  112. package/dist/next/index.js +20 -28
  113. package/dist/next/index.js.map +1 -1
  114. package/dist/node/index.d.ts +8 -0
  115. package/dist/node/index.d.ts.map +1 -0
  116. package/dist/node/index.js +10 -0
  117. package/dist/node/index.js.map +1 -0
  118. package/dist/node/loader.d.ts +5 -2
  119. package/dist/node/loader.d.ts.map +1 -1
  120. package/dist/node/loader.js +17 -11
  121. package/dist/node/loader.js.map +1 -1
  122. package/dist/{node-CVAU22o3.js → node-2VZOh3P9.js} +7 -5
  123. package/dist/node-2VZOh3P9.js.map +1 -0
  124. package/dist/plugins/git.d.ts +3 -2
  125. package/dist/plugins/git.js +2 -61
  126. package/dist/plugins/json-schema.d.ts +26 -2
  127. package/dist/plugins/json-schema.d.ts.map +1 -0
  128. package/dist/plugins/json-schema.js +41 -50
  129. package/dist/plugins/json-schema.js.map +1 -1
  130. package/dist/plugins/loader/index.d.ts +4 -0
  131. package/dist/plugins/loader/index.js +3 -0
  132. package/dist/plugins/loader/webpack.d.ts +4 -0
  133. package/dist/plugins/loader/webpack.js +60 -0
  134. package/dist/plugins/loader/webpack.js.map +1 -0
  135. package/dist/runtime-HN-HSB0Z.d.ts +31 -0
  136. package/dist/runtime-HN-HSB0Z.d.ts.map +1 -0
  137. package/dist/runtime-browser-BQEk7qjc.d.ts +29 -0
  138. package/dist/runtime-browser-BQEk7qjc.d.ts.map +1 -0
  139. package/dist/store-DiuGdV5M.d.ts +31 -0
  140. package/dist/store-DiuGdV5M.d.ts.map +1 -0
  141. package/dist/{store-D166MOLw.js → store-IvpEBdxi.js} +4 -4
  142. package/dist/store-IvpEBdxi.js.map +1 -0
  143. package/dist/{validation-BYUzZIfc.js → validation-BvVvvLII.js} +1 -1
  144. package/dist/{validation-BYUzZIfc.js.map → validation-BvVvvLII.js.map} +1 -1
  145. package/dist/vite/index.d.ts +5 -15
  146. package/dist/vite/index.d.ts.map +1 -1
  147. package/dist/vite/index.js +18 -21
  148. package/dist/vite/index.js.map +1 -1
  149. package/dist/{vite-6awgG092.js → vite-C1qXY47G.js} +2 -2
  150. package/dist/vite-C1qXY47G.js.map +1 -0
  151. package/package.json +19 -18
  152. package/dist/build-mdx-CSrSOQxF.js +0 -4
  153. package/dist/build-mdx-DugsQ0sk.js.map +0 -1
  154. package/dist/bun-Br1ReMiq.js.map +0 -1
  155. package/dist/code-generator-BvuyL0UO.js +0 -133
  156. package/dist/code-generator-BvuyL0UO.js.map +0 -1
  157. package/dist/collections/handlers/fs.d.ts +0 -2
  158. package/dist/collections/handlers/fs.js +0 -31
  159. package/dist/collections/handlers/fs.js.map +0 -1
  160. package/dist/collections/index.js.map +0 -1
  161. package/dist/collections/mdx/runtime-browser.d.ts.map +0 -1
  162. package/dist/collections/mdx/runtime.d.ts.map +0 -1
  163. package/dist/collections/mdx.js.map +0 -1
  164. package/dist/collections/meta/loader-webpack.d.ts +0 -9
  165. package/dist/collections/meta/loader-webpack.d.ts.map +0 -1
  166. package/dist/collections/meta/loader-webpack.js +0 -25
  167. package/dist/collections/meta/loader-webpack.js.map +0 -1
  168. package/dist/collections/meta/runtime.d.ts +0 -11
  169. package/dist/collections/meta/runtime.d.ts.map +0 -1
  170. package/dist/collections/meta/runtime.js.map +0 -1
  171. package/dist/collections/meta.d.ts +0 -2
  172. package/dist/collections/meta.js +0 -131
  173. package/dist/collections/meta.js.map +0 -1
  174. package/dist/collections/runtime/file-store.d.ts.map +0 -1
  175. package/dist/core-CRWvbE7W.d.ts +0 -588
  176. package/dist/core-CRWvbE7W.d.ts.map +0 -1
  177. package/dist/core-CnZQDCJ1.js.map +0 -1
  178. package/dist/dynamic.d.ts.map +0 -1
  179. package/dist/dynamic.js.map +0 -1
  180. package/dist/load-from-file-BctwhOUd.js +0 -3
  181. package/dist/load-from-file-XiM8eZha.js.map +0 -1
  182. package/dist/loader-BHMDOncZ.js +0 -4
  183. package/dist/loader-C7W_Rwj8.js.map +0 -1
  184. package/dist/loader-DLSJPUiO.js +0 -69
  185. package/dist/loader-DLSJPUiO.js.map +0 -1
  186. package/dist/loader-DkmGoUvo.js +0 -4
  187. package/dist/next/index.cjs +0 -497
  188. package/dist/node-CVAU22o3.js.map +0 -1
  189. package/dist/pipe-UEMV1mRg.js +0 -31
  190. package/dist/pipe-UEMV1mRg.js.map +0 -1
  191. package/dist/plugins/git.js.map +0 -1
  192. package/dist/plugins/with-loader/index.d.ts +0 -2
  193. package/dist/plugins/with-loader/index.js +0 -28
  194. package/dist/plugins/with-loader/index.js.map +0 -1
  195. package/dist/plugins/with-loader/webpack.d.ts +0 -19
  196. package/dist/plugins/with-loader/webpack.d.ts.map +0 -1
  197. package/dist/plugins/with-loader/webpack.js +0 -43
  198. package/dist/plugins/with-loader/webpack.js.map +0 -1
  199. package/dist/store-BtGmZUAC.d.ts +0 -31
  200. package/dist/store-BtGmZUAC.d.ts.map +0 -1
  201. package/dist/store-D166MOLw.js.map +0 -1
  202. package/dist/vite-6awgG092.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader-C7W_Rwj8.js","names":["after: (() => Promise<void>) | undefined"],"sources":["../src/collections/mdx/loader.ts"],"sourcesContent":["import { fumaMatter } from \"@/collections/mdx/fuma-matter\";\nimport type { SourceMap } from \"rollup\";\nimport { z } from \"zod\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createHash } from \"node:crypto\";\nimport type { Loader } from \"@/plugins/with-loader\";\nimport type { DynamicCore } from \"@/dynamic\";\n\nconst querySchema = z\n .object({\n only: z.literal([\"frontmatter\", \"all\"]).default(\"all\"),\n collection: z.string().optional(),\n workspace: z.string().optional(),\n })\n .loose();\n\nconst cacheEntry = z.object({\n code: z.string(),\n map: z.any().optional(),\n hash: z.string().optional(),\n});\n\ntype CacheEntry = z.infer<typeof cacheEntry>;\n\nexport function createMdxLoader({ getCore }: DynamicCore): Loader {\n return {\n async load({ getSource, development: isDevelopment, query, compiler, filePath }) {\n let core = await getCore();\n const value = await getSource();\n const matter = fumaMatter(value);\n const { collection: collectionName, workspace, only } = querySchema.parse(query);\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n let after: (() => Promise<void>) | undefined;\n\n const { experimentalBuildCache = false } = core.getConfig();\n if (!isDevelopment && experimentalBuildCache) {\n const cacheDir = experimentalBuildCache;\n const cacheKey = `${collectionName ?? \"global\"}_${generateCacheHash(filePath)}`;\n\n const cached = await fs\n .readFile(path.join(cacheDir, cacheKey))\n .then((content) => cacheEntry.parse(JSON.parse(content.toString())))\n .catch(() => null);\n\n if (cached && cached.hash === generateCacheHash(value)) return cached;\n after = async () => {\n await fs.mkdir(cacheDir, { recursive: true });\n await fs.writeFile(\n path.join(cacheDir, cacheKey),\n JSON.stringify({\n ...out,\n hash: generateCacheHash(value),\n } satisfies CacheEntry),\n );\n };\n }\n\n const collection = collectionName ? core.getCollection(collectionName) : undefined;\n const handler = collection?.handlers.mdx;\n\n if (collection && handler?.frontmatter) {\n matter.data = await handler.frontmatter.run(matter.data as Record<string, unknown>, {\n collection,\n filePath,\n source: value,\n });\n }\n\n if (only === \"frontmatter\") {\n return {\n code: `export const frontmatter = ${JSON.stringify(matter.data)}`,\n map: null,\n };\n }\n\n // ensure the line number is correct in dev mode\n const lineOffset = isDevelopment ? countLines(matter.matter) : 0;\n\n const { buildMDX } = await import(\"@/collections/mdx/build-mdx\");\n const compiled = await buildMDX(core, collection, {\n isDevelopment,\n source: \"\\n\".repeat(lineOffset) + matter.content,\n filePath,\n frontmatter: matter.data as Record<string, unknown>,\n _compiler: compiler,\n environment: \"bundler\",\n });\n\n const out = {\n code: String(compiled.value),\n map: compiled.map as SourceMap,\n };\n\n await after?.();\n return out;\n },\n };\n}\n\nfunction generateCacheHash(input: string): string {\n return createHash(\"md5\").update(input).digest(\"hex\");\n}\n\nfunction countLines(s: string) {\n let num = 0;\n\n for (const c of s) {\n if (c === \"\\n\") num++;\n }\n\n return num;\n}\n"],"mappings":";;;;;;;AASA,MAAM,cAAc,EACjB,OAAO;CACN,MAAM,EAAE,QAAQ,CAAC,eAAe,MAAM,CAAC,CAAC,QAAQ,MAAM;CACtD,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC,CACD,OAAO;AAEV,MAAM,aAAa,EAAE,OAAO;CAC1B,MAAM,EAAE,QAAQ;CAChB,KAAK,EAAE,KAAK,CAAC,UAAU;CACvB,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC5B,CAAC;AAIF,SAAgB,gBAAgB,EAAE,WAAgC;AAChE,QAAO,EACL,MAAM,KAAK,EAAE,WAAW,aAAa,eAAe,OAAO,UAAU,YAAY;EAC/E,IAAI,OAAO,MAAM,SAAS;EAC1B,MAAM,QAAQ,MAAM,WAAW;EAC/B,MAAM,SAAS,WAAW,MAAM;EAChC,MAAM,EAAE,YAAY,gBAAgB,WAAW,SAAS,YAAY,MAAM,MAAM;AAChF,MAAI,UACF,QAAO,KAAK,eAAe,CAAC,IAAI,UAAU,IAAI;EAGhD,IAAIA;EAEJ,MAAM,EAAE,yBAAyB,UAAU,KAAK,WAAW;AAC3D,MAAI,CAAC,iBAAiB,wBAAwB;GAC5C,MAAM,WAAW;GACjB,MAAM,WAAW,GAAG,kBAAkB,SAAS,GAAG,kBAAkB,SAAS;GAE7E,MAAM,SAAS,MAAM,GAClB,SAAS,KAAK,KAAK,UAAU,SAAS,CAAC,CACvC,MAAM,YAAY,WAAW,MAAM,KAAK,MAAM,QAAQ,UAAU,CAAC,CAAC,CAAC,CACnE,YAAY,KAAK;AAEpB,OAAI,UAAU,OAAO,SAAS,kBAAkB,MAAM,CAAE,QAAO;AAC/D,WAAQ,YAAY;AAClB,UAAM,GAAG,MAAM,UAAU,EAAE,WAAW,MAAM,CAAC;AAC7C,UAAM,GAAG,UACP,KAAK,KAAK,UAAU,SAAS,EAC7B,KAAK,UAAU;KACb,GAAG;KACH,MAAM,kBAAkB,MAAM;KAC/B,CAAsB,CACxB;;;EAIL,MAAM,aAAa,iBAAiB,KAAK,cAAc,eAAe,GAAG;EACzE,MAAM,UAAU,YAAY,SAAS;AAErC,MAAI,cAAc,SAAS,YACzB,QAAO,OAAO,MAAM,QAAQ,YAAY,IAAI,OAAO,MAAiC;GAClF;GACA;GACA,QAAQ;GACT,CAAC;AAGJ,MAAI,SAAS,cACX,QAAO;GACL,MAAM,8BAA8B,KAAK,UAAU,OAAO,KAAK;GAC/D,KAAK;GACN;EAIH,MAAM,aAAa,gBAAgB,WAAW,OAAO,OAAO,GAAG;EAE/D,MAAM,EAAE,aAAa,MAAM,OAAO;EAClC,MAAM,WAAW,MAAM,SAAS,MAAM,YAAY;GAChD;GACA,QAAQ,KAAK,OAAO,WAAW,GAAG,OAAO;GACzC;GACA,aAAa,OAAO;GACpB,WAAW;GACX,aAAa;GACd,CAAC;EAEF,MAAM,MAAM;GACV,MAAM,OAAO,SAAS,MAAM;GAC5B,KAAK,SAAS;GACf;AAED,QAAM,SAAS;AACf,SAAO;IAEV;;AAGH,SAAS,kBAAkB,OAAuB;AAChD,QAAO,WAAW,MAAM,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGtD,SAAS,WAAW,GAAW;CAC7B,IAAI,MAAM;AAEV,MAAK,MAAM,KAAK,EACd,KAAI,MAAM,KAAM;AAGlB,QAAO"}
@@ -1,69 +0,0 @@
1
- import { r as validate } from "./validation-BYUzZIfc.js";
2
- import { load } from "js-yaml";
3
- import { z } from "zod";
4
-
5
- //#region src/collections/meta/loader.ts
6
- const querySchema = z.object({
7
- collection: z.string().optional(),
8
- workspace: z.string().optional()
9
- }).loose();
10
- /**
11
- * load meta files, fallback to bundler's built-in plugins when ?collection is unspecified.
12
- */
13
- function createMetaLoader({ getCore }, resolve = {}) {
14
- const { json: resolveJson = "js" } = resolve;
15
- function parse(filePath, source) {
16
- try {
17
- if (filePath.endsWith(".json")) return JSON.parse(source);
18
- if (filePath.endsWith(".yaml")) return load(source);
19
- } catch (e) {
20
- throw new Error(`invalid data in ${filePath}`, { cause: e });
21
- }
22
- throw new Error(`Unknown file type ${filePath}`);
23
- }
24
- function onMeta(source, { filePath, query }) {
25
- const parsed = querySchema.safeParse(query);
26
- if (!parsed.success || !parsed.data.collection) return null;
27
- const { collection: collectionName, workspace } = parsed.data;
28
- return async () => {
29
- let core = await getCore();
30
- if (workspace) core = core.getWorkspaces().get(workspace) ?? core;
31
- const handler = core.getCollection(collectionName)?.handlers.meta;
32
- let data = parse(filePath, source);
33
- if (!handler) return data;
34
- const context = {
35
- path: filePath,
36
- source
37
- };
38
- if (handler.schema) data = await validate(handler.schema, data, context, `invalid data in ${filePath}`);
39
- return handler.transform.run(data, context);
40
- };
41
- }
42
- return {
43
- async load(input) {
44
- const result = onMeta(await input.getSource(), input);
45
- if (result === null) return null;
46
- const data = await result();
47
- if (input.filePath.endsWith(".json")) return {
48
- code: resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`,
49
- moduleType: resolveJson
50
- };
51
- else return { code: `export default ${JSON.stringify(data)}` };
52
- },
53
- bun: { load(source, input) {
54
- const result = onMeta(source, input);
55
- if (result === null) return {
56
- loader: "object",
57
- exports: parse(input.filePath, source)
58
- };
59
- return result().then((data) => ({
60
- loader: "object",
61
- exports: { default: data }
62
- }));
63
- } }
64
- };
65
- }
66
-
67
- //#endregion
68
- export { createMetaLoader as t };
69
- //# sourceMappingURL=loader-DLSJPUiO.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader-DLSJPUiO.js","names":["data: unknown","context: MetaTransformationContext"],"sources":["../src/collections/meta/loader.ts"],"sourcesContent":["import type { Loader, LoaderInput } from \"@/plugins/with-loader\";\nimport { load } from \"js-yaml\";\nimport { z } from \"zod\";\nimport { validate } from \"@/utils/validation\";\nimport type { MetaTransformationContext } from \"@/collections/meta\";\nimport type { DynamicCore } from \"@/dynamic\";\n\nconst querySchema = z\n .object({\n collection: z.string().optional(),\n workspace: z.string().optional(),\n })\n .loose();\n\n/**\n * load meta files, fallback to bundler's built-in plugins when ?collection is unspecified.\n */\nexport function createMetaLoader(\n { getCore }: DynamicCore,\n resolve: {\n json?: \"json\" | \"js\";\n } = {},\n): Loader {\n const { json: resolveJson = \"js\" } = resolve;\n\n function parse(filePath: string, source: string) {\n try {\n if (filePath.endsWith(\".json\")) return JSON.parse(source);\n if (filePath.endsWith(\".yaml\")) return load(source);\n } catch (e) {\n throw new Error(`invalid data in ${filePath}`, { cause: e });\n }\n\n throw new Error(`Unknown file type ${filePath}`);\n }\n\n function onMeta(source: string, { filePath, query }: LoaderInput) {\n const parsed = querySchema.safeParse(query);\n if (!parsed.success || !parsed.data.collection) return null;\n const { collection: collectionName, workspace } = parsed.data;\n\n return async (): Promise<unknown> => {\n let core = await getCore();\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n const collection = core.getCollection(collectionName);\n const handler = collection?.handlers.meta;\n let data: unknown = parse(filePath, source);\n if (!handler) return data;\n\n const context: MetaTransformationContext = {\n path: filePath,\n source,\n };\n\n if (handler.schema) {\n data = await validate(handler.schema, data, context, `invalid data in ${filePath}`);\n }\n\n return handler.transform.run(data, context);\n };\n }\n\n return {\n async load(input) {\n const result = onMeta(await input.getSource(), input);\n if (result === null) return null;\n const data = await result();\n\n if (input.filePath.endsWith(\".json\")) {\n return {\n code:\n resolveJson === \"json\"\n ? JSON.stringify(data)\n : `export default ${JSON.stringify(data)}`,\n moduleType: resolveJson,\n };\n } else {\n return {\n code: `export default ${JSON.stringify(data)}`,\n };\n }\n },\n bun: {\n load(source, input) {\n const result = onMeta(source, input);\n if (result === null)\n return {\n loader: \"object\",\n exports: parse(input.filePath, source),\n };\n\n return result().then((data) => ({\n loader: \"object\",\n exports: { default: data },\n }));\n },\n },\n };\n}\n"],"mappings":";;;;;AAOA,MAAM,cAAc,EACjB,OAAO;CACN,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC,CACD,OAAO;;;;AAKV,SAAgB,iBACd,EAAE,WACF,UAEI,EAAE,EACE;CACR,MAAM,EAAE,MAAM,cAAc,SAAS;CAErC,SAAS,MAAM,UAAkB,QAAgB;AAC/C,MAAI;AACF,OAAI,SAAS,SAAS,QAAQ,CAAE,QAAO,KAAK,MAAM,OAAO;AACzD,OAAI,SAAS,SAAS,QAAQ,CAAE,QAAO,KAAK,OAAO;WAC5C,GAAG;AACV,SAAM,IAAI,MAAM,mBAAmB,YAAY,EAAE,OAAO,GAAG,CAAC;;AAG9D,QAAM,IAAI,MAAM,qBAAqB,WAAW;;CAGlD,SAAS,OAAO,QAAgB,EAAE,UAAU,SAAsB;EAChE,MAAM,SAAS,YAAY,UAAU,MAAM;AAC3C,MAAI,CAAC,OAAO,WAAW,CAAC,OAAO,KAAK,WAAY,QAAO;EACvD,MAAM,EAAE,YAAY,gBAAgB,cAAc,OAAO;AAEzD,SAAO,YAA8B;GACnC,IAAI,OAAO,MAAM,SAAS;AAC1B,OAAI,UACF,QAAO,KAAK,eAAe,CAAC,IAAI,UAAU,IAAI;GAIhD,MAAM,UADa,KAAK,cAAc,eAAe,EACzB,SAAS;GACrC,IAAIA,OAAgB,MAAM,UAAU,OAAO;AAC3C,OAAI,CAAC,QAAS,QAAO;GAErB,MAAMC,UAAqC;IACzC,MAAM;IACN;IACD;AAED,OAAI,QAAQ,OACV,QAAO,MAAM,SAAS,QAAQ,QAAQ,MAAM,SAAS,mBAAmB,WAAW;AAGrF,UAAO,QAAQ,UAAU,IAAI,MAAM,QAAQ;;;AAI/C,QAAO;EACL,MAAM,KAAK,OAAO;GAChB,MAAM,SAAS,OAAO,MAAM,MAAM,WAAW,EAAE,MAAM;AACrD,OAAI,WAAW,KAAM,QAAO;GAC5B,MAAM,OAAO,MAAM,QAAQ;AAE3B,OAAI,MAAM,SAAS,SAAS,QAAQ,CAClC,QAAO;IACL,MACE,gBAAgB,SACZ,KAAK,UAAU,KAAK,GACpB,kBAAkB,KAAK,UAAU,KAAK;IAC5C,YAAY;IACb;OAED,QAAO,EACL,MAAM,kBAAkB,KAAK,UAAU,KAAK,IAC7C;;EAGL,KAAK,EACH,KAAK,QAAQ,OAAO;GAClB,MAAM,SAAS,OAAO,QAAQ,MAAM;AACpC,OAAI,WAAW,KACb,QAAO;IACL,QAAQ;IACR,SAAS,MAAM,MAAM,UAAU,OAAO;IACvC;AAEH,UAAO,QAAQ,CAAC,MAAM,UAAU;IAC9B,QAAQ;IACR,SAAS,EAAE,SAAS,MAAM;IAC3B,EAAE;KAEN;EACF"}
@@ -1,4 +0,0 @@
1
- import "./fuma-matter-D3kkMkdj.js";
2
- import { t as createMdxLoader } from "./loader-C7W_Rwj8.js";
3
-
4
- export { createMdxLoader };
@@ -1,497 +0,0 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
-
27
- //#endregion
28
- let node_path = require("node:path");
29
- node_path = __toESM(node_path);
30
- let node_url = require("node:url");
31
- let node_fs_promises = require("node:fs/promises");
32
- node_fs_promises = __toESM(node_fs_promises);
33
- let tinyglobby = require("tinyglobby");
34
-
35
- //#region src/config/load-from-file.ts
36
- async function compileConfig(core) {
37
- const { build } = await import("esbuild");
38
- const { configPath, outDir } = core.getOptions();
39
- if ((await build({
40
- entryPoints: [{
41
- in: configPath,
42
- out: "content.config"
43
- }],
44
- bundle: true,
45
- outdir: outDir,
46
- target: "node20",
47
- write: true,
48
- platform: "node",
49
- format: "esm",
50
- packages: "external",
51
- outExtension: { ".js": ".mjs" },
52
- allowOverwrite: true
53
- })).errors.length > 0) throw new Error("failed to compile configuration file");
54
- }
55
- /**
56
- * Load config
57
- *
58
- * @param build - By default, it assumes the config file has been compiled. Set this `true` to compile the config first.
59
- */
60
- async function loadConfig(core, build = false) {
61
- if (build) await compileConfig(core);
62
- const url = (0, node_url.pathToFileURL)(core.getCompiledConfigPath());
63
- url.searchParams.set("hash", Date.now().toString());
64
- return import(url.href);
65
- }
66
-
67
- //#endregion
68
- //#region src/utils/async-cache.ts
69
- /**
70
- * cache for async resources, finished promises will be resolved into original value, otherwise wrapped with a promise.
71
- */
72
- function createCache(store = /* @__PURE__ */ new Map()) {
73
- return {
74
- cached(key, fn) {
75
- let cached = store.get(key);
76
- if (cached) return cached;
77
- cached = fn();
78
- if (cached instanceof Promise) cached = cached.then((out) => {
79
- if (store.has(key)) store.set(key, out);
80
- return out;
81
- });
82
- store.set(key, cached);
83
- return cached;
84
- },
85
- invalidate(key) {
86
- store.delete(key);
87
- },
88
- $value() {
89
- return this;
90
- }
91
- };
92
- }
93
-
94
- //#endregion
95
- //#region src/utils/code-generator.ts
96
- function importInfo() {
97
- return {
98
- named: /* @__PURE__ */ new Map(),
99
- namespaces: /* @__PURE__ */ new Set(),
100
- isUsed: /* @__PURE__ */ new Set()
101
- };
102
- }
103
- /**
104
- * Code generator (one instance per file)
105
- */
106
- var CodeGenerator = class {
107
- lines = [];
108
- globCache;
109
- importInfos = /* @__PURE__ */ new Map();
110
- eagerImportId = 0;
111
- options;
112
- constructor({ target = "default", jsExtension = false, globCache = /* @__PURE__ */ new Map(), outDir = "" }) {
113
- this.options = {
114
- target,
115
- jsExtension,
116
- globCache,
117
- outDir
118
- };
119
- this.globCache = createCache(globCache);
120
- }
121
- addNamespaceImport(namespace, specifier, types = false) {
122
- const info = this.importInfos.get(specifier) ?? importInfo();
123
- this.importInfos.set(specifier, info);
124
- if (!types) info.isUsed.add(namespace);
125
- info.namespaces.add(namespace);
126
- }
127
- addNamedImport(names, specifier, types = false) {
128
- const info = this.importInfos.get(specifier) ?? importInfo();
129
- this.importInfos.set(specifier, info);
130
- for (const name of names) {
131
- const [memberName, importName = memberName] = name.split(/\s+as\s+/, 2);
132
- info.named.set(importName, memberName);
133
- if (!types) info.isUsed.add(importName);
134
- }
135
- }
136
- push(...insert) {
137
- this.lines.push(...insert);
138
- }
139
- async pushAsync(insert) {
140
- for (const line of await Promise.all(insert)) {
141
- if (line === void 0) continue;
142
- this.lines.push(line);
143
- }
144
- }
145
- async generateGlobImport(patterns, options) {
146
- if (this.options.target === "vite") return this.generateViteGlobImport(patterns, options);
147
- return this.generateNodeGlobImport(patterns, options);
148
- }
149
- generateViteGlobImport(patterns, { base, ...rest }) {
150
- patterns = (typeof patterns === "string" ? [patterns] : patterns).map(normalizeViteGlobPath);
151
- return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify({
152
- base: normalizeViteGlobPath(node_path.default.relative(this.options.outDir, base)),
153
- ...rest
154
- }, null, 2)})`;
155
- }
156
- async generateNodeGlobImport(patterns, { base, eager = false, query = {}, import: importName }) {
157
- const files = await this.globCache.cached(JSON.stringify({
158
- patterns,
159
- base
160
- }), () => (0, tinyglobby.glob)(patterns, { cwd: base }));
161
- let code = "{";
162
- for (const item of files) {
163
- const fullPath = node_path.default.join(base, item);
164
- const searchParams = new URLSearchParams();
165
- for (const [k, v] of Object.entries(query)) if (v !== void 0) searchParams.set(k, v);
166
- const importPath = `${this.formatImportPath(fullPath)}?${searchParams.toString()}`;
167
- if (eager) {
168
- const name = `__fd_glob_${this.eagerImportId++}`;
169
- this.lines.unshift(importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`);
170
- code += `${JSON.stringify(item)}: ${name}, `;
171
- } else {
172
- let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
173
- if (importName) line += `.then(mod => mod.${importName})`;
174
- code += `${line}, `;
175
- }
176
- }
177
- code += "}";
178
- return code;
179
- }
180
- formatImportPath(file) {
181
- const ext = node_path.default.extname(file);
182
- let filename;
183
- if (ext === ".ts") {
184
- filename = file.substring(0, file.length - ext.length);
185
- if (this.options.jsExtension) filename += ".js";
186
- } else filename = file;
187
- const importPath = slash(node_path.default.relative(this.options.outDir, filename));
188
- return importPath.startsWith(".") ? importPath : `./${importPath}`;
189
- }
190
- toString() {
191
- const final = ["// @ts-nocheck"];
192
- if (this.options.target === "vite") final.push("/// <reference types=\"vite/client\" />");
193
- for (const [specifier, info] of this.importInfos) {
194
- const { namespaces, named, isUsed } = info;
195
- for (const namespace of namespaces) final.push(isUsed.has(namespace) ? `import * as ${namespace} from "${specifier}";` : `import type * as ${namespace} from "${specifier}";`);
196
- const namedImports = [];
197
- for (const [importName, memberName] of named) {
198
- const item = importName === memberName ? importName : `${memberName} as ${importName}`;
199
- namedImports.push(isUsed.has(importName) ? item : `type ${item}`);
200
- }
201
- if (namedImports.length > 0) final.push(`import { ${namedImports.join(", ")} } from "${specifier}";`);
202
- }
203
- final.push(...this.lines);
204
- return final.join("\n");
205
- }
206
- };
207
- /**
208
- * convert into POSIX & relative file paths, such that Vite can accept it.
209
- */
210
- function normalizeViteGlobPath(file) {
211
- file = slash(file);
212
- if (file.startsWith("./")) return file;
213
- if (file.startsWith("/")) return `.${file}`;
214
- return `./${file}`;
215
- }
216
- function slash(path$3) {
217
- if (path$3.startsWith("\\\\?\\")) return path$3;
218
- return path$3.replaceAll("\\", "/");
219
- }
220
-
221
- //#endregion
222
- //#region src/core.ts
223
- async function getPlugins(pluginOptions) {
224
- const plugins = [];
225
- for (const option of await Promise.all(pluginOptions)) {
226
- if (!option) continue;
227
- if (Array.isArray(option)) plugins.push(...await getPlugins(option));
228
- else plugins.push(option);
229
- }
230
- return plugins;
231
- }
232
- var Core = class Core {
233
- workspaces = /* @__PURE__ */ new Map();
234
- options;
235
- plugins = [];
236
- config;
237
- static defaultOptions = {
238
- configPath: "content.config.ts",
239
- outDir: ".content"
240
- };
241
- /**
242
- * Convenient cache store, reset when config changes.
243
- *
244
- * You can group namespaces in cache key with ":", like `my-plugin:data`
245
- */
246
- cache = /* @__PURE__ */ new Map();
247
- constructor(options = {}) {
248
- const cwd = options.cwd ? node_path.default.resolve(options.cwd) : process.cwd();
249
- this.options = {
250
- ...options,
251
- cwd,
252
- outDir: node_path.default.resolve(cwd, options.outDir ?? Core.defaultOptions.outDir),
253
- configPath: node_path.default.resolve(cwd, options.configPath ?? Core.defaultOptions.configPath)
254
- };
255
- }
256
- async init({ config: newConfig, plugins: customPlugins }) {
257
- this.config = this.buildConfig(await newConfig);
258
- this.cache.clear();
259
- this.workspaces.clear();
260
- const loadedCollectionTypeIds = /* @__PURE__ */ new Set();
261
- this.plugins = await getPlugins([
262
- customPlugins,
263
- this.config.plugins,
264
- ...this.config.collections.values().map(({ typeInfo }) => {
265
- if (loadedCollectionTypeIds.has(typeInfo.id)) return false;
266
- loadedCollectionTypeIds.add(typeInfo.id);
267
- return typeInfo.plugins;
268
- })
269
- ]);
270
- const ctx = this.getPluginContext();
271
- for (const plugin of this.plugins) {
272
- const out = await plugin.config?.call(ctx, this.config);
273
- if (out) this.config = out;
274
- }
275
- if (!this.options.workspace && this.config.workspaces) await Promise.all(Object.entries(this.config.workspaces).map(async ([name, workspace]) => {
276
- const child = new Core({
277
- ...this.options,
278
- cwd: node_path.default.resolve(this.options.cwd, workspace.dir),
279
- workspace: {
280
- name,
281
- parent: this,
282
- dir: workspace.dir
283
- }
284
- });
285
- await child.init({ config: workspace.config });
286
- this.workspaces.set(name, child);
287
- }));
288
- await Promise.all(this.config.collections.values().map(async (collection) => {
289
- for (const plugin of this.plugins) await plugin.collection?.call(ctx, collection);
290
- }));
291
- }
292
- getWorkspaces() {
293
- return this.workspaces;
294
- }
295
- getOptions() {
296
- return this.options;
297
- }
298
- getConfig() {
299
- return this.config;
300
- }
301
- /**
302
- * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
303
- */
304
- getCompiledConfigPath() {
305
- return node_path.default.join(this.options.outDir, "content.config.mjs");
306
- }
307
- getPlugins(workspace = false) {
308
- if (workspace) {
309
- const plugins = [...this.plugins];
310
- for (const workspace$1 of this.workspaces.values()) plugins.push(...workspace$1.plugins);
311
- return plugins;
312
- }
313
- return this.plugins;
314
- }
315
- getCollections(workspace = false) {
316
- const list = Array.from(this.config.collections.values());
317
- if (workspace) for (const workspace$1 of this.workspaces.values()) list.push(...workspace$1.getCollections());
318
- return list;
319
- }
320
- getCollection(name) {
321
- return this.config.collections.get(name);
322
- }
323
- getPluginContext() {
324
- return { core: this };
325
- }
326
- async initServer(server) {
327
- const ctx = this.getPluginContext();
328
- const promises = [];
329
- for (const plugin of this.plugins) promises.push(plugin.configureServer?.call(ctx, server));
330
- for (const workspace of this.workspaces.values()) promises.push(workspace.initServer(server));
331
- await Promise.all(promises);
332
- }
333
- async emit(emitOptions = {}) {
334
- const { workspace, outDir } = this.options;
335
- const { target, jsExtension } = this.config.emit ?? {};
336
- const { filterPlugin, filterWorkspace, write = false } = emitOptions;
337
- const start = performance.now();
338
- const globCache = /* @__PURE__ */ new Map();
339
- const ctx = {
340
- ...this.getPluginContext(),
341
- createCodeGenerator: async (path$3, content) => {
342
- const codegen = new CodeGenerator({
343
- target,
344
- outDir,
345
- jsExtension,
346
- globCache
347
- });
348
- await content({
349
- core: this,
350
- codegen,
351
- workspace: workspace?.name
352
- });
353
- return {
354
- path: path$3,
355
- content: codegen.toString()
356
- };
357
- }
358
- };
359
- const added = /* @__PURE__ */ new Set();
360
- const out = {
361
- entries: [],
362
- workspaces: {}
363
- };
364
- for (const li of await Promise.all(this.plugins.map((plugin) => {
365
- if (filterPlugin && !filterPlugin(plugin) || !plugin.emit) return null;
366
- return plugin.emit.call(ctx);
367
- }))) {
368
- if (!li) continue;
369
- for (const item of li) {
370
- if (added.has(item.path)) continue;
371
- out.entries.push(item);
372
- added.add(item.path);
373
- }
374
- }
375
- if (write) {
376
- await Promise.all(out.entries.map(async (entry) => {
377
- const file = node_path.default.join(outDir, entry.path);
378
- await node_fs_promises.default.mkdir(node_path.default.dirname(file), { recursive: true });
379
- await node_fs_promises.default.writeFile(file, entry.content);
380
- }));
381
- console.log(workspace ? `[MDX: ${workspace.name}] generated files in ${performance.now() - start}ms` : `[MDX] generated files in ${performance.now() - start}ms`);
382
- }
383
- await Promise.all(this.workspaces.entries().map(async ([name, workspace$1]) => {
384
- if (filterWorkspace && !filterWorkspace(name)) return;
385
- out.workspaces[name] = (await workspace$1.emit(emitOptions)).entries;
386
- }));
387
- return out;
388
- }
389
- /**
390
- * convert absolute path into a runtime path (relative to **runtime** cwd)
391
- */
392
- _toRuntimePath(absolutePath) {
393
- return node_path.default.relative(process.cwd(), absolutePath);
394
- }
395
- buildConfig(config) {
396
- const collections = /* @__PURE__ */ new Map();
397
- let globalConfig;
398
- if ("default" in config) {
399
- globalConfig = config.default;
400
- for (const [k, v] of Object.entries(config)) {
401
- if (k === "default") continue;
402
- globalConfig.collections ??= {};
403
- globalConfig.collections[k] = v;
404
- }
405
- } else globalConfig = config;
406
- if (globalConfig.collections) for (const [name, collection] of Object.entries(globalConfig.collections)) {
407
- collection.init?.({
408
- name,
409
- core: this
410
- });
411
- collections.set(name, collection);
412
- }
413
- return {
414
- ...globalConfig,
415
- collections
416
- };
417
- }
418
- };
419
-
420
- //#endregion
421
- //#region src/next/index.ts
422
- async function createContent(nextOptions = {}) {
423
- const core = createNextCore(applyDefaults(nextOptions));
424
- await core.init({ config: loadConfig(core, true) });
425
- if (process.env._FUMADOCS_MDX !== "1") {
426
- process.env._FUMADOCS_MDX = "1";
427
- await core.emit({ write: true });
428
- await init(process.env.NODE_ENV === "development", core);
429
- }
430
- return (nextConfig = {}) => {
431
- const ctx = core.getPluginContext();
432
- for (const plugin of core.getPlugins(true)) nextConfig = plugin.next?.config?.call(ctx, nextConfig) ?? nextConfig;
433
- return nextConfig;
434
- };
435
- }
436
- async function init(dev, core) {
437
- if (!dev) return;
438
- const { FSWatcher } = await import("chokidar");
439
- const { configPath, outDir } = core.getOptions();
440
- const absoluteConfigPath = node_path.default.resolve(configPath);
441
- let watcher;
442
- async function devServer() {
443
- if (watcher && !watcher.closed) await watcher.close();
444
- watcher = new FSWatcher({
445
- ignoreInitial: true,
446
- persistent: true,
447
- ignored: [outDir]
448
- });
449
- watcher.add(configPath);
450
- for (const collection of core.getCollections(true)) {
451
- const handler = collection.handlers.fs;
452
- if (handler) watcher.add(handler.dir);
453
- }
454
- watcher.once("ready", () => {
455
- console.log("[MDX] started dev server");
456
- });
457
- watcher.on("all", (_event, file) => {
458
- if (node_path.default.resolve(file) === absoluteConfigPath) {
459
- console.log("[MDX] restarting dev server");
460
- watcher?.removeAllListeners();
461
- (async () => {
462
- await core.init({ config: loadConfig(core, true) });
463
- await devServer();
464
- await core.emit({ write: true });
465
- })();
466
- }
467
- });
468
- await core.initServer({ watcher });
469
- }
470
- process.on("exit", () => {
471
- if (!watcher || watcher.closed) return;
472
- console.log("[MDX] closing dev server");
473
- watcher.close();
474
- });
475
- await devServer();
476
- }
477
- async function createStandaloneCore(options) {
478
- const core = createNextCore(applyDefaults(options));
479
- await core.init({ config: loadConfig(core, true) });
480
- return core;
481
- }
482
- function applyDefaults(options) {
483
- return {
484
- outDir: options.outDir ?? Core.defaultOptions.outDir,
485
- configPath: options.configPath ?? Core.defaultOptions.configPath
486
- };
487
- }
488
- function createNextCore(options) {
489
- return new Core({
490
- outDir: options.outDir,
491
- configPath: options.configPath
492
- });
493
- }
494
-
495
- //#endregion
496
- exports.createContent = createContent;
497
- exports.createStandaloneCore = createStandaloneCore;
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-CVAU22o3.js","names":[],"sources":["../src/plugins/with-loader/node.ts"],"sourcesContent":["import type { LoadFnOutput, LoadHook } from \"node:module\";\nimport { fileURLToPath } from \"node:url\";\nimport fs from \"node:fs/promises\";\nimport type { Loader } from \"@/plugins/with-loader\";\n\nexport function toNode(test: RegExp | undefined, loader: Loader): LoadHook {\n return async (url, _context, nextLoad): Promise<LoadFnOutput> => {\n if (url.startsWith(\"file:///\") && (!test || test.test(url))) {\n const parsedUrl = new URL(url);\n const filePath = fileURLToPath(parsedUrl);\n\n const result = await loader.load({\n filePath,\n query: Object.fromEntries(parsedUrl.searchParams.entries()),\n async getSource() {\n return (await fs.readFile(filePath)).toString();\n },\n development: false,\n compiler: {\n addDependency() {},\n },\n });\n\n if (result) {\n return {\n source: result.code,\n format: \"module\",\n shortCircuit: true,\n };\n }\n }\n\n return nextLoad(url);\n };\n}\n"],"mappings":";;;;AAKA,SAAgB,OAAO,MAA0B,QAA0B;AACzE,QAAO,OAAO,KAAK,UAAU,aAAoC;AAC/D,MAAI,IAAI,WAAW,WAAW,KAAK,CAAC,QAAQ,KAAK,KAAK,IAAI,GAAG;GAC3D,MAAM,YAAY,IAAI,IAAI,IAAI;GAC9B,MAAM,WAAW,cAAc,UAAU;GAEzC,MAAM,SAAS,MAAM,OAAO,KAAK;IAC/B;IACA,OAAO,OAAO,YAAY,UAAU,aAAa,SAAS,CAAC;IAC3D,MAAM,YAAY;AAChB,aAAQ,MAAM,GAAG,SAAS,SAAS,EAAE,UAAU;;IAEjD,aAAa;IACb,UAAU,EACR,gBAAgB,IACjB;IACF,CAAC;AAEF,OAAI,OACF,QAAO;IACL,QAAQ,OAAO;IACf,QAAQ;IACR,cAAc;IACf;;AAIL,SAAO,SAAS,IAAI"}
@@ -1,31 +0,0 @@
1
- //#region src/utils/pipe.ts
2
- function pipe() {
3
- const steps = [];
4
- return {
5
- run(data, ctx) {
6
- for (const step of steps) data = step(data, ctx);
7
- return data;
8
- },
9
- pipe(fn) {
10
- steps.push(fn);
11
- return this;
12
- }
13
- };
14
- }
15
- function asyncPipe() {
16
- const steps = [];
17
- return {
18
- async run(data, ctx) {
19
- for (const step of steps) data = await step(data, ctx);
20
- return data;
21
- },
22
- pipe(fn) {
23
- steps.push(fn);
24
- return this;
25
- }
26
- };
27
- }
28
-
29
- //#endregion
30
- export { pipe as n, asyncPipe as t };
31
- //# sourceMappingURL=pipe-UEMV1mRg.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pipe-UEMV1mRg.js","names":["steps: ((data: Data, context: Context) => Data)[]","steps: ((data: Data, context: Context) => Awaitable<Data>)[]"],"sources":["../src/utils/pipe.ts"],"sourcesContent":["import type { Awaitable } from \"@/types\";\n\nexport interface Pipe<Data, Context = undefined> {\n /**\n * add a transformation step\n *\n * @returns the same pipe instance\n */\n pipe: (fn: (data: Data, context: Context) => Data) => Pipe<Data, Context>;\n run: (data: Data, context: Context) => Data;\n}\n\nexport interface AsyncPipe<Data, Context = undefined> {\n /**\n * add a transformation step\n *\n * @returns the same pipe instance\n */\n pipe: (fn: (data: Data, context: Context) => Awaitable<Data>) => AsyncPipe<Data, Context>;\n run: (data: Data, context: Context) => Awaitable<Data>;\n}\n\nexport function pipe<Data, Context>(): Pipe<Data, Context> {\n const steps: ((data: Data, context: Context) => Data)[] = [];\n return {\n run(data, ctx) {\n for (const step of steps) {\n data = step(data, ctx);\n }\n return data;\n },\n pipe(fn) {\n steps.push(fn);\n return this;\n },\n };\n}\n\nexport function asyncPipe<Data, Context>(): AsyncPipe<Data, Context> {\n const steps: ((data: Data, context: Context) => Awaitable<Data>)[] = [];\n return {\n async run(data, ctx) {\n for (const step of steps) {\n data = await step(data, ctx);\n }\n return data;\n },\n pipe(fn) {\n steps.push(fn);\n return this;\n },\n };\n}\n"],"mappings":";AAsBA,SAAgB,OAA2C;CACzD,MAAMA,QAAoD,EAAE;AAC5D,QAAO;EACL,IAAI,MAAM,KAAK;AACb,QAAK,MAAM,QAAQ,MACjB,QAAO,KAAK,MAAM,IAAI;AAExB,UAAO;;EAET,KAAK,IAAI;AACP,SAAM,KAAK,GAAG;AACd,UAAO;;EAEV;;AAGH,SAAgB,YAAqD;CACnE,MAAMC,QAA+D,EAAE;AACvE,QAAO;EACL,MAAM,IAAI,MAAM,KAAK;AACnB,QAAK,MAAM,QAAQ,MACjB,QAAO,MAAM,KAAK,MAAM,IAAI;AAE9B,UAAO;;EAET,KAAK,IAAI;AACP,SAAM,KAAK,GAAG;AACd,UAAO;;EAEV"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"git.js","names":["client: VersionControlClient"],"sources":["../../src/plugins/git.ts"],"sourcesContent":["import path from \"node:path\";\nimport { type Output, x } from \"tinyexec\";\nimport type { Plugin } from \"@/core\";\nimport { createCache } from \"@/utils/async-cache\";\n\nexport interface VersionControlFileData {\n /**\n * Last modified date of file, obtained from version control.\n */\n lastModified: Date | null;\n /**\n * Creation date of file, obtained from version control.\n */\n creationDate: Date | null;\n}\n\nexport interface VersionControlHandler {\n /**\n * receive the version control client.\n */\n client: (context: { client: VersionControlClient }) => void | Promise<void>;\n}\n\nexport interface GitPluginOptions {\n /**\n * Filter the collections to include by names\n */\n filter?: (collection: string) => boolean;\n}\n\n/**\n * Add version control integration for Git.\n * 1. Injects `creationDate` & `lastModified` properties to page exports.\n *\n * @remarks If you are using Vercel, please set `VERCEL_DEEP_CLONE` environment variable to `true`. This ensures the client can access the full commit history of Git.\n */\nexport default function git(options: GitPluginOptions = {}): Plugin {\n const { filter = () => true } = options;\n let client: VersionControlClient;\n\n return {\n name: \"git\",\n config() {\n const { cwd } = this.core.getOptions();\n client = createGitClient(cwd);\n },\n collection(collection) {\n if (!filter(collection.name)) return;\n\n const handler = collection.handlers[\"version-control\"];\n if (!handler) return;\n return handler.client({ client });\n },\n };\n}\n\nexport interface VersionControlClient {\n getFileData: (options: { filePath: string }) => Promise<VersionControlFileData>;\n}\n\nfunction createGitClient(cwd: string): VersionControlClient {\n const cache = createCache<VersionControlFileData>();\n\n function mapDate(out: Output): Date | null {\n if (out.exitCode !== 0) return null;\n const date = new Date(out.stdout);\n return Number.isNaN(date.getTime()) ? null : date;\n }\n\n return {\n async getFileData({ filePath }) {\n return cache.cached(filePath, async () => {\n const relativePath = path.relative(cwd, filePath);\n const [mod, create] = await Promise.all([\n x(\"git\", [\"log\", \"-1\", \"--pretty=%ai\", relativePath], {\n nodeOptions: {\n cwd,\n },\n }),\n x(\"git\", [\"log\", \"--diff-filter=A\", \"--follow\", \"--format=%ai\", \"-1\", relativePath], {\n nodeOptions: {\n cwd,\n },\n }),\n ]);\n\n return {\n lastModified: mapDate(mod),\n creationDate: mapDate(create),\n };\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AAoCA,SAAwB,IAAI,UAA4B,EAAE,EAAU;CAClE,MAAM,EAAE,eAAe,SAAS;CAChC,IAAIA;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP,MAAM,EAAE,QAAQ,KAAK,KAAK,YAAY;AACtC,YAAS,gBAAgB,IAAI;;EAE/B,WAAW,YAAY;AACrB,OAAI,CAAC,OAAO,WAAW,KAAK,CAAE;GAE9B,MAAM,UAAU,WAAW,SAAS;AACpC,OAAI,CAAC,QAAS;AACd,UAAO,QAAQ,OAAO,EAAE,QAAQ,CAAC;;EAEpC;;AAOH,SAAS,gBAAgB,KAAmC;CAC1D,MAAM,QAAQ,aAAqC;CAEnD,SAAS,QAAQ,KAA0B;AACzC,MAAI,IAAI,aAAa,EAAG,QAAO;EAC/B,MAAM,OAAO,IAAI,KAAK,IAAI,OAAO;AACjC,SAAO,OAAO,MAAM,KAAK,SAAS,CAAC,GAAG,OAAO;;AAG/C,QAAO,EACL,MAAM,YAAY,EAAE,YAAY;AAC9B,SAAO,MAAM,OAAO,UAAU,YAAY;GACxC,MAAM,eAAe,KAAK,SAAS,KAAK,SAAS;GACjD,MAAM,CAAC,KAAK,UAAU,MAAM,QAAQ,IAAI,CACtC,EAAE,OAAO;IAAC;IAAO;IAAM;IAAgB;IAAa,EAAE,EACpD,aAAa,EACX,KACD,EACF,CAAC,EACF,EAAE,OAAO;IAAC;IAAO;IAAmB;IAAY;IAAgB;IAAM;IAAa,EAAE,EACnF,aAAa,EACX,KACD,EACF,CAAC,CACH,CAAC;AAEF,UAAO;IACL,cAAc,QAAQ,IAAI;IAC1B,cAAc,QAAQ,OAAO;IAC9B;IACD;IAEL"}
@@ -1,2 +0,0 @@
1
- import { B as withLoader, F as CompilerOptions, I as Loader, L as LoaderInput, R as LoaderOutput, z as WithLoaderConfig } from "../../core-CRWvbE7W.js";
2
- export { CompilerOptions, Loader, LoaderInput, LoaderOutput, WithLoaderConfig, withLoader };
@@ -1,28 +0,0 @@
1
- //#region src/plugins/with-loader/index.ts
2
- /**
3
- * a light layer for implementing loaders.
4
- *
5
- * @remarks it doesn't include Next.js, you have to define the webpack/turbopack config, and export the loaders on your own.
6
- */
7
- function withLoader(plugin, { test, createLoader }) {
8
- let loader;
9
- return {
10
- bun: { async build(build) {
11
- const { toBun } = await import("../../bun-Br1ReMiq.js");
12
- toBun(test, await (loader ??= createLoader.call(this, "bun")))(build);
13
- } },
14
- node: { async createLoad() {
15
- const { toNode } = await import("../../node-CVAU22o3.js");
16
- return toNode(test, await (loader ??= createLoader.call(this, "node")));
17
- } },
18
- vite: { async createPlugin() {
19
- const { toVite } = await import("../../vite-6awgG092.js");
20
- return toVite(plugin.name, test, await (loader ??= createLoader.call(this, "vite")));
21
- } },
22
- ...plugin
23
- };
24
- }
25
-
26
- //#endregion
27
- export { withLoader };
28
- //# sourceMappingURL=index.js.map