Problem/Motivation
Extracted from #2631732-13: Clean up libraries validation code:
[T]he Cropper library registration in
hook_libraries_infoexpects the files in the library root (e.g.libraries/cropper/cropper.min.js). This does not match the structure of the packaged files, which places the script & style sheets in the/dist/sub-folder. As this also effects backward compatibility for users that placed the files in the expected path, I have not yet addressed this issue.
Directory struckture should match Cropper library.
Proposed resolution
Change the hook_libraries_info implementation to include the dist directory.
Current implementation:
<?php
/**
* Implements hook_libraries_info().
*/
function image_widget_crop_libraries_info() {
$libraries = [
'cropper' => [
'name' => 'cropper',
'vendor url' => 'https://github.com/fengyuanchen/cropper',
'download url' => 'https://cdnjs.com/libraries/cropper',
'version arguments' => [
'file' => 'cropper.min.js',
'pattern' => '/Cropper v(.*)/',
'lines' => 2,
],
'files' => [
'js' => [
'cropper.min.js' => [],
],
'css' => [
'cropper.min.css' => [],
],
],
],
];
return $libraries;
}
?>Compatibility
This change is not backwards compatible and requires existing installations to adjust to the new structure by moving the files. Maybe this can be handled by an update hook?
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | interdiff-libraries_registration-2793455-16.txt | 7.18 KB | woprrr |
| #16 | libraries_registration-2793455-16.patch | 7 KB | woprrr |
Comments
Comment #2
ckaotikComment #3
woprrr commentedYes is now my focus to update that :). I purpose a patch fast to solve it thank a lot @ckaotik
Comment #4
ckaotikGreat to hear! I didn't want to push you, just wanted to make sure that part is not forgotten.
Keep it up :thumbsup:
Comment #5
mxtI'm changing priority of this feature request because using Composer to download Cropper library the code comes within /dist, so nothing works with actual DEV.
Please, consider this ASAP because Composer workflow to manage D8 websites is largely diffuse now.
Thank you very much!
Comment #6
woprrr commentedI change that into bug because that is verry prior issue to purpose an new release of module ! I fix that Today can you stand ready to test it fastly ?
Comment #7
woprrr commented@MXT for using composer to downloading cropper can you purpose a patch ?
This issue is the last blocker before release. @ckaotik have you a small moment to view this with me ? :)
I ve begin tp create composer.json file:
Comment #8
ckaotikHey @woprrr,
I'm not that firm on Composer, either. I have no idea how Composer handles installation of a JS library. The documentation states:
This might mean that the user gets a
distdirectory, or doesn't. Also, if we includedfengyuanchen/cropperas a dependency, we might run into trouble as the library requirescomponent/jquerywhen Drupal usesdrupal/jquery. We don't want multiple jQuery installations in one Drupal *shudder*You can always compare against other modules'
composer.json, e.g. from Address (which needs a PHP library). They provide far less information in theirs.On the other hand, https://drupal.org/project/dropzonejs is in a similar situation as we are (i.e. the need for a JS library), and doesn't use Composer to manage that library. Instead, they provide download instructions in their README.md and have no
composer.jsonat all.Composer really is more for PHP libraries. Personally, I prefer the "old-fashioned" way followed by dropzonejs, as we are less likely to break things ;) That probably means we'd have to simply ignore composer with regards to the library, and adjust the
hook_libraries_infofiles to something like$libraries['cropper']['files']['js']['dist/cropper.min.js' = []for both files.Then the question remains, on how to upgrade existing installs - or whether just to provide information on the changed location on drupal.org's release notes.
Comment #9
ckaotikOne afterthought: If you still wish to use Composer for the JS library, you might want to take a look at this issue on StackOverflow :)
Comment #10
woprrr commentedThat patch prevent all cases with update_n for old user of libraries. FileSystem component in Symfony basis are powerfull for manipulate files / folders.
I ve process an helper in update_n because two cases possible with libraries for location of files and i prefer an approach more solid and detest code duplication :P
Can you test it and tell me if all is okay for u ? For me all works fine in all cases
I ve just an problem to stop Update_n when exception fired (in extrem cases if we have an files with name modified i think we can't prevent all exotic cases in this update_n because that introduce an too complex logic).
Comment #11
berdirNo, this is not OK.
You can't move files, that's not your job in an update function. If it has to change, then you need to document it instead.
Many people today deploy to containers and other read-only file systems. They use tools to download assets and so on.
This seems like a problematic change for a stable update. Maybe there's a way to support both?
Comment #12
woprrr commented@berdir i see your opinion, and I agree that. It better to inform users using libraries to move her files manually. You think is better to add a notice in report page ?
If you take abstraction of .install all work for you when you have /libraries/cropper/dist/* ?
I Re-patch fast when I have your opinion about report notice :)
Thank a lot for you fast feedback berdir I am glad to see you in iwc issues :)
Comment #13
woprrr commentedI ve re-patch, but can you confirm me if these start of solution feel like for you ? I add an requirment to verify and prevent user to change her configuration.
Comment #14
woprrr commentedI purpose that :) is more precise & clear.
Comment #15
berdirSpecifying a version is problematic, see https://www.drupal.org/node/2817789#comment-11730919.
People using the official d.o packages have version numbers like 1.0.0, not 8.1.0. So this won't install for them. Just put a * there or try specifying boh versions, not sure how well that would work.
") {" should be on the same line as the if
I'm not sure if doing this request is worth it. If people put a wrong path there, then they should see a 404 entry in their logs. No strong opinion, fine if you'd prefer to have this. Maybe only do a HEAD request though, to avoid downloading the file?
I think
<strong>should be used instead of<b>these days?why specify this? according to http://www.drupalcontrib.org/api/drupal/contributions!libraries!librarie..., this shouldn't be used, as other locations (like profiles/someting/libraries/cropper) wouldn't work anymore?
I think you want to specify dist/some_file.. instead later in the code, for the actual files?
That said, I still think you should consider doing a check for the file with and without dist/ for backwards compatible. People don't expect that things change in a stable module update. At the very least, you should put a big warning into the release notes.
Comment #16
woprrr commentedThank a lot again @berdir for your full feedback :) I re-patch with your feedback, yes you right, I think I have too much more complex in the Previous patch to try to cover too many cases as possible. Nothing beats a nice line in the description of the release;). About backward compatibility part, I totally agree with you !! so I leave the options you have to be able to function with the old structure.
For the first point : Yes you right !!! I was still on the old version on packagist-drupal, thanks to you I am now aware
2. Yes !! fixed
3. Yes you right too in this case it's not really revelant to test it and increase complexity, i delete this unused part.
4. I ve found the two cases on core, but i can switch easy to Fixed.
5. Yes ! wrong way for me i ve read more doccumentation about libraries and patch it ! I see to maintain backward compatibility with old / new possible path.
Comment #18
woprrr commentedComment #19
woprrr commented