Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! Split common vendor chunk
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Dec 3, 2021
1 parent 60dc882 commit a290149
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/private/legacy/OC_Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public static function initTemplateEngine($renderAs) {
}
OC_Util::addStyle('css-variables', null, true);
OC_Util::addStyle('server', null, true);
OC_Util::addTranslations('core', null, true);

// include common nextcloud webpack bundle
Util::addScript('core', 'common');
Util::addScript('core', 'main');
Util::addTranslations('core');

if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) {
Util::addScript('core', 'files_fileinfo');
Expand Down
13 changes: 10 additions & 3 deletions lib/private/legacy/template/functions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use OCP\Util;

/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
Expand Down Expand Up @@ -111,17 +114,21 @@ function print_unescaped($string) {

/**
* Shortcut for adding scripts to a page
* All scripts are forced to be loaded after core since
* they are coming from a template registration.
* Please consider moving them into the relevant controller
*
* @param string $app the appname
* @param string|string[] $file the filename,
* if an array is given it will add all scripts
*/
function script($app, $file = null) {
if (is_array($file)) {
foreach ($file as $f) {
OC_Util::addScript($app, $f);
foreach ($file as $script) {
Util::addScript($app, $script, 'core');
}
} else {
OC_Util::addScript($app, $file);
Util::addScript($app, $file, 'core');
}
}

Expand Down
11 changes: 8 additions & 3 deletions lib/public/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,12 @@ public static function addScript($application, $file = null, $afterAppId = null)
public static function getScripts(): array {
// merging first and last data set
$mapFunc = function (array $scriptsArray): array {
return array_merge(...array_values($scriptsArray));
return array_merge($scriptsArray['first'] ?? [], $scriptsArray['last'] ?? []);
};
$appScripts = array_map($mapFunc, self::$scripts);

// sort core first
$scripts = array_merge(isset($appScripts['core']) ? $appScripts['core'] : [], ...array_values($appScripts));
$scripts = array_merge($appScripts['core'] ?? [], ...array_values($appScripts));
// remove duplicates
return array_unique($scripts);
}
Expand All @@ -259,10 +260,14 @@ public static function addTranslations($application, $languageCode = null) {
}
if (!empty($application)) {
$path = "$application/l10n/$languageCode";
// init script entry if empty
if (!array_key_exists($application, self::$scripts)) {
self::$scripts[$application] = ['first' => [], 'last' => []];
}
} else {
$path = "l10n/$languageCode";
}
self::$scripts[$application]['first'][] = $path;
self::$scripts[$application]['last'][] = $path;
}

/**
Expand Down

0 comments on commit a290149

Please sign in to comment.