@astryxdesign/cli 0.7.11-canary.ec945c9 → 0.7.11

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 (64) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/api/build/kit/rank.mjs +4 -21
  3. package/api/build/kit/words.d.mts +0 -1
  4. package/api/build/kit/words.mjs +1 -1
  5. package/api/icon/_adapter.d.mts +2 -3
  6. package/api/icon/_adapter.mjs +2 -8
  7. package/api/icon/_authoring.d.mts +0 -1
  8. package/api/icon/_authoring.mjs +66 -586
  9. package/api/icon/_records.d.mts +1 -1
  10. package/api/icon/_records.mjs +0 -1
  11. package/api/icon/add/add.mjs +38 -224
  12. package/api/icon/icon.type.d.mts +2 -22
  13. package/api/icon/icon.type.mjs +2 -6
  14. package/api/icon/iconAdd.doc.mjs +2 -2
  15. package/api/icon/iconNewDefinition.doc.mjs +2 -3
  16. package/api/icon/iconNewSet.doc.mjs +4 -4
  17. package/api/icon/search/search.mjs +9 -10
  18. package/api/integration/add-helpers.d.mts +1 -11
  19. package/api/integration/add-helpers.mjs +2 -5
  20. package/api/integration/authoring-checks.d.mts +2 -0
  21. package/api/integration/authoring-checks.mjs +6 -1
  22. package/api/logger.mjs +1 -2
  23. package/api/swizzle/_adapter.d.mts +0 -1
  24. package/api/swizzle/_adapter.mjs +1 -4
  25. package/api/swizzle/copy/copy.d.mts +43 -2
  26. package/api/swizzle/copy/copy.mjs +314 -194
  27. package/api/swizzle/swizzle.d.mts +2 -0
  28. package/api/swizzle/swizzle.doc.mjs +4 -8
  29. package/api/swizzle/swizzle.mjs +7 -3
  30. package/api/swizzle/swizzle.type.d.mts +1 -1
  31. package/api/swizzle/swizzle.type.mjs +2 -2
  32. package/assets/discover/official-packages.json +0 -12
  33. package/assets/docs/tree/icon-sets.doc.mjs +5 -11
  34. package/assets/templates/pages/file-explorer/page.tsx +79 -103
  35. package/assets/templates/pages/table-grouped/page.tsx +232 -160
  36. package/assets/templates/pages/table-grouped/template.doc.mjs +2 -0
  37. package/assets/templates/pages/theme-showcase/page.tsx +792 -724
  38. package/assets/templates/pages/theme-showcase/template.doc.mjs +5 -4
  39. package/clients/cli/commands/experimental/icon.mjs +10 -31
  40. package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
  41. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -2
  42. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
  43. package/clients/cli/commands/swizzle.doc.mjs +3 -6
  44. package/clients/cli/commands/swizzle.mjs +9 -8
  45. package/foundation/discovery/component-loader.d.mts +1 -1
  46. package/foundation/discovery/doc-types.mjs +2 -9
  47. package/foundation/discovery/icon-ranking.d.mts +3 -27
  48. package/foundation/discovery/icon-ranking.mjs +8 -125
  49. package/foundation/discovery/icon-set-checks.mjs +35 -44
  50. package/foundation/discovery/icon-set-discovery.d.mts +0 -13
  51. package/foundation/discovery/icon-set-discovery.mjs +0 -25
  52. package/foundation/discovery/icon-set-writer.d.mts +16 -238
  53. package/foundation/discovery/icon-set-writer.mjs +79 -676
  54. package/foundation/discovery/module-exports.d.mts +2 -3
  55. package/foundation/discovery/module-exports.mjs +37 -167
  56. package/foundation/fs/paths.d.mts +1 -2
  57. package/foundation/fs/paths.mjs +4 -3
  58. package/package.json +6 -6
  59. package/api/icon/_default-look.d.mts +0 -155
  60. package/api/icon/_default-look.mjs +0 -474
  61. package/api/swizzle/_moduleGraph.d.mts +0 -162
  62. package/api/swizzle/_moduleGraph.mjs +0 -754
  63. package/foundation/text/shell-arg.d.mts +0 -14
  64. package/foundation/text/shell-arg.mjs +0 -17
@@ -13,7 +13,6 @@
13
13
  import * as fs from 'node:fs';
14
14
  import * as path from 'node:path';
15
15
  import {AstryxError} from '../error.mjs';
16
- import {logger} from '../logger.mjs';
17
16
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
18
17
  import {
19
18
  assertWithin,
@@ -42,13 +41,8 @@ import {
42
41
  iconSetDataText,
43
42
  journalFile,
44
43
  librarySource,
45
- everyLibraryIcon,
46
44
  libraryIcons,
47
- libraryLooks,
48
- lookPositions,
49
- moduleNaming,
50
45
  nonIconExports,
51
- packageRootMoves,
52
46
  resolveIconSource,
53
47
  peerNote,
54
48
  typecheckNote,
@@ -56,16 +50,6 @@ import {
56
50
  writeGeneratedIcons,
57
51
  writeIconSetData,
58
52
  } from '../../foundation/discovery/icon-set-writer.mjs';
59
- import {
60
- describedLooks,
61
- drawnLooks,
62
- resolveDefaultLook,
63
- } from './_default-look.mjs';
64
- import {shellArg} from '../../foundation/text/shell-arg.mjs';
65
- import {
66
- hasLicenseNotice,
67
- licenseNoticeFix,
68
- } from '../../foundation/discovery/icon-set-discovery.mjs';
69
53
  import {astryxIconDefinitions} from '../../foundation/discovery/icon-definition-discovery.mjs';
70
54
  import {suggestedIcons} from '../../foundation/discovery/icon-set-checks.mjs';
71
55
  import {
@@ -115,7 +99,7 @@ function quoteJs(value) {
115
99
  */
116
100
  export async function addIconSet(name, options) {
117
101
  const {cwd = process.cwd(), dryRun = false, from} = options;
118
- const given = variantOptions(options);
102
+ const looks = variantOptions(options);
119
103
  const exclude =
120
104
  typeof options.exclude === 'string'
121
105
  ? options.exclude
@@ -208,30 +192,7 @@ export async function addIconSet(name, options) {
208
192
  dryRun,
209
193
  from,
210
194
  exclude,
211
- looks: given,
212
- describe: {
213
- displayName: options.displayName,
214
- description: options.description,
215
- },
216
- packageDir,
217
- rootPath,
218
- manifestPath: projectPath(path.relative(packageDir, manifestFile)),
219
- });
220
- }
221
- // Without --from, an existing set takes new variants, a default variant, a
222
- // display name or a description in place, and nothing else changes.
223
- if (
224
- from == null &&
225
- fs.existsSync(docFile) &&
226
- fs.existsSync(dataFile) &&
227
- (given != null ||
228
- options.displayName?.trim() ||
229
- options.description?.trim())
230
- ) {
231
- return redeclareIconSet(name, {
232
- cwd,
233
- dryRun,
234
- looks: given,
195
+ looks,
235
196
  describe: {
236
197
  displayName: options.displayName,
237
198
  description: options.description,
@@ -266,48 +227,14 @@ export async function addIconSet(name, options) {
266
227
  let skipped = [];
267
228
  /** @type {ReturnType<typeof librarySource>} */
268
229
  let library = null;
269
- /** @type {{summary: import('../../foundation/discovery/icon-set-writer.mjs').LibraryLookSummary | null}} */
270
- const lookFound = {summary: null};
271
- // Without --from the set has no icons yet, so no look to match.
272
- let looks =
273
- from == null
274
- ? resolveDefaultLook({
275
- name,
276
- given,
277
- current: undefined,
278
- icons: 0,
279
- drawn: null,
280
- library: null,
281
- }).looks
282
- : null;
283
230
  if (from != null) {
284
231
  const source = await iconAuthoring(() =>
285
232
  resolveIconSource(from, {packageDir, pkg}),
286
233
  );
287
- const found = libraryIcons(source.file, {
288
- exclude,
289
- // The library's look words decide the default before any glyph is
290
- // picked, so each icon's export draws it.
291
- prefer: positions => {
292
- looks = resolveDefaultLook({
293
- name,
294
- given,
295
- current: undefined,
296
- icons: 0,
297
- drawn: null,
298
- library: {module: source.module, positions},
299
- }).looks;
300
- return looks ? [looks.default] : [];
301
- },
302
- module: source.module,
303
- progress: line => logger.warn(line),
304
- summary: each => {
305
- lookFound.summary = each;
306
- },
307
- });
234
+ const found = libraryIcons(source.file, {exclude});
308
235
  if (found.length === 0) {
309
236
  throw new AstryxError(
310
- `"${from}" exports no icon components this command can read. If its icons are data (objects or SVG strings), run \`astryx experimental icon new-set ${name}\`, declare an "adapter" in ${name}.icons.json, and run this command again; or add icons one at a time with \`astryx experimental icon add <Export> --from ${from} --set ${name}\`.`,
237
+ `"${from}" exports no icon components this command can read. If its icons are data (objects or SVG strings), run \`astryx experimental icon new-set ${name}\`, declare an "adapter" in ${name}.icons.json, and run this command again; or add icons one at a time with \`astryx experimental icon add <Export> --from ${from}\`.`,
311
238
  undefined,
312
239
  ERROR_CODES.ERR_NOT_FOUND,
313
240
  );
@@ -486,11 +413,6 @@ export async function addIconSet(name, options) {
486
413
  writtenFiles,
487
414
  dryRun,
488
415
  );
489
- const missingNotice = noticeToAdd(
490
- library,
491
- packageDir,
492
- projectPath(path.relative(packageDir, setDir)),
493
- );
494
416
  {
495
417
  result.data.icons = icons.length;
496
418
  if (from != null) {
@@ -530,220 +452,14 @@ export async function addIconSet(name, options) {
530
452
  `Left out ${skipped.length} exports that are not icons: ${skipped.slice(0, 12).join(', ')}${skipped.length > 12 ? ', …' : ''}.`,
531
453
  ]
532
454
  : []),
533
- ...(from != null && lookFound.summary == null
534
- ? [`Found ${icons.length} icons in ${from}.`]
535
- : []),
536
- ...(from != null && lookFound.summary != null
537
- ? lookNotes(lookFound.summary, icons.length, from, looks, name)
538
- : []),
539
- ...(missingNotice ? [missingNotice.note] : []),
540
- ...mappedNotes(map, name),
541
- ...suggestionNotes(suggestions, name),
455
+ ...mappedNotes(map),
456
+ ...suggestionNotes(suggestions),
542
457
  'Run `astryx integration check` to see the icon definitions still to map.',
543
458
  ];
544
- if (missingNotice) {
545
- result.data.licenseNoticeMissing = missingNotice.receipt;
546
- }
547
459
  }
548
460
  return result;
549
461
  }
550
462
 
551
- /**
552
- * The license notice the author must add when the wrapped library ships no
553
- * license file to copy and the package root has none. The CLI never writes
554
- * it: the license text is the author's to state. Null when nothing is
555
- * missing.
556
- * @param {{package: string, version: string, notices: string[]} | null} library
557
- * @param {string} packageDir
558
- * @param {string} setDir the set directory, from the package root
559
- * @returns {{note: string, receipt: {library: string, path: string}} | null}
560
- */
561
- function noticeToAdd(library, packageDir, setDir) {
562
- if (!library || library.notices.length > 0) return null;
563
- if (hasLicenseNotice(packageDir)) return null;
564
- const named = `${library.package}@${library.version}`;
565
- return {
566
- note: `${named} ships no LICENSE or NOTICE file to copy, so the set has no license notice. ${licenseNoticeFix(setDir, named)}`,
567
- receipt: {library: named, path: `${setDir}/NOTICE`},
568
- };
569
- }
570
-
571
- /**
572
- * A set descriptor's source with `--display-name` and `--description`
573
- * written into its fields; the rest as it was.
574
- * @param {string} source
575
- * @param {{displayName?: string, description?: string}} describe
576
- */
577
- function describedDoc(source, describe) {
578
- let out = source;
579
- for (const [field, value] of /** @type {const} */ ([
580
- ['displayName', describe.displayName],
581
- ['description', describe.description],
582
- ])) {
583
- if (!value?.trim()) continue;
584
- out = out.replace(
585
- new RegExp(`^(\\s*${field}:\\s*)(['"\`])(?:\\\\.|(?!\\2).)*\\2,?$`, 'mu'),
586
- (_, lead) => `${lead}${quoteJs(value.trim())},`,
587
- );
588
- }
589
- return out;
590
- }
591
-
592
- /**
593
- * `new-set <name>` without `--from` over an existing set: declare its
594
- * variants and default variant, and rewrite its display name and
595
- * description, in place. Its icons, map and generated module stay as they
596
- * are. A variant an icon still has must stay declared, and the default
597
- * variant is one no icon lists as an extra look. A set with icons keeps its
598
- * default variant: only a refresh with `--from` from a library whose names
599
- * name its looks moves it. With none declared,
600
- * its default is the look its icons' exports draw.
601
- * @param {string} name
602
- * @param {{cwd: string, dryRun: boolean, looks: Looks | null, describe: {displayName?: string, description?: string}, packageDir: string, rootPath: string, manifestPath: string}} options
603
- */
604
- async function redeclareIconSet(
605
- name,
606
- {cwd, dryRun, looks: given, describe, packageDir, rootPath, manifestPath},
607
- ) {
608
- return iconAuthoring(async () => {
609
- const where = await findLocalIconSet(cwd, name);
610
- const {set} = where;
611
- const current = set.data.default?.variant;
612
- const drawn =
613
- given && set.data.icons.length > 0
614
- ? drawnLooks(set, packageDir, module =>
615
- libraryPositions(module, where, Boolean(set.data.adapter)),
616
- )
617
- : null;
618
- const {looks} = resolveDefaultLook({
619
- name,
620
- given,
621
- current,
622
- icons: set.data.icons.length,
623
- drawn,
624
- library: null,
625
- });
626
- if (looks) {
627
- const declared = new Set(looks.variants);
628
- const dropped = set.data.icons.flatMap(icon =>
629
- (icon.variants ?? [])
630
- .filter(each => !declared.has(each.variant))
631
- .map(each => `${icon.id} (${each.variant})`),
632
- );
633
- if (dropped.length > 0) {
634
- throw new AstryxError(
635
- `These icons still have a variant --variants leaves out: ${dropped.slice(0, 8).join(', ')}${dropped.length > 8 ? ', …' : ''}. Keep it in --variants.`,
636
- [
637
- {
638
- name: `--variants ${[...new Set([...looks.variants, ...set.data.icons.flatMap(icon => (icon.variants ?? []).map(each => each.variant))])].join(',')}`,
639
- reason: 'keep every variant an icon has',
640
- },
641
- ],
642
- ERROR_CODES.ERR_INVALID_ARGUMENT,
643
- );
644
- }
645
- const asExtra = set.data.icons
646
- .filter(icon =>
647
- (icon.variants ?? []).some(each => each.variant === looks.default),
648
- )
649
- .map(icon => icon.id);
650
- if (asExtra.length > 0) {
651
- throw new AstryxError(
652
- `"${looks.default}" can't be the default variant: ${asExtra.length} icons list it as another look (${asExtra.slice(0, 8).join(', ')}${asExtra.length > 8 ? ', …' : ''}), and each icon's own export draws the default.`,
653
- undefined,
654
- ERROR_CODES.ERR_INVALID_ARGUMENT,
655
- );
656
- }
657
- }
658
- const next = {
659
- ...set.data,
660
- ...(looks
661
- ? {variants: looks.variants, default: {variant: looks.default}}
662
- : {}),
663
- };
664
- const docFile = path.join(set.dir, `${set.name}.doc.mjs`);
665
- const docBefore = fs.readFileSync(docFile, 'utf-8');
666
- const docAfter = describedDoc(docBefore, describe);
667
- const dataChanged =
668
- iconSetDataText(next) !== fs.readFileSync(set.dataPath, 'utf-8');
669
- /** @type {string[]} */
670
- const files = [];
671
- if (dataChanged) {
672
- files.push(projectPath(path.relative(packageDir, set.dataPath)));
673
- }
674
- if (docAfter !== docBefore) {
675
- files.push(projectPath(path.relative(packageDir, docFile)));
676
- }
677
- if (!dryRun) {
678
- if (dataChanged) writeIconSetData(set, next);
679
- if (docAfter !== docBefore) {
680
- journalFile(docFile);
681
- fs.writeFileSync(docFile, docAfter);
682
- }
683
- }
684
- const result = receipt(
685
- 'icon-set',
686
- name,
687
- {path: rootPath, created: false},
688
- manifestPath,
689
- files,
690
- dryRun,
691
- );
692
- result.data.icons = set.data.icons.length;
693
- result.data.updated = true;
694
- // A look the icons' own library draws comes from that library, so its
695
- // command runs as printed; any other look comes from a module the
696
- // author names.
697
- /** @param {string} variant */
698
- const fromFor = variant =>
699
- drawn != null && drawn.positions.some(each => each.has(variant))
700
- ? shellArg(drawn.module)
701
- : '<module>';
702
- const added = (looks?.variants ?? []).filter(
703
- variant =>
704
- variant !== looks?.default &&
705
- !(set.data.variants ?? []).includes(variant),
706
- );
707
- result.data.notes = [
708
- files.length === 0
709
- ? `Icon set "${name}" already declares this; nothing changed.`
710
- : `Updated icon set "${name}" in place; its icons, map and generated module are unchanged.`,
711
- ...(added.length > 0
712
- ? [
713
- `Give each icon its ${added.join(', ')} look: ${added.map(variant => `\`astryx experimental icon add --variant ${variant} --from ${fromFor(variant)} --all --set ${name}\``).join(', ')}, or one icon with \`astryx experimental icon add <Export> --from <module> --id <icon> --variant <name> --set ${name}\`.`,
714
- ]
715
- : []),
716
- ];
717
- return result;
718
- });
719
- }
720
-
721
- /**
722
- * The receipt's notes for a library that draws each icon in several looks
723
- * (a style, a size, a weight): what it found, the look the set took, and
724
- * how to add another look as a variant.
725
- * @param {import('../../foundation/discovery/icon-set-writer.mjs').LibraryLookSummary} summary
726
- * @param {number} count icons in the set
727
- * @param {string} from
728
- * @param {{variants: string[], default: string} | null} looks
729
- * @param {string} name the set's name
730
- * @returns {string[]}
731
- */
732
- function lookNotes(summary, count, from, looks, name) {
733
- const described = describedLooks(summary.positions);
734
- const taken = [...summary.preferred].reverse().join(' ');
735
- const styles = new Set(summary.positions.flat());
736
- const others = (looks?.variants ?? []).filter(
737
- variant => variant !== looks?.default && styles.has(variant),
738
- );
739
- return [
740
- `Found ${count} icons in ${from}, each drawn in several looks (${described}) by ${summary.exports} exports. The set wraps each icon once, in the ${taken} look, named without the look words (\`x\`, \`XIcon\`).`,
741
- others.length > 0
742
- ? `Add the ${others.join(', ')} look${others.length > 1 ? 's' : ''} as variant${others.length > 1 ? 's' : ''}: ${others.map(variant => `\`astryx experimental icon add --variant ${variant} --from ${from} --all --set ${name}\``).join(', ')}.`
743
- : `To offer another look as a variant, declare it with \`astryx experimental icon new-set ${name} --variants ${[...summary.preferred].reverse()[0]},<look>\` (no --from: the set's icons stay as they are) and run \`astryx experimental icon add --variant <look> --from ${from} --all --set ${name}\`.`,
744
- ];
745
- }
746
-
747
463
  /**
748
464
  * An icon's words from its id: each part, leaving out a bare number
749
465
  * (`volume-2` is `volume`) unless the id is only numbers.
@@ -804,40 +520,36 @@ function definitionSuggestions(icons, map) {
804
520
  /**
805
521
  * The receipt's note for the suggestions, if any.
806
522
  * @param {Array<{definition: string, icon: string}>} suggestions
807
- * @param {string} name the set's name
808
523
  */
809
- function suggestionNotes(suggestions, name) {
524
+ function suggestionNotes(suggestions) {
810
525
  if (suggestions.length === 0) return [];
811
526
  const count = new Set(suggestions.map(each => each.definition)).size;
812
527
  return [
813
- `${count} unmapped icon definitions have possible icons (listed under Suggestions; nothing was written for them). Check each meaning, then map the ones that fit: \`astryx experimental icon map <definition> <icon> --set ${name}\`.`,
528
+ `${count} unmapped icon definitions have possible icons (listed under Suggestions; nothing was written for them). Check each meaning, then map the ones that fit: \`astryx experimental icon map <definition> <icon>\`.`,
814
529
  ];
815
530
  }
816
531
 
817
532
  /**
818
533
  * The receipt's note for the entries an exact name wrote, if any.
819
534
  * @param {Record<string, string>} map
820
- * @param {string} name the set's name
821
535
  */
822
- function mappedNotes(map, name) {
536
+ function mappedNotes(map) {
823
537
  const count = Object.keys(map).length;
824
538
  if (count === 0) return [];
825
539
  return [
826
- `${count} icon definitions were mapped because an icon has their exact name (listed under Mapped by name). A library can draw another meaning under the same name, such as a backspace key named delete: check each, and remap with \`astryx experimental icon map <definition> <icon> --set ${name}\`.`,
540
+ `${count} icon definitions were mapped because an icon has their exact name (listed under Mapped by name). A library can draw another meaning under the same name, such as a backspace key named delete: check each, and remap with \`astryx experimental icon map <definition> <icon>\`.`,
827
541
  ];
828
542
  }
829
543
 
830
- /** @typedef {import('./_default-look.mjs').Looks} Looks */
831
-
832
544
  /** A variant name: lower-kebab, such as `outline` or `mini-solid`. */
833
545
  const VARIANT_NAME_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
834
546
 
835
547
  /**
836
548
  * The variants and default variant `--variants` and `--default-variant`
837
- * declare, or null when neither is given. Unless named, `default` is the
838
- * first variant until {@link resolveDefaultLook} decides it.
549
+ * declare, or
550
+ * null when neither is given. The default is the first variant unless named.
839
551
  * @param {{variants?: string[] | string, defaultVariant?: string}} options
840
- * @returns {Looks | null}
552
+ * @returns {{variants: string[], default: string} | null}
841
553
  */
842
554
  function variantOptions(options) {
843
555
  const given =
@@ -882,28 +594,7 @@ function variantOptions(options) {
882
594
  ERROR_CODES.ERR_INVALID_ARGUMENT,
883
595
  );
884
596
  }
885
- return {variants, default: chosen || variants[0], named: Boolean(chosen)};
886
- }
887
-
888
- /**
889
- * The look positions of a library the set's generated module names, or
890
- * null when it can't be read.
891
- * @param {string} module
892
- * @param {{packageDir: string, pkg: Record<string, any>}} where
893
- * @param {boolean} adapter
894
- * @returns {Array<Set<string>> | null}
895
- */
896
- function libraryPositions(module, where, adapter) {
897
- try {
898
- const source = resolveIconSource(module, where);
899
- return moduleNaming(source.file, {
900
- adapter,
901
- module,
902
- progress: line => logger.warn(line),
903
- }).positions;
904
- } catch {
905
- return null;
906
- }
597
+ return {variants, default: chosen || variants[0]};
907
598
  }
908
599
 
909
600
  /**
@@ -935,77 +626,13 @@ async function iconAuthoring(step) {
935
626
  }
936
627
  }
937
628
 
938
- /**
939
- * Whether an id is one an id rule derives from a library glyph: the glyph id,
940
- * or its library export, broken into words another way (`squares-2-x2` for
941
- * `squares-2x2`, `glyph-eye` for `glyphEye`). Any other id is the author's.
942
- * @param {string} id
943
- * @param {{id: string, export: string}} glyph
944
- */
945
- function derivedId(id, glyph) {
946
- const flat = (/** @type {string} */ text) =>
947
- text.toLowerCase().replace(/[^a-z0-9]/gu, '');
948
- return [glyph.id, glyph.export, glyph.export.replace(/Icon$/u, '')]
949
- .map(flat)
950
- .includes(flat(id));
951
- }
952
-
953
- /**
954
- * Keep the root moves that give each root export to one export of the set.
955
- * A root export that an export of the set already reads, or that an earlier
956
- * move takes, stays where it is. The icon that would move keeps its own file,
957
- * and its variants stay with it. Returns the kept moves and the ids of the
958
- * icons that stay (with `(<variant>)` for a variant that stays).
959
- * @param {{data: {module: string, icons: Array<{id: string, export: string, module?: string, variants?: Array<{variant: string, export: string}>}>}}} set
960
- * @param {Map<string, {module: string, source: string}>} origins
961
- * @param {string} root
962
- * @param {Map<string, {source: string, from: string}>} moves
963
- */
964
- function claimRootMoves(set, origins, root, moves) {
965
- /** @type {Map<string, {source: string, from: string}>} */
966
- const kept = new Map();
967
- /** @type {string[]} */
968
- const skipped = [];
969
- const claimed = new Set(
970
- [...origins.values()]
971
- .filter(origin => sameIconModule(origin.module, root))
972
- .map(origin => origin.source),
973
- );
974
- for (const icon of set.data.icons) {
975
- if ((icon.module ?? set.data.module) !== set.data.module) continue;
976
- const own = moves.get(icon.export);
977
- const origin = origins.get(icon.export);
978
- const readsRoot = origin != null && sameIconModule(origin.module, root);
979
- if (own) {
980
- if (claimed.has(own.source)) {
981
- skipped.push(icon.id);
982
- continue;
983
- }
984
- claimed.add(own.source);
985
- kept.set(icon.export, own);
986
- } else if (!readsRoot) continue;
987
- for (const each of icon.variants ?? []) {
988
- const move = moves.get(each.export);
989
- if (!move) continue;
990
- if (claimed.has(move.source)) {
991
- skipped.push(`${icon.id} (${each.variant})`);
992
- continue;
993
- }
994
- claimed.add(move.source);
995
- kept.set(each.export, move);
996
- }
997
- }
998
- skipped.sort();
999
- return {moves: kept, skipped};
1000
- }
1001
-
1002
629
  /**
1003
630
  * Wrap a library into an existing set again: its icons are replaced by what
1004
631
  * the library exports now (an icon whose words the author extended keeps
1005
632
  * them), the generated module gains the new exports, `map` keeps every entry
1006
633
  * whose icon still exists, and the receipt names the entries that lost theirs.
1007
634
  * @param {string} name
1008
- * @param {{cwd: string, dryRun: boolean, from: string, exclude: string[], looks: Looks | null, describe: {displayName?: string, description?: string}, packageDir: string, rootPath: string, manifestPath: string}} options
635
+ * @param {{cwd: string, dryRun: boolean, from: string, exclude: string[], looks: {variants: string[], default: string} | null, describe: {displayName?: string, description?: string}, packageDir: string, rootPath: string, manifestPath: string}} options
1009
636
  */
1010
637
  async function refreshIconSet(
1011
638
  name,
@@ -1014,7 +641,7 @@ async function refreshIconSet(
1014
641
  dryRun,
1015
642
  from,
1016
643
  exclude,
1017
- looks: given,
644
+ looks,
1018
645
  describe,
1019
646
  packageDir,
1020
647
  rootPath,
@@ -1024,73 +651,24 @@ async function refreshIconSet(
1024
651
  return iconAuthoring(async () => {
1025
652
  const where = await findLocalIconSet(cwd, name);
1026
653
  const {set} = where;
1027
- const current = set.data.default?.variant;
1028
654
  const source = resolveIconSource(from, where);
1029
655
  // Exports left out before stay out; --exclude adds to them.
1030
656
  const excluded = [
1031
657
  ...new Set([...(set.data.exclude ?? []), ...exclude]),
1032
658
  ].sort();
1033
- const everyIcon = everyLibraryIcon(source.file, {
659
+ const found = libraryIcons(source.file, {
1034
660
  adapter: Boolean(set.data.adapter),
1035
661
  exclude: excluded,
1036
- module: source.module,
1037
- progress: line => logger.warn(line),
1038
662
  });
1039
- const libraryLookPositions = lookPositions(everyIcon.map(icon => icon.id));
1040
- // The look the icons from this library draw now decides whether a named
1041
- // default moves them.
1042
- const {looks, moved} = resolveDefaultLook({
1043
- name,
1044
- given,
1045
- current,
1046
- icons: set.data.icons.length,
1047
- drawn: drawnLooks(set, packageDir, () => libraryLookPositions, {
1048
- module: source.module,
1049
- }),
1050
- library: {module: source.module, positions: libraryLookPositions},
1051
- });
1052
- if (looks) {
1053
- const asExtra = set.data.icons
1054
- .filter(icon =>
1055
- (icon.variants ?? []).some(each => each.variant === looks.default),
1056
- )
1057
- .map(icon => icon.id);
1058
- if (asExtra.length > 0) {
1059
- throw new AstryxError(
1060
- `"${looks.default}" can't be the default variant: ${asExtra.length} icons list it as another look (${asExtra.slice(0, 8).join(', ')}${asExtra.length > 8 ? ', …' : ''}), and each icon's own export draws the default.`,
1061
- undefined,
1062
- ERROR_CODES.ERR_INVALID_ARGUMENT,
1063
- );
1064
- }
1065
- }
1066
-
1067
663
  // A refresh changes only the icons the refreshed module supplies: those
1068
664
  // the generated module re-exports or adapts from it. Every other icon
1069
665
  // (your own `./` artwork, another library's) is kept as it is, with its
1070
666
  // map entries and variants.
1071
667
  const generatedBefore = generatedModulePath(set, packageDir);
1072
668
  const origins = generatedOrigins(packageDir, generatedBefore);
1073
- // A refresh from a package root also supplies the exports that read one
1074
- // file of that package, when the root exports the same icon. They move to
1075
- // the root import, so the set has one import style.
1076
- const {moves: rootMoves, skipped: skippedMoves} = claimRootMoves(
1077
- set,
1078
- origins,
1079
- source.module,
1080
- packageRootMoves(
1081
- origins,
1082
- source,
1083
- everyIcon.map(icon => icon.export),
1084
- where,
1085
- ),
1086
- );
1087
- /** @param {string} name the set's export */
1088
- const libraryExportOf = name =>
1089
- rootMoves.get(name)?.source ?? origins.get(name)?.source;
1090
669
  /** @param {{export: string, module?: string}} icon */
1091
670
  const suppliedHere = icon => {
1092
671
  if ((icon.module ?? set.data.module) !== set.data.module) return false;
1093
- if (rootMoves.has(icon.export)) return true;
1094
672
  const origin = origins.get(icon.export);
1095
673
  return origin != null && sameIconModule(origin.module, source.module);
1096
674
  };
@@ -1098,93 +676,39 @@ async function refreshIconSet(
1098
676
  const others = set.data.icons.filter(icon => !suppliedHere(icon));
1099
677
  // An existing icon is the same icon when the library still exports it:
1100
678
  // its identity is the library export its generated module re-exports
1101
- // (`HiSquares2X2Icon`, or the root export a per-file icon moves to), then
1102
- // its public export, then its id. Ids and public names are derived, and a
1103
- // newer rule may spell them differently (`squares-2-x2` is now
1104
- // `squares-2x2`); an icon matched this way keeps its public export byte
1105
- // for byte, every field it had (its variants, the words the author added,
1106
- // its module), and its map entries. The same rule holds on every refresh,
1107
- // so a second refresh changes nothing the first one wrote.
1108
- const moving = new Set(supplied.filter(icon => rootMoves.has(icon.export)));
679
+ // (`HiSquares2X2Icon`), then its public export, then its id. Ids and
680
+ // public names are derived, and a newer rule may spell them differently
681
+ // (`squares-2-x2` is now `squares-2x2`); an icon matched this way keeps
682
+ // its public export byte for byte, every field it had (its variants, the
683
+ // words the author added, its module), and its map entries.
1109
684
  const byId = new Map(supplied.map(icon => [icon.id, icon]));
1110
685
  const byExport = new Map(supplied.map(icon => [icon.export, icon]));
1111
686
  const bySource = new Map(
1112
- supplied.map(icon => [libraryExportOf(icon.export), icon]),
1113
- );
1114
- // One icon per glyph. A look the set already wraps keeps its icon and id.
1115
- // A new glyph comes in once, in the preferred look. A new default variant
1116
- // moves each glyph's icon to that look.
1117
- const preferred = looks?.default ?? current;
1118
- const {icons: looksOf} = libraryLooks(
1119
- everyIcon,
1120
- preferred ? [preferred] : [],
687
+ supplied.map(icon => [origins.get(icon.export)?.source, icon]),
1121
688
  );
1122
- const iconByExport = new Map(everyIcon.map(icon => [icon.export, icon]));
1123
- /** @type {string[]} the set's exports whose statement now names another look */
1124
- const repicked = [];
1125
- /** @type {Map<string, (typeof supplied)[number]>} the new look's export → the icon it now draws */
1126
- const repickedBy = new Map();
1127
- const found = looksOf.flatMap(icon => {
1128
- const wrapped = (icon.looks ?? []).filter(look => bySource.has(look));
1129
- if (wrapped.length === 0) return [icon];
1130
- return wrapped.map(look => {
1131
- const prior = /** @type {(typeof supplied)[number]} */ (
1132
- bySource.get(look)
1133
- );
1134
- // A moved icon is the glyph its root export draws, whatever its id.
1135
- const sameGlyph = moving.has(prior) || prior.id === icon.id;
1136
- if (moved && sameGlyph && !bySource.has(icon.export)) {
1137
- repicked.push(prior.export);
1138
- repickedBy.set(icon.export, prior);
1139
- return icon;
1140
- }
1141
- const own = /** @type {(typeof everyIcon)[number]} */ (
1142
- iconByExport.get(look)
1143
- );
1144
- // Read by the glyph's id when the set already names it so.
1145
- return prior.id === icon.id
1146
- ? {...own, id: icon.id, name: icon.name}
1147
- : own;
1148
- });
1149
- });
1150
- /** @param {{export: string}} glyph */
1151
- const resolvedPrior = glyph =>
1152
- repickedBy.get(glyph.export) ?? bySource.get(glyph.export) ?? null;
1153
- // An icon its library export already gives to one glyph is never given to
1154
- // a second glyph by name or id: that glyph is left out.
1155
- const resolved = new Set(found.map(resolvedPrior).filter(Boolean));
1156
- const takenIds = new Set(others.map(icon => icon.id));
1157
- const takenExports = new Set(others.map(icon => icon.export));
1158
- /** @type {string[]} library icons left out: an icon of the set has the id or name */
689
+ /** @param {{export: string, name: string, id: string}} icon */
690
+ const priorOf = icon =>
691
+ bySource.get(icon.export) ??
692
+ byExport.get(icon.name) ??
693
+ byId.get(icon.id) ??
694
+ null;
695
+ const otherIds = new Set(others.map(icon => icon.id));
696
+ const otherExports = new Set(others.map(icon => icon.export));
697
+ /** @type {string[]} library icons left out: an icon of yours has the id or name */
1159
698
  const shadowed = [];
1160
699
  /** @type {Map<string, string>} old id → new id */
1161
700
  const renames = new Map();
1162
701
  /** @type {Map<string, string>} the library export → the set's export */
1163
702
  const publicName = new Map();
1164
703
  const fromLibrary = found.flatMap(icon => {
1165
- const byOrigin = resolvedPrior(icon);
1166
- const byName = byOrigin
1167
- ? null
1168
- : (byExport.get(icon.name) ?? byId.get(icon.id) ?? null);
1169
- const prior = byOrigin ?? (resolved.has(byName) ? null : byName);
704
+ const prior = priorOf(icon);
1170
705
  const name = prior?.export ?? icon.name;
1171
- if (
1172
- !prior &&
1173
- (byName || takenIds.has(icon.id) || takenExports.has(name))
1174
- ) {
706
+ if (!prior && (otherIds.has(icon.id) || otherExports.has(name))) {
1175
707
  shadowed.push(icon.id);
1176
708
  return [];
1177
709
  }
1178
- publicName.set(icon.export, name);
1179
- if (prior && byOrigin && !derivedId(prior.id, icon)) {
1180
- return [
1181
- {
1182
- ...prior,
1183
- words: [...new Set([...(prior.words ?? []), ...icon.aliases])],
1184
- },
1185
- ];
1186
- }
1187
710
  if (prior && prior.id !== icon.id) renames.set(prior.id, icon.id);
711
+ publicName.set(icon.export, name);
1188
712
  // The words its old id gave are the old rule's, not the author's.
1189
713
  const oldIdWords =
1190
714
  prior && prior.id !== icon.id ? new Set(idWords(prior.id)) : new Set();
@@ -1204,42 +728,17 @@ async function refreshIconSet(
1204
728
  ];
1205
729
  });
1206
730
  const icons = [...fromLibrary, ...others];
1207
- // An icon is listed under `moved` when it or one of its variants moves.
1208
- /** @type {Array<{id: string, from: string, to: string}>} */
1209
- const movedIcons = [];
1210
- /** @type {import('../../foundation/discovery/icon-set-writer.mjs').GeneratedIcon[]} */
1211
- const movedVariants = [];
1212
- for (const icon of fromLibrary) {
1213
- const variantMoves = (icon.variants ?? []).filter(each =>
1214
- rootMoves.has(each.export),
1215
- );
1216
- for (const each of variantMoves) {
1217
- const move = /** @type {{source: string, from: string}} */ (
1218
- rootMoves.get(each.export)
1219
- );
1220
- movedVariants.push({
1221
- name: each.export,
1222
- from: source.module,
1223
- source: move.source,
1224
- adapt: iconByExport.get(move.source)?.adapt ?? false,
1225
- });
1226
- }
1227
- const from = (
1228
- rootMoves.get(icon.export) ?? rootMoves.get(variantMoves[0]?.export)
1229
- )?.from;
1230
- if (from) movedIcons.push({id: icon.id, from, to: source.module});
1231
- }
1232
- movedIcons.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
1233
731
  // The icons this module supplied that it no longer exports: they leave
1234
732
  // the set and its generated module, and the receipt names them.
1235
733
  // Each is named for why it left: `--exclude` (or the data file's
1236
734
  // `exclude`) names its library export, or the library no longer exports
1237
735
  // it.
1238
736
  const excludedNames = new Set(excluded);
1239
- const keptExports = new Set(fromLibrary.map(each => each.export));
1240
- const gone = supplied.filter(icon => !keptExports.has(icon.export));
737
+ const gone = supplied.filter(
738
+ icon => !fromLibrary.some(each => each.export === icon.export),
739
+ );
1241
740
  const isExcluded = (/** @type {{export: string}} */ icon) =>
1242
- excludedNames.has(libraryExportOf(icon.export) ?? '') ||
741
+ excludedNames.has(origins.get(icon.export)?.source ?? '') ||
1243
742
  excludedNames.has(icon.export);
1244
743
  const goneExcluded = gone.filter(isExcluded);
1245
744
  const goneMissing = gone.filter(icon => !isExcluded(icon));
@@ -1283,7 +782,20 @@ async function refreshIconSet(
1283
782
  // --display-name and --description rewrite the descriptor's fields.
1284
783
  const docFile = path.join(set.dir, `${set.name}.doc.mjs`);
1285
784
  const docBefore = fs.readFileSync(docFile, 'utf-8');
1286
- let docAfter = describedDoc(docBefore, describe);
785
+ let docAfter = docBefore;
786
+ for (const [field, value] of /** @type {const} */ ([
787
+ ['displayName', describe.displayName],
788
+ ['description', describe.description],
789
+ ])) {
790
+ if (!value?.trim()) continue;
791
+ docAfter = docAfter.replace(
792
+ new RegExp(
793
+ `^(\\s*${field}:\\s*)(['"\`])(?:\\\\.|(?!\\2).)*\\2,?$`,
794
+ 'mu',
795
+ ),
796
+ (_, lead) => `${lead}${quoteJs(value.trim())},`,
797
+ );
798
+ }
1287
799
  // A refresh that first records the library as the set's source does what
1288
800
  // `new-set --from` does: the descriptor takes the library's license, but
1289
801
  // only over the value `new-set` wrote by default (the package's license,
@@ -1328,31 +840,21 @@ async function refreshIconSet(
1328
840
  files.push(projectPath(path.relative(packageDir, target)));
1329
841
  }
1330
842
  if (!dryRun) {
1331
- const rewritten = found
1332
- .map(icon => ({
1333
- name: publicName.get(icon.export) ?? icon.name,
1334
- from: source.module,
1335
- source: icon.export,
1336
- adapt: icon.adapt,
1337
- }))
1338
- .filter(icon => publicName.has(icon.source))
1339
- .concat(movedVariants);
1340
- const rewrittenNames = new Set(rewritten.map(icon => icon.name));
1341
843
  const written = writeGeneratedIcons(
1342
844
  packageDir,
1343
845
  generated,
1344
846
  next,
1345
- rewritten,
847
+ found
848
+ .map(icon => ({
849
+ name: publicName.get(icon.export) ?? icon.name,
850
+ from: source.module,
851
+ source: icon.export,
852
+ adapt: icon.adapt,
853
+ }))
854
+ .filter(icon => publicName.has(icon.source)),
1346
855
  // The icons the library no longer exports leave the module too; a
1347
- // renamed icon keeps its export. An icon moved to the new default
1348
- // look keeps its export, which now names that look. An export moved
1349
- // to the root is written again with the root import. Every other
1350
- // export stays as it is, because the data file still lists it.
1351
- [
1352
- ...gone.map(icon => icon.export),
1353
- ...repicked,
1354
- ...[...rootMoves.keys()].filter(name => rewrittenNames.has(name)),
1355
- ],
856
+ // renamed icon keeps its export.
857
+ gone.map(icon => icon.export),
1356
858
  );
1357
859
  files.push(...written.files);
1358
860
  try {
@@ -1404,32 +906,15 @@ async function refreshIconSet(
1404
906
  if (renames.size > 0) {
1405
907
  result.data.renamed = [...renames].map(([from, to]) => ({from, to}));
1406
908
  }
1407
- if (movedIcons.length > 0) result.data.moved = movedIcons;
1408
- const missingNotice = hasLicenseNotice(set.dir)
1409
- ? null
1410
- : noticeToAdd(
1411
- library,
1412
- packageDir,
1413
- projectPath(path.relative(packageDir, set.dir)),
1414
- );
1415
- if (missingNotice) {
1416
- result.data.licenseNoticeMissing = missingNotice.receipt;
1417
- }
1418
909
  result.data.notes = [
1419
910
  ...(licenseNote ? [licenseNote] : []),
1420
- ...(missingNotice ? [missingNotice.note] : []),
1421
911
  ...(renames.size > 0
1422
912
  ? [
1423
913
  `${renames.size} icons have a new id under this release's id rule, and keep their map entries, variants, and words: ${[...renames].map(([from, to]) => `${from} -> ${to}`).join(', ')}.`,
1424
914
  ]
1425
915
  : []),
1426
- ...(movedIcons.length > 0
1427
- ? [
1428
- `${movedIcons.length} icons now import from ${source.module} instead of one file each, and keep their ids, exports, map entries, variants, and words: ${movedIcons.map(each => each.id).join(', ')}.`,
1429
- ]
1430
- : []),
1431
- ...mappedNotes(byName, name),
1432
- ...suggestionNotes(suggestions, name),
916
+ ...mappedNotes(byName),
917
+ ...suggestionNotes(suggestions),
1433
918
  ...(goneMissing.length > 0
1434
919
  ? [
1435
920
  `${goneMissing.length} icons the library no longer exports were removed from the set: ${goneMissing.map(icon => icon.id).join(', ')}.`,
@@ -1452,12 +937,7 @@ async function refreshIconSet(
1452
937
  : []),
1453
938
  ...(shadowed.length > 0
1454
939
  ? [
1455
- `Left out ${shadowed.length} library icons whose id or name an icon of the set already has: ${shadowed.join(', ')}.`,
1456
- ]
1457
- : []),
1458
- ...(skippedMoves.length > 0
1459
- ? [
1460
- `${skippedMoves.length} icons stay on their own file, because another icon of the set already reads the same export of ${source.module}: ${skippedMoves.join(', ')}.`,
940
+ `Left out ${shadowed.length} library icons whose id or name an icon of yours from another module already has: ${shadowed.join(', ')}.`,
1461
941
  ]
1462
942
  : []),
1463
943
  astryxIconDefinitions().definitions.every(({doc}) => map[doc.name])