@astryxdesign/cli 0.7.5-canary.dc5a8cf → 0.7.5-canary.e4b225e

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/api/hook/detail/detail.test.mjs +11 -0
  3. package/api/swizzle/copy/copy.mjs +1 -1
  4. package/api/theme/build/build.icon-function-entries.test.mjs +499 -0
  5. package/api/theme/build/build.mjs +172 -14
  6. package/api/theme/build/icon-imports.d.mts +12 -2
  7. package/api/theme/build/icon-imports.mjs +36 -11
  8. package/assets/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +1 -1
  9. package/assets/codemods/transforms/v0.1.5/rename-switch-label-spacing-default-to-hug.mjs +1 -1
  10. package/assets/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +1 -1
  11. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +1 -1
  12. package/assets/codemods/transforms/v0.2.0/remove-tablist-orientation.mjs +1 -1
  13. package/assets/codemods/transforms/v0.2.1/migrate-dialog-position-to-logical.mjs +1 -1
  14. package/assets/docs/README.md +13 -13
  15. package/assets/docs/author-a-theme.doc.mjs +2 -0
  16. package/assets/docs/getting-started.doc.mjs +5 -5
  17. package/assets/docs/icons.doc.mjs +1 -1
  18. package/assets/docs/motion.doc.mjs +1 -1
  19. package/assets/docs/tree/i18n-library-integration.doc.mjs +1 -1
  20. package/assets/docs/tree/tokens-ease.doc.mjs +4 -0
  21. package/assets/docs/tree/tokens.doc.mjs +1 -1
  22. package/assets/theme.template.ts +1 -1
  23. package/authoring/config/config.doc.mjs +1 -1
  24. package/clients/cli/commands/swizzle.routing.test.mjs +1 -1
  25. package/foundation/config/project.d.mts +1 -1
  26. package/foundation/config/project.mjs +1 -1
  27. package/foundation/debug/redact.test.mjs +1 -1
  28. package/package.json +12 -12
package/CHANGELOG.md CHANGED
@@ -71,7 +71,7 @@ Thanks to everyone who contributed to this release:
71
71
  #### New Features
72
72
 
73
73
  - `astryx build` names the right block first far more often. It ranks every block in the catalog by what the request means, read from each block's own name, description, and component, so a block that word matching missed can still come first, with its own score and reason; and the block picker's fixed values are refitted on a larger, more varied set of written example requests, which helps most with requests worded in a product's own terms. A block the request names by its exact name, and a block from an integration, keep their place. The kit never lists more blocks than before, and its fields, page call, start template, and alternatives are unchanged.
74
- - `astryx search` puts the entry you are after first more often: it orders the matches inside each score band, every result keeps its match score and reason, and a query that is an entry's exact name still answers with that entry first ([#7752](https://github.com/facebook/astryx/pull/7752)).
74
+ - `astryx search` puts the entry you are after first more often: it orders the matches inside each score band, every result keeps its match score and reason, and a query that is an entry's exact name still answers with that entry first ([#7752](https://github.com/meta/astryx/pull/7752)).
75
75
  - `astryx doctor integration validate` and `astryx integration check` check the component names a package's docs and blocks give, and list what they find as notes beside validate's issues, each with its fix. Nothing counts a note and `integration check --strict` does not fail on them; they become failing warnings in the next minor release:
76
76
  - `doc_name_mismatch` lists a component doc whose `name` is not the name the component is listed under when the module its printed import names (the doc's `import`, the published subpath, or the package root) provably does not export that name, so `astryx component` would print a broken import. The `Fix:` proposes the file name when that module exports it, otherwise the component it exports. A name that module's exports cannot prove or rule out (a re-export from another package, `export =`, a destructured binding, a namespace, an import that resolves to no file, or, when no import can be resolved, a source that only exports a default) is listed as not checked, with the reason, in validate's new `docNames` report.
77
77
  - `unknown_block_component` lists a name a template's `exampleFor` or `componentsUsed` gives that neither the package nor Core has (every doc `astryx component` resolves in Core counts) and the template does not import it. Imports the template's local helpers make count too, including through a barrel such as `parts/index.ts`. A name is judged only where the template reaches components solely through named imports and re-exports from Core, React, StyleX, local helpers read in full, or the package's own name (followed through its `exports` like a helper). Anything else is listed as not checked in validate's new `blockComponents` report: an import from another package, which may render other components; any `default` binding other than React's or StyleX's; a namespace import; an alias of or member read off an imported binding; a component held in a variable; `require()`; a dynamic `import()`; a file that does not parse cleanly; a local module this check cannot read; and, without Core installed, any name only Core could resolve.
@@ -141,7 +141,7 @@ Thanks to everyone who contributed to this release:
141
141
  - Agents that follow the guide global mode writes to the home folder now know what to do when `astryx` is not found: run the command that installed the CLI for the computer first, with the same package manager and folder, such as `npm i -g @astryxdesign/cli` or `pnpm add -g @astryxdesign/cli`. On machines that keep the home folder but reset system folders on restart, the guide outlived the CLI installed for the computer and told agents to run a command that was gone. Outside a project, when the guide names `astryx` and no `astryx` command is on the search path, apart from a package runner's own copy, `astryx doctor` now says so and names the install step the guide records, or npm's when it records none. The global-mode guide for CI and containers explains how to keep the CLI across restarts. A guide written for a host's own command is unchanged. No JSON shape or exit code changes.
142
142
  - The butter, stone, and y2k themes no longer show the secondary hover fill on a disabled `ComplexSelector` trigger, whether the trigger is natively disabled or exposes `aria-disabled="true"`, the focusable form every disabled control now uses. Before, the guard only recognized a natively disabled trigger. The themes `astryx theme eject` copies carry the same guard.
143
143
  - Apps that use Core's prebuilt CSS without a StyleX build step now get the default data colors: the prebuilt CSS defines the canonical `dataVars` defaults, so compiled imports and raw CSS references paint correctly.
144
- - `astryx init` writes the agent docs at the project root, in files the project commits, so Codex, Gemini CLI, Copilot CLI and Claude Code all read the block from the project root or any folder below it ([#7497](https://github.com/facebook/astryx/pull/7497)). It no longer writes agent docs into a project's subfolder, the home folder, or a settings folder in it such as `~/.gemini`.
144
+ - `astryx init` writes the agent docs at the project root, in files the project commits, so Codex, Gemini CLI, Copilot CLI and Claude Code all read the block from the project root or any folder below it ([#7497](https://github.com/meta/astryx/pull/7497)). It no longer writes agent docs into a project's subfolder, the home folder, or a settings folder in it such as `~/.gemini`.
145
145
  - `AGENTS.md` holds the block, created when missing. Before, a project with only `CLAUDE.md` got the block only there, so Codex and Gemini CLI never saw it.
146
146
  - Claude Code skips `AGENTS.md` in a folder that has a `CLAUDE.md` or `.claude/CLAUDE.md`, so the Claude Code file the project already has keeps a full copy: root `CLAUDE.md`, else `.claude/CLAUDE.md`. It keeps the copy even when it imports `AGENTS.md`, because Claude Code does not follow that import in a session started in a subfolder; started at the root, Claude Code then reads two. When both exist, the copy goes in root `CLAUDE.md`, which projects commit even when they ignore `.claude/`, and a block in `.claude/CLAUDE.md` is removed. Init creates no Claude file. `astryx upgrade` refreshes every copy, except in a project at the top of a home settings folder (see the next entry).
147
147
  - Gemini CLI reads only `GEMINI.md`: init adds a one-line import, `@./AGENTS.md`, creating `GEMINI.md` when it is missing. It adds none when `GEMINI.md` already imports `AGENTS.md`, inline or on its own line. It adds the import even when the project's `.gemini/settings.json` has Gemini read `AGENTS.md` through `context.fileName`: Gemini loads those settings only when it starts at the project root, so a session started in a subfolder would otherwise get no copy. Started at the root, Gemini then reads two.
@@ -160,7 +160,7 @@ Thanks to everyone who contributed to this release:
160
160
  - **Migration:** run `astryx init` from the project's own folder, or add the block to the file by hand. Move a project rooted at the home folder or a settings folder into a folder of its own, or update or remove its block by hand. To remove a block an earlier version wrote into `~/.claude/CLAUDE.md`, run `astryx init --remove-agents` in the home folder.
161
161
  - Repeated searches in one process answer faster: `astryx search` reuses its entry index while the catalog is unchanged, and ties that reuse to one list of the fields the index reads, so the index is never reused after any of them changes. Every answer is unchanged.
162
162
  - Tools that bundle the CLI into a server function no longer pack their whole project folder into it: one path in `integration check`'s import checks was built in a way file tracers cannot follow. The path and its results are unchanged.
163
- - `search()` from `@astryxdesign/cli/api` answers faster when one process searches again: it reuses the components, docs, templates and themes it gathered for the same folder and `type` while no file it read, and no folder it listed, has changed since (a linked workspace package included). To see those reads, the first such search in a process wraps `node:fs`'s read functions for that process; outside a search they behave exactly as before. Results are unchanged. Short-lived runs are unaffected: each `astryx search` command gathers once, as before ([#7830](https://github.com/facebook/astryx/pull/7830)).
163
+ - `search()` from `@astryxdesign/cli/api` answers faster when one process searches again: it reuses the components, docs, templates and themes it gathered for the same folder and `type` while no file it read, and no folder it listed, has changed since (a linked workspace package included). To see those reads, the first such search in a process wraps `node:fs`'s read functions for that process; outside a search they behave exactly as before. Results are unchanged. Short-lived runs are unaffected: each `astryx search` command gathers once, as before ([#7830](https://github.com/meta/astryx/pull/7830)).
164
164
  - `astryx search` and `astryx build` find a block by its authored display name when that name has two words or more and holds every word of the component the block shows: a query naming it, such as "rich text editor" for an integration's Rich Text Editor block, ranks it first. A display name that labels only the variant, such as "Inside a card", is not read.
165
165
 
166
166
  #### Documentation
@@ -27,6 +27,17 @@ describe('hook.detail leaf', () => {
27
27
  expect(Array.isArray(res.data.returns)).toBe(true);
28
28
  }, SLOW);
29
29
 
30
+ it('resolves useCombobox from the Selector entry point with its field props and the requirements it names', async () => {
31
+ const res = await detail('useCombobox', {cwd: REPO});
32
+ expect(res.data.importPath).toBe('@astryxdesign/core/Selector');
33
+ expect(res.data.returns.map(entry => entry.name)).toEqual(
34
+ expect.arrayContaining(['getFieldProps', 'getListboxProps', 'getOptionProps']),
35
+ );
36
+ expect(res.data.usage.accessibility?.map(entry => entry.requirement)).toEqual(
37
+ [1, 2, 3, 4, 5, 6, 7].map(n => `AST-075 FR${n}`),
38
+ );
39
+ }, SLOW);
40
+
30
41
  it('throws ERR_UNKNOWN_HOOK with fuzzy suggestions for an unknown hook', async () => {
31
42
  let err;
32
43
  try {
@@ -30,7 +30,7 @@ import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
30
30
  import {AstryxError, writeFailed} from '../../error.mjs';
31
31
 
32
32
  /** Default issue tracker for maintainer feedback after swizzling. */
33
- const DEFAULT_ISSUES_URL = 'https://github.com/facebook/astryx/issues/new';
33
+ const DEFAULT_ISSUES_URL = 'https://github.com/meta/astryx/issues/new';
34
34
 
35
35
  /**
36
36
  * Rewrite relative imports that point outside the component directory to use
@@ -0,0 +1,499 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Built themes carry function icon entries and resolve them as runtime.
5
+ * @input Real themeBuild and themeBuildFamily calls on source themes whose icon
6
+ * registries hold functions of `{size, variant}` and that list icon variants:
7
+ * a child under a replaced list, a theme extending a built module, a theme
8
+ * extending a package theme, and a family.
9
+ * @output Native ESM loads that render `<Icon>` for every request a theme's
10
+ * entries can receive under the built and the runtime theme, read the public
11
+ * icon views, and a TypeScript program that extends a built theme.
12
+ * @position `architecture:theme-compilation` INV15 and `spec:AST-087` FR3,
13
+ * FR18, and FR19 for theme build. The node project's global setup supplies
14
+ * the compiled core package.
15
+ */
16
+
17
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
18
+ import {execFileSync} from 'node:child_process';
19
+ import * as fs from 'node:fs';
20
+ import * as path from 'node:path';
21
+ import ts from 'typescript';
22
+ import {themeBuild, themeBuildFamily} from './build.mjs';
23
+
24
+ const SIZES = ['xsm', 'sm', 'md', 'lg'];
25
+
26
+ let tmpDir;
27
+ beforeEach(() => {
28
+ // Under the CLI package, so core, React, and TypeScript resolve both in the
29
+ // theme loader and in the native artifact checks.
30
+ tmpDir = fs.mkdtempSync(
31
+ path.resolve(import.meta.dirname, '../../..', '.tmp-icon-functions-'),
32
+ );
33
+ });
34
+ afterEach(() => {
35
+ fs.rmSync(tmpDir, {recursive: true, force: true});
36
+ });
37
+
38
+ /** @param {string} file @param {string} source */
39
+ function write(file, source) {
40
+ fs.mkdirSync(path.dirname(path.join(tmpDir, file)), {recursive: true});
41
+ fs.writeFileSync(path.join(tmpDir, file), source);
42
+ }
43
+
44
+ /** A registry module whose function entries label what they were asked for. */
45
+ function writeRegistry(file, exportName, entries) {
46
+ write(
47
+ file,
48
+ `import {createElement} from 'react';
49
+ const draw = label => ({size, variant}) =>
50
+ createElement('svg', {'data-icon': label + ':' + size + ':' + (variant ?? 'normal')});
51
+ export const ${exportName} = {
52
+ ${Object.entries(entries)
53
+ .map(([key, label]) =>
54
+ label.startsWith('node:')
55
+ ? ` ${JSON.stringify(key)}: createElement('svg', {'data-icon': ${JSON.stringify(label.slice(5))}}),`
56
+ : ` ${JSON.stringify(key)}: draw(${JSON.stringify(label)}),`,
57
+ )
58
+ .join('\n')}
59
+ };
60
+ `,
61
+ );
62
+ }
63
+
64
+ /** The base, its child under a replaced list, and their registries. */
65
+ function writeLineage() {
66
+ writeRegistry('base/icons.mjs', 'baseIcons', {
67
+ info: 'base-info',
68
+ close: 'base-close',
69
+ check: 'node:base-check',
70
+ 'parity:mark': 'base-mark',
71
+ });
72
+ write(
73
+ 'base/source.mjs',
74
+ `import {defineTheme} from '@astryxdesign/core/theme';
75
+ import {baseIcons} from './icons.mjs';
76
+ export const baseTheme = defineTheme({
77
+ name: 'parity-base', tokens: {}, iconVariants: ['outline', 'filled'], icons: baseIcons,
78
+ });
79
+ export default baseTheme;
80
+ `,
81
+ );
82
+ writeRegistry('child/icons.mjs', 'childIcons', {
83
+ close: 'child-close',
84
+ menu: 'child-menu',
85
+ });
86
+ write(
87
+ 'child/source.mjs',
88
+ `import {defineTheme} from '@astryxdesign/core/theme';
89
+ import {baseTheme} from '../base/source.mjs';
90
+ import {childIcons} from './icons.mjs';
91
+ export const childTheme = defineTheme({
92
+ name: 'parity-child', extends: baseTheme, tokens: {},
93
+ iconVariants: ['filled', 'bold'], icons: childIcons,
94
+ });
95
+ export default childTheme;
96
+ `,
97
+ );
98
+ }
99
+
100
+ /** @param {string} file */
101
+ async function buildAndCheck(file) {
102
+ const built = await themeBuild(file, {}, {cwd: tmpDir});
103
+ expect(built?.type).toBe('theme.build');
104
+ const checked = await themeBuild(file, {check: true}, {cwd: tmpDir});
105
+ expect(checked?.data.upToDate).toBe(true);
106
+ return built;
107
+ }
108
+
109
+ /**
110
+ * Load built and runtime themes with native Node and report, for each pair,
111
+ * what `<Icon>` renders for every request and what the public reads return.
112
+ * The requests are every key a theme draws × the four sizes × no variant and
113
+ * each name any theme here lists, so unlisted names are covered too.
114
+ *
115
+ * @param {Array<{label: string, built: string, runtime: string}>} pairs -
116
+ * Module specifiers with `#export` suffixes, relative to the fixture root.
117
+ */
118
+ function inspect(pairs) {
119
+ const load = specifier => {
120
+ const [file, name] = specifier.split('#');
121
+ return `(await import(${JSON.stringify(file)}))[${JSON.stringify(name)}]`;
122
+ };
123
+ const output = execFileSync(
124
+ process.execPath,
125
+ [
126
+ '--input-type=module',
127
+ '--eval',
128
+ `import {createElement, isValidElement} from 'react';
129
+ import {renderToStaticMarkup} from 'react-dom/server';
130
+ import {Icon, getIcon, getIconRegistry} from '@astryxdesign/core/Icon';
131
+ import {Theme} from '@astryxdesign/core/theme';
132
+ const SIZES = ${JSON.stringify(SIZES)};
133
+ const VARIANTS = [undefined, 'outline', 'filled', 'bold'];
134
+ const label = node => {
135
+ if (node == null) return null;
136
+ if (!isValidElement(node)) return 'not-a-node:' + typeof node;
137
+ return node.props['data-icon'];
138
+ };
139
+ const rendered = (theme, icon, size, variant) => {
140
+ const html = renderToStaticMarkup(
141
+ createElement(Theme, {theme}, createElement(Icon, {icon, size, variant})),
142
+ );
143
+ return /data-icon="([^"]+)"/.exec(html)?.[1] ?? null;
144
+ };
145
+ const describe = theme => {
146
+ const keys = Object.keys(theme.icons ?? {}).sort();
147
+ const requests = {};
148
+ for (const key of keys) {
149
+ for (const size of SIZES) {
150
+ for (const variant of VARIANTS) {
151
+ requests[key + '|' + size + '|' + (variant ?? '-')] = rendered(theme, key, size, variant);
152
+ }
153
+ }
154
+ }
155
+ return {
156
+ keys,
157
+ requests,
158
+ icons: Object.fromEntries(keys.map(key => [key, label(theme.icons[key])])),
159
+ getIcon: Object.fromEntries(keys.map(key => [key, label(getIcon(key, theme))])),
160
+ registry: Object.fromEntries(
161
+ Object.entries(getIconRegistry(theme))
162
+ .filter(([key]) => keys.includes(key))
163
+ .map(([key, node]) => [key, label(node)]),
164
+ ),
165
+ iconVariants: theme.iconVariants ?? null,
166
+ };
167
+ };
168
+ const result = {};
169
+ ${pairs
170
+ .map(
171
+ ({label, built, runtime}) => `{
172
+ const built = ${load(built)};
173
+ const runtime = ${load(runtime)};
174
+ const mod = await import(${JSON.stringify(built.split('#')[0])});
175
+ const reexports = Object.entries(mod).filter(([name]) => name !== ${JSON.stringify(built.split('#')[1])});
176
+ result[${JSON.stringify(label)}] = {
177
+ built: describe(built),
178
+ runtime: describe(runtime),
179
+ reexportIsNodeView: reexports.length === 0 ? null : reexports.every(([, value]) => value === built.icons),
180
+ };
181
+ }`,
182
+ )
183
+ .join('\n')}
184
+ process.stdout.write(JSON.stringify(result));`,
185
+ ],
186
+ {cwd: tmpDir, encoding: 'utf8', timeout: 60000},
187
+ );
188
+ return JSON.parse(output);
189
+ }
190
+
191
+ describe('built themes keep function icon entries', () => {
192
+ it('resolve every request as the runtime theme does, including an inherited entry under a replaced list', async () => {
193
+ writeLineage();
194
+ await buildAndCheck('base/source.mjs');
195
+ await buildAndCheck('child/source.mjs');
196
+ // A grandchild extends the BUILT child module.
197
+ write(
198
+ 'grandchild/source.mjs',
199
+ `import {defineTheme} from '@astryxdesign/core/theme';
200
+ import {parityChildTheme} from '../child/parity-child.js';
201
+ export default defineTheme({name: 'parity-grandchild', extends: parityChildTheme, tokens: {}});
202
+ `,
203
+ );
204
+ await buildAndCheck('grandchild/source.mjs');
205
+
206
+ const result = inspect([
207
+ {
208
+ label: 'base',
209
+ built: './base/parity-base.js#parityBaseTheme',
210
+ runtime: './base/source.mjs#default',
211
+ },
212
+ {
213
+ label: 'child',
214
+ built: './child/parity-child.js#parityChildTheme',
215
+ runtime: './child/source.mjs#default',
216
+ },
217
+ {
218
+ label: 'grandchild',
219
+ built: './grandchild/parity-grandchild.js#parityGrandchildTheme',
220
+ runtime: './grandchild/source.mjs#default',
221
+ },
222
+ ]);
223
+
224
+ for (const {built, runtime, reexportIsNodeView} of Object.values(result)) {
225
+ // INV15: built resolution and public views match runtime.
226
+ expect(built).toEqual(runtime);
227
+ expect(reexportIsNodeView).not.toBe(false);
228
+ }
229
+
230
+ const child = result.child.built;
231
+ expect(child.keys).toEqual([
232
+ 'check',
233
+ 'close',
234
+ 'info',
235
+ 'menu',
236
+ 'parity:mark',
237
+ ]);
238
+ for (const size of SIZES) {
239
+ // The child's own entry receives the names the child lists.
240
+ expect(child.requests[`close|${size}|bold`]).toBe(
241
+ `child-close:${size}:bold`,
242
+ );
243
+ expect(child.requests[`close|${size}|filled`]).toBe(
244
+ `child-close:${size}:filled`,
245
+ );
246
+ expect(child.requests[`close|${size}|outline`]).toBe(
247
+ `child-close:${size}:normal`,
248
+ );
249
+ // The inherited entry keeps its defining theme's list: 'outline' is no
250
+ // longer listed by the child, and the base never listed 'bold'.
251
+ expect(child.requests[`info|${size}|filled`]).toBe(
252
+ `base-info:${size}:filled`,
253
+ );
254
+ expect(child.requests[`info|${size}|outline`]).toBe(
255
+ `base-info:${size}:normal`,
256
+ );
257
+ expect(child.requests[`info|${size}|bold`]).toBe(
258
+ `base-info:${size}:normal`,
259
+ );
260
+ expect(child.requests[`info|${size}|-`]).toBe(`base-info:${size}:normal`);
261
+ // A node entry renders the same node for every request.
262
+ expect(child.requests[`check|${size}|filled`]).toBe('base-check');
263
+ }
264
+ expect(result.grandchild.built.requests).toEqual(child.requests);
265
+
266
+ // FR18: public reads are React nodes, each function read at md.
267
+ expect(child.icons).toEqual({
268
+ check: 'base-check',
269
+ close: 'child-close:md:normal',
270
+ info: 'base-info:md:normal',
271
+ menu: 'child-menu:md:normal',
272
+ 'parity:mark': 'base-mark:md:normal',
273
+ });
274
+ expect(child.getIcon).toEqual(child.icons);
275
+ expect(child.registry).toEqual({
276
+ check: 'base-check',
277
+ close: 'child-close:md:normal',
278
+ info: 'base-info:md:normal',
279
+ menu: 'child-menu:md:normal',
280
+ });
281
+ expect(result.base.reexportIsNodeView).toBe(true);
282
+ expect(result.child.reexportIsNodeView).toBe(true);
283
+ });
284
+
285
+ it('keeps the function entries of a package theme it extends', async () => {
286
+ const pkg = 'node_modules/@fixture/function-icons';
287
+ write(
288
+ `${pkg}/package.json`,
289
+ JSON.stringify({
290
+ name: '@fixture/function-icons',
291
+ type: 'module',
292
+ exports: './index.mjs',
293
+ }),
294
+ );
295
+ writeRegistry(`${pkg}/icons.mjs`, 'packageIcons', {info: 'package-info'});
296
+ write(
297
+ `${pkg}/index.mjs`,
298
+ `import {defineTheme} from '@astryxdesign/core/theme';
299
+ import {packageIcons} from './icons.mjs';
300
+ export const packageTheme = defineTheme({
301
+ name: 'parity-package', tokens: {}, iconVariants: ['filled'], icons: packageIcons,
302
+ });
303
+ `,
304
+ );
305
+ write(
306
+ 'package-child.mjs',
307
+ `import {defineTheme} from '@astryxdesign/core/theme';
308
+ import {packageTheme} from '@fixture/function-icons';
309
+ export default defineTheme({name: 'parity-package-child', extends: packageTheme, tokens: {}});
310
+ `,
311
+ );
312
+ await buildAndCheck('package-child.mjs');
313
+
314
+ const {packageChild} = inspect([
315
+ {
316
+ label: 'packageChild',
317
+ built: './parity-package-child.js#parityPackageChildTheme',
318
+ runtime: './package-child.mjs#default',
319
+ },
320
+ ]);
321
+
322
+ expect(packageChild.built).toEqual(packageChild.runtime);
323
+ for (const size of SIZES) {
324
+ expect(packageChild.built.requests[`info|${size}|filled`]).toBe(
325
+ `package-info:${size}:filled`,
326
+ );
327
+ }
328
+ expect(packageChild.built.icons).toEqual({info: 'package-info:md:normal'});
329
+ });
330
+
331
+ it('keeps function entries in a family build', async () => {
332
+ writeLineage();
333
+ // A member that sets no icons of its own inherits the child's entries.
334
+ write(
335
+ 'inherit/source.mjs',
336
+ `import {defineTheme} from '@astryxdesign/core/theme';
337
+ import {childTheme} from '../child/source.mjs';
338
+ export default defineTheme({name: 'parity-inherit', extends: childTheme, tokens: {}});
339
+ `,
340
+ );
341
+ const receipt = await themeBuildFamily(
342
+ ['base/source.mjs', 'child/source.mjs', 'inherit/source.mjs'],
343
+ {familyKey: 'parity-family'},
344
+ {cwd: tmpDir},
345
+ );
346
+ expect(receipt?.type).toBe('theme.build');
347
+ const familyModule = `./${receipt.data.outputs.js}`;
348
+
349
+ const result = inspect([
350
+ {
351
+ label: 'base',
352
+ built: `${familyModule}#parityBaseTheme`,
353
+ runtime: './base/source.mjs#default',
354
+ },
355
+ {
356
+ label: 'child',
357
+ built: `${familyModule}#parityChildTheme`,
358
+ runtime: './child/source.mjs#default',
359
+ },
360
+ {
361
+ label: 'inherit',
362
+ built: `${familyModule}#parityInheritTheme`,
363
+ runtime: './inherit/source.mjs#default',
364
+ },
365
+ ]);
366
+
367
+ expect(result.base.built).toEqual(result.base.runtime);
368
+ expect(result.child.built).toEqual(result.child.runtime);
369
+ expect(result.inherit.built).toEqual(result.inherit.runtime);
370
+ expect(result.inherit.built.requests).toEqual(result.child.built.requests);
371
+ expect(result.child.built.requests['info|sm|filled']).toBe(
372
+ 'base-info:sm:filled',
373
+ );
374
+ expect(result.child.built.requests['info|sm|outline']).toBe(
375
+ 'base-info:sm:normal',
376
+ );
377
+ });
378
+ });
379
+
380
+ describe('the node view never captures a registry binding', () => {
381
+ it.each(['entries', 'nodes', 'name', 'entry', 'Object'])(
382
+ 'loads a built theme whose registry is imported as `%s`',
383
+ async binding => {
384
+ writeRegistry('icons.mjs', 'registry', {info: 'bound-info'});
385
+ write(
386
+ 'bound.mjs',
387
+ `import {defineTheme} from '@astryxdesign/core/theme';
388
+ import {registry as ${binding}} from './icons.mjs';
389
+ export default defineTheme({
390
+ name: 'bound', tokens: {}, iconVariants: ['filled'], icons: ${binding},
391
+ });
392
+ `,
393
+ );
394
+ await buildAndCheck('bound.mjs');
395
+
396
+ const {bound} = inspect([
397
+ {
398
+ label: 'bound',
399
+ built: './bound.js#boundTheme',
400
+ runtime: './bound.mjs#default',
401
+ },
402
+ ]);
403
+ expect(bound.built).toEqual(bound.runtime);
404
+ expect(bound.built.icons).toEqual({info: 'bound-info:md:normal'});
405
+ expect(bound.built.requests['info|lg|filled']).toBe(
406
+ 'bound-info:lg:filled',
407
+ );
408
+ expect(bound.reexportIsNodeView).toBe(true);
409
+ },
410
+ );
411
+ });
412
+
413
+ describe('a built theme types its icon variants', () => {
414
+ it('lets a theme extending the built module type `variant` by its list', async () => {
415
+ writeLineage();
416
+ await buildAndCheck('base/source.mjs');
417
+
418
+ const variants = fs.readFileSync(
419
+ path.join(tmpDir, 'base/parity-base.variants.d.ts'),
420
+ 'utf8',
421
+ );
422
+ expect(variants).toContain("declare module '@astryxdesign/core/Icon'");
423
+ expect(variants).toContain("'outline': true;");
424
+ expect(variants).toContain("'filled': true;");
425
+
426
+ write(
427
+ 'consumer.ts',
428
+ `import {defineTheme} from '@astryxdesign/core/theme';
429
+ import type {IconVariant} from '@astryxdesign/core/Icon';
430
+ import {parityBaseTheme} from './base/parity-base.js';
431
+
432
+ type Equal<A, B> =
433
+ (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
434
+
435
+ defineTheme({
436
+ name: 'consumer',
437
+ extends: parityBaseTheme,
438
+ icons: {
439
+ info: ({variant}) => {
440
+ const exact: Equal<typeof variant, 'outline' | 'filled' | undefined> = true;
441
+ return exact ? null : null;
442
+ },
443
+ // @ts-expect-error -- 'bold' is not a name the built theme lists.
444
+ close: ({variant}) => (variant === 'bold' ? null : null),
445
+ },
446
+ });
447
+
448
+ // The built theme's augmentation adds its names to IconVariant.
449
+ export const listed: IconVariant = 'filled';
450
+ // @ts-expect-error -- no theme here lists 'bold'.
451
+ export const unlisted: IconVariant = 'bold';
452
+ `,
453
+ );
454
+ const program = ts.createProgram([path.join(tmpDir, 'consumer.ts')], {
455
+ strict: true,
456
+ noEmit: true,
457
+ skipLibCheck: true,
458
+ target: ts.ScriptTarget.ES2022,
459
+ module: ts.ModuleKind.ESNext,
460
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
461
+ types: [],
462
+ });
463
+ const diagnostics = ts
464
+ .getPreEmitDiagnostics(program)
465
+ .filter(diagnostic => diagnostic.file?.fileName.endsWith('consumer.ts'))
466
+ .map(diagnostic =>
467
+ ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
468
+ );
469
+ expect(diagnostics).toEqual([]);
470
+ });
471
+ });
472
+
473
+ describe('a function the build cannot carry fails the build', () => {
474
+ it.each([
475
+ [
476
+ 'an inline function entry',
477
+ `icons: {info: ({size}) => createElement('svg', {'data-size': size})}`,
478
+ ],
479
+ [
480
+ 'a function beside a spread registry',
481
+ `icons: {...baseIcons, info: () => null}`,
482
+ ],
483
+ ])('rejects %s before writing', async (_label, iconsField) => {
484
+ writeRegistry('icons.mjs', 'baseIcons', {close: 'base-close'});
485
+ write(
486
+ 'inline.mjs',
487
+ `import {createElement} from 'react';
488
+ import {defineTheme} from '@astryxdesign/core/theme';
489
+ import {baseIcons} from './icons.mjs';
490
+ export default defineTheme({name: 'inline-functions', tokens: {}, ${iconsField}});
491
+ `,
492
+ );
493
+
494
+ await expect(
495
+ themeBuild('inline.mjs', {}, {cwd: tmpDir}),
496
+ ).rejects.toMatchObject({code: 'ERR_THEME_INVALID'});
497
+ expect(fs.readdirSync(tmpDir).sort()).toEqual(['icons.mjs', 'inline.mjs']);
498
+ });
499
+ });