@astryxdesign/cli 0.1.4-canary.f00b844 → 0.1.4-canary.f01eb10
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.
- package/CHANGELOG.md +2 -1
- package/package.json +14 -9
- package/src/api/doctor.mjs +13 -2
- package/src/codemods/__tests__/runner.test.mjs +38 -0
- package/src/codemods/runner.mjs +2 -0
- package/src/commands/build-theme.mjs +110 -13
- package/src/commands/build-theme.variants.test.mjs +204 -0
- package/src/commands/doctor.test.mjs +34 -0
- package/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +14 -0
- package/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +58 -0
- package/templates/blocks/components/CodeBlock/CodeBlockTerminal.doc.mjs +14 -0
- package/templates/blocks/components/CodeBlock/CodeBlockTerminal.tsx +24 -0
- package/templates/blocks/components/Collapsible/CollapsibleDividedAccordion.doc.mjs +13 -0
- package/templates/blocks/components/Collapsible/CollapsibleDividedAccordion.tsx +33 -0
- package/templates/blocks/components/CommandPaletteGroup/CommandPaletteGroupShowcase.tsx +27 -48
- package/templates/blocks/components/CommandPaletteInput/CommandPaletteInputBasic.doc.mjs +15 -0
- package/templates/blocks/components/CommandPaletteInput/CommandPaletteInputBasic.tsx +39 -0
- package/templates/blocks/components/CommandPaletteInput/CommandPaletteInputShowcase.doc.mjs +15 -0
- package/templates/blocks/components/CommandPaletteInput/CommandPaletteInputShowcase.tsx +39 -0
- package/templates/blocks/components/CommandPaletteItem/CommandPaletteItemShowcase.tsx +31 -54
- package/templates/blocks/components/CommandPaletteList/CommandPaletteListBasic.doc.mjs +15 -0
- package/templates/blocks/components/CommandPaletteList/CommandPaletteListBasic.tsx +27 -0
- package/templates/blocks/components/CommandPaletteList/CommandPaletteListShowcase.doc.mjs +15 -0
- package/templates/blocks/components/CommandPaletteList/CommandPaletteListShowcase.tsx +38 -0
- package/templates/blocks/components/ContextMenuItem/ContextMenuItemBasic.doc.mjs +14 -0
- package/templates/blocks/components/ContextMenuItem/ContextMenuItemBasic.tsx +44 -0
- package/templates/blocks/components/ContextMenuItem/ContextMenuItemShowcase.doc.mjs +15 -0
- package/templates/blocks/components/ContextMenuItem/ContextMenuItemShowcase.tsx +107 -0
- package/templates/blocks/components/NavHeadingMenu/NavHeadingMenuShowcase.doc.mjs +15 -0
- package/templates/blocks/components/NavHeadingMenu/NavHeadingMenuShowcase.tsx +47 -0
- package/templates/pages/table-page-chart/page.tsx +3 -13
- package/templates/pages/table-page-shoe-store-heatmap/page.tsx +4 -18
package/CHANGELOG.md
CHANGED
|
@@ -36,7 +36,7 @@ Thanks to everyone who contributed to this release:
|
|
|
36
36
|
- Strict config + integration v1 schema (integrations, issuesUrl, hooks.postCodemod) and new @astryxdesign/cli/integration export.
|
|
37
37
|
- File-based codemod API (createCodemod/createConfigCodemod) with the @astryxdesign/cli/codemod export and integration codemod discovery in upgrade.
|
|
38
38
|
- component, template, and upgrade now print a one-line non-blocking warning when a configured integration has validation issues, pointing to validate-integration.
|
|
39
|
-
- Add a Kanban Board page template: color-coded status columns, draggable task cards with priority tags, and board toolbar.
|
|
39
|
+
- Add a Kanban Board page template: color-coded status columns, draggable task cards with priority tags, and board toolbar. Based on a design by @cg-hub18.
|
|
40
40
|
- Add frame-first layout guidance: new `astryx docs layout` topic (shell choice, region budgets, app archetypes, cards-vs-rows policy, responsive contracts), layout rules in the generated agent cheat sheet, and layout anti-patterns in `docs principles`.
|
|
41
41
|
- Add a v0.1.3 config codemod that migrates astryx.config layout.components to experimental.xle.components.
|
|
42
42
|
- Add v0.1.0 codemods for migrating `declare module "@xds/core/..."` type augmentations and `.xds-*` / `[data-xds-theme]` / `@layer xds-theme` CSS surfaces to their `@astryxdesign`/`astryx-*` equivalents.
|
|
@@ -80,6 +80,7 @@ Thanks to everyone who contributed to this release:
|
|
|
80
80
|
Thanks to everyone who contributed to this release:
|
|
81
81
|
|
|
82
82
|
- @AKnassa
|
|
83
|
+
- @cg-hub18
|
|
83
84
|
- @ejhammond
|
|
84
85
|
- @ernestt
|
|
85
86
|
- @harshavardhan194
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.1.4-canary.
|
|
3
|
+
"version": "0.1.4-canary.f01eb10",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -75,12 +75,16 @@
|
|
|
75
75
|
"zod": "^4.4.3"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@astryxdesign/
|
|
79
|
-
"@astryxdesign/
|
|
80
|
-
"@astryxdesign/
|
|
81
|
-
"
|
|
78
|
+
"@astryxdesign/charts": "0.1.4-canary.f01eb10",
|
|
79
|
+
"@astryxdesign/core": "0.1.4-canary.f01eb10",
|
|
80
|
+
"@astryxdesign/lab": "0.1.4-canary.f01eb10",
|
|
81
|
+
"@astryxdesign/theme-neutral": "0.1.4-canary.f01eb10",
|
|
82
|
+
"gpt-tokenizer": "^3.4.0"
|
|
82
83
|
},
|
|
83
84
|
"peerDependenciesMeta": {
|
|
85
|
+
"@astryxdesign/charts": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
84
88
|
"@astryxdesign/core": {
|
|
85
89
|
"optional": true
|
|
86
90
|
},
|
|
@@ -92,10 +96,11 @@
|
|
|
92
96
|
}
|
|
93
97
|
},
|
|
94
98
|
"devDependencies": {
|
|
95
|
-
"@astryxdesign/
|
|
96
|
-
"@astryxdesign/
|
|
97
|
-
"@astryxdesign/
|
|
98
|
-
"
|
|
99
|
+
"@astryxdesign/charts": "0.1.4-canary.f01eb10",
|
|
100
|
+
"@astryxdesign/core": "0.1.4-canary.f01eb10",
|
|
101
|
+
"@astryxdesign/lab": "0.1.4-canary.f01eb10",
|
|
102
|
+
"@astryxdesign/theme-neutral": "0.1.4-canary.f01eb10",
|
|
103
|
+
"gpt-tokenizer": "^3.4.0"
|
|
99
104
|
},
|
|
100
105
|
"scripts": {
|
|
101
106
|
"astryx": "node bin/astryx.mjs",
|
package/src/api/doctor.mjs
CHANGED
|
@@ -115,10 +115,21 @@ function findThemePackages(cwd) {
|
|
|
115
115
|
return found;
|
|
116
116
|
}
|
|
117
117
|
for (const entry of entries) {
|
|
118
|
-
if (!entry.isDirectory()) continue;
|
|
119
118
|
if (!entry.name.startsWith('theme-')) continue;
|
|
119
|
+
const dir = path.join(scopeDir, entry.name);
|
|
120
|
+
// pnpm installs packages as symlinks into node_modules/.pnpm, and a
|
|
121
|
+
// symlink dirent reports isDirectory() as false — stat the target instead.
|
|
122
|
+
let isDir = entry.isDirectory();
|
|
123
|
+
if (!isDir && entry.isSymbolicLink()) {
|
|
124
|
+
try {
|
|
125
|
+
isDir = fs.statSync(dir).isDirectory();
|
|
126
|
+
} catch {
|
|
127
|
+
isDir = false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (!isDir) continue;
|
|
120
131
|
const name = `@astryxdesign/${entry.name}`;
|
|
121
|
-
found.push({name, version: pkgVersion(
|
|
132
|
+
found.push({name, version: pkgVersion(dir)});
|
|
122
133
|
}
|
|
123
134
|
return found;
|
|
124
135
|
}
|
|
@@ -99,5 +99,43 @@ describe('runCodemods — unified config codemod path', () => {
|
|
|
99
99
|
expect(fs.readFileSync(path.join(srcDir, 'a.ts'), 'utf-8')).toContain(
|
|
100
100
|
'const bar = 1',
|
|
101
101
|
);
|
|
102
|
+
// writtenFiles must be returned (consumed by upgrade.mjs to run the
|
|
103
|
+
// post-codemod formatting/lint hooks). Regression guard: it was previously
|
|
104
|
+
// built internally but omitted from the return object, so hooks received an
|
|
105
|
+
// empty file list and silently skipped, leaving codemod output unformatted.
|
|
106
|
+
expect(result.writtenFiles).toEqual([path.join(srcDir, 'a.ts')]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('returns writtenFiles for every changed file (post-codemod hook input)', async () => {
|
|
110
|
+
const srcDir = path.join(tmpDir, 'src');
|
|
111
|
+
fs.mkdirSync(srcDir);
|
|
112
|
+
fs.writeFileSync(path.join(srcDir, 'a.ts'), 'const foo = 1;\n');
|
|
113
|
+
fs.writeFileSync(path.join(srcDir, 'b.ts'), 'const foo = 2;\n');
|
|
114
|
+
fs.writeFileSync(path.join(srcDir, 'c.ts'), 'const untouched = 3;\n');
|
|
115
|
+
|
|
116
|
+
const versionManifests = [
|
|
117
|
+
{
|
|
118
|
+
version: '0.1.3',
|
|
119
|
+
transforms: [
|
|
120
|
+
{
|
|
121
|
+
name: 'synthetic-code-codemod',
|
|
122
|
+
meta: {title: 'Synthetic code codemod'},
|
|
123
|
+
transform: file => file.source.replace(/foo/g, 'bar'),
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
const result = await runCodemods(versionManifests, {
|
|
130
|
+
apply: true,
|
|
131
|
+
path: './src',
|
|
132
|
+
silent: true,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
expect(result.totalFilesChanged).toBe(2);
|
|
136
|
+
// Only the two files that actually changed are reported (not c.ts).
|
|
137
|
+
expect([...result.writtenFiles].sort()).toEqual(
|
|
138
|
+
[path.join(srcDir, 'a.ts'), path.join(srcDir, 'b.ts')].sort(),
|
|
139
|
+
);
|
|
102
140
|
});
|
|
103
141
|
});
|
package/src/codemods/runner.mjs
CHANGED
|
@@ -178,6 +178,7 @@ function toUnifiedEntry(transformEntry, version) {
|
|
|
178
178
|
* @param {string|undefined} options.codemod - Run only this specific transform
|
|
179
179
|
* @param {Set<string>} [options.skipCodemods] - Transform names to exclude
|
|
180
180
|
* @param {boolean} [options.silent] - Suppress all human-facing output (for --json)
|
|
181
|
+
* @returns {{totalFilesChanged: number, totalTransformsApplied: number, totalValidationBlocked: number, writtenFiles: string[], errors: Array, skippedOptional: Array}}
|
|
181
182
|
*/
|
|
182
183
|
export async function runCodemods(
|
|
183
184
|
versionManifests,
|
|
@@ -405,6 +406,7 @@ export async function runCodemods(
|
|
|
405
406
|
totalFilesChanged,
|
|
406
407
|
totalTransformsApplied,
|
|
407
408
|
totalValidationBlocked,
|
|
409
|
+
writtenFiles,
|
|
408
410
|
errors,
|
|
409
411
|
skippedOptional,
|
|
410
412
|
};
|
|
@@ -175,14 +175,85 @@ async function getKnownValues(componentName) {
|
|
|
175
175
|
return _knownValuesCache.get(componentName);
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Resolve `@astryxdesign/core`'s package root relative to the CLI package. Core
|
|
180
|
+
* and the CLI ship as siblings (`@astryxdesign/core`, `@astryxdesign/cli`), so
|
|
181
|
+
* `../../../core` from `src/commands/` reaches core whether installed from npm
|
|
182
|
+
* or run inside the monorepo. Returns null if it can't be found.
|
|
183
|
+
*/
|
|
184
|
+
function resolveCoreRoot() {
|
|
185
|
+
const cliDir = path.dirname(fileURLToPath(import.meta.url));
|
|
186
|
+
const coreRoot = path.resolve(cliDir, '../../../core');
|
|
187
|
+
return fs.existsSync(coreRoot) ? coreRoot : null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Read the type declarations `@astryxdesign/core/<Component>` exposes so we can
|
|
192
|
+
* check whether a given augmentation-target interface actually exists before
|
|
193
|
+
* generating a module augmentation against it.
|
|
194
|
+
*
|
|
195
|
+
* Reads the shipped `dist/<Component>/index.d.ts` (what a consumer's TypeScript
|
|
196
|
+
* actually sees), falling back to the `src/<Component>/index.ts` in the
|
|
197
|
+
* monorepo. Returns the file contents, or '' if nothing is found.
|
|
198
|
+
*/
|
|
199
|
+
const _componentDeclCache = new Map();
|
|
200
|
+
function readComponentDeclarations(pascalName) {
|
|
201
|
+
if (_componentDeclCache.has(pascalName)) {
|
|
202
|
+
return _componentDeclCache.get(pascalName);
|
|
203
|
+
}
|
|
204
|
+
let contents = '';
|
|
205
|
+
const coreRoot = resolveCoreRoot();
|
|
206
|
+
if (coreRoot) {
|
|
207
|
+
const candidates = [
|
|
208
|
+
path.join(coreRoot, 'dist', pascalName, 'index.d.ts'),
|
|
209
|
+
path.join(coreRoot, 'src', pascalName, 'index.ts'),
|
|
210
|
+
];
|
|
211
|
+
for (const file of candidates) {
|
|
212
|
+
try {
|
|
213
|
+
if (fs.existsSync(file)) {
|
|
214
|
+
contents = fs.readFileSync(file, 'utf-8');
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
} catch {
|
|
218
|
+
// ignore and try the next candidate
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
_componentDeclCache.set(pascalName, contents);
|
|
223
|
+
return contents;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Determine whether `@astryxdesign/core/<Component>` exports an interface named
|
|
228
|
+
* `interfaceName` that can be augmented via module augmentation.
|
|
229
|
+
*
|
|
230
|
+
* Only interfaces are extension points — closed literal-union types (e.g.
|
|
231
|
+
* `HeadingType`, `ButtonSize`) are NOT augmentable, so a generated augmentation
|
|
232
|
+
* against them is dead code. We check that the name is exported (directly or
|
|
233
|
+
* re-exported) as a type/interface.
|
|
234
|
+
*/
|
|
235
|
+
function componentHasAugmentableInterface(pascalName, interfaceName) {
|
|
236
|
+
const decl = readComponentDeclarations(pascalName);
|
|
237
|
+
if (!decl) return false;
|
|
238
|
+
// Word-boundary match so `ButtonVariantMap` doesn't match `XButtonVariantMap`.
|
|
239
|
+
const re = new RegExp(`\\b${interfaceName}\\b`);
|
|
240
|
+
return re.test(decl);
|
|
241
|
+
}
|
|
242
|
+
|
|
178
243
|
/**
|
|
179
244
|
* Generate TypeScript declaration content with module augmentation for custom
|
|
180
245
|
* component prop values found in the theme's `components` keys. Reads known
|
|
181
246
|
* values from doc files to filter out base prop values.
|
|
182
247
|
*
|
|
183
|
-
* Interface naming convention:
|
|
184
|
-
* banner + status →
|
|
185
|
-
* button + variant →
|
|
248
|
+
* Interface naming convention: PascalCase(component) + PascalCase(prop) + Map
|
|
249
|
+
* banner + status → BannerStatusMap
|
|
250
|
+
* button + variant → ButtonVariantMap
|
|
251
|
+
*
|
|
252
|
+
* An augmentation is only emitted when `@astryxdesign/core/<Component>` actually
|
|
253
|
+
* exports a matching interface. Props backed by closed literal-union types
|
|
254
|
+
* (e.g. Button `size`, Heading `type`/`level`) have no augmentation point, so
|
|
255
|
+
* generating a `declare module` block for them would be dead code — those are
|
|
256
|
+
* skipped.
|
|
186
257
|
*
|
|
187
258
|
* @param {object} themeDef - Theme definition (resolved by defineTheme)
|
|
188
259
|
* @returns {Promise<string|null>} TypeScript declaration content, or null if no augmentations needed
|
|
@@ -234,7 +305,14 @@ async function generateVariantDeclarationsAsync(themeDef) {
|
|
|
234
305
|
const pascal = toPascalCase(component);
|
|
235
306
|
const propPascal = prop.charAt(0).toUpperCase() + prop.slice(1);
|
|
236
307
|
const modulePath = `@astryxdesign/core/${pascal}`;
|
|
237
|
-
const interfaceName =
|
|
308
|
+
const interfaceName = `${pascal}${propPascal}Map`;
|
|
309
|
+
|
|
310
|
+
// Only augment interfaces that actually exist as an extension point in
|
|
311
|
+
// core. Props backed by closed literal-union types (e.g. Button `size`,
|
|
312
|
+
// Heading `type`/`level`) have no `*Map` interface — a `declare module`
|
|
313
|
+
// block against a non-existent interface just creates a new, unused
|
|
314
|
+
// interface and never extends the component's prop union, so skip it.
|
|
315
|
+
if (!componentHasAugmentableInterface(pascal, interfaceName)) continue;
|
|
238
316
|
|
|
239
317
|
sections.push(`declare module '${modulePath}' {`);
|
|
240
318
|
sections.push(` interface ${interfaceName} {`);
|
|
@@ -247,6 +325,13 @@ async function generateVariantDeclarationsAsync(themeDef) {
|
|
|
247
325
|
}
|
|
248
326
|
}
|
|
249
327
|
|
|
328
|
+
// If every custom value targeted a non-augmentable prop, there's nothing to
|
|
329
|
+
// emit beyond the header — return null so no `.variants.d.ts` is written.
|
|
330
|
+
const hasEmittedAugmentation = sections.some(line =>
|
|
331
|
+
line.startsWith('declare module'),
|
|
332
|
+
);
|
|
333
|
+
if (!hasEmittedAugmentation) return null;
|
|
334
|
+
|
|
250
335
|
return sections.join('\n');
|
|
251
336
|
}
|
|
252
337
|
|
|
@@ -433,13 +518,21 @@ ${iconReExport}`;
|
|
|
433
518
|
/**
|
|
434
519
|
* Generate TypeScript declarations for a built theme module.
|
|
435
520
|
*/
|
|
436
|
-
function generateBuiltTypes(themeDef, iconInfo) {
|
|
521
|
+
function generateBuiltTypes(themeDef, iconInfo, variantsFileName) {
|
|
437
522
|
const iconType = iconInfo
|
|
438
523
|
? `import type { IconRegistry } from '@astryxdesign/core/Icon';
|
|
439
524
|
export declare const ${iconInfo.exportName}: IconRegistry;
|
|
440
525
|
`
|
|
441
526
|
: '';
|
|
442
|
-
|
|
527
|
+
// Pull in the generated custom-variant augmentations so that importing the
|
|
528
|
+
// theme's types also loads the module augmentations (otherwise the
|
|
529
|
+
// `.variants.d.ts` is emitted but never referenced, and the custom variants
|
|
530
|
+
// never widen the component prop unions for consumers).
|
|
531
|
+
const variantsRef = variantsFileName
|
|
532
|
+
? `/// <reference path="./${variantsFileName}" />
|
|
533
|
+
`
|
|
534
|
+
: '';
|
|
535
|
+
return `${variantsRef}import type { DefinedTheme } from '@astryxdesign/core/theme';
|
|
443
536
|
${iconType}export declare const ${toIdentifier(themeDef.name)}Theme: DefinedTheme;
|
|
444
537
|
`;
|
|
445
538
|
}
|
|
@@ -894,19 +987,23 @@ export function registerTheme(program) {
|
|
|
894
987
|
|
|
895
988
|
const iconInfo = extractIconInfo(filePath);
|
|
896
989
|
|
|
897
|
-
//
|
|
898
|
-
|
|
899
|
-
const jsContent = generatedHeader(sourceRelative, 'js', buildCommand) + generateBuiltModule(resolvedTheme || themeDef, iconInfo);
|
|
900
|
-
const dtsContent = generatedHeader(sourceRelative, 'ts', buildCommand) + generateBuiltTypes(themeDef, iconInfo);
|
|
901
|
-
|
|
902
|
-
// Type augmentation .d.ts if theme has custom prop values
|
|
990
|
+
// Type augmentation .d.ts if theme has custom prop values. Computed
|
|
991
|
+
// before the main .d.ts so the latter can reference it (see below).
|
|
903
992
|
const augmentationSource = resolvedTheme || themeDef;
|
|
904
993
|
const variantDecl = await generateVariantDeclarationsAsync(augmentationSource);
|
|
905
|
-
const
|
|
994
|
+
const variantsFileName = variantDecl ? `${baseName}.variants.d.ts` : null;
|
|
995
|
+
const variantDtsPath = variantDecl ? path.join(outDir, variantsFileName) : null;
|
|
906
996
|
const variantContent = variantDecl
|
|
907
997
|
? generatedHeader(sourceRelative, 'ts', buildCommand) + variantDecl
|
|
908
998
|
: null;
|
|
909
999
|
|
|
1000
|
+
// Generate all file contents in memory first. The main .d.ts references
|
|
1001
|
+
// the variants file (when present) via a triple-slash directive so
|
|
1002
|
+
// importing the theme also loads the custom-variant augmentations.
|
|
1003
|
+
const cssContent = generatedHeader(sourceRelative, 'css', buildCommand) + css;
|
|
1004
|
+
const jsContent = generatedHeader(sourceRelative, 'js', buildCommand) + generateBuiltModule(resolvedTheme || themeDef, iconInfo);
|
|
1005
|
+
const dtsContent = generatedHeader(sourceRelative, 'ts', buildCommand) + generateBuiltTypes(themeDef, iconInfo, variantsFileName);
|
|
1006
|
+
|
|
910
1007
|
// Atomic-ish write: stage every file as `<dest>.tmp`, then rename
|
|
911
1008
|
// each into place. If any stage step fails we clean up partials and
|
|
912
1009
|
// exit; if a rename fails mid-way we still have the originals (or
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Regression test for the custom-variant type augmentations emitted by
|
|
5
|
+
* `astryx theme build` (#3391 companion: #3371).
|
|
6
|
+
*
|
|
7
|
+
* When a theme declares a custom component prop value (e.g.
|
|
8
|
+
* `button['variant:accentOutline']`), the build emits a `<name>.variants.d.ts`
|
|
9
|
+
* with a module augmentation so the custom value type-checks. This suite pins
|
|
10
|
+
* the two bugs that made that augmentation dead code:
|
|
11
|
+
*
|
|
12
|
+
* 1. The augmentation targeted a non-existent, `XDS`-prefixed interface
|
|
13
|
+
* (`XDSButtonVariantMap`) instead of core's real `ButtonVariantMap`, so it
|
|
14
|
+
* created a new unused interface and never widened the prop union.
|
|
15
|
+
* 2. Props with no augmentation point (closed literal-union types such as
|
|
16
|
+
* Button `size` or Heading `type`/`level`) still got a `declare module`
|
|
17
|
+
* block against a `*Map` interface that doesn't exist.
|
|
18
|
+
* 3. The generated `.variants.d.ts` was never referenced by the main
|
|
19
|
+
* `<name>.d.ts`, so even a correct augmentation never loaded.
|
|
20
|
+
*
|
|
21
|
+
* Building `astryx theme build` requires a compiled @astryxdesign/core, so this
|
|
22
|
+
* suite builds core once in beforeAll (mirrors build-theme.prose.test.mjs).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {describe, it, expect, beforeAll, beforeEach, afterEach} from 'vitest';
|
|
26
|
+
import {execFileSync} from 'node:child_process';
|
|
27
|
+
import * as fs from 'node:fs';
|
|
28
|
+
import * as path from 'node:path';
|
|
29
|
+
import * as os from 'node:os';
|
|
30
|
+
import {fileURLToPath} from 'node:url';
|
|
31
|
+
|
|
32
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
33
|
+
const CLI_BIN = path.resolve(__dirname, '../../bin/astryx.mjs');
|
|
34
|
+
const REPO_ROOT = path.resolve(__dirname, '../../../..');
|
|
35
|
+
const CORE_THEME_ENTRY = path.join(
|
|
36
|
+
REPO_ROOT,
|
|
37
|
+
'packages/core/dist/theme/index.js',
|
|
38
|
+
);
|
|
39
|
+
// The fix reads core's shipped component declarations to decide whether an
|
|
40
|
+
// interface is augmentable; those .d.ts files come from the same core build.
|
|
41
|
+
const CORE_BUTTON_DTS = path.join(
|
|
42
|
+
REPO_ROOT,
|
|
43
|
+
'packages/core/dist/Button/index.d.ts',
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
function runCli(args, cwd) {
|
|
47
|
+
try {
|
|
48
|
+
const out = execFileSync('node', [CLI_BIN, ...args], {
|
|
49
|
+
cwd,
|
|
50
|
+
encoding: 'utf-8',
|
|
51
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
52
|
+
env: {...process.env, FORCE_COLOR: '0'},
|
|
53
|
+
});
|
|
54
|
+
return {code: 0, stdout: out, stderr: ''};
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return {
|
|
57
|
+
code: e.status ?? 1,
|
|
58
|
+
stdout: e.stdout?.toString() ?? '',
|
|
59
|
+
stderr: e.stderr?.toString() ?? '',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function writeTheme(dir, contents) {
|
|
65
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
66
|
+
const file = path.join(dir, 'variants-theme.mjs');
|
|
67
|
+
fs.writeFileSync(file, contents);
|
|
68
|
+
return file;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
beforeAll(() => {
|
|
72
|
+
if (!fs.existsSync(CORE_THEME_ENTRY) || !fs.existsSync(CORE_BUTTON_DTS)) {
|
|
73
|
+
execFileSync('pnpm', ['-F', '@astryxdesign/core', 'build'], {
|
|
74
|
+
cwd: REPO_ROOT,
|
|
75
|
+
stdio: 'pipe',
|
|
76
|
+
timeout: 180_000,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}, 200_000);
|
|
80
|
+
|
|
81
|
+
let tmpDir;
|
|
82
|
+
beforeEach(() => {
|
|
83
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-build-theme-variants-'));
|
|
84
|
+
});
|
|
85
|
+
afterEach(() => {
|
|
86
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('theme build custom-variant augmentations', () => {
|
|
90
|
+
it('targets the real (un-prefixed) core interface for a custom variant', () => {
|
|
91
|
+
const themeFile = writeTheme(
|
|
92
|
+
tmpDir,
|
|
93
|
+
`export default {
|
|
94
|
+
name: 'variants-theme',
|
|
95
|
+
tokens: { '--color-bg': '#fff' },
|
|
96
|
+
components: {
|
|
97
|
+
button: { 'variant:accentOutline': { backgroundColor: 'transparent' } },
|
|
98
|
+
},
|
|
99
|
+
};\n`,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const result = runCli(
|
|
103
|
+
['theme', 'build', path.relative(tmpDir, themeFile)],
|
|
104
|
+
tmpDir,
|
|
105
|
+
);
|
|
106
|
+
expect(result.code).toBe(0);
|
|
107
|
+
|
|
108
|
+
const variantsPath = path.join(tmpDir, 'variants-theme.variants.d.ts');
|
|
109
|
+
expect(fs.existsSync(variantsPath)).toBe(true);
|
|
110
|
+
const dts = fs.readFileSync(variantsPath, 'utf-8');
|
|
111
|
+
|
|
112
|
+
// Targets core's actual augmentation point…
|
|
113
|
+
expect(dts).toContain("declare module '@astryxdesign/core/Button'");
|
|
114
|
+
expect(dts).toMatch(/interface ButtonVariantMap\b/);
|
|
115
|
+
expect(dts).toContain("'accentOutline': true;");
|
|
116
|
+
// …and NOT the old, non-existent XDS-prefixed interface.
|
|
117
|
+
expect(dts).not.toMatch(/XDSButtonVariantMap/);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('skips props with no augmentation point (Button size, Heading type)', () => {
|
|
121
|
+
const themeFile = writeTheme(
|
|
122
|
+
tmpDir,
|
|
123
|
+
`export default {
|
|
124
|
+
name: 'variants-theme',
|
|
125
|
+
tokens: { '--color-bg': '#fff' },
|
|
126
|
+
components: {
|
|
127
|
+
button: {
|
|
128
|
+
'variant:accentOutline': { backgroundColor: 'transparent' },
|
|
129
|
+
'size:jumbo': { paddingBlock: '40px' },
|
|
130
|
+
},
|
|
131
|
+
heading: { 'type:hero': { fontSize: '80px' } },
|
|
132
|
+
},
|
|
133
|
+
};\n`,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const result = runCli(
|
|
137
|
+
['theme', 'build', path.relative(tmpDir, themeFile)],
|
|
138
|
+
tmpDir,
|
|
139
|
+
);
|
|
140
|
+
expect(result.code).toBe(0);
|
|
141
|
+
|
|
142
|
+
const variantsPath = path.join(tmpDir, 'variants-theme.variants.d.ts');
|
|
143
|
+
expect(fs.existsSync(variantsPath)).toBe(true);
|
|
144
|
+
const dts = fs.readFileSync(variantsPath, 'utf-8');
|
|
145
|
+
|
|
146
|
+
// The augmentable variant is emitted…
|
|
147
|
+
expect(dts).toMatch(/interface ButtonVariantMap\b/);
|
|
148
|
+
// …but closed literal-union props get no dead augmentation.
|
|
149
|
+
expect(dts).not.toMatch(/ButtonSizeMap/);
|
|
150
|
+
expect(dts).not.toMatch(/HeadingTypeMap/);
|
|
151
|
+
expect(dts).not.toContain("declare module '@astryxdesign/core/Heading'");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('does not emit a .variants.d.ts when every custom value is non-augmentable', () => {
|
|
155
|
+
const themeFile = writeTheme(
|
|
156
|
+
tmpDir,
|
|
157
|
+
`export default {
|
|
158
|
+
name: 'variants-theme',
|
|
159
|
+
tokens: { '--color-bg': '#fff' },
|
|
160
|
+
components: {
|
|
161
|
+
button: { 'size:jumbo': { paddingBlock: '40px' } },
|
|
162
|
+
},
|
|
163
|
+
};\n`,
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const result = runCli(
|
|
167
|
+
['theme', 'build', path.relative(tmpDir, themeFile)],
|
|
168
|
+
tmpDir,
|
|
169
|
+
);
|
|
170
|
+
expect(result.code).toBe(0);
|
|
171
|
+
expect(
|
|
172
|
+
fs.existsSync(path.join(tmpDir, 'variants-theme.variants.d.ts')),
|
|
173
|
+
).toBe(false);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('references the variants file from the main .d.ts so the augmentation loads', () => {
|
|
177
|
+
const themeFile = writeTheme(
|
|
178
|
+
tmpDir,
|
|
179
|
+
`export default {
|
|
180
|
+
name: 'variants-theme',
|
|
181
|
+
tokens: { '--color-bg': '#fff' },
|
|
182
|
+
components: {
|
|
183
|
+
button: { 'variant:accentOutline': { backgroundColor: 'transparent' } },
|
|
184
|
+
},
|
|
185
|
+
};\n`,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const result = runCli(
|
|
189
|
+
['theme', 'build', path.relative(tmpDir, themeFile)],
|
|
190
|
+
tmpDir,
|
|
191
|
+
);
|
|
192
|
+
expect(result.code).toBe(0);
|
|
193
|
+
|
|
194
|
+
const dts = fs.readFileSync(
|
|
195
|
+
path.join(tmpDir, 'variants-theme.d.ts'),
|
|
196
|
+
'utf-8',
|
|
197
|
+
);
|
|
198
|
+
// A triple-slash reference to the variants file, so importing the theme's
|
|
199
|
+
// types also loads the module augmentation.
|
|
200
|
+
expect(dts).toMatch(
|
|
201
|
+
/\/\/\/\s*<reference path="\.\/variants-theme\.variants\.d\.ts"\s*\/>/,
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -63,6 +63,33 @@ function installPkg(name, version = '1.0.0') {
|
|
|
63
63
|
return dir;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Mirror pnpm's layout: the real package lives under node_modules/.pnpm and
|
|
68
|
+
* the entry in the scope directory is a symlink to it.
|
|
69
|
+
*/
|
|
70
|
+
function installPkgPnpmStyle(name, version = '1.0.0') {
|
|
71
|
+
const realDir = path.join(
|
|
72
|
+
tmpDir,
|
|
73
|
+
'node_modules',
|
|
74
|
+
'.pnpm',
|
|
75
|
+
`${name.replace('/', '+')}@${version}`,
|
|
76
|
+
'node_modules',
|
|
77
|
+
...name.split('/'),
|
|
78
|
+
);
|
|
79
|
+
fs.mkdirSync(realDir, {recursive: true});
|
|
80
|
+
fs.writeFileSync(
|
|
81
|
+
path.join(realDir, 'package.json'),
|
|
82
|
+
JSON.stringify({name, version, main: 'index.js'}),
|
|
83
|
+
);
|
|
84
|
+
fs.writeFileSync(path.join(realDir, 'index.js'), 'module.exports = {};');
|
|
85
|
+
const linkPath = path.join(tmpDir, 'node_modules', ...name.split('/'));
|
|
86
|
+
fs.mkdirSync(path.dirname(linkPath), {recursive: true});
|
|
87
|
+
// 'junction' keeps this working on Windows without elevated permissions;
|
|
88
|
+
// it is ignored on posix.
|
|
89
|
+
fs.symlinkSync(realDir, linkPath, 'junction');
|
|
90
|
+
return linkPath;
|
|
91
|
+
}
|
|
92
|
+
|
|
66
93
|
function find(checks, id) {
|
|
67
94
|
return checks.find(c => c.id === id);
|
|
68
95
|
}
|
|
@@ -119,6 +146,13 @@ describe('doctor — individual checks', () => {
|
|
|
119
146
|
expect(res.status).toBe('pass');
|
|
120
147
|
});
|
|
121
148
|
|
|
149
|
+
it('themes: detects pnpm-style symlinked theme packages (#3530)', () => {
|
|
150
|
+
installPkgPnpmStyle('@astryxdesign/theme-neutral', '0.1.2');
|
|
151
|
+
const res = checkThemes({cwd: tmpDir, configTheme: 'default'});
|
|
152
|
+
expect(res.status).toBe('pass');
|
|
153
|
+
expect(res.message).toContain('@astryxdesign/theme-neutral');
|
|
154
|
+
});
|
|
155
|
+
|
|
122
156
|
it('config: INFO when no astryx.config.mjs', async () => {
|
|
123
157
|
const res = await checkConfig({cwd: tmpDir, configPath: null});
|
|
124
158
|
expect(res.status).toBe('info');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */
|
|
4
|
+
export const doc = {
|
|
5
|
+
type: 'block',
|
|
6
|
+
exampleFor: 'BaseTypeahead',
|
|
7
|
+
name: 'BaseTypeahead — Custom Search Bar',
|
|
8
|
+
displayName: 'BaseTypeahead — Custom Search Bar',
|
|
9
|
+
description:
|
|
10
|
+
'BaseTypeahead embedded inside a custom-styled wrapper. The wrapper provides its own border and icon chrome; anchorRef positions the dropdown relative to it. Use this pattern when Typeahead\'s built-in field layout does not fit your composition.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 16 / 9,
|
|
13
|
+
componentsUsed: ['BaseTypeahead', 'Icon', 'Layout', 'Text'],
|
|
14
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useRef, useState} from 'react';
|
|
6
|
+
import {BaseTypeahead, createStaticSource} from '@astryxdesign/core/Typeahead';
|
|
7
|
+
import type {SearchableItem} from '@astryxdesign/core/Typeahead';
|
|
8
|
+
import {Icon} from '@astryxdesign/core/Icon';
|
|
9
|
+
import {HStack, VStack} from '@astryxdesign/core/Layout';
|
|
10
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
11
|
+
import {MagnifyingGlassIcon} from '@heroicons/react/24/outline';
|
|
12
|
+
|
|
13
|
+
const frameworks: SearchableItem[] = [
|
|
14
|
+
{id: 'react', label: 'React'},
|
|
15
|
+
{id: 'vue', label: 'Vue'},
|
|
16
|
+
{id: 'angular', label: 'Angular'},
|
|
17
|
+
{id: 'svelte', label: 'Svelte'},
|
|
18
|
+
{id: 'solid', label: 'SolidJS'},
|
|
19
|
+
{id: 'remix', label: 'Remix'},
|
|
20
|
+
{id: 'next', label: 'Next.js'},
|
|
21
|
+
{id: 'nuxt', label: 'Nuxt'},
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const source = createStaticSource(frameworks);
|
|
25
|
+
|
|
26
|
+
export default function BaseTypeaheadCustomSearch() {
|
|
27
|
+
const [value, setValue] = useState<SearchableItem | null>(null);
|
|
28
|
+
const wrapperRef = useRef<HTMLElement>(null);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<VStack gap={3} style={{width: 320}}>
|
|
32
|
+
<HStack
|
|
33
|
+
ref={wrapperRef}
|
|
34
|
+
gap={2}
|
|
35
|
+
vAlign="center"
|
|
36
|
+
style={{
|
|
37
|
+
border: '1px solid var(--color-border)',
|
|
38
|
+
borderRadius: 'var(--radius-control)',
|
|
39
|
+
padding: '6px 10px',
|
|
40
|
+
background: 'var(--color-surface)',
|
|
41
|
+
}}>
|
|
42
|
+
<Icon icon={MagnifyingGlassIcon} size="sm" color="secondary" />
|
|
43
|
+
<BaseTypeahead
|
|
44
|
+
searchSource={source}
|
|
45
|
+
value={value}
|
|
46
|
+
onChange={setValue}
|
|
47
|
+
anchorRef={wrapperRef}
|
|
48
|
+
placeholder="Search frameworks…"
|
|
49
|
+
hasEntriesOnFocus
|
|
50
|
+
debounceMs={0}
|
|
51
|
+
/>
|
|
52
|
+
</HStack>
|
|
53
|
+
<Text type="supporting" color="secondary">
|
|
54
|
+
{value != null ? `Selected: ${value.label}` : 'No selection'}
|
|
55
|
+
</Text>
|
|
56
|
+
</VStack>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */
|
|
4
|
+
export const doc = {
|
|
5
|
+
type: 'block',
|
|
6
|
+
exampleFor: 'CodeBlock',
|
|
7
|
+
name: 'Code — Terminal',
|
|
8
|
+
displayName: 'Code — Terminal',
|
|
9
|
+
description:
|
|
10
|
+
'A dark terminal-style command block: a bash CodeBlock wrapped in SyntaxTheme with the GitHub Dark preset, copy button on, and no line numbers. Use for shell sessions or CLI output that should read as a terminal even on light pages. Reach for a dark syntax preset instead of hand-rolling a dark box with custom CSS.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 16 / 9,
|
|
13
|
+
componentsUsed: ['CodeBlock', 'SyntaxTheme'],
|
|
14
|
+
};
|