Problem/Motivation
Just like CSS, we need to move all javascript files to a js subfolder inside modules and update the library information for those modules.
A module that does it well and can be used as reference is the toolbar module.
Steps to reproduce
N/A
Proposed resolution
Move module js files into a js folder and deprecate old paths
Remaining tasks
Check if all files are moved
Review
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
Possibly but would just reference the CR https://www.drupal.org/node/3471539
| Comment | File | Size | Author |
|---|---|---|---|
| #103 | interdiff-100-103.txt | 608 bytes | nod_ |
| #103 | core-move-all-2484623-103.patch | 27.46 KB | nod_ |
| #100 | core-move-all-2484623-100.patch | 27.13 KB | nod_ |
| #99 | interdiff_2484623_97-99.txt | 7.46 KB | ankithashetty |
| #99 | 2484623-99.patch | 27.17 KB | ankithashetty |
Issue fork drupal-2484623
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 2484623-move-all-js
changes, plain diff MR !9251
Comments
Comment #1
nod_Comment #2
anavarreHere's a start.
Comment #4
anavarreComment #6
nod_Looks like this one is missing (I know it's a testing module but let's move it too for consistency).
core/modules/system/tests/modules/twig_theme_test/twig_theme_test.jsThe last one I can find not in a js subfolder is
core/modules/locale/tests/locale_test.jsbut it's not exactly a module so I say it's fine like that.Before:
After:
After the change to
twig_theme_test.jsand fixes to the tests we're RTBC :)Comment #7
nod_All test failures seems to be related to the locale module js file. The magic in
locale_js_alterdoesn't have the right path anymore.Comment #8
anavarreYeh I didn't really know what to do with twig_theme_test.js but I've added it for consistency now. Trying to fix more failing tests for now. Likely not yet ready.
Comment #9
nod_One more to replace in the local alter hook, a few lines below there is
$placeholder_file = 'core/modules/locale/locale.translation.js';Let's see what the tests say. Should be pretty close.
Comment #10
anavarreOops, thanks. Missed this one.
Comment #13
anavarreWorking on the failures. I already found one more path to fix.
Comment #14
anavarreComment #16
anavarreThat should be it.
Comment #18
anavarreNot sure I know what's happening with that last fail.
So, the integer returned for each strpos() is not what I was expecting. To make the test pass, we'd have to change the comparison operator to >
Tried to dump the strpos() without this patch and here's what I'm getting:
Comment #19
anavarreComment #24
rteijeiro commentedCancelled test in #16. We should try to test only latest patch.
Comment #25
rteijeiro commentedJust a nit I found with a js file in a test folder. I found that in other modules the js files for tests are also placed in a js folder.
Comment #26
rteijeiro commentedSorry, forgot to add a file :(
Comment #28
anavarreIn #6, _nod said:
Thus why it's been left as is. I guess it's fine to have both approaches so that we can pick the one we eventually prefer.
Comment #29
nod_The change in #18 is not correct, we're making the test useless. What broke the test is we forgot on more path change in simpletest js alter hook.
I'm ok with putting that file in a js subfolder. Doesn't matter much :)
Comment #31
nod_This is needed for consistency and best practices.
Comment #34
droplet commented+1 RTBC
Comment #35
cilefen commentedLike all issues hoping to be committed right now, this one needs a beta evaluation. Also, I had to be a nudge but if you mark an issue RTBC it will help the community and the committers if you explain how you came to that conclusion.
Comment #36
travis-bradbury commentedI took a crack at a beta evaluation and I don't think this change is unfrozen or prioritized so I suggest postponing it. Please share if you disagree.
Comment #37
cilefen commented@tbradbury I agree. This can be done in the next release.
Comment #38
nod_I would like it for 8.0.x it's all about setting a good example for contrib and it's just moving files around.
Comment #39
droplet commentedDrupal tracking All JS via PHP in CORE. And this is the only and must way to use Drupal libs via Drupal API. We should consider these as private and protected scope members. We're doing internal improvement now.
Comment #43
cilefen commented@nod_ and @droplet According to the beta policy the only way this issue can go in now is if it reduces fragility. The decision on fragility is a core maintainer decision (in other words, your decision) and is on a case-by-case basis. This fragility examples from https://www.drupal.org/core/beta-changes do not seem to apply here:
Comment #44
jeroentCreated reroll.
Patch attached.
Comment #45
travis-bradbury commented8.0.x:
After #44:
Looks good.
Comment #50
jeroentRTBC as per #45.
Comment #51
xjmThanks @cilefen and @tbradbury. I agree that this does not really pass the beta evaluation. Even if it is just moving files around internally, there is not any specific reason this change is prioritized during the beta. Unfortunately consistency/best practice/DX are not by themselves enough to justify the change. There isn't really a case for it reducing fragility.
I asked @Wim Leers if this would be reasonable to change in 8.1.x, and he pointed out that since other code can alter these libraries, the paths would be wrong and the alters would break. So there is disruption from this change, and it would need to be postponed to 9.x. It also could break an existing site or module's custom JS for one of these libraries now.
So unfortunately I'm postponing this issue to 9.x. Thanks all for your work on the patch nonetheless. I can see why this would be good to clean up eventually.
Comment #52
droplet commentedWe should reconsider once for this changes. D8 is the release with big changes in structures. Let's do it together.
Comment #53
nod_I agree, it's not a big deal to change that during beta, and postponing to D9 means contrib doesn't have a best practice from core to rely on.
Comment #54
nod_Since we use libraries, we have library override and extending from the info file, the actual path don't matter much. and if they do it's a trivial fix.
Comment #55
manuel garcia commentedI agree, rerolling against 8.1.x
Fixed conflicts on:
Comment #57
manuel garcia commentedThis should fix the failing test.
Comment #58
dawehnerShould we add an empty update function to cause a cache rebuild?
Comment #59
manuel garcia commented@dawehner: that is probably a good idea.
Comment #60
dawehnerCool, afaik we add those doc groups for each updates, so we probably want one for 8.1.x
Comment #61
hass commented@_nod #54: I think you are wrong. See #2642122: Overriding already overridden libraries-override requires knowledge of previous libraries-overrides and #1308152: Add stream wrappers to access .json files in extensions will not really solve this if you change subfolders.
libraries-overridecan have paths and this will all break if the folder structure is changed. I'm not sure whether these makes this a D9 issue.Comment #62
nod_You're right, the path does matter but I think it's a small price to pay for consistency, especially because the files moved are not really the ones I see overriden in contrib or in projects:
We're not touching misc/ making this patch much less disruptive than assumed.
Whatever is decided, this patch is ready to go.
Comment #63
manuel garcia commentedAttempting to address comment #60. Not entirely sure on the docblock, I couldn't find documentation about this on the coding standards, so I just tried to follow what was there previously. Have a look.
Comment #64
nandasoftware commentedComment #65
nandasoftware commentedComment #66
nandasoftware commentedComment #67
lokesh.soni commentedComment #68
lokesh.soni commentedComment #69
star-szrThis seems a bit problematic for backwards compatibility because of libraries-override and such…
Comment #70
nod_Even RTBC it's still clean-up :)
@Cottser: It looks sloppy to keep it like that until 9.x whenever that is. We can just add a comment in the release notes and/or a change notice. From what I'm aware, file paths are not part of the 'Public API'.
Comment #71
alexpottI think I agree with @Cottser - if someone has done the following in their theme...
We'd be breaking this no?
Comment #72
star-szrYeah we would be breaking it… I'm a bit torn but overall it feels a bit wrong to potentially break BC for cleanup.
I talked to @catch the other day about this and he mentioned we could maybe do a mapping of old paths to new to preserve the BC. This method could probably also make hook_library_info_alter() done by modules still work which is perhaps a more common use case than from the theme, i.e. replacing a core-provided JS file with a custom one.
Sorry if it seems like overkill. Setting back to needs review for more consideration.
Comment #74
skaughtcross-posting:
Comment #75
xjmSo there are two questions here:
Comment #76
xjmPostponing on #75 to make sure we don't fragment the discussion. Thanks everyone.
Comment #77
skaughtChange directory structure for JavaScript files this was what i was cross posting from.
Comment #78
catch#72 is still my position on this - we should look at how feasible it is to do a backwards compatibility layer for the old paths given it's a fixed number.
We should also document that file locations for assets are @internal - i.e. we let you mess with things via override stuff in .info.yml and alter hooks, but that doesn't mean we promise that the data structures you're modifying don't change, especially given other modules or base themes could be altering the same things anyway.
The bc layer would allow modules to work on both 8.1.x and 8.2.x until 8.2.x is released. We could then even remove that bc layer in 8.3.x or 8.4.x given it's an internal API change since it's going to be an ugly hardcoded mapping at best.
Comment #80
nod_Updated patch. Need BC layer, here are the files concerned.
The new paths:
Comment #81
nod_testbot
Comment #82
nod_Comment #83
joelpittetWe could check if an alter/override is using the old path and hot swap it for the correct override/alter as a BC layer but may want to wait on catch's changes to the aggregation to get in?
#1014086: Stampedes and cold cache performance issues with css/js aggregation Since they may conflict if that BC is implemented, thoughts? maybe postpone on that?
Comment #94
nod_Comment #95
nod_trying things out, no tests yet.
Comment #97
kostyashupenkoComment #98
nod_Need to update .eslintignore file :)
Comment #99
ankithashettyUpdated
.eslintignorefile as suggested in #98, thanks!Comment #100
nod_Thanks :)
There was already a entry for this file in eslintignore, changed the line instead of adding a new one.
Comment #103
nod_Comment #104
nod_Comment #105
nod_D10 version needed
At this time we need a D10.1.x patch or MR for this issue.
careful reroll
The patch can be tricky to reroll and some code might get lost in the process. When rerolling this issue please make sure all the parts of the patch are kept (new files, new tests, all the changes to the different parts of the file, changes to es6 files ported to .js files, etc.)
es6 files
In Drupal 10 there is no
.es6.jsfiles anymore see https://www.drupal.org/node/3305487 The changes to the *.es6.js files needs to be moved to the corresponding Drupal 10 *.js file. The changes to the generated files should be dropped as there is no code generation in Drupal 10.Comment #107
catchOpened #3432601: Add deprecation/bc support for library-overrides when files are moved for deprecation/bc support.
Comment #110
quietone commentedI converted the latest patch to an MR.
There were conflicts in the following, but it was a simple conversion.
Leaving at Needs work for adding deprecations.
Comment #111
quietone commentedI updated the MR to add the deprecations. This is tagged for tests. What tests are needed?
Comment #112
nod_Tests were asked before we had the deprecation process for files, so we're good to go here I think.
Comment #113
nod_Thanks for getting this going, comment in the MR
Comment #114
quietone commentedYes, I wasn't sure about the deprecations but went ahead anyway. Using the correct version provided I updated the other instances, and updated the 'How to deprecate' policy.
There is one failing test, core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFilterTest.php, which often fails for me lately although I don't see it in the list of known random failures, #2829040: [meta] Known intermittent, random, and environment-specific test failures
The CR still needs to be updated.
Comment #115
quietone commentedI updated the CR to the current state of the MR.
Then went hunting for *.js file not in a js directory. This command seems to work for that. They are all in tests except for core/modules/ckeditor5/webpack.config.js.
I am guessing the ones in
core/modules/system/tests/modulesshould be moved.Comment #117
smustgrave commentedCleaned up the IS some.
Left 1 comment on the MR.
Previously rebased just to get the tests to run again and failure before was random, can't re-run manually as MR was opened by a committer.
Comment #118
quietone commentedComment #119
smustgrave commentedThanks rest looks good!
Comment #120
nod_Still an issue with the library names. I updated the change record to make it easier to understand hopefully: https://www.drupal.org/node/3432773
Comment #121
quietone commented@nod_, thanks for updating the CR.
Hopefully, these changes are correct.
Comment #122
smustgrave commentedThat's my mistake also I was not aware of that @nod_
Deprecation seems to be inline with the deprecation example in the CR https://www.drupal.org/project/drupal/issues/3458589
Comment #123
alexpottCommitted e9a2e9a and pushed to 11.x. Thanks!
Comment #127
quietone commentedUpdate version to the branch this applies to.