@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,129 @@
1
+ import { extname } from "node:path";
2
+ import { readFile } from "node:fs/promises";
3
+
4
+ //#region src/cli/dev/http.ts
5
+ const MIME = {
6
+ ".js": "text/javascript; charset=utf-8",
7
+ ".mjs": "text/javascript; charset=utf-8",
8
+ ".css": "text/css; charset=utf-8",
9
+ ".html": "text/html; charset=utf-8",
10
+ ".json": "application/json; charset=utf-8",
11
+ ".map": "application/json; charset=utf-8",
12
+ ".svg": "image/svg+xml",
13
+ ".ico": "image/x-icon",
14
+ ".png": "image/png",
15
+ ".jpg": "image/jpeg",
16
+ ".jpeg": "image/jpeg",
17
+ ".gif": "image/gif",
18
+ ".webp": "image/webp",
19
+ ".avif": "image/avif",
20
+ ".mp4": "video/mp4",
21
+ ".webm": "video/webm",
22
+ ".mov": "video/quicktime",
23
+ ".mp3": "audio/mpeg",
24
+ ".wav": "audio/wav",
25
+ ".pdf": "application/pdf",
26
+ ".zip": "application/zip",
27
+ ".woff": "font/woff",
28
+ ".woff2": "font/woff2",
29
+ ".ttf": "font/ttf",
30
+ ".otf": "font/otf",
31
+ ".eot": "application/vnd.ms-fontobject"
32
+ };
33
+ /** The content type a file is served under, by extension. */
34
+ function contentTypeFor(path) {
35
+ return MIME[extname(path).toLowerCase()] ?? "application/octet-stream";
36
+ }
37
+ function sendText(res, status, body) {
38
+ res.statusCode = status;
39
+ res.setHeader("content-type", "text/plain; charset=utf-8");
40
+ res.end(body);
41
+ }
42
+ function sendHtml(res, html) {
43
+ res.setHeader("content-type", "text/html; charset=utf-8");
44
+ res.end(html);
45
+ }
46
+ function sendBytes(res, contentType, bytes, disposition) {
47
+ res.setHeader("content-type", contentType);
48
+ if (disposition !== void 0) res.setHeader("content-disposition", disposition);
49
+ res.end(Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength));
50
+ }
51
+ /** Read a request body, bounded. */
52
+ async function readBody(req, maxBytes) {
53
+ const chunks = [];
54
+ let size = 0;
55
+ for await (const chunk of req) {
56
+ const buf = chunk;
57
+ size += buf.length;
58
+ if (size > maxBytes) throw new RequestError(413, `request body exceeds ${maxBytes} bytes`);
59
+ chunks.push(buf);
60
+ }
61
+ return Buffer.concat(chunks);
62
+ }
63
+ /** A request the server refuses with a status of its own choosing and a sentence. */
64
+ var RequestError = class extends Error {
65
+ status;
66
+ constructor(status, message) {
67
+ super(message);
68
+ this.status = status;
69
+ }
70
+ };
71
+ /**
72
+ * One `bytes=` range (the only form a media element sends) against a body of `size`
73
+ * bytes: the inclusive slice to serve, `null` for no or an unparsable header (serve the
74
+ * whole body), `"unsatisfiable"` when it starts past the end.
75
+ */
76
+ function parseByteRange(header, size) {
77
+ const match = header ? /^bytes=(\d*)-(\d*)$/.exec(header.trim()) : null;
78
+ if (!match || match[1] === "" && match[2] === "") return null;
79
+ if (match[1] === "") {
80
+ const suffix = Number(match[2]);
81
+ if (suffix === 0 || size === 0) return "unsatisfiable";
82
+ return {
83
+ start: Math.max(0, size - suffix),
84
+ end: size - 1
85
+ };
86
+ }
87
+ const start = Number(match[1]);
88
+ const end = match[2] === "" ? size - 1 : Math.min(Number(match[2]), size - 1);
89
+ if (start >= size || start > end) return "unsatisfiable";
90
+ return {
91
+ start,
92
+ end
93
+ };
94
+ }
95
+ /**
96
+ * Serve a file from disk, honouring a byte range. A `<video>` seeks by ranges: a player
97
+ * that asked for `bytes=N-` and got the whole file back reports `seekable` as empty and
98
+ * snaps every seek to zero. A missing file 404s.
99
+ */
100
+ async function sendFile(req, res, path) {
101
+ let buf;
102
+ try {
103
+ buf = await readFile(path);
104
+ } catch {
105
+ sendText(res, 404, "not found");
106
+ return;
107
+ }
108
+ res.setHeader("content-type", contentTypeFor(path));
109
+ res.setHeader("accept-ranges", "bytes");
110
+ const range = parseByteRange(req.headers.range, buf.byteLength);
111
+ if (range === "unsatisfiable") {
112
+ res.statusCode = 416;
113
+ res.setHeader("content-range", `bytes */${buf.byteLength}`);
114
+ res.end();
115
+ return;
116
+ }
117
+ if (range) {
118
+ res.statusCode = 206;
119
+ res.setHeader("content-range", `bytes ${range.start}-${range.end}/${buf.byteLength}`);
120
+ res.setHeader("content-length", String(range.end - range.start + 1));
121
+ res.end(buf.subarray(range.start, range.end + 1));
122
+ return;
123
+ }
124
+ res.setHeader("content-length", String(buf.byteLength));
125
+ res.end(buf);
126
+ }
127
+
128
+ //#endregion
129
+ export { RequestError, contentTypeFor, parseByteRange, readBody, sendBytes, sendFile, sendHtml, sendText };
@@ -0,0 +1,70 @@
1
+ import { findCommand, flagDefault, parseSpec, stringFlag } from "../commands.js";
2
+ import { TEMPLATE_FILE } from "./workspace-reader.js";
3
+ import { startDevServer } from "./server.js";
4
+ import { findWorkspaceRoot } from "../workspace.js";
5
+ import { existsSync } from "node:fs";
6
+ import { join } from "node:path";
7
+ import { parseArgs } from "node:util";
8
+
9
+ //#region src/cli/dev/index.ts
10
+ const DEFAULT_PORT = Number(flagDefault(findCommand("dev"), "port"));
11
+ /** The port a `--port` value names: a positive integer, else the default. */
12
+ function parsePort(raw) {
13
+ if (raw === null) return DEFAULT_PORT;
14
+ const port = Number(raw);
15
+ return Number.isInteger(port) && port > 0 ? port : DEFAULT_PORT;
16
+ }
17
+ const processSignals = () => new Promise((resolveStop) => {
18
+ process.once("SIGINT", () => resolveStop());
19
+ process.once("SIGTERM", () => resolveStop());
20
+ });
21
+ function createDevRunner(deps) {
22
+ return async (argv, io) => {
23
+ let values;
24
+ try {
25
+ values = parseArgs({
26
+ args: [...argv],
27
+ ...parseSpec("dev"),
28
+ allowPositionals: false,
29
+ strict: true
30
+ }).values;
31
+ } catch (err) {
32
+ io.stderr.write(`concrete dev: ${err instanceof Error ? err.message : String(err)}\n`);
33
+ return 1;
34
+ }
35
+ const port = parsePort(stringFlag(values, "port"));
36
+ let root;
37
+ try {
38
+ root = await findWorkspaceRoot(io.cwd);
39
+ } catch (err) {
40
+ io.stderr.write(`concrete dev: ${err instanceof Error ? err.message : String(err)}\n`);
41
+ return 1;
42
+ }
43
+ if (!existsSync(join(root, "template.ts"))) {
44
+ io.stderr.write(`concrete dev: there is no ${TEMPLATE_FILE} at ${root} — a workspace declares its template there.\n`);
45
+ return 1;
46
+ }
47
+ let server;
48
+ try {
49
+ server = await deps.start({
50
+ root,
51
+ port,
52
+ log: io.stderr
53
+ });
54
+ } catch (err) {
55
+ io.stderr.write(`concrete dev: ${err instanceof Error ? err.message : String(err)}\n`);
56
+ return 1;
57
+ }
58
+ io.stdout.write(`concrete dev — ${server.url}\n`);
59
+ await deps.untilStopped();
60
+ await server.close();
61
+ return 0;
62
+ };
63
+ }
64
+ const runDev = createDevRunner({
65
+ start: startDevServer,
66
+ untilStopped: processSignals
67
+ });
68
+
69
+ //#endregion
70
+ export { createDevRunner, parsePort, runDev };
@@ -0,0 +1,390 @@
1
+ import { CAPTURE_ISLANDS_READY_GLOBAL } from "../../packages/internal/format-geometry/dist/capture.js";
2
+ import "../../packages/internal/format-geometry/dist/index.js";
3
+ import { hasClientDirective } from "../../islands/client-module.js";
4
+ import { readFileSync, readdirSync } from "node:fs";
5
+ import { basename, dirname, extname, join, relative, sep } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
8
+ import { createHash } from "node:crypto";
9
+
10
+ //#region src/cli/dev/islands.ts
11
+ const COMPONENT_EXTS = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
12
+ const SKIPPED_DIRS = /* @__PURE__ */ new Set([
13
+ "node_modules",
14
+ "dist",
15
+ ".concrete"
16
+ ]);
17
+ /** Forward slashes: Vite module ids use them on every platform, `node:path` does not. */
18
+ function toPosixPath(path) {
19
+ return sep === "\\" ? path.replaceAll("\\", "/") : path;
20
+ }
21
+ const SERVER_FRAME = /^[ \t]*export[ \t]+const[ \t]+serverFrame[ \t]*(?::[^=]*)?=[ \t]*(.*)$/m;
22
+ /** Whether a client module declares the literal `serverFrame = false`: no server-rendered first frame. */
23
+ function declaresNoServerFrame(text) {
24
+ const declaration = SERVER_FRAME.exec(text);
25
+ if (!declaration) return false;
26
+ const source = (declaration[1] ?? "").replace(/;.*$/, "").trim();
27
+ const literal = /^(true|false)\b/.exec(source);
28
+ if (!literal) return false;
29
+ const rest = source.slice(literal[0].length).trim();
30
+ if (rest !== "" && !/^(?:satisfies|as)\b/.test(rest)) return false;
31
+ return literal[1] === "false";
32
+ }
33
+ /**
34
+ * The island key of a module: its workspace path without the extension, split at the
35
+ * last segment — `sections/hero/Counter.tsx` → `sections/hero:Counter`.
36
+ */
37
+ function islandKeyFor(root, file) {
38
+ const rel = toPosixPath(relative(root, file));
39
+ const dir = dirname(rel);
40
+ const stem = basename(rel, extname(rel));
41
+ return `${dir === "." ? "" : dir}:${stem}`;
42
+ }
43
+ /** Every island module in the workspace, sorted: a `.tsx`/`.jsx` file whose prologue says `"use client"`. */
44
+ function findWorkspaceIslands(root) {
45
+ const out = [];
46
+ const walk = (dir, depth) => {
47
+ let entries;
48
+ try {
49
+ entries = readdirSync(dir, { withFileTypes: true });
50
+ } catch {
51
+ return;
52
+ }
53
+ for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
54
+ if (entry.name.startsWith(".")) continue;
55
+ const path = join(dir, entry.name);
56
+ if (entry.isDirectory()) {
57
+ if (SKIPPED_DIRS.has(entry.name) || depth === 0 && entry.name === "fixtures") continue;
58
+ walk(path, depth + 1);
59
+ } else if (entry.isFile() && COMPONENT_EXTS.has(extname(entry.name)) && !/\.test\.[^/]+$/.test(entry.name)) {
60
+ let text;
61
+ try {
62
+ text = readFileSync(path, "utf8");
63
+ } catch {
64
+ continue;
65
+ }
66
+ if (hasClientDirective(text)) out.push(path);
67
+ }
68
+ }
69
+ };
70
+ walk(root, 0);
71
+ return out;
72
+ }
73
+ /** island key → the root-relative URL Vite serves the module at. */
74
+ function islandMapOf(root, files) {
75
+ const map = {};
76
+ for (const file of files) map[islandKeyFor(root, file)] = `/${toPosixPath(relative(root, file))}`;
77
+ return map;
78
+ }
79
+ function markerModule(islandKey, markerSpecifier, children) {
80
+ return `
81
+ ;
82
+ import { createElement as __trCreateElement, useId as __trUseId } from "react";
83
+ import { IslandMarker as __TrIslandMarker } from ${JSON.stringify(markerSpecifier)};
84
+ export default function __trIslandWrapper(__trProps) {
85
+ const __trIslandId = __trUseId();
86
+ return __trCreateElement(
87
+ __TrIslandMarker,
88
+ { islandKey: ${JSON.stringify(islandKey)}, islandId: __trIslandId, props: __trProps },${children}
89
+ );
90
+ }
91
+ `;
92
+ }
93
+ const DEFAULT_EXPORT = /export\s+default\s+/;
94
+ /**
95
+ * A client module rewritten so its default export renders through the island marker. The
96
+ * original is rebound to `__trIslandReal` and re-exported under that name: a top-level
97
+ * marker must hydrate the RAW component (the marker's children are its own output),
98
+ * while a nested usage must render the wrapper so its marker is emitted, and one shared
99
+ * Vite module graph serves both. `null` for a non-client module or one with no default.
100
+ */
101
+ function wrapClientModule(code, islandKey, markerSpecifier) {
102
+ if (!hasClientDirective(code) || !DEFAULT_EXPORT.test(code)) return null;
103
+ return code.replace(DEFAULT_EXPORT, "const __trIslandReal = ") + markerModule(islandKey, markerSpecifier, "\n __trCreateElement(__trIslandReal, __trProps),") + "export { __trIslandReal };\n";
104
+ }
105
+ /** The marker-only module the SERVER graph gets for an island declaring `serverFrame = false`. */
106
+ function stubClientModule(code, islandKey, markerSpecifier) {
107
+ if (!hasClientDirective(code) || !DEFAULT_EXPORT.test(code) || !declaresNoServerFrame(code)) return null;
108
+ return markerModule(islandKey, markerSpecifier, "");
109
+ }
110
+ /**
111
+ * The Vite transform that makes an island of every workspace client module, in both
112
+ * graphs. The browser graph needs the wrap too: a NESTED island is marked in the server
113
+ * HTML, so its parent's client render must emit that marker, or React discards the
114
+ * parent's server tree. The server graph alone stubs an island with no server frame.
115
+ *
116
+ * It must run before the React plugin, which consumes the directive otherwise.
117
+ */
118
+ function islandTransformPlugin(options) {
119
+ const inside = options.root.endsWith(sep) ? options.root : options.root + sep;
120
+ return {
121
+ name: "concrete-dev:islands",
122
+ enforce: "pre",
123
+ transform(code, id, transformOptions) {
124
+ const file = id.split("?")[0] ?? id;
125
+ if (!COMPONENT_EXTS.has(extname(file)) || !file.startsWith(inside) || file.includes(`${sep}node_modules${sep}`)) return null;
126
+ const key = islandKeyFor(options.root, file);
127
+ if (transformOptions?.ssr === true) {
128
+ const stub = stubClientModule(code, key, options.markerSpecifier);
129
+ if (stub !== null) return {
130
+ code: stub,
131
+ map: null
132
+ };
133
+ }
134
+ const wrapped = wrapClientModule(code, key, options.markerSpecifier);
135
+ return wrapped === null ? null : {
136
+ code: wrapped,
137
+ map: null
138
+ };
139
+ }
140
+ };
141
+ }
142
+ /**
143
+ * The same transform for the server graph `concrete dev` renders from, which esbuild
144
+ * bundles (./load-template.ts): a workspace client module is stubbed when it declares no
145
+ * server frame and wrapped otherwise, exactly as the browser graph's Vite plugin does.
146
+ */
147
+ function islandEsbuildPlugin(options) {
148
+ const inside = options.root.endsWith(sep) ? options.root : options.root + sep;
149
+ return {
150
+ name: "concrete-dev:islands",
151
+ setup(build) {
152
+ build.onLoad({ filter: /\.[jt]sx$/ }, async (args) => {
153
+ if (!args.path.startsWith(inside) || args.path.includes(`${sep}node_modules${sep}`)) return void 0;
154
+ const code = await readFile(args.path, "utf8");
155
+ const key = islandKeyFor(options.root, args.path);
156
+ const contents = stubClientModule(code, key, options.markerSpecifier) ?? wrapClientModule(code, key, options.markerSpecifier);
157
+ if (contents === null) return void 0;
158
+ return {
159
+ contents,
160
+ loader: extname(args.path) === ".jsx" ? "jsx" : "tsx",
161
+ resolveDir: dirname(args.path)
162
+ };
163
+ });
164
+ }
165
+ };
166
+ }
167
+ /**
168
+ * The island runtime module the host scripts import, by absolute path: the built entry
169
+ * beside this module in dist, or the source module when running from source.
170
+ */
171
+ function islandRuntimeFile() {
172
+ const here = fileURLToPath(import.meta.url);
173
+ return extname(here) === ".ts" ? join(dirname(here), "island-runtime.ts") : join(dirname(here), "..", "..", "playground-island-runtime.js");
174
+ }
175
+ /** The `/@fs/` URL Vite serves an absolute file at. */
176
+ function fsUrl(file) {
177
+ return `/@fs/${toPosixPath(file).replace(/^\/+/, "")}`;
178
+ }
179
+ function importers(root, files) {
180
+ return `const modules = {\n${files.map((file) => {
181
+ const url = `/${toPosixPath(relative(root, file))}`;
182
+ return ` ${JSON.stringify(url)}: () => import(${JSON.stringify(url)}),`;
183
+ }).join("\n")}\n};`;
184
+ }
185
+ const REAL_COMPONENT = `
186
+ // The island transform rewrites the browser graph too, so a client module's \`default\`
187
+ // renders the marker. A TOP-LEVEL marker hydrates the raw component instead.
188
+ function realComponent(mod) {
189
+ return mod.__trIslandReal || mod.default;
190
+ }
191
+ `;
192
+ function previewHostSource(runtimeUrl, root, files) {
193
+ return `import { hydrateIslands, islandsCaptureReady } from ${JSON.stringify(runtimeUrl)};
194
+
195
+ ${importers(root, files)}
196
+ const map = window.__TR_ISLAND_MAP || {};
197
+ ${REAL_COMPONENT}
198
+ // The first island that fails to hydrate: logged as it happens, and re-thrown out of the
199
+ // readiness promise, because a capture of a page whose island threw is a hole in an artifact.
200
+ let hydrationFailure = null;
201
+
202
+ const hydrated = hydrateIslands({
203
+ load: async (key) => {
204
+ const url = map[key];
205
+ const importer = url ? modules[url] : undefined;
206
+ if (!importer) return Promise.reject(new Error("concrete dev: no island module for " + key));
207
+ const mod = await importer();
208
+ return { ...mod, default: realComponent(mod) };
209
+ },
210
+ // Absent on a browsed page, so the loader's viewport default runs — what deployment does.
211
+ // A captured document sets "eager".
212
+ schedule: window.__TR_ISLAND_SCHEDULE,
213
+ onError: (error, ctx) => {
214
+ console.error("concrete dev: island failed to hydrate:", ctx.key, error);
215
+ if (!hydrationFailure) {
216
+ hydrationFailure = new Error("island " + ctx.key + " failed to hydrate: " + ((error && error.message) || error));
217
+ }
218
+ },
219
+ });
220
+
221
+ // The capture settle's hydration leg: every handle mounted, then every capture hold drained.
222
+ const ready = hydrated.then(async (handles) => {
223
+ await islandsCaptureReady(handles);
224
+ if (hydrationFailure) throw hydrationFailure;
225
+ });
226
+ window.${CAPTURE_ISLANDS_READY_GLOBAL} = ready;
227
+ ready.catch(() => {});
228
+ `;
229
+ }
230
+ /**
231
+ * The canvas island host, over whatever reaches the island modules: `concrete dev`'s Vite
232
+ * importers, or a published build's hashed bundles (`bundledCanvasHostSource`). One body,
233
+ * so the gate, the shields and the commit signal a hosted canvas runs are the ones a
234
+ * developer saw in `dev`.
235
+ */
236
+ function canvasHostCore(runtimeSpecifier, modules) {
237
+ return `${modules.head}
238
+ import { hydrateIslands, unmountIslands } from ${JSON.stringify(runtimeSpecifier)};
239
+ import { createElement, useLayoutEffect } from "react";
240
+
241
+ // The shared canvas kernel's shield names: this script must speak the same spellings or
242
+ // its shields never lift.
243
+ const SHIELD_CLASS = "we-enh-shield";
244
+ const SHIELD_ITEM_CLASS = "we-enh-shield--item";
245
+ const LIVE_ATTR = "data-we-live";
246
+ const ITEM_ATTR = "data-slot-item";
247
+
248
+ const map = window.__TR_ISLAND_MAP || {};
249
+ ${modules.importer}
250
+
251
+ // Per-island hydration-commit signal, keyed by the \`editor\` object each load() clones —
252
+ // never by island key, or N copies of one island would share one commit.
253
+ const commitOf = new WeakMap();
254
+
255
+ function withCommitSignal(component, signalCommit) {
256
+ return function IslandCommitSignal(props) {
257
+ useLayoutEffect(signalCommit, []);
258
+ return createElement(component, props);
259
+ };
260
+ }
261
+ ${REAL_COMPONENT}
262
+ async function load(key) {
263
+ const mod = await importIsland(key);
264
+ let signalCommit;
265
+ const committed = new Promise((resolve) => { signalCommit = resolve; });
266
+ const editor = mod.editor ? { ...mod.editor } : undefined;
267
+ if (editor) commitOf.set(editor, { committed, signalCommit });
268
+ return { ...mod, editor, default: withCommitSignal(realComponent(mod), signalCommit) };
269
+ }
270
+
271
+ function makeShield(doc, itemShield) {
272
+ const shield = doc.createElement("div");
273
+ shield.className = itemShield ? SHIELD_CLASS + " " + SHIELD_ITEM_CLASS : SHIELD_CLASS;
274
+ shield.setAttribute("aria-hidden", "true");
275
+ return shield;
276
+ }
277
+
278
+ function installShield(surface, itemShield) {
279
+ const doc = surface.ownerDocument;
280
+ const win = doc.defaultView;
281
+ const pos = win ? win.getComputedStyle(surface).position : "";
282
+ if (!pos || pos === "static") surface.style.position = "relative";
283
+ if (Array.from(surface.children).some((c) => c.classList.contains(SHIELD_CLASS))) return;
284
+ surface.appendChild(makeShield(doc, itemShield));
285
+ }
286
+
287
+ // Shields derive from the island's own markup: an item shield per collection-item copy,
288
+ // then a base shield per root box (the marker is display:contents).
289
+ function shieldHandle(handle) {
290
+ const editor = handle.editor;
291
+ if (!editor || editor.live !== true) return;
292
+ const root = handle.element;
293
+ for (const itemEl of Array.from(root.querySelectorAll("[" + ITEM_ATTR + "]"))) installShield(itemEl, true);
294
+ const doc = root.ownerDocument;
295
+ const win = doc.defaultView;
296
+ const display = win ? win.getComputedStyle(root).display : "";
297
+ const baseEls = display === "contents" ? Array.from(root.children) : [root];
298
+ for (const baseEl of baseEls) installShield(baseEl, false);
299
+ }
300
+
301
+ let styleInstalled = false;
302
+ function ensureShieldStyle() {
303
+ if (styleInstalled || document.getElementById("tr-canvas-shield-style")) return;
304
+ styleInstalled = true;
305
+ const style = document.createElement("style");
306
+ style.id = "tr-canvas-shield-style";
307
+ style.textContent =
308
+ "." + SHIELD_CLASS + "{position:absolute;inset:0;z-index:1;cursor:pointer;background:transparent;}" +
309
+ "." + SHIELD_ITEM_CLASS + "{z-index:2;}" +
310
+ "[" + LIVE_ATTR + "] ." + SHIELD_CLASS + "{display:none;}";
311
+ document.head.appendChild(style);
312
+ }
313
+
314
+ async function hydrateRoot(root) {
315
+ ensureShieldStyle();
316
+ const handles = await hydrateIslands({
317
+ root,
318
+ load,
319
+ // The shield pass needs every handle the moment this settles.
320
+ schedule: "eager",
321
+ shouldHydrate: (ctx) => (ctx.editor ? ctx.editor.live === true : false),
322
+ onError: (error, ctx) => {
323
+ console.error(${JSON.stringify(`${modules.label}: canvas island failed to hydrate:`)}, ctx.key, error);
324
+ if (ctx.editor) { const c = commitOf.get(ctx.editor); if (c) c.signalCommit(); }
325
+ },
326
+ });
327
+ // React commits on a scheduler task; mutating its DOM before the commit makes it discard
328
+ // the server tree, shields and all.
329
+ await Promise.all(
330
+ handles.map((h) => (h.editor ? commitOf.get(h.editor) : undefined)).filter((c) => c !== undefined).map((c) => c.committed),
331
+ );
332
+ for (const handle of handles) shieldHandle(handle);
333
+ return handles;
334
+ }
335
+
336
+ function unmountRoot(root) {
337
+ unmountIslands(root);
338
+ root.querySelectorAll("." + SHIELD_CLASS).forEach((s) => s.remove());
339
+ }
340
+
341
+ window.__trCanvasIslands = { hydrateRoot, unmountRoot };
342
+ void hydrateRoot(document.body);
343
+ `;
344
+ }
345
+ function canvasHostSource(runtimeUrl, root, files) {
346
+ return canvasHostCore(runtimeUrl, {
347
+ head: `import RefreshRuntime from "/@react-refresh";
348
+
349
+ // The React Refresh preamble. The React plugin compiles every client component to assert
350
+ // it ran, and the canvas frame is not built by Vite's own html transform, so the one
351
+ // module every canvas frame loads supplies it.
352
+ if (!window.__vite_plugin_react_preamble_installed__) {
353
+ RefreshRuntime.injectIntoGlobalHook(window);
354
+ window.$RefreshReg$ = () => {};
355
+ window.$RefreshSig$ = () => (type) => type;
356
+ window.__vite_plugin_react_preamble_installed__ = true;
357
+ }
358
+ `,
359
+ importer: `${importers(root, files)}
360
+ function importIsland(key) {
361
+ const url = map[key];
362
+ const importer = url ? modules[url] : undefined;
363
+ return importer ? importer() : Promise.reject(new Error("concrete dev: no island module for " + key));
364
+ }`,
365
+ label: "concrete dev"
366
+ });
367
+ }
368
+ /**
369
+ * Write both host scripts under the workspace's `.concrete/dev/` and return the URLs Vite
370
+ * serves them at. Each URL carries a hash of its contents, so a changed island set is a
371
+ * new module to Vite rather than a cached one.
372
+ */
373
+ async function writeIslandHostScripts(root, files) {
374
+ const dir = join(root, ".concrete", "dev");
375
+ await mkdir(dir, { recursive: true });
376
+ const runtimeUrl = fsUrl(islandRuntimeFile());
377
+ const write = async (name, source) => {
378
+ const file = join(dir, name);
379
+ await writeFile(file, source, "utf8");
380
+ const version = createHash("sha256").update(source).digest("hex").slice(0, 12);
381
+ return `${fsUrl(file)}?v=${version}`;
382
+ };
383
+ return {
384
+ canvas: await write("island-canvas-host.js", canvasHostSource(runtimeUrl, root, files)),
385
+ preview: await write("island-preview-host.js", previewHostSource(runtimeUrl, root, files))
386
+ };
387
+ }
388
+
389
+ //#endregion
390
+ export { declaresNoServerFrame, findWorkspaceIslands, fsUrl, hasClientDirective, islandEsbuildPlugin, islandKeyFor, islandMapOf, islandRuntimeFile, islandTransformPlugin, stubClientModule, toPosixPath, wrapClientModule, writeIslandHostScripts };
@@ -0,0 +1,46 @@
1
+ import { islandEsbuildPlugin } from "./islands.js";
2
+ import { MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace } from "../../fixtures/media-plugin.js";
3
+ import { join } from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import { build } from "esbuild";
6
+
7
+ //#region src/cli/dev/load-template.ts
8
+ let serial = 0;
9
+ /** Bundle `<root>/template.ts` into the workspace's `.concrete/` cache and import the output. */
10
+ async function loadTemplateModule(options) {
11
+ const { root } = options;
12
+ const media = createFixtureMediaPlugin(root);
13
+ const outfile = join(root, ".concrete", "cache", "dev", "template.mjs");
14
+ await build({
15
+ entryPoints: [options.templateFile],
16
+ bundle: true,
17
+ format: "esm",
18
+ platform: "node",
19
+ target: "node22",
20
+ outfile,
21
+ absWorkingDir: root,
22
+ packages: "external",
23
+ jsx: "automatic",
24
+ loader: {
25
+ ".css": "empty",
26
+ ...MEDIA_LOADERS
27
+ },
28
+ plugins: [
29
+ externalOutsideWorkspace(root),
30
+ islandEsbuildPlugin({
31
+ root,
32
+ markerSpecifier: options.markerSpecifier
33
+ }),
34
+ media.plugin
35
+ ],
36
+ write: true,
37
+ logLevel: "silent"
38
+ });
39
+ return {
40
+ template: (await import(`${pathToFileURL(outfile).href}?load=${Date.now()}-${serial++}`)).default,
41
+ assets: media.assets
42
+ };
43
+ }
44
+
45
+ //#endregion
46
+ export { loadTemplateModule };
@@ -0,0 +1,22 @@
1
+ //#region src/cli/dev/request-error.ts
2
+ /**
3
+ * Answer a rejected request handler. Safe to call at any point in a response's
4
+ * life: it never writes headers twice, and it never throws.
5
+ */
6
+ function respondToHandlerError(err, req, res, fixStacktrace) {
7
+ const error = err instanceof Error ? err : new Error(String(err));
8
+ fixStacktrace?.(error);
9
+ if (res.headersSent || res.writableEnded) {
10
+ const where = `${req.method ?? "?"} ${req.url ?? "?"}`;
11
+ console.error(`[dev] ${where} failed after its response began: ${error.stack ?? error.message}`);
12
+ if (!res.writableEnded) res.destroy(error);
13
+ return;
14
+ }
15
+ console.error(`[dev] ${req.method ?? "?"} ${req.url ?? "?"} failed: ${error.message}`);
16
+ res.statusCode = 500;
17
+ res.setHeader("content-type", "text/plain");
18
+ res.end(`dev server error: ${error.message}`);
19
+ }
20
+
21
+ //#endregion
22
+ export { respondToHandlerError };