2014-10-22 05:32:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-02-06 09:44:05 +00:00
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
|
use Wikimedia\ObjectFactory;
|
|
|
|
|
|
2014-10-10 00:07:14 +00:00
|
|
|
/**
|
|
|
|
|
* @group ResourceLoader
|
|
|
|
|
*/
|
2014-10-22 05:32:13 +00:00
|
|
|
class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2014-10-22 05:32:13 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2020-07-15 05:28:37 +00:00
|
|
|
$skinFactory = new SkinFactory(
|
|
|
|
|
new ObjectFactory( $this->createMock( ContainerInterface::class ) ), []
|
|
|
|
|
);
|
2020-02-06 09:44:05 +00:00
|
|
|
// The empty spec shouldn't matter since this test should never call it
|
2019-06-03 00:55:00 +00:00
|
|
|
$skinFactory->register(
|
2014-10-22 05:32:13 +00:00
|
|
|
'fakeskin',
|
|
|
|
|
'FakeSkin',
|
2020-02-06 09:44:05 +00:00
|
|
|
[]
|
2014-10-22 05:32:13 +00:00
|
|
|
);
|
2019-06-03 00:55:00 +00:00
|
|
|
$this->setService( 'SkinFactory', $skinFactory );
|
2019-06-19 22:44:39 +00:00
|
|
|
|
|
|
|
|
// This test is not expected to query any database
|
|
|
|
|
MediaWiki\MediaWikiServices::disableStorageBackend();
|
2014-10-22 05:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-23 03:57:45 +00:00
|
|
|
private static function getModules() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$base = [
|
2019-06-19 22:44:39 +00:00
|
|
|
'localBasePath' => __DIR__,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-10-10 00:07:14 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
'noTemplateModule' => [],
|
2014-10-10 00:07:14 +00:00
|
|
|
|
2016-07-14 22:09:06 +00:00
|
|
|
'deprecatedModule' => $base + [
|
|
|
|
|
'deprecated' => true,
|
|
|
|
|
],
|
|
|
|
|
'deprecatedTomorrow' => $base + [
|
2017-03-18 00:22:34 +00:00
|
|
|
'deprecated' => 'Will be removed tomorrow.'
|
2016-07-14 22:09:06 +00:00
|
|
|
],
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
'htmlTemplateModule' => $base + [
|
|
|
|
|
'templates' => [
|
2014-10-10 00:07:14 +00:00
|
|
|
'templates/template.html',
|
|
|
|
|
'templates/template2.html',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
2014-10-10 00:07:14 +00:00
|
|
|
|
2017-06-27 04:21:36 +00:00
|
|
|
'htmlTemplateUnknown' => $base + [
|
|
|
|
|
'templates' => [
|
|
|
|
|
'templates/notfound.html',
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
'aliasedHtmlTemplateModule' => $base + [
|
|
|
|
|
'templates' => [
|
2014-10-10 00:07:14 +00:00
|
|
|
'foo.html' => 'templates/template.html',
|
|
|
|
|
'bar.html' => 'templates/template2.html',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
2014-10-10 00:07:14 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
'templateModuleHandlebars' => $base + [
|
|
|
|
|
'templates' => [
|
2014-10-10 00:07:14 +00:00
|
|
|
'templates/template_awesome.handlebars',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
2014-12-17 20:30:54 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
'aliasFooFromBar' => $base + [
|
|
|
|
|
'templates' => [
|
2014-12-17 20:30:54 +00:00
|
|
|
'foo.foo' => 'templates/template.bar',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2014-12-17 20:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function providerTemplateDependencies() {
|
|
|
|
|
$modules = self::getModules();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
2014-12-17 20:30:54 +00:00
|
|
|
$modules['noTemplateModule'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
],
|
|
|
|
|
[
|
2014-12-17 20:30:54 +00:00
|
|
|
$modules['htmlTemplateModule'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-12-17 20:30:54 +00:00
|
|
|
'mediawiki.template',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2014-12-17 20:30:54 +00:00
|
|
|
$modules['templateModuleHandlebars'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-12-17 20:30:54 +00:00
|
|
|
'mediawiki.template',
|
|
|
|
|
'mediawiki.template.handlebars',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2014-12-17 20:30:54 +00:00
|
|
|
$modules['aliasFooFromBar'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-12-17 20:30:54 +00:00
|
|
|
'mediawiki.template',
|
|
|
|
|
'mediawiki.template.foo',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
2014-10-10 00:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 20:30:54 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider providerTemplateDependencies
|
|
|
|
|
* @covers ResourceLoaderFileModule::__construct
|
|
|
|
|
* @covers ResourceLoaderFileModule::getDependencies
|
|
|
|
|
*/
|
|
|
|
|
public function testTemplateDependencies( $module, $expected ) {
|
|
|
|
|
$rl = new ResourceLoaderFileModule( $module );
|
2016-09-12 00:07:52 +00:00
|
|
|
$rl->setName( 'testing' );
|
2014-12-17 20:30:54 +00:00
|
|
|
$this->assertEquals( $rl->getDependencies(), $expected );
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-14 22:09:06 +00:00
|
|
|
public static function providerDeprecatedModules() {
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'deprecatedModule',
|
|
|
|
|
'mw.log.warn("This page is using the deprecated ResourceLoader module \"deprecatedModule\".");',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'deprecatedTomorrow',
|
|
|
|
|
'mw.log.warn(' .
|
|
|
|
|
'"This page is using the deprecated ResourceLoader module \"deprecatedTomorrow\".\\n' .
|
|
|
|
|
"Will be removed tomorrow." .
|
|
|
|
|
'");'
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider providerDeprecatedModules
|
2016-08-06 08:04:21 +00:00
|
|
|
* @covers ResourceLoaderFileModule::getScript
|
2016-07-14 22:09:06 +00:00
|
|
|
*/
|
|
|
|
|
public function testDeprecatedModules( $name, $expected ) {
|
|
|
|
|
$modules = self::getModules();
|
2017-06-27 05:04:21 +00:00
|
|
|
$module = new ResourceLoaderFileModule( $modules[$name] );
|
|
|
|
|
$module->setName( $name );
|
2016-12-03 00:46:53 +00:00
|
|
|
$ctx = $this->getResourceLoaderContext();
|
2017-06-27 05:04:21 +00:00
|
|
|
$this->assertEquals( $module->getScript( $ctx ), $expected );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderFileModule::getScript
|
2018-06-26 01:52:40 +00:00
|
|
|
* @covers ResourceLoaderFileModule::getScriptFiles
|
|
|
|
|
* @covers ResourceLoaderFileModule::readScriptFiles
|
2017-06-27 05:04:21 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetScript() {
|
|
|
|
|
$module = new ResourceLoaderFileModule( [
|
|
|
|
|
'localBasePath' => __DIR__ . '/../../data/resourceloader',
|
|
|
|
|
'scripts' => [ 'script-nosemi.js', 'script-comment.js' ],
|
|
|
|
|
] );
|
|
|
|
|
$module->setName( 'testing' );
|
|
|
|
|
$ctx = $this->getResourceLoaderContext();
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"/* eslint-disable */\nmw.foo()\n" .
|
2019-07-27 09:26:58 +00:00
|
|
|
"/* eslint-disable */\nmw.foo()\n// mw.bar();\n",
|
|
|
|
|
$module->getScript( $ctx ),
|
|
|
|
|
'scripts with newline at the end are concatenated without a newline'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$module = new ResourceLoaderFileModule( [
|
|
|
|
|
'localBasePath' => __DIR__ . '/../../data/resourceloader',
|
|
|
|
|
'scripts' => [ 'script-nosemi-nonl.js', 'script-comment-nonl.js' ],
|
|
|
|
|
] );
|
|
|
|
|
$module->setName( 'testing' );
|
|
|
|
|
$ctx = $this->getResourceLoaderContext();
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"/* eslint-disable */\nmw.foo()" .
|
2017-06-27 05:04:21 +00:00
|
|
|
"\n" .
|
2019-07-27 09:26:58 +00:00
|
|
|
"/* eslint-disable */\nmw.foo()\n// mw.bar();" .
|
2017-06-27 05:04:21 +00:00
|
|
|
"\n",
|
|
|
|
|
$module->getScript( $ctx ),
|
2019-07-27 09:26:58 +00:00
|
|
|
'scripts without newline at the end are concatenated with a newline'
|
2017-06-27 05:04:21 +00:00
|
|
|
);
|
2016-07-14 22:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
resourceloader: Fix debug mode for RL-to-RL cross-wiki module loads
The native "foreign module source" feature, as used by the GlobalCssJs
extension, did not work correctly in debug mode as the urls returned
by the remote wiki were formatted as "/w/load.php...", which would
be interpreted by the browser relative to the host document, instead
of relative to the parent script.
For example:
1. Page view on en.wikipedia.org.
2. Script call to
meta.wikimedia.org/w/load.php?debug=true&modules=ext.globalCssJs.user&user
This URL is formatted by getScriptURLsForDebug on en.wikipedia.org,
when building the article HTML. It knows the modules is on Meta, and
formats it as such.
So far so good.
3. meta.wikimedia.org responds with an array of urls for sub resources.
That array contained URLs like "/w/load.php...only=scripts".
These were formatted by getScriptURLsForDebug running on Meta,
no longer with a reason to make it a Meta-Wiki URL as it isn't
perceived as cross-wiki. It is indistinguishable from debugging
a Meta-Wiki page view from its perspective.
This patch affects scenario 3 by always expanding it relative to the
current-request's wgServer. We still only do this in debug mode. There
is not yet a need to do this in non-debug mode, and if there was we'd
likely want to find a way to avoid it in the common case to keep
embedded URLs short.
The ResourceLoader::expandUrl() method is similar to the one in
Wikimedia\Minify\CSSMin.
Test Plan:
* view-source:http://mw.localhost:8080/w/load.php?debug=1&modules=site
For Module base class.
Before, the array entries were relative. After, they are full.
* view-source:http://mw.localhost:8080/w/load.php?debug=1&modules=jquery
For FileModule.
Before, the array entries were relative. After, they are full.
* view-source:http://mw.localhost:8080/wiki/Main_Page?debug=true
Unchanged.
* view-source:http://mw.localhost:8080/wiki/Main_Page
Unchanged.
Bug: T255367
Change-Id: I83919744b2677c7fb52b84089ecc60b89957d32a
2021-08-25 02:36:25 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::expandUrl
|
|
|
|
|
* @covers ResourceLoaderFileModule
|
|
|
|
|
*/
|
|
|
|
|
public function testGetScriptURLsForDebug() {
|
|
|
|
|
$ctx = $this->getResourceLoaderContext();
|
|
|
|
|
$module = new ResourceLoaderFileModule( [
|
|
|
|
|
'localBasePath' => __DIR__ . '/../../data/resourceloader',
|
|
|
|
|
'remoteBasePath' => '/w/something',
|
|
|
|
|
'scripts' => [ 'script-comment.js' ],
|
|
|
|
|
] );
|
|
|
|
|
$module->setName( 'testing' );
|
|
|
|
|
$module->setConfig( $ctx->getResourceLoader()->getConfig() );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[
|
|
|
|
|
'https://example.org/w/something/script-comment.js'
|
|
|
|
|
],
|
|
|
|
|
$module->getScriptURLsForDebug( $ctx )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 05:32:13 +00:00
|
|
|
/**
|
2019-11-29 05:39:53 +00:00
|
|
|
* @covers ResourceLoaderFileModule
|
2014-10-22 05:32:13 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetAllSkinStyleFiles() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$baseParams = [
|
|
|
|
|
'scripts' => [
|
2014-10-22 05:32:13 +00:00
|
|
|
'foo.js',
|
|
|
|
|
'bar.js',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'styles' => [
|
2014-10-22 05:32:13 +00:00
|
|
|
'foo.css',
|
2016-02-17 09:09:32 +00:00
|
|
|
'bar.css' => [ 'media' => 'print' ],
|
|
|
|
|
'screen.less' => [ 'media' => 'screen' ],
|
|
|
|
|
'screen-query.css' => [ 'media' => 'screen and (min-width: 400px)' ],
|
|
|
|
|
],
|
|
|
|
|
'skinStyles' => [
|
2014-10-22 05:32:13 +00:00
|
|
|
'default' => 'quux-fallback.less',
|
2016-02-17 09:09:32 +00:00
|
|
|
'fakeskin' => [
|
2014-10-22 05:32:13 +00:00
|
|
|
'baz-vector.css',
|
|
|
|
|
'quux-vector.less',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'messages' => [
|
2014-10-22 05:32:13 +00:00
|
|
|
'hello',
|
|
|
|
|
'world',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2014-10-22 05:32:13 +00:00
|
|
|
|
|
|
|
|
$module = new ResourceLoaderFileModule( $baseParams );
|
2016-09-12 00:07:52 +00:00
|
|
|
$module->setName( 'testing' );
|
2014-10-22 05:32:13 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-10-22 05:32:13 +00:00
|
|
|
'foo.css',
|
|
|
|
|
'baz-vector.css',
|
|
|
|
|
'quux-vector.less',
|
|
|
|
|
'quux-fallback.less',
|
|
|
|
|
'bar.css',
|
|
|
|
|
'screen.less',
|
|
|
|
|
'screen-query.css',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2014-10-22 05:32:13 +00:00
|
|
|
array_map( 'basename', $module->getAllStyleFiles() )
|
|
|
|
|
);
|
|
|
|
|
}
|
2014-10-10 00:07:14 +00:00
|
|
|
|
2015-03-23 03:57:45 +00:00
|
|
|
/**
|
|
|
|
|
* Strip @noflip annotations from CSS code.
|
|
|
|
|
* @param string $css
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private static function stripNoflip( $css ) {
|
|
|
|
|
return str_replace( '/*@noflip*/ ', '', $css );
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 18:29:09 +00:00
|
|
|
/**
|
|
|
|
|
* Confirm that 'ResourceModuleSkinStyles' skin attributes get injected
|
|
|
|
|
* into the module, and have their file contents read correctly from their
|
|
|
|
|
* own (out-of-module) directories.
|
|
|
|
|
*
|
|
|
|
|
* @covers ResourceLoader
|
|
|
|
|
* @covers ResourceLoaderFileModule
|
|
|
|
|
*/
|
|
|
|
|
public function testInjectSkinStyles() {
|
|
|
|
|
$moduleDir = __DIR__ . '/../../data/resourceloader';
|
|
|
|
|
$skinDir = __DIR__ . '/../../data/resourceloader/myskin';
|
|
|
|
|
$rl = new ResourceLoader( new HashConfig( self::getSettings() ) );
|
|
|
|
|
$rl->setModuleSkinStyles( [
|
|
|
|
|
'fakeskin' => [
|
|
|
|
|
'localBasePath' => $skinDir,
|
|
|
|
|
'testing' => [
|
|
|
|
|
'override.css',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
] );
|
|
|
|
|
$rl->register( 'testing', [
|
|
|
|
|
'localBasePath' => $moduleDir,
|
|
|
|
|
'styles' => [ 'simple.css' ],
|
|
|
|
|
] );
|
|
|
|
|
$ctx = $this->getResourceLoaderContext( [ 'skin' => 'fakeskin' ], $rl );
|
|
|
|
|
|
|
|
|
|
$module = $rl->getModule( 'testing' );
|
|
|
|
|
$this->assertInstanceOf( ResourceLoaderFileModule::class, $module );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[ 'all' => ".example { color: blue; }\n\n.override { line-height: 2; }\n" ],
|
|
|
|
|
$module->getStyles( $ctx )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 03:57:45 +00:00
|
|
|
/**
|
|
|
|
|
* What happens when you mix @embed and @noflip?
|
|
|
|
|
* This really is an integration test, but oh well.
|
|
|
|
|
*
|
|
|
|
|
* @covers ResourceLoaderFileModule::getStyles
|
|
|
|
|
* @covers ResourceLoaderFileModule::getStyleFiles
|
2018-06-26 01:52:40 +00:00
|
|
|
* @covers ResourceLoaderFileModule::readStyleFiles
|
|
|
|
|
* @covers ResourceLoaderFileModule::readStyleFile
|
2015-03-23 03:57:45 +00:00
|
|
|
*/
|
2015-06-16 19:06:19 +00:00
|
|
|
public function testMixedCssAnnotations() {
|
2015-03-23 03:57:45 +00:00
|
|
|
$basePath = __DIR__ . '/../../data/css';
|
2019-06-19 22:44:39 +00:00
|
|
|
$testModule = new ResourceLoaderFileTestModule( [
|
2015-03-23 03:57:45 +00:00
|
|
|
'localBasePath' => $basePath,
|
2016-02-17 09:09:32 +00:00
|
|
|
'styles' => [ 'test.css' ],
|
|
|
|
|
] );
|
2016-09-12 00:07:52 +00:00
|
|
|
$testModule->setName( 'testing' );
|
2019-06-19 22:44:39 +00:00
|
|
|
$expectedModule = new ResourceLoaderFileTestModule( [
|
2015-03-23 03:57:45 +00:00
|
|
|
'localBasePath' => $basePath,
|
2016-02-17 09:09:32 +00:00
|
|
|
'styles' => [ 'expected.css' ],
|
|
|
|
|
] );
|
2016-09-12 00:07:52 +00:00
|
|
|
$expectedModule->setName( 'testing' );
|
2015-03-23 03:57:45 +00:00
|
|
|
|
2016-12-03 00:46:53 +00:00
|
|
|
$contextLtr = $this->getResourceLoaderContext( [
|
|
|
|
|
'lang' => 'en',
|
|
|
|
|
'dir' => 'ltr',
|
|
|
|
|
] );
|
|
|
|
|
$contextRtl = $this->getResourceLoaderContext( [
|
|
|
|
|
'lang' => 'he',
|
|
|
|
|
'dir' => 'rtl',
|
|
|
|
|
] );
|
2015-03-23 03:57:45 +00:00
|
|
|
|
|
|
|
|
// Since we want to compare the effect of @noflip+@embed against the effect of just @embed, and
|
|
|
|
|
// the @noflip annotations are always preserved, we need to strip them first.
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$expectedModule->getStyles( $contextLtr ),
|
|
|
|
|
self::stripNoflip( $testModule->getStyles( $contextLtr ) ),
|
|
|
|
|
"/*@noflip*/ with /*@embed*/ gives correct results in LTR mode"
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$expectedModule->getStyles( $contextLtr ),
|
|
|
|
|
self::stripNoflip( $testModule->getStyles( $contextRtl ) ),
|
|
|
|
|
"/*@noflip*/ with /*@embed*/ gives correct results in RTL mode"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-29 05:39:53 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderFileModule
|
|
|
|
|
*/
|
|
|
|
|
public function testCssFlipping() {
|
|
|
|
|
$plain = new ResourceLoaderFileTestModule( [
|
|
|
|
|
'localBasePath' => __DIR__ . '/../../data/resourceloader',
|
|
|
|
|
'styles' => [ 'direction.css' ],
|
|
|
|
|
] );
|
|
|
|
|
$plain->setName( 'test' );
|
|
|
|
|
|
|
|
|
|
$context = $this->getResourceLoaderContext( [ 'lang' => 'en', 'dir' => 'ltr' ] );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$plain->getStyles( $context ),
|
|
|
|
|
[ 'all' => ".example { text-align: left; }\n" ],
|
|
|
|
|
'Unchanged styles in LTR mode'
|
|
|
|
|
);
|
|
|
|
|
$context = $this->getResourceLoaderContext( [ 'lang' => 'he', 'dir' => 'rtl' ] );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$plain->getStyles( $context ),
|
|
|
|
|
[ 'all' => ".example { text-align: right; }\n" ],
|
|
|
|
|
'Flipped styles in RTL mode'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$noflip = new ResourceLoaderFileTestModule( [
|
|
|
|
|
'localBasePath' => __DIR__ . '/../../data/resourceloader',
|
|
|
|
|
'styles' => [ 'direction.css' ],
|
|
|
|
|
'noflip' => true,
|
|
|
|
|
] );
|
|
|
|
|
$noflip->setName( 'test' );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$plain->getStyles( $context ),
|
|
|
|
|
[ 'all' => ".example { text-align: right; }\n" ],
|
|
|
|
|
'Unchanged styles in RTL mode with noflip at module level'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 02:14:05 +00:00
|
|
|
/**
|
|
|
|
|
* Test reading files from elsewhere than localBasePath using ResourceLoaderFilePath.
|
|
|
|
|
*
|
2021-08-11 18:29:09 +00:00
|
|
|
* The use of ResourceLoaderFilePath objects resembles the way that ResourceLoader::getModule()
|
|
|
|
|
* injects additional files when 'ResourceModuleSkinStyles' or 'OOUIThemePaths' skin attributes
|
|
|
|
|
* apply to a given module.
|
2017-03-17 02:14:05 +00:00
|
|
|
*
|
|
|
|
|
* @covers ResourceLoaderFilePath::getLocalBasePath
|
|
|
|
|
* @covers ResourceLoaderFilePath::getRemoteBasePath
|
|
|
|
|
*/
|
|
|
|
|
public function testResourceLoaderFilePath() {
|
|
|
|
|
$basePath = __DIR__ . '/../../data/blahblah';
|
|
|
|
|
$filePath = __DIR__ . '/../../data/rlfilepath';
|
|
|
|
|
$testModule = new ResourceLoaderFileModule( [
|
|
|
|
|
'localBasePath' => $basePath,
|
|
|
|
|
'remoteBasePath' => 'blahblah',
|
|
|
|
|
'styles' => new ResourceLoaderFilePath( 'style.css', $filePath, 'rlfilepath' ),
|
|
|
|
|
'skinStyles' => [
|
|
|
|
|
'vector' => new ResourceLoaderFilePath( 'skinStyle.css', $filePath, 'rlfilepath' ),
|
|
|
|
|
],
|
|
|
|
|
'scripts' => new ResourceLoaderFilePath( 'script.js', $filePath, 'rlfilepath' ),
|
|
|
|
|
'templates' => new ResourceLoaderFilePath( 'template.html', $filePath, 'rlfilepath' ),
|
|
|
|
|
] );
|
|
|
|
|
$expectedModule = new ResourceLoaderFileModule( [
|
|
|
|
|
'localBasePath' => $filePath,
|
|
|
|
|
'remoteBasePath' => 'rlfilepath',
|
|
|
|
|
'styles' => 'style.css',
|
|
|
|
|
'skinStyles' => [
|
|
|
|
|
'vector' => 'skinStyle.css',
|
|
|
|
|
],
|
|
|
|
|
'scripts' => 'script.js',
|
|
|
|
|
'templates' => 'template.html',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$context = $this->getResourceLoaderContext();
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$expectedModule->getModuleContent( $context ),
|
|
|
|
|
$testModule->getModuleContent( $context ),
|
|
|
|
|
"Using ResourceLoaderFilePath works correctly"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-23 03:57:45 +00:00
|
|
|
public static function providerGetTemplates() {
|
|
|
|
|
$modules = self::getModules();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
2015-03-23 03:57:45 +00:00
|
|
|
$modules['noTemplateModule'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-03-23 03:57:45 +00:00
|
|
|
$modules['templateModuleHandlebars'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-03-23 03:57:45 +00:00
|
|
|
'templates/template_awesome.handlebars' => "wow\n",
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-03-23 03:57:45 +00:00
|
|
|
$modules['htmlTemplateModule'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-03-23 03:57:45 +00:00
|
|
|
'templates/template.html' => "<strong>hello</strong>\n",
|
|
|
|
|
'templates/template2.html' => "<div>goodbye</div>\n",
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-03-23 03:57:45 +00:00
|
|
|
$modules['aliasedHtmlTemplateModule'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-03-23 03:57:45 +00:00
|
|
|
'foo.html' => "<strong>hello</strong>\n",
|
|
|
|
|
'bar.html' => "<div>goodbye</div>\n",
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
2017-06-27 04:21:36 +00:00
|
|
|
[
|
|
|
|
|
$modules['htmlTemplateUnknown'],
|
|
|
|
|
false,
|
|
|
|
|
],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-03-23 03:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-10 00:07:14 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider providerGetTemplates
|
|
|
|
|
* @covers ResourceLoaderFileModule::getTemplates
|
|
|
|
|
*/
|
|
|
|
|
public function testGetTemplates( $module, $expected ) {
|
|
|
|
|
$rl = new ResourceLoaderFileModule( $module );
|
2016-09-12 00:07:52 +00:00
|
|
|
$rl->setName( 'testing' );
|
2014-10-10 00:07:14 +00:00
|
|
|
|
2017-06-27 04:21:36 +00:00
|
|
|
if ( $expected === false ) {
|
2019-12-01 01:58:30 +00:00
|
|
|
$this->expectException( RuntimeException::class );
|
2017-06-27 04:21:36 +00:00
|
|
|
$rl->getTemplates();
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals( $rl->getTemplates(), $expected );
|
|
|
|
|
}
|
2014-10-10 00:07:14 +00:00
|
|
|
}
|
2016-05-11 11:53:59 +00:00
|
|
|
|
2017-06-27 04:44:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderFileModule::stripBom
|
|
|
|
|
*/
|
2016-05-11 11:53:59 +00:00
|
|
|
public function testBomConcatenation() {
|
|
|
|
|
$basePath = __DIR__ . '/../../data/css';
|
2019-06-19 22:44:39 +00:00
|
|
|
$testModule = new ResourceLoaderFileTestModule( [
|
2016-05-11 11:53:59 +00:00
|
|
|
'localBasePath' => $basePath,
|
|
|
|
|
'styles' => [ 'bom.css' ],
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
] );
|
2016-09-12 00:07:52 +00:00
|
|
|
$testModule->setName( 'testing' );
|
2016-05-11 11:53:59 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
substr( file_get_contents( "$basePath/bom.css" ), 0, 10 ),
|
|
|
|
|
"\xef\xbb\xbf.efbbbf",
|
|
|
|
|
'File has leading BOM'
|
|
|
|
|
);
|
|
|
|
|
|
2016-12-03 00:46:53 +00:00
|
|
|
$context = $this->getResourceLoaderContext();
|
2016-05-11 11:53:59 +00:00
|
|
|
$this->assertEquals(
|
2016-12-03 00:46:53 +00:00
|
|
|
$testModule->getStyles( $context ),
|
2016-05-11 11:53:59 +00:00
|
|
|
[ 'all' => ".efbbbf_bom_char_at_start_of_file {}\n" ],
|
|
|
|
|
'Leading BOM removed when concatenating files'
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-07-27 01:53:37 +00:00
|
|
|
|
2018-08-09 15:09:56 +00:00
|
|
|
/**
|
2019-11-29 05:39:53 +00:00
|
|
|
* @covers ResourceLoaderFileModule
|
2018-08-09 15:09:56 +00:00
|
|
|
*/
|
|
|
|
|
public function testLessFileCompilation() {
|
|
|
|
|
$context = $this->getResourceLoaderContext();
|
|
|
|
|
$basePath = __DIR__ . '/../../data/less/module';
|
|
|
|
|
$module = new ResourceLoaderFileTestModule( [
|
|
|
|
|
'localBasePath' => $basePath,
|
|
|
|
|
'styles' => [ 'styles.less' ],
|
|
|
|
|
'lessVars' => [ 'foo' => '2px', 'Foo' => '#eeeeee' ]
|
|
|
|
|
] );
|
|
|
|
|
$module->setName( 'test.less' );
|
|
|
|
|
$styles = $module->getStyles( $context );
|
|
|
|
|
$this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-12 14:05:09 +00:00
|
|
|
public function provideGetVersionHash() {
|
|
|
|
|
$a = [];
|
|
|
|
|
$b = [
|
|
|
|
|
'lessVars' => [ 'key' => 'value' ],
|
|
|
|
|
];
|
|
|
|
|
yield 'with and without Less variables' => [ $a, $b, false ];
|
|
|
|
|
|
|
|
|
|
$a = [
|
|
|
|
|
'lessVars' => [ 'key' => 'value1' ],
|
|
|
|
|
];
|
|
|
|
|
$b = [
|
|
|
|
|
'lessVars' => [ 'key' => 'value2' ],
|
|
|
|
|
];
|
|
|
|
|
yield 'different Less variables' => [ $a, $b, false ];
|
|
|
|
|
|
|
|
|
|
$x = [
|
|
|
|
|
'lessVars' => [ 'key' => 'value' ],
|
|
|
|
|
];
|
|
|
|
|
yield 'identical Less variables' => [ $x, $x, true ];
|
2019-06-12 00:57:17 +00:00
|
|
|
|
|
|
|
|
$a = [
|
2021-02-07 13:10:36 +00:00
|
|
|
'packageFiles' => [ [ 'name' => 'data.json', 'callback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
return [ 'aaa' ];
|
|
|
|
|
} ] ]
|
|
|
|
|
];
|
|
|
|
|
$b = [
|
2021-02-07 13:10:36 +00:00
|
|
|
'packageFiles' => [ [ 'name' => 'data.json', 'callback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
return [ 'bbb' ];
|
|
|
|
|
} ] ]
|
|
|
|
|
];
|
|
|
|
|
yield 'packageFiles with different callback' => [ $a, $b, false ];
|
|
|
|
|
|
|
|
|
|
$a = [
|
2021-02-07 13:10:36 +00:00
|
|
|
'packageFiles' => [ [ 'name' => 'aaa.json', 'callback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
return [ 'x' ];
|
|
|
|
|
} ] ]
|
|
|
|
|
];
|
|
|
|
|
$b = [
|
2021-02-07 13:10:36 +00:00
|
|
|
'packageFiles' => [ [ 'name' => 'bbb.json', 'callback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
return [ 'x' ];
|
|
|
|
|
} ] ]
|
|
|
|
|
];
|
|
|
|
|
yield 'packageFiles with different file name and a callback' => [ $a, $b, false ];
|
|
|
|
|
|
|
|
|
|
$a = [
|
2021-02-07 13:10:36 +00:00
|
|
|
'packageFiles' => [ [ 'name' => 'data.json', 'versionCallback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
return [ 'A-version' ];
|
2021-02-07 13:10:36 +00:00
|
|
|
}, 'callback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
throw new Exception( 'Unexpected computation' );
|
|
|
|
|
} ] ]
|
|
|
|
|
];
|
|
|
|
|
$b = [
|
2021-02-07 13:10:36 +00:00
|
|
|
'packageFiles' => [ [ 'name' => 'data.json', 'versionCallback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
return [ 'B-version' ];
|
2021-02-07 13:10:36 +00:00
|
|
|
}, 'callback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
throw new Exception( 'Unexpected computation' );
|
|
|
|
|
} ] ]
|
|
|
|
|
];
|
|
|
|
|
yield 'packageFiles with different versionCallback' => [ $a, $b, false ];
|
|
|
|
|
|
|
|
|
|
$a = [
|
|
|
|
|
'packageFiles' => [ [ 'name' => 'aaa.json',
|
2021-02-07 13:10:36 +00:00
|
|
|
'versionCallback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
return [ 'X-version' ];
|
|
|
|
|
},
|
2021-02-07 13:10:36 +00:00
|
|
|
'callback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
throw new Exception( 'Unexpected computation' );
|
|
|
|
|
}
|
|
|
|
|
] ]
|
|
|
|
|
];
|
|
|
|
|
$b = [
|
|
|
|
|
'packageFiles' => [ [ 'name' => 'bbb.json',
|
2021-02-07 13:10:36 +00:00
|
|
|
'versionCallback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
return [ 'X-version' ];
|
|
|
|
|
},
|
2021-02-07 13:10:36 +00:00
|
|
|
'callback' => static function () {
|
2019-06-12 00:57:17 +00:00
|
|
|
throw new Exception( 'Unexpected computation' );
|
|
|
|
|
}
|
|
|
|
|
] ]
|
|
|
|
|
];
|
|
|
|
|
yield 'packageFiles with different file name and a versionCallback' => [ $a, $b, false ];
|
2019-06-12 14:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-27 01:53:37 +00:00
|
|
|
/**
|
2019-06-12 14:05:09 +00:00
|
|
|
* @dataProvider provideGetVersionHash
|
2017-07-27 01:53:37 +00:00
|
|
|
* @covers ResourceLoaderFileModule::getDefinitionSummary
|
2018-06-26 01:52:40 +00:00
|
|
|
* @covers ResourceLoaderFileModule::getFileHashes
|
2017-07-27 01:53:37 +00:00
|
|
|
*/
|
2019-06-12 14:05:09 +00:00
|
|
|
public function testGetVersionHash( $a, $b, $isEqual ) {
|
resourceloader: Skip version hash calculation in debug mode
=== Why
* More speed
In debug mode, the server should regenerate the startup manifest
on each page view to ensure immediate effect of changes. But,
this also means more version recomputation work on the server.
For most modules, this was already quite fast on repeat views
because of OS-level file caches, and our file-hash caches and
LESS compile caches in php-apcu from ResourceLoader.
But, this makes it even faster.
* Better integration with browser devtools.
Breakpoints stay more consistently across browsers when the
URL stays the same even after you have changed the file and
reloaded the page. For static files, I believe most browsers ignore
query parameters. But for package files that come from load.php,
this was harder for browsers to guess correctly which old script URL
is logically replaced by a different one on the next page view.
=== How
Change Module::getVersionHash to return empty strings in debug mode.
I considered approaching this from StartupModule::getModuleRegistrations
instead to make the change apply only to the client-side manifest.
I decided against this because we have other calls to getVersionHash
on the server-side (such as for E-Tag calculation, and formatting
cross-wiki URLs) which would then not match the version queries that
mw.loader formats in debug mode.
Also, those calls would still be incurring some the avoidable costs.
=== Notes
* The two test cases for verifying the graceful fallback in production
if version hash computations throw an exception, were moved to a
non-debug test case as no longer happen now during the debug
(unminified) test cases.
* Avoid "PHP Notice: Undefined offset 0" in testMakeModuleResponseStartupError
by adding a fallback to empty string so that if the test fails,
it fails in a more useful way instead of aborting with this error
before the assertion happens. (Since PHPUnit generally stops on the
first error.)
* In practice, there are still "version" query parameters and E-Tag
headers in debug mode. These are not module versions, but URL
"combined versions" crafted by getCombinedVersion() in JS and PHP.
These return the constant "ztntf" in debug mode, which is the hash
of an empty string. We could alter these methods to special-case
when all inputs are and join to a still-empty string, or maybe we
just leave them be. I've done the latter for now.
Bug: T235672
Bug: T85805
Change-Id: I0e63eef4f85b13089a0aa3806a5b6f821d527a92
2021-08-28 02:53:36 +00:00
|
|
|
$context = $this->getResourceLoaderContext( [ 'debug' => 'false' ] );
|
2017-07-27 01:53:37 +00:00
|
|
|
|
2019-06-12 14:05:09 +00:00
|
|
|
$moduleA = new ResourceLoaderFileTestModule( $a );
|
2021-06-11 15:11:37 +00:00
|
|
|
$moduleA->setConfig( $context->getResourceLoader()->getConfig() );
|
2019-06-12 14:05:09 +00:00
|
|
|
$versionA = $moduleA->getVersionHash( $context );
|
|
|
|
|
$moduleB = new ResourceLoaderFileTestModule( $b );
|
2021-06-11 15:11:37 +00:00
|
|
|
$moduleB->setConfig( $context->getResourceLoader()->getConfig() );
|
2019-06-12 14:05:09 +00:00
|
|
|
$versionB = $moduleB->getVersionHash( $context );
|
|
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$isEqual,
|
|
|
|
|
( $versionA === $versionB ),
|
|
|
|
|
'Whether versions hashes are equal'
|
2017-07-27 01:53:37 +00:00
|
|
|
);
|
|
|
|
|
}
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
|
2019-06-12 14:05:09 +00:00
|
|
|
public function provideGetScriptPackageFiles() {
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$basePath = __DIR__ . '/../../data/resourceloader';
|
|
|
|
|
$base = [ 'localBasePath' => $basePath ];
|
|
|
|
|
$commentScript = file_get_contents( "$basePath/script-comment.js" );
|
|
|
|
|
$nosemiScript = file_get_contents( "$basePath/script-nosemi.js" );
|
2020-02-04 01:42:03 +00:00
|
|
|
$vueComponentDebug = trim( file_get_contents( "$basePath/vue-component-output-debug.js.txt" ) );
|
2020-05-22 23:10:50 +00:00
|
|
|
$vueComponentNonDebug = trim( file_get_contents( "$basePath/vue-component-output-nondebug.js.txt" ) );
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$config = RequestContext::getMain()->getConfig();
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
|
|
|
|
'script-comment.js',
|
|
|
|
|
'script-nosemi.js'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'files' => [
|
|
|
|
|
'script-comment.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => $commentScript,
|
|
|
|
|
],
|
|
|
|
|
'script-nosemi.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => $nosemiScript
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'main' => 'script-comment.js'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
|
|
|
|
'script-comment.js',
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
[ 'name' => 'script-nosemi.js', 'main' => true ]
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
],
|
|
|
|
|
'deprecated' => 'Deprecation test',
|
|
|
|
|
'name' => 'test-deprecated'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'files' => [
|
|
|
|
|
'script-comment.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => $commentScript,
|
|
|
|
|
],
|
|
|
|
|
'script-nosemi.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => 'mw.log.warn(' .
|
|
|
|
|
'"This page is using the deprecated ResourceLoader module \"test-deprecated\".\\n' .
|
|
|
|
|
"Deprecation test" .
|
|
|
|
|
'");' .
|
|
|
|
|
$nosemiScript
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'main' => 'script-nosemi.js'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
[ 'name' => 'init.js', 'file' => 'script-comment.js', 'main' => true ],
|
|
|
|
|
[ 'name' => 'nosemi.js', 'file' => 'script-nosemi.js' ],
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'files' => [
|
|
|
|
|
'init.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => $commentScript,
|
|
|
|
|
],
|
|
|
|
|
'nosemi.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => $nosemiScript
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'main' => 'init.js'
|
|
|
|
|
]
|
|
|
|
|
],
|
2019-06-12 00:57:17 +00:00
|
|
|
'package file with callback' => [
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
[ 'name' => 'foo.json', 'content' => [ 'Hello' => 'world' ] ],
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
'sample.json',
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
[ 'name' => 'bar.js', 'content' => "console.log('Hello');" ],
|
2019-10-18 18:27:30 +00:00
|
|
|
[
|
|
|
|
|
'name' => 'data.json',
|
2021-02-07 13:10:36 +00:00
|
|
|
'callback' => static function ( $context, $config, $extra ) {
|
2019-10-18 18:27:30 +00:00
|
|
|
return [ 'langCode' => $context->getLanguage(), 'extra' => $extra ];
|
|
|
|
|
},
|
|
|
|
|
'callbackParam' => [ 'a' => 'b' ],
|
|
|
|
|
],
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
[ 'name' => 'config.json', 'config' => [
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
'Sitename',
|
2020-02-25 01:33:18 +00:00
|
|
|
'server' => 'ServerName',
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
] ],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'files' => [
|
|
|
|
|
'foo.json' => [
|
|
|
|
|
'type' => 'data',
|
|
|
|
|
'content' => [ 'Hello' => 'world' ],
|
|
|
|
|
],
|
|
|
|
|
'sample.json' => [
|
|
|
|
|
'type' => 'data',
|
|
|
|
|
'content' => (object)[ 'foo' => 'bar', 'answer' => 42 ],
|
|
|
|
|
],
|
|
|
|
|
'bar.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => "console.log('Hello');",
|
|
|
|
|
],
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
'data.json' => [
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
'type' => 'data',
|
2019-10-18 18:27:30 +00:00
|
|
|
'content' => [ 'langCode' => 'fy', 'extra' => [ 'a' => 'b' ] ],
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
],
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
'config.json' => [
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
'type' => 'data',
|
|
|
|
|
'content' => [
|
|
|
|
|
'Sitename' => $config->get( 'Sitename' ),
|
2020-02-25 01:33:18 +00:00
|
|
|
'server' => $config->get( 'ServerName' ),
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'main' => 'bar.js'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'lang' => 'fy'
|
|
|
|
|
]
|
|
|
|
|
],
|
2019-06-12 00:57:17 +00:00
|
|
|
'package file with callback and versionCallback' => [
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
|
|
|
|
[ 'name' => 'bar.js', 'content' => "console.log('Hello');" ],
|
2019-10-18 18:27:30 +00:00
|
|
|
[
|
|
|
|
|
'name' => 'data.json',
|
2021-02-07 13:10:36 +00:00
|
|
|
'versionCallback' => static function ( $context ) {
|
2019-10-18 18:27:30 +00:00
|
|
|
return 'x';
|
|
|
|
|
},
|
2021-02-07 13:10:36 +00:00
|
|
|
'callback' => static function ( $context, $config, $extra ) {
|
2019-10-18 18:27:30 +00:00
|
|
|
return [ 'langCode' => $context->getLanguage(), 'extra' => $extra ];
|
|
|
|
|
},
|
|
|
|
|
'callbackParam' => [ 'A', 'B' ]
|
|
|
|
|
],
|
2019-06-12 00:57:17 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'files' => [
|
|
|
|
|
'bar.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => "console.log('Hello');",
|
|
|
|
|
],
|
|
|
|
|
'data.json' => [
|
|
|
|
|
'type' => 'data',
|
2019-10-18 18:27:30 +00:00
|
|
|
'content' => [ 'langCode' => 'fy', 'extra' => [ 'A', 'B' ] ],
|
2019-06-12 00:57:17 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'main' => 'bar.js'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'lang' => 'fy'
|
|
|
|
|
]
|
|
|
|
|
],
|
2019-12-11 22:08:31 +00:00
|
|
|
'package file with callback that returns a file (1)' => [
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
2021-02-07 13:10:36 +00:00
|
|
|
[ 'name' => 'dynamic.js', 'callback' => static function ( $context ) {
|
2019-12-11 22:08:31 +00:00
|
|
|
$file = $context->getLanguage() === 'fy' ? 'script-comment.js' : 'script-nosemi.js';
|
|
|
|
|
return new ResourceLoaderFilePath( $file );
|
|
|
|
|
} ]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'files' => [
|
|
|
|
|
'dynamic.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => $commentScript,
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'main' => 'dynamic.js'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'lang' => 'fy'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'package file with callback that returns a file (2)' => [
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
2021-02-07 13:10:36 +00:00
|
|
|
[ 'name' => 'dynamic.js', 'callback' => static function ( $context ) {
|
2019-12-11 22:08:31 +00:00
|
|
|
$file = $context->getLanguage() === 'fy' ? 'script-comment.js' : 'script-nosemi.js';
|
|
|
|
|
return new ResourceLoaderFilePath( $file );
|
|
|
|
|
} ]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'files' => [
|
|
|
|
|
'dynamic.js' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => $nosemiScript,
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'main' => 'dynamic.js'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'lang' => 'nl'
|
|
|
|
|
]
|
|
|
|
|
],
|
2020-02-04 01:42:03 +00:00
|
|
|
'.vue file in debug mode' => [
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
|
|
|
|
'vue-component.vue'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'files' => [
|
|
|
|
|
'vue-component.vue' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => $vueComponentDebug
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'main' => 'vue-component.vue',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'debug' => 'true'
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'.vue file in non-debug mode' => [
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
|
|
|
|
'vue-component.vue'
|
|
|
|
|
],
|
|
|
|
|
'name' => 'nondebug',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'files' => [
|
|
|
|
|
'vue-component.vue' => [
|
|
|
|
|
'type' => 'script',
|
|
|
|
|
'content' => $vueComponentNonDebug
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
'main' => 'vue-component.vue'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'debug' => 'false'
|
|
|
|
|
]
|
|
|
|
|
],
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
[
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
|
|
|
|
[ 'file' => 'script-comment.js' ]
|
|
|
|
|
]
|
|
|
|
|
],
|
2019-12-01 01:58:30 +00:00
|
|
|
LogicException::class
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
],
|
2019-06-12 00:57:17 +00:00
|
|
|
'package file with invalid callback' => [
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
[ 'name' => 'foo.json', 'callback' => 'functionThatDoesNotExist142857' ]
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
]
|
|
|
|
|
],
|
2019-12-01 01:58:30 +00:00
|
|
|
LogicException::class
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
],
|
|
|
|
|
[
|
2019-12-01 01:58:30 +00:00
|
|
|
// 'config' not valid for 'script' type
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
'foo.json' => [ 'type' => 'script', 'config' => [ 'Sitename' ] ]
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
]
|
|
|
|
|
],
|
2019-12-01 01:58:30 +00:00
|
|
|
LogicException::class
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
],
|
|
|
|
|
[
|
2019-12-01 01:58:30 +00:00
|
|
|
// 'config' not valid for '*.js' file
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
[ 'name' => 'foo.js', 'config' => 'Sitename' ]
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
]
|
|
|
|
|
],
|
2019-12-01 01:58:30 +00:00
|
|
|
LogicException::class
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
],
|
|
|
|
|
[
|
2019-12-01 01:58:30 +00:00
|
|
|
// missing type/name/file.
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
|
|
|
|
'foo.js' => [ 'garbage' => 'data' ]
|
|
|
|
|
]
|
|
|
|
|
],
|
2019-12-01 01:58:30 +00:00
|
|
|
LogicException::class
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
|
|
|
|
'filethatdoesnotexist142857.js'
|
|
|
|
|
]
|
|
|
|
|
],
|
2019-12-01 01:58:30 +00:00
|
|
|
RuntimeException::class
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
],
|
|
|
|
|
[
|
2019-12-01 01:58:30 +00:00
|
|
|
// JSON can't be a main file
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$base + [
|
|
|
|
|
'packageFiles' => [
|
|
|
|
|
'script-nosemi.js',
|
resourceloader: Change 'packageFiles' format to be JSON-compatible
The module definition format for 'packageFiles', as initially designed,
mixes sequential and associative arrays. This works in PHP, but not in
JSON. To make the format JSON compatible, use a 'name' key instead of
using the key in the main array.
Leave backwards compatibility in place so that extensions using the old
format can be migrated. This will be removed in the next commit.
Before:
'packageFiles' => [
'script.js',
'script2.js',
'config.json' => [ 'config' => [ 'Foo', 'Bar' ] ],
'data.json' => [ 'callback' => function () { ... } ],
],
After:
'packageFiles' => [
'script.js',
'script2.js',
[ 'name' => 'config.json', 'config' => [ 'Foo', 'Bar' ] ],
[ 'name' => 'data.json', 'callback' => function () { ... } ],
],
This can then be written in extension.json as:
"packageFiles": [
"script.js",
"script2.js",
[ "name": "config.json", "config": [ "Foo", "Bar" ] ],
[ "name": "data.json", "callback: [ "MyExtHooks", "getData" ] ]
]
Change-Id: Ic566a1cd7efd075c380bc50ba0cc2c329a2041d7
2019-02-22 01:26:23 +00:00
|
|
|
[ 'name' => 'foo.json', 'content' => [ 'Hello' => 'world' ], 'main' => true ]
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
]
|
|
|
|
|
],
|
2019-12-01 01:58:30 +00:00
|
|
|
LogicException::class
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-06-12 14:05:09 +00:00
|
|
|
* @dataProvider provideGetScriptPackageFiles
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
* @covers ResourceLoaderFileModule::getScript
|
|
|
|
|
* @covers ResourceLoaderFileModule::getPackageFiles
|
|
|
|
|
* @covers ResourceLoaderFileModule::expandPackageFiles
|
|
|
|
|
*/
|
|
|
|
|
public function testGetScriptPackageFiles( $moduleDefinition, $expected, $contextOptions = [] ) {
|
|
|
|
|
$module = new ResourceLoaderFileModule( $moduleDefinition );
|
|
|
|
|
$context = $this->getResourceLoaderContext( $contextOptions );
|
2021-06-11 15:11:37 +00:00
|
|
|
$module->setConfig( $context->getResourceLoader()->getConfig() );
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
if ( isset( $moduleDefinition['name'] ) ) {
|
|
|
|
|
$module->setName( $moduleDefinition['name'] );
|
|
|
|
|
}
|
2019-12-01 01:58:30 +00:00
|
|
|
if ( is_string( $expected ) ) {
|
|
|
|
|
// Class name of expected exception
|
|
|
|
|
$this->expectException( $expected );
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$module->getScript( $context );
|
|
|
|
|
} else {
|
2019-12-01 01:58:30 +00:00
|
|
|
// Array of expected return value
|
ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.
Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.
The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.
The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.
Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
XmlJsCode objects into one larger XmlJsCode object. This is needed for
encoding the packageFiles parameter in mw.loader.implement() calls.
Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2018-11-03 00:53:17 +00:00
|
|
|
$this->assertEquals( $expected, $module->getScript( $context ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-23 07:33:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderFileModule::requiresES6
|
|
|
|
|
*/
|
|
|
|
|
public function testRequiresES6() {
|
|
|
|
|
$module = new ResourceLoaderFileModule();
|
|
|
|
|
$this->assertFalse( $module->requiresES6(), 'requiresES6 defaults to false' );
|
|
|
|
|
$module = new ResourceLoaderFileModule( [ 'es6' => false ] );
|
|
|
|
|
$this->assertFalse( $module->requiresES6(), 'requiresES6 is false when set to false' );
|
|
|
|
|
$module = new ResourceLoaderFileModule( [ 'es6' => true ] );
|
|
|
|
|
$this->assertTrue( $module->requiresES6(), 'requiresES6 is true when set to true' );
|
|
|
|
|
}
|
2014-10-22 05:32:13 +00:00
|
|
|
}
|