@astryxdesign/cli 0.7.4 → 0.7.5-canary.2a50a80

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 (161) hide show
  1. package/README.md +18 -18
  2. package/api/icon/_adapter.d.mts +3 -2
  3. package/api/icon/_adapter.mjs +16 -3
  4. package/api/icon/_authoring.d.mts +5 -1
  5. package/api/icon/_authoring.mjs +478 -63
  6. package/api/icon/_options.d.mts +11 -0
  7. package/api/icon/_options.mjs +39 -4
  8. package/api/icon/_records.d.mts +19 -0
  9. package/api/icon/_records.mjs +25 -0
  10. package/api/icon/add/add.d.mts +3 -3
  11. package/api/icon/add/add.mjs +227 -14
  12. package/api/icon/all-or-nothing.test.mjs +283 -0
  13. package/api/icon/detail/detail.mjs +2 -13
  14. package/api/icon/error-codes.test.mjs +14 -7
  15. package/api/icon/icon.d.mts +2 -2
  16. package/api/icon/icon.doc.mjs +30 -2
  17. package/api/icon/icon.mjs +57 -8
  18. package/api/icon/icon.test.mjs +133 -1
  19. package/api/icon/icon.type.d.mts +126 -1
  20. package/api/icon/icon.type.mjs +67 -3
  21. package/api/icon/iconAdd.doc.mjs +22 -6
  22. package/api/icon/iconMap.doc.mjs +24 -8
  23. package/api/icon/iconNewDefinition.doc.mjs +2 -2
  24. package/api/icon/iconNewSet.doc.mjs +30 -2
  25. package/api/icon/iconUse.doc.mjs +4 -1
  26. package/api/icon/map/map.d.mts +4 -4
  27. package/api/icon/map/map.mjs +134 -9
  28. package/api/icon/new-definition/new-definition.mjs +6 -2
  29. package/api/icon/new-set/new-set.mjs +2 -2
  30. package/api/icon/new-set/new-set.test.mjs +60 -10
  31. package/api/icon/option-pairs.test.mjs +368 -0
  32. package/api/icon/search/search.d.mts +10 -0
  33. package/api/icon/search/search.mjs +55 -14
  34. package/api/icon/use/use.mjs +2 -13
  35. package/api/integration/add-helpers.d.mts +15 -1
  36. package/api/integration/add-helpers.mjs +1 -1
  37. package/api/integration/validate-integration.type.d.mts +3 -2
  38. package/api/integration/validate-integration.type.mjs +3 -2
  39. package/api/template/template.type.d.mts +2 -1
  40. package/api/template/template.type.mjs +1 -1
  41. package/assets/discover/official-packages.json +4 -0
  42. package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
  43. package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
  44. package/assets/docs/tree/icon-sets.doc.mjs +50 -20
  45. package/assets/icons/definitions/activity.doc.mjs +1 -1
  46. package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
  47. package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
  48. package/assets/icons/definitions/alignStart.doc.mjs +10 -0
  49. package/assets/icons/definitions/archive.doc.mjs +1 -1
  50. package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
  51. package/assets/icons/definitions/attach.doc.mjs +1 -1
  52. package/assets/icons/definitions/audio.doc.mjs +1 -1
  53. package/assets/icons/definitions/cart.doc.mjs +1 -1
  54. package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
  55. package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
  56. package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
  57. package/assets/icons/definitions/close.doc.mjs +1 -1
  58. package/assets/icons/definitions/collapse.doc.mjs +1 -1
  59. package/assets/icons/definitions/compose.doc.mjs +1 -1
  60. package/assets/icons/definitions/conversation.doc.mjs +1 -1
  61. package/assets/icons/definitions/copy.doc.mjs +1 -1
  62. package/assets/icons/definitions/cpu.doc.mjs +9 -0
  63. package/assets/icons/definitions/database.doc.mjs +1 -1
  64. package/assets/icons/definitions/desktop.doc.mjs +1 -1
  65. package/assets/icons/definitions/discount.doc.mjs +1 -1
  66. package/assets/icons/definitions/download.doc.mjs +1 -1
  67. package/assets/icons/definitions/emoji.doc.mjs +1 -1
  68. package/assets/icons/definitions/error.doc.mjs +1 -1
  69. package/assets/icons/definitions/expand.doc.mjs +1 -1
  70. package/assets/icons/definitions/experiment.doc.mjs +1 -1
  71. package/assets/icons/definitions/externalLink.doc.mjs +7 -1
  72. package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
  73. package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
  74. package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
  75. package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
  76. package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
  77. package/assets/icons/definitions/gitFork.doc.mjs +9 -0
  78. package/assets/icons/definitions/info.doc.mjs +1 -1
  79. package/assets/icons/definitions/location.doc.mjs +1 -1
  80. package/assets/icons/definitions/mention.doc.mjs +1 -1
  81. package/assets/icons/definitions/menu.doc.mjs +1 -1
  82. package/assets/icons/definitions/microphone.doc.mjs +1 -1
  83. package/assets/icons/definitions/mobile.doc.mjs +1 -1
  84. package/assets/icons/definitions/money.doc.mjs +1 -1
  85. package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
  86. package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
  87. package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
  88. package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
  89. package/assets/icons/definitions/panelRight.doc.mjs +10 -0
  90. package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
  91. package/assets/icons/definitions/redo.doc.mjs +1 -1
  92. package/assets/icons/definitions/refresh.doc.mjs +1 -1
  93. package/assets/icons/definitions/rotate.doc.mjs +9 -0
  94. package/assets/icons/definitions/scale.doc.mjs +10 -0
  95. package/assets/icons/definitions/search.doc.mjs +1 -1
  96. package/assets/icons/definitions/send.doc.mjs +1 -1
  97. package/assets/icons/definitions/settings.doc.mjs +1 -1
  98. package/assets/icons/definitions/star.doc.mjs +1 -1
  99. package/assets/icons/definitions/stop.doc.mjs +1 -1
  100. package/assets/icons/definitions/success.doc.mjs +1 -1
  101. package/assets/icons/definitions/textCase.doc.mjs +9 -0
  102. package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
  103. package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
  104. package/assets/icons/definitions/trendDown.doc.mjs +7 -1
  105. package/assets/icons/definitions/trendUp.doc.mjs +1 -1
  106. package/assets/icons/definitions/undo.doc.mjs +1 -1
  107. package/assets/icons/definitions/upload.doc.mjs +1 -1
  108. package/assets/icons/definitions/userAdd.doc.mjs +1 -1
  109. package/assets/icons/definitions/warning.doc.mjs +1 -1
  110. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
  111. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
  112. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
  113. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
  114. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
  115. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
  116. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
  117. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
  118. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
  119. package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
  120. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
  121. package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
  122. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
  123. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
  124. package/authoring/doctypes/icon-set/parse.d.mts +1 -0
  125. package/authoring/doctypes/icon-set/parse.mjs +1 -0
  126. package/authoring/doctypes/icon-set/type.ts +5 -0
  127. package/authoring/doctypes/template/template.doc.mjs +1 -1
  128. package/authoring/doctypes/template/type.ts +2 -1
  129. package/clients/cli/commands/doctor.mjs +16 -17
  130. package/clients/cli/commands/experimental/icon.mjs +167 -35
  131. package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
  132. package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
  133. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
  134. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
  135. package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
  136. package/clients/cli/commands/experimental.doc.mjs +2 -1
  137. package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
  138. package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
  139. package/clients/cli/commands/icon.test.mjs +1 -1
  140. package/clients/cli/commands/template.mjs +4 -1
  141. package/foundation/discovery/component-discovery.d.mts +2 -1
  142. package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
  143. package/foundation/discovery/component-discovery.mjs +13 -7
  144. package/foundation/discovery/icon-set-checks.d.mts +43 -9
  145. package/foundation/discovery/icon-set-checks.mjs +296 -21
  146. package/foundation/discovery/icon-set-checks.test.mjs +125 -12
  147. package/foundation/discovery/icon-set-writer.d.mts +192 -3
  148. package/foundation/discovery/icon-set-writer.mjs +608 -34
  149. package/foundation/discovery/icon-set-writer.test.mjs +26 -0
  150. package/foundation/discovery/module-exports.mjs +82 -25
  151. package/foundation/discovery/module-exports.test.mjs +38 -1
  152. package/foundation/discovery/package-exports.d.mts +13 -0
  153. package/foundation/discovery/package-exports.mjs +40 -1
  154. package/foundation/discovery/template-icons.d.mts +6 -0
  155. package/foundation/discovery/template-icons.mjs +98 -10
  156. package/foundation/discovery/template-icons.test.mjs +103 -0
  157. package/foundation/doc-compiler/tree.mjs +3 -1
  158. package/foundation/response/response-types.doc.mjs +25 -1
  159. package/foundation/text/string-utils.mjs +33 -0
  160. package/foundation/text/string-utils.test.mjs +17 -0
  161. package/package.json +9 -9
@@ -7,6 +7,17 @@
7
7
  * @param {Record<string, unknown>} options
8
8
  */
9
9
  export function refuseOtherOptions(kind: keyof typeof ALLOWED, options: Record<string, unknown>): void;
10
+ /**
11
+ * Refuse two options given together when the call would ignore one of them
12
+ * (spec:AST-042 FR5): each pair names the two as the caller writes them
13
+ * (`--list`, `a query`), and `given` says which the caller passed. A pair is
14
+ * refused with `ERR_INVALID_OPTION`, in the order the list gives, before any
15
+ * file is written.
16
+ * @param {Record<string, boolean>} given each option's label, and whether it was passed
17
+ * @param {ReadonlyArray<readonly [string, string]>} pairs
18
+ */
19
+ export function refuseIgnoredPairs(given: Record<string, boolean>, pairs: ReadonlyArray<readonly [string, string]>): void;
20
+ export function passed(value: unknown): boolean;
10
21
  /** The options each call takes. */
11
22
  declare const ALLOWED: {
12
23
  'icon-set': Set<string>;
@@ -1,10 +1,11 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file The options each icon authoring call takes; any other is refused, so
5
- * a caller never gets a silent success that did not do what it asked.
4
+ * @file The options each icon call takes, and the option pairs it cannot
5
+ * honor together; either is refused, so a caller never gets a silent success
6
+ * that did not do what it asked (spec:AST-042 FR5).
6
7
  *
7
- * @position api/icon — read by api/icon/new-set and api/icon/new-definition
8
+ * @position api/icon — read by every icon leaf
8
9
  */
9
10
 
10
11
  import {AstryxError} from '../error.mjs';
@@ -12,7 +13,16 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
12
13
 
13
14
  /** The options each call takes. */
14
15
  const ALLOWED = {
15
- 'icon-set': new Set(['cwd', 'dryRun', 'from', 'exclude']),
16
+ 'icon-set': new Set([
17
+ 'cwd',
18
+ 'dryRun',
19
+ 'from',
20
+ 'exclude',
21
+ 'variants',
22
+ 'defaultVariant',
23
+ 'displayName',
24
+ 'description',
25
+ ]),
16
26
  'icon-definition': new Set([
17
27
  'cwd',
18
28
  'dryRun',
@@ -39,3 +49,28 @@ export function refuseOtherOptions(kind, options) {
39
49
  }
40
50
  }
41
51
  }
52
+
53
+ /**
54
+ * Refuse two options given together when the call would ignore one of them
55
+ * (spec:AST-042 FR5): each pair names the two as the caller writes them
56
+ * (`--list`, `a query`), and `given` says which the caller passed. A pair is
57
+ * refused with `ERR_INVALID_OPTION`, in the order the list gives, before any
58
+ * file is written.
59
+ * @param {Record<string, boolean>} given each option's label, and whether it was passed
60
+ * @param {ReadonlyArray<readonly [string, string]>} pairs
61
+ */
62
+ export function refuseIgnoredPairs(given, pairs) {
63
+ for (const [a, b] of pairs) {
64
+ if (given[a] && given[b]) {
65
+ throw new AstryxError(
66
+ `${a} and ${b} cannot be used together`,
67
+ undefined,
68
+ ERROR_CODES.ERR_INVALID_OPTION,
69
+ );
70
+ }
71
+ }
72
+ }
73
+
74
+ /** @param {unknown} value whether an option was passed at all */
75
+ export const passed = value =>
76
+ value !== undefined && value !== null && value !== false && value !== '';
@@ -29,6 +29,24 @@ export function withdrawnReason(withdrawn: Array<{
29
29
  package: string;
30
30
  reason: string;
31
31
  }>, selector: string): string | null;
32
+ /**
33
+ * The one error every icon entry point gives for a set selector that names
34
+ * no valid installed set (AST-084 FR17): withdrawn, with its reason, when it
35
+ * names an installed set that was withdrawn; else not installed. Both are
36
+ * `ERR_NOT_FOUND`, with the closest valid sets as suggestions.
37
+ * @param {Array<{name: string, package: string}>} sets the valid sets
38
+ * @param {Array<{name: string, package: string, reason: string}>} withdrawn
39
+ * @param {string} selector
40
+ * @returns {AstryxError}
41
+ */
42
+ export function unusableSet(sets: Array<{
43
+ name: string;
44
+ package: string;
45
+ }>, withdrawn: Array<{
46
+ name: string;
47
+ package: string;
48
+ reason: string;
49
+ }>, selector: string): AstryxError;
32
50
  /**
33
51
  * Suggestions for a name that matched nothing: the closest candidates first.
34
52
  * @param {string} wanted
@@ -44,4 +62,5 @@ export type DiscoveredIconSet = import("../../foundation/discovery/icon-set-disc
44
62
  export type IconSetIcon = import("../../authoring/doctypes/icon-set/type").IconSetIcon;
45
63
  export type IconRecord = import("./icon.type.mjs").IconRecord;
46
64
  export type IconMatchEntry = import("./icon.type.mjs").IconMatchEntry;
65
+ import { AstryxError } from '../error.mjs';
47
66
  export { iconRecord, importLine, leadingReading, matchIcon, rankIcons, scoreIcon } from "./_adapter.mjs";
@@ -11,6 +11,8 @@
11
11
  * @position api/icon — shared by the search, detail, and list leaves
12
12
  */
13
13
 
14
+ import {AstryxError} from '../error.mjs';
15
+ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
14
16
  import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
15
17
  export {
16
18
  iconRecord,
@@ -53,6 +55,29 @@ export function withdrawnReason(withdrawn, selector) {
53
55
  : null;
54
56
  }
55
57
 
58
+ /**
59
+ * The one error every icon entry point gives for a set selector that names
60
+ * no valid installed set (AST-084 FR17): withdrawn, with its reason, when it
61
+ * names an installed set that was withdrawn; else not installed. Both are
62
+ * `ERR_NOT_FOUND`, with the closest valid sets as suggestions.
63
+ * @param {Array<{name: string, package: string}>} sets the valid sets
64
+ * @param {Array<{name: string, package: string, reason: string}>} withdrawn
65
+ * @param {string} selector
66
+ * @returns {AstryxError}
67
+ */
68
+ export function unusableSet(sets, withdrawn, selector) {
69
+ return new AstryxError(
70
+ withdrawnReason(withdrawn, selector) ??
71
+ `No installed icon set named "${selector}"`,
72
+ closest(
73
+ selector,
74
+ sets.flatMap(each => [each.name, `${each.package}/${each.name}`]),
75
+ 'installed icon set',
76
+ ),
77
+ ERROR_CODES.ERR_NOT_FOUND,
78
+ );
79
+ }
80
+
56
81
  /**
57
82
  * Suggestions for a name that matched nothing: the closest candidates first.
58
83
  * @param {string} wanted
@@ -7,8 +7,8 @@
7
7
  * Experimental (spec:AST-017 FR27): may change or be removed in a patch
8
8
  * release.
9
9
  * @experimental
10
- * @param {string} exportName the export the set exposes the icon as
10
+ * @param {string | undefined} exportName the export the set exposes the icon as; absent with `all`
11
11
  * @param {import('../icon.type.mjs').IconAddOptions} options
12
- * @returns {Promise<import('../icon.type.mjs').IconAddResponse | import('../icon.type.mjs').IconDefinitionMatchesResponse>}
12
+ * @returns {Promise<import('../icon.type.mjs').IconAddResponse | import('../icon.type.mjs').IconDefinitionMatchesResponse | import('../icon.type.mjs').IconAddVariantsResponse>}
13
13
  */
14
- export function iconAdd(exportName: string, options: import("../icon.type.mjs").IconAddOptions): Promise<import("../icon.type.mjs").IconAddResponse | import("../icon.type.mjs").IconDefinitionMatchesResponse>;
14
+ export function iconAdd(exportName: string | undefined, options: import("../icon.type.mjs").IconAddOptions): Promise<import("../icon.type.mjs").IconAddResponse | import("../icon.type.mjs").IconDefinitionMatchesResponse | import("../icon.type.mjs").IconAddVariantsResponse>;
@@ -38,7 +38,12 @@ import {
38
38
  exportValueKind,
39
39
  generatedModulePath,
40
40
  generatedNamesOf,
41
+ generatedOrigins,
42
+ iconModulePackage,
41
43
  iconNaming,
44
+ localSourceNote,
45
+ definitionNameOf,
46
+ libraryIcons,
42
47
  modulePrefix,
43
48
  variantExportName,
44
49
  rankIcons,
@@ -50,6 +55,7 @@ import {
50
55
  writeIconSetData,
51
56
  refuseOutsideProject,
52
57
  } from '../_adapter.mjs';
58
+ import {passed, refuseIgnoredPairs} from '../_options.mjs';
53
59
 
54
60
  /** The lowest score a definition match needs: an exact word or name. */
55
61
  const FIT_FLOOR = 80;
@@ -63,24 +69,72 @@ const MATCH_LIMIT = 10;
63
69
  * Experimental (spec:AST-017 FR27): may change or be removed in a patch
64
70
  * release.
65
71
  * @experimental
66
- * @param {string} exportName the export the set exposes the icon as
72
+ * @param {string | undefined} exportName the export the set exposes the icon as; absent with `all`
67
73
  * @param {import('../icon.type.mjs').IconAddOptions} options
68
- * @returns {Promise<import('../icon.type.mjs').IconAddResponse | import('../icon.type.mjs').IconDefinitionMatchesResponse>}
74
+ * @returns {Promise<import('../icon.type.mjs').IconAddResponse | import('../icon.type.mjs').IconDefinitionMatchesResponse | import('../icon.type.mjs').IconAddVariantsResponse>}
69
75
  */
70
76
  export async function iconAdd(exportName, options) {
71
77
  const {
72
78
  cwd = process.cwd(),
73
79
  from,
74
80
  set: selector,
75
- definition,
81
+ definition: givenDefinition,
76
82
  newDefinition,
77
83
  description,
78
84
  words,
79
85
  useDefault = false,
80
86
  variant,
81
87
  id: givenId,
88
+ all = false,
82
89
  } = options ?? {};
83
90
  refuseOutsideProject(cwd, 'experimental icon add', 'the icon-set package');
91
+ // `--all` adds a declared variant to existing icons, so it names no icon
92
+ // and maps nothing; a description and words describe only a new
93
+ // definition (spec:AST-042 FR5).
94
+ refuseIgnoredPairs(
95
+ {
96
+ 'an export name': passed(exportName),
97
+ '--definition': passed(givenDefinition),
98
+ '--new-definition': passed(newDefinition),
99
+ '--description': passed(description),
100
+ '--words': passed(words),
101
+ '--default': passed(useDefault),
102
+ '--id': passed(givenId),
103
+ '--all': passed(all),
104
+ },
105
+ [
106
+ ['--all', 'an export name'],
107
+ ['--all', '--definition'],
108
+ ['--all', '--new-definition'],
109
+ ['--all', '--description'],
110
+ ['--all', '--words'],
111
+ ['--all', '--default'],
112
+ ['--all', '--id'],
113
+ ['--definition', '--new-definition'],
114
+ ['--definition', '--description'],
115
+ ['--definition', '--words'],
116
+ ],
117
+ );
118
+ for (const [flag, value] of /** @type {const} */ ([
119
+ ['--description', description],
120
+ ['--words', words],
121
+ ])) {
122
+ if (passed(value) && !passed(newDefinition)) {
123
+ throw new AstryxError(
124
+ `${flag} describes a new definition, so it needs --new-definition`,
125
+ [
126
+ {
127
+ name: `--new-definition <name> --description '<what it is for>' --words a,b`,
128
+ reason: 'add your own definition',
129
+ },
130
+ ],
131
+ ERROR_CODES.ERR_INVALID_OPTION,
132
+ );
133
+ }
134
+ }
135
+ if (all) {
136
+ return authoring(() => addVariantForAll({cwd, from, selector, variant}));
137
+ }
84
138
  return authoring(async () => {
85
139
  if (
86
140
  typeof exportName !== 'string' ||
@@ -99,15 +153,13 @@ export async function iconAdd(exportName, options) {
99
153
  ERROR_CODES.ERR_MISSING_ARGUMENT,
100
154
  );
101
155
  }
102
- if (definition != null && newDefinition != null) {
103
- throw new AstryxError(
104
- 'Pass --definition or --new-definition, not both.',
105
- undefined,
106
- ERROR_CODES.ERR_INVALID_ARGUMENT,
107
- );
108
- }
109
156
  const where = await findLocalIconSet(cwd, selector);
110
157
  const {packageDir, set} = where;
158
+ // The docs' kebab id (`eye-slash`) names the same definition.
159
+ const definition =
160
+ givenDefinition == null
161
+ ? undefined
162
+ : definitionNameOf(givenDefinition, mappableDefinitions(set));
111
163
  const source = resolveIconSource(from, where);
112
164
  const sourceExport = useDefault ? 'default' : exportName;
113
165
  assertIconExport(source.file, source.module, sourceExport);
@@ -126,9 +178,12 @@ export async function iconAdd(exportName, options) {
126
178
  const module = set.data.module;
127
179
  // A library prefix every icon export shares (`feather` in `featherEye`)
128
180
  // is left out of the id and the set's export name, as the bulk wrap does.
129
- const shared = useDefault
130
- ? []
131
- : modulePrefix(source.file, {adapter: Boolean(set.data.adapter)});
181
+ // A ./ path is the author's own files, named as written: never a library
182
+ // prefix (`CheckDouble` and `CheckDoubleSolid` share `check`).
183
+ const shared =
184
+ useDefault || source.module.startsWith('./')
185
+ ? []
186
+ : modulePrefix(source.file, {adapter: Boolean(set.data.adapter)});
132
187
  const nameWords = iconIdOf(exportName).split('-');
133
188
  const prefix =
134
189
  shared.length > 0 &&
@@ -305,7 +360,15 @@ export async function iconAdd(exportName, options) {
305
360
  JSON.stringify(next) !== JSON.stringify(set.data) ||
306
361
  created != null ||
307
362
  generatedChanged;
308
- const note = setModuleNote(set, where, generated, setName);
363
+ // A ./ file publishes only when package.json `files` lists it; the
364
+ // author adds it (architecture:cli-surface INV16).
365
+ const note =
366
+ [
367
+ localSourceNote(packageDir, source.module),
368
+ setModuleNote(set, where, generated, setName),
369
+ ]
370
+ .filter(Boolean)
371
+ .join(' ') || null;
309
372
  return {
310
373
  type: /** @type {const} */ ('icon.add'),
311
374
  data: {
@@ -414,3 +477,153 @@ function definitionMatches(set, exportName, from, id) {
414
477
  },
415
478
  };
416
479
  }
480
+
481
+ /**
482
+ * `--all`: add one variant for every icon of the set whose library export
483
+ * has a counterpart in `from` with the same id (`TrashIcon` in the solid
484
+ * module is the solid variant of `trash`), in one write.
485
+ * @param {{cwd: string, from: string | undefined, selector: string | undefined, variant: string | undefined}} args
486
+ * @returns {Promise<import('../icon.type.mjs').IconAddVariantsResponse>}
487
+ */
488
+ async function addVariantForAll({cwd, from, selector, variant}) {
489
+ if (variant == null || variant === '') {
490
+ throw new AstryxError(
491
+ '--all adds one variant for every icon: pass --variant with the variant, such as solid.',
492
+ undefined,
493
+ ERROR_CODES.ERR_MISSING_ARGUMENT,
494
+ );
495
+ }
496
+ if (typeof from !== 'string' || from.trim() === '') {
497
+ throw new AstryxError(
498
+ 'Pass --from with the module that exports the variant, such as @heroicons/react/24/solid.',
499
+ undefined,
500
+ ERROR_CODES.ERR_MISSING_ARGUMENT,
501
+ );
502
+ }
503
+ const where = await findLocalIconSet(cwd, selector);
504
+ const {packageDir, set} = where;
505
+ const declared = set.data.variants ?? [];
506
+ if (!declared.includes(variant)) {
507
+ throw new AstryxError(
508
+ `Icon set "${set.name}" declares no variant "${variant}"${declared.length > 0 ? ` (it declares ${declared.join(', ')})` : ''}. Declare it first.`,
509
+ [
510
+ {
511
+ name: `astryx experimental icon new-set ${set.name} --from <its library> --variants ${[...new Set([...(declared.length > 0 ? declared : ['<default>']), variant])].join(',')}`,
512
+ reason: 'declare the variants',
513
+ },
514
+ ],
515
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
516
+ );
517
+ }
518
+ if (set.data.default?.variant === variant) {
519
+ throw new AstryxError(
520
+ `"${variant}" is the set's default variant: each icon's own export already draws it.`,
521
+ undefined,
522
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
523
+ );
524
+ }
525
+ const source = resolveIconSource(from, where);
526
+ const found = libraryIcons(source.file, {adapter: Boolean(set.data.adapter)});
527
+ const byId = new Map(found.map(each => [each.id, each]));
528
+ // An existing icon is known by the library export it re-exports, then by
529
+ // its own export, then by its id: an icon whose id or name an older rule
530
+ // wrote (`squares-2-x2`, `Squares2X2Icon`) still meets its variant
531
+ // (`HiSquares2X2Icon` in the solid module).
532
+ const byLibraryExport = new Map(found.map(each => [each.export, each]));
533
+ const byName = new Map(found.map(each => [each.name, each]));
534
+ const origins = generatedOrigins(
535
+ packageDir,
536
+ generatedModulePath(set, packageDir),
537
+ );
538
+ // Only icons from the same package as the variant module can have a
539
+ // variant there: an icon from your own `./` file, or from another library,
540
+ // is left as it is and never listed as missing.
541
+ const variantPackage = iconModulePackage(source.module);
542
+ const generated = generatedModulePath(set, packageDir);
543
+ /** @type {import('../../../foundation/discovery/icon-set-writer.mjs').GeneratedIcon[]} */
544
+ const toWrite = [];
545
+ /** @type {string[]} */
546
+ const added = [];
547
+ /** @type {string[]} */
548
+ const already = [];
549
+ /** @type {string[]} */
550
+ const missing = [];
551
+ const icons = set.data.icons.map(icon => {
552
+ const origin = origins.get(icon.export);
553
+ if (origin && iconModulePackage(origin.module) !== variantPackage) {
554
+ return icon;
555
+ }
556
+ const librarySource =
557
+ origin && origin.source !== 'default' ? origin.source : undefined;
558
+ const match =
559
+ (librarySource ? byLibraryExport.get(librarySource) : undefined) ??
560
+ byName.get(icon.export) ??
561
+ byId.get(icon.id);
562
+ if (!match) {
563
+ missing.push(icon.id);
564
+ return icon;
565
+ }
566
+ if (match.adapt && !set.data.adapter) {
567
+ missing.push(icon.id);
568
+ return icon;
569
+ }
570
+ const name = variantExportName(icon.export, variant);
571
+ const variants = [...(icon.variants ?? [])];
572
+ if (variants.some(each => each.variant === variant)) {
573
+ already.push(icon.id);
574
+ return icon;
575
+ }
576
+ toWrite.push({
577
+ name,
578
+ from: source.module,
579
+ source: match.export,
580
+ adapt: match.adapt,
581
+ });
582
+ variants.push({variant, export: name});
583
+ added.push(icon.id);
584
+ return {...icon, variants};
585
+ });
586
+ if (added.length === 0 && already.length === 0) {
587
+ throw new AstryxError(
588
+ `"${source.module}" exports no icon with the id of an icon in "${set.name}". Pass the module that exports the ${variant} variant under the same names.`,
589
+ undefined,
590
+ ERROR_CODES.ERR_NOT_FOUND,
591
+ );
592
+ }
593
+ const next = {
594
+ ...set.data,
595
+ ...(set.data.generated ? {} : {generated}),
596
+ ...(set.data.themeMap ? {} : {themeMap: THEME_MAP_NAME}),
597
+ icons,
598
+ };
599
+ /** @type {string[]} */
600
+ const files = [];
601
+ const written = writeGeneratedIcons(packageDir, generated, next, toWrite);
602
+ files.push(...written.files);
603
+ const dataChanged = JSON.stringify(next) !== JSON.stringify(set.data);
604
+ if (dataChanged) {
605
+ try {
606
+ writeIconSetData(set, next);
607
+ } catch (error) {
608
+ written.undo();
609
+ throw error;
610
+ }
611
+ files.push(
612
+ path.relative(packageDir, set.dataPath).split(path.sep).join('/'),
613
+ );
614
+ }
615
+ return {
616
+ type: /** @type {const} */ ('icon.addVariants'),
617
+ data: {
618
+ set: set.name,
619
+ package: set.package,
620
+ variant,
621
+ from: source.module,
622
+ added: added.length,
623
+ already: already.length,
624
+ missing,
625
+ files,
626
+ changed: dataChanged || written.changed,
627
+ },
628
+ };
629
+ }