@homepages/concrete 11.0.0 → 13.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 (322) hide show
  1. package/CHANGELOG.md +203 -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 +17 -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 -60
  16. package/dist/base.css +19 -59
  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 +48 -22
  123. package/dist/packages/internal/fill-bake/dist/held-rows.js +2 -0
  124. package/dist/packages/internal/fill-bake/dist/index.js +6 -1
  125. package/dist/packages/internal/fill-bake/dist/item-merge.js +4 -3
  126. package/dist/packages/internal/fill-bake/dist/resolve-instance.js +9 -0
  127. package/dist/packages/internal/fill-bake/dist/resolve.js +3 -0
  128. package/dist/packages/internal/fill-bake/dist/round-trip.js +2 -0
  129. package/dist/packages/internal/fill-bake/dist/strip.js +6 -0
  130. package/dist/packages/internal/fill-vocabulary/dist/holder.js +1 -1
  131. package/dist/packages/internal/fill-vocabulary/dist/resolved-decision.js +1 -1
  132. package/dist/packages/internal/fill-vocabulary/dist/verbs.js +1 -1
  133. package/dist/packages/internal/format-geometry/dist/capture.js +3 -11
  134. package/dist/packages/internal/format-geometry/dist/format.d.ts +2 -8
  135. package/dist/packages/internal/format-geometry/dist/geometry.js +2 -13
  136. package/dist/packages/internal/island-runtime/dist/index.js +1 -10
  137. package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +5 -0
  138. package/dist/packages/internal/lead-fields/dist/ingest.js +72 -0
  139. package/dist/packages/internal/media-resolution/dist/video.js +6 -2
  140. package/dist/packages/internal/page-render/dist/addresses.js +57 -0
  141. package/dist/packages/internal/page-render/dist/index.js +6 -0
  142. package/dist/packages/internal/page-render/dist/kept.js +30 -0
  143. package/dist/packages/internal/page-render/dist/nav.js +42 -0
  144. package/dist/packages/internal/page-render/dist/render.js +152 -0
  145. package/dist/packages/internal/page-shell/dist/assemble.js +161 -0
  146. package/dist/packages/internal/page-shell/dist/escape.js +10 -0
  147. package/dist/packages/internal/page-shell/dist/frame.js +23 -0
  148. package/dist/packages/internal/page-shell/dist/index.js +26 -0
  149. package/dist/packages/internal/playground/dist/build-fingerprint.js +18 -0
  150. package/dist/packages/internal/playground/dist/fixture-conversions/list-names-properties.js +76 -0
  151. package/dist/packages/internal/playground/dist/fixture-formats.d.ts +37 -0
  152. package/dist/packages/internal/playground/dist/fixture-formats.js +20 -0
  153. package/dist/packages/internal/playground/dist/host/bootstrap.js +108 -0
  154. package/dist/packages/internal/playground/dist/host/built.js +202 -0
  155. package/dist/packages/internal/playground/dist/host/catalog-fixture.js +53 -0
  156. package/dist/packages/internal/playground/dist/host/download.js +34 -0
  157. package/dist/packages/internal/playground/dist/host/env.js +11 -0
  158. package/dist/packages/internal/playground/dist/host/everywhere-saves.js +353 -0
  159. package/dist/packages/internal/playground/dist/host/fixture-addresses.js +52 -0
  160. package/dist/packages/internal/playground/dist/host/fixture-documents.js +494 -0
  161. package/dist/packages/internal/playground/dist/host/fixture-operations.js +364 -0
  162. package/dist/packages/internal/playground/dist/host/fixture-units.js +93 -0
  163. package/dist/{fixtures → packages/internal/playground/dist/host}/image-dimensions.js +1 -1
  164. package/dist/packages/internal/playground/dist/host/leads.js +41 -0
  165. package/dist/packages/internal/playground/dist/host/media-saves.js +309 -0
  166. package/dist/{fixtures → packages/internal/playground/dist/host}/media-store.js +79 -26
  167. package/dist/packages/internal/playground/dist/host/overridable.js +9 -0
  168. package/dist/packages/internal/playground/dist/host/owned-saves.js +203 -0
  169. package/dist/{playground → packages/internal/playground/dist}/host/page-state.js +1 -1
  170. package/dist/packages/internal/playground/dist/host/program.js +54 -0
  171. package/dist/packages/internal/playground/dist/host/property-derive.js +216 -0
  172. package/dist/packages/internal/playground/dist/host/property-saves.js +74 -0
  173. package/dist/{fixtures → packages/internal/playground/dist/host}/property.js +88 -229
  174. package/dist/packages/internal/playground/dist/host/provenance.js +49 -0
  175. package/dist/packages/internal/playground/dist/host/resolve.js +553 -0
  176. package/dist/packages/internal/playground/dist/host/row-images.js +41 -0
  177. package/dist/{fixtures → packages/internal/playground/dist/host}/rows.js +1 -1
  178. package/dist/packages/internal/playground/dist/host/save.js +429 -0
  179. package/dist/packages/internal/playground/dist/host/serve.js +952 -0
  180. package/dist/packages/internal/playground/dist/host/site.js +79 -0
  181. package/dist/packages/internal/playground/dist/host/slots.js +202 -0
  182. package/dist/packages/internal/playground/dist/host/stated-content.js +93 -0
  183. package/dist/packages/internal/playground/dist/host/stored-fixtures.js +135 -0
  184. package/dist/packages/internal/playground/dist/host/violations.js +7 -0
  185. package/dist/packages/internal/playground/dist/jobs/lanes.js +24 -0
  186. package/dist/packages/internal/playground/dist/jobs/memory-queue.js +112 -0
  187. package/dist/packages/internal/playground/dist/jobs/probe.js +37 -0
  188. package/dist/packages/internal/playground/dist/jobs/queue.js +28 -0
  189. package/dist/packages/internal/playground/dist/jobs/runner.js +207 -0
  190. package/dist/packages/internal/playground/dist/layout.js +14 -0
  191. package/dist/packages/internal/playground/dist/platform.js +33 -0
  192. package/dist/packages/internal/playground/dist/server/changes.js +57 -0
  193. package/dist/packages/internal/playground/dist/server/crop.js +47 -0
  194. package/dist/packages/internal/playground/dist/server/derived-files.js +88 -0
  195. package/dist/packages/internal/playground/dist/server/download.js +158 -0
  196. package/dist/{cli/dev → packages/internal/playground/dist/server}/http.js +4 -12
  197. package/dist/packages/internal/playground/dist/server/jobs.js +29 -0
  198. package/dist/{cli/dev → packages/internal/playground/dist/server}/listen.js +4 -11
  199. package/dist/packages/internal/playground/dist/server/playground-server.js +424 -0
  200. package/dist/{cli/dev → packages/internal/playground/dist/server}/request-error.js +1 -1
  201. package/dist/packages/internal/playground/dist/server/size-ladders.js +170 -0
  202. package/dist/packages/internal/playground/dist/server/verification.js +75 -0
  203. package/dist/packages/internal/playground/dist/server/verify-build.js +139 -0
  204. package/dist/packages/internal/playground/dist/wire.js +78 -0
  205. package/dist/packages/internal/property-facts/dist/registry-facts.js +1 -1
  206. package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +1 -1
  207. package/dist/packages/internal/section-contracts/dist/reads-acyclic-contract.js +1 -1
  208. package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +1 -1
  209. package/dist/packages/internal/site-files/dist/head.js +59 -0
  210. package/dist/packages/internal/site-files/dist/index.js +4 -0
  211. package/dist/packages/internal/site-files/dist/site.js +211 -0
  212. package/dist/packages/internal/static-assets-binding/dist/index.js +32 -0
  213. package/dist/packages/internal/static-assets-binding/dist/section-asset-url.js +38 -5
  214. package/dist/packages/internal/template-artifact/dist/asset-mime.js +8 -1
  215. package/dist/packages/internal/template-artifact/dist/build.js +148 -0
  216. package/dist/packages/internal/template-artifact/dist/composition.js +62 -0
  217. package/dist/packages/internal/template-artifact/dist/index.js +2 -2
  218. package/dist/packages/internal/template-artifact/dist/layout.js +48 -12
  219. package/dist/packages/internal/template-artifact/dist/manifest.js +3 -10
  220. package/dist/packages/internal/template-artifact/dist/verify.js +51 -31
  221. package/dist/packages/internal/template-contracts/dist/address-value.js +6 -1
  222. package/dist/packages/internal/template-contracts/dist/content-categories.js +10 -1
  223. package/dist/packages/internal/template-contracts/dist/fact-compute.d.ts +1 -1
  224. package/dist/packages/internal/template-contracts/dist/fact-keys.d.ts +1 -1
  225. package/dist/packages/internal/template-contracts/dist/fact-registry.d.ts +3 -3
  226. package/dist/packages/internal/template-contracts/dist/fact-registry.js +59 -32
  227. package/dist/packages/internal/template-contracts/dist/fill-spec.js +14 -1
  228. package/dist/packages/internal/template-contracts/dist/list.d.ts +3 -3
  229. package/dist/packages/internal/template-contracts/dist/media-candidates.js +67 -2
  230. package/dist/packages/internal/template-contracts/dist/media-offer.js +180 -0
  231. package/dist/packages/internal/template-contracts/dist/object.d.ts +2 -2
  232. package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +9 -2
  233. package/dist/packages/internal/template-contracts/dist/read-graph.js +36 -2
  234. package/dist/packages/internal/template-contracts/dist/ref-locate.js +16 -1
  235. package/dist/packages/internal/template-contracts/dist/registry-facts.d.ts +9 -10
  236. package/dist/packages/internal/template-contracts/dist/registry-facts.js +12 -1
  237. package/dist/packages/internal/template-contracts/dist/registry-graph.js +112 -0
  238. package/dist/packages/internal/template-contracts/dist/registry-shape.js +15 -2
  239. package/dist/packages/internal/template-contracts/dist/require-graph.js +300 -0
  240. package/dist/packages/internal/template-contracts/dist/row-ref.d.ts +3 -3
  241. package/dist/packages/internal/template-contracts/dist/row.d.ts +3 -3
  242. package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +1 -1
  243. package/dist/{schema → packages/internal/template-contracts/dist}/section-nav.d.ts +1 -1
  244. package/dist/packages/internal/template-contracts/dist/slot-builders.d.ts +4 -4
  245. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +3 -1
  246. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +24 -1
  247. package/dist/packages/internal/template-contracts/dist/slot-overrides.js +26 -1
  248. package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +1 -1
  249. package/dist/packages/internal/template-contracts/dist/slot-types.js +1 -1
  250. package/dist/packages/internal/template-contracts/dist/slot-value.d.ts +1 -1
  251. package/dist/packages/internal/template-contracts/dist/table-members.js +7 -2
  252. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
  253. package/dist/packages/internal/upload-formats/dist/heic.js +35 -0
  254. package/dist/packages/internal/upload-formats/dist/index.js +80 -0
  255. package/dist/packages/internal/upload-formats/dist/magic-bytes.js +293 -0
  256. package/dist/platform/paths.js +1 -0
  257. package/dist/platform/process.js +49 -1
  258. package/dist/primitives/FrameShell.d.ts +5 -2
  259. package/dist/primitives/FrameShell.js +2 -1
  260. package/dist/rules/registry.js +28 -4
  261. package/dist/schema/fact.d.ts +2 -2
  262. package/dist/schema/facts-view.d.ts +1 -1
  263. package/dist/schema/format.d.ts +0 -1
  264. package/dist/schema/format.js +1 -2
  265. package/dist/schema/manifest.js +18 -24
  266. package/dist/schema/section-props.d.ts +1 -1
  267. package/dist/schema/section-schema.d.ts +1 -1
  268. package/dist/schema/section-schema.js +1 -0
  269. package/dist/section/declare.d.ts +1 -1
  270. package/dist/section/discovery.js +6 -2
  271. package/dist/section/publish-shape.js +38 -0
  272. package/dist/section/section.d.ts +1 -1
  273. package/dist/site-analytics.js +6 -1
  274. package/dist/site-runtime/window-height.js +19 -0
  275. package/dist/template/define-template.d.ts +25 -4
  276. package/dist/template/define-template.js +3 -0
  277. package/dist/template/logic-shim.d.ts +1 -1
  278. package/dist/template/materialize.js +3 -1
  279. package/dist/template/running-copy.js +0 -1
  280. package/dist/template/section-reads.js +1 -1
  281. package/guide/reference/cli/INDEX.md +6 -5
  282. package/guide/reference/cli/build.md +10 -8
  283. package/guide/reference/cli/check.md +4 -2
  284. package/guide/reference/cli/dev.md +6 -2
  285. package/guide/reference/cli/install.md +41 -0
  286. package/guide/reference/cli/property-add.md +5 -4
  287. package/guide/reference/cli/property-list.md +2 -2
  288. package/guide/reference/cli/publish.md +5 -5
  289. package/guide/reference/cli/upgrade.md +1 -1
  290. package/guide/reference/rules/INDEX.md +9 -5
  291. package/package.json +14 -30
  292. package/dist/artifact/playground/client/assets/index-ByeGGedv.js +0 -1259
  293. package/dist/artifact/playground/client/assets/index-CxWPYOH2.css +0 -1
  294. package/dist/cli/build/artifact.js +0 -220
  295. package/dist/cli/build/captures.js +0 -48
  296. package/dist/cli/build/fixtures.js +0 -92
  297. package/dist/cli/capture/capture-browser.js +0 -37
  298. package/dist/cli/capture/capture.js +0 -113
  299. package/dist/cli/check/render/inputs.js +0 -60
  300. package/dist/cli/check/render/nav.js +0 -31
  301. package/dist/cli/dev/crop.js +0 -20
  302. package/dist/cli/dev/fixture-ladders.js +0 -96
  303. package/dist/cli/dev/hmr.js +0 -26
  304. package/dist/cli/dev/islands.js +0 -234
  305. package/dist/cli/dev/load-template.js +0 -52
  306. package/dist/cli/dev/vite.js +0 -114
  307. package/dist/cli/dev/workspace-reader.js +0 -248
  308. package/dist/cli/publish/freshness.js +0 -64
  309. package/dist/fixtures/brand.d.ts +0 -4
  310. package/dist/fixtures/brand.js +0 -8
  311. package/dist/fixtures/load.js +0 -159
  312. package/dist/fixtures/resolve.js +0 -392
  313. package/dist/fixtures.d.ts +0 -429
  314. package/dist/fixtures.js +0 -23
  315. package/dist/packages/internal/canvas-core/dist/island-host.js +0 -62
  316. package/dist/packages/internal/canvas-core/dist/island-shields.js +0 -30
  317. package/dist/playground/canvas-island-host.d.ts +0 -11
  318. package/dist/playground/canvas-island-host.js +0 -29
  319. package/dist/playground/canvas-markers.js +0 -14
  320. package/dist/playground/host/paths.js +0 -8
  321. package/dist/playground/layout.js +0 -17
  322. package/dist/playground/wire.js +0 -28
@@ -0,0 +1,125 @@
1
+ import { externalFile, packageFile, workspacePath } from "../../platform/paths.js";
2
+ import { FIXTURE_MEDIA_PATH, MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace } from "../../fixtures/media-plugin.js";
3
+ import { listDirSync, removeTree } from "../../platform/fs.js";
4
+ import { createPackageStylesheetsPlugin } from "../../fixtures/package-stylesheets.js";
5
+ import { runningCopyPlugin } from "../../template/running-copy.js";
6
+ import { basename, join } from "node:path";
7
+ import { pathToFileURL } from "node:url";
8
+ import { mkdir, mkdtemp } from "node:fs/promises";
9
+ import { build } from "esbuild";
10
+ import { createHash } from "node:crypto";
11
+
12
+ //#region src/cli/upgrade/fixture-modules.ts
13
+ const FIXTURES_DIR = "fixtures";
14
+ const MODULE_FILE = /\.(?:[cm]?[jt]s|[jt]sx)$/;
15
+ const SKIPPED_FILE = /\.test\.[^/]+$|\.d\.[cm]?ts$/;
16
+ const SKIPPED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".concrete"]);
17
+ function listFixtureModules(root) {
18
+ const out = [];
19
+ const walk = (dir) => {
20
+ let entries;
21
+ try {
22
+ entries = listDirSync(dir);
23
+ } catch {
24
+ return;
25
+ }
26
+ for (const entry of entries) {
27
+ if (entry.name.startsWith(".")) continue;
28
+ if (entry.isDirectory()) {
29
+ if (!SKIPPED_DIRS.has(entry.name)) walk(entry.path);
30
+ } else if (entry.isFile() && MODULE_FILE.test(entry.name) && !SKIPPED_FILE.test(entry.name)) out.push(entry.path);
31
+ }
32
+ };
33
+ walk(join(root, FIXTURES_DIR));
34
+ return out;
35
+ }
36
+ function legacyFixturesFile() {
37
+ return packageFile("cli/upgrade/legacy-fixtures.ts", "cli/upgrade/legacy-fixtures.js");
38
+ }
39
+ function retiredSubpathPlugin() {
40
+ const file = legacyFixturesFile();
41
+ return {
42
+ name: "concrete-retired-fixtures-subpath",
43
+ setup(pass) {
44
+ pass.onResolve({ filter: /^@homepages\/concrete\/fixtures$/ }, () => externalFile(file));
45
+ }
46
+ };
47
+ }
48
+ function buildMessages(err) {
49
+ const messages = err.errors;
50
+ return Array.isArray(messages) ? messages : null;
51
+ }
52
+ function urlOfPath(path) {
53
+ return `${FIXTURE_MEDIA_PATH}/${createHash("sha256").update(path).digest("hex").slice(0, 12)}/${basename(path)}`;
54
+ }
55
+ let importSerial = 0;
56
+ async function evaluateFixtureModules(root, files) {
57
+ const cache = join(root, ".concrete", "cache", "fixtures");
58
+ await mkdir(cache, { recursive: true });
59
+ const outdir = await mkdtemp(join(cache, `${importSerial++}-`));
60
+ const media = createFixtureMediaPlugin(root, urlOfPath);
61
+ const stylesheets = await createPackageStylesheetsPlugin(root);
62
+ try {
63
+ let result;
64
+ try {
65
+ result = await build({
66
+ entryPoints: [...files],
67
+ bundle: true,
68
+ splitting: true,
69
+ format: "esm",
70
+ platform: "node",
71
+ target: "node22",
72
+ outdir,
73
+ outExtension: { ".js": ".mjs" },
74
+ outbase: root,
75
+ absWorkingDir: root,
76
+ packages: "external",
77
+ jsx: "automatic",
78
+ loader: {
79
+ ".css": "empty",
80
+ ...MEDIA_LOADERS
81
+ },
82
+ plugins: [
83
+ retiredSubpathPlugin(),
84
+ runningCopyPlugin(),
85
+ externalOutsideWorkspace(root),
86
+ media.plugin,
87
+ stylesheets.plugin
88
+ ],
89
+ metafile: true,
90
+ write: true,
91
+ logLevel: "silent"
92
+ });
93
+ } catch (err) {
94
+ const messages = buildMessages(err);
95
+ if (messages === null) throw err;
96
+ return {
97
+ modules: /* @__PURE__ */ new Map(),
98
+ assets: media.assets,
99
+ problems: messages.map((m) => ({
100
+ file: m.location?.file ?? `${"fixtures"}/`,
101
+ message: m.location === null || m.location === void 0 ? m.text : `${m.text} (${m.location.file}:${String(m.location.line)})`
102
+ }))
103
+ };
104
+ }
105
+ const outputByInput = /* @__PURE__ */ new Map();
106
+ for (const [out, meta] of Object.entries(result.metafile.outputs)) if (meta.entryPoint !== void 0) outputByInput.set(join(root, meta.entryPoint), join(root, out));
107
+ const modules = /* @__PURE__ */ new Map();
108
+ for (const file of files) {
109
+ const out = outputByInput.get(file);
110
+ if (out === void 0) throw new Error(`fixtures: esbuild produced no output for ${workspacePath(root, file)}.`);
111
+ modules.set(file, await import(pathToFileURL(out).href));
112
+ }
113
+ return {
114
+ modules,
115
+ assets: media.assets,
116
+ problems: []
117
+ };
118
+ } finally {
119
+ await stylesheets.dispose();
120
+ await removeTree(outdir);
121
+ }
122
+ }
123
+
124
+ //#endregion
125
+ export { FIXTURES_DIR, evaluateFixtureModules, legacyFixturesFile, listFixtureModules };
@@ -0,0 +1,40 @@
1
+ import { CodemodReport } from "./codemod.js";
2
+ //#region src/cli/upgrade/fixtures-to-data.d.ts
3
+ /** Where the fixture list is written, and how `template.ts` names it. */
4
+ declare const FIXTURE_LIST = "fixtures/index.json";
5
+ /** A property the conversion made by copying files into a folder of its own. */
6
+ interface MadeProperty {
7
+ /** Its document, relative to the workspace root. */
8
+ readonly document: string;
9
+ /** What it was written as: an export (`module#name`) or the fixture that stated it inline. */
10
+ readonly from: string;
11
+ /** The fixtures on it. */
12
+ readonly fixtures: readonly string[];
13
+ /** The files copied into its folder, and their bytes. */
14
+ readonly files: number;
15
+ readonly bytes: number;
16
+ }
17
+ interface FixturesToDataReport extends CodemodReport {
18
+ /** Every property made by copying, for the author to keep or drop. */
19
+ readonly made: readonly MadeProperty[];
20
+ /** Every content fixture written, relative to the workspace root, in list order. */
21
+ readonly fixtures: readonly string[];
22
+ }
23
+ /** `newBuildingThin` → `new-building-thin`: an export name as a file name. */
24
+ declare function kebabCase(name: string): string;
25
+ /** `template.ts` with the `fixtures` member added to its `defineTemplate({ … })`, or why it cannot be. */
26
+ declare function withFixturesMember(source: string, list: string): {
27
+ readonly text: string;
28
+ } | {
29
+ readonly unchanged: true;
30
+ } | {
31
+ readonly reason: string;
32
+ };
33
+ /**
34
+ * Convert the workspace at `root`. Returns what it wrote and removed, what it handed back,
35
+ * and the properties it made by copying. A workspace with no fixture module is left as it is.
36
+ * Throws when the modules do not load.
37
+ */
38
+ declare function fixturesToData(root: string): Promise<FixturesToDataReport>;
39
+ //#endregion
40
+ export { FIXTURE_LIST, FixturesToDataReport, MadeProperty, fixturesToData, kebabCase, withFixturesMember };
@@ -0,0 +1,498 @@
1
+ import { isMediaType } from "../../packages/internal/template-contracts/dist/slot-catalog.js";
2
+ import { toPosix, workspacePath } from "../../platform/paths.js";
3
+ import { contactImageId } from "../../packages/internal/playground/dist/host/property-derive.js";
4
+ import { MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace } from "../../fixtures/media-plugin.js";
5
+ import { isOverridable } from "../../packages/internal/playground/dist/host/overridable.js";
6
+ import { removeTree } from "../../platform/fs.js";
7
+ import "../../packages/internal/playground/dist/host/property.js";
8
+ import { FIXTURES_DIR, evaluateFixtureModules, listFixtureModules } from "./fixture-modules.js";
9
+ import { isFixture } from "./legacy-fixtures.js";
10
+ import { basename, dirname, extname, join, relative } from "node:path";
11
+ import ts from "typescript";
12
+ import { copyFile, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
13
+ import { build } from "esbuild";
14
+
15
+ //#region src/cli/upgrade/fixtures-to-data.ts
16
+ const FIXTURE_LIST = `${FIXTURES_DIR}/index.json`;
17
+ const TEMPLATE_FILE = "template.ts";
18
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
19
+ function kebabCase(name) {
20
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/([a-zA-Z])([0-9])/g, "$1-$2").replace(/[^A-Za-z0-9]+/g, "-").replace(/^-+|-+$/g, "").toLowerCase();
21
+ }
22
+ const posix = (path) => toPosix(path);
23
+ function relativeTo(from, to) {
24
+ return posix(relative(dirname(from), to));
25
+ }
26
+ function json(value) {
27
+ return `${JSON.stringify(value, null, 2)}\n`;
28
+ }
29
+ async function exists(path) {
30
+ try {
31
+ await stat(path);
32
+ return true;
33
+ } catch {
34
+ return false;
35
+ }
36
+ }
37
+ async function evaluate(root) {
38
+ const files = listFixtureModules(root);
39
+ if (files.length === 0) return null;
40
+ const imported = await evaluateFixtureModules(root, files);
41
+ if (imported.problems.length > 0) throw new Error(`the fixture modules do not load, so there is nothing to convert from:\n${imported.problems.map((v) => ` ${v.file}: ${v.message}`).join("\n")}`);
42
+ const fixtures = [];
43
+ const exports = [];
44
+ const seen = /* @__PURE__ */ new Set();
45
+ for (const file of files) {
46
+ const module = workspacePath(root, file);
47
+ for (const [name, value] of Object.entries(imported.modules.get(file) ?? {})) {
48
+ exports.push({
49
+ value,
50
+ module,
51
+ name
52
+ });
53
+ if (!isFixture(value) || seen.has(value)) continue;
54
+ seen.add(value);
55
+ fixtures.push({
56
+ id: name,
57
+ fixture: value
58
+ });
59
+ }
60
+ }
61
+ const own = files.map((f) => workspacePath(root, f));
62
+ const template = join(root, TEMPLATE_FILE);
63
+ const shipped = await exists(template) ? await workspaceModules(root, [template]) : /* @__PURE__ */ new Set();
64
+ const only = [...await workspaceModules(root, files)].filter((m) => !shipped.has(m) && !own.includes(m)).sort();
65
+ return {
66
+ fixtures,
67
+ exports,
68
+ assets: imported.assets,
69
+ modules: [...own, ...only]
70
+ };
71
+ }
72
+ async function workspaceModules(root, entries) {
73
+ const inputs = (await build({
74
+ entryPoints: [...entries],
75
+ bundle: true,
76
+ format: "esm",
77
+ platform: "node",
78
+ outdir: join(root, ".concrete", "cache", "fixtures-to-data"),
79
+ outbase: root,
80
+ absWorkingDir: root,
81
+ packages: "external",
82
+ jsx: "automatic",
83
+ loader: {
84
+ ".css": "empty",
85
+ ...MEDIA_LOADERS
86
+ },
87
+ plugins: [externalOutsideWorkspace(root), createFixtureMediaPlugin(root).plugin],
88
+ metafile: true,
89
+ write: false,
90
+ logLevel: "silent"
91
+ })).metafile.inputs;
92
+ return new Set(Object.keys(inputs).map((input) => toPosix(input)).filter((file) => !file.includes(":") && !file.startsWith("../") && /\.[cm]?[jt]sx?$/.test(file)));
93
+ }
94
+ const UPLOAD_FILES = [
95
+ "file",
96
+ "poster",
97
+ "preview"
98
+ ];
99
+ const CONTACT_FILES = [
100
+ "headshot",
101
+ "logo_dark",
102
+ "logo_light"
103
+ ];
104
+ const PICK_LISTS = [
105
+ "property_media",
106
+ "floor_plans",
107
+ "property_documents"
108
+ ];
109
+ const ROW_TABLES = ["units", "commercial_spaces"];
110
+ function pick(value) {
111
+ return isRecord(value) && typeof value["id"] === "string" ? { media: value["id"] } : value;
112
+ }
113
+ function propertyDocument(property, fileOf) {
114
+ const doc = { ...property };
115
+ if (Array.isArray(property["uploads"])) doc["uploads"] = property["uploads"].map((raw, i) => {
116
+ if (!isRecord(raw)) return raw;
117
+ const entry = { ...raw };
118
+ for (const member of UPLOAD_FILES) if (entry[member] !== void 0 && entry[member] !== null) entry[member] = { file: fileOf(entry[member], `uploads[${String(i)}].${member}`) };
119
+ return entry;
120
+ });
121
+ for (const list of PICK_LISTS) if (Array.isArray(property[list])) doc[list] = property[list].map(pick);
122
+ if (property["hero"] !== void 0 && property["hero"] !== null) doc["hero"] = pick(property["hero"]);
123
+ for (const table of ROW_TABLES) {
124
+ if (!Array.isArray(property[table])) continue;
125
+ doc[table] = property[table].map((raw) => {
126
+ if (!isRecord(raw)) return raw;
127
+ const row = { ...raw };
128
+ if (Array.isArray(row["photos"])) row["photos"] = row["photos"].map(pick);
129
+ if (Array.isArray(row["floor_plans"])) row["floor_plans"] = row["floor_plans"].map((plan) => isRecord(plan) ? {
130
+ ...plan,
131
+ image: pick(plan["image"])
132
+ } : plan);
133
+ return row;
134
+ });
135
+ }
136
+ if (Array.isArray(property["contacts"])) doc["contacts"] = property["contacts"].map((raw, i) => {
137
+ if (!isRecord(raw)) return raw;
138
+ const contact = { ...raw };
139
+ for (const member of CONTACT_FILES) if (contact[member] !== void 0 && contact[member] !== null) contact[member] = { file: fileOf(contact[member], `contacts[${String(i)}].${member}`) };
140
+ return contact;
141
+ });
142
+ if (Array.isArray(property["comparables"])) doc["comparables"] = property["comparables"].map((raw, i) => {
143
+ if (!isRecord(raw) || raw["photo"] === void 0 || raw["photo"] === null) return raw;
144
+ return {
145
+ ...raw,
146
+ photo: { file: fileOf(raw["photo"], `comparables[${String(i)}].photo`) }
147
+ };
148
+ });
149
+ return doc;
150
+ }
151
+ const isFilePlaceholder = (value) => isRecord(value) && Object.keys(value).length === 1 && typeof value["file"] === "string";
152
+ function filesOf(value, out = []) {
153
+ if (isFilePlaceholder(value)) {
154
+ if (!out.includes(value.file)) out.push(value.file);
155
+ } else if (Array.isArray(value)) for (const item of value) filesOf(item, out);
156
+ else if (isRecord(value)) for (const item of Object.values(value)) filesOf(item, out);
157
+ return out;
158
+ }
159
+ function withPaths(value, pathOf) {
160
+ if (isFilePlaceholder(value)) return pathOf(value.file);
161
+ if (Array.isArray(value)) return value.map((item) => withPaths(item, pathOf));
162
+ if (isRecord(value)) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, withPaths(item, pathOf)]));
163
+ return value;
164
+ }
165
+ function isPropertyShaped(value) {
166
+ return isRecord(value) && !isFixture(value) && isRecord(value["address"]) && Array.isArray(value["uploads"]) && "listing_intent" in value;
167
+ }
168
+ const CONTACT_IMAGE_FIELDS = /* @__PURE__ */ new Set([
169
+ "headshot",
170
+ "logo_dark",
171
+ "logo_light"
172
+ ]);
173
+ function mediaValue(value) {
174
+ if (!isRecord(value)) return value;
175
+ if ("image" in value && "crop" in value) {
176
+ const ref = mediaValue(value["image"]);
177
+ if (!isRecord(ref)) return value;
178
+ return {
179
+ ...ref,
180
+ crop: value["crop"],
181
+ ...isRecord(value["mobile"]) && value["mobile"]["crop"] !== void 0 ? { mobile: { crop: value["mobile"]["crop"] } } : {}
182
+ };
183
+ }
184
+ if (typeof value["field"] === "string" && CONTACT_IMAGE_FIELDS.has(value["field"]) && isRecord(value["contact"]) && typeof value["contact"]["id"] === "string") return { media: contactImageId(value["contact"]["id"], value["field"]) };
185
+ return typeof value["id"] === "string" ? { media: value["id"] } : value;
186
+ }
187
+ function dataValue(def, value) {
188
+ if (value === void 0 || value === null) return void 0;
189
+ if (def === void 0) return value;
190
+ if (isMediaType(def.type)) return mediaValue(value);
191
+ if (def.type === "object" && isRecord(value)) return dataFields(def.fields, value, false);
192
+ if (def.type === "list" && Array.isArray(value) && def.element !== void 0) {
193
+ const element = def.element;
194
+ if (element.type === "object") {
195
+ const fields = element.fields;
196
+ return value.map((item) => isRecord(item) ? dataFields(fields, item, false) : item);
197
+ }
198
+ return value.map((item) => dataValue(element, item)).filter((item) => item !== void 0);
199
+ }
200
+ return value;
201
+ }
202
+ function dataFields(fields, value, top) {
203
+ const out = {};
204
+ for (const [key, item] of Object.entries(value)) {
205
+ const def = fields[key];
206
+ if (top && def !== void 0 && isOverridable(def)) continue;
207
+ const converted = key === "id" && def === void 0 ? item : dataValue(def, item);
208
+ if (converted !== void 0) out[key] = converted;
209
+ }
210
+ return out;
211
+ }
212
+ function instanceDocument(entry) {
213
+ const declared = entry.section.schema?.slots ?? {};
214
+ const { enabled, variant, ...values } = entry.values;
215
+ const slots = {};
216
+ for (const [id, value] of Object.entries(values)) {
217
+ const def = declared[id];
218
+ if (def !== void 0 && isOverridable(def)) continue;
219
+ const converted = def?.type === "object" && isRecord(value) ? dataFields(def.fields, value, true) : dataValue(def, value);
220
+ if (converted !== void 0) slots[id] = converted;
221
+ }
222
+ const scalar = {};
223
+ for (const [id, value] of Object.entries(entry.overrides ?? {})) {
224
+ if (value === void 0) continue;
225
+ const def = declared[id];
226
+ if (def?.type === "object" && isRecord(value)) {
227
+ const fields = def.fields;
228
+ const object = isRecord(slots[id]) ? { ...slots[id] } : {};
229
+ for (const [field, fieldValue] of Object.entries(value)) {
230
+ if (fieldValue === void 0) continue;
231
+ object[field] = fieldValue === null ? null : dataValue(fields[field], fieldValue);
232
+ scalar[`${id}.${field}`] = true;
233
+ }
234
+ slots[id] = object;
235
+ } else {
236
+ slots[id] = value === null ? null : dataValue(def, value);
237
+ scalar[id] = true;
238
+ }
239
+ }
240
+ const doc = {};
241
+ if (Object.keys(slots).length > 0) doc.slots = slots;
242
+ if (Object.keys(scalar).length > 0) doc.slot_overrides = { scalar };
243
+ if (typeof enabled === "boolean") doc.enabled = enabled;
244
+ if (typeof variant === "string") doc.variant = variant;
245
+ return {
246
+ instance: entry.instance ?? `${entry.section.key}-1`,
247
+ doc
248
+ };
249
+ }
250
+ function withFixturesMember(source, list) {
251
+ const file = ts.createSourceFile(TEMPLATE_FILE, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
252
+ let literal;
253
+ const visit = (node) => {
254
+ if (literal !== void 0) return;
255
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "defineTemplate") {
256
+ const arg = node.arguments[0];
257
+ if (arg !== void 0 && ts.isObjectLiteralExpression(arg)) literal = arg;
258
+ return;
259
+ }
260
+ ts.forEachChild(node, visit);
261
+ };
262
+ visit(file);
263
+ if (literal === void 0) return { reason: "no `defineTemplate({ … })` call with an object literal to add `fixtures` to" };
264
+ if (literal.properties.find((p) => p.name !== void 0 && (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name)) && p.name.text === "fixtures") !== void 0) return { unchanged: true };
265
+ const member = `fixtures: ${JSON.stringify(list)},`;
266
+ const last = literal.properties[literal.properties.length - 1];
267
+ if (last === void 0) {
268
+ const open = literal.getStart(file) + 1;
269
+ return { text: `${source.slice(0, open)} ${member} ${source.slice(open)}` };
270
+ }
271
+ const lineStart = source.lastIndexOf("\n", last.getStart(file)) + 1;
272
+ const indent = /^[ \t]*/.exec(source.slice(lineStart))?.[0] ?? " ";
273
+ let end = last.getEnd();
274
+ const hasComma = literal.properties.hasTrailingComma;
275
+ if (hasComma) end = source.indexOf(",", end) + 1;
276
+ return { text: `${source.slice(0, end)}${hasComma ? "" : ","}\n${indent}${member}${source.slice(end)}` };
277
+ }
278
+ async function fixturesToData(root) {
279
+ const evaluated = await evaluate(root);
280
+ if (evaluated === null) return {
281
+ rewritten: [],
282
+ notRewritten: [],
283
+ made: [],
284
+ fixtures: []
285
+ };
286
+ const notRewritten = [];
287
+ const rewritten = [];
288
+ const fileOf = (value, at) => {
289
+ const url = typeof value === "string" ? value : isRecord(value) && typeof value["url"] === "string" ? value["url"] : null;
290
+ const asset = url === null ? void 0 : evaluated.assets.get(url);
291
+ if (asset === void 0) throw new Error(`a property's ${at} is ${JSON.stringify(value)}, not a file a module imported`);
292
+ return asset.path;
293
+ };
294
+ const properties = /* @__PURE__ */ new Map();
295
+ const exportOf = (value) => evaluated.exports.find((e) => e.value === value);
296
+ const ownExport = (value) => {
297
+ const owners = evaluated.exports.filter((e) => e.value === value && /^property\.[cm]?[jt]sx?$/.test(basename(e.module)));
298
+ for (const owner of owners) if (evaluated.exports.filter((e) => e.module === owner.module && isPropertyShaped(e.value) && e.value !== value).length === 0) return owner.module;
299
+ return null;
300
+ };
301
+ const plan = (value, fixtureId) => {
302
+ const known = properties.get(value);
303
+ if (known !== void 0) return known;
304
+ const module = ownExport(value);
305
+ const exported = exportOf(value);
306
+ const planned = {
307
+ value,
308
+ doc: propertyDocument(value, fileOf),
309
+ document: module === null ? "" : `${posix(dirname(module))}/property.json`,
310
+ inPlace: module !== null,
311
+ from: exported !== void 0 ? `${exported.module}#${exported.name}` : `the fixture ${fixtureId ?? "?"}`,
312
+ fixtures: []
313
+ };
314
+ properties.set(value, planned);
315
+ return planned;
316
+ };
317
+ for (const e of evaluated.exports) if (isPropertyShaped(e.value) && ownExport(e.value) !== null) plan(e.value, null);
318
+ for (const { id, fixture } of evaluated.fixtures) plan(fixture.property, id).fixtures.push(id);
319
+ const canonical = /* @__PURE__ */ new Map();
320
+ const sameAs = /* @__PURE__ */ new Map();
321
+ const ordered = [...properties.values()].sort((a, b) => Number(b.inPlace) - Number(a.inPlace));
322
+ for (const planned of ordered) {
323
+ const key = JSON.stringify(planned.doc);
324
+ const prior = canonical.get(key);
325
+ if (prior === void 0) canonical.set(key, planned);
326
+ else {
327
+ sameAs.set(planned, prior);
328
+ prior.fixtures.push(...planned.fixtures);
329
+ }
330
+ }
331
+ const kept = ordered.filter((p) => !sameAs.has(p));
332
+ const firstOwn = kept.find((p) => p.inPlace);
333
+ const propertiesDir = firstOwn === void 0 ? `${FIXTURES_DIR}/properties` : posix(dirname(dirname(firstOwn.document)));
334
+ const taken = new Set(kept.filter((p) => p.inPlace).map((p) => posix(dirname(p.document))));
335
+ for (const planned of kept) {
336
+ if (planned.inPlace) continue;
337
+ const name = kebabCase(planned.from.includes("#") ? planned.from.slice(planned.from.indexOf("#") + 1) : planned.fixtures[0] ?? "property") || "property";
338
+ let folder = `${propertiesDir}/${name}`;
339
+ for (let n = 2; taken.has(folder) || await exists(join(root, folder)); n++) folder = `${propertiesDir}/${name}-${String(n)}`;
340
+ taken.add(folder);
341
+ planned.document = `${folder}/property.json`;
342
+ }
343
+ const made = [];
344
+ const provenance = new SourcesIndex(root);
345
+ for (const planned of kept) {
346
+ const folder = posix(dirname(planned.document));
347
+ const placed = /* @__PURE__ */ new Map();
348
+ const names = /* @__PURE__ */ new Set();
349
+ let bytes = 0;
350
+ let copied = 0;
351
+ const sources = [];
352
+ for (const file of filesOf(planned.doc)) {
353
+ const inside = posix(relative(join(root, folder), file));
354
+ if (planned.inPlace && !inside.startsWith("../") && inside !== "..") {
355
+ placed.set(file, inside);
356
+ continue;
357
+ }
358
+ const ext = extname(file);
359
+ const stem = basename(file, ext);
360
+ let target = `media/${stem}${ext}`;
361
+ for (let n = 2; names.has(target) || planned.inPlace && await exists(join(root, folder, target)); n++) target = `media/${stem}-${String(n)}${ext}`;
362
+ names.add(target);
363
+ await mkdir(dirname(join(root, folder, target)), { recursive: true });
364
+ await copyFile(file, join(root, folder, target));
365
+ bytes += (await stat(file)).size;
366
+ copied++;
367
+ placed.set(file, target);
368
+ rewritten.push(`${folder}/${target}`);
369
+ const row = await provenance.rowOf(file);
370
+ if (row !== null) sources.push({
371
+ ...row,
372
+ file: target
373
+ });
374
+ }
375
+ if (!planned.inPlace && sources.length > 0) {
376
+ await writeFile(join(root, folder, SOURCES_FILE), json({ files: sources }));
377
+ rewritten.push(`${folder}/${SOURCES_FILE}`);
378
+ }
379
+ const doc = withPaths(planned.doc, (file) => placed.get(file) ?? file);
380
+ const notes = planned.inPlace ? {} : { notes: `Made from ${planned.from} by the fixtures-to-data conversion, with its own copy of every file it names.` };
381
+ await mkdir(join(root, folder), { recursive: true });
382
+ await writeFile(join(root, planned.document), json({
383
+ ...notes,
384
+ ...doc
385
+ }));
386
+ rewritten.push(planned.document);
387
+ if (!planned.inPlace && planned.fixtures.length > 0) made.push({
388
+ document: planned.document,
389
+ from: planned.from,
390
+ fixtures: planned.fixtures.map(kebabCase),
391
+ files: copied,
392
+ bytes
393
+ });
394
+ }
395
+ const fixtureFiles = [];
396
+ const ids = /* @__PURE__ */ new Set();
397
+ for (const { id, fixture } of evaluated.fixtures) {
398
+ let planned = properties.get(fixture.property);
399
+ planned = sameAs.get(planned) ?? planned;
400
+ let name = kebabCase(id) || "fixture";
401
+ for (let n = 2; ids.has(name); n++) name = `${kebabCase(id)}-${String(n)}`;
402
+ ids.add(name);
403
+ const path = `${FIXTURES_DIR}/${name}.json`;
404
+ const content = {};
405
+ for (const entry of fixture.content ?? []) {
406
+ const { instance, doc } = instanceDocument(entry);
407
+ content[instance] = doc;
408
+ }
409
+ await writeFile(join(root, path), json({
410
+ ...fixture.label === void 0 ? {} : { label: fixture.label },
411
+ property: relativeTo(path, planned.document),
412
+ ...Object.keys(content).length === 0 ? {} : { content }
413
+ }));
414
+ fixtureFiles.push(path);
415
+ rewritten.push(path);
416
+ }
417
+ const listPath = join(root, FIXTURE_LIST);
418
+ const prior = await readFile(listPath, "utf8").then((text) => JSON.parse(text), () => null);
419
+ const listed = isRecord(prior) && Array.isArray(prior["fixtures"]) ? prior["fixtures"].filter((f) => typeof f === "string") : [];
420
+ const added = fixtureFiles.map((f) => relativeTo(FIXTURE_LIST, f)).filter((f) => !listed.includes(f));
421
+ await writeFile(listPath, json({
422
+ ...isRecord(prior) ? prior : {},
423
+ fixtures: [...listed, ...added]
424
+ }));
425
+ rewritten.push(FIXTURE_LIST);
426
+ const templatePath = join(root, TEMPLATE_FILE);
427
+ const template = await readFile(templatePath, "utf8").catch(() => null);
428
+ const edit = template === null ? { reason: "the workspace has no template.ts" } : withFixturesMember(template, `./${FIXTURE_LIST}`);
429
+ if ("text" in edit) {
430
+ await writeFile(templatePath, edit.text);
431
+ rewritten.push(TEMPLATE_FILE);
432
+ } else if ("reason" in edit) notRewritten.push({
433
+ file: TEMPLATE_FILE,
434
+ reason: `${edit.reason}; add \`fixtures: "./${FIXTURE_LIST}"\` to it by hand`
435
+ });
436
+ for (const module of evaluated.modules) {
437
+ await removeTree(join(root, module));
438
+ rewritten.push(module);
439
+ }
440
+ for (const test of await fixtureTests(root)) notRewritten.push({
441
+ file: test,
442
+ reason: "a test of the TypeScript fixture modules, which are converted and removed; port or remove it"
443
+ });
444
+ return {
445
+ rewritten,
446
+ notRewritten,
447
+ made,
448
+ fixtures: fixtureFiles
449
+ };
450
+ }
451
+ const SOURCES_FILE = "sources.json";
452
+ var SourcesIndex = class {
453
+ root;
454
+ folders = /* @__PURE__ */ new Map();
455
+ constructor(root) {
456
+ this.root = root;
457
+ }
458
+ async rowOf(file) {
459
+ for (let dir = dirname(file); posix(relative(this.root, dir)) !== "" && !posix(relative(this.root, dir)).startsWith(".."); dir = dirname(dir)) {
460
+ const row = (await this.rows(dir)).find((r) => typeof r["file"] === "string" && join(dir, r["file"]) === file);
461
+ if (row !== void 0) return row;
462
+ }
463
+ return null;
464
+ }
465
+ rows(dir) {
466
+ let pending = this.folders.get(dir);
467
+ if (pending === void 0) {
468
+ pending = readFile(join(dir, SOURCES_FILE), "utf8").then((text) => {
469
+ const parsed = JSON.parse(text);
470
+ return isRecord(parsed) && Array.isArray(parsed["files"]) ? parsed["files"].filter(isRecord) : [];
471
+ }, () => []);
472
+ this.folders.set(dir, pending);
473
+ }
474
+ return pending;
475
+ }
476
+ };
477
+ async function fixtureTests(root) {
478
+ const out = [];
479
+ const walk = async (dir) => {
480
+ let entries;
481
+ try {
482
+ entries = await readdir(dir, { withFileTypes: true });
483
+ } catch {
484
+ return;
485
+ }
486
+ for (const entry of entries) {
487
+ if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
488
+ const path = join(dir, entry.name);
489
+ if (entry.isDirectory()) await walk(path);
490
+ else if (/\.test\.[cm]?[jt]sx?$/.test(entry.name)) out.push(workspacePath(root, path));
491
+ }
492
+ };
493
+ await walk(join(root, FIXTURES_DIR));
494
+ return out.sort();
495
+ }
496
+
497
+ //#endregion
498
+ export { FIXTURE_LIST, fixturesToData, kebabCase, withFixturesMember };