Problem/Motivation
Currently Drupal has no way to deprecate asset libraries. In Drupal contrib this is less of a problem, but in Drupal core it is crucial, since many Drupal contrib/custom modules depend on asset libraries in Drupal core, and Drupal core may want to remove some of them.
For example: jQuery UI is EOL, so we need a way to mark the various jQuery UI asset libraries (core/jquery.ui.*) as deprecated, to be removed in Drupal 9 or 10.
Proposed resolution
From @catch:
For libraries the obvious place to trigger a deprecation error would be
\Drupal\Core\Asset\LibraryDiscovery::getLibraryByName()- by adding adeprecatedkey to library definitions with a deprecation message as the value.
Remaining tasks
RTBC- Commit
- Publish change record
User interface changes
None
API changes
*.libraries.yml files now support a deprecated key which will trigger an error in \Drupal\Core\Asset\LibraryDiscovery::getLibraryByName().
Data model changes
None
Release notes snippet
*.libraries.yml files now support marking asset libraries as deprecated, and tests that use deprecated libraries will now fail unless they are marked as @group legacy. Numerous dependency libraries provided by core will be deprecated in 8.8.0 and removed in Drupal 9.0.0. Read more in the Drupal deprecation policy.
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 3064017-31.patch | 3.76 KB | wim leers |
| #31 | interdiff.txt | 2.19 KB | wim leers |
| #26 | 3064017-26.patch | 5.78 KB | wim leers |
| #26 | interdiff.txt | 3.25 KB | wim leers |
| #23 | 3064017-23.patch | 5.67 KB | wim leers |
Comments
Comment #2
mikelutzLet's give it a try. :-)
Comment #3
mikelutzComment #4
catchLooks very promising to me, nothing to complain about in the patch.
Comment #5
alexpottThis seems like a really good idea.
I think we should go with what we do in the container. I.e use the key
deprecated- less to have to remember and learn. SeeAnd maybe we could do something %library_name% or %library_id% too
Comment #6
catchLet's do both of those, although went for '%library%' for the placeholder.
Comment #7
mikelutzComment #8
mikelutzUpdated change record. At some point we might want to update https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module#library
Comment #9
dwwMostly looks great. Some minor nits:
Core seems to use "JavaScript" consistently, not "javascript".
Also, coder is now complaining about the formatting of deprecation messages:
"The text '@deprecated %s' does not match the standard format: @deprecated in %%deprecation-version%% and is removed from %%removal-version%% . %%extra-info%%.";Finally, I don't think we want that ending period after the URL in @see.
So, I think we want:
"%library% is deprecated in drupal:8.8.0 and is removed in drupal:9.0.0. Require jQuery UI as an explicit dependency or create a pure JavaScript solution. See https://www.drupal.org/node/3064015"
This will have to be changed to match whatever happens with point 1.
s/will be removed/is removed/ per #1.
s/Drupal 9.0.0/drupal:9.0.0/
s/instad/instead/
Also, inconsistent with two spaces after period or not. Should always use a single space.
As above, should this also be in '@group Asset'?
Needs update to match point 3.
Comment #10
dwwThis fixes everything from #9 except point 4 which I wasn't sure about.
Comment #11
dwwp.s. I updated the change record to match the current deprecation message and to fix a few grammar + formatting bugs.
Comment #12
dwwp.p.s. Note to committers: @mikelutz wrote the bulk of this patch. @catch and I just did some tweaking. Sadly, d.o's credit heuristics list @mikelutz as the last author, but he should get 1st billing on this issue. Please modify the commit message accordingly. Thanks!
Comment #14
dwwOof. The new test needs @doesNotPerformAssertions after #3059332: Mark kernel tests that perform no assertions as risky
Comment #15
alexpottThis can be done in another slightly cleaner way. We can use a custom error handler in the test and catch the deprecation here ourselves. And test that. Then we don't have to mark this test @group legacy when it is not.
See \Drupal\KernelTests\Core\Database\QueryTest::testConditionOperatorArgumentsSQLInjection for an example of a custom error handler in a test.
Or https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Con... for a specific example for deprecations.
Comment #16
wim leersdeprecatedkey inWe can adopt at least the prefix here.
%library_id%, not%library%.Übernit: s/Test/Tests/
Comment #17
wim leers#15++
This reroll addresses that.
On top of that, the current method name causes this:
So also renamed it.
Comment #18
wim leersImproved issue summary & title.
Comment #19
wim leersI wondered whether it is okay to only update
getLibraryByName()— what about\Drupal\Core\Asset\LibraryDiscovery::getLibrariesByExtension()?Turns out this is only called by tests, at least in core. #2203411: Convert drupal_get_library() into a service introduced it. And even there it was only called by tests. Shall I open a follow-up to deprecate that method?
Comment #20
wim leersComment #21
andypostWim ++ to followup, api & scope
The message needs one more review, rtbc++
Comment #22
dww@Wim Leers: thanks for picking this up and running with it!
Re: #16.2.3:
Tell that to coder. :/ See #2908391: Add a rule for expected format of @deprecated and @trigger_error() text. The version of coder that's installed in vendor to do our code sniff testing is expecting this:
See also https://www.drupal.org/core/deprecation and #3024461: Adopt consistent deprecation format for core and contrib deprecation messages.
Personally, I agree "will be removed in" is better than "is removed from", but apparently that's not what @xjm and @jonathan1055 went with (over the objections of @alexpott, it seems). Anyway, "is removed from" is now what's documented and enforced by coder, so I think we're stuck with it. That's why I raised it at #9.1 and #9.3.
Therefore, I believe we have to change your (otherwise nice) deprecation messages to be like this:
The "%library_id%" asset library is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Require jQuery UI as an explicit dependency or create a pure JavaScript solution. See https://www.drupal.org/node/3064015Comment #23
wim leers👍🙏✅
Comment #24
lauriiiShould we also mention the extension that the library belongs to? Having only the name of the library isn't specific enough because a library with the same name could be provided by multiple extensions.
Comment #25
wim leers+1, will do!
Comment #26
wim leersDone.
Comment #27
dww@lauriii: +1 on #24.
#26 looks great to me. Thanks, @Wim Leers!
No further concerns. I've got some fingerprints on this patch, but I still feel safe to RTBC.
Thanks!
-Derek
p.s. Reminder to core committers: I still think @mikelutz should get "first billing" on the commit message for this issue. Not that it really matters, but I think it's a kind thing to do. I believe the accurate order should be:
git commit -m 'Issue #3064017 by mikelutz, Wim Leers, dww, catch: Create a means to mark an asset library as deprecated in a *.libraries.yml file'Comment #28
lauriiiDeprecating
jquery.ui.effects.scalefeels like outside of the scope of this issue. I think it would be better to handle as part of https://www.drupal.org/project/drupal/issues/3051352.Another concern I have related to this is that jQuery UI is deprecated from Drupal 9.0.0, and we probably want this test coverage to stay in place after Drupal 9.0.0 has shipped. Any thoughts on making this test depend on a test module or theme that has a deprecated library instead?
Comment #29
mikelutzWhenever I've added a feature similar to this intended to be used in several follow-ups, I've added the first usage as part of the patch to prove the feature works, and to avoid adding dead code to core, which is why I originally added the first deprecation here. If anything, I've been wondering if we should change the IS and deprecate all the effects plugins as part of this initial patch, though I'm happy to be overruled on this.
As far as the test for deprecating the scale plugin, I don't see why we would keep the file in Drupal 9. Like any legacy test, it should be removed, and if we deprecate a library in D9, then a new test should be added for that. There's no reason to keep the file until that happens, we already have a test for the feature itself.
Comment #30
catchThis hunk is enough for general test coverage of the feature, we don't need a test module.
The only issue with doing the actual scale deprecation here is that #3051352: [Plan] Remove unused jQuery UI components and replace with a suite of contrib packages for the continuous upgrade path is still being discussed.
Comment #31
wim leers#30: hah, that's exactly what I was about to reply with :)
So to resolve #28 (which I agree with by the way!), I just omitted all actual asset library hunks from the patch.
Comment #32
catch+1, tests are still running, but I'm happy with the current patch.
Comment #33
mikelutzIf we aren't ready to deprecate jQuery, then that's a different story. I have no problem with adding the ability to deprecate a library without actually deprecating one if we don't have one ready to be deprecated yet. We've proven the ability to do so with test coverage, so this is fine.
Comment #34
dwwSo the work here doesn't get lost (other than hidden in an interdiff), I posted the removed hunks to a proof-of-concept patch at #3051352-39: [Plan] Remove unused jQuery UI components and replace with a suite of contrib packages for the continuous upgrade path so folks can expand on it over there.
Meanwhile, +1 to RTBC in here.
Cheers,
-Derek
Comment #35
catchCommitted 0d82715 and pushed to 8.8.x. Thanks!
Comment #38
wim leersComment #39
xjmPolishing the release note a bit to explain why this is a change that people should be aware of.
Comment #41
xjmAlso crediting @pameeela for helping improve the release note.
Comment #42
xjmComment #43
xjmTypo.
Comment #44
xjm