symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony
https://ux.symfony.com/
MIT License
793 stars 282 forks source link

[StimulusBundle] Asset mapper dependency #1313

Closed Jibbarth closed 8 months ago

Jibbarth commented 8 months ago

Hi there,

I had a strange issue running composer update, and having an upgrade for stimulus-bundle from 2.12 to 2.13.2

Upgrading symfony/stimulus-bundle (v2.12.0 => v2.13.2)

After upgrading, on the clear:cache, had the following issue :

image

After looked at the stacktrace, I inspected the compiler pass, and it seems to browse all definitions to check each one is a command, but nevermind.

I don't have yet installed asset-mapper (but I plan to :wink:)

The StimulusLoaderJavaScriptCompiler, which implement an interface from asset-mapper, is now loaded in a service, whereas in 2.12 it wasn't, probably thanks to the following lines :

image

So I'm wondering if now, the asset-mapper should be a direct dependency of stimulus-bundle, or should we find a workaround to not load this service when the asset-mapper component is not installed.

I tried adding

if (interface_exists(AssetMapperInterface::class)) {
        $container->services()
            ->set('stimulus.asset_mapper.loader_javascript_compiler', StimulusLoaderJavaScriptCompiler::class)
            ->args([
                service('stimulus.asset_mapper.controllers_map_generator'),
                param('kernel.debug'),
            ])
            ->tag('asset_mapper.compiler', ['priority' => 100])
        ;
    }

in config/services.php and it seems working - for my case, and I can provide a fix PR.

WDYT ?

smnandre commented 8 months ago

Can you share your composer show (at least the symfony components ?)

That'd help to understand where we missed something

Jibbarth commented 8 months ago

Hello @smnandre,

Sure, here it is:

Full composer show list amphp/amp v3.0.0 A non-blocking concurrency framework for PHP applications. amphp/byte-stream v2.1.0 A stream abstraction to make working with non-blocking I/O simple. amphp/cache v2.0.0 A fiber-aware cache API based on Amp and Revolt. amphp/dns v2.1.0 Async DNS resolution for Amp. amphp/parallel v2.2.4 Parallel processing component for Amp. amphp/parser v1.1.0 A generator parser to make streaming parsers simple. amphp/pipeline v1.0.0 Asynchronous iterators and operators. amphp/process v2.0.1 A fiber-aware process manager based on Amp and Revolt. amphp/serialization v1.0.0 Serialization tools for IPC and data storage in PHP. amphp/socket v2.2.0 Non-blocking socket connection / server implementations based on Amp and Revolt. amphp/sync v2.1.0 Non-blocking synchronization primitives for PHP based on Amp and Revolt. amphp/windows-registry v1.0.0 Windows Registry Reader. clue/stream-filter v1.6.0 A simple and modern approach to stream filtering in PHP cmgmyr/phploc 8.0.3 A tool for quickly measuring the size of a PHP project. composer/pcre 3.1.1 PCRE wrapping library that offers type-safe preg_* replacements. composer/semver 3.4.0 Semver library that offers utilities, version constraint parsing and validation. composer/xdebug-handler 3.0.3 Restarts a process without Xdebug. daverandom/libdns v2.0.3 DNS protocol implementation written in pure PHP dealerdirect/phpcodesniffer-composer-installer v1.0.0 PHP_CodeSniffer Standards Composer Installer Plugin dflydev/dot-access-data v3.0.2 Given a deep data structure, access data by dot notation. doctrine/cache 2.2.0 PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc,... doctrine/collections 2.1.4 PHP Doctrine Collections library that adds additional functionality on top of PHP arrays. doctrine/deprecations 1.1.2 A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selective... doctrine/inflector 2.0.8 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plu... ergebnis/phpstan-rules 2.1.0 Provides additional rules for phpstan/phpstan. friendsofphp/php-cs-fixer v3.40.0 A tool to automatically fix PHP code style gitonomy/gitlib v1.3.8 Library for accessing git guzzlehttp/psr7 2.6.1 PSR-7 message implementation that also provides common utility methods intervention/image 2.7.2 Image handling and manipulation library with support for Laravel integration justinrainbow/json-schema v5.2.13 A library to validate a json schema. kelunik/certificate v1.1.3 Access certificate details and transform between different formats. knplabs/github-api v3.13.0 GitHub API v3 client kornrunner/blurhash v1.2.2 Pure PHP implementation of Blurhash laravel/serializable-closure v1.3.3 Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP. league/commonmark 2.4.1 Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM) league/config v1.2.0 Define configuration arrays with strict schemas and access values with dot notation league/container 4.2.0 A fast and intuitive dependency injection container. league/uri 7.3.0 URI manipulation library league/uri-interfaces 7.3.0 Common interfaces and classes for URI representation and interaction masterminds/html5 2.8.1 An HTML5 parser and serializer. mnapoli/front-yaml 2.0.2 monolog/monolog 3.5.0 Sends your logs to files, sockets, inboxes, databases and various web services nesbot/carbon 2.71.0 An API extension for DateTime that supports 281 different languages. nette/neon v3.4.1 🍸 Nette NEON: encodes and decodes NEON file format. nette/schema v1.2.5 📐 Nette Schema: validating data structures against a given Schema. nette/utils v3.2.10 🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validati... nikic/php-parser v4.17.1 A PHP parser written in PHP nunomaduro/phpinsights v2.10.0 Instant PHP quality checks from your console. nyholm/psr7 1.8.1 A fast PHP7 implementation of PSR-7 ondram/ci-detector 4.1.0 Detect continuous integration environment and provide unified access to properties of current build pdepend/pdepend 2.16.0 Official version of pdepend to be handled with Composer php-http/cache-plugin 1.8.1 PSR-6 Cache plugin for HTTPlug php-http/client-common 2.7.0 Common HTTP Client implementations and tools for HTTPlug php-http/discovery 1.19.1 Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations php-http/httplug 2.4.0 HTTPlug, the HTTP client abstraction for PHP php-http/message 1.16.0 HTTP Message related tools php-http/message-factory 1.1.0 Factory interfaces for PSR-7 HTTP Message php-http/multipart-stream-builder 1.3.0 A builder class that help you create a multipart stream php-http/promise 1.2.1 Promise used for asynchronous HTTP requests php-parallel-lint/php-parallel-lint v1.3.2 This tool check syntax of PHP files about 20x faster than serial check. phpdocumentor/reflection-common 2.2.0 Common reflection classes used by phpdocumentor to reflect the code structure phpdocumentor/reflection-docblock 5.3.0 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embe... phpdocumentor/type-resolver 1.7.3 A PSR-5 based resolver of Class names, Types and Structural Element Names phpmd/phpmd 2.14.1 PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. phpro/grumphp v2.3.0 A composer plugin that enables source code quality checks. phpstan/extension-installer 1.3.1 Composer plugin for automatic installation of PHPStan extensions phpstan/phpdoc-parser 1.24.4 PHPDoc parser with support for nullable, intersection and generic types phpstan/phpstan 1.10.46 PHPStan - PHP Static Analysis Tool phpstan/phpstan-strict-rules 1.5.2 Extra strict and opinionated rules for PHPStan phpstan/phpstan-symfony 1.3.5 Symfony Framework extensions and rules for PHPStan phpunit/php-file-iterator 3.0.6 FilterIterator implementation that filters files based on a list of suffixes. phpunit/php-timer 5.0.3 Utility class for timing psr/cache 3.0.0 Common interface for caching libraries psr/clock 1.0.0 Common interface for reading the clock. psr/container 2.0.2 Common Container Interface (PHP FIG PSR-11) psr/event-dispatcher 1.0.0 Standard interfaces for event handling. psr/http-client 1.0.3 Common interface for HTTP clients psr/http-factory 1.0.2 Common interfaces for PSR-7 HTTP message factories psr/http-message 2.0 Common interface for HTTP messages psr/log 3.0.0 Common interface for logging libraries psr/simple-cache 3.0.0 Common interfaces for simple caching ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. ramsey/collection 2.0.0 A PHP library for representing and manipulating collections. revolt/event-loop v1.0.5 Rock-solid event loop for concurrent PHP applications. sebastian/cli-parser 1.0.1 Library for parsing CLI options sebastian/diff 5.0.3 Diff implementation sebastian/phpcpd 6.0.3 Copy/Paste Detector (CPD) for PHP code. sebastian/version 3.0.2 Library that helps with managing the version number of Git-hosted PHP projects seld/jsonlint 1.10.0 JSON Linter slevomat/coding-standard 8.14.1 Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks. squizlabs/php_codesniffer 3.7.2 PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. symfony/asset v6.4.0 Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files symfony/browser-kit v6.4.0 Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically symfony/cache v6.4.0 Provides extended PSR-6, PSR-16 (and tags) implementations symfony/cache-contracts v3.4.0 Generic abstractions related to caching symfony/config v6.4.0 Helps you find, load, combine, autofill and validate configuration values of any kind symfony/console v6.4.0 Eases the creation of beautiful and testable command line interfaces symfony/css-selector v6.4.0 Converts CSS selectors to XPath expressions symfony/dependency-injection v6.4.0 Allows you to standardize and centralize the way objects are constructed in your application symfony/deprecation-contracts v3.4.0 A generic function and convention to trigger deprecation notices symfony/dom-crawler v6.4.0 Eases DOM navigation for HTML and XML documents symfony/dotenv v6.4.0 Registers environment variables from a .env file symfony/error-handler v6.4.0 Provides tools to manage errors and ease debugging PHP code symfony/event-dispatcher v6.4.0 Provides tools that allow your application components to communicate with each other by dispatching events and listening to them symfony/event-dispatcher-contracts v3.4.0 Generic abstractions related to dispatching event symfony/filesystem v6.4.0 Provides basic utilities for the filesystem symfony/finder v6.4.0 Finds files and directories via an intuitive fluent interface symfony/flex v2.4.1 Composer plugin for Symfony symfony/framework-bundle v6.4.0 Provides a tight integration between Symfony components and the Symfony full-stack framework symfony/http-client v6.4.0 Provides powerful methods to fetch HTTP resources synchronously or asynchronously symfony/http-client-contracts v3.4.0 Generic abstractions related to HTTP clients symfony/http-foundation v6.4.0 Defines an object-oriented layer for the HTTP specification symfony/http-kernel v6.4.0 Provides a structured process for converting a Request into a Response symfony/intl v6.4.0 Provides access to the localization data of the ICU library symfony/maker-bundle v1.52.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boiler... symfony/mime v6.4.0 Allows manipulating MIME messages symfony/options-resolver v6.4.0 Provides an improved replacement for the array_replace PHP function symfony/polyfill-intl-grapheme v1.28.0 Symfony polyfill for intl's grapheme_* functions symfony/polyfill-intl-idn v1.28.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-intl-normalizer v1.28.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.28.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php80 v1.28.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions symfony/polyfill-php81 v1.28.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions symfony/polyfill-php83 v1.28.0 Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions symfony/process v6.4.0 Executes commands in sub-processes symfony/property-access v6.4.0 Provides functions to read and write from/to an object or array using a simple string notation symfony/property-info v6.4.0 Extracts information about PHP class' properties using metadata of popular sources symfony/routing v6.4.0 Maps an HTTP request to a set of configuration variables symfony/runtime v6.4.0 Enables decoupling PHP applications from global state symfony/serializer v6.4.0 Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML... symfony/service-contracts v3.4.0 Generic abstractions related to writing services symfony/stimulus-bundle v2.13.0 Integration with your Symfony app & Stimulus! symfony/stopwatch v6.4.0 Provides a way to profile code symfony/string v6.4.0 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way symfony/translation v6.4.0 Provides tools to internationalize your application symfony/translation-contracts v3.4.0 Generic abstractions related to translation symfony/twig-bridge v6.4.0 Provides integration for Twig with various Symfony components symfony/twig-bundle v6.4.0 Provides a tight integration of Twig into the Symfony full-stack framework symfony/ux-lazy-image v2.13.2 Lazy image loader and utilities for Symfony symfony/ux-turbo v2.13.2 Hotwire Turbo integration for Symfony symfony/validator v6.4.0 Provides tools to validate values symfony/var-dumper v6.4.0 Provides mechanisms for walking through any arbitrary PHP variable symfony/var-exporter v6.4.0 Allows exporting any serializable PHP data structure to plain PHP code symfony/web-profiler-bundle v6.4.0 Provides a development tool that gives detailed information about the execution of any request symfony/webpack-encore-bundle v2.1.1 Integration with your Symfony app & Webpack Encore! symfony/yaml v6.4.0 Loads and dumps YAML files symfonycorp/connect v8.1.0 SymfonyConnect SDK symplify/autowire-array-parameter 9.4.70 Autowire array parameters for your Symfony applications symplify/composer-json-manipulator 9.4.70 Package to load, merge and save composer.json file(s) symplify/console-package-builder 9.4.70 Package to speed up building command line applications symplify/easy-testing 9.4.70 Testing made easy symplify/package-builder 9.4.70 Dependency Injection, Console and Kernel toolkit for Symplify packages. symplify/smart-file-system 9.4.70 Sanitized FileInfo with safe getRealPath() and other handy methods symplify/symfony-static-dumper 9.4.70 Dump Symfony application to Static Website symplify/symplify-kernel 9.4.70 Internal Kernel for Symplify packages thecodingmachine/safe v2.5.0 PHP core functions that throw exceptions instead of returning FALSE on error twig/extra-bundle v3.8.0 A Symfony bundle for extra Twig extensions twig/intl-extra v3.8.0 A Twig extension for Intl twig/markdown-extra v3.8.0 A Twig extension for Markdown twig/twig v3.8.0 Twig, the flexible, fast, and secure template language for PHP webmozart/assert 1.11.0 Assertions to validate method input/output with nice error messages.

And you can find whole project here if you wanna go deeper.

As far as I looked, the compiler pass where the issue is thrown is coming from symplify/console-package-builder, so not directly related to Symfony. (and this package is deprecated, i have to remove the dependency on it :sweat_smile:)

But the fact is that StimulusLoaderJavaScriptCompiler is now loaded as service, even when we don't have asset-mapper. Let me know if you have enough information :slightly_smiling_face:

smnandre commented 8 months ago

Could you try something ? In the vendor code of the StimulusBundle, could you hard edit the following file

vendor/symfony/stimulus-bundle/src/DependencyInjection/Compiler/ RemoveAssetMapperServicesCompiler.php

And replace stimulus_loader_javascript_compiler by loader_javascript_compiler

    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('asset_mapper')) {
            $container->removeDefinition('stimulus.ux_controllers_twig_runtime');
            $container->removeDefinition('stimulus.asset_mapper.controllers_map_generator');
            // $container->removeDefinition('stimulus.asset_mapper.stimulus_loader_javascript_compiler'); // Before
            $container->removeDefinition('stimulus.asset_mapper.loader_javascript_compiler'); // After
        }
    }

I think this i a little bug that could fix your problem ?

Jibbarth commented 8 months ago

Ooh I didn't see that compiler pass that remove definition 🤩. Seems to be a good catch, I will give it a try.

smnandre commented 8 months ago

It does not remove it.... if the name differs from the added one 😅

Jibbarth commented 8 months ago

Thanks @smnandre, I can confirm that is work, if I load stimulus bundle before the other one that raise the issue.

I probably didn't get the error before on 1.12 even with stimulus bundle loaded after because the service was removed in the load method of extension, not via a compiler pass.