@astryxdesign/cli 0.7.4 → 0.7.5-canary.04434e7
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 +19 -19
- 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/unknown-name.test.mjs +63 -0
- package/api/upgrade/run/failure-receipt.test.mjs +155 -0
- package/api/upgrade/run/run.mjs +170 -8
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +12 -1
- package/api/upgrade/upgrade.type.mjs +16 -3
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/run-codemod.mjs +17 -3
- package/assets/codemods/runner.mjs +81 -8
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- 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 +123 -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 +200 -32
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +19 -77
- package/assets/discover/official-packages.json +4 -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/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/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 +9 -8
- 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/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -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/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 +17 -0
- package/clients/cli/commands/upgrade.file-protection.test.mjs +29 -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/index.mjs +1 -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 +38 -1
- 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 +14 -9
|
@@ -1,95 +1,148 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import {afterAll, describe, expect, it} from 'vitest';
|
|
7
|
+
import transform, {meta} from '../validate-data-token-ownership.mjs';
|
|
8
|
+
import {upgrade} from '../../../../../api/upgrade/upgrade.mjs';
|
|
5
9
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const SLOW = 30_000;
|
|
11
|
+
const tempRoots = [];
|
|
12
|
+
|
|
13
|
+
afterAll(() => {
|
|
14
|
+
for (const root of tempRoots) fs.rmSync(root, {recursive: true, force: true});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const STALE_THEME = `/* @generated by \`astryx theme build\` */
|
|
18
|
+
@layer astryx-base {
|
|
19
|
+
:root { --color-data-categorical-green: #008000; }
|
|
20
|
+
}`;
|
|
21
|
+
|
|
22
|
+
const RAW_USES = {
|
|
23
|
+
'src/chart.tsx': `export const fill = 'var(--color-data-categorical-green)';
|
|
24
|
+
export const border = \`1px solid var(--color-data-blue-3)\`;
|
|
25
|
+
`,
|
|
26
|
+
'src/chart.css': '.bar { fill: var(--color-data-categorical-green); }\n',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A project with Core 0.7.0 installed and the given files, as a repository.
|
|
31
|
+
* @param {Record<string, string | object>} files
|
|
32
|
+
*/
|
|
33
|
+
function project(files) {
|
|
34
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-data-token-'));
|
|
35
|
+
tempRoots.push(root);
|
|
36
|
+
fs.mkdirSync(path.join(root, '.git'));
|
|
37
|
+
const all = {
|
|
38
|
+
'node_modules/@astryxdesign/core/package.json': {
|
|
39
|
+
name: '@astryxdesign/core',
|
|
40
|
+
version: '0.7.0',
|
|
41
|
+
},
|
|
42
|
+
...files,
|
|
14
43
|
};
|
|
15
|
-
|
|
44
|
+
for (const [rel, contents] of Object.entries(all)) {
|
|
45
|
+
const file = path.join(root, rel);
|
|
46
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
47
|
+
fs.writeFileSync(
|
|
48
|
+
file,
|
|
49
|
+
typeof contents === 'string' ? contents : JSON.stringify(contents),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return root;
|
|
16
53
|
}
|
|
17
54
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
55
|
+
const PREBUILT = {
|
|
56
|
+
'package.json': {dependencies: {'@astryxdesign/core': '0.7.3'}},
|
|
57
|
+
'src/main.tsx': "import '@astryxdesign/core/astryx.css';\n",
|
|
58
|
+
};
|
|
59
|
+
const SOURCE_BUILT = {
|
|
60
|
+
'package.json': {
|
|
61
|
+
dependencies: {'@astryxdesign/core': '0.7.3'},
|
|
62
|
+
devDependencies: {'@astryxdesign/build': '0.7.3'},
|
|
63
|
+
},
|
|
64
|
+
'vite.config.ts':
|
|
65
|
+
"import {astryxStylex} from '@astryxdesign/build/vite';\nexport default {plugins: [...astryxStylex()]};\n",
|
|
66
|
+
};
|
|
31
67
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
);
|
|
38
|
-
await expect(
|
|
39
|
-
run('.bar { fill: var(--color-data-categorical-blue); }', 'chart.css'),
|
|
40
|
-
).rejects.toThrow(/load @astryxdesign\/core\/astryx\.css in prebuilt mode/);
|
|
41
|
-
});
|
|
68
|
+
const runUpgrade = root =>
|
|
69
|
+
upgrade(
|
|
70
|
+
{from: '0.6.9', codemod: 'validate-data-token-ownership', apply: true},
|
|
71
|
+
{cwd: root},
|
|
72
|
+
);
|
|
42
73
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const fallback = 'var(--color-data-categorical-green, #008000)';
|
|
47
|
-
const fill = dataVars['--color-data-categorical-green'];
|
|
48
|
-
`;
|
|
49
|
-
expect(await run(source)).toBeUndefined();
|
|
74
|
+
describe('validate-data-token-ownership', () => {
|
|
75
|
+
it('reads only stylesheets', () => {
|
|
76
|
+
expect(meta.fileExtensions).toEqual(['.css']);
|
|
50
77
|
});
|
|
51
78
|
|
|
52
|
-
it('
|
|
53
|
-
|
|
54
|
-
@layer astryx-base {
|
|
55
|
-
:root { --color-data-categorical-green: #008000; }
|
|
56
|
-
}`;
|
|
57
|
-
await expect(run(source, 'theme.css')).rejects.toThrow(
|
|
79
|
+
it('fails on stale generated theme CSS with root data defaults', () => {
|
|
80
|
+
expect(() => transform({source: STALE_THEME, path: 'theme.css'})).toThrow(
|
|
58
81
|
/Rebuild it with `astryx theme build`/,
|
|
59
82
|
);
|
|
60
83
|
});
|
|
61
84
|
|
|
62
|
-
it('
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
`/* var(--color-data-categorical-green) */
|
|
72
|
-
.bar { fill: var(--color-data-categorical-green, #008000); }`,
|
|
73
|
-
'chart.css',
|
|
74
|
-
),
|
|
75
|
-
).toBeUndefined();
|
|
85
|
+
it('passes raw data-token uses with or without a fallback', () => {
|
|
86
|
+
for (const source of [
|
|
87
|
+
'.bar { fill: var(--color-data-categorical-green); }',
|
|
88
|
+
'.bar { fill: var(--color-data-categorical-green, #008000); }',
|
|
89
|
+
`/* @generated by \`astryx theme build\` */
|
|
90
|
+
.bar { fill: var(--color-data-blue-3); }`,
|
|
91
|
+
]) {
|
|
92
|
+
expect(transform({source, path: 'chart.css'})).toBeUndefined();
|
|
93
|
+
}
|
|
76
94
|
});
|
|
77
95
|
|
|
78
|
-
it('does not claim ownership of hand-authored CSS or sparse theme overrides',
|
|
96
|
+
it('does not claim ownership of hand-authored CSS or sparse theme overrides', () => {
|
|
79
97
|
expect(
|
|
80
|
-
|
|
81
|
-
':root { --color-data-categorical-green: #008000; }',
|
|
82
|
-
'app.css',
|
|
83
|
-
),
|
|
98
|
+
transform({
|
|
99
|
+
source: ':root { --color-data-categorical-green: #008000; }',
|
|
100
|
+
path: 'app.css',
|
|
101
|
+
}),
|
|
84
102
|
).toBeUndefined();
|
|
85
103
|
expect(
|
|
86
|
-
|
|
87
|
-
`/* @generated by \`astryx theme build\` */
|
|
104
|
+
transform({
|
|
105
|
+
source: `/* @generated by \`astryx theme build\` */
|
|
88
106
|
@scope ([data-astryx-theme="ocean"]) {
|
|
89
107
|
:scope { --color-data-categorical-green: #008000; }
|
|
90
108
|
}`,
|
|
91
|
-
'theme.css',
|
|
92
|
-
),
|
|
109
|
+
path: 'theme.css',
|
|
110
|
+
}),
|
|
93
111
|
).toBeUndefined();
|
|
94
112
|
});
|
|
113
|
+
|
|
114
|
+
it(
|
|
115
|
+
'completes `astryx upgrade --apply` over raw uses in a prebuilt project',
|
|
116
|
+
async () => {
|
|
117
|
+
const root = project({...PREBUILT, ...RAW_USES});
|
|
118
|
+
const res = await runUpgrade(root);
|
|
119
|
+
expect(res.data.complete).toBe(true);
|
|
120
|
+
expect(res.data.errors ?? []).toEqual([]);
|
|
121
|
+
expect(res.data.modifiedFiles ?? []).toEqual([]);
|
|
122
|
+
},
|
|
123
|
+
SLOW,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
it(
|
|
127
|
+
'completes `astryx upgrade --apply` over raw uses in a source-built project',
|
|
128
|
+
async () => {
|
|
129
|
+
const root = project({...SOURCE_BUILT, ...RAW_USES});
|
|
130
|
+
const res = await runUpgrade(root);
|
|
131
|
+
expect(res.data.complete).toBe(true);
|
|
132
|
+
expect(res.data.errors ?? []).toEqual([]);
|
|
133
|
+
expect(res.data.modifiedFiles ?? []).toEqual([]);
|
|
134
|
+
},
|
|
135
|
+
SLOW,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
it(
|
|
139
|
+
'fails `astryx upgrade --apply` on stale generated theme CSS',
|
|
140
|
+
async () => {
|
|
141
|
+
const root = project({...PREBUILT, 'src/theme.css': STALE_THEME});
|
|
142
|
+
await expect(runUpgrade(root)).rejects.toMatchObject({
|
|
143
|
+
code: 'ERR_CODEMOD_FAILED',
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
SLOW,
|
|
147
|
+
);
|
|
95
148
|
});
|
|
@@ -214,6 +214,11 @@ export const V06_THEME_SELECTOR_TARGETS = {
|
|
|
214
214
|
"typeahead": {"error":["status","error"],"lg":["size","lg"],"md":["size","md"],"sm":["size","sm"],"success":["status","success"],"warning":["status","warning"]},
|
|
215
215
|
};
|
|
216
216
|
|
|
217
|
+
// Only a prop typed as an open string emitted unbounded bare classes
|
|
218
|
+
// (CodeBlock `language`). MetadataList `columns` is `'single' | 'multi' |
|
|
219
|
+
// number`: its strings are in the table above and every number keeps the
|
|
220
|
+
// `columns-` prefix, so any other class beside `.astryx-metadata-list` is
|
|
221
|
+
// the app's own and stays unchanged.
|
|
217
222
|
/** @type {Record<string, Array<{axis: string, token: 'class-value' | 'prefixed', prefix?: string}>>} */
|
|
218
223
|
// prettier-ignore
|
|
219
224
|
export const V06_THEME_SELECTOR_DYNAMIC_AXES = {
|
|
@@ -224,6 +229,6 @@ export const V06_THEME_SELECTOR_DYNAMIC_AXES = {
|
|
|
224
229
|
"codeblock-header": [{"axis":"language","token":"class-value"}],
|
|
225
230
|
"codeblock-title": [{"axis":"language","token":"class-value"}],
|
|
226
231
|
"grid": [{"axis":"columns","token":"prefixed","prefix":"columns-"}],
|
|
227
|
-
"metadata-list": [{"axis":"columns","token":"prefixed","prefix":"columns-"}
|
|
232
|
+
"metadata-list": [{"axis":"columns","token":"prefixed","prefix":"columns-"}],
|
|
228
233
|
"outline-item": [{"axis":"level","token":"prefixed","prefix":"level-"}],
|
|
229
234
|
};
|
|
@@ -5,19 +5,28 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Static keys directly inside a theme's `components` object move to their
|
|
7
7
|
* canonical target. A theme is a `defineTheme()` call imported from Astryx, an
|
|
8
|
-
* object typed as an Astryx theme (annotation, `as`, or `satisfies`), or
|
|
9
|
-
* direct theme object
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* object typed as an Astryx theme (annotation, `as`, or `satisfies`), or the
|
|
9
|
+
* direct theme object a same-stem theme descriptor (`<stem>.doc.mjs`) declares:
|
|
10
|
+
* the top-level binding exported as `<stem>`, with a static `name` and
|
|
11
|
+
* component entries that are style objects. Shape alone is not proof: a
|
|
12
|
+
* look-alike object anywhere else, including another object in the same theme
|
|
13
|
+
* source, is left unchanged. CSS selectors move the same target classes, keep
|
|
14
|
+
* the owner scope of the per-component clear-icon aliases, and replace
|
|
15
|
+
* target-qualified bare prop/state classes with reflected `data-*` selectors
|
|
16
|
+
* using the final 0.6 runtime contract. A known bare class that cannot be
|
|
17
|
+
* classified for its target gets a TODO. Dynamic theme keys, unqualified classes, declarations, comments,
|
|
15
18
|
* and strings containing CSS are left for manual review.
|
|
16
19
|
*/
|
|
17
20
|
|
|
21
|
+
import * as fs from 'node:fs';
|
|
18
22
|
import path from 'node:path';
|
|
19
23
|
import postcss from 'postcss';
|
|
20
24
|
import selectorParser from 'postcss-selector-parser';
|
|
25
|
+
import {readThemeDescriptorValue} from '../../../../foundation/discovery/theme-discovery.mjs';
|
|
26
|
+
import {
|
|
27
|
+
importedComponents,
|
|
28
|
+
resolveImportedComponent,
|
|
29
|
+
} from '../../transform-prop.mjs';
|
|
21
30
|
import {migrateAstryxThemeSelectors} from '../v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs';
|
|
22
31
|
import {
|
|
23
32
|
V06_THEME_SELECTOR_DYNAMIC_AXES,
|
|
@@ -338,15 +347,88 @@ const TS_WRAPPERS = new Set([
|
|
|
338
347
|
]);
|
|
339
348
|
|
|
340
349
|
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
350
|
+
* The export name a same-stem theme descriptor beside this file declares
|
|
351
|
+
* (`brandTheme` for `brandTheme.ts` beside `brandTheme.doc.mjs`), or null. The
|
|
352
|
+
* descriptor is read statically, never executed; an unreadable or non-theme
|
|
353
|
+
* descriptor is not proof.
|
|
354
|
+
* @param {string} filePath
|
|
355
|
+
* @returns {string | null}
|
|
356
|
+
*/
|
|
357
|
+
function describedThemeExportName(filePath) {
|
|
358
|
+
const stem = path.basename(filePath, path.extname(filePath));
|
|
359
|
+
const docPath = path.join(path.dirname(filePath), `${stem}.doc.mjs`);
|
|
360
|
+
if (!fs.existsSync(docPath)) return null;
|
|
361
|
+
try {
|
|
362
|
+
return readThemeDescriptorValue(docPath, `Theme descriptor ${docPath}`)
|
|
363
|
+
.type === 'theme'
|
|
364
|
+
? stem
|
|
365
|
+
: null;
|
|
366
|
+
} catch {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Top-level local names this module exports under `exportName`: an exported
|
|
373
|
+
* declaration of that name, or a source-less `export {local as exportName}`.
|
|
374
|
+
* @param {any} root @param {any} j @param {string} exportName
|
|
375
|
+
*/
|
|
376
|
+
function localNamesExportedAs(root, j, exportName) {
|
|
377
|
+
/** @type {Set<string>} */
|
|
378
|
+
const locals = new Set();
|
|
379
|
+
root
|
|
380
|
+
.find(j.ExportNamedDeclaration)
|
|
381
|
+
.forEach((/** @type {any} */ exportPath) => {
|
|
382
|
+
const node = exportPath.node;
|
|
383
|
+
if (node.exportKind === 'type' || node.source) return;
|
|
384
|
+
for (const declarator of node.declaration?.declarations ?? []) {
|
|
385
|
+
if (declarator.id?.name === exportName) locals.add(exportName);
|
|
386
|
+
}
|
|
387
|
+
for (const specifier of node.specifiers ?? []) {
|
|
388
|
+
const exported = specifier.exported?.name ?? specifier.exported?.value;
|
|
389
|
+
const local = specifier.local?.name ?? specifier.local?.value;
|
|
390
|
+
if (
|
|
391
|
+
specifier.exportKind !== 'type' &&
|
|
392
|
+
exported === exportName &&
|
|
393
|
+
typeof local === 'string'
|
|
394
|
+
) {
|
|
395
|
+
locals.add(local);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
return locals;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Astryx's `defineTheme` imports (resolved at each call site, so a shadowing
|
|
404
|
+
* parameter or local never counts), its theme types, an Astryx namespace
|
|
405
|
+
* import, and the binding a theme descriptor declares.
|
|
406
|
+
* @param {any} root @param {any} j @param {string} filePath
|
|
344
407
|
*/
|
|
345
|
-
function astryxThemeBindings(root, j) {
|
|
408
|
+
function astryxThemeBindings(root, j, filePath) {
|
|
409
|
+
/** @type {Set<string> | undefined} */
|
|
410
|
+
let describedLocals;
|
|
346
411
|
const bindings = {
|
|
347
|
-
defineTheme:
|
|
412
|
+
defineTheme: importedComponents(root, j, {
|
|
413
|
+
matchesImport: source => ASTRYX_MODULE.test(source),
|
|
414
|
+
components: new Map([['defineTheme', new Set()]]),
|
|
415
|
+
}),
|
|
348
416
|
themeTypes: new Set(),
|
|
349
417
|
namespaces: new Set(),
|
|
418
|
+
/**
|
|
419
|
+
* Top-level locals exported under the descriptor's name. Read lazily:
|
|
420
|
+
* only a direct theme-shaped object needs the descriptor.
|
|
421
|
+
* @returns {Set<string>}
|
|
422
|
+
*/
|
|
423
|
+
describedThemeLocals() {
|
|
424
|
+
if (describedLocals == null) {
|
|
425
|
+
const exportName = describedThemeExportName(filePath);
|
|
426
|
+
describedLocals = exportName
|
|
427
|
+
? localNamesExportedAs(root, j, exportName)
|
|
428
|
+
: new Set();
|
|
429
|
+
}
|
|
430
|
+
return describedLocals;
|
|
431
|
+
},
|
|
350
432
|
};
|
|
351
433
|
root.find(j.ImportDeclaration).forEach((/** @type {any} */ importPath) => {
|
|
352
434
|
const source = importPath.node.source?.value;
|
|
@@ -358,7 +440,6 @@ function astryxThemeBindings(root, j) {
|
|
|
358
440
|
bindings.namespaces.add(local);
|
|
359
441
|
} else if (specifier.type === 'ImportSpecifier') {
|
|
360
442
|
const imported = specifier.imported?.name ?? specifier.imported?.value;
|
|
361
|
-
if (imported === 'defineTheme') bindings.defineTheme.add(local);
|
|
362
443
|
if (THEME_TYPE_NAMES.has(imported)) bindings.themeTypes.add(local);
|
|
363
444
|
}
|
|
364
445
|
}
|
|
@@ -379,20 +460,80 @@ function namesBinding(name, locals, namespaces, members) {
|
|
|
379
460
|
);
|
|
380
461
|
}
|
|
381
462
|
|
|
382
|
-
/** @param {any} typeNode @param {ReturnType<typeof astryxThemeBindings>} bindings */
|
|
383
|
-
function isAstryxThemeType(typeNode, bindings) {
|
|
463
|
+
/** @param {any} typeNode @param {any} usePath @param {ReturnType<typeof astryxThemeBindings>} bindings */
|
|
464
|
+
function isAstryxThemeType(typeNode, usePath, bindings) {
|
|
384
465
|
const node = typeNode?.typeAnnotation ?? typeNode;
|
|
385
|
-
|
|
386
|
-
node?.type
|
|
387
|
-
namesBinding(
|
|
466
|
+
if (
|
|
467
|
+
node?.type !== 'TSTypeReference' ||
|
|
468
|
+
!namesBinding(
|
|
388
469
|
node.typeName,
|
|
389
470
|
bindings.themeTypes,
|
|
390
471
|
bindings.namespaces,
|
|
391
472
|
THEME_TYPE_NAMES,
|
|
392
473
|
)
|
|
474
|
+
) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
const root =
|
|
478
|
+
node.typeName.type === 'Identifier' ? node.typeName : node.typeName.left;
|
|
479
|
+
return isModuleTypeBinding(usePath, root.name);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** @param {any} statement @param {string} name */
|
|
483
|
+
function statementDeclares(statement, name) {
|
|
484
|
+
const node =
|
|
485
|
+
statement?.type === 'ExportNamedDeclaration' ||
|
|
486
|
+
statement?.type === 'ExportDefaultDeclaration'
|
|
487
|
+
? statement.declaration
|
|
488
|
+
: statement;
|
|
489
|
+
if (node?.id?.type === 'Identifier' && node.id.name === name) return true;
|
|
490
|
+
return (node?.declarations ?? []).some(
|
|
491
|
+
(/** @type {any} */ declarator) =>
|
|
492
|
+
declarator.id?.type === 'Identifier' && declarator.id.name === name,
|
|
393
493
|
);
|
|
394
494
|
}
|
|
395
495
|
|
|
496
|
+
/**
|
|
497
|
+
* True when a type-position `name` at `path` can only mean the module-scope
|
|
498
|
+
* import: no enclosing type parameter, parameter, or block-level declaration
|
|
499
|
+
* (type alias, interface, enum, class, namespace, function, or variable)
|
|
500
|
+
* reuses the name. Anything this cannot rule out counts as shadowed.
|
|
501
|
+
* @param {any} path @param {string} name
|
|
502
|
+
*/
|
|
503
|
+
function isModuleTypeBinding(path, name) {
|
|
504
|
+
const valueScope = path.scope?.lookup(name);
|
|
505
|
+
if (valueScope != null && valueScope.path.node.type !== 'Program') {
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
for (let current = path; current != null; current = current.parent) {
|
|
509
|
+
const node = current.node;
|
|
510
|
+
if (node.type === 'Program') return true;
|
|
511
|
+
const typeParameters = node.typeParameters?.params ?? [];
|
|
512
|
+
if (
|
|
513
|
+
typeParameters.some(
|
|
514
|
+
(/** @type {any} */ parameter) =>
|
|
515
|
+
(parameter.name?.name ?? parameter.name) === name,
|
|
516
|
+
)
|
|
517
|
+
) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
const statements =
|
|
521
|
+
node.type === 'SwitchCase'
|
|
522
|
+
? node.consequent
|
|
523
|
+
: node.type !== 'ClassBody' && Array.isArray(node.body)
|
|
524
|
+
? node.body
|
|
525
|
+
: [];
|
|
526
|
+
if (
|
|
527
|
+
statements.some((/** @type {any} */ statement) =>
|
|
528
|
+
statementDeclares(statement, name),
|
|
529
|
+
)
|
|
530
|
+
) {
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
|
|
396
537
|
/**
|
|
397
538
|
* True for a theme object whose shape alone identifies it: a static string
|
|
398
539
|
* `name` beside a `components` map whose entries are all style objects.
|
|
@@ -426,16 +567,45 @@ function isDirectThemeObject(node) {
|
|
|
426
567
|
);
|
|
427
568
|
}
|
|
428
569
|
|
|
570
|
+
/**
|
|
571
|
+
* True when this object literal initializes the top-level binding that the
|
|
572
|
+
* file's theme descriptor declares, directly or through TypeScript wrappers.
|
|
573
|
+
* @param {any} objectPath @param {ReturnType<typeof astryxThemeBindings>} bindings
|
|
574
|
+
*/
|
|
575
|
+
function isDescribedThemeBinding(objectPath, bindings) {
|
|
576
|
+
let parent = objectPath.parent;
|
|
577
|
+
while (parent != null && TS_WRAPPERS.has(parent.node.type)) {
|
|
578
|
+
parent = parent.parent;
|
|
579
|
+
}
|
|
580
|
+
const declarator = parent?.node;
|
|
581
|
+
if (
|
|
582
|
+
declarator?.type !== 'VariableDeclarator' ||
|
|
583
|
+
declarator.id?.type !== 'Identifier'
|
|
584
|
+
) {
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
const declaration = parent.parent;
|
|
588
|
+
const container = declaration?.parent?.node;
|
|
589
|
+
const topLevel =
|
|
590
|
+
container?.type === 'Program' ||
|
|
591
|
+
(container?.type === 'ExportNamedDeclaration' &&
|
|
592
|
+
declaration.parent.parent?.node.type === 'Program');
|
|
593
|
+
return topLevel && bindings.describedThemeLocals().has(declarator.id.name);
|
|
594
|
+
}
|
|
595
|
+
|
|
429
596
|
/**
|
|
430
597
|
* True when this object literal is an Astryx theme: the argument of an
|
|
431
|
-
* imported `defineTheme()`, typed as an Astryx theme, or
|
|
598
|
+
* imported `defineTheme()`, typed as an Astryx theme, or the direct theme
|
|
599
|
+
* object a theme descriptor declares.
|
|
432
600
|
* @param {any} objectPath @param {ReturnType<typeof astryxThemeBindings>} bindings
|
|
433
601
|
*/
|
|
434
602
|
function isThemeRoot(objectPath, bindings) {
|
|
435
603
|
let child = objectPath;
|
|
436
604
|
let parent = objectPath.parent;
|
|
437
605
|
while (parent != null && TS_WRAPPERS.has(parent.node.type)) {
|
|
438
|
-
if (isAstryxThemeType(parent.node.typeAnnotation, bindings))
|
|
606
|
+
if (isAstryxThemeType(parent.node.typeAnnotation, parent, bindings)) {
|
|
607
|
+
return true;
|
|
608
|
+
}
|
|
439
609
|
child = parent;
|
|
440
610
|
parent = parent.parent;
|
|
441
611
|
}
|
|
@@ -443,22 +613,20 @@ function isThemeRoot(objectPath, bindings) {
|
|
|
443
613
|
if (
|
|
444
614
|
node?.type === 'CallExpression' &&
|
|
445
615
|
node.arguments?.[0] === child.node &&
|
|
446
|
-
|
|
447
|
-
node.callee,
|
|
448
|
-
bindings.defineTheme,
|
|
449
|
-
bindings.namespaces,
|
|
450
|
-
new Set(['defineTheme']),
|
|
451
|
-
)
|
|
616
|
+
resolveImportedComponent(node.callee, parent, bindings.defineTheme)
|
|
452
617
|
) {
|
|
453
618
|
return true;
|
|
454
619
|
}
|
|
455
620
|
if (
|
|
456
621
|
node?.type === 'VariableDeclarator' &&
|
|
457
|
-
isAstryxThemeType(node.id?.typeAnnotation, bindings)
|
|
622
|
+
isAstryxThemeType(node.id?.typeAnnotation, parent, bindings)
|
|
458
623
|
) {
|
|
459
624
|
return true;
|
|
460
625
|
}
|
|
461
|
-
return
|
|
626
|
+
return (
|
|
627
|
+
isDirectThemeObject(objectPath.node) &&
|
|
628
|
+
isDescribedThemeBinding(objectPath, bindings)
|
|
629
|
+
);
|
|
462
630
|
}
|
|
463
631
|
|
|
464
632
|
/**
|
|
@@ -567,10 +735,10 @@ function addScopeTodo(property, oldKey, owner, j) {
|
|
|
567
735
|
];
|
|
568
736
|
}
|
|
569
737
|
|
|
570
|
-
/** @param {string} source @param {any} j */
|
|
571
|
-
function migrateStaticThemeKeys(source, j) {
|
|
738
|
+
/** @param {string} source @param {string} filePath @param {any} j */
|
|
739
|
+
function migrateStaticThemeKeys(source, filePath, j) {
|
|
572
740
|
const root = j(source);
|
|
573
|
-
const bindings = astryxThemeBindings(root, j);
|
|
741
|
+
const bindings = astryxThemeBindings(root, j, filePath);
|
|
574
742
|
let changed = false;
|
|
575
743
|
|
|
576
744
|
root.find(j.ObjectExpression).forEach((/** @type {any} */ objectPath) => {
|
|
@@ -620,5 +788,5 @@ export default function migrateDeprecatedThemeSurface(file, api) {
|
|
|
620
788
|
const result = migrateCss(file.source, file.path);
|
|
621
789
|
return result === file.source ? undefined : result;
|
|
622
790
|
}
|
|
623
|
-
return migrateStaticThemeKeys(file.source, api.jscodeshift);
|
|
791
|
+
return migrateStaticThemeKeys(file.source, file.path, api.jscodeshift);
|
|
624
792
|
}
|