@astryxdesign/cli 0.7.0-canary.e92e36f → 0.7.0-canary.eaca8eb

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 (75) hide show
  1. package/README.md +61 -61
  2. package/api/doctor/doctor.d.mts +30 -2
  3. package/api/doctor/doctor.doc.mjs +2 -1
  4. package/api/doctor/doctor.mjs +153 -3
  5. package/api/doctor/doctor.test.mjs +250 -4
  6. package/api/integration/pack-check.test.mjs +8 -0
  7. package/api/template/template.doc.mjs +1 -1
  8. package/api/template/template.type.mjs +1 -1
  9. package/api/theme/build/build.d.mts +0 -1
  10. package/api/theme/build/build.mjs +4 -29
  11. package/api/theme/build/family.mjs +1 -1
  12. package/assets/codemods/transforms/next/__tests__/migrate-field-input-styling.test.mjs +108 -0
  13. package/assets/codemods/transforms/next/__tests__/preserve-bottom-sheet-content-padding.test.mjs +178 -0
  14. package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
  15. package/assets/codemods/transforms/next/index.mjs +24 -0
  16. package/assets/codemods/transforms/next/migrate-field-input-styling.mjs +198 -0
  17. package/assets/codemods/transforms/next/preserve-bottom-sheet-content-padding.mjs +242 -0
  18. package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
  19. package/assets/docs/author-a-theme.doc.mjs +1 -1
  20. package/assets/docs/spacing.doc.mjs +2 -2
  21. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  22. package/assets/docs/tree/tokens-spacing.doc.mjs +15 -15
  23. package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
  24. package/assets/templates/blocks/components/BottomSheet/BottomSheetHeights.tsx +1 -1
  25. package/assets/templates/blocks/components/BottomSheet/BottomSheetMobileKeyboard.tsx +1 -1
  26. package/assets/templates/blocks/components/BottomSheet/BottomSheetNoScrim.tsx +1 -1
  27. package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.tsx +1 -1
  28. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx +1 -1
  29. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorShowcase.tsx +1 -1
  30. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorTreeSearch.tsx +1 -1
  31. package/assets/templates/blocks/components/Dialog/DialogAdaptivePresentation.tsx +1 -1
  32. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
  33. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +1 -1
  34. package/assets/templates/blocks/components/Selector/SelectorClearable.tsx +1 -1
  35. package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +2 -2
  36. package/assets/templates/blocks/components/Selector/SelectorShowcase.tsx +1 -1
  37. package/assets/templates/blocks/components/Selector/SelectorWithSections.tsx +1 -1
  38. package/assets/templates/blocks/components/SelectorOption/SelectorOptionBasic.tsx +1 -1
  39. package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
  40. package/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx +1 -1
  41. package/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx +1 -1
  42. package/assets/templates/blocks/components/Slider/SliderShowcase.tsx +1 -1
  43. package/assets/templates/blocks/components/Slider/SliderWithMarks.tsx +1 -1
  44. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -1
  45. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +2 -2
  46. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -1
  47. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +1 -1
  48. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +1 -1
  49. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -2
  50. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +1 -1
  51. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +4 -4
  52. package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -1
  53. package/assets/templates/pages/canvas-editor/page.tsx +2 -2
  54. package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
  55. package/assets/templates/pages/payment-form/page.tsx +1 -1
  56. package/assets/templates/pages/table-filter/page.tsx +11 -6
  57. package/assets/templates/pages/table-inbox/page.tsx +3 -1
  58. package/assets/templates/pages/theme-showcase/page.tsx +2 -2
  59. package/assets/templates/themes/butter/butterTheme.ts +12 -0
  60. package/assets/templates/themes/chocolate/chocolateTheme.ts +12 -0
  61. package/assets/templates/themes/matcha/matchaTheme.ts +14 -14
  62. package/assets/templates/themes/neutral/neutralTheme.ts +12 -0
  63. package/assets/templates/themes/stone/stoneTheme.ts +12 -0
  64. package/assets/templates/themes/y2k/y2kTheme.ts +10 -10
  65. package/assets/theme.template.ts +1 -1
  66. package/clients/cli/commands/build-theme.color-scheme.test.mjs +10 -6
  67. package/clients/cli/commands/build-theme.data-tokens.test.mjs +23 -75
  68. package/clients/cli/commands/doctor.doc.mjs +1 -1
  69. package/clients/cli/commands/doctor.test.mjs +33 -0
  70. package/foundation/discovery/template-needs.mjs +93 -11
  71. package/foundation/discovery/template-needs.test.mjs +106 -3
  72. package/foundation/env/package-manager.d.mts +13 -0
  73. package/foundation/env/package-manager.mjs +106 -63
  74. package/foundation/response/response-types.doc.mjs +1 -2
  75. package/package.json +9 -9
@@ -1042,7 +1042,7 @@ describe('doctor says why it skipped and what it checked', () => {
1042
1042
  }
1043
1043
 
1044
1044
  it(
1045
- 'warns, and quotes the reason, when the CLI cannot load the project from a config that imports',
1045
+ 'fails, and quotes the reason, when the CLI cannot load the project from a config that imports',
1046
1046
  async () => {
1047
1047
  const dir = cwdProject({
1048
1048
  'package.json': '{"name":"app"}',
@@ -1051,7 +1051,7 @@ describe('doctor says why it skipped and what it checked', () => {
1051
1051
  });
1052
1052
  const {checks, summary} = (await doctor({cwd: dir})).data;
1053
1053
  const by = Object.fromEntries(checks.map(c => [c.id, c]));
1054
- expect(by.config.status).toBe('warn');
1054
+ expect(by.config.status).toBe('fail');
1055
1055
  expect(by.config.message).toMatch(
1056
1056
  /^astryx\.config\.mjs loads, but the CLI could not load the project from it: .*integrations/,
1057
1057
  );
@@ -1064,8 +1064,8 @@ describe('doctor says why it skipped and what it checked', () => {
1064
1064
  expect(by['integration-issues'].message).toMatch(
1065
1065
  /^Skipped — the project integration graph could not be loaded: .*integrations/,
1066
1066
  );
1067
- // A warning: the exit code a released CLI gave this project is unchanged.
1068
- expect(summary.fail).toBe(0);
1067
+ // The config check is the one failure; the skipped checks stay info.
1068
+ expect(summary.fail).toBe(1);
1069
1069
  },
1070
1070
  SLOW,
1071
1071
  );
@@ -1123,6 +1123,252 @@ describe('doctor says why it skipped and what it checked', () => {
1123
1123
  });
1124
1124
  });
1125
1125
 
1126
+ describe('a configured integration that cannot load fails the gate', () => {
1127
+ const CORE_STUB = {
1128
+ 'node_modules/@astryxdesign/core/package.json': JSON.stringify({
1129
+ name: '@astryxdesign/core',
1130
+ version: '0.6.3',
1131
+ }),
1132
+ };
1133
+ const WIDGETS = 'node_modules/@acme/widgets';
1134
+ /** @param {string} [manifest] */
1135
+ const widgets = (
1136
+ manifest = "export default {components: './components'};\n",
1137
+ ) => ({
1138
+ [`${WIDGETS}/package.json`]: JSON.stringify({
1139
+ name: '@acme/widgets',
1140
+ version: '1.0.0',
1141
+ }),
1142
+ [`${WIDGETS}/astryx.integration.mjs`]: manifest,
1143
+ [`${WIDGETS}/components/AcmeCard.doc.mjs`]:
1144
+ "export default {type: 'component', name: 'AcmeCard', displayName: 'AcmeCard', description: 'Fixture.', props: []};\n",
1145
+ [`${WIDGETS}/components/AcmeCard.tsx`]:
1146
+ 'export default function AcmeCard() { return null; }\n',
1147
+ });
1148
+ const APP = {
1149
+ 'package.json': '{"name":"app"}',
1150
+ ...CORE_STUB,
1151
+ 'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
1152
+ };
1153
+
1154
+ /** Run doctor on a project under the working directory. */
1155
+ async function report(files) {
1156
+ const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
1157
+ tmpDirs.push(dir);
1158
+ for (const [rel, content] of Object.entries(files)) {
1159
+ const abs = path.join(dir, rel);
1160
+ fs.mkdirSync(path.dirname(abs), {recursive: true});
1161
+ fs.writeFileSync(abs, content);
1162
+ }
1163
+ const {checks, summary} = (await doctor({cwd: dir})).data;
1164
+ return {by: Object.fromEntries(checks.map(c => [c.id, c])), summary};
1165
+ }
1166
+
1167
+ it.each([
1168
+ ['not installed', {}, /Could not find installed integration package "@acme\/widgets"/],
1169
+ [
1170
+ 'installed without a manifest',
1171
+ {[`${WIDGETS}/package.json`]: JSON.stringify({name: '@acme/widgets', version: '1.0.0'})},
1172
+ /no conventional root manifest/,
1173
+ ],
1174
+ ['installed with a manifest that throws', widgets('export default { not valid ((\n'), /Unexpected/],
1175
+ ])(
1176
+ 'fails when a configured integration is %s, and names it',
1177
+ async (_shape, extra, reason) => {
1178
+ const {by, summary} = await report({...APP, ...extra});
1179
+ const check = by['configured-integrations'];
1180
+ expect(check.status).toBe('fail');
1181
+ expect(check.message).toMatch(
1182
+ /^1 of 1 integration named in astryx\.config could not be loaded, so it contributes nothing: @acme\/widgets \(/,
1183
+ );
1184
+ expect(check.message).toMatch(reason);
1185
+ expect(check.fix).toContain('astryx doctor integration validate <package>');
1186
+ expect(summary.fail).toBe(1);
1187
+ },
1188
+ SLOW,
1189
+ );
1190
+
1191
+ it(
1192
+ 'counts the package being authored when its own config names it',
1193
+ async () => {
1194
+ const {by} = await report({
1195
+ ...CORE_STUB,
1196
+ 'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
1197
+ 'astryx.integration.mjs': "export default {components: './components'};\n",
1198
+ 'components/AcmeCard.doc.mjs':
1199
+ "export default {type: 'component', name: 'AcmeCard', displayName: 'AcmeCard', description: 'Fixture.', props: []};\n",
1200
+ 'components/AcmeCard.tsx': 'export default function AcmeCard() { return null; }\n',
1201
+ 'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
1202
+ });
1203
+ expect(by['configured-integrations'].status).toBe('pass');
1204
+ expect(by['configured-integrations'].message).toBe(
1205
+ '1 integration named in astryx.config loaded: @acme/widgets.',
1206
+ );
1207
+ },
1208
+ SLOW,
1209
+ );
1210
+
1211
+ it(
1212
+ 'fails when the package being authored is named by its own config and its manifest throws',
1213
+ async () => {
1214
+ const {by, summary} = await report({
1215
+ ...CORE_STUB,
1216
+ 'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
1217
+ 'astryx.integration.mjs': 'export default { not valid ((\n',
1218
+ 'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
1219
+ });
1220
+ const check = by['configured-integrations'];
1221
+ expect(check.status).toBe('fail');
1222
+ expect(check.message).toMatch(
1223
+ /^1 of 1 integration named in astryx\.config could not be loaded, so it contributes nothing: @acme\/widgets \(/,
1224
+ );
1225
+ expect(summary.fail).toBe(1);
1226
+ },
1227
+ SLOW,
1228
+ );
1229
+
1230
+ it(
1231
+ 'fails when node_modules links the configured name back to the authored package and its manifest throws',
1232
+ async () => {
1233
+ const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
1234
+ tmpDirs.push(dir);
1235
+ const files = {
1236
+ ...CORE_STUB,
1237
+ 'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
1238
+ 'astryx.integration.mjs': 'export default { not valid ((\n',
1239
+ 'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
1240
+ };
1241
+ for (const [rel, content] of Object.entries(files)) {
1242
+ const abs = path.join(dir, rel);
1243
+ fs.mkdirSync(path.dirname(abs), {recursive: true});
1244
+ fs.writeFileSync(abs, content);
1245
+ }
1246
+ fs.mkdirSync(path.join(dir, 'node_modules/@acme'), {recursive: true});
1247
+ fs.symlinkSync(dir, path.join(dir, 'node_modules/@acme/widgets'), 'dir');
1248
+ const {checks, summary} = (await doctor({cwd: dir})).data;
1249
+ const by = Object.fromEntries(checks.map(c => [c.id, c]));
1250
+ expect(by['configured-integrations'].status).toBe('fail');
1251
+ expect(by['configured-integrations'].message).toMatch(
1252
+ /^1 of 1 integration named in astryx\.config could not be loaded/,
1253
+ );
1254
+ expect(summary.fail).toBe(1);
1255
+ },
1256
+ SLOW,
1257
+ );
1258
+
1259
+ it(
1260
+ 'fails for the self-linked authored package when the working directory is itself a symlink',
1261
+ async () => {
1262
+ const real = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
1263
+ tmpDirs.push(real);
1264
+ const linkParent = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
1265
+ tmpDirs.push(linkParent);
1266
+ const cwd = path.join(linkParent, 'link');
1267
+ fs.symlinkSync(real, cwd, 'dir');
1268
+ const files = {
1269
+ ...CORE_STUB,
1270
+ 'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
1271
+ 'astryx.integration.mjs': 'export default { not valid ((\n',
1272
+ 'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
1273
+ };
1274
+ for (const [rel, content] of Object.entries(files)) {
1275
+ const abs = path.join(real, rel);
1276
+ fs.mkdirSync(path.dirname(abs), {recursive: true});
1277
+ fs.writeFileSync(abs, content);
1278
+ }
1279
+ fs.mkdirSync(path.join(real, 'node_modules/@acme'), {recursive: true});
1280
+ fs.symlinkSync(real, path.join(real, 'node_modules/@acme/widgets'), 'dir');
1281
+ const {checks, summary} = (await doctor({cwd})).data;
1282
+ const by = Object.fromEntries(checks.map(c => [c.id, c]));
1283
+ expect(by['configured-integrations'].status).toBe('fail');
1284
+ expect(summary.fail).toBe(1);
1285
+ },
1286
+ SLOW,
1287
+ );
1288
+
1289
+ it(
1290
+ 'still counts a configured package that was set aside for a provider conflict',
1291
+ async () => {
1292
+ const CHARTS = 'node_modules/@acme/charts';
1293
+ const {by} = await report({
1294
+ ...APP,
1295
+ 'astryx.config.mjs':
1296
+ "export default { integrations: ['@acme/widgets', '@acme/charts'] };\n",
1297
+ ...widgets("export default {providerId: 'acme', components: './components'};\n"),
1298
+ [`${CHARTS}/package.json`]: JSON.stringify({name: '@acme/charts', version: '1.0.0'}),
1299
+ [`${CHARTS}/astryx.integration.mjs`]:
1300
+ "export default {providerId: 'acme', components: './components'};\n",
1301
+ [`${CHARTS}/components/AcmeChart.doc.mjs`]:
1302
+ "export default {type: 'component', name: 'AcmeChart', displayName: 'AcmeChart', description: 'Fixture.', props: []};\n",
1303
+ [`${CHARTS}/components/AcmeChart.tsx`]: 'export default function AcmeChart() { return null; }\n',
1304
+ });
1305
+ expect(by['configured-integrations'].status).toBe('pass');
1306
+ expect(by['configured-integrations'].message).toMatch(/^2 integrations named in astryx\.config loaded: /);
1307
+ expect(by['configured-integrations'].message).toContain('@acme/charts');
1308
+ },
1309
+ SLOW,
1310
+ );
1311
+
1312
+ it(
1313
+ 'passes, naming each one, when every configured integration loads',
1314
+ async () => {
1315
+ const {by, summary} = await report({...APP, ...widgets()});
1316
+ expect(by['configured-integrations']).toEqual({
1317
+ id: 'configured-integrations',
1318
+ label: 'Configured integrations',
1319
+ status: 'pass',
1320
+ message: '1 integration named in astryx.config loaded: @acme/widgets.',
1321
+ });
1322
+ expect(summary.fail).toBe(0);
1323
+ },
1324
+ SLOW,
1325
+ );
1326
+
1327
+ it.each([
1328
+ [
1329
+ 'an invalid component doc',
1330
+ {[`${WIDGETS}/components/AcmeCard.doc.mjs`]: 'export default {;\n'},
1331
+ ],
1332
+ [
1333
+ 'a declared root missing on disk',
1334
+ {
1335
+ [`${WIDGETS}/astryx.integration.mjs`]:
1336
+ "export default {components: './components', templates: './templates'};\n",
1337
+ },
1338
+ ],
1339
+ ])(
1340
+ 'keeps %s a warning, because the rest of the integration still loads (spec:AST-035 FR9)',
1341
+ async (_shape, extra) => {
1342
+ const {by, summary} = await report({...APP, ...widgets(), ...extra});
1343
+ expect(by['configured-integrations'].status).toBe('pass');
1344
+ expect(by['integration-issues'].status).toBe('warn');
1345
+ expect(summary.fail).toBe(0);
1346
+ },
1347
+ SLOW,
1348
+ );
1349
+
1350
+ it(
1351
+ 'leaves an autolinked dependency that cannot load informational',
1352
+ async () => {
1353
+ const {by, summary} = await report({
1354
+ 'package.json': JSON.stringify({
1355
+ name: 'app',
1356
+ dependencies: {'@acme/widgets': '1.0.0'},
1357
+ }),
1358
+ ...CORE_STUB,
1359
+ ...widgets('export default { not valid ((\n'),
1360
+ });
1361
+ expect(by['configured-integrations']).toMatchObject({
1362
+ status: 'info',
1363
+ message: 'No integration is named in astryx.config.',
1364
+ });
1365
+ expect(by['implicit-integrations'].status).toBe('info');
1366
+ expect(summary.fail).toBe(0);
1367
+ },
1368
+ SLOW,
1369
+ );
1370
+ });
1371
+
1126
1372
  describe('no Astryx-owned environment variables (spec:AST-017 FR14)', () => {
1127
1373
  it('no source file reads an ASTRYX_* env var', () => {
1128
1374
  const cliDir = path.resolve(REPO, 'packages/cli');
@@ -504,6 +504,14 @@ describe('integrationPackCheck', () => {
504
504
  message:
505
505
  'Theme "ocean" exports @acme/widgets/theme.css without a complete built module and stylesheet pair. Missing partner exports alone do not block packing; add the matching export when the theme should be importable. Every declared export must resolve. Staleness is a warning until the complete importable pair is declared.',
506
506
  },
507
+ // A 0.6.5-built stylesheet still carries the root data-color defaults
508
+ // that theme output no longer emits, so it no longer matches its source.
509
+ {
510
+ code: 'theme_stylesheet_stale',
511
+ severity: 'warning',
512
+ message:
513
+ 'Theme "ocean" stylesheet does not match themes/ocean/oceanTheme.ts. This incomplete export remains packable, but run `astryx theme build themes/ocean/oceanTheme.ts` before adding its matching export.',
514
+ },
507
515
  ]);
508
516
  const cli = runCliVerify();
509
517
  expect(cli.status, cli.stderr).toBe(0);
@@ -125,7 +125,7 @@ export const doc = {
125
125
  {
126
126
  type: 'template.copy',
127
127
  description:
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).',
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).',
129
129
  },
130
130
  {
131
131
  type: 'template.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
  }
@@ -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
+ });