@astryxdesign/cli 0.7.0-canary.9eb7c76 → 0.7.0-canary.c700d4c

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 (147) hide show
  1. package/README.md +79 -83
  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/gap-report/gap-report.doc.mjs +1 -1
  8. package/api/gap-report/gap-report.mjs +15 -0
  9. package/api/index.d.mts +0 -2
  10. package/api/index.mjs +0 -2
  11. package/api/init/init.mjs +22 -0
  12. package/api/integration/pack-check.test.mjs +8 -0
  13. package/api/integration/validate-integration.d.mts +4 -0
  14. package/api/integration/validate-integration.mjs +5 -2
  15. package/api/integration/validateIntegration.doc.mjs +1 -1
  16. package/api/json/index.ts +0 -1
  17. package/api/template/list/list.mjs +23 -2
  18. package/api/template/list/list.test.mjs +52 -0
  19. package/api/template/template-integration.test.mjs +37 -100
  20. package/api/template/template.doc.mjs +8 -3
  21. package/api/template/template.mjs +45 -0
  22. package/api/template/template.type.mjs +1 -1
  23. package/api/theme/build/build.d.mts +0 -1
  24. package/api/theme/build/build.mjs +4 -29
  25. package/api/theme/build/family.mjs +1 -1
  26. package/api/upgrade/upgrade.doc.mjs +1 -1
  27. package/api/upgrade/upgrade.mjs +19 -0
  28. package/assets/codemods/transforms/next/__tests__/migrate-field-input-styling.test.mjs +108 -0
  29. package/assets/codemods/transforms/next/__tests__/preserve-bottom-sheet-content-padding.test.mjs +178 -0
  30. package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
  31. package/assets/codemods/transforms/next/index.mjs +24 -0
  32. package/assets/codemods/transforms/next/migrate-field-input-styling.mjs +198 -0
  33. package/assets/codemods/transforms/next/preserve-bottom-sheet-content-padding.mjs +242 -0
  34. package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
  35. package/assets/docs/author-a-theme.doc.mjs +4 -4
  36. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  37. package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
  38. package/assets/templates/blocks/components/BottomSheet/BottomSheetHeights.tsx +1 -1
  39. package/assets/templates/blocks/components/BottomSheet/BottomSheetMobileKeyboard.tsx +1 -1
  40. package/assets/templates/blocks/components/BottomSheet/BottomSheetNoScrim.tsx +1 -1
  41. package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.tsx +1 -1
  42. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx +1 -1
  43. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorShowcase.tsx +1 -1
  44. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorTreeSearch.tsx +1 -1
  45. package/assets/templates/blocks/components/Dialog/DialogAdaptivePresentation.tsx +1 -1
  46. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
  47. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +1 -1
  48. package/assets/templates/blocks/components/Selector/SelectorClearable.tsx +1 -1
  49. package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +2 -2
  50. package/assets/templates/blocks/components/Selector/SelectorShowcase.tsx +1 -1
  51. package/assets/templates/blocks/components/Selector/SelectorWithSections.tsx +1 -1
  52. package/assets/templates/blocks/components/SelectorOption/SelectorOptionBasic.tsx +1 -1
  53. package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
  54. package/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx +1 -1
  55. package/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx +1 -1
  56. package/assets/templates/blocks/components/Slider/SliderShowcase.tsx +1 -1
  57. package/assets/templates/blocks/components/Slider/SliderWithMarks.tsx +1 -1
  58. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -1
  59. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +2 -2
  60. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -1
  61. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +1 -1
  62. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +1 -1
  63. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -2
  64. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +1 -1
  65. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +4 -4
  66. package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -1
  67. package/assets/templates/pages/canvas-editor/page.tsx +2 -2
  68. package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
  69. package/assets/templates/pages/payment-form/page.tsx +1 -1
  70. package/assets/templates/pages/table-filter/page.tsx +11 -6
  71. package/assets/templates/pages/table-inbox/page.tsx +3 -1
  72. package/assets/templates/pages/theme-showcase/page.tsx +2 -2
  73. package/assets/templates/themes/butter/butterTheme.ts +12 -0
  74. package/assets/templates/themes/chocolate/chocolateTheme.ts +12 -0
  75. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +10 -9
  76. package/assets/templates/themes/neutral/neutralTheme.ts +12 -0
  77. package/assets/templates/themes/stone/stoneTheme.ts +12 -0
  78. package/clients/cli/command-result-coverage.test.mjs +1 -1
  79. package/clients/cli/commands/build-theme.color-scheme.test.mjs +10 -6
  80. package/clients/cli/commands/build-theme.data-tokens.test.mjs +23 -75
  81. package/clients/cli/commands/build.doc.mjs +1 -1
  82. package/clients/cli/commands/build.mjs +1 -1
  83. package/clients/cli/commands/component-ownership.test.mjs +2 -2
  84. package/clients/cli/commands/debug-result-summary.test.mjs +0 -16
  85. package/clients/cli/commands/doctor.mjs +5 -2
  86. package/clients/cli/commands/gap-report.doc.mjs +1 -1
  87. package/clients/cli/commands/gap-report.test.mjs +2 -2
  88. package/clients/cli/commands/init.doc.mjs +4 -4
  89. package/clients/cli/commands/init.flag-help.test.mjs +7 -10
  90. package/clients/cli/commands/integration.mjs +2 -1
  91. package/clients/cli/commands/option-pair-refusals.test.mjs +37 -0
  92. package/clients/cli/commands/silent-success-refusals.test.mjs +15 -0
  93. package/clients/cli/commands/template.doc.mjs +4 -4
  94. package/clients/cli/commands/template.flag-help.test.mjs +18 -11
  95. package/clients/cli/commands/text-json-parity.test.mjs +0 -17
  96. package/clients/cli/commands/upgrade.doc.mjs +1 -1
  97. package/clients/cli/commands/upgrade.flag-help.test.mjs +7 -11
  98. package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +67 -0
  99. package/clients/cli/index.mjs +0 -4
  100. package/clients/cli/lib/exit-codes.test.mjs +0 -7
  101. package/clients/cli/lib/json-shim.test.mjs +0 -24
  102. package/foundation/discovery/template-needs.mjs +93 -11
  103. package/foundation/discovery/template-needs.test.mjs +106 -3
  104. package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
  105. package/foundation/env/package-manager.d.mts +13 -0
  106. package/foundation/env/package-manager.mjs +106 -63
  107. package/foundation/response/error-codes.doc.mjs +1 -1
  108. package/foundation/response/response-types.doc.mjs +2 -19
  109. package/foundation/response/response.doc.mjs +1 -1
  110. package/foundation/xle/browser.d.mts +2 -2
  111. package/foundation/xle/browser.mjs +2 -2
  112. package/foundation/xle/expand.mjs +1 -1
  113. package/foundation/xle/print.mjs +1 -1
  114. package/package.json +9 -9
  115. package/api/layout/_adapter.d.mts +0 -34
  116. package/api/layout/_adapter.mjs +0 -148
  117. package/api/layout/check/check.d.mts +0 -17
  118. package/api/layout/check/check.mjs +0 -41
  119. package/api/layout/expand/expand.d.mts +0 -23
  120. package/api/layout/expand/expand.mjs +0 -161
  121. package/api/layout/expand/expand.path-safety.test.mjs +0 -53
  122. package/api/layout/expand/expand.receipt.test.mjs +0 -74
  123. package/api/layout/grammar/grammar.d.mts +0 -14
  124. package/api/layout/grammar/grammar.mjs +0 -88
  125. package/api/layout/layout.d.mts +0 -6
  126. package/api/layout/layout.mjs +0 -17
  127. package/api/layout/layout.test.mjs +0 -297
  128. package/api/layout/layout.type.d.mts +0 -90
  129. package/api/layout/layout.type.mjs +0 -104
  130. package/api/layout/layoutCheck.doc.d.mts +0 -11
  131. package/api/layout/layoutCheck.doc.mjs +0 -85
  132. package/api/layout/layoutExpand.doc.d.mts +0 -11
  133. package/api/layout/layoutExpand.doc.mjs +0 -107
  134. package/api/layout/layoutGrammar.doc.d.mts +0 -11
  135. package/api/layout/layoutGrammar.doc.mjs +0 -57
  136. package/clients/cli/commands/layout-check.doc.mjs +0 -67
  137. package/clients/cli/commands/layout-expand.doc.mjs +0 -87
  138. package/clients/cli/commands/layout-grammar.doc.mjs +0 -32
  139. package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +0 -140
  140. package/clients/cli/commands/layout.doc.mjs +0 -36
  141. package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
  142. package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
  143. package/clients/cli/commands/layout.expand-receipt.test.mjs +0 -94
  144. package/clients/cli/commands/layout.mjs +0 -327
  145. package/clients/cli/commands/layout.path-help.test.mjs +0 -33
  146. package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
  147. package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
@@ -72,6 +72,7 @@ export {validateLoadedIntegration};
72
72
  * @property {string} [name] Integration package name (from package.json).
73
73
  * @property {string} [version] Integration package version.
74
74
  * @property {string} [manifestFile] Absolute path to the loaded manifest.
75
+ * @property {'no_package_json'} [reason] Why nothing was validated (internal).
75
76
  * @property {Issue[]} issues
76
77
  * @property {import('../../foundation/integrations/integrations.mjs').LoadedIntegration} [integration]
77
78
  */
@@ -349,7 +350,7 @@ async function validateAtPackageDir(
349
350
  export async function validateLocalIntegration(cwd = process.cwd()) {
350
351
  const pkgJsonPath = findNearestPackageJson(cwd);
351
352
  if (!pkgJsonPath) {
352
- return {found: false, issues: []};
353
+ return {found: false, reason: 'no_package_json', issues: []};
353
354
  }
354
355
  const packageDir = path.dirname(pkgJsonPath);
355
356
 
@@ -468,7 +469,9 @@ export async function validateIntegration(pkg, options = {}) {
468
469
  validated: result.found,
469
470
  name: result.found ? (result.name ?? null) : null,
470
471
  version: result.found ? (result.version ?? null) : null,
471
- issues: result.issues,
472
+ issues: result.reason === 'no_package_json'
473
+ ? [{code: 'no_package', severity: 'error', message: 'No package.json found. Run this command inside a package directory.'}]
474
+ : result.issues,
472
475
  },
473
476
  };
474
477
  }
@@ -46,7 +46,7 @@ export const doc = {
46
46
  {
47
47
  type: 'integration.validate',
48
48
  description:
49
- 'The result envelope: `data.validated`, false only when no integration manifest was found — nothing was checked, so the empty `data.issues` means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',
49
+ 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',
50
50
  },
51
51
  ],
52
52
  examples: [
package/api/json/index.ts CHANGED
@@ -26,7 +26,6 @@ export type * from '../gap-report/gap-report.type.mjs';
26
26
  export type * from '../upgrade/upgrade.type.mjs';
27
27
  export type * from '../init/init.type.mjs';
28
28
  export type * from '../doctor/doctor.type.mjs';
29
- export type * from '../layout/layout.type.mjs';
30
29
  export type * from '../integration/validate-integration.type.mjs';
31
30
  export type * from '../integration/authoring-checks.type.mjs';
32
31
  export type * from '../integration/pack-check.type.mjs';
@@ -10,6 +10,8 @@
10
10
  */
11
11
 
12
12
  import {pkgOf} from '../../../foundation/discovery/template-adapter.mjs';
13
+ import {AstryxError} from '../../error.mjs';
14
+ import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
13
15
 
14
16
  /**
15
17
  * Project a discovered template set into the `template.list` envelope.
@@ -19,10 +21,29 @@ import {pkgOf} from '../../../foundation/discovery/template-adapter.mjs';
19
21
  */
20
22
  export function templateList(templates, options = {}) {
21
23
  const {type, package: packageFilter} = options;
24
+ const VALID_TYPES = ['page', 'block'];
22
25
  let filtered = templates;
23
- if (type) filtered = filtered.filter(t => t.type === type);
24
- if (packageFilter)
26
+ if (type) {
27
+ if (!VALID_TYPES.includes(type)) {
28
+ throw new AstryxError(
29
+ `Unknown template type "${type}". Valid types: ${VALID_TYPES.join(', ')}.`,
30
+ VALID_TYPES.map(t => ({name: t, reason: 'valid type'})),
31
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
32
+ );
33
+ }
34
+ filtered = filtered.filter(t => t.type === type);
35
+ }
36
+ if (packageFilter) {
37
+ const allPackages = [...new Set(templates.map(t => pkgOf(t)))];
38
+ if (!allPackages.includes(packageFilter)) {
39
+ throw new AstryxError(
40
+ `No templates found in package "${packageFilter}".`,
41
+ allPackages.sort().map(p => ({name: p, reason: 'has templates'})),
42
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
43
+ );
44
+ }
25
45
  filtered = filtered.filter(t => pkgOf(t) === packageFilter);
46
+ }
26
47
  return {
27
48
  type: 'template.list',
28
49
  data: filtered.map(t => ({
@@ -0,0 +1,52 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ import {describe, expect, it} from 'vitest';
3
+ import {templateList} from './list.mjs';
4
+
5
+ const t = (type, dirName, pkg) => ({
6
+ type,
7
+ dirName,
8
+ name: dirName,
9
+ description: dirName,
10
+ ...(pkg ? {package: pkg} : {}),
11
+ });
12
+
13
+ const templates = [
14
+ t('page', 'dashboard'),
15
+ t('block', 'hero'),
16
+ t('block', 'promo', '@acme/blocks'),
17
+ ];
18
+
19
+ describe('templateList filters', () => {
20
+ it('returns an empty list for a valid filter that matches nothing', () => {
21
+ // @acme/blocks ships only blocks, so asking it for pages is a valid
22
+ // filter with no match: an empty list, not an error.
23
+ const response = templateList(templates, {
24
+ type: 'page',
25
+ package: '@acme/blocks',
26
+ });
27
+ expect(response.type).toBe('template.list');
28
+ expect(response.data).toEqual([]);
29
+ });
30
+
31
+ it('refuses a type outside page or block', () => {
32
+ expect(() => templateList(templates, {type: 'bogus'})).toThrow(
33
+ /Unknown template type "bogus"/,
34
+ );
35
+ });
36
+
37
+ it('refuses a package that provides no templates', () => {
38
+ expect(() => templateList(templates, {package: '@nope/x'})).toThrow(
39
+ /No templates found in package "@nope\/x"/,
40
+ );
41
+ });
42
+
43
+ it('keeps a matching type and package filter', () => {
44
+ const response = templateList(templates, {
45
+ type: 'block',
46
+ package: '@acme/blocks',
47
+ });
48
+ expect(response.data.map(item => item.id ?? item.dirName)).toEqual([
49
+ 'promo',
50
+ ]);
51
+ });
52
+ });
@@ -19,7 +19,6 @@ import {
19
19
  } from './template.mjs';
20
20
  import {search} from '../search/search.mjs';
21
21
  import {build} from '../build/build.mjs';
22
- import {layoutExpand} from '../layout/layout.mjs';
23
22
  import {runCli} from '../../test-utils/run-cli.mjs';
24
23
 
25
24
  let tmpDir;
@@ -532,105 +531,6 @@ describe('integration template discovery', () => {
532
531
  });
533
532
  });
534
533
 
535
- it('resolves a replacement block through the layout alias', async () => {
536
- const pkgDir = installWidgets(tmpDir);
537
- writeTemplate(pkgDir, 'acme-card-callout', {
538
- kind: 'block',
539
- source:
540
- 'export default function AcmeCardCallout() { return <span>Acme replacement block</span>; }\n',
541
- });
542
- declareReplaces(pkgDir, {
543
- 'acme-card-callout': 'CardCallout',
544
- });
545
-
546
- const accidental = path.join(tmpDir, 'node_modules', '@acme', 'extra');
547
- fs.mkdirSync(path.join(accidental, 'templates'), {recursive: true});
548
- fs.writeFileSync(
549
- path.join(accidental, 'package.json'),
550
- JSON.stringify({name: '@acme/extra', version: '1.0.0'}),
551
- );
552
- fs.writeFileSync(
553
- path.join(accidental, 'astryx.integration.mjs'),
554
- `export default {templates: './templates'};\n`,
555
- );
556
- writeTemplate(accidental, 'CardCallout', {
557
- kind: 'block',
558
- body: `export default {type: 'block', name: 'ZZZ accidental block', description: 'collision'};\n`,
559
- source:
560
- 'export default function Accidental() { return <span>Accidental block</span>; }\n',
561
- });
562
- fs.writeFileSync(
563
- path.join(tmpDir, 'astryx.config.mjs'),
564
- `export default { integrations: ['@acme/widgets', '@acme/extra'] };\n`,
565
- );
566
-
567
- const result = await layoutExpand('C{card-callout}', {
568
- name: 'ReplacementLayout',
569
- cwd: tmpDir,
570
- });
571
-
572
- expect(result.data.code).toContain('Acme replacement block');
573
- expect(result.data.code).not.toContain('Accidental block');
574
- expect(result.data.blocksReferenced).toEqual(
575
- expect.arrayContaining([
576
- expect.objectContaining({name: 'CardCallout', mode: 'splice'}),
577
- ]),
578
- );
579
- }, 30_000);
580
-
581
- it('resolves chained block aliases consistently in template and layout', async () => {
582
- const [firstTarget, secondTarget] = (await discoverCoreTemplates()).filter(
583
- candidate => candidate.type === 'block',
584
- );
585
- expect(firstTarget).toBeDefined();
586
- expect(secondTarget).toBeDefined();
587
-
588
- const pkgDir = installWidgets(tmpDir);
589
- writeTemplate(pkgDir, secondTarget.dirName, {
590
- kind: 'block',
591
- source:
592
- 'export default function FirstReplacement() { return <span>First chain replacement</span>; }\n',
593
- });
594
- writeTemplate(pkgDir, 'acme-final-block', {
595
- kind: 'block',
596
- source:
597
- 'export default function FinalReplacement() { return <span>Final chain replacement</span>; }\n',
598
- });
599
- declareReplaces(pkgDir, {
600
- [secondTarget.dirName]: firstTarget.dirName,
601
- 'acme-final-block': secondTarget.dirName,
602
- });
603
-
604
- const firstTemplate = await template(firstTarget.dirName, {
605
- show: true,
606
- cwd: tmpDir,
607
- });
608
- expect(firstTemplate.data.source).toContain('First chain replacement');
609
- const layoutId = id =>
610
- id.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();
611
- const firstLayout = await layoutExpand(
612
- `C{${layoutId(firstTarget.dirName)}}`,
613
- {
614
- cwd: tmpDir,
615
- },
616
- );
617
- expect(firstLayout.data.code).toContain('First chain replacement');
618
- expect(firstLayout.data.code).not.toContain('Final chain replacement');
619
-
620
- const secondTemplate = await template(secondTarget.dirName, {
621
- show: true,
622
- cwd: tmpDir,
623
- });
624
- expect(secondTemplate.data.source).toContain('Final chain replacement');
625
- const secondLayout = await layoutExpand(
626
- `C{${layoutId(secondTarget.dirName)}}`,
627
- {
628
- cwd: tmpDir,
629
- },
630
- );
631
- expect(secondLayout.data.code).toContain('Final chain replacement');
632
- }, 30_000);
633
-
634
534
  it('keeps the old discovery behavior when no replacement is declared', async () => {
635
535
  const pkgDir = installWidgets(tmpDir);
636
536
  writeTemplate(pkgDir, 'acme-app-shell', {kind: 'page'});
@@ -1334,4 +1234,41 @@ describe('build names a start its command selects', () => {
1334
1234
  template('contact-form', {show: true, cwd: tmpDir}),
1335
1235
  ).rejects.toMatchObject({code: 'ERR_AMBIGUOUS_TEMPLATE'});
1336
1236
  });
1237
+
1238
+ it('resolves chained template aliases without the layout command', async () => {
1239
+ const [firstTarget, secondTarget] = (await discoverCoreTemplates()).filter(
1240
+ candidate => candidate.type === 'block',
1241
+ );
1242
+ expect(firstTarget).toBeDefined();
1243
+ expect(secondTarget).toBeDefined();
1244
+
1245
+ const pkgDir = installWidgets(tmpDir);
1246
+ writeTemplate(pkgDir, secondTarget.dirName, {
1247
+ kind: 'block',
1248
+ source:
1249
+ 'export default function FirstReplacement() { return <span>First chain replacement</span>; }\n',
1250
+ });
1251
+ writeTemplate(pkgDir, 'acme-final-block', {
1252
+ kind: 'block',
1253
+ source:
1254
+ 'export default function FinalReplacement() { return <span>Final chain replacement</span>; }\n',
1255
+ });
1256
+ declareReplaces(pkgDir, {
1257
+ [secondTarget.dirName]: firstTarget.dirName,
1258
+ 'acme-final-block': secondTarget.dirName,
1259
+ });
1260
+
1261
+ const firstTemplate = await template(firstTarget.dirName, {
1262
+ show: true,
1263
+ cwd: tmpDir,
1264
+ });
1265
+ expect(firstTemplate.data.source).toContain('First chain replacement');
1266
+
1267
+ const secondTemplate = await template(secondTarget.dirName, {
1268
+ show: true,
1269
+ cwd: tmpDir,
1270
+ });
1271
+ expect(secondTemplate.data.source).toContain('Final chain replacement');
1272
+ }, 30_000);
1273
+
1337
1274
  });
@@ -48,7 +48,8 @@ export const doc = {
48
48
  {
49
49
  name: 'options.list',
50
50
  type: 'boolean',
51
- description: 'Force the list response even when a name is given.',
51
+ description:
52
+ 'List templates instead of scaffolding; refused with ERR_INVALID_ARGUMENT when a name or path is also given.',
52
53
  default: 'false',
53
54
  },
54
55
  {
@@ -89,7 +90,7 @@ export const doc = {
89
90
  type: 'string',
90
91
  description:
91
92
  'Destination (relative to cwd) to scaffold the template into. Its presence switches a named lookup into a copy. ' +
92
- 'A path that ends in .tsx, .ts, .jsx, .js, .mjs, .cjs, .css, .scss, .json, .md or .html is the file to write; any other path is a directory, which receives page.tsx for a page template or the block\'s own file name for a block.',
93
+ "A path that ends in .tsx, .ts, .jsx, .js, .mjs, .cjs, .css, .scss, .json, .md or .html is the file to write; any other path is a directory, which receives page.tsx for a page template or the block's own file name for a block.",
93
94
  },
94
95
  {
95
96
  name: 'options.overwrite',
@@ -124,7 +125,7 @@ export const doc = {
124
125
  {
125
126
  type: 'template.copy',
126
127
  description:
127
- 'A receipt after scaffolding the template into the project: the template id, output directory, written file name, file count, `demoMediaReplaced` — how many Astryx demo media references were replaced with placeholders, `notes` — setup notes naming what the template needs that the project lacks (missing packages, missing StyleX compiler; empty when satisfied), `missingPackages` — external package names the template imports that are not in the project, and `installCommand` — a ready-to-run install command with the detected package manager and workspace version ranges (null when nothing is missing).',
128
+ 'A receipt after scaffolding the template into the project: the template id, output directory, written file name, file count, `demoMediaReplaced` — how many Astryx demo media references were replaced with placeholders, `notes` — setup notes naming what the template needs that the project lacks (missing packages, missing StyleX compiler; empty when satisfied), `missingPackages` — external package names the template imports that are not in the project, and `installCommand` — a ready-to-run install command with the detected package manager and workspace version ranges (null when nothing is missing, or when several lockfiles leave the package manager undetermined; `missingPackages` still names the packages).',
128
129
  },
129
130
  {
130
131
  type: 'template.cdn',
@@ -133,6 +134,10 @@ export const doc = {
133
134
  },
134
135
  ],
135
136
  throws: [
137
+ {
138
+ code: 'ERR_INVALID_ARGUMENT',
139
+ when: '--cdn is combined with <name>, --list, --skeleton, --type, or --package; --list is combined with <name>, <path>, --skeleton, or --overwrite; --skeleton is combined with <path> or --overwrite; or options.list is set with a type outside page or block, or with a package that provides no templates (a valid filter that matches nothing returns an empty list instead)',
140
+ },
136
141
  {
137
142
  code: 'ERR_UNKNOWN_TEMPLATE',
138
143
  when: 'the named template does not exist, or options.skeleton is set without a name',
@@ -86,6 +86,51 @@ export async function template(name, options = {}) {
86
86
  cwd = process.cwd(),
87
87
  } = options;
88
88
 
89
+ if (cdn) {
90
+ const ignored = [
91
+ name ? '<name>' : null,
92
+ list ? '--list' : null,
93
+ skeleton ? '--skeleton' : null,
94
+ type ? '--type' : null,
95
+ packageFilter ? '--package' : null,
96
+ ].filter(Boolean);
97
+ if (ignored.length > 0) {
98
+ throw new AstryxError(
99
+ `\`--cdn\` cannot be combined with ${ignored.join(', ')}: the CDN starter does not use templates.`,
100
+ undefined,
101
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
102
+ );
103
+ }
104
+ }
105
+ if (list) {
106
+ const ignored = [
107
+ name ? '<name>' : null,
108
+ targetPath ? '<path>' : null,
109
+ skeleton ? '--skeleton' : null,
110
+ overwrite ? '--overwrite' : null,
111
+ ].filter(Boolean);
112
+ if (ignored.length > 0) {
113
+ throw new AstryxError(
114
+ `\`--list\` cannot be combined with ${ignored.join(', ')}: it lists templates and does not scaffold.`,
115
+ undefined,
116
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
117
+ );
118
+ }
119
+ }
120
+ if (skeleton) {
121
+ const ignored = [
122
+ targetPath ? '<path>' : null,
123
+ overwrite ? '--overwrite' : null,
124
+ ].filter(Boolean);
125
+ if (ignored.length > 0) {
126
+ throw new AstryxError(
127
+ `\`--skeleton\` cannot be combined with ${ignored.join(', ')}: it prints the skeleton and does not write files.`,
128
+ undefined,
129
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
130
+ );
131
+ }
132
+ }
133
+
89
134
  // The CDN starter ships as an asset rather than as a discovered template, so
90
135
  // it answers before discovery — nothing here needs a name resolved.
91
136
  if (cdn) {
@@ -82,7 +82,7 @@
82
82
  * @property {number} data.demoMediaReplaced Astryx demo media references (images, posters, videos) replaced in the written file: images with a neutral placeholder, videos with an empty source. Swap in your own media at those points; no media is installed. 0 when the template carried none.
83
83
  * @property {string[]} data.notes Setup notes: what the template needs that the project lacks (missing packages, missing StyleX compiler). Each note is one actionable line. Empty when the template needs nothing the project lacks.
84
84
  * @property {string[]} data.missingPackages External package names the template imports that are not in the project's dependencies. Empty when none are missing.
85
- * @property {string | null} data.installCommand A ready-to-run install command for the missing packages, using the project's package manager and the CLI workspace's version ranges. Null when no packages are missing.
85
+ * @property {string | null} data.installCommand A ready-to-run install command for the missing packages, using the project's package manager and the CLI workspace's version ranges. Null when no packages are missing, or when several lockfiles leave the package manager undetermined; missingPackages still names the packages.
86
86
  */
87
87
 
88
88
  /**
@@ -222,5 +222,4 @@ export type CoreBindings = {
222
222
  generateThemeRulesSplit: any;
223
223
  generateOnMediaCSS: any;
224
224
  generateAdaptationCSS: any;
225
- dataTokenDefaults: any;
226
225
  };
@@ -99,14 +99,12 @@ import {resolveIconImports} from './icon-imports.mjs';
99
99
  // capability instead, required only by a theme that actually uses it:
100
100
  // requiring it unconditionally made every theme build — adaptations or not —
101
101
  // fail against an older published core. This is a targeted allowance for that
102
- // one capability, not a general scheme; the other two optional reads below
103
- // (`generateOnMediaCSS`, `dataTokenDefaults`) both exist in every core that
104
- // ships adaptations' predecessor surface.
102
+ // one capability, not a general scheme; `generateOnMediaCSS` exists in every
103
+ // core that ships adaptations' predecessor surface.
105
104
  /** @type {any} */ let _defineTheme = null;
106
105
  /** @type {any} */ let _generateThemeRulesSplit = null;
107
106
  /** @type {any} */ let _generateOnMediaCSS = null;
108
107
  /** @type {any} */ let _generateAdaptationCSS = null;
109
- /** @type {any} */ let _dataTokenDefaults = null;
110
108
  /**
111
109
  * The whole `@astryxdesign/core/theme` namespace. A theme file handed a
112
110
  * wrapped core must still get every export the installed one has, including
@@ -129,7 +127,6 @@ try {
129
127
  _generateThemeRulesSplit = coreTheme.generateThemeRulesSplit;
130
128
  _generateOnMediaCSS = coreTheme.generateOnMediaCSS;
131
129
  _generateAdaptationCSS = coreTheme.generateAdaptationCSS;
132
- _dataTokenDefaults = coreTheme.dataTokenDefaults;
133
130
  try {
134
131
  _coreRootModule = await import('@astryxdesign/core');
135
132
  } catch {
@@ -156,7 +153,6 @@ try {
156
153
  * generateThemeRulesSplit: any,
157
154
  * generateOnMediaCSS: any,
158
155
  * generateAdaptationCSS: any,
159
- * dataTokenDefaults: any,
160
156
  * }} CoreBindings
161
157
  */
162
158
 
@@ -173,7 +169,6 @@ const _cliCore = {
173
169
  generateThemeRulesSplit: _generateThemeRulesSplit,
174
170
  generateOnMediaCSS: _generateOnMediaCSS,
175
171
  generateAdaptationCSS: _generateAdaptationCSS,
176
- dataTokenDefaults: _dataTokenDefaults,
177
172
  };
178
173
 
179
174
  /**
@@ -188,7 +183,6 @@ function setCore(core) {
188
183
  _generateThemeRulesSplit = core.generateThemeRulesSplit;
189
184
  _generateOnMediaCSS = core.generateOnMediaCSS;
190
185
  _generateAdaptationCSS = core.generateAdaptationCSS;
191
- _dataTokenDefaults = core.dataTokenDefaults;
192
186
  }
193
187
 
194
188
  /**
@@ -295,7 +289,6 @@ async function loadProjectCore(cwd) {
295
289
  generateThemeRulesSplit: themeModule.generateThemeRulesSplit,
296
290
  generateOnMediaCSS: themeModule.generateOnMediaCSS,
297
291
  generateAdaptationCSS: themeModule.generateAdaptationCSS,
298
- dataTokenDefaults: themeModule.dataTokenDefaults,
299
292
  };
300
293
  }
301
294
 
@@ -2739,26 +2732,8 @@ async function themeBuildInternal(
2739
2732
  logger.log(`${source}No overrides found; nothing to build.`);
2740
2733
  return null;
2741
2734
  }
2742
- // The data-token defaults are theme-independent and go in @layer
2743
- // astryx-base, below the theme's own overrides. Formatted here from the
2744
- // public `dataTokenDefaults` export, byte for byte as the `<Theme>`
2745
- // runtime emits it — build-theme.data-tokens.test.mjs is the drift guard.
2746
- // Placed after the reset block and before the theme block: a layer's order
2747
- // is fixed by where it is first declared, so emitting it anywhere else in
2748
- // the file would invert reset < astryx-base < astryx-theme for a consumer
2749
- // who imports this stylesheet on its own.
2750
- const baseCss = _dataTokenDefaults
2751
- ? `:root {\n${Object.entries(_dataTokenDefaults)
2752
- .map(([name, value]) => ` ${name}: ${value};`)
2753
- .join('\n')}\n}`
2754
- : '';
2755
- if (baseCss) {
2756
- cssParts.splice(
2757
- prose.length > 0 ? 1 : 0,
2758
- 0,
2759
- `@layer astryx-base {\n${baseCss}\n}`,
2760
- );
2761
- }
2735
+ cssParts.unshift('@layer reset, astryx-base, astryx-theme;');
2736
+ const baseCss = '';
2762
2737
  cssPlan = {
2763
2738
  base: baseCss,
2764
2739
  prose,
@@ -438,5 +438,5 @@ export function generateFamilyCSS(members) {
438
438
  parts.push(`@layer astryx-base {\n${base.join('\n\n')}\n}`);
439
439
  if (themed.length > 0)
440
440
  parts.push(`@layer astryx-theme {\n${themed.join('\n\n')}\n}`);
441
- return `${parts.join('\n\n')}\n`;
441
+ return `@layer reset, astryx-base, astryx-theme;\n\n${parts.join('\n\n')}\n`;
442
442
  }
@@ -129,7 +129,7 @@ export const doc = {
129
129
  throws: [
130
130
  {
131
131
  code: 'ERR_INVALID_ARGUMENT',
132
- when: '`from` is missing (and neither `list` nor `registry` is set); `list` and `registry` are both set; `registry` is combined with `from`, `force`, `codemod`, `skipCodemod`, `integration` or `installDeps`; an `integration` specifier is invalid or not installed; or astryx.config fails to load or validate and no pending config codemod repairs it',
132
+ when: '`from` is missing (and neither `list` nor `registry` is set); `list` and `registry` are both set; `list` is combined with `from`, `force`, `apply`, `path` (non-default), `codemod`, `skipCodemod`, `integration` or `installDeps`; `registry` is combined with `from`, `force`, `codemod`, `skipCodemod`, `integration` or `installDeps`; an `integration` specifier is invalid or not installed; or astryx.config fails to load or validate and no pending config codemod repairs it',
133
133
  },
134
134
  {code: 'ERR_INVALID_VERSION', when: '`from` is not a valid semver string'},
135
135
  {code: 'ERR_PATH_TRAVERSAL', when: '`path` resolves outside cwd'},
@@ -53,6 +53,25 @@ export async function upgrade(options = {}, {cwd = process.cwd()} = {}) {
53
53
  throw new AstryxError(msg, undefined, ERROR_CODES.ERR_INVALID_ARGUMENT);
54
54
  }
55
55
 
56
+ if (options.list) {
57
+ const ignored = [
58
+ options.from ? '--from' : null,
59
+ options.force ? '--force' : null,
60
+ options.apply ? '--apply' : null,
61
+ options.path && options.path !== './src' ? '--path' : null,
62
+ options.codemod ? '--codemod' : null,
63
+ options.skipCodemod?.length ? '--skip-codemod' : null,
64
+ options.integration?.length ? '--integration' : null,
65
+ options.installDeps ? '--install-deps' : null,
66
+ ].filter(Boolean);
67
+ if (ignored.length > 0) {
68
+ const msg = `\`--list\` cannot be combined with ${ignored.join(', ')}: it lists available codemods and does not run a migration.`;
69
+ logger.error(msg);
70
+ logger.log('Aborted\n');
71
+ throw new AstryxError(msg, undefined, ERROR_CODES.ERR_INVALID_ARGUMENT);
72
+ }
73
+ }
74
+
56
75
  if (options.registry) {
57
76
  const incompatible = [
58
77
  options.from ? '--from' : null,
@@ -0,0 +1,108 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+ import jscodeshift from 'jscodeshift';
5
+ import transform from '../migrate-field-input-styling.mjs';
6
+
7
+ const j = jscodeshift.withParser('tsx');
8
+ const api = {jscodeshift: j, stats: () => {}, report: () => {}};
9
+
10
+ /** @param {string} source */
11
+ function apply(source) {
12
+ return transform({source, path: 'test.tsx'}, api) ?? source;
13
+ }
14
+
15
+ describe('migrate-field-input-styling', () => {
16
+ it('moves control-box members to control*', () => {
17
+ const input = `import {TextInput, Selector, DateInput} from '@astryxdesign/core';
18
+ const a = <TextInput label="Name" xstyle={styles.input} className="name" style={{width: 200}} />;
19
+ const b = <Selector label="Fruit" options={options} xstyle={styles.selector} />;
20
+ const c = <DateInput label="Due" className="due" />;`;
21
+ const output = apply(input);
22
+ expect(output).toContain(
23
+ '<TextInput label="Name" controlXstyle={styles.input} controlClassName="name" controlStyle={{width: 200}} />',
24
+ );
25
+ expect(output).toContain('controlXstyle={styles.selector}');
26
+ expect(output).toContain(
27
+ '<DateInput label="Due" controlClassName="due" />',
28
+ );
29
+ });
30
+
31
+ it('moves Field-root members to container*', () => {
32
+ const input = `import {Typeahead} from '@astryxdesign/core/Typeahead';
33
+ import {RadioList, Slider} from '@astryxdesign/core';
34
+ const a = <Typeahead label="Fruit" xstyle={styles.wide} />;
35
+ const b = <RadioList label="Plan" style={{marginTop: 8}}>{items}</RadioList>;
36
+ const c = <Slider label="Volume" className="volume" value={1} />;`;
37
+ const output = apply(input);
38
+ expect(output).toContain('containerXstyle={styles.wide}');
39
+ expect(output).toContain('containerStyle={{marginTop: 8}}');
40
+ expect(output).toContain('containerClassName="volume"');
41
+ });
42
+
43
+ it('moves a Typeahead inside InputGroup to control*, where its root styling painted the surface', () => {
44
+ const input = `import {InputGroup, Typeahead} from '@astryxdesign/core';
45
+ const a = (
46
+ <InputGroup label="Produce">
47
+ <Typeahead label="Fruit" className="grouped" />
48
+ </InputGroup>
49
+ );
50
+ const b = <Typeahead label="Fruit" className="standalone" />;`;
51
+ const output = apply(input);
52
+ expect(output).toContain('controlClassName="grouped"');
53
+ expect(output).toContain('containerClassName="standalone"');
54
+ });
55
+
56
+ it('follows aliased and namespace imports', () => {
57
+ const input = `import {TextArea as Notes} from '@astryxdesign/core';
58
+ import * as Astryx from '@astryxdesign/core';
59
+ const a = <Notes label="Notes" className="notes" />;
60
+ const b = <Astryx.Tokenizer label="Tags" xstyle={styles.tags} />;`;
61
+ const output = apply(input);
62
+ expect(output).toContain(
63
+ '<Notes label="Notes" controlClassName="notes" />',
64
+ );
65
+ expect(output).toContain(
66
+ '<Astryx.Tokenizer label="Tags" containerXstyle={styles.tags} />',
67
+ );
68
+ });
69
+
70
+ it('leaves unrelated components, other packages, nested JSX, and spreads alone', () => {
71
+ const input = `import {TextInput} from 'some-other-library';
72
+ import {Button, NumberInput} from '@astryxdesign/core';
73
+ const a = <TextInput className="kept" />;
74
+ const b = <Button xstyle={styles.button} />;
75
+ const c = <NumberInput label="Qty" {...rest} startIcon={<Icon className="icon" />} />;`;
76
+ expect(apply(input)).toBe(input);
77
+ });
78
+
79
+ it('leaves tags whose name is shadowed by a local binding', () => {
80
+ const input = `import {TextInput} from '@astryxdesign/core';
81
+ import * as Astryx from '@astryxdesign/core';
82
+ function Row({TextInput}) {
83
+ return <TextInput className="kept" />;
84
+ }
85
+ function Other(Astryx) {
86
+ return <Astryx.Typeahead className="kept" />;
87
+ }`;
88
+ expect(apply(input)).toBe(input);
89
+ });
90
+
91
+ it('marks a conflict with a TODO instead of dropping a value', () => {
92
+ const input = `import {TextInput} from '@astryxdesign/core';
93
+ const a = <TextInput label="Name" className="old" controlClassName="new" />;`;
94
+ const output = apply(input);
95
+ expect(output).toContain('controlClassName="new"');
96
+ expect(output).toContain('className="old"');
97
+ expect(output).toContain('TODO(astryx upgrade)');
98
+ });
99
+
100
+ it('is idempotent', () => {
101
+ const input = `import {TextInput, CheckboxList} from '@astryxdesign/core';
102
+ const a = <TextInput label="Name" className="old" controlClassName="new" />;
103
+ const b = <TextInput label="Email" xstyle={styles.email} />;
104
+ const c = <CheckboxList label="Prefs" style={{margin: 4}}>{items}</CheckboxList>;`;
105
+ const once = apply(input);
106
+ expect(apply(once)).toBe(once);
107
+ });
108
+ });