@astryxdesign/cli 0.7.0-canary.21875fc → 0.7.0-canary.291c4e9
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/README.md +79 -84
- package/api/build/build.mjs +9 -0
- package/api/component/_adapter.d.mts +2 -0
- package/api/component/_adapter.mjs +3 -1
- package/api/component/component.doc.mjs +5 -1
- package/api/docs/compiled-topics.test.mjs +16 -0
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.test.mjs +28 -0
- package/api/doctor/theme-checks.mjs +10 -10
- package/api/doctor/theme-checks.test.mjs +5 -4
- package/api/gap-report/gap-report.doc.mjs +1 -1
- package/api/gap-report/gap-report.mjs +15 -0
- package/api/gap-report/gap-report.test.mjs +1 -1
- package/api/index.d.mts +0 -2
- package/api/index.mjs +0 -2
- package/api/init/init.doc.mjs +5 -1
- package/api/init/init.mjs +22 -0
- package/api/init/init.type.d.mts +4 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/remove/remove.mjs +8 -3
- package/api/init/remove/remove.test.mjs +12 -0
- package/api/init/run/run.d.mts +1 -1
- package/api/init/run/run.mjs +3 -3
- package/api/integration/pack-check.test.mjs +8 -0
- package/api/integration/validate-integration.d.mts +4 -0
- package/api/integration/validate-integration.mjs +5 -2
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/json/index.ts +0 -1
- package/api/search/search.doc.mjs +1 -1
- package/api/search/search.mjs +1 -1
- package/api/search/search.test.mjs +1 -1
- package/api/search/search.type.d.mts +1 -1
- package/api/search/search.type.mjs +1 -1
- package/api/template/list/list.mjs +23 -2
- package/api/template/list/list.test.mjs +52 -0
- package/api/template/template-integration.test.mjs +37 -100
- package/api/template/template.doc.mjs +8 -3
- package/api/template/template.mjs +45 -0
- package/api/template/template.type.mjs +1 -1
- package/api/theme/_adapter.mjs +3 -3
- package/api/theme/add/add.d.mts +11 -5
- package/api/theme/add/add.mjs +19 -192
- package/api/theme/add/add.test.mjs +68 -258
- package/api/theme/add/add.types.test.mjs +0 -1
- package/api/theme/build/build.d.mts +3 -4
- package/api/theme/build/build.mjs +26 -65
- package/api/theme/build/build.test.mjs +11 -24
- package/api/theme/build/family.mjs +1 -1
- package/api/theme/eject/eject.copy-compat.test.mjs +168 -0
- package/api/theme/integration-themes.test.mjs +3 -3
- package/api/theme/remove/remove.test.mjs +1 -1
- package/api/theme/targets/targets.test.mjs +0 -4
- package/api/theme/template/template.mjs +1 -1
- package/api/theme/theme.type.d.mts +1 -30
- package/api/theme/theme.type.mjs +3 -13
- package/api/theme/themeAdd.doc.mjs +19 -27
- package/api/theme/themeTargets.doc.mjs +3 -4
- package/api/theme/themeTemplate.doc.mjs +1 -1
- package/api/theme/use/use.test.mjs +1 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.mjs +19 -0
- package/assets/codemods/transforms/next/__tests__/migrate-deprecated-theme-surface.test.mjs +322 -0
- package/assets/codemods/transforms/next/__tests__/migrate-field-input-styling.test.mjs +108 -0
- package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
- package/assets/codemods/transforms/next/index.mjs +27 -1
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface-v0.6-data.mjs +229 -0
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface.mjs +624 -0
- package/assets/codemods/transforms/next/migrate-field-input-styling.mjs +198 -0
- package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +38 -18
- package/assets/docs/author-a-theme.doc.mjs +5 -5
- package/assets/docs/getting-started.doc.mjs +2 -2
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +2 -2
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
- package/assets/docs/tree/fonts-and-assets.doc.mjs +3 -3
- package/assets/docs/tree/styling-advanced.doc.mjs +21 -14
- package/assets/docs/tree/themes.doc.mjs +1 -1
- package/assets/docs/tree/tokens-data.doc.mjs +2 -2
- package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +2 -2
- package/assets/docs/tree/versioning.doc.mjs +1 -4
- package/assets/docs/use-a-theme.doc.mjs +16 -16
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorShowcase.tsx +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorTreeSearch.tsx +1 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorClearable.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +2 -2
- package/assets/templates/blocks/components/Selector/SelectorShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorWithSections.tsx +1 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionBasic.tsx +1 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderWithMarks.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +4 -4
- package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -1
- package/assets/templates/pages/canvas-editor/page.tsx +2 -2
- package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
- package/assets/templates/pages/payment-form/page.tsx +1 -1
- package/assets/templates/pages/table-filter/page.tsx +3 -3
- package/assets/templates/pages/theme-showcase/page.tsx +2 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +10 -9
- package/authoring/debug/type.ts +2 -2
- package/authoring/doctypes/base/type.ts +0 -9
- package/authoring/integration/integration.doc.mjs +1 -1
- package/clients/cli/command-result-coverage.test.mjs +1 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +4 -0
- package/clients/cli/commands/build-theme.ascii-output.test.mjs +35 -8
- package/clients/cli/commands/build-theme.color-scheme.test.mjs +10 -6
- package/clients/cli/commands/build-theme.data-tokens.test.mjs +23 -75
- package/clients/cli/commands/build-theme.mjs +31 -67
- package/clients/cli/commands/build-theme.registry.test.mjs +0 -10
- package/clients/cli/commands/build.doc.mjs +1 -1
- package/clients/cli/commands/build.mjs +1 -1
- package/clients/cli/commands/component-ownership.test.mjs +2 -2
- package/clients/cli/commands/debug-result-summary.test.mjs +0 -16
- package/clients/cli/commands/discover.mjs +2 -1
- package/clients/cli/commands/doctor.mjs +5 -2
- package/clients/cli/commands/empty-argument.test.mjs +16 -0
- package/clients/cli/commands/gap-report.doc.mjs +1 -1
- package/clients/cli/commands/gap-report.test.mjs +2 -2
- package/clients/cli/commands/init.doc.mjs +4 -4
- package/clients/cli/commands/init.flag-help.test.mjs +7 -10
- package/clients/cli/commands/init.next-steps.test.mjs +1 -1
- package/clients/cli/commands/integration.mjs +2 -1
- package/clients/cli/commands/option-pair-refusals.test.mjs +37 -0
- package/clients/cli/commands/search.test.mjs +1 -1
- package/clients/cli/commands/silent-success-refusals.test.mjs +15 -0
- package/clients/cli/commands/swizzle.mjs +4 -1
- package/clients/cli/commands/template.doc.mjs +4 -4
- package/clients/cli/commands/template.flag-help.test.mjs +18 -11
- package/clients/cli/commands/template.mjs +7 -1
- package/clients/cli/commands/text-json-parity.test.mjs +0 -17
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +142 -49
- package/clients/cli/commands/theme-add.doc.mjs +10 -17
- package/clients/cli/commands/theme-list.behavior.test.mjs +2 -1
- package/clients/cli/commands/theme-targets.behavior.test.mjs +8 -6
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +2 -2
- package/clients/cli/commands/upgrade.doc.mjs +1 -1
- package/clients/cli/commands/upgrade.flag-help.test.mjs +7 -11
- package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +67 -0
- package/clients/cli/index.mjs +0 -4
- package/clients/cli/lib/cli-error.mjs +19 -0
- package/clients/cli/lib/component-format.mjs +111 -57
- package/clients/cli/lib/component-format.test.mjs +28 -39
- package/clients/cli/lib/doc-text-ascii.test.mjs +5 -2
- package/clients/cli/lib/exit-codes.test.mjs +0 -7
- package/clients/cli/lib/json-shim.test.mjs +0 -24
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +6 -1
- package/foundation/agent-docs/app-theme-workflow.test.mjs +3 -0
- package/foundation/config/theme-state.mjs +3 -3
- package/foundation/debug/debug-fields.test.mjs +13 -35
- package/foundation/debug/event.mjs +13 -78
- package/foundation/debug/privacy-contract.test.mjs +20 -12
- package/foundation/debug/redact.d.mts +2 -2
- package/foundation/debug/redact.mjs +2 -2
- package/foundation/discovery/template-needs.mjs +93 -11
- package/foundation/discovery/template-needs.test.mjs +106 -3
- package/foundation/discovery/theme-imports.mjs +1 -1
- package/foundation/discovery/theming-targets.d.mts +1 -20
- package/foundation/discovery/theming-targets.mjs +1 -38
- package/foundation/discovery/theming-targets.test.mjs +9 -175
- package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
- package/foundation/env/package-manager.d.mts +13 -0
- package/foundation/env/package-manager.mjs +106 -63
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +11 -31
- package/foundation/response/response-types.doc.test.mjs +36 -14
- package/foundation/response/response.doc.mjs +1 -1
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/browser.mjs +2 -2
- package/foundation/xle/expand.mjs +1 -1
- package/foundation/xle/print.mjs +1 -1
- package/package.json +9 -9
- package/api/layout/_adapter.d.mts +0 -34
- package/api/layout/_adapter.mjs +0 -148
- package/api/layout/check/check.d.mts +0 -17
- package/api/layout/check/check.mjs +0 -41
- package/api/layout/expand/expand.d.mts +0 -23
- package/api/layout/expand/expand.mjs +0 -161
- package/api/layout/expand/expand.path-safety.test.mjs +0 -53
- package/api/layout/expand/expand.receipt.test.mjs +0 -74
- package/api/layout/grammar/grammar.d.mts +0 -14
- package/api/layout/grammar/grammar.mjs +0 -88
- package/api/layout/layout.d.mts +0 -6
- package/api/layout/layout.mjs +0 -17
- package/api/layout/layout.test.mjs +0 -297
- package/api/layout/layout.type.d.mts +0 -90
- package/api/layout/layout.type.mjs +0 -104
- package/api/layout/layoutCheck.doc.d.mts +0 -11
- package/api/layout/layoutCheck.doc.mjs +0 -85
- package/api/layout/layoutExpand.doc.d.mts +0 -11
- package/api/layout/layoutExpand.doc.mjs +0 -107
- package/api/layout/layoutGrammar.doc.d.mts +0 -11
- package/api/layout/layoutGrammar.doc.mjs +0 -57
- package/api/theme/add/add.binary.test.mjs +0 -157
- package/api/theme/add/add.rollback.test.mjs +0 -158
- package/api/theme/add/add.staging.test.mjs +0 -83
- package/clients/cli/commands/layout-check.doc.mjs +0 -67
- package/clients/cli/commands/layout-expand.doc.mjs +0 -87
- package/clients/cli/commands/layout-grammar.doc.mjs +0 -32
- package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +0 -140
- package/clients/cli/commands/layout.doc.mjs +0 -36
- package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
- package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
- package/clients/cli/commands/layout.expand-receipt.test.mjs +0 -94
- package/clients/cli/commands/layout.mjs +0 -327
- package/clients/cli/commands/layout.path-help.test.mjs +0 -33
- package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
- package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import jscodeshift from 'jscodeshift';
|
|
5
|
+
import manifest from '../index.mjs';
|
|
6
|
+
import transform, {
|
|
7
|
+
DEPRECATED_THEME_TARGETS,
|
|
8
|
+
} from '../migrate-deprecated-theme-surface.mjs';
|
|
9
|
+
|
|
10
|
+
const j = jscodeshift.withParser('tsx');
|
|
11
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
12
|
+
|
|
13
|
+
const IMPORT = "import {defineTheme} from '@astryxdesign/core/theme';\n";
|
|
14
|
+
|
|
15
|
+
function apply(source, filePath = 'theme.ts') {
|
|
16
|
+
return transform({source, path: filePath}, api) ?? source;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const EXPECTED_TARGETS = {
|
|
20
|
+
'base-table': 'table',
|
|
21
|
+
checkbox: 'checkbox-indicator',
|
|
22
|
+
codeblock: 'code-block',
|
|
23
|
+
'codeblock-copy-button': 'code-block-copy-button',
|
|
24
|
+
'codeblock-header': 'code-block-header',
|
|
25
|
+
'codeblock-title': 'code-block-title',
|
|
26
|
+
'date-input-clear-icon': 'input-clear-icon',
|
|
27
|
+
'date-range-input-clear-icon': 'input-clear-icon',
|
|
28
|
+
hovercard: 'hover-card',
|
|
29
|
+
'multi-selector-clear-icon': 'input-clear-icon',
|
|
30
|
+
navicon: 'nav-icon',
|
|
31
|
+
'popover-surface': 'popover',
|
|
32
|
+
progressbar: 'progress-bar',
|
|
33
|
+
'progressbar-fill': 'progress-bar-fill',
|
|
34
|
+
'progressbar-mark': 'progress-bar-mark',
|
|
35
|
+
'progressbar-track': 'progress-bar-track',
|
|
36
|
+
radio: 'radio-indicator',
|
|
37
|
+
'radio-dot': 'radio-indicator-dot',
|
|
38
|
+
'selector-clear-icon': 'input-clear-icon',
|
|
39
|
+
statusdot: 'status-dot',
|
|
40
|
+
textarea: 'text-area',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
describe('migrate-deprecated-theme-surface', () => {
|
|
44
|
+
it('is staged as a required next-release code codemod', () => {
|
|
45
|
+
const entry = manifest.find(
|
|
46
|
+
candidate => candidate.name === 'migrate-deprecated-theme-surface',
|
|
47
|
+
);
|
|
48
|
+
expect(entry).toBeDefined();
|
|
49
|
+
expect(entry?.optional).not.toBe(true);
|
|
50
|
+
expect(entry?.meta.fileExtensions).toContain('.css');
|
|
51
|
+
expect(entry?.meta.fileExtensions).toContain('.ts');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('owns the complete approved 21-target mapping', () => {
|
|
55
|
+
expect(DEPRECATED_THEME_TARGETS).toEqual(EXPECTED_TARGETS);
|
|
56
|
+
expect(Object.keys(DEPRECATED_THEME_TARGETS)).toHaveLength(21);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it.each(Object.entries(EXPECTED_TARGETS))(
|
|
60
|
+
'renames static target key %s to %s inside a components map',
|
|
61
|
+
(oldKey, newKey) => {
|
|
62
|
+
const output = apply(
|
|
63
|
+
`export default {name: 'brand', components: {${JSON.stringify(oldKey)}: {base: {color: 'red'}}}};`,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
expect(output).not.toContain(`${JSON.stringify(oldKey)}:`);
|
|
67
|
+
expect(output).toContain(`'${newKey}':`);
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
it('renames root, mode, and adaptation component maps', () => {
|
|
72
|
+
const output = apply(`${IMPORT}const theme = defineTheme({
|
|
73
|
+
components: {progressbar: {base: {color: 'red'}}},
|
|
74
|
+
onDark: {components: {'statusdot': {base: {color: 'white'}}}},
|
|
75
|
+
adaptations: {rules: [{value: {components: {'popover-surface': {base: {padding: 8}}}}}]},
|
|
76
|
+
});`);
|
|
77
|
+
|
|
78
|
+
expect(output).toContain("'progress-bar':");
|
|
79
|
+
expect(output).toContain("'status-dot':");
|
|
80
|
+
expect(output).toContain("'popover':");
|
|
81
|
+
expect(output).not.toMatch(/(?:progressbar|statusdot|popover-surface)\s*:/);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('renames a statically declared components variable used by defineTheme', () => {
|
|
85
|
+
const output =
|
|
86
|
+
apply(`${IMPORT}const components = {textarea: {base: {color: 'red'}}};
|
|
87
|
+
export const theme = defineTheme({name: 'brand', components});`);
|
|
88
|
+
expect(output).toContain("'text-area':");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('does not rewrite an unrelated object property named components', () => {
|
|
92
|
+
const input = `const registry = {components: {checkbox: Checkbox}};`;
|
|
93
|
+
expect(apply(input)).toBe(input);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('does not rewrite a default-exported application component registry', () => {
|
|
97
|
+
for (const input of [
|
|
98
|
+
`export default {components: {checkbox: Checkbox, textarea: TextArea}};`,
|
|
99
|
+
`export default {name: 'app', components: {checkbox: Checkbox}};`,
|
|
100
|
+
`const theme = {components: {checkbox: {base: {color: 'red'}}}};`,
|
|
101
|
+
]) {
|
|
102
|
+
expect(apply(input)).toBe(input);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('does not treat a defineTheme from another library as an Astryx theme', () => {
|
|
107
|
+
const input = `import {defineTheme} from 'other-ui';
|
|
108
|
+
export default defineTheme({components: {checkbox: {base: {color: 'red'}}}});`;
|
|
109
|
+
expect(apply(input)).toBe(input);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it.each([
|
|
113
|
+
[
|
|
114
|
+
'an aliased defineTheme import',
|
|
115
|
+
`import {defineTheme as makeTheme} from '@astryxdesign/core';
|
|
116
|
+
export default makeTheme({name: 'brand', components: {navicon: {base: {}}}});`,
|
|
117
|
+
],
|
|
118
|
+
[
|
|
119
|
+
'a namespace defineTheme call',
|
|
120
|
+
`import * as astryx from '@astryxdesign/core/theme';
|
|
121
|
+
export default astryx.defineTheme({components: {navicon: {base: {}}}});`,
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
'a satisfies-typed theme object',
|
|
125
|
+
`import type {DefineThemeInput} from '@astryxdesign/core';
|
|
126
|
+
export default {components: {navicon: {base: {}}}} satisfies DefineThemeInput;`,
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
'an as-typed theme object',
|
|
130
|
+
`import type {DefineThemeInput} from '@astryxdesign/core';
|
|
131
|
+
export default ({components: {navicon: {base: {}}}}) as DefineThemeInput;`,
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
'an annotated theme variable',
|
|
135
|
+
`import type {DefineThemeInput} from '@astryxdesign/core';
|
|
136
|
+
const brand: DefineThemeInput = {name: 'brand', components: {navicon: {base: {}}}};`,
|
|
137
|
+
],
|
|
138
|
+
])('recognizes %s', (_name, input) => {
|
|
139
|
+
const output = apply(input);
|
|
140
|
+
expect(output).toContain("'nav-icon':");
|
|
141
|
+
expect(output).not.toMatch(/navicon\s*:/);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('renames a clear-icon alias with a TODO naming the owner scope it loses', () => {
|
|
145
|
+
const output = apply(
|
|
146
|
+
`export default {name: 'brand', components: {'selector-clear-icon': {base: {color: 'red'}}}};`,
|
|
147
|
+
);
|
|
148
|
+
expect(output).toContain("'input-clear-icon':");
|
|
149
|
+
expect(output).toContain(
|
|
150
|
+
'TODO(astryx upgrade): `selector-clear-icon` became `input-clear-icon`',
|
|
151
|
+
);
|
|
152
|
+
expect(output).toContain(
|
|
153
|
+
'.astryx-input-clear-icon:where(.astryx-selector *)',
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('flags two clear-icon aliases that collapse onto the shared target', () => {
|
|
158
|
+
const output = apply(`export default {name: 'brand', components: {
|
|
159
|
+
'selector-clear-icon': {base: {color: 'red'}},
|
|
160
|
+
'date-input-clear-icon': {base: {color: 'blue'}},
|
|
161
|
+
}};`);
|
|
162
|
+
expect(output).toContain("'input-clear-icon':");
|
|
163
|
+
expect(output).toContain(
|
|
164
|
+
'merge deprecated theme target `date-input-clear-icon` into `input-clear-icon`',
|
|
165
|
+
);
|
|
166
|
+
expect(output).toContain("'date-input-clear-icon':");
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('uses lexical scope when a theme components variable shadows a registry', () => {
|
|
170
|
+
const input = `${IMPORT}const components = {checkbox: Checkbox};
|
|
171
|
+
function makeTheme() {
|
|
172
|
+
const components = {textarea: {base: {color: 'red'}}};
|
|
173
|
+
return defineTheme({components});
|
|
174
|
+
}`;
|
|
175
|
+
const output = apply(input);
|
|
176
|
+
expect(output).toContain('const components = {checkbox: Checkbox};');
|
|
177
|
+
expect(output).toContain("'text-area':");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('does not rename matching keys outside a components map or dynamic keys', () => {
|
|
181
|
+
const input = `const labels = {progressbar: 'Progress'};
|
|
182
|
+
const oldTarget = 'progressbar';
|
|
183
|
+
const theme = {name: 'brand', components: {[oldTarget]: {base: {color: 'red'}}}};`;
|
|
184
|
+
expect(apply(input)).toBe(input);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('flags a static old/new collision instead of silently dropping either rule', () => {
|
|
188
|
+
const input = `${IMPORT}const theme = defineTheme({name: 'brand', components: {
|
|
189
|
+
progressbar: {base: {color: 'red'}},
|
|
190
|
+
'progress-bar': {base: {backgroundColor: 'blue'}},
|
|
191
|
+
}});`;
|
|
192
|
+
const output = apply(input);
|
|
193
|
+
expect(output).toContain('TODO(astryx upgrade)');
|
|
194
|
+
expect(output).toContain('merge deprecated theme target `progressbar`');
|
|
195
|
+
expect(output).toContain('progressbar:');
|
|
196
|
+
expect(output).toContain("'progress-bar':");
|
|
197
|
+
expect(apply(output)).toBe(output);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('renames every removed target class in CSS selectors', () => {
|
|
201
|
+
const input = Object.keys(EXPECTED_TARGETS)
|
|
202
|
+
.map(key => `.astryx-${key} { color: red; }`)
|
|
203
|
+
.join('\n');
|
|
204
|
+
const output = apply(input, 'theme.css');
|
|
205
|
+
|
|
206
|
+
for (const [oldKey, newKey] of Object.entries(EXPECTED_TARGETS)) {
|
|
207
|
+
expect(output).not.toMatch(
|
|
208
|
+
new RegExp(
|
|
209
|
+
`\\.astryx-${oldKey.replace(/[.*+?^${}()|[\\]\\]/g, '\\$&')}(?![a-z0-9-])`,
|
|
210
|
+
),
|
|
211
|
+
);
|
|
212
|
+
expect(output).toContain(`.astryx-${newKey}`);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('replaces target-qualified bare classes with reflected data selectors', () => {
|
|
217
|
+
const output = apply(
|
|
218
|
+
`.astryx-button.primary.sm:hover { color: red; }
|
|
219
|
+
.astryx-heading.level-2 { margin: 0; }
|
|
220
|
+
.astryx-switch.checked { opacity: 1; }
|
|
221
|
+
.astryx-grid.center { place-content: center; }`,
|
|
222
|
+
'theme.css',
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
expect(output).toContain(
|
|
226
|
+
'.astryx-button:is([data-variant="primary"]):is([data-size="sm"]):hover',
|
|
227
|
+
);
|
|
228
|
+
expect(output).toContain('.astryx-heading:is([data-level="2"])');
|
|
229
|
+
expect(output).toContain('.astryx-switch:is([data-checked="checked"])');
|
|
230
|
+
expect(output).toContain(
|
|
231
|
+
'.astryx-grid:is([data-align="center"],[data-justify="center"])',
|
|
232
|
+
);
|
|
233
|
+
expect(output).not.toMatch(
|
|
234
|
+
/\.(?:primary|sm|level-2|checked|center)(?![a-z0-9_-])/,
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('canonicalizes aliases before emitting data-attribute selectors', () => {
|
|
239
|
+
const output = apply(
|
|
240
|
+
'.astryx-progressbar.success > .astryx-progressbar-mark.fill {}',
|
|
241
|
+
'theme.css',
|
|
242
|
+
);
|
|
243
|
+
expect(output).toContain(
|
|
244
|
+
'.astryx-progress-bar:is([data-variant="success"])',
|
|
245
|
+
);
|
|
246
|
+
expect(output).toContain(
|
|
247
|
+
'.astryx-progress-bar-mark:is([data-placement="fill"])',
|
|
248
|
+
);
|
|
249
|
+
expect(output).not.toContain('astryx-progressbar');
|
|
250
|
+
expect(output).not.toMatch(/\.(?:success|fill)(?![a-z0-9_-])/);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('finishes selectors produced by the 0.6 compatibility codemod', () => {
|
|
254
|
+
const output = apply(
|
|
255
|
+
'.astryx-button:is(.primary,[data-variant="primary"]) {}',
|
|
256
|
+
'theme.css',
|
|
257
|
+
);
|
|
258
|
+
expect(output).toContain('.astryx-button:is([data-variant="primary"])');
|
|
259
|
+
expect(output).not.toContain('.primary');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('keeps the owner scope of clear-icon aliases in CSS without adding specificity', () => {
|
|
263
|
+
const output = apply(
|
|
264
|
+
`.astryx-selector-clear-icon:hover { color: red; }
|
|
265
|
+
.astryx-date-range-input-clear-icon { color: blue; }`,
|
|
266
|
+
'theme.css',
|
|
267
|
+
);
|
|
268
|
+
expect(output).toContain(
|
|
269
|
+
'.astryx-input-clear-icon:where(.astryx-selector *):hover',
|
|
270
|
+
);
|
|
271
|
+
expect(output).toContain(
|
|
272
|
+
'.astryx-input-clear-icon:where(.astryx-date-range-input *)',
|
|
273
|
+
);
|
|
274
|
+
expect(output).not.toMatch(/-clear-icon(?!:where)/);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('migrates bare classes that first shipped after 0.5.4', () => {
|
|
278
|
+
const output = apply('.astryx-heading.bold { color: red; }', 'theme.css');
|
|
279
|
+
expect(output).toContain('.astryx-heading:is([data-weight="bold"])');
|
|
280
|
+
expect(output).not.toMatch(/\.bold(?![a-z0-9_-])/);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('flags a known bare class that has no 0.6 meaning on its target', () => {
|
|
284
|
+
const input = '.astryx-button.checked { color: red; }';
|
|
285
|
+
const output = apply(input, 'theme.css');
|
|
286
|
+
expect(output).toContain(
|
|
287
|
+
'TODO(astryx upgrade): Astryx 0.7 no longer emits',
|
|
288
|
+
);
|
|
289
|
+
expect(output).toContain('.checked had no known 0.6 meaning');
|
|
290
|
+
expect(output).toContain('.astryx-button.checked');
|
|
291
|
+
expect(apply(output, 'theme.css')).toBe(output);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('leaves unqualified and unknown consumer classes unchanged', () => {
|
|
295
|
+
const input = `.primary { color: red; }
|
|
296
|
+
.astryx-button.brand { color: blue; }`;
|
|
297
|
+
expect(apply(input, 'theme.css')).toBe(input);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('does not remove a data-selector union from a different selector compound', () => {
|
|
301
|
+
const output = apply(
|
|
302
|
+
'.astryx-button.primary .consumer:is(.primary,[data-custom="x"]) {}',
|
|
303
|
+
'theme.css',
|
|
304
|
+
);
|
|
305
|
+
expect(output).toContain('.astryx-button:is([data-variant="primary"])');
|
|
306
|
+
expect(output).toContain('.consumer:is(.primary,[data-custom="x"])');
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('never rewrites CSS examples in JavaScript strings', () => {
|
|
310
|
+
const input = `const selector = '.astryx-progressbar.success';`;
|
|
311
|
+
expect(apply(input)).toBe(input);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('is byte-idempotent after JavaScript and CSS migration', () => {
|
|
315
|
+
const js = `export default {name: 'brand', components: {statusdot: {base: {color: 'red'}}, 'selector-clear-icon': {base: {color: 'red'}}}};`;
|
|
316
|
+
const css = '.astryx-textarea.sm {}';
|
|
317
|
+
const jsOnce = apply(js);
|
|
318
|
+
const cssOnce = apply(css, 'theme.css');
|
|
319
|
+
expect(apply(jsOnce)).toBe(jsOnce);
|
|
320
|
+
expect(apply(cssOnce, 'theme.css')).toBe(cssOnce);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import transform from '../validate-data-token-ownership.mjs';
|
|
5
|
+
|
|
6
|
+
async function run(source, file = 'test.tsx') {
|
|
7
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
8
|
+
const parser =
|
|
9
|
+
file.endsWith('.ts') || file.endsWith('.tsx') ? 'tsx' : 'babel';
|
|
10
|
+
const api = {
|
|
11
|
+
jscodeshift: jscodeshift.withParser(parser),
|
|
12
|
+
stats: () => {},
|
|
13
|
+
report: () => {},
|
|
14
|
+
};
|
|
15
|
+
return transform({source, path: file}, api);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('validate-data-token-ownership', () => {
|
|
19
|
+
it('reports direct string and static-template consumers with both migration paths', async () => {
|
|
20
|
+
for (const source of [
|
|
21
|
+
`const fill = 'var(--color-data-categorical-green)';`,
|
|
22
|
+
'const fill = `var(--color-data-categorical-green)`;',
|
|
23
|
+
`const border = '1px solid var(--color-data-categorical-green)';`,
|
|
24
|
+
'const border = `${width}px solid var(--color-data-categorical-green)`;',
|
|
25
|
+
]) {
|
|
26
|
+
await expect(run(source)).rejects.toThrow(
|
|
27
|
+
/CSS-capable code imports dataVars.*Canvas.*resolveThemeToken/s,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('leaves fallbacks, dataVars access, and comments unchanged', async () => {
|
|
33
|
+
const source = `
|
|
34
|
+
// var(--color-data-categorical-green)
|
|
35
|
+
const fallback = 'var(--color-data-categorical-green, #008000)';
|
|
36
|
+
const fill = dataVars['--color-data-categorical-green'];
|
|
37
|
+
`;
|
|
38
|
+
expect(await run(source)).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('reports stale generated theme CSS with root data defaults', async () => {
|
|
42
|
+
const source = `/* @generated by \`astryx theme build\` */
|
|
43
|
+
@layer astryx-base {
|
|
44
|
+
:root { --color-data-categorical-green: #008000; }
|
|
45
|
+
}`;
|
|
46
|
+
await expect(run(source, 'theme.css')).rejects.toThrow(
|
|
47
|
+
/Rebuild it with `astryx theme build`/,
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('reports raw stylesheet uses without a fallback', async () => {
|
|
52
|
+
await expect(
|
|
53
|
+
run('.bar { fill: var(--color-data-categorical-green); }', 'chart.css'),
|
|
54
|
+
).rejects.toThrow(/Raw var\(--color-data-categorical-green\).*line 1/s);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('leaves stylesheet uses with a fallback, and comments, unchanged', async () => {
|
|
58
|
+
expect(
|
|
59
|
+
await run(
|
|
60
|
+
`/* var(--color-data-categorical-green) */
|
|
61
|
+
.bar { fill: var(--color-data-categorical-green, #008000); }`,
|
|
62
|
+
'chart.css',
|
|
63
|
+
),
|
|
64
|
+
).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('does not claim ownership of hand-authored CSS or sparse theme overrides', async () => {
|
|
68
|
+
expect(
|
|
69
|
+
await run(
|
|
70
|
+
':root { --color-data-categorical-green: #008000; }',
|
|
71
|
+
'app.css',
|
|
72
|
+
),
|
|
73
|
+
).toBeUndefined();
|
|
74
|
+
expect(
|
|
75
|
+
await run(
|
|
76
|
+
`/* @generated by \`astryx theme build\` */
|
|
77
|
+
@scope ([data-astryx-theme="ocean"]) {
|
|
78
|
+
:scope { --color-data-categorical-green: #008000; }
|
|
79
|
+
}`,
|
|
80
|
+
'theme.css',
|
|
81
|
+
),
|
|
82
|
+
).toBeUndefined();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -7,4 +7,30 @@
|
|
|
7
7
|
* this file into the resolved version folder.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
import migrateDeprecatedThemeSurface, {
|
|
11
|
+
meta as migrateDeprecatedThemeSurfaceMeta,
|
|
12
|
+
} from './migrate-deprecated-theme-surface.mjs';
|
|
13
|
+
import migrateFieldInputStyling, {
|
|
14
|
+
meta as migrateFieldInputStylingMeta,
|
|
15
|
+
} from './migrate-field-input-styling.mjs';
|
|
16
|
+
import validateDataTokenOwnership, {
|
|
17
|
+
meta as validateDataTokenOwnershipMeta,
|
|
18
|
+
} from './validate-data-token-ownership.mjs';
|
|
19
|
+
|
|
20
|
+
export default [
|
|
21
|
+
{
|
|
22
|
+
name: 'migrate-deprecated-theme-surface',
|
|
23
|
+
transform: migrateDeprecatedThemeSurface,
|
|
24
|
+
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'validate-data-token-ownership',
|
|
28
|
+
transform: validateDataTokenOwnership,
|
|
29
|
+
meta: validateDataTokenOwnershipMeta,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'migrate-field-input-styling',
|
|
33
|
+
transform: migrateFieldInputStyling,
|
|
34
|
+
meta: migrateFieldInputStylingMeta,
|
|
35
|
+
},
|
|
36
|
+
];
|