@astryxdesign/cli 0.7.5-canary.fccd771 → 0.7.5

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 (117) hide show
  1. package/CHANGELOG.md +91 -3
  2. package/README.md +2 -2
  3. package/api/hook/detail/detail.test.mjs +11 -0
  4. package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
  5. package/api/integration/pack-check.mjs +10 -4
  6. package/api/integration/pack-check.test.mjs +5 -1
  7. package/api/swizzle/copy/copy.mjs +1 -1
  8. package/api/template/tokenizer-showcase.test.mjs +47 -0
  9. package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
  10. package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
  11. package/api/theme/build/build.icon-function-entries.test.mjs +499 -0
  12. package/api/theme/build/build.icon-variants.test.mjs +105 -0
  13. package/api/theme/build/build.mjs +371 -113
  14. package/api/theme/build/build.project-core.test.mjs +63 -8
  15. package/api/theme/build/build.test.mjs +77 -0
  16. package/api/theme/build/icon-imports.d.mts +12 -2
  17. package/api/theme/build/icon-imports.mjs +36 -11
  18. package/api/upgrade/_adapter.d.mts +47 -2
  19. package/api/upgrade/_adapter.mjs +58 -2
  20. package/api/upgrade/run/failure-receipt.test.mjs +212 -0
  21. package/api/upgrade/run/outcomes.test.mjs +646 -0
  22. package/api/upgrade/run/run.d.mts +36 -0
  23. package/api/upgrade/run/run.mjs +670 -44
  24. package/api/upgrade/upgrade.doc.mjs +4 -4
  25. package/api/upgrade/upgrade.mjs +19 -4
  26. package/api/upgrade/upgrade.type.d.mts +36 -1
  27. package/api/upgrade/upgrade.type.mjs +29 -4
  28. package/assets/codemods/__tests__/registry.test.mjs +1 -0
  29. package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
  30. package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
  31. package/assets/codemods/integration-runner.mjs +8 -2
  32. package/assets/codemods/integration-runner.protection.test.mjs +53 -0
  33. package/assets/codemods/outcome.mjs +79 -0
  34. package/assets/codemods/outcome.test.mjs +40 -0
  35. package/assets/codemods/parse.mjs +94 -0
  36. package/assets/codemods/registry.mjs +1 -0
  37. package/assets/codemods/run-codemod.mjs +109 -5
  38. package/assets/codemods/runner.mjs +119 -13
  39. package/assets/codemods/transform-prop.mjs +99 -49
  40. package/assets/codemods/transform-prop.test.mjs +36 -1
  41. package/assets/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +1 -1
  42. package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
  43. package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
  44. package/assets/codemods/transforms/v0.1.5/rename-switch-label-spacing-default-to-hug.mjs +1 -1
  45. package/assets/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +1 -1
  46. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +1 -1
  47. package/assets/codemods/transforms/v0.2.0/remove-tablist-orientation.mjs +1 -1
  48. package/assets/codemods/transforms/v0.2.1/migrate-dialog-position-to-logical.mjs +1 -1
  49. package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
  50. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
  51. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +143 -70
  52. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
  53. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
  54. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
  55. package/assets/codemods/transforms/v0.7.5/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
  56. package/assets/codemods/transforms/v0.7.5/index.mjs +20 -0
  57. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +315 -0
  58. package/assets/docs/README.md +13 -13
  59. package/assets/docs/author-a-theme.doc.mjs +5 -1
  60. package/assets/docs/getting-started.doc.mjs +5 -5
  61. package/assets/docs/icons.doc.mjs +82 -1
  62. package/assets/docs/motion.doc.mjs +1 -1
  63. package/assets/docs/theme.doc.dense.mjs +8 -0
  64. package/assets/docs/theme.doc.mjs +16 -0
  65. package/assets/docs/theme.doc.zh.mjs +11 -0
  66. package/assets/docs/tree/i18n-library-integration.doc.mjs +1 -1
  67. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  68. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  69. package/assets/docs/tree/tokens-color.doc.mjs +145 -1
  70. package/assets/docs/tree/tokens-ease.doc.mjs +4 -0
  71. package/assets/docs/tree/tokens.doc.mjs +1 -1
  72. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
  73. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
  74. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
  75. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
  76. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
  77. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
  78. package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
  79. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
  80. package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
  81. package/assets/templates/pages/library/page.tsx +1 -2
  82. package/assets/templates/pages/table-comparison/page.tsx +12 -3
  83. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
  84. package/assets/templates/themes/butter/butterTheme.ts +47 -44
  85. package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
  86. package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
  87. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
  88. package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
  89. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
  90. package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
  91. package/assets/templates/themes/stone/stoneTheme.ts +46 -21
  92. package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
  93. package/assets/theme.template.ts +19 -6
  94. package/authoring/codemod/type.ts +10 -0
  95. package/authoring/config/config.doc.mjs +1 -1
  96. package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
  97. package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
  98. package/clients/cli/commands/swizzle.routing.test.mjs +1 -1
  99. package/clients/cli/commands/upgrade.doc.mjs +47 -2
  100. package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
  101. package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
  102. package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
  103. package/clients/cli/commands/upgrade.mjs +9 -2
  104. package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
  105. package/foundation/agent-docs/agent-docs.mjs +1 -0
  106. package/foundation/agent-docs/agent-docs.test.mjs +5 -0
  107. package/foundation/config/project.d.mts +1 -1
  108. package/foundation/config/project.mjs +1 -1
  109. package/foundation/debug/redact.test.mjs +1 -1
  110. package/foundation/doc-compiler/doc-loads.test.mjs +2 -6
  111. package/foundation/response/base.d.ts +7 -0
  112. package/foundation/response/error-codes.doc.mjs +3 -2
  113. package/foundation/response/error-codes.mjs +1 -1
  114. package/foundation/response/json.d.mts +10 -3
  115. package/foundation/response/json.mjs +16 -4
  116. package/foundation/response/response-types.doc.mjs +1 -1
  117. package/package.json +13 -12
@@ -7,15 +7,26 @@
7
7
  * app's `<Theme>` runs on the app's Core either way, so the build loads the
8
8
  * project's installed `@astryxdesign/core` when it differs from the CLI's own.
9
9
  * When there is no Core to use, the error names the fix for where it ran:
10
- * install it in an app, build it in the Astryx repository.
10
+ * install it in an app, build it in the Astryx repository. An installed Core
11
+ * that does not load, or lacks the functions the build calls, fails the build,
12
+ * naming it, rather than leave the build to the CLI's own Core.
11
13
  */
12
14
 
13
- import {afterEach, beforeEach, describe, expect, it} from 'vitest';
15
+ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
14
16
  import * as fs from 'node:fs';
15
17
  import * as os from 'node:os';
16
18
  import * as path from 'node:path';
17
19
  import {fileURLToPath, pathToFileURL} from 'node:url';
18
20
  import {coreUnavailableMessage, themeBuild} from './build.mjs';
21
+ import {fetchCarriedThemeCoreDir} from '../_adapter.mjs';
22
+
23
+ vi.mock('../_adapter.mjs', async importOriginal => {
24
+ const actual = /** @type {Record<string, any>} */ (await importOriginal());
25
+ return {
26
+ ...actual,
27
+ fetchCarriedThemeCoreDir: vi.fn(actual.fetchCarriedThemeCoreDir),
28
+ };
29
+ });
19
30
 
20
31
  const HERE = path.dirname(fileURLToPath(import.meta.url));
21
32
  const REPO_ROOT = path.resolve(HERE, '../../../../..');
@@ -53,9 +64,10 @@ afterEach(() => {
53
64
  * entry as it is imported. Its `exports` map lists `source` first, as Core's
54
65
  * own does, so the build must skip that condition to find the runtime file.
55
66
  * @param {string} dir
56
- * @param {{broken?: boolean}} [options]
67
+ * @param {{broken?: boolean, themeModule?: string}} [options] `themeModule`
68
+ * replaces the theme entry's source
57
69
  */
58
- function installCore(dir, {broken = false} = {}) {
70
+ function installCore(dir, {broken = false, themeModule} = {}) {
59
71
  const core = path.join(dir, 'node_modules', '@astryxdesign', 'core');
60
72
  fs.mkdirSync(core, {recursive: true});
61
73
  fs.writeFileSync(
@@ -82,12 +94,29 @@ function installCore(dir, {broken = false} = {}) {
82
94
  `globalThis.__astryxProjectCoreLoads = [...(globalThis.__astryxProjectCoreLoads ?? []), '${entry}'];\n`;
83
95
  fs.writeFileSync(
84
96
  path.join(core, 'theme.mjs'),
85
- module('theme', 'theme/index.js'),
97
+ themeModule ?? module('theme', 'theme/index.js'),
86
98
  );
87
99
  fs.writeFileSync(path.join(core, 'root.mjs'), module('root', 'index.js'));
88
100
  return core;
89
101
  }
90
102
 
103
+ describe('theme build outside a project, with the Core this CLI release carries', () => {
104
+ it('fails naming a carried Core that does not load, rather than build with the CLI’s own', async () => {
105
+ const carried = installCore(makeDir(), {broken: true});
106
+ vi.mocked(fetchCarriedThemeCoreDir).mockReturnValueOnce(carried);
107
+ const bare = makeDir();
108
+ const build = themeBuild('ocean.mjs', {}, {cwd: bare});
109
+ await expect(build).rejects.toMatchObject({
110
+ code: 'ERR_CORE_NOT_FOUND',
111
+ message: expect.stringContaining(
112
+ `Could not load the @astryxdesign/core this CLI release carries, at ${carried}`,
113
+ ),
114
+ });
115
+ await expect(build).rejects.toThrow(/Import error: this Core is broken/);
116
+ expect(fs.existsSync(path.join(bare, 'ocean.css'))).toBe(false);
117
+ });
118
+ });
119
+
91
120
  describe('theme build generates with the Core the project installed', () => {
92
121
  it('loads the app’s installed Core when it differs from the CLI’s own', async () => {
93
122
  const app = makeDir();
@@ -114,11 +143,37 @@ describe('theme build generates with the Core the project installed', () => {
114
143
  expect(fs.existsSync(path.join(bare, 'ocean.css'))).toBe(true);
115
144
  });
116
145
 
117
- it('keeps the CLI’s own Core when the installed one does not load', async () => {
146
+ it('fails naming an installed Core that does not load, rather than build with the CLI’s own', async () => {
118
147
  const app = makeDir();
119
148
  installCore(app, {broken: true});
120
- await themeBuild('ocean.mjs', {}, {cwd: app});
121
- expect(fs.existsSync(path.join(app, 'ocean.css'))).toBe(true);
149
+ await expect(themeBuild('ocean.mjs', {}, {cwd: app})).rejects.toMatchObject(
150
+ {
151
+ code: 'ERR_CORE_NOT_FOUND',
152
+ message: expect.stringContaining(
153
+ `Could not load the @astryxdesign/core installed at ${path.join('node_modules', '@astryxdesign', 'core')}`,
154
+ ),
155
+ },
156
+ );
157
+ await expect(themeBuild('ocean.mjs', {}, {cwd: app})).rejects.toThrow(
158
+ /Import error: this Core is broken/,
159
+ );
160
+ expect(fs.existsSync(path.join(app, 'ocean.css'))).toBe(false);
161
+ });
162
+
163
+ it('fails naming an installed Core without the functions the build calls, rather than build with the CLI’s own', async () => {
164
+ const app = makeDir();
165
+ installCore(app, {
166
+ themeModule: 'export const defineTheme = theme => theme;\n',
167
+ });
168
+ await expect(themeBuild('ocean.mjs', {}, {cwd: app})).rejects.toMatchObject(
169
+ {
170
+ code: 'ERR_CORE_INCOMPATIBLE',
171
+ message: expect.stringContaining(
172
+ 'does not export generateThemeRulesSplit',
173
+ ),
174
+ },
175
+ );
176
+ expect(fs.existsSync(path.join(app, 'ocean.css'))).toBe(false);
122
177
  });
123
178
  });
124
179
 
@@ -27,6 +27,7 @@ import {
27
27
  import {
28
28
  themeBuild,
29
29
  validateComponentOverridesAgainstRegistry,
30
+ validateThemePrivateInputs,
30
31
  } from './build.mjs';
31
32
 
32
33
  // `themeBuild` captures core's generator once at module load. Wrap the two
@@ -212,6 +213,55 @@ describe('themeBuild() — receipt', () => {
212
213
  });
213
214
  });
214
215
 
216
+ describe.each(['mjs', 'ts'])('a .%s theme module with no theme export', ext => {
217
+ beforeEach(() => {
218
+ fs.writeFileSync(
219
+ path.join(tmpDir, `none.${ext}`),
220
+ 'export const notATheme = 42;\n',
221
+ );
222
+ });
223
+
224
+ it('fails the build as a module that does not load a theme', async () => {
225
+ const build = themeBuild(`none.${ext}`, {}, {cwd: tmpDir});
226
+ await expect(build).rejects.toThrow(
227
+ /Could not find a defineTheme\(\) result/,
228
+ );
229
+ await expect(build).rejects.toMatchObject({code: 'ERR_THEME_LOAD'});
230
+ });
231
+
232
+ it("fails doctor's private-input check the same way, rather than read its exports as a theme", async () => {
233
+ await expect(
234
+ validateThemePrivateInputs(`none.${ext}`, {cwd: tmpDir}),
235
+ ).rejects.toThrow(/Could not find a defineTheme\(\) result/);
236
+ });
237
+ });
238
+
239
+ describe('themeBuild() — a theme module that does not load', () => {
240
+ it('fails with the import error, rather than build the theme from the file text', async () => {
241
+ fs.writeFileSync(
242
+ path.join(tmpDir, 'unresolved.mjs'),
243
+ "import './missing-helper.mjs';\nexport default {name: 'unresolved', tokens: {'--color-bg': '#000'}};\n",
244
+ );
245
+ await expect(
246
+ themeBuild('unresolved.mjs', {}, {cwd: tmpDir}),
247
+ ).rejects.toThrow(
248
+ /Failed to load theme from .*unresolved\.mjs: .*missing-helper\.mjs/s,
249
+ );
250
+ expect(fs.existsSync(path.join(tmpDir, 'unresolved.css'))).toBe(false);
251
+ });
252
+
253
+ it('fails with the error the module throws, rather than build the theme from the file text', async () => {
254
+ fs.writeFileSync(
255
+ path.join(tmpDir, 'throws.mjs'),
256
+ "throw new Error('the theme module failed');\nexport default {name: 'throws', tokens: {'--color-bg': '#000'}};\n",
257
+ );
258
+ await expect(themeBuild('throws.mjs', {}, {cwd: tmpDir})).rejects.toThrow(
259
+ /the theme module failed/,
260
+ );
261
+ expect(fs.existsSync(path.join(tmpDir, 'throws.css'))).toBe(false);
262
+ });
263
+ });
264
+
215
265
  describe('themeBuild() — dropped declarations reach the receipt', () => {
216
266
  // Core's generator refuses a declaration whose value would end it early
217
267
  // (an unquoted `;` or brace, an unclosed string/comment/url). The runtime
@@ -599,6 +649,33 @@ describe('themeBuild() — component override validation', () => {
599
649
  });
600
650
  });
601
651
 
652
+ describe('themeBuild() — Icon size dimensions', () => {
653
+ it('writes width and height on an icon size into the vars the glyph reads, with no warnings', async () => {
654
+ // spec:AST-087 FR10: a built theme sets an Icon size's glyph dimension the
655
+ // way the runtime provider does, through the shared compiler's derived
656
+ // vars. Raw width/height would lose to a consumer's unlayered StyleX.
657
+ const themeFile = path.join(tmpDir, 'iconsizes.mjs');
658
+ fs.writeFileSync(
659
+ themeFile,
660
+ `export default {
661
+ name: 'iconsizes',
662
+ tokens: {'--color-bg': '#0a0a0a'},
663
+ components: {icon: {'size:sm': {width: '18px', height: '22px'}}},
664
+ };\n`,
665
+ );
666
+
667
+ const result = await themeBuild('iconsizes.mjs', {}, {cwd: tmpDir});
668
+
669
+ expect(result?.data.warnings).toEqual([]);
670
+ const css = fs.readFileSync(path.join(tmpDir, 'iconsizes.css'), 'utf8');
671
+ const rule =
672
+ css.match(/\.astryx-icon\[data-size="sm"\]\s*\{([^}]*)\}/)?.[1] ?? '';
673
+ expect(rule).toMatch(/--_icon-width:\s*18px/);
674
+ expect(rule).toMatch(/--_icon-height:\s*22px/);
675
+ expect(rule).not.toMatch(/(^|[\s;])(width|height)\s*:/);
676
+ });
677
+ });
678
+
602
679
  describe('themeBuild() — the shipped theme template', () => {
603
680
  // `assets/theme.template.ts` is what `astryx theme template` puts in a
604
681
  // consumer's project. It is the one theme file we hand out, so it has to
@@ -6,13 +6,18 @@
6
6
  * Local base themes are traced to their registry imports. Package bases remain
7
7
  * public theme imports, so their implementation and private files stay private.
8
8
  *
9
+ * A theme whose resolved icon entries include a function keeps them: a package
10
+ * base is read for its entries (`__icons`) as well as its node-valued `icons`,
11
+ * and a built base module's `__icons` field is followed instead of `icons`.
12
+ *
9
13
  * @param {string} filePath
10
14
  * @param {string | undefined} exportName
11
- * @param {{hasIcons: boolean, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
15
+ * @param {{hasIcons: boolean, functionEntries?: boolean, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
12
16
  * @returns {Promise<IconImports | null>}
13
17
  */
14
- export function resolveIconImports(filePath: string, exportName: string | undefined, { hasIcons, readSource, resolveModule, reservedNames, rawInput }: {
18
+ export function resolveIconImports(filePath: string, exportName: string | undefined, { hasIcons, functionEntries, readSource, resolveModule, reservedNames, rawInput, }: {
15
19
  hasIcons: boolean;
20
+ functionEntries?: boolean;
16
21
  readSource: (filename: string) => string;
17
22
  resolveModule: (specifier: string, fromFile: string) => string | Promise<string>;
18
23
  reservedNames?: string[];
@@ -35,11 +40,16 @@ export type RegistryReference = {
35
40
  binding: any;
36
41
  members: string[];
37
42
  };
43
+ /**
44
+ * `entries` marks a package theme read for its icon entries: its node-valued
45
+ * `icons` merged with the `__icons` that hold its function entries, if any.
46
+ */
38
47
  export type RegistryPlan = {
39
48
  kind: "registry";
40
49
  ref: RegistryReference;
41
50
  preferredName: string;
42
51
  override?: boolean;
52
+ entries?: boolean;
43
53
  } | {
44
54
  kind: "merge";
45
55
  base: RegistryPlan;
@@ -24,7 +24,11 @@ import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
24
24
  */
25
25
 
26
26
  /** @typedef {{kind: 'reference', module: any, binding: any, members: string[]}} RegistryReference */
27
- /** @typedef {{kind: 'registry', ref: RegistryReference, preferredName: string, override?: boolean} | {kind: 'merge', base: RegistryPlan, own: RegistryPlan}} RegistryPlan */
27
+ /**
28
+ * `entries` marks a package theme read for its icon entries: its node-valued
29
+ * `icons` merged with the `__icons` that hold its function entries, if any.
30
+ * @typedef {{kind: 'registry', ref: RegistryReference, preferredName: string, override?: boolean, entries?: boolean} | {kind: 'merge', base: RegistryPlan, own: RegistryPlan}} RegistryPlan
31
+ */
28
32
 
29
33
  /** @param {any} node */
30
34
  function unwrap(node) {
@@ -98,15 +102,26 @@ function invalidRegistry(name, reason = '') {
98
102
  * Local base themes are traced to their registry imports. Package bases remain
99
103
  * public theme imports, so their implementation and private files stay private.
100
104
  *
105
+ * A theme whose resolved icon entries include a function keeps them: a package
106
+ * base is read for its entries (`__icons`) as well as its node-valued `icons`,
107
+ * and a built base module's `__icons` field is followed instead of `icons`.
108
+ *
101
109
  * @param {string} filePath
102
110
  * @param {string | undefined} exportName
103
- * @param {{hasIcons: boolean, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
111
+ * @param {{hasIcons: boolean, functionEntries?: boolean, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
104
112
  * @returns {Promise<IconImports | null>}
105
113
  */
106
114
  export async function resolveIconImports(
107
115
  filePath,
108
116
  exportName,
109
- {hasIcons, readSource, resolveModule, reservedNames = [], rawInput = false},
117
+ {
118
+ hasIcons,
119
+ functionEntries = false,
120
+ readSource,
121
+ resolveModule,
122
+ reservedNames = [],
123
+ rawInput = false,
124
+ },
110
125
  ) {
111
126
  if (exportName === undefined) {
112
127
  if (!hasIcons) return null;
@@ -391,11 +406,16 @@ export async function resolveIconImports(
391
406
 
392
407
  /** @param {RegistryReference} ref @returns {RegistryPlan} */
393
408
  function packageTheme(ref) {
394
- return {
395
- kind: 'registry',
396
- ref: {...ref, members: [...ref.members, 'icons']},
397
- preferredName: 'themeIcons',
398
- };
409
+ // A theme's `icons` is node-valued; its function entries live in
410
+ // `__icons`. Read both only when the built theme needs its functions, so
411
+ // a theme without them keeps its existing output.
412
+ return functionEntries
413
+ ? {kind: 'registry', ref, preferredName: 'themeIcons', entries: true}
414
+ : {
415
+ kind: 'registry',
416
+ ref: {...ref, members: [...ref.members, 'icons']},
417
+ preferredName: 'themeIcons',
418
+ };
399
419
  }
400
420
 
401
421
  /** @param {any} module @param {string} name @param {boolean} [rejectOpaque] @returns {Promise<RegistryPlan | null>} */
@@ -513,7 +533,7 @@ export async function resolveIconImports(
513
533
  : propertyName(item.key);
514
534
  if (key === null)
515
535
  invalidRegistry(undefined, 'Computed theme keys cannot be resolved.');
516
- if (!['icons', 'extends'].includes(key)) continue;
536
+ if (!['icons', '__icons', 'extends'].includes(key)) continue;
517
537
  if (
518
538
  !['ObjectProperty', 'Property'].includes(item.type) ||
519
539
  item.method ||
@@ -566,7 +586,9 @@ export async function resolveIconImports(
566
586
  }
567
587
  const config = await fields(module, node);
568
588
  const baseField = config.get('extends');
569
- const iconField = config.get('icons');
589
+ // A built module keeps its function entries in `__icons` beside its
590
+ // node-valued `icons`; the entries are the registry to carry.
591
+ const iconField = config.get('__icons') ?? config.get('icons');
570
592
  const base = baseField
571
593
  ? await theme(baseField.module, baseField.node)
572
594
  : null;
@@ -655,10 +677,13 @@ export async function resolveIconImports(
655
677
  localName,
656
678
  });
657
679
  }
658
- const expression = ref.members.reduce(
680
+ const target = ref.members.reduce(
659
681
  (result, member) => `${result}[${JSON.stringify(member)}]`,
660
682
  localName,
661
683
  );
684
+ const expression = value.entries
685
+ ? `{...${target}["icons"], ...${target}["__icons"]}`
686
+ : target;
662
687
  return {
663
688
  expression,
664
689
  preferredName:
@@ -180,13 +180,42 @@ export function getCoreVersionManifests(from: string, to: string): Promise<CoreV
180
180
  export function ensureCodemodDeps({ installDeps }?: {
181
181
  installDeps?: boolean;
182
182
  }): Promise<boolean>;
183
+ /**
184
+ * @typedef {{kind: 'manual', file: string, codemod: string, message: string, line?: number} | {kind: 'regenerate', file: string, codemod: string, message: string, commands: string[]}} CodemodOutcomeRecord
185
+ */
186
+ /**
187
+ * Wrap each core code and config transform so the non-failure outcomes it
188
+ * throws (`assets/codemods/outcome.mjs`) are recorded instead of reaching the
189
+ * runner as errors. The wrapped transform leaves that file unchanged, exactly
190
+ * as the throw did. Project codemods keep their own contract. One wrapper per
191
+ * pass: the regeneration re-check takes a fresh one, so an outcome a hook
192
+ * resolved does not linger.
193
+ *
194
+ * @template {{version: string, transforms: Array<{name: string, transform: any, meta?: {codemodType?: string}}>}} M
195
+ * @param {M[]} versionManifests
196
+ * @param {string} root project root; recorded files are relative to it
197
+ * @returns {{versionManifests: M[], outcomes: CodemodOutcomeRecord[]}}
198
+ */
199
+ export function withCodemodOutcomes<M extends {
200
+ version: string;
201
+ transforms: Array<{
202
+ name: string;
203
+ transform: any;
204
+ meta?: {
205
+ codemodType?: string;
206
+ };
207
+ }>;
208
+ }>(versionManifests: M[], root: string): {
209
+ versionManifests: M[];
210
+ outcomes: CodemodOutcomeRecord[];
211
+ };
183
212
  /**
184
213
  * Run the CORE registry codemods. Runs BEFORE the config is loaded so a core
185
214
  * CONFIG codemod can repair a config the strict loader would otherwise reject.
186
215
  * @param {CoreVersionManifest[]} versionManifests
187
- * @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean}} options
216
+ * @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean, outcomes?: CodemodOutcomeRecord[]}} options
188
217
  */
189
- export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply, path: srcPath, codemod, skipCodemods, root, protection, silent, coversTarget, }: {
218
+ export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply, path: srcPath, codemod, skipCodemods, root, protection, silent, coversTarget, outcomes, }: {
190
219
  apply: boolean;
191
220
  path: string;
192
221
  codemod?: string;
@@ -198,6 +227,7 @@ export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply
198
227
  };
199
228
  silent?: boolean;
200
229
  coversTarget?: boolean;
230
+ outcomes?: CodemodOutcomeRecord[];
201
231
  }): Promise<{
202
232
  totalFilesChanged: number;
203
233
  totalTransformsApplied: number;
@@ -206,6 +236,7 @@ export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply
206
236
  writtenFiles: string[];
207
237
  stagedContents: Map<string, string>;
208
238
  protectedFiles: import("../../authoring/codemod/type").CodemodRunResult["protectedFiles"];
239
+ declinedCandidates: NonNullable<import("../../authoring/codemod/type").CodemodRunResult["declinedCandidates"]>;
209
240
  errors: Array<{
210
241
  file: string;
211
242
  codemod: string;
@@ -301,6 +332,7 @@ export function runIntegrationCodemodsStep(versionGroups: Array<{
301
332
  writtenFiles: string[];
302
333
  stagedContents: Map<string, string>;
303
334
  protectedFiles: import("../../authoring/codemod/type").CodemodRunResult["protectedFiles"];
335
+ declinedCandidates: NonNullable<import("../../authoring/codemod/type").CodemodRunResult["declinedCandidates"]>;
304
336
  errors: Array<{
305
337
  file: string;
306
338
  codemod: string;
@@ -347,4 +379,17 @@ export type AgentDocsRefreshPlan = {
347
379
  renderedBlock: string | null;
348
380
  summary: import("./upgrade.type.mjs").AgentDocsSummary;
349
381
  };
382
+ export type CodemodOutcomeRecord = {
383
+ kind: "manual";
384
+ file: string;
385
+ codemod: string;
386
+ message: string;
387
+ line?: number;
388
+ } | {
389
+ kind: "regenerate";
390
+ file: string;
391
+ codemod: string;
392
+ message: string;
393
+ commands: string[];
394
+ };
350
395
  import { inspectAgentDocs } from '../../foundation/agent-docs/agent-docs.mjs';
@@ -24,6 +24,7 @@ import {
24
24
  latestVersion,
25
25
  } from '../../assets/codemods/registry.mjs';
26
26
  import {runCodemods} from '../../assets/codemods/runner.mjs';
27
+ import {codemodOutcome} from '../../assets/codemods/outcome.mjs';
27
28
  import {
28
29
  discoverIntegrationCodemods,
29
30
  selectIntegrationCodemods,
@@ -141,7 +142,12 @@ export function relativeToOrigin(result, {cwd: root, origin}) {
141
142
  };
142
143
  }
143
144
  if (data.modifiedFiles) data.modifiedFiles = data.modifiedFiles.map(rebase);
144
- for (const key of ['protectedFiles', 'declinedCandidates', 'errors']) {
145
+ for (const key of [
146
+ 'protectedFiles',
147
+ 'declinedCandidates',
148
+ 'errors',
149
+ 'regenerate',
150
+ ]) {
145
151
  if (data[key]) {
146
152
  data[key] = data[key].map(
147
153
  (/** @type {{file: string, declarations?: string[]}} */ entry) => ({
@@ -599,11 +605,59 @@ export async function ensureCodemodDeps({installDeps} = {}) {
599
605
  return ensureJscodeshift({installDeps, silent: logger.silent});
600
606
  }
601
607
 
608
+ /**
609
+ * @typedef {{kind: 'manual', file: string, codemod: string, message: string, line?: number} | {kind: 'regenerate', file: string, codemod: string, message: string, commands: string[]}} CodemodOutcomeRecord
610
+ */
611
+
612
+ /**
613
+ * Wrap each core code and config transform so the non-failure outcomes it
614
+ * throws (`assets/codemods/outcome.mjs`) are recorded instead of reaching the
615
+ * runner as errors. The wrapped transform leaves that file unchanged, exactly
616
+ * as the throw did. Project codemods keep their own contract. One wrapper per
617
+ * pass: the regeneration re-check takes a fresh one, so an outcome a hook
618
+ * resolved does not linger.
619
+ *
620
+ * @template {{version: string, transforms: Array<{name: string, transform: any, meta?: {codemodType?: string}}>}} M
621
+ * @param {M[]} versionManifests
622
+ * @param {string} root project root; recorded files are relative to it
623
+ * @returns {{versionManifests: M[], outcomes: CodemodOutcomeRecord[]}}
624
+ */
625
+ export function withCodemodOutcomes(versionManifests, root) {
626
+ /** @type {CodemodOutcomeRecord[]} */
627
+ const outcomes = [];
628
+ const wrapped = versionManifests.map(manifest => ({
629
+ ...manifest,
630
+ transforms: manifest.transforms.map(entry => {
631
+ if (entry.meta?.codemodType === 'project') return entry;
632
+ const {transform, name} = entry;
633
+ return {
634
+ ...entry,
635
+ /** @param {{path: string, source: string}} file @param {unknown} api */
636
+ transform(file, api) {
637
+ try {
638
+ return transform(file, api);
639
+ } catch (err) {
640
+ const outcome = codemodOutcome(err);
641
+ if (!outcome) throw err;
642
+ outcomes.push({
643
+ ...outcome,
644
+ file: path.relative(root, file.path).split(path.sep).join('/'),
645
+ codemod: `core:${name}`,
646
+ });
647
+ return undefined;
648
+ }
649
+ },
650
+ };
651
+ }),
652
+ }));
653
+ return {versionManifests: /** @type {M[]} */ (wrapped), outcomes};
654
+ }
655
+
602
656
  /**
603
657
  * Run the CORE registry codemods. Runs BEFORE the config is loaded so a core
604
658
  * CONFIG codemod can repair a config the strict loader would otherwise reject.
605
659
  * @param {CoreVersionManifest[]} versionManifests
606
- * @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean}} options
660
+ * @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean, outcomes?: CodemodOutcomeRecord[]}} options
607
661
  */
608
662
  export async function runCoreCodemods(
609
663
  versionManifests,
@@ -616,6 +670,7 @@ export async function runCoreCodemods(
616
670
  protection,
617
671
  silent,
618
672
  coversTarget,
673
+ outcomes,
619
674
  },
620
675
  ) {
621
676
  return runCodemods(versionManifests, {
@@ -627,6 +682,7 @@ export async function runCoreCodemods(
627
682
  root,
628
683
  protection,
629
684
  coversTarget,
685
+ outcomes,
630
686
  });
631
687
  }
632
688