@astryxdesign/cli 0.7.0-canary.693da50 → 0.7.0-canary.6ecd417

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 (241) hide show
  1. package/README.md +79 -84
  2. package/api/build/build.mjs +9 -0
  3. package/api/component/_adapter.d.mts +2 -0
  4. package/api/component/_adapter.mjs +3 -1
  5. package/api/component/component.doc.mjs +5 -1
  6. package/api/docs/compiled-topics.test.mjs +16 -0
  7. package/api/doctor/doctor.doc.mjs +1 -1
  8. package/api/doctor/doctor.test.mjs +28 -0
  9. package/api/doctor/theme-checks.mjs +10 -10
  10. package/api/doctor/theme-checks.test.mjs +5 -4
  11. package/api/gap-report/gap-report.doc.mjs +1 -1
  12. package/api/gap-report/gap-report.mjs +15 -0
  13. package/api/gap-report/gap-report.test.mjs +1 -1
  14. package/api/index.d.mts +0 -2
  15. package/api/index.mjs +0 -2
  16. package/api/init/init.doc.mjs +5 -1
  17. package/api/init/init.mjs +22 -0
  18. package/api/init/init.type.d.mts +4 -1
  19. package/api/init/init.type.mjs +1 -1
  20. package/api/init/remove/remove.mjs +8 -3
  21. package/api/init/remove/remove.test.mjs +12 -0
  22. package/api/init/run/run.d.mts +1 -1
  23. package/api/init/run/run.mjs +3 -3
  24. package/api/integration/pack-check.test.mjs +8 -0
  25. package/api/integration/validate-integration.d.mts +4 -0
  26. package/api/integration/validate-integration.mjs +5 -2
  27. package/api/integration/validateIntegration.doc.mjs +1 -1
  28. package/api/json/index.ts +0 -1
  29. package/api/search/search.doc.mjs +1 -1
  30. package/api/search/search.mjs +1 -1
  31. package/api/search/search.test.mjs +1 -1
  32. package/api/search/search.type.d.mts +1 -1
  33. package/api/search/search.type.mjs +1 -1
  34. package/api/template/list/list.mjs +23 -2
  35. package/api/template/list/list.test.mjs +52 -0
  36. package/api/template/template-integration.test.mjs +37 -100
  37. package/api/template/template.doc.mjs +8 -3
  38. package/api/template/template.mjs +45 -0
  39. package/api/template/template.type.mjs +1 -1
  40. package/api/theme/_adapter.mjs +3 -3
  41. package/api/theme/add/add.d.mts +11 -5
  42. package/api/theme/add/add.mjs +19 -192
  43. package/api/theme/add/add.test.mjs +68 -258
  44. package/api/theme/add/add.types.test.mjs +0 -1
  45. package/api/theme/build/build.d.mts +3 -4
  46. package/api/theme/build/build.mjs +26 -65
  47. package/api/theme/build/build.test.mjs +11 -24
  48. package/api/theme/build/family.mjs +1 -1
  49. package/api/theme/eject/eject.copy-compat.test.mjs +168 -0
  50. package/api/theme/integration-themes.test.mjs +3 -3
  51. package/api/theme/remove/remove.test.mjs +1 -1
  52. package/api/theme/targets/targets.test.mjs +0 -4
  53. package/api/theme/template/template.mjs +1 -1
  54. package/api/theme/theme.type.d.mts +1 -30
  55. package/api/theme/theme.type.mjs +3 -13
  56. package/api/theme/themeAdd.doc.mjs +19 -27
  57. package/api/theme/themeTargets.doc.mjs +3 -4
  58. package/api/theme/themeTemplate.doc.mjs +1 -1
  59. package/api/theme/use/use.test.mjs +1 -1
  60. package/api/upgrade/upgrade.doc.mjs +1 -1
  61. package/api/upgrade/upgrade.mjs +19 -0
  62. package/assets/codemods/transforms/next/__tests__/migrate-deprecated-theme-surface.test.mjs +322 -0
  63. package/assets/codemods/transforms/next/__tests__/migrate-field-input-styling.test.mjs +108 -0
  64. package/assets/codemods/transforms/next/__tests__/preserve-bottom-sheet-content-padding.test.mjs +178 -0
  65. package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
  66. package/assets/codemods/transforms/next/index.mjs +35 -1
  67. package/assets/codemods/transforms/next/migrate-deprecated-theme-surface-v0.6-data.mjs +229 -0
  68. package/assets/codemods/transforms/next/migrate-deprecated-theme-surface.mjs +624 -0
  69. package/assets/codemods/transforms/next/migrate-field-input-styling.mjs +198 -0
  70. package/assets/codemods/transforms/next/preserve-bottom-sheet-content-padding.mjs +242 -0
  71. package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
  72. package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +38 -18
  73. package/assets/docs/author-a-theme.doc.mjs +5 -5
  74. package/assets/docs/getting-started.doc.mjs +2 -2
  75. package/assets/docs/spacing.doc.mjs +2 -2
  76. package/assets/docs/theme.doc.dense.mjs +1 -1
  77. package/assets/docs/theme.doc.mjs +2 -2
  78. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  79. package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
  80. package/assets/docs/tree/fonts-and-assets.doc.mjs +3 -3
  81. package/assets/docs/tree/styling-advanced.doc.mjs +21 -14
  82. package/assets/docs/tree/themes.doc.mjs +1 -1
  83. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  84. package/assets/docs/tree/tokens-spacing.doc.mjs +15 -15
  85. package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
  86. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +2 -2
  87. package/assets/docs/tree/versioning.doc.mjs +1 -4
  88. package/assets/docs/use-a-theme.doc.mjs +16 -16
  89. package/assets/templates/blocks/components/BottomSheet/BottomSheetHeights.tsx +1 -1
  90. package/assets/templates/blocks/components/BottomSheet/BottomSheetMobileKeyboard.tsx +1 -1
  91. package/assets/templates/blocks/components/BottomSheet/BottomSheetNoScrim.tsx +1 -1
  92. package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.tsx +1 -1
  93. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx +1 -1
  94. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorShowcase.tsx +1 -1
  95. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorTreeSearch.tsx +1 -1
  96. package/assets/templates/blocks/components/Dialog/DialogAdaptivePresentation.tsx +1 -1
  97. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
  98. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +1 -1
  99. package/assets/templates/blocks/components/Selector/SelectorClearable.tsx +1 -1
  100. package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +2 -2
  101. package/assets/templates/blocks/components/Selector/SelectorShowcase.tsx +1 -1
  102. package/assets/templates/blocks/components/Selector/SelectorWithSections.tsx +1 -1
  103. package/assets/templates/blocks/components/SelectorOption/SelectorOptionBasic.tsx +1 -1
  104. package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
  105. package/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx +1 -1
  106. package/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx +1 -1
  107. package/assets/templates/blocks/components/Slider/SliderShowcase.tsx +1 -1
  108. package/assets/templates/blocks/components/Slider/SliderWithMarks.tsx +1 -1
  109. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -1
  110. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +2 -2
  111. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -1
  112. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +1 -1
  113. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +1 -1
  114. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -2
  115. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +1 -1
  116. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +4 -4
  117. package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -1
  118. package/assets/templates/pages/canvas-editor/page.tsx +2 -2
  119. package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
  120. package/assets/templates/pages/payment-form/page.tsx +1 -1
  121. package/assets/templates/pages/table-filter/page.tsx +11 -6
  122. package/assets/templates/pages/table-inbox/page.tsx +3 -1
  123. package/assets/templates/pages/theme-showcase/page.tsx +2 -2
  124. package/assets/templates/themes/butter/butterTheme.ts +12 -0
  125. package/assets/templates/themes/chocolate/chocolateTheme.ts +12 -0
  126. package/assets/templates/themes/matcha/matchaTheme.ts +14 -14
  127. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +10 -9
  128. package/assets/templates/themes/neutral/neutralTheme.ts +12 -0
  129. package/assets/templates/themes/stone/stoneTheme.ts +12 -0
  130. package/assets/templates/themes/y2k/y2kTheme.ts +10 -10
  131. package/assets/theme.template.ts +1 -1
  132. package/authoring/debug/type.ts +2 -2
  133. package/authoring/doctypes/base/type.ts +0 -9
  134. package/authoring/integration/integration.doc.mjs +1 -1
  135. package/clients/cli/command-result-coverage.test.mjs +1 -1
  136. package/clients/cli/commands/build-theme.adaptations.test.mjs +4 -0
  137. package/clients/cli/commands/build-theme.ascii-output.test.mjs +35 -8
  138. package/clients/cli/commands/build-theme.color-scheme.test.mjs +10 -6
  139. package/clients/cli/commands/build-theme.data-tokens.test.mjs +23 -75
  140. package/clients/cli/commands/build-theme.mjs +31 -67
  141. package/clients/cli/commands/build-theme.registry.test.mjs +0 -10
  142. package/clients/cli/commands/build.doc.mjs +1 -1
  143. package/clients/cli/commands/build.mjs +1 -1
  144. package/clients/cli/commands/component-ownership.test.mjs +2 -2
  145. package/clients/cli/commands/debug-result-summary.test.mjs +0 -16
  146. package/clients/cli/commands/discover.mjs +2 -1
  147. package/clients/cli/commands/doctor.mjs +5 -2
  148. package/clients/cli/commands/empty-argument.test.mjs +16 -0
  149. package/clients/cli/commands/gap-report.doc.mjs +1 -1
  150. package/clients/cli/commands/gap-report.test.mjs +2 -2
  151. package/clients/cli/commands/init.doc.mjs +4 -4
  152. package/clients/cli/commands/init.flag-help.test.mjs +7 -10
  153. package/clients/cli/commands/init.next-steps.test.mjs +1 -1
  154. package/clients/cli/commands/integration.mjs +2 -1
  155. package/clients/cli/commands/option-pair-refusals.test.mjs +37 -0
  156. package/clients/cli/commands/search.test.mjs +1 -1
  157. package/clients/cli/commands/silent-success-refusals.test.mjs +15 -0
  158. package/clients/cli/commands/swizzle.mjs +4 -1
  159. package/clients/cli/commands/template.doc.mjs +4 -4
  160. package/clients/cli/commands/template.flag-help.test.mjs +18 -11
  161. package/clients/cli/commands/template.mjs +7 -1
  162. package/clients/cli/commands/text-json-parity.test.mjs +0 -17
  163. package/clients/cli/commands/theme-add-lifecycle.test.mjs +142 -49
  164. package/clients/cli/commands/theme-add.doc.mjs +10 -17
  165. package/clients/cli/commands/theme-list.behavior.test.mjs +2 -1
  166. package/clients/cli/commands/theme-targets.behavior.test.mjs +8 -6
  167. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  168. package/clients/cli/commands/theme.doc.mjs +2 -2
  169. package/clients/cli/commands/upgrade.doc.mjs +1 -1
  170. package/clients/cli/commands/upgrade.flag-help.test.mjs +7 -11
  171. package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +67 -0
  172. package/clients/cli/index.mjs +0 -4
  173. package/clients/cli/lib/cli-error.mjs +19 -0
  174. package/clients/cli/lib/component-format.mjs +111 -57
  175. package/clients/cli/lib/component-format.test.mjs +28 -39
  176. package/clients/cli/lib/doc-text-ascii.test.mjs +5 -2
  177. package/clients/cli/lib/exit-codes.test.mjs +0 -7
  178. package/clients/cli/lib/json-shim.test.mjs +0 -24
  179. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  180. package/foundation/agent-docs/agent-docs.mjs +6 -1
  181. package/foundation/agent-docs/app-theme-workflow.test.mjs +3 -0
  182. package/foundation/config/theme-state.mjs +3 -3
  183. package/foundation/debug/debug-fields.test.mjs +13 -35
  184. package/foundation/debug/event.mjs +13 -78
  185. package/foundation/debug/privacy-contract.test.mjs +20 -12
  186. package/foundation/debug/redact.d.mts +2 -2
  187. package/foundation/debug/redact.mjs +2 -2
  188. package/foundation/discovery/template-needs.mjs +93 -11
  189. package/foundation/discovery/template-needs.test.mjs +106 -3
  190. package/foundation/discovery/theme-imports.mjs +1 -1
  191. package/foundation/discovery/theming-targets.d.mts +1 -20
  192. package/foundation/discovery/theming-targets.mjs +1 -38
  193. package/foundation/discovery/theming-targets.test.mjs +9 -175
  194. package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
  195. package/foundation/env/package-manager.d.mts +13 -0
  196. package/foundation/env/package-manager.mjs +106 -63
  197. package/foundation/response/error-codes.doc.mjs +1 -1
  198. package/foundation/response/response-types.doc.mjs +11 -31
  199. package/foundation/response/response-types.doc.test.mjs +36 -14
  200. package/foundation/response/response.doc.mjs +1 -1
  201. package/foundation/xle/browser.d.mts +2 -2
  202. package/foundation/xle/browser.mjs +2 -2
  203. package/foundation/xle/expand.mjs +1 -1
  204. package/foundation/xle/print.mjs +1 -1
  205. package/package.json +9 -9
  206. package/api/layout/_adapter.d.mts +0 -34
  207. package/api/layout/_adapter.mjs +0 -148
  208. package/api/layout/check/check.d.mts +0 -17
  209. package/api/layout/check/check.mjs +0 -41
  210. package/api/layout/expand/expand.d.mts +0 -23
  211. package/api/layout/expand/expand.mjs +0 -161
  212. package/api/layout/expand/expand.path-safety.test.mjs +0 -53
  213. package/api/layout/expand/expand.receipt.test.mjs +0 -74
  214. package/api/layout/grammar/grammar.d.mts +0 -14
  215. package/api/layout/grammar/grammar.mjs +0 -88
  216. package/api/layout/layout.d.mts +0 -6
  217. package/api/layout/layout.mjs +0 -17
  218. package/api/layout/layout.test.mjs +0 -297
  219. package/api/layout/layout.type.d.mts +0 -90
  220. package/api/layout/layout.type.mjs +0 -104
  221. package/api/layout/layoutCheck.doc.d.mts +0 -11
  222. package/api/layout/layoutCheck.doc.mjs +0 -85
  223. package/api/layout/layoutExpand.doc.d.mts +0 -11
  224. package/api/layout/layoutExpand.doc.mjs +0 -107
  225. package/api/layout/layoutGrammar.doc.d.mts +0 -11
  226. package/api/layout/layoutGrammar.doc.mjs +0 -57
  227. package/api/theme/add/add.binary.test.mjs +0 -157
  228. package/api/theme/add/add.rollback.test.mjs +0 -158
  229. package/api/theme/add/add.staging.test.mjs +0 -83
  230. package/clients/cli/commands/layout-check.doc.mjs +0 -67
  231. package/clients/cli/commands/layout-expand.doc.mjs +0 -87
  232. package/clients/cli/commands/layout-grammar.doc.mjs +0 -32
  233. package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +0 -140
  234. package/clients/cli/commands/layout.doc.mjs +0 -36
  235. package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
  236. package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
  237. package/clients/cli/commands/layout.expand-receipt.test.mjs +0 -94
  238. package/clients/cli/commands/layout.mjs +0 -327
  239. package/clients/cli/commands/layout.path-help.test.mjs +0 -33
  240. package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
  241. package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
@@ -0,0 +1,198 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Migrate root styling on Field-composed inputs to their named parts.
5
+ *
6
+ * Field-composed inputs no longer accept root `xstyle`, `className`, or
7
+ * `style` (family:input-fields FR10). Each rename keeps the element the
8
+ * styling reached before: components whose root styling painted the visual
9
+ * control box move to `controlXstyle`/`controlClassName`/`controlStyle`;
10
+ * components whose root styling reached the Field box move to
11
+ * `containerXstyle`/`containerClassName`/`containerStyle`.
12
+ *
13
+ * Only JSX attributes written directly on an element bound to an Astryx import
14
+ * are renamed (named, aliased, or namespace imports). Spread attributes,
15
+ * wrappers that forward their own props, and unrelated components of the same
16
+ * name are left alone; those callsites fail type-checking and are migrated by
17
+ * hand. When the target attribute is already present, the root attribute gets a
18
+ * TODO instead of a rename so no value is silently dropped.
19
+ */
20
+
21
+ import {transformProp} from '../../transform-prop.mjs';
22
+
23
+ export const meta = {
24
+ title: 'Migrate input root styling to container/control parts',
25
+ description:
26
+ 'Renames root `xstyle`/`className`/`style` on Field-composed inputs to the `control*` or `container*` part they styled before.',
27
+ fileExtensions: ['.tsx', '.jsx', '.ts', '.js', '.mjs', '.cjs'],
28
+ };
29
+
30
+ /** Components whose root styling painted the visual control box. */
31
+ const CONTROL_COMPONENTS = [
32
+ 'TextInput',
33
+ 'TextArea',
34
+ 'NumberInput',
35
+ 'FileInput',
36
+ 'DateInput',
37
+ 'DateRangeInput',
38
+ 'DateTimeInput',
39
+ 'TimeInput',
40
+ 'Selector',
41
+ 'MultiSelector',
42
+ 'ComplexSelector',
43
+ ];
44
+
45
+ /** Components whose root styling reached the Field box. */
46
+ const CONTAINER_COMPONENTS = [
47
+ 'Typeahead',
48
+ 'Tokenizer',
49
+ 'CheckboxList',
50
+ 'RadioList',
51
+ 'Slider',
52
+ ];
53
+
54
+ /**
55
+ * Field-root members that also render inside InputGroup. There Field is absent
56
+ * and root styling painted the control surface, so it moves to `control*`.
57
+ */
58
+ const GROUPED_CONTROL_COMPONENTS = new Set(['Typeahead']);
59
+
60
+ /** @type {ReadonlyMap<string, 'control' | 'container'>} */
61
+ const PART_BY_COMPONENT = new Map([
62
+ ...CONTROL_COMPONENTS.map(name => /** @type {const} */ ([name, 'control'])),
63
+ ...CONTAINER_COMPONENTS.map(
64
+ name => /** @type {const} */ ([name, 'container']),
65
+ ),
66
+ ]);
67
+
68
+ const ROOT_STYLE_PROPS = /** @type {const} */ ({
69
+ xstyle: 'Xstyle',
70
+ className: 'ClassName',
71
+ style: 'Style',
72
+ });
73
+
74
+ const PACKAGE_PATTERN = /^@(astryxdesign|xds)\/core(\/[A-Za-z]+)?$/u;
75
+
76
+ const TODO =
77
+ ' TODO(astryx upgrade): root styling is no longer accepted here; merge it into ';
78
+
79
+ /** @type {ReadonlyMap<string, ReadonlySet<string>>} */
80
+ const COMPONENT_PROPS = new Map(
81
+ [...PART_BY_COMPONENT.keys()].map(name => [
82
+ name,
83
+ new Set(Object.keys(ROOT_STYLE_PROPS)),
84
+ ]),
85
+ );
86
+
87
+ /**
88
+ * @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
89
+ * @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
90
+ * @returns {string | undefined}
91
+ */
92
+ export default function migrateFieldInputStyling(file, api) {
93
+ if (!/xstyle|className|style/u.test(file.source)) return undefined;
94
+ if (![...PART_BY_COMPONENT.keys()].some(name => file.source.includes(name))) {
95
+ return undefined;
96
+ }
97
+
98
+ const j = api.jscodeshift;
99
+ const root = j(file.source);
100
+ const matchesImport = (/** @type {string} */ source) =>
101
+ PACKAGE_PATTERN.test(source);
102
+
103
+ // Local names that resolve to an Astryx InputGroup (named or namespace).
104
+ /** @type {Set<string>} */
105
+ const inputGroupNames = new Set();
106
+ /** @type {Set<string>} */
107
+ const namespaceNames = new Set();
108
+ root.find(j.ImportDeclaration).forEach((/** @type {any} */ path) => {
109
+ const source = path.node.source.value;
110
+ if (path.node.importKind === 'type') return;
111
+ if (typeof source !== 'string' || !matchesImport(source)) return;
112
+ for (const specifier of path.node.specifiers ?? []) {
113
+ if (specifier.importKind === 'type') continue;
114
+ if (
115
+ specifier.type === 'ImportSpecifier' &&
116
+ specifier.imported?.name === 'InputGroup'
117
+ ) {
118
+ inputGroupNames.add(specifier.local?.name ?? 'InputGroup');
119
+ } else if (specifier.type === 'ImportNamespaceSpecifier') {
120
+ namespaceNames.add(specifier.local.name);
121
+ }
122
+ }
123
+ });
124
+
125
+ /** @param {any} elementPath a JSXElement path */
126
+ const isInputGroup = elementPath => {
127
+ const name = elementPath.node.openingElement.name;
128
+ let localName;
129
+ if (name.type === 'JSXIdentifier' && inputGroupNames.has(name.name)) {
130
+ localName = name.name;
131
+ } else if (
132
+ name.type === 'JSXMemberExpression' &&
133
+ name.object?.type === 'JSXIdentifier' &&
134
+ name.property?.type === 'JSXIdentifier' &&
135
+ name.property.name === 'InputGroup' &&
136
+ namespaceNames.has(name.object.name)
137
+ ) {
138
+ localName = name.object.name;
139
+ } else {
140
+ return false;
141
+ }
142
+ const scope = elementPath.scope?.lookup(localName);
143
+ return scope?.path.node.type === 'Program';
144
+ };
145
+
146
+ /** @param {any} openingPath a JSXOpeningElement path */
147
+ const isInsideInputGroup = openingPath => {
148
+ for (let p = openingPath.parent?.parent; p; p = p.parent) {
149
+ if (p.node.type === 'JSXElement' && isInputGroup(p)) return true;
150
+ }
151
+ return false;
152
+ };
153
+
154
+ let changed = false;
155
+ transformProp(
156
+ root,
157
+ j,
158
+ {matchesImport, components: COMPONENT_PROPS},
159
+ (propPath, {component}) => {
160
+ const attribute = propPath.node;
161
+ const openingPath = propPath.parent;
162
+ let part = PART_BY_COMPONENT.get(component);
163
+ if (!part) return;
164
+ if (
165
+ part === 'container' &&
166
+ GROUPED_CONTROL_COMPONENTS.has(component) &&
167
+ isInsideInputGroup(openingPath)
168
+ ) {
169
+ part = 'control';
170
+ }
171
+ const name = /** @type {keyof typeof ROOT_STYLE_PROPS} */ (
172
+ attribute.name.name
173
+ );
174
+ const next = part + ROOT_STYLE_PROPS[name];
175
+ const present = (openingPath.node.attributes ?? []).some(
176
+ (/** @type {any} */ a) =>
177
+ a.type === 'JSXAttribute' && a.name?.name === next,
178
+ );
179
+ if (present) {
180
+ const comment = `${TODO}\`${next}\`. `;
181
+ attribute.comments ??= [];
182
+ if (
183
+ !attribute.comments.some(
184
+ (/** @type {any} */ c) => c.value === comment,
185
+ )
186
+ ) {
187
+ attribute.comments.push(j.commentBlock(comment, true, false));
188
+ changed = true;
189
+ }
190
+ return;
191
+ }
192
+ attribute.name = j.jsxIdentifier(next);
193
+ changed = true;
194
+ },
195
+ );
196
+
197
+ return changed ? root.toSource({quote: 'single'}) : undefined;
198
+ }
@@ -0,0 +1,242 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Codemod: preserve BottomSheet content geometry after it became a container
5
+ *
6
+ * BottomSheet now pads its content box like Dialog (theme `bottom-sheet`
7
+ * padding, else `--spacing-4`). Before, the content box had no padding, so
8
+ * callers supplied their own inset. This codemod keeps every existing sheet's
9
+ * geometry by adding `padding={0}` to imported BottomSheet elements that do not
10
+ * set `padding`.
11
+ *
12
+ * Sheets whose only child is a core `Section` or `Layout` are left alone: both
13
+ * escape the inset their container publishes, so they already render exactly
14
+ * as they did in the unpadded box.
15
+ *
16
+ * `padding={0}` goes before the first spread attribute, so a spread that
17
+ * carries `padding` still wins.
18
+ *
19
+ * `padding={0}` also zeroes the inset a nested `Layout` puts between its
20
+ * regions: a Layout's own `padding` restores only its outer edges, and the
21
+ * inner inset comes from the sheet's container chain. Such a sheet still gets
22
+ * `padding={0}`, plus a TODO comment on its statement (api.report is a stub;
23
+ * comments are the only warning channel).
24
+ */
25
+
26
+ export const meta = {
27
+ title: 'Preserve BottomSheet content padding',
28
+ description:
29
+ 'BottomSheet now pads its content like Dialog. Adds `padding={0}` to ' +
30
+ 'BottomSheet elements that do not set `padding`, keeping their previous ' +
31
+ 'unpadded content box. Sheets whose only child is a Section ' +
32
+ 'or Layout are left unchanged; they render identically. A sheet with a ' +
33
+ 'nested Layout anywhere in its content also gets a TODO comment, because ' +
34
+ "padding={0} removes the inset between that Layout's regions and the " +
35
+ "Layout's own padding restores only its outer edges. Remove " +
36
+ '`padding={0}` and your own inset to adopt the theme padding. An app ' +
37
+ 'whose theme already sets `bottom-sheet` padding on every edge is not ' +
38
+ 'affected by the new default; the transform cannot see the theme, so ' +
39
+ 'remove the added `padding={0}` there to keep the theme inset.',
40
+ };
41
+
42
+ const CORE_IMPORT_RE = /^@(astryxdesign|xds)\/core(?:\/|$)/;
43
+
44
+ const TODO_COMMENT =
45
+ ' TODO(astryx upgrade): BottomSheet now pads its content like Dialog. ' +
46
+ 'padding={0} keeps the unpadded content box, but it also removes the inset ' +
47
+ "between a nested Layout's regions, which the Layout's own padding does " +
48
+ "not restore. Drop padding={0} and the sheet content's own inset, or give " +
49
+ 'the Layout its inset another way. ';
50
+
51
+ /**
52
+ * Local JSX names bound to core components, by imported name.
53
+ * @param {any} root
54
+ * @param {any} j
55
+ * @param {string} component
56
+ * @returns {{direct: Set<string>, namespaces: Set<string>}}
57
+ */
58
+ function findBindings(root, j, component) {
59
+ const direct = new Set();
60
+ const namespaces = new Set();
61
+ root.find(j.ImportDeclaration).forEach((/** @type {any} */ importPath) => {
62
+ const source = importPath.node.source.value;
63
+ if (
64
+ importPath.node.importKind === 'type' ||
65
+ typeof source !== 'string' ||
66
+ !CORE_IMPORT_RE.test(source)
67
+ ) {
68
+ return;
69
+ }
70
+ const subpath = source.split('/').at(-1);
71
+ for (const specifier of importPath.node.specifiers ?? []) {
72
+ if (specifier.importKind === 'type') continue;
73
+ if (specifier.type === 'ImportSpecifier') {
74
+ const imported = specifier.imported?.name ?? specifier.imported?.value;
75
+ if (imported === component) {
76
+ direct.add(specifier.local?.name ?? imported);
77
+ }
78
+ } else if (
79
+ specifier.type === 'ImportDefaultSpecifier' &&
80
+ subpath === component
81
+ ) {
82
+ direct.add(specifier.local.name);
83
+ } else if (specifier.type === 'ImportNamespaceSpecifier') {
84
+ namespaces.add(specifier.local.name);
85
+ }
86
+ }
87
+ });
88
+ return {direct, namespaces};
89
+ }
90
+
91
+ /**
92
+ * @param {any} name JSX element name node
93
+ * @param {{direct: Set<string>, namespaces: Set<string>}} bindings
94
+ * @param {string} component
95
+ */
96
+ function nameMatches(name, bindings, component) {
97
+ if (name?.type === 'JSXIdentifier') {
98
+ return bindings.direct.has(name.name);
99
+ }
100
+ return (
101
+ name?.type === 'JSXMemberExpression' &&
102
+ name.object?.type === 'JSXIdentifier' &&
103
+ bindings.namespaces.has(name.object.name) &&
104
+ name.property?.name === component
105
+ );
106
+ }
107
+
108
+ // A parameter or local declaration with the imported name shadows the module
109
+ // binding (same rule as transform-prop.mjs): only a tag whose root binding
110
+ // resolves to the Program scope is the imported component.
111
+ /** @param {any} elementPath @param {any} name */
112
+ function isModuleBinding(elementPath, name) {
113
+ const localName =
114
+ name?.type === 'JSXIdentifier'
115
+ ? name.name
116
+ : name?.type === 'JSXMemberExpression' &&
117
+ name.object?.type === 'JSXIdentifier'
118
+ ? name.object.name
119
+ : null;
120
+ if (localName == null) return false;
121
+ const scope = elementPath.scope?.lookup(localName);
122
+ return scope?.path?.node?.type === 'Program';
123
+ }
124
+
125
+ /**
126
+ * Children that render something: drops whitespace-only text and empty
127
+ * `{}` / `{/* comment *\/}` containers.
128
+ * @param {any[]} children
129
+ */
130
+ function meaningfulChildren(children) {
131
+ return children.filter((/** @type {any} */ child) => {
132
+ if (child.type === 'JSXText') {
133
+ return child.value.trim() !== '';
134
+ }
135
+ if (child.type === 'JSXExpressionContainer') {
136
+ return child.expression?.type !== 'JSXEmptyExpression';
137
+ }
138
+ return true;
139
+ });
140
+ }
141
+
142
+ /**
143
+ * Attach the TODO to the nearest enclosing statement: a comment on a JSX node
144
+ * inside JSX children would print as text.
145
+ * @param {any} j
146
+ * @param {any} elementPath
147
+ */
148
+ function addTodo(j, elementPath) {
149
+ let path = elementPath;
150
+ while (path && !j.Statement.check(path.node)) {
151
+ path = path.parent;
152
+ }
153
+ if (!path) return;
154
+ const host = path.node;
155
+ host.comments = host.comments ?? [];
156
+ if (host.comments.some((/** @type {any} */ c) => c.value === TODO_COMMENT)) {
157
+ return;
158
+ }
159
+ host.comments.push(j.commentBlock(TODO_COMMENT, true, false));
160
+ }
161
+
162
+ /**
163
+ * @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
164
+ * @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
165
+ * @returns {string | null | undefined}
166
+ */
167
+ export default function transformer(file, api) {
168
+ if (!file.source.includes('BottomSheet')) return undefined;
169
+ const j = api.jscodeshift;
170
+ const root = j(file.source);
171
+ const sheets = findBindings(root, j, 'BottomSheet');
172
+ if (sheets.direct.size === 0 && sheets.namespaces.size === 0) {
173
+ return undefined;
174
+ }
175
+ const sections = findBindings(root, j, 'Section');
176
+ const layouts = findBindings(root, j, 'Layout');
177
+ let hasChanges = false;
178
+
179
+ root.find(j.JSXElement).forEach((/** @type {any} */ elementPath) => {
180
+ const opening = elementPath.node.openingElement;
181
+ if (!nameMatches(opening.name, sheets, 'BottomSheet')) return;
182
+ if (!isModuleBinding(elementPath, opening.name)) return;
183
+
184
+ const attributes = opening.attributes ?? [];
185
+ const setsPadding = attributes.some(
186
+ (/** @type {any} */ attribute) =>
187
+ attribute.type === 'JSXAttribute' && attribute.name?.name === 'padding',
188
+ );
189
+ if (setsPadding) return;
190
+
191
+ const children = meaningfulChildren(elementPath.node.children ?? []);
192
+ const hasChildrenAttribute = attributes.some(
193
+ (/** @type {any} */ attribute) =>
194
+ attribute.type === 'JSXAttribute' &&
195
+ attribute.name?.name === 'children',
196
+ );
197
+ if (
198
+ !hasChildrenAttribute &&
199
+ children.length === 1 &&
200
+ children[0].type === 'JSXElement' &&
201
+ (nameMatches(children[0].openingElement.name, sections, 'Section') ||
202
+ nameMatches(children[0].openingElement.name, layouts, 'Layout')) &&
203
+ isModuleBinding(
204
+ elementPath.get('children', 0),
205
+ children[0].openingElement.name,
206
+ )
207
+ ) {
208
+ return;
209
+ }
210
+
211
+ const padding = j.jsxAttribute(
212
+ j.jsxIdentifier('padding'),
213
+ j.jsxExpressionContainer(j.numericLiteral(0)),
214
+ );
215
+ const firstSpread = attributes.findIndex(
216
+ (/** @type {any} */ attribute) => attribute.type === 'JSXSpreadAttribute',
217
+ );
218
+ if (firstSpread === -1) {
219
+ attributes.push(padding);
220
+ } else {
221
+ attributes.splice(firstSpread, 0, padding);
222
+ }
223
+ opening.attributes = attributes;
224
+ hasChanges = true;
225
+
226
+ // Any nested core Layout loses the inset between its regions, with or
227
+ // without its own padding, so every one gets the TODO.
228
+ const hasNestedLayout =
229
+ j(elementPath)
230
+ .find(j.JSXOpeningElement)
231
+ .filter(
232
+ (/** @type {any} */ openingPath) =>
233
+ nameMatches(openingPath.node.name, layouts, 'Layout') &&
234
+ isModuleBinding(openingPath, openingPath.node.name),
235
+ ).length > 0;
236
+ if (hasNestedLayout) {
237
+ addTodo(j, elementPath);
238
+ }
239
+ });
240
+
241
+ return hasChanges ? root.toSource() : undefined;
242
+ }
@@ -0,0 +1,102 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Report data-token consumers that need an ownership migration.
5
+ *
6
+ * @input Consumer JavaScript/TypeScript source and generated theme CSS
7
+ * @output No rewritten source; actionable upgrade errors for fallback-less
8
+ * `var(--color-data-*)` uses (in JS strings, embedded or whole, and in CSS)
9
+ * and stale generated root-default artifacts
10
+ * @position Next-release upgrade validation for spec:AST-066
11
+ */
12
+
13
+ import * as path from 'node:path';
14
+
15
+ export const meta = {
16
+ title: 'Validate data-token ownership',
17
+ description:
18
+ 'Reports fallback-less data-token var() uses in source strings and stylesheets for manual CSS/non-CSS migration, and stale generated theme CSS that still owns root defaults.',
19
+ fileExtensions: ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.css'],
20
+ };
21
+
22
+ // A use without a fallback; `var(--color-data-x, <fallback>)` stays valid.
23
+ const DIRECT_DATA_VAR = /var\(\s*(--color-data-[a-z0-9-]+)\s*\)/u;
24
+ const CSS_COMMENT = /\/\*[\s\S]*?\*\//gu;
25
+ const GENERATED_THEME_HEADER = '@generated by `astryx theme build`';
26
+ const ROOT_DATA_DECLARATION = /:root\s*\{[^}]*--color-data-/su;
27
+
28
+ /** @param {any} node */
29
+ function staticString(node) {
30
+ if (
31
+ (node?.type === 'StringLiteral' || node?.type === 'Literal') &&
32
+ typeof node.value === 'string'
33
+ ) {
34
+ return node.value;
35
+ }
36
+ if (node?.type === 'TemplateLiteral') {
37
+ // Each static chunk of the template; a use can sit between expressions.
38
+ return (node.quasis ?? [])
39
+ .map((/** @type {any} */ q) => q?.value?.cooked ?? q?.value?.raw ?? '')
40
+ .join('\u0000');
41
+ }
42
+ return undefined;
43
+ }
44
+
45
+ /**
46
+ * @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
47
+ * @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
48
+ * @returns {undefined}
49
+ */
50
+ export default function validateDataTokenOwnership(file, api) {
51
+ if (!file.source.includes('--color-data-')) return undefined;
52
+
53
+ if (path.extname(file.path) === '.css') {
54
+ if (
55
+ file.source.includes(GENERATED_THEME_HEADER) &&
56
+ ROOT_DATA_DECLARATION.test(file.source)
57
+ ) {
58
+ throw new Error(
59
+ 'This generated theme CSS still emits canonical data defaults at :root. Rebuild it with `astryx theme build`; defaults now come from compiled dataVars consumers.',
60
+ );
61
+ }
62
+ const uncommented = file.source.replace(CSS_COMMENT, comment =>
63
+ comment.replace(/[^\n]/gu, ' '),
64
+ );
65
+ const cssMatch = DIRECT_DATA_VAR.exec(uncommented);
66
+ if (cssMatch) {
67
+ const line = uncommented.slice(0, cssMatch.index).split('\n').length;
68
+ throw new Error(
69
+ `Raw var(${cssMatch[1]}) without a fallback at line ${line} needs manual migration: compiled dataVars output is not guaranteed in this stylesheet, so add an explicit fallback or style the element from code that imports dataVars from @astryxdesign/core/theme/dataTokens.stylex.`,
70
+ );
71
+ }
72
+ return undefined;
73
+ }
74
+
75
+ const j = api.jscodeshift;
76
+ const root = j(file.source);
77
+ /** @type {{token: string, line: number|null}|null} */
78
+ let found = null;
79
+ const inspect = (/** @type {any} */ node) => {
80
+ if (found) return;
81
+ const value = staticString(node);
82
+ const match =
83
+ typeof value === 'string' ? value.match(DIRECT_DATA_VAR) : null;
84
+ if (match) {
85
+ found = {token: match[1], line: node.loc?.start?.line ?? null};
86
+ }
87
+ };
88
+
89
+ /** @param {any} nodePath */
90
+ const inspectPath = nodePath => inspect(nodePath.node);
91
+ root.find(j.StringLiteral).forEach(inspectPath);
92
+ root.find(j.Literal).forEach(inspectPath);
93
+ root.find(j.TemplateLiteral).forEach(inspectPath);
94
+
95
+ if (found) {
96
+ const {token, line} = found;
97
+ throw new Error(
98
+ `Direct var(${token})${line == null ? '' : ` at line ${line}`} needs manual migration: CSS-capable code imports dataVars from @astryxdesign/core/theme/dataTokens.stylex; Canvas and other non-CSS APIs use resolveThemeToken() or useTheme().token().`,
99
+ );
100
+ }
101
+ return undefined;
102
+ }
@@ -30,10 +30,16 @@ export const meta = {
30
30
  /** @typedef {[string, string]} AttributeCandidate */
31
31
  /** @typedef {AttributeCandidate | AttributeCandidate[]} CandidateEntry */
32
32
 
33
+ /** @typedef {Record<string, Array<{axis: string, token: 'class-value' | 'prefixed', prefix?: string}>>} DynamicAxes */
34
+ /** @typedef {{targets: Record<string, Record<string, CandidateEntry>>, dynamicAxes: DynamicAxes}} SelectorData */
35
+
36
+ // The selector tables in effect for the current synchronous migration. They
37
+ // default to the 0.5.4 snapshot this codemod shipped with; a later release can
38
+ // pass a newer frozen snapshot to migrateAstryxThemeSelectors().
33
39
  /** @type {Record<string, Record<string, CandidateEntry>>} */
34
- const TARGETS = V054_THEME_SELECTOR_TARGETS;
35
- /** @type {Record<string, Array<{axis: string, token: 'class-value' | 'prefixed', prefix?: string}>>} */
36
- const DYNAMIC_AXES = V054_THEME_SELECTOR_DYNAMIC_AXES;
40
+ let TARGETS = V054_THEME_SELECTOR_TARGETS;
41
+ /** @type {DynamicAxes} */
42
+ let DYNAMIC_AXES = V054_THEME_SELECTOR_DYNAMIC_AXES;
37
43
  const SAME_ELEMENT_FUNCTIONAL_PSEUDOS = new Set([':is', ':where', ':not']);
38
44
 
39
45
  /** @param {string} axis */
@@ -108,7 +114,10 @@ function candidatesFor(target, token) {
108
114
  function dedupeCandidates(candidates) {
109
115
  return [
110
116
  ...new Map(
111
- candidates.map(candidate => [`${candidate[0]}\0${candidate[1]}`, candidate]),
117
+ candidates.map(candidate => [
118
+ `${candidate[0]}\0${candidate[1]}`,
119
+ candidate,
120
+ ]),
112
121
  ).values(),
113
122
  ];
114
123
  }
@@ -410,10 +419,7 @@ function migrateCompound(
410
419
  const selectorArms = node.nodes.filter(
411
420
  (/** @type {any} */ selector) => selector.type === 'selector',
412
421
  );
413
- if (
414
- completedArms.size > 0 &&
415
- completedArms.size === selectorArms.length
416
- ) {
422
+ if (completedArms.size > 0 && completedArms.size === selectorArms.length) {
417
423
  continue;
418
424
  }
419
425
  if (node.value === ':nth-child' || node.value === ':nth-last-child') {
@@ -427,11 +433,7 @@ function migrateCompound(
427
433
  : [];
428
434
  for (const selector of selectorArms) {
429
435
  if (completedArms.has(selector)) continue;
430
- migrateSelectorNode(
431
- selector,
432
- nestedTargets,
433
- nestedConditionalTargets,
434
- );
436
+ migrateSelectorNode(selector, nestedTargets, nestedConditionalTargets);
435
437
  }
436
438
  }
437
439
 
@@ -490,9 +492,7 @@ function combineSelectorListContexts(contexts) {
490
492
  );
491
493
  return {
492
494
  guaranteed,
493
- possible: [
494
- ...new Set(contexts.flatMap(context => context.possible)),
495
- ],
495
+ possible: [...new Set(contexts.flatMap(context => context.possible))],
496
496
  };
497
497
  }
498
498
 
@@ -655,8 +655,28 @@ function migrateScopeParams(params) {
655
655
  return result + params.slice(last);
656
656
  }
657
657
 
658
+ /**
659
+ * @param {string} source
660
+ * @param {string} [from]
661
+ * @param {SelectorData} [data] frozen selector tables; defaults to 0.5.4
662
+ * @returns {string}
663
+ */
664
+ export function migrateAstryxThemeSelectors(source, from = 'styles.css', data) {
665
+ if (data == null) return migrateWithActiveTables(source, from);
666
+ const previousTargets = TARGETS;
667
+ const previousAxes = DYNAMIC_AXES;
668
+ TARGETS = data.targets;
669
+ DYNAMIC_AXES = data.dynamicAxes;
670
+ try {
671
+ return migrateWithActiveTables(source, from);
672
+ } finally {
673
+ TARGETS = previousTargets;
674
+ DYNAMIC_AXES = previousAxes;
675
+ }
676
+ }
677
+
658
678
  /** @param {string} source @param {string} from @returns {string} */
659
- export function migrateAstryxThemeSelectors(source, from = 'styles.css') {
679
+ function migrateWithActiveTables(source, from) {
660
680
  const root = postcss.parse(source, {from});
661
681
  const existingComments = new Set();
662
682
  root.walkComments(comment => {
@@ -683,7 +703,7 @@ export function migrateAstryxThemeSelectors(source, from = 'styles.css') {
683
703
  }
684
704
  const parentContext =
685
705
  parent?.type === 'rule'
686
- ? ruleContexts.get(parent) ?? {guaranteed: [], possible: []}
706
+ ? (ruleContexts.get(parent) ?? {guaranteed: [], possible: []})
687
707
  : {guaranteed: [], possible: []};
688
708
  try {
689
709
  const migrated = migrateSelectorTextWithContext(