skilld-labs / ui-patterns-kaizen

Development for https://www.drupal.org/project/ui_suite
3 stars 0 forks source link

Composer Based libraries dependencies #6

Open iberdinsky-skilld opened 1 year ago

iberdinsky-skilld commented 1 year ago

According last disqussion i found way how to define components dependencies inside component

More info:

https://www.drupal.org/docs/8/modules/webform/webform-cookbook/using-the-composer-merge-plugin-to-download-libraries-with https://github.com/wikimedia/composer-merge-plugin

Approach taken from webform:

https://git.drupalcode.org/project/webform/-/blob/6.1.x/composer.libraries.json

libraries temporary gitignored in PR.

library can be defined in ui_patterns.yml

In fact it can be improved with custom asset type which can be installed into /templates/patterns/atoms/button/assets/choices

"extra": {
    "installer-paths": {
        "web/libraries/{$name}": [ "enyo/dropzone" ]
    }
}
gaydabura commented 1 year ago

if you are talking about webform it always (!!!) has fallback

take any example , let see choises

https://git.drupalcode.org/project/webform/-/blob/6.1.x/js/webform.element.choices.js#L23 - simple js

https://git.drupalcode.org/project/webform/-/blob/6.1.x/src/Plugin/WebformElement/Select.php#L78 - php

which means next: 1. you may do composer require choices in you main composer file which is correct way

OR you may use approach with merge-plugin proposed by webform.

but still good way to control all packages in your project from one place

shortly - webform does care if you have library or no webform will work if you dont have library library may be delivered in normal way described in d.org webform has its own way which requires merge-plugin - but you are free to not use it thats flexibility which does not breaks drupal paradigm

gaydabura commented 1 year ago

Another very important thing, which is missed in your PR library definition, according webform - https://git.drupalcode.org/project/webform/-/blob/6.1.x/webform.libraries.yml#L1030 as you may see library is declared here and finally internal library has a dependency from external https://git.drupalcode.org/project/webform/-/blob/6.1.x/webform.libraries.yml#L491

and finally element (component) may attach internal library which has:

iberdinsky-skilld commented 1 year ago

TODO: review https://getcomposer.org/doc/articles/plugins.md#plugin-modifies-install-path