Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): experimental icon sets — add a look's variant from its own package, and skip pack exports (#10896)

Joeydc91a5b12705
diff --git a/.changeset/icon-sets-look-packages-and-packs.md b/.changeset/icon-sets-look-packages-and-packs.md
new file mode 100644
index 0000000000..8569a4b195
--- /dev/null
+++ b/.changeset/icon-sets-look-packages-and-packs.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[experimental] Icon sets: `experimental icon add --variant <look> --from <module> --all` now works for a library that ships each look as its own package, such as Font Awesome's solid and regular packages of icon data objects. Before, it found no icon to give the variant, because every icon came from another package. An icon gains the variant from the export of the same name and kind, and the receipt lists as missing the icons of that library that the look's package does not export. Wrapping such a library also no longer turns a pack export (`fas`, an object of the other exports) into an icon, so the shared `fa` prefix comes off the names again. A name that would then start with a digit keeps the prefix (`fa0` becomes `Fa0Icon`), so the generated module still parses. Only the experimental icon commands and `integration check` on an icon set change.
+@josephfarina
diff --git a/docs/specs/AST-084-icon-sets/spec.md b/docs/specs/AST-084-icon-sets/spec.md
index 9abc73b766..810e2a0548 100644
--- a/docs/specs/AST-084-icon-sets/spec.md
+++ b/docs/specs/AST-084-icon-sets/spec.md
@@ -373,12 +373,17 @@ icon, and the CLI verifies it, writes the files, and checks the set.
its name from `--id`, and when its first look word that differs from
the wrapped export's is a declared variant other than the default, the
listing adds the command that adds it as that icon's variant. With
- `--variant <name> --all` and no export, it adds that variant for every
- icon from that module's package whose `id` an export of the module has
- (in a library of looks, the glyph's look of that name), in one write; an
- icon from another module is left alone and not listed as missing, and a
- glyph drawn in no look of that name, or whose own export is that look,
- is listed as missing. For a `./`
+ `--variant <name> --all` and no export, it adds that variant in one
+ write for every icon from that module's package whose `id` an export of
+ the module has (in a library of looks, the glyph's look of that name),
+ and for every icon from another package whose library export the module
+ exports under the same name and kind (a library that ships each look as
+ its own package). Once one icon of another package matches this way,
+ the other icons of that package are matched as icons of the module's
+ package, and each one the module has no export for is listed as
+ missing. Any other icon from another module is left alone and not
+ listed as missing, and a glyph drawn in no look of that name, or whose
+ own export is that look, is listed as missing. For a `./`
file outside package.json `files`, it names the `files` array that
publishes it.
- `experimental icon map <definition> <icon>` writes one `map` entry,
diff --git a/packages/cli/api/icon/add/add.mjs b/packages/cli/api/icon/add/add.mjs
index 19d26b861a..7d1821a682 100644
--- a/packages/cli/api/icon/add/add.mjs
+++ b/packages/cli/api/icon/add/add.mjs
@@ -647,8 +647,27 @@ async function addVariantForAll({cwd, from, selector, variant}) {
);
// Only icons from the same package as the variant module can have a
// variant there: an icon from your own `./` file, or from another library,
- // is left as it is and never listed as missing.
+ // is left as it is and never listed as missing. Some libraries ship each
+ // look as its own package (Font Awesome's solid and regular packages): an
+ // icon from another package meets its variant only under the same export
+ // name and of the same kind, a component or data for the adapter. Once
+ // one icon of a package meets its twin, that package is a look package of
+ // the variant module, so its other icons are listed as missing.
const variantPackage = iconModulePackage(source.module);
+ /** @param {{module: string, source: string, adapt: boolean}} origin */
+ const otherPackageTwin = origin => {
+ if (origin.module.startsWith('.')) return false;
+ const twin = byLibraryExport.get(origin.source);
+ return twin != null && twin.adapt === origin.adapt;
+ };
+ const lookPackages = new Set(
+ set.data.icons.flatMap(icon => {
+ const origin = origins.get(icon.export);
+ return origin && otherPackageTwin(origin)
+ ? [iconModulePackage(origin.module)]
+ : [];
+ }),
+ );
const generated = generatedModulePath(set, packageDir);
/** @type {import('../../../foundation/discovery/icon-set-writer.mjs').GeneratedIcon[]} */
const toWrite = [];
@@ -662,7 +681,11 @@ async function addVariantForAll({cwd, from, selector, variant}) {
const own = [];
const icons = set.data.icons.map(icon => {
const origin = origins.get(icon.export);
- if (origin && iconModulePackage(origin.module) !== variantPackage) {
+ if (
+ origin &&
+ iconModulePackage(origin.module) !== variantPackage &&
+ !lookPackages.has(iconModulePackage(origin.module))
+ ) {
return icon;
}
const librarySource =
diff --git a/packages/cli/assets/docs/tree/icon-sets.doc.mjs b/packages/cli/assets/docs/tree/icon-sets.doc.mjs
index f24394111a..b91ace0ad4 100644
--- a/packages/cli/assets/docs/tree/icon-sets.doc.mjs
+++ b/packages/cli/assets/docs/tree/icon-sets.doc.mjs
@@ -139,11 +139,11 @@ astryx experimental icon add --variant solid --from @heroicons/react/24/solid --
},
{
type: 'prose',
- text: "A library that redraws its artwork for small sizes (Heroicons' 20px mini and 16px micro) ships each of those as its own set in its own package (their export names match the 24px ones), not as variants: a variant's size comes from CSS. `--variants` lists the variants; `--default-variant` names the one each icon's own export draws (when omitted, the look a library that names its looks draws; otherwise the set's current default, else, on a set without icons, the first variant; a set with icons changes it only with `--from`, and only in a library that names its looks). `--all` adds the variant for every icon whose id an export of `--from` has (`TrashIcon` in the solid module becomes `TrashSolidIcon`, the solid variant of `trash`), and the receipt lists the icons the module has no export for. Running it again changes nothing.",
+ text: "A library that redraws its artwork for small sizes (Heroicons' 20px mini and 16px micro) ships each of those as its own set in its own package (their export names match the 24px ones), not as variants: a variant's size comes from CSS. `--variants` lists the variants; `--default-variant` names the one each icon's own export draws (when omitted, the look a library that names its looks draws; otherwise the set's current default, else, on a set without icons, the first variant; a set with icons changes it only with `--from`, and only in a library that names its looks). `--all` adds the variant for every icon whose id an export of `--from` has (`TrashIcon` in the solid module becomes `TrashSolidIcon`, the solid variant of `trash`), and the receipt lists the icons the module has no export for. A library may ship each look as its own package (Font Awesome's solid and regular packages): `--from` may then name the other package, and an icon gains the variant from the export of the same name there; the receipt lists the icons that package has no export for. Running it again changes nothing.",
},
{
type: 'prose',
- text: 'A library whose icons are data (objects or SVG strings) has no components to find: create the set, declare an `adapter` in its data file (see library shapes), and run the command again; every data export then becomes an icon through the adapter. When every icon export shares a leading word, such as `feather` in `featherEye` and `featherSun`, ids and export names leave it out: `featherEye` becomes id `eye`, exported as `EyeIcon`. The prefix is read over icon-like exports only: SCREAMING_CASE constants (`README`, `VERSION`), number and boolean exports, and, next to components or icon objects, plain strings are never icons. Components named `…Provider` or `…Context` are never icons either. Leave out any other export that is not an icon with `--exclude meta,version`: the data file keeps the list in `exclude`, so a refresh leaves them out too. When a library exports one icon under several names (`Trash2` and `Trash`), the icon is recorded once and its other names become words, so `experimental icon trash-2` finds it and `experimental icon map delete trash-2` maps it. `experimental icon add` reads the prefix the same way, and reuses the icon an export already has, so its commands need no `--id`.',
+ text: 'A library whose icons are data (objects or SVG strings) has no components to find: create the set, declare an `adapter` in its data file (see library shapes), and run the command again; every data export then becomes an icon through the adapter. When every icon export shares a leading word, such as `feather` in `featherEye` and `featherSun`, ids and export names leave it out: `featherEye` becomes id `eye`, exported as `EyeIcon`. The prefix is read over icon-like exports only: SCREAMING_CASE constants (`README`, `VERSION`), number and boolean exports, and, next to components or icon objects, plain strings are never icons. Components named `…Provider` or `…Context` are never icons either, and neither is a pack: an object whose keys are all other exports of the module, such as `fas` next to `faXmark`. Leave out any other export that is not an icon with `--exclude meta,version`: the data file keeps the list in `exclude`, so a refresh leaves them out too. When a library exports one icon under several names (`Trash2` and `Trash`), the icon is recorded once and its other names become words, so `experimental icon trash-2` finds it and `experimental icon map delete trash-2` maps it. `experimental icon add` reads the prefix the same way, and reuses the icon an export already has, so its commands need no `--id`.',
},
],
},
diff --git a/packages/cli/clients/cli/commands/icon-look-packages.test.mjs b/packages/cli/clients/cli/commands/icon-look-packages.test.mjs
new file mode 100644
index 0000000000..e768311abc
--- /dev/null
+++ b/packages/cli/clients/cli/commands/icon-look-packages.test.mjs
@@ -0,0 +1,344 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Icon sets over a library of icon data objects that ships each look as
+ * its own package, shaped like Font Awesome: `add --variant <look> --from
+ * <other package> --all` adds the look for every icon, and a pack export
+ * (`fas`, an object of the other exports) is no icon and keeps the library
+ * prefix coming off, also in TypeScript source under `as` or `satisfies`.
+ * An icon of the set that the look's package does not
+ * export is listed as missing, and a glyph whose name starts with a digit
+ * (`fa0`) keeps the prefix.
+ */
+
+import * as fs from 'node:fs';
+import * as os from 'node:os';
+import * as path from 'node:path';
+import {afterEach, beforeEach, describe, expect, it} from 'vitest';
+import {runCli} from '../../../test-utils/run-cli.mjs';
+import {ICON_NAMES} from '../../../authoring/doctypes/icon-set/icon-names.mjs';
+
+/** @type {string} */
+let tmp;
+/** @type {string} */
+let pkg;
+
+const SOLID = '@acme/free-solid-glyphs';
+const REGULAR = '@acme/free-regular-glyphs';
+
+/**
+ * One look's package: data objects declared first and exported in one list,
+ * with alias names, a prefix string, an optional pack of every icon, and a
+ * declaration file.
+ * @param {string} name
+ * @param {string} prefix the look's prefix, `fas` or `far`
+ * @param {boolean} pack whether it exports the pack under the prefix
+ * @param {Array<[string, string]>} [extra] more glyphs, as export name and
+ * icon name
+ * @param {boolean} [typed] whether the package is TypeScript source whose
+ * pack wraps each value in `as` or `satisfies`
+ */
+function writeLook(name, prefix, pack, extra = [], typed = false) {
+ const lib = path.join(pkg, 'node_modules', ...name.split('/'));
+ fs.mkdirSync(lib, {recursive: true});
+ const source = typed ? 'index.ts' : 'index.mjs';
+ fs.writeFileSync(
+ path.join(lib, 'package.json'),
+ JSON.stringify({
+ name,
+ version: '7.0.0',
+ license: 'MIT',
+ main: typed ? source : 'index.js',
+ module: source,
+ types: typed ? source : 'index.d.ts',
+ exports: {
+ '.': typed
+ ? `./${source}`
+ : {
+ types: './index.d.ts',
+ import: './index.mjs',
+ require: './index.js',
+ },
+ },
+ }),
+ );
+ fs.writeFileSync(path.join(lib, 'LICENSE.txt'), 'MIT License\n');
+ const glyph = (/** @type {string} */ iconName, /** @type {string} */ d) =>
+ `{prefix: '${prefix}', iconName: '${iconName}', icon: [512, 512, [], 'f000', '${d}']}`;
+ const packValue = (/** @type {string} */ each, /** @type {number} */ at) =>
+ !typed
+ ? each
+ : `${each} ${at % 2 === 0 ? 'as' : 'satisfies'} IconDefinition`;
+ const exported = [
+ 'faClose',
+ 'faHome',
+ 'faHouse',
+ 'faMagnifyingGlass',
+ 'faXmark',
+ ...extra.map(([each]) => each),
+ ];
+ fs.writeFileSync(
+ path.join(lib, source),
+ [
+ ...(typed
+ ? [
+ 'type IconDefinition = {prefix: string; iconName: string; icon: unknown[]};',
+ ]
+ : []),
+ `var prefix = '${prefix}';`,
+ `var faXmark = ${glyph('xmark', 'M0 0')};`,
+ 'var faClose = faXmark;',
+ `var faHouse = ${glyph('house', 'M1 1')};`,
+ 'var faHome = faHouse;',
+ `var faMagnifyingGlass = ${glyph('magnifying-glass', 'M2 2')};`,
+ ...extra.map(
+ ([each, iconName]) => `var ${each} = ${glyph(iconName, 'M3 3')};`,
+ ),
+ `var icons = {${exported.map((each, at) => `${each}: ${packValue(each, at)}`).join(', ')}};`,
+ '',
+ `export { ${pack ? `icons as ${prefix}, ` : ''}prefix, ${exported.join(', ')} };`,
+ '',
+ ].join('\n'),
+ );
+ if (typed) return;
+ fs.writeFileSync(
+ path.join(lib, 'index.d.ts'),
+ [
+ ...(pack ? [`export const ${prefix}: object;`] : []),
+ 'export const prefix: string;',
+ ...exported.map(each => `export const ${each}: object;`),
+ '',
+ ].join('\n'),
+ );
+}
+
+beforeEach(() => {
+ tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-icon-look-packages-'));
+ pkg = path.join(tmp, 'icons');
+ fs.mkdirSync(path.join(pkg, 'src'), {recursive: true});
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(
+ {
+ name: '@acme/icons',
+ version: '1.0.0',
+ license: 'MIT',
+ type: 'module',
+ exports: {'.': './index.js'},
+ dependencies: {[SOLID]: '^7.0.0', [REGULAR]: '^7.0.0'},
+ },
+ null,
+ 2,
+ ),
+ );
+ fs.writeFileSync(
+ path.join(pkg, 'src', 'adapt.js'),
+ 'export function adapt(data) { return () => null; }\n',
+ );
+ fs.writeFileSync(
+ path.join(pkg, 'index.js'),
+ "export * from './icon-sets/glyphs/glyphs.generated.js';\n",
+ );
+});
+afterEach(() => {
+ fs.rmSync(tmp, {recursive: true, force: true});
+});
+
+/** @param {string[]} args */
+async function json(args) {
+ const res = await runCli([...args, '--json'], pkg);
+ return {code: res.code, body: JSON.parse(res.stdout)};
+}
+
+const dataFile = () =>
+ path.join(pkg, 'icon-sets', 'glyphs', 'glyphs.icons.json');
+const dataOf = () => JSON.parse(fs.readFileSync(dataFile(), 'utf-8'));
+
+/** A set with solid and regular variants and the adapter, wrapping solid. */
+async function wrapSolid() {
+ const created = await json([
+ 'experimental',
+ 'icon',
+ 'new-set',
+ 'glyphs',
+ '--variants',
+ 'solid,regular',
+ '--default-variant',
+ 'solid',
+ ]);
+ expect(created.code, JSON.stringify(created.body)).toBe(0);
+ const data = dataOf();
+ data.adapter = {module: './src/adapt.js', export: 'adapt'};
+ fs.writeFileSync(dataFile(), JSON.stringify(data));
+ const wrapped = await json([
+ 'experimental',
+ 'icon',
+ 'new-set',
+ 'glyphs',
+ '--from',
+ SOLID,
+ ]);
+ expect(wrapped.code, JSON.stringify(wrapped.body)).toBe(0);
+}
+
+const addRegular = () =>
+ json([
+ 'experimental',
+ 'icon',
+ 'add',
+ '--variant',
+ 'regular',
+ '--from',
+ REGULAR,
+ '--all',
+ ]);
+
+/** The set's icons as `[id, export, ...variant exports]`. */
+const iconRows = () =>
+ dataOf().icons.map((/** @type {any} */ icon) => [
+ icon.id,
+ icon.export,
+ ...(icon.variants ?? []).map((/** @type {any} */ each) => each.export),
+ ]);
+
+/**
+ * Map every built-in definition to one icon and run the strict check.
+ * Returns every issue it reports and every failure, without the skipped
+ * TypeScript work.
+ */
+async function strictFailures() {
+ const mapped = await json([
+ 'experimental',
+ 'icon',
+ 'map',
+ '--pairs',
+ ICON_NAMES.map(name => `${name}=xmark`).join(','),
+ ]);
+ expect(mapped.code, JSON.stringify(mapped.body)).toBe(0);
+ const res = await runCli(['integration', 'check', '--strict', '--json'], pkg);
+ const {checks, failures} = JSON.parse(res.stdout).data;
+ return [
+ ...checks.flatMap(
+ (/** @type {any} */ each) => each.response?.data?.issues ?? [],
+ ),
+ ...failures,
+ ]
+ .filter(
+ (/** @type {{code: string}} */ each) => each.code !== 'doc_types_skipped',
+ )
+ .map(
+ (/** @type {{code: string, message: string}} */ each) =>
+ `${each.code}: ${each.message}`,
+ );
+}
+
+describe('a library of icon data objects with one package per look', () => {
+ it('add --variant regular --all from the regular package adds the variant for every icon', async () => {
+ writeLook(SOLID, 'fas', false);
+ writeLook(REGULAR, 'far', false);
+ await wrapSolid();
+ const added = await addRegular();
+ expect(added.code, JSON.stringify(added.body)).toBe(0);
+ expect(added.body.data).toMatchObject({added: 3, missing: []});
+ expect(iconRows()).toEqual([
+ ['house', 'HouseIcon', 'HouseRegularIcon'],
+ ['magnifying-glass', 'MagnifyingGlassIcon', 'MagnifyingGlassRegularIcon'],
+ ['xmark', 'XmarkIcon', 'XmarkRegularIcon'],
+ ]);
+ const generated = fs.readFileSync(
+ path.join(pkg, 'icon-sets', 'glyphs', 'glyphs.generated.js'),
+ 'utf-8',
+ );
+ expect(generated).toContain(
+ `import {faXmark as XmarkRegularIconSource} from '${REGULAR}';`,
+ );
+ expect(generated).toContain(
+ 'export const XmarkRegularIcon = adaptIcon(XmarkRegularIconSource);',
+ );
+ const again = await addRegular();
+ expect(again.body.data).toMatchObject({added: 0, changed: false});
+ expect(await strictFailures()).toEqual([]);
+ });
+
+ it('a pack export (`fas`) is no icon, and the `fa` prefix still comes off the names', async () => {
+ writeLook(SOLID, 'fas', true);
+ writeLook(REGULAR, 'far', true);
+ await wrapSolid();
+ expect(iconRows()).toEqual([
+ ['house', 'HouseIcon'],
+ ['magnifying-glass', 'MagnifyingGlassIcon'],
+ ['xmark', 'XmarkIcon'],
+ ]);
+ const added = await addRegular();
+ expect(added.code, JSON.stringify(added.body)).toBe(0);
+ expect(added.body.data).toMatchObject({added: 3, missing: []});
+ expect(await strictFailures()).toEqual([]);
+ });
+
+ it('a TypeScript pack whose values use `as` or `satisfies` is no icon either', async () => {
+ writeLook(SOLID, 'fas', true, [], true);
+ writeLook(REGULAR, 'far', true, [], true);
+ await wrapSolid();
+ expect(iconRows()).toEqual([
+ ['house', 'HouseIcon'],
+ ['magnifying-glass', 'MagnifyingGlassIcon'],
+ ['xmark', 'XmarkIcon'],
+ ]);
+ });
+
+ it('icons whose names start with a digit (`fa0`, `fa500px`) keep the `fa` prefix, and the set passes the strict check', async () => {
+ writeLook(SOLID, 'fas', true, [
+ ['fa0', '0'],
+ ['fa500px', '500px'],
+ ]);
+ writeLook(REGULAR, 'far', true);
+ await wrapSolid();
+ expect(iconRows()).toEqual([
+ ['fa-0', 'Fa0Icon'],
+ ['fa-500px', 'Fa500pxIcon'],
+ ['house', 'HouseIcon'],
+ ['magnifying-glass', 'MagnifyingGlassIcon'],
+ ['xmark', 'XmarkIcon'],
+ ]);
+ expect(await strictFailures()).toEqual([]);
+ });
+
+ it('add --variant regular --all lists the icons the regular package does not export as missing', async () => {
+ writeLook(SOLID, 'fas', true, [
+ ['fa0', '0'],
+ ['faTrash', 'trash'],
+ ]);
+ writeLook(REGULAR, 'far', true);
+ await wrapSolid();
+ const added = await addRegular();
+ expect(added.code, JSON.stringify(added.body)).toBe(0);
+ expect(added.body.data).toMatchObject({
+ added: 3,
+ missing: ['fa-0', 'trash'],
+ });
+ expect(iconRows()).toEqual([
+ ['fa-0', 'Fa0Icon'],
+ ['house', 'HouseIcon', 'HouseRegularIcon'],
+ ['magnifying-glass', 'MagnifyingGlassIcon', 'MagnifyingGlassRegularIcon'],
+ ['trash', 'TrashIcon'],
+ ['xmark', 'XmarkIcon', 'XmarkRegularIcon'],
+ ]);
+ const res = await runCli(
+ [
+ 'experimental',
+ 'icon',
+ 'add',
+ '--variant',
+ 'regular',
+ '--from',
+ REGULAR,
+ '--all',
+ ],
+ pkg,
+ );
+ expect(res.stdout).toContain(
+ `2 icons have no regular export in ${REGULAR} and keep none: fa-0, trash`,
+ );
+ expect(await strictFailures()).toEqual([]);
+ });
+});
diff --git a/packages/cli/foundation/discovery/icon-set-writer.mjs b/packages/cli/foundation/discovery/icon-set-writer.mjs
index fe287e5d15..8904cd33db 100644
--- a/packages/cli/foundation/discovery/icon-set-writer.mjs
+++ b/packages/cli/foundation/discovery/icon-set-writer.mjs
@@ -48,6 +48,7 @@ import {
exportValueKind,
followedExportNames,
moduleExportOrigin,
+ staticExportBindings,
} from './module-exports.mjs';
/** @typedef {import('./icon-set-discovery.mjs').DiscoveredIconSet} DiscoveredIconSet */
@@ -608,7 +609,7 @@ const SCREAMING_CASE_RE = /^[A-Z][A-Z0-9_]+$/u;
* set declares an adapter, also data exports, camelCase included: objects,
* and plain strings only in a library whose candidates are all strings.
* Left out: `default`, `Icon`, `…Provider` and `…Context` components, SCREAMING_CASE constants, number and boolean
- * exports, and `exclude`.
+ * exports, packs of other exports ({@link isIconPack}), and `exclude`.
* @param {string} file
* @param {{adapter?: boolean, exclude?: string[]}} [options] `exclude`: export
* names that are not icons
@@ -618,7 +619,9 @@ function iconCandidates(file, {adapter = false, exclude = []} = {}) {
const skipped = new Set(exclude);
/** @type {Array<{name: string, adapt: boolean, scalar: string | null}>} */
const out = [];
- for (const name of followedExportNames(file)) {
+ const names = followedExportNames(file);
+ const exported = new Set(names);
+ for (const name of names) {
if (name === 'default' || name === 'Icon' || skipped.has(name)) continue;
// A context provider or context (`LucideProvider`) is a component that
// draws nothing.
@@ -631,7 +634,8 @@ function iconCandidates(file, {adapter = false, exclude = []} = {}) {
} else if (
adapter &&
kind === 'data' &&
- /^[A-Za-z][A-Za-z0-9]*$/u.test(name)
+ /^[A-Za-z][A-Za-z0-9]*$/u.test(name) &&
+ !isIconPack(file, name, exported)
) {
const scalar = exportScalarType(file, name);
// A number or a boolean draws nothing; a string may be SVG markup.
@@ -646,6 +650,20 @@ function iconCandidates(file, {adapter = false, exclude = []} = {}) {
: out;
}
+/**
+ * Whether a data export is a pack: an object whose keys are all other
+ * exports of the module, such as `fas` in a library that also exports
+ * `faXmark` and `faHouse`. A pack holds icons but draws nothing.
+ * @param {string} file
+ * @param {string} name
+ * @param {Set<string>} exported every export name of the module
+ */
+function isIconPack(file, name, exported) {
+ const bindings = staticExportBindings(file, name);
+ if (bindings == null || bindings.size < 2) return false;
+ return [...bindings.keys()].every(key => key !== name && exported.has(key));
+}
+
/**
* The exports of a library that are not icons and that wrapping it leaves
* out (`Icon`, `LucideProvider`, `createLucideIcon`, constants), so the
@@ -1868,10 +1886,11 @@ export function generatedNamesOf(packageDir, generated, from, source) {
* differently; and a refresh changes only the icons its module supplies.
* @param {string} packageDir
* @param {string} generated
- * @returns {Map<string, {module: string, source: string}>}
+ * @returns {Map<string, {module: string, source: string, adapt: boolean}>}
+ * `adapt`: the set's adapter turns the export into a component
*/
export function generatedOrigins(packageDir, generated) {
- /** @type {Map<string, {module: string, source: string}>} */
+ /** @type {Map<string, {module: string, source: string, adapt: boolean}>} */
const origins = new Map();
const file = path.join(packageDir, generated);
if (!fs.existsSync(file)) return origins;
@@ -1898,6 +1917,7 @@ export function generatedOrigins(packageDir, generated) {
origins.set(reexport[2] ?? reexport[1], {
module: fromRoot(reexport[3]),
source: reexport[1],
+ adapt: false,
});
continue;
}
@@ -1908,6 +1928,7 @@ export function generatedOrigins(packageDir, generated) {
origins.set(adapted[2], {
module: fromRoot(adapted[3]),
source: adapted[1],
+ adapt: true,
});
continue;
}
@@ -1918,6 +1939,7 @@ export function generatedOrigins(packageDir, generated) {
origins.set(adaptedDefault[1], {
module: fromRoot(adaptedDefault[2]),
source: 'default',
+ adapt: true,
});
}
}