Icon package builds and framework exports
The icon package build system projects one shared icon catalog and its SVG artwork into installable outputs for raw data, static files, and UI frameworks. It keeps slugs, artwork paths, metadata, and available variants aligned while adapting the catalog for React, React Native, Vue, Svelte, Preact, Solid, Astro, and the thesvg compatibility package.
Build pipeline
The pipeline reads catalog records and the SVG files named by those records. Package builders then create public modules or files, while package-specific checks confirm that the output still represents the catalog and fits its target runtime.
Catalog and artwork contract
The catalog in src/…/icons.json is the shared contract for slugs, metadata, and variant paths. The SVG files under public/icons provide the artwork. Generated dist folders are release output and are not hand-maintained source.
Generic package builders use one shared collection filter. The flags collection stays in the catalog for site, search, CLI, MCP, and CDN use, but it is built by the specialty flags package rather than by the generic icon and framework packages.
Builders use each recorded variant path instead of guessing a file name from a variant key. This lets an icon keep working when its file name or directory differs from the variant name.
References: src/…/icons.json• L1-20 packages/…/build-icons.ts• L34-76 packages/…/catalog.ts• L1-24 packages/…/excluded-collections.json• L1-4 scripts/…/generate-flags.mjs• L15-20
Source safety
SVG intake and audit tools keep unsafe or unusable artwork out of package output. Imported candidates need a usable SVG root and viewBox; audits reject executable markup, unsafe links, external references, and embedded raster content.
The repository also has an icon quality gate for size, drawable content, duplicate IDs, editor metadata, unsafe markup, and mono-variant paint. The sanitizer removes dangerous elements and attributes before enriched SVG content reaches downstream builders. A source file that passes intake can still need a renderer-specific transform before it is used by a framework package.
References: scripts/validate-icons.ts• L1-39 scripts/validate-icons.ts• L119-173 packages/…/enrich-svgl-variants.ts• L122-165 packages/…/sanitize-svg.ts• L79-99 packages/…/sanitize-svg.ts• L101-163 packages/…/audit-svg.ts• L32-70 packages/…/audit-svg-sources.ts• L13-46
Derived catalog data
Some catalog jobs create data for the site rather than package exports. The adopter snapshot records public repository use, and the tone raster job records icons that need contrast plates; neither changes the generic package module set.
References: scripts/adopters-snapshot.ts• L142-183 scripts/icon-tones-raster.mjs• L19-53
Catalog-backed services
The MCP worker is a private service consumer rather than a published icon export. Its package scripts copy the shared catalog into the worker before development, type checks, tests, and deployment so search and tool responses use the same catalog as the package builders.
References: packages/…/package.json• L18-28
Build order
The core data package is the first generated package. The thesvg package mirrors that output and must be rebuilt after @thesvg/icons; the other packages can then build their own framework surfaces from the shared catalog and artwork.
This diagram shows how the catalog selects generic and specialty outputs before each consumer-facing surface is built.
flowchart TD
C[Catalog metadata] --> S[Catalog selection]
A[SVG artwork] --> G[Generic package builders]
S --> G
S --> B[Flags package builder]
G --> I[@thesvg/icons]
I --> T[thesvg re-exports]
G --> F[Framework and static builders]
F --> R[React]
F --> N[React Native]
F --> V[Vue]
F --> U[Svelte]
F --> P[Preact]
F --> O[Solid]
F --> X[Astro and static files]
B --> Q[@thesvg/flags]
References: .github/…/release.yml• L50-68 packages/…/build-reexports.mjs• L9-65 packages/…/build-icons.ts• L61-115 packages/…/catalog.ts• L13-24 scripts/…/generate-flags.mjs• L228-240
Package outputs
Each output serves a different consumption model. The core and convenience packages expose icon data, the static package serves files without JavaScript, and framework packages provide typed components that match the host renderer.
Core icon data package
@thesvg/icons is the base package for consumers that need raw SVG data and icon metadata. It generates per-icon modules, shared types, and ESM and CommonJS entry points while omitting records that have no readable SVG source or belong to an excluded specialty collection.
Its scripts separate generation from release gates. build creates the output, test checks catalog and generator helpers, audit checks source SVGs and generated code, and validate checks the published distribution. The publish hook runs the build, audit, and distribution validation in that order.
The package metadata records the flags package split. Flags remain in the shared catalog but are not added to the generic package or its framework projections.
References: packages/…/build-icons.ts• L62-119 packages/…/catalog.test.ts• L1-16 packages/…/package.json• L27-52 packages/…/validate-dist.mjs• L38-181
React and React Native packages
@thesvg/react turns icon artwork into typed React components. It keeps catalog variant choices and forwards normal SVG props. @thesvg/react-native converts the same artwork into native render data and uses a shared runtime for react-native-svg.
React Native is a separate native compatibility boundary. Its builder removes SVG constructs that the native renderer cannot use and reports what it flattens. The package exposes barrel and per-icon imports, typed variant props, and a shared createIcon entry.
Both packages validate icon coverage and declared variants against the catalog. React Native also checks its shared runtime and type contract. Their publish hooks build the generated output, while React and React Native validation remains an explicit package role.
References: packages/…/build-components.ts• L280-318 packages/…/validate-output.ts• L74-198 packages/…/build-components.ts• L445-479 packages/…/build-components.ts• L781-884 packages/…/validate-output.ts• L43-139 packages/…/package.json• L49-57 packages/…/package.json• L55-65
Vue and Svelte packages
@thesvg/vue and @thesvg/svelte project a primary SVG for each catalog icon into native components for their runtimes. They preserve caller attributes and use catalog paths, so artwork location does not depend on the variant name.
Svelte emits component files and declarations with Svelte-aware export conditions. Its generated component forwards SVG attributes and uses the SVG inner content as component markup. Vue and Svelte build during publication but do not define the same standalone output validator used by React and React Native.
References: packages/…/build-components.ts• L81-120 packages/…/build-components.ts• L289-342 packages/…/package.json• L30-55 packages/…/build-components.ts• L79-161 packages/…/build-components.ts• L190-225 packages/…/package.json• L29-53
Preact and Solid packages
@thesvg/preact and @thesvg/solid provide typed components for their host runtimes. Preact uses precompiled render calls, while Solid uses its dynamic element model so the result can serve browser and server rendering.
Both packages expose a shared component contract and per-icon modules. Their validation checks cover generated module shape, source paint fidelity, icon coverage, and the variants that have real files in the catalog.
References: packages/…/build-components.ts• L4-95 packages/…/build-components.ts• L4-107 packages/…/validate-output.ts• L47-115 packages/…/validate-output.ts• L47-115 packages/…/package.json• L29-56 packages/…/package.json• L30-57
Astro package
@thesvg/astro generates one typed .astro component for each usable primary SVG. It targets build-time rendering, so the published component produces static inline SVG without client JavaScript and supports individual imports for small bundles.
The builder also makes internal SVG IDs unique per icon and publishes component declarations and named barrels. Astro uses a different export shape from the dual ESM/CommonJS framework packages because its consumers resolve .astro files and Astro-specific types.
References: packages/…/build-components.ts• L45-91 packages/…/build-components.ts• L106-159 packages/…/build-components.ts• L203-237 packages/…/package.json• L30-54 packages/…/README.md• L18-24
Static package
@thesvg/static serves the catalog for CDNs, plain HTML, CSS, and other non-JavaScript use cases. Its build copies every referenced SVG into a stable dist/svg/<slug>/ tree and writes a compact manifest with icon identity, categories, and variant paths.
The static output follows the same generic catalog selection as the other package builders. Its --check mode confirms that the manifest covers the packaged registry and that each icon has at least one variant. Its package exports expose the manifest and SVG paths rather than component modules.
References: packages/…/build.mjs• L1-42 packages/…/package.json• L19-29 packages/…/README.md• L5-23 packages/…/catalog.ts• L1-24
Convenience re-export package
thesvg is a shorter compatibility name for the core icon data package. Its generator mirrors generated core modules, barrels, and shared types into its own distribution instead of creating a second catalog.
Because it reads packages/icons/dist, it has no independent source build. Release automation must run packages/…/build-reexports.mjs after the core build. Its workspace dependency on @thesvg/icons means releases must keep the compatibility surface aligned with the core package.
References: packages/…/build-reexports.mjs• L9-65 packages/…/package.json• L33-55 .github/…/release.yml• L50-54
Export and validation contracts
Generated output is usable only when its files, declarations, barrels, and package export map agree. Validation therefore checks both content and reachability from package entry points.
Public module surfaces
Most component and data packages publish a root entry plus one per-icon subpath in ESM, CommonJS, and declaration form. Svelte and Astro use framework-aware export conditions. React Native adds a shared runtime entry and places icon modules under icons/.
| Package | Main consumer surface | Per-icon surface |
|---|---|---|
@thesvg/icons | Raw icon data and types | /<slug> |
@thesvg/react | React components | /<slug> |
@thesvg/react-native | Native components and types | /icons/<slug> plus /createIcon |
@thesvg/vue | Vue components | /<slug> |
@thesvg/svelte | Svelte components | /<slug> |
@thesvg/preact | Preact components | /<slug> |
@thesvg/solid | Solid components | /<slug> |
@thesvg/astro | Astro component barrel and types | /<slug> |
@thesvg/static | Manifest and SVG files | ./icons.json, ./svg/* |
thesvg | Forwarded core icon data | /<slug> |
@thesvg/flags | Flag data, React components, and metadata | /flags/*, /react/*, /svg/* |
The generic surfaces do not expose the excluded flags collection. The separate @thesvg/flags package publishes raw, React, and static flag surfaces through its own export map. An output file that is missing from its barrel or export map is not a usable public export. This is why package shape and module resolution are part of the build contract.
References: packages/…/package.json• L27-37 packages/…/package.json• L30-45 packages/…/package.json• L29-41 packages/…/package.json• L30-42 packages/…/package.json• L19-23 packages/…/package.json• L33-46 packages/…/package.json• L28-91 packages/…/excluded-collections.json• L1-4
Validation layers
Validation is split by risk. Core checks cover generated safety, distribution shape, imports, and source SVGs. Framework checks compare generated output with the catalog and target renderer. Static checks compare the manifest with the packaged registry.
| Area | Main guarantee |
|---|---|
| Core data | Generated modules and exports cover usable, non-excluded catalog entries. |
| SVG source | Artwork meets source quality and safety rules. |
| React and native | Components keep source paint and declared usable variants. |
| Preact and Solid | Generated modules remain renderer-safe and complete. |
| Static files | Manifest counts and referenced files match the packaged registry. |
| Vue, Svelte, and Astro | Build output follows each framework’s public file contract. |
| Flags | The specialty collection has its own source, metadata, artwork, and license checks. |
The core distribution validator checks required package files, output counts, excluded-collection leakage, bundle size, reserved-word identifiers, sample imports, and the package export map. The catalog helper tests protect the shared selection rule so a new generic builder does not silently include specialty entries.
References: packages/…/validate-dist.mjs• L38-181 packages/…/catalog.test.ts• L1-16 scripts/validate-icons.ts• L119-173 packages/…/security-audit.mjs• L14-128 packages/…/validate-output.ts• L74-198 packages/…/validate-output.ts• L43-139 packages/…/validate-output.ts• L47-115 packages/…/build.mjs• L33-39 scripts/…/generate-flags.mjs• L380-404
Release scripts
Package scripts define local roles. The release workflow defines the complete cross-package sequence. Core output and its convenience re-export must be current before the framework and static packages are published.
| Package | Build role | Validation or test role | Publish role |
|---|---|---|---|
@thesvg/icons | Generate raw modules for the packaged catalog | Tests selection and helpers, audits, and distribution validation | Runs all core gates |
@thesvg/react | Generate React components | Generated-output validation | Runs build |
@thesvg/react-native | Generate native data and shared runtime | Output validation and TypeScript checking | Builds before publish |
@thesvg/vue | Generate Vue components | No package validator | Runs build |
@thesvg/svelte | Generate Svelte components | No package validator | Runs build |
@thesvg/preact | Generate Preact components | Output validation | Runs build |
@thesvg/solid | Generate Solid components | Output validation | Runs build |
@thesvg/astro | Generate Astro components | Build output only | Runs build |
@thesvg/static | Copy SVGs and write manifest | Rebuild-and-check mode | Runs build |
thesvg | Mirror core output | Release workflow responsibility | Explicit re-export script |
@thesvg/flags | Generate the excluded flags collection and metadata | Builds the package and checks source, count, fidelity, and license rules | Separate specialty package release |
@thesvg/mcp-worker | Copy the shared catalog for the worker | Type checks and runs worker tests against the copied catalog | Copies the catalog before deployment |
The current package scripts keep build and publish roles explicit. In particular, the packages without a standalone validator still run their build before publication, while the static package uses its test command as a manifest check and the flags generator stages all writes before committing them.
References: packages/…/package.json• L47-52 packages/…/package.json• L49-53 packages/…/package.json• L49-54 packages/…/package.json• L50-55 packages/…/package.json• L49-51 packages/…/package.json• L25-29 packages/…/package.json• L48-51 packages/…/package.json• L50-53 packages/…/package.json• L102-106 packages/…/package.json• L18-28 scripts/…/generate-flags.mjs• L1-23 .github/…/release.yml• L50-68
Catalog relationships
The package pipeline is one consumer of the shared catalog. The icon catalog and data pipeline page explains catalog creation, web icon discovery explains browser-facing use, and icon families and brand grouping explains related grouping data.
Shared catalog effects
A catalog or SVG change can affect raw data, static files, framework components, and browser-facing views at once. The builders do not create catalog meaning; they project the existing slug, metadata, and variant contract into formats that downstream consumers can import or serve.
The compatibility package uses the workspace @thesvg/icons dependency and must be released with a matching core output. The flags remain visible in shared catalog features, while generic package builders exclude them and the specialty generator produces their own package data and artwork.
References: src/…/icons.json• L1-20 packages/…/build-icons.ts• L61-115 packages/…/catalog.ts• L13-24 scripts/…/generate-flags.mjs• L303-373 packages/…/package.json• L28-106 packages/…/package.json• L33-55
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to src/…/icons.json or
public/iconsrequire the core build, thethesvgre-export build, and fresh framework and static builds. If the change is inflags, use the specialty flags build instead of adding it to generic package output. - Changes to packages/…/excluded-collections.json or a new generic builder must preserve the one shared exclusion rule. Update the expected distribution count and selection tests with the rule.
- Variant keys and recorded paths must preserve the catalog-to-file contract. React, React Native, Preact, and Solid validation use real source paths to confirm variant coverage.
- Slug changes affect file names, component names, barrels, subpath imports, static paths, and re-export discovery. Clean generated output before relying on the result.
- Changes to module format or framework conditions must update the matching
exportsmap and generated barrels. A present file that is not exported cannot be imported. - Changes to SVG constructs must be checked against the target renderer. Browser SVG, React Native SVG, Astro, Vue, Svelte, Preact, and Solid do not have identical support.
- Changes to source SVG quality rules or their exemptions must keep scripts/validate-icons.ts and the flag generator’s size and fidelity rules consistent where they cover the same artwork.
- Changes to core output must happen before packages/…/build-reexports.mjs; otherwise the compatibility package can expose stale data. Release
thesvgwith the matching@thesvg/iconsoutput even though the workspace dependency is version-ranged during development. - Changes to React Native build or publish scripts must keep its compiled icons, declarations, validation, and type checking aligned with the package export contract.
- Changes to package build or publish scripts must preserve the explicit release list. Packages without a package-level validator still need their release build step.
- Changes to the shared catalog must preserve the MCP worker copy step before worker build, test, and deployment scripts run.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
thesvg re-exports run before @thesvg/icons builds | The compatibility package exposes old or missing icon modules | Build core first, then run build-reexports.mjs |
thesvg and @thesvg/icons are released from different generated outputs | Consumers can receive a compatibility surface that does not match the core catalog | Build core first and release both package surfaces together |
| A catalog path points to a missing SVG | Core output omits the icon or a framework emits an empty result | Run core validation and framework coverage checks |
| A specialty collection is not passed through the shared catalog filter | Flags leak into generic packages or create duplicate public surfaces | Keep excluded-collections.json as the source of truth and run catalog tests |
| A variant key is used to guess a file name | Valid variants disappear when paths do not match keys | Use the catalog path as the file location |
| Unsafe or oversized SVG markup reaches intake | Source or generated audits fail, or unsafe content reaches consumers | Run source quality and security audits |
A slug changes without cleaning dist | Old modules remain importable and can enter re-exports | Clean output before generation |
| A generated file lacks an export-map or barrel entry | Consumers get resolution or named-export errors | Check generated files, barrels, and exports together |
| Browser-only SVG markup reaches native output | The icon loses supported styles, filters, or elements | Apply native conversion rules and run native validation |
| Static output is built from an old catalog | CDN files and manifest entries do not match package data | Rebuild static output and run --check |
| A package publish hook omits its build | A published package contains stale or missing generated output | Keep each package’s prepublishOnly build role intact |
| A flag source or license check fails during generation | The flags package and shared catalog are not updated as one set | Let the staged flags generator abort before it writes output |
| The MCP worker uses a stale copied catalog | Search and tool responses do not reflect the shared icon catalog | Run the package pre-build, pre-test, and pre-deploy catalog copy steps |
Key files
| File | Why to read it |
|---|---|
| src/…/icons.json | Defines the shared slug, metadata, and variant-path contract. |
public/icons/ | Holds the SVG artwork consumed by package builders. |
| packages/…/build-icons.ts | Shows the core raw-data generation flow. |
| packages/…/catalog.ts | Defines which catalog entries generic packages build. |
| packages/…/excluded-collections.json | Records specialty collections excluded from generic package output. |
| packages/…/catalog.test.ts | Protects the shared catalog selection rule. |
| packages/…/validate-dist.mjs | Defines core distribution, count, import, and export checks. |
| scripts/validate-icons.ts | Defines the repository-wide SVG quality gate. |
| packages/…/audit-svg-sources.ts | Applies source SVG safety checks. |
| packages/…/sanitize-svg.ts | Defines SVG safety transforms used before downstream generation. |
| packages/…/build-components.ts | Shows the browser React projection. |
| packages/…/build-components.ts | Shows the native render-data and shared-runtime boundary. |
| packages/…/package.json | Defines native package exports and build, validation, test, typecheck, and publish roles. |
| packages/…/build-components.ts | Shows the Vue component projection. |
| packages/…/build-components.ts | Shows the Svelte component and declaration projection. |
| packages/…/build-components.ts | Shows the precompiled Preact component model. |
| packages/…/build-components.ts | Shows the Solid component and server-rendering model. |
| packages/…/build-components.ts | Shows static Astro component generation and ID handling. |
| packages/…/build.mjs | Shows static SVG copying and manifest generation. |
| packages/…/build-reexports.mjs | Shows how the compatibility package mirrors core output. |
| packages/…/package.json | Defines the compatibility package dependency and public export map. |
| scripts/…/generate-flags.mjs | Shows the separate specialty collection build and its source checks. |
| packages/…/package.json | Defines the flags package export surfaces and generation, build, test, and pack roles. |
| packages/…/package.json | Defines when the worker copies catalog data and how its build, test, and deployment checks run. |
| packages/…/package.json | Defines package exports, scripts, peer contracts, and published files. |
| .github/…/release.yml | Defines the cross-package build and publish order. |
| .github/…/version.yml | Defines version fan-out after catalog and package changes. |