Hi,
On 05/05/2017 01:22 PM, George, Garrett J. (JSC-CB111)[SGT, INC] wrote:
Hey,
I'm on Mediawiki 1.27.
I've been developing a fairly robust Special Pages extension using a solid amount of
Javascript, nearly over 1000 lines currently.
I would prefer to improve my code's readability and organization by using the modular
design seen in modern projects through CommonJS or RequireJS. It may be a problem with how
I'm using `require` but I'm stuck trying to even find examples of people using
require inside their extension since very few even use Javascript loaded through
$out->addModules. The current state of my extension works fine but it's contained
in a single Javascript file that would be extremely difficult for people to read besides
myself.
You can specify multiple files for the "scripts" and "styles" options
which are then loaded in order. Extension:VisualEditor's extension.json
has quite a few examples.
The problem is that the dependency key in
ResourceModules inside of extension.json only works for modules that have already been
loaded. In `ResourceModules` the dependency tag is less about code order of execution when
ResourceLoader calls `mw.loader.implement` and more about which globally accessible
libraries/javascript files should be included when `mw.loader.implement` is called for a
module. ResourceLoader doesn't do any sort of callback. So if my module X has module Y
as a dependency it won't recognize Y isn't loaded, find Y, load Y, then return to
loading X. It just stops when it finds Y isn't loaded and throws a fatal error about
module Y not being loaded.
If X has specified a dependency upon Y in extension.json, it should load
Y before X. Are you experiencing something different? Or did you mean
something else?
Also a sidenote, from very initial testing calling
`$out->addModules()` loads them into ResourceLoader in alphabetical order. Which is
weird and doesn't make sense to me. I had dependency problems and I simply changed one
module from starting with a Q to starting with an A and it was sent to mw.loader.implement
before another module starting after A.
This is expected I think, as it assumes that you'll set your modules'
dependencies in extension.json (or mw.loader.using[1]).
[1]
https://www.mediawiki.org/wiki/ResourceLoader/Core_modules#mw.loader.using
-- Legoktm