@astryxdesign/cli 0.7.4 → 0.7.5-canary.031a639

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 (315) hide show
  1. package/README.md +20 -20
  2. package/api/component/_adapter.mjs +16 -1
  3. package/api/component/component.test.mjs +31 -0
  4. package/api/discover/_adapter.d.mts +1 -1
  5. package/api/docs/_adapter.d.mts +5 -2
  6. package/api/docs/_adapter.mjs +24 -16
  7. package/api/docs/docs.test.mjs +18 -0
  8. package/api/docs/integrationDocs.test.mjs +2 -2
  9. package/api/experimental.d.mts +5 -0
  10. package/api/experimental.mjs +15 -0
  11. package/api/hook/list/list.d.mts +1 -1
  12. package/api/icon/_adapter.d.mts +3 -2
  13. package/api/icon/_adapter.mjs +16 -3
  14. package/api/icon/_authoring.d.mts +5 -1
  15. package/api/icon/_authoring.mjs +478 -63
  16. package/api/icon/_options.d.mts +11 -0
  17. package/api/icon/_options.mjs +39 -4
  18. package/api/icon/_records.d.mts +19 -0
  19. package/api/icon/_records.mjs +25 -0
  20. package/api/icon/add/add.d.mts +3 -3
  21. package/api/icon/add/add.mjs +227 -14
  22. package/api/icon/all-or-nothing.test.mjs +283 -0
  23. package/api/icon/detail/detail.mjs +2 -13
  24. package/api/icon/error-codes.test.mjs +14 -7
  25. package/api/icon/icon.d.mts +2 -2
  26. package/api/icon/icon.doc.mjs +30 -2
  27. package/api/icon/icon.mjs +57 -8
  28. package/api/icon/icon.test.mjs +133 -1
  29. package/api/icon/icon.type.d.mts +126 -1
  30. package/api/icon/icon.type.mjs +67 -3
  31. package/api/icon/iconAdd.doc.mjs +22 -6
  32. package/api/icon/iconMap.doc.mjs +24 -8
  33. package/api/icon/iconNewDefinition.doc.mjs +2 -2
  34. package/api/icon/iconNewSet.doc.mjs +30 -2
  35. package/api/icon/iconUse.doc.mjs +4 -1
  36. package/api/icon/map/map.d.mts +4 -4
  37. package/api/icon/map/map.mjs +134 -9
  38. package/api/icon/new-definition/new-definition.mjs +6 -2
  39. package/api/icon/new-set/new-set.mjs +2 -2
  40. package/api/icon/new-set/new-set.test.mjs +60 -10
  41. package/api/icon/option-pairs.test.mjs +368 -0
  42. package/api/icon/search/search.d.mts +10 -0
  43. package/api/icon/search/search.mjs +55 -14
  44. package/api/icon/use/use.mjs +2 -13
  45. package/api/integration/add-helpers.d.mts +15 -1
  46. package/api/integration/add-helpers.mjs +1 -1
  47. package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
  48. package/api/integration/pack-check.mjs +10 -4
  49. package/api/integration/pack-check.test.mjs +5 -1
  50. package/api/integration/validate-integration.type.d.mts +3 -2
  51. package/api/integration/validate-integration.type.mjs +3 -2
  52. package/api/render/_adapter.d.mts +28 -0
  53. package/api/render/_adapter.mjs +540 -0
  54. package/api/render/render.d.mts +15 -0
  55. package/api/render/render.doc.d.mts +9 -0
  56. package/api/render/render.doc.mjs +112 -0
  57. package/api/render/render.mjs +113 -0
  58. package/api/render/render.test.mjs +1155 -0
  59. package/api/render/render.type.d.mts +74 -0
  60. package/api/render/render.type.mjs +64 -0
  61. package/api/search/_adapter.test.mjs +21 -2
  62. package/api/search/_result.d.mts +5 -5
  63. package/api/search/search.d.mts +1 -1
  64. package/api/template/template.mjs +3 -1
  65. package/api/template/template.type.d.mts +2 -1
  66. package/api/template/template.type.mjs +1 -1
  67. package/api/template/tokenizer-showcase.test.mjs +47 -0
  68. package/api/template/unknown-name.test.mjs +63 -0
  69. package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
  70. package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
  71. package/api/theme/build/build.icon-variants.test.mjs +105 -0
  72. package/api/theme/build/build.mjs +134 -75
  73. package/api/theme/build/build.test.mjs +77 -0
  74. package/api/upgrade/_adapter.d.mts +47 -2
  75. package/api/upgrade/_adapter.mjs +58 -2
  76. package/api/upgrade/run/failure-receipt.test.mjs +212 -0
  77. package/api/upgrade/run/outcomes.test.mjs +646 -0
  78. package/api/upgrade/run/run.d.mts +36 -0
  79. package/api/upgrade/run/run.mjs +670 -44
  80. package/api/upgrade/upgrade.doc.mjs +4 -4
  81. package/api/upgrade/upgrade.mjs +19 -4
  82. package/api/upgrade/upgrade.type.d.mts +36 -1
  83. package/api/upgrade/upgrade.type.mjs +29 -4
  84. package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
  85. package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
  86. package/assets/codemods/integration-runner.mjs +8 -2
  87. package/assets/codemods/integration-runner.protection.test.mjs +53 -0
  88. package/assets/codemods/outcome.mjs +79 -0
  89. package/assets/codemods/outcome.test.mjs +40 -0
  90. package/assets/codemods/parse.mjs +94 -0
  91. package/assets/codemods/run-codemod.mjs +109 -5
  92. package/assets/codemods/runner.mjs +119 -13
  93. package/assets/codemods/transform-prop.mjs +99 -49
  94. package/assets/codemods/transform-prop.test.mjs +36 -1
  95. package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
  96. package/assets/codemods/transforms/next/index.mjs +11 -1
  97. package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
  98. package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
  99. package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
  100. package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
  101. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
  102. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +143 -70
  103. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
  104. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
  105. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
  106. package/assets/discover/official-packages.json +4 -0
  107. package/assets/docs/author-a-theme.doc.mjs +3 -1
  108. package/assets/docs/icons.doc.mjs +82 -1
  109. package/assets/docs/theme.doc.dense.mjs +8 -0
  110. package/assets/docs/theme.doc.mjs +16 -0
  111. package/assets/docs/theme.doc.zh.mjs +11 -0
  112. package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
  113. package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
  114. package/assets/docs/tree/icon-sets.doc.mjs +50 -20
  115. package/assets/docs/tree/render-pages.doc.mjs +94 -0
  116. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  117. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  118. package/assets/docs/tree/tokens-color.doc.mjs +145 -1
  119. package/assets/docs/tree/tokens.doc.mjs +1 -1
  120. package/assets/icons/definitions/activity.doc.mjs +1 -1
  121. package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
  122. package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
  123. package/assets/icons/definitions/alignStart.doc.mjs +10 -0
  124. package/assets/icons/definitions/archive.doc.mjs +1 -1
  125. package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
  126. package/assets/icons/definitions/attach.doc.mjs +1 -1
  127. package/assets/icons/definitions/audio.doc.mjs +1 -1
  128. package/assets/icons/definitions/cart.doc.mjs +1 -1
  129. package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
  130. package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
  131. package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
  132. package/assets/icons/definitions/close.doc.mjs +1 -1
  133. package/assets/icons/definitions/collapse.doc.mjs +1 -1
  134. package/assets/icons/definitions/compose.doc.mjs +1 -1
  135. package/assets/icons/definitions/conversation.doc.mjs +1 -1
  136. package/assets/icons/definitions/copy.doc.mjs +1 -1
  137. package/assets/icons/definitions/cpu.doc.mjs +9 -0
  138. package/assets/icons/definitions/database.doc.mjs +1 -1
  139. package/assets/icons/definitions/desktop.doc.mjs +1 -1
  140. package/assets/icons/definitions/discount.doc.mjs +1 -1
  141. package/assets/icons/definitions/download.doc.mjs +1 -1
  142. package/assets/icons/definitions/emoji.doc.mjs +1 -1
  143. package/assets/icons/definitions/error.doc.mjs +1 -1
  144. package/assets/icons/definitions/expand.doc.mjs +1 -1
  145. package/assets/icons/definitions/experiment.doc.mjs +1 -1
  146. package/assets/icons/definitions/externalLink.doc.mjs +7 -1
  147. package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
  148. package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
  149. package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
  150. package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
  151. package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
  152. package/assets/icons/definitions/gitFork.doc.mjs +9 -0
  153. package/assets/icons/definitions/info.doc.mjs +1 -1
  154. package/assets/icons/definitions/location.doc.mjs +1 -1
  155. package/assets/icons/definitions/mention.doc.mjs +1 -1
  156. package/assets/icons/definitions/menu.doc.mjs +1 -1
  157. package/assets/icons/definitions/microphone.doc.mjs +1 -1
  158. package/assets/icons/definitions/mobile.doc.mjs +1 -1
  159. package/assets/icons/definitions/money.doc.mjs +1 -1
  160. package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
  161. package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
  162. package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
  163. package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
  164. package/assets/icons/definitions/panelRight.doc.mjs +10 -0
  165. package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
  166. package/assets/icons/definitions/redo.doc.mjs +1 -1
  167. package/assets/icons/definitions/refresh.doc.mjs +1 -1
  168. package/assets/icons/definitions/rotate.doc.mjs +9 -0
  169. package/assets/icons/definitions/scale.doc.mjs +10 -0
  170. package/assets/icons/definitions/search.doc.mjs +1 -1
  171. package/assets/icons/definitions/send.doc.mjs +1 -1
  172. package/assets/icons/definitions/settings.doc.mjs +1 -1
  173. package/assets/icons/definitions/star.doc.mjs +1 -1
  174. package/assets/icons/definitions/stop.doc.mjs +1 -1
  175. package/assets/icons/definitions/success.doc.mjs +1 -1
  176. package/assets/icons/definitions/textCase.doc.mjs +9 -0
  177. package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
  178. package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
  179. package/assets/icons/definitions/trendDown.doc.mjs +7 -1
  180. package/assets/icons/definitions/trendUp.doc.mjs +1 -1
  181. package/assets/icons/definitions/undo.doc.mjs +1 -1
  182. package/assets/icons/definitions/upload.doc.mjs +1 -1
  183. package/assets/icons/definitions/userAdd.doc.mjs +1 -1
  184. package/assets/icons/definitions/warning.doc.mjs +1 -1
  185. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
  186. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
  187. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
  188. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
  189. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
  190. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
  191. package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
  192. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
  193. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
  194. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
  195. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
  196. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
  197. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
  198. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +22 -14
  199. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
  200. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
  201. package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
  202. package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
  203. package/assets/templates/pages/library/page.tsx +1 -2
  204. package/assets/templates/pages/table-comparison/page.tsx +12 -3
  205. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
  206. package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
  207. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
  208. package/assets/templates/themes/butter/butterTheme.ts +47 -44
  209. package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
  210. package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
  211. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
  212. package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
  213. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
  214. package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
  215. package/assets/templates/themes/stone/stoneTheme.ts +46 -21
  216. package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
  217. package/assets/theme.template.ts +18 -5
  218. package/authoring/codemod/type.ts +10 -0
  219. package/authoring/debug/parse.d.mts +2 -2
  220. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
  221. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
  222. package/authoring/doctypes/icon-set/parse.d.mts +1 -0
  223. package/authoring/doctypes/icon-set/parse.mjs +1 -0
  224. package/authoring/doctypes/icon-set/type.ts +5 -0
  225. package/authoring/doctypes/template/template.doc.mjs +1 -1
  226. package/authoring/doctypes/template/type.ts +2 -1
  227. package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
  228. package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
  229. package/clients/cli/commands/doctor.mjs +16 -17
  230. package/clients/cli/commands/experimental/icon.mjs +167 -35
  231. package/clients/cli/commands/experimental/index.mjs +2 -0
  232. package/clients/cli/commands/experimental/render.mjs +113 -0
  233. package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
  234. package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
  235. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
  236. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
  237. package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
  238. package/clients/cli/commands/experimental-render.doc.mjs +60 -0
  239. package/clients/cli/commands/experimental.doc.mjs +4 -2
  240. package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
  241. package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
  242. package/clients/cli/commands/icon.test.mjs +1 -1
  243. package/clients/cli/commands/template.mjs +4 -1
  244. package/clients/cli/commands/text-json-parity.test.mjs +46 -0
  245. package/clients/cli/commands/upgrade.doc.mjs +47 -2
  246. package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
  247. package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
  248. package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
  249. package/clients/cli/commands/upgrade.mjs +9 -2
  250. package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
  251. package/clients/cli/index.mjs +1 -0
  252. package/foundation/agent-docs/agent-docs.mjs +1 -0
  253. package/foundation/agent-docs/agent-docs.test.mjs +5 -0
  254. package/foundation/discovery/component-discovery.d.mts +2 -1
  255. package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
  256. package/foundation/discovery/component-discovery.mjs +13 -7
  257. package/foundation/discovery/icon-set-checks.d.mts +43 -9
  258. package/foundation/discovery/icon-set-checks.mjs +296 -21
  259. package/foundation/discovery/icon-set-checks.test.mjs +125 -12
  260. package/foundation/discovery/icon-set-writer.d.mts +192 -3
  261. package/foundation/discovery/icon-set-writer.mjs +608 -34
  262. package/foundation/discovery/icon-set-writer.test.mjs +26 -0
  263. package/foundation/discovery/module-exports.mjs +82 -25
  264. package/foundation/discovery/module-exports.test.mjs +38 -1
  265. package/foundation/discovery/package-exports.d.mts +13 -0
  266. package/foundation/discovery/package-exports.mjs +40 -1
  267. package/foundation/discovery/template-icons.d.mts +6 -0
  268. package/foundation/discovery/template-icons.mjs +98 -10
  269. package/foundation/discovery/template-icons.test.mjs +103 -0
  270. package/foundation/doc-compiler/doc-loads.test.mjs +22 -11
  271. package/foundation/doc-compiler/import.mjs +81 -8
  272. package/foundation/doc-compiler/read.d.mts +4 -3
  273. package/foundation/doc-compiler/read.mjs +15 -10
  274. package/foundation/doc-compiler/read.test.mjs +59 -1
  275. package/foundation/doc-compiler/tree.mjs +3 -1
  276. package/foundation/fs/module-loader.d.mts +3 -2
  277. package/foundation/fs/module-loader.mjs +3 -2
  278. package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
  279. package/foundation/fs/read-record.d.mts +27 -0
  280. package/foundation/fs/read-record.mjs +83 -15
  281. package/foundation/fs/read-record.test.mjs +88 -1
  282. package/foundation/render/assets.d.mts +31 -0
  283. package/foundation/render/assets.mjs +102 -0
  284. package/foundation/render/component-map.d.mts +52 -0
  285. package/foundation/render/component-map.mjs +141 -0
  286. package/foundation/render/css-cut.d.mts +29 -0
  287. package/foundation/render/css-cut.mjs +144 -0
  288. package/foundation/render/embedded-files.d.mts +28 -0
  289. package/foundation/render/embedded-files.mjs +108 -0
  290. package/foundation/render/embedded-imports.d.mts +61 -0
  291. package/foundation/render/embedded-imports.mjs +315 -0
  292. package/foundation/render/html-reader.d.mts +37 -0
  293. package/foundation/render/html-reader.mjs +121 -0
  294. package/foundation/render/page-worker.d.mts +7 -0
  295. package/foundation/render/page-worker.mjs +519 -0
  296. package/foundation/render/rebuild.d.mts +19 -0
  297. package/foundation/render/rebuild.mjs +269 -0
  298. package/foundation/render/render-page.d.mts +85 -0
  299. package/foundation/render/render-page.mjs +612 -0
  300. package/foundation/render/render.test.mjs +117 -0
  301. package/foundation/render/source-block.d.mts +52 -0
  302. package/foundation/render/source-block.mjs +106 -0
  303. package/foundation/response/base.d.ts +7 -0
  304. package/foundation/response/error-codes.d.mts +10 -1
  305. package/foundation/response/error-codes.doc.mjs +59 -2
  306. package/foundation/response/error-codes.mjs +62 -1
  307. package/foundation/response/json.d.mts +10 -3
  308. package/foundation/response/json.mjs +16 -4
  309. package/foundation/response/response-types.doc.mjs +39 -2
  310. package/foundation/text/string-utils.mjs +33 -0
  311. package/foundation/text/string-utils.test.mjs +17 -0
  312. package/foundation/text/suggest-order.d.mts +17 -3
  313. package/foundation/text/suggest-order.mjs +58 -13
  314. package/foundation/text/suggest-order.test.mjs +53 -0
  315. package/package.json +15 -9
@@ -57,8 +57,15 @@ export function registerUpgrade(program) {
57
57
  // already printed the error before throwing.
58
58
  logger.setSilent(json);
59
59
  if (e instanceof AstryxError) {
60
- if (json) jsonError(e.message, undefined, e.code);
61
- else {
60
+ if (json) {
61
+ // A failed migration still names the files it already changed.
62
+ jsonError(
63
+ e.message,
64
+ undefined,
65
+ e.code,
66
+ /** @type {any} */ (e).receipt,
67
+ );
68
+ } else {
62
69
  // The logger was silent only for --list; replay the error there.
63
70
  // Non-list failures were already printed by the API.
64
71
  if (isList) logger.error(e.message);
@@ -0,0 +1,350 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx upgrade` end to end: generated files to rebuild are listed in
5
+ * `regenerate` with their commands. A file the project protects keeps the run
6
+ * incomplete (ERR_CODEMOD_PROTECTED, as for any protected file); one nothing
7
+ * protects stays a codemod error (ERR_CODEMOD_FAILED). A declared
8
+ * regeneration clears them, and a real codemod failure keeps its
9
+ * ERR_CODEMOD_FAILED error.
10
+ * Manual migrations are covered at the API level in
11
+ * `api/upgrade/run/outcomes.test.mjs`.
12
+ */
13
+
14
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
15
+ import {spawnSync} from 'node:child_process';
16
+ import * as fs from 'node:fs';
17
+ import * as os from 'node:os';
18
+ import * as path from 'node:path';
19
+ import {fileURLToPath} from 'node:url';
20
+ import {CLI_VERSION} from '../../../test-utils/release-fixtures.mjs';
21
+
22
+ const CLI = path.resolve(
23
+ path.dirname(fileURLToPath(import.meta.url)),
24
+ '..',
25
+ 'bin',
26
+ 'astryx.mjs',
27
+ );
28
+ const CODEMOD = 'core:validate-data-token-ownership';
29
+ const STALE_THEME =
30
+ '/* @generated by `astryx theme build` */\n' +
31
+ '@layer astryx-base {\n :root { --color-data-categorical-green: #008000; }\n}\n';
32
+ const FRESH_THEME = '/* @generated by `astryx theme build` */\n.theme {}\n';
33
+ // The generated block below authored rules: the marker is not in the leading
34
+ // comment block, so nothing protects this file (spec:AST-040 FR3).
35
+ const UNPROTECTED_STALE_THEME = `.app { color: red; }\n${STALE_THEME}`;
36
+
37
+ let root;
38
+
39
+ function write(relative, contents) {
40
+ const file = path.join(root, relative);
41
+ fs.mkdirSync(path.dirname(file), {recursive: true});
42
+ fs.writeFileSync(file, contents);
43
+ }
44
+
45
+ function read(relative) {
46
+ return fs.readFileSync(path.join(root, relative), 'utf8');
47
+ }
48
+
49
+ function run(args, {json = true, cwd = root} = {}) {
50
+ const result = spawnSync(
51
+ process.execPath,
52
+ [CLI, ...(json ? ['--json'] : []), 'upgrade', ...args],
53
+ {
54
+ cwd,
55
+ encoding: 'utf8',
56
+ timeout: 60_000,
57
+ env: {...process.env, FORCE_COLOR: '0', CI: ''},
58
+ },
59
+ );
60
+ return {...result, envelope: json ? JSON.parse(result.stdout) : null};
61
+ }
62
+
63
+ /** @param {{config?: string}} [options] */
64
+ function seed({config = 'export default {};\n'} = {}) {
65
+ write(
66
+ 'package.json',
67
+ JSON.stringify({
68
+ name: 'consumer',
69
+ private: true,
70
+ dependencies: {'@astryxdesign/core': CLI_VERSION},
71
+ }),
72
+ );
73
+ write(
74
+ 'node_modules/@astryxdesign/core/package.json',
75
+ JSON.stringify({name: '@astryxdesign/core', version: CLI_VERSION}),
76
+ );
77
+ write('astryx.config.mjs', config);
78
+ }
79
+
80
+ const ONLY = ['--from', '0.6.0', '--codemod', 'validate-data-token-ownership'];
81
+
82
+ beforeEach(() => {
83
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-upgrade-outcomes-'));
84
+ });
85
+
86
+ afterEach(() => {
87
+ fs.rmSync(root, {recursive: true, force: true});
88
+ });
89
+
90
+ describe('generated files to regenerate', () => {
91
+ it('are listed with the rebuild command, and in protectedFiles with the declaration that protects them', () => {
92
+ seed();
93
+ write('app/theme.css', STALE_THEME);
94
+
95
+ const applied = run([...ONLY, '--path', '.', '--apply']);
96
+
97
+ expect(applied.status).toBe(1);
98
+ expect(applied.envelope).toMatchObject({
99
+ type: 'upgrade.run',
100
+ data: {
101
+ complete: false,
102
+ errorCode: 'ERR_CODEMOD_PROTECTED',
103
+ errors: [],
104
+ declinedCandidates: [],
105
+ // The stale theme carries an @generated header, so it is a protected
106
+ // file that still requires a change, with its declaration.
107
+ protectedFiles: [
108
+ {
109
+ file: 'app/theme.css',
110
+ codemods: [CODEMOD],
111
+ reasons: ['generated'],
112
+ declarations: [expect.stringContaining('@generated')],
113
+ commands: ['astryx theme build'],
114
+ },
115
+ ],
116
+ regenerate: [
117
+ {
118
+ file: 'app/theme.css',
119
+ codemods: [CODEMOD],
120
+ commands: ['astryx theme build'],
121
+ messages: [expect.stringContaining('Rebuild it')],
122
+ },
123
+ ],
124
+ },
125
+ });
126
+ expect(read('app/theme.css')).toBe(STALE_THEME);
127
+ });
128
+
129
+ it('read as incomplete in text, never as up to date', () => {
130
+ seed();
131
+ write('app/theme.css', STALE_THEME);
132
+
133
+ const text = run([...ONLY, '--path', '.', '--apply'], {json: false});
134
+
135
+ expect(text.status).toBe(1);
136
+ expect(text.stderr).toMatch(
137
+ /ERR_CODEMOD_PROTECTED: 1 protected file still requires a codemod change:\n\s+app\/theme\.css — .*@generated/,
138
+ );
139
+ expect(text.stdout).toMatch(/Regenerate with: astryx theme build/);
140
+ expect(text.stdout).toMatch(/Upgrade incomplete/);
141
+ expect(`${text.stdout}\n${text.stderr}`).not.toMatch(/No changes needed/);
142
+ });
143
+
144
+ it('keep the incomplete result, not a config error, when astryx.config fails validation too', () => {
145
+ seed({config: "export default {theme: 'neutral'};\n"});
146
+ write('app/theme.css', STALE_THEME);
147
+
148
+ const applied = run([...ONLY, '--path', '.', '--apply']);
149
+
150
+ expect(applied.status).toBe(1);
151
+ expect(applied.envelope).toMatchObject({
152
+ type: 'upgrade.run',
153
+ data: {
154
+ complete: false,
155
+ errorCode: 'ERR_CODEMOD_PROTECTED',
156
+ protectedFiles: [expect.objectContaining({file: 'app/theme.css'})],
157
+ regenerate: [
158
+ expect.objectContaining({
159
+ file: 'app/theme.css',
160
+ commands: ['astryx theme build'],
161
+ }),
162
+ ],
163
+ // The config's own error is still listed, as main reports it.
164
+ errors: [
165
+ {
166
+ file: '.',
167
+ codemod: 'config',
168
+ error: expect.stringContaining('astryx.config'),
169
+ },
170
+ ],
171
+ },
172
+ });
173
+
174
+ const configError = applied.envelope.data.errors[0].error;
175
+ const text = run([...ONLY, '--path', '.', '--apply'], {json: false});
176
+ expect(text.status).toBe(1);
177
+ expect(text.stderr).toContain(configError);
178
+ expect(text.stdout).toMatch(/Upgrade incomplete: protected changes remain/);
179
+ });
180
+
181
+ it('include protected generated files with their header command, alongside protectedFiles', () => {
182
+ seed();
183
+ write('.gitattributes', 'generated/** linguist-generated=true\n');
184
+ write(
185
+ 'generated/panel.tsx',
186
+ '// @generated\n// Command: pnpm run gen:panel\n' +
187
+ "import {useResizable} from '@astryxdesign/core';\n" +
188
+ 'export const usePanel = () => useResizable({minSizePx: 200});\n',
189
+ );
190
+
191
+ const applied = run([
192
+ '--from',
193
+ '0.5.0',
194
+ '--codemod',
195
+ 'rename-resizable-pixel-bounds',
196
+ '--path',
197
+ '.',
198
+ '--apply',
199
+ ]);
200
+
201
+ expect(applied.status).toBe(1);
202
+ expect(applied.envelope.data).toMatchObject({
203
+ complete: false,
204
+ errorCode: 'ERR_CODEMOD_PROTECTED',
205
+ protectedFiles: [expect.objectContaining({file: 'generated/panel.tsx'})],
206
+ regenerate: [
207
+ {
208
+ file: 'generated/panel.tsx',
209
+ codemods: ['core:rename-resizable-pixel-bounds'],
210
+ commands: ['pnpm run gen:panel'],
211
+ messages: [],
212
+ },
213
+ ],
214
+ });
215
+ });
216
+
217
+ it('clear once the declared regeneration rebuilds the file', () => {
218
+ const rebuild = `require('node:fs').writeFileSync('app/theme.css', ${JSON.stringify(FRESH_THEME)})`;
219
+ seed({
220
+ config: `export default {hooks: {postCodemod: [{name: 'theme', buildCommand: () => ({command: process.execPath, args: ['-e', ${JSON.stringify(rebuild)}]})}]}};\n`,
221
+ });
222
+ write('app/theme.css', STALE_THEME);
223
+
224
+ const applied = run([...ONLY, '--path', '.', '--apply']);
225
+
226
+ expect(applied.status, applied.stderr).toBe(0);
227
+ expect(applied.envelope.data).toMatchObject({
228
+ complete: true,
229
+ regenerate: [],
230
+ modifiedFiles: ['app/theme.css'],
231
+ });
232
+ expect(read('app/theme.css')).toBe(FRESH_THEME);
233
+ });
234
+
235
+ it('report one nothing protects as a codemod error, not ERR_CODEMOD_PROTECTED', () => {
236
+ seed();
237
+ write('app/theme.css', UNPROTECTED_STALE_THEME);
238
+
239
+ const applied = run([...ONLY, '--path', '.', '--apply']);
240
+
241
+ expect(applied.status).toBe(1);
242
+ expect(applied.envelope).not.toHaveProperty('type');
243
+ expect(applied.envelope).toMatchObject({
244
+ code: 'ERR_CODEMOD_FAILED',
245
+ receipt: {
246
+ complete: false,
247
+ errorCode: 'ERR_CODEMOD_FAILED',
248
+ protectedFiles: [],
249
+ errors: [
250
+ expect.objectContaining({
251
+ file: 'app/theme.css',
252
+ codemod: CODEMOD,
253
+ error: expect.stringContaining('Rebuild it'),
254
+ }),
255
+ ],
256
+ regenerate: [
257
+ expect.objectContaining({
258
+ file: 'app/theme.css',
259
+ commands: ['astryx theme build'],
260
+ }),
261
+ ],
262
+ },
263
+ });
264
+
265
+ const text = run([...ONLY, '--path', '.', '--apply'], {json: false});
266
+ expect(text.status).toBe(1);
267
+ expect(text.stderr).toMatch(
268
+ /1 generated file must be regenerated:\n\s+app\/theme\.css — /,
269
+ );
270
+ expect(text.stderr).not.toMatch(/ERR_CODEMOD_PROTECTED/);
271
+ expect(text.stdout).toMatch(/Regenerate with: astryx theme build/);
272
+ expect(text.stdout).toMatch(/Upgrade failed/);
273
+ expect(`${text.stdout}\n${text.stderr}`).not.toMatch(
274
+ /No changes needed|Done!/,
275
+ );
276
+ });
277
+
278
+ it('name files from the folder the command runs in', () => {
279
+ seed();
280
+ write('app/theme.css', STALE_THEME);
281
+
282
+ const applied = run([...ONLY, '--path', '.', '--apply'], {
283
+ cwd: path.join(root, 'app'),
284
+ });
285
+
286
+ expect(applied.envelope.data).toMatchObject({
287
+ regenerate: [expect.objectContaining({file: 'theme.css'})],
288
+ });
289
+ });
290
+ });
291
+
292
+ describe('a real failure beside them', () => {
293
+ function seedFailing() {
294
+ seed({config: "export default {integrations: ['@acme/widgets']};\n"});
295
+ write(
296
+ 'node_modules/@acme/widgets/package.json',
297
+ JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
298
+ );
299
+ write(
300
+ 'node_modules/@acme/widgets/astryx.integration.mjs',
301
+ "export default {codemods: './codemods'};\n",
302
+ );
303
+ write(
304
+ 'node_modules/@acme/widgets/codemods/0.7.0/fail.mjs',
305
+ "export default {type: 'code', title: 'Fail on boom', transform: file => { if (file.source.includes('boom')) throw new Error('codemod boom'); return undefined; }};\n",
306
+ );
307
+ write('src/broken.ts', 'export const boom = 1;\n');
308
+ }
309
+
310
+ it('keeps the ERR_CODEMOD_FAILED error, whose receipt carries both lists', () => {
311
+ seedFailing();
312
+
313
+ const applied = run(['--from', '0.6.0', '--path', 'src', '--apply']);
314
+
315
+ expect(applied.status).toBe(1);
316
+ expect(applied.envelope).toMatchObject({
317
+ code: 'ERR_CODEMOD_FAILED',
318
+ receipt: {
319
+ complete: false,
320
+ errorCode: 'ERR_CODEMOD_FAILED',
321
+ errors: [
322
+ expect.objectContaining({
323
+ file: 'src/broken.ts',
324
+ codemod: '@acme/widgets:fail',
325
+ }),
326
+ ],
327
+ declinedCandidates: [],
328
+ regenerate: [],
329
+ },
330
+ });
331
+ });
332
+
333
+ it('with a protected file to regenerate, returns the incomplete receipt as for a protected file', () => {
334
+ seedFailing();
335
+ write('src/theme.css', STALE_THEME);
336
+
337
+ const applied = run(['--from', '0.6.0', '--path', 'src', '--apply']);
338
+
339
+ expect(applied.status).toBe(1);
340
+ expect(applied.envelope).toMatchObject({
341
+ type: 'upgrade.run',
342
+ data: {
343
+ complete: false,
344
+ errorCode: 'ERR_CODEMOD_PROTECTED',
345
+ errors: [expect.objectContaining({file: 'src/broken.ts'})],
346
+ regenerate: [expect.objectContaining({file: 'src/theme.css'})],
347
+ },
348
+ });
349
+ });
350
+ });
@@ -99,6 +99,7 @@ export const JSON_SUPPORTED = new Set([
99
99
  'experimental icon use',
100
100
  'experimental icon new-set',
101
101
  'experimental icon new-definition',
102
+ 'experimental render',
102
103
  'build',
103
104
  'swizzle',
104
105
  'gap-report',
@@ -673,6 +673,7 @@ export function detectStylingSystem(targetDir) {
673
673
  '@stylexjs/rollup-plugin',
674
674
  '@stylexjs/webpack-plugin',
675
675
  '@stylexjs/nextjs-plugin',
676
+ '@stylexjs/unplugin',
676
677
  'vite-plugin-stylex',
677
678
  'unplugin-stylex',
678
679
  '@stylexswc/unplugin',
@@ -552,6 +552,11 @@ describe('detectStylingSystem', () => {
552
552
  expect(detectStylingSystem(tmpDir)).toBe('stylex');
553
553
  });
554
554
 
555
+ it('detects the official unplugin (the standard Vite path)', () => {
556
+ writePkg({'@stylexjs/unplugin': '0.10.0'});
557
+ expect(detectStylingSystem(tmpDir)).toBe('stylex');
558
+ });
559
+
555
560
  it('detects tailwind when tailwindcss is present', () => {
556
561
  writePkg({tailwindcss: '4.0.0'});
557
562
  expect(detectStylingSystem(tmpDir)).toBe('tailwind');
@@ -127,7 +127,8 @@ export function docStem(docPath: string): string;
127
127
  /**
128
128
  * The local module a doc's import names: the doc's own `import`, else the
129
129
  * subpath its directory publishes, read through the package's `exports` (its
130
- * `main` when it has none). Undefined when the package directory is unknown;
130
+ * `main` when it has none). A subpath's `source` condition wins when its file
131
+ * is in the package, so the answer does not depend on a build. Undefined when the package directory is unknown;
131
132
  * null when the import names another package or resolves to no file.
132
133
  *
133
134
  * @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
@@ -705,6 +705,47 @@ describe('integration components a family doc lists in components', () => {
705
705
  expect(namesIn(loaded)).toEqual(['AcmeList']);
706
706
  });
707
707
 
708
+ it('reads members through the source condition, the same with or without built output', () => {
709
+ // The family's member is exported only from the root entry, as Lab's
710
+ // TourStep is.
711
+ const loaded = writePackage(
712
+ {
713
+ exports: {
714
+ '.': {
715
+ source: './src/index.ts',
716
+ types: './dist/index.d.ts',
717
+ default: './dist/index.js',
718
+ },
719
+ },
720
+ },
721
+ {
722
+ 'src/index.ts':
723
+ "export {AcmeList} from './list/AcmeList';\nexport {AcmeListRow} from './list/row';\n",
724
+ 'src/list/AcmeList.doc.mjs': family(
725
+ 'AcmeList',
726
+ "{name: 'AcmeList', description: 'x'}, {name: 'AcmeListRow', description: 'x'}",
727
+ ),
728
+ 'src/list/AcmeList.tsx':
729
+ 'export function AcmeList() { return null; }\n',
730
+ 'src/list/row.tsx': 'export function AcmeListRow() { return null; }\n',
731
+ },
732
+ );
733
+ expect(namesIn(loaded)).toEqual(['AcmeList', 'AcmeListRow']);
734
+ expect(findIntegrationComponentSource(loaded, 'AcmeListRow')).toBe(
735
+ path.join(root, 'src', 'list', 'row.tsx'),
736
+ );
737
+ // Built output, even a stale one without the member, changes nothing.
738
+ fs.mkdirSync(path.join(root, 'dist'), {recursive: true});
739
+ fs.writeFileSync(
740
+ path.join(root, 'dist', 'index.js'),
741
+ 'export function AcmeList() { return null; }\n',
742
+ );
743
+ expect(namesIn(loaded)).toEqual(['AcmeList', 'AcmeListRow']);
744
+ // A package that does not ship its source reads the built output.
745
+ fs.rmSync(path.join(root, 'src', 'index.ts'));
746
+ expect(namesIn(loaded)).toEqual(['AcmeList']);
747
+ });
748
+
708
749
  it('lists a member another folder declares, with no source', async () => {
709
750
  const loaded = writePackage(
710
751
  {exports: {'./menu': './src/menu/index.ts'}},
@@ -18,7 +18,10 @@ import {
18
18
  moduleExportsName,
19
19
  staticExportObject,
20
20
  } from './module-exports.mjs';
21
- import {inspectPackageExport} from './package-exports.mjs';
21
+ import {
22
+ inspectPackageExport,
23
+ sourceExportTarget,
24
+ } from './package-exports.mjs';
22
25
 
23
26
  const require = createRequire(import.meta.url);
24
27
 
@@ -996,7 +999,8 @@ function packageMain(packageDir) {
996
999
  /**
997
1000
  * The local module a doc's import names: the doc's own `import`, else the
998
1001
  * subpath its directory publishes, read through the package's `exports` (its
999
- * `main` when it has none). Undefined when the package directory is unknown;
1002
+ * `main` when it has none). A subpath's `source` condition wins when its file
1003
+ * is in the package, so the answer does not depend on a build. Undefined when the package directory is unknown;
1000
1004
  * null when the import names another package or resolves to no file.
1001
1005
  *
1002
1006
  * @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
@@ -1027,11 +1031,13 @@ export function importedModule(integration, docPath, doc) {
1027
1031
  specifier === packageName
1028
1032
  ? '.'
1029
1033
  : `./${specifier.slice(packageName.length + 1)}`;
1030
- return inspectPackageExport(
1031
- {name: packageName, exports: exportsMap ?? undefined},
1032
- packageDir,
1033
- subpath,
1034
- ).target;
1034
+ const pkg = {name: packageName, exports: exportsMap ?? undefined};
1035
+ // The `source` condition first, when its file is there, so a family lists
1036
+ // the same members whether or not the package has been built.
1037
+ return (
1038
+ sourceExportTarget(pkg, packageDir, subpath) ??
1039
+ inspectPackageExport(pkg, packageDir, subpath).target
1040
+ );
1035
1041
  }
1036
1042
 
1037
1043
  /**
@@ -28,9 +28,8 @@ export function iconSetIssues(packageDir: string, loaded: {
28
28
  * Astryx's optional (not built-in) definitions the set's `map` does not
29
29
  * name. Mapping them is optional, so they never fail a check.
30
30
  * @property {Array<{definition: string, icon: string}>} suggestions for every
31
- * unmapped definition, built-in, optional, or the set's own, the icon whose
32
- * whole id is the definition's name or one of its words; nothing is guessed
33
- * beyond that
31
+ * unmapped definition, built-in, optional, or the set's own, the best icon
32
+ * {@link suggestedIcons} gives, if any
34
33
  * @property {IconSetUnchecked[]} unchecked what the checks could not judge:
35
34
  * never counted, never failing, even under `--strict`
36
35
  */
@@ -48,9 +47,8 @@ export function iconSetCoverage(loaded: {
48
47
  iconSets?: string;
49
48
  }, unchecked?: Map<string, IconSetUnchecked[]>): IconSetCoverage[];
50
49
  /**
51
- * The set's icon whose whole id is the definition's name (`chevronDown` is
52
- * `chevron-down`) or, in order, one of its words (spaces read as `-`). Null
53
- * when none is: a suggestion is never a guess from parts of words.
50
+ * The best icon {@link suggestedIcons} gives for a definition, or null when
51
+ * it gives none.
54
52
  * @param {DiscoveredIconSet} set
55
53
  * @param {import('../../authoring/doctypes/icon-definition/type').IconDefinitionDoc} doc
56
54
  * @returns {{map: string, icon: string} | null}
@@ -59,6 +57,41 @@ export function suggestIcon(set: DiscoveredIconSet, doc: import("../../authoring
59
57
  map: string;
60
58
  icon: string;
61
59
  } | null;
60
+ /**
61
+ * The icons a definition might map to, best first, at most three, in the
62
+ * order AST-084 FR13 gives: the name in another spelling, an icon the library
63
+ * gives the name as another name, ids that start with the name (`video` →
64
+ * `video-camera`, never `close` → `panel-left-close`), an id that is one of
65
+ * its words (`delete` → `trash`), another name that is one of its words, and
66
+ * two-word ids that are a one-word word sized, shaped, or numbered
67
+ * (`grid-2x2`). An icon `map` already names
68
+ * for another definition, or whose id is another definition's name, is left
69
+ * out: it has a meaning of its own. Never a negated form or the opposite
70
+ * direction, and never a guess from parts of words.
71
+ * @param {{data: {icons: Array<{id: string, words?: string[]}>, map?: Record<string, string>}, definitions?: Array<{doc: {name: string}}>}} set
72
+ * @param {{name: string, words: string[]}} doc
73
+ * @returns {Array<{icon: string, word: string}>}
74
+ */
75
+ export function suggestedIcons(set: {
76
+ data: {
77
+ icons: Array<{
78
+ id: string;
79
+ words?: string[];
80
+ }>;
81
+ map?: Record<string, string>;
82
+ };
83
+ definitions?: Array<{
84
+ doc: {
85
+ name: string;
86
+ };
87
+ }>;
88
+ }, doc: {
89
+ name: string;
90
+ words: string[];
91
+ }): Array<{
92
+ icon: string;
93
+ word: string;
94
+ }>;
62
95
  /** @typedef {import('../integrations/issue').AstryxIntegrationIssue} Issue */
63
96
  /** @typedef {import('./icon-set-discovery.mjs').DiscoveredIconSet} DiscoveredIconSet */
64
97
  /** An invalid descriptor or data file. */
@@ -87,6 +120,8 @@ export const ICON_DEFINITION_UNUSED: "icon_definition_unused";
87
120
  export const ICON_SOURCE_VERSION_DRIFT: "icon_source_version_drift";
88
121
  /** A set with an upstream and no license notice. */
89
122
  export const ICON_LICENSE_NOTICE_MISSING: "icon_license_notice_missing";
123
+ /** How many icons one definition is suggested at most. */
124
+ export const SUGGESTIONS_PER_DEFINITION: 3;
90
125
  /**
91
126
  * One item a check could not judge: listed, never counted, never failing.
92
127
  */
@@ -124,9 +159,8 @@ export type IconSetCoverage = {
124
159
  }>;
125
160
  /**
126
161
  * for every
127
- * unmapped definition, built-in, optional, or the set's own, the icon whose
128
- * whole id is the definition's name or one of its words; nothing is guessed
129
- * beyond that
162
+ * unmapped definition, built-in, optional, or the set's own, the best icon
163
+ * {@link suggestedIcons} gives, if any
130
164
  */
131
165
  suggestions: Array<{
132
166
  definition: string;