@astryxdesign/cli 0.7.4 → 0.7.5-canary.0418c47
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 +20 -20
- package/api/component/_adapter.mjs +16 -1
- package/api/component/component.test.mjs +31 -0
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +5 -2
- package/api/docs/_adapter.mjs +24 -16
- package/api/docs/docs.test.mjs +18 -0
- package/api/docs/integrationDocs.test.mjs +2 -2
- package/api/experimental.d.mts +5 -0
- package/api/experimental.mjs +15 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +16 -3
- package/api/icon/_authoring.d.mts +5 -1
- package/api/icon/_authoring.mjs +478 -63
- package/api/icon/_options.d.mts +11 -0
- package/api/icon/_options.mjs +39 -4
- package/api/icon/_records.d.mts +19 -0
- package/api/icon/_records.mjs +25 -0
- package/api/icon/add/add.d.mts +3 -3
- package/api/icon/add/add.mjs +227 -14
- package/api/icon/all-or-nothing.test.mjs +283 -0
- package/api/icon/detail/detail.mjs +2 -13
- package/api/icon/error-codes.test.mjs +14 -7
- package/api/icon/icon.d.mts +2 -2
- package/api/icon/icon.doc.mjs +30 -2
- package/api/icon/icon.mjs +57 -8
- package/api/icon/icon.test.mjs +133 -1
- package/api/icon/icon.type.d.mts +126 -1
- package/api/icon/icon.type.mjs +67 -3
- package/api/icon/iconAdd.doc.mjs +22 -6
- package/api/icon/iconMap.doc.mjs +24 -8
- package/api/icon/iconNewDefinition.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +30 -2
- package/api/icon/iconUse.doc.mjs +4 -1
- package/api/icon/map/map.d.mts +4 -4
- package/api/icon/map/map.mjs +134 -9
- package/api/icon/new-definition/new-definition.mjs +6 -2
- package/api/icon/new-set/new-set.mjs +2 -2
- package/api/icon/new-set/new-set.test.mjs +60 -10
- package/api/icon/option-pairs.test.mjs +368 -0
- package/api/icon/search/search.d.mts +10 -0
- package/api/icon/search/search.mjs +55 -14
- package/api/icon/use/use.mjs +2 -13
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
- package/api/integration/pack-check.mjs +10 -4
- package/api/integration/pack-check.test.mjs +5 -1
- package/api/integration/validate-integration.type.d.mts +3 -2
- package/api/integration/validate-integration.type.mjs +3 -2
- package/api/render/_adapter.d.mts +28 -0
- package/api/render/_adapter.mjs +540 -0
- package/api/render/render.d.mts +15 -0
- package/api/render/render.doc.d.mts +9 -0
- package/api/render/render.doc.mjs +112 -0
- package/api/render/render.mjs +113 -0
- package/api/render/render.test.mjs +1155 -0
- package/api/render/render.type.d.mts +74 -0
- package/api/render/render.type.mjs +64 -0
- package/api/search/_adapter.test.mjs +21 -2
- package/api/search/_result.d.mts +5 -5
- package/api/search/search.d.mts +1 -1
- package/api/template/template.mjs +3 -1
- package/api/template/template.type.d.mts +2 -1
- package/api/template/template.type.mjs +1 -1
- package/api/template/tokenizer-showcase.test.mjs +47 -0
- package/api/template/unknown-name.test.mjs +63 -0
- package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
- package/api/theme/build/build.icon-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +36 -7
- package/api/theme/build/build.test.mjs +27 -0
- package/api/upgrade/_adapter.d.mts +47 -2
- package/api/upgrade/_adapter.mjs +58 -2
- package/api/upgrade/run/failure-receipt.test.mjs +212 -0
- package/api/upgrade/run/outcomes.test.mjs +646 -0
- package/api/upgrade/run/run.d.mts +36 -0
- package/api/upgrade/run/run.mjs +670 -44
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +36 -1
- package/api/upgrade/upgrade.type.mjs +29 -4
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
- package/assets/codemods/integration-runner.mjs +8 -2
- package/assets/codemods/integration-runner.protection.test.mjs +53 -0
- package/assets/codemods/outcome.mjs +79 -0
- package/assets/codemods/outcome.test.mjs +40 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/run-codemod.mjs +109 -5
- package/assets/codemods/runner.mjs +119 -13
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
- package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
- package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
- package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
- package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +143 -70
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +71 -1
- package/assets/docs/theme.doc.dense.mjs +8 -0
- package/assets/docs/theme.doc.mjs +16 -0
- package/assets/docs/theme.doc.zh.mjs +11 -0
- package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
- package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +50 -20
- package/assets/docs/tree/render-pages.doc.mjs +94 -0
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +145 -1
- package/assets/docs/tree/tokens.doc.mjs +1 -1
- package/assets/icons/definitions/activity.doc.mjs +1 -1
- package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
- package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
- package/assets/icons/definitions/alignStart.doc.mjs +10 -0
- package/assets/icons/definitions/archive.doc.mjs +1 -1
- package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
- package/assets/icons/definitions/attach.doc.mjs +1 -1
- package/assets/icons/definitions/audio.doc.mjs +1 -1
- package/assets/icons/definitions/cart.doc.mjs +1 -1
- package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
- package/assets/icons/definitions/close.doc.mjs +1 -1
- package/assets/icons/definitions/collapse.doc.mjs +1 -1
- package/assets/icons/definitions/compose.doc.mjs +1 -1
- package/assets/icons/definitions/conversation.doc.mjs +1 -1
- package/assets/icons/definitions/copy.doc.mjs +1 -1
- package/assets/icons/definitions/cpu.doc.mjs +9 -0
- package/assets/icons/definitions/database.doc.mjs +1 -1
- package/assets/icons/definitions/desktop.doc.mjs +1 -1
- package/assets/icons/definitions/discount.doc.mjs +1 -1
- package/assets/icons/definitions/download.doc.mjs +1 -1
- package/assets/icons/definitions/emoji.doc.mjs +1 -1
- package/assets/icons/definitions/error.doc.mjs +1 -1
- package/assets/icons/definitions/expand.doc.mjs +1 -1
- package/assets/icons/definitions/experiment.doc.mjs +1 -1
- package/assets/icons/definitions/externalLink.doc.mjs +7 -1
- package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
- package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
- package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
- package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
- package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
- package/assets/icons/definitions/gitFork.doc.mjs +9 -0
- package/assets/icons/definitions/info.doc.mjs +1 -1
- package/assets/icons/definitions/location.doc.mjs +1 -1
- package/assets/icons/definitions/mention.doc.mjs +1 -1
- package/assets/icons/definitions/menu.doc.mjs +1 -1
- package/assets/icons/definitions/microphone.doc.mjs +1 -1
- package/assets/icons/definitions/mobile.doc.mjs +1 -1
- package/assets/icons/definitions/money.doc.mjs +1 -1
- package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
- package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
- package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
- package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
- package/assets/icons/definitions/panelRight.doc.mjs +10 -0
- package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
- package/assets/icons/definitions/redo.doc.mjs +1 -1
- package/assets/icons/definitions/refresh.doc.mjs +1 -1
- package/assets/icons/definitions/rotate.doc.mjs +9 -0
- package/assets/icons/definitions/scale.doc.mjs +10 -0
- package/assets/icons/definitions/search.doc.mjs +1 -1
- package/assets/icons/definitions/send.doc.mjs +1 -1
- package/assets/icons/definitions/settings.doc.mjs +1 -1
- package/assets/icons/definitions/star.doc.mjs +1 -1
- package/assets/icons/definitions/stop.doc.mjs +1 -1
- package/assets/icons/definitions/success.doc.mjs +1 -1
- package/assets/icons/definitions/textCase.doc.mjs +9 -0
- package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
- package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
- package/assets/icons/definitions/trendDown.doc.mjs +7 -1
- package/assets/icons/definitions/trendUp.doc.mjs +1 -1
- package/assets/icons/definitions/undo.doc.mjs +1 -1
- package/assets/icons/definitions/upload.doc.mjs +1 -1
- package/assets/icons/definitions/userAdd.doc.mjs +1 -1
- package/assets/icons/definitions/warning.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +22 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/library/page.tsx +1 -2
- package/assets/templates/pages/table-comparison/page.tsx +12 -3
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
- package/assets/templates/themes/butter/butterTheme.ts +47 -44
- package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
- package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
- package/assets/templates/themes/stone/stoneTheme.ts +46 -21
- package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
- package/assets/theme.template.ts +18 -5
- package/authoring/codemod/type.ts +10 -0
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
- package/authoring/doctypes/icon-set/parse.d.mts +1 -0
- package/authoring/doctypes/icon-set/parse.mjs +1 -0
- package/authoring/doctypes/icon-set/type.ts +5 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +2 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
- package/clients/cli/commands/doctor.mjs +16 -17
- package/clients/cli/commands/experimental/icon.mjs +167 -35
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/render.mjs +113 -0
- package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
- package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
- package/clients/cli/commands/experimental-render.doc.mjs +60 -0
- package/clients/cli/commands/experimental.doc.mjs +4 -2
- package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
- package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
- package/clients/cli/commands/icon.test.mjs +1 -1
- package/clients/cli/commands/template.mjs +4 -1
- package/clients/cli/commands/text-json-parity.test.mjs +46 -0
- package/clients/cli/commands/upgrade.doc.mjs +47 -2
- package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
- package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
- package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
- package/clients/cli/commands/upgrade.mjs +9 -2
- package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
- package/clients/cli/index.mjs +1 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +5 -0
- package/foundation/discovery/component-discovery.d.mts +2 -1
- package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
- package/foundation/discovery/component-discovery.mjs +13 -7
- package/foundation/discovery/icon-set-checks.d.mts +43 -9
- package/foundation/discovery/icon-set-checks.mjs +296 -21
- package/foundation/discovery/icon-set-checks.test.mjs +125 -12
- package/foundation/discovery/icon-set-writer.d.mts +192 -3
- package/foundation/discovery/icon-set-writer.mjs +608 -34
- package/foundation/discovery/icon-set-writer.test.mjs +26 -0
- package/foundation/discovery/module-exports.mjs +82 -25
- package/foundation/discovery/module-exports.test.mjs +38 -1
- package/foundation/discovery/package-exports.d.mts +13 -0
- package/foundation/discovery/package-exports.mjs +40 -1
- package/foundation/discovery/template-icons.d.mts +6 -0
- package/foundation/discovery/template-icons.mjs +98 -10
- package/foundation/discovery/template-icons.test.mjs +103 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
- package/foundation/doc-compiler/import.mjs +81 -8
- package/foundation/doc-compiler/read.d.mts +4 -3
- package/foundation/doc-compiler/read.mjs +15 -10
- package/foundation/doc-compiler/read.test.mjs +59 -1
- package/foundation/doc-compiler/tree.mjs +3 -1
- package/foundation/fs/module-loader.d.mts +3 -2
- package/foundation/fs/module-loader.mjs +3 -2
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
- package/foundation/fs/read-record.d.mts +27 -0
- package/foundation/fs/read-record.mjs +83 -15
- package/foundation/fs/read-record.test.mjs +88 -1
- package/foundation/render/assets.d.mts +31 -0
- package/foundation/render/assets.mjs +102 -0
- package/foundation/render/component-map.d.mts +52 -0
- package/foundation/render/component-map.mjs +141 -0
- package/foundation/render/css-cut.d.mts +29 -0
- package/foundation/render/css-cut.mjs +144 -0
- package/foundation/render/embedded-files.d.mts +28 -0
- package/foundation/render/embedded-files.mjs +108 -0
- package/foundation/render/embedded-imports.d.mts +61 -0
- package/foundation/render/embedded-imports.mjs +315 -0
- package/foundation/render/html-reader.d.mts +37 -0
- package/foundation/render/html-reader.mjs +121 -0
- package/foundation/render/page-worker.d.mts +7 -0
- package/foundation/render/page-worker.mjs +519 -0
- package/foundation/render/rebuild.d.mts +19 -0
- package/foundation/render/rebuild.mjs +269 -0
- package/foundation/render/render-page.d.mts +85 -0
- package/foundation/render/render-page.mjs +612 -0
- package/foundation/render/render.test.mjs +117 -0
- package/foundation/render/source-block.d.mts +52 -0
- package/foundation/render/source-block.mjs +106 -0
- package/foundation/response/base.d.ts +7 -0
- package/foundation/response/error-codes.d.mts +10 -1
- package/foundation/response/error-codes.doc.mjs +59 -2
- package/foundation/response/error-codes.mjs +62 -1
- package/foundation/response/json.d.mts +10 -3
- package/foundation/response/json.mjs +16 -4
- package/foundation/response/response-types.doc.mjs +39 -2
- package/foundation/text/string-utils.mjs +33 -0
- package/foundation/text/string-utils.test.mjs +17 -0
- package/foundation/text/suggest-order.d.mts +17 -3
- package/foundation/text/suggest-order.mjs +58 -13
- package/foundation/text/suggest-order.test.mjs +53 -0
- package/package.json +15 -9
|
@@ -162,6 +162,52 @@ export default createConfig({
|
|
|
162
162
|
});
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
+
describe('migrate-layout-components-to-experimental — default export by const reference', () => {
|
|
166
|
+
it('returns null for a generated config with no layout key', async () => {
|
|
167
|
+
const input = `// Generated Astryx config.
|
|
168
|
+
const config = {
|
|
169
|
+
integrations: ["@acme/ui"],
|
|
170
|
+
issuesUrl: "https://example.com/issues",
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export default config;
|
|
174
|
+
`;
|
|
175
|
+
const output = await applyTransform(input);
|
|
176
|
+
expect(output).toBeNull();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('migrates layout.components in a const-bound object literal', async () => {
|
|
180
|
+
const input = `const config = {
|
|
181
|
+
layout: { components: { KpiCard: '@/components/KpiCard' } },
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export default config;
|
|
185
|
+
`;
|
|
186
|
+
const output = await applyTransform(input);
|
|
187
|
+
expect(output).not.toBeNull();
|
|
188
|
+
expect(output).toMatch(/const config = \{/);
|
|
189
|
+
expect(output).toContain('export default config;');
|
|
190
|
+
expect(output).toMatch(/experimental:\s*\{\s*xle:\s*\{\s*components:\s*\{\s*KpiCard:\s*\{\s*from:\s*['"]@\/components\/KpiCard['"]/);
|
|
191
|
+
expect(output).not.toMatch(/layout\s*:/);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('migrates layout.components in a const-bound createConfig({ ... }) call', async () => {
|
|
195
|
+
const input = `import { createConfig } from '@astryxdesign/cli';
|
|
196
|
+
|
|
197
|
+
const config = createConfig({
|
|
198
|
+
layout: { components: { KpiCard: '@/components/KpiCard' } },
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
export default config;
|
|
202
|
+
`;
|
|
203
|
+
const output = await applyTransform(input);
|
|
204
|
+
expect(output).not.toBeNull();
|
|
205
|
+
expect(output).toContain('createConfig(');
|
|
206
|
+
expect(output).toMatch(/KpiCard:\s*\{\s*from:\s*['"]@\/components\/KpiCard['"]/);
|
|
207
|
+
expect(output).not.toMatch(/layout\s*:/);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
165
211
|
describe('migrate-layout-components-to-experimental — placement', () => {
|
|
166
212
|
it('adds xle to a pre-existing experimental (no xle)', async () => {
|
|
167
213
|
const input = `export default {
|
|
@@ -239,8 +285,69 @@ export default {
|
|
|
239
285
|
await expect(applyTransform(input)).rejects.toThrow(/cannot be safely migrated/);
|
|
240
286
|
});
|
|
241
287
|
|
|
242
|
-
it('throws
|
|
243
|
-
const input = `
|
|
288
|
+
it('throws when the default export is an identifier with no top-level const binding', async () => {
|
|
289
|
+
const input = `import config from './base-config.mjs';
|
|
290
|
+
export default config;
|
|
291
|
+
`;
|
|
292
|
+
await expect(applyTransform(input)).rejects.toThrow(/statically analyze/);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('throws when a const-bound config is mutated after its declaration', async () => {
|
|
296
|
+
const input = `const config = {};
|
|
297
|
+
config.layout = { components: { KpiCard: '@/components/KpiCard' } };
|
|
298
|
+
export default config;
|
|
299
|
+
`;
|
|
300
|
+
await expect(applyTransform(input)).rejects.toThrow(/statically analyze/);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('throws when a const-bound config is passed to another call', async () => {
|
|
304
|
+
const input = `const config = {};
|
|
305
|
+
Object.assign(config, { layout: { components: { KpiCard: '@/components/KpiCard' } } });
|
|
306
|
+
export default config;
|
|
307
|
+
`;
|
|
308
|
+
await expect(applyTransform(input)).rejects.toThrow(/statically analyze/);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('throws when a const-bound config is aliased', async () => {
|
|
312
|
+
const input = `const config = {};
|
|
313
|
+
const alias = config;
|
|
314
|
+
alias.layout = { components: { KpiCard: '@/components/KpiCard' } };
|
|
315
|
+
export default config;
|
|
316
|
+
`;
|
|
317
|
+
await expect(applyTransform(input)).rejects.toThrow(/statically analyze/);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('throws when the const-bound config is also exported with export const', async () => {
|
|
321
|
+
const input = `export const config = {
|
|
322
|
+
layout: { components: { KpiCard: '@/components/KpiCard' } },
|
|
323
|
+
};
|
|
324
|
+
export default config;
|
|
325
|
+
`;
|
|
326
|
+
await expect(applyTransform(input)).rejects.toThrow(/statically analyze/);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('throws when the const-bound config is also exported by name', async () => {
|
|
330
|
+
const input = `const config = {
|
|
331
|
+
layout: { components: { KpiCard: '@/components/KpiCard' } },
|
|
332
|
+
};
|
|
333
|
+
export { config };
|
|
334
|
+
export default config;
|
|
335
|
+
`;
|
|
336
|
+
await expect(applyTransform(input)).rejects.toThrow(/statically analyze/);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('throws when the const-bound config is also exported under another name', async () => {
|
|
340
|
+
const input = `const config = {
|
|
341
|
+
layout: { components: { KpiCard: '@/components/KpiCard' } },
|
|
342
|
+
};
|
|
343
|
+
export { config as baseConfig };
|
|
344
|
+
export default config;
|
|
345
|
+
`;
|
|
346
|
+
await expect(applyTransform(input)).rejects.toThrow(/statically analyze/);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('throws when the default export is bound by a reassignable let', async () => {
|
|
350
|
+
const input = `let config = { layout: { components: { KpiCard: '@/components/KpiCard' } } };
|
|
244
351
|
export default config;
|
|
245
352
|
`;
|
|
246
353
|
await expect(applyTransform(input)).rejects.toThrow(/statically analyze/);
|
|
@@ -306,6 +413,113 @@ describe('migrate-layout-components-to-experimental — end-to-end via runConfig
|
|
|
306
413
|
}
|
|
307
414
|
});
|
|
308
415
|
|
|
416
|
+
it('leaves a generated const-bound config with no layout untouched and reports no error', async () => {
|
|
417
|
+
const {runConfigCodemod} = await import('../../../run-codemod.mjs');
|
|
418
|
+
const {default: transform, meta} = await import(
|
|
419
|
+
'../migrate-layout-components-to-experimental.mjs'
|
|
420
|
+
);
|
|
421
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
422
|
+
|
|
423
|
+
const originalCwd = process.cwd();
|
|
424
|
+
const tmpDir = fs.mkdtempSync(
|
|
425
|
+
path.join(process.cwd(), '.astryx-v013-codemod-test-'),
|
|
426
|
+
);
|
|
427
|
+
const configSource = `// Generated Astryx config.
|
|
428
|
+
const config = {
|
|
429
|
+
integrations: ["@acme/ui"],
|
|
430
|
+
issuesUrl: "https://example.com/issues",
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
export default config;
|
|
434
|
+
`;
|
|
435
|
+
try {
|
|
436
|
+
process.chdir(tmpDir);
|
|
437
|
+
fs.writeFileSync(
|
|
438
|
+
path.join(tmpDir, 'package.json'),
|
|
439
|
+
JSON.stringify({name: 'consumer'}),
|
|
440
|
+
);
|
|
441
|
+
fs.writeFileSync(path.join(tmpDir, 'astryx.config.mjs'), configSource);
|
|
442
|
+
|
|
443
|
+
const entry = {
|
|
444
|
+
id: 'migrate-layout-components-to-experimental',
|
|
445
|
+
type: 'config',
|
|
446
|
+
codemod: {title: meta.title, transform},
|
|
447
|
+
package: 'core',
|
|
448
|
+
version: '0.1.3',
|
|
449
|
+
};
|
|
450
|
+
const log = {
|
|
451
|
+
step() {},
|
|
452
|
+
info() {},
|
|
453
|
+
success() {},
|
|
454
|
+
warn() {},
|
|
455
|
+
error() {},
|
|
456
|
+
message() {},
|
|
457
|
+
};
|
|
458
|
+
const result = runConfigCodemod(entry, {apply: true, log, jscodeshift});
|
|
459
|
+
|
|
460
|
+
expect(result.errors).toHaveLength(0);
|
|
461
|
+
expect(result.filesChanged).toBe(0);
|
|
462
|
+
expect(
|
|
463
|
+
fs.readFileSync(path.join(tmpDir, 'astryx.config.mjs'), 'utf-8'),
|
|
464
|
+
).toBe(configSource);
|
|
465
|
+
} finally {
|
|
466
|
+
process.chdir(originalCwd);
|
|
467
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it('reports an error, not success, for a mutated const-bound config', async () => {
|
|
472
|
+
const {runConfigCodemod} = await import('../../../run-codemod.mjs');
|
|
473
|
+
const {default: transform, meta} = await import(
|
|
474
|
+
'../migrate-layout-components-to-experimental.mjs'
|
|
475
|
+
);
|
|
476
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
477
|
+
|
|
478
|
+
const originalCwd = process.cwd();
|
|
479
|
+
const tmpDir = fs.mkdtempSync(
|
|
480
|
+
path.join(process.cwd(), '.astryx-v013-codemod-test-'),
|
|
481
|
+
);
|
|
482
|
+
const configSource = `const config = {};
|
|
483
|
+
config.layout = { components: { KpiCard: '@/components/KpiCard' } };
|
|
484
|
+
export default config;
|
|
485
|
+
`;
|
|
486
|
+
try {
|
|
487
|
+
process.chdir(tmpDir);
|
|
488
|
+
fs.writeFileSync(
|
|
489
|
+
path.join(tmpDir, 'package.json'),
|
|
490
|
+
JSON.stringify({name: 'consumer'}),
|
|
491
|
+
);
|
|
492
|
+
fs.writeFileSync(path.join(tmpDir, 'astryx.config.mjs'), configSource);
|
|
493
|
+
|
|
494
|
+
const entry = {
|
|
495
|
+
id: 'migrate-layout-components-to-experimental',
|
|
496
|
+
type: 'config',
|
|
497
|
+
codemod: {title: meta.title, transform},
|
|
498
|
+
package: 'core',
|
|
499
|
+
version: '0.1.3',
|
|
500
|
+
};
|
|
501
|
+
const log = {
|
|
502
|
+
step() {},
|
|
503
|
+
info() {},
|
|
504
|
+
success() {},
|
|
505
|
+
warn() {},
|
|
506
|
+
error() {},
|
|
507
|
+
message() {},
|
|
508
|
+
};
|
|
509
|
+
const result = runConfigCodemod(entry, {apply: true, log, jscodeshift});
|
|
510
|
+
|
|
511
|
+
expect(result.filesChanged).toBe(0);
|
|
512
|
+
expect(result.errors).toHaveLength(1);
|
|
513
|
+
expect(result.errors[0].error).toMatch(/statically analyze/);
|
|
514
|
+
expect(
|
|
515
|
+
fs.readFileSync(path.join(tmpDir, 'astryx.config.mjs'), 'utf-8'),
|
|
516
|
+
).toBe(configSource);
|
|
517
|
+
} finally {
|
|
518
|
+
process.chdir(originalCwd);
|
|
519
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
|
|
309
523
|
it('surfaces a thrown bail as a structured error through runConfigCodemod', async () => {
|
|
310
524
|
const {runConfigCodemod} = await import('../../../run-codemod.mjs');
|
|
311
525
|
const {default: transform, meta} = await import(
|
|
@@ -28,10 +28,14 @@
|
|
|
28
28
|
* - object `{ from, description?, default? }` → carried over UNCHANGED
|
|
29
29
|
* (from/description/default preserved, key order preserved).
|
|
30
30
|
*
|
|
31
|
-
* The transform recognizes the config default export as
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
31
|
+
* The transform recognizes the config default export as a bare object literal
|
|
32
|
+
* (`export default { ... }`), a `createConfig({ ... })` call wrapping an object
|
|
33
|
+
* literal (`export default createConfig({ ... })`), or an identifier bound by a
|
|
34
|
+
* top-level `const` to either form (`const config = { ... }; export default
|
|
35
|
+
* config;`, the shape generated configs use) when the binding is not
|
|
36
|
+
* exported any other way and the default export is its only reference, so
|
|
37
|
+
* nothing can mutate the object after its declaration. Anything else is not statically analyzable and the transform
|
|
38
|
+
* THROWS with a clear
|
|
35
39
|
* migrate-manually message (the unified config-codemod contract has no
|
|
36
40
|
* structured-error return — `runConfigCodemod` surfaces a thrown `err.message`
|
|
37
41
|
* as `{file, codemod, error}`).
|
|
@@ -76,10 +80,16 @@ export default function transformer(file, api) {
|
|
|
76
80
|
|
|
77
81
|
const declaration = defaultExports.paths()[0].node.declaration;
|
|
78
82
|
|
|
79
|
-
// Resolve the config object literal from
|
|
83
|
+
// Resolve the config object literal from any supported form:
|
|
80
84
|
// export default { ... }
|
|
81
85
|
// export default createConfig({ ... })
|
|
82
|
-
const
|
|
86
|
+
// const config = { ... } | createConfig({ ... }); export default config;
|
|
87
|
+
const configObject = resolveConfigObject(
|
|
88
|
+
j,
|
|
89
|
+
j.Identifier.check(declaration)
|
|
90
|
+
? findTopLevelConstInit(j, root, declaration)
|
|
91
|
+
: declaration,
|
|
92
|
+
);
|
|
83
93
|
if (!configObject) {
|
|
84
94
|
throw new Error(
|
|
85
95
|
`could not statically analyze astryx config; ${MANUAL}`,
|
|
@@ -179,6 +189,78 @@ function resolveConfigObject(/** @type {any} */ j, /** @type {any} */ declaratio
|
|
|
179
189
|
return null;
|
|
180
190
|
}
|
|
181
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Find the initializer of the top-level, non-exported `const <name> = <init>`
|
|
194
|
+
* declaration that the default-exported identifier refers to. `let`/`var`
|
|
195
|
+
* bindings can be reassigned, so they are not treated as statically
|
|
196
|
+
* analyzable. Neither is a binding exported any other way (`export const`,
|
|
197
|
+
* `export { name }`, `export { name as other }`), since another module could
|
|
198
|
+
* import and mutate it, nor one referenced anywhere besides its declaration
|
|
199
|
+
* and the default export: a member write, an alias or a call argument could
|
|
200
|
+
* change the object after its initializer. A named export specifier is such a
|
|
201
|
+
* reference, so `hasOtherReference` rejects it.
|
|
202
|
+
* @returns {any} the initializer node, or null if there is no such binding
|
|
203
|
+
*/
|
|
204
|
+
function findTopLevelConstInit(/** @type {any} */ j, /** @type {any} */ root, /** @type {any} */ exported) {
|
|
205
|
+
const name = exported.name;
|
|
206
|
+
for (const statement of root.get().node.program.body) {
|
|
207
|
+
// `export const` is skipped on purpose: another module can import the
|
|
208
|
+
// binding and mutate the object.
|
|
209
|
+
if (
|
|
210
|
+
!j.VariableDeclaration.check(statement) ||
|
|
211
|
+
statement.kind !== 'const'
|
|
212
|
+
) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
for (const declarator of statement.declarations) {
|
|
216
|
+
if (
|
|
217
|
+
j.VariableDeclarator.check(declarator) &&
|
|
218
|
+
j.Identifier.check(declarator.id) &&
|
|
219
|
+
declarator.id.name === name
|
|
220
|
+
) {
|
|
221
|
+
return hasOtherReference(j, root, name, [declarator.id, exported])
|
|
222
|
+
? null
|
|
223
|
+
: declarator.init ?? null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Whether any identifier named `name`, other than the `allowed` nodes, could
|
|
232
|
+
* refer to the binding. Non-computed member properties (`x.name`) and object
|
|
233
|
+
* keys (`{ name: 1 }`) name a property, not the binding, so they don't count;
|
|
234
|
+
* every other occurrence (including a shadowing one) does.
|
|
235
|
+
* @returns {boolean}
|
|
236
|
+
*/
|
|
237
|
+
function hasOtherReference(/** @type {any} */ j, /** @type {any} */ root, /** @type {string} */ name, /** @type {any[]} */ allowed) {
|
|
238
|
+
return root
|
|
239
|
+
.find(j.Identifier, {name})
|
|
240
|
+
.some((/** @type {any} */ path) => {
|
|
241
|
+
const node = path.node;
|
|
242
|
+
if (allowed.includes(node)) return false;
|
|
243
|
+
const parent = path.parent?.node;
|
|
244
|
+
if (
|
|
245
|
+
(j.MemberExpression.check(parent) ||
|
|
246
|
+
j.OptionalMemberExpression.check(parent)) &&
|
|
247
|
+
parent.property === node &&
|
|
248
|
+
!parent.computed
|
|
249
|
+
) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
if (
|
|
253
|
+
(j.ObjectProperty.check(parent) || j.Property.check(parent)) &&
|
|
254
|
+
parent.key === node &&
|
|
255
|
+
!parent.computed &&
|
|
256
|
+
!parent.shorthand
|
|
257
|
+
) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
182
264
|
/**
|
|
183
265
|
* Find a (non-computed, non-spread) property on an object literal by key name.
|
|
184
266
|
* Supports Identifier and string-literal keys.
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import path from 'node:path';
|
|
16
16
|
import postcss from 'postcss';
|
|
17
17
|
import selectorParser from 'postcss-selector-parser';
|
|
18
|
+
import {parseCss, processSelector} from '../../parse.mjs';
|
|
18
19
|
import {
|
|
19
20
|
V054_THEME_SELECTOR_DYNAMIC_AXES,
|
|
20
21
|
V054_THEME_SELECTOR_TARGETS,
|
|
@@ -555,7 +556,7 @@ function migrateSelectorTextWithContext(
|
|
|
555
556
|
) {
|
|
556
557
|
/** @type {TargetContext} */
|
|
557
558
|
let context = {guaranteed: [], possible: []};
|
|
558
|
-
const text =
|
|
559
|
+
const text = processSelector(selector, selectors => {
|
|
559
560
|
/** @type {TargetContext[]} */
|
|
560
561
|
const branchContexts = [];
|
|
561
562
|
selectors.each(selectorNode => {
|
|
@@ -593,7 +594,7 @@ function migrateSelectorTextWithContext(
|
|
|
593
594
|
});
|
|
594
595
|
});
|
|
595
596
|
context = combineSelectorListContexts(branchContexts);
|
|
596
|
-
})
|
|
597
|
+
});
|
|
597
598
|
return {text, context};
|
|
598
599
|
}
|
|
599
600
|
|
|
@@ -677,7 +678,7 @@ export function migrateAstryxThemeSelectors(source, from = 'styles.css', data) {
|
|
|
677
678
|
|
|
678
679
|
/** @param {string} source @param {string} from @returns {string} */
|
|
679
680
|
function migrateWithActiveTables(source, from) {
|
|
680
|
-
const root =
|
|
681
|
+
const root = parseCss(source, {from});
|
|
681
682
|
const existingComments = new Set();
|
|
682
683
|
root.walkComments(comment => {
|
|
683
684
|
existingComments.add(comment.text.trim());
|
package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
4
7
|
import jscodeshift from 'jscodeshift';
|
|
5
8
|
import manifest from '../index.mjs';
|
|
6
9
|
import transform, {
|
|
@@ -16,6 +19,38 @@ function apply(source, filePath = 'theme.ts') {
|
|
|
16
19
|
return transform({source, path: filePath}, api) ?? source;
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
/** A proven theme: an object passed to Astryx's imported defineTheme(). */
|
|
23
|
+
function defined(components) {
|
|
24
|
+
return `${IMPORT}export default defineTheme({name: 'brand', components: ${components}});`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const THEME_DOC = `/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */
|
|
28
|
+
export default {
|
|
29
|
+
type: 'theme',
|
|
30
|
+
name: 'brand',
|
|
31
|
+
displayName: 'Brand',
|
|
32
|
+
description: 'A brand theme.',
|
|
33
|
+
maintained: false,
|
|
34
|
+
};
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const tempDirs = [];
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
for (const dir of tempDirs.splice(0)) {
|
|
40
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/** Write `files` into a fresh directory and return its path. */
|
|
45
|
+
function folder(files) {
|
|
46
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-theme-surface-'));
|
|
47
|
+
tempDirs.push(dir);
|
|
48
|
+
for (const [name, content] of Object.entries(files)) {
|
|
49
|
+
fs.writeFileSync(path.join(dir, name), content);
|
|
50
|
+
}
|
|
51
|
+
return dir;
|
|
52
|
+
}
|
|
53
|
+
|
|
19
54
|
const EXPECTED_TARGETS = {
|
|
20
55
|
'base-table': 'table',
|
|
21
56
|
checkbox: 'checkbox-indicator',
|
|
@@ -60,7 +95,7 @@ describe('migrate-deprecated-theme-surface', () => {
|
|
|
60
95
|
'renames static target key %s to %s inside a components map',
|
|
61
96
|
(oldKey, newKey) => {
|
|
62
97
|
const output = apply(
|
|
63
|
-
`
|
|
98
|
+
defined(`{${JSON.stringify(oldKey)}: {base: {color: 'red'}}}`),
|
|
64
99
|
);
|
|
65
100
|
|
|
66
101
|
expect(output).not.toContain(`${JSON.stringify(oldKey)}:`);
|
|
@@ -103,12 +138,114 @@ export const theme = defineTheme({name: 'brand', components});`);
|
|
|
103
138
|
}
|
|
104
139
|
});
|
|
105
140
|
|
|
141
|
+
it('does not rewrite a look-alike theme object from another library', () => {
|
|
142
|
+
const input = `export const muiTheme = {
|
|
143
|
+
name: 'brand',
|
|
144
|
+
components: {checkbox: {root: {color: 'red'}}, radio: {root: {}}, textarea: {root: {}}},
|
|
145
|
+
};`;
|
|
146
|
+
expect(apply(input, 'src/muiTheme.ts')).toBe(input);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('does not take a file-level Astryx import as proof for a look-alike object', () => {
|
|
150
|
+
const input = `import {Button} from '@astryxdesign/core';
|
|
151
|
+
export const editorTheme = {name: 'editor', components: {textarea: {root: {}}}};`;
|
|
152
|
+
expect(apply(input, 'src/editorTheme.ts')).toBe(input);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('renames a direct theme object in a source its theme descriptor declares', () => {
|
|
156
|
+
const dir = folder({'brandTheme.doc.mjs': THEME_DOC});
|
|
157
|
+
const output = apply(
|
|
158
|
+
`export const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};`,
|
|
159
|
+
path.join(dir, 'brandTheme.ts'),
|
|
160
|
+
);
|
|
161
|
+
expect(output).toContain("'nav-icon':");
|
|
162
|
+
expect(output).not.toMatch(/navicon\s*:/);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('renames only the declared theme binding in a described theme source', () => {
|
|
166
|
+
const dir = folder({'brandTheme.doc.mjs': THEME_DOC});
|
|
167
|
+
const output = apply(
|
|
168
|
+
`export const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};
|
|
169
|
+
export const otherLibraryTheme = {
|
|
170
|
+
name: 'other',
|
|
171
|
+
components: {checkbox: {root: {}}, textarea: {root: {}}},
|
|
172
|
+
};`,
|
|
173
|
+
path.join(dir, 'brandTheme.ts'),
|
|
174
|
+
);
|
|
175
|
+
expect(output).toContain("'nav-icon':");
|
|
176
|
+
expect(output).toContain(
|
|
177
|
+
'components: {checkbox: {root: {}}, textarea: {root: {}}}',
|
|
178
|
+
);
|
|
179
|
+
expect(output).not.toContain('checkbox-indicator');
|
|
180
|
+
expect(output).not.toContain('text-area');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('follows a local binding exported under the descriptor name', () => {
|
|
184
|
+
const dir = folder({'brandTheme.doc.mjs': THEME_DOC});
|
|
185
|
+
const output = apply(
|
|
186
|
+
`const theme = {name: 'brand', components: {navicon: {base: {}}}} as const;
|
|
187
|
+
export {theme as brandTheme};`,
|
|
188
|
+
path.join(dir, 'brandTheme.ts'),
|
|
189
|
+
);
|
|
190
|
+
expect(output).toContain("'nav-icon':");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('does not treat an unexported or nested same-named object as the declared theme', () => {
|
|
194
|
+
const dir = folder({'brandTheme.doc.mjs': THEME_DOC});
|
|
195
|
+
for (const input of [
|
|
196
|
+
`const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};`,
|
|
197
|
+
`export function make() {
|
|
198
|
+
const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};
|
|
199
|
+
return brandTheme;
|
|
200
|
+
}`,
|
|
201
|
+
]) {
|
|
202
|
+
expect(apply(input, path.join(dir, 'brandTheme.ts'))).toBe(input);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('does not treat a descriptor for another stem or kind as theme proof', () => {
|
|
207
|
+
const input = `export const brandTheme = {name: 'brand', components: {navicon: {base: {}}}};`;
|
|
208
|
+
const otherStem = folder({'otherTheme.doc.mjs': THEME_DOC});
|
|
209
|
+
expect(apply(input, path.join(otherStem, 'brandTheme.ts'))).toBe(input);
|
|
210
|
+
const otherKind = folder({
|
|
211
|
+
'brandTheme.doc.mjs': 'export default {name: "brand", props: []};\n',
|
|
212
|
+
});
|
|
213
|
+
expect(apply(input, path.join(otherKind, 'brandTheme.ts'))).toBe(input);
|
|
214
|
+
});
|
|
215
|
+
|
|
106
216
|
it('does not treat a defineTheme from another library as an Astryx theme', () => {
|
|
107
217
|
const input = `import {defineTheme} from 'other-ui';
|
|
108
218
|
export default defineTheme({components: {checkbox: {base: {color: 'red'}}}});`;
|
|
109
219
|
expect(apply(input)).toBe(input);
|
|
110
220
|
});
|
|
111
221
|
|
|
222
|
+
it.each([
|
|
223
|
+
[
|
|
224
|
+
'named defineTheme',
|
|
225
|
+
`import {defineTheme} from '@astryxdesign/core';
|
|
226
|
+
function unrelated(defineTheme) {
|
|
227
|
+
return defineTheme({name: 'fake', components: {checkbox: {root: {}}}});
|
|
228
|
+
}`,
|
|
229
|
+
],
|
|
230
|
+
[
|
|
231
|
+
'aliased defineTheme',
|
|
232
|
+
`import {defineTheme as makeTheme} from '@astryxdesign/core';
|
|
233
|
+
function unrelated() {
|
|
234
|
+
const makeTheme = otherLibrary.createTheme;
|
|
235
|
+
return makeTheme({name: 'fake', components: {checkbox: {root: {}}}});
|
|
236
|
+
}`,
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
'namespace defineTheme',
|
|
240
|
+
`import * as Astryx from '@astryxdesign/core';
|
|
241
|
+
function unrelated(Astryx) {
|
|
242
|
+
return Astryx.defineTheme({name: 'fake', components: {checkbox: {root: {}}}});
|
|
243
|
+
}`,
|
|
244
|
+
],
|
|
245
|
+
])('does not treat a shadowed %s as an Astryx call', (_name, input) => {
|
|
246
|
+
expect(apply(input)).toBe(input);
|
|
247
|
+
});
|
|
248
|
+
|
|
112
249
|
it.each([
|
|
113
250
|
[
|
|
114
251
|
'an aliased defineTheme import',
|
|
@@ -141,9 +278,54 @@ const brand: DefineThemeInput = {name: 'brand', components: {navicon: {base: {}}
|
|
|
141
278
|
expect(output).not.toMatch(/navicon\s*:/);
|
|
142
279
|
});
|
|
143
280
|
|
|
281
|
+
it.each([
|
|
282
|
+
[
|
|
283
|
+
'a locally redeclared named type',
|
|
284
|
+
`import type {DefineThemeInput} from '@astryxdesign/core';
|
|
285
|
+
function unrelated() {
|
|
286
|
+
type DefineThemeInput = OtherTheme;
|
|
287
|
+
return {name: 'fake', components: {checkbox: {root: {}}}} satisfies DefineThemeInput;
|
|
288
|
+
}`,
|
|
289
|
+
],
|
|
290
|
+
[
|
|
291
|
+
'an aliased type shadowed by a type parameter',
|
|
292
|
+
`import type {DefineThemeInput as Theme} from '@astryxdesign/core';
|
|
293
|
+
function unrelated<Theme>(value: unknown) {
|
|
294
|
+
const theme: Theme = {name: 'fake', components: {checkbox: {root: {}}}};
|
|
295
|
+
return theme;
|
|
296
|
+
}`,
|
|
297
|
+
],
|
|
298
|
+
[
|
|
299
|
+
'a namespace shadowed by a type parameter',
|
|
300
|
+
`import type * as Astryx from '@astryxdesign/core';
|
|
301
|
+
function unrelated<Astryx>() {
|
|
302
|
+
return {name: 'fake', components: {checkbox: {root: {}}}} satisfies Astryx.DefineThemeInput;
|
|
303
|
+
}`,
|
|
304
|
+
],
|
|
305
|
+
[
|
|
306
|
+
'a namespace shadowed by a local namespace',
|
|
307
|
+
`import * as Astryx from '@astryxdesign/core';
|
|
308
|
+
function unrelated() {
|
|
309
|
+
namespace Astryx { export type DefineThemeInput = OtherTheme; }
|
|
310
|
+
return ({name: 'fake', components: {checkbox: {root: {}}}}) as Astryx.DefineThemeInput;
|
|
311
|
+
}`,
|
|
312
|
+
],
|
|
313
|
+
])('does not treat %s as an Astryx theme type', (_name, input) => {
|
|
314
|
+
expect(apply(input)).toBe(input);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('still recognizes an unshadowed theme type inside a function', () => {
|
|
318
|
+
const output =
|
|
319
|
+
apply(`import type {DefineThemeInput} from '@astryxdesign/core';
|
|
320
|
+
function makeTheme<T>() {
|
|
321
|
+
return {components: {navicon: {base: {}}}} satisfies DefineThemeInput;
|
|
322
|
+
}`);
|
|
323
|
+
expect(output).toContain("'nav-icon':");
|
|
324
|
+
});
|
|
325
|
+
|
|
144
326
|
it('renames a clear-icon alias with a TODO naming the owner scope it loses', () => {
|
|
145
327
|
const output = apply(
|
|
146
|
-
`
|
|
328
|
+
defined(`{'selector-clear-icon': {base: {color: 'red'}}}`),
|
|
147
329
|
);
|
|
148
330
|
expect(output).toContain("'input-clear-icon':");
|
|
149
331
|
expect(output).toContain(
|
|
@@ -155,10 +337,12 @@ const brand: DefineThemeInput = {name: 'brand', components: {navicon: {base: {}}
|
|
|
155
337
|
});
|
|
156
338
|
|
|
157
339
|
it('flags two clear-icon aliases that collapse onto the shared target', () => {
|
|
158
|
-
const output = apply(
|
|
340
|
+
const output = apply(
|
|
341
|
+
defined(`{
|
|
159
342
|
'selector-clear-icon': {base: {color: 'red'}},
|
|
160
343
|
'date-input-clear-icon': {base: {color: 'blue'}},
|
|
161
|
-
}
|
|
344
|
+
}`),
|
|
345
|
+
);
|
|
162
346
|
expect(output).toContain("'input-clear-icon':");
|
|
163
347
|
expect(output).toContain(
|
|
164
348
|
'merge deprecated theme target `date-input-clear-icon` into `input-clear-icon`',
|
|
@@ -291,6 +475,21 @@ const theme = {name: 'brand', components: {[oldTarget]: {base: {color: 'red'}}}}
|
|
|
291
475
|
expect(apply(output, 'theme.css')).toBe(output);
|
|
292
476
|
});
|
|
293
477
|
|
|
478
|
+
it('maps only the column values MetadataList emitted, not app classes', () => {
|
|
479
|
+
const output = apply(
|
|
480
|
+
`.astryx-metadata-list.app-compact-list { gap: 4px; }
|
|
481
|
+
.astryx-metadata-list.columns-3, .astryx-metadata-list.multi { gap: 8px; }`,
|
|
482
|
+
'theme.css',
|
|
483
|
+
);
|
|
484
|
+
expect(output).toContain('.astryx-metadata-list.app-compact-list');
|
|
485
|
+
expect(output).not.toContain('data-columns="app-compact-list"');
|
|
486
|
+
expect(output).toContain('.astryx-metadata-list:is([data-columns="3"])');
|
|
487
|
+
expect(output).not.toContain('data-columns="columns-3"');
|
|
488
|
+
expect(output).toContain(
|
|
489
|
+
'.astryx-metadata-list:is([data-columns="multi"])',
|
|
490
|
+
);
|
|
491
|
+
});
|
|
492
|
+
|
|
294
493
|
it('leaves unqualified and unknown consumer classes unchanged', () => {
|
|
295
494
|
const input = `.primary { color: red; }
|
|
296
495
|
.astryx-button.brand { color: blue; }`;
|
|
@@ -312,7 +511,9 @@ const theme = {name: 'brand', components: {[oldTarget]: {base: {color: 'red'}}}}
|
|
|
312
511
|
});
|
|
313
512
|
|
|
314
513
|
it('is byte-idempotent after JavaScript and CSS migration', () => {
|
|
315
|
-
const js =
|
|
514
|
+
const js = defined(
|
|
515
|
+
`{statusdot: {base: {color: 'red'}}, 'selector-clear-icon': {base: {color: 'red'}}}`,
|
|
516
|
+
);
|
|
316
517
|
const css = '.astryx-textarea.sm {}';
|
|
317
518
|
const jsOnce = apply(js);
|
|
318
519
|
const cssOnce = apply(css, 'theme.css');
|