mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
JavaScript::optimizeDefine: Take multiple define()
calls in same file into account
This commit is contained in:
parent
c4b6e4bdda
commit
9be6574356
@ -213,10 +213,11 @@ class JavaScript
|
||||
*/
|
||||
public static function optimizeDefine($js, $filePath, $basePath, $packageName)
|
||||
{
|
||||
if (! preg_match(self::DEFINE_RE, $js, $match) || strpos($js, 'define.amd') !== false) {
|
||||
if (! preg_match_all(self::DEFINE_RE, $js, $matches, PREG_SET_ORDER) || strpos($js, 'define.amd') !== false) {
|
||||
return $js;
|
||||
}
|
||||
|
||||
foreach ($matches as $match) {
|
||||
try {
|
||||
$assetName = $match[1] ? Json::decode($match[1]) : '';
|
||||
if (! $assetName) {
|
||||
@ -232,7 +233,10 @@ class JavaScript
|
||||
$assetName = Json::encode($assetName, JSON_UNESCAPED_SLASHES);
|
||||
} catch (JsonDecodeException $_) {
|
||||
$assetName = $match[1];
|
||||
Logger::debug('Can\'t optimize name of "%s". Are single quotes used instead of double quotes?', $filePath);
|
||||
Logger::debug(
|
||||
'Can\'t optimize name of "%s". Are single quotes used instead of double quotes?',
|
||||
$filePath
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -246,10 +250,13 @@ class JavaScript
|
||||
if (preg_match('~^((?:\.\.?/)+)*(.*)~', $dependencyName, $natch)) {
|
||||
$dependencyName = join(DIRECTORY_SEPARATOR, array_filter([
|
||||
$packageName,
|
||||
ltrim(substr(
|
||||
ltrim(
|
||||
substr(
|
||||
realpath(join(DIRECTORY_SEPARATOR, [dirname($filePath), $natch[1]])),
|
||||
strlen(realpath($basePath))
|
||||
), DIRECTORY_SEPARATOR),
|
||||
),
|
||||
DIRECTORY_SEPARATOR
|
||||
),
|
||||
$natch[2]
|
||||
]));
|
||||
}
|
||||
@ -264,6 +271,9 @@ class JavaScript
|
||||
);
|
||||
}
|
||||
|
||||
return str_replace($match[0], sprintf("define(%s, %s, %s", $assetName, $dependencies, $match[3]), $js);
|
||||
$js = str_replace($match[0], sprintf("define(%s, %s, %s", $assetName, $dependencies, $match[3]), $js);
|
||||
}
|
||||
|
||||
return $js;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user