@astryxdesign/cli 0.7.5-canary.fccd771 → 0.7.5-canary.fd0aba8

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 (115) hide show
  1. package/CHANGELOG.md +3 -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__/runner.symlinks.test.mjs +205 -0
  29. package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
  30. package/assets/codemods/integration-runner.mjs +8 -2
  31. package/assets/codemods/integration-runner.protection.test.mjs +53 -0
  32. package/assets/codemods/outcome.mjs +79 -0
  33. package/assets/codemods/outcome.test.mjs +40 -0
  34. package/assets/codemods/parse.mjs +94 -0
  35. package/assets/codemods/run-codemod.mjs +109 -5
  36. package/assets/codemods/runner.mjs +119 -13
  37. package/assets/codemods/transform-prop.mjs +99 -49
  38. package/assets/codemods/transform-prop.test.mjs +36 -1
  39. package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
  40. package/assets/codemods/transforms/next/index.mjs +11 -1
  41. package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
  42. package/assets/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +1 -1
  43. package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
  44. package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
  45. package/assets/codemods/transforms/v0.1.5/rename-switch-label-spacing-default-to-hug.mjs +1 -1
  46. package/assets/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +1 -1
  47. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +1 -1
  48. package/assets/codemods/transforms/v0.2.0/remove-tablist-orientation.mjs +1 -1
  49. package/assets/codemods/transforms/v0.2.1/migrate-dialog-position-to-logical.mjs +1 -1
  50. package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
  51. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
  52. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +143 -70
  53. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
  54. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
  55. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
  56. package/assets/docs/README.md +13 -13
  57. package/assets/docs/author-a-theme.doc.mjs +5 -1
  58. package/assets/docs/getting-started.doc.mjs +5 -5
  59. package/assets/docs/icons.doc.mjs +82 -1
  60. package/assets/docs/motion.doc.mjs +1 -1
  61. package/assets/docs/theme.doc.dense.mjs +8 -0
  62. package/assets/docs/theme.doc.mjs +16 -0
  63. package/assets/docs/theme.doc.zh.mjs +11 -0
  64. package/assets/docs/tree/i18n-library-integration.doc.mjs +1 -1
  65. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  66. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  67. package/assets/docs/tree/tokens-color.doc.mjs +145 -1
  68. package/assets/docs/tree/tokens-ease.doc.mjs +4 -0
  69. package/assets/docs/tree/tokens.doc.mjs +1 -1
  70. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
  71. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
  72. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
  73. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
  74. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
  75. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
  76. package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
  77. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
  78. package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
  79. package/assets/templates/pages/library/page.tsx +1 -2
  80. package/assets/templates/pages/table-comparison/page.tsx +12 -3
  81. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
  82. package/assets/templates/themes/butter/butterTheme.ts +47 -44
  83. package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
  84. package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
  85. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
  86. package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
  87. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
  88. package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
  89. package/assets/templates/themes/stone/stoneTheme.ts +46 -21
  90. package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
  91. package/assets/theme.template.ts +19 -6
  92. package/authoring/codemod/type.ts +10 -0
  93. package/authoring/config/config.doc.mjs +1 -1
  94. package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
  95. package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
  96. package/clients/cli/commands/swizzle.routing.test.mjs +1 -1
  97. package/clients/cli/commands/upgrade.doc.mjs +47 -2
  98. package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
  99. package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
  100. package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
  101. package/clients/cli/commands/upgrade.mjs +9 -2
  102. package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
  103. package/foundation/agent-docs/agent-docs.mjs +1 -0
  104. package/foundation/agent-docs/agent-docs.test.mjs +5 -0
  105. package/foundation/config/project.d.mts +1 -1
  106. package/foundation/config/project.mjs +1 -1
  107. package/foundation/debug/redact.test.mjs +1 -1
  108. package/foundation/doc-compiler/doc-loads.test.mjs +2 -6
  109. package/foundation/response/base.d.ts +7 -0
  110. package/foundation/response/error-codes.doc.mjs +3 -2
  111. package/foundation/response/error-codes.mjs +1 -1
  112. package/foundation/response/json.d.mts +10 -3
  113. package/foundation/response/json.mjs +16 -4
  114. package/foundation/response/response-types.doc.mjs +1 -1
  115. package/package.json +13 -12
@@ -5,19 +5,34 @@
5
5
  *
6
6
  * Static keys directly inside a theme's `components` object move to their
7
7
  * canonical target. A theme is a `defineTheme()` call imported from Astryx, an
8
- * object typed as an Astryx theme (annotation, `as`, or `satisfies`), or a
9
- * direct theme object with a static `name` whose component entries are style
10
- * objects. CSS selectors move the same target classes, keep the owner scope of
11
- * the per-component clear-icon aliases, and replace target-qualified bare
12
- * prop/state classes with reflected `data-*` selectors using the final 0.6
13
- * runtime contract. A known bare class that cannot be classified for its target
14
- * gets a TODO. Dynamic theme keys, unqualified classes, declarations, comments,
8
+ * object typed as an Astryx theme (annotation, `as`, or `satisfies`), or the
9
+ * direct theme object a same-stem theme descriptor (`<stem>.doc.mjs`) declares:
10
+ * the top-level binding exported as `<stem>`, with a static `name` and
11
+ * component entries that are style objects. Shape alone is not proof: a
12
+ * look-alike object anywhere else, including another object in the same theme
13
+ * source, is left unchanged. CSS selectors move the same target classes, keep
14
+ * the owner scope of the per-component clear-icon aliases, and replace
15
+ * target-qualified bare prop/state classes with reflected `data-*` selectors
16
+ * using the final 0.6 runtime contract. A known bare class that cannot be
17
+ * classified for its target gets a TODO. Dynamic theme keys, unqualified classes, declarations, comments,
15
18
  * and strings containing CSS are left for manual review.
16
19
  */
17
20
 
21
+ import * as fs from 'node:fs';
18
22
  import path from 'node:path';
19
23
  import postcss from 'postcss';
20
24
  import selectorParser from 'postcss-selector-parser';
25
+ import {readThemeDescriptorValue} from '../../../../foundation/discovery/theme-discovery.mjs';
26
+ import {
27
+ importedComponents,
28
+ resolveImportedComponent,
29
+ } from '../../transform-prop.mjs';
30
+ import {
31
+ isCodemodParseError,
32
+ markParseError,
33
+ parseCss,
34
+ processSelector,
35
+ } from '../../parse.mjs';
21
36
  import {migrateAstryxThemeSelectors} from '../v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs';
22
37
  import {
23
38
  V06_THEME_SELECTOR_DYNAMIC_AXES,
@@ -195,7 +210,7 @@ function ownerScope(owner) {
195
210
  function unclassifiedBareClasses(selectorText) {
196
211
  /** @type {Set<string>} */
197
212
  const found = new Set();
198
- selectorParser(selectors => {
213
+ processSelector(selectorText, selectors => {
199
214
  selectors.walk((/** @type {any} */ node) => {
200
215
  if (node.type !== 'selector') return;
201
216
  /** @type {any[][]} */
@@ -223,19 +238,23 @@ function unclassifiedBareClasses(selectorText) {
223
238
  }
224
239
  }
225
240
  });
226
- }).processSync(selectorText, {lossless: true});
241
+ });
227
242
  return [...found].sort();
228
243
  }
229
244
 
230
- /** @param {string} selector */
245
+ /** @param {string | import('postcss').Rule} selector selector text, or the rule that holds it */
231
246
  function finishSelectorText(selector) {
232
- return selectorParser(selectors => {
247
+ return processSelector(selector, selectors => {
233
248
  selectors.each(finishSelectorMigration);
234
- }).processSync(selector, {lossless: true});
249
+ });
235
250
  }
236
251
 
237
- /** @param {string} params */
238
- function finishScopeParams(params) {
252
+ /**
253
+ * Migrate each parenthesized selector group of an `@scope` prelude.
254
+ * @param {string} params
255
+ * @param {(selector: string, start: number) => string} [finish] migrates one group; `start` is its offset in `params`
256
+ */
257
+ function finishScopeParams(params, finish = finishSelectorText) {
239
258
  let result = '';
240
259
  let last = 0;
241
260
  let depth = 0;
@@ -272,7 +291,7 @@ function finishScopeParams(params) {
272
291
  if (char === ')' && depth > 0) {
273
292
  depth--;
274
293
  if (depth === 0 && groupStart >= 0) {
275
- result += finishSelectorText(params.slice(groupStart, index));
294
+ result += finish(params.slice(groupStart, index), groupStart);
276
295
  result += ')';
277
296
  last = index + 1;
278
297
  groupStart = -1;
@@ -284,15 +303,39 @@ function finishScopeParams(params) {
284
303
 
285
304
  /** @param {string} source @param {string} from */
286
305
  function migrateCss(source, from) {
306
+ // Parse every selector of the stylesheet as written first, so one the
307
+ // selector parser rejects is reported at its line and column in the file,
308
+ // not in the migrated text below.
309
+ const original = parseCss(source, {from});
310
+ original.walkRules(rule => {
311
+ processSelector(rule, () => {});
312
+ });
313
+ original.walkAtRules('scope', atRule => {
314
+ const offset =
315
+ `@${atRule.name}`.length + (atRule.raws.afterName ?? '').length;
316
+ finishScopeParams(atRule.params, (selector, start) => {
317
+ try {
318
+ processSelector(selector, () => {});
319
+ } catch (err) {
320
+ if (!isCodemodParseError(err)) throw err;
321
+ throw markParseError(
322
+ atRule.error(/** @type {Error} */ (err).message, {
323
+ index: offset + start,
324
+ }),
325
+ );
326
+ }
327
+ return selector;
328
+ });
329
+ });
287
330
  const migrated = migrateAstryxThemeSelectors(source, from, SELECTOR_DATA);
288
- const root = postcss.parse(migrated, {from});
331
+ const root = parseCss(migrated, {from});
289
332
  /** @type {Set<string>} */
290
333
  const existingComments = new Set();
291
334
  root.walkComments(comment => {
292
335
  existingComments.add(comment.text.trim());
293
336
  });
294
337
  root.walkRules(rule => {
295
- rule.selector = finishSelectorText(rule.selector);
338
+ rule.selector = finishSelectorText(rule);
296
339
  const tokens = unclassifiedBareClasses(rule.selector);
297
340
  if (tokens.length === 0) return;
298
341
  const list = tokens.map(token => `.${token}`).join(', ');
@@ -338,15 +381,88 @@ const TS_WRAPPERS = new Set([
338
381
  ]);
339
382
 
340
383
  /**
341
- * Local names that refer to Astryx's `defineTheme`, its theme types, or an
342
- * Astryx namespace import.
343
- * @param {any} root @param {any} j
384
+ * The export name a same-stem theme descriptor beside this file declares
385
+ * (`brandTheme` for `brandTheme.ts` beside `brandTheme.doc.mjs`), or null. The
386
+ * descriptor is read statically, never executed; an unreadable or non-theme
387
+ * descriptor is not proof.
388
+ * @param {string} filePath
389
+ * @returns {string | null}
390
+ */
391
+ function describedThemeExportName(filePath) {
392
+ const stem = path.basename(filePath, path.extname(filePath));
393
+ const docPath = path.join(path.dirname(filePath), `${stem}.doc.mjs`);
394
+ if (!fs.existsSync(docPath)) return null;
395
+ try {
396
+ return readThemeDescriptorValue(docPath, `Theme descriptor ${docPath}`)
397
+ .type === 'theme'
398
+ ? stem
399
+ : null;
400
+ } catch {
401
+ return null;
402
+ }
403
+ }
404
+
405
+ /**
406
+ * Top-level local names this module exports under `exportName`: an exported
407
+ * declaration of that name, or a source-less `export {local as exportName}`.
408
+ * @param {any} root @param {any} j @param {string} exportName
409
+ */
410
+ function localNamesExportedAs(root, j, exportName) {
411
+ /** @type {Set<string>} */
412
+ const locals = new Set();
413
+ root
414
+ .find(j.ExportNamedDeclaration)
415
+ .forEach((/** @type {any} */ exportPath) => {
416
+ const node = exportPath.node;
417
+ if (node.exportKind === 'type' || node.source) return;
418
+ for (const declarator of node.declaration?.declarations ?? []) {
419
+ if (declarator.id?.name === exportName) locals.add(exportName);
420
+ }
421
+ for (const specifier of node.specifiers ?? []) {
422
+ const exported = specifier.exported?.name ?? specifier.exported?.value;
423
+ const local = specifier.local?.name ?? specifier.local?.value;
424
+ if (
425
+ specifier.exportKind !== 'type' &&
426
+ exported === exportName &&
427
+ typeof local === 'string'
428
+ ) {
429
+ locals.add(local);
430
+ }
431
+ }
432
+ });
433
+ return locals;
434
+ }
435
+
436
+ /**
437
+ * Astryx's `defineTheme` imports (resolved at each call site, so a shadowing
438
+ * parameter or local never counts), its theme types, an Astryx namespace
439
+ * import, and the binding a theme descriptor declares.
440
+ * @param {any} root @param {any} j @param {string} filePath
344
441
  */
345
- function astryxThemeBindings(root, j) {
442
+ function astryxThemeBindings(root, j, filePath) {
443
+ /** @type {Set<string> | undefined} */
444
+ let describedLocals;
346
445
  const bindings = {
347
- defineTheme: new Set(),
446
+ defineTheme: importedComponents(root, j, {
447
+ matchesImport: source => ASTRYX_MODULE.test(source),
448
+ components: new Map([['defineTheme', new Set()]]),
449
+ }),
348
450
  themeTypes: new Set(),
349
451
  namespaces: new Set(),
452
+ /**
453
+ * Top-level locals exported under the descriptor's name. Read lazily:
454
+ * only a direct theme-shaped object needs the descriptor.
455
+ * @returns {Set<string>}
456
+ */
457
+ describedThemeLocals() {
458
+ if (describedLocals == null) {
459
+ const exportName = describedThemeExportName(filePath);
460
+ describedLocals = exportName
461
+ ? localNamesExportedAs(root, j, exportName)
462
+ : new Set();
463
+ }
464
+ return describedLocals;
465
+ },
350
466
  };
351
467
  root.find(j.ImportDeclaration).forEach((/** @type {any} */ importPath) => {
352
468
  const source = importPath.node.source?.value;
@@ -358,7 +474,6 @@ function astryxThemeBindings(root, j) {
358
474
  bindings.namespaces.add(local);
359
475
  } else if (specifier.type === 'ImportSpecifier') {
360
476
  const imported = specifier.imported?.name ?? specifier.imported?.value;
361
- if (imported === 'defineTheme') bindings.defineTheme.add(local);
362
477
  if (THEME_TYPE_NAMES.has(imported)) bindings.themeTypes.add(local);
363
478
  }
364
479
  }
@@ -379,20 +494,80 @@ function namesBinding(name, locals, namespaces, members) {
379
494
  );
380
495
  }
381
496
 
382
- /** @param {any} typeNode @param {ReturnType<typeof astryxThemeBindings>} bindings */
383
- function isAstryxThemeType(typeNode, bindings) {
497
+ /** @param {any} typeNode @param {any} usePath @param {ReturnType<typeof astryxThemeBindings>} bindings */
498
+ function isAstryxThemeType(typeNode, usePath, bindings) {
384
499
  const node = typeNode?.typeAnnotation ?? typeNode;
385
- return (
386
- node?.type === 'TSTypeReference' &&
387
- namesBinding(
500
+ if (
501
+ node?.type !== 'TSTypeReference' ||
502
+ !namesBinding(
388
503
  node.typeName,
389
504
  bindings.themeTypes,
390
505
  bindings.namespaces,
391
506
  THEME_TYPE_NAMES,
392
507
  )
508
+ ) {
509
+ return false;
510
+ }
511
+ const root =
512
+ node.typeName.type === 'Identifier' ? node.typeName : node.typeName.left;
513
+ return isModuleTypeBinding(usePath, root.name);
514
+ }
515
+
516
+ /** @param {any} statement @param {string} name */
517
+ function statementDeclares(statement, name) {
518
+ const node =
519
+ statement?.type === 'ExportNamedDeclaration' ||
520
+ statement?.type === 'ExportDefaultDeclaration'
521
+ ? statement.declaration
522
+ : statement;
523
+ if (node?.id?.type === 'Identifier' && node.id.name === name) return true;
524
+ return (node?.declarations ?? []).some(
525
+ (/** @type {any} */ declarator) =>
526
+ declarator.id?.type === 'Identifier' && declarator.id.name === name,
393
527
  );
394
528
  }
395
529
 
530
+ /**
531
+ * True when a type-position `name` at `path` can only mean the module-scope
532
+ * import: no enclosing type parameter, parameter, or block-level declaration
533
+ * (type alias, interface, enum, class, namespace, function, or variable)
534
+ * reuses the name. Anything this cannot rule out counts as shadowed.
535
+ * @param {any} path @param {string} name
536
+ */
537
+ function isModuleTypeBinding(path, name) {
538
+ const valueScope = path.scope?.lookup(name);
539
+ if (valueScope != null && valueScope.path.node.type !== 'Program') {
540
+ return false;
541
+ }
542
+ for (let current = path; current != null; current = current.parent) {
543
+ const node = current.node;
544
+ if (node.type === 'Program') return true;
545
+ const typeParameters = node.typeParameters?.params ?? [];
546
+ if (
547
+ typeParameters.some(
548
+ (/** @type {any} */ parameter) =>
549
+ (parameter.name?.name ?? parameter.name) === name,
550
+ )
551
+ ) {
552
+ return false;
553
+ }
554
+ const statements =
555
+ node.type === 'SwitchCase'
556
+ ? node.consequent
557
+ : node.type !== 'ClassBody' && Array.isArray(node.body)
558
+ ? node.body
559
+ : [];
560
+ if (
561
+ statements.some((/** @type {any} */ statement) =>
562
+ statementDeclares(statement, name),
563
+ )
564
+ ) {
565
+ return false;
566
+ }
567
+ }
568
+ return false;
569
+ }
570
+
396
571
  /**
397
572
  * True for a theme object whose shape alone identifies it: a static string
398
573
  * `name` beside a `components` map whose entries are all style objects.
@@ -426,16 +601,45 @@ function isDirectThemeObject(node) {
426
601
  );
427
602
  }
428
603
 
604
+ /**
605
+ * True when this object literal initializes the top-level binding that the
606
+ * file's theme descriptor declares, directly or through TypeScript wrappers.
607
+ * @param {any} objectPath @param {ReturnType<typeof astryxThemeBindings>} bindings
608
+ */
609
+ function isDescribedThemeBinding(objectPath, bindings) {
610
+ let parent = objectPath.parent;
611
+ while (parent != null && TS_WRAPPERS.has(parent.node.type)) {
612
+ parent = parent.parent;
613
+ }
614
+ const declarator = parent?.node;
615
+ if (
616
+ declarator?.type !== 'VariableDeclarator' ||
617
+ declarator.id?.type !== 'Identifier'
618
+ ) {
619
+ return false;
620
+ }
621
+ const declaration = parent.parent;
622
+ const container = declaration?.parent?.node;
623
+ const topLevel =
624
+ container?.type === 'Program' ||
625
+ (container?.type === 'ExportNamedDeclaration' &&
626
+ declaration.parent.parent?.node.type === 'Program');
627
+ return topLevel && bindings.describedThemeLocals().has(declarator.id.name);
628
+ }
629
+
429
630
  /**
430
631
  * True when this object literal is an Astryx theme: the argument of an
431
- * imported `defineTheme()`, typed as an Astryx theme, or a direct theme object.
632
+ * imported `defineTheme()`, typed as an Astryx theme, or the direct theme
633
+ * object a theme descriptor declares.
432
634
  * @param {any} objectPath @param {ReturnType<typeof astryxThemeBindings>} bindings
433
635
  */
434
636
  function isThemeRoot(objectPath, bindings) {
435
637
  let child = objectPath;
436
638
  let parent = objectPath.parent;
437
639
  while (parent != null && TS_WRAPPERS.has(parent.node.type)) {
438
- if (isAstryxThemeType(parent.node.typeAnnotation, bindings)) return true;
640
+ if (isAstryxThemeType(parent.node.typeAnnotation, parent, bindings)) {
641
+ return true;
642
+ }
439
643
  child = parent;
440
644
  parent = parent.parent;
441
645
  }
@@ -443,22 +647,20 @@ function isThemeRoot(objectPath, bindings) {
443
647
  if (
444
648
  node?.type === 'CallExpression' &&
445
649
  node.arguments?.[0] === child.node &&
446
- namesBinding(
447
- node.callee,
448
- bindings.defineTheme,
449
- bindings.namespaces,
450
- new Set(['defineTheme']),
451
- )
650
+ resolveImportedComponent(node.callee, parent, bindings.defineTheme)
452
651
  ) {
453
652
  return true;
454
653
  }
455
654
  if (
456
655
  node?.type === 'VariableDeclarator' &&
457
- isAstryxThemeType(node.id?.typeAnnotation, bindings)
656
+ isAstryxThemeType(node.id?.typeAnnotation, parent, bindings)
458
657
  ) {
459
658
  return true;
460
659
  }
461
- return isDirectThemeObject(objectPath.node);
660
+ return (
661
+ isDirectThemeObject(objectPath.node) &&
662
+ isDescribedThemeBinding(objectPath, bindings)
663
+ );
462
664
  }
463
665
 
464
666
  /**
@@ -567,10 +769,10 @@ function addScopeTodo(property, oldKey, owner, j) {
567
769
  ];
568
770
  }
569
771
 
570
- /** @param {string} source @param {any} j */
571
- function migrateStaticThemeKeys(source, j) {
772
+ /** @param {string} source @param {string} filePath @param {any} j */
773
+ function migrateStaticThemeKeys(source, filePath, j) {
572
774
  const root = j(source);
573
- const bindings = astryxThemeBindings(root, j);
775
+ const bindings = astryxThemeBindings(root, j, filePath);
574
776
  let changed = false;
575
777
 
576
778
  root.find(j.ObjectExpression).forEach((/** @type {any} */ objectPath) => {
@@ -620,5 +822,5 @@ export default function migrateDeprecatedThemeSurface(file, api) {
620
822
  const result = migrateCss(file.source, file.path);
621
823
  return result === file.source ? undefined : result;
622
824
  }
623
- return migrateStaticThemeKeys(file.source, api.jscodeshift);
825
+ return migrateStaticThemeKeys(file.source, file.path, api.jscodeshift);
624
826
  }
@@ -1,101 +1,46 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Report data-token consumers that need an ownership migration.
4
+ * @file Reject stale generated theme CSS that still owns data-token defaults.
5
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
6
+ * @input Generated theme CSS
7
+ * @output No rewritten source; a regeneration report (`RegenerationRequired`,
8
+ * with `astryx theme build`) for a generated theme stylesheet that still
9
+ * declares data-color defaults at `:root`
10
+ * @position Next-release upgrade validation for spec:AST-066 FR19
11
+ *
12
+ * Raw `var(--color-data-*)` uses are not checked: prebuilt
13
+ * `@astryxdesign/core/astryx.css` and the `@astryxdesign/build` PostCSS
14
+ * integration define all 56 defaults, and other source builds read data
15
+ * colors through `dataVars` (spec:AST-066 FR3/FR4).
11
16
  */
12
17
 
13
18
  import * as path from 'node:path';
19
+ import {RegenerationRequired} from '../../outcome.mjs';
14
20
 
15
21
  export const meta = {
16
22
  title: 'Validate data-token ownership',
17
23
  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'],
24
+ 'Reports generated theme CSS that still emits the canonical data-color defaults at :root, so it can be rebuilt with `astryx theme build`.',
25
+ fileExtensions: ['.css'],
20
26
  };
21
27
 
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
28
  const GENERATED_THEME_HEADER = '@generated by `astryx theme build`';
26
29
  const ROOT_DATA_DECLARATION = /:root\s*\{[^}]*--color-data-/su;
27
30
 
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
31
  /**
46
32
  * @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
47
- * @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
48
33
  * @returns {undefined}
49
34
  */
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 come from source-compiled dataVars consumers or @astryxdesign/core/astryx.css in prebuilt mode.',
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 an availability check: load @astryxdesign/core/astryx.css in prebuilt mode, ensure a source-compiled dataVars consumer retains the group, or add an explicit fallback. CSS-capable code 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 and, in prebuilt mode, loads @astryxdesign/core/astryx.css; Canvas and other non-CSS APIs use resolveThemeToken() or useTheme().token().`,
35
+ export default function validateDataTokenOwnership(file) {
36
+ if (
37
+ path.extname(file.path) === '.css' &&
38
+ file.source.includes(GENERATED_THEME_HEADER) &&
39
+ ROOT_DATA_DECLARATION.test(file.source)
40
+ ) {
41
+ throw new RegenerationRequired(
42
+ 'This generated theme CSS still emits canonical data defaults at :root. Rebuild it with `astryx theme build`; defaults come from @astryxdesign/core/astryx.css in prebuilt mode, and in a source build from the @astryxdesign/build PostCSS integration or dataVars imports.',
43
+ {commands: ['astryx theme build']},
99
44
  );
100
45
  }
101
46
  return undefined;
@@ -32,22 +32,22 @@ A public authoring-quality rubric is also caller-facing when it helps someone ev
32
32
 
33
33
  ## Where the rest goes
34
34
 
35
- The material is usually good; the finding is placement, not quality. It goes in the [wiki](https://github.com/facebook/astryx/wiki) — **as a section on the page that already covers it, not a new page.** The wiki is at nearly 60 pages, several of them overlapping, because every stray section got its own.
35
+ The material is usually good; the finding is placement, not quality. It goes in the [wiki](https://github.com/meta/astryx/wiki) — **as a section on the page that already covers it, not a new page.** The wiki is at nearly 60 pages, several of them overlapping, because every stray section got its own.
36
36
 
37
37
  | what you wrote | where it goes |
38
38
  | --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
39
- | how a component is graded — checks, scoring | [Component-Audit-Rubric](https://github.com/facebook/astryx/wiki/Component-Audit-Rubric) |
40
- | lab → core promotion, what a component must satisfy | [Component-Lifecycle](https://github.com/facebook/astryx/wiki/Component-Lifecycle) |
41
- | how to build a new component | [Component-Authoring-Guide](https://github.com/facebook/astryx/wiki/Component-Authoring-Guide), [Creating-New-Components](https://github.com/facebook/astryx/wiki/Creating-New-Components) |
42
- | what a component must be hardened against | [Component-Hardening-Protocol](https://github.com/facebook/astryx/wiki/Component-Hardening-Protocol), [Hardening-Audit-Guide](https://github.com/facebook/astryx/wiki/Hardening-Audit-Guide) |
43
- | a11y requirements as checks we run | [Accessibility-Checklist](https://github.com/facebook/astryx/wiki/Accessibility-Checklist) |
44
- | how the system is put together | [System-Architecture](https://github.com/facebook/astryx/wiki/System-Architecture), [Theming-Infrastructure](https://github.com/facebook/astryx/wiki/Theming-Infrastructure) |
45
- | API naming and shape decisions | [API-Conventions](https://github.com/facebook/astryx/wiki/API-Conventions), [API-Arbitration](https://github.com/facebook/astryx/wiki/API-Arbitration) |
46
- | contributor workflow, PR process | [Contributing](https://github.com/facebook/astryx/wiki/Contributing), [Contributing-with-AI-Assistants](https://github.com/facebook/astryx/wiki/Contributing-with-AI-Assistants) |
47
- | release mechanics | [Release-Process](https://github.com/facebook/astryx/wiki/Release-Process) |
48
- | what a nightly agent role does | the Night-Watch pages, from [Night-Watch-Overview](https://github.com/facebook/astryx/wiki/Night-Watch-Overview) |
49
-
50
- **Fits no row?** It is still not caller-facing. Default it to [Contributing](https://github.com/facebook/astryx/wiki/Contributing), or `CONTRIBUTING.md` when it is a step someone follows with the repo cloned. Never default it back to this directory.
39
+ | how a component is graded — checks, scoring | [Component-Audit-Rubric](https://github.com/meta/astryx/wiki/Component-Audit-Rubric) |
40
+ | lab → core promotion, what a component must satisfy | [Component-Lifecycle](https://github.com/meta/astryx/wiki/Component-Lifecycle) |
41
+ | how to build a new component | [Component-Authoring-Guide](https://github.com/meta/astryx/wiki/Component-Authoring-Guide), [Creating-New-Components](https://github.com/meta/astryx/wiki/Creating-New-Components) |
42
+ | what a component must be hardened against | [Component-Hardening-Protocol](https://github.com/meta/astryx/wiki/Component-Hardening-Protocol), [Hardening-Audit-Guide](https://github.com/meta/astryx/wiki/Hardening-Audit-Guide) |
43
+ | a11y requirements as checks we run | [Accessibility-Checklist](https://github.com/meta/astryx/wiki/Accessibility-Checklist) |
44
+ | how the system is put together | [System-Architecture](https://github.com/meta/astryx/wiki/System-Architecture), [Theming-Infrastructure](https://github.com/meta/astryx/wiki/Theming-Infrastructure) |
45
+ | API naming and shape decisions | [API-Conventions](https://github.com/meta/astryx/wiki/API-Conventions), [API-Arbitration](https://github.com/meta/astryx/wiki/API-Arbitration) |
46
+ | contributor workflow, PR process | [Contributing](https://github.com/meta/astryx/wiki/Contributing), [Contributing-with-AI-Assistants](https://github.com/meta/astryx/wiki/Contributing-with-AI-Assistants) |
47
+ | release mechanics | [Release-Process](https://github.com/meta/astryx/wiki/Release-Process) |
48
+ | what a nightly agent role does | the Night-Watch pages, from [Night-Watch-Overview](https://github.com/meta/astryx/wiki/Night-Watch-Overview) |
49
+
50
+ **Fits no row?** It is still not caller-facing. Default it to [Contributing](https://github.com/meta/astryx/wiki/Contributing), or `CONTRIBUTING.md` when it is a step someone follows with the repo cloned. Never default it back to this directory.
51
51
 
52
52
  Worked example: a responsive-and-interaction readiness rubric is grading criteria → **Component-Audit-Rubric**, or **Component-Lifecycle** if it is a promotion gate.
53
53
 
@@ -55,9 +55,11 @@ export const docs = {
55
55
  ['tokens', 'Base tokens are copied first, then child tokens override on top.'],
56
56
  ['components', 'Deep-merged: child component rules override matching keys from the base.'],
57
57
  ['icons', 'Shallow-merged: child icons override matching names from the base.'],
58
+ ['iconVariants', 'Replaced, never merged: a child that sets iconVariants replaces the base list; a child that omits it inherits the list.'],
58
59
  ['indicators', 'Shallow-merged: child indicators override matching names from the base.'],
59
60
  ['onDark, onLight', "Deep-merged per surface: the base's resolved surface first, then the child's overrides."],
60
- ['typography, motion, radius, color', 'Child config replaces base entirely (these are scale inputs, not additive).'],
61
+ ['motion', "Field by field: the child's `fast`, `medium` and `ratio` regenerate the fast and medium duration tokens; `slow` and `easing` left unset keep the base theme's tokens, so an inherited slow band stays at the base's ratio."],
62
+ ['typography, radius, color', 'Child config replaces base entirely (these are scale inputs, not additive).'],
61
63
  ['adaptations', 'Width-breakpoint overrides merge by fixed name. Inherited ordered rules keep their relative order; child rules append and re-resolve against the child root axes.'],
62
64
  ]},
63
65
  {type: 'prose', text: "Inheritance is resolved when the theme is defined, so an extended theme is flat: `{@command theme build}` emits one self-contained stylesheet holding everything the child inherited, and the base theme's CSS does not need to be loaded next to it. A base that is not a theme (most often an import that missed) throws when `defineTheme` runs, rather than producing a theme that silently inherits nothing."},
@@ -134,6 +136,8 @@ export const docs = {
134
136
  {type: 'prose', text: 'In the example above, the generated theme imports `./icons.mjs` from `dist`. If the second command is skipped, `theme build` can still succeed, but loading or bundling the generated module fails because `dist/icons.mjs` is missing. `--icons-specifier` changes the emitted import; it does not create or verify the target file. Match the specifier to a module that resolves from the generated JS file.'},
135
137
  {type: 'prose', text: 'Without `--icons-specifier`, the detected source import specifier is emitted unchanged. In the default flow without `--out`, a bundler can resolve an extensionless `./icons` to the neighboring `icons.tsx` source, but Node ESM does not perform that lookup and reports `ERR_MODULE_NOT_FOUND`. Moving the output with `--out` also changes where relative imports resolve from.'},
136
138
  {type: 'prose', text: 'Keep `react` and the icon library external so the registry does not bundle its own copies of those dependencies.'},
139
+ {type: 'prose', text: "A registry entry can be a function of `{size, variant}`. The built theme keeps the function, so `Icon` asks it for the size and variant it renders, as the runtime theme does, including for entries inherited from a built or package theme. The built theme's `icons` field and the registry its module re-exports are React nodes, with each function read at size `md`. A function written in the theme file itself cannot be carried, so the build fails; move it into the registry module."},
140
+ {type: 'prose', text: "A theme that lists `iconVariants` also writes an `IconVariantMap` augmentation into `<theme>.variants.d.ts`, so `Icon`'s `variant` accepts those names wherever the theme's types load. Its declaration carries the list too, so a theme that extends the built theme types `variant` in its icon entries by that list."},
137
141
  ],
138
142
  },
139
143
  {
@@ -193,22 +193,22 @@ const overrides = stylex.create({
193
193
  [
194
194
  'Next.js',
195
195
  'Next.js + theme CSS',
196
- '[apps/example-nextjs](https://github.com/facebook/astryx/tree/main/apps/example-nextjs)',
196
+ '[apps/example-nextjs](https://github.com/meta/astryx/tree/main/apps/example-nextjs)',
197
197
  ],
198
198
  [
199
199
  'Next.js + StyleX',
200
200
  'Next.js + StyleX for custom styles',
201
- '[apps/example-nextjs-stylex](https://github.com/facebook/astryx/tree/main/apps/example-nextjs-stylex)',
201
+ '[apps/example-nextjs-stylex](https://github.com/meta/astryx/tree/main/apps/example-nextjs-stylex)',
202
202
  ],
203
203
  [
204
204
  'Next.js + Tailwind',
205
205
  'Next.js + Tailwind bridge',
206
- '[apps/example-nextjs-tailwind](https://github.com/facebook/astryx/tree/main/apps/example-nextjs-tailwind)',
206
+ '[apps/example-nextjs-tailwind](https://github.com/meta/astryx/tree/main/apps/example-nextjs-tailwind)',
207
207
  ],
208
208
  [
209
209
  'Vite + Tailwind',
210
210
  'Vite + Tailwind bridge',
211
- '[apps/example-vite-tailwind](https://github.com/facebook/astryx/tree/main/apps/example-vite-tailwind)',
211
+ '[apps/example-vite-tailwind](https://github.com/meta/astryx/tree/main/apps/example-vite-tailwind)',
212
212
  ],
213
213
  ],
214
214
  },
@@ -216,7 +216,7 @@ const overrides = stylex.create({
216
216
  type: 'code',
217
217
  lang: 'bash',
218
218
  label: 'Clone and run an example',
219
- code: `git clone https://github.com/facebook/astryx.git
219
+ code: `git clone https://github.com/meta/astryx.git
220
220
  cd astryx/apps/example-nextjs
221
221
  {@pm install}
222
222
  {@pm run dev}`,