Re: [Wikitech-l] Issue loading JS with ResourceLoader but not with addScript

2017-04-26 Thread James Montalvo
Is there a phabricator task to track this?

On Tue, Apr 18, 2017 at 7:07 PM, Krinkle  wrote:

> The error string "Module "jquery" is not loaded" actually comes from
> mw.loader.require,
> unlike the "Unknown dependency: jquery" error which can come from
> mw.loader.load.
>
> It looks like the "masonry.pkgd.js" script is detecting a
> CommonJS-compatible environment
> and therefore assumes jQuery must also be available through require().
>
> ResourceLoader in MediaWiki only recently added support for module.exports
> and require.
> While it is available, it is not yet the default for most modules,
> including jQuery.
> However, this assumption is reasonable and actually fairly common in
> libraries so we should
> definitely add support for it. Either that, or we need a way for registered
> modules to opt-out
> of having require/module.exports available, so that libraries such as these
> can be loaded
> without problem.
>
> -- Timo
>
>
> On Tue, Apr 18, 2017 at 4:04 PM, James Montalvo 
> wrote:
>
> > No jquery dependency specified. I put together a minimal extension to
> > demonstrate the issue. Below is a link to the comparison of the first
> > commit (using ResourceLoader) and the second (using
> OutputPage::addScript).
> >
> > https://github.com/jamesmontalvo3/JustMasonry/compare/ResourceLoader...
> > addScript
> >
> > On the `ResourceLoader` branch I get the 'Module "jquery" is not loaded'
> > error. On the `addScript` branch I do not, and I'm able to use the
> library
> > like:
> >
> > var test = new Masonry("#bodyContent");
> >
> > OS:
> > CentOS Linux release 7.3.1611
> >
> > Installed software:
> > MediaWiki 1.27.2 (1c409c5)
> > PHP 5.6.30 (apache2handler)
> > MariaDB 5.5.52-MariaDB
> > ICU 50.1.2
> >
> > Skins:
> > Vector – (d11a80a) 12:02, 19 May 2016
> >
> > Extensions:
> > JustMasonry 2017.4.18 (68bcd0a) 17:47, 18 April 2017
> > I removed all other extensions and confirmed this is still an issue.
> >
> > Thanks,
> > James
> >
> > On Tue, Apr 18, 2017 at 1:51 PM, Legoktm 
> > wrote:
> >
> > > Hi,
> > >
> > > On 04/17/2017 02:17 PM, James Montalvo wrote:
> > > > Uncaught Error: Module "jquery" is not loaded.
> > >
> > > Does your module definition have a dependency on 'jquery'? You should
> > > remove that as it will cause errors like this. jQuery is always loaded
> > > before any other RL modules are.
> > >
> > > -- Legoktm
> > >
> > > ___
> > > Wikitech-l mailing list
> > > Wikitech-l@lists.wikimedia.org
> > > https://lists.wikimedia.org/mailman/listinfo/wikitech-l
> > ___
> > Wikitech-l mailing list
> > Wikitech-l@lists.wikimedia.org
> > https://lists.wikimedia.org/mailman/listinfo/wikitech-l
> >
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] Issue loading JS with ResourceLoader but not with addScript

2017-04-18 Thread Krinkle
The error string "Module "jquery" is not loaded" actually comes from
mw.loader.require,
unlike the "Unknown dependency: jquery" error which can come from
mw.loader.load.

It looks like the "masonry.pkgd.js" script is detecting a
CommonJS-compatible environment
and therefore assumes jQuery must also be available through require().

ResourceLoader in MediaWiki only recently added support for module.exports
and require.
While it is available, it is not yet the default for most modules,
including jQuery.
However, this assumption is reasonable and actually fairly common in
libraries so we should
definitely add support for it. Either that, or we need a way for registered
modules to opt-out
of having require/module.exports available, so that libraries such as these
can be loaded
without problem.

-- Timo


On Tue, Apr 18, 2017 at 4:04 PM, James Montalvo 
wrote:

> No jquery dependency specified. I put together a minimal extension to
> demonstrate the issue. Below is a link to the comparison of the first
> commit (using ResourceLoader) and the second (using OutputPage::addScript).
>
> https://github.com/jamesmontalvo3/JustMasonry/compare/ResourceLoader...
> addScript
>
> On the `ResourceLoader` branch I get the 'Module "jquery" is not loaded'
> error. On the `addScript` branch I do not, and I'm able to use the library
> like:
>
> var test = new Masonry("#bodyContent");
>
> OS:
> CentOS Linux release 7.3.1611
>
> Installed software:
> MediaWiki 1.27.2 (1c409c5)
> PHP 5.6.30 (apache2handler)
> MariaDB 5.5.52-MariaDB
> ICU 50.1.2
>
> Skins:
> Vector – (d11a80a) 12:02, 19 May 2016
>
> Extensions:
> JustMasonry 2017.4.18 (68bcd0a) 17:47, 18 April 2017
> I removed all other extensions and confirmed this is still an issue.
>
> Thanks,
> James
>
> On Tue, Apr 18, 2017 at 1:51 PM, Legoktm 
> wrote:
>
> > Hi,
> >
> > On 04/17/2017 02:17 PM, James Montalvo wrote:
> > > Uncaught Error: Module "jquery" is not loaded.
> >
> > Does your module definition have a dependency on 'jquery'? You should
> > remove that as it will cause errors like this. jQuery is always loaded
> > before any other RL modules are.
> >
> > -- Legoktm
> >
> > ___
> > Wikitech-l mailing list
> > Wikitech-l@lists.wikimedia.org
> > https://lists.wikimedia.org/mailman/listinfo/wikitech-l
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] Issue loading JS with ResourceLoader but not with addScript

2017-04-18 Thread James Montalvo
No jquery dependency specified. I put together a minimal extension to
demonstrate the issue. Below is a link to the comparison of the first
commit (using ResourceLoader) and the second (using OutputPage::addScript).

https://github.com/jamesmontalvo3/JustMasonry/compare/ResourceLoader...addScript

On the `ResourceLoader` branch I get the 'Module "jquery" is not loaded'
error. On the `addScript` branch I do not, and I'm able to use the library
like:

var test = new Masonry("#bodyContent");

OS:
CentOS Linux release 7.3.1611

Installed software:
MediaWiki 1.27.2 (1c409c5)
PHP 5.6.30 (apache2handler)
MariaDB 5.5.52-MariaDB
ICU 50.1.2

Skins:
Vector – (d11a80a) 12:02, 19 May 2016

Extensions:
JustMasonry 2017.4.18 (68bcd0a) 17:47, 18 April 2017
I removed all other extensions and confirmed this is still an issue.

Thanks,
James

On Tue, Apr 18, 2017 at 1:51 PM, Legoktm 
wrote:

> Hi,
>
> On 04/17/2017 02:17 PM, James Montalvo wrote:
> > Uncaught Error: Module "jquery" is not loaded.
>
> Does your module definition have a dependency on 'jquery'? You should
> remove that as it will cause errors like this. jQuery is always loaded
> before any other RL modules are.
>
> -- Legoktm
>
> ___
> Wikitech-l mailing list
> Wikitech-l@lists.wikimedia.org
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Re: [Wikitech-l] Issue loading JS with ResourceLoader but not with addScript

2017-04-18 Thread Legoktm
Hi,

On 04/17/2017 02:17 PM, James Montalvo wrote:
> Uncaught Error: Module "jquery" is not loaded.

Does your module definition have a dependency on 'jquery'? You should
remove that as it will cause errors like this. jQuery is always loaded
before any other RL modules are.

-- Legoktm

___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

[Wikitech-l] Issue loading JS with ResourceLoader but not with addScript

2017-04-17 Thread James Montalvo
I'm having an issue with getting ResourceLoader to properly load the
Masonry library [1]. This issue was not present on MW 1.25 but is on MW
1.27. If I do the following:

$out->addModules( 'ext.masonrymainpage.libs' ); // or as dependency to base
$out->addModules( 'ext.masonrymainpage.base' );

Then I get the following error in my browser:

Uncaught Error: Module "jquery" is not loaded.
at require
(load.php?debug=true=en=jquery%2Cmediawiki=scripts=vector=ciafJ7Ly:12581)
at masonry.pkgd.js?c5dde:29
at masonry.pkgd.js?c5dde:39
require @
load.php?debug=true=en=jquery%2Cmediawiki=scripts=vector=ciafJ7Ly:12581
(anonymous) @ masonry.pkgd.js?c5dde:29
(anonymous) @ masonry.pkgd.js?c5dde:39
load.php?debug=true=en=jquery%2Cmediawiki=scripts=vector=ciafJ7Ly:11145
Use of "wgCategories" is deprecated. Use mw.config instead.
get @
load.php?debug=true=en=jquery%2Cmediawiki=scripts=vector=ciafJ7Ly:11145
(anonymous) @
load.php?debug=true=en=site=scripts=vector=680c78b07fb0:273

However, if I load Masonry not from the ext.masonrymainpage.libs module,
but instead using OutputPage::addScript() then I have no issues:

global $wgServer, $wgExtensionAssetsPath;
$scriptURL =
"$wgServer/$wgExtensionAssetsPath/MasonryMainPage/masonry.pkgd.js";
$out->addScript( "" );
$out->addModules( 'ext.masonrymainpage.base' );

Can anyone help me figure out how to do this the right way?

Thanks,
James

[1] https://github.com/desandro/masonry
___
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l