Replace iconify/json with build-time icon fetching#499
Open
titouanmathis wants to merge 11 commits intodevelopfrom
Open
Replace iconify/json with build-time icon fetching#499titouanmathis wants to merge 11 commits intodevelopfrom
titouanmathis wants to merge 11 commits intodevelopfrom
Conversation
Adds a Composer plugin that scans templates for meta_icon() calls and fetches only the used icons from the Iconify API. Icons are stored as local SVG files in a configurable output directory. New classes: - Plugin: hooks into post-install/post-update events - Config: reads settings from composer.json extra section - IconScanner: scans templates for meta_icon() references - IconFetcher: batch-fetches icons from the Iconify API - IconStorage: manages local SVG files - IconSyncCommand: composer ui:icons [--dry-run] [--prune] - IconPruneCommand: composer ui:icons:prune Closes #498 Co-authored-by: Claude <claude@anthropic.com>
The meta_icon() Twig function now checks for local SVG files first (stored by the Composer plugin), then falls back to iconify/json if installed. This ensures full backward compatibility — existing projects continue to work unchanged. Co-authored-by: Claude <claude@anthropic.com>
The iconify/json and iconify/json-tools packages are no longer required at runtime since the Composer plugin fetches icons at build-time. They are kept in require-dev for testing the legacy fallback. The package type is changed to composer-plugin so the Plugin class can hook into post-install/post-update events and provide CLI commands. Co-authored-by: Claude <claude@anthropic.com>
Tests for IconScanner, IconFetcher, IconStorage, and Icon local file fallback. 26 new tests covering scanning, fetching, storage, pruning, and the Twig function's local-file-first behavior. Co-authored-by: Claude <claude@anthropic.com>
Export SizeUnchanged@studiometa/ui
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #499 +/- ##
==============================================
+ Coverage 67.96% 87.14% +19.18%
- Complexity 20 134 +114
==============================================
Files 77 12 -65
Lines 1998 498 -1500
Branches 357 0 -357
==============================================
- Hits 1358 434 -924
+ Misses 558 64 -494
+ Partials 82 0 -82
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Co-authored-by: Claude <claude@anthropic.com>
Add installation instructions for the Composer plugin (allow-plugins, CLI commands, configuration options) and a tip in the Icon component docs about automatic icon fetching. Co-authored-by: Claude <claude@anthropic.com>
- Remove composer/composer from require-dev (causes dependency conflicts on PHP 8.1) - Exclude Composer plugin classes from phpstan analysis (they depend on Composer classes available at runtime, not in vendor) - Regenerate composer.lock with PHP 8.1 to ensure compatibility across the full CI matrix (8.1–8.4) Co-authored-by: Claude <claude@anthropic.com>
- Bump PHP requirement from ^8.1 to ^8.3 - Upgrade pestphp/pest from ^2.0 to ^3.0 - Upgrade spatie/pest-plugin-snapshots from ^2.0 to ^2.3 - Add composer/composer ^2.9 as dev dependency for testing Composer plugin - Update CI matrices to PHP 8.3, 8.4, 8.5 Co-authored-by: Claude <claude@anthropic.com>
- ConfigTest: 7 tests covering all config reading and path resolution - PluginCommandProviderTest: 1 test verifying command registration - IconSyncCommandTest: 8 tests covering sync, dry-run, prune, failures - IconPruneCommandTest: 4 tests covering prune scenarios - PluginTest: 6 tests covering event subscription and sync lifecycle - Add helpers.php with createComposerStub and createCommandTester - Update snapshots for Pest 3 compatibility Co-authored-by: Claude <claude@anthropic.com>
Co-authored-by: Claude <claude@anthropic.com>
- Add mock Iconify API server (tests/Composer/fixtures/mock-api.php) - All tests now use mock server instead of hitting the real Iconify API - Add mockery/mockery dev dependency - Remove phpstan excludePaths for Composer directory (passes at max level) - Tests run in 0.4s instead of 1.8s Co-authored-by: Claude <claude@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #498
Replaces the ~690MB
iconify/jsonruntime dependency with a Composer plugin that fetches only the icons actually used in templates from the Iconify API at build-time.What changed
New: Composer plugin (
packages/twig-extension/Composer/)composer install/composer updateto auto-sync iconscomposer.jsonextra.studiometa/ui.iconsmeta_icon()calls{output}/{prefix}/{name}.svg)CLI commands
composer ui:icons— scan & sync iconscomposer ui:icons --dry-run— show detected icons without fetchingcomposer ui:icons --prune— sync + remove unused iconscomposer ui:icons:prune— remove unused icons onlyModified:
Icon.php(Twig function)meta_icon()now checks for local SVG files first, then falls back toiconify/jsonif installed. Twig usage is 100% unchanged — the SVG output is identical (verified).composer.jsoncomposer-pluginiconify/json+iconify/json-toolsmoved fromrequiretorequire-devcomposer-plugin-api+composer/composeraddedNon-breaking
composer install/update, someta_icon('mdi:home')keeps working identicallyiconify/jsonis still installed, it works as fallbackiconify/jsonoutput exactlyConfiguration (optional)
In the consuming project's
composer.json:{ "extra": { "studiometa/ui": { "icons": { "enabled": true, "output": "assets/icons", "scan": ["templates", "app"], "include": ["mdi:loading"], "exclude": ["mdi:test-*"] } } } }Size impact
iconify/json(before)Tests