@decocms/blocks 8.9.1 → 8.11.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 (409) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/protocol/channel.d.ts +98 -0
  6. package/dist/protocol/channel.d.ts.map +1 -0
  7. package/dist/protocol/channel.js +58 -0
  8. package/dist/protocol/channel.js.map +1 -0
  9. package/dist/protocol/client.js +2 -2
  10. package/dist/protocol/client.js.map +1 -1
  11. package/dist/protocol/conformance/blockMetaVectors.json +214 -0
  12. package/dist/protocol/conformance/contentHashFixtures.d.ts +22 -0
  13. package/dist/protocol/conformance/contentHashFixtures.d.ts.map +1 -1
  14. package/dist/protocol/conformance/contentHashFixtures.js +55 -0
  15. package/dist/protocol/conformance/contentHashFixtures.js.map +1 -1
  16. package/dist/protocol/conformance/index.d.ts +2 -1
  17. package/dist/protocol/conformance/index.d.ts.map +1 -1
  18. package/dist/protocol/conformance/index.js +2 -1
  19. package/dist/protocol/conformance/index.js.map +1 -1
  20. package/dist/protocol/conformance/vectors.d.ts +33 -0
  21. package/dist/protocol/conformance/vectors.d.ts.map +1 -0
  22. package/dist/protocol/conformance/vectors.js +3 -0
  23. package/dist/protocol/conformance/vectors.js.map +1 -0
  24. package/dist/protocol/index.d.ts +11 -1
  25. package/dist/protocol/index.d.ts.map +1 -1
  26. package/dist/protocol/index.js +11 -1
  27. package/dist/protocol/index.js.map +1 -1
  28. package/dist/protocol/keys.d.ts +1 -1
  29. package/dist/protocol/keys.js +1 -1
  30. package/dist/v8/background.d.ts +13 -0
  31. package/dist/v8/background.d.ts.map +1 -1
  32. package/dist/v8/background.js +41 -0
  33. package/dist/v8/background.js.map +1 -1
  34. package/dist/v8/blockMeta.d.ts +27 -0
  35. package/dist/v8/blockMeta.d.ts.map +1 -0
  36. package/dist/v8/blockMeta.js +75 -0
  37. package/dist/v8/blockMeta.js.map +1 -0
  38. package/dist/v8/blockStore.d.ts +43 -0
  39. package/dist/v8/blockStore.d.ts.map +1 -0
  40. package/dist/v8/blockStore.js +95 -0
  41. package/dist/v8/blockStore.js.map +1 -0
  42. package/dist/v8/boundedJson.d.ts +5 -0
  43. package/dist/v8/boundedJson.d.ts.map +1 -1
  44. package/dist/v8/boundedJson.js +10 -2
  45. package/dist/v8/boundedJson.js.map +1 -1
  46. package/dist/v8/boundedMap.d.ts +19 -0
  47. package/dist/v8/boundedMap.d.ts.map +1 -0
  48. package/dist/v8/boundedMap.js +52 -0
  49. package/dist/v8/boundedMap.js.map +1 -0
  50. package/dist/v8/builtins/data.d.ts +18 -2
  51. package/dist/v8/builtins/data.d.ts.map +1 -1
  52. package/dist/v8/builtins/data.js +17 -1
  53. package/dist/v8/builtins/data.js.map +1 -1
  54. package/dist/v8/builtins/index.d.ts.map +1 -1
  55. package/dist/v8/builtins/index.js +2 -1
  56. package/dist/v8/builtins/index.js.map +1 -1
  57. package/dist/v8/builtins/legacy.d.ts +6 -3
  58. package/dist/v8/builtins/legacy.d.ts.map +1 -1
  59. package/dist/v8/builtins/legacy.js +6 -3
  60. package/dist/v8/builtins/legacy.js.map +1 -1
  61. package/dist/v8/canonical.d.ts +8 -0
  62. package/dist/v8/canonical.d.ts.map +1 -1
  63. package/dist/v8/canonical.js +15 -0
  64. package/dist/v8/canonical.js.map +1 -1
  65. package/dist/v8/cli/builtins.d.ts.map +1 -1
  66. package/dist/v8/cli/builtins.js +1 -0
  67. package/dist/v8/cli/builtins.js.map +1 -1
  68. package/dist/v8/cli/check/index.d.ts +10 -0
  69. package/dist/v8/cli/check/index.d.ts.map +1 -1
  70. package/dist/v8/cli/check/index.js +91 -7
  71. package/dist/v8/cli/check/index.js.map +1 -1
  72. package/dist/v8/cli/content.d.ts +12 -25
  73. package/dist/v8/cli/content.d.ts.map +1 -1
  74. package/dist/v8/cli/content.js +46 -75
  75. package/dist/v8/cli/content.js.map +1 -1
  76. package/dist/v8/cli/index.d.ts +2 -2
  77. package/dist/v8/cli/index.d.ts.map +1 -1
  78. package/dist/v8/cli/index.js +2 -2
  79. package/dist/v8/cli/index.js.map +1 -1
  80. package/dist/v8/cli/remote/commands.d.ts +71 -0
  81. package/dist/v8/cli/remote/commands.d.ts.map +1 -0
  82. package/dist/v8/cli/remote/commands.js +644 -0
  83. package/dist/v8/cli/remote/commands.js.map +1 -0
  84. package/dist/v8/cli/remote/diff.d.ts +15 -0
  85. package/dist/v8/cli/remote/diff.d.ts.map +1 -0
  86. package/dist/v8/cli/remote/diff.js +102 -0
  87. package/dist/v8/cli/remote/diff.js.map +1 -0
  88. package/dist/v8/cli/remote/env.d.ts +35 -0
  89. package/dist/v8/cli/remote/env.d.ts.map +1 -0
  90. package/dist/v8/cli/remote/env.js +84 -0
  91. package/dist/v8/cli/remote/env.js.map +1 -0
  92. package/dist/v8/cli/remote/http.d.ts +149 -0
  93. package/dist/v8/cli/remote/http.d.ts.map +1 -0
  94. package/dist/v8/cli/remote/http.js +381 -0
  95. package/dist/v8/cli/remote/http.js.map +1 -0
  96. package/dist/v8/cli/remote/local.d.ts +90 -0
  97. package/dist/v8/cli/remote/local.d.ts.map +1 -0
  98. package/dist/v8/cli/remote/local.js +309 -0
  99. package/dist/v8/cli/remote/local.js.map +1 -0
  100. package/dist/v8/cli/root.d.ts +29 -0
  101. package/dist/v8/cli/root.d.ts.map +1 -1
  102. package/dist/v8/cli/root.js +28 -0
  103. package/dist/v8/cli/root.js.map +1 -1
  104. package/dist/v8/cli/run.d.ts +13 -1
  105. package/dist/v8/cli/run.d.ts.map +1 -1
  106. package/dist/v8/cli/run.js +310 -124
  107. package/dist/v8/cli/run.js.map +1 -1
  108. package/dist/v8/cli/schema/builtinSchemas.d.ts.map +1 -1
  109. package/dist/v8/cli/schema/builtinSchemas.js +28 -10
  110. package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
  111. package/dist/v8/cli/schema/generate.js +1 -1
  112. package/dist/v8/cli/schema/generate.js.map +1 -1
  113. package/dist/v8/cli/skills.d.ts +25 -0
  114. package/dist/v8/cli/skills.d.ts.map +1 -0
  115. package/dist/v8/cli/skills.js +70 -0
  116. package/dist/v8/cli/skills.js.map +1 -0
  117. package/dist/v8/client.d.ts +9 -9
  118. package/dist/v8/client.d.ts.map +1 -1
  119. package/dist/v8/client.js +138 -50
  120. package/dist/v8/client.js.map +1 -1
  121. package/dist/v8/cms.d.ts +2 -1
  122. package/dist/v8/cms.d.ts.map +1 -1
  123. package/dist/v8/cms.js +55 -46
  124. package/dist/v8/cms.js.map +1 -1
  125. package/dist/v8/content.d.ts +39 -78
  126. package/dist/v8/content.d.ts.map +1 -1
  127. package/dist/v8/content.js +155 -195
  128. package/dist/v8/content.js.map +1 -1
  129. package/dist/v8/contentIndex.d.ts +71 -0
  130. package/dist/v8/contentIndex.d.ts.map +1 -0
  131. package/dist/v8/contentIndex.js +137 -0
  132. package/dist/v8/contentIndex.js.map +1 -0
  133. package/dist/v8/draft.d.ts +7 -7
  134. package/dist/v8/draft.d.ts.map +1 -1
  135. package/dist/v8/draft.js +10 -9
  136. package/dist/v8/draft.js.map +1 -1
  137. package/dist/v8/draftChanges.d.ts +59 -32
  138. package/dist/v8/draftChanges.d.ts.map +1 -1
  139. package/dist/v8/draftChanges.js +139 -75
  140. package/dist/v8/draftChanges.js.map +1 -1
  141. package/dist/v8/errors.d.ts +21 -0
  142. package/dist/v8/errors.d.ts.map +1 -1
  143. package/dist/v8/errors.js +22 -0
  144. package/dist/v8/errors.js.map +1 -1
  145. package/dist/v8/hostedSource.d.ts +57 -0
  146. package/dist/v8/hostedSource.d.ts.map +1 -0
  147. package/dist/v8/hostedSource.js +18 -0
  148. package/dist/v8/hostedSource.js.map +1 -0
  149. package/dist/v8/identity.d.ts +1 -1
  150. package/dist/v8/identity.js +1 -1
  151. package/dist/v8/index.d.ts +1 -0
  152. package/dist/v8/index.d.ts.map +1 -1
  153. package/dist/v8/index.js +1 -0
  154. package/dist/v8/index.js.map +1 -1
  155. package/dist/v8/matchRoute.js +7 -4
  156. package/dist/v8/matchRoute.js.map +1 -1
  157. package/dist/v8/pin.d.ts +34 -0
  158. package/dist/v8/pin.d.ts.map +1 -0
  159. package/dist/v8/pin.js +156 -0
  160. package/dist/v8/pin.js.map +1 -0
  161. package/dist/v8/preview/StudioBridge.d.ts +8 -8
  162. package/dist/v8/preview/StudioBridge.d.ts.map +1 -1
  163. package/dist/v8/preview/StudioBridge.js +8 -10
  164. package/dist/v8/preview/StudioBridge.js.map +1 -1
  165. package/dist/v8/preview/StudioChannel.d.ts +51 -0
  166. package/dist/v8/preview/StudioChannel.d.ts.map +1 -0
  167. package/dist/v8/preview/StudioChannel.js +104 -0
  168. package/dist/v8/preview/StudioChannel.js.map +1 -0
  169. package/dist/v8/preview/index.d.ts +3 -0
  170. package/dist/v8/preview/index.d.ts.map +1 -1
  171. package/dist/v8/preview/index.js +3 -0
  172. package/dist/v8/preview/index.js.map +1 -1
  173. package/dist/v8/remoteLoader.d.ts +42 -5
  174. package/dist/v8/remoteLoader.d.ts.map +1 -1
  175. package/dist/v8/remoteLoader.js +317 -259
  176. package/dist/v8/remoteLoader.js.map +1 -1
  177. package/dist/v8/resolver.d.ts +22 -8
  178. package/dist/v8/resolver.d.ts.map +1 -1
  179. package/dist/v8/resolver.js +37 -32
  180. package/dist/v8/resolver.js.map +1 -1
  181. package/dist/v8/revisionId.d.ts +11 -0
  182. package/dist/v8/revisionId.d.ts.map +1 -0
  183. package/dist/v8/revisionId.js +13 -0
  184. package/dist/v8/revisionId.js.map +1 -0
  185. package/dist/v8/settings.d.ts +6 -6
  186. package/dist/v8/settings.d.ts.map +1 -1
  187. package/dist/v8/settings.js +8 -7
  188. package/dist/v8/settings.js.map +1 -1
  189. package/dist/v8/telemetry.d.ts +4 -2
  190. package/dist/v8/telemetry.d.ts.map +1 -1
  191. package/dist/v8/telemetry.js +2 -2
  192. package/dist/v8/telemetry.js.map +1 -1
  193. package/dist/v8/types.d.ts +52 -40
  194. package/dist/v8/types.d.ts.map +1 -1
  195. package/dist/v8/variants.d.ts +7 -2
  196. package/dist/v8/variants.d.ts.map +1 -1
  197. package/dist/v8/variants.js +21 -24
  198. package/dist/v8/variants.js.map +1 -1
  199. package/dist/v8/vite/index.d.ts +2 -2
  200. package/dist/v8/vite/index.js +1 -1
  201. package/dist/v8/vite/index.js.map +1 -1
  202. package/package.json +3 -2
  203. package/skills/deco-apps/SKILL.md +82 -0
  204. package/skills/deco-apps/references/algolia.md +51 -0
  205. package/skills/deco-apps/references/commerce-types.md +132 -0
  206. package/skills/deco-apps/references/instrumented-fetch.md +144 -0
  207. package/skills/deco-apps/references/magento.md +55 -0
  208. package/skills/deco-apps/references/messaging.md +76 -0
  209. package/skills/deco-apps/references/shopify.md +69 -0
  210. package/skills/deco-apps/references/vendored-loaders.md +135 -0
  211. package/skills/deco-apps/references/vtex-cookies-auth.md +146 -0
  212. package/skills/deco-apps/references/vtex.md +150 -0
  213. package/skills/deco-apps/references/wake.md +75 -0
  214. package/skills/deco-cms-schema/SKILL.md +80 -0
  215. package/skills/deco-cms-schema/references/annotations.md +147 -0
  216. package/skills/deco-cms-schema/references/content-hygiene.md +91 -0
  217. package/skills/deco-cms-schema/references/formats-and-widgets.md +112 -0
  218. package/skills/deco-cms-schema/references/shapes-that-break-the-form.md +165 -0
  219. package/skills/deco-cms-schema/references/types-to-fields.md +112 -0
  220. package/skills/deco-go-live/SKILL.md +127 -0
  221. package/skills/deco-go-live/references/content-releases.md +90 -0
  222. package/skills/deco-go-live/references/process.md +106 -0
  223. package/skills/deco-go-live/references/proxy-headers-checkout.md +139 -0
  224. package/skills/deco-go-live/references/qa-checklist-template.md +150 -0
  225. package/skills/deco-go-live/references/qa-inventory.md +120 -0
  226. package/skills/deco-go-live/references/react-spa.md +183 -0
  227. package/skills/deco-go-live/references/seo-analytics.md +114 -0
  228. package/skills/deco-go-live/references/traffic-ramp.md +87 -0
  229. package/skills/deco-go-live/references/worker-runtime.md +93 -0
  230. package/skills/deco-go-live/scripts/preflight.sh +221 -0
  231. package/skills/deco-images-media/SKILL.md +64 -0
  232. package/skills/deco-images-media/references/asset-upload.md +191 -0
  233. package/skills/deco-images-media/references/components-per-binding.md +167 -0
  234. package/skills/deco-images-media/references/providers-and-cdn.md +145 -0
  235. package/skills/deco-images-media/references/quality-and-lcp.md +93 -0
  236. package/skills/deco-images-media/references/troubleshooting.md +147 -0
  237. package/skills/deco-images-media/references/video.md +122 -0
  238. package/skills/deco-make-editable/SKILL.md +94 -0
  239. package/skills/deco-make-editable/references/a11y-and-e2e.md +104 -0
  240. package/skills/deco-make-editable/references/content-shapes.md +198 -0
  241. package/skills/deco-make-editable/references/from-figma.md +110 -0
  242. package/skills/deco-make-editable/references/i18n-fields.md +112 -0
  243. package/skills/deco-make-editable/references/inventory.md +79 -0
  244. package/skills/deco-make-editable/references/pixel-parity.md +175 -0
  245. package/skills/deco-make-editable/references/seeding-content.md +119 -0
  246. package/skills/deco-nextjs-site/SKILL.md +74 -0
  247. package/skills/deco-nextjs-site/references/caching.md +116 -0
  248. package/skills/deco-nextjs-site/references/metadata-seo.md +100 -0
  249. package/skills/deco-nextjs-site/references/proxy-and-drafts.md +177 -0
  250. package/skills/deco-nextjs-site/references/rendering.md +171 -0
  251. package/skills/deco-nextjs-site/references/setup.md +190 -0
  252. package/skills/deco-nextjs-site/references/studio-bridge.md +130 -0
  253. package/skills/deco-site-authoring/SKILL.md +75 -0
  254. package/skills/deco-site-authoring/references/lazy-blocks.md +155 -0
  255. package/skills/deco-site-authoring/references/loaders.md +192 -0
  256. package/skills/deco-site-authoring/references/pages.md +156 -0
  257. package/skills/deco-site-authoring/references/review-before-publish.md +95 -0
  258. package/skills/deco-site-authoring/references/sections.md +158 -0
  259. package/skills/deco-site-authoring/references/seo.md +116 -0
  260. package/skills/deco-site-workflow/SKILL.md +92 -0
  261. package/skills/deco-site-workflow/references/check.md +116 -0
  262. package/skills/deco-site-workflow/references/cli-reference.md +104 -0
  263. package/skills/deco-site-workflow/references/content-layout.md +93 -0
  264. package/skills/deco-site-workflow/references/content-sync.md +146 -0
  265. package/skills/deco-site-workflow/references/delivery.md +51 -0
  266. package/skills/deco-site-workflow/references/deploy.md +87 -0
  267. package/skills/deco-site-workflow/references/schema.md +173 -0
  268. package/skills/deco-site-workflow/references/serve-and-studio.md +138 -0
  269. package/skills/deco-storefront-caching/SKILL.md +67 -0
  270. package/skills/deco-storefront-caching/references/cache-keys.md +129 -0
  271. package/skills/deco-storefront-caching/references/case-study.md +82 -0
  272. package/skills/deco-storefront-caching/references/egress-traps.md +153 -0
  273. package/skills/deco-storefront-caching/references/nextjs.md +60 -0
  274. package/skills/deco-storefront-caching/references/perf-guardrails-e2e.md +123 -0
  275. package/skills/deco-storefront-caching/references/verification.md +136 -0
  276. package/skills/deco-storefront-caching/references/worker-page-cache.md +160 -0
  277. package/skills/deco-storefront-caching/scripts/html-anatomy.mjs +97 -0
  278. package/skills/deco-storefront-performance/SKILL.md +81 -0
  279. package/skills/deco-storefront-performance/references/cls-third-party.md +90 -0
  280. package/skills/deco-storefront-performance/references/hydration.md +116 -0
  281. package/skills/deco-storefront-performance/references/loaders-n-plus-1.md +107 -0
  282. package/skills/deco-storefront-performance/references/navigation-ux.md +130 -0
  283. package/skills/deco-storefront-performance/references/payload-trim.md +163 -0
  284. package/skills/deco-storefront-performance/references/render-location.md +152 -0
  285. package/skills/deco-storefront-performance/references/request-dedupe.md +147 -0
  286. package/skills/deco-storefront-performance/references/trace-reading.md +79 -0
  287. package/skills/deco-storefront-performance/references/worker-memory.md +176 -0
  288. package/skills/deco-tanstack-site/SKILL.md +68 -0
  289. package/skills/deco-tanstack-site/references/document-and-security.md +155 -0
  290. package/skills/deco-tanstack-site/references/router-and-navigation.md +137 -0
  291. package/skills/deco-tanstack-site/references/routes-and-pages.md +183 -0
  292. package/skills/deco-tanstack-site/references/server-functions.md +123 -0
  293. package/skills/deco-tanstack-site/references/setup.md +153 -0
  294. package/skills/deco-tanstack-site/references/worker-entry.md +152 -0
  295. package/skills/deco-v7-to-v8-migration/SKILL.md +122 -0
  296. package/skills/deco-v7-to-v8-migration/references/caching-and-privacy.md +10 -0
  297. package/skills/deco-v7-to-v8-migration/references/content.md +25 -0
  298. package/skills/deco-v7-to-v8-migration/references/editor-forms.md +27 -0
  299. package/skills/deco-v7-to-v8-migration/references/faststore.md +40 -0
  300. package/skills/deco-v7-to-v8-migration/references/framework-code.md +53 -0
  301. package/skills/deco-v7-to-v8-migration/references/hosted-releases.md +16 -0
  302. package/skills/deco-v7-to-v8-migration/references/import-map.md +81 -0
  303. package/skills/deco-v7-to-v8-migration/references/legacy-names.md +33 -0
  304. package/skills/deco-v7-to-v8-migration/references/manual-steps.md +10 -0
  305. package/skills/deco-v7-to-v8-migration/references/native-apps.md +43 -0
  306. package/skills/deco-v7-to-v8-migration/references/nextjs.md +19 -0
  307. package/skills/deco-v7-to-v8-migration/references/parity.md +66 -0
  308. package/skills/deco-v7-to-v8-migration/references/rendering.md +13 -0
  309. package/skills/deco-v7-to-v8-migration/references/running-the-script.md +29 -0
  310. package/skills/deco-v7-to-v8-migration/references/script-steps.md +13 -0
  311. package/skills/deco-v7-to-v8-migration/references/server-functions.md +15 -0
  312. package/skills/deco-v7-to-v8-migration/references/sibling-port.md +11 -0
  313. package/skills/deco-v7-to-v8-migration/references/site-code.md +15 -0
  314. package/skills/deco-v7-to-v8-migration/references/telemetry.md +10 -0
  315. package/skills/deco-v7-to-v8-migration/references/verify.md +20 -0
  316. package/skills/deco-v7-to-v8-migration/scripts/apps.ts +297 -0
  317. package/skills/deco-v7-to-v8-migration/scripts/asyncRendering.ts +73 -0
  318. package/skills/deco-v7-to-v8-migration/scripts/blockMap.ts +584 -0
  319. package/skills/deco-v7-to-v8-migration/scripts/ciSchemaCheck.ts +145 -0
  320. package/skills/deco-v7-to-v8-migration/scripts/compat.ts +357 -0
  321. package/skills/deco-v7-to-v8-migration/scripts/content.ts +121 -0
  322. package/skills/deco-v7-to-v8-migration/scripts/experiments.ts +81 -0
  323. package/skills/deco-v7-to-v8-migration/scripts/framework.ts +61 -0
  324. package/skills/deco-v7-to-v8-migration/scripts/imageCopy.ts +276 -0
  325. package/skills/deco-v7-to-v8-migration/scripts/imageModule.ts +285 -0
  326. package/skills/deco-v7-to-v8-migration/scripts/imports.ts +942 -0
  327. package/skills/deco-v7-to-v8-migration/scripts/invoke.ts +624 -0
  328. package/skills/deco-v7-to-v8-migration/scripts/legacyNames.ts +45 -0
  329. package/skills/deco-v7-to-v8-migration/scripts/main.ts +59 -0
  330. package/skills/deco-v7-to-v8-migration/scripts/matchers.ts +41 -0
  331. package/skills/deco-v7-to-v8-migration/scripts/migrate.ts +176 -0
  332. package/skills/deco-v7-to-v8-migration/scripts/redirects.ts +455 -0
  333. package/skills/deco-v7-to-v8-migration/scripts/report.ts +50 -0
  334. package/skills/deco-v7-to-v8-migration/scripts/scaffold.ts +1119 -0
  335. package/skills/deco-v7-to-v8-migration/scripts/secrets.ts +35 -0
  336. package/skills/deco-v7-to-v8-migration/scripts/sectionLoaders.ts +216 -0
  337. package/skills/deco-v7-to-v8-migration/scripts/siteSettings.ts +261 -0
  338. package/skills/deco-v7-to-v8-migration/scripts/stubs.ts +388 -0
  339. package/skills/deco-v7-to-v8-migration/scripts/tsconfig.json +7 -0
  340. package/skills/deco-v7-to-v8-migration/scripts/vendor.ts +249 -0
  341. package/skills/deco-v7-to-v8-migration/scripts/vtexInvoke.ts +240 -0
  342. package/skills/deco-v7-to-v8-migration/scripts/walk.ts +30 -0
  343. package/skills/deco-variants/SKILL.md +57 -0
  344. package/skills/deco-variants/references/caching-variants.md +63 -0
  345. package/skills/deco-variants/references/custom-matchers.md +83 -0
  346. package/skills/deco-variants/references/draft-preview.md +59 -0
  347. package/skills/deco-variants/references/experiments-and-campaigns.md +104 -0
  348. package/skills/deco-variants/references/multivariate.md +85 -0
  349. package/skills/deco-variants/references/v7-matchers.md +71 -0
  350. package/src/index.ts +2 -0
  351. package/src/protocol/channel.ts +127 -0
  352. package/src/protocol/client.ts +2 -2
  353. package/src/protocol/conformance/blockMetaVectors.json +214 -0
  354. package/src/protocol/conformance/contentHashFixtures.ts +74 -0
  355. package/src/protocol/conformance/index.ts +9 -1
  356. package/src/protocol/conformance/vectors.ts +36 -0
  357. package/src/protocol/index.ts +32 -0
  358. package/src/protocol/keys.ts +1 -1
  359. package/src/v8/background.ts +42 -0
  360. package/src/v8/blockMeta.ts +100 -0
  361. package/src/v8/blockStore.ts +124 -0
  362. package/src/v8/boundedJson.ts +20 -2
  363. package/src/v8/boundedMap.ts +53 -0
  364. package/src/v8/builtins/data.ts +26 -2
  365. package/src/v8/builtins/index.ts +2 -1
  366. package/src/v8/builtins/legacy.ts +6 -3
  367. package/src/v8/canonical.ts +15 -0
  368. package/src/v8/cli/builtins.ts +1 -0
  369. package/src/v8/cli/check/index.ts +97 -7
  370. package/src/v8/cli/content.ts +49 -91
  371. package/src/v8/cli/index.ts +2 -2
  372. package/src/v8/cli/remote/commands.ts +834 -0
  373. package/src/v8/cli/remote/diff.ts +100 -0
  374. package/src/v8/cli/remote/env.ts +107 -0
  375. package/src/v8/cli/remote/http.ts +484 -0
  376. package/src/v8/cli/remote/local.ts +343 -0
  377. package/src/v8/cli/root.ts +40 -0
  378. package/src/v8/cli/run.ts +366 -135
  379. package/src/v8/cli/schema/builtinSchemas.ts +29 -10
  380. package/src/v8/cli/schema/generate.ts +1 -1
  381. package/src/v8/cli/skills.ts +91 -0
  382. package/src/v8/client.ts +162 -60
  383. package/src/v8/cms.ts +62 -53
  384. package/src/v8/content.ts +179 -229
  385. package/src/v8/contentIndex.ts +183 -0
  386. package/src/v8/draft.ts +15 -14
  387. package/src/v8/draftChanges.ts +151 -85
  388. package/src/v8/errors.ts +37 -0
  389. package/src/v8/hostedSource.ts +67 -0
  390. package/src/v8/identity.ts +1 -1
  391. package/src/v8/index.ts +1 -0
  392. package/src/v8/matchRoute.ts +7 -4
  393. package/src/v8/pin.ts +176 -0
  394. package/src/v8/preview/StudioBridge.ts +8 -10
  395. package/src/v8/preview/StudioChannel.ts +116 -0
  396. package/src/v8/preview/index.ts +3 -0
  397. package/src/v8/remoteLoader.ts +350 -286
  398. package/src/v8/resolver.ts +56 -33
  399. package/src/v8/revisionId.ts +14 -0
  400. package/src/v8/settings.ts +10 -9
  401. package/src/v8/telemetry.ts +3 -3
  402. package/src/v8/types.ts +52 -40
  403. package/src/v8/variants.ts +30 -26
  404. package/src/v8/vite/index.ts +3 -3
  405. package/dist/v8/cli/serve/server.d.ts +0 -29
  406. package/dist/v8/cli/serve/server.d.ts.map +0 -1
  407. package/dist/v8/cli/serve/server.js +0 -296
  408. package/dist/v8/cli/serve/server.js.map +0 -1
  409. package/src/v8/cli/serve/server.ts +0 -348
@@ -0,0 +1,388 @@
1
+ /**
2
+ * `src/migration-stubs.ts`: stand-ins for the v7 runtime the next major
3
+ * doesn't have, written where the codemods meet it so the site compiles and
4
+ * every use stays easy to find (each stub is `@deprecated`, so editors strike
5
+ * it through, and `grep migration-stubs` lists what's left):
6
+ *
7
+ * - `unportedInvoke(key, props)`: an invoke the script couldn't turn into a
8
+ * server function (`ctx.invoke` in a loader, a key with no handler file).
9
+ * It rejects, as calling `ctx` does in v8;
10
+ * - `appState(name)`: a read of an app's state off v7's loader `ctx`. Throws.
11
+ *
12
+ * Both are typed `any`, as v7's ctx was, so the code around them compiles;
13
+ * - `useSection()` / `usePartialSection()` / `HTMX_LEGACY_URL`: v7 7.x's own
14
+ * stand-ins for Fresh's partial sections, with 7.x's output (the placeholder
15
+ * URL), so a page renders as it did. Nothing serves that URL in v7 or v8, so
16
+ * the `hx-*` attributes that carry it do nothing in either.
17
+ *
18
+ * `rewriteLoaderContext` rewrites `ctx.invoke…(…)` and app-state reads in v7
19
+ * loaders (`(props, req, ctx)`); `rewritePartialImports` points v7's
20
+ * `useSection` imports at the stubs. Both run before the import codemod.
21
+ */
22
+ import fs from "node:fs";
23
+ import path from "node:path";
24
+ import ts from "typescript";
25
+ import {
26
+ applyEdits,
27
+ type Edit,
28
+ importInsertion,
29
+ listSources,
30
+ loaderContextOf,
31
+ parse,
32
+ unwrapIdentifier,
33
+ } from "./compat";
34
+ import type { Report } from "./report";
35
+ import { relativeSpecifier } from "./vendor";
36
+
37
+ export const STUBS_FILE = path.join("src", "migration-stubs.ts");
38
+
39
+ export type Stub =
40
+ | "unportedInvoke"
41
+ | "unportedVtexInvoke"
42
+ | "appState"
43
+ | "useSection"
44
+ | "usePartialSection"
45
+ | "HTMX_LEGACY_URL";
46
+
47
+ const STUB_SOURCES: Record<Stub, string[]> = {
48
+ unportedInvoke: [
49
+ "/**",
50
+ " * @deprecated v7's invoke of a loader or action the migration couldn't turn into a server function:",
51
+ " * `ctx.invoke` in a loader (v8 has no ctx), or a key no handler file answers. Call the handler module",
52
+ " * (or the server function in src/server/invoke.functions.ts / invoke.actions.ts) directly.",
53
+ " */",
54
+ "export function unportedInvoke(key: unknown, _props?: unknown): Promise<any> {",
55
+ " return Promise.reject(",
56
+ " new Error(",
57
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
58
+ " `invoke(${String(key)}) has no v8 equivalent here: call its handler or its server function (see src/migration-stubs.ts)`,",
59
+ " ),",
60
+ " );",
61
+ "}",
62
+ ],
63
+ unportedVtexInvoke: [
64
+ "/**",
65
+ " * @deprecated A VTEX invoke key v7's VTEX app answered from its own invoke map, migrated with",
66
+ " * --vtex-invoke v8 (no v7 code) to an operation @decocms/apps-vtex's client doesn't have. Write it over",
67
+ " * the site's VTEX client (src/clients/vtex.ts) in src/server/vtex-invoke.server.ts, with a server function.",
68
+ " */",
69
+ "export function unportedVtexInvoke(key: unknown, _props?: unknown): Promise<any> {",
70
+ " return Promise.reject(",
71
+ " new Error(",
72
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
73
+ " `VTEX invoke ${String(key)} isn't ported to the v8 VTEX client yet (migrated with --vtex-invoke v8; see src/migration-stubs.ts)`,",
74
+ " ),",
75
+ " );",
76
+ "}",
77
+ ],
78
+ appState: [
79
+ "/**",
80
+ " * @deprecated An app's state read off v7's loader ctx. v8 has no ctx and no apps: pass the setting in",
81
+ " * (a prop, a constant) or create the platform's client in code (src/clients/).",
82
+ " */",
83
+ "export function appState(name: string): any {",
84
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: generated source with a template literal
85
+ " throw new Error(`ctx.${name} is gone: v8 has no ctx and no app state (see src/migration-stubs.ts)`);",
86
+ "}",
87
+ ],
88
+ HTMX_LEGACY_URL: [
89
+ "/** @deprecated v7 7.x's placeholder for a partial section's URL; nothing serves it. */",
90
+ 'export const HTMX_LEGACY_URL = "/__deco_legacy_htmx_section__";',
91
+ ],
92
+ useSection: [
93
+ "/**",
94
+ " * @deprecated v7 7.x's stand-in for Fresh's partial sections: it returned this placeholder URL, which",
95
+ " * nothing serves, so hx-* attributes that carry it did nothing in v7 and do nothing now. Fetch the",
96
+ " * section's data with a server function and render it with React state instead.",
97
+ " */",
98
+ "export function useSection(_props?: Record<string, unknown>): string {",
99
+ ' return "/__deco_legacy_htmx_section__";',
100
+ "}",
101
+ ],
102
+ usePartialSection: [
103
+ "/** @deprecated See useSection: v7 7.x returned the same placeholder URL. */",
104
+ "export function usePartialSection(_props?: Record<string, unknown>): string {",
105
+ ' return "/__deco_legacy_htmx_section__";',
106
+ "}",
107
+ ],
108
+ };
109
+
110
+ const ORDER: Stub[] = [
111
+ "unportedInvoke",
112
+ "unportedVtexInvoke",
113
+ "appState",
114
+ "useSection",
115
+ "usePartialSection",
116
+ "HTMX_LEGACY_URL",
117
+ ];
118
+
119
+ /** The stubs `src/migration-stubs.ts` exports: the ones it had, plus `stubs`. */
120
+ export function writeStubs(root: string, stubs: Iterable<Stub>, report: Report): void {
121
+ const file = path.join(root, STUBS_FILE);
122
+ const wanted = new Set(stubs);
123
+ if (wanted.size === 0) return;
124
+ const existing = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : "";
125
+ for (const stub of ORDER) {
126
+ if (new RegExp(`export (function|const) ${stub}\\b`).test(existing)) wanted.add(stub);
127
+ }
128
+ const lines = [
129
+ "/**",
130
+ " * Stand-ins for v7 runtime the next major doesn't have, written by the deco-v7-to-v8-migration skill",
131
+ " * where the site used it. Each is @deprecated: replace every use, then delete this file.",
132
+ " */",
133
+ ];
134
+ for (const stub of ORDER) if (wanted.has(stub)) lines.push("", ...STUB_SOURCES[stub]);
135
+ const text = `${lines.join("\n")}\n`;
136
+ if (text === existing) return;
137
+ fs.mkdirSync(path.dirname(file), { recursive: true });
138
+ fs.writeFileSync(file, text);
139
+ report.done.push({
140
+ step: "imports",
141
+ subject: "src/migration-stubs.ts",
142
+ message: `${ORDER.filter((s) => wanted.has(s)).join(", ")}: @deprecated stand-ins where the site used v7 runtime v8 doesn't have; replace each use (grep migration-stubs), then delete the file`,
143
+ });
144
+ }
145
+
146
+ /** Adds `import { names } from "<stubs>"` to a file's edits (merging into one line). */
147
+ export function stubImport(
148
+ file: string,
149
+ root: string,
150
+ names: Iterable<string>,
151
+ source: ts.SourceFile,
152
+ ): Edit {
153
+ const at = importInsertion(source);
154
+ const line = `import { ${[...new Set(names)].sort().join(", ")} } from "${relativeSpecifier(file, path.join(root, STUBS_FILE))}";`;
155
+ return { start: at, end: at, text: at === 0 ? `${line}\n` : `\n${line}` };
156
+ }
157
+
158
+ /** The key a static invoke chain names (`invoke.vtex.loaders.x` → `vtex/loaders/x`), else undefined. */
159
+ export function chainKey(segments: (string | null)[]): string | undefined {
160
+ if (segments.length === 0 || segments.some((s) => s === null)) return undefined;
161
+ return normalizeKey(segments.join("/"));
162
+ }
163
+
164
+ /** v7 accepted keys with or without `.ts`/`.tsx` and a leading slash. */
165
+ export function normalizeKey(key: string): string {
166
+ return key.replace(/^\/+/, "").replace(/\.tsx?$/, "");
167
+ }
168
+
169
+ /**
170
+ * The property chain under `expr` down to an identifier: `a.b["c"]?.d` →
171
+ * { root: a, segments: ["b", "c", "d"] }; a non-literal element is `null`.
172
+ */
173
+ export function propertyChain(
174
+ expr: ts.Expression,
175
+ ): { root: ts.Identifier; segments: (string | null)[] } | undefined {
176
+ const segments: (string | null)[] = [];
177
+ let e: ts.Expression = expr;
178
+ for (;;) {
179
+ while (ts.isParenthesizedExpression(e) || ts.isNonNullExpression(e) || ts.isAsExpression(e))
180
+ e = e.expression;
181
+ if (ts.isPropertyAccessExpression(e)) {
182
+ segments.unshift(e.name.text);
183
+ e = e.expression;
184
+ } else if (ts.isElementAccessExpression(e)) {
185
+ const arg = e.argumentExpression;
186
+ segments.unshift(
187
+ ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg) ? arg.text : null,
188
+ );
189
+ e = e.expression;
190
+ } else if (ts.isIdentifier(e)) {
191
+ return { root: e, segments };
192
+ } else {
193
+ return undefined;
194
+ }
195
+ }
196
+ }
197
+
198
+ /** What a loader's `ctx` gave v7 that isn't app state. `device` is the device step's; `response` is reported. */
199
+ const CONTEXT_FIELDS = new Set(["device", "response", "invoke", "getAppState"]);
200
+
201
+ /**
202
+ * One file's `ctx.invoke…(…)` calls and app-state reads (`ctx.vtex`,
203
+ * `ctx.getAppState("x")`) in v7 loaders, as stub calls. Returns the new text
204
+ * and the stubs used, or undefined when nothing changed.
205
+ */
206
+ export function rewriteLoaderContextIn(
207
+ file: string,
208
+ text: string,
209
+ root: string,
210
+ ): { text: string; stubs: Set<Stub>; lines: number[] } | undefined {
211
+ if (!/\b(ctx|context)\b|Context\b/i.test(text)) return undefined;
212
+ const source = parse(file, text);
213
+ const edits: Edit[] = [];
214
+ const stubs = new Set<Stub>();
215
+ const lines: number[] = [];
216
+ const line = (node: ts.Node) =>
217
+ source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
218
+ const args = (call: ts.CallExpression, from = 0) =>
219
+ call.arguments
220
+ .slice(from)
221
+ .map((a) => a.getText(source))
222
+ .join(", ");
223
+
224
+ const visit = (node: ts.Node, scope: string[]) => {
225
+ let inner = scope;
226
+ // Only a v7 loader's ctx: `(props, req, ctx)`, not any third `ctx` (react-query's onError context).
227
+ const context = loaderContextOf(node, source);
228
+ if (context?.isRequest) inner = [...scope, context.ctx];
229
+ const isCtx = (e: ts.Expression) => {
230
+ const id = unwrapIdentifier(e);
231
+ return id !== undefined && inner.includes(id.text);
232
+ };
233
+
234
+ // ctx.invoke…(…), ctx.invoke(key, props), ctx.getAppState("x")
235
+ if (ts.isCallExpression(node)) {
236
+ const chain = propertyChain(node.expression);
237
+ if (chain && inner.includes(chain.root.text) && chain.segments[0] === "invoke") {
238
+ const rest = chain.segments.slice(1);
239
+ let replacement: string;
240
+ if (rest.length === 0) {
241
+ const [key] = node.arguments;
242
+ const keyText =
243
+ key && (ts.isStringLiteral(key) || ts.isNoSubstitutionTemplateLiteral(key))
244
+ ? JSON.stringify(normalizeKey(key.text))
245
+ : (key?.getText(source) ?? "undefined");
246
+ replacement = `unportedInvoke(${[keyText, args(node, 1)].filter(Boolean).join(", ")})`;
247
+ } else {
248
+ const key = chainKey(rest);
249
+ const keyText = key
250
+ ? JSON.stringify(key)
251
+ : JSON.stringify(rest.map((s) => s ?? "?").join("/"));
252
+ replacement = `unportedInvoke(${[keyText, args(node)].filter(Boolean).join(", ")})`;
253
+ }
254
+ edits.push({ start: node.getStart(source), end: node.getEnd(), text: replacement });
255
+ stubs.add("unportedInvoke");
256
+ lines.push(line(node));
257
+ return;
258
+ }
259
+ if (
260
+ chain &&
261
+ inner.includes(chain.root.text) &&
262
+ chain.segments.length === 1 &&
263
+ chain.segments[0] === "getAppState"
264
+ ) {
265
+ edits.push({
266
+ start: node.getStart(source),
267
+ end: node.getEnd(),
268
+ text: `appState(${args(node) || '""'})`,
269
+ });
270
+ stubs.add("appState");
271
+ lines.push(line(node));
272
+ return;
273
+ }
274
+ }
275
+
276
+ // ctx.<app>: an app's state.
277
+ if (
278
+ (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
279
+ isCtx(node.expression)
280
+ ) {
281
+ const name = ts.isPropertyAccessExpression(node)
282
+ ? node.name.text
283
+ : ts.isStringLiteral(node.argumentExpression)
284
+ ? node.argumentExpression.text
285
+ : undefined;
286
+ const assigned =
287
+ ts.isBinaryExpression(node.parent) &&
288
+ node.parent.left === node &&
289
+ node.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken;
290
+ if (name !== undefined && !CONTEXT_FIELDS.has(name) && !assigned) {
291
+ edits.push({
292
+ start: node.getStart(source),
293
+ end: node.getEnd(),
294
+ text: `appState(${JSON.stringify(name)})`,
295
+ });
296
+ stubs.add("appState");
297
+ lines.push(line(node));
298
+ return;
299
+ }
300
+ }
301
+ ts.forEachChild(node, (child) => visit(child, inner));
302
+ };
303
+ visit(source, []);
304
+ if (edits.length === 0) return undefined;
305
+ edits.push(stubImport(file, root, stubs, source));
306
+ return { text: applyEdits(text, edits), stubs, lines };
307
+ }
308
+
309
+ /** `ctx.invoke` and app-state reads in v7 loaders under `src/`, as stubs. Returns the stubs used. */
310
+ export function rewriteLoaderContext(root: string, report: Report): Set<Stub> {
311
+ const used = new Set<Stub>();
312
+ for (const file of listSources(path.join(root, "src"))) {
313
+ if (path.resolve(file) === path.join(root, STUBS_FILE)) continue;
314
+ const text = fs.readFileSync(file, "utf8");
315
+ const out = rewriteLoaderContextIn(file, text, root);
316
+ if (!out) continue;
317
+ fs.writeFileSync(file, out.text);
318
+ for (const s of out.stubs) used.add(s);
319
+ const rel = path.relative(root, file).split(path.sep).join("/");
320
+ report.manual.push({
321
+ step: "imports",
322
+ subject: `${rel}:${[...new Set(out.lines)].join(", ")}`,
323
+ message: `v7's loader ctx (${[...out.stubs].map((s) => (s === "unportedInvoke" ? "ctx.invoke" : "app state")).join(", ")}) became ${[...out.stubs].join(" and ")} from src/migration-stubs.ts, which reject as reading ctx does in v8 (the section keeps its saved props): call the loader's handler module directly with (props, req), and pass settings in or use the platform's client (src/clients/)`,
324
+ });
325
+ }
326
+ return used;
327
+ }
328
+
329
+ const PARTIAL_NAMES = new Set<string>(["useSection", "usePartialSection", "HTMX_LEGACY_URL"]);
330
+ const PARTIAL_SPECIFIER = /^@decocms\/blocks\/sdk(\/useScript)?$/;
331
+
332
+ /**
333
+ * v7's `useSection`, `usePartialSection` and `HTMX_LEGACY_URL` imports →
334
+ * the stubs (7.x's own placeholders, same output). Returns the stubs used;
335
+ * `hx-*` attributes are listed in the report.
336
+ */
337
+ export function rewritePartialImports(root: string, report: Report): Set<Stub> {
338
+ const used = new Set<Stub>();
339
+ const htmx: string[] = [];
340
+ for (const file of listSources(path.join(root, "src"))) {
341
+ const text = fs.readFileSync(file, "utf8");
342
+ const rel = path.relative(root, file).split(path.sep).join("/");
343
+ if (/\shx-[a-z]+(:[a-z-]+)?=/.test(text)) htmx.push(rel);
344
+ if (!/useSection|usePartialSection|HTMX_LEGACY_URL/.test(text)) continue;
345
+ const source = parse(file, text);
346
+ const edits: Edit[] = [];
347
+ for (const s of source.statements) {
348
+ if (!ts.isImportDeclaration(s) || !ts.isStringLiteral(s.moduleSpecifier)) continue;
349
+ if (!PARTIAL_SPECIFIER.test(s.moduleSpecifier.text)) continue;
350
+ const bindings = s.importClause?.namedBindings;
351
+ if (!bindings || !ts.isNamedImports(bindings) || s.importClause?.name) continue;
352
+ const moved = bindings.elements.filter((el) =>
353
+ PARTIAL_NAMES.has((el.propertyName ?? el.name).text),
354
+ );
355
+ if (moved.length === 0) continue;
356
+ const rest = bindings.elements.filter((el) => !moved.includes(el));
357
+ const quote = s.moduleSpecifier.getText(source)[0];
358
+ const typeOnly = s.importClause?.isTypeOnly ? "type " : "";
359
+ const out = [
360
+ `import ${typeOnly}{ ${moved.map((el) => el.getText(source)).join(", ")} } from ${quote}${relativeSpecifier(file, path.join(root, STUBS_FILE))}${quote};`,
361
+ ];
362
+ if (rest.length > 0)
363
+ out.push(
364
+ `import ${typeOnly}{ ${rest.map((el) => el.getText(source)).join(", ")} } from ${quote}${s.moduleSpecifier.text}${quote};`,
365
+ );
366
+ edits.push({ start: s.getStart(source), end: s.getEnd(), text: out.join("\n") });
367
+ for (const el of moved) used.add((el.propertyName ?? el.name).text as Stub);
368
+ }
369
+ if (edits.length > 0) fs.writeFileSync(file, applyEdits(text, edits));
370
+ }
371
+ if (used.size > 0) {
372
+ report.done.push({
373
+ step: "imports",
374
+ subject: [...used].join(", "),
375
+ message:
376
+ "now come from src/migration-stubs.ts: v7 7.x's own placeholders (the same URL, /__deco_legacy_htmx_section__), so pages render as they did",
377
+ });
378
+ }
379
+ if (htmx.length > 0) {
380
+ report.manual.push({
381
+ step: "imports",
382
+ subject: `hx-* attributes (${htmx.slice(0, 3).join(", ")}${htmx.length > 3 ? `, +${htmx.length - 3} more` : ""})`,
383
+ message:
384
+ "Fresh's partial sections (HTMX): v7 on TanStack Start and Next.js loaded no HTMX and its useSection returned a placeholder URL, so these did nothing in v7 and do nothing now. Rebuild the interaction with a server function and React state, then drop the attributes",
385
+ });
386
+ }
387
+ return used;
388
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "noEmit": true
5
+ },
6
+ "include": ["**/*.ts"]
7
+ }
@@ -0,0 +1,249 @@
1
+ /**
2
+ * Vendoring (spec: renames-and-migrations › Loaders, actions and invoke). In
3
+ * the next major the apps ship no loaders or actions, so the ones a site's
4
+ * content uses are copied into the site, from the v7 app package it has
5
+ * installed, with every module they import from that same package.
6
+ *
7
+ * A v7 type name `<app>/<path>` lives in `@decocms/apps-<app>/src/<path>`
8
+ * (7.x) or `@decocms/apps/<app>/<path>` (6.x). Either way it is copied to
9
+ * `src/vendor/<app>/<path>`, so relative imports inside the copy keep
10
+ * working, and imports of the package by name are rewritten to relative ones.
11
+ * Imports of other packages stay as they are; the import report lists them.
12
+ */
13
+ import fs from "node:fs";
14
+ import path from "node:path";
15
+ import type { Report } from "./report";
16
+
17
+ const SOURCE_EXTENSIONS = [".ts", ".tsx"];
18
+ const VENDOR_DIR = path.join("src", "vendor");
19
+
20
+ /** `.tsx?` is optional in v7 type names (`shopify/loaders/ProductList` and `…/ProductList.ts`). */
21
+ function withExtensions(file: string): string[] {
22
+ return /\.(tsx?|jsx?)$/.test(file)
23
+ ? [file]
24
+ : [
25
+ ...SOURCE_EXTENSIONS.map((e) => file + e),
26
+ ...SOURCE_EXTENSIONS.map((e) => path.join(file, `index${e}`)),
27
+ ];
28
+ }
29
+
30
+ function isFile(file: string): boolean {
31
+ try {
32
+ return fs.statSync(file).isFile();
33
+ } catch {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ /** The first candidate that is a file. */
39
+ export function firstFile(candidates: string[]): string | undefined {
40
+ return candidates.find(isFile);
41
+ }
42
+
43
+ interface PackageRef {
44
+ /** The package folder in node_modules. */
45
+ dir: string;
46
+ /** `exports` of its package.json. */
47
+ exports: Record<string, string>;
48
+ }
49
+
50
+ function readPackage(root: string, name: string): PackageRef | undefined {
51
+ const dir = path.join(root, "node_modules", name);
52
+ try {
53
+ const manifest = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
54
+ const exports: Record<string, string> = {};
55
+ for (const [key, target] of Object.entries(manifest.exports ?? {})) {
56
+ if (typeof target === "string") exports[key] = target;
57
+ }
58
+ if (!exports["."] && typeof manifest.main === "string") exports["."] = manifest.main;
59
+ return { dir: fs.realpathSync(dir), exports };
60
+ } catch {
61
+ return undefined;
62
+ }
63
+ }
64
+
65
+ /** A subpath through a package's `exports` (exact keys and one-`*` patterns). */
66
+ function matchExports(pkg: PackageRef, subpath: string): string | undefined {
67
+ const exact = pkg.exports[subpath];
68
+ if (exact) return firstFile([path.join(pkg.dir, exact)]);
69
+ for (const [key, target] of Object.entries(pkg.exports)) {
70
+ const star = key.indexOf("*");
71
+ if (star < 0) continue;
72
+ const [prefix, suffix] = [key.slice(0, star), key.slice(star + 1)];
73
+ if (
74
+ subpath.startsWith(prefix) &&
75
+ subpath.endsWith(suffix) &&
76
+ subpath.length >= key.length - 1
77
+ ) {
78
+ const middle = subpath.slice(prefix.length, subpath.length - suffix.length);
79
+ const file = firstFile([path.join(pkg.dir, target.replace("*", middle))]);
80
+ if (file) return file;
81
+ }
82
+ }
83
+ return undefined;
84
+ }
85
+
86
+ function splitSpecifier(specifier: string): { name: string; subpath: string } | undefined {
87
+ const parts = specifier.split("/");
88
+ if (specifier.startsWith("@") ? parts.length < 2 : parts.length < 1) return undefined;
89
+ const count = specifier.startsWith("@") ? 2 : 1;
90
+ const rest = parts.slice(count).join("/");
91
+ return { name: parts.slice(0, count).join("/"), subpath: rest ? `./${rest}` : "." };
92
+ }
93
+
94
+ /** The file a bare specifier names in the site's node_modules, through the package's `exports`. */
95
+ export function resolvePackageFile(root: string, specifier: string): string | undefined {
96
+ const parts = splitSpecifier(specifier);
97
+ if (!parts) return undefined;
98
+ const pkg = readPackage(root, parts.name);
99
+ return pkg ? matchExports(pkg, parts.subpath) : undefined;
100
+ }
101
+
102
+ /** Where one app's sources sit, and where its copies go. */
103
+ interface AppSource {
104
+ /** The package's source root: copies keep their path relative to it. */
105
+ base: string;
106
+ /** The folder a v7 type name's `<path>` starts in. */
107
+ dir: string;
108
+ /** The package name; its own imports by name are rewritten to the copies. */
109
+ packageName: string;
110
+ /** Where the copies go: `src/vendor/<app>` (7.x) or `src/vendor` (6.x, a folder per app). */
111
+ dest: string;
112
+ }
113
+
114
+ function appSources(root: string, app: string): AppSource[] {
115
+ const sources: AppSource[] = [];
116
+ const split = readPackage(root, `@decocms/apps-${app}`); // 7.x: one package per app
117
+ if (split) {
118
+ const base = path.join(split.dir, "src");
119
+ sources.push({
120
+ base,
121
+ dir: base,
122
+ packageName: `@decocms/apps-${app}`,
123
+ dest: path.join(root, VENDOR_DIR, app),
124
+ });
125
+ }
126
+ const single = readPackage(root, "@decocms/apps"); // 6.x: one package, a folder per app
127
+ if (single) {
128
+ sources.push({
129
+ base: single.dir,
130
+ dir: path.join(single.dir, app),
131
+ packageName: "@decocms/apps",
132
+ dest: path.join(root, VENDOR_DIR),
133
+ });
134
+ }
135
+ return sources;
136
+ }
137
+
138
+ interface AppModule {
139
+ file: string;
140
+ app: AppSource;
141
+ }
142
+
143
+ /** The installed v7 source of a type name like `shopify/loaders/ProductList.ts`, if any. */
144
+ export function locateAppModule(root: string, type: string): AppModule | undefined {
145
+ const [app, ...rest] = type.split("/");
146
+ if (!app || rest.length === 0) return undefined;
147
+ for (const source of appSources(root, app)) {
148
+ const file = firstFile(withExtensions(path.join(source.dir, ...rest)));
149
+ // A type name is content, which editors control: never leave the package.
150
+ if (file && isInside(source.base, file)) return { file, app: source };
151
+ }
152
+ return undefined;
153
+ }
154
+
155
+ const IMPORT_SPECIFIER =
156
+ /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\bexport\s+\*\s+from\s*)(["'])([^"']+)\2/g;
157
+
158
+ function isInside(dir: string, file: string): boolean {
159
+ const rel = path.relative(dir, file);
160
+ return rel !== "" && !rel.startsWith("..") && !path.isAbsolute(rel);
161
+ }
162
+
163
+ /** An import specifier from one file to another, without extension or `/index`. */
164
+ export function relativeSpecifier(fromFile: string, toFile: string): string {
165
+ let rel = path.relative(path.dirname(fromFile), toFile).split(path.sep).join("/");
166
+ rel = rel.replace(/(\/index)?\.tsx?$/, "");
167
+ return rel.startsWith(".") ? rel : `./${rel}`;
168
+ }
169
+
170
+ /**
171
+ * Copy `entry` and the modules of its package it imports into the site, and
172
+ * return the copy of `entry`. `copies` maps each installed source to its copy
173
+ * and is shared across calls, so a module is copied once. A copy that exists
174
+ * is kept, so a second run never overwrites edits.
175
+ */
176
+ export function vendorModule(
177
+ root: string,
178
+ entry: AppModule,
179
+ copies: Map<string, string>,
180
+ report: Report,
181
+ ): string {
182
+ const { app } = entry;
183
+ const destOf = (source: string) => path.join(app.dest, path.relative(app.base, source));
184
+ const queue = [entry.file];
185
+
186
+ while (queue.length > 0) {
187
+ const source = queue.shift()!;
188
+ if (copies.has(source)) continue;
189
+ const dest = destOf(source);
190
+ copies.set(source, dest);
191
+ let text = fs.readFileSync(source, "utf8");
192
+ text = text.replace(
193
+ IMPORT_SPECIFIER,
194
+ (match, lead: string, quote: string, specifier: string) => {
195
+ let target: string | undefined;
196
+ if (specifier.startsWith(".")) {
197
+ target = firstFile(
198
+ withExtensions(path.resolve(path.dirname(source), specifier.replace(/\.js$/, ""))),
199
+ );
200
+ } else if (specifier === app.packageName || specifier.startsWith(`${app.packageName}/`)) {
201
+ target = resolvePackageFile(root, specifier);
202
+ } else {
203
+ return match;
204
+ }
205
+ if (!target) {
206
+ const asset = specifier.startsWith(".")
207
+ ? path.resolve(path.dirname(source), specifier)
208
+ : undefined;
209
+ if (asset && isInside(app.base, asset) && isFile(asset)) {
210
+ // A JSON or other non-TS file: copied as it is, same relative path.
211
+ const assetDest = destOf(asset);
212
+ if (!fs.existsSync(assetDest)) {
213
+ fs.mkdirSync(path.dirname(assetDest), { recursive: true });
214
+ fs.copyFileSync(asset, assetDest);
215
+ }
216
+ } else {
217
+ report.manual.push({
218
+ step: "vendor",
219
+ subject: path.relative(root, dest),
220
+ message: `imports ${specifier}, which doesn't resolve to a file; fix the import`,
221
+ });
222
+ }
223
+ return match;
224
+ }
225
+ if (!isInside(app.base, target)) {
226
+ report.manual.push({
227
+ step: "vendor",
228
+ subject: path.relative(root, dest),
229
+ message: `imports ${specifier}, outside ${app.packageName}; fix the import`,
230
+ });
231
+ return match;
232
+ }
233
+ queue.push(target);
234
+ return specifier.startsWith(".")
235
+ ? match
236
+ : `${lead}${quote}${relativeSpecifier(dest, destOf(target))}${quote}`;
237
+ },
238
+ );
239
+ if (!fs.existsSync(dest)) {
240
+ const origin = path.relative(app.base, source).split(path.sep).join("/");
241
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
242
+ fs.writeFileSync(
243
+ dest,
244
+ `// Vendored from ${app.packageName} (${origin}) by the deco-v7-to-v8-migration skill. It's your code now.\n${text}`,
245
+ );
246
+ }
247
+ }
248
+ return destOf(entry.file);
249
+ }