@astryxdesign/cli 0.7.5-canary.fccd771 → 0.7.5

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 (117) hide show
  1. package/CHANGELOG.md +91 -3
  2. package/README.md +2 -2
  3. package/api/hook/detail/detail.test.mjs +11 -0
  4. package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
  5. package/api/integration/pack-check.mjs +10 -4
  6. package/api/integration/pack-check.test.mjs +5 -1
  7. package/api/swizzle/copy/copy.mjs +1 -1
  8. package/api/template/tokenizer-showcase.test.mjs +47 -0
  9. package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
  10. package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
  11. package/api/theme/build/build.icon-function-entries.test.mjs +499 -0
  12. package/api/theme/build/build.icon-variants.test.mjs +105 -0
  13. package/api/theme/build/build.mjs +371 -113
  14. package/api/theme/build/build.project-core.test.mjs +63 -8
  15. package/api/theme/build/build.test.mjs +77 -0
  16. package/api/theme/build/icon-imports.d.mts +12 -2
  17. package/api/theme/build/icon-imports.mjs +36 -11
  18. package/api/upgrade/_adapter.d.mts +47 -2
  19. package/api/upgrade/_adapter.mjs +58 -2
  20. package/api/upgrade/run/failure-receipt.test.mjs +212 -0
  21. package/api/upgrade/run/outcomes.test.mjs +646 -0
  22. package/api/upgrade/run/run.d.mts +36 -0
  23. package/api/upgrade/run/run.mjs +670 -44
  24. package/api/upgrade/upgrade.doc.mjs +4 -4
  25. package/api/upgrade/upgrade.mjs +19 -4
  26. package/api/upgrade/upgrade.type.d.mts +36 -1
  27. package/api/upgrade/upgrade.type.mjs +29 -4
  28. package/assets/codemods/__tests__/registry.test.mjs +1 -0
  29. package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
  30. package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
  31. package/assets/codemods/integration-runner.mjs +8 -2
  32. package/assets/codemods/integration-runner.protection.test.mjs +53 -0
  33. package/assets/codemods/outcome.mjs +79 -0
  34. package/assets/codemods/outcome.test.mjs +40 -0
  35. package/assets/codemods/parse.mjs +94 -0
  36. package/assets/codemods/registry.mjs +1 -0
  37. package/assets/codemods/run-codemod.mjs +109 -5
  38. package/assets/codemods/runner.mjs +119 -13
  39. package/assets/codemods/transform-prop.mjs +99 -49
  40. package/assets/codemods/transform-prop.test.mjs +36 -1
  41. package/assets/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +1 -1
  42. package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
  43. package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
  44. package/assets/codemods/transforms/v0.1.5/rename-switch-label-spacing-default-to-hug.mjs +1 -1
  45. package/assets/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +1 -1
  46. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +1 -1
  47. package/assets/codemods/transforms/v0.2.0/remove-tablist-orientation.mjs +1 -1
  48. package/assets/codemods/transforms/v0.2.1/migrate-dialog-position-to-logical.mjs +1 -1
  49. package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
  50. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
  51. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +143 -70
  52. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
  53. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
  54. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
  55. package/assets/codemods/transforms/v0.7.5/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
  56. package/assets/codemods/transforms/v0.7.5/index.mjs +20 -0
  57. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +315 -0
  58. package/assets/docs/README.md +13 -13
  59. package/assets/docs/author-a-theme.doc.mjs +5 -1
  60. package/assets/docs/getting-started.doc.mjs +5 -5
  61. package/assets/docs/icons.doc.mjs +82 -1
  62. package/assets/docs/motion.doc.mjs +1 -1
  63. package/assets/docs/theme.doc.dense.mjs +8 -0
  64. package/assets/docs/theme.doc.mjs +16 -0
  65. package/assets/docs/theme.doc.zh.mjs +11 -0
  66. package/assets/docs/tree/i18n-library-integration.doc.mjs +1 -1
  67. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  68. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  69. package/assets/docs/tree/tokens-color.doc.mjs +145 -1
  70. package/assets/docs/tree/tokens-ease.doc.mjs +4 -0
  71. package/assets/docs/tree/tokens.doc.mjs +1 -1
  72. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
  73. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
  74. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
  75. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
  76. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
  77. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
  78. package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
  79. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
  80. package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
  81. package/assets/templates/pages/library/page.tsx +1 -2
  82. package/assets/templates/pages/table-comparison/page.tsx +12 -3
  83. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
  84. package/assets/templates/themes/butter/butterTheme.ts +47 -44
  85. package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
  86. package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
  87. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
  88. package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
  89. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
  90. package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
  91. package/assets/templates/themes/stone/stoneTheme.ts +46 -21
  92. package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
  93. package/assets/theme.template.ts +19 -6
  94. package/authoring/codemod/type.ts +10 -0
  95. package/authoring/config/config.doc.mjs +1 -1
  96. package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
  97. package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
  98. package/clients/cli/commands/swizzle.routing.test.mjs +1 -1
  99. package/clients/cli/commands/upgrade.doc.mjs +47 -2
  100. package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
  101. package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
  102. package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
  103. package/clients/cli/commands/upgrade.mjs +9 -2
  104. package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
  105. package/foundation/agent-docs/agent-docs.mjs +1 -0
  106. package/foundation/agent-docs/agent-docs.test.mjs +5 -0
  107. package/foundation/config/project.d.mts +1 -1
  108. package/foundation/config/project.mjs +1 -1
  109. package/foundation/debug/redact.test.mjs +1 -1
  110. package/foundation/doc-compiler/doc-loads.test.mjs +2 -6
  111. package/foundation/response/base.d.ts +7 -0
  112. package/foundation/response/error-codes.doc.mjs +3 -2
  113. package/foundation/response/error-codes.mjs +1 -1
  114. package/foundation/response/json.d.mts +10 -3
  115. package/foundation/response/json.mjs +16 -4
  116. package/foundation/response/response-types.doc.mjs +1 -1
  117. package/package.json +13 -12
@@ -26,13 +26,16 @@ const withAlpha = (color: string, alpha: string): string => `${color}${alpha}`;
26
26
  */
27
27
  const INPUT_STATUS_VARS = {
28
28
  'status:success': {
29
- '--color-success': lightDark(green.light[55], green.dark[70]),
29
+ '--color-border-success': lightDark(green.light[55], green.dark[70]),
30
+ '--color-icon-success': lightDark(green.light[55], green.dark[70]),
30
31
  },
31
32
  'status:warning': {
32
- '--color-warning': lightDark(yellow.light[55], yellow.dark[70]),
33
+ '--color-border-warning': lightDark(yellow.light[55], yellow.dark[70]),
34
+ '--color-icon-warning': lightDark(yellow.light[55], yellow.dark[70]),
33
35
  },
34
36
  'status:error': {
35
- '--color-error': lightDark(red.light[60], red.dark[70]),
37
+ '--color-border-error': lightDark(red.light[60], red.dark[70]),
38
+ '--color-icon-error': lightDark(red.light[60], red.dark[70]),
36
39
  },
37
40
  } as const;
38
41
 
@@ -188,9 +191,22 @@ export const stoneTheme = defineTheme({
188
191
  '--color-on-dark': neutral.light[100],
189
192
  '--color-on-light': [neutral.light[15], neutral.dark[15]],
190
193
  '--color-on-accent': [neutral.light[100], neutral.dark[15]],
191
- '--color-on-success': [green.light[30], green.dark[90]],
192
- '--color-on-error': [red.light[30], red.dark[90]],
193
- '--color-on-warning': [yellow.light[30], yellow.dark[90]],
194
+ '--color-on-success': [neutral.light[100], neutral.dark[10]],
195
+ '--color-on-error': [neutral.light[100], neutral.dark[10]],
196
+ '--color-on-warning': [neutral.light[100], neutral.dark[10]],
197
+
198
+ '--color-info': [blue.light[40], blue.dark[70]],
199
+ '--color-info-muted': [blue.light[90], blue.dark[25]],
200
+ '--color-on-info': [neutral.light[100], neutral.dark[15]],
201
+
202
+ '--color-text-info': [blue.light[30], blue.dark[90]],
203
+ '--color-text-success': [green.light[30], green.dark[90]],
204
+ '--color-text-warning': [yellow.light[30], yellow.dark[90]],
205
+ '--color-text-error': [red.light[30], red.dark[90]],
206
+ '--color-on-info-muted': [blue.light[30], blue.dark[90]],
207
+ '--color-on-success-muted': [green.light[30], green.dark[25]],
208
+ '--color-on-warning-muted': [yellow.light[30], yellow.dark[25]],
209
+ '--color-on-error-muted': [red.light[30], red.dark[25]],
194
210
 
195
211
  // Icon
196
212
  '--color-icon-accent': [neutral.light[15], neutral.dark[95]],
@@ -336,32 +352,23 @@ export const stoneTheme = defineTheme({
336
352
  },
337
353
  },
338
354
 
339
- // Banner surface declarations live above the theme layer, so redirect the
340
- // semantic variables here instead of attempting a losing direct fill.
355
+ // Banner status surfaces and content use the matching categorical pair.
341
356
  banner: {
342
357
  'status:info': {
343
- '--color-accent-muted': 'var(--color-background-blue)',
344
- '--color-text-primary': 'var(--color-text-blue)',
345
- '--color-text-secondary': 'var(--color-text-blue)',
346
- '--color-accent': 'var(--color-text-blue)',
358
+ '--color-info-muted': 'var(--color-background-blue)',
359
+ '--color-on-info-muted': 'var(--color-text-blue)',
347
360
  },
348
361
  'status:success': {
349
362
  '--color-success-muted': 'var(--color-background-green)',
350
- '--color-text-primary': 'var(--color-text-green)',
351
- '--color-text-secondary': 'var(--color-text-green)',
352
- '--color-success': 'var(--color-text-green)',
363
+ '--color-on-success-muted': 'var(--color-text-green)',
353
364
  },
354
365
  'status:warning': {
355
366
  '--color-warning-muted': 'var(--color-background-yellow)',
356
- '--color-text-primary': 'var(--color-text-yellow)',
357
- '--color-text-secondary': 'var(--color-text-yellow)',
358
- '--color-warning': 'var(--color-text-yellow)',
367
+ '--color-on-warning-muted': 'var(--color-text-yellow)',
359
368
  },
360
369
  'status:error': {
361
370
  '--color-error-muted': 'var(--color-background-red)',
362
- '--color-text-primary': 'var(--color-text-red)',
363
- '--color-text-secondary': 'var(--color-text-red)',
364
- '--color-error': 'var(--color-text-red)',
371
+ '--color-on-error-muted': 'var(--color-text-red)',
365
372
  },
366
373
  },
367
374
 
@@ -382,6 +389,21 @@ export const stoneTheme = defineTheme({
382
389
  },
383
390
  },
384
391
 
392
+ 'progress-bar-mark': {
393
+ 'placement:fill+variant:accent': {
394
+ backgroundColor: 'var(--color-on-light)',
395
+ },
396
+ 'placement:fill+variant:success': {
397
+ backgroundColor: 'var(--color-on-light)',
398
+ },
399
+ 'placement:fill+variant:warning': {
400
+ backgroundColor: 'var(--color-on-light)',
401
+ },
402
+ 'placement:fill+variant:error': {
403
+ backgroundColor: 'var(--color-on-light)',
404
+ },
405
+ },
406
+
385
407
  // The default muted track is too close to Stone's body surface.
386
408
  'progress-bar-track': {
387
409
  base: {
@@ -400,12 +422,15 @@ export const stoneTheme = defineTheme({
400
422
  'field-status': {
401
423
  'type:success': {
402
424
  backgroundColor: 'var(--color-background-green)',
425
+ color: 'var(--color-text-green)',
403
426
  },
404
427
  'type:warning': {
405
428
  backgroundColor: 'var(--color-background-yellow)',
429
+ color: 'var(--color-text-yellow)',
406
430
  },
407
431
  'type:error': {
408
432
  backgroundColor: 'var(--color-background-red)',
433
+ color: 'var(--color-text-red)',
409
434
  },
410
435
  },
411
436
 
@@ -192,6 +192,18 @@ export const y2kTheme = defineTheme({
192
192
  '--color-on-error': [red.light[30], red.dark[20]],
193
193
  '--color-on-warning': [yellow.light[30], yellow.dark[20]],
194
194
 
195
+ '--color-info': [blue.light[40], blue.dark[75]],
196
+ '--color-info-muted': 'var(--color-background-blue)',
197
+
198
+ '--color-text-info': [blue.light[20], blue.dark[75]],
199
+ '--color-text-success': [green.light[30], green.dark[75]],
200
+ '--color-text-warning': [yellow.light[30], yellow.dark[85]],
201
+ '--color-text-error': [red.light[30], red.dark[75]],
202
+ '--color-on-info-muted': 'var(--color-text-blue)',
203
+ '--color-on-success-muted': 'var(--color-text-green)',
204
+ '--color-on-warning-muted': 'var(--color-text-yellow)',
205
+ '--color-on-error-muted': 'var(--color-text-red)',
206
+
195
207
  // Icon
196
208
  '--color-icon-accent': [neutral.light[15], neutral.dark[95]],
197
209
  '--color-icon-primary': [neutral.light[15], neutral.dark[95]],
@@ -393,28 +405,20 @@ export const y2kTheme = defineTheme({
393
405
  borderRadius: '0px',
394
406
  },
395
407
  'status:info': {
396
- backgroundColor: 'var(--color-background-blue)',
397
- '--color-text-primary': 'var(--color-text-blue)',
398
- '--color-text-secondary': 'var(--color-text-blue)',
399
- '--color-accent': 'var(--color-text-blue)',
408
+ '--color-info-muted': 'var(--color-background-blue)',
409
+ '--color-on-info-muted': 'var(--color-text-blue)',
400
410
  },
401
411
  'status:success': {
402
- backgroundColor: 'var(--color-background-green)',
403
- '--color-text-primary': 'var(--color-text-green)',
404
- '--color-text-secondary': 'var(--color-text-green)',
405
- '--color-success': 'var(--color-text-green)',
412
+ '--color-success-muted': 'var(--color-background-green)',
413
+ '--color-on-success-muted': 'var(--color-text-green)',
406
414
  },
407
415
  'status:warning': {
408
- backgroundColor: 'var(--color-background-yellow)',
409
- '--color-text-primary': 'var(--color-text-yellow)',
410
- '--color-text-secondary': 'var(--color-text-yellow)',
411
- '--color-warning': 'var(--color-text-yellow)',
416
+ '--color-warning-muted': 'var(--color-background-yellow)',
417
+ '--color-on-warning-muted': 'var(--color-text-yellow)',
412
418
  },
413
419
  'status:error': {
414
- backgroundColor: 'var(--color-background-red)',
415
- '--color-text-primary': 'var(--color-text-red)',
416
- '--color-text-secondary': 'var(--color-text-red)',
417
- '--color-error': 'var(--color-text-red)',
420
+ '--color-error-muted': 'var(--color-background-red)',
421
+ '--color-on-error-muted': 'var(--color-text-red)',
418
422
  },
419
423
  },
420
424
 
@@ -91,9 +91,11 @@ export const myTheme = defineTheme({
91
91
 
92
92
  /**
93
93
  * Start from another theme instead of the defaults. Tokens are copied then
94
- * overridden, `components` deep-merge, `icons` shallow-merge — but the scale
95
- * configs below REPLACE the base's rather than merging, because they are
96
- * inputs to a generator, not values.
94
+ * overridden, `components` deep-merge, `icons` shallow-merge — but the
95
+ * typography, radius and color scale configs below REPLACE the base's rather
96
+ * than merging, because they are inputs to a generator, not values. `motion`
97
+ * inherits field by field: `fast`, `medium` and `ratio` regenerate the fast
98
+ * and medium durations, and a `slow` or `easing` left unset keeps the base's.
97
99
  *
98
100
  * Reference: `astryx theme list` (themes you can install and extend).
99
101
  */
@@ -215,7 +217,7 @@ export const myTheme = defineTheme({
215
217
  // --radius-* none · inner · element · container · page · chat · full
216
218
  // --shadow-* low/med/high + inset-{hover,selected,success,warning,error}
217
219
  // --duration-* {fast,medium,slow} × {-min, base, -max}
218
- // --ease-standard
220
+ // --ease-* standard (arriving, state) · exit (leaving)
219
221
  // --font-family-* body · heading · code
220
222
  // --font-size-* 4xs … 5xl
221
223
  // --font-weight-* normal · medium · semibold · bold
@@ -312,10 +314,21 @@ export const myTheme = defineTheme({
312
314
 
313
315
  /**
314
316
  * Swap the artwork behind semantic icon names — every component that asks
315
- * for `check`, `close`, `chevron-down` gets yours.
317
+ * for `check`, `close`, `chevron-down` gets yours. An entry may also be a
318
+ * pure function of `{size, variant}` that picks artwork for the size Icon
319
+ * renders at.
316
320
  * Reference: `astryx docs icons` lists the names.
317
321
  */
318
- // icons: {check: <MyCheck />, close: <MyClose />},
322
+ // icons: {check: <MyCheck />, info: ({size}) => <MyInfo bold={size === 'sm'} />},
323
+
324
+ /**
325
+ * The icon variant names this theme supports, listed once for the whole
326
+ * theme. An icon entry function receives `variant` typed as these names.
327
+ * A theme that sets the list replaces the one it would inherit; omit it to
328
+ * inherit the base's list.
329
+ * Reference: `astryx docs icons`.
330
+ */
331
+ // iconVariants: ['outline', 'filled'],
319
332
 
320
333
  /**
321
334
  * Replace the small components that DRAW control state — the checkbox box,
@@ -141,6 +141,16 @@ export interface CodemodRunResult {
141
141
  generated: boolean;
142
142
  command?: string;
143
143
  }>;
144
+ /**
145
+ * Protected files left for manual review because their own source does not
146
+ * parse, so no change can be proven in them. They do not fail the run.
147
+ */
148
+ declinedCandidates?: Array<{
149
+ file: string;
150
+ codemod: string;
151
+ location?: string;
152
+ reason: string;
153
+ }>;
144
154
  errors: Array<{file: string; codemod: string; error: string}>;
145
155
  }
146
156
 
@@ -31,7 +31,7 @@ export const doc = {
31
31
  type: 'string',
32
32
  description:
33
33
  "Where reports about Core go: `{@command gap-report}` routes a Core report here when no handler is loaded, gapReport handlers receive it as `report.target.issuesUrl`, and `{@command swizzle}` prints it as the feedback link for a Core component. A report or swizzle for an integration's component uses that integration's own issuesUrl, never this one. An absolute URL; a value that is not a URL makes the config invalid.",
34
- default: "'https://github.com/facebook/astryx/issues/new'",
34
+ default: "'https://github.com/meta/astryx/issues/new'",
35
35
  },
36
36
  {
37
37
  name: 'hooks',
@@ -95,6 +95,116 @@ describe('theme build adaptations', () => {
95
95
  );
96
96
  });
97
97
 
98
+ it('emits scoped status aliases in built CSS and preserves child extension parity', async () => {
99
+ const {defineTheme, generateThemeCSS} =
100
+ await import('@astryxdesign/core/theme');
101
+ const project = path.join(tmpDir, 'project');
102
+ const themesDir = path.join(project, 'themes');
103
+ const input = {
104
+ name: 'status-aliases',
105
+ tokens: {
106
+ '--color-info': '#225bff',
107
+ '--color-text-blue': '#203a6c',
108
+ },
109
+ adaptations: {
110
+ rules: [
111
+ {
112
+ when: {contrast: 'more'},
113
+ value: {
114
+ tokens: {'--color-text-success': '#123456'},
115
+ },
116
+ },
117
+ {
118
+ when: {pointer: 'coarse'},
119
+ value: {tokens: {'--color-text-green': '#abcdef'}},
120
+ },
121
+ ],
122
+ },
123
+ onDark: {
124
+ tokens: {'--color-text-blue': '#fefefe'},
125
+ },
126
+ };
127
+ const themeFile = writeTheme(themesDir, input.name, JSON.stringify(input));
128
+
129
+ const result = await build(project, themeFile);
130
+ expect(result.code, result.stderr).toBe(0);
131
+
132
+ const css = fs.readFileSync(
133
+ path.join(themesDir, 'status-aliases.css'),
134
+ 'utf8',
135
+ );
136
+ const mediaAlias = '--color-text-info: var(--color-text-blue);';
137
+ const adaptationAlias = '--color-text-success: var(--color-text-green);';
138
+ const authoredRole = '--color-text-success: #123456;';
139
+ // The authored Info fill is a concrete hue, so theme generation derives
140
+ // its content, text, and pale-fill content (theme-compilation INV17).
141
+ for (const role of ['on-info', 'text-info', 'on-info-muted']) {
142
+ expect(css).toMatch(
143
+ new RegExp(
144
+ `--color-${role}: light-dark\\(#[0-9A-F]{6}, #[0-9A-F]{6}\\);`,
145
+ ),
146
+ );
147
+ }
148
+ // The dark media surface that sets the hue rebinds the text alias.
149
+ expect(css).toContain(mediaAlias);
150
+ expect(css).toContain(adaptationAlias);
151
+ expect(css.split(authoredRole).length - 1).toBeGreaterThanOrEqual(2);
152
+ expect(css.lastIndexOf(authoredRole)).toBeGreaterThan(
153
+ css.lastIndexOf(adaptationAlias),
154
+ );
155
+
156
+ const {statusAliasesTheme: builtTheme} = await import(
157
+ pathToFileURL(path.join(themesDir, 'status-aliases.js')).href
158
+ );
159
+ const source = defineTheme(input);
160
+ const childInput = {
161
+ name: 'status-alias-child',
162
+ tokens: {'--color-text-blue': '#345678'},
163
+ };
164
+ const fromSource = defineTheme({...childInput, extends: source});
165
+ const fromBuilt = defineTheme({...childInput, extends: builtTheme});
166
+ expect(generateThemeCSS(fromBuilt)).toEqual(generateThemeCSS(fromSource));
167
+ });
168
+
169
+ it('derives a complete status set for a minimal theme in built CSS (INV17)', async () => {
170
+ const {defineTheme, generateThemeCSS} =
171
+ await import('@astryxdesign/core/theme');
172
+ const project = path.join(tmpDir, 'project');
173
+ const themesDir = path.join(project, 'themes');
174
+ const input = {
175
+ name: 'status-minimal',
176
+ tokens: {
177
+ '--color-success': '#3FB950',
178
+ '--color-warning': '#D29922',
179
+ '--color-error': '#F85149',
180
+ '--color-info': '#6E40C9',
181
+ },
182
+ };
183
+ const themeFile = writeTheme(themesDir, input.name, JSON.stringify(input));
184
+ const result = await build(project, themeFile);
185
+ expect(result.code, result.stderr).toBe(0);
186
+
187
+ const css = fs.readFileSync(
188
+ path.join(themesDir, 'status-minimal.css'),
189
+ 'utf8',
190
+ );
191
+ for (const status of ['success', 'warning', 'error', 'info']) {
192
+ expect(css).toMatch(
193
+ new RegExp(
194
+ `--color-text-${status}: light-dark\\(#[0-9A-F]{6}, #[0-9A-F]{6}\\);`,
195
+ ),
196
+ );
197
+ expect(css).toContain(
198
+ `--color-icon-${status}: var(--color-text-${status});`,
199
+ );
200
+ }
201
+ // Built and runtime output derive the same values.
202
+ const runtime = generateThemeCSS(defineTheme(input));
203
+ const derived = css.match(/--color-text-warning: [^;]+;/)?.[0];
204
+ expect(derived).toBeDefined();
205
+ expect(JSON.stringify(runtime)).toContain(derived);
206
+ });
207
+
98
208
  it.each([
99
209
  ['defined', writeTheme],
100
210
  ['plain', writePlainTheme],
@@ -0,0 +1,140 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx theme build` outside any project, as a separate process.
5
+ *
6
+ * A theme in a folder with no Core installed (an empty folder, a fresh clone)
7
+ * imports `defineTheme` from Core all the same: the build hands its imports
8
+ * the Core the CLI answers with, as a new project with that Core would build
9
+ * it (spec AST-081 FR3). The CLI runs as its own process, without the
10
+ * `NODE_PATH` a pnpm script sets (it reaches the repository's packages): in
11
+ * the test runner, or with that path, the theme's import would find the
12
+ * repository's Core, which a real run outside a project cannot.
13
+ */
14
+
15
+ import {afterEach, beforeAll, beforeEach, describe, expect, it} from 'vitest';
16
+ import * as fs from 'node:fs';
17
+ import * as os from 'node:os';
18
+ import * as path from 'node:path';
19
+ import {spawnSync} from 'node:child_process';
20
+ import {fileURLToPath} from 'node:url';
21
+ import {ensureCoreBuilt} from './ensure-core-built.mjs';
22
+
23
+ const CLI_BIN = fileURLToPath(new URL('../bin/astryx.mjs', import.meta.url));
24
+ const CORE_DIR = fileURLToPath(new URL('../../../../core', import.meta.url));
25
+
26
+ /** @param {string[]} args @param {string} cwd */
27
+ function runCliProcess(args, cwd) {
28
+ const {NODE_PATH: _repositoryPackages, ...env} = process.env;
29
+ const result = spawnSync(process.execPath, [CLI_BIN, ...args], {
30
+ cwd,
31
+ encoding: 'utf-8',
32
+ timeout: 60_000,
33
+ env,
34
+ });
35
+ if (result.error) throw result.error;
36
+ return result;
37
+ }
38
+
39
+ beforeAll(() => {
40
+ ensureCoreBuilt();
41
+ }, 200_000);
42
+
43
+ let tmpDir;
44
+ beforeEach(() => {
45
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-theme-outside-'));
46
+ });
47
+ afterEach(() => {
48
+ fs.rmSync(tmpDir, {recursive: true, force: true});
49
+ });
50
+
51
+ /**
52
+ * A project beside the empty folder: its own package.json and Core (this
53
+ * repository's, linked), so the same theme builds there through the
54
+ * project's own resolution.
55
+ * @param {string} dir
56
+ */
57
+ function makeProject(dir) {
58
+ fs.mkdirSync(path.join(dir, 'node_modules', '@astryxdesign'), {
59
+ recursive: true,
60
+ });
61
+ fs.writeFileSync(
62
+ path.join(dir, 'package.json'),
63
+ '{"name": "theme-project", "private": true, "dependencies": {"@astryxdesign/core": "*"}}\n',
64
+ );
65
+ fs.symlinkSync(
66
+ CORE_DIR,
67
+ path.join(dir, 'node_modules', '@astryxdesign', 'core'),
68
+ 'junction',
69
+ );
70
+ }
71
+
72
+ describe('theme build outside any project builds a plain-object theme as a project does', () => {
73
+ const themes = {
74
+ typography: `export default {
75
+ name: 'plain-type',
76
+ tokens: {'--color-background': '#123456'},
77
+ typography: {body: {family: 'Helvetica', fallbacks: 'Arial, sans-serif'}},
78
+ };\n`,
79
+ 'local tokens and media surfaces': `export default {
80
+ name: 'plain-local',
81
+ tokens: {'--color-background': '#123456'},
82
+ localTokens: {'--ac-selection-ink': ['#0077b6', '#48cae4']},
83
+ components: {badge: {'variant:info': {backgroundColor: 'var(--ac-selection-ink)'}}},
84
+ onDark: {components: {badge: {'variant:info': {color: 'var(--ac-selection-ink)'}}}},
85
+ };\n`,
86
+ };
87
+ for (const [what, source] of Object.entries(themes)) {
88
+ for (const ext of ['mjs', 'ts']) {
89
+ it(`with ${what}, in a .${ext} file`, () => {
90
+ const name = /name: '([^']+)'/.exec(source)[1];
91
+ const project = path.join(tmpDir, 'project');
92
+ makeProject(project);
93
+ const outside = path.join(tmpDir, 'outside');
94
+ fs.mkdirSync(outside);
95
+ for (const dir of [project, outside]) {
96
+ fs.writeFileSync(path.join(dir, `theme.${ext}`), source);
97
+ const result = runCliProcess(['theme', 'build', `theme.${ext}`], dir);
98
+ expect(result.status, result.stderr + result.stdout).toBe(0);
99
+ }
100
+ expect(fs.readFileSync(path.join(outside, `${name}.css`), 'utf8')).toBe(
101
+ fs.readFileSync(path.join(project, `${name}.css`), 'utf8'),
102
+ );
103
+ });
104
+ }
105
+ }
106
+ });
107
+
108
+ describe('theme build outside any project', () => {
109
+ for (const ext of ['mjs', 'ts']) {
110
+ it(`builds a .${ext} theme that imports defineTheme from Core, with the Core the CLI answers with`, () => {
111
+ fs.writeFileSync(
112
+ path.join(tmpDir, `outside.${ext}`),
113
+ "import {defineTheme} from '@astryxdesign/core/theme';\n" +
114
+ "export default defineTheme({name: 'outside', tokens: {'--color-background': '#123456'}});\n",
115
+ );
116
+ const result = runCliProcess(
117
+ ['theme', 'build', `outside.${ext}`],
118
+ tmpDir,
119
+ );
120
+ expect(result.status, result.stderr + result.stdout).toBe(0);
121
+ expect(
122
+ fs.readFileSync(path.join(tmpDir, 'outside.css'), 'utf8'),
123
+ ).toContain('#123456');
124
+ });
125
+ }
126
+
127
+ for (const ext of ['mjs', 'ts']) {
128
+ it(`still fails a .${ext} module that defines no theme`, () => {
129
+ fs.writeFileSync(
130
+ path.join(tmpDir, `none.${ext}`),
131
+ 'export const notATheme = 42;\n',
132
+ );
133
+ const result = runCliProcess(['theme', 'build', `none.${ext}`], tmpDir);
134
+ expect(result.status).toBe(1);
135
+ expect(result.stderr + result.stdout).toMatch(
136
+ /Could not find a defineTheme\(\) result/,
137
+ );
138
+ });
139
+ }
140
+ });
@@ -155,7 +155,7 @@ describe('swizzle — core feedback routing via config', () => {
155
155
  expect(result.code).toBe(0);
156
156
  const env = JSON.parse(result.stdout);
157
157
  expect(env.data.feedback.issuesUrl).toBe(
158
- 'https://github.com/facebook/astryx/issues/new',
158
+ 'https://github.com/meta/astryx/issues/new',
159
159
  );
160
160
  });
161
161
  });
@@ -108,14 +108,17 @@ export const doc = {
108
108
  ],
109
109
  outsideProject: 'own',
110
110
  exitCodes: [
111
- {code: 0, when: 'success, including complete dry-run previews'},
111
+ {
112
+ code: 0,
113
+ when: 'success, including complete dry-run previews and runs whose only findings are manual migrations',
114
+ },
112
115
  {
113
116
  code: 1,
114
117
  when:
115
118
  'missing or invalid --from, --registry with --list or a migration flag, a --path escape, ' +
116
119
  'no installed @astryxdesign/core (or legacy @xds/core), jscodeshift missing and not installed by --install-deps, ' +
117
120
  'an astryx.config that fails validation and that no pending config codemod repairs, ' +
118
- 'an unreadable or invalid protection declaration, a protected file that still requires a codemod change, ' +
121
+ 'an unreadable or invalid protection declaration, a protected file that still requires a codemod change, a generated file that must be regenerated, ' +
119
122
  'an unknown codemod, a codemod or post-codemod hook failure, or unresolved registry items',
120
123
  },
121
124
  ],
@@ -157,6 +160,13 @@ export const doc = {
157
160
  'it is an installed dependency (such as anything in `node_modules`), is inside `.git`, `.hg`, or `.sl`, is a symbolic link, or is outside the project',
158
161
  ],
159
162
  },
163
+ {
164
+ type: 'prose',
165
+ text:
166
+ 'upgrade does not scan installed dependencies or version-control folders at all, including through a symbolic link: ' +
167
+ 'a symlinked `node_modules`, or a link whose target is inside one or inside a package store such as `.yarn/cache`, is skipped. ' +
168
+ 'Other symbolically linked folders are scanned so a change they need is reported, but nothing is written through them.',
169
+ },
160
170
  {
161
171
  type: 'prose',
162
172
  text:
@@ -194,5 +204,40 @@ export const doc = {
194
204
  '`Command:` line in its header, such as `// Command: pnpm run gen:panel`; upgrade prints it as ' +
195
205
  '`Regenerate with: <command>` and lists it in `commands`.',
196
206
  },
207
+ {
208
+ type: 'prose',
209
+ text:
210
+ 'A protected file a codemod cannot parse, such as a vendored bundle written for another toolchain, cannot need a ' +
211
+ 'change the codemod can prove, and upgrade never writes it. upgrade skips it, lists it under ' +
212
+ '`declinedCandidates` with the parse error and where it occurred, and carries on; on its own it does not fail the run. ' +
213
+ 'If another codemod in the same upgrade still requires a change to that file (the 0.6.0 theme selector migration, for one, ' +
214
+ 'adds a TODO comment above a selector it cannot parse), the file is listed once, under `protectedFiles`, and the run is ' +
215
+ 'incomplete as for any protected file. A file upgrade owns that does not parse still fails the run with ERR_CODEMOD_FAILED.',
216
+ },
217
+ {type: 'heading', level: 3, text: 'Manual migrations and regeneration'},
218
+ {
219
+ type: 'prose',
220
+ text:
221
+ 'Some changes a codemod can find but not make. upgrade lists them in the result, so a script can keep the rest of the run and act on each. ' +
222
+ 'Code a codemod can identify but cannot migrate safely is a manual migration: upgrade lists each file with its line, ' +
223
+ 'the codemod and what to change, finishes the run, and exits 0. With --json they are in `declinedCandidates`, one row per file (each finding in `reason` starts with `manual migration needed (<codemod>):`, and a file with several findings lists them all, joined by `; `), and `complete` stays true. ' +
224
+ 'A generated file that must be rebuilt is listed in `regenerate` with the command that rebuilds it, such as `astryx theme build`: a protected generated file a codemod still needs to change ' +
225
+ '(also in `protectedFiles`), or a generated output a codemod found out of date (also in `protectedFiles`, with the rule that protects it, when the project marks it generated). With --apply, upgrade runs your `hooks.postCodemod` commands and checks again. ' +
226
+ 'If a protected file still needs rebuilding, the run is incomplete exactly as for any protected file: it exits 1 and the result says `complete: false` and `errorCode: "ERR_CODEMOD_PROTECTED"`. ' +
227
+ 'If a file nothing protects still needs rebuilding, no protected file is in the way: the codemod could not make a required change, so it is also in `errors` and the run fails with `ERR_CODEMOD_FAILED`, as described below. ' +
228
+ 'Either way, rebuild it, then run the same upgrade again. ' +
229
+ 'When a codemod also failed, the failure is reported as below, and the receipt it carries still lists `declinedCandidates` and `regenerate`, ' +
230
+ 'unless a protected file to regenerate also remains, in which case the run returns `ERR_CODEMOD_PROTECTED` with the failure in `errors`.',
231
+ },
232
+ {type: 'heading', level: 3, text: 'A failed codemod'},
233
+ {
234
+ type: 'prose',
235
+ text:
236
+ 'When a codemod or a `hooks.postCodemod` command fails, upgrade still makes every other change, exits 1 with ERR_CODEMOD_FAILED, and does not refresh the agent docs. ' +
237
+ 'With --json, the result is the usual error, `{"error": ..., "code": "ERR_CODEMOD_FAILED"}`, plus a `receipt`: the same fields a finished run returns, with `complete: false`, ' +
238
+ 'each failure in `errors`, and every file upgrade changed (or would change) in `modifiedFiles`, so a script can review, keep, or revert them. ' +
239
+ 'An error that stops the run after codemods have written files, such as an astryx.config that fails validation, carries a `receipt` too. ' +
240
+ 'Rerun past a failed codemod with --skip-codemod.',
241
+ },
197
242
  ],
198
243
  };