@astryxdesign/cli 0.7.4 → 0.7.5-canary.1093026

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 (208) hide show
  1. package/README.md +18 -18
  2. package/api/discover/_adapter.d.mts +1 -1
  3. package/api/experimental.d.mts +5 -0
  4. package/api/experimental.mjs +15 -0
  5. package/api/hook/list/list.d.mts +1 -1
  6. package/api/icon/_adapter.d.mts +3 -2
  7. package/api/icon/_adapter.mjs +16 -3
  8. package/api/icon/_authoring.d.mts +5 -1
  9. package/api/icon/_authoring.mjs +478 -63
  10. package/api/icon/_options.d.mts +11 -0
  11. package/api/icon/_options.mjs +39 -4
  12. package/api/icon/_records.d.mts +19 -0
  13. package/api/icon/_records.mjs +25 -0
  14. package/api/icon/add/add.d.mts +3 -3
  15. package/api/icon/add/add.mjs +227 -14
  16. package/api/icon/all-or-nothing.test.mjs +283 -0
  17. package/api/icon/detail/detail.mjs +2 -13
  18. package/api/icon/error-codes.test.mjs +14 -7
  19. package/api/icon/icon.d.mts +2 -2
  20. package/api/icon/icon.doc.mjs +30 -2
  21. package/api/icon/icon.mjs +57 -8
  22. package/api/icon/icon.test.mjs +133 -1
  23. package/api/icon/icon.type.d.mts +126 -1
  24. package/api/icon/icon.type.mjs +67 -3
  25. package/api/icon/iconAdd.doc.mjs +22 -6
  26. package/api/icon/iconMap.doc.mjs +24 -8
  27. package/api/icon/iconNewDefinition.doc.mjs +2 -2
  28. package/api/icon/iconNewSet.doc.mjs +30 -2
  29. package/api/icon/iconUse.doc.mjs +4 -1
  30. package/api/icon/map/map.d.mts +4 -4
  31. package/api/icon/map/map.mjs +134 -9
  32. package/api/icon/new-definition/new-definition.mjs +6 -2
  33. package/api/icon/new-set/new-set.mjs +2 -2
  34. package/api/icon/new-set/new-set.test.mjs +60 -10
  35. package/api/icon/option-pairs.test.mjs +368 -0
  36. package/api/icon/search/search.d.mts +10 -0
  37. package/api/icon/search/search.mjs +55 -14
  38. package/api/icon/use/use.mjs +2 -13
  39. package/api/integration/add-helpers.d.mts +15 -1
  40. package/api/integration/add-helpers.mjs +1 -1
  41. package/api/integration/validate-integration.type.d.mts +3 -2
  42. package/api/integration/validate-integration.type.mjs +3 -2
  43. package/api/render/_adapter.d.mts +28 -0
  44. package/api/render/_adapter.mjs +540 -0
  45. package/api/render/render.d.mts +15 -0
  46. package/api/render/render.doc.d.mts +9 -0
  47. package/api/render/render.doc.mjs +112 -0
  48. package/api/render/render.mjs +113 -0
  49. package/api/render/render.test.mjs +1155 -0
  50. package/api/render/render.type.d.mts +74 -0
  51. package/api/render/render.type.mjs +64 -0
  52. package/api/search/_result.d.mts +5 -5
  53. package/api/search/search.d.mts +1 -1
  54. package/api/template/template.type.d.mts +2 -1
  55. package/api/template/template.type.mjs +1 -1
  56. package/assets/discover/official-packages.json +4 -0
  57. package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
  58. package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
  59. package/assets/docs/tree/icon-sets.doc.mjs +50 -20
  60. package/assets/docs/tree/render-pages.doc.mjs +94 -0
  61. package/assets/icons/definitions/activity.doc.mjs +1 -1
  62. package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
  63. package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
  64. package/assets/icons/definitions/alignStart.doc.mjs +10 -0
  65. package/assets/icons/definitions/archive.doc.mjs +1 -1
  66. package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
  67. package/assets/icons/definitions/attach.doc.mjs +1 -1
  68. package/assets/icons/definitions/audio.doc.mjs +1 -1
  69. package/assets/icons/definitions/cart.doc.mjs +1 -1
  70. package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
  71. package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
  72. package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
  73. package/assets/icons/definitions/close.doc.mjs +1 -1
  74. package/assets/icons/definitions/collapse.doc.mjs +1 -1
  75. package/assets/icons/definitions/compose.doc.mjs +1 -1
  76. package/assets/icons/definitions/conversation.doc.mjs +1 -1
  77. package/assets/icons/definitions/copy.doc.mjs +1 -1
  78. package/assets/icons/definitions/cpu.doc.mjs +9 -0
  79. package/assets/icons/definitions/database.doc.mjs +1 -1
  80. package/assets/icons/definitions/desktop.doc.mjs +1 -1
  81. package/assets/icons/definitions/discount.doc.mjs +1 -1
  82. package/assets/icons/definitions/download.doc.mjs +1 -1
  83. package/assets/icons/definitions/emoji.doc.mjs +1 -1
  84. package/assets/icons/definitions/error.doc.mjs +1 -1
  85. package/assets/icons/definitions/expand.doc.mjs +1 -1
  86. package/assets/icons/definitions/experiment.doc.mjs +1 -1
  87. package/assets/icons/definitions/externalLink.doc.mjs +7 -1
  88. package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
  89. package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
  90. package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
  91. package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
  92. package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
  93. package/assets/icons/definitions/gitFork.doc.mjs +9 -0
  94. package/assets/icons/definitions/info.doc.mjs +1 -1
  95. package/assets/icons/definitions/location.doc.mjs +1 -1
  96. package/assets/icons/definitions/mention.doc.mjs +1 -1
  97. package/assets/icons/definitions/menu.doc.mjs +1 -1
  98. package/assets/icons/definitions/microphone.doc.mjs +1 -1
  99. package/assets/icons/definitions/mobile.doc.mjs +1 -1
  100. package/assets/icons/definitions/money.doc.mjs +1 -1
  101. package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
  102. package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
  103. package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
  104. package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
  105. package/assets/icons/definitions/panelRight.doc.mjs +10 -0
  106. package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
  107. package/assets/icons/definitions/redo.doc.mjs +1 -1
  108. package/assets/icons/definitions/refresh.doc.mjs +1 -1
  109. package/assets/icons/definitions/rotate.doc.mjs +9 -0
  110. package/assets/icons/definitions/scale.doc.mjs +10 -0
  111. package/assets/icons/definitions/search.doc.mjs +1 -1
  112. package/assets/icons/definitions/send.doc.mjs +1 -1
  113. package/assets/icons/definitions/settings.doc.mjs +1 -1
  114. package/assets/icons/definitions/star.doc.mjs +1 -1
  115. package/assets/icons/definitions/stop.doc.mjs +1 -1
  116. package/assets/icons/definitions/success.doc.mjs +1 -1
  117. package/assets/icons/definitions/textCase.doc.mjs +9 -0
  118. package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
  119. package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
  120. package/assets/icons/definitions/trendDown.doc.mjs +7 -1
  121. package/assets/icons/definitions/trendUp.doc.mjs +1 -1
  122. package/assets/icons/definitions/undo.doc.mjs +1 -1
  123. package/assets/icons/definitions/upload.doc.mjs +1 -1
  124. package/assets/icons/definitions/userAdd.doc.mjs +1 -1
  125. package/assets/icons/definitions/warning.doc.mjs +1 -1
  126. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
  127. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
  128. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
  129. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
  130. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
  131. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
  132. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
  133. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
  134. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
  135. package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
  136. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
  137. package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
  138. package/authoring/debug/parse.d.mts +2 -2
  139. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
  140. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
  141. package/authoring/doctypes/icon-set/parse.d.mts +1 -0
  142. package/authoring/doctypes/icon-set/parse.mjs +1 -0
  143. package/authoring/doctypes/icon-set/type.ts +5 -0
  144. package/authoring/doctypes/template/template.doc.mjs +1 -1
  145. package/authoring/doctypes/template/type.ts +2 -1
  146. package/clients/cli/commands/doctor.mjs +16 -17
  147. package/clients/cli/commands/experimental/icon.mjs +167 -35
  148. package/clients/cli/commands/experimental/index.mjs +2 -0
  149. package/clients/cli/commands/experimental/render.mjs +113 -0
  150. package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
  151. package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
  152. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
  153. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
  154. package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
  155. package/clients/cli/commands/experimental-render.doc.mjs +60 -0
  156. package/clients/cli/commands/experimental.doc.mjs +4 -2
  157. package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
  158. package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
  159. package/clients/cli/commands/icon.test.mjs +1 -1
  160. package/clients/cli/commands/template.mjs +4 -1
  161. package/clients/cli/commands/text-json-parity.test.mjs +46 -0
  162. package/clients/cli/index.mjs +1 -0
  163. package/foundation/discovery/component-discovery.d.mts +2 -1
  164. package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
  165. package/foundation/discovery/component-discovery.mjs +13 -7
  166. package/foundation/discovery/icon-set-checks.d.mts +43 -9
  167. package/foundation/discovery/icon-set-checks.mjs +296 -21
  168. package/foundation/discovery/icon-set-checks.test.mjs +125 -12
  169. package/foundation/discovery/icon-set-writer.d.mts +192 -3
  170. package/foundation/discovery/icon-set-writer.mjs +608 -34
  171. package/foundation/discovery/icon-set-writer.test.mjs +26 -0
  172. package/foundation/discovery/module-exports.mjs +82 -25
  173. package/foundation/discovery/module-exports.test.mjs +38 -1
  174. package/foundation/discovery/package-exports.d.mts +13 -0
  175. package/foundation/discovery/package-exports.mjs +40 -1
  176. package/foundation/discovery/template-icons.d.mts +6 -0
  177. package/foundation/discovery/template-icons.mjs +98 -10
  178. package/foundation/discovery/template-icons.test.mjs +103 -0
  179. package/foundation/doc-compiler/doc-loads.test.mjs +15 -0
  180. package/foundation/doc-compiler/tree.mjs +3 -1
  181. package/foundation/render/assets.d.mts +31 -0
  182. package/foundation/render/assets.mjs +102 -0
  183. package/foundation/render/component-map.d.mts +52 -0
  184. package/foundation/render/component-map.mjs +141 -0
  185. package/foundation/render/css-cut.d.mts +29 -0
  186. package/foundation/render/css-cut.mjs +144 -0
  187. package/foundation/render/embedded-files.d.mts +28 -0
  188. package/foundation/render/embedded-files.mjs +108 -0
  189. package/foundation/render/embedded-imports.d.mts +61 -0
  190. package/foundation/render/embedded-imports.mjs +315 -0
  191. package/foundation/render/html-reader.d.mts +37 -0
  192. package/foundation/render/html-reader.mjs +121 -0
  193. package/foundation/render/page-worker.d.mts +7 -0
  194. package/foundation/render/page-worker.mjs +519 -0
  195. package/foundation/render/rebuild.d.mts +19 -0
  196. package/foundation/render/rebuild.mjs +269 -0
  197. package/foundation/render/render-page.d.mts +85 -0
  198. package/foundation/render/render-page.mjs +612 -0
  199. package/foundation/render/render.test.mjs +117 -0
  200. package/foundation/render/source-block.d.mts +52 -0
  201. package/foundation/render/source-block.mjs +106 -0
  202. package/foundation/response/error-codes.d.mts +10 -1
  203. package/foundation/response/error-codes.doc.mjs +56 -0
  204. package/foundation/response/error-codes.mjs +61 -0
  205. package/foundation/response/response-types.doc.mjs +38 -1
  206. package/foundation/text/string-utils.mjs +33 -0
  207. package/foundation/text/string-utils.test.mjs +17 -0
  208. package/package.json +14 -9
@@ -0,0 +1,26 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @file Icon ids from export names (AST-084): a dimension stays one word. */
4
+
5
+ import {describe, expect, it} from 'vitest';
6
+ import {iconIdOf} from './icon-set-writer.mjs';
7
+
8
+ describe('iconIdOf', () => {
9
+ it.each([
10
+ ['XMarkIcon', 'x-mark'],
11
+ ['Trash2', 'trash-2'],
12
+ ['ArrowUpDown', 'arrow-up-down'],
13
+ ['Squares2X2Icon', 'squares-2x2'],
14
+ ['Grid2x2', 'grid-2x2'],
15
+ ['Grid2X2Check', 'grid-2x2-check'],
16
+ ['Grid3x3', 'grid-3x3'],
17
+ ['Tally5', 'tally-5'],
18
+ ['H1Icon', 'h1'],
19
+ ['Box', 'box'],
20
+ ['CalendarX2', 'calendar-x-2'],
21
+ ['MapPinXInside', 'map-pin-x-inside'],
22
+ ['Heading1', 'heading-1'],
23
+ ])('%s → %s', (name, id) => {
24
+ expect(iconIdOf(name)).toBe(id);
25
+ });
26
+ });
@@ -146,15 +146,44 @@ const NOT_CHILDREN = new Set([
146
146
  ]);
147
147
 
148
148
  /**
149
- * Every node of `type` in the tree, at any depth, in source order.
149
+ * Every node of `type` under each tree walked, by tree and type: a parsed
150
+ * module is cached and never changes, so a library of a thousand icons is
151
+ * walked once per type, not once per export looked up.
152
+ * @type {WeakMap<object, Map<string, readonly any[]>>}
153
+ */
154
+ const nodesByTree = new WeakMap();
155
+
156
+ /**
157
+ * Every node of `type` in the tree, at any depth, in source order. The
158
+ * answer is shared: callers only read it.
159
+ * @param {any} node
160
+ * @param {string} type
161
+ * @returns {readonly any[]}
162
+ */
163
+ function nodesOfType(node, type) {
164
+ if (node == null || typeof node !== 'object') return [];
165
+ let byType = nodesByTree.get(node);
166
+ if (!byType) {
167
+ byType = new Map();
168
+ nodesByTree.set(node, byType);
169
+ }
170
+ let found = byType.get(type);
171
+ if (!found) {
172
+ found = collectNodesOfType(node, type, []);
173
+ byType.set(type, found);
174
+ }
175
+ return found;
176
+ }
177
+
178
+ /**
150
179
  * @param {any} node
151
180
  * @param {string} type
152
- * @param {any[]} [found]
181
+ * @param {any[]} found
153
182
  * @returns {any[]}
154
183
  */
155
- function nodesOfType(node, type, found = []) {
184
+ function collectNodesOfType(node, type, found) {
156
185
  if (Array.isArray(node)) {
157
- for (const child of node) nodesOfType(child, type, found);
186
+ for (const child of node) collectNodesOfType(child, type, found);
158
187
  return found;
159
188
  }
160
189
  if (node == null || typeof node !== 'object') return found;
@@ -163,7 +192,7 @@ function nodesOfType(node, type, found = []) {
163
192
  if (NOT_CHILDREN.has(key)) continue;
164
193
  const child = node[key];
165
194
  if (child != null && typeof child === 'object') {
166
- nodesOfType(child, type, found);
195
+ collectNodesOfType(child, type, found);
167
196
  }
168
197
  }
169
198
  return found;
@@ -890,6 +919,43 @@ export function staticExportObject(file, exportNames) {
890
919
  return null;
891
920
  }
892
921
 
922
+ /**
923
+ * A module's runtime named exports, indexed once per parsed tree: the
924
+ * export declarations that declare something, and each export specifier by
925
+ * the name it exports, in source order.
926
+ * @type {WeakMap<object, {declarations: any[], specifiers: Map<string, Array<{node: any, specifier: any}>>}>}
927
+ */
928
+ const namedExportIndexes = new WeakMap();
929
+
930
+ /** @param {any} program */
931
+ function namedExportIndex(program) {
932
+ const cached = namedExportIndexes.get(program);
933
+ if (cached) return cached;
934
+ /** @type {any[]} */
935
+ const declarations = [];
936
+ /** @type {Map<string, Array<{node: any, specifier: any}>>} */
937
+ const specifiers = new Map();
938
+ for (const node of nodesOfType(program, 'ExportNamedDeclaration')) {
939
+ if (node.exportKind === 'type') continue;
940
+ if (node.declaration) declarations.push(node);
941
+ for (const specifier of node.specifiers ?? []) {
942
+ if (
943
+ specifier.type !== 'ExportSpecifier' ||
944
+ specifier.exportKind === 'type'
945
+ ) {
946
+ continue;
947
+ }
948
+ const exported = specifier.exported?.name ?? specifier.exported?.value;
949
+ const list = specifiers.get(exported) ?? [];
950
+ list.push({node, specifier});
951
+ specifiers.set(exported, list);
952
+ }
953
+ }
954
+ const index = {declarations, specifiers};
955
+ namedExportIndexes.set(program, index);
956
+ return index;
957
+ }
958
+
893
959
  /**
894
960
  * Where a module's runtime export is declared, as the file and the name it
895
961
  * has there, without executing anything: local re-exports, renames, and
@@ -911,30 +977,21 @@ export function moduleExportOrigin(file, exportName, seen = new Set()) {
911
977
  } catch {
912
978
  return null;
913
979
  }
914
- for (const node of nodesOfType(ast.program, 'ExportNamedDeclaration')) {
915
- if (node.exportKind === 'type') continue;
980
+ const {declarations, specifiers} = namedExportIndex(ast.program);
981
+ for (const node of declarations) {
916
982
  if (declarationExports(node.declaration, exportName)) {
917
983
  return {file, name: exportName};
918
984
  }
919
- for (const specifier of node.specifiers ?? []) {
920
- if (
921
- specifier.type !== 'ExportSpecifier' ||
922
- specifier.exportKind === 'type'
923
- ) {
924
- continue;
925
- }
926
- const exported = specifier.exported?.name ?? specifier.exported?.value;
927
- if (exported !== exportName) continue;
928
- const local =
929
- specifier.local?.name ?? specifier.local?.value ?? exportName;
930
- if (node.source) {
931
- const target = resolveModuleOrPackage(node.source.value, file);
932
- const origin = target ? moduleExportOrigin(target, local, seen) : null;
933
- if (origin) return origin;
934
- continue;
935
- }
936
- return bindingOrigin(ast, file, local, seen);
985
+ }
986
+ for (const {node, specifier} of specifiers.get(exportName) ?? []) {
987
+ const local = specifier.local?.name ?? specifier.local?.value ?? exportName;
988
+ if (node.source) {
989
+ const target = resolveModuleOrPackage(node.source.value, file);
990
+ const origin = target ? moduleExportOrigin(target, local, seen) : null;
991
+ if (origin) return origin;
992
+ continue;
937
993
  }
994
+ return bindingOrigin(ast, file, local, seen);
938
995
  }
939
996
  if (exportName === 'default') {
940
997
  for (const node of nodesOfType(ast.program, 'ExportDefaultDeclaration')) {
@@ -9,7 +9,11 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
9
9
  import * as fs from 'node:fs';
10
10
  import * as os from 'node:os';
11
11
  import * as path from 'node:path';
12
- import {moduleExportSource, staticExportObject} from './module-exports.mjs';
12
+ import {
13
+ moduleExportOrigin,
14
+ moduleExportSource,
15
+ staticExportObject,
16
+ } from './module-exports.mjs';
13
17
 
14
18
  /** @type {string} */
15
19
  let dir;
@@ -170,3 +174,36 @@ describe('moduleExportSource', () => {
170
174
  expect(moduleExportSource(file, 'AcmePanel')).toBeNull();
171
175
  });
172
176
  });
177
+
178
+ describe('a library of thousands of icons', () => {
179
+ it('finds the origin of every export in about linear time', () => {
180
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-many-exports-'));
181
+ try {
182
+ const count = 3000;
183
+ fs.writeFileSync(
184
+ path.join(dir, 'icon.js'),
185
+ 'export function make(name) { return function Icon() { return name; }; }\n',
186
+ );
187
+ const lines = ["import {make} from './icon.js';"];
188
+ for (let i = 0; i < count; i++) {
189
+ lines.push(`const Glyph${i} = make('g${i}');`);
190
+ lines.push(
191
+ `export {Glyph${i}, Glyph${i} as Glyph${i}Icon, Glyph${i} as LucideGlyph${i}};`,
192
+ );
193
+ }
194
+ const file = path.join(dir, 'index.js');
195
+ fs.writeFileSync(file, `${lines.join('\n')}\n`);
196
+ const started = Date.now();
197
+ for (let i = 0; i < count; i++) {
198
+ expect(moduleExportOrigin(file, `Glyph${i}Icon`)).toEqual({
199
+ file,
200
+ name: `Glyph${i}`,
201
+ });
202
+ }
203
+ // Walking the whole module once per lookup took minutes.
204
+ expect(Date.now() - started).toBeLessThan(10_000);
205
+ } finally {
206
+ fs.rmSync(dir, {recursive: true, force: true});
207
+ }
208
+ }, 60_000);
209
+ });
@@ -1,6 +1,19 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * The file a subpath's `source` condition names, when that file is in the
6
+ * package. A package that ships its source (or a workspace package before it
7
+ * is built) declares it beside the built target, so reading it answers the
8
+ * same with or without a build. Null when there is no such condition or file.
9
+ * @param {{exports?: unknown}} pkg
10
+ * @param {string} packageDir
11
+ * @param {string} subpath `.` or a `./`-prefixed subpath
12
+ * @returns {string|null}
13
+ */
14
+ export function sourceExportTarget(pkg: {
15
+ exports?: unknown;
16
+ }, packageDir: string, subpath: string): string | null;
4
17
  /**
5
18
  * @typedef {object} PackageExportResult
6
19
  * @property {string} subpath
@@ -8,7 +8,8 @@
8
8
  * their legacy public deep paths and are resolved from files on disk.
9
9
  *
10
10
  * @input Parsed package.json, package directory, and a public subpath
11
- * @output The public specifier and confined target file, when exported
11
+ * @output The public specifier and confined target file, when exported, and
12
+ * the file a subpath's `source` condition names, when the package has it
12
13
  * @position packages/cli/foundation/discovery — shared package import metadata
13
14
  */
14
15
 
@@ -165,6 +166,44 @@ function resolveLegacy(packageDir, subpath) {
165
166
  return candidates.find(regularFile) ?? null;
166
167
  }
167
168
 
169
+ /**
170
+ * The raw export value one subpath maps to, with the wildcard it matched.
171
+ * @param {unknown} exportsField
172
+ * @param {string} subpath
173
+ * @returns {{value: unknown, wildcard: string} | null}
174
+ */
175
+ function rawExportValue(exportsField, subpath) {
176
+ if (exportsField == null) return null;
177
+ if (!isRecord(exportsField)) {
178
+ return subpath === '.' ? {value: exportsField, wildcard: ''} : null;
179
+ }
180
+ if (!Object.keys(exportsField).some(key => key.startsWith('.'))) {
181
+ return subpath === '.' ? {value: exportsField, wildcard: ''} : null;
182
+ }
183
+ const selected = subpathValue(exportsField, subpath);
184
+ return selected.found
185
+ ? {value: selected.value, wildcard: selected.wildcard}
186
+ : null;
187
+ }
188
+
189
+ /**
190
+ * The file a subpath's `source` condition names, when that file is in the
191
+ * package. A package that ships its source (or a workspace package before it
192
+ * is built) declares it beside the built target, so reading it answers the
193
+ * same with or without a build. Null when there is no such condition or file.
194
+ * @param {{exports?: unknown}} pkg
195
+ * @param {string} packageDir
196
+ * @param {string} subpath `.` or a `./`-prefixed subpath
197
+ * @returns {string|null}
198
+ */
199
+ export function sourceExportTarget(pkg, packageDir, subpath) {
200
+ const selected = rawExportValue(pkg.exports, subpath);
201
+ if (!selected || !isRecord(selected.value)) return null;
202
+ const source = selected.value.source;
203
+ if (typeof source !== 'string') return null;
204
+ return resolveTarget(packageDir, source.replaceAll('*', selected.wildcard));
205
+ }
206
+
168
207
  /**
169
208
  * @typedef {object} PackageExportResult
170
209
  * @property {string} subpath
@@ -103,6 +103,12 @@ export type MappedIcon = {
103
103
  module: string;
104
104
  export: string;
105
105
  };
106
+ /**
107
+ * the library's sizing props (`size`,
108
+ * `strokeWidth`, `absoluteStrokeWidth`) removed from its elements: an icon
109
+ * set's icons take their size from CSS
110
+ */
111
+ dropped?: string[] | undefined;
106
112
  /**
107
113
  * `match`: a reviewed
108
114
  * `exact` or `strong` match in the project set's data names the source
@@ -63,6 +63,9 @@ import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
63
63
  * @typedef {object} MappedIcon
64
64
  * @property {{module: string, export: string}} source
65
65
  * @property {{set: string, package: string, id: string, module: string, export: string}} target
66
+ * @property {string[]} [dropped] the library's sizing props (`size`,
67
+ * `strokeWidth`, `absoluteStrokeWidth`) removed from its elements: an icon
68
+ * set's icons take their size from CSS
66
69
  * @property {'match' | 'definition'} by `match`: a reviewed
67
70
  * `exact` or `strong` match in the project set's data names the source
68
71
  * icon; `definition`: the target's `map` names it for the Astryx icon
@@ -390,6 +393,12 @@ export function iconsNotImported(source, declared) {
390
393
  return Object.keys(declared).filter(key => !keys.has(key));
391
394
  }
392
395
 
396
+ /**
397
+ * A library's own sizing props, dropped from a mapped icon: an icon set's
398
+ * icons take their size from CSS.
399
+ */
400
+ const SIZING_PROPS = new Set(['size', 'strokeWidth', 'absoluteStrokeWidth']);
401
+
393
402
  /** What a template reads with no icon-set state given: nothing is mapped. */
394
403
  export const NO_ICON_SETS = Object.freeze({
395
404
  sets: [],
@@ -520,6 +529,10 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
520
529
  let insertAt = -1;
521
530
  /** The declared keys reported as mapped or kept so far. */
522
531
  const accounted = new Set();
532
+ /** The local names of mapped imports, as the template wrote them. */
533
+ const mappedLocals = new Set();
534
+ /** @type {Array<[MappedIcon, string]>} each mapped icon and its local name */
535
+ const mappedEntries = [];
523
536
 
524
537
  for (const node of ast.program.body) {
525
538
  if (node.type !== 'ImportDeclaration') continue;
@@ -582,7 +595,9 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
582
595
  added.set(key, entry);
583
596
  }
584
597
  if (local !== entry.local) renames.set(local, entry.local);
585
- icons.mapped.push({
598
+ mappedLocals.add(local);
599
+ /** @type {MappedIcon} */
600
+ const mappedIcon = {
586
601
  source: {module, export: imported},
587
602
  target: {
588
603
  set: target.name,
@@ -592,30 +607,74 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
592
607
  export: chosen.export,
593
608
  },
594
609
  by: match.by,
595
- });
610
+ };
611
+ icons.mapped.push(mappedIcon);
612
+ mappedEntries.push([mappedIcon, local]);
596
613
  }
597
614
 
598
615
  if (keep.length === node.specifiers.length) continue;
599
616
  if (insertAt === -1) insertAt = node.start;
617
+ // Comments inside the statement, and one that trails it on its line,
618
+ // survive the rewrite: those a kept specifier does not carry move to
619
+ // their own lines above it.
620
+ // A kept specifier carries a comment beside it with only whitespace
621
+ // between (`Pencil /* pen */`).
622
+ const keptRanges = keep.map(each => {
623
+ let [a, b] = [each.start, each.end];
624
+ for (const comment of ast.comments ?? []) {
625
+ if (comment.start < node.start || comment.end > node.end) continue;
626
+ if (comment.start >= b && /^\s*$/u.test(source.slice(b, comment.start)))
627
+ b = comment.end;
628
+ }
629
+ for (const comment of [...(ast.comments ?? [])].reverse()) {
630
+ if (comment.start < node.start || comment.end > node.end) continue;
631
+ if (comment.end <= a && /^\s*$/u.test(source.slice(comment.end, a)))
632
+ a = comment.start;
633
+ }
634
+ return [a, b];
635
+ });
636
+ const inside = (ast.comments ?? []).filter(
637
+ (/** @type {any} */ comment) =>
638
+ comment.start >= node.start &&
639
+ comment.end <= node.end &&
640
+ !keptRanges.some(([a, b]) => comment.start >= a && comment.end <= b),
641
+ );
642
+ const trailing = /^[ \t]*(\/\/[^\n]*|\/\*[^\n]*?\*\/)[ \t]*(?=\n|$)/u.exec(
643
+ source.slice(node.end),
644
+ );
645
+ /** @type {string[]} */
646
+ const moved = inside.map((/** @type {any} */ comment) =>
647
+ source.slice(comment.start, comment.end),
648
+ );
649
+ const above = moved.map(comment => `${comment}\n`).join('');
600
650
  if (keep.length === 0) {
601
651
  let end = node.end;
652
+ if (trailing) {
653
+ moved.push(trailing[1]);
654
+ end += trailing[0].length;
655
+ }
602
656
  if (source[end] === '\n') end += 1;
603
- edits.push({start: node.start, end, text: ''});
657
+ edits.push({
658
+ start: node.start,
659
+ end,
660
+ text: moved.map(comment => `${comment}\n`).join(''),
661
+ });
604
662
  } else {
663
+ /** @param {any} each */
664
+ const textOf = each => {
665
+ const [a, b] = keptRanges[keep.indexOf(each)];
666
+ return source.slice(a, b);
667
+ };
605
668
  const defaults = keep.filter(each => each.type !== 'ImportSpecifier');
606
669
  const named = keep.filter(each => each.type === 'ImportSpecifier');
607
670
  const parts = [
608
- ...defaults.map(each => source.slice(each.start, each.end)),
609
- ...(named.length > 0
610
- ? [
611
- `{${named.map(each => source.slice(each.start, each.end)).join(', ')}}`,
612
- ]
613
- : []),
671
+ ...defaults.map(textOf),
672
+ ...(named.length > 0 ? [`{${named.map(textOf).join(', ')}}`] : []),
614
673
  ];
615
674
  edits.push({
616
675
  start: node.start,
617
676
  end: node.end,
618
- text: `import ${parts.join(', ')} from ${source.slice(node.source.start, node.source.end)};`,
677
+ text: `${above}import ${parts.join(', ')} from ${source.slice(node.source.start, node.source.end)};`,
619
678
  });
620
679
  }
621
680
  }
@@ -678,6 +737,35 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
678
737
  edits.push({start: node.start, end: node.end, text: next});
679
738
  }
680
739
  });
740
+ // Size comes from CSS in every icon set (its export contract), so a
741
+ // library's own sizing props on a mapped icon are dropped and reported.
742
+ /** @type {Map<string, Set<string>>} local name → props dropped */
743
+ const dropped = new Map();
744
+ walk(ast.program, node => {
745
+ if (node.type !== 'JSXOpeningElement' || node.name.type !== 'JSXIdentifier')
746
+ return;
747
+ const local = node.name.name;
748
+ if (!mappedLocals.has(local)) return;
749
+ for (const attribute of node.attributes) {
750
+ if (
751
+ attribute.type !== 'JSXAttribute' ||
752
+ attribute.name.type !== 'JSXIdentifier' ||
753
+ !SIZING_PROPS.has(attribute.name.name)
754
+ ) {
755
+ continue;
756
+ }
757
+ let start = attribute.start;
758
+ while (start > 0 && /\s/u.test(source[start - 1])) start -= 1;
759
+ edits.push({start, end: attribute.end, text: ''});
760
+ const set = dropped.get(local) ?? new Set();
761
+ set.add(attribute.name.name);
762
+ dropped.set(local, set);
763
+ }
764
+ });
765
+ for (const [entry, local] of mappedEntries) {
766
+ const props = dropped.get(local);
767
+ if (props) entry.dropped = [...props].sort();
768
+ }
681
769
  // A shorthand property is visited as both key and value; keep one edit.
682
770
  const unique = new Map();
683
771
  for (const edit of edits) {
@@ -125,6 +125,59 @@ describe('mapTemplateIcons', () => {
125
125
  ]);
126
126
  });
127
127
 
128
+ it("drops a library's sizing props from a mapped icon and reports them", () => {
129
+ const {source, icons} = map(
130
+ [
131
+ "import {CloseGlyph, PencilGlyph} from '@acme/library';",
132
+ '',
133
+ 'export const A = () => (',
134
+ ' <div>',
135
+ ' <CloseGlyph size={16} strokeWidth={2} className="x" />',
136
+ ' <CloseGlyph',
137
+ ' absoluteStrokeWidth',
138
+ ' />',
139
+ ' <PencilGlyph size={16} />',
140
+ ' </div>',
141
+ ');',
142
+ '',
143
+ ].join('\n'),
144
+ DECLARED,
145
+ );
146
+ expect(source).toContain('<XIcon className="x" />');
147
+ expect(source).toMatch(/<XIcon\s*\/>/u);
148
+ expect(source).not.toContain('absoluteStrokeWidth');
149
+ // A kept icon keeps its props.
150
+ expect(source).toContain('<PencilGlyph size={16} />');
151
+ expect(icons.mapped[0].dropped).toEqual([
152
+ 'absoluteStrokeWidth',
153
+ 'size',
154
+ 'strokeWidth',
155
+ ]);
156
+ expect(icons.kept[0]).not.toHaveProperty('dropped');
157
+ });
158
+
159
+ it('keeps comments inside and after a rewritten import line', () => {
160
+ const {source} = map(
161
+ [
162
+ "import {CloseGlyph /* close */, PencilGlyph /* pen */} from '@acme/library'; // tools",
163
+ "import {HomeGlyph} from '@acme/library/home'; // the home link",
164
+ '',
165
+ 'export const A = () => <><CloseGlyph /><PencilGlyph /><HomeGlyph /></>;',
166
+ '',
167
+ ].join('\n'),
168
+ DECLARED,
169
+ );
170
+ expect(source).toContain('/* close */');
171
+ expect(source).toContain('/* pen */');
172
+ expect(source).toContain('// tools');
173
+ expect(source).toContain('// the home link');
174
+ // Each comment is outside any code it would swallow.
175
+ expect(source).toContain(
176
+ "import {PencilGlyph /* pen */} from '@acme/library'; // tools",
177
+ );
178
+ expect(source).toMatch(/^\/\/ the home link$/mu);
179
+ });
180
+
128
181
  it('an undeclared import is not an icon: it is left alone and not reported', () => {
129
182
  const source =
130
183
  "import {CloseGlyph} from '@acme/library';\nexport const A = () => <CloseGlyph />;\n";
@@ -455,3 +508,53 @@ describe('icons another installed set ships', () => {
455
508
  ]);
456
509
  });
457
510
  });
511
+
512
+ describe('one key for a name imported from two modules (FR9)', () => {
513
+ it('maps both imports by the one key, and each keeps its variant', () => {
514
+ const LINES = /** @type {any} */ ({
515
+ name: 'lines',
516
+ package: '@acme/lines',
517
+ data: {
518
+ schemaVersion: 1,
519
+ module: '@acme/lines',
520
+ variants: ['outline', 'solid'],
521
+ default: {variant: 'outline'},
522
+ map: {delete: 'trash'},
523
+ icons: [
524
+ {
525
+ id: 'trash',
526
+ export: 'TrashIcon',
527
+ words: ['trash'],
528
+ variants: [
529
+ {
530
+ variant: 'solid',
531
+ export: 'TrashIcon',
532
+ module: '@acme/lines/solid',
533
+ },
534
+ ],
535
+ },
536
+ ],
537
+ },
538
+ });
539
+ const {source, icons} = map(
540
+ [
541
+ "import {TrashIcon} from '@acme/lines';",
542
+ "import {TrashIcon as TrashSolid} from '@acme/lines/solid';",
543
+ 'export const A = () => <><TrashIcon /><TrashSolid /></>;',
544
+ '',
545
+ ].join('\n'),
546
+ {TrashIcon: 'delete'},
547
+ SELECTED,
548
+ [SET, LINES],
549
+ );
550
+ expect(
551
+ icons.mapped.map(each => [each.source.module, each.target.export]),
552
+ ).toEqual([
553
+ ['@acme/lines', 'TrashIcon'],
554
+ ['@acme/lines/solid', 'TrashSolidIcon'],
555
+ ]);
556
+ expect(source).toContain(
557
+ "import {TrashIcon, TrashSolidIcon} from '@acme/glyphs';",
558
+ );
559
+ });
560
+ });
@@ -123,6 +123,13 @@ const RUNNERS = {
123
123
  runs: SELF_DOCS,
124
124
  sites: ['import ../experimental.doc.mjs'],
125
125
  },
126
+ 'clients/cli/commands/experimental/render.mjs': {
127
+ runs: SELF_DOCS,
128
+ sites: [
129
+ 'import ../../../../api/render/render.doc.mjs',
130
+ 'import ../experimental-render.doc.mjs',
131
+ ],
132
+ },
126
133
  'clients/cli/commands/manifest.mjs': {
127
134
  runs: SELF_DOCS,
128
135
  sites: ['import ./manifest.doc.mjs'],
@@ -350,6 +357,14 @@ const RUNNERS = {
350
357
  runs: 'authored doc files, each one handed to the compiler, with the loader its reader has always used',
351
358
  sites: ['importDocModule', 'importNativeModule ×3', 'importTemplateModule'],
352
359
  },
360
+ 'foundation/render/page-worker.mjs': {
361
+ runs: 'the page `astryx experimental render` renders, its local modules, React, and the StyleX compiler, in a worker',
362
+ sites: ['.import() ×3', 'createJiti ×2', 'require(@stylexjs/babel-plugin)'],
363
+ },
364
+ 'foundation/render/render-page.mjs': {
365
+ runs: 'the render worker, so a page that never finishes can be stopped',
366
+ sites: ['worker_threads.Worker'],
367
+ },
353
368
  'foundation/fs/module-loader.mjs': {
354
369
  runs: 'user modules (config, manifests, handlers, codemods): natively, through jiti, or by require for a fresh CommonJS read',
355
370
  sites: [
@@ -986,7 +986,9 @@ export function iconDefinitionTreeInput(doc, file, provider, providerId) {
986
986
  kind: 'icon-definition',
987
987
  name: doc.name,
988
988
  title: doc.name,
989
- summary: doc.description,
989
+ // Built-in definitions are the ones every set must map; the words are
990
+ // what an author searches the library for.
991
+ summary: `${doc.builtIn ? '[built-in] ' : ''}${doc.description}${doc.words.length > 0 ? ` Words: ${doc.words.join(', ')}.` : ''}`,
990
992
  group: ICON_DEFINITIONS_GROUP,
991
993
  placement: undefined,
992
994
  ref: {selfDoc: doc},
@@ -0,0 +1,31 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * Read a local file as a data: URI.
6
+ * @param {string} file absolute path
7
+ * @returns {string}
8
+ */
9
+ export function assetDataUri(file: string): string;
10
+ /**
11
+ * Whether bytes are a known image, font or media format, whatever the file's
12
+ * extension says (a JPEG saved as `.png` is still an inert image): their
13
+ * leading bytes match one (an SVG is XML with an <svg> element). A carried
14
+ * asset is carried, and written back, only when they do.
15
+ * @param {Buffer} bytes
16
+ */
17
+ export function isAssetBytes(bytes: Buffer): boolean;
18
+ /** The largest single file inlined into a rendered page. */
19
+ export const MAX_ASSET_BYTES: number;
20
+ export function isAssetPath(file: string): boolean;
21
+ /** An error carrying a render error code. */
22
+ export class RenderAssetError extends Error {
23
+ /**
24
+ * @param {string} code
25
+ * @param {string} message
26
+ * @param {Record<string, unknown>} [detail]
27
+ */
28
+ constructor(code: string, message: string, detail?: Record<string, unknown>);
29
+ code: string;
30
+ detail: Record<string, unknown> | undefined;
31
+ }