@astryxdesign/cli 0.7.15 → 0.7.16-canary.g22213fd

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 (222) hide show
  1. package/README.md +6 -4
  2. package/api/build/_adapter.d.mts +10 -0
  3. package/api/build/_adapter.mjs +24 -0
  4. package/api/build/blocks/blocks.d.mts +1 -0
  5. package/api/build/blocks/blocks.mjs +18 -1
  6. package/api/build/kit/shell.weights.json +1 -0
  7. package/api/build/kit/shellcall.d.mts +26 -0
  8. package/api/build/kit/shellcall.mjs +87 -0
  9. package/api/build/kit/start.mjs +67 -4
  10. package/api/build/kit/weights.d.mts +15 -0
  11. package/api/build/kit/weights.mjs +27 -0
  12. package/api/component/__fixtures__/resolutions/modules.txt +1 -1
  13. package/api/component/_adapter.d.mts +1 -1
  14. package/api/component/_adapter.mjs +28 -1
  15. package/api/doctor/_adapter.d.mts +38 -2
  16. package/api/doctor/_adapter.mjs +76 -1
  17. package/api/doctor/built-checks.mjs +1 -1
  18. package/api/doctor/doctor.d.mts +26 -0
  19. package/api/doctor/doctor.doc.mjs +1 -1
  20. package/api/doctor/doctor.mjs +156 -11
  21. package/api/doctor/theme-checks.mjs +163 -18
  22. package/api/icon/_adapter.d.mts +7 -3
  23. package/api/icon/_adapter.mjs +12 -3
  24. package/api/icon/icon.type.d.mts +15 -0
  25. package/api/icon/icon.type.mjs +10 -3
  26. package/api/icon/iconUse.doc.mjs +19 -5
  27. package/api/icon/list/list.mjs +7 -1
  28. package/api/icon/use/use.d.mts +8 -5
  29. package/api/icon/use/use.mjs +95 -13
  30. package/api/init/run/run.mjs +1 -0
  31. package/api/integration/add-contribution.mjs +3 -3
  32. package/api/integration/pack-check.mjs +14 -8
  33. package/api/integration/validate-integration.mjs +1 -1
  34. package/api/search/_adapter.mjs +15 -16
  35. package/api/search/_entries.d.mts +2 -1
  36. package/api/search/_entries.mjs +28 -1
  37. package/api/swizzle/_moduleGraph.mjs +1 -1
  38. package/api/template/template.type.d.mts +6 -2
  39. package/api/template/template.type.mjs +2 -1
  40. package/api/theme/_adapter.d.mts +5 -2
  41. package/api/theme/_adapter.mjs +59 -14
  42. package/api/theme/_fork.mjs +1 -1
  43. package/api/theme/build/build.d.mts +120 -32
  44. package/api/theme/build/build.mjs +471 -111
  45. package/api/theme/eject/eject.mjs +22 -1
  46. package/api/theme/generateTonalPalette.doc.mjs +2 -2
  47. package/api/theme/palette/generate/generator.mjs +141 -2
  48. package/api/theme/template/template.d.mts +19 -0
  49. package/api/theme/template/template.mjs +102 -25
  50. package/api/theme/theme.type.d.mts +44 -1
  51. package/api/theme/theme.type.mjs +23 -1
  52. package/api/theme/themeBuild.doc.mjs +4 -4
  53. package/api/theme/themeEject.doc.mjs +1 -1
  54. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  55. package/api/theme/themeTemplate.doc.mjs +9 -3
  56. package/api/theme-edit/_adapter.d.mts +33 -2
  57. package/api/theme-edit/_adapter.mjs +276 -41
  58. package/api/theme-edit/_check.d.mts +93 -4
  59. package/api/theme-edit/_check.mjs +1712 -223
  60. package/api/theme-edit/_color.d.mts +2 -8
  61. package/api/theme-edit/_color.mjs +292 -219
  62. package/api/theme-edit/_compiler.d.mts +1 -0
  63. package/api/theme-edit/_compiler.mjs +20 -1
  64. package/api/theme-edit/_context.d.mts +31 -1
  65. package/api/theme-edit/_context.mjs +445 -41
  66. package/api/theme-edit/_css.d.mts +60 -1
  67. package/api/theme-edit/_css.mjs +404 -28
  68. package/api/theme-edit/_edit.d.mts +25 -0
  69. package/api/theme-edit/_edit.mjs +1620 -154
  70. package/api/theme-edit/_how-commands.d.mts +11 -26
  71. package/api/theme-edit/_how-commands.mjs +30 -2
  72. package/api/theme-edit/_how-question.d.mts +15 -0
  73. package/api/theme-edit/_how-question.mjs +1469 -194
  74. package/api/theme-edit/_how.mjs +144 -30
  75. package/api/theme-edit/_marks.d.mts +13 -0
  76. package/api/theme-edit/_marks.mjs +15 -0
  77. package/api/theme-edit/_overview.mjs +2 -0
  78. package/api/theme-edit/_palette.d.mts +38 -0
  79. package/api/theme-edit/_palette.mjs +306 -73
  80. package/api/theme-edit/_parts.d.mts +33 -0
  81. package/api/theme-edit/_parts.mjs +138 -9
  82. package/api/theme-edit/_png.d.mts +18 -0
  83. package/api/theme-edit/_png.mjs +95 -14
  84. package/api/theme-edit/_preview-app.d.mts +55 -1
  85. package/api/theme-edit/_preview-app.mjs +1552 -101
  86. package/api/theme-edit/_preview.d.mts +71 -3
  87. package/api/theme-edit/_preview.mjs +565 -35
  88. package/api/theme-edit/_project.d.mts +15 -0
  89. package/api/theme-edit/_project.mjs +68 -13
  90. package/api/theme-edit/_settings.d.mts +299 -5
  91. package/api/theme-edit/_settings.mjs +2806 -158
  92. package/api/theme-edit/_tables.d.mts +24 -0
  93. package/api/theme-edit/_tables.mjs +212 -150
  94. package/api/theme-edit/_vet.d.mts +42 -0
  95. package/api/theme-edit/_vet.mjs +144 -0
  96. package/api/theme-edit/theme-edit.type.d.mts +31 -2
  97. package/api/theme-edit/theme-edit.type.mjs +10 -2
  98. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  99. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  100. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  101. package/api/upgrade/registry/registry.mjs +6 -1
  102. package/assets/codemods/parse.mjs +2 -2
  103. package/assets/docs/author-a-theme.doc.mjs +1 -1
  104. package/assets/docs/theme.doc.dense.mjs +1 -1
  105. package/assets/docs/theme.doc.mjs +1 -1
  106. package/assets/docs/theme.doc.zh.mjs +4 -3
  107. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  108. package/assets/docs/tree/icon-sets.doc.mjs +63 -8
  109. package/assets/docs/tree/single-component.doc.mjs +11 -2
  110. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  111. package/assets/docs.generated.json +2 -2
  112. package/assets/preview-app/next.config.mjs +7 -1
  113. package/assets/preview-app/package.json +1 -0
  114. package/assets/preview-app/src/app/globals.css +1 -0
  115. package/assets/self-audit.generated.json +1 -1
  116. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
  117. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
  118. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  119. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  120. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  121. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  122. package/assets/templates/components.generated.json +1 -1
  123. package/assets/templates/pages/ai-chat/page.tsx +20 -2
  124. package/assets/templates/pages/dashboard/page.tsx +1 -1
  125. package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
  126. package/authoring/config/config.doc.mjs +8 -0
  127. package/authoring/config/parse.d.mts +1 -0
  128. package/authoring/config/parse.mjs +12 -0
  129. package/authoring/config/type.ts +8 -0
  130. package/authoring/doctypes/_schema.d.mts +52 -5
  131. package/authoring/doctypes/_schema.mjs +62 -7
  132. package/authoring/doctypes/base/type.ts +10 -0
  133. package/authoring/doctypes/component/component.doc.mjs +1 -1
  134. package/authoring/doctypes/function/function.doc.mjs +6 -0
  135. package/authoring/doctypes/function/type.ts +3 -0
  136. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
  137. package/authoring/doctypes/legacy.mjs +5 -1
  138. package/authoring/index.d.ts +1 -0
  139. package/authoring/shadcn/source-variants.d.mts +1 -1
  140. package/authoring/shadcn/source-variants.mjs +32 -10
  141. package/clients/cli/build-id.generated.json +1 -1
  142. package/clients/cli/commands/doctor.doc.mjs +2 -2
  143. package/clients/cli/commands/experimental/icon.mjs +61 -6
  144. package/clients/cli/commands/experimental/theme.mjs +244 -45
  145. package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
  146. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  147. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  148. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  149. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
  150. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  151. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  152. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  153. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  154. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  155. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  156. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  157. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  158. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  159. package/clients/cli/commands/theme.doc.mjs +7 -2
  160. package/clients/cli/commands/theme.mjs +222 -55
  161. package/clients/cli/commands.generated.json +1 -1
  162. package/clients/cli/formatters/index.mjs +7 -4
  163. package/clients/cli/index.mjs +25 -5
  164. package/clients/cli/lib/cli-error.mjs +9 -3
  165. package/clients/cli/lib/component-format.mjs +27 -9
  166. package/clients/cli/lib/json-shim.mjs +72 -2
  167. package/clients/cli/manifest.generated.json +1 -1
  168. package/clients/cli/run.mjs +49 -0
  169. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  170. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  171. package/foundation/agent-docs/agent-docs.mjs +4 -3
  172. package/foundation/config/config-writer.d.mts +23 -0
  173. package/foundation/config/config-writer.mjs +152 -58
  174. package/foundation/config/project.mjs +103 -16
  175. package/foundation/discovery/component-discovery.mjs +11 -22
  176. package/foundation/discovery/icon-set-checks.mjs +164 -48
  177. package/foundation/discovery/icon-set-discovery.d.mts +38 -5
  178. package/foundation/discovery/icon-set-discovery.mjs +50 -6
  179. package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
  180. package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
  181. package/foundation/discovery/icon-set-writer.d.mts +2 -3
  182. package/foundation/discovery/icon-set-writer.mjs +58 -17
  183. package/foundation/discovery/module-exports.mjs +1 -15
  184. package/foundation/discovery/template-adapter.mjs +44 -19
  185. package/foundation/discovery/template-icons.d.mts +27 -10
  186. package/foundation/discovery/template-icons.mjs +142 -26
  187. package/foundation/discovery/template-source-tree.mjs +3 -16
  188. package/foundation/discovery/theme-discovery.d.mts +30 -1
  189. package/foundation/discovery/theme-discovery.mjs +109 -50
  190. package/foundation/fs/exact-codec.d.mts +35 -0
  191. package/foundation/fs/exact-codec.mjs +148 -0
  192. package/foundation/fs/gather-cache.d.mts +15 -5
  193. package/foundation/fs/gather-cache.mjs +129 -31
  194. package/foundation/fs/paths.d.mts +39 -0
  195. package/foundation/fs/paths.mjs +44 -11
  196. package/foundation/fs/read-record.mjs +11 -1
  197. package/foundation/integrations/autolink.d.mts +4 -2
  198. package/foundation/integrations/autolink.mjs +4 -2
  199. package/foundation/integrations/cli-requirement.d.mts +16 -5
  200. package/foundation/integrations/cli-requirement.mjs +27 -6
  201. package/foundation/integrations/contribution-fixes.mjs +1 -16
  202. package/foundation/integrations/may-have-integrations.mjs +7 -3
  203. package/foundation/integrations/missing-dependency.d.mts +9 -0
  204. package/foundation/integrations/missing-dependency.mjs +100 -0
  205. package/foundation/integrations/public-imports.mjs +1 -1
  206. package/foundation/render/embedded-imports.mjs +1 -1
  207. package/foundation/render/host-exit.d.mts +8 -0
  208. package/foundation/render/host-exit.mjs +11 -0
  209. package/foundation/render/page-host.mjs +56 -10
  210. package/foundation/render/page-worker.mjs +14 -0
  211. package/foundation/render/render-page.mjs +37 -2
  212. package/foundation/response/error-codes.d.mts +2 -1
  213. package/foundation/response/error-codes.d.ts +1 -0
  214. package/foundation/response/error-codes.doc.mjs +5 -0
  215. package/foundation/response/error-codes.mjs +3 -0
  216. package/foundation/response/json.d.mts +15 -0
  217. package/foundation/response/json.mjs +52 -1
  218. package/foundation/response/response-types.doc.mjs +1 -1
  219. package/foundation/runtime/lazy-dependencies.d.mts +14 -0
  220. package/foundation/runtime/lazy-dependencies.mjs +82 -0
  221. package/foundation/xle/browser.d.mts +2 -2
  222. package/package.json +7 -6
@@ -25,7 +25,7 @@ import * as fs from 'node:fs';
25
25
  import * as path from 'node:path';
26
26
  import {randomUUID} from 'node:crypto';
27
27
  import {AsyncLocalStorage} from 'node:async_hooks';
28
- import {parse} from '@babel/parser';
28
+ import {babelParse as parse} from '../runtime/lazy-dependencies.mjs';
29
29
  import {parseIconSetData} from '../../authoring/doctypes/icon-set/parse.mjs';
30
30
  import {ICON_NAMES} from '../../authoring/doctypes/icon-set/icon-names.mjs';
31
31
  import {assertWithin} from '../fs/path-safety.mjs';
@@ -34,6 +34,12 @@ import {loadManifestObject} from '../integrations/integrations.mjs';
34
34
  import {levenshteinDistance} from '../text/string-utils.mjs';
35
35
  import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
36
36
  import {generatedTypesPath} from './icon-set-paths.mjs';
37
+ import {
38
+ lookExport,
39
+ THEME_MAP_NAME,
40
+ variantThemeMapName,
41
+ variantThemeMaps,
42
+ } from './icon-set-theme-maps.mjs';
37
43
 
38
44
  export {generatedTypesPath};
39
45
  import {
@@ -1373,6 +1379,7 @@ const GENERATED_HEADER = [
1373
1379
  '// Edit with those commands; a statement added by hand is kept.',
1374
1380
  '// themeIcons has one entry per built-in icon definition in map (the names Core renders), not one per icon;',
1375
1381
  '// the import lines above it give it local names for the re-exported icons.',
1382
+ '// themeIcons<Variant> draws the same names in that variant, for each variant an icon draws.',
1376
1383
  ];
1377
1384
 
1378
1385
  /**
@@ -1542,8 +1549,7 @@ export function generatedTypesMatch(actual, expected, label) {
1542
1549
  /** The local name the generated module gives the set's adapter. */
1543
1550
  const ADAPTER_LOCAL = 'adaptIcon';
1544
1551
 
1545
- /** The theme map the generated module writes. */
1546
- export const THEME_MAP_NAME = 'themeIcons';
1552
+ export {THEME_MAP_NAME};
1547
1553
 
1548
1554
  /** How the generated module imports React for its theme map. */
1549
1555
  const REACT_IMPORT = "import {createElement} from 'react'";
@@ -1620,7 +1626,8 @@ export function generatedTypesText(statements) {
1620
1626
  const theme = /^export const (\w+) = \{(.*)\}$/u.exec(statement);
1621
1627
  if (
1622
1628
  theme &&
1623
- (theme[1] === THEME_MAP_NAME || statement.includes('createElement('))
1629
+ (theme[1].startsWith(THEME_MAP_NAME) ||
1630
+ statement.includes('createElement('))
1624
1631
  ) {
1625
1632
  react.add('ReactElement');
1626
1633
  const keys = [...theme[2].matchAll(/(\w+): createElement\(/gu)].map(
@@ -1687,6 +1694,14 @@ export function generatedModuleText(
1687
1694
  return relative.startsWith('.') ? relative : `./${relative}`;
1688
1695
  };
1689
1696
  const themeName = data.themeMap === THEME_MAP_NAME ? THEME_MAP_NAME : null;
1697
+ // Every theme map the module may hold, one per declared look, so a look's
1698
+ // map no icon draws any more is dropped as well.
1699
+ const themeNames = [
1700
+ THEME_MAP_NAME,
1701
+ ...(data.variants ?? [])
1702
+ .filter(variant => variant !== data.default?.variant)
1703
+ .map(variantThemeMapName),
1704
+ ];
1690
1705
  const lines = before == null ? [] : generatedStatements(before, generated);
1691
1706
  const lineSet = new Set(lines);
1692
1707
  // Written once, below: the adapter's import, React's createElement, and
@@ -1712,7 +1727,8 @@ export function generatedModuleText(
1712
1727
  return (
1713
1728
  line === REACT_IMPORT ||
1714
1729
  themeImport(line) ||
1715
- (themeName != null && line.startsWith(`export const ${themeName} = `))
1730
+ (themeName != null &&
1731
+ themeNames.some(name => line.startsWith(`export const ${name} = `)))
1716
1732
  );
1717
1733
  };
1718
1734
  const imports = new Set(
@@ -1777,22 +1793,42 @@ export function generatedModuleText(
1777
1793
  }
1778
1794
  /** @type {string[]} */
1779
1795
  const theme = [];
1796
+ /** @type {Array<{name: string, entries: string[]}>} */
1797
+ const looks = themeName
1798
+ ? variantThemeMaps({...data, generated}).map(({name}) => ({
1799
+ name,
1800
+ entries: [],
1801
+ }))
1802
+ : [];
1780
1803
  /** @type {Set<string>} */
1781
1804
  const themeImports = new Set();
1805
+ /**
1806
+ * A theme-map entry for one built-in definition, and the import that
1807
+ * gives a re-exported icon its local name.
1808
+ * @param {string} name
1809
+ * @param {string} exportName
1810
+ */
1811
+ const themeEntry = (name, exportName) => {
1812
+ const line = exported.get(exportName);
1813
+ const reexport =
1814
+ line != null && line.startsWith('export {') ? line : undefined;
1815
+ if (reexport) {
1816
+ themeImports.add(`import${reexport.slice('export'.length)}`);
1817
+ }
1818
+ return ` ${name}: createElement(${exportName}, ${THEME_ELEMENT_PROPS}),`;
1819
+ };
1782
1820
  if (themeName) {
1783
- const byId = new Map(data.icons.map(icon => [icon.id, icon.export]));
1821
+ const byId = new Map(data.icons.map(icon => [icon.id, icon]));
1822
+ const lookVariants = variantThemeMaps({...data, generated});
1784
1823
  for (const name of Object.keys(data.map ?? {}).sort()) {
1785
- const exportName = byId.get(/** @type {string} */ (data.map?.[name]));
1786
- if (BUILT_IN.has(name) && exportName) {
1787
- theme.push(
1788
- ` ${name}: createElement(${exportName}, ${THEME_ELEMENT_PROPS}),`,
1789
- );
1790
- const line = exported.get(exportName);
1791
- const reexport =
1792
- line != null && line.startsWith('export {') ? line : undefined;
1793
- if (reexport) {
1794
- themeImports.add(`import${reexport.slice('export'.length)}`);
1795
- }
1824
+ const icon = byId.get(/** @type {string} */ (data.map?.[name]));
1825
+ if (BUILT_IN.has(name) && icon) {
1826
+ theme.push(themeEntry(name, icon.export));
1827
+ lookVariants.forEach(({variant}, index) => {
1828
+ looks[index].entries.push(
1829
+ themeEntry(name, lookExport(icon, variant)),
1830
+ );
1831
+ });
1796
1832
  }
1797
1833
  }
1798
1834
  }
@@ -1815,6 +1851,11 @@ export function generatedModuleText(
1815
1851
  ? [`export const ${themeName} = {`, ...theme, '};']
1816
1852
  : [`export const ${themeName} = {};`]
1817
1853
  : []),
1854
+ ...looks.flatMap(({name, entries}) =>
1855
+ entries.length > 0
1856
+ ? [`export const ${name} = {`, ...entries, '};']
1857
+ : [`export const ${name} = {};`],
1858
+ ),
1818
1859
  '',
1819
1860
  ].join('\n');
1820
1861
  const typesPath = generatedTypesPath(generated);
@@ -19,9 +19,9 @@
19
19
 
20
20
  import * as fs from 'node:fs';
21
21
  import * as path from 'node:path';
22
- import {createRequire} from 'node:module';
23
22
  import {findInstalledPackage} from '../fs/paths.mjs';
24
23
  import {inspectPackageExport} from './package-exports.mjs';
24
+ import {babelParser} from '../runtime/lazy-dependencies.mjs';
25
25
 
26
26
  const MODULE_EXTENSIONS = [
27
27
  '.mjs',
@@ -103,20 +103,6 @@ function moduleText(file) {
103
103
  return text;
104
104
  }
105
105
 
106
- const requireFromHere = createRequire(import.meta.url);
107
- /** @type {typeof import('@babel/parser') | undefined} */
108
- let parser;
109
-
110
- /**
111
- * @babel/parser, loaded on first use: a run that reads no module's exports
112
- * never loads it.
113
- * @returns {typeof import('@babel/parser')}
114
- */
115
- function babelParser() {
116
- parser ??= requireFromHere('@babel/parser');
117
- return /** @type {typeof import('@babel/parser')} */ (parser);
118
- }
119
-
120
106
  /** @param {string} file */
121
107
  function parseModule(file) {
122
108
  const stamp = fileStamp(file);
@@ -24,11 +24,10 @@
24
24
 
25
25
  import * as fs from 'node:fs';
26
26
  import * as path from 'node:path';
27
- import {createRequire} from 'node:module';
28
27
  import {readDocView} from '../doc-compiler/read.mjs';
29
28
  import {importDocModule} from '../doc-compiler/import.mjs';
30
29
  import {readStore, storedKey} from '../doc-compiler/stored-docs.mjs';
31
- import {CLI_ROOT, discoverExternalPackages} from '../fs/paths.mjs';
30
+ import {CLI_ROOT, discoverExternalPackages, realDir} from '../fs/paths.mjs';
32
31
  import {listDirEntries} from '../fs/listing-cache.mjs';
33
32
  import {CORE_PROVIDER_ID} from '../identity/providers.mjs';
34
33
  import {Project} from '../config/project.mjs';
@@ -40,8 +39,10 @@ import {
40
39
  writtenNames,
41
40
  TEMPLATE_COMPONENTS_FILE,
42
41
  } from './template-source-tree.mjs';
43
-
44
- const require = createRequire(import.meta.url);
42
+ import {persistedGather} from '../fs/gather-cache.mjs';
43
+ import {EXACT_CODEC} from '../fs/exact-codec.mjs';
44
+ import {hostedRun} from '../runtime/package-root.mjs';
45
+ import {babelParser} from '../runtime/lazy-dependencies.mjs';
45
46
 
46
47
  /** Identity used for core (built-in) templates in package-scoped listings. */
47
48
  const CORE_PACKAGE = CORE_PROVIDER_ID;
@@ -1070,19 +1071,6 @@ function expressionUse(source, open, close) {
1070
1071
  return null;
1071
1072
  }
1072
1073
 
1073
- /** @type {typeof import('@babel/parser') | undefined} */
1074
- let babelParser;
1075
-
1076
- /**
1077
- * The template source parser, loaded on first use so listing templates
1078
- * never pays for it.
1079
- * @returns {typeof import('@babel/parser')}
1080
- */
1081
- function templateSourceParser() {
1082
- babelParser ??= require('@babel/parser');
1083
- return /** @type {typeof import('@babel/parser')} */ (babelParser);
1084
- }
1085
-
1086
1074
  /**
1087
1075
  * The [start, end) range of every comment in `source`, or none when it does
1088
1076
  * not parse as TSX.
@@ -1091,7 +1079,7 @@ function templateSourceParser() {
1091
1079
  */
1092
1080
  function commentRanges(source) {
1093
1081
  try {
1094
- const {comments} = templateSourceParser().parse(source, {
1082
+ const {comments} = babelParser().parse(source, {
1095
1083
  sourceType: 'module',
1096
1084
  plugins: ['jsx', 'typescript'],
1097
1085
  });
@@ -1569,6 +1557,18 @@ export async function discoverAllUnresolved(cwd = process.cwd()) {
1569
1557
  );
1570
1558
  }
1571
1559
 
1560
+ /** Template discovery's records, kept exactly, with the shape they need. */
1561
+ const TEMPLATE_SOURCES_CODEC = {
1562
+ ...EXACT_CODEC,
1563
+ valid: (/** @type {any} */ value) =>
1564
+ value != null &&
1565
+ Array.isArray(value.templates) &&
1566
+ Array.isArray(value.errors) &&
1567
+ value.templates.every(
1568
+ (/** @type {any} */ t) => t != null && typeof t.name === 'string',
1569
+ ),
1570
+ };
1571
+
1572
1572
  /**
1573
1573
  * Resolve replacement declarations while retaining package-addressable entries
1574
1574
  * that are shadowed or rejected in the default discovery view.
@@ -1576,6 +1576,31 @@ export async function discoverAllUnresolved(cwd = process.cwd()) {
1576
1576
  * @returns {Promise<{templates: DiscoveredTemplate[], errors: Array<TemplateDiscoveryError | TemplateReplacementError>}>}
1577
1577
  */
1578
1578
  async function resolveAllSources(cwd = process.cwd()) {
1579
+ // A function of the files discovery reads, which the kept gather stamps:
1580
+ // a later run with every one unchanged reads the records back.
1581
+ return /** @type {Awaited<ReturnType<typeof resolveAllSourcesNow>>} */ (
1582
+ await persistedGather(
1583
+ // The folder, and the copy of the CLI that answers with the
1584
+ // integrations a host approves: outside a project the integrations
1585
+ // beside the answering copy load too.
1586
+ [
1587
+ 'template-sources',
1588
+ realDir(cwd),
1589
+ CLI_ROOT,
1590
+ hostedRun()?.integrations ?? [],
1591
+ ],
1592
+ () => resolveAllSourcesNow(cwd),
1593
+ TEMPLATE_SOURCES_CODEC,
1594
+ )
1595
+ );
1596
+ }
1597
+
1598
+ /**
1599
+ * resolveAllSources, worked out now.
1600
+ * @param {string} cwd
1601
+ * @returns {Promise<{templates: DiscoveredTemplate[], errors: Array<TemplateDiscoveryError | TemplateReplacementError>}>}
1602
+ */
1603
+ async function resolveAllSourcesNow(cwd) {
1579
1604
  const discovered = await discoverAllSources(cwd);
1580
1605
  const replacementErrors = discovered.errors.filter(
1581
1606
  error => error.replacementTarget != null,
@@ -2079,7 +2104,7 @@ function topLevelBindings(src) {
2079
2104
  const astryxImports = new Map();
2080
2105
  let program;
2081
2106
  try {
2082
- program = templateSourceParser().parse(src, {
2107
+ program = babelParser().parse(src, {
2083
2108
  sourceType: 'module',
2084
2109
  plugins: ['jsx', 'typescript'],
2085
2110
  errorRecovery: true,
@@ -35,12 +35,16 @@ export function placeholderUses(source: string): Array<{
35
35
  meanings: string[] | null;
36
36
  }> | null;
37
37
  /**
38
- * The commands that give a placeholder icon a real one.
38
+ * The commands that give a placeholder icon a real one. The `use` command
39
+ * keeps the list's backups and the project's look, and adds a backup after
40
+ * them.
39
41
  * @param {string[]} definitions
40
42
  * @param {string} main the main set's name as the list writes it
43
+ * @param {readonly string[]} [backups] the list's backups as it writes them
44
+ * @param {string | null} [variant] the project's look
41
45
  * @returns {string[]}
42
46
  */
43
- export function placeholderFixes(definitions: string[], main: string): string[];
47
+ export function placeholderFixes(definitions: string[], main: string, backups?: readonly string[], variant?: string | null): string[];
44
48
  /**
45
49
  * The target-set icon whose reviewed `matches` name the source icon with one
46
50
  * of `confidences`, ties broken by the order the confidences are given and
@@ -177,13 +181,16 @@ export function mapTemplateIcons(source: string, { sets, choice }: {
177
181
  * @property {string[]} [dropped] the library's sizing props (`size`,
178
182
  * `strokeWidth`, `absoluteStrokeWidth`) removed from its elements: an icon
179
183
  * set's icons take their size from CSS
180
- * @property {'match' | 'definition'} by `match`: a reviewed
184
+ * @property {'match' | 'definition' | 'variant'} by `match`: a reviewed
181
185
  * `exact` or `strong` match in the project set's data names the source
182
186
  * icon; `definition`: the target's `map` names it for the Astryx icon
183
- * definition the source draws
187
+ * definition the source draws; `variant`: the source is already this icon
188
+ * of a set in the project's list, in another look, and moves to the look
189
+ * the project names
184
190
  * @property {{asked: string, used: string | null}} [variant] present when the
185
- * source draws a look the target set's icon does not have: the look it
186
- * asked for, and the look used (the set's default look)
191
+ * look asked for, the project's variant or else the look the source draws,
192
+ * is one the target set's icon does not have: that look, and the look used
193
+ * (the set's default look)
187
194
  */
188
195
  /**
189
196
  * One icon no set in the project's list has: each of its uses in the copied
@@ -227,6 +234,8 @@ export function mapTemplateIcons(source: string, { sets, choice }: {
227
234
  * @property {string[]} [order] the main set and each backup, as
228
235
  * `<package>/<set>`, in the order icons are looked up; present when the
229
236
  * project lists backups
237
+ * @property {string} [variant] the look the project's icons draw, as
238
+ * `experimental.iconVariant` names it; present when it is set
230
239
  * @property {string} reason
231
240
  * @property {MappedIcon[]} mapped
232
241
  * @property {PlaceholderIcon[]} placeholder
@@ -297,13 +306,16 @@ export type MappedIcon = {
297
306
  * `match`: a reviewed
298
307
  * `exact` or `strong` match in the project set's data names the source
299
308
  * icon; `definition`: the target's `map` names it for the Astryx icon
300
- * definition the source draws
309
+ * definition the source draws; `variant`: the source is already this icon
310
+ * of a set in the project's list, in another look, and moves to the look
311
+ * the project names
301
312
  */
302
- by: "match" | "definition";
313
+ by: "match" | "definition" | "variant";
303
314
  /**
304
315
  * present when the
305
- * source draws a look the target set's icon does not have: the look it
306
- * asked for, and the look used (the set's default look)
316
+ * look asked for, the project's variant or else the look the source draws,
317
+ * is one the target set's icon does not have: that look, and the look used
318
+ * (the set's default look)
307
319
  */
308
320
  variant?: {
309
321
  asked: string;
@@ -410,6 +422,11 @@ export type TemplateIconsReport = {
410
422
  * project lists backups
411
423
  */
412
424
  order?: string[] | undefined;
425
+ /**
426
+ * the look the project's icons draw, as
427
+ * `experimental.iconVariant` names it; present when it is set
428
+ */
429
+ variant?: string | undefined;
413
430
  reason: string;
414
431
  mapped: MappedIcon[];
415
432
  placeholder: PlaceholderIcon[];