ResourceLoader: Set 'virtualFilePath' for startup.js

Source maps are now enabled on www.mediawiki.org, and one of the
things that stands out is the (one) virtual file on every page view
for startup.js.

Bug: T47514
Change-Id: I7017de5757b22263f1076cfdcef0b5c9536dcc6a
This commit is contained in:
Timo Tijhof 2023-09-14 14:48:33 -07:00 committed by Krinkle
parent 85b68372c5
commit 93a27630c2

View file

@ -358,9 +358,9 @@ class StartUpModule extends Module {
/**
* @param Context $context
* @return string JavaScript code
* @return string|array JavaScript code
*/
public function getScript( Context $context ): string {
public function getScript( Context $context ) {
global $IP;
$conf = $this->getConfig();
@ -368,6 +368,8 @@ class StartUpModule extends Module {
return '/* Requires only=scripts */';
}
$enableJsProfiler = $conf->get( MainConfigNames::ResourceLoaderEnableJSProfiler );
$startupCode = file_get_contents( "$IP/resources/src/startup/startup.js" );
// The files read here MUST be kept in sync with maintenance/jsduck/eg-iframe.html.
@ -405,23 +407,27 @@ class StartUpModule extends Module {
'$VARS.sourceMapLinks' => $context->encodeJson(
$conf->get( MainConfigNames::ResourceLoaderEnableSourceMapLinks )
),
// When profiling is enabled, insert the calls.
// When disabled (the default), insert nothing.
'$CODE.profileExecuteStart();' => $enableJsProfiler
? 'mw.loader.profiler.onExecuteStart( module );'
: '',
'$CODE.profileExecuteEnd();' => $enableJsProfiler
? 'mw.loader.profiler.onExecuteEnd( module );'
: '',
'$CODE.profileScriptStart();' => $enableJsProfiler
? 'mw.loader.profiler.onScriptStart( module );'
: '',
'$CODE.profileScriptEnd();' => $enableJsProfiler
? 'mw.loader.profiler.onScriptEnd( module );'
: '',
// Debug stubs
'$CODE.consoleLog();' => $context->getDebug()
? 'console.log.apply( console, arguments );'
: '',
];
$profilerStubs = [
'$CODE.profileExecuteStart();' => 'mw.loader.profiler.onExecuteStart( module );',
'$CODE.profileExecuteEnd();' => 'mw.loader.profiler.onExecuteEnd( module );',
'$CODE.profileScriptStart();' => 'mw.loader.profiler.onScriptStart( module );',
'$CODE.profileScriptEnd();' => 'mw.loader.profiler.onScriptEnd( module );',
];
$debugStubs = [
'$CODE.consoleLog();' => 'console.log.apply( console, arguments );',
];
// When profiling is enabled, insert the calls. When disabled (by default), insert nothing.
$mwLoaderPairs += $conf->get( MainConfigNames::ResourceLoaderEnableJSProfiler )
? $profilerStubs
: array_fill_keys( array_keys( $profilerStubs ), '' );
$mwLoaderPairs += $context->getDebug()
? $debugStubs
: array_fill_keys( array_keys( $debugStubs ), '' );
$mwLoaderCode = strtr( $mwLoaderCode, $mwLoaderPairs );
// Perform string replacements for startup.js
@ -432,7 +438,18 @@ class StartUpModule extends Module {
];
$startupCode = strtr( $startupCode, $pairs );
return $startupCode;
return [
'plainScripts' => [
[
'virtualFilePath' => new FilePath(
'resources/src/startup/startup.js',
MW_INSTALL_PATH,
$conf->get( MainConfigNames::ResourceBasePath )
),
'content' => $startupCode,
],
],
];
}
/**