@homepages/concrete 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +174 -0
  3. package/codemods/manifest.json +9 -0
  4. package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
  5. package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
  6. package/dist/artifact/playground/client/index.html +13 -0
  7. package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
  8. package/dist/artifact/playground/host.mjs +127 -0
  9. package/dist/asset-modules.d.ts +99 -0
  10. package/dist/base.css +220 -0
  11. package/dist/browser/site-config.d.ts +18 -0
  12. package/dist/browser/site-config.js +56 -0
  13. package/dist/browser/submit-lead.d.ts +98 -0
  14. package/dist/browser/submit-lead.js +188 -0
  15. package/dist/browser.d.ts +3 -0
  16. package/dist/browser.js +4 -0
  17. package/dist/cli/build/artifact.js +225 -0
  18. package/dist/cli/build/captures.js +67 -0
  19. package/dist/cli/build/esbuild.js +127 -0
  20. package/dist/cli/build/fixtures.js +96 -0
  21. package/dist/cli/build/icons.js +76 -0
  22. package/dist/cli/build/index.js +38 -0
  23. package/dist/cli/build/playground.js +31 -0
  24. package/dist/cli/build/sections.js +236 -0
  25. package/dist/cli/build/source.js +62 -0
  26. package/dist/cli/build/static.js +156 -0
  27. package/dist/cli/capture/bundle.js +37 -0
  28. package/dist/cli/capture/capture-browser.js +51 -0
  29. package/dist/cli/capture/capture.js +121 -0
  30. package/dist/cli/check/analyze.js +95 -0
  31. package/dist/cli/check/index.js +19 -0
  32. package/dist/cli/check/load-workspace.js +119 -0
  33. package/dist/cli/check/messages.js +16 -0
  34. package/dist/cli/check/render/class-conflicts.js +39 -0
  35. package/dist/cli/check/render/html.js +86 -0
  36. package/dist/cli/check/render/inputs.js +53 -0
  37. package/dist/cli/check/render/invariants.js +58 -0
  38. package/dist/cli/check/render/island-frames.js +72 -0
  39. package/dist/cli/check/render/marker-coverage.js +102 -0
  40. package/dist/cli/check/render/nav.js +64 -0
  41. package/dist/cli/check/report.js +73 -0
  42. package/dist/cli/check/stages/bundles.js +129 -0
  43. package/dist/cli/check/stages/composition.js +67 -0
  44. package/dist/cli/check/stages/contracts.js +22 -0
  45. package/dist/cli/check/stages/dependencies.js +261 -0
  46. package/dist/cli/check/stages/fixtures.js +74 -0
  47. package/dist/cli/check/stages/lint.js +41 -0
  48. package/dist/cli/check/stages/logic.js +63 -0
  49. package/dist/cli/check/stages/render.js +144 -0
  50. package/dist/cli/check/stages/sections.js +83 -0
  51. package/dist/cli/check/stages/stylesheet.js +31 -0
  52. package/dist/cli/check/stages/typecheck.js +68 -0
  53. package/dist/cli/check/stages/workspace.js +26 -0
  54. package/dist/cli/commands.js +342 -0
  55. package/dist/cli/currency/cache.js +89 -0
  56. package/dist/cli/currency/decide.js +65 -0
  57. package/dist/cli/currency/opt-out.js +16 -0
  58. package/dist/cli/currency/preamble.js +183 -0
  59. package/dist/cli/currency/prompt.js +28 -0
  60. package/dist/cli/currency/refresh.js +44 -0
  61. package/dist/cli/currency/resolve-latest.js +185 -0
  62. package/dist/cli/currency/version-order.js +38 -0
  63. package/dist/cli/dev/crop.js +22 -0
  64. package/dist/cli/dev/hmr.js +26 -0
  65. package/dist/cli/dev/http.js +129 -0
  66. package/dist/cli/dev/index.js +70 -0
  67. package/dist/cli/dev/islands.js +390 -0
  68. package/dist/cli/dev/load-template.js +46 -0
  69. package/dist/cli/dev/request-error.js +22 -0
  70. package/dist/cli/dev/server.js +307 -0
  71. package/dist/cli/dev/tsconfig-paths.js +95 -0
  72. package/dist/cli/dev/vite.js +85 -0
  73. package/dist/cli/dev/workspace-reader.js +274 -0
  74. package/dist/cli/io.d.ts +14 -0
  75. package/dist/cli/media/cache.js +125 -0
  76. package/dist/cli/media/derive.js +252 -0
  77. package/dist/cli/media/deriver-plugin.js +71 -0
  78. package/dist/cli/property/index.js +180 -0
  79. package/dist/cli/property/library.js +137 -0
  80. package/dist/cli/publish/client.js +119 -0
  81. package/dist/cli/publish/freshness.js +66 -0
  82. package/dist/cli/publish/git.js +43 -0
  83. package/dist/cli/publish/index.js +207 -0
  84. package/dist/cli/publish/pack.js +78 -0
  85. package/dist/cli/publish/report.js +98 -0
  86. package/dist/cli/publish/target.js +87 -0
  87. package/dist/cli/publish/wire.js +29 -0
  88. package/dist/cli/tar.js +87 -0
  89. package/dist/cli/upgrade/codemod.js +56 -0
  90. package/dist/cli/upgrade/index.js +263 -0
  91. package/dist/cli/upgrade/manifest.js +72 -0
  92. package/dist/cli/upgrade/plan.js +68 -0
  93. package/dist/cli/upgrade/stage.js +71 -0
  94. package/dist/cli/version.d.ts +12 -0
  95. package/dist/cli/version.js +15 -0
  96. package/dist/cli/workspace.js +108 -0
  97. package/dist/cli.d.ts +6 -0
  98. package/dist/cli.js +94 -0
  99. package/dist/css/compile.js +77 -0
  100. package/dist/css/graph.js +109 -0
  101. package/dist/css/inline.js +132 -0
  102. package/dist/css/rules.js +65 -0
  103. package/dist/design-system/format-variants.js +127 -0
  104. package/dist/eslint/authoring.js +46 -0
  105. package/dist/eslint/correctness.js +42 -0
  106. package/dist/eslint/rules/editor-declaration.js +103 -0
  107. package/dist/eslint/rules/editor-reason.js +135 -0
  108. package/dist/eslint/rules/island-imports.js +20 -0
  109. package/dist/eslint/rules/jsx-visitor.js +20 -0
  110. package/dist/eslint/rules/no-client-runtime.js +88 -0
  111. package/dist/eslint/rules/no-editor-globals.js +60 -0
  112. package/dist/eslint/rules/no-hard-coded-color.js +183 -0
  113. package/dist/eslint/rules/no-inline-style.js +24 -0
  114. package/dist/eslint/rules/no-marker-literal.js +37 -0
  115. package/dist/eslint/rules/no-nondeterminism.js +44 -0
  116. package/dist/eslint/rules/no-px-breakpoint.js +44 -0
  117. package/dist/eslint/rules/no-raw-values.js +45 -0
  118. package/dist/eslint/rules/serializable-props.js +95 -0
  119. package/dist/eslint.d.ts +6 -0
  120. package/dist/eslint.js +26 -0
  121. package/dist/fixtures/brand.d.ts +4 -0
  122. package/dist/fixtures/brand.js +9 -0
  123. package/dist/fixtures/bundle-rule.js +67 -0
  124. package/dist/fixtures/canonical.d.ts +149 -0
  125. package/dist/fixtures/image-dimensions.js +59 -0
  126. package/dist/fixtures/load.js +154 -0
  127. package/dist/fixtures/media-plugin.js +141 -0
  128. package/dist/fixtures/media.js +165 -0
  129. package/dist/fixtures/property.js +210 -0
  130. package/dist/fixtures/resolve.js +202 -0
  131. package/dist/fixtures/rows.js +108 -0
  132. package/dist/fixtures/synthesize-empties.js +42 -0
  133. package/dist/fixtures.d.ts +213 -0
  134. package/dist/fixtures.js +37 -0
  135. package/dist/index.d.ts +53 -0
  136. package/dist/index.js +37 -0
  137. package/dist/islands/client-module.js +97 -0
  138. package/dist/islands/marker.d.ts +43 -0
  139. package/dist/islands/marker.js +44 -0
  140. package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
  141. package/dist/packages/external/concrete/package.js +5 -0
  142. package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
  143. package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
  144. package/dist/packages/internal/fill-bake/dist/display.js +9 -0
  145. package/dist/packages/internal/fill-bake/dist/index.js +6 -0
  146. package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
  147. package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
  148. package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
  149. package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
  150. package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
  151. package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
  152. package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
  153. package/dist/packages/internal/format-geometry/dist/index.js +4 -0
  154. package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
  155. package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
  156. package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
  157. package/dist/packages/internal/image-ladder/dist/index.js +4 -0
  158. package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
  159. package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
  160. package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
  161. package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
  162. package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
  163. package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
  164. package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
  165. package/dist/packages/internal/island-runtime/dist/index.js +163 -0
  166. package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
  167. package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
  168. package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
  169. package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
  170. package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
  171. package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
  172. package/dist/packages/internal/property-facts/dist/index.js +3 -0
  173. package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
  174. package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
  175. package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
  176. package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
  177. package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
  178. package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
  179. package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
  180. package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
  181. package/dist/packages/internal/section-contracts/dist/index.js +26 -0
  182. package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
  183. package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
  184. package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
  185. package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
  186. package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
  187. package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
  188. package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
  189. package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
  190. package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
  191. package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
  192. package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
  193. package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
  194. package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
  195. package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
  196. package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
  197. package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
  198. package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
  199. package/dist/packages/internal/source-resolution/dist/index.js +222 -0
  200. package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
  201. package/dist/packages/internal/template-artifact/dist/index.js +7 -0
  202. package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
  203. package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
  204. package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
  205. package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
  206. package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
  207. package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
  208. package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
  209. package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
  210. package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
  211. package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
  212. package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
  213. package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
  214. package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
  215. package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
  216. package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
  217. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
  218. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
  219. package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
  220. package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
  221. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
  222. package/dist/playground/host/page-state.js +12 -0
  223. package/dist/playground/host/paths.js +9 -0
  224. package/dist/playground/layout.js +24 -0
  225. package/dist/playground/wire.js +36 -0
  226. package/dist/playground-island-runtime.d.ts +3 -0
  227. package/dist/playground-island-runtime.js +4 -0
  228. package/dist/primitives/FrameShell.d.ts +29 -0
  229. package/dist/primitives/FrameShell.js +34 -0
  230. package/dist/primitives/Image.d.ts +119 -0
  231. package/dist/primitives/Image.js +173 -0
  232. package/dist/primitives/Section.d.ts +22 -0
  233. package/dist/primitives/Section.js +26 -0
  234. package/dist/primitives/Tour.d.ts +43 -0
  235. package/dist/primitives/Tour.js +72 -0
  236. package/dist/primitives/Video.d.ts +57 -0
  237. package/dist/primitives/Video.js +116 -0
  238. package/dist/primitives/embed-playback.js +50 -0
  239. package/dist/primitives/index.d.ts +11 -0
  240. package/dist/primitives/marker-attrs.js +44 -0
  241. package/dist/primitives/object-fit.js +11 -0
  242. package/dist/primitives/picture-sources.d.ts +24 -0
  243. package/dist/primitives/picture-sources.js +52 -0
  244. package/dist/primitives/probe-context.js +24 -0
  245. package/dist/primitives/slot-bindings.d.ts +96 -0
  246. package/dist/primitives/slot-bindings.js +226 -0
  247. package/dist/primitives/slot-document.d.ts +35 -0
  248. package/dist/primitives/slot-document.js +37 -0
  249. package/dist/primitives/slot-group.d.ts +40 -0
  250. package/dist/primitives/slot-group.js +45 -0
  251. package/dist/primitives/slot-list.d.ts +21 -0
  252. package/dist/primitives/slot-list.js +23 -0
  253. package/dist/primitives/slot-media.d.ts +71 -0
  254. package/dist/primitives/slot-media.js +98 -0
  255. package/dist/primitives/slot-scalar.d.ts +53 -0
  256. package/dist/primitives/slot-scalar.js +98 -0
  257. package/dist/primitives/slot.d.ts +26 -0
  258. package/dist/primitives/slot.js +28 -0
  259. package/dist/rules/registry.js +479 -0
  260. package/dist/schema/compute.d.ts +22 -0
  261. package/dist/schema/compute.js +30 -0
  262. package/dist/schema/define-schema.d.ts +27 -0
  263. package/dist/schema/define-schema.js +73 -0
  264. package/dist/schema/extract-fill-spec.js +246 -0
  265. package/dist/schema/extract-used-facts.js +176 -0
  266. package/dist/schema/fact.d.ts +65 -0
  267. package/dist/schema/fact.js +33 -0
  268. package/dist/schema/fill-builders.d.ts +387 -0
  269. package/dist/schema/fill-builders.js +263 -0
  270. package/dist/schema/fill-declaration.d.ts +76 -0
  271. package/dist/schema/fill-declaration.js +43 -0
  272. package/dist/schema/fill-spec.d.ts +18 -0
  273. package/dist/schema/fill-spec.js +170 -0
  274. package/dist/schema/format-presets.d.ts +27 -0
  275. package/dist/schema/format-presets.js +76 -0
  276. package/dist/schema/format.d.ts +22 -0
  277. package/dist/schema/format.js +40 -0
  278. package/dist/schema/formats.d.ts +6 -0
  279. package/dist/schema/formats.js +7 -0
  280. package/dist/schema/layout.d.ts +32 -0
  281. package/dist/schema/layout.js +30 -0
  282. package/dist/schema/manifest.js +300 -0
  283. package/dist/schema/property-facts.d.ts +83 -0
  284. package/dist/schema/runtime-values.d.ts +88 -0
  285. package/dist/schema/section-nav.d.ts +38 -0
  286. package/dist/schema/section-nav.js +29 -0
  287. package/dist/schema/section-props.d.ts +98 -0
  288. package/dist/schema/section-schema.d.ts +53 -0
  289. package/dist/schema/section-schema.js +54 -0
  290. package/dist/schema/slot-builders.d.ts +497 -0
  291. package/dist/schema/slot-builders.js +331 -0
  292. package/dist/schema/slot-types.d.ts +110 -0
  293. package/dist/schema/slot-types.js +187 -0
  294. package/dist/section/declare.d.ts +44 -0
  295. package/dist/section/declare.js +27 -0
  296. package/dist/section/discovery.js +76 -0
  297. package/dist/section/groups.js +74 -0
  298. package/dist/section/materialize.js +28 -0
  299. package/dist/section/placements.js +28 -0
  300. package/dist/section/section.d.ts +69 -0
  301. package/dist/section/section.js +101 -0
  302. package/dist/site-analytics.d.ts +1 -0
  303. package/dist/site-analytics.js +15 -0
  304. package/dist/site-runtime/analytics.js +97 -0
  305. package/dist/site-runtime/site-integrations.js +97 -0
  306. package/dist/styles.css +60 -0
  307. package/dist/template/define-template.d.ts +139 -0
  308. package/dist/template/define-template.js +98 -0
  309. package/dist/template/logic-build.js +191 -0
  310. package/dist/template/logic-shim.d.ts +43 -0
  311. package/dist/template/logic-shim.js +52 -0
  312. package/dist/template/logic-transform.js +92 -0
  313. package/dist/template/materialize.js +107 -0
  314. package/dist/template/reconcile.d.ts +67 -0
  315. package/dist/template/reconcile.js +25 -0
  316. package/dist/template/running-copy.js +58 -0
  317. package/guide/reference/cli/INDEX.md +79 -0
  318. package/guide/reference/cli/build.md +48 -0
  319. package/guide/reference/cli/check.md +49 -0
  320. package/guide/reference/cli/dev.md +46 -0
  321. package/guide/reference/cli/property-add.md +53 -0
  322. package/guide/reference/cli/property-list.md +46 -0
  323. package/guide/reference/cli/publish.md +54 -0
  324. package/guide/reference/cli/upgrade.md +48 -0
  325. package/guide/reference/rules/INDEX.md +190 -0
  326. package/package.json +137 -0
  327. package/tsconfig.base.json +16 -0
@@ -0,0 +1,127 @@
1
+ import { MEDIA_LOADERS } from "../../fixtures/media-plugin.js";
2
+ import { runningCopyEntries } from "../../template/running-copy.js";
3
+ import { basename, dirname, extname, join } from "node:path";
4
+ import { readFile } from "node:fs/promises";
5
+
6
+ //#region src/cli/build/esbuild.ts
7
+ /** The URL prefix every author asset a bundle references is baked under. */
8
+ const ASSET_PUBLIC_PATH = "/section-assets";
9
+ /** Content-hashed asset names, as the platform's asset store keys them. */
10
+ const ASSET_NAMES = "[name]-[hash]";
11
+ const CONTENT_TYPES = {
12
+ ".svg": "image/svg+xml",
13
+ ".png": "image/png",
14
+ ".jpg": "image/jpeg",
15
+ ".jpeg": "image/jpeg",
16
+ ".gif": "image/gif",
17
+ ".webp": "image/webp",
18
+ ".avif": "image/avif",
19
+ ".ico": "image/x-icon",
20
+ ".woff": "font/woff",
21
+ ".woff2": "font/woff2",
22
+ ".ttf": "font/ttf",
23
+ ".otf": "font/otf",
24
+ ".eot": "application/vnd.ms-fontobject",
25
+ ".mp4": "video/mp4",
26
+ ".webm": "video/webm",
27
+ ".mov": "video/quicktime",
28
+ ".mp3": "audio/mpeg",
29
+ ".wav": "audio/wav",
30
+ ".pdf": "application/pdf",
31
+ ".zip": "application/zip"
32
+ };
33
+ /** The content type an asset store serves a filename with. */
34
+ function assetContentType(filename) {
35
+ return CONTENT_TYPES[extname(filename).toLowerCase()] ?? "application/octet-stream";
36
+ }
37
+ const MANIFEST_NAMESPACE = "concrete-build-manifest";
38
+ /**
39
+ * Resolve `@homepages/concrete` and its subpaths to the running copy, bundled rather
40
+ * than external.
41
+ *
42
+ * Running from source, the barrel reads its version with a named import from its
43
+ * `package.json` under `with { type: "json" }`, which Node allows and esbuild refuses (a
44
+ * JSON module has only a default export). The built barrel carries the version inlined,
45
+ * so only a source run meets this: the package's own manifest is served to the pass as
46
+ * a module exporting its fields by name.
47
+ */
48
+ function bundledFrameworkPlugin() {
49
+ const entries = runningCopyEntries();
50
+ const framework = entries.get("@homepages/concrete");
51
+ const manifest = framework === void 0 ? void 0 : join(dirname(dirname(framework)), "package.json");
52
+ return {
53
+ name: "concrete-build-framework",
54
+ setup(build) {
55
+ build.onResolve({ filter: /^@homepages\/concrete(?:\/[a-z-]+)?$/ }, (args) => {
56
+ const path = entries.get(args.path);
57
+ return path === void 0 ? null : { path };
58
+ });
59
+ build.onResolve({ filter: /package\.json$/ }, (args) => {
60
+ const path = join(args.resolveDir, args.path);
61
+ return path === manifest ? {
62
+ path,
63
+ namespace: MANIFEST_NAMESPACE
64
+ } : null;
65
+ });
66
+ build.onLoad({
67
+ filter: /.*/,
68
+ namespace: MANIFEST_NAMESPACE
69
+ }, async (args) => {
70
+ const fields = JSON.parse(await readFile(args.path, "utf8"));
71
+ return {
72
+ contents: [...Object.entries(fields).filter(([name]) => /^[A-Za-z_$][\w$]*$/.test(name)).map(([name, value]) => `export const ${name} = ${JSON.stringify(value)};`), `export default ${JSON.stringify(fields)};`].join("\n"),
73
+ loader: "js"
74
+ };
75
+ });
76
+ }
77
+ };
78
+ }
79
+ /** The loader options every pass over workspace code takes: stylesheets empty, media through the file loader. */
80
+ function workspaceLoaders(root) {
81
+ return {
82
+ loader: {
83
+ ".css": "empty",
84
+ ...MEDIA_LOADERS
85
+ },
86
+ publicPath: ASSET_PUBLIC_PATH,
87
+ assetNames: ASSET_NAMES,
88
+ outdir: join(root, ".concrete", "cache", "build")
89
+ };
90
+ }
91
+ /** The non-JavaScript files a pass emitted, by filename. */
92
+ function emittedAssets(outputs) {
93
+ const byName = /* @__PURE__ */ new Map();
94
+ for (const file of outputs) {
95
+ const ext = extname(file.path).toLowerCase();
96
+ if (ext === ".js" || ext === ".mjs" || ext === ".css" || ext === ".map") continue;
97
+ const filename = basename(file.path);
98
+ if (!byName.has(filename)) byName.set(filename, {
99
+ filename,
100
+ bytes: file.contents,
101
+ contentType: assetContentType(filename)
102
+ });
103
+ }
104
+ return [...byName.values()];
105
+ }
106
+ /** The one JavaScript output of a single-entry pass. */
107
+ function javascriptOutput(outputs, what) {
108
+ const js = outputs?.find((file) => file.path.endsWith(".js")) ?? (outputs?.length === 1 ? outputs[0] : void 0);
109
+ if (js === void 0) throw new Error(`${what}: esbuild produced no JavaScript output.`);
110
+ return js.contents;
111
+ }
112
+ /** Run a pass, turning esbuild's failure into one error naming what was being built and where. */
113
+ async function runPass(what, pass) {
114
+ try {
115
+ return await pass();
116
+ } catch (cause) {
117
+ const errors = cause.errors;
118
+ if (!Array.isArray(errors)) throw cause;
119
+ const lines = errors.map((m) => {
120
+ return ` ${m.location === null ? "" : `${m.location.file}:${String(m.location.line)}: `}${m.text}`;
121
+ });
122
+ throw new Error(`${what} failed to bundle:\n${lines.join("\n")}`, { cause });
123
+ }
124
+ }
125
+
126
+ //#endregion
127
+ export { ASSET_NAMES, ASSET_PUBLIC_PATH, assetContentType, bundledFrameworkPlugin, emittedAssets, javascriptOutput, runPass, workspaceLoaders };
@@ -0,0 +1,96 @@
1
+ import { ASSET_URL_PREFIX, FIXTURE_FILES, fixturePath, isFixtureId } from "../../packages/internal/template-artifact/dist/layout.js";
2
+ import "../../packages/internal/template-artifact/dist/index.js";
3
+ import { deriveAuthorImage } from "../media/derive.js";
4
+ import { assetContentType } from "./esbuild.js";
5
+ import { mediaUrl } from "../../fixtures/property.js";
6
+ import { basename } from "node:path";
7
+ import { readFile } from "node:fs/promises";
8
+
9
+ //#region src/cli/build/fixtures.ts
10
+ const encoder = new TextEncoder();
11
+ const json = (value) => encoder.encode(`${JSON.stringify(value, null, 2)}\n`);
12
+ /** Every string in `value` that is a key of `urls`, replaced by its value. */
13
+ function rewriteUrls(value, urls) {
14
+ if (typeof value === "string") return urls.get(value) ?? value;
15
+ if (Array.isArray(value)) return value.map((item) => rewriteUrls(item, urls));
16
+ if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, inner]) => [key, rewriteUrls(inner, urls)]));
17
+ return value;
18
+ }
19
+ /** Build every authored fixture's files and the media they name. */
20
+ async function fixtureFiles(input) {
21
+ const files = /* @__PURE__ */ new Map();
22
+ const assets = /* @__PURE__ */ new Map();
23
+ const artifactFiles = /* @__PURE__ */ new Map();
24
+ const artifactFile = async (file) => {
25
+ const served = mediaUrl(file);
26
+ const known = artifactFiles.get(served);
27
+ if (known !== void 0) return known;
28
+ const source = input.assets.get(served);
29
+ if (source === void 0) throw new Error(`build: fixture media ${served} was not recorded by the fixture load.`);
30
+ const bytes = new Uint8Array(await readFile(source.path));
31
+ let result;
32
+ if (source.derived && typeof file !== "string") {
33
+ const derivation = await deriveAuthorImage(source.path, bytes, { cacheDir: input.cacheDir });
34
+ if (derivation.passthrough) throw new Error(`Fixture media ${source.path} could not be derived because \`sharp\` is not installed. An artifact carries every image's responsive ladder; reinstall so sharp's native binary lands, then build again.`);
35
+ for (const asset of [...derivation.derivatives, derivation.master]) assets.set(asset.filename, asset);
36
+ result = {
37
+ file: derivation.image,
38
+ urls: /* @__PURE__ */ new Map([[served, derivation.image.url]]),
39
+ bytes: bytes.byteLength
40
+ };
41
+ } else {
42
+ const filename = basename(served);
43
+ assets.set(filename, {
44
+ filename,
45
+ bytes,
46
+ contentType: assetContentType(filename)
47
+ });
48
+ const url = `${ASSET_URL_PREFIX}${filename}`;
49
+ result = {
50
+ file: url,
51
+ urls: /* @__PURE__ */ new Map([[served, url]]),
52
+ bytes: bytes.byteLength
53
+ };
54
+ }
55
+ artifactFiles.set(served, result);
56
+ return result;
57
+ };
58
+ const ids = [];
59
+ for (const fixture of input.fixtures) {
60
+ if (fixture.synthesized) continue;
61
+ if (!isFixtureId(fixture.id)) throw new Error(`Fixture "${fixture.id}" (${fixture.module}) cannot name an artifact directory: an id is one path segment of letters, digits, ".", "_" and "-". Rename the export.`);
62
+ ids.push(fixture.id);
63
+ const urls = /* @__PURE__ */ new Map();
64
+ const media = {};
65
+ for (const [id, entry] of fixture.media) {
66
+ if (entry.file === null) {
67
+ media[id] = entry;
68
+ continue;
69
+ }
70
+ const stored = await artifactFile(entry.file);
71
+ for (const [from, to] of stored.urls) urls.set(from, to);
72
+ media[id] = {
73
+ ...entry,
74
+ file: stored.file,
75
+ sizeBytes: stored.bytes
76
+ };
77
+ }
78
+ files.set(fixturePath(fixture.id, FIXTURE_FILES.contentDoc), json(fixture.contentDoc));
79
+ files.set(fixturePath(fixture.id, FIXTURE_FILES.property), json({
80
+ facts: rewriteUrls(fixture.facts, urls),
81
+ media
82
+ }));
83
+ files.set(fixturePath(fixture.id, FIXTURE_FILES.meta), json({
84
+ label: fixture.label,
85
+ provenance: fixture.provenance
86
+ }));
87
+ }
88
+ return {
89
+ files,
90
+ assets: [...assets.values()],
91
+ ids
92
+ };
93
+ }
94
+
95
+ //#endregion
96
+ export { fixtureFiles };
@@ -0,0 +1,76 @@
1
+ import { assetContentType } from "./esbuild.js";
2
+ import { extname } from "node:path";
3
+ import { readFile } from "node:fs/promises";
4
+ import { createHash } from "node:crypto";
5
+
6
+ //#region src/cli/build/icons.ts
7
+ const SITE_ICON_PNG_SIZES = [192];
8
+ const APPLE_TOUCH_ICON_SIZE = 180;
9
+ const ICO_SIZE = 32;
10
+ /** Wrap one PNG in an ICO container: ICONDIR, one ICONDIRENTRY, then the PNG verbatim. */
11
+ function pngToIco(png, size) {
12
+ const header = Buffer.alloc(22);
13
+ header.writeUInt16LE(0, 0);
14
+ header.writeUInt16LE(1, 2);
15
+ header.writeUInt16LE(1, 4);
16
+ header.writeUInt8(size >= 256 ? 0 : size, 6);
17
+ header.writeUInt8(size >= 256 ? 0 : size, 7);
18
+ header.writeUInt8(0, 8);
19
+ header.writeUInt8(0, 9);
20
+ header.writeUInt16LE(1, 10);
21
+ header.writeUInt16LE(32, 12);
22
+ header.writeUInt32LE(png.length, 14);
23
+ header.writeUInt32LE(22, 18);
24
+ return Buffer.concat([header, png]);
25
+ }
26
+ /** `icon-<16 hex of the master's sha256>`: the stem every derived file of one master shares. */
27
+ function siteIconStem(master) {
28
+ return `icon-${createHash("sha256").update(master).digest("hex").slice(0, 16)}`;
29
+ }
30
+ async function loadSharp() {
31
+ try {
32
+ return (await import("sharp")).default;
33
+ } catch {
34
+ throw new Error("The template's site icons cannot be derived: `sharp` is not installed. It is an optional dependency of @homepages/concrete; reinstall so its native binary lands, then build again.");
35
+ }
36
+ }
37
+ /** Derive the icon set from the master at `path`, an `.svg` or `.png`. */
38
+ async function deriveSiteIcons(path) {
39
+ const format = extname(path).toLowerCase();
40
+ if (format !== ".svg" && format !== ".png") throw new Error(`The template's icon must be an .svg or a .png; ${path} is neither.`);
41
+ const master = new Uint8Array(await readFile(path));
42
+ const sharp = await loadSharp();
43
+ const squarePng = (size) => sharp(master, { density: 300 }).resize(size, size, {
44
+ fit: "cover",
45
+ position: "centre"
46
+ }).png().toBuffer();
47
+ const stem = siteIconStem(master);
48
+ const assets = [];
49
+ const emit = (filename, bytes) => {
50
+ assets.push({
51
+ filename,
52
+ bytes,
53
+ contentType: assetContentType(filename)
54
+ });
55
+ return {
56
+ filename,
57
+ content_hash: createHash("sha256").update(bytes).digest("hex")
58
+ };
59
+ };
60
+ const ico = emit(`${stem}.ico`, pngToIco(await squarePng(32), 32));
61
+ const svg = format === ".svg" ? emit(`${stem}.svg`, master) : null;
62
+ const png = {};
63
+ for (const size of SITE_ICON_PNG_SIZES) png[String(size)] = emit(`${stem}-${String(size)}.png`, await squarePng(size));
64
+ return {
65
+ icons: {
66
+ ico,
67
+ svg,
68
+ png,
69
+ apple_touch: emit(`${stem}-${String(180)}.png`, await squarePng(180))
70
+ },
71
+ assets
72
+ };
73
+ }
74
+
75
+ //#endregion
76
+ export { SITE_ICON_PNG_SIZES, deriveSiteIcons, pngToIco, siteIconStem };
@@ -0,0 +1,38 @@
1
+ import { DEFAULT_BUILD_DIR, parseSpec, stringFlag } from "../commands.js";
2
+ import { formatHuman } from "../check/report.js";
3
+ import { buildArtifact } from "./artifact.js";
4
+ import { findWorkspaceRoot } from "../workspace.js";
5
+ import { resolve } from "node:path";
6
+ import { parseArgs } from "node:util";
7
+
8
+ //#region src/cli/build/index.ts
9
+ const runBuild = async (argv, io) => {
10
+ const { values } = parseArgs({
11
+ args: [...argv],
12
+ ...parseSpec("build")
13
+ });
14
+ const root = await findWorkspaceRoot(io.cwd);
15
+ const out = resolve(root, stringFlag(values, "out") ?? ".concrete/build");
16
+ let outcome;
17
+ try {
18
+ outcome = await buildArtifact({
19
+ root,
20
+ out
21
+ });
22
+ } catch (cause) {
23
+ io.stderr.write(`concrete build: ${cause instanceof Error ? cause.message : String(cause)}\n`);
24
+ return 1;
25
+ }
26
+ if (!outcome.ok) {
27
+ io.stderr.write(formatHuman(outcome.report));
28
+ io.stderr.write("concrete build: check is not green, so no artifact was written.\n");
29
+ return 1;
30
+ }
31
+ const { manifest } = outcome;
32
+ const count = manifest.sections.length;
33
+ io.stdout.write(`concrete build: wrote ${out} — template ${manifest.key} ${manifest.template.content_hash.slice(0, 12)}, ${String(count)} ${count === 1 ? "section" : "sections"}.\n`);
34
+ return 0;
35
+ };
36
+
37
+ //#endregion
38
+ export { runBuild };
@@ -0,0 +1,31 @@
1
+ import { PLAYGROUND_FILES, playgroundPath } from "../../packages/internal/template-artifact/dist/layout.js";
2
+ import "../../packages/internal/template-artifact/dist/index.js";
3
+ import { playgroundDistDir } from "../../playground/layout.js";
4
+ import { existsSync } from "node:fs";
5
+ import { dirname, join, relative, sep } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { readFile, readdir } from "node:fs/promises";
8
+
9
+ //#region src/cli/build/playground.ts
10
+ /** The package root: this module sits at `src/cli/build/` from source and `dist/cli/build/` built. */
11
+ function packageRoot() {
12
+ return join(dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
13
+ }
14
+ async function listFiles(dir) {
15
+ return (await readdir(dir, {
16
+ withFileTypes: true,
17
+ recursive: true
18
+ })).filter((entry) => entry.isFile()).map((entry) => join(entry.parentPath, entry.name));
19
+ }
20
+ /** Every playground file, by artifact-relative path, in path order. */
21
+ async function playgroundFiles(root = packageRoot()) {
22
+ const dir = playgroundDistDir(root);
23
+ for (const file of Object.values(PLAYGROUND_FILES)) if (!existsSync(join(dir, file))) throw new Error(`The framework's playground is not built (${join(dir, file)} is missing). Reinstall @homepages/concrete, or build the package from its checkout.`);
24
+ const out = /* @__PURE__ */ new Map();
25
+ const paths = (await listFiles(dir)).map((file) => relative(dir, file).split(sep).join("/")).sort();
26
+ for (const path of paths) out.set(playgroundPath(path), new Uint8Array(await readFile(join(dir, ...path.split("/")))));
27
+ return out;
28
+ }
29
+
30
+ //#endregion
31
+ export { playgroundFiles };
@@ -0,0 +1,236 @@
1
+ import { mediaCacheDir } from "../media/cache.js";
2
+ import { declaresNoServerFrame, stubClientModule, wrapClientModule } from "../dev/islands.js";
3
+ import { createMediaDeriver } from "../media/deriver-plugin.js";
4
+ import { bundledFrameworkPlugin, emittedAssets, javascriptOutput, runPass, workspaceLoaders } from "./esbuild.js";
5
+ import { basename, dirname, extname, join, relative, sep } from "node:path";
6
+ import { readFile } from "node:fs/promises";
7
+ import { createHash } from "node:crypto";
8
+ import { build } from "esbuild";
9
+
10
+ //#region src/cli/build/sections.ts
11
+ /** The bare specifiers every island chunk and the island runtime leave to the page's import map. */
12
+ const ISLAND_REACT_EXTERNALS = [
13
+ "react",
14
+ "react-dom",
15
+ "react-dom/client",
16
+ "react/jsx-runtime"
17
+ ];
18
+ const MARKER_SPECIFIER = "@homepages/concrete";
19
+ const COMPONENT_EXT = /\.[jt]sx$/;
20
+ function sanitizeKey(key) {
21
+ return key.replace(/[^a-z0-9]+/gi, "-");
22
+ }
23
+ function sha256(bytes) {
24
+ return createHash("sha256").update(bytes).digest("hex");
25
+ }
26
+ function inside(root, file) {
27
+ const prefix = root.endsWith(sep) ? root : root + sep;
28
+ return file.startsWith(prefix) && !file.includes(`${sep}node_modules${sep}`);
29
+ }
30
+ function islandKeyOf(sectionKey, file) {
31
+ return `${sectionKey}:${basename(file, extname(file))}`;
32
+ }
33
+ function loaderOf(file) {
34
+ return extname(file) === ".jsx" ? "jsx" : "tsx";
35
+ }
36
+ const toPosix = (path) => path.split(sep).join("/");
37
+ /**
38
+ * The server graph's island transform: wrap (or, when `stubFrameless`, stub) every
39
+ * workspace client module, recording each one and refusing two modules that would share
40
+ * one island key.
41
+ */
42
+ function serverIslandsPlugin(root, sectionKey, found, stubFrameless) {
43
+ return {
44
+ name: "concrete-build:islands-server",
45
+ setup(api) {
46
+ api.onLoad({ filter: COMPONENT_EXT }, async (args) => {
47
+ if (!inside(root, args.path)) return void 0;
48
+ const code = await readFile(args.path, "utf8");
49
+ const islandKey = islandKeyOf(sectionKey, args.path);
50
+ const contents = (stubFrameless ? stubClientModule(code, islandKey, MARKER_SPECIFIER) : null) ?? wrapClientModule(code, islandKey, MARKER_SPECIFIER);
51
+ if (contents === null) return void 0;
52
+ const prior = found.get(islandKey);
53
+ if (prior !== void 0 && prior !== args.path) throw new Error(`Section "${sectionKey}" reaches two island modules named ${basename(args.path)} (${prior} and ${args.path}); an island key is the module's file name, so rename one.`);
54
+ found.set(islandKey, args.path);
55
+ return {
56
+ contents,
57
+ loader: loaderOf(args.path),
58
+ resolveDir: dirname(args.path)
59
+ };
60
+ });
61
+ }
62
+ };
63
+ }
64
+ /** The browser graph's transform for one chunk: every client module but the entry is wrapped. */
65
+ function nestedIslandsPlugin(root, sectionKey, entry) {
66
+ return {
67
+ name: "concrete-build:islands-nested",
68
+ setup(api) {
69
+ api.onLoad({ filter: COMPONENT_EXT }, async (args) => {
70
+ if (args.path === entry || !inside(root, args.path)) return void 0;
71
+ const contents = wrapClientModule(await readFile(args.path, "utf8"), islandKeyOf(sectionKey, args.path), MARKER_SPECIFIER);
72
+ return contents === null ? void 0 : {
73
+ contents,
74
+ loader: loaderOf(args.path),
75
+ resolveDir: dirname(args.path)
76
+ };
77
+ });
78
+ }
79
+ };
80
+ }
81
+ function derivedAssets(deriver) {
82
+ return [...deriver.derived.values()].map((asset) => ({
83
+ filename: asset.filename,
84
+ bytes: asset.bytes,
85
+ contentType: asset.contentType
86
+ }));
87
+ }
88
+ /**
89
+ * The renderer pass. `stubFrameless: false` wraps every island for real, so a
90
+ * `serverFrame = false` island's server render is in the output: the bundle `check`
91
+ * grades that declaration against, never one that ships.
92
+ */
93
+ async function rendererPass(input, deriver, found, stubFrameless) {
94
+ const { root, key } = input;
95
+ return runPass(`The renderer bundle of section "${key}"`, async () => {
96
+ const result = await build({
97
+ stdin: {
98
+ contents: `export { ${input.exportName} as default } from ${JSON.stringify(input.module)};`,
99
+ resolveDir: root,
100
+ loader: "ts"
101
+ },
102
+ bundle: true,
103
+ format: "esm",
104
+ target: "es2022",
105
+ platform: "neutral",
106
+ mainFields: ["module", "main"],
107
+ minify: true,
108
+ write: false,
109
+ jsx: "automatic",
110
+ external: [
111
+ "react",
112
+ "react-dom",
113
+ "react/jsx-runtime"
114
+ ],
115
+ absWorkingDir: root,
116
+ ...workspaceLoaders(root),
117
+ plugins: [
118
+ bundledFrameworkPlugin(),
119
+ serverIslandsPlugin(root, key, found, stubFrameless),
120
+ deriver.plugin
121
+ ],
122
+ metafile: true,
123
+ logLevel: "silent"
124
+ });
125
+ return {
126
+ bytes: javascriptOutput(result.outputFiles, `section "${key}"`),
127
+ outputFiles: result.outputFiles,
128
+ metafile: result.metafile
129
+ };
130
+ });
131
+ }
132
+ /** Emitted asset filename → the workspace file it was copied from: an asset output has exactly one input. */
133
+ function sourcesOf(metafile) {
134
+ const byEmitted = /* @__PURE__ */ new Map();
135
+ for (const [out, meta] of Object.entries(metafile.outputs)) {
136
+ const inputs = Object.keys(meta.inputs);
137
+ if (inputs.length === 1) byEmitted.set(basename(out), inputs[0]);
138
+ }
139
+ return byEmitted;
140
+ }
141
+ /** Build a placed section's renderer bundle and its island chunks. */
142
+ async function buildSection(input) {
143
+ const { root, key } = input;
144
+ const cacheDir = mediaCacheDir(root);
145
+ const found = /* @__PURE__ */ new Map();
146
+ const assets = /* @__PURE__ */ new Map();
147
+ const sources = /* @__PURE__ */ new Map();
148
+ const masters = /* @__PURE__ */ new Map();
149
+ const passthrough = /* @__PURE__ */ new Set();
150
+ const collect = (deriver, outputFiles, metafile) => {
151
+ const emitted = emittedAssets(outputFiles);
152
+ const sourceByEmitted = sourcesOf(metafile);
153
+ for (const asset of [...emitted, ...derivedAssets(deriver)]) if (!assets.has(asset.filename)) assets.set(asset.filename, asset);
154
+ for (const asset of emitted) {
155
+ const file = toPosix(sourceByEmitted.get(asset.filename) ?? asset.filename);
156
+ sources.set(file, {
157
+ file,
158
+ bytes: asset.bytes.byteLength
159
+ });
160
+ }
161
+ for (const [master, { masterBytes, derivatives }] of deriver.sources) {
162
+ const file = toPosix(relative(root, master));
163
+ sources.set(file, {
164
+ file,
165
+ bytes: masterBytes,
166
+ largestRungBytes: Math.max(0, ...derivatives.map((d) => d.bytes.byteLength))
167
+ });
168
+ }
169
+ for (const [masterKey, filename] of deriver.masters) masters.set(masterKey, filename);
170
+ for (const path of deriver.passthrough) passthrough.add(path);
171
+ };
172
+ const rendererDeriver = createMediaDeriver({ cacheDir });
173
+ const rendered = await rendererPass(input, rendererDeriver, found, true);
174
+ collect(rendererDeriver, rendered.outputFiles, rendered.metafile);
175
+ const islands = [];
176
+ for (const [islandKey, file] of [...found].sort(([a], [b]) => a < b ? -1 : 1)) {
177
+ const deriver = createMediaDeriver({ cacheDir });
178
+ const bytes = await runPass(`The island chunk ${islandKey}`, async () => {
179
+ const result = await build({
180
+ entryPoints: [file],
181
+ bundle: true,
182
+ format: "esm",
183
+ target: "es2022",
184
+ platform: "browser",
185
+ minify: true,
186
+ write: false,
187
+ jsx: "automatic",
188
+ external: [...ISLAND_REACT_EXTERNALS],
189
+ absWorkingDir: root,
190
+ ...workspaceLoaders(root),
191
+ plugins: [
192
+ bundledFrameworkPlugin(),
193
+ nestedIslandsPlugin(root, key, file),
194
+ deriver.plugin
195
+ ],
196
+ metafile: true,
197
+ logLevel: "silent"
198
+ });
199
+ collect(deriver, result.outputFiles, result.metafile);
200
+ return javascriptOutput(result.outputFiles, `island ${islandKey}`);
201
+ });
202
+ const contentHash = sha256(bytes);
203
+ const frameless = declaresNoServerFrame(await readFile(file, "utf8"));
204
+ islands.push({
205
+ islandKey,
206
+ filename: `island-${sanitizeKey(islandKey)}-${contentHash}.mjs`,
207
+ contentHash,
208
+ bytes,
209
+ file,
210
+ frameless
211
+ });
212
+ }
213
+ return {
214
+ renderer: rendered.bytes,
215
+ islands,
216
+ assets: [...assets.values()],
217
+ sources: [...sources.values()].sort((a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : 0),
218
+ masters,
219
+ passthrough
220
+ };
221
+ }
222
+ /**
223
+ * The section's renderer bundle with every island wrapped for real, `serverFrame = false`
224
+ * or not: what each island's server render would put on the page if the declaration did
225
+ * not delete it. Never written to an artifact.
226
+ */
227
+ async function buildFramedRenderer(input) {
228
+ return (await rendererPass(input, createMediaDeriver({ cacheDir: mediaCacheDir(input.root) }), /* @__PURE__ */ new Map(), false)).bytes;
229
+ }
230
+ /** Where `check` writes a framed renderer to import it: inside the workspace, so its React resolves from there. */
231
+ function framedRendererPath(root, key, bytes) {
232
+ return join(root, ".concrete", "cache", "check", "frames", `${sanitizeKey(key)}-${sha256(bytes).slice(0, 16)}.mjs`);
233
+ }
234
+
235
+ //#endregion
236
+ export { ISLAND_REACT_EXTERNALS, buildFramedRenderer, buildSection, framedRendererPath, sanitizeKey };
@@ -0,0 +1,62 @@
1
+ import { join, relative, sep } from "node:path";
2
+ import { readFile, readdir } from "node:fs/promises";
3
+ import { execFile } from "node:child_process";
4
+ import { promisify } from "node:util";
5
+
6
+ //#region src/cli/build/source.ts
7
+ const run = promisify(execFile);
8
+ const toPosix = (path) => sep === "\\" ? path.replaceAll("\\", "/") : path;
9
+ async function gitListing(root) {
10
+ try {
11
+ const { stdout } = await run("git", [
12
+ "ls-files",
13
+ "-z",
14
+ "--cached",
15
+ "--others",
16
+ "--exclude-standard",
17
+ "--",
18
+ "."
19
+ ], {
20
+ cwd: root,
21
+ maxBuffer: 64 * 1024 * 1024
22
+ });
23
+ return stdout.split("\0").filter((path) => path !== "");
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ async function walk(root) {
29
+ const out = [];
30
+ const visit = async (dir) => {
31
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
32
+ const path = join(dir, entry.name);
33
+ if (entry.isDirectory()) {
34
+ if (entry.name === "node_modules" || entry.name === ".git") continue;
35
+ await visit(path);
36
+ } else if (entry.isFile()) out.push(toPosix(relative(root, path)));
37
+ }
38
+ };
39
+ await visit(root);
40
+ return out;
41
+ }
42
+ /**
43
+ * The source files of the workspace at `root`, sorted by path, excluding `.concrete/`
44
+ * and every directory in `exclude` (absolute).
45
+ */
46
+ async function collectSourceFiles(root, exclude) {
47
+ const excluded = [".concrete", ...exclude.map((dir) => toPosix(relative(root, dir)))].filter((dir) => dir !== "" && !dir.startsWith("..")).map((dir) => `${dir.replace(/\/+$/, "")}/`);
48
+ const paths = (await gitListing(root) ?? await walk(root)).filter((path) => !excluded.some((dir) => path.startsWith(dir)));
49
+ const files = [];
50
+ for (const path of [...new Set(paths)].sort()) try {
51
+ files.push({
52
+ path,
53
+ bytes: new Uint8Array(await readFile(join(root, path)))
54
+ });
55
+ } catch (cause) {
56
+ if (cause.code !== "ENOENT") throw cause;
57
+ }
58
+ return files;
59
+ }
60
+
61
+ //#endregion
62
+ export { collectSourceFiles };