@homepages/concrete 12.0.0 → 13.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/CHANGELOG.md +192 -0
  2. package/README.md +8 -10
  3. package/codemods/fixtures-are-data.mjs +7 -0
  4. package/codemods/fixtures-list-properties.mjs +6 -0
  5. package/codemods/manifest.json +15 -0
  6. package/codemods/steps/fixtures-list-properties.mjs +16 -0
  7. package/codemods/steps/fixtures-to-data.mjs +41 -0
  8. package/dist/artifact/playground/client/assets/archivo-latin-ext-wght-normal-C4zznr8T.woff2 +0 -0
  9. package/dist/artifact/playground/client/assets/archivo-latin-wght-normal-E0tuGl4L.woff2 +0 -0
  10. package/dist/artifact/playground/client/assets/archivo-vietnamese-wght-normal-XAtsl5Q_.woff2 +0 -0
  11. package/dist/artifact/playground/client/assets/index-Bmvcss4B.js +1338 -0
  12. package/dist/artifact/playground/client/assets/index-C01UCAWD.css +1 -0
  13. package/dist/artifact/playground/client/index.html +2 -2
  14. package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
  15. package/dist/artifact/playground/host.mjs +110 -59
  16. package/dist/base.css +2 -2
  17. package/dist/cli/build/icons.js +1 -1
  18. package/dist/cli/build/index.js +11 -10
  19. package/dist/cli/build/manifest.js +44 -0
  20. package/dist/cli/build/record.js +123 -0
  21. package/dist/cli/build/sections.js +28 -18
  22. package/dist/cli/build/source.js +1 -1
  23. package/dist/cli/build/static.js +8 -5
  24. package/dist/cli/build/template-build.js +614 -0
  25. package/dist/cli/check/analyze.js +18 -1
  26. package/dist/cli/check/load-workspace.js +2 -2
  27. package/dist/cli/check/portable-names.js +1 -1
  28. package/dist/cli/check/render/corpus.js +119 -0
  29. package/dist/cli/check/render/invariants.js +1 -0
  30. package/dist/cli/check/stages/bundles.js +15 -18
  31. package/dist/cli/check/stages/composition.js +8 -25
  32. package/dist/cli/check/stages/fixtures.js +14 -10
  33. package/dist/cli/check/stages/logic.js +7 -23
  34. package/dist/cli/check/stages/render.js +12 -14
  35. package/dist/cli/check/stages/sections.js +22 -66
  36. package/dist/cli/check/stages/stylesheet.js +4 -26
  37. package/dist/cli/check/stages/workspace.js +27 -22
  38. package/dist/cli/commands.js +51 -23
  39. package/dist/cli/currency/preamble.js +1 -1
  40. package/dist/cli/currency/resolve-latest.js +3 -2
  41. package/dist/cli/dev/capture-browser.js +26 -0
  42. package/dist/cli/dev/fixture-schema.js +441 -0
  43. package/dist/cli/dev/folder-files.js +244 -0
  44. package/dist/cli/dev/index.js +7 -3
  45. package/dist/cli/dev/playground-server.js +34 -0
  46. package/dist/cli/dev/section-ladders.js +76 -0
  47. package/dist/cli/dev/server.js +120 -304
  48. package/dist/cli/install/background.js +16 -0
  49. package/dist/cli/install/index.js +45 -0
  50. package/dist/cli/install/tools.js +27 -0
  51. package/dist/cli/media/derive.js +19 -13
  52. package/dist/cli/media/deriver-plugin.js +14 -3
  53. package/dist/cli/property/fixture-list.js +46 -0
  54. package/dist/cli/property/index.js +12 -9
  55. package/dist/cli/property/library.js +12 -10
  56. package/dist/cli/publish/artifact.js +90 -0
  57. package/dist/cli/publish/captures.js +61 -0
  58. package/dist/cli/publish/fixtures.js +17 -0
  59. package/dist/cli/publish/index.js +10 -18
  60. package/dist/cli/{build → publish}/playground.js +3 -3
  61. package/dist/cli/publish/report.js +15 -33
  62. package/dist/cli/upgrade/codemod.d.ts +14 -0
  63. package/dist/cli/upgrade/fixture-conversion.d.ts +11 -0
  64. package/dist/cli/upgrade/fixture-conversion.js +54 -0
  65. package/dist/cli/upgrade/fixture-modules.js +125 -0
  66. package/dist/cli/upgrade/fixtures-to-data.d.ts +40 -0
  67. package/dist/cli/upgrade/fixtures-to-data.js +498 -0
  68. package/dist/cli/upgrade/index.js +18 -2
  69. package/dist/cli/upgrade/legacy-fixtures.d.ts +34 -0
  70. package/dist/cli/upgrade/legacy-fixtures.js +22 -0
  71. package/dist/cli/upgrade/stage.js +1 -1
  72. package/dist/cli/workspace-fixtures.js +80 -0
  73. package/dist/cli.js +1 -0
  74. package/dist/css/compile.js +9 -3
  75. package/dist/fixtures/bundle-rule.js +16 -16
  76. package/dist/fixtures/media-plugin.js +12 -33
  77. package/dist/fixtures/synthesize-empties.js +3 -2
  78. package/dist/index.d.ts +7 -7
  79. package/dist/{playground-island-runtime.d.ts → island-runtime.d.ts} +1 -2
  80. package/dist/{playground-island-runtime.js → island-runtime.js} +1 -2
  81. package/dist/islands/client-module.js +1 -1
  82. package/dist/{cli/dev → islands}/tsconfig-paths.js +2 -14
  83. package/dist/islands/wrap.js +40 -0
  84. package/dist/node_modules/.pnpm/acorn@8.18.0/node_modules/acorn/dist/acorn.js +5119 -0
  85. package/dist/packages/external/concrete/package.js +1 -1
  86. package/dist/packages/internal/bundle-evaluation/dist/cache.js +36 -0
  87. package/dist/packages/internal/bundle-evaluation/dist/evaluate.js +174 -0
  88. package/dist/packages/internal/bundle-evaluation/dist/index.js +5 -0
  89. package/dist/packages/internal/bundle-evaluation/dist/section-code.js +10 -0
  90. package/dist/packages/internal/capture-settle/dist/index.js +2 -2
  91. package/dist/packages/internal/capture-settle/dist/settle.js +88 -13
  92. package/dist/packages/internal/code-fingerprint/dist/index.js +57 -0
  93. package/dist/packages/internal/content-doc-ops/dist/index.js +176 -0
  94. package/dist/packages/internal/content-doc-ops/dist/made-rows.js +15 -0
  95. package/dist/packages/internal/deliverable-reads/dist/bootstrap.js +81 -0
  96. package/dist/packages/internal/deliverable-reads/dist/display.js +21 -0
  97. package/dist/packages/internal/deliverable-reads/dist/format.js +15 -0
  98. package/dist/packages/internal/deliverable-reads/dist/index.js +7 -0
  99. package/dist/packages/internal/deliverable-reads/dist/pages.js +29 -0
  100. package/dist/packages/internal/deliverable-reads/dist/requirements.js +72 -0
  101. package/dist/{cli/capture → packages/internal/download-files/dist}/bundle.js +8 -4
  102. package/dist/packages/internal/download-files/dist/capture-origin.js +126 -0
  103. package/dist/packages/internal/download-files/dist/capture-routes.js +139 -0
  104. package/dist/packages/internal/download-files/dist/capture-shell.js +38 -0
  105. package/dist/packages/internal/download-files/dist/capture.js +74 -0
  106. package/dist/packages/internal/download-files/dist/egress-watch.js +38 -0
  107. package/dist/packages/internal/download-files/dist/files.js +7 -0
  108. package/dist/packages/internal/download-files/dist/finish.js +35 -0
  109. package/dist/packages/internal/download-files/dist/fleet.js +94 -0
  110. package/dist/packages/internal/download-files/dist/format.js +40 -0
  111. package/dist/packages/internal/download-files/dist/make.js +105 -0
  112. package/dist/packages/internal/download-files/dist/master-tally.js +32 -0
  113. package/dist/packages/internal/download-files/dist/names.js +24 -0
  114. package/dist/packages/internal/download-files/dist/pdf-boxes.js +33 -0
  115. package/dist/packages/internal/download-files/dist/pdf-image-placements.js +194 -0
  116. package/dist/packages/internal/download-files/dist/pdf-images.js +289 -0
  117. package/dist/packages/internal/file-store/dist/files.js +8 -0
  118. package/dist/packages/internal/file-store/dist/lru.js +40 -0
  119. package/dist/packages/internal/file-store/dist/refusal.js +12 -0
  120. package/dist/packages/internal/file-store/dist/trees.js +151 -0
  121. package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +1 -1
  122. package/dist/packages/internal/fill-bake/dist/compute-reads.js +47 -21
  123. package/dist/packages/internal/fill-bake/dist/index.js +5 -1
  124. package/dist/packages/internal/fill-bake/dist/item-merge.js +4 -3
  125. package/dist/packages/internal/fill-bake/dist/resolve-instance.js +9 -0
  126. package/dist/packages/internal/fill-bake/dist/resolve.js +3 -0
  127. package/dist/packages/internal/fill-bake/dist/round-trip.js +2 -0
  128. package/dist/packages/internal/fill-bake/dist/strip.js +6 -0
  129. package/dist/packages/internal/fill-vocabulary/dist/holder.js +1 -1
  130. package/dist/packages/internal/fill-vocabulary/dist/resolved-decision.js +1 -1
  131. package/dist/packages/internal/fill-vocabulary/dist/verbs.js +1 -1
  132. package/dist/packages/internal/island-runtime/dist/index.js +1 -10
  133. package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +5 -0
  134. package/dist/packages/internal/lead-fields/dist/ingest.js +72 -0
  135. package/dist/packages/internal/media-resolution/dist/video.js +6 -2
  136. package/dist/packages/internal/page-render/dist/addresses.js +57 -0
  137. package/dist/packages/internal/page-render/dist/index.js +6 -0
  138. package/dist/packages/internal/page-render/dist/kept.js +30 -0
  139. package/dist/packages/internal/page-render/dist/nav.js +42 -0
  140. package/dist/packages/internal/page-render/dist/render.js +152 -0
  141. package/dist/packages/internal/page-shell/dist/assemble.js +161 -0
  142. package/dist/packages/internal/page-shell/dist/escape.js +10 -0
  143. package/dist/packages/internal/page-shell/dist/frame.js +23 -0
  144. package/dist/packages/internal/page-shell/dist/index.js +26 -0
  145. package/dist/packages/internal/playground/dist/build-fingerprint.js +18 -0
  146. package/dist/packages/internal/playground/dist/fixture-conversions/list-names-properties.js +76 -0
  147. package/dist/packages/internal/playground/dist/fixture-formats.d.ts +37 -0
  148. package/dist/packages/internal/playground/dist/fixture-formats.js +20 -0
  149. package/dist/packages/internal/playground/dist/host/bootstrap.js +108 -0
  150. package/dist/packages/internal/playground/dist/host/built.js +202 -0
  151. package/dist/packages/internal/playground/dist/host/catalog-fixture.js +53 -0
  152. package/dist/packages/internal/playground/dist/host/download.js +34 -0
  153. package/dist/packages/internal/playground/dist/host/env.js +11 -0
  154. package/dist/packages/internal/playground/dist/host/everywhere-saves.js +353 -0
  155. package/dist/packages/internal/playground/dist/host/fixture-addresses.js +52 -0
  156. package/dist/packages/internal/playground/dist/host/fixture-documents.js +494 -0
  157. package/dist/packages/internal/playground/dist/host/fixture-operations.js +364 -0
  158. package/dist/packages/internal/playground/dist/host/fixture-units.js +93 -0
  159. package/dist/{fixtures → packages/internal/playground/dist/host}/image-dimensions.js +1 -1
  160. package/dist/packages/internal/playground/dist/host/leads.js +41 -0
  161. package/dist/packages/internal/playground/dist/host/media-saves.js +309 -0
  162. package/dist/{fixtures → packages/internal/playground/dist/host}/media-store.js +79 -26
  163. package/dist/packages/internal/playground/dist/host/overridable.js +9 -0
  164. package/dist/packages/internal/playground/dist/host/owned-saves.js +203 -0
  165. package/dist/{playground → packages/internal/playground/dist}/host/page-state.js +1 -1
  166. package/dist/packages/internal/playground/dist/host/program.js +54 -0
  167. package/dist/packages/internal/playground/dist/host/property-derive.js +216 -0
  168. package/dist/packages/internal/playground/dist/host/property-saves.js +74 -0
  169. package/dist/{fixtures → packages/internal/playground/dist/host}/property.js +88 -229
  170. package/dist/packages/internal/playground/dist/host/provenance.js +49 -0
  171. package/dist/packages/internal/playground/dist/host/resolve.js +553 -0
  172. package/dist/packages/internal/playground/dist/host/row-images.js +41 -0
  173. package/dist/{fixtures → packages/internal/playground/dist/host}/rows.js +1 -1
  174. package/dist/packages/internal/playground/dist/host/save.js +429 -0
  175. package/dist/packages/internal/playground/dist/host/serve.js +952 -0
  176. package/dist/packages/internal/playground/dist/host/site.js +79 -0
  177. package/dist/packages/internal/playground/dist/host/slots.js +202 -0
  178. package/dist/packages/internal/playground/dist/host/stated-content.js +93 -0
  179. package/dist/packages/internal/playground/dist/host/stored-fixtures.js +135 -0
  180. package/dist/packages/internal/playground/dist/host/violations.js +7 -0
  181. package/dist/packages/internal/playground/dist/jobs/lanes.js +24 -0
  182. package/dist/packages/internal/playground/dist/jobs/memory-queue.js +112 -0
  183. package/dist/packages/internal/playground/dist/jobs/probe.js +37 -0
  184. package/dist/packages/internal/playground/dist/jobs/queue.js +28 -0
  185. package/dist/packages/internal/playground/dist/jobs/runner.js +207 -0
  186. package/dist/packages/internal/playground/dist/layout.js +14 -0
  187. package/dist/packages/internal/playground/dist/platform.js +33 -0
  188. package/dist/packages/internal/playground/dist/server/changes.js +57 -0
  189. package/dist/packages/internal/playground/dist/server/crop.js +47 -0
  190. package/dist/packages/internal/playground/dist/server/derived-files.js +88 -0
  191. package/dist/packages/internal/playground/dist/server/download.js +158 -0
  192. package/dist/{cli/dev → packages/internal/playground/dist/server}/http.js +4 -12
  193. package/dist/packages/internal/playground/dist/server/jobs.js +29 -0
  194. package/dist/{cli/dev → packages/internal/playground/dist/server}/listen.js +4 -11
  195. package/dist/packages/internal/playground/dist/server/playground-server.js +424 -0
  196. package/dist/{cli/dev → packages/internal/playground/dist/server}/request-error.js +1 -1
  197. package/dist/packages/internal/playground/dist/server/size-ladders.js +170 -0
  198. package/dist/packages/internal/playground/dist/server/verification.js +75 -0
  199. package/dist/packages/internal/playground/dist/server/verify-build.js +139 -0
  200. package/dist/packages/internal/playground/dist/wire.js +78 -0
  201. package/dist/packages/internal/property-facts/dist/registry-facts.js +1 -1
  202. package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +1 -1
  203. package/dist/packages/internal/section-contracts/dist/reads-acyclic-contract.js +1 -1
  204. package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +1 -1
  205. package/dist/packages/internal/site-files/dist/head.js +59 -0
  206. package/dist/packages/internal/site-files/dist/index.js +4 -0
  207. package/dist/packages/internal/site-files/dist/site.js +211 -0
  208. package/dist/packages/internal/static-assets-binding/dist/index.js +32 -0
  209. package/dist/packages/internal/static-assets-binding/dist/section-asset-url.js +38 -5
  210. package/dist/packages/internal/template-artifact/dist/asset-mime.js +8 -1
  211. package/dist/packages/internal/template-artifact/dist/build.js +148 -0
  212. package/dist/packages/internal/template-artifact/dist/composition.js +62 -0
  213. package/dist/packages/internal/template-artifact/dist/index.js +2 -2
  214. package/dist/packages/internal/template-artifact/dist/layout.js +48 -12
  215. package/dist/packages/internal/template-artifact/dist/manifest.js +3 -10
  216. package/dist/packages/internal/template-artifact/dist/verify.js +51 -31
  217. package/dist/packages/internal/template-contracts/dist/address-value.js +6 -1
  218. package/dist/packages/internal/template-contracts/dist/content-categories.js +10 -1
  219. package/dist/packages/internal/template-contracts/dist/fact-compute.d.ts +1 -1
  220. package/dist/packages/internal/template-contracts/dist/fact-keys.d.ts +1 -1
  221. package/dist/packages/internal/template-contracts/dist/fact-registry.d.ts +3 -3
  222. package/dist/packages/internal/template-contracts/dist/fact-registry.js +59 -32
  223. package/dist/packages/internal/template-contracts/dist/fill-spec.js +14 -1
  224. package/dist/packages/internal/template-contracts/dist/list.d.ts +3 -3
  225. package/dist/packages/internal/template-contracts/dist/media-candidates.js +67 -2
  226. package/dist/packages/internal/template-contracts/dist/media-offer.js +180 -0
  227. package/dist/packages/internal/template-contracts/dist/object.d.ts +2 -2
  228. package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +9 -2
  229. package/dist/packages/internal/template-contracts/dist/read-graph.js +36 -2
  230. package/dist/packages/internal/template-contracts/dist/ref-locate.js +16 -1
  231. package/dist/packages/internal/template-contracts/dist/registry-facts.d.ts +9 -10
  232. package/dist/packages/internal/template-contracts/dist/registry-facts.js +12 -1
  233. package/dist/packages/internal/template-contracts/dist/registry-graph.js +112 -0
  234. package/dist/packages/internal/template-contracts/dist/registry-shape.js +15 -2
  235. package/dist/packages/internal/template-contracts/dist/require-graph.js +300 -0
  236. package/dist/packages/internal/template-contracts/dist/row-ref.d.ts +3 -3
  237. package/dist/packages/internal/template-contracts/dist/row.d.ts +3 -3
  238. package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +1 -1
  239. package/dist/{schema → packages/internal/template-contracts/dist}/section-nav.d.ts +1 -1
  240. package/dist/packages/internal/template-contracts/dist/slot-builders.d.ts +4 -4
  241. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +3 -1
  242. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +24 -1
  243. package/dist/packages/internal/template-contracts/dist/slot-overrides.js +26 -1
  244. package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +1 -1
  245. package/dist/packages/internal/template-contracts/dist/slot-types.js +1 -1
  246. package/dist/packages/internal/template-contracts/dist/slot-value.d.ts +1 -1
  247. package/dist/packages/internal/template-contracts/dist/table-members.js +7 -2
  248. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
  249. package/dist/packages/internal/upload-formats/dist/heic.js +35 -0
  250. package/dist/packages/internal/upload-formats/dist/index.js +80 -0
  251. package/dist/packages/internal/upload-formats/dist/magic-bytes.js +293 -0
  252. package/dist/platform/paths.js +1 -0
  253. package/dist/platform/process.js +49 -1
  254. package/dist/rules/registry.js +27 -3
  255. package/dist/schema/fact.d.ts +2 -2
  256. package/dist/schema/facts-view.d.ts +1 -1
  257. package/dist/schema/section-props.d.ts +1 -1
  258. package/dist/schema/section-schema.d.ts +1 -1
  259. package/dist/schema/section-schema.js +1 -0
  260. package/dist/section/declare.d.ts +1 -1
  261. package/dist/section/discovery.js +6 -2
  262. package/dist/section/publish-shape.js +38 -0
  263. package/dist/section/section.d.ts +1 -1
  264. package/dist/template/define-template.d.ts +14 -4
  265. package/dist/template/define-template.js +2 -0
  266. package/dist/template/logic-shim.d.ts +1 -1
  267. package/dist/template/materialize.js +1 -1
  268. package/dist/template/running-copy.js +0 -1
  269. package/dist/template/section-reads.js +1 -1
  270. package/guide/reference/cli/INDEX.md +6 -5
  271. package/guide/reference/cli/build.md +10 -8
  272. package/guide/reference/cli/check.md +4 -2
  273. package/guide/reference/cli/dev.md +6 -2
  274. package/guide/reference/cli/install.md +41 -0
  275. package/guide/reference/cli/property-add.md +5 -4
  276. package/guide/reference/cli/property-list.md +2 -2
  277. package/guide/reference/cli/publish.md +5 -5
  278. package/guide/reference/cli/upgrade.md +1 -1
  279. package/guide/reference/rules/INDEX.md +8 -4
  280. package/package.json +14 -30
  281. package/dist/artifact/playground/client/assets/index-BcLGpWLR.js +0 -1266
  282. package/dist/artifact/playground/client/assets/index-CxWPYOH2.css +0 -1
  283. package/dist/cli/build/artifact.js +0 -220
  284. package/dist/cli/build/captures.js +0 -48
  285. package/dist/cli/build/fixtures.js +0 -92
  286. package/dist/cli/capture/capture-browser.js +0 -37
  287. package/dist/cli/capture/capture.js +0 -115
  288. package/dist/cli/check/render/inputs.js +0 -60
  289. package/dist/cli/check/render/nav.js +0 -31
  290. package/dist/cli/dev/crop.js +0 -20
  291. package/dist/cli/dev/fixture-ladders.js +0 -96
  292. package/dist/cli/dev/hmr.js +0 -26
  293. package/dist/cli/dev/islands.js +0 -234
  294. package/dist/cli/dev/load-template.js +0 -52
  295. package/dist/cli/dev/vite.js +0 -114
  296. package/dist/cli/dev/workspace-reader.js +0 -249
  297. package/dist/cli/publish/freshness.js +0 -64
  298. package/dist/fixtures/brand.d.ts +0 -4
  299. package/dist/fixtures/brand.js +0 -8
  300. package/dist/fixtures/load.js +0 -159
  301. package/dist/fixtures/resolve.js +0 -392
  302. package/dist/fixtures.d.ts +0 -429
  303. package/dist/fixtures.js +0 -23
  304. package/dist/packages/internal/canvas-core/dist/island-host.js +0 -62
  305. package/dist/packages/internal/canvas-core/dist/island-shields.js +0 -30
  306. package/dist/playground/canvas-island-host.d.ts +0 -11
  307. package/dist/playground/canvas-island-host.js +0 -29
  308. package/dist/playground/canvas-markers.js +0 -14
  309. package/dist/playground/host/paths.js +0 -8
  310. package/dist/playground/layout.js +0 -17
  311. package/dist/playground/wire.js +0 -28
@@ -1,334 +1,150 @@
1
- import { RUNNING_FROM_SOURCE, isInsideRoot, packageFile, packageRoot, toPosix } from "../../platform/paths.js";
2
- import { findWorkspaceIslands, fsUrl, islandMapOf, writeIslandHostScripts } from "./islands.js";
1
+ import { qualify } from "../../rules/registry.js";
2
+ import { toPosix } from "../../platform/paths.js";
3
3
  import { mediaCacheDir } from "../media/cache.js";
4
- import { FIXTURE_MEDIA_PATH } from "../../fixtures/media-plugin.js";
5
- import { HMR_EVENTS, ROUTES } from "../../playground/wire.js";
6
- import { hmrPortFor, listenOn } from "./listen.js";
7
- import { sectionAssetPrefix } from "../../packages/internal/static-assets-binding/dist/section-asset-url.js";
8
- import { STYLESHEET_PATHS } from "../../playground/host/paths.js";
9
- import { playgroundClientOutDir, playgroundHostFile } from "../../playground/layout.js";
10
- import { CaptureUnavailableError, captureFixture, createCapturer } from "../capture/capture.js";
11
- import { CROP_PARAM, parseCropParam } from "../../packages/internal/crop-region/dist/index.js";
12
- import { croppedMediaUrl, cutRegion } from "./crop.js";
13
- import { createFixtureLadders } from "./fixture-ladders.js";
14
- import { createHmrBus } from "./hmr.js";
15
- import { RequestError, contentTypeFor, readBody, sendBytes, sendFile, sendHtml, sendText } from "./http.js";
16
- import { respondToHandlerError } from "./request-error.js";
17
- import { createDevVite, settleBrowserDependencies } from "./vite.js";
18
- import { DevWorkspace } from "./workspace-reader.js";
19
- import { existsSync, statSync } from "node:fs";
20
- import { extname, join, relative, resolve } from "node:path";
21
- import { pathToFileURL } from "node:url";
22
- import { readFile } from "node:fs/promises";
23
- import { createServer } from "node:http";
4
+ import { buildTemplate } from "../build/template-build.js";
5
+ import { writeFixtureSchemas } from "./fixture-schema.js";
6
+ import { createSectionLadders } from "./section-ladders.js";
7
+ import { folderFiles } from "./folder-files.js";
8
+ import { startPlaygroundServer } from "./playground-server.js";
9
+ import { watch } from "node:fs";
10
+ import { join, relative } from "node:path";
24
11
 
25
12
  //#region src/cli/dev/server.ts
26
- const MAX_BODY_BYTES = 1024 * 1024;
27
- const MAX_CACHED_CROPS = 64;
28
- const SECTION_ASSET_PREFIXES = [sectionAssetPrefix({ kind: "canonical" }), sectionAssetPrefix({
29
- kind: "canvas",
30
- basePath: "/"
31
- })];
32
- function stampBase(html, base) {
33
- const tag = `<base href="${base}">`;
34
- return /<head[^>]*>/i.test(html) ? html.replace(/<head[^>]*>/i, (head) => `${head}\n ${tag}`) : `${tag}${html}`;
13
+ const DEV_BUILD_DIR = ".concrete/dev";
14
+ const TOOLING_FILES = /* @__PURE__ */ new Set(["package.json", "tsconfig.json"]);
15
+ const FIXTURES_MOVED = {
16
+ source: false,
17
+ stylesheet: false,
18
+ fixtures: true
19
+ };
20
+ const SOURCE_MOVED = {
21
+ source: true,
22
+ stylesheet: false,
23
+ fixtures: false
24
+ };
25
+ const SETTLE_MS = 30;
26
+ function failureText(failures) {
27
+ return failures.map((failure) => `${failure.file}${failure.line === void 0 ? "" : `:${String(failure.line)}`} ${qualify(failure.rule)}\n ${failure.message.replace(/\n/g, "\n ")}`).join("\n");
35
28
  }
36
- function isCanvasPath(path) {
37
- if (path === "/") return true;
38
- const [head, fixture, view, ...rest] = path.split("/").filter(Boolean);
39
- return head === "fixtures" && fixture !== void 0 && view === "canvas" && rest.length <= 1;
40
- }
41
- async function loadHostModule(packageRoot) {
42
- const file = playgroundHostFile(packageRoot);
43
- if (!existsSync(file)) throw new Error(`the playground host module is not built (${file}) — run the package's build.`);
44
- const mod = await import(pathToFileURL(file).href);
45
- if (typeof mod.createHost !== "function") throw new Error(`${file} does not export createHost.`);
46
- return mod.createHost;
29
+ function isWorkspaceChange(path) {
30
+ return path.split("/").every((segment) => segment !== "node_modules" && !segment.startsWith("."));
47
31
  }
48
32
  async function startDevServer(options) {
49
- const { root, port, log } = options;
50
- const hmrPort = hmrPortFor(port);
51
- const packageRoot$1 = packageRoot();
52
- const clientDir = playgroundClientOutDir(packageRoot$1);
53
- if (!existsSync(join(clientDir, "index.html"))) log.write(`concrete dev: the playground client is not built (${clientDir}) — run the package's build.\n`);
54
- const createHost = await loadHostModule(packageRoot$1);
55
- const sourceMarker = join(packageRoot$1, "src", "islands", "marker.tsx");
56
- const browserMarker = RUNNING_FROM_SOURCE ? fsUrl(sourceMarker) : "@homepages/concrete";
57
- const serverMarker = RUNNING_FROM_SOURCE ? sourceMarker : "@homepages/concrete";
58
- const islandEntries = findWorkspaceIslands(root).map((file) => toPosix(relative(root, file)));
59
- const browserAssets = /* @__PURE__ */ new Map();
33
+ const { root, log } = options;
34
+ const out = join(root, ...DEV_BUILD_DIR.split("/"));
60
35
  let onLadderReady = () => {};
61
- const ladders = createFixtureLadders({
36
+ const ladders = createSectionLadders({
62
37
  cacheDir: mediaCacheDir(root),
63
38
  log,
64
39
  onReady: () => onLadderReady()
65
40
  });
66
- const hmrServer = createServer((_req, res) => {
67
- res.writeHead(426).end("Upgrade Required");
68
- });
69
- await listenOn(hmrServer, hmrPort, `port ${String(hmrPort)} (the editor's module-reload socket, --port + ${String(100)})`);
70
- const closeHmrServer = () => new Promise((done) => hmrServer.close(() => done()));
71
- let vite;
72
- try {
73
- vite = await createDevVite({
74
- root,
75
- packageRoot: packageRoot$1,
76
- markerSpecifier: browserMarker,
77
- hmrServer,
78
- hmrPort,
79
- islandEntries,
80
- assets: browserAssets,
81
- ladders
82
- });
83
- } catch (err) {
84
- await closeHmrServer();
85
- throw err;
86
- }
87
- let islands = {
88
- map: {},
89
- canvasHost: null,
90
- previewHost: null
91
- };
92
- let islandKey = "";
93
- const refreshIslands = async () => {
94
- const files = findWorkspaceIslands(root);
95
- const key = files.join("\n");
96
- if (key === islandKey && islands.canvasHost !== null) return false;
97
- islandKey = key;
98
- const scripts = await writeIslandHostScripts(root, files);
99
- islands = files.length === 0 ? {
100
- map: {},
101
- canvasHost: null,
102
- previewHost: null
103
- } : {
104
- map: islandMapOf(root, files),
105
- canvasHost: scripts.canvas,
106
- previewHost: scripts.preview
107
- };
108
- return true;
109
- };
110
- await refreshIslands();
111
- const capturer = options.capturer ?? createCapturer({
41
+ let server = null;
42
+ const files = folderFiles({
112
43
  root,
113
- packageRoot: packageRoot$1
44
+ build: { failure: "The template is still building." },
45
+ onWritten: () => server?.changes.moved(FIXTURES_MOVED)
114
46
  });
115
- const origin = `http://localhost:${port}/`;
116
- let browserGraphSettled = null;
117
- const capture = async (request) => {
118
- browserGraphSettled ??= settleBrowserDependencies(vite, [...islands.previewHost === null ? [] : [islands.previewHost], ...Object.values(islands.map)]);
119
- await browserGraphSettled;
47
+ const buildOnce = async () => {
48
+ const started = performance.now();
120
49
  try {
121
- return await captureFixture(capturer, origin, request);
122
- } catch (err) {
123
- if (err instanceof CaptureUnavailableError) throw new RequestError(501, err.message);
124
- throw err;
50
+ const build = await buildTemplate({
51
+ root,
52
+ out,
53
+ pending: ladders
54
+ });
55
+ if (build.output === null) {
56
+ const text = failureText(build.failures);
57
+ log.write(`concrete dev: the template did not build:\n${text}\n`);
58
+ return { failure: `The template did not build:\n${text}` };
59
+ }
60
+ if (build.composition?.ok === true) await writeFixtureSchemas(root, build.composition.value).catch(() => void 0);
61
+ const { sections } = build.output.record;
62
+ const rebuilt = sections.filter((section) => section.rebuilt).length;
63
+ log.write(`concrete dev: built in ${String(Math.round(performance.now() - started))} ms — ${String(rebuilt)} of ${String(sections.length)} sections.\n`);
64
+ return { output: build.output };
65
+ } catch (cause) {
66
+ const message = cause instanceof Error ? cause.message : String(cause);
67
+ log.write(`concrete dev: the template did not build: ${message}\n`);
68
+ return { failure: `The template did not build: ${message}` };
125
69
  }
126
70
  };
127
- const workspace = new DevWorkspace({
71
+ let running = null;
72
+ let again = false;
73
+ const rebuild = () => {
74
+ if (running !== null) {
75
+ again = true;
76
+ return running;
77
+ }
78
+ running = (async () => {
79
+ do {
80
+ again = false;
81
+ files.serve(await buildOnce());
82
+ server?.changes.moved(SOURCE_MOVED);
83
+ } while (again);
84
+ })().finally(() => {
85
+ running = null;
86
+ });
87
+ return running;
88
+ };
89
+ server = await startPlaygroundServer({
128
90
  root,
129
- markerSpecifier: serverMarker,
130
- islands: () => islands,
131
- capture,
132
- ladders
133
- });
134
- const assetUrl = (path, transform) => transform === void 0 ? path : croppedMediaUrl(path, transform.crop);
135
- const host = createHost({
136
- reader: workspace,
137
- assetUrl,
138
- renderer: workspace.renderer(),
139
- base: "/"
140
- });
141
- const hmr = createHmrBus();
142
- const ctx = {
143
- port,
144
- vite,
145
- workspace,
146
- host,
147
- hmr,
148
- clientDir,
149
- baseCss: packageFile("css/base.css", "base.css"),
91
+ port: options.port,
150
92
  log,
151
- browserAssets,
152
- ladders,
153
- crops: /* @__PURE__ */ new Map()
154
- };
155
- const fixturesDir = join(root, "fixtures");
156
- const onChange = (path) => {
157
- vite.moduleGraph.invalidateAll();
158
- browserGraphSettled = null;
159
- if (isInsideRoot(fixturesDir, path)) {
160
- workspace.invalidateFixtures();
161
- hmr.broadcast(HMR_EVENTS.fixtures);
162
- return;
93
+ files,
94
+ cutsLadders: true,
95
+ ...options.browser === void 0 ? {} : { browser: options.browser },
96
+ ...options.toolsReady === void 0 ? {} : { toolsReady: options.toolsReady }
97
+ });
98
+ const playground = server;
99
+ onLadderReady = () => void rebuild();
100
+ let pending = null;
101
+ let fixturesChanged = false;
102
+ let sourceChanged = false;
103
+ const flush = () => {
104
+ pending = null;
105
+ if (fixturesChanged) {
106
+ fixturesChanged = false;
107
+ files.changed();
108
+ playground.changes.moved(FIXTURES_MOVED);
163
109
  }
164
- if (extname(path) === ".css") {
165
- workspace.invalidateStylesheet();
166
- hmr.broadcast(HMR_EVENTS.stylesheet);
167
- return;
110
+ if (sourceChanged) {
111
+ sourceChanged = false;
112
+ rebuild();
168
113
  }
169
- workspace.invalidateSource();
170
- refreshIslands().finally(() => {
171
- hmr.broadcast(HMR_EVENTS.source);
172
- hmr.broadcast(HMR_EVENTS.stylesheet);
173
- });
174
- };
175
- onLadderReady = () => {
176
- vite.moduleGraph.invalidateAll();
177
- browserGraphSettled = null;
178
- workspace.invalidateMedia();
179
- hmr.broadcast(HMR_EVENTS.source);
180
114
  };
181
- vite.watcher.on("change", onChange);
182
- vite.watcher.on("add", onChange);
183
- vite.watcher.on("unlink", onChange);
184
- const server = createServer((req, res) => {
185
- handle(req, res, ctx).catch((err) => {
186
- if (err instanceof RequestError && !res.headersSent) {
187
- sendText(res, err.status, err.message);
188
- return;
189
- }
190
- respondToHandlerError(err, req, res, (error) => vite.ssrFixStacktrace(error));
191
- });
115
+ const watcher = watch(root, { recursive: true }, (_event, filename) => {
116
+ if (filename === null) return;
117
+ const path = toPosix(relative(root, join(root, filename)));
118
+ if (path === "" || path.startsWith("../") || !isWorkspaceChange(path)) return;
119
+ if (files.reaches(path) || path.endsWith(".json") && !TOOLING_FILES.has(path)) fixturesChanged = true;
120
+ else sourceChanged = true;
121
+ pending ??= setTimeout(flush, SETTLE_MS);
192
122
  });
193
- try {
194
- await listenOn(server, port, `port ${String(port)}`);
195
- } catch (err) {
196
- await vite.close();
197
- await closeHmrServer();
198
- throw err;
199
- }
123
+ watcher.on("error", (err) => log.write(`concrete dev: the workspace watcher stopped: ${err.message}\n`));
124
+ await rebuild();
125
+ const built = async () => {
126
+ while (pending !== null || running !== null) {
127
+ if (pending !== null) {
128
+ clearTimeout(pending);
129
+ flush();
130
+ }
131
+ await running;
132
+ }
133
+ };
200
134
  return {
201
- url: origin,
202
- port,
203
- workspace,
204
- ladders,
135
+ url: playground.url,
136
+ port: playground.port,
137
+ sectionLadders: ladders,
138
+ built,
205
139
  close: async () => {
206
- hmr.closeAll();
207
- await new Promise((done) => server.close(() => done()));
208
- await capturer.close();
140
+ watcher.close();
141
+ if (pending !== null) clearTimeout(pending);
142
+ await running;
143
+ await playground.close();
209
144
  await ladders.close();
210
- await vite.close();
211
- await closeHmrServer();
212
145
  }
213
146
  };
214
147
  }
215
- async function toFetchRequest(req, url) {
216
- const method = req.method ?? "GET";
217
- const headers = new Headers();
218
- for (const [name, value] of Object.entries(req.headers)) if (typeof value === "string") headers.set(name, value);
219
- else if (Array.isArray(value)) for (const item of value) headers.append(name, item);
220
- const body = method === "GET" || method === "HEAD" ? void 0 : await readBody(req, MAX_BODY_BYTES);
221
- return new Request(url, {
222
- method,
223
- headers,
224
- ...body === void 0 ? {} : { body: new Uint8Array(body) }
225
- });
226
- }
227
- async function sendFetchResponse(res, response) {
228
- res.statusCode = response.status;
229
- response.headers.forEach((value, name) => res.setHeader(name, value));
230
- res.end(Buffer.from(await response.arrayBuffer()));
231
- }
232
- async function handle(req, res, ctx) {
233
- const url = new URL(req.url ?? "/", `http://localhost:${ctx.port}`);
234
- const path = url.pathname;
235
- if (isCanvasPath(path)) return sendClientShell(ctx, res);
236
- if (path === `/${ROUTES.hmr}`) return ctx.hmr.attach(res);
237
- if (path === `/${STYLESHEET_PATHS.base}`) return sendBytes(res, "text/css; charset=utf-8", await readFile(ctx.baseCss));
238
- if (path === `/${STYLESHEET_PATHS.template}`) return sendTemplateCss(ctx, res);
239
- const assetPrefix = SECTION_ASSET_PREFIXES.find((prefix) => path.startsWith(prefix));
240
- if (assetPrefix !== void 0) return sendSectionAsset(ctx, path.slice(assetPrefix.length), res);
241
- if (path.startsWith(`${"/fixture-media"}/`)) return sendFixtureMedia(ctx, req, url, res);
242
- const answered = await ctx.host.handle(await toFetchRequest(req, url));
243
- if (answered !== null) return sendFetchResponse(res, answered);
244
- if (await sendClientAsset(ctx, path, res)) return;
245
- ctx.vite.middlewares(req, res, () => sendText(res, 404, "not found"));
246
- }
247
- async function sendClientShell(ctx, res) {
248
- let html;
249
- try {
250
- html = await readFile(join(ctx.clientDir, "index.html"), "utf8");
251
- } catch {
252
- sendText(res, 500, "the playground client is not built — run the package's build");
253
- return;
254
- }
255
- sendHtml(res, stampBase(html, "/"));
256
- }
257
- async function sendClientAsset(ctx, path, res) {
258
- const file = resolve(ctx.clientDir, `.${decodeURIComponent(path)}`);
259
- if (!isInsideRoot(ctx.clientDir, file)) return false;
260
- try {
261
- if (!statSync(file).isFile()) return false;
262
- } catch {
263
- return false;
264
- }
265
- sendBytes(res, contentTypeFor(file), await readFile(file));
266
- return true;
267
- }
268
- async function sendTemplateCss(ctx, res) {
269
- const { css, violations } = await ctx.workspace.templateCss();
270
- for (const violation of violations) ctx.log.write(`concrete dev: ${violation.file}: ${violation.message} (${violation.rule})\n`);
271
- res.setHeader("cache-control", "no-cache");
272
- sendBytes(res, "text/css; charset=utf-8", new TextEncoder().encode(css));
273
- }
274
- function sendSectionAsset(ctx, rawFilename, res) {
275
- const filename = decodeURIComponent(rawFilename);
276
- if (filename.includes("/") || filename.includes("\\") || filename.includes("..")) {
277
- sendText(res, 403, "forbidden");
278
- return;
279
- }
280
- const asset = ctx.workspace.sectionAsset(filename);
281
- if (asset === void 0) {
282
- sendText(res, 404, "not found");
283
- return;
284
- }
285
- sendBytes(res, asset.contentType, asset.bytes);
286
- }
287
- async function sendFixtureMedia(ctx, req, url, res) {
288
- if (req.method !== "GET" && req.method !== "HEAD") {
289
- sendText(res, 405, "fixture media only reads; the playground accepts no uploads.");
290
- return;
291
- }
292
- const path = decodeURIComponent(url.pathname);
293
- const asset = await ctx.workspace.fixtureAsset(path) ?? ctx.browserAssets.get(path);
294
- const cropValue = url.searchParams.get(CROP_PARAM);
295
- if (asset === void 0) {
296
- const rung = ctx.ladders.rung(path);
297
- if (rung === void 0) sendText(res, 404, "not found");
298
- else if (cropValue !== null) sendText(res, 400, `${url.pathname} is one rung of an image's ladder; crop the image itself.`);
299
- else sendBytes(res, rung.contentType, rung.bytes);
300
- return;
301
- }
302
- if (cropValue === null) {
303
- await sendFile(req, res, asset.path);
304
- return;
305
- }
306
- const rect = parseCropParam(cropValue);
307
- if (rect === null) {
308
- sendText(res, 400, `"${cropValue}" is not a crop of the image.`);
309
- return;
310
- }
311
- if (!asset.derived) {
312
- sendText(res, 400, `${url.pathname} is not a raster image and cannot be cropped.`);
313
- return;
314
- }
315
- const key = `${url.pathname}?${CROP_PARAM}=${cropValue}`;
316
- let cut = ctx.crops.get(key);
317
- if (cut === void 0) {
318
- cut = readFile(asset.path).then((bytes) => cutRegion(bytes, rect));
319
- cut.catch(() => ctx.crops.delete(key));
320
- ctx.crops.set(key, cut);
321
- if (ctx.crops.size > MAX_CACHED_CROPS) ctx.crops.delete(ctx.crops.keys().next().value);
322
- }
323
- const image = await cut;
324
- if (image === null) {
325
- ctx.log.write(`concrete dev: sharp is not installed, so a crop of ${url.pathname} serves the whole image.\n`);
326
- await sendFile(req, res, asset.path);
327
- return;
328
- }
329
- res.setHeader("cache-control", "no-cache");
330
- sendBytes(res, image.contentType, image.bytes);
331
- }
332
148
 
333
149
  //#endregion
334
- export { isCanvasPath, stampBase, startDevServer };
150
+ export { DEV_BUILD_DIR, failureText, startDevServer };
@@ -0,0 +1,16 @@
1
+ import { PLAYGROUND_TOOLS, TOOLS_INSTALL_COMMAND } from "./tools.js";
2
+
3
+ //#region src/cli/install/background.ts
4
+ async function installMissingTools(log, tools = PLAYGROUND_TOOLS) {
5
+ const missing = [];
6
+ for (const tool of tools) if (!await tool.present().catch(() => true)) missing.push(tool);
7
+ if (missing.length === 0) return { ready: Promise.resolve() };
8
+ const names = missing.map((tool) => tool.name).join(" and ");
9
+ log.write(`concrete dev: installing ${names} in the background — captures wait for it.\n`);
10
+ return { ready: Promise.all(missing.map((tool) => tool.install().catch((cause) => {
11
+ log.write(`concrete dev: installing ${tool.name} failed (${cause instanceof Error ? cause.message : String(cause)}). Install it with \`${TOOLS_INSTALL_COMMAND}\`.\n`);
12
+ }))).then(() => void 0) };
13
+ }
14
+
15
+ //#endregion
16
+ export { installMissingTools };
@@ -0,0 +1,45 @@
1
+ import { parseSpec } from "../commands.js";
2
+ import { PLAYGROUND_TOOLS, TOOLS_INSTALL_COMMAND } from "./tools.js";
3
+ import { parseArgs } from "node:util";
4
+
5
+ //#region src/cli/install/index.ts
6
+ const PREFIX = "concrete install";
7
+ function messageOf(cause) {
8
+ return cause instanceof Error ? cause.message : String(cause);
9
+ }
10
+ function installWith(tools) {
11
+ return async (argv, io) => {
12
+ try {
13
+ parseArgs({
14
+ args: [...argv],
15
+ ...parseSpec("install"),
16
+ allowPositionals: false,
17
+ strict: true
18
+ });
19
+ } catch (cause) {
20
+ io.stderr.write(`${PREFIX}: ${messageOf(cause)}\n`);
21
+ return 1;
22
+ }
23
+ let failed = false;
24
+ for (const tool of tools) {
25
+ if (await tool.present()) {
26
+ io.stdout.write(`${PREFIX}: ${tool.name} is already installed.\n`);
27
+ continue;
28
+ }
29
+ io.stdout.write(`${PREFIX}: installing ${tool.name}…\n`);
30
+ try {
31
+ await tool.install({ sink: io.stderr });
32
+ io.stdout.write(`${PREFIX}: ${tool.name} installed.\n`);
33
+ } catch (cause) {
34
+ io.stderr.write(`${PREFIX}: installing ${tool.name} failed: ${messageOf(cause)}\n`);
35
+ failed = true;
36
+ }
37
+ }
38
+ if (failed) io.stderr.write(`${PREFIX}: run \`${TOOLS_INSTALL_COMMAND}\` again once the download can complete.\n`);
39
+ return failed ? 1 : 0;
40
+ };
41
+ }
42
+ const runInstall = installWith(PLAYGROUND_TOOLS);
43
+
44
+ //#endregion
45
+ export { installWith, runInstall };
@@ -0,0 +1,27 @@
1
+ import { runNodeScript } from "../../platform/process.js";
2
+ import { existsSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { createRequire } from "node:module";
5
+
6
+ //#region src/cli/install/tools.ts
7
+ const require = createRequire(import.meta.url);
8
+ const chromium = {
9
+ name: "Chromium",
10
+ async present() {
11
+ const { chromium: browser } = await import("playwright-core");
12
+ return existsSync(browser.executablePath());
13
+ },
14
+ async install({ sink } = {}) {
15
+ const failure = await runNodeScript([
16
+ join(dirname(require.resolve("playwright-core/package.json")), "cli.js"),
17
+ "install",
18
+ "chromium"
19
+ ], sink === void 0 ? {} : { sink });
20
+ if (failure !== null) throw new Error(`Playwright's installer ${failure}`);
21
+ }
22
+ };
23
+ const PLAYGROUND_TOOLS = [chromium];
24
+ const TOOLS_INSTALL_COMMAND = "npx concrete install";
25
+
26
+ //#endregion
27
+ export { PLAYGROUND_TOOLS, TOOLS_INSTALL_COMMAND, chromium };
@@ -92,16 +92,8 @@ async function lookupCached(keys, masterByteLength, cacheDir) {
92
92
  derivationCache.set(keys.memoKey, memo);
93
93
  return toDerivation(memo, keys.master, masterByteLength, false);
94
94
  }
95
- async function cachedAuthorImage(absPath, bytes, opts = {}) {
96
- return lookupCached(derivationKeys(absPath, bytes, opts), bytes.byteLength, opts.cacheDir);
97
- }
98
- async function deriveAuthorImage(absPath, bytes, opts = {}) {
99
- const keys = derivationKeys(absPath, bytes, opts);
100
- const { stem, hash, floor, memoKey, diskKey, master } = keys;
101
- const hit = await lookupCached(keys, bytes.byteLength, opts.cacheDir);
102
- if (hit) return hit;
103
- const sharp = await (opts.loadSharp ?? defaultLoadSharp)();
104
- if (!sharp) return {
95
+ function masterOnly(master, masterByteLength) {
96
+ return {
105
97
  image: {
106
98
  url: `${ASSET_PUBLIC_PATH}/${master.filename}`,
107
99
  responsive: null,
@@ -114,10 +106,24 @@ async function deriveAuthorImage(absPath, bytes, opts = {}) {
114
106
  contentType: master.contentType
115
107
  }],
116
108
  master,
117
- masterBytes: bytes.byteLength,
118
- derivedBytes: bytes.byteLength,
109
+ masterBytes: masterByteLength,
110
+ derivedBytes: masterByteLength,
119
111
  passthrough: true
120
112
  };
113
+ }
114
+ function masterOnlyDerivation(absPath, bytes) {
115
+ return masterOnly(derivationKeys(absPath, bytes, {}).master, bytes.byteLength);
116
+ }
117
+ async function cachedAuthorImage(absPath, bytes, opts = {}) {
118
+ return lookupCached(derivationKeys(absPath, bytes, opts), bytes.byteLength, opts.cacheDir);
119
+ }
120
+ async function deriveAuthorImage(absPath, bytes, opts = {}) {
121
+ const keys = derivationKeys(absPath, bytes, opts);
122
+ const { stem, hash, floor, memoKey, diskKey, master } = keys;
123
+ const hit = await lookupCached(keys, bytes.byteLength, opts.cacheDir);
124
+ if (hit) return hit;
125
+ const sharp = await (opts.loadSharp ?? defaultLoadSharp)();
126
+ if (!sharp) return masterOnly(master, bytes.byteLength);
121
127
  const { encodeRungs, LADDER_SPEC, rungsFor } = await loadImageLadder();
122
128
  const buffer = Buffer.from(bytes);
123
129
  const meta = await sharp(buffer).metadata();
@@ -170,4 +176,4 @@ async function deriveAuthorImage(absPath, bytes, opts = {}) {
170
176
  }
171
177
 
172
178
  //#endregion
173
- export { DERIVABLE_EXTENSIONS, UnsafeStemError, cachedAuthorImage, deriveAuthorImage, frameReachableRungs, masterHash };
179
+ export { DERIVABLE_EXTENSIONS, UnsafeStemError, cachedAuthorImage, deriveAuthorImage, frameReachableRungs, masterHash, masterOnlyDerivation };
@@ -1,4 +1,4 @@
1
- import { DERIVABLE_EXTENSIONS, deriveAuthorImage } from "./derive.js";
1
+ import { DERIVABLE_EXTENSIONS, cachedAuthorImage, deriveAuthorImage, masterOnlyDerivation } from "./derive.js";
2
2
  import { extname } from "node:path";
3
3
  import { readFile } from "node:fs/promises";
4
4
 
@@ -10,6 +10,7 @@ function createMediaDeriver(opts = {}) {
10
10
  const derived = /* @__PURE__ */ new Map();
11
11
  const masters = /* @__PURE__ */ new Map();
12
12
  const passthrough = /* @__PURE__ */ new Set();
13
+ const pending = /* @__PURE__ */ new Set();
13
14
  const sources = /* @__PURE__ */ new Map();
14
15
  return {
15
16
  plugin: {
@@ -37,10 +38,19 @@ function createMediaDeriver(opts = {}) {
37
38
  namespace: NAMESPACE
38
39
  }, async (args) => {
39
40
  const bytes = await readFile(args.path);
40
- const derivation = await deriveAuthorImage(args.path, bytes, {
41
+ const options = {
41
42
  cacheDir: opts.cacheDir,
42
43
  minRungWidth: opts.minRungWidth
43
- });
44
+ };
45
+ let derivation = opts.pending === void 0 ? await deriveAuthorImage(args.path, bytes, options) : await cachedAuthorImage(args.path, bytes, options);
46
+ if (derivation === null) {
47
+ derivation = {
48
+ ...masterOnlyDerivation(args.path, bytes),
49
+ passthrough: false
50
+ };
51
+ pending.add(args.path);
52
+ opts.pending?.derive(args.path, bytes, opts.minRungWidth);
53
+ }
44
54
  for (const asset of derivation.derivatives) derived.set(asset.filename, asset);
45
55
  const { key, filename, bytes: masterBytes, contentType } = derivation.master;
46
56
  derived.set(filename, {
@@ -65,6 +75,7 @@ function createMediaDeriver(opts = {}) {
65
75
  derived,
66
76
  masters,
67
77
  passthrough,
78
+ pending,
68
79
  sources
69
80
  };
70
81
  }