@astryxdesign/cli 0.7.0-canary.693da50 → 0.7.0-canary.81dc9bb
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 +21 -26
- 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/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 +7 -2
- package/api/template/template.mjs +45 -0
- 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 -3
- package/api/theme/build/build.mjs +22 -36
- package/api/theme/build/build.test.mjs +11 -24
- 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/index.mjs +11 -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/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +38 -18
- package/assets/docs/author-a-theme.doc.mjs +4 -4
- 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/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/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.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/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/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +11 -30
- 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
|
@@ -17,9 +17,8 @@ export const doc = {
|
|
|
17
17
|
summary: 'List every component theming target a theme can override.',
|
|
18
18
|
description:
|
|
19
19
|
'Enumerates the whole themeable surface: each `defineTheme` components key, the stable ' +
|
|
20
|
-
'class it paints, the component that declares it, the props and states that are legal ' +
|
|
21
|
-
'override keys under it
|
|
22
|
-
'Same source as the Theming table `astryx component <Name>` prints ' +
|
|
20
|
+
'class it paints, the component that declares it, and the props and states that are legal ' +
|
|
21
|
+
'override keys under it. Same source as the Theming table `astryx component <Name>` prints ' +
|
|
23
22
|
'(the component docs), so the list cannot drift from the components, and `theme build` ' +
|
|
24
23
|
'validates overrides against this exact set. A filter naming a component gives that ' +
|
|
25
24
|
"component's set; anything else is a case-insensitive substring search over each target's key, class and component.",
|
|
@@ -55,7 +54,7 @@ export const doc = {
|
|
|
55
54
|
{
|
|
56
55
|
type: 'theme.targets',
|
|
57
56
|
description:
|
|
58
|
-
'The echoed filter, how many components are represented, and the targets: each {key, className, component, props, states
|
|
57
|
+
'The echoed filter, how many components are represented, and the targets: each {key, className, component, props, states}.',
|
|
59
58
|
},
|
|
60
59
|
],
|
|
61
60
|
throws: [
|
|
@@ -19,7 +19,7 @@ export const doc = {
|
|
|
19
19
|
'Writes theme.template.ts: the annotated reference for the whole theme surface, covering every ' +
|
|
20
20
|
'defineTheme field, the token families, the component override syntax, and how a theme is ' +
|
|
21
21
|
'consumed, with the CLI command that prints the authoritative reference for each section. ' +
|
|
22
|
-
'Read it, copy what you need into your own theme file, delete it. Use `theme add
|
|
22
|
+
'Read it, copy what you need into your own theme file, delete it. Use `theme add` to ' +
|
|
23
23
|
'use an installed built theme, extend that theme for ordinary customization, or use ' +
|
|
24
24
|
'`theme eject` for a complete source fork. This command starts a new blank theme. Refuses to overwrite without ' +
|
|
25
25
|
'`overwrite`, so it is safe to re-run.',
|
|
@@ -92,7 +92,7 @@ describe('themeUse', () => {
|
|
|
92
92
|
it('names theme add when the slug is not added', async () => {
|
|
93
93
|
await expect(themeUse('missing', {cwd: tmpDir})).rejects.toMatchObject({
|
|
94
94
|
code: 'ERR_UNKNOWN_THEME',
|
|
95
|
-
message: expect.stringContaining('astryx theme add missing
|
|
95
|
+
message: expect.stringContaining('astryx theme add missing'),
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
});
|
|
@@ -129,7 +129,7 @@ export const doc = {
|
|
|
129
129
|
throws: [
|
|
130
130
|
{
|
|
131
131
|
code: 'ERR_INVALID_ARGUMENT',
|
|
132
|
-
when: '`from` is missing (and neither `list` nor `registry` is set); `list` and `registry` are both set; `registry` is combined with `from`, `force`, `codemod`, `skipCodemod`, `integration` or `installDeps`; an `integration` specifier is invalid or not installed; or astryx.config fails to load or validate and no pending config codemod repairs it',
|
|
132
|
+
when: '`from` is missing (and neither `list` nor `registry` is set); `list` and `registry` are both set; `list` is combined with `from`, `force`, `apply`, `path` (non-default), `codemod`, `skipCodemod`, `integration` or `installDeps`; `registry` is combined with `from`, `force`, `codemod`, `skipCodemod`, `integration` or `installDeps`; an `integration` specifier is invalid or not installed; or astryx.config fails to load or validate and no pending config codemod repairs it',
|
|
133
133
|
},
|
|
134
134
|
{code: 'ERR_INVALID_VERSION', when: '`from` is not a valid semver string'},
|
|
135
135
|
{code: 'ERR_PATH_TRAVERSAL', when: '`path` resolves outside cwd'},
|
package/api/upgrade/upgrade.mjs
CHANGED
|
@@ -53,6 +53,25 @@ export async function upgrade(options = {}, {cwd = process.cwd()} = {}) {
|
|
|
53
53
|
throw new AstryxError(msg, undefined, ERROR_CODES.ERR_INVALID_ARGUMENT);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
if (options.list) {
|
|
57
|
+
const ignored = [
|
|
58
|
+
options.from ? '--from' : null,
|
|
59
|
+
options.force ? '--force' : null,
|
|
60
|
+
options.apply ? '--apply' : null,
|
|
61
|
+
options.path && options.path !== './src' ? '--path' : null,
|
|
62
|
+
options.codemod ? '--codemod' : null,
|
|
63
|
+
options.skipCodemod?.length ? '--skip-codemod' : null,
|
|
64
|
+
options.integration?.length ? '--integration' : null,
|
|
65
|
+
options.installDeps ? '--install-deps' : null,
|
|
66
|
+
].filter(Boolean);
|
|
67
|
+
if (ignored.length > 0) {
|
|
68
|
+
const msg = `\`--list\` cannot be combined with ${ignored.join(', ')}: it lists available codemods and does not run a migration.`;
|
|
69
|
+
logger.error(msg);
|
|
70
|
+
logger.log('Aborted\n');
|
|
71
|
+
throw new AstryxError(msg, undefined, ERROR_CODES.ERR_INVALID_ARGUMENT);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
56
75
|
if (options.registry) {
|
|
57
76
|
const incompatible = [
|
|
58
77
|
options.from ? '--from' : null,
|
|
@@ -0,0 +1,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
|
+
});
|
|
@@ -7,4 +7,14 @@
|
|
|
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
|
+
|
|
14
|
+
export default [
|
|
15
|
+
{
|
|
16
|
+
name: 'migrate-deprecated-theme-surface',
|
|
17
|
+
transform: migrateDeprecatedThemeSurface,
|
|
18
|
+
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
19
|
+
},
|
|
20
|
+
];
|