@astryxdesign/cli 0.6.1 → 0.6.2-canary.0faf070
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -1
- package/README.md +1 -1
- package/api/component/_adapter.mjs +64 -23
- package/api/component/component.doc.mjs +1 -1
- package/api/component/component.type.d.mts +8 -2
- package/api/component/component.type.mjs +5 -2
- package/api/component/integration-import-agreement.test.mjs +162 -6
- package/api/component/list/list.mjs +91 -15
- package/api/doctor/doctor.mjs +5 -16
- package/api/init/init.doc.mjs +2 -2
- package/api/init/init.type.d.mts +1 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/run/run.mjs +1 -1
- package/api/integration/add-helpers.mjs +2 -1
- package/api/integration/pack-check.mjs +9 -3
- package/api/search/search.d.mts +1 -1
- package/api/search/search.mjs +135 -41
- package/api/theme/build/build.d.mts +45 -17
- package/api/theme/build/build.family.test.mjs +435 -0
- package/api/theme/build/build.mjs +681 -121
- package/api/theme/build/build.packed-old-core.test.mjs +25 -9
- package/api/theme/build/build.test.mjs +142 -0
- package/api/theme/build/core-interception.d.mts +14 -2
- package/api/theme/build/core-interception.mjs +38 -14
- package/api/theme/build/family.d.mts +15 -0
- package/api/theme/build/family.mjs +442 -0
- package/api/theme/palette/generate/generate.mjs +2 -1
- package/assets/docs/theme.doc.dense.mjs +12 -0
- package/assets/docs/theme.doc.mjs +37 -0
- package/assets/docs/working-with-ai.doc.mjs +2 -1
- package/assets/templates/blocks/components/Kbd/KbdModifierCombos.tsx +3 -1
- package/clients/cli/commands/build-theme.mjs +63 -5
- package/clients/cli/commands/component/index.mjs +4 -1
- package/clients/cli/commands/init.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +28 -10
- package/foundation/agent-docs/agent-doc-state.mjs +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +2 -2
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/agent-docs/agent-docs.test.mjs +14 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.d.mts +24 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.mjs +19 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.d.mts +14 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.mjs +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.d.mts +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.mjs +11 -0
- package/foundation/discovery/component-discovery.d.mts +5 -3
- package/foundation/discovery/component-discovery.mjs +25 -9
- package/foundation/discovery/component-loader.mjs +4 -1
- package/foundation/discovery/component-loader.test.mjs +48 -0
- package/foundation/discovery/theming-targets.test.mjs +29 -0
- package/foundation/fs/paths.d.mts +19 -0
- package/foundation/fs/paths.mjs +54 -0
- package/foundation/fs/paths.test.mjs +102 -1
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +62 -0
- package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +107 -0
- package/foundation/fs/publish-file.d.mts +22 -0
- package/foundation/fs/publish-file.mjs +68 -0
- package/foundation/fs/publish-file.test.mjs +136 -0
- package/foundation/integrations/manifest-writer.mjs +2 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +15 -10
|
@@ -38,29 +38,57 @@ export function validateComponentOverridesAgainstRegistry(themeDef: {
|
|
|
38
38
|
propsByKey: Record<string, string[]>;
|
|
39
39
|
deprecatedByKey: Record<string, string>;
|
|
40
40
|
}): string[];
|
|
41
|
-
/**
|
|
42
|
-
* Compile a defineTheme file to CSS + JS + .d.ts (and an optional
|
|
43
|
-
* `.variants.d.ts`). Performs the writes and returns a `theme.build` receipt,
|
|
44
|
-
* or `null` when the theme produced no CSS (nothing to build). Throws
|
|
45
|
-
* AstryxError (stable code) on failure. Progress is emitted through the shared
|
|
46
|
-
* `logger` (silent by default).
|
|
47
|
-
*
|
|
48
|
-
* @param {string} file - Theme file path, resolved against `cwd`.
|
|
49
|
-
* @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] -
|
|
50
|
-
* `out` overrides the output CSS path; `check` compares against on-disk outputs
|
|
51
|
-
* instead of writing. `iconsSpecifier` overrides the icon registry import
|
|
52
|
-
* specifier in the generated module (e.g. `./icons.mjs`); when omitted, the
|
|
53
|
-
* specifier scraped from the theme source is emitted unchanged.
|
|
54
|
-
* @param {{cwd?: string}} [ctx]
|
|
55
|
-
* @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>}
|
|
56
|
-
*/
|
|
41
|
+
/** @param {string} file @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] @param {{cwd?: string}} [ctx] @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>} */
|
|
57
42
|
export function themeBuild(file: string, options?: {
|
|
58
43
|
out?: string;
|
|
59
44
|
check?: boolean;
|
|
60
45
|
iconsSpecifier?: string;
|
|
61
|
-
},
|
|
46
|
+
}, ctx?: {
|
|
62
47
|
cwd?: string;
|
|
63
48
|
}): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
|
|
49
|
+
/** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string}} options @param {{cwd?: string}} [ctx] */
|
|
50
|
+
export function themeBuildFamily(files: string[], options: {
|
|
51
|
+
familyKey: string;
|
|
52
|
+
check?: boolean;
|
|
53
|
+
iconsSpecifier?: string;
|
|
54
|
+
}, { cwd }?: {
|
|
55
|
+
cwd?: string;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
type: string;
|
|
58
|
+
data: {
|
|
59
|
+
name: any;
|
|
60
|
+
upToDate: boolean;
|
|
61
|
+
stale: {
|
|
62
|
+
path: string;
|
|
63
|
+
reason: "missing" | "outdated";
|
|
64
|
+
}[];
|
|
65
|
+
checked: string[];
|
|
66
|
+
tokenCount?: undefined;
|
|
67
|
+
componentCount?: undefined;
|
|
68
|
+
sizeKB?: undefined;
|
|
69
|
+
outputs?: undefined;
|
|
70
|
+
warnings?: undefined;
|
|
71
|
+
notices?: undefined;
|
|
72
|
+
};
|
|
73
|
+
} | {
|
|
74
|
+
type: string;
|
|
75
|
+
data: {
|
|
76
|
+
name: any;
|
|
77
|
+
tokenCount: any;
|
|
78
|
+
componentCount: any;
|
|
79
|
+
sizeKB: number;
|
|
80
|
+
outputs: {
|
|
81
|
+
css: string;
|
|
82
|
+
js: string;
|
|
83
|
+
dts: string;
|
|
84
|
+
};
|
|
85
|
+
warnings: any[];
|
|
86
|
+
notices: string[];
|
|
87
|
+
upToDate?: undefined;
|
|
88
|
+
stale?: undefined;
|
|
89
|
+
checked?: undefined;
|
|
90
|
+
};
|
|
91
|
+
}>;
|
|
64
92
|
/**
|
|
65
93
|
* How one `prop:value` pair on a component target is classified — the single
|
|
66
94
|
* vocabulary both the root and adaptation paths reason in.
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
/** @file Focused contract tests for keyed theme-family builds. */
|
|
3
|
+
import {parse} from '@babel/parser';
|
|
4
|
+
import {execFileSync} from 'node:child_process';
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
import {afterEach, beforeAll, beforeEach, describe, expect, it, vi} from 'vitest';
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as os from 'node:os';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import {pathToFileURL} from 'node:url';
|
|
11
|
+
import {defineTheme as defineCoreTheme} from '@astryxdesign/core/theme';
|
|
12
|
+
import {themeBuild, themeBuildFamily} from './build.mjs';
|
|
13
|
+
import {interceptCore} from './core-interception.mjs';
|
|
14
|
+
import {ensureCoreBuilt} from '../../../clients/cli/commands/ensure-core-built.mjs';
|
|
15
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
16
|
+
vi.setConfig({testTimeout: 120_000});
|
|
17
|
+
const CLI_ROOT = path.resolve(import.meta.dirname, '../../..');
|
|
18
|
+
const FAMILY_KEY = 'ocean-family';
|
|
19
|
+
const OUTPUTS = [`${FAMILY_KEY}.css`, `${FAMILY_KEY}.js`, `${FAMILY_KEY}.d.ts`];
|
|
20
|
+
/** @type {string[]} */ let dirs;
|
|
21
|
+
beforeAll(() => ensureCoreBuilt(), 200_000);
|
|
22
|
+
beforeEach(() => (dirs = []));
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
afterEach(() => { for (const dir of dirs) fs.rmSync(dir, {recursive: true, force: true}); });
|
|
25
|
+
// prettier-ignore
|
|
26
|
+
function makeDir() { const dir = fs.mkdtempSync(path.join(CLI_ROOT, '.tmp-theme-family-')); dirs.push(dir); fs.mkdirSync(path.join(dir, 'themes'), {recursive: true}); fs.writeFileSync(path.join(dir, 'package.json'), '{"type":"module"}\n'); return dir; }
|
|
27
|
+
function writeFamily(dir) {
|
|
28
|
+
const themes = path.join(dir, 'themes');
|
|
29
|
+
const hidden = path.join(themes, '.hidden');
|
|
30
|
+
fs.mkdirSync(hidden, {recursive: true});
|
|
31
|
+
const write = (root, name, source) =>
|
|
32
|
+
fs.writeFileSync(path.join(root, name), source);
|
|
33
|
+
const helper = path.join(dir, 'node_modules/@fixture/static-helper');
|
|
34
|
+
fs.mkdirSync(helper, {recursive: true});
|
|
35
|
+
fs.writeFileSync(
|
|
36
|
+
path.join(helper, 'package.json'),
|
|
37
|
+
JSON.stringify({
|
|
38
|
+
name: '@fixture/static-helper',
|
|
39
|
+
type: 'module',
|
|
40
|
+
exports: {import: './index.mjs'},
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
fs.writeFileSync(
|
|
44
|
+
path.join(helper, 'index.mjs'),
|
|
45
|
+
`export const marker=true;\n`,
|
|
46
|
+
);
|
|
47
|
+
// prettier-ignore
|
|
48
|
+
for (const [root, name, source] of [[themes, 'base-icons.mjs', `import '@fixture/static-helper';export {icons} from './base-icons-leaf.mjs';\n`], [themes, 'base-icons-leaf.mjs', `export const icons={close:'base-close',menu:'base-menu'};\n`], [hidden, 'child-icons.mjs', `export const icons={close:'child-close'};\n`], [themes, 'base-indicators.mjs', `export const indicators={check:'base-check',radio:'base-radio'};\n`], [hidden, 'child-indicators.mjs', `export const indicators={check:'child-check'};\n`]]) write(root, name, source);
|
|
49
|
+
// prettier-ignore
|
|
50
|
+
write(themes, 'ocean.mjs', `import {defineTheme} from '@astryxdesign/core/theme';
|
|
51
|
+
import {icons} from './base-icons.mjs';
|
|
52
|
+
import {indicators} from './base-indicators.mjs';
|
|
53
|
+
await Promise.resolve();
|
|
54
|
+
export const oceanTheme=defineTheme({
|
|
55
|
+
name:'ocean',icons,indicators,
|
|
56
|
+
tokens:{'--color-accent':'rgb(0 119 182)','--color-background-body':'rgb(240 248 255)'},
|
|
57
|
+
localTokens:{'--tide':'8px','--wash':'linear-gradient(\\nred,\\nblue\\n)','--commented':'red /* ) */','--payload':'[one; two]'},
|
|
58
|
+
components:{button:{base:{borderRadius:'6px',backgroundImage:'url(/icons/*/mark.svg)',':hover':{backgroundColor:'rgb(220 40 40)'}},'variant:a{b':{color:'rgb(1 2 3)'}},card:{base:{padding:'8px 16px'}},text:{'type:body':{letterSpacing:'0.01em'}}},
|
|
59
|
+
adaptations:{rules:[{when:{width:{below:'md'}},value:{tokens:{'--spacing-4':'12px'},components:{button:{base:{minHeight:'40px'}}}}}]},
|
|
60
|
+
onDark:{tokens:{'--color-border':'rgb(80 120 140)'},components:{button:{base:{borderColor:'rgb(80 120 140)','::before':{content:\`'@scope ([data-astryx-theme="ocean"])'\`}}}}},
|
|
61
|
+
});export default oceanTheme;\n`,
|
|
62
|
+
);
|
|
63
|
+
write(
|
|
64
|
+
themes,
|
|
65
|
+
'ocean-barrel.mjs',
|
|
66
|
+
`export {oceanTheme} from './ocean.mjs';\n`,
|
|
67
|
+
);
|
|
68
|
+
// prettier-ignore
|
|
69
|
+
write(hidden, 'ocean-calm.mjs', `import {defineTheme} from '@astryxdesign/core/theme';
|
|
70
|
+
import {oceanTheme} from '../ocean-barrel.mjs';
|
|
71
|
+
import {icons as brandIcons} from './child-icons.mjs';
|
|
72
|
+
import {indicators as brandIndicators} from './child-indicators.mjs';
|
|
73
|
+
export const resolvedOceanCalmTheme=defineTheme({
|
|
74
|
+
name:'ocean-calm',extends:oceanTheme,icons:brandIcons,indicators:brandIndicators,
|
|
75
|
+
tokens:{'--color-accent':['rgb(0 150 170)','rgb(0 170 190)']},
|
|
76
|
+
localTokens:{'--tide':'10px','--wash':'linear-gradient(\\nred,\\ngreen\\n)','--payload':'[one; three]'},
|
|
77
|
+
components:{button:{base:{backgroundColor:'rgb(220 250 250)',borderColor:'rgb(0 0 0)',minHeight:'28px'},'variant:lagoon':{backgroundColor:'rgb(0 90 110)'}},card:{base:{padding:'24px'}}},
|
|
78
|
+
adaptations:{widthBreakpoints:{md:900}},
|
|
79
|
+
});export const oceanCalmTheme={...resolvedOceanCalmTheme};export default oceanCalmTheme;\n`,
|
|
80
|
+
);
|
|
81
|
+
// prettier-ignore
|
|
82
|
+
write(hidden, 'ocean-calm-deep.mjs', `import {defineTheme} from '@astryxdesign/core/theme';\nimport {oceanCalmTheme} from './ocean-calm.mjs';\nexport const oceanCalmDeepTheme=defineTheme({name:'ocean-calm-deep',extends:oceanCalmTheme});\n`);
|
|
83
|
+
// prettier-ignore
|
|
84
|
+
write(themes, 'ocean-midnight.mjs', `import {oceanTheme} from './ocean.mjs';\nexport const oceanMidnightTheme={name:'ocean-midnight',extends:oceanTheme,tokens:{'--color-background-body':'rgb(4 20 32)'},components:{button:{base:{color:'rgb(235 250 255)'}}}};export default oceanMidnightTheme;\n`);
|
|
85
|
+
// prettier-ignore
|
|
86
|
+
return ['themes/ocean.mjs', 'themes/.hidden/ocean-calm.mjs', 'themes/.hidden/ocean-calm-deep.mjs', 'themes/ocean-midnight.mjs'];
|
|
87
|
+
}
|
|
88
|
+
const count = (text, needle) => text.split(needle).length - 1;
|
|
89
|
+
/** @param {string} source */
|
|
90
|
+
// prettier-ignore
|
|
91
|
+
function executableDependencies(source) {
|
|
92
|
+
const ast = parse(source, {sourceType: 'module'}); /** @type {string[]} */ const dependencies = [];
|
|
93
|
+
/** @param {any} node */ const visit = node => {
|
|
94
|
+
if (!node || typeof node !== 'object') return;
|
|
95
|
+
if (['ImportDeclaration', 'ExportNamedDeclaration', 'ExportAllDeclaration'].includes(node.type) && typeof node.source?.value === 'string') dependencies.push(node.source.value);
|
|
96
|
+
const dynamic = node.type === 'ImportExpression' ? node.source : node.type === 'CallExpression' && (node.callee?.type === 'Import' || node.callee?.name === 'require') ? node.arguments?.[0] : null;
|
|
97
|
+
if (dynamic) dependencies.push(typeof dynamic.value === 'string' ? dynamic.value : '<non-static>');
|
|
98
|
+
for (const value of Object.values(node)) if (Array.isArray(value)) value.forEach(child => child?.type && visit(child)); else if (value?.type) visit(value);
|
|
99
|
+
};
|
|
100
|
+
visit(ast); return dependencies;
|
|
101
|
+
}
|
|
102
|
+
// prettier-ignore
|
|
103
|
+
const build = (dir, files, options = {}) => themeBuildFamily(files, {familyKey: FAMILY_KEY, ...options}, {cwd: dir});
|
|
104
|
+
describe('themeBuildFamily()', () => {
|
|
105
|
+
// prettier-ignore
|
|
106
|
+
it('does not add lineage metadata to ordinary Core themes', () => {
|
|
107
|
+
const base = defineCoreTheme({name: 'runtime-base'}), child = defineCoreTheme({name: 'runtime-child', extends: base}), spread = {...child};
|
|
108
|
+
expect(Object.getOwnPropertySymbols(base)).toEqual([]); expect(Object.getOwnPropertySymbols(child)).toEqual([]);
|
|
109
|
+
expect(Reflect.ownKeys(spread)).toEqual(Reflect.ownKeys(child)); expect(JSON.stringify(spread)).toBe(JSON.stringify(child));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('emits one deterministic complete trio with shared rules and member deltas', async () => {
|
|
113
|
+
const first = makeDir();
|
|
114
|
+
const second = makeDir();
|
|
115
|
+
const firstFiles = writeFamily(first);
|
|
116
|
+
const secondFiles = writeFamily(second);
|
|
117
|
+
// prettier-ignore
|
|
118
|
+
const result = await build(first, [firstFiles[2], firstFiles[3], firstFiles[0], firstFiles[1]]);
|
|
119
|
+
// prettier-ignore
|
|
120
|
+
await build(second, [secondFiles[1], secondFiles[0], secondFiles[3], secondFiles[2]]);
|
|
121
|
+
expect(result?.type).toBe('theme.build');
|
|
122
|
+
expect(result?.data.name).toBe('ocean');
|
|
123
|
+
// prettier-ignore
|
|
124
|
+
expect(result?.data.outputs).toEqual({css: `themes/${FAMILY_KEY}.css`, js: `themes/${FAMILY_KEY}.js`, dts: `themes/${FAMILY_KEY}.d.ts`});
|
|
125
|
+
// prettier-ignore
|
|
126
|
+
for (const output of OUTPUTS) { const a = fs.readFileSync(path.join(first, 'themes', output), 'utf8'), b = fs.readFileSync(path.join(second, 'themes', output), 'utf8'); expect({output, content: a}).toEqual({output, content: b}); }
|
|
127
|
+
const css = fs.readFileSync(
|
|
128
|
+
path.join(first, 'themes', `${FAMILY_KEY}.css`),
|
|
129
|
+
'utf8',
|
|
130
|
+
);
|
|
131
|
+
expect(css).toContain(
|
|
132
|
+
':where([data-astryx-theme="ocean"], [data-astryx-theme="ocean-calm"], [data-astryx-theme="ocean-calm-deep"], [data-astryx-theme="ocean-midnight"])',
|
|
133
|
+
);
|
|
134
|
+
expect(css).toContain(
|
|
135
|
+
':where([data-astryx-theme="ocean-calm"], [data-astryx-theme="ocean-calm-deep"])',
|
|
136
|
+
);
|
|
137
|
+
expect(css).not.toContain(':where(.astryx-button)');
|
|
138
|
+
expect(css).toContain('--tide: 8px;');
|
|
139
|
+
expect(css).toMatch(/--wash: linear-gradient\(\s*red,\s*green\s*\);/);
|
|
140
|
+
expect(css).toContain('--commented: red /* ) */;');
|
|
141
|
+
expect(css).toContain('[data-variant="a{b"]');
|
|
142
|
+
expect(css).toContain('background-image: url(/icons/*/mark.svg);');
|
|
143
|
+
expect(css).toContain('--payload: [one; two];');
|
|
144
|
+
expect(css).toContain('--payload: [one; three];');
|
|
145
|
+
expect(css).toContain(`content: '@scope ([data-astryx-theme="ocean"])';`);
|
|
146
|
+
expect(css).toContain('--tide: 10px;');
|
|
147
|
+
expect(count(css, '--tide: 8px;')).toBe(1);
|
|
148
|
+
expect(count(css, '--tide: 10px;')).toBe(1);
|
|
149
|
+
expect(css).toContain('--astryx-card-padding: 24px;');
|
|
150
|
+
expect(css).toContain('--astryx-card-padding-inline: 16px;');
|
|
151
|
+
expect(css).toContain('@media (width < 768px)');
|
|
152
|
+
expect(css).toContain('@media (width < 900px)');
|
|
153
|
+
expect(css).toContain('[data-astryx-media="dark"]');
|
|
154
|
+
// prettier-ignore
|
|
155
|
+
for (const text of [':root:where([data-astryx-theme="ocean-calm"], [data-astryx-theme="ocean-calm-deep"])', ':where(:scope:not([data-theme]):not(html[data-theme] *))', ':where(:scope:not([data-theme]):is(html[data-theme="dark"] *))', 'html[data-theme="dark"]:where([data-astryx-theme="ocean-calm"], [data-astryx-theme="ocean-calm-deep"])']) expect(css).toContain(text);
|
|
156
|
+
expect(css).not.toContain('\n :root { color-scheme: light dark; }');
|
|
157
|
+
// prettier-ignore
|
|
158
|
+
expect(css).not.toContain('@scope (:where([data-astryx-theme="ocean-calm-deep"]))');
|
|
159
|
+
// prettier-ignore
|
|
160
|
+
const js = fs.readFileSync(path.join(first, 'themes', `${FAMILY_KEY}.js`), 'utf8'), dts = fs.readFileSync(path.join(first, 'themes', `${FAMILY_KEY}.d.ts`), 'utf8');
|
|
161
|
+
const dependencies = executableDependencies(js);
|
|
162
|
+
expect(dependencies).not.toContain('<non-static>');
|
|
163
|
+
expect(
|
|
164
|
+
dependencies.some(specifier => /\.css(?:$|[?#])/i.test(specifier)),
|
|
165
|
+
).toBe(false);
|
|
166
|
+
expect(js).toContain('from "./.hidden/child-icons.mjs"');
|
|
167
|
+
// prettier-ignore
|
|
168
|
+
for (const name of ['oceanTheme', 'oceanCalmTheme', 'oceanCalmDeepTheme', 'oceanMidnightTheme']) {
|
|
169
|
+
expect(js).toContain(`export const ${name}`);
|
|
170
|
+
expect(dts).toContain(`export declare const ${name}`);
|
|
171
|
+
}
|
|
172
|
+
// prettier-ignore
|
|
173
|
+
const imported = await import(`${pathToFileURL(path.join(first, 'themes', `${FAMILY_KEY}.js`)).href}?${Date.now()}`);
|
|
174
|
+
expect(imported.oceanTheme.icons.close).toBe('base-close');
|
|
175
|
+
expect(imported.oceanCalmTheme.icons.close).toBe('child-close');
|
|
176
|
+
expect(imported.oceanCalmTheme.icons.menu).toBe('base-menu');
|
|
177
|
+
expect(imported.oceanCalmDeepTheme.icons.menu).toBe('base-menu');
|
|
178
|
+
expect(imported.oceanCalmTheme.indicators.check).toBe('child-check');
|
|
179
|
+
expect(imported.oceanCalmTheme.indicators.radio).toBe('base-radio');
|
|
180
|
+
expect(imported.oceanCalmDeepTheme.indicators.radio).toBe('base-radio');
|
|
181
|
+
expect(imported.oceanCalmDeepTheme.name).toBe('ocean-calm-deep');
|
|
182
|
+
expect(Object.hasOwn(imported.oceanCalmTheme, '__extends')).toBe(false);
|
|
183
|
+
fs.writeFileSync(
|
|
184
|
+
path.join(first, 'themes', 'consumer.tsx'),
|
|
185
|
+
`import type {DefinedTheme} from '@astryxdesign/core/theme';\n` +
|
|
186
|
+
`import {Button} from '@astryxdesign/core/Button';\n` +
|
|
187
|
+
`import {oceanTheme, oceanCalmTheme, oceanCalmDeepTheme, oceanMidnightTheme} from './ocean-family.js';\n` +
|
|
188
|
+
`const family: DefinedTheme[] = [oceanTheme, oceanCalmTheme, oceanCalmDeepTheme, oceanMidnightTheme];\n` +
|
|
189
|
+
`// @ts-expect-error family lineage is build-private, not DefinedTheme API\n` +
|
|
190
|
+
`oceanCalmTheme.__extends;\n` +
|
|
191
|
+
`export const Probe = () => <Button label={String(family.length)} variant="lagoon" />;\n`,
|
|
192
|
+
);
|
|
193
|
+
fs.writeFileSync(
|
|
194
|
+
path.join(first, 'themes', 'tsconfig.json'),
|
|
195
|
+
JSON.stringify({
|
|
196
|
+
compilerOptions: {
|
|
197
|
+
module: 'esnext',
|
|
198
|
+
target: 'es2022',
|
|
199
|
+
jsx: 'react-jsx',
|
|
200
|
+
moduleResolution: 'bundler',
|
|
201
|
+
strict: true,
|
|
202
|
+
skipLibCheck: true,
|
|
203
|
+
},
|
|
204
|
+
include: ['consumer.tsx', 'ocean-family.d.ts'],
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
execFileSync(
|
|
208
|
+
'pnpm',
|
|
209
|
+
['exec', 'tsc', '--project', 'tsconfig.json', '--noEmit'],
|
|
210
|
+
{cwd: path.join(first, 'themes'), stdio: 'pipe'},
|
|
211
|
+
);
|
|
212
|
+
// prettier-ignore
|
|
213
|
+
for (const member of ['ocean', 'ocean-calm', 'ocean-calm-deep', 'ocean-midnight']) expect(fs.existsSync(path.join(first, 'themes', `${member}.css`))).toBe(false);
|
|
214
|
+
});
|
|
215
|
+
// prettier-ignore
|
|
216
|
+
it('retains private capture across cached frozen exports', () => {
|
|
217
|
+
const core = {defineTheme: input => Object.freeze({name: input.name, tokens: {}})}, first = interceptCore(core), wrapped = /** @type {any} */ (first.modules['@astryxdesign/core/theme']);
|
|
218
|
+
const parent = wrapped.defineTheme({name: 'parent'}), child = wrapped.defineTheme({name: 'child', extends: parent, adaptations: {rules: []}});
|
|
219
|
+
first.retain(child); first.strip(child); const retry = interceptCore(core);
|
|
220
|
+
expect(retry.parentOf(child)).toBe(parent); expect(retry.lineageOf(child).some(value => value?.adaptations)).toBe(true); expect(retry.unobservedIn(child)).toEqual([]);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('checks the exact keyed trio without writing stale or missing output', async () => {
|
|
224
|
+
const dir = makeDir();
|
|
225
|
+
const files = writeFamily(dir);
|
|
226
|
+
await build(dir, files);
|
|
227
|
+
const cssPath = path.join(dir, 'themes', `${FAMILY_KEY}.css`);
|
|
228
|
+
const jsPath = path.join(dir, 'themes', `${FAMILY_KEY}.js`);
|
|
229
|
+
const dtsPath = path.join(dir, 'themes', `${FAMILY_KEY}.d.ts`);
|
|
230
|
+
const cssBefore = fs.readFileSync(cssPath, 'utf8');
|
|
231
|
+
expect((await build(dir, files, {check: true}))?.data).toMatchObject({
|
|
232
|
+
upToDate: true,
|
|
233
|
+
stale: [],
|
|
234
|
+
checked: OUTPUTS.map(file => `themes/${file}`),
|
|
235
|
+
});
|
|
236
|
+
fs.writeFileSync(jsPath, '/* stale */\n');
|
|
237
|
+
fs.rmSync(dtsPath);
|
|
238
|
+
const checked = await build(dir, files, {check: true});
|
|
239
|
+
expect(checked?.type).toBe('theme.build.check');
|
|
240
|
+
expect(checked?.data.upToDate).toBe(false);
|
|
241
|
+
expect(checked?.data.stale).toEqual([
|
|
242
|
+
{path: `themes/${FAMILY_KEY}.js`, reason: 'outdated'},
|
|
243
|
+
{path: `themes/${FAMILY_KEY}.d.ts`, reason: 'missing'},
|
|
244
|
+
]);
|
|
245
|
+
expect(fs.readFileSync(cssPath, 'utf8')).toBe(cssBefore);
|
|
246
|
+
expect(fs.readFileSync(jsPath, 'utf8')).toBe('/* stale */\n');
|
|
247
|
+
expect(fs.existsSync(dtsPath)).toBe(false);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('fails without publishing a mixed trio when staging a write fails', async () => {
|
|
251
|
+
const dir = makeDir();
|
|
252
|
+
const files = writeFamily(dir);
|
|
253
|
+
const outputDir = path.join(dir, 'themes');
|
|
254
|
+
const blockedTmp = path.join(
|
|
255
|
+
outputDir,
|
|
256
|
+
`${FAMILY_KEY}.js.${process.pid}.tmp`,
|
|
257
|
+
);
|
|
258
|
+
fs.mkdirSync(blockedTmp);
|
|
259
|
+
|
|
260
|
+
await expect(build(dir, files)).rejects.toThrow(
|
|
261
|
+
/Failed to write theme outputs/,
|
|
262
|
+
);
|
|
263
|
+
for (const output of OUTPUTS) {
|
|
264
|
+
expect(fs.existsSync(path.join(outputDir, output))).toBe(false);
|
|
265
|
+
}
|
|
266
|
+
expect(
|
|
267
|
+
fs.existsSync(
|
|
268
|
+
path.join(outputDir, `${FAMILY_KEY}.css.${process.pid}.tmp`),
|
|
269
|
+
),
|
|
270
|
+
).toBe(false);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('rejects invalid graphs and keys before touching an existing trio', async () => {
|
|
274
|
+
const dir = makeDir();
|
|
275
|
+
const files = writeFamily(dir);
|
|
276
|
+
const outputDir = path.join(dir, 'themes');
|
|
277
|
+
for (const output of [...OUTPUTS, 'ocean.css', 'ocean.js', 'ocean.d.ts']) {
|
|
278
|
+
fs.writeFileSync(path.join(outputDir, output), `sentinel:${output}`);
|
|
279
|
+
}
|
|
280
|
+
const unrelated = 'themes/unrelated.mjs';
|
|
281
|
+
// prettier-ignore
|
|
282
|
+
fs.writeFileSync(path.join(dir, unrelated), `import {defineTheme} from '@astryxdesign/core/theme';export default defineTheme({name:'unrelated'});\n`);
|
|
283
|
+
const duplicate = 'themes/duplicate.mjs';
|
|
284
|
+
// prettier-ignore
|
|
285
|
+
fs.writeFileSync(path.join(dir, duplicate), `import {defineTheme} from '@astryxdesign/core/theme';export default defineTheme({name:'ocean'});\n`);
|
|
286
|
+
const impostor = 'themes/impostor.mjs';
|
|
287
|
+
const impostorChild = 'themes/impostor-child.mjs';
|
|
288
|
+
// prettier-ignore
|
|
289
|
+
fs.writeFileSync(path.join(dir, impostor), `import {oceanTheme} from './ocean.mjs';export const impostor={...oceanTheme};\n`);
|
|
290
|
+
// prettier-ignore
|
|
291
|
+
fs.writeFileSync(path.join(dir, impostorChild), `import {defineTheme} from '@astryxdesign/core/theme';import {impostor} from './impostor.mjs';export default defineTheme({name:'impostor-child',extends:impostor});\n`);
|
|
292
|
+
const emptyParent = 'themes/empty-parent.mjs';
|
|
293
|
+
// prettier-ignore
|
|
294
|
+
fs.writeFileSync(path.join(dir, emptyParent), `import {defineTheme} from '@astryxdesign/core/theme';const invalid={name:'',tokens:{}};export default defineTheme({name:'empty-parent',extends:invalid});\n`);
|
|
295
|
+
const sourceCollision = 'themes/Theme-family.js';
|
|
296
|
+
const sourceBytes = `export const baseTheme={name:'base',tokens:{},extends:undefined};\n`;
|
|
297
|
+
fs.writeFileSync(path.join(dir, sourceCollision), sourceBytes);
|
|
298
|
+
const sourceChild = 'themes/source-child.mjs';
|
|
299
|
+
// prettier-ignore
|
|
300
|
+
fs.writeFileSync(path.join(dir, sourceChild), `import {defineTheme} from '@astryxdesign/core/theme';import {baseTheme} from './Theme-family.js';export default defineTheme({name:'source-child',extends:baseTheme});\n`);
|
|
301
|
+
const bypass = 'themes/bypass.mjs';
|
|
302
|
+
fs.writeFileSync(
|
|
303
|
+
path.join(dir, bypass),
|
|
304
|
+
`export default {name:'bypass',tokens:{}};\n`,
|
|
305
|
+
);
|
|
306
|
+
const graphIcons = 'themes/graph-icons.mjs';
|
|
307
|
+
const graphRoot = 'themes/graph-root.mjs';
|
|
308
|
+
const graphChild = 'themes/graph-child.mjs';
|
|
309
|
+
// prettier-ignore
|
|
310
|
+
fs.writeFileSync(path.join(dir, graphIcons), `export const icons={close:'x'};if(false)import(\`./hidden.css\`);\n`);
|
|
311
|
+
fs.writeFileSync(path.join(dir, 'themes/hidden.css'), '.hidden{}\n');
|
|
312
|
+
// prettier-ignore
|
|
313
|
+
fs.writeFileSync(path.join(dir, graphRoot), `import {defineTheme} from '@astryxdesign/core/theme';import {icons} from './graph-icons.mjs';export const root=defineTheme({name:'graph-root',icons,tokens:{'--color-accent':'red'}});\n`);
|
|
314
|
+
// prettier-ignore
|
|
315
|
+
fs.writeFileSync(path.join(dir, graphChild), `import {defineTheme} from '@astryxdesign/core/theme';import {root} from './graph-root.mjs';export default defineTheme({name:'graph-child',extends:root});\n`);
|
|
316
|
+
// prettier-ignore
|
|
317
|
+
for (const [name, type, entry, source] of [['external-registry', 'module', 'index.mjs', `export const icons={close:'external'};if(false)import('./missing.mjs');\n`], ['computed-registry', 'module', 'index.mjs', `export const icons={close:'computed'};const extension='css';if(false)import(\`./hidden.\${extension}\`);\n`], ['cjs-registry', 'commonjs', 'index.cjs', `exports.icons={close:'cjs'};\n`]]) { const root = path.join(dir, 'node_modules/@fixture', name); fs.mkdirSync(root, {recursive: true}); fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({name: `@fixture/${name}`, type, exports: `./${entry}`})); fs.writeFileSync(path.join(root, entry), source); }
|
|
318
|
+
fs.writeFileSync(
|
|
319
|
+
path.join(dir, 'node_modules/@fixture/computed-registry/hidden.css'),
|
|
320
|
+
'.hidden{}\n',
|
|
321
|
+
);
|
|
322
|
+
const cycleShared = 'themes/cycle-shared.mjs';
|
|
323
|
+
const cycleA = 'themes/cycle-a.mjs';
|
|
324
|
+
const cycleB = 'themes/cycle-b.mjs';
|
|
325
|
+
// prettier-ignore
|
|
326
|
+
fs.writeFileSync(path.join(dir, cycleShared), `import {defineTheme} from '@astryxdesign/core/theme';const input={name:'cycle-a'};export const a=defineTheme(input);export const b=defineTheme({name:'cycle-b',extends:a});input.extends=b;\n`);
|
|
327
|
+
fs.writeFileSync(
|
|
328
|
+
path.join(dir, cycleA),
|
|
329
|
+
`export {a as default} from './cycle-shared.mjs';\n`,
|
|
330
|
+
);
|
|
331
|
+
fs.writeFileSync(
|
|
332
|
+
path.join(dir, cycleB),
|
|
333
|
+
`export {b as default} from './cycle-shared.mjs';\n`,
|
|
334
|
+
);
|
|
335
|
+
// prettier-ignore
|
|
336
|
+
const cases = [
|
|
337
|
+
{files: [files[0]], key: FAMILY_KEY, message: /at least two/i}, {files: [files[0], files[0]], key: FAMILY_KEY, message: /duplicate/i},
|
|
338
|
+
{files: [files[0], duplicate], key: FAMILY_KEY, message: /duplicate.*ocean/i}, {files: [files[1], unrelated], key: FAMILY_KEY, message: /ancestor|parent/i},
|
|
339
|
+
{files: [files[0], unrelated], key: FAMILY_KEY, message: /one selected root/i}, {files: [files[0], impostorChild], key: FAMILY_KEY, message: /does not extend the selected/i},
|
|
340
|
+
{files: [files[0], bypass], key: FAMILY_KEY, message: /exact family ancestry could not be observed/i},
|
|
341
|
+
{files: [cycleA, cycleB], key: FAMILY_KEY, message: /cycle/i},
|
|
342
|
+
{files: [graphRoot, graphChild], key: 'graph-family', message: /registry graph imports CSS/i},
|
|
343
|
+
{files: [emptyParent, unrelated], key: FAMILY_KEY, message: /invalid normalized parent/i},
|
|
344
|
+
{files: [sourceCollision, sourceChild], key: 'theme-family', message: /collides with a selected source/i},
|
|
345
|
+
{files, key: 'ocean', message: /collides.*standalone/i},
|
|
346
|
+
{files, key: '../escaped', message: /family key/i},
|
|
347
|
+
{files, key: 'Ocean_Family', message: /lower-kebab/i},
|
|
348
|
+
];
|
|
349
|
+
// prettier-ignore
|
|
350
|
+
for (const testCase of cases) await expect(themeBuildFamily(testCase.files, {familyKey: testCase.key}, {cwd: dir})).rejects.toThrow(testCase.message);
|
|
351
|
+
// prettier-ignore
|
|
352
|
+
fs.writeFileSync(path.join(dir, graphIcons), `export const icons={close:'x'};if(false)import('./missing.mjs');\n`);
|
|
353
|
+
// prettier-ignore
|
|
354
|
+
await expect(themeBuildFamily([graphRoot, graphChild], {familyKey: 'graph-family'}, {cwd: dir})).rejects.toThrow(/cannot resolve registry import/i);
|
|
355
|
+
// prettier-ignore
|
|
356
|
+
fs.writeFileSync(path.join(dir, graphIcons), `export {icons} from './nested-icons';\n`);
|
|
357
|
+
// prettier-ignore
|
|
358
|
+
fs.writeFileSync(path.join(dir, 'themes/nested-icons.mjs'), `export const icons={close:'x'};\n`);
|
|
359
|
+
// prettier-ignore
|
|
360
|
+
await expect(themeBuildFamily([graphRoot, graphChild], {familyKey: 'graph-family'}, {cwd: dir})).rejects.toThrow(/cannot resolve registry import/i);
|
|
361
|
+
// prettier-ignore
|
|
362
|
+
for (const [name, source] of [['graph-icons.mjs', `export const icons={close:'x'};\n`], ['graph-leaf.mjs', `export const other={};\n`], ['broken-icons.mjs', `import {missing} from './graph-leaf.mjs';export {missing as icons};\n`], ['compiled-icons.mjs', `export const icons={close:'x'};\n`]]) fs.writeFileSync(path.join(dir, 'themes', name), source);
|
|
363
|
+
// prettier-ignore
|
|
364
|
+
await expect(themeBuildFamily([graphRoot, graphChild], {familyKey: 'graph-family', iconsSpecifier: './broken-icons.mjs'}, {cwd: dir})).rejects.toThrow(/cannot import family registry|does not export/i);
|
|
365
|
+
// prettier-ignore
|
|
366
|
+
await expect(themeBuildFamily([graphRoot, graphChild], {familyKey: 'graph-family', iconsSpecifier: './compiled-icons'}, {cwd: dir})).rejects.toThrow(/cannot resolve registry import/i);
|
|
367
|
+
// prettier-ignore
|
|
368
|
+
await expect(themeBuildFamily([graphRoot, graphChild], {familyKey: 'graph-family', iconsSpecifier: '@fixture/external-registry'}, {cwd: dir})).rejects.toThrow(/cannot resolve registry import/i);
|
|
369
|
+
// prettier-ignore
|
|
370
|
+
await expect(themeBuildFamily([graphRoot, graphChild], {familyKey: 'computed-family', iconsSpecifier: '@fixture/computed-registry'}, {cwd: dir})).rejects.toThrow(/non-static dependency.*resolvable and CSS-free/i);
|
|
371
|
+
// prettier-ignore
|
|
372
|
+
for (const extension of ['css', 'js', 'd.ts']) expect(fs.existsSync(path.join(outputDir, `computed-family.${extension}`))).toBe(false);
|
|
373
|
+
// prettier-ignore
|
|
374
|
+
fs.writeFileSync(path.join(dir, 'themes/cjs-icons.mjs'), `export {icons} from '@fixture/cjs-registry';\n`);
|
|
375
|
+
// prettier-ignore
|
|
376
|
+
await expect(themeBuildFamily([graphRoot, graphChild], {familyKey: 'cjs-family', iconsSpecifier: './cjs-icons.mjs', check: true}, {cwd: dir})).resolves.toMatchObject({data: {upToDate: false}});
|
|
377
|
+
// prettier-ignore
|
|
378
|
+
expect(fs.readFileSync(path.join(dir, sourceCollision), 'utf8')).toBe(sourceBytes);
|
|
379
|
+
// prettier-ignore
|
|
380
|
+
for (const output of [...OUTPUTS, 'ocean.css', 'ocean.js', 'ocean.d.ts']) expect(fs.readFileSync(path.join(outputDir, output), 'utf8')).toBe(`sentinel:${output}`);
|
|
381
|
+
});
|
|
382
|
+
it('leaves standalone build bytes and outputs independent of family mode', async () => {
|
|
383
|
+
const dir = makeDir();
|
|
384
|
+
const files = writeFamily(dir);
|
|
385
|
+
const standalone = await themeBuild(files[0], {}, {cwd: dir});
|
|
386
|
+
// prettier-ignore
|
|
387
|
+
const before = Object.fromEntries(['ocean.css', 'ocean.js', 'ocean.d.ts'].map(file => [file, fs.readFileSync(path.join(dir, 'themes', file), 'utf8')]));
|
|
388
|
+
await build(dir, files);
|
|
389
|
+
const checked = await themeBuild(files[0], {check: true}, {cwd: dir});
|
|
390
|
+
expect(standalone?.type).toBe('theme.build');
|
|
391
|
+
expect(checked?.data.upToDate).toBe(true);
|
|
392
|
+
// prettier-ignore
|
|
393
|
+
for (const [file, content] of Object.entries(before)) expect(fs.readFileSync(path.join(dir, 'themes', file), 'utf8')).toBe(content);
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
describe('theme build --family CLI', () => {
|
|
397
|
+
it('requires the key exactly with family mode and closes incompatible flags', async () => {
|
|
398
|
+
const dir = makeDir();
|
|
399
|
+
const files = writeFamily(dir);
|
|
400
|
+
// prettier-ignore
|
|
401
|
+
const cases = [
|
|
402
|
+
{args: ['theme', 'build', '--family', ...files], message: /family-key/i},
|
|
403
|
+
{args: ['theme', 'build', ...files, '--family-key', FAMILY_KEY], message: /family/i},
|
|
404
|
+
{args: ['theme', 'build', '--family', ...files, '--family-key', FAMILY_KEY, '--out', 'other.css'], message: /--out/i},
|
|
405
|
+
{args: ['theme', 'build', '--family', ...files, '--family-key', FAMILY_KEY, '--watch'], message: /--watch/i},
|
|
406
|
+
];
|
|
407
|
+
// prettier-ignore
|
|
408
|
+
for (const testCase of cases) { const result = await runCli(testCase.args, dir); expect(result.status).toBe(1); expect(result.stdout + result.stderr).toMatch(testCase.message); }
|
|
409
|
+
});
|
|
410
|
+
it('builds and checks one family through the existing response contract', async () => {
|
|
411
|
+
const dir = makeDir();
|
|
412
|
+
const files = writeFamily(dir);
|
|
413
|
+
const args = [
|
|
414
|
+
'--json',
|
|
415
|
+
'theme',
|
|
416
|
+
'build',
|
|
417
|
+
'--family',
|
|
418
|
+
...files,
|
|
419
|
+
'--family-key',
|
|
420
|
+
FAMILY_KEY,
|
|
421
|
+
];
|
|
422
|
+
const built = await runCli(args, dir);
|
|
423
|
+
expect(built.status).toBe(0);
|
|
424
|
+
expect(JSON.parse(built.stdout)).toMatchObject({
|
|
425
|
+
type: 'theme.build',
|
|
426
|
+
data: {name: 'ocean'},
|
|
427
|
+
});
|
|
428
|
+
const checked = await runCli([...args, '--check'], dir);
|
|
429
|
+
expect(checked.status).toBe(0);
|
|
430
|
+
expect(JSON.parse(checked.stdout)).toMatchObject({
|
|
431
|
+
type: 'theme.build.check',
|
|
432
|
+
data: {name: 'ocean', upToDate: true},
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
});
|