@astryxdesign/cli 0.7.12 → 0.7.13-canary.802938b

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 (89) hide show
  1. package/api/component/__fixtures__/resolutions/modules.txt +2 -2
  2. package/api/doctor/_adapter.d.mts +17 -0
  3. package/api/doctor/_adapter.mjs +40 -0
  4. package/api/doctor/doctor.d.mts +34 -4
  5. package/api/doctor/doctor.mjs +108 -21
  6. package/api/icon/_adapter.d.mts +6 -3
  7. package/api/icon/_adapter.mjs +11 -3
  8. package/api/icon/icon.type.d.mts +22 -1
  9. package/api/icon/icon.type.mjs +12 -4
  10. package/api/icon/iconUse.doc.mjs +27 -7
  11. package/api/icon/list/list.mjs +29 -3
  12. package/api/icon/use/use.d.mts +7 -3
  13. package/api/icon/use/use.mjs +68 -18
  14. package/api/integration/validate-integration.d.mts +4 -0
  15. package/api/integration/validate-integration.mjs +32 -2
  16. package/api/integration/validate-integration.type.d.mts +15 -0
  17. package/api/integration/validate-integration.type.mjs +6 -1
  18. package/api/template/copy/copy.mjs +4 -2
  19. package/api/template/template.type.d.mts +42 -4
  20. package/api/template/template.type.mjs +9 -6
  21. package/assets/discover/official-packages.json +4 -0
  22. package/assets/docs/tree/icon-sets.doc.mjs +91 -7
  23. package/assets/icons/definitions/alignBottom.doc.mjs +9 -0
  24. package/assets/icons/definitions/alignJustify.doc.mjs +9 -0
  25. package/assets/icons/definitions/alignMiddle.doc.mjs +9 -0
  26. package/assets/icons/definitions/alignTop.doc.mjs +9 -0
  27. package/assets/icons/definitions/angle.doc.mjs +9 -0
  28. package/assets/icons/definitions/cloud.doc.mjs +9 -0
  29. package/assets/icons/definitions/collection.doc.mjs +9 -0
  30. package/assets/icons/definitions/contrast.doc.mjs +9 -0
  31. package/assets/icons/definitions/cornerRadius.doc.mjs +9 -0
  32. package/assets/icons/definitions/cut.doc.mjs +9 -0
  33. package/assets/icons/definitions/fingerprint.doc.mjs +9 -0
  34. package/assets/icons/definitions/fire.doc.mjs +9 -0
  35. package/assets/icons/definitions/frame.doc.mjs +9 -0
  36. package/assets/icons/definitions/gift.doc.mjs +9 -0
  37. package/assets/icons/definitions/group.doc.mjs +9 -0
  38. package/assets/icons/definitions/integration.doc.mjs +9 -0
  39. package/assets/icons/definitions/lowercase.doc.mjs +9 -0
  40. package/assets/icons/definitions/paddingHorizontal.doc.mjs +9 -0
  41. package/assets/icons/definitions/paddingPerSide.doc.mjs +9 -0
  42. package/assets/icons/definitions/paddingVertical.doc.mjs +9 -0
  43. package/assets/icons/definitions/panelBottom.doc.mjs +9 -0
  44. package/assets/icons/definitions/photoEffect.doc.mjs +9 -0
  45. package/assets/icons/definitions/radiusPerCorner.doc.mjs +9 -0
  46. package/assets/icons/definitions/rotateCounterclockwise.doc.mjs +9 -0
  47. package/assets/icons/definitions/tablet.doc.mjs +9 -0
  48. package/assets/icons/definitions/text.doc.mjs +9 -0
  49. package/assets/icons/definitions/textRegular.doc.mjs +9 -0
  50. package/assets/icons/definitions/transfer.doc.mjs +9 -0
  51. package/assets/icons/definitions/uppercase.doc.mjs +9 -0
  52. package/assets/icons/definitions/userRemove.doc.mjs +9 -0
  53. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadMenu.doc.mjs +23 -0
  54. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadMenu.tsx +199 -0
  55. package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +1 -0
  56. package/assets/templates/blocks/components/ChatSystemMessage/ChatSystemMessageStatusUpdates.doc.mjs +7 -2
  57. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider04Calendar.doc.mjs +21 -0
  58. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider04Calendar.tsx +46 -0
  59. package/assets/templates/blocks/components/InternationalizationProvider/useDirectionHookUsage.doc.mjs +18 -0
  60. package/assets/templates/blocks/components/InternationalizationProvider/useDirectionHookUsage.tsx +101 -0
  61. package/assets/templates/blocks/components/Text/useTruncationHookUsage.doc.mjs +14 -0
  62. package/assets/templates/blocks/components/Text/useTruncationHookUsage.tsx +112 -0
  63. package/assets/templates/pages/canvas-editor/template.doc.mjs +20 -0
  64. package/assets/templates/pages/editor/template.doc.mjs +1 -0
  65. package/assets/templates/pages/form-wizard-vertical/template.doc.mjs +1 -0
  66. package/assets/templates/pages/settings-dialog/template.doc.mjs +4 -0
  67. package/assets/templates/pages/shell-top-nav/template.doc.mjs +3 -0
  68. package/assets/templates/pages/table-collapsible/template.doc.mjs +1 -0
  69. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
  70. package/authoring/config/config.doc.mjs +4 -4
  71. package/authoring/config/parse.d.mts +1 -1
  72. package/authoring/config/parse.mjs +3 -1
  73. package/authoring/config/type.ts +7 -5
  74. package/authoring/doctypes/template/template.doc.mjs +1 -1
  75. package/authoring/doctypes/template/type.ts +5 -3
  76. package/clients/cli/commands/experimental/icon.mjs +38 -9
  77. package/clients/cli/commands/experimental-icon-use.doc.mjs +9 -4
  78. package/clients/cli/commands/template.mjs +12 -3
  79. package/foundation/config/config-writer.d.mts +14 -0
  80. package/foundation/config/config-writer.mjs +73 -17
  81. package/foundation/discovery/icon-set-discovery.d.mts +77 -7
  82. package/foundation/discovery/icon-set-discovery.mjs +128 -42
  83. package/foundation/discovery/template-icon-notes.d.mts +46 -0
  84. package/foundation/discovery/template-icon-notes.mjs +94 -16
  85. package/foundation/discovery/template-icons.d.mts +247 -0
  86. package/foundation/discovery/template-icons.mjs +591 -37
  87. package/foundation/integrations/cli-requirement.d.mts +13 -4
  88. package/foundation/integrations/cli-requirement.mjs +18 -6
  89. package/package.json +14 -14
@@ -1,7 +1,8 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Write one string field of a project's astryx.config.
4
+ * @file Write one string field, or one list of strings, in a project's
5
+ * astryx.config.
5
6
  *
6
7
  * The field is a top-level key or a dotted path into nested object literals
7
8
  * (`experimental.iconSet`); a missing object on the path is created.
@@ -18,7 +19,8 @@
18
19
  * `ERR_CODEMOD_PROTECTED` naming the protecting declaration, and an unreadable
19
20
  * protection source fails with `ERR_CODEMOD_PROTECTION_SOURCE`.
20
21
  *
21
- * @input A project directory, a field name, and its string value
22
+ * @input A project directory, a field name, and its value: a string or a
23
+ * list of strings
22
24
  * @output The config file written and the value it replaced
23
25
  * @position packages/cli/foundation/config — read by `astryx experimental icon use`
24
26
  */
@@ -87,6 +89,47 @@ function propertyNamed(property, name) {
87
89
  );
88
90
  }
89
91
 
92
+ /** @param {string} text */
93
+ const quote = text => `'${text.replace(/\\/gu, '\\\\').replace(/'/gu, "\\'")}'`;
94
+
95
+ /** @param {string | readonly string[]} value */
96
+ const written = value =>
97
+ typeof value === 'string'
98
+ ? quote(value)
99
+ : `[${value.map(each => quote(each)).join(', ')}]`;
100
+
101
+ /**
102
+ * The string, or list of strings, a config property holds; null for any
103
+ * other value.
104
+ * @param {any} node
105
+ * @returns {string | string[] | null}
106
+ */
107
+ function literalValue(node) {
108
+ if (node?.type === 'StringLiteral' || node?.type === 'Literal') {
109
+ return typeof node.value === 'string' ? node.value : null;
110
+ }
111
+ if (node?.type === 'ArrayExpression') {
112
+ const items = node.elements.map((/** @type {any} */ each) =>
113
+ each?.type === 'StringLiteral' ||
114
+ (each?.type === 'Literal' && typeof each.value === 'string')
115
+ ? String(each.value)
116
+ : null,
117
+ );
118
+ return items.every((/** @type {string | null} */ each) => each != null)
119
+ ? /** @type {string[]} */ (items)
120
+ : null;
121
+ }
122
+ return null;
123
+ }
124
+
125
+ /**
126
+ * @param {string | string[] | null} a
127
+ * @param {string | readonly string[]} b
128
+ */
129
+ function sameValue(a, b) {
130
+ return JSON.stringify(a) === JSON.stringify(b);
131
+ }
132
+
90
133
  /**
91
134
  * Set `key` to `value` in the project's astryx.config.
92
135
  * @param {string} projectDir
@@ -95,6 +138,22 @@ function propertyNamed(property, name) {
95
138
  * @returns {{file: string, created: boolean, previous: string | null, changed: boolean}}
96
139
  */
97
140
  export function setConfigString(projectDir, key, value) {
141
+ const result = setConfigValue(projectDir, key, value);
142
+ return {
143
+ ...result,
144
+ previous: typeof result.previous === 'string' ? result.previous : null,
145
+ };
146
+ }
147
+
148
+ /**
149
+ * Set `key` to `value`, a string or a list of strings, in the project's
150
+ * astryx.config.
151
+ * @param {string} projectDir
152
+ * @param {string} key a top-level key, or a dotted path (`experimental.iconSet`)
153
+ * @param {string | readonly string[]} value
154
+ * @returns {{file: string, created: boolean, previous: string | string[] | null, changed: boolean}}
155
+ */
156
+ export function setConfigValue(projectDir, key, value) {
98
157
  const keys = key.split('.');
99
158
  const leaf = /** @type {string} */ (keys[keys.length - 1]);
100
159
  const existing = CONFIG_BASENAMES.map(name =>
@@ -103,7 +162,6 @@ export function setConfigString(projectDir, key, value) {
103
162
  if (!existing) {
104
163
  const file = path.join(projectDir, 'astryx.config.mjs');
105
164
  assertWritable(projectDir, file);
106
- const quoted = `'${value.replace(/\\/gu, '\\\\').replace(/'/gu, "\\'")}'`;
107
165
  // Each key on the path opens one nested object: `experimental: {`.
108
166
  const open = keys
109
167
  .slice(0, -1)
@@ -116,7 +174,7 @@ export function setConfigString(projectDir, key, value) {
116
174
  .join('');
117
175
  writeAtomically(
118
176
  file,
119
- `export default {\n${open}${' '.repeat(keys.length)}${leaf}: ${quoted},\n${close}};\n`,
177
+ `export default {\n${open}${' '.repeat(keys.length)}${leaf}: ${written(value)},\n${close}};\n`,
120
178
  );
121
179
  return {file, created: true, previous: null, changed: true};
122
180
  }
@@ -127,7 +185,7 @@ export function setConfigString(projectDir, key, value) {
127
185
  let object = findManifestObject(j, ast);
128
186
  const refuse = () =>
129
187
  new Error(
130
- `Could not update ${path.basename(existing)} safely: its default export is not a static object literal. Set "${key}: '${value}'" in it yourself.`,
188
+ `Could not update ${path.basename(existing)} safely: its default export is not a static object literal. Set "${key}: ${written(value)}" in it yourself.`,
131
189
  );
132
190
  if (!object) throw refuse();
133
191
  // A spread on the path can hold the same keys: a key added beside it would
@@ -137,7 +195,7 @@ export function setConfigString(projectDir, key, value) {
137
195
  const assertNoSpread = (holder, where) => {
138
196
  if (holder.properties.some((/** @type {any} */ each) => isSpread(each))) {
139
197
  throw new Error(
140
- `Could not update ${path.basename(existing)} safely: ${where} spreads another object (\`...\`), whose keys a written "${key}" could replace. Set "${key}: '${value}'" in it yourself.`,
198
+ `Could not update ${path.basename(existing)} safely: ${where} spreads another object (\`...\`), whose keys a written "${key}" could replace. Set "${key}: ${written(value)}" in it yourself.`,
141
199
  );
142
200
  }
143
201
  };
@@ -160,22 +218,20 @@ export function setConfigString(projectDir, key, value) {
160
218
  const property = object.properties.find((/** @type {any} */ each) =>
161
219
  propertyNamed(each, leaf),
162
220
  );
163
- /** @type {string | null} */
221
+ const node =
222
+ typeof value === 'string'
223
+ ? j.stringLiteral(value)
224
+ : j.arrayExpression(value.map(each => j.stringLiteral(each)));
225
+ /** @type {string | string[] | null} */
164
226
  let previous = null;
165
227
  if (property) {
166
- const current = property.value;
167
- previous =
168
- current?.type === 'StringLiteral' || current?.type === 'Literal'
169
- ? String(current.value)
170
- : null;
171
- if (previous === value) {
228
+ previous = literalValue(property.value);
229
+ if (sameValue(previous, value)) {
172
230
  return {file: existing, created: false, previous, changed: false};
173
231
  }
174
- property.value = j.stringLiteral(value);
232
+ property.value = node;
175
233
  } else {
176
- object.properties.push(
177
- j.objectProperty(j.identifier(leaf), j.stringLiteral(value)),
178
- );
234
+ object.properties.push(j.objectProperty(j.identifier(leaf), node));
179
235
  }
180
236
  let next = ast.toSource({quote: 'single', reuseWhitespace: true});
181
237
  if (source.endsWith('\n') && !next.endsWith('\n')) next += '\n';
@@ -43,6 +43,14 @@ export function hasLicenseNotice(dir: string): boolean;
43
43
  * file is invalid; `unresolved`: its module does not resolve from the project
44
44
  * @property {string} reason
45
45
  */
46
+ /**
47
+ * One backup set the project's list names, and what it resolves to.
48
+ * @typedef {object} IconSetBackup
49
+ * @property {string} selector the name as the list writes it
50
+ * @property {'selected' | 'ambiguous' | 'missing' | 'withdrawn'} status
51
+ * @property {DiscoveredIconSet} [set] the set, when selected
52
+ * @property {string} reason one sentence saying why
53
+ */
46
54
  /**
47
55
  * The project's icon set (FR8).
48
56
  * @typedef {object} IconSetChoice
@@ -53,7 +61,13 @@ export function hasLicenseNotice(dir: string): boolean;
53
61
  * `withdrawn`: it names a set that is installed but withdrawn (invalid, or
54
62
  * its module does not resolve), and `reason` says why
55
63
  * @property {DiscoveredIconSet} [set] the project's set, when selected
56
- * @property {string} [configured] the `experimental.iconSet` config value, when set
64
+ * @property {string} [configured] the main set `experimental.iconSet` names
65
+ * (its first entry, when it is a list), when set
66
+ * @property {IconSetBackup[]} [backups] the backup sets the list names after
67
+ * the main set, in order, when it names any
68
+ * @property {DiscoveredIconSet[]} [order] the sets a template icon is looked
69
+ * up in, in order: the main set, then each backup that resolves. Present
70
+ * only when the main set is selected
57
71
  * @property {string} reason one sentence saying why
58
72
  */
59
73
  /**
@@ -120,16 +134,39 @@ export function discoverIntegrationIconSets(integration: import("../integrations
120
134
  */
121
135
  export function withdrawnNamed(withdrawn: WithdrawnIconSet[], selector: string): WithdrawnIconSet[];
122
136
  /**
123
- * Pick the project's icon set (FR8, FR17): the set `experimental.iconSet`
124
- * names, as `"<set>"` or `"<package>/<set>"`; otherwise the only installed
137
+ * The entries of an `experimental.iconSet` value, main set first: a string is
138
+ * a one-entry list.
139
+ * @param {string | readonly string[] | undefined} configured
140
+ * @returns {string[]}
141
+ */
142
+ export function iconSetList(configured: string | readonly string[] | undefined): string[];
143
+ /**
144
+ * Installed sets the project's list leaves out: the problem, and the fix that
145
+ * adds them as backups after the list's own. Doctor and `experimental icon
146
+ * use` print the same words.
147
+ * @param {number} installed how many sets are installed
148
+ * @param {string} main the main set as the list writes it
149
+ * @param {string[]} backups the list's backups, in order
150
+ * @param {string[]} unlisted the installed sets the list leaves out
151
+ * @returns {{problem: string, command: string, fix: string}}
152
+ */
153
+ export function unlistedIconSets(installed: number, main: string, backups: string[], unlisted: string[]): {
154
+ problem: string;
155
+ command: string;
156
+ fix: string;
157
+ };
158
+ /**
159
+ * Pick the project's icon set (FR8, FR17): the main set `experimental.iconSet`
160
+ * names, as `"<set>"` or `"<package>/<set>"`, or as the first entry of a list
161
+ * whose other entries are backup sets in order; otherwise the only installed
125
162
  * set; otherwise none. A configured name that matches no valid set but an
126
163
  * installed set that was withdrawn says so, with why.
127
164
  * @param {DiscoveredIconSet[]} sets installed sets, in integration load order
128
- * @param {string | undefined} configured the `experimental.iconSet` config value
165
+ * @param {string | readonly string[] | undefined} configured the `experimental.iconSet` config value
129
166
  * @param {WithdrawnIconSet[]} [withdrawn] installed sets that were withdrawn
130
167
  * @returns {IconSetChoice}
131
168
  */
132
- export function chooseProjectIconSet(sets: DiscoveredIconSet[], configured: string | undefined, withdrawn?: WithdrawnIconSet[]): IconSetChoice;
169
+ export function chooseProjectIconSet(sets: DiscoveredIconSet[], configured: string | readonly string[] | undefined, withdrawn?: WithdrawnIconSet[]): IconSetChoice;
133
170
  /**
134
171
  * A set's full name, `<package>/<set>`.
135
172
  * @param {{package: string, name: string}} set
@@ -139,7 +176,8 @@ export function iconSetKey(set: {
139
176
  name: string;
140
177
  }): string;
141
178
  /**
142
- * Sets in tie order (FR6, FR8): the project's set first, then load order.
179
+ * Sets in tie order (FR6, FR8): the project's set and its backups first, in
180
+ * list order, then load order.
143
181
  * @param {DiscoveredIconSet[]} sets
144
182
  * @param {IconSetChoice} choice
145
183
  * @returns {DiscoveredIconSet[]}
@@ -147,6 +185,8 @@ export function iconSetKey(set: {
147
185
  export function orderIconSets(sets: DiscoveredIconSet[], choice: IconSetChoice): DiscoveredIconSet[];
148
186
  /** A license or notice file a set ships beside its data (FR15). */
149
187
  export const NOTICE_FILE_RE: RegExp;
188
+ /** The command that chooses a main set and backups, as the CLI prints it. */
189
+ export const ICON_USE_ORDER_COMMAND: "astryx experimental icon use <main> --backup <set>";
150
190
  /**
151
191
  * One installed icon set: its descriptor, its data, and where it came from.
152
192
  */
@@ -213,6 +253,24 @@ export type WithdrawnIconSet = {
213
253
  kind: "invalid" | "unresolved";
214
254
  reason: string;
215
255
  };
256
+ /**
257
+ * One backup set the project's list names, and what it resolves to.
258
+ */
259
+ export type IconSetBackup = {
260
+ /**
261
+ * the name as the list writes it
262
+ */
263
+ selector: string;
264
+ status: "selected" | "ambiguous" | "missing" | "withdrawn";
265
+ /**
266
+ * the set, when selected
267
+ */
268
+ set?: DiscoveredIconSet | undefined;
269
+ /**
270
+ * one sentence saying why
271
+ */
272
+ reason: string;
273
+ };
216
274
  /**
217
275
  * The project's icon set (FR8).
218
276
  */
@@ -230,9 +288,21 @@ export type IconSetChoice = {
230
288
  */
231
289
  set?: DiscoveredIconSet | undefined;
232
290
  /**
233
- * the `experimental.iconSet` config value, when set
291
+ * the main set `experimental.iconSet` names
292
+ * (its first entry, when it is a list), when set
234
293
  */
235
294
  configured?: string | undefined;
295
+ /**
296
+ * the backup sets the list names after
297
+ * the main set, in order, when it names any
298
+ */
299
+ backups?: IconSetBackup[] | undefined;
300
+ /**
301
+ * the sets a template icon is looked
302
+ * up in, in order: the main set, then each backup that resolves. Present
303
+ * only when the main set is selected
304
+ */
305
+ order?: DiscoveredIconSet[] | undefined;
236
306
  /**
237
307
  * one sentence saying why
238
308
  */
@@ -99,6 +99,15 @@ export function hasLicenseNotice(dir) {
99
99
  * @property {string} reason
100
100
  */
101
101
 
102
+ /**
103
+ * One backup set the project's list names, and what it resolves to.
104
+ * @typedef {object} IconSetBackup
105
+ * @property {string} selector the name as the list writes it
106
+ * @property {'selected' | 'ambiguous' | 'missing' | 'withdrawn'} status
107
+ * @property {DiscoveredIconSet} [set] the set, when selected
108
+ * @property {string} reason one sentence saying why
109
+ */
110
+
102
111
  /**
103
112
  * The project's icon set (FR8).
104
113
  * @typedef {object} IconSetChoice
@@ -109,7 +118,13 @@ export function hasLicenseNotice(dir) {
109
118
  * `withdrawn`: it names a set that is installed but withdrawn (invalid, or
110
119
  * its module does not resolve), and `reason` says why
111
120
  * @property {DiscoveredIconSet} [set] the project's set, when selected
112
- * @property {string} [configured] the `experimental.iconSet` config value, when set
121
+ * @property {string} [configured] the main set `experimental.iconSet` names
122
+ * (its first entry, when it is a list), when set
123
+ * @property {IconSetBackup[]} [backups] the backup sets the list names after
124
+ * the main set, in order, when it names any
125
+ * @property {DiscoveredIconSet[]} [order] the sets a template icon is looked
126
+ * up in, in order: the main set, then each backup that resolves. Present
127
+ * only when the main set is selected
113
128
  * @property {string} reason one sentence saying why
114
129
  */
115
130
 
@@ -407,55 +422,126 @@ export function withdrawnNamed(withdrawn, selector) {
407
422
  }
408
423
 
409
424
  /**
410
- * Pick the project's icon set (FR8, FR17): the set `experimental.iconSet`
411
- * names, as `"<set>"` or `"<package>/<set>"`; otherwise the only installed
425
+ * The entries of an `experimental.iconSet` value, main set first: a string is
426
+ * a one-entry list.
427
+ * @param {string | readonly string[] | undefined} configured
428
+ * @returns {string[]}
429
+ */
430
+ export function iconSetList(configured) {
431
+ if (configured == null) return [];
432
+ return typeof configured === 'string' ? [configured] : [...configured];
433
+ }
434
+
435
+ /**
436
+ * What one name in the list resolves to: a set, or why not.
437
+ * @param {DiscoveredIconSet[]} sets
438
+ * @param {string} selector `"<set>"` or `"<package>/<set>"`
439
+ * @param {WithdrawnIconSet[]} withdrawn
440
+ * @returns {{status: 'selected' | 'ambiguous' | 'missing' | 'withdrawn', set?: DiscoveredIconSet, reason: string}}
441
+ */
442
+ function resolveSelector(sets, selector, withdrawn) {
443
+ const exact = sets.filter(set => `${set.package}/${set.name}` === selector);
444
+ const byName =
445
+ exact.length > 0 ? exact : sets.filter(set => set.name === selector);
446
+ if (byName.length === 1) {
447
+ return {
448
+ status: 'selected',
449
+ set: byName[0],
450
+ reason: `experimental.iconSet names "${selector}".`,
451
+ };
452
+ }
453
+ if (byName.length > 1) {
454
+ return {
455
+ status: 'ambiguous',
456
+ reason: `experimental.iconSet "${selector}" names a set in ${byName.map(set => set.package).join(' and ')}; write it as "<package>/<set>".`,
457
+ };
458
+ }
459
+ const gone = withdrawnNamed(withdrawn, selector);
460
+ if (gone.length > 0) {
461
+ return {
462
+ status: 'withdrawn',
463
+ reason: `experimental.iconSet names "${selector}", which is installed but withdrawn: ${gone.map(each => each.reason).join(' ')}`,
464
+ };
465
+ }
466
+ return {
467
+ status: 'missing',
468
+ reason: `experimental.iconSet names "${selector}", but no installed set has that name${sets.length > 0 ? ` (installed: ${sets.map(iconSetKey).join(', ')})` : ''}.`,
469
+ };
470
+ }
471
+
472
+ /** The command that chooses a main set and backups, as the CLI prints it. */
473
+ export const ICON_USE_ORDER_COMMAND =
474
+ 'astryx experimental icon use <main> --backup <set>';
475
+
476
+ /**
477
+ * Installed sets the project's list leaves out: the problem, and the fix that
478
+ * adds them as backups after the list's own. Doctor and `experimental icon
479
+ * use` print the same words.
480
+ * @param {number} installed how many sets are installed
481
+ * @param {string} main the main set as the list writes it
482
+ * @param {string[]} backups the list's backups, in order
483
+ * @param {string[]} unlisted the installed sets the list leaves out
484
+ * @returns {{problem: string, command: string, fix: string}}
485
+ */
486
+ export function unlistedIconSets(installed, main, backups, unlisted) {
487
+ const them = unlisted.length === 1 ? 'it' : 'them';
488
+ const command = `astryx experimental icon use ${main}${[...backups, ...unlisted].map(each => ` --backup ${each}`).join('')}`;
489
+ return {
490
+ problem: `${installed} icon sets are installed and ${unlisted.join(', ')} ${unlisted.length === 1 ? 'is' : 'are'} not in your list`,
491
+ command,
492
+ fix: `Add ${them} as backup with \`${command}\`, or uninstall ${them}.`,
493
+ };
494
+ }
495
+
496
+ /**
497
+ * Pick the project's icon set (FR8, FR17): the main set `experimental.iconSet`
498
+ * names, as `"<set>"` or `"<package>/<set>"`, or as the first entry of a list
499
+ * whose other entries are backup sets in order; otherwise the only installed
412
500
  * set; otherwise none. A configured name that matches no valid set but an
413
501
  * installed set that was withdrawn says so, with why.
414
502
  * @param {DiscoveredIconSet[]} sets installed sets, in integration load order
415
- * @param {string | undefined} configured the `experimental.iconSet` config value
503
+ * @param {string | readonly string[] | undefined} configured the `experimental.iconSet` config value
416
504
  * @param {WithdrawnIconSet[]} [withdrawn] installed sets that were withdrawn
417
505
  * @returns {IconSetChoice}
418
506
  */
419
507
  export function chooseProjectIconSet(sets, configured, withdrawn = []) {
420
- if (configured) {
421
- const exact = sets.filter(
422
- set => `${set.package}/${set.name}` === configured,
423
- );
424
- const byName =
425
- exact.length > 0 ? exact : sets.filter(set => set.name === configured);
426
- if (byName.length === 1) {
427
- return {
428
- status: 'selected',
429
- set: byName[0],
430
- configured,
431
- reason: `experimental.iconSet names "${configured}".`,
432
- };
433
- }
434
- if (byName.length > 1) {
435
- return {
436
- status: 'ambiguous',
437
- configured,
438
- reason: `experimental.iconSet "${configured}" names a set in ${byName.map(set => set.package).join(' and ')}; write it as "<package>/<set>".`,
439
- };
440
- }
441
- const gone = withdrawnNamed(withdrawn, configured);
442
- if (gone.length > 0) {
443
- return {
444
- status: 'withdrawn',
445
- configured,
446
- reason: `experimental.iconSet names "${configured}", which is installed but withdrawn: ${gone.map(each => each.reason).join(' ')}`,
447
- };
448
- }
449
- return {
450
- status: 'missing',
451
- configured,
452
- reason: `experimental.iconSet names "${configured}", but no installed set has that name${sets.length > 0 ? ` (installed: ${sets.map(iconSetKey).join(', ')})` : ''}.`,
508
+ const [main, ...rest] = iconSetList(configured);
509
+ if (main) {
510
+ const resolved = resolveSelector(sets, main, withdrawn);
511
+ /** @type {IconSetBackup[]} */
512
+ const backups = rest.map(selector => ({
513
+ selector,
514
+ ...resolveSelector(sets, selector, withdrawn),
515
+ }));
516
+ /** @type {IconSetChoice} */
517
+ const choice = {
518
+ status: resolved.status,
519
+ ...(resolved.set ? {set: resolved.set} : {}),
520
+ configured: main,
521
+ ...(backups.length > 0 ? {backups} : {}),
522
+ reason: resolved.reason,
453
523
  };
524
+ if (resolved.set) {
525
+ /** @type {DiscoveredIconSet[]} */
526
+ const order = [resolved.set];
527
+ for (const backup of backups) {
528
+ if (backup.set && !order.includes(backup.set)) order.push(backup.set);
529
+ }
530
+ choice.order = order;
531
+ if (order.length > 1) {
532
+ choice.reason = `experimental.iconSet names "${main}", with ${order
533
+ .slice(1)
534
+ .map(set => `"${iconSetKey(set)}"`)
535
+ .join(', then ')} as backup.`;
536
+ }
537
+ }
538
+ return choice;
454
539
  }
455
540
  if (sets.length === 1) {
456
541
  return {
457
542
  status: 'selected',
458
543
  set: sets[0],
544
+ order: [sets[0]],
459
545
  reason: `"${iconSetKey(sets[0])}" is the only installed icon set.`,
460
546
  };
461
547
  }
@@ -464,7 +550,7 @@ export function chooseProjectIconSet(sets, configured, withdrawn = []) {
464
550
  }
465
551
  return {
466
552
  status: 'ambiguous',
467
- reason: `${sets.length} icon sets are installed (${sets.map(iconSetKey).join(', ')}) and astryx.config sets no experimental.iconSet.`,
553
+ reason: `${sets.length} icon sets are installed (${sets.map(iconSetKey).join(', ')}) and astryx.config sets no experimental.iconSet, so none is your main set.`,
468
554
  };
469
555
  }
470
556
 
@@ -477,13 +563,13 @@ export function iconSetKey(set) {
477
563
  }
478
564
 
479
565
  /**
480
- * Sets in tie order (FR6, FR8): the project's set first, then load order.
566
+ * Sets in tie order (FR6, FR8): the project's set and its backups first, in
567
+ * list order, then load order.
481
568
  * @param {DiscoveredIconSet[]} sets
482
569
  * @param {IconSetChoice} choice
483
570
  * @returns {DiscoveredIconSet[]}
484
571
  */
485
572
  export function orderIconSets(sets, choice) {
486
- const first = choice.set;
487
- if (!first) return [...sets];
488
- return [first, ...sets.filter(set => set !== first)];
573
+ const first = choice.order ?? (choice.set ? [choice.set] : []);
574
+ return [...first, ...sets.filter(set => !first.includes(set))];
489
575
  }
@@ -11,5 +11,51 @@ export function templateIconNotes(loaded: any, packageDir: string): Promise<Arra
11
11
  code: string;
12
12
  message: string;
13
13
  }>>;
14
+ /**
15
+ * One item the undeclared-icon check could not judge.
16
+ * @typedef {object} TemplateIconUnchecked
17
+ * @property {string} file the template, relative to the package
18
+ * @property {string} icon the imported name
19
+ * @property {string} module the module it is imported from
20
+ * @property {string} reason why, and what would let the check judge it
21
+ */
22
+ /**
23
+ * One note per icon a template imports but does not declare in `icons`, and
24
+ * each import the check cannot judge. Only a package whose templates declare
25
+ * `icons` gets either: a package that never labels its icons sees no change.
26
+ * @param {any} loaded a loaded integration (absolute roots)
27
+ * @param {string} packageDir
28
+ * @returns {Promise<{notes: Array<{code: string, message: string}>, unchecked: TemplateIconUnchecked[]}>}
29
+ */
30
+ export function templateIconUndeclaredNotes(loaded: any, packageDir: string): Promise<{
31
+ notes: Array<{
32
+ code: string;
33
+ message: string;
34
+ }>;
35
+ unchecked: TemplateIconUnchecked[];
36
+ }>;
14
37
  /** A template `icons` key its source never imports. */
15
38
  export const TEMPLATE_ICON_NOT_IMPORTED: "template_icon_not_imported";
39
+ /** An icon a template imports that its `icons` does not declare. */
40
+ export const TEMPLATE_ICON_UNDECLARED: "template_icon_undeclared";
41
+ /**
42
+ * One item the undeclared-icon check could not judge.
43
+ */
44
+ export type TemplateIconUnchecked = {
45
+ /**
46
+ * the template, relative to the package
47
+ */
48
+ file: string;
49
+ /**
50
+ * the imported name
51
+ */
52
+ icon: string;
53
+ /**
54
+ * the module it is imported from
55
+ */
56
+ module: string;
57
+ /**
58
+ * why, and what would let the check judge it
59
+ */
60
+ reason: string;
61
+ };