@astryxdesign/cli 0.7.16 → 0.7.17-canary.g49a475f

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 (354) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +12 -0
  3. package/api/build/_adapter.mjs +51 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +4 -3
  7. package/api/build/build.type.d.mts +2 -2
  8. package/api/build/build.type.mjs +3 -3
  9. package/api/build/kit/kind.d.mts +2 -1
  10. package/api/build/kit/kind.mjs +199 -10
  11. package/api/build/kit/kit.mjs +6 -4
  12. package/api/build/kit/rank.d.mts +4 -2
  13. package/api/build/kit/rank.mjs +125 -24
  14. package/api/build/kit/start.d.mts +5 -4
  15. package/api/build/kit/start.mjs +12 -8
  16. package/api/build/kit/weights.d.mts +39 -3
  17. package/api/build/kit/weights.json +1 -1
  18. package/api/build/kit/weights.mjs +340 -43
  19. package/api/build/kit/word-model.d.mts +23 -0
  20. package/api/build/kit/word-model.mjs +46 -0
  21. package/api/build/kit/words.d.mts +48 -0
  22. package/api/build/kit/words.mjs +90 -1
  23. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  24. package/api/component/list/list.d.mts +1 -1
  25. package/api/component/list/list.mjs +48 -6
  26. package/api/discover/_adapter.d.mts +1 -1
  27. package/api/discover/search/search.mjs +3 -2
  28. package/api/docs/_adapter.d.mts +26 -2
  29. package/api/docs/_adapter.mjs +219 -6
  30. package/api/docs/docs.d.mts +3 -0
  31. package/api/docs/docs.doc.mjs +7 -1
  32. package/api/docs/docs.mjs +12 -0
  33. package/api/docs/docs.type.d.mts +5 -0
  34. package/api/docs/docs.type.mjs +2 -0
  35. package/api/docs/node/node.mjs +1 -1
  36. package/api/doctor/_adapter.d.mts +27 -5
  37. package/api/doctor/_adapter.mjs +83 -10
  38. package/api/doctor/built-checks.mjs +40 -14
  39. package/api/doctor/doctor.d.mts +4 -3
  40. package/api/doctor/doctor.mjs +14 -7
  41. package/api/doctor/theme-checks.mjs +121 -17
  42. package/api/icon/_records.mjs +2 -1
  43. package/api/index.d.mts +2 -0
  44. package/api/index.mjs +2 -0
  45. package/api/integration/_adapter.d.mts +44 -0
  46. package/api/integration/_adapter.mjs +77 -1
  47. package/api/integration/authoring-checks.mjs +6 -6
  48. package/api/integration/example-scope.d.mts +14 -0
  49. package/api/integration/example-scope.mjs +44 -0
  50. package/api/integration/example-scope.type.d.mts +29 -0
  51. package/api/integration/example-scope.type.mjs +25 -0
  52. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  53. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  54. package/api/integration/validate-integration.mjs +19 -1
  55. package/api/integration/validate-integration.type.d.mts +9 -0
  56. package/api/integration/validate-integration.type.mjs +1 -1
  57. package/api/integration/validateIntegration.doc.mjs +1 -1
  58. package/api/render/_adapter.mjs +591 -195
  59. package/api/render/render.doc.mjs +11 -3
  60. package/api/render/render.type.d.mts +52 -0
  61. package/api/render/render.type.mjs +31 -1
  62. package/api/search/ORDERING.md +1 -1
  63. package/api/search/_adapter.d.mts +9 -0
  64. package/api/search/_adapter.mjs +85 -0
  65. package/api/search/_candidate-score.mjs +51 -32
  66. package/api/search/_fit-order.mjs +3 -3
  67. package/api/search/_gather-components.d.mts +3 -2
  68. package/api/search/_gather-components.mjs +12 -3
  69. package/api/search/_lexical.d.mts +5 -0
  70. package/api/search/_lexical.mjs +8 -2
  71. package/api/search/_result.d.mts +11 -9
  72. package/api/search/_result.mjs +4 -4
  73. package/api/search/_score.d.mts +6 -1
  74. package/api/search/_score.mjs +15 -3
  75. package/api/search/search-index.mjs +7 -1
  76. package/api/search/search.d.mts +1 -1
  77. package/api/theme/_adapter.mjs +12 -1
  78. package/api/theme/build/build.d.mts +75 -0
  79. package/api/theme/build/build.mjs +243 -58
  80. package/api/theme/build/font-warning.d.mts +7 -0
  81. package/api/theme/build/font-warning.mjs +17 -0
  82. package/api/theme/theme.type.d.mts +10 -0
  83. package/api/theme/theme.type.mjs +7 -1
  84. package/api/theme-edit/_adapter.d.mts +63 -2
  85. package/api/theme-edit/_adapter.mjs +771 -57
  86. package/api/theme-edit/_check.d.mts +40 -22
  87. package/api/theme-edit/_check.mjs +2029 -336
  88. package/api/theme-edit/_color.d.mts +10 -0
  89. package/api/theme-edit/_color.mjs +49 -1
  90. package/api/theme-edit/_compiler.mjs +9 -0
  91. package/api/theme-edit/_context.d.mts +3 -3
  92. package/api/theme-edit/_context.mjs +111 -48
  93. package/api/theme-edit/_css.d.mts +14 -0
  94. package/api/theme-edit/_css.mjs +46 -1
  95. package/api/theme-edit/_edit.d.mts +18 -4
  96. package/api/theme-edit/_edit.mjs +1685 -155
  97. package/api/theme-edit/_how-commands.d.mts +65 -0
  98. package/api/theme-edit/_how-commands.mjs +633 -1
  99. package/api/theme-edit/_how-question.d.mts +84 -0
  100. package/api/theme-edit/_how-question.mjs +5124 -281
  101. package/api/theme-edit/_how.mjs +140 -29
  102. package/api/theme-edit/_marks.d.mts +31 -5
  103. package/api/theme-edit/_marks.mjs +57 -5
  104. package/api/theme-edit/_name-rule.d.mts +11 -0
  105. package/api/theme-edit/_name-rule.mjs +12 -0
  106. package/api/theme-edit/_normal.d.mts +257 -0
  107. package/api/theme-edit/_normal.mjs +1252 -0
  108. package/api/theme-edit/_palette.mjs +10 -4
  109. package/api/theme-edit/_parts.d.mts +10 -1
  110. package/api/theme-edit/_parts.mjs +179 -3
  111. package/api/theme-edit/_preview-app.d.mts +7 -1
  112. package/api/theme-edit/_preview-app.mjs +515 -148
  113. package/api/theme-edit/_preview.d.mts +100 -14
  114. package/api/theme-edit/_preview.mjs +549 -137
  115. package/api/theme-edit/_settings.d.mts +347 -30
  116. package/api/theme-edit/_settings.mjs +2971 -327
  117. package/api/theme-edit/_tables.d.mts +6 -0
  118. package/api/theme-edit/_tables.mjs +44 -1
  119. package/api/theme-edit/_vet.d.mts +18 -0
  120. package/api/theme-edit/_vet.mjs +32 -0
  121. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  122. package/api/theme-edit/theme-edit.type.mjs +4 -1
  123. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  124. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  125. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  126. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  127. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  128. package/api/upgrade/run/run.mjs +4 -3
  129. package/assets/codemods/integration-discovery.mjs +2 -1
  130. package/assets/codemods/run-codemod.mjs +87 -7
  131. package/assets/codemods/transforms/next/index.mjs +11 -1
  132. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  133. package/assets/component-list.generated.json +1 -0
  134. package/assets/docs/author-a-theme.doc.mjs +1 -0
  135. package/assets/docs/theme.doc.dense.mjs +2 -2
  136. package/assets/docs/theme.doc.mjs +1 -1
  137. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  138. package/assets/docs/tree/checks.doc.mjs +1 -1
  139. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  140. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  141. package/assets/docs/tree/single-component.doc.mjs +4 -0
  142. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  143. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  144. package/assets/docs/use-a-theme.doc.mjs +1 -1
  145. package/assets/docs.generated.json +2 -2
  146. package/assets/search-catalog.generated.json +2 -0
  147. package/assets/self-audit.generated.json +1 -1
  148. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  149. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  150. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  151. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  152. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  153. package/assets/templates/components.generated.json +1 -1
  154. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  155. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  156. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  157. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  158. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  159. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  160. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  161. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  162. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  163. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  164. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  165. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  166. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  167. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  168. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  169. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  170. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  171. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  172. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  173. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  174. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  175. package/assets/templates/pages/ide/page.tsx +24 -2
  176. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  177. package/assets/templates/pages/library/template.doc.mjs +4 -1
  178. package/assets/templates/pages/login/template.doc.mjs +2 -1
  179. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  180. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  181. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  182. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  183. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  184. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  185. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  186. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  187. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  188. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  189. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  190. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  191. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  192. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  193. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  194. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  195. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  196. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  197. package/assets/theme.template.ts +6 -0
  198. package/authoring/debug/parse.d.mts +3 -3
  199. package/authoring/doctypes/_schema.d.mts +3 -3
  200. package/authoring/doctypes/command/command.doc.mjs +1 -1
  201. package/authoring/doctypes/component/categories.d.mts +37 -0
  202. package/authoring/doctypes/component/categories.mjs +54 -0
  203. package/authoring/doctypes/template/template.doc.mjs +1 -1
  204. package/authoring/doctypes/template/type.ts +9 -0
  205. package/authoring/example/example.doc.d.mts +12 -0
  206. package/authoring/example/example.doc.mjs +69 -0
  207. package/authoring/example/preview.d.mts +92 -0
  208. package/authoring/example/preview.mjs +994 -0
  209. package/authoring/example/type.ts +102 -0
  210. package/authoring/index.d.mts +1 -0
  211. package/authoring/index.d.ts +12 -0
  212. package/authoring/index.mjs +3 -1
  213. package/clients/cli/bin/astryx.mjs +6 -9
  214. package/clients/cli/build-id.generated.json +1 -1
  215. package/clients/cli/commands/component.doc.mjs +1 -1
  216. package/clients/cli/commands/component.mjs +22 -3
  217. package/clients/cli/commands/docs.doc.mjs +7 -1
  218. package/clients/cli/commands/docs.mjs +3 -1
  219. package/clients/cli/commands/doctor.mjs +32 -14
  220. package/clients/cli/commands/experimental/render.mjs +42 -1
  221. package/clients/cli/commands/experimental/theme.mjs +163 -28
  222. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  223. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  224. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  225. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  226. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  227. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  228. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  229. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  230. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  231. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  232. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  233. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  234. package/clients/cli/commands/search.doc.mjs +2 -1
  235. package/clients/cli/commands/search.mjs +6 -1
  236. package/clients/cli/commands/template.mjs +4 -2
  237. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  238. package/clients/cli/commands/theme.doc.mjs +1 -1
  239. package/clients/cli/commands/theme.mjs +209 -8
  240. package/clients/cli/commands/upgrade.mjs +42 -7
  241. package/clients/cli/index.mjs +1 -1
  242. package/clients/cli/lib/cli-error.mjs +2 -1
  243. package/clients/cli/lib/component-format.mjs +205 -98
  244. package/clients/cli/lib/hook-format.mjs +9 -19
  245. package/clients/cli/lib/json-shim.mjs +77 -21
  246. package/clients/cli/lib/manifest.mjs +3 -2
  247. package/clients/cli/manifest.generated.json +1 -1
  248. package/foundation/agent-docs/agent-docs.mjs +1 -1
  249. package/foundation/config/theme-state.d.mts +13 -1
  250. package/foundation/config/theme-state.mjs +47 -7
  251. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  252. package/foundation/discovery/component-discovery.d.mts +11 -0
  253. package/foundation/discovery/component-discovery.mjs +56 -8
  254. package/foundation/discovery/component-replacement.mjs +130 -1
  255. package/foundation/discovery/copied-passages.mjs +2 -1
  256. package/foundation/discovery/doc-types.mjs +4 -3
  257. package/foundation/discovery/entry-name-files.d.mts +43 -0
  258. package/foundation/discovery/entry-name-files.mjs +264 -0
  259. package/foundation/discovery/hook-discovery.d.mts +8 -2
  260. package/foundation/discovery/hook-discovery.mjs +22 -8
  261. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  262. package/foundation/discovery/icon-set-checks.mjs +2 -1
  263. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  264. package/foundation/discovery/integration-doc-files.mjs +2 -1
  265. package/foundation/discovery/package-exports.d.mts +10 -0
  266. package/foundation/discovery/package-exports.mjs +56 -3
  267. package/foundation/discovery/prop-drift.mjs +9 -9
  268. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  269. package/foundation/discovery/runner-allowlist.mjs +2 -0
  270. package/foundation/discovery/stored-component-list.d.mts +43 -0
  271. package/foundation/discovery/stored-component-list.mjs +90 -0
  272. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  273. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  274. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  275. package/foundation/discovery/stored-self-audit.mjs +38 -18
  276. package/foundation/discovery/template-adapter.d.mts +52 -0
  277. package/foundation/discovery/template-adapter.mjs +176 -12
  278. package/foundation/discovery/template-icons.mjs +2 -1
  279. package/foundation/discovery/theme-discovery.mjs +3 -2
  280. package/foundation/discovery/theme-imports.d.mts +14 -0
  281. package/foundation/discovery/theme-imports.mjs +43 -1
  282. package/foundation/discovery/theming-targets.mjs +3 -2
  283. package/foundation/doc-compiler/import.mjs +7 -1
  284. package/foundation/doc-compiler/inputs.mjs +3 -2
  285. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  286. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  287. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  288. package/foundation/env/semver.mjs +3 -1
  289. package/foundation/fonts/font-stylesheet.d.mts +31 -0
  290. package/foundation/fonts/font-stylesheet.mjs +115 -0
  291. package/foundation/fs/cache-eviction.d.mts +21 -0
  292. package/foundation/fs/cache-eviction.mjs +73 -0
  293. package/foundation/fs/file-protection.mjs +4 -3
  294. package/foundation/fs/gather-cache.d.mts +25 -4
  295. package/foundation/fs/gather-cache.mjs +164 -55
  296. package/foundation/fs/jiti-cache.d.mts +19 -1
  297. package/foundation/fs/jiti-cache.mjs +130 -6
  298. package/foundation/fs/kept-tree.d.mts +60 -0
  299. package/foundation/fs/kept-tree.mjs +154 -0
  300. package/foundation/fs/listing-cache.d.mts +7 -0
  301. package/foundation/fs/listing-cache.mjs +10 -0
  302. package/foundation/fs/module-loader.d.mts +24 -2
  303. package/foundation/fs/module-loader.mjs +94 -21
  304. package/foundation/fs/paths.d.mts +18 -0
  305. package/foundation/fs/paths.mjs +15 -2
  306. package/foundation/identity/provider-identity.d.mts +6 -0
  307. package/foundation/identity/provider-identity.mjs +10 -1
  308. package/foundation/integrations/contribution-inventory.mjs +4 -3
  309. package/foundation/integrations/example-code.d.mts +63 -0
  310. package/foundation/integrations/example-code.mjs +416 -0
  311. package/foundation/integrations/public-imports.d.mts +9 -0
  312. package/foundation/integrations/public-imports.mjs +3 -2
  313. package/foundation/integrations/validate-contributions.mjs +17 -45
  314. package/foundation/render/embedded-files.d.mts +6 -0
  315. package/foundation/render/embedded-files.mjs +25 -5
  316. package/foundation/render/embedded-imports.d.mts +39 -7
  317. package/foundation/render/embedded-imports.mjs +66 -27
  318. package/foundation/render/file-header.d.mts +66 -0
  319. package/foundation/render/file-header.mjs +118 -0
  320. package/foundation/render/host-answer.d.mts +18 -0
  321. package/foundation/render/host-answer.mjs +46 -0
  322. package/foundation/render/host-exit.d.mts +1 -0
  323. package/foundation/render/host-exit.mjs +6 -1
  324. package/foundation/render/html-reader.d.mts +55 -2
  325. package/foundation/render/html-reader.mjs +145 -26
  326. package/foundation/render/markup-edits.d.mts +57 -0
  327. package/foundation/render/markup-edits.mjs +182 -0
  328. package/foundation/render/page-host.mjs +29 -12
  329. package/foundation/render/page-worker.mjs +121 -13
  330. package/foundation/render/picture-chrome.d.mts +4 -0
  331. package/foundation/render/picture-chrome.mjs +185 -0
  332. package/foundation/render/picture-playwright.d.mts +4 -0
  333. package/foundation/render/picture-playwright.mjs +34 -0
  334. package/foundation/render/rebuild.mjs +2 -1
  335. package/foundation/render/render-page.d.mts +35 -3
  336. package/foundation/render/render-page.mjs +316 -42
  337. package/foundation/render/source-block.d.mts +85 -6
  338. package/foundation/render/source-block.mjs +211 -20
  339. package/foundation/render/ts-paths.d.mts +69 -6
  340. package/foundation/render/ts-paths.mjs +326 -40
  341. package/foundation/response/error-codes.d.mts +3 -1
  342. package/foundation/response/error-codes.d.ts +1 -0
  343. package/foundation/response/error-codes.doc.mjs +12 -1
  344. package/foundation/response/error-codes.mjs +11 -1
  345. package/foundation/response/response-types.doc.mjs +2 -2
  346. package/foundation/text/compare-text.d.mts +14 -0
  347. package/foundation/text/compare-text.mjs +68 -0
  348. package/foundation/text/string-utils.d.mts +3 -2
  349. package/foundation/text/string-utils.mjs +18 -4
  350. package/foundation/text/suggest-order.d.mts +9 -0
  351. package/foundation/text/suggest-order.mjs +15 -1
  352. package/foundation/xle/expand.mjs +2 -1
  353. package/host/index.mjs +8 -6
  354. package/package.json +7 -6
@@ -24,10 +24,16 @@
24
24
  import * as fs from 'node:fs';
25
25
  import * as path from 'node:path';
26
26
  import {spawnSync} from 'node:child_process';
27
- import {builtinModules, createRequire} from 'node:module';
27
+ import {createRequire} from 'node:module';
28
28
  import {isValidSemver} from '../env/semver.mjs';
29
29
  import {findProjectCoreDir} from '../fs/paths.mjs';
30
30
  import {KNOWN_INTEGRATION_KEYS} from '../../authoring/integration/schema.mjs';
31
+ import {
32
+ isNodeEnvRead,
33
+ isProcessEnv,
34
+ isServerOnlyImport,
35
+ packagesInstalledWith,
36
+ } from '../../authoring/example/preview.mjs';
31
37
  import {
32
38
  contributionFiles,
33
39
  findSourceOnlyCandidates,
@@ -1049,10 +1055,6 @@ export async function blockComponentsCheck(integration) {
1049
1055
  // `A/B Testing`).
1050
1056
  const PATH_CATEGORY = /^[a-z0-9][\w.-]*(?:\/[\w.-]+)+$/u;
1051
1057
 
1052
- /** Imports a browser cannot load, which a showcase must not make. */
1053
- const SERVER_ONLY_IMPORTS =
1054
- /^(?:server-only|next\/headers|next\/server|next\/cache|node:.+)$/u;
1055
-
1056
1058
  /**
1057
1059
  * Every spelling a glob's `{a,b}` braces stand for, nested braces included.
1058
1060
  * @param {string} pattern
@@ -1341,10 +1343,10 @@ function literalPath(node) {
1341
1343
  * (which bundlers replace). `assets` are the relative paths it loads with `new URL('./x', import.meta.url)`. A module
1342
1344
  * that does not parse reports nothing; the template check owns that.
1343
1345
  * @param {string} source
1344
- * @param {Set<string>} builtins
1346
+ * @param {ReadonlyArray<string>} dependencies the packages the package declares
1345
1347
  * @returns {{server: string[], assets: string[]}}
1346
1348
  */
1347
- function readModule(source, builtins) {
1349
+ function readModule(source, dependencies) {
1348
1350
  /** @type {any} */
1349
1351
  let ast;
1350
1352
  try {
@@ -1362,10 +1364,7 @@ function readModule(source, builtins) {
1362
1364
  const found = [];
1363
1365
  /** @param {unknown} spec */
1364
1366
  const checkSpec = spec => {
1365
- if (
1366
- typeof spec === 'string' &&
1367
- (SERVER_ONLY_IMPORTS.test(spec) || builtins.has(spec))
1368
- ) {
1367
+ if (typeof spec === 'string' && isServerOnlyImport(spec, dependencies)) {
1369
1368
  found.push(`imports '${spec}'`);
1370
1369
  }
1371
1370
  };
@@ -1431,30 +1430,13 @@ function readModule(source, builtins) {
1431
1430
  }
1432
1431
  break;
1433
1432
  }
1434
- case 'MemberExpression': {
1435
- const object = node.object;
1436
- if (
1437
- object.type === 'Identifier' &&
1438
- object.name === 'process' &&
1439
- !node.computed &&
1440
- node.property.name === 'env'
1441
- ) {
1442
- found.push('reads process.env');
1443
- return;
1444
- }
1445
- if (
1446
- object.type === 'MemberExpression' &&
1447
- object.object.type === 'Identifier' &&
1448
- object.object.name === 'process' &&
1449
- !object.computed &&
1450
- object.property.name === 'env'
1451
- ) {
1452
- if (!node.computed && node.property.name === 'NODE_ENV') return;
1433
+ case 'MemberExpression':
1434
+ if (isNodeEnvRead(node)) return;
1435
+ if (isProcessEnv(node) || isProcessEnv(node.object)) {
1453
1436
  found.push('reads process.env');
1454
1437
  return;
1455
1438
  }
1456
1439
  break;
1457
- }
1458
1440
  default:
1459
1441
  break;
1460
1442
  }
@@ -1560,21 +1542,14 @@ export async function componentExamplesCheck(integration) {
1560
1542
  const rel = (/** @type {string} */ file) => slash(path.relative(base, file));
1561
1543
  /** @type {unknown} */
1562
1544
  let packedFiles;
1563
- /** @type {Set<string>} */
1564
- const declared = new Set();
1545
+ /** @type {string[]} the packages an app installs with this one */
1546
+ let dependencies = [];
1565
1547
  try {
1566
1548
  const pkg = JSON.parse(
1567
1549
  fs.readFileSync(path.join(base, 'package.json'), 'utf8'),
1568
1550
  );
1569
1551
  packedFiles = pkg.files;
1570
- for (const field of [
1571
- 'dependencies',
1572
- 'peerDependencies',
1573
- 'optionalDependencies',
1574
- 'devDependencies',
1575
- ]) {
1576
- for (const name of Object.keys(pkg[field] ?? {})) declared.add(name);
1577
- }
1552
+ dependencies = packagesInstalledWith(pkg);
1578
1553
  } catch {
1579
1554
  packedFiles = undefined;
1580
1555
  }
@@ -1582,9 +1557,6 @@ export async function componentExamplesCheck(integration) {
1582
1557
  const npm = {};
1583
1558
  /** @type {Array<{file: string, asset: string, reason: string}>} */
1584
1559
  const unchecked = [];
1585
- // A bare builtin name the package installs from npm (`buffer`, `events`)
1586
- // is that package, which bundlers ship to the browser.
1587
- const builtins = new Set(builtinModules.filter(name => !declared.has(name)));
1588
1560
  /** @type {Set<string>} */
1589
1561
  const shown = new Set();
1590
1562
  for (const template of templates) {
@@ -1616,7 +1588,7 @@ export async function componentExamplesCheck(integration) {
1616
1588
  } catch {
1617
1589
  continue;
1618
1590
  }
1619
- const parsed = readModule(source, builtins);
1591
+ const parsed = readModule(source, dependencies);
1620
1592
  // A block is a showcase when it says so, or when it shows components
1621
1593
  // through `alsoShowcaseFor`, which counts them as shown above.
1622
1594
  const showcase =
@@ -26,3 +26,9 @@ export function embeddedPathProblem(p: string, options?: {
26
26
  } | null;
27
27
  /** The file extensions a page module may have. */
28
28
  export const PAGE_EXTENSIONS: string[];
29
+ /**
30
+ * The file extensions of a module a render carries: a page module's, and the
31
+ * module kinds a page module may import that hold no JSX (`.mts`, `.cts`,
32
+ * `.cjs`).
33
+ */
34
+ export const MODULE_EXTENSIONS: string[];
@@ -18,12 +18,32 @@ import {isAssetPath} from './assets.mjs';
18
18
  /** The file extensions a page module may have. */
19
19
  export const PAGE_EXTENSIONS = ['.tsx', '.jsx', '.ts', '.js', '.mjs'];
20
20
 
21
- /** JSON files that configure a project or a tool rather than hold page data. */
21
+ /**
22
+ * The file extensions of a module a render carries: a page module's, and the
23
+ * module kinds a page module may import that hold no JSX (`.mts`, `.cts`,
24
+ * `.cjs`).
25
+ */
26
+ export const MODULE_EXTENSIONS = [...PAGE_EXTENSIONS, '.mts', '.cts', '.cjs'];
27
+
28
+ /**
29
+ * JSON files that configure a project or a tool rather than hold page data,
30
+ * by the names tools read: a manifest or a tool's own file (`package.json`,
31
+ * `turbo.json`, `project.json`, ...), a TypeScript or JavaScript project
32
+ * (`tsconfig.json`, `tsconfig.app.json`, `jsconfig.json`), a `*.config.json`,
33
+ * and a lockfile. Page data may have any other name (`config.json`,
34
+ * `chart-config.json`). An rc file a tool reads is a dotfile, which no render
35
+ * carries.
36
+ */
22
37
  const CONFIG_JSON =
23
- /^(package|package-lock|composer|deno|turbo|vercel|nx|lerna|app|bower|now|netlify|firebase|renovate|project|workspace|angular|biome|components)\.jsonc?$|config|(^|[._-])rc\.jsonc?$|(^|[._-])lock\.jsonc?$/i;
38
+ /^(package|package-lock|composer|deno|turbo|vercel|nx|lerna|app|bower|now|netlify|firebase|renovate|project|workspace|angular|biome|components)\.jsonc?$|^(ts|js)config(\.[^.]+)*\.jsonc?$|\.config\.jsonc?$|(^|[._-])lock\.jsonc?$/i;
24
39
 
25
- /** Tool configuration modules: `vite.config.ts`, `astryx.config.mjs`, `next.config.js`, `.eslintrc.js`, ... */
26
- const CONFIG_MODULE = /(^|\.)config\.[cm]?[jt]sx?$|^[a-z0-9-]+rc\.[cm]?[jt]s$/i;
40
+ /**
41
+ * Tool configuration modules, by the names tools read: `vite.config.ts`,
42
+ * `astryx.config.mjs`, `next.config.js`. A module named `config.ts` or
43
+ * `arc.ts` is the page's own; an rc module a tool reads (`.eslintrc.js`) is
44
+ * a dotfile, which no render carries.
45
+ */
46
+ const CONFIG_MODULE = /\.config\.[cm]?[jt]sx?$/i;
27
47
 
28
48
  /** Any script module. */
29
49
  const SCRIPT = /\.(c|m)?[jt]sx?$/i;
@@ -103,6 +123,6 @@ export function embeddedPathProblem(p, options = {}) {
103
123
  if (((ext === '.json' || ext === '.jsonc') && CONFIG_JSON.test(base)) || CONFIG_MODULE.test(base)) {
104
124
  return {code: 'ERR_RENDER_SOURCE_DAMAGED', reason: `a project or tool configuration file (${p})`};
105
125
  }
106
- if (PAGE_EXTENSIONS.includes(ext) || ext === '.css' || ext === '.json' || isAssetPath(p)) return null;
126
+ if (MODULE_EXTENSIONS.includes(ext) || ext === '.css' || ext === '.json' || isAssetPath(p)) return null;
107
127
  return {code: 'ERR_RENDER_SOURCE_DAMAGED', reason: `a kind of file a render never embeds (${p})`};
108
128
  }
@@ -1,6 +1,16 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * Whether only a path alias can resolve an import: its name cannot be a
6
+ * package's, a Node built-in's, or a package's own subpath import
7
+ * (`@/components/Header` and `~/lib/data` cannot; `react`, `@acme/ui`, `fs`
8
+ * and `#utils`, which a package.json `imports` maps, can). A received file's
9
+ * record of alias imports counts only for these, so it can never remap a
10
+ * package, or the reader's own imports, for the reader.
11
+ * @param {string} spec
12
+ */
13
+ export function aliasOnly(spec: string): boolean;
4
14
  /**
5
15
  * What a stylesheet's `@import` rules load, read with postcss so comments
6
16
  * are ignored.
@@ -23,33 +33,49 @@ export function importSpecifiers(source: string, file: string): string[];
23
33
  */
24
34
  export function assetRefsIn(text: string): string[];
25
35
  /**
26
- * The path aliases (`compilerOptions.paths`) of the project that holds
27
- * `dir`, by TypeScript's rules (see ts-paths.mjs).
28
- * @param {string} dir
36
+ * The images, fonts and media a carried file names by a relative path: in a
37
+ * module's strings, or in a stylesheet. A render carries each one that
38
+ * exists, and {@link reachableFiles} expects each one back.
39
+ * @param {string} source
40
+ * @param {string} file its path; a `.css` file is read as a stylesheet
41
+ * @returns {string[]}
42
+ */
43
+ export function assetRefsOf(source: string, file: string): string[];
44
+ /**
45
+ * The path aliases (`compilerOptions.paths`) that TypeScript reads for a page
46
+ * written at `file`, by its rules (see ts-paths.mjs). The file and its
47
+ * folders need not exist yet.
48
+ * @param {string} file absolute
29
49
  * @returns {import('./ts-paths.mjs').PathPattern[]}
30
50
  */
31
- export function receivingAliases(dir: string): import("./ts-paths.mjs").PathPattern[];
51
+ export function receivingAliases(file: string): import("./ts-paths.mjs").PathPattern[];
32
52
  /**
33
53
  * @typedef {object} Reach
34
54
  * @property {boolean} relative - Reached by a relative import (or it is the
35
55
  * page), so it goes where the page's layout puts it.
36
56
  * @property {Set<string>} aliased - Absolute paths a receiving-project alias
37
57
  * import names for it, so it also goes there.
58
+ * @property {Set<string>} unaliased - Alias imports that name it where no
59
+ * receiving-project alias does: the render recorded the file each named,
60
+ * so it goes where the page's layout puts it, and the page needs the alias.
38
61
  */
39
62
  /**
40
63
  * The embedded files the page reaches through its imports.
41
64
  * @param {{path: string, base64: string}[]} files the embedded files, page
42
65
  * first; every path appears once (callers refuse duplicates first)
43
- * @param {{aliases?: import('./ts-paths.mjs').PathPattern[]}} [options] the
44
- * receiving project's path aliases (see receivingAliases)
66
+ * @param {{aliases?: import('./ts-paths.mjs').PathPattern[], recorded?: unknown}} [options]
67
+ * the receiving project's path aliases (see receivingAliases), and the
68
+ * alias imports the render recorded (an untrusted record: only an entry
69
+ * that names a carried file counts)
45
70
  * @returns {{reached: Map<string, Reach>, missing: string[]}} the reached
46
71
  * tree paths, and the relative imports the file does not carry
47
72
  */
48
73
  export function reachableFiles(files: {
49
74
  path: string;
50
75
  base64: string;
51
- }[], { aliases }?: {
76
+ }[], { aliases, recorded }?: {
52
77
  aliases?: import("./ts-paths.mjs").PathPattern[];
78
+ recorded?: unknown;
53
79
  }): {
54
80
  reached: Map<string, Reach>;
55
81
  missing: string[];
@@ -65,4 +91,10 @@ export type Reach = {
65
91
  * import names for it, so it also goes there.
66
92
  */
67
93
  aliased: Set<string>;
94
+ /**
95
+ * - Alias imports that name it where no
96
+ * receiving-project alias does: the render recorded the file each named,
97
+ * so it goes where the page's layout puts it, and the page needs the alias.
98
+ */
99
+ unaliased: Set<string>;
68
100
  };
@@ -13,13 +13,33 @@
13
13
  * @position foundation/render — used by the render subject's adapter
14
14
  */
15
15
 
16
- import * as fs from 'node:fs';
17
16
  import * as path from 'node:path';
18
17
  import {babelParse as parse} from '../runtime/lazy-dependencies.mjs';
19
- import {PAGE_EXTENSIONS} from './embedded-files.mjs';
18
+ import {MODULE_EXTENSIONS} from './embedded-files.mjs';
20
19
  import postcss from 'postcss';
21
- import {matchPath, readPathsIn} from './ts-paths.mjs';
20
+ import {builtinModules} from 'node:module';
21
+ import {matchPath, pathsFor} from './ts-paths.mjs';
22
22
  import {isAssetPath} from './assets.mjs';
23
+ import {climbsOut} from '../fs/paths.mjs';
24
+
25
+ /** A name npm gives a package, scoped or not (older names may have capitals). */
26
+ const PACKAGE_NAME = /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9-][\w.-]*$/i;
27
+
28
+ /**
29
+ * Whether only a path alias can resolve an import: its name cannot be a
30
+ * package's, a Node built-in's, or a package's own subpath import
31
+ * (`@/components/Header` and `~/lib/data` cannot; `react`, `@acme/ui`, `fs`
32
+ * and `#utils`, which a package.json `imports` maps, can). A received file's
33
+ * record of alias imports counts only for these, so it can never remap a
34
+ * package, or the reader's own imports, for the reader.
35
+ * @param {string} spec
36
+ */
37
+ export function aliasOnly(spec) {
38
+ if (spec.startsWith('node:') || spec.startsWith('#')) return false;
39
+ const segments = spec.split('/');
40
+ const name = spec.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0];
41
+ return !PACKAGE_NAME.test(name) && !builtinModules.includes(name);
42
+ }
23
43
 
24
44
  /**
25
45
  * What a stylesheet's `@import` rules load, read with postcss so comments
@@ -43,7 +63,7 @@ export function cssImports(css) {
43
63
  }
44
64
 
45
65
  /** Extensions an extensionless import may stand for, in resolution order. */
46
- const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.json'];
66
+ const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.mts', '.cts', '.cjs', '.json'];
47
67
 
48
68
  /**
49
69
  * The string specifiers one module imports.
@@ -71,6 +91,18 @@ export function assetRefsIn(text) {
71
91
  return out;
72
92
  }
73
93
 
94
+ /**
95
+ * The images, fonts and media a carried file names by a relative path: in a
96
+ * module's strings, or in a stylesheet. A render carries each one that
97
+ * exists, and {@link reachableFiles} expects each one back.
98
+ * @param {string} source
99
+ * @param {string} file its path; a `.css` file is read as a stylesheet
100
+ * @returns {string[]}
101
+ */
102
+ export function assetRefsOf(source, file) {
103
+ return /\.css$/i.test(file) ? assetRefsIn(source) : scanModule(source, file).assets;
104
+ }
105
+
74
106
  /**
75
107
  * One module's imports, and the relative asset paths its strings name
76
108
  * (`<img src="./logo.png">`, `url(./bg.png)` in a style).
@@ -132,22 +164,14 @@ function scanModule(source, file) {
132
164
  }
133
165
 
134
166
  /**
135
- * The path aliases (`compilerOptions.paths`) of the project that holds
136
- * `dir`, by TypeScript's rules (see ts-paths.mjs).
137
- * @param {string} dir
167
+ * The path aliases (`compilerOptions.paths`) that TypeScript reads for a page
168
+ * written at `file`, by its rules (see ts-paths.mjs). The file and its
169
+ * folders need not exist yet.
170
+ * @param {string} file absolute
138
171
  * @returns {import('./ts-paths.mjs').PathPattern[]}
139
172
  */
140
- export function receivingAliases(dir) {
141
- let d = dir;
142
- while (!fs.existsSync(d) && path.dirname(d) !== d) d = path.dirname(d);
143
- for (;;) {
144
- const found = readPathsIn(d);
145
- if (found) return found;
146
- if (fs.existsSync(path.join(d, 'package.json'))) return [];
147
- const up = path.dirname(d);
148
- if (up === d) return [];
149
- d = up;
150
- }
173
+ export function receivingAliases(file) {
174
+ return pathsFor(file);
151
175
  }
152
176
 
153
177
  /**
@@ -156,18 +180,23 @@ export function receivingAliases(dir) {
156
180
  * page), so it goes where the page's layout puts it.
157
181
  * @property {Set<string>} aliased - Absolute paths a receiving-project alias
158
182
  * import names for it, so it also goes there.
183
+ * @property {Set<string>} unaliased - Alias imports that name it where no
184
+ * receiving-project alias does: the render recorded the file each named,
185
+ * so it goes where the page's layout puts it, and the page needs the alias.
159
186
  */
160
187
 
161
188
  /**
162
189
  * The embedded files the page reaches through its imports.
163
190
  * @param {{path: string, base64: string}[]} files the embedded files, page
164
191
  * first; every path appears once (callers refuse duplicates first)
165
- * @param {{aliases?: import('./ts-paths.mjs').PathPattern[]}} [options] the
166
- * receiving project's path aliases (see receivingAliases)
192
+ * @param {{aliases?: import('./ts-paths.mjs').PathPattern[], recorded?: unknown}} [options]
193
+ * the receiving project's path aliases (see receivingAliases), and the
194
+ * alias imports the render recorded (an untrusted record: only an entry
195
+ * that names a carried file counts)
167
196
  * @returns {{reached: Map<string, Reach>, missing: string[]}} the reached
168
197
  * tree paths, and the relative imports the file does not carry
169
198
  */
170
- export function reachableFiles(files, {aliases = []} = {}) {
199
+ export function reachableFiles(files, {aliases = [], recorded} = {}) {
171
200
  const byPath = new Map(files.map(f => [f.path, f]));
172
201
  /** @type {Map<string, Reach>} */
173
202
  const reached = new Map();
@@ -203,7 +232,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
203
232
  let r = reached.get(p);
204
233
  const fresh = !r;
205
234
  if (!r) {
206
- r = {relative: false, aliased: new Set()};
235
+ r = {relative: false, aliased: new Set(), unaliased: new Set()};
207
236
  reached.set(p, r);
208
237
  }
209
238
  return {r, fresh};
@@ -217,7 +246,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
217
246
  while (queue.length > 0) {
218
247
  const current = /** @type {string} */ (queue.shift());
219
248
  const ext = path.posix.extname(current).toLowerCase();
220
- const isModule = PAGE_EXTENSIONS.includes(ext);
249
+ const isModule = MODULE_EXTENSIONS.includes(ext);
221
250
  if (!isModule && ext !== '.css') continue;
222
251
  const entry = byPath.get(current);
223
252
  if (!entry) continue;
@@ -225,7 +254,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
225
254
  // Images and fonts a module or stylesheet names by a relative path are
226
255
  // part of the page too.
227
256
  const scanned = isModule
228
- ? scanModule(source, current)
257
+ ? {imports: importSpecifiers(source, current), assets: assetRefsOf(source, current)}
229
258
  : {
230
259
  // A stylesheet's own `@import`s count as imports.
231
260
  // A stylesheet's own relative `@import`s count as imports (read
@@ -237,11 +266,11 @@ export function reachableFiles(files, {aliases = []} = {}) {
237
266
  // carries one, else a package's.
238
267
  .filter(ref => ref.startsWith('.') || byPath.has(path.posix.normalize(path.posix.join(path.posix.dirname(current), ref))))
239
268
  .map(ref => (ref.startsWith('.') ? ref : `./${ref}`)),
240
- assets: assetRefsIn(source),
269
+ assets: assetRefsOf(source, current),
241
270
  };
242
271
  for (const ref of scanned.assets) {
243
272
  const joined = path.posix.normalize(path.posix.join(path.posix.dirname(current), ref));
244
- if (joined.startsWith('..')) continue;
273
+ if (climbsOut(joined)) continue;
245
274
  if (!byPath.has(joined)) {
246
275
  missing.add(joined);
247
276
  continue;
@@ -252,7 +281,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
252
281
  const bare = spec.split('?')[0];
253
282
  if (bare.startsWith('./') || bare.startsWith('../')) {
254
283
  const joined = path.posix.normalize(path.posix.join(path.posix.dirname(current), bare));
255
- const target = joined.startsWith('..') ? null : resolveIn(joined);
284
+ const target = climbsOut(joined) ? null : resolveIn(joined);
256
285
  if (!target) {
257
286
  missing.add(joined);
258
287
  continue;
@@ -317,6 +346,16 @@ export function reachableFiles(files, {aliases = []} = {}) {
317
346
  r.aliased.add(chosen.abs);
318
347
  if (fresh) queue.push(chosen.hit.path);
319
348
  }
349
+ continue;
350
+ }
351
+ // No alias here names it, but the render recorded the carried file it
352
+ // named: that file comes back in the page's own layout.
353
+ const sent = aliasOnly(bare) && recorded && typeof recorded === 'object' && Object.hasOwn(recorded, bare) ? /** @type {Record<string, unknown>} */ (recorded)[bare] : undefined;
354
+ if (typeof sent === 'string' && byPath.has(sent)) {
355
+ const {r, fresh} = reach(sent);
356
+ r.relative = true;
357
+ r.unaliased.add(bare);
358
+ if (fresh) queue.push(sent);
320
359
  }
321
360
  }
322
361
  }
@@ -0,0 +1,66 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @typedef {object} FileFacts
6
+ * @property {string | null} cli - The CLI version that rendered the file.
7
+ * @property {number} format - The render format of the embedded source.
8
+ * @property {string} file - The rendered file's name.
9
+ * @property {string} page - The page's path from its project's root; outside a project, its path among the files it carries.
10
+ * @property {string} restored - Where --reverse writes the page by default, from the rendered file's folder.
11
+ * @property {string[]} files - The embedded files, page first.
12
+ * @property {Record<string, string>} packages - The packages the page rendered with, by name: their versions.
13
+ * @property {string[]} install - What a render outside a project must install first, as name@version.
14
+ * @property {string} [title] - The title given with --title.
15
+ */
16
+ /**
17
+ * The note at the top of a rendered file.
18
+ * @param {FileFacts} facts
19
+ * @returns {string} an HTML comment on lines of its own
20
+ */
21
+ export function headerNote(facts: FileFacts): string;
22
+ /**
23
+ * The note after the embedded source.
24
+ * @param {Pick<FileFacts, 'cli' | 'format' | 'file'>} facts
25
+ * @returns {string} an HTML comment on one line
26
+ */
27
+ export function endNote(facts: Pick<FileFacts, "cli" | "format" | "file">): string;
28
+ export function cliCommand(version: string | null): string;
29
+ export type FileFacts = {
30
+ /**
31
+ * - The CLI version that rendered the file.
32
+ */
33
+ cli: string | null;
34
+ /**
35
+ * - The render format of the embedded source.
36
+ */
37
+ format: number;
38
+ /**
39
+ * - The rendered file's name.
40
+ */
41
+ file: string;
42
+ /**
43
+ * - The page's path from its project's root; outside a project, its path among the files it carries.
44
+ */
45
+ page: string;
46
+ /**
47
+ * - Where --reverse writes the page by default, from the rendered file's folder.
48
+ */
49
+ restored: string;
50
+ /**
51
+ * - The embedded files, page first.
52
+ */
53
+ files: string[];
54
+ /**
55
+ * - The packages the page rendered with, by name: their versions.
56
+ */
57
+ packages: Record<string, string>;
58
+ /**
59
+ * - What a render outside a project must install first, as name@version.
60
+ */
61
+ install: string[];
62
+ /**
63
+ * - The title given with --title.
64
+ */
65
+ title?: string | undefined;
66
+ };
@@ -0,0 +1,118 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {shellArg} from '../text/shell-arg.mjs';
4
+
5
+ /**
6
+ * @file The plain-text notes a rendered file carries for whoever opens it
7
+ * next, a person or an agent with no other context: what made the file, what
8
+ * it carries, and the exact commands that give the page back and render it
9
+ * again. The note at the top sits in <head> after the charset and generator
10
+ * metas, so browsers and older CLIs still find both in the first bytes. The
11
+ * short note at the end follows the embedded source, for a reader that starts
12
+ * at the end of the file.
13
+ *
14
+ * The notes never spell the opening tag of the embedded block: every CLI
15
+ * finds the block by that tag, and the last match wins.
16
+ *
17
+ * @position foundation/render — used by render-page.mjs
18
+ */
19
+
20
+ /**
21
+ * The command that runs one version of the CLI anywhere npm runs.
22
+ * @param {string | null} version
23
+ */
24
+ export const cliCommand = version => `npx @astryxdesign/cli${version ? `@${version}` : ''}`;
25
+
26
+
27
+ /**
28
+ * Text that cannot end or nest an HTML comment.
29
+ * @param {string} text
30
+ */
31
+ const commentSafe = text => text.replace(/--!?>/g, '- ->').replace(/<!--/g, '<!- -');
32
+
33
+ /** The most file names the note at the top lists. */
34
+ const MAX_LISTED = 24;
35
+
36
+ /**
37
+ * @typedef {object} FileFacts
38
+ * @property {string | null} cli - The CLI version that rendered the file.
39
+ * @property {number} format - The render format of the embedded source.
40
+ * @property {string} file - The rendered file's name.
41
+ * @property {string} page - The page's path from its project's root; outside a project, its path among the files it carries.
42
+ * @property {string} restored - Where --reverse writes the page by default, from the rendered file's folder.
43
+ * @property {string[]} files - The embedded files, page first.
44
+ * @property {Record<string, string>} packages - The packages the page rendered with, by name: their versions.
45
+ * @property {string[]} install - What a render outside a project must install first, as name@version.
46
+ * @property {string} [title] - The title given with --title.
47
+ */
48
+
49
+ /**
50
+ * The note at the top of a rendered file.
51
+ * @param {FileFacts} facts
52
+ * @returns {string} an HTML comment on lines of its own
53
+ */
54
+ export function headerNote(facts) {
55
+ const run = cliCommand(facts.cli);
56
+ const file = shellArg(facts.file);
57
+ const shown = facts.files.slice(0, MAX_LISTED).join(', ');
58
+ const more = facts.files.length > MAX_LISTED ? `, and ${facts.files.length - MAX_LISTED} more` : '';
59
+ const versions = Object.entries(facts.packages).map(([name, version]) => `${name} ${version}`);
60
+ const core = facts.packages['@astryxdesign/core'];
61
+ // A title with < or > stays out of the note, which other tools read as
62
+ // HTML; step 1 prints the command with it.
63
+ const quotable = facts.title !== undefined && !/[<>]/.test(facts.title);
64
+ const title = quotable ? ` --title ${shellArg(/** @type {string} */ (facts.title))}` : '';
65
+ const lines = [
66
+ `Rendered by Astryx: astryx experimental render, @astryxdesign/cli ${facts.cli ?? '(version unknown)'}, render format ${facts.format}.`,
67
+ 'This is one static file. It runs no script and loads nothing from the network.',
68
+ 'It also carries the source of the page, so the page can come back exactly.',
69
+ '',
70
+ `Page: ${facts.page}`,
71
+ `Carried files (${facts.files.length}): ${shown}${more}`,
72
+ ...(versions.length > 0 ? [`Rendered with: ${versions.join(', ')}`] : []),
73
+ '',
74
+ 'To change the page, change its source and render it again. Do not edit this HTML:',
75
+ 'the carried source does not get the edits you make here.',
76
+ 'Run these commands in the folder that holds this file:',
77
+ ` 1. Get the source back. This writes ${facts.restored} and the files it imports`,
78
+ ` (into ${facts.restored.split('/')[0]}-2/ and so on when that folder exists; the output names it):`,
79
+ ` ${run} experimental render --reverse ${file}`,
80
+ ' 2. Edit the restored files.',
81
+ ' 3. Render again. A render replaces a file that a render wrote. Step 1 prints this',
82
+ ' command with the folder it wrote:',
83
+ ` ${run} experimental render ${shellArg(facts.restored)} --out ${file}${title}`,
84
+ ...(facts.title !== undefined && !quotable ? [' The page was rendered with --title; step 1 prints the command with it.'] : []),
85
+ `If you have the project, edit ${facts.page} there instead, and render it in the same way.`,
86
+ "Inside a project, the project's own CLI answers these commands. A project CLI older than",
87
+ `${facts.cli ?? 'the one that rendered this file'} writes the page without this note; to keep the note, update that CLI first:`,
88
+ ` npm install --save-dev @astryxdesign/cli@${facts.cli ?? 'latest'}`,
89
+ ...(facts.install.length > 0
90
+ ? [
91
+ 'Outside a project, the CLI supplies Astryx, React and StyleX. Install the other packages first:',
92
+ ` npm install ${facts.install.join(' ')}`,
93
+ ]
94
+ : []),
95
+ ...(core
96
+ ? [
97
+ `The source was written for @astryxdesign/core ${core}. In a project on a newer Core, update the`,
98
+ "restored code from inside that project (the CLI hands this to the project's own CLI):",
99
+ ` ${cliCommand(null)} upgrade --from ${core} --path ${shellArg(facts.restored.split('/')[0])} --apply`,
100
+ ]
101
+ : []),
102
+ 'Later CLI versions read this file too.',
103
+ 'If someone edits this HTML after the render, step 1 still gives back the page as rendered,',
104
+ 'and it lists the text that changed, so you can make the same change in the source.',
105
+ 'The source is in the script block at the end of this file. Keep it: without it,',
106
+ 'step 1 can rebuild only the text and the layout from the markup.',
107
+ ];
108
+ return `<!--\n${lines.map(line => (line ? ` ${commentSafe(line)}` : '')).join('\n')}\n-->`.replace(/<(?=\/?script)/gi, '&lt;');
109
+ }
110
+
111
+ /**
112
+ * The note after the embedded source.
113
+ * @param {Pick<FileFacts, 'cli' | 'format' | 'file'>} facts
114
+ * @returns {string} an HTML comment on one line
115
+ */
116
+ export function endNote(facts) {
117
+ return `<!-- Astryx render: the block above is the source of the page (render format ${facts.format}), as JSON; each file is base64 with its SHA-256. Get it back: ${commentSafe(cliCommand(facts.cli))} experimental render --reverse ${commentSafe(shellArg(facts.file))} -->`;
118
+ }
@@ -0,0 +1,18 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @param {{
6
+ * send: (message: unknown, done: (error: Error | null) => void) => unknown,
7
+ * exit: (code: number) => void,
8
+ * connected: () => boolean,
9
+ * record?: (phase: 'no-channel' | 'sending' | 'sent' | 'send-failed') => void,
10
+ * }} io
11
+ * @returns {(message: unknown) => void}
12
+ */
13
+ export function makeAnswer({ send, exit, connected, record }: {
14
+ send: (message: unknown, done: (error: Error | null) => void) => unknown;
15
+ exit: (code: number) => void;
16
+ connected: () => boolean;
17
+ record?: (phase: "no-channel" | "sending" | "sent" | "send-failed") => void;
18
+ }): (message: unknown) => void;