@astryxdesign/cli 0.6.5-canary.eb0010b → 0.6.5-canary.efac39f
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/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +146 -69
- package/api/theme/build/build.test.mjs +190 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +14 -3
- package/foundation/doc-compiler/doc-loads.test.mjs +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Icon preservation through multiple generations of built themes.
|
|
5
|
+
* @input Real themeBuild calls and registries imported under the same local
|
|
6
|
+
* binding name from separate base and child theme directories.
|
|
7
|
+
* @output A native ESM load verifies inherited and overridden React icons
|
|
8
|
+
* survive when a grandchild extends the child's generated artifact.
|
|
9
|
+
* @position Direct API regression for persisted icon inheritance in #5058.
|
|
10
|
+
* The node project's global setup supplies the compiled core package.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {expect, it} from 'vitest';
|
|
14
|
+
import {execFileSync} from 'node:child_process';
|
|
15
|
+
import * as fs from 'node:fs';
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
import {themeBuild} from './build.mjs';
|
|
18
|
+
|
|
19
|
+
it('preserves merged icon lineage through a built child with colliding import names', async () => {
|
|
20
|
+
const tmpDir = fs.mkdtempSync(
|
|
21
|
+
path.resolve(import.meta.dirname, '../../..', '.tmp-icon-lineage-'),
|
|
22
|
+
);
|
|
23
|
+
try {
|
|
24
|
+
for (const directory of ['base', 'child']) {
|
|
25
|
+
fs.mkdirSync(path.join(tmpDir, directory));
|
|
26
|
+
}
|
|
27
|
+
const write = (file, source) =>
|
|
28
|
+
fs.writeFileSync(path.join(tmpDir, file), source);
|
|
29
|
+
const writeRegistry = (file, labels) => {
|
|
30
|
+
write(
|
|
31
|
+
file,
|
|
32
|
+
`import {createElement} from 'react';
|
|
33
|
+
export const icons = {
|
|
34
|
+
${Object.entries(labels)
|
|
35
|
+
.map(
|
|
36
|
+
([key, label]) =>
|
|
37
|
+
` ${JSON.stringify(key)}: createElement('svg', {'data-icon': ${JSON.stringify(label)}}),`,
|
|
38
|
+
)
|
|
39
|
+
.join('\n')}
|
|
40
|
+
};
|
|
41
|
+
`,
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
writeRegistry('base/icons.mjs', {
|
|
46
|
+
check: 'base-check',
|
|
47
|
+
close: 'base-close',
|
|
48
|
+
});
|
|
49
|
+
writeRegistry('child/icons.mjs', {
|
|
50
|
+
add: 'child-add',
|
|
51
|
+
close: 'child-close',
|
|
52
|
+
});
|
|
53
|
+
write(
|
|
54
|
+
'base/source.mjs',
|
|
55
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
56
|
+
import {icons} from './icons.mjs';
|
|
57
|
+
export const baseTheme = defineTheme({
|
|
58
|
+
name: 'base', tokens: {'--color-bg': '#fff'}, icons,
|
|
59
|
+
});
|
|
60
|
+
`,
|
|
61
|
+
);
|
|
62
|
+
write(
|
|
63
|
+
'child/source.mjs',
|
|
64
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
65
|
+
import {baseTheme} from '../base/source.mjs';
|
|
66
|
+
import {icons} from './icons.mjs';
|
|
67
|
+
export default defineTheme({
|
|
68
|
+
name: 'child', extends: baseTheme, tokens: {}, icons,
|
|
69
|
+
});
|
|
70
|
+
`,
|
|
71
|
+
);
|
|
72
|
+
const child = await themeBuild('child/source.mjs', {}, {cwd: tmpDir});
|
|
73
|
+
expect(child?.type).toBe('theme.build');
|
|
74
|
+
|
|
75
|
+
write(
|
|
76
|
+
'grandchild.mjs',
|
|
77
|
+
`import {defineTheme} from '@astryxdesign/core/theme';
|
|
78
|
+
import {childTheme} from './child/child.js';
|
|
79
|
+
export default defineTheme({name: 'grandchild', extends: childTheme, tokens: {}});
|
|
80
|
+
`,
|
|
81
|
+
);
|
|
82
|
+
const grandchild = await themeBuild('grandchild.mjs', {}, {cwd: tmpDir});
|
|
83
|
+
expect(grandchild?.type).toBe('theme.build');
|
|
84
|
+
const checked = await themeBuild(
|
|
85
|
+
'grandchild.mjs',
|
|
86
|
+
{check: true},
|
|
87
|
+
{cwd: tmpDir},
|
|
88
|
+
);
|
|
89
|
+
expect(checked?.data.upToDate).toBe(true);
|
|
90
|
+
|
|
91
|
+
// Native imports catch invalid aliases and incorrect relative specifiers
|
|
92
|
+
// that the source loader could otherwise resolve or transform away.
|
|
93
|
+
execFileSync(
|
|
94
|
+
process.execPath,
|
|
95
|
+
[
|
|
96
|
+
'--input-type=module',
|
|
97
|
+
'--eval',
|
|
98
|
+
`import assert from 'node:assert/strict';
|
|
99
|
+
import {isValidElement} from 'react';
|
|
100
|
+
import {childTheme} from './child/child.js';
|
|
101
|
+
import {grandchildTheme} from './grandchild.js';
|
|
102
|
+
const expected = {check: 'base-check', close: 'child-close', add: 'child-add'};
|
|
103
|
+
assert.deepEqual(Object.keys(grandchildTheme.icons).sort(), Object.keys(expected).sort());
|
|
104
|
+
for (const [key, label] of Object.entries(expected)) {
|
|
105
|
+
const icon = grandchildTheme.icons[key];
|
|
106
|
+
assert.ok(isValidElement(icon), key + ' must remain a React element');
|
|
107
|
+
assert.equal(icon.type, 'svg');
|
|
108
|
+
assert.equal(icon.props['data-icon'], label);
|
|
109
|
+
assert.equal(icon, childTheme.icons[key], key + ' must retain its imported identity');
|
|
110
|
+
}`,
|
|
111
|
+
],
|
|
112
|
+
{cwd: tmpDir, stdio: 'pipe', timeout: 10000},
|
|
113
|
+
);
|
|
114
|
+
} finally {
|
|
115
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
116
|
+
}
|
|
117
|
+
});
|