@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,368 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Every pair of options an icon command declares has a decided result
5
+ * (spec:AST-042 FR5): for each command, the pairs come from its CommandDoc
6
+ * (its options and its optional arguments; a required argument is always
7
+ * given), and each pair is either
8
+ * - refused together with `ERR_INVALID_OPTION` (the `refused` table), or
9
+ * - composed: the call succeeds with both (the `composes` table), or
10
+ * - prevented by another rule: the call fails with another code the
11
+ * function documents (every other pair).
12
+ * A pair that succeeds without being listed as composing fails this test, so
13
+ * a new option, or a change that starts ignoring one, is decided in review.
14
+ */
15
+
16
+ import * as fs from 'node:fs';
17
+ import * as os from 'node:os';
18
+ import * as path from 'node:path';
19
+ import {afterAll, beforeAll, describe, expect, it} from 'vitest';
20
+ import {writeIconSetProject} from '../../test-utils/icon-set-fixture.mjs';
21
+ import {icon} from './icon.mjs';
22
+ import {iconAdd} from './add/add.mjs';
23
+ import {iconMap} from './map/map.mjs';
24
+ import {iconNewSet} from './new-set/new-set.mjs';
25
+ import {iconNewDefinition} from './new-definition/new-definition.mjs';
26
+ import {iconUse} from './use/use.mjs';
27
+ import {doc as iconCommand} from '../../clients/cli/commands/experimental-icon.doc.mjs';
28
+ import {doc as addCommand} from '../../clients/cli/commands/experimental-icon-add.doc.mjs';
29
+ import {doc as mapCommand} from '../../clients/cli/commands/experimental-icon-map.doc.mjs';
30
+ import {doc as newSetCommand} from '../../clients/cli/commands/experimental-icon-new-set.doc.mjs';
31
+ import {doc as newDefinitionCommand} from '../../clients/cli/commands/experimental-icon-new-definition.doc.mjs';
32
+ import {doc as useCommand} from '../../clients/cli/commands/experimental-icon-use.doc.mjs';
33
+ import {doc as iconFn} from './icon.doc.mjs';
34
+ import {doc as addFn} from './iconAdd.doc.mjs';
35
+ import {doc as mapFn} from './iconMap.doc.mjs';
36
+ import {doc as newSetFn} from './iconNewSet.doc.mjs';
37
+ import {doc as newDefinitionFn} from './iconNewDefinition.doc.mjs';
38
+ import {doc as useFn} from './iconUse.doc.mjs';
39
+
40
+ /** @type {string} */
41
+ let tmp;
42
+ beforeAll(() => {
43
+ tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-icon-pairs-'));
44
+ });
45
+ afterAll(() => {
46
+ fs.rmSync(tmp, {recursive: true, force: true});
47
+ });
48
+
49
+ const FROM = '@acme/glyph-library';
50
+
51
+ /**
52
+ * An icon-set package `@acme/icons` with an installed library, and, unless
53
+ * `bare`, its set `glyphs` made from that library with two variants.
54
+ * @param {{bare?: boolean}} [options]
55
+ * @returns {Promise<string>}
56
+ */
57
+ async function makePackage({bare = false} = {}) {
58
+ const dir = fs.mkdtempSync(path.join(tmp, 'pkg-'));
59
+ fs.writeFileSync(
60
+ path.join(dir, 'package.json'),
61
+ `${JSON.stringify({name: '@acme/icons', version: '1.0.0', license: 'MIT', type: 'module'}, null, 2)}\n`,
62
+ );
63
+ const lib = path.join(dir, 'node_modules', '@acme', 'glyph-library');
64
+ fs.mkdirSync(lib, {recursive: true});
65
+ fs.writeFileSync(
66
+ path.join(lib, 'package.json'),
67
+ JSON.stringify({
68
+ name: '@acme/glyph-library',
69
+ version: '2.0.0',
70
+ type: 'module',
71
+ exports: {'.': './index.js', './solid': './solid.js'},
72
+ }),
73
+ );
74
+ const icons =
75
+ 'export const Bin = props => null;\nexport const Close = props => null;\n';
76
+ fs.writeFileSync(path.join(lib, 'index.js'), icons);
77
+ fs.writeFileSync(path.join(lib, 'solid.js'), icons);
78
+ if (!bare) {
79
+ await iconNewSet('glyphs', {
80
+ cwd: dir,
81
+ from: FROM,
82
+ variants: 'outline,solid',
83
+ });
84
+ }
85
+ return dir;
86
+ }
87
+
88
+ /**
89
+ * @typedef {object} Case
90
+ * @property {any} command the CommandDoc
91
+ * @property {any} fn the FunctionDoc
92
+ * @property {(...args: any[]) => Promise<unknown>} call
93
+ * @property {() => Promise<string>} cwd a fresh folder for one call
94
+ * @property {Record<string, unknown>} values a value for each API parameter
95
+ * @property {Array<[string, string]>} refused pairs refused together
96
+ * @property {Array<[string, string]>} composes pairs that succeed together
97
+ */
98
+
99
+ /** @type {Record<string, Case>} */
100
+ const CASES = {
101
+ 'experimental icon': {
102
+ command: iconCommand,
103
+ fn: iconFn,
104
+ call: icon,
105
+ cwd: async () =>
106
+ writeIconSetProject(fs.mkdtempSync(path.join(tmp, 'app-'))),
107
+ values: {
108
+ query: 'trash',
109
+ 'options.list': true,
110
+ 'options.set': 'glyphs',
111
+ 'options.limit': 3,
112
+ 'options.definitions': true,
113
+ 'options.allIcons': true,
114
+ },
115
+ refused: [
116
+ ['query', '--list'],
117
+ ['query', '--definitions'],
118
+ ['query', '--all-icons'],
119
+ ['--list', '--set'],
120
+ ['--list', '--limit'],
121
+ ['--list', '--definitions'],
122
+ ['--list', '--all-icons'],
123
+ ['--set', '--definitions'],
124
+ ['--limit', '--definitions'],
125
+ ['--limit', '--all-icons'],
126
+ ['--definitions', '--all-icons'],
127
+ ],
128
+ composes: [
129
+ ['query', '--set'],
130
+ ['query', '--limit'],
131
+ ['--set', '--all-icons'],
132
+ ],
133
+ },
134
+ 'experimental icon add': {
135
+ command: addCommand,
136
+ fn: addFn,
137
+ call: iconAdd,
138
+ cwd: () => makePackage(),
139
+ values: {
140
+ exportName: 'Bin',
141
+ 'options.from': FROM,
142
+ 'options.definition': 'delete',
143
+ 'options.newDefinition': 'binIt',
144
+ 'options.description': 'Put something in the bin.',
145
+ 'options.words': ['bin'],
146
+ 'options.useDefault': true,
147
+ 'options.variant': 'solid',
148
+ 'options.all': true,
149
+ 'options.id': 'bin',
150
+ 'options.set': 'glyphs',
151
+ },
152
+ refused: [
153
+ ['export', '--all'],
154
+ ['--definition', '--new-definition'],
155
+ ['--definition', '--description'],
156
+ ['--definition', '--words'],
157
+ ['--definition', '--all'],
158
+ ['--new-definition', '--all'],
159
+ ['--description', '--all'],
160
+ ['--words', '--all'],
161
+ ['--default', '--all'],
162
+ ['--all', '--id'],
163
+ // A description and words describe only a new definition.
164
+ ['export', '--description'],
165
+ ['export', '--words'],
166
+ ['--from', '--description'],
167
+ ['--from', '--words'],
168
+ ['--description', '--words'],
169
+ ['--description', '--default'],
170
+ ['--description', '--variant'],
171
+ ['--description', '--id'],
172
+ ['--description', '--set'],
173
+ ['--words', '--default'],
174
+ ['--words', '--variant'],
175
+ ['--words', '--id'],
176
+ ['--words', '--set'],
177
+ ],
178
+ composes: [['export', '--from']],
179
+ },
180
+ 'experimental icon map': {
181
+ command: mapCommand,
182
+ fn: mapFn,
183
+ call: iconMap,
184
+ cwd: () => makePackage(),
185
+ values: {
186
+ definition: 'delete',
187
+ icon: 'bin',
188
+ 'options.set': 'glyphs',
189
+ 'options.remove': true,
190
+ 'options.pairs': 'close=close',
191
+ },
192
+ refused: [
193
+ ['definition', '--pairs'],
194
+ ['icon', '--remove'],
195
+ ['icon', '--pairs'],
196
+ ['--remove', '--pairs'],
197
+ ],
198
+ composes: [
199
+ ['definition', 'icon'],
200
+ ['definition', '--remove'],
201
+ ['--set', '--pairs'],
202
+ ],
203
+ },
204
+ 'experimental icon new-set': {
205
+ command: newSetCommand,
206
+ fn: newSetFn,
207
+ call: iconNewSet,
208
+ cwd: () => makePackage({bare: true}),
209
+ values: {
210
+ name: 'glyphs',
211
+ 'options.dryRun': true,
212
+ 'options.from': FROM,
213
+ 'options.exclude': 'Close',
214
+ 'options.variants': 'outline,solid',
215
+ 'options.defaultVariant': 'solid',
216
+ 'options.displayName': 'Glyphs',
217
+ 'options.description': 'Glyph icons.',
218
+ },
219
+ refused: [
220
+ // `--exclude` needs `--from`, `--default-variant` needs `--variants`.
221
+ ['--dry-run', '--exclude'],
222
+ ['--dry-run', '--default-variant'],
223
+ ['--exclude', '--variants'],
224
+ ['--exclude', '--default-variant'],
225
+ ['--exclude', '--display-name'],
226
+ ['--exclude', '--description'],
227
+ ['--from', '--default-variant'],
228
+ ['--default-variant', '--display-name'],
229
+ ['--default-variant', '--description'],
230
+ ],
231
+ composes: [
232
+ ['--dry-run', '--from'],
233
+ ['--dry-run', '--variants'],
234
+ ['--dry-run', '--display-name'],
235
+ ['--dry-run', '--description'],
236
+ ['--from', '--exclude'],
237
+ ['--from', '--variants'],
238
+ ['--from', '--display-name'],
239
+ ['--from', '--description'],
240
+ ['--variants', '--default-variant'],
241
+ ['--variants', '--display-name'],
242
+ ['--variants', '--description'],
243
+ ['--display-name', '--description'],
244
+ ],
245
+ },
246
+ 'experimental icon new-definition': {
247
+ command: newDefinitionCommand,
248
+ fn: newDefinitionFn,
249
+ call: iconNewDefinition,
250
+ cwd: () => makePackage(),
251
+ values: {
252
+ name: 'binIt',
253
+ 'options.dryRun': true,
254
+ 'options.set': 'glyphs',
255
+ 'options.description': 'Put something in the bin.',
256
+ 'options.words': ['bin'],
257
+ 'options.icon': 'bin',
258
+ },
259
+ refused: [],
260
+ composes: [['--description', '--words']],
261
+ },
262
+ 'experimental icon use': {
263
+ command: useCommand,
264
+ fn: useFn,
265
+ call: iconUse,
266
+ cwd: async () =>
267
+ writeIconSetProject(fs.mkdtempSync(path.join(tmp, 'app-'))),
268
+ values: {set: 'glyphs'},
269
+ refused: [],
270
+ composes: [],
271
+ },
272
+ };
273
+
274
+ /**
275
+ * The pair members a command declares: its optional arguments, by name, and
276
+ * its options, by long flag; each with the API parameter it sets.
277
+ * @param {any} command
278
+ * @returns {Array<{label: string, param: string}>}
279
+ */
280
+ function members(command) {
281
+ return [
282
+ ...(command.args ?? [])
283
+ .filter((/** @type {any} */ arg) => arg.required !== true)
284
+ .map((/** @type {any} */ arg) => ({label: arg.name, param: arg.param})),
285
+ ...(command.options ?? []).map((/** @type {any} */ option) => ({
286
+ label: option.flag.split(/[\s,]/u)[0],
287
+ param: option.param,
288
+ })),
289
+ ];
290
+ }
291
+
292
+ /** @param {[string, string]} pair */
293
+ const key = ([a, b]) => [a, b].sort().join(' + ');
294
+
295
+ describe.each(Object.entries(CASES))('%s', (_name, spec) => {
296
+ const declared = members(spec.command);
297
+ const labels = declared.map(each => each.label);
298
+ /** @type {Array<[string, string]>} */
299
+ const pairs = [];
300
+ for (let i = 0; i < declared.length; i++) {
301
+ for (let j = i + 1; j < declared.length; j++) {
302
+ pairs.push([declared[i].label, declared[j].label]);
303
+ }
304
+ }
305
+ const refused = new Set(spec.refused.map(key));
306
+ const composes = new Set(spec.composes.map(key));
307
+ const documented = new Set(
308
+ (spec.fn.throws ?? []).map((/** @type {any} */ each) => each.code),
309
+ );
310
+
311
+ it('names only pairs the command declares, each in one table', () => {
312
+ for (const pair of [...spec.refused, ...spec.composes]) {
313
+ expect(labels, key(pair)).toEqual(expect.arrayContaining(pair));
314
+ }
315
+ expect([...refused].filter(each => composes.has(each))).toEqual([]);
316
+ for (const {param} of declared) {
317
+ expect(Object.keys(spec.values), param).toContain(param);
318
+ }
319
+ });
320
+
321
+ if (pairs.length === 0) return;
322
+ it.each(pairs)('%s with %s', async (a, b) => {
323
+ const given = new Set([a, b]);
324
+ const cwd = await spec.cwd();
325
+ // Required arguments are always given, in order; the rest only when
326
+ // they are one of the pair.
327
+ const args = (spec.command.args ?? []).map((/** @type {any} */ arg) =>
328
+ arg.required === true || given.has(arg.name)
329
+ ? spec.values[arg.param]
330
+ : undefined,
331
+ );
332
+ /** @type {Record<string, unknown>} */
333
+ const options = {cwd};
334
+ for (const {label, param} of declared) {
335
+ if (given.has(label) && param.startsWith('options.')) {
336
+ options[param.slice('options.'.length)] = spec.values[param];
337
+ }
338
+ }
339
+ /** @type {any} */
340
+ let error = null;
341
+ try {
342
+ await spec.call(...args, options);
343
+ } catch (thrown) {
344
+ error = thrown;
345
+ }
346
+ const pair = key([a, b]);
347
+ if (refused.has(pair)) {
348
+ expect(error?.code, `${pair}: ${error?.message}`).toBe(
349
+ 'ERR_INVALID_OPTION',
350
+ );
351
+ } else if (composes.has(pair)) {
352
+ expect(error, `${pair}: ${error?.message}`).toBeNull();
353
+ } else {
354
+ // Prevented by another rule: a documented code, never a silent
355
+ // success and never an unknown error.
356
+ expect(
357
+ error,
358
+ `${pair} succeeded but is not listed as composing`,
359
+ ).not.toBeNull();
360
+ expect(error.code, `${pair}: ${error.message}`).not.toBe(
361
+ 'ERR_INVALID_OPTION',
362
+ );
363
+ expect([...documented], `${pair}: ${error.message}`).toContain(
364
+ error.code,
365
+ );
366
+ }
367
+ });
368
+ });
@@ -1,6 +1,16 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * Every icon of one set, by id: `--set <name> --all-icons`, so an author can read
6
+ * a whole library's ids, words, and the definitions each icon draws.
7
+ * @param {{cwd: string, set: string}} options
8
+ * @returns {Promise<import('../icon.type.mjs').IconSetIconsResponse>}
9
+ */
10
+ export function iconSetIcons({ cwd, set }: {
11
+ cwd: string;
12
+ set: string;
13
+ }): Promise<import("../icon.type.mjs").IconSetIconsResponse>;
4
14
  /**
5
15
  * Rank every installed icon against a query.
6
16
  * @param {string} query
@@ -12,7 +12,54 @@
12
12
  import {AstryxError} from '../../error.mjs';
13
13
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
14
14
  import {loadIconSets} from '../_adapter.mjs';
15
- import {closest, rankIcons, setsNamed, withdrawnReason} from '../_records.mjs';
15
+ import {rankIcons, setsNamed, unusableSet} from '../_records.mjs';
16
+
17
+ /** The lowest score of a whole-word or word-start match. */
18
+ const WORD_SCORE = 60;
19
+
20
+ /**
21
+ * Every icon of one set, by id: `--set <name> --all-icons`, so an author can read
22
+ * a whole library's ids, words, and the definitions each icon draws.
23
+ * @param {{cwd: string, set: string}} options
24
+ * @returns {Promise<import('../icon.type.mjs').IconSetIconsResponse>}
25
+ */
26
+ export async function iconSetIcons({cwd, set}) {
27
+ const {sets, withdrawn} = await loadIconSets(cwd);
28
+ const named = setsNamed(sets, set);
29
+ if (named.length === 0) throw unusableSet(sets, withdrawn, set);
30
+ if (named.length > 1) {
31
+ throw new AstryxError(
32
+ `"${set}" names ${named.length} sets; name one as <package>/<set>`,
33
+ named.map(each => ({
34
+ name: `${each.package}/${each.name}`,
35
+ reason: 'name the package',
36
+ })),
37
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
38
+ );
39
+ }
40
+ const [only] = named;
41
+ /** @type {Map<string, string[]>} */
42
+ const drawn = new Map();
43
+ for (const [definition, id] of Object.entries(only.data.map ?? {})) {
44
+ drawn.set(id, [...(drawn.get(id) ?? []), definition]);
45
+ }
46
+ return {
47
+ type: 'icon.setIcons',
48
+ data: {
49
+ set: only.name,
50
+ package: only.package,
51
+ iconCount: only.data.icons.length,
52
+ icons: [...only.data.icons]
53
+ .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
54
+ .map(icon => ({
55
+ id: icon.id,
56
+ export: icon.export,
57
+ words: icon.words,
58
+ definitions: (drawn.get(icon.id) ?? []).sort(),
59
+ })),
60
+ },
61
+ };
62
+ }
16
63
 
17
64
  /**
18
65
  * Rank every installed icon against a query.
@@ -25,20 +72,14 @@ export async function iconSearch(query, {cwd, set, limit}) {
25
72
  let searched = sets;
26
73
  if (set != null) {
27
74
  searched = setsNamed(sets, set);
28
- if (searched.length === 0) {
29
- throw new AstryxError(
30
- withdrawnReason(withdrawn, set) ??
31
- `No installed icon set named "${set}"`,
32
- closest(
33
- set,
34
- sets.flatMap(each => [each.name, `${each.package}/${each.name}`]),
35
- 'installed icon set',
36
- ),
37
- ERROR_CODES.ERR_NOT_FOUND,
38
- );
39
- }
75
+ if (searched.length === 0) throw unusableSet(sets, withdrawn, set);
40
76
  }
41
- const matches = rankIcons(searched, query);
77
+ const ranked = rankIcons(searched, query);
78
+ // A partial match (`pin` inside `shopping`) answers only when nothing
79
+ // matches a whole word or a word start.
80
+ const matches = ranked.some(each => each.score >= WORD_SCORE)
81
+ ? ranked.filter(each => each.score >= WORD_SCORE)
82
+ : ranked;
42
83
  return {
43
84
  type: 'icon.search',
44
85
  data: {
@@ -18,7 +18,7 @@ import {
18
18
  refuseOutsideProject,
19
19
  setConfigString,
20
20
  } from '../_adapter.mjs';
21
- import {closest, setsNamed, withdrawnReason} from '../_records.mjs';
21
+ import {setsNamed, unusableSet} from '../_records.mjs';
22
22
 
23
23
  /**
24
24
  * Make an installed set the project's icon set.
@@ -45,18 +45,7 @@ export async function iconUse(selector, {cwd = process.cwd()} = {}) {
45
45
  refuseOutsideProject(cwd, 'experimental icon use', 'the app project');
46
46
  const {projectDir, sets, withdrawn} = await loadIconProject(cwd);
47
47
  const named = setsNamed(sets, selector);
48
- if (named.length === 0) {
49
- throw new AstryxError(
50
- withdrawnReason(withdrawn, selector) ??
51
- `No installed icon set is named "${selector}".`,
52
- closest(
53
- selector,
54
- sets.flatMap(set => [set.name, iconSetKey(set)]),
55
- 'an installed icon set',
56
- ),
57
- ERROR_CODES.ERR_NOT_FOUND,
58
- );
59
- }
48
+ if (named.length === 0) throw unusableSet(sets, withdrawn, selector);
60
49
  if (named.length > 1) {
61
50
  throw new AstryxError(
62
51
  `Two installed packages ship an icon set named "${selector}"; name it with its package.`,
@@ -92,7 +92,7 @@ export function loadCurrentManifest(manifestFile: string, manifestExists: boolea
92
92
  * @param {string} manifestPath
93
93
  * @param {string[]} files
94
94
  * @param {boolean} dryRun
95
- * @returns {{type: 'integration.add', data: Omit<import('./integration-authoring.type.mjs').IntegrationAddData, 'kind'> & {kind: K, icons?: number, notes?: string[]}}}
95
+ * @returns {{type: 'integration.add', data: Omit<import('./integration-authoring.type.mjs').IntegrationAddData, 'kind'> & {kind: K, icons?: number, refreshed?: boolean, renamed?: Array<{from: string, to: string}>, mapped?: Array<{definition: string, icon: string}>, suggestions?: Array<{definition: string, icon: string, word: string}>, notes?: string[]}}}
96
96
  */
97
97
  export function receipt<K extends import("./integration-authoring.type.mjs").IntegrationAddData["kind"] | import("../icon/icon.type.mjs").IconNewData["kind"]>(kind: K, name: string, root: {
98
98
  path: string;
@@ -102,6 +102,20 @@ export function receipt<K extends import("./integration-authoring.type.mjs").Int
102
102
  data: Omit<import("./integration-authoring.type.mjs").IntegrationAddData, "kind"> & {
103
103
  kind: K;
104
104
  icons?: number;
105
+ refreshed?: boolean;
106
+ renamed?: Array<{
107
+ from: string;
108
+ to: string;
109
+ }>;
110
+ mapped?: Array<{
111
+ definition: string;
112
+ icon: string;
113
+ }>;
114
+ suggestions?: Array<{
115
+ definition: string;
116
+ icon: string;
117
+ word: string;
118
+ }>;
105
119
  notes?: string[];
106
120
  };
107
121
  };
@@ -483,7 +483,7 @@ export async function loadCurrentManifest(manifestFile, manifestExists) {
483
483
  * @param {string} manifestPath
484
484
  * @param {string[]} files
485
485
  * @param {boolean} dryRun
486
- * @returns {{type: 'integration.add', data: Omit<import('./integration-authoring.type.mjs').IntegrationAddData, 'kind'> & {kind: K, icons?: number, notes?: string[]}}}
486
+ * @returns {{type: 'integration.add', data: Omit<import('./integration-authoring.type.mjs').IntegrationAddData, 'kind'> & {kind: K, icons?: number, refreshed?: boolean, renamed?: Array<{from: string, to: string}>, mapped?: Array<{definition: string, icon: string}>, suggestions?: Array<{definition: string, icon: string, word: string}>, notes?: string[]}}}
487
487
  */
488
488
  export function receipt(kind, name, root, manifestPath, files, dryRun) {
489
489
  return {
@@ -166,8 +166,9 @@ export type IconSetCoverage = {
166
166
  }>;
167
167
  /**
168
168
  * For each
169
- * unmapped definition (built-in, optional, or the set's own), the icon
170
- * whose whole id is the definition's name or one of its words, when one is.
169
+ * unmapped definition (built-in, optional, or the set's own), the best icon
170
+ * `integration check` gives it, by the rule `experimental icon new-set`
171
+ * uses for its suggestions, when one is.
171
172
  */
172
173
  suggestions: Array<{
173
174
  definition: string;
@@ -126,8 +126,9 @@
126
126
  * Astryx's optional (not built-in) definitions the set's `map` does not
127
127
  * name. An unmapped built-in definition is an error issue instead.
128
128
  * @property {Array<{definition: string, icon: string}>} suggestions For each
129
- * unmapped definition (built-in, optional, or the set's own), the icon
130
- * whose whole id is the definition's name or one of its words, when one is.
129
+ * unmapped definition (built-in, optional, or the set's own), the best icon
130
+ * `integration check` gives it, by the rule `experimental icon new-set`
131
+ * uses for its suggestions, when one is.
131
132
  * @property {Array<{icon?: string, adapter?: string, entry?: string, reason: string}>} unchecked
132
133
  * What the checks could not judge, each with the reason: an icon export
133
134
  * whose module is an `exports` target not built yet, or that the reader
@@ -0,0 +1,28 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * Render a page module to one HTML file and write it.
6
+ * @param {{cwd: string, input: string, output: string, title?: string}} args absolute paths
7
+ * @returns {Promise<import('./render.type.mjs').RenderPageResponse['data']>}
8
+ */
9
+ export function renderToFile({ cwd, input, output, title }: {
10
+ cwd: string;
11
+ input: string;
12
+ output: string;
13
+ title?: string;
14
+ }): Promise<import("./render.type.mjs").RenderPageResponse["data"]>;
15
+ /**
16
+ * Turn a rendered HTML file back into a page module.
17
+ * @param {{cwd: string, input: string, output: string | undefined, overwrite: boolean}} args absolute paths
18
+ * @returns {import('./render.type.mjs').RenderReverseResponse['data']}
19
+ */
20
+ export function reverseToFile({ cwd, input, output, overwrite }: {
21
+ cwd: string;
22
+ input: string;
23
+ output: string | undefined;
24
+ overwrite: boolean;
25
+ }): import("./render.type.mjs").RenderReverseResponse["data"];
26
+ import { PAGE_EXTENSIONS } from '../../foundation/render/render-page.mjs';
27
+ import { embeddedPathProblem } from '../../foundation/render/embedded-files.mjs';
28
+ export { PAGE_EXTENSIONS, embeddedPathProblem };