summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-01-10 09:41:18 +0100
committerGitHub <noreply@github.com>2022-01-10 09:41:18 +0100
commit91c7efaeb6c3a65643f1f0a9377d7c42b9231f8a (patch)
tree8dc915870df52089dc873c347a31699729bd2c57 /lib
parentf71475de34e63ec03b26323ac2d98de800777f52 (diff)
parent79f14e8299d5329fa310650f2036f280a2fba4fe (diff)
downloadnextcloud-server-91c7efaeb6c3a65643f1f0a9377d7c42b9231f8a.tar.gz
nextcloud-server-91c7efaeb6c3a65643f1f0a9377d7c42b9231f8a.zip
Merge pull request #30020 from nextcloud/feat/webpack-vendors-bundles
Feat/webpack vendors bundles
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php2
-rw-r--r--lib/private/Template/JSResourceLocator.php8
-rw-r--r--lib/private/TemplateLayout.php3
-rw-r--r--lib/private/legacy/OC_Template.php34
-rw-r--r--lib/private/legacy/template/functions.php14
-rw-r--r--lib/public/Util.php10
6 files changed, 52 insertions, 19 deletions
diff --git a/lib/base.php b/lib/base.php
index 75459fc6b42..91544c949c2 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -292,7 +292,7 @@ class OC {
// render error page
$template = new OC_Template('', 'update.user', 'guest');
- OC_Util::addScript('dist/maintenance');
+ OC_Util::addScript('maintenance');
OC_Util::addStyle('core', 'guest');
$template->printPage();
die();
diff --git a/lib/private/Template/JSResourceLocator.php b/lib/private/Template/JSResourceLocator.php
index 3f6b2b49e10..1421e28033a 100644
--- a/lib/private/Template/JSResourceLocator.php
+++ b/lib/private/Template/JSResourceLocator.php
@@ -48,6 +48,10 @@ class JSResourceLocator extends ResourceLocator {
return;
}
+ // Extracting the appId and the script file name
+ $app = substr($script, 0, strpos($script, '/'));
+ $scriptName = basename($script);
+
if (strpos($script, '/l10n/') !== false) {
// For language files we try to load them all, so themes can overwrite
// single l10n strings without having to translate all of them.
@@ -65,15 +69,17 @@ class JSResourceLocator extends ResourceLocator {
} elseif ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js')
|| $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js')
|| $this->appendIfExist($this->serverroot, $script.'.js')
+ || $this->appendIfExist($this->serverroot, "dist/$app-$scriptName.js")
+ || $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js')
|| $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json')
|| $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js')
|| $this->appendIfExist($this->serverroot, 'core/'.$script.'.js')
+ || $this->appendIfExist($this->serverroot, "dist/core-$scriptName.js")
|| $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json')
) {
return;
}
- $app = substr($script, 0, strpos($script, '/'));
$script = substr($script, strpos($script, '/') + 1);
$app_path = \OC_App::getAppPath($app);
$app_url = \OC_App::getAppWebPath($app);
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 317862ff386..9cfc1aec6dd 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -96,7 +96,7 @@ class TemplateLayout extends \OC_Template {
$this->initialState->provideInitialState('core', 'active-app', $this->navigationManager->getActiveEntry());
$this->initialState->provideInitialState('unified-search', 'limit-default', SearchQuery::LIMIT_DEFAULT);
- Util::addScript('core', 'dist/unified-search', 'core');
+ Util::addScript('core', 'unified-search', 'core');
// Add navigation entry
$this->assign('application', '');
@@ -209,6 +209,7 @@ class TemplateLayout extends \OC_Template {
}
// Add the js files
+ // TODO: remove deprecated OC_Util injection
$jsFiles = self::findJavascriptFiles(array_merge(\OC_Util::$scripts, Util::getScripts()));
$this->assign('jsfiles', []);
if ($this->config->getSystemValue('installed', false) && $renderAs != TemplateResponse::RENDER_AS_ERROR) {
diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php
index 9dfdb87e5ee..16ad7273cd2 100644
--- a/lib/private/legacy/OC_Template.php
+++ b/lib/private/legacy/OC_Template.php
@@ -39,6 +39,7 @@
*/
use OC\TemplateLayout;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\Util;
require_once __DIR__.'/template/functions.php';
@@ -101,24 +102,31 @@ class OC_Template extends \OC\Template\Base {
public static function initTemplateEngine($renderAs) {
if (self::$initTemplateEngineFirstRun) {
- //apps that started before the template initialization can load their own scripts/styles
- //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
- //meaning the last script/style in this list will be loaded first
- if (\OC::$server->getSystemConfig()->getValue('installed', false) && $renderAs !== TemplateResponse::RENDER_AS_ERROR && !\OCP\Util::needUpgrade()) {
- if (\OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
- OC_Util::addScript('backgroundjobs', null, true);
- }
- }
+ // apps that started before the template initialization can load their own scripts/styles
+ // so to make sure this scripts/styles here are loaded first we put all core scripts first
+ // check lib/public/Util.php
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()) {
- OC_Util::addScript('merged-template-prepend', null, true);
- OC_Util::addScript('dist/files_client', null, true);
- OC_Util::addScript('dist/files_fileinfo', null, true);
+ Util::addScript('core', 'files_fileinfo');
+ Util::addScript('core', 'files_client');
+ Util::addScript('core', 'merged-template-prepend');
+ }
+
+ // If installed and background job is set to ajax, add dedicated script
+ if (\OC::$server->getSystemConfig()->getValue('installed', false)
+ && $renderAs !== TemplateResponse::RENDER_AS_ERROR
+ && !\OCP\Util::needUpgrade()) {
+ if (\OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
+ Util::addScript('core', 'backgroundjobs');
+ }
}
- OC_Util::addScript('core', 'dist/main', true);
self::$initTemplateEngineFirstRun = false;
}
diff --git a/lib/private/legacy/template/functions.php b/lib/private/legacy/template/functions.php
index 6b18c9476b4..e28cf02f7a3 100644
--- a/lib/private/legacy/template/functions.php
+++ b/lib/private/legacy/template/functions.php
@@ -1,4 +1,7 @@
<?php
+
+use OCP\Util;
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -111,17 +114,22 @@ 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
+ * @deprecated 23.1.0
*/
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');
}
}
diff --git a/lib/public/Util.php b/lib/public/Util.php
index f8d8b1aaf71..61b8d9369cc 100644
--- a/lib/public/Util.php
+++ b/lib/public/Util.php
@@ -597,4 +597,14 @@ class Util {
}
return $temp;
}
+
+ /**
+ * Reset scripts and scriptDeps to empty arrays.
+ * Only used in tests.
+ * @since 24.0.0
+ */
+ public static function clearScriptsState() {
+ self::$scripts = [];
+ self::$scriptDeps = [];
+ }
}