[META] Update Asset Libraries and Discovery to use a Plugin System

Created on 23 June 2020, over 4 years ago
Updated 20 August 2023, about 1 year ago

Problem/Motivation

Adding third party library systems (such as for web components and pattern libraries) and customizing the behavior of assets (js / css parsing & collections settings) is difficult, if not impossible, with the current core system.

If a module wanted to add library support for additional systems, it would need to recreate core's library handling, and use a workaround (such as drupalSettings: {}) for libraries consisting only of new systems (see https://drupal.org/project/patternkit or any other module that attempts to add support for HTML fragment libraries).

The Asset Libraries system is over-complicated:

  • AssetResolver
    • LibraryDependencyResolver
      • LibraryDiscovery + Interface
        • LibraryDiscoveryCollector
            LibraryDiscoveryParser

and over-specific:

  • CSSCollectionOptimizer
    • CSSCollectionOptimizer
      • CSSCollectionGrouper
      • CSSOptimizer
      • CSSDumper
  • CSSCollectionRenderer
  • JSCollectionOptimizer
    • JSCollectionOptimizer
      • JSCollectionGrouper
      • JSOptimizer
      • JSDumper
  • JSCollectionRenderer

Proposed resolution

Each item here will be created as sub-issues under this META issue's Remaining Tasks section to keep this issue centered on discussion and the sub-issues centered on implementation.

  1. Merge LibraryDiscovery and LibraryDiscoveryCollector into a single \Drupal\Core\Asset\Discovery\Library class πŸ“Œ Move library discovery into Core\Asset\Discovery namespace and add 'asset.' prefix to service IDs Closed: won't fix .
  2. Create a new Library class to replace the arbitrary library arrays, to make development easier and make it clearer which fields are required.
  3. Move LibraryDiscoveryParser to \Drupal\Core\Asset\Parser\Base class.
  4. Break out the parser tooling into subclasses \Drupal\Core\Asset\Parser\JS & CSS.
  5. Add support for Library plugins to the new Library class.
    • Add Plugin\Library annotation class.
    • Add LibraryPluginDefault class.
    • Add LibraryPluginDefinition class.
    • Add LibraryPluginInterface interface.
    • Add LibraryPluginManager class and plugin.manager.library service.
  6. Genericize AssetType* classes into \Drupal\Core\Asset\AssetCollectionOptimizer etc.
  7. Move specific AssetType* class functionality into Library plugins (JS, CSS).
  8. This would possible enable a future separate issue of: Add patternkit module to core to support HTML fragment libraries such as Twig and WebComponents.

Remaining tasks

(reviews needed, tests to be written or run, documentation to be written, etc.)

User interface changes

None.

API changes

Addition of Library Plugin support.

Data model changes

None.

Release notes snippet

(Major and critical issues should have a snippet that can be pulled into the release notes when a release is created that includes the fix)

✨ Feature request
Status

Postponed: needs info

Version

10.0 ✨

Component
Asset libraryΒ  β†’

Last updated 2 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States cyb.tachyon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024