mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 23:34:08 +02:00
Javascript: Enhance optimization
* Don't try to optimize non-icinga define calls * Don't optimize `exports` dependency * Log errors to debug log, it's stuff for devs
This commit is contained in:
parent
8c22514758
commit
a00166f15b
@ -226,7 +226,7 @@ class JavaScript
|
|||||||
*/
|
*/
|
||||||
public static function optimizeDefine($js, $filePath, $basePath, $packageName)
|
public static function optimizeDefine($js, $filePath, $basePath, $packageName)
|
||||||
{
|
{
|
||||||
if (! preg_match(self::DEFINE_RE, $js, $match)) {
|
if (! preg_match(self::DEFINE_RE, $js, $match) || strpos($js, 'define.amd') !== false) {
|
||||||
return $js;
|
return $js;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,12 +245,17 @@ class JavaScript
|
|||||||
$assetName = Json::encode($assetName, JSON_UNESCAPED_SLASHES);
|
$assetName = Json::encode($assetName, JSON_UNESCAPED_SLASHES);
|
||||||
} catch (JsonDecodeException $_) {
|
} catch (JsonDecodeException $_) {
|
||||||
$assetName = $match[1];
|
$assetName = $match[1];
|
||||||
Logger::error('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 {
|
try {
|
||||||
$dependencies = $match[2] ? Json::decode($match[2]) : [];
|
$dependencies = $match[2] ? Json::decode($match[2]) : [];
|
||||||
foreach ($dependencies as &$dependencyName) {
|
foreach ($dependencies as &$dependencyName) {
|
||||||
|
if ($dependencyName === 'exports') {
|
||||||
|
// exports is a special keyword and doesn't need optimization
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (preg_match('~^((?:\.\.?/)+)*(.*)~', $dependencyName, $natch)) {
|
if (preg_match('~^((?:\.\.?/)+)*(.*)~', $dependencyName, $natch)) {
|
||||||
$dependencyName = join(DIRECTORY_SEPARATOR, array_filter([
|
$dependencyName = join(DIRECTORY_SEPARATOR, array_filter([
|
||||||
$packageName,
|
$packageName,
|
||||||
@ -266,7 +271,7 @@ class JavaScript
|
|||||||
$dependencies = Json::encode($dependencies, JSON_UNESCAPED_SLASHES);
|
$dependencies = Json::encode($dependencies, JSON_UNESCAPED_SLASHES);
|
||||||
} catch (JsonDecodeException $_) {
|
} catch (JsonDecodeException $_) {
|
||||||
$dependencies = $match[2];
|
$dependencies = $match[2];
|
||||||
Logger::error(
|
Logger::debug(
|
||||||
'Can\'t optimize dependencies of "%s". Are single quotes used instead of double quotes?',
|
'Can\'t optimize dependencies of "%s". Are single quotes used instead of double quotes?',
|
||||||
$filePath
|
$filePath
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user