Topic on Talk:Requests for comment/Isolate custom jQuery libraries

Slightly different directory layout proposal

2
Matma Rex (talkcontribs)

Another problem we have is the 'mediawiki' vs 'jquery' divide, with the implication that all core things should go in the former, and all outside things in the latter. This might be a surprise to some :P, but JS libraries which don't use jQuery exist! – one such library which we already have in core is QUnit (misleadingly named 'jquery.qunit.js' right now), another would be Underscore/Lo-Dash should we decide to include it. (We also have several custom scripts in the 'jquery' namespace which barely use jQuery, sometimes just extending its global object – jquery.byteLength, jquery.client, …)

Quoting this RFC:

  • 3rd party libraries and MediaWiki specific libraries should be isolated from each other:
    • resources/jquery/ should be restricted to 3rd party unmodified libraries.
    • Custom and forked jQuery libraries should go into another directory such as jquery.custom or jquery.local.
    • Libraries integrated directly with MediaWiki's mediaWiki.* or dependent on its environment should go in another directory such as mediawiki.jquery.

While I'm all for the general direction, I'd suggest a slightly different way to go about it: let's create 'libs' and 'core' directories inside resources/.

'libs' would include anything that is (or started as) a third-party library and that has an upstream that could be linked to; forks with minor changes would go there too (with the restrictions as mentioned in the RFC, and unless the fork is a large rewrite). 'core' would include libraries specific to MediaWiki itself; both ones directly tied in into it (mediawiki.api, mediawiki.special.*, …) and ones which were just created here, but could conceivably be useful elsewhere with none or minor modifications (all of our custom stuff now sitting in resources/jquery/, mediawiki.ui).

The 'libs' directory could contain libraries managed with some dependency manager, or git submodules, or straight copied files (but that's out of scope here). The 'core' directory would contain regular files with no magic. If we ever split a library out (as suggested by the RFC), it would just be moved to the other directory (module name could stay the same).

Both 'libs' and 'core' could be further subdivided, but in libs' case I'd rather do away with things like the 'jquery' directory containing everything with 'jQuery' in its name and just place the files directly there. We would instead have directories (or submodules, whatever…) for libraries like jquery.chosen or jquery.tipsy, which come with their own images, styles or licenses. In core's case the current division of mediawiki.* libraries makes sense to me (plus a new directory called 'jquery' would likely appear with our custom jQuery scripts).

Thoughts?

Dantman (talkcontribs)

Sorry if it was ambiguous but when I said "resources/jquery/ should be restricted to 3rd party unmodified libraries." I was not implying that everything should go into the jquery folder. I said that because as of writing it resources/jquery/ was the only folder where we foolishly threw 3rd party libraries, forks, and MediaWiki specific code. For non-jquery 3rd party libraries under the old/current resources/*/ folders my thoughts were then that each major library should have it's own folder, resources/underscore/ resources/lodash/ and MediaWiki stuff naturally come in resources/mediawiki.*/ folders, not that random 3rd party libraries go in resources/jquery/.

Reply to "Slightly different directory layout proposal"