[23:48:06] Krinkle, hi, is there a way to dynamically change resources? I want an extra external js lib to be part of of a resource depending on the extension config [23:49:23] yurik: Yes, subclass ResourceLoaderModule. [23:49:43] Krinkle, what about public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) { [23:49:43] $resourceModules = $resourceLoader->getConfig()->get( 'ResourceModules' ); [23:50:07] $resourceLoader->register( $addModules ); [23:50:19] yurik: getScript() would proxy the script content, and then use either enableModuleContentVersion() or getDefinitionSummary() to track changes. [23:50:34] yurik: Oh by extenral you don't mean from a differnet url. [23:50:45] right, just an upstream lib [23:50:53] i just don't want to include it by default [23:51:00] define include. [23:51:02] load? or register? [23:51:06] both [23:51:13] That's fine [23:51:19] onResourceLoaderRegisterModules is the way, yeah [23:51:27] avoid ResourceModules. [23:51:32] that's for static only. [23:51:47] (in theory you can use wgExtensionFunctions to change wgResourceModules, but that's icky) [23:52:13] Krinkle, so what should onResourceLoaderRegisterModules() do in my case? [23:52:24] yurik: if ( .. ) $rl->register($module) [23:52:56] Krinkle, but i want to insert a new js lib in the middle of the existing chain [23:53:07] yurik: i'm not sure I follow. [23:53:29] e.g. module A and B needs module C. Module C has 5 files. I want to add 6th file to module C to [23:53:34] You can conditionally register() it, and then also conditionally add that as a dependency to the relevant leaf node module. [23:53:55] yurik: Hm.. that's possible too, though I'm not sure that's intuitive. [23:53:57] yurik: that way lies madness [23:54:01] In that case you'd keep the module definition in an array [23:54:09] and confitionally change the 'scripts' array before calling register() [23:54:18] right [23:54:22] Shoudl work fine. [23:54:30] We do that in some cases for the 'dependencies' array [23:54:33] of a given module [23:54:43] we had this in uploadwizard. it leads to messes and nastiness. [23:54:58] yurik: What is the end use case? [23:54:59] (we no longer do and i sleep better at night) [23:55:17] MatmaRex, i want to experiment with this module. If its ok, i will launch it for prod, and remove this craziness, but before that, I want to test it thoroughly behind a feature flag [23:55:23] Krinkle, ^ [23:55:39] yurik: i recommend either subclassing ResourceLoaderModule and making the getScript() method dynamic, or creating a separate module for the library and deciding whether to load it from JS code [23:56:08] (subclassing ResourceLoaderFileModule, i guess) [23:56:20] meh, i was hoping to have it transparent without any other code changes. Its for graphs - and this extra lib will simply allow an extra type of graphs [23:56:26] Yeah, that keeps the logic central. [23:56:42] subclass ResourceLoaderFileModule and use config in the constructor to feed the 'scripts' array. [23:56:57] sigh, ok, i will try. [23:57:11] MatmaRex, by the way, have you had any luck with the maps loading in upload wizard? [23:57:19] we just refactored all of our resources [23:57:21] yurik: For POC, an if condition in onResourceLoaderRegisterModules should work though. [23:57:39] $module = [ ... scripts => [] ] ; if (x ) $module['scripts'][] = file6.js. register($module) [23:57:48] Krinkle, even if the module itself is in extension.json file, right? [23:57:53] No. [23:57:56] Don't mix. [23:58:07] Move the whole definitoin of that particular module to the hook. [23:58:08] hmm... ok [23:58:13] gotcha [23:58:16] You can't change existing modules. [23:58:17] thx for your help! [23:58:26] ah, that was the main misunderstanding :) [23:58:35] $this->register( $config->get( 'ResourceModules' ) ); [23:58:35] Hooks::run( 'ResourceLoaderRegisterModules', [ &$this ] ); [23:58:44] This is on purpose :) [23:58:46] yurik: no, i haven't had time to debug why https://gerrit.wikimedia.org/r/286906 is unreliable. things keep coming up [23:59:10] that patch works (worked), but only most of the time :P [23:59:43] MatmaRex, ping jgirault, he might know