@conloca/astro-cms 0.1.16 → 0.2.1

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 (422) hide show
  1. package/README.md +254 -301
  2. package/dist/internal/acorn-default.mjs +11 -3
  3. package/dist/internal/page-handler.astro +137 -358
  4. package/dist/ts/node/content.d.ts +4 -0
  5. package/dist/ts/node/content.d.ts.map +1 -0
  6. package/dist/ts/node/content.js +3 -0
  7. package/dist/ts/node/content.js.map +1 -0
  8. package/dist/ts/node/index.d.ts +9 -0
  9. package/dist/ts/node/index.d.ts.map +1 -0
  10. package/dist/ts/node/index.js +14 -0
  11. package/dist/ts/node/index.js.map +1 -0
  12. package/dist/ts/src/asset-ref-base.d.ts +3 -0
  13. package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
  14. package/dist/ts/src/asset-ref-base.js +48 -0
  15. package/dist/ts/src/asset-ref-base.js.map +1 -0
  16. package/dist/ts/src/checks.d.ts +7 -0
  17. package/dist/ts/src/checks.d.ts.map +1 -0
  18. package/dist/ts/src/checks.js +7 -0
  19. package/dist/ts/src/checks.js.map +1 -0
  20. package/dist/{src → ts/src}/cms-handler.d.ts +0 -1
  21. package/dist/ts/src/cms-handler.d.ts.map +1 -0
  22. package/dist/{src → ts/src}/cms-handler.js +11 -131
  23. package/dist/ts/src/cms-handler.js.map +1 -0
  24. package/dist/ts/src/collections.d.ts +161 -0
  25. package/dist/ts/src/collections.d.ts.map +1 -0
  26. package/dist/ts/src/collections.js +178 -0
  27. package/dist/ts/src/collections.js.map +1 -0
  28. package/dist/{src → ts/src}/components/HydrationWrapper.d.ts +1 -1
  29. package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
  30. package/dist/{src → ts/src}/components/HydrationWrapper.js +1 -0
  31. package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
  32. package/dist/{src/components/RenderWithBlocks.d.ts → ts/src/components/RenderWithFragments.d.ts} +8 -4
  33. package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
  34. package/dist/ts/src/components/RenderWithFragments.js +133 -0
  35. package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
  36. package/dist/{src → ts/src}/components/RenderWithHydration.d.ts +6 -2
  37. package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
  38. package/dist/{src → ts/src}/components/RenderWithHydration.js +6 -3
  39. package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
  40. package/dist/ts/src/components.d.ts +4 -0
  41. package/dist/ts/src/components.d.ts.map +1 -0
  42. package/dist/ts/src/components.js +4 -0
  43. package/dist/ts/src/components.js.map +1 -0
  44. package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
  45. package/dist/{src → ts/src}/discovery/astro-frontmatter.js +1 -0
  46. package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
  47. package/dist/ts/src/discovery/discover.d.ts +43 -0
  48. package/dist/ts/src/discovery/discover.d.ts.map +1 -0
  49. package/dist/ts/src/discovery/discover.js +87 -0
  50. package/dist/ts/src/discovery/discover.js.map +1 -0
  51. package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
  52. package/dist/{src → ts/src}/discovery/extract-props-ts.js +1 -0
  53. package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
  54. package/dist/{src → ts/src}/discovery/merge-registry.d.ts +3 -3
  55. package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
  56. package/dist/{src → ts/src}/discovery/merge-registry.js +1 -0
  57. package/dist/ts/src/discovery/merge-registry.js.map +1 -0
  58. package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
  59. package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
  60. package/dist/ts/src/discovery/registry-endpoint.js +76 -0
  61. package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
  62. package/dist/{src → ts/src}/discovery/scan-components.d.ts +3 -7
  63. package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
  64. package/dist/{src → ts/src}/discovery/scan-components.js +4 -6
  65. package/dist/ts/src/discovery/scan-components.js.map +1 -0
  66. package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
  67. package/dist/{src → ts/src}/discovery/scan-mdx.js +1 -0
  68. package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
  69. package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
  70. package/dist/{src → ts/src}/discovery/scan-overrides.js +1 -0
  71. package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
  72. package/dist/ts/src/editor-descriptors.d.ts +31 -0
  73. package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
  74. package/dist/ts/src/editor-descriptors.js +84 -0
  75. package/dist/ts/src/editor-descriptors.js.map +1 -0
  76. package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
  77. package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
  78. package/dist/ts/src/handlers/collection-content-api.js +166 -0
  79. package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
  80. package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
  81. package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
  82. package/dist/ts/src/handlers/page-render-core.js +315 -0
  83. package/dist/ts/src/handlers/page-render-core.js.map +1 -0
  84. package/dist/ts/src/hydration.d.ts.map +1 -0
  85. package/dist/{src → ts/src}/hydration.js +1 -0
  86. package/dist/ts/src/hydration.js.map +1 -0
  87. package/dist/ts/src/index.d.ts +21 -0
  88. package/dist/ts/src/index.d.ts.map +1 -0
  89. package/dist/ts/src/index.js +45 -0
  90. package/dist/ts/src/index.js.map +1 -0
  91. package/dist/ts/src/internal/declared-collections.d.ts +30 -0
  92. package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
  93. package/dist/ts/src/internal/declared-collections.js +84 -0
  94. package/dist/ts/src/internal/declared-collections.js.map +1 -0
  95. package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
  96. package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
  97. package/dist/ts/src/internal/page-collection-schema.js +152 -0
  98. package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
  99. package/dist/ts/src/lib/content-config-guard.d.ts +13 -0
  100. package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
  101. package/dist/ts/src/lib/content-config-guard.js +45 -0
  102. package/dist/ts/src/lib/content-config-guard.js.map +1 -0
  103. package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
  104. package/dist/{src → ts/src}/lib/hydration-scanner.js +1 -0
  105. package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
  106. package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
  107. package/dist/{src → ts/src}/lib/hydration-script.js +1 -0
  108. package/dist/ts/src/lib/hydration-script.js.map +1 -0
  109. package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
  110. package/dist/{src → ts/src}/lib/hydration-utils.js +1 -0
  111. package/dist/ts/src/lib/hydration-utils.js.map +1 -0
  112. package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
  113. package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
  114. package/dist/ts/src/lib/resolve-locale.js +16 -0
  115. package/dist/ts/src/lib/resolve-locale.js.map +1 -0
  116. package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
  117. package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
  118. package/dist/ts/src/lib/resolve-site-name.js +12 -0
  119. package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
  120. package/dist/{src → ts/src}/lib/route-utils.d.ts +26 -6
  121. package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
  122. package/dist/{src → ts/src}/lib/route-utils.js +33 -15
  123. package/dist/ts/src/lib/route-utils.js.map +1 -0
  124. package/dist/{src → ts/src}/lib/routing-config.d.ts +7 -1
  125. package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
  126. package/dist/{src → ts/src}/lib/routing-config.js +13 -0
  127. package/dist/ts/src/lib/routing-config.js.map +1 -0
  128. package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
  129. package/dist/{src → ts/src}/lib/serialize-props.js +1 -0
  130. package/dist/ts/src/lib/serialize-props.js.map +1 -0
  131. package/dist/ts/src/lib/unknown-components.d.ts +21 -0
  132. package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
  133. package/dist/ts/src/lib/unknown-components.js +49 -0
  134. package/dist/ts/src/lib/unknown-components.js.map +1 -0
  135. package/dist/{src → ts/src}/lib/virtual-module-generators.d.ts +0 -24
  136. package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
  137. package/dist/ts/src/lib/virtual-module-generators.js +51 -0
  138. package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
  139. package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
  140. package/dist/{src → ts/src}/lib/withHydration.js +1 -0
  141. package/dist/ts/src/lib/withHydration.js.map +1 -0
  142. package/dist/ts/src/loader.d.ts +27 -0
  143. package/dist/ts/src/loader.d.ts.map +1 -0
  144. package/dist/{src → ts/src}/loader.js +33 -4
  145. package/dist/ts/src/loader.js.map +1 -0
  146. package/dist/ts/src/locales-helpers.d.ts.map +1 -0
  147. package/dist/{src → ts/src}/locales-helpers.js +1 -0
  148. package/dist/ts/src/locales-helpers.js.map +1 -0
  149. package/dist/ts/src/mime-types.d.ts.map +1 -0
  150. package/dist/{src → ts/src}/mime-types.js +1 -0
  151. package/dist/ts/src/mime-types.js.map +1 -0
  152. package/dist/ts/src/page-feed.d.ts +13 -0
  153. package/dist/ts/src/page-feed.d.ts.map +1 -0
  154. package/dist/ts/src/page-feed.js +20 -0
  155. package/dist/ts/src/page-feed.js.map +1 -0
  156. package/dist/ts/src/page-schemas.d.ts +6 -0
  157. package/dist/ts/src/page-schemas.d.ts.map +1 -0
  158. package/dist/ts/src/page-schemas.js +6 -0
  159. package/dist/ts/src/page-schemas.js.map +1 -0
  160. package/dist/ts/src/path-validation.d.ts.map +1 -0
  161. package/dist/{src → ts/src}/path-validation.js +1 -0
  162. package/dist/ts/src/path-validation.js.map +1 -0
  163. package/dist/{src → ts/src}/plugin-spa.d.ts +28 -10
  164. package/dist/ts/src/plugin-spa.d.ts.map +1 -0
  165. package/dist/{src → ts/src}/plugin-spa.js +301 -88
  166. package/dist/ts/src/plugin-spa.js.map +1 -0
  167. package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
  168. package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
  169. package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
  170. package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
  171. package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
  172. package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
  173. package/dist/ts/src/puck-manifest/field-projection.js +422 -0
  174. package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
  175. package/dist/ts/src/puck-manifest/index.d.ts +4 -0
  176. package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
  177. package/dist/ts/src/puck-manifest/index.js +3 -0
  178. package/dist/ts/src/puck-manifest/index.js.map +1 -0
  179. package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
  180. package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
  181. package/dist/ts/src/puck-manifest/literal.js +354 -0
  182. package/dist/ts/src/puck-manifest/literal.js.map +1 -0
  183. package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
  184. package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
  185. package/dist/ts/src/puck-manifest/read-config.js +517 -0
  186. package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
  187. package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
  188. package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
  189. package/dist/ts/src/puck-manifest/read-field.js +11 -0
  190. package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
  191. package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
  192. package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
  193. package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
  194. package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
  195. package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
  196. package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
  197. package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
  198. package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
  199. package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
  200. package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
  201. package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
  202. package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
  203. package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
  204. package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
  205. package/dist/ts/src/puck-manifest/source-reference.js +424 -0
  206. package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
  207. package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
  208. package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
  209. package/dist/ts/src/puck-manifest/syntax.js +79 -0
  210. package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
  211. package/dist/ts/src/puck-manifest/types.d.ts +145 -0
  212. package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
  213. package/dist/ts/src/puck-manifest/types.js +2 -0
  214. package/dist/ts/src/puck-manifest/types.js.map +1 -0
  215. package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
  216. package/dist/{src → ts/src}/safe-json-stringify.js +1 -0
  217. package/dist/ts/src/safe-json-stringify.js.map +1 -0
  218. package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
  219. package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
  220. package/dist/ts/src/sandbox-frame-handler.js +27 -0
  221. package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
  222. package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.d.ts +2 -5
  223. package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
  224. package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.js +5 -8
  225. package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
  226. package/dist/{src → ts/src}/site-styles/render-endpoint.d.ts +4 -9
  227. package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
  228. package/dist/{src → ts/src}/site-styles/render-endpoint.js +1 -0
  229. package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
  230. package/dist/{src → ts/src}/site-styles/styles-endpoint.d.ts +2 -4
  231. package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
  232. package/dist/{src → ts/src}/site-styles/styles-endpoint.js +3 -5
  233. package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
  234. package/dist/ts/src/sitemap-options.d.ts +21 -0
  235. package/dist/ts/src/sitemap-options.d.ts.map +1 -0
  236. package/dist/ts/src/sitemap-options.js +92 -0
  237. package/dist/ts/src/sitemap-options.js.map +1 -0
  238. package/dist/ts/src/tiptap-html-static.d.ts +16 -0
  239. package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
  240. package/dist/ts/src/tiptap-html-static.js +117 -0
  241. package/dist/ts/src/tiptap-html-static.js.map +1 -0
  242. package/dist/{src → ts/src}/types.d.ts +26 -110
  243. package/dist/ts/src/types.d.ts.map +1 -0
  244. package/dist/ts/src/types.js +2 -0
  245. package/dist/ts/src/types.js.map +1 -0
  246. package/dist/virtual-modules.d.ts +12 -93
  247. package/node/content.ts +14 -0
  248. package/node/index.ts +22 -0
  249. package/package.json +161 -73
  250. package/src/asset-ref-base.ts +48 -0
  251. package/src/checks.ts +11 -0
  252. package/src/cms-handler.ts +281 -0
  253. package/src/collections.ts +271 -0
  254. package/src/components/HydrationWrapper.tsx +41 -0
  255. package/src/components/RenderWithFragments.tsx +204 -0
  256. package/src/components/RenderWithHydration.tsx +55 -0
  257. package/src/components.ts +3 -0
  258. package/src/discovery/astro-frontmatter.ts +24 -0
  259. package/src/discovery/discover.ts +108 -0
  260. package/src/discovery/extract-props-ts.ts +255 -0
  261. package/src/discovery/merge-registry.ts +411 -0
  262. package/src/discovery/registry-endpoint.ts +80 -0
  263. package/src/discovery/scan-components.ts +458 -0
  264. package/src/discovery/scan-mdx.ts +190 -0
  265. package/src/discovery/scan-overrides.ts +92 -0
  266. package/src/editor-descriptors.ts +96 -0
  267. package/src/env.d.ts +31 -0
  268. package/src/handlers/collection-content-api.ts +196 -0
  269. package/src/handlers/page-handler.astro +320 -0
  270. package/src/handlers/page-render-core.ts +456 -0
  271. package/src/hydration.ts +7 -0
  272. package/src/index.ts +111 -0
  273. package/src/internal/acorn-default.mjs +37 -0
  274. package/src/internal/declared-collections.ts +98 -0
  275. package/src/internal/page-collection-schema.ts +210 -0
  276. package/src/lib/content-config-guard.ts +53 -0
  277. package/src/lib/hydration-scanner.ts +176 -0
  278. package/src/lib/hydration-script.ts +126 -0
  279. package/src/lib/hydration-utils.ts +120 -0
  280. package/src/lib/resolve-locale.ts +22 -0
  281. package/src/lib/resolve-site-name.ts +10 -0
  282. package/src/lib/route-utils.ts +106 -0
  283. package/src/lib/routing-config.ts +126 -0
  284. package/src/lib/serialize-props.ts +7 -0
  285. package/src/lib/unknown-components.ts +64 -0
  286. package/src/lib/virtual-module-generators.ts +58 -0
  287. package/{dist/withHydration-DkKpkmzJ.d.mts → src/lib/withHydration.ts} +25 -8
  288. package/src/loader.ts +145 -0
  289. package/{dist/locales-helpers-BvYYqnJ5.d.mts → src/locales-helpers.ts} +21 -17
  290. package/src/mime-types.ts +19 -0
  291. package/src/page-feed.ts +26 -0
  292. package/src/page-schemas.ts +19 -0
  293. package/src/path-validation.ts +13 -0
  294. package/src/plugin-spa.ts +1496 -0
  295. package/src/puck-manifest/components-endpoint.ts +55 -0
  296. package/src/puck-manifest/field-projection.ts +510 -0
  297. package/src/puck-manifest/index.ts +3 -0
  298. package/src/puck-manifest/literal.ts +459 -0
  299. package/src/puck-manifest/read-config.ts +577 -0
  300. package/src/puck-manifest/read-field.ts +19 -0
  301. package/src/puck-manifest/read-wrapper.ts +1056 -0
  302. package/src/puck-manifest/reading-budget.ts +127 -0
  303. package/src/puck-manifest/resolve-reference.ts +9 -0
  304. package/src/puck-manifest/source-reference.ts +484 -0
  305. package/src/puck-manifest/syntax.ts +104 -0
  306. package/src/puck-manifest/types.ts +139 -0
  307. package/src/safe-json-stringify.ts +17 -0
  308. package/src/sandbox-frame-handler.ts +31 -0
  309. package/src/site-styles/content-wrapper-endpoint.ts +327 -0
  310. package/src/site-styles/render-endpoint.ts +331 -0
  311. package/src/site-styles/styles-endpoint.ts +184 -0
  312. package/src/sitemap-options.ts +115 -0
  313. package/src/tiptap-html-static.ts +134 -0
  314. package/{dist/types-CS9neadI.d.mts → src/types.ts} +87 -124
  315. package/src/virtual-modules.d.ts +74 -0
  316. package/dist/collections-Bd7EME4b.mjs +0 -129
  317. package/dist/collections-Bd7EME4b.mjs.map +0 -1
  318. package/dist/collections.d.mts +0 -35
  319. package/dist/collections.d.mts.map +0 -1
  320. package/dist/collections.mjs +0 -2
  321. package/dist/components.d.mts +0 -41
  322. package/dist/components.d.mts.map +0 -1
  323. package/dist/components.mjs +0 -223
  324. package/dist/components.mjs.map +0 -1
  325. package/dist/hydration.d.mts +0 -4
  326. package/dist/hydration.mjs +0 -2
  327. package/dist/index.d.mts +0 -108
  328. package/dist/index.d.mts.map +0 -1
  329. package/dist/index.mjs +0 -67
  330. package/dist/index.mjs.map +0 -1
  331. package/dist/internal/cms-handler.d.mts +0 -25
  332. package/dist/internal/cms-handler.d.mts.map +0 -1
  333. package/dist/internal/cms-handler.mjs +0 -314
  334. package/dist/internal/cms-handler.mjs.map +0 -1
  335. package/dist/lib/hydration-script.d.mts +0 -30
  336. package/dist/lib/hydration-script.d.mts.map +0 -1
  337. package/dist/lib/hydration-script.mjs +0 -84
  338. package/dist/lib/hydration-script.mjs.map +0 -1
  339. package/dist/locales-helpers-BvYYqnJ5.d.mts.map +0 -1
  340. package/dist/locales-helpers-qiwh7nxS.mjs +0 -54
  341. package/dist/locales-helpers-qiwh7nxS.mjs.map +0 -1
  342. package/dist/node/content.d.mts +0 -18
  343. package/dist/node/content.d.mts.map +0 -1
  344. package/dist/node/content.d.ts +0 -3
  345. package/dist/node/content.d.ts.map +0 -1
  346. package/dist/node/content.js +0 -2
  347. package/dist/node/content.mjs +0 -2
  348. package/dist/node/index.d.mts +0 -200
  349. package/dist/node/index.d.mts.map +0 -1
  350. package/dist/node/index.d.ts +0 -4
  351. package/dist/node/index.d.ts.map +0 -1
  352. package/dist/node/index.js +0 -3
  353. package/dist/node/index.mjs +0 -2513
  354. package/dist/node/index.mjs.map +0 -1
  355. package/dist/serialize-props-BHoNpzH6.mjs +0 -72
  356. package/dist/serialize-props-BHoNpzH6.mjs.map +0 -1
  357. package/dist/src/cms-handler.d.ts.map +0 -1
  358. package/dist/src/collections.d.ts +0 -32
  359. package/dist/src/collections.d.ts.map +0 -1
  360. package/dist/src/collections.js +0 -50
  361. package/dist/src/components/HydrationWrapper.d.ts.map +0 -1
  362. package/dist/src/components/RenderWithBlocks.d.ts.map +0 -1
  363. package/dist/src/components/RenderWithBlocks.js +0 -129
  364. package/dist/src/components/RenderWithHydration.d.ts.map +0 -1
  365. package/dist/src/components.d.ts +0 -4
  366. package/dist/src/components.d.ts.map +0 -1
  367. package/dist/src/components.js +0 -3
  368. package/dist/src/discovery/astro-frontmatter.d.ts.map +0 -1
  369. package/dist/src/discovery/extract-props-ts.d.ts.map +0 -1
  370. package/dist/src/discovery/merge-registry.d.ts.map +0 -1
  371. package/dist/src/discovery/registry-endpoint.d.ts +0 -42
  372. package/dist/src/discovery/registry-endpoint.d.ts.map +0 -1
  373. package/dist/src/discovery/registry-endpoint.js +0 -81
  374. package/dist/src/discovery/scan-components.d.ts.map +0 -1
  375. package/dist/src/discovery/scan-mdx.d.ts.map +0 -1
  376. package/dist/src/discovery/scan-overrides.d.ts.map +0 -1
  377. package/dist/src/hydration.d.ts.map +0 -1
  378. package/dist/src/index.d.ts +0 -11
  379. package/dist/src/index.d.ts.map +0 -1
  380. package/dist/src/index.js +0 -25
  381. package/dist/src/lib/hydration-scanner.d.ts.map +0 -1
  382. package/dist/src/lib/hydration-script.d.ts.map +0 -1
  383. package/dist/src/lib/hydration-utils.d.ts.map +0 -1
  384. package/dist/src/lib/page-api.d.ts +0 -77
  385. package/dist/src/lib/page-api.d.ts.map +0 -1
  386. package/dist/src/lib/page-api.js +0 -121
  387. package/dist/src/lib/route-utils.d.ts.map +0 -1
  388. package/dist/src/lib/routing-config.d.ts.map +0 -1
  389. package/dist/src/lib/serialize-props.d.ts.map +0 -1
  390. package/dist/src/lib/virtual-module-generators.d.ts.map +0 -1
  391. package/dist/src/lib/virtual-module-generators.js +0 -263
  392. package/dist/src/lib/withHydration.d.ts.map +0 -1
  393. package/dist/src/loader.d.ts +0 -14
  394. package/dist/src/loader.d.ts.map +0 -1
  395. package/dist/src/locales-helpers.d.ts.map +0 -1
  396. package/dist/src/mime-types.d.ts.map +0 -1
  397. package/dist/src/path-validation.d.ts.map +0 -1
  398. package/dist/src/plugin-spa.d.ts.map +0 -1
  399. package/dist/src/safe-json-stringify.d.ts.map +0 -1
  400. package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +0 -1
  401. package/dist/src/site-styles/render-endpoint.d.ts.map +0 -1
  402. package/dist/src/site-styles/styles-endpoint.d.ts.map +0 -1
  403. package/dist/src/types.d.ts.map +0 -1
  404. package/dist/src/types.js +0 -1
  405. package/dist/types-CS9neadI.d.mts.map +0 -1
  406. package/dist/withHydration-C256ox_6.mjs +0 -49
  407. package/dist/withHydration-C256ox_6.mjs.map +0 -1
  408. package/dist/withHydration-DkKpkmzJ.d.mts.map +0 -1
  409. /package/dist/{src → ts/src}/discovery/astro-frontmatter.d.ts +0 -0
  410. /package/dist/{src → ts/src}/discovery/extract-props-ts.d.ts +0 -0
  411. /package/dist/{src → ts/src}/discovery/scan-mdx.d.ts +0 -0
  412. /package/dist/{src → ts/src}/discovery/scan-overrides.d.ts +0 -0
  413. /package/dist/{src → ts/src}/hydration.d.ts +0 -0
  414. /package/dist/{src → ts/src}/lib/hydration-scanner.d.ts +0 -0
  415. /package/dist/{src → ts/src}/lib/hydration-script.d.ts +0 -0
  416. /package/dist/{src → ts/src}/lib/hydration-utils.d.ts +0 -0
  417. /package/dist/{src → ts/src}/lib/serialize-props.d.ts +0 -0
  418. /package/dist/{src → ts/src}/lib/withHydration.d.ts +0 -0
  419. /package/dist/{src → ts/src}/locales-helpers.d.ts +0 -0
  420. /package/dist/{src → ts/src}/mime-types.d.ts +0 -0
  421. /package/dist/{src → ts/src}/path-validation.d.ts +0 -0
  422. /package/dist/{src → ts/src}/safe-json-stringify.d.ts +0 -0
@@ -0,0 +1,458 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { createRequire } from 'node:module';
4
+ import { basename, dirname, extname, resolve } from 'node:path';
5
+ import fg from 'fast-glob';
6
+ import type { Project } from 'ts-morph';
7
+ import { extractAstroFrontmatter } from './astro-frontmatter.js';
8
+ import { createScanProject, extractPropsViaTs } from './extract-props-ts.js';
9
+ import type { MdxScanResult } from './scan-mdx.js';
10
+
11
+ /**
12
+ * Walks configured folder globs for `.astro` and `.tsx` files,
13
+ * extracts each component's `Props` interface, and returns a
14
+ * descriptor-friendly schema. Used alongside `scan-mdx.ts` to
15
+ * populate the CMS registry without the host hand-writing
16
+ * `mdx-components.tsx`.
17
+ *
18
+ * Type extraction uses the TypeScript compiler API (via ts-morph,
19
+ * see `./extract-props-ts.ts`). Derived types — `(typeof X)[number]`,
20
+ * imported aliases, mapped types, conditional types — all resolve
21
+ * to their concrete shape, which is what makes the registry feel
22
+ * smart for real component libraries (eg Starlight's Aside, whose
23
+ * `type` prop uses indexed access). For `.astro` files we extract
24
+ * the leading `---` frontmatter block and feed it to the same
25
+ * extractor as a virtual `.ts` source.
26
+ *
27
+ * A single ts-morph Project is built per scan run and shared across
28
+ * every file in that run, so the per-file cost is small after the
29
+ * initial type-checker warmup. Sidecar `cmsConfig` overrides still
30
+ * apply (see `./scan-overrides.ts`) for components whose author
31
+ * wants to override or annotate fields beyond what the type says.
32
+ *
33
+ * Component name = basename of the file without extension.
34
+ * Component source = the resolved file path. The render endpoint
35
+ * hands this to `server.ssrLoadModule`, which accepts absolute
36
+ * paths in dev.
37
+ */
38
+ export interface ParsedProp {
39
+ name: string;
40
+ /** Inferred from the TypeScript type annotation. `'string'` covers
41
+ * literal-string unions too — `options` holds the union values
42
+ * when applicable so the prop panel can render a dropdown. */
43
+ type: 'string' | 'number' | 'boolean' | 'expression';
44
+ /** True when the prop's TS field lacks a `?` modifier. */
45
+ required: boolean;
46
+ /** Literal-string union values, eg `'note' | 'tip' | 'caution'`. */
47
+ options?: string[];
48
+ }
49
+
50
+ export interface LocalComponentScanResult {
51
+ /** Absolute file path of the component. */
52
+ filepath: string;
53
+ /** Component name (filename without extension). */
54
+ name: string;
55
+ /** Path to pass to `server.ssrLoadModule` — currently the absolute
56
+ * file path. Build-time callers rewrite it to the project-relative
57
+ * form via `toPortableImports` (discover.ts) before serializing. */
58
+ source: string;
59
+ /** All components from this scanner are treated as flow (block).
60
+ * Inline-only components are rare in authored libraries; if any
61
+ * surface as text-level usage they get classified at merge time
62
+ * from the MDX scan, not here. */
63
+ kind: 'flow';
64
+ props: ParsedProp[];
65
+ }
66
+
67
+ /**
68
+ * Scan every `.astro` / `.tsx` file under each configured folder.
69
+ * Folder globs are resolved relative to `projectRoot`.
70
+ */
71
+ export async function scanLocalComponents(folders: string[], projectRoot: string): Promise<LocalComponentScanResult[]> {
72
+ if (folders.length === 0) return [];
73
+ // Source files (`.astro` for Astro, `.tsx` for React) first; `.d.ts`
74
+ // declaration files only if no matching source file exists. Same
75
+ // priority rationale as `scanExternalComponents` — host source is
76
+ // ground truth, declarations are last-resort schema.
77
+ const sourcePatterns = folders.map((f) => `${f.replace(/\/+$/, '')}/**/*.{astro,tsx}`);
78
+ const dtsPatterns = folders.map((f) => `${f.replace(/\/+$/, '')}/**/*.d.ts`);
79
+ const sourceFiles = await fg(sourcePatterns, { cwd: projectRoot, absolute: true, dot: false });
80
+ const dtsFiles = await fg(dtsPatterns, { cwd: projectRoot, absolute: true, dot: false });
81
+ const seen = new Set<string>();
82
+ const allFiles: string[] = [];
83
+ for (const file of sourceFiles) {
84
+ const name = componentNameFromPath(file);
85
+ if (seen.has(name)) continue;
86
+ seen.add(name);
87
+ allFiles.push(file);
88
+ }
89
+ for (const file of dtsFiles) {
90
+ const name = componentNameFromPath(file);
91
+ if (seen.has(name)) continue;
92
+ seen.add(name);
93
+ allFiles.push(file);
94
+ }
95
+ // One ts-morph Project per scan run, shared across every file
96
+ // we extract from. Building the Project loads `lib.dom.d.ts` etc.
97
+ // (the dominant cost ~500ms-2s); sharing across files amortises
98
+ // it. Fed the host's tsconfig when present so cross-file `typeof`
99
+ // refs and path mappings (`@/foo`) resolve as authored.
100
+ const tsConfigFilePath = findTsConfig(projectRoot);
101
+ const project = createScanProject(tsConfigFilePath);
102
+
103
+ const results: LocalComponentScanResult[] = [];
104
+ for (const file of allFiles) {
105
+ try {
106
+ const r = await scanFile(file, project);
107
+ if (r) results.push(r);
108
+ } catch (err) {
109
+ console.warn(`[conloca:discovery] failed to scan ${file}:`, err instanceof Error ? err.message : err);
110
+ }
111
+ }
112
+ return results;
113
+ }
114
+
115
+ async function scanFile(filepath: string, project: Project): Promise<LocalComponentScanResult | null> {
116
+ const content = await readFile(filepath, 'utf8');
117
+ const name = componentNameFromPath(filepath);
118
+ // Components typically start with a capital. Lowercase-named files
119
+ // are usually utilities, not authorable components — skip them so
120
+ // we don't pollute the registry with `helpers.ts` and friends.
121
+ if (!/^[A-Z]/.test(name)) return null;
122
+ const props = extractPropsForFile(project, filepath, content, name);
123
+ return {
124
+ filepath,
125
+ name,
126
+ source: filepath,
127
+ kind: 'flow',
128
+ props,
129
+ };
130
+ }
131
+
132
+ /**
133
+ * Bridge between the file-level scanner and the ts-morph extractor.
134
+ * Handles the three file types we accept:
135
+ * - `.astro` — extract the `---`-fenced frontmatter, feed it as
136
+ * a virtual `.ts` source.
137
+ * - `.tsx` / `.d.ts` — feed the whole file content directly.
138
+ *
139
+ * The virtual source path is the real filepath suffixed with
140
+ * `.virtual.ts` for `.astro` files, so ts-morph's diagnostics still
141
+ * point back at the right author file. For `.tsx` / `.d.ts` we use
142
+ * the real path verbatim — ts-morph parses TS extensions natively.
143
+ */
144
+ function extractPropsForFile(project: Project, filepath: string, content: string, componentName: string): ParsedProp[] {
145
+ if (filepath.endsWith('.astro')) {
146
+ const frontmatter = extractAstroFrontmatter(content);
147
+ if (!frontmatter) return [];
148
+ return extractPropsViaTs(project, `${filepath}.virtual.ts`, frontmatter, componentName);
149
+ }
150
+ return extractPropsViaTs(project, filepath, content, componentName);
151
+ }
152
+
153
+ /**
154
+ * Locate the host's `tsconfig.json` so the ts-morph Project can
155
+ * resolve cross-file `typeof` refs, path aliases, and node_modules
156
+ * declarations the same way the author's IDE does. Walks up from
157
+ * `projectRoot` looking for the closest tsconfig; returns `undefined`
158
+ * if none found (the Project then uses permissive defaults).
159
+ */
160
+ function findTsConfig(projectRoot: string): string | undefined {
161
+ const candidate = resolve(projectRoot, 'tsconfig.json');
162
+ return existsSync(candidate) ? candidate : undefined;
163
+ }
164
+
165
+ /**
166
+ * Derive the canonical component name from a file path.
167
+ *
168
+ * Two extension shapes:
169
+ * - Single (`.astro`, `.tsx`) → strip with `extname`/`basename`.
170
+ * - Compound (`.d.ts`) → strip `.d.ts` explicitly, since `extname`
171
+ * would return only `.ts` and leave a trailing `.d` (`Card.d`).
172
+ *
173
+ * Keeps the rule simple and consistent: file basename === component
174
+ * name. Multi-component files (a `.d.ts` exporting many React
175
+ * components from one barrel) are NOT supported through this path —
176
+ * the sidecar `cmsConfig` mechanism (future task) covers those.
177
+ */
178
+ function componentNameFromPath(filepath: string): string {
179
+ const base = basename(filepath);
180
+ if (base.endsWith('.d.ts')) return base.slice(0, -'.d.ts'.length);
181
+ return base.slice(0, -extname(base).length);
182
+ }
183
+
184
+ /**
185
+ * Scan every npm-style import source referenced in the MDX usage scan
186
+ * and treat any `.astro` / `.tsx` file inside the resolved package as a
187
+ * candidate component. Resolves each unique specifier via Node's
188
+ * `require.resolve` (run from `projectRoot` so packages are looked up
189
+ * in the consumer's `node_modules`, not ours), walks up to the package
190
+ * root, then globs the package for component-shaped files.
191
+ *
192
+ * The returned `source` on each result is the ORIGINAL specifier from
193
+ * the MDX import (e.g. `@astrojs/starlight/components`) — not the
194
+ * resolved file path. That's what makes the merge work: `scan-mdx`
195
+ * records imports by their literal source string, so for the merge
196
+ * registry to dedupe local-folder scan ⨯ MDX-usage scan we need both
197
+ * sides to key on the same specifier. Vite's `ssrLoadModule` handles
198
+ * the specifier itself at render time, so we don't need an absolute
199
+ * file path on the descriptor.
200
+ *
201
+ * Caveats:
202
+ * - Specifiers that look like local paths (`./foo`, `/abs/path`) are
203
+ * intentionally skipped here — those are local components, already
204
+ * covered by `scanLocalComponents`.
205
+ * - One specifier per package: if a package is imported via two
206
+ * different specifiers (`@pkg/components` and `@pkg`), we'll scan
207
+ * it twice and emit two descriptor sets keyed on each specifier.
208
+ * The merge layer's collision resolution picks the one with more
209
+ * real usage, so this is self-correcting in practice.
210
+ * - We cap glob depth at 4 to avoid walking into deeply-nested
211
+ * library internals (most component packages put their exports
212
+ * near the root). Components nested deeper won't surface; hosts
213
+ * can either re-export them at a shallower path or add a sidecar
214
+ * `cmsConfig` (when sidecar support lands).
215
+ */
216
+ export async function scanExternalComponents(
217
+ mdxScans: MdxScanResult[],
218
+ projectRoot: string,
219
+ ): Promise<LocalComponentScanResult[]> {
220
+ const specifiers = collectExternalSpecifiers(mdxScans);
221
+ if (specifiers.size === 0) return [];
222
+
223
+ // Same Project-per-scan rationale as scanLocalComponents — pay the
224
+ // checker init cost once, share across every external file.
225
+ const tsConfigFilePath = findTsConfig(projectRoot);
226
+ const project = createScanProject(tsConfigFilePath);
227
+
228
+ const results: LocalComponentScanResult[] = [];
229
+ // `createRequire(projectRoot/package.json)` so resolution starts in
230
+ // the consumer's tree. Without this, Node looks up modules relative
231
+ // to wherever this file lives (our package), which would miss the
232
+ // consumer's installed dependencies.
233
+ const requireFromProject = createRequire(`${projectRoot.replace(/\/$/, '')}/package.json`);
234
+
235
+ for (const specifier of specifiers) {
236
+ try {
237
+ const resolved = requireFromProject.resolve(specifier);
238
+ const packageRoot = findPackageRoot(resolved);
239
+ if (!packageRoot) continue;
240
+
241
+ // First try: parse the resolved file as a re-export barrel
242
+ // (`export { default as Card } from './user-components/Card.astro'`).
243
+ // If we find re-exports, scan ONLY those files — the package's
244
+ // own author has declared the public surface, and everything
245
+ // else is internal noise we don't want in the registry.
246
+ //
247
+ // This is the Starlight case: `@astrojs/starlight/components`
248
+ // resolves to a barrel `.ts` listing exactly the 12 components
249
+ // the package intends for MDX use, hiding ~30 internal layout
250
+ // components in the same `node_modules` tree.
251
+ const barrelFiles = await collectBarrelExports(resolved, packageRoot);
252
+ let scanFiles: string[];
253
+ if (barrelFiles.length > 0) {
254
+ scanFiles = barrelFiles;
255
+ } else {
256
+ // Fallback: glob the whole package. Source files (`.astro`,
257
+ // `.tsx`) first, then `.d.ts` as a last-resort schema source
258
+ // for compiled packages. Dedupe by component name so a package
259
+ // shipping BOTH `Card.tsx` and `Card.d.ts` uses the source
260
+ // file (more reliable schema) and ignores the declaration.
261
+ const sourceFiles = await fg('**/*.{astro,tsx}', {
262
+ cwd: packageRoot,
263
+ absolute: true,
264
+ dot: false,
265
+ deep: 4,
266
+ });
267
+ const dtsFiles = await fg('**/*.d.ts', {
268
+ cwd: packageRoot,
269
+ absolute: true,
270
+ dot: false,
271
+ deep: 4,
272
+ });
273
+ const seen = new Set<string>();
274
+ scanFiles = [];
275
+ for (const file of [...sourceFiles, ...dtsFiles]) {
276
+ const name = componentNameFromPath(file);
277
+ if (seen.has(name)) continue;
278
+ seen.add(name);
279
+ scanFiles.push(file);
280
+ }
281
+ }
282
+
283
+ for (const file of scanFiles) {
284
+ try {
285
+ const r = await scanExternalFile(file, specifier, project);
286
+ if (r) results.push(r);
287
+ } catch (err) {
288
+ console.warn(`[conloca:discovery] failed to scan ${file}:`, err instanceof Error ? err.message : err);
289
+ }
290
+ }
291
+ } catch (err) {
292
+ // Resolution failures are common and expected — a `./local.css`
293
+ // import or a missing optional peer dep both land here. Skip
294
+ // quietly rather than failing the whole registry build.
295
+ console.warn(
296
+ `[conloca:discovery] could not resolve '${specifier}' from ${projectRoot}:`,
297
+ err instanceof Error ? err.message : err,
298
+ );
299
+ }
300
+ }
301
+
302
+ return results;
303
+ }
304
+
305
+ /**
306
+ * Same parsing as `scanFile`, but with `source` set to the original
307
+ * npm specifier instead of the absolute file path. See the function
308
+ * doc on `scanExternalComponents` for why.
309
+ */
310
+ async function scanExternalFile(
311
+ filepath: string,
312
+ specifier: string,
313
+ project: Project,
314
+ ): Promise<LocalComponentScanResult | null> {
315
+ const content = await readFile(filepath, 'utf8');
316
+ const name = componentNameFromPath(filepath);
317
+ if (!/^[A-Z]/.test(name)) return null;
318
+ const props = extractPropsForFile(project, filepath, content, name);
319
+ return {
320
+ filepath,
321
+ name,
322
+ // CRITICAL: source = specifier (not filepath) so merge-registry
323
+ // joins this entry with MDX-usage entries that key on the same
324
+ // specifier. See the merge logic at `byKey` in merge-registry.ts.
325
+ source: specifier,
326
+ kind: 'flow',
327
+ props,
328
+ };
329
+ }
330
+
331
+ /**
332
+ * Pick out unique npm-style specifiers from every import seen in the
333
+ * MDX scan. Local paths (`./foo`, `/abs`) are dropped — `scanLocalComponents`
334
+ * covers those via its folder glob.
335
+ */
336
+ function collectExternalSpecifiers(mdxScans: MdxScanResult[]): Set<string> {
337
+ const out = new Set<string>();
338
+ for (const scan of mdxScans) {
339
+ for (const imp of Object.values(scan.imports)) {
340
+ const src = imp.source;
341
+ if (!src) continue;
342
+ // Local-path indicators per ESM spec: starts with `.` (`./foo`,
343
+ // `../bar`) or `/` (absolute). Everything else is treated as
344
+ // npm-resolvable.
345
+ if (src.startsWith('.') || src.startsWith('/')) continue;
346
+ out.add(src);
347
+ }
348
+ }
349
+ return out;
350
+ }
351
+
352
+ /**
353
+ * If `resolvedFile` is a barrel (re-export aggregator), return the
354
+ * absolute paths of every re-exported component file. Otherwise
355
+ * return an empty array.
356
+ *
357
+ * Patterns recognized:
358
+ * - `export { default as Foo } from './path/to/Foo.astro'`
359
+ * - `export { Foo } from './path/to/Foo'`
360
+ * - `export { Foo, Bar } from './path/to/m'`
361
+ * - `export * from './path/to/m'` (treated as opaque — we
362
+ * can't enumerate the
363
+ * names without a real
364
+ * parser, so we skip and
365
+ * fall back to glob-all)
366
+ *
367
+ * The barrel must resolve to a real file we can re-resolve to one of
368
+ * the supported extensions (`.astro`, `.tsx`, `.d.ts`). Missing or
369
+ * unsupported targets are dropped quietly. Comments are stripped
370
+ * first to avoid matching commented-out exports.
371
+ *
372
+ * Why this matters: Starlight's `@astrojs/starlight/components`
373
+ * barrel lists exactly the 12 MDX-friendly components. Globbing the
374
+ * whole package would also pull in ~30 internal layout components
375
+ * (Banner, Hero, Pagination, ...) — they'd litter the slash menu
376
+ * even though they're not meant for author use.
377
+ */
378
+ async function collectBarrelExports(resolvedFile: string, packageRoot: string): Promise<string[]> {
379
+ // Only `.ts` / `.js` / `.mjs` source files can be barrels; an
380
+ // `.astro` or `.tsx` file is the component itself, not an
381
+ // aggregator. Bail early to avoid reading binary or unsupported
382
+ // file types.
383
+ if (!/\.(?:m?[jt]s)$/.test(resolvedFile)) return [];
384
+
385
+ let content: string;
386
+ try {
387
+ content = await readFile(resolvedFile, 'utf8');
388
+ } catch {
389
+ return [];
390
+ }
391
+ const cleaned = content.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^:])\/\/[^\n]*/g, '$1');
392
+
393
+ // Collect the relative source paths from every `export {...} from '<path>'`.
394
+ // We don't need the export names here — we just need the files to
395
+ // scan. Each scanned file's component name comes from its own
396
+ // basename, the same way local components work.
397
+ const pathRe = /export\s*(?:\{[^}]*\}|\*)\s*from\s*['"]([^'"]+)['"]/g;
398
+ const relPaths = new Set<string>();
399
+ for (const m of cleaned.matchAll(pathRe)) {
400
+ const rel = m[1];
401
+ // Skip `export *` — we can't enumerate without a real parser, and
402
+ // re-running the barrel collector recursively would invite cycles.
403
+ // Falls through to glob-all below if no other re-exports exist.
404
+ if (!rel) continue;
405
+ relPaths.add(rel);
406
+ }
407
+ if (relPaths.size === 0) return [];
408
+
409
+ // Resolve each relative path. `import.meta.resolve` doesn't take a
410
+ // base file, so use the barrel's directory as the resolution root.
411
+ const barrelDir = dirname(resolvedFile);
412
+ const requireFromBarrel = createRequire(`${barrelDir}/_.js`);
413
+ const resolved: string[] = [];
414
+ for (const rel of relPaths) {
415
+ try {
416
+ const target = requireFromBarrel.resolve(rel);
417
+ // Only keep targets that look like component files we can
418
+ // scan (extensions our extractor supports) AND live inside
419
+ // the package root (defensive — barrels in the wild can
420
+ // re-export from sibling packages, which we don't want to
421
+ // descend into).
422
+ if (!/\.(?:astro|tsx|d\.ts)$/.test(target)) continue;
423
+ if (!target.startsWith(packageRoot)) continue;
424
+ resolved.push(target);
425
+ } catch {
426
+ // Missing optional file or extension we don't handle — skip.
427
+ }
428
+ }
429
+ return resolved;
430
+ }
431
+
432
+ /**
433
+ * Walk up from a resolved file path until we find the directory that
434
+ * contains the closest `package.json`. That's the package root we'll
435
+ * glob for component files. Returns `null` if no package.json is found
436
+ * within a reasonable depth (defensive — shouldn't happen for a real
437
+ * resolution).
438
+ */
439
+ function findPackageRoot(resolvedPath: string): string | null {
440
+ let dir = dirname(resolvedPath);
441
+ for (let i = 0; i < 10; i++) {
442
+ // Sync existsSync is fine here — the walk is at most ~10 hops per
443
+ // package and runs once per unique specifier per scan.
444
+ if (existsSync(`${dir}/package.json`)) return dir;
445
+ const parent = dirname(dir);
446
+ if (parent === dir) return null;
447
+ dir = parent;
448
+ }
449
+ return null;
450
+ }
451
+
452
+ // Prop extraction lives in `./extract-props-ts.ts` (TypeScript
453
+ // compiler API via ts-morph). The previous regex-based scanner —
454
+ // `extractPropsInterface` + `parseTypeExpr` — was removed in the
455
+ // migration: it silently dropped options for derived types like
456
+ // `(typeof asideVariants)[number]`, mapped types, conditional types,
457
+ // and imported aliases. The ts-morph path resolves all of those.
458
+ // Astro frontmatter extraction lives in `./astro-frontmatter.ts`.
@@ -0,0 +1,190 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import fg from 'fast-glob';
3
+ import { fromMarkdown } from 'mdast-util-from-markdown';
4
+ import { mdxFromMarkdown } from 'mdast-util-mdx';
5
+ import { mdxjs } from 'micromark-extension-mdxjs';
6
+
7
+ /**
8
+ * Walks the content directory for `.mdx` files, parses each one, and
9
+ * returns a per-file record of:
10
+ *
11
+ * - **imports** — every `import { Foo, Bar as Baz } from 'pkg'` /
12
+ * `import Default from 'pkg'` declaration in the file's ESM
13
+ * header, keyed by the LOCAL name as seen in the JSX usages
14
+ * below. The `aliasedFrom` field records when the local name
15
+ * differs from the canonical export, so the save serializer can
16
+ * preserve the alias when rewriting the file.
17
+ *
18
+ * - **usages** — every `<Foo>` / `<Foo />` element in the file's
19
+ * body, in source order, with its observed string attributes.
20
+ *
21
+ * The merge step (downstream) joins each usage to its import via
22
+ * the local name to build the final component descriptor list.
23
+ *
24
+ * Parsing uses `mdast-util-from-markdown` with the full MDX extension
25
+ * bundle (`micromark-extension-mdxjs` + `mdast-util-mdx`) — the same
26
+ * stack the editor uses on every save, so what we observe here is
27
+ * exactly what the editor's save path can round-trip.
28
+ */
29
+ export interface MdxImport {
30
+ /** The npm-style or relative source path. */
31
+ source: string;
32
+ /** True for `import Foo from '...'`; false for named imports. */
33
+ defaultExport: boolean;
34
+ /** The canonical export name on the package side. For
35
+ * `import { Aside as Callout }`, this is `'Aside'` while the
36
+ * local key is `'Callout'`. For default imports this is `'default'`. */
37
+ exportName: string;
38
+ /** Local alias used in this file, if it differs from `exportName`.
39
+ * `undefined` when the file uses the canonical name unchanged. */
40
+ aliasedFrom?: string;
41
+ }
42
+
43
+ export interface MdxUsage {
44
+ /** The local name used in the JSX tag — `<Foo>` → `'Foo'`. */
45
+ name: string;
46
+ /** Observed attributes as raw strings. Expression-valued attrs
47
+ * (`prop={42}`) and complex values are not captured here; this
48
+ * field is for inferring "values seen in real usage" to populate
49
+ * dropdown choices on the prop panel. */
50
+ attrs: Record<string, string>;
51
+ /** `'flow'` (block-level) or `'text'` (inline-level) — matches the
52
+ * mdast node type. Used to set the descriptor's `kind`. */
53
+ kind: 'flow' | 'text';
54
+ }
55
+
56
+ export interface MdxScanResult {
57
+ /** Absolute path of the scanned file. */
58
+ filepath: string;
59
+ /** Local name → import declaration. */
60
+ imports: Record<string, MdxImport>;
61
+ /** All JSX usages in document order. */
62
+ usages: MdxUsage[];
63
+ }
64
+
65
+ /**
66
+ * Scan every `.mdx` file under `rootDir` (recursive). Returns one
67
+ * result per file. Files that fail to parse are skipped with a
68
+ * warning rather than throwing — the discovery flow shouldn't take
69
+ * down the dev server on a single broken file.
70
+ */
71
+ export async function scanMdxFiles(rootDir: string): Promise<MdxScanResult[]> {
72
+ const files = await fg('**/*.mdx', { cwd: rootDir, absolute: true, dot: false });
73
+ const results: MdxScanResult[] = [];
74
+ for (const file of files) {
75
+ try {
76
+ results.push(await scanFile(file));
77
+ } catch (err) {
78
+ console.warn(`[conloca:discovery] failed to scan ${file}:`, err instanceof Error ? err.message : err);
79
+ }
80
+ }
81
+ return results;
82
+ }
83
+
84
+ async function scanFile(filepath: string): Promise<MdxScanResult> {
85
+ const content = await readFile(filepath, 'utf8');
86
+ const tree = fromMarkdown(content, {
87
+ extensions: [mdxjs()],
88
+ mdastExtensions: [mdxFromMarkdown()],
89
+ });
90
+
91
+ const imports: Record<string, MdxImport> = {};
92
+ const usages: MdxUsage[] = [];
93
+
94
+ walk(tree, (node) => {
95
+ if (isEsmNode(node)) {
96
+ collectImports(node, imports);
97
+ } else if (node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') {
98
+ const name = typeof node.name === 'string' ? node.name : '';
99
+ if (!name) return;
100
+ const attrs: Record<string, string> = {};
101
+ const rawAttrs = (node.attributes as Array<{ type?: string; name?: unknown; value?: unknown }> | undefined) ?? [];
102
+ for (const a of rawAttrs) {
103
+ if (a.type !== 'mdxJsxAttribute' || typeof a.name !== 'string') continue;
104
+ if (typeof a.value === 'string') {
105
+ attrs[a.name] = a.value;
106
+ }
107
+ // Expression values (`prop={...}`) and null (boolean
108
+ // shorthand) are intentionally ignored here — they don't
109
+ // contribute to the "observed string values" we use to
110
+ // suggest dropdown options. The full attribute set per node
111
+ // lives in the editor's mdast node anyway.
112
+ }
113
+ usages.push({
114
+ name,
115
+ attrs,
116
+ kind: node.type === 'mdxJsxFlowElement' ? 'flow' : 'text',
117
+ });
118
+ }
119
+ });
120
+
121
+ return { filepath, imports, usages };
122
+ }
123
+
124
+ function isEsmNode(node: { type?: string }): node is EsmNode {
125
+ return node.type === 'mdxjsEsm';
126
+ }
127
+
128
+ interface EsmNode {
129
+ type: 'mdxjsEsm';
130
+ value?: string;
131
+ data?: { estree?: { body?: EstreeStatement[] } };
132
+ }
133
+
134
+ interface EstreeStatement {
135
+ type: string;
136
+ source?: { value?: string };
137
+ specifiers?: EstreeImportSpec[];
138
+ }
139
+
140
+ interface EstreeImportSpec {
141
+ type: 'ImportDefaultSpecifier' | 'ImportSpecifier' | 'ImportNamespaceSpecifier';
142
+ imported?: { type?: string; name?: string; value?: string };
143
+ local: { name: string };
144
+ }
145
+
146
+ function collectImports(esmNode: EsmNode, out: Record<string, MdxImport>): void {
147
+ const estree = esmNode.data?.estree;
148
+ if (!estree?.body) return;
149
+ for (const stmt of estree.body) {
150
+ if (stmt.type !== 'ImportDeclaration') continue;
151
+ const source = stmt.source?.value;
152
+ if (typeof source !== 'string') continue;
153
+ for (const spec of stmt.specifiers ?? []) {
154
+ const local = spec.local?.name;
155
+ if (typeof local !== 'string') continue;
156
+ if (spec.type === 'ImportDefaultSpecifier') {
157
+ out[local] = { source, defaultExport: true, exportName: 'default' };
158
+ } else if (spec.type === 'ImportSpecifier') {
159
+ const exportName =
160
+ spec.imported?.type === 'Identifier'
161
+ ? spec.imported.name
162
+ : typeof spec.imported?.value === 'string'
163
+ ? spec.imported.value
164
+ : local;
165
+ out[local] = {
166
+ source,
167
+ defaultExport: false,
168
+ exportName: exportName ?? local,
169
+ ...(exportName && exportName !== local ? { aliasedFrom: exportName } : {}),
170
+ };
171
+ }
172
+ // ImportNamespaceSpecifier (`import * as X`) is rare in MDX and
173
+ // wouldn't produce a usable component descriptor on its own —
174
+ // we'd see `<X.Foo>` namespaced usages we don't model. Skip.
175
+ }
176
+ }
177
+ }
178
+
179
+ /** Depth-first walk; visits every node including the root. */
180
+ function walk(
181
+ node: { type?: string; children?: unknown[] },
182
+ fn: (n: { type?: string } & Record<string, unknown>) => void,
183
+ ): void {
184
+ fn(node as { type?: string } & Record<string, unknown>);
185
+ if (Array.isArray((node as { children?: unknown[] }).children)) {
186
+ for (const child of (node as { children?: unknown[] }).children!) {
187
+ if (child && typeof child === 'object') walk(child as { type?: string; children?: unknown[] }, fn);
188
+ }
189
+ }
190
+ }