Browse Source

Move bundles to /dist

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
John Molakvoæ (skjnldsv) 2 years ago
parent
commit
b664aad7ab

+ 3 - 1
apps/files/lib/Controller/ViewController.php

@@ -197,7 +197,9 @@ class ViewController extends Controller {
 		// Load the files we need
 		\OCP\Util::addStyle('files', 'merged');
 		\OCP\Util::addScript('files', 'merged-index');
-		\OCP\Util::addScript('files', 'dist/main');
+		\OCP\Util::addScript('files', 'templates');
+		\OCP\Util::addScript('files', 'files-app-settings');
+		\OCP\Util::addScript('files', 'legacy-filelist-search');
 
 		// mostly for the home storage's free space
 		// FIXME: Make non static

+ 1 - 1
apps/files/lib/Listener/LoadSidebarListener.php

@@ -37,7 +37,7 @@ class LoadSidebarListener implements IEventListener {
 			return;
 		}
 
-		Util::addScript(Application::APP_ID, 'dist/sidebar');
+		Util::addScript(Application::APP_ID, 'sidebar');
 		// needed by the Sidebar legacy tabs
 		// TODO: remove when all tabs migrated to the new api
 		Util::addScript('files', 'fileinfomodel');

+ 0 - 3
apps/files/src/main.js

@@ -1,3 +0,0 @@
-import './files-app-settings'
-import './templates'
-import './legacy/filelistSearch'

+ 1 - 1
apps/files/templates/settings-personal.php

@@ -22,7 +22,7 @@
  */
 
 
-script(\OCA\Files\AppInfo\Application::APP_ID, 'dist/personal-settings');
+script(\OCA\Files\AppInfo\Application::APP_ID, 'personal-settings');
 
 ?>
 <div id="files-personal-settings" class="section">

+ 2 - 2
apps/files_sharing/lib/AppInfo/Application.php

@@ -113,7 +113,7 @@ class Application extends App implements IBootstrap {
 		/**
 		 * Always add main sharing script
 		 */
-		Util::addScript(self::APP_ID, 'dist/main');
+		Util::addScript(self::APP_ID, 'main');
 	}
 
 
@@ -129,7 +129,7 @@ class Application extends App implements IBootstrap {
 		$dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class);
 		$dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class);
 		$dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () {
-			\OCP\Util::addScript('files_sharing', 'dist/collaboration');
+			\OCP\Util::addScript('files_sharing', 'collaboration');
 		});
 		$dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class);
 		$dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class);

+ 2 - 2
apps/files_sharing/lib/Listener/LoadAdditionalListener.php

@@ -38,9 +38,9 @@ class LoadAdditionalListener implements IEventListener {
 		}
 
 		// After files for the files list shared content
-		Util::addScript(Application::APP_ID, 'dist/files_sharing', 'files');
+		Util::addScript(Application::APP_ID, 'files_sharing', 'files');
 		// After files for the breadcrumb share indicator
-		Util::addScript(Application::APP_ID, 'dist/additionalScripts', 'files');
+		Util::addScript(Application::APP_ID, 'additionalScripts', 'files');
 		Util::addStyle(Application::APP_ID, 'icons');
 	}
 }

+ 1 - 1
apps/files_sharing/lib/Listener/LoadSidebarListener.php

@@ -37,6 +37,6 @@ class LoadSidebarListener implements IEventListener {
 			return;
 		}
 
-		Util::addScript(Application::APP_ID, 'dist/files_sharing_tab', 'files');
+		Util::addScript(Application::APP_ID, 'files_sharing_tab', 'files');
 	}
 }

+ 1 - 1
apps/files_sharing/templates/Settings/personal.php

@@ -22,7 +22,7 @@ declare(strict_types=1);
  *
  */
 
-script(\OCA\Files_Sharing\AppInfo\Application::APP_ID, 'dist/personal-settings');
+script(\OCA\Files_Sharing\AppInfo\Application::APP_ID, 'personal-settings');
 
 ?>
 <div id="files-sharing-personal-settings" class="section">

+ 1 - 1
apps/systemtags/lib/AppInfo/Application.php

@@ -52,7 +52,7 @@ class Application extends App implements IBootstrap {
 			$dispatcher->addListener(
 				'OCA\Files::loadAdditionalScripts',
 				function () {
-					\OCP\Util::addScript('core', 'dist/systemtags');
+					\OCP\Util::addScript('core', 'systemtags');
 					\OCP\Util::addScript(self::APP_ID, 'systemtags');
 				}
 			);

+ 1 - 1
apps/systemtags/templates/admin.php

@@ -19,7 +19,7 @@
  *
  */
 
-script('core', 'dist/systemtags');
+script('core', 'systemtags');
 
 script('systemtags', 'admin');
 style('systemtags', 'settings');

+ 1 - 1
apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php

@@ -99,7 +99,7 @@ class BeforeTemplateRenderedListener implements IEventListener {
 			return ['profileEnabled' => $this->isProfileEnabled($account)];
 		});
 
-		\OCP\Util::addScript('user_status', 'user-status-menu');
+		\OCP\Util::addScript('user_status', 'user_status-menu');
 		\OCP\Util::addStyle('user_status', 'user-status-menu');
 	}
 }

+ 1 - 1
apps/workflowengine/lib/Listener/LoadAdditionalSettingsScriptsListener.php

@@ -41,7 +41,7 @@ class LoadAdditionalSettingsScriptsListener implements IEventListener {
 			class_exists(Template::class, true);
 		}
 
-		script('core', 'dist/systemtags');
+		script('core', 'systemtags');
 
 		script(Application::APP_ID, [
 			'workflowengine',

+ 1 - 1
core/Controller/ProfilePageController.php

@@ -143,7 +143,7 @@ class ProfilePageController extends Controller {
 			$this->profileManager->getProfileParams($targetUser, $visitingUser),
 		);
 
-		\OCP\Util::addScript('core', 'dist/profile');
+		\OCP\Util::addScript('core', 'profile');
 
 		return new TemplateResponse(
 			'core',

+ 1 - 1
core/templates/installation.php

@@ -1,5 +1,5 @@
 <?php
-script('core', 'dist/install');
+script('core', 'install');
 ?>
 <input type='hidden' id='hasMySQL' value='<?php p($_['hasMySQL']) ?>'>
 <input type='hidden' id='hasSQLite' value='<?php p($_['hasSQLite']) ?>'>

+ 1 - 1
core/templates/login.php

@@ -1,6 +1,6 @@
 <?php /** @var \OCP\IL10N $l */ ?>
 <?php
-script('core', 'dist/login');
+script('core', 'login');
 ?>
 
 <div id="login"></div>

+ 1 - 1
core/templates/recommendedapps.php

@@ -21,7 +21,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-script('core', 'dist/recommendedapps');
+script('core', 'recommendedapps');
 
 ?>
 

+ 1 - 1
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();

+ 11 - 8
lib/private/Template/JSResourceLocator.php

@@ -48,11 +48,14 @@ 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.
 			$found = 0;
-			$found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js');
 			$found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js');
 			$found += $this->appendIfExist($this->serverroot, $script.'.js');
 			$found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js');
@@ -65,16 +68,16 @@ 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->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);
 
@@ -86,21 +89,21 @@ class JSResourceLocator extends ResourceLocator {
 		}
 
 		// missing translations files fill be ignored
-		if (strpos($script, 'l10n/') === 0) {
-			$this->appendIfExist($app_path, $script . '.js', $app_url);
+		if (strpos($scriptName, 'l10n/') === 0) {
+			$this->appendIfExist($app_path, $scriptName . '.js', $app_url);
 			return;
 		}
 
 		if ($app_path === false && $app_url === false) {
 			$this->logger->error('Could not find resource {resource} to load', [
-				'resource' => $app . '/' . $script . '.js',
+				'resource' => $app . '/' . $scriptName . '.js',
 				'app' => 'jsresourceloader',
 			]);
 			return;
 		}
 
-		if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
-			$this->append($app_path, $script . '.js', $app_url);
+		if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $scriptName.'.json', $app)) {
+			$this->append($app_path, $scriptName . '.js', $app_url);
 		}
 	}
 

+ 2 - 2
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,7 +209,7 @@ class TemplateLayout extends \OC_Template {
 		}
 
 		// Add the js files
-		$jsFiles = self::findJavascriptFiles(array_merge(\OC_Util::$scripts, Util::getScripts()));
+		$jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
 		$this->assign('jsfiles', []);
 		if ($this->config->getSystemValue('installed', false) && $renderAs != TemplateResponse::RENDER_AS_ERROR) {
 			// this is on purpose outside of the if statement below so that the initial state is prefilled (done in the getConfig() call)

+ 5 - 5
lib/private/legacy/OC_Template.php

@@ -106,7 +106,7 @@ class OC_Template extends \OC\Template\Base {
 			//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);
+					OC_Util::addScript('core', 'backgroundjobs', true);
 				}
 			}
 			OC_Util::addStyle('css-variables', null, true);
@@ -114,11 +114,11 @@ class OC_Template extends \OC\Template\Base {
 			OC_Util::addTranslations('core', null, true);
 
 			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);
+				OC_Util::addScript('core', 'merged-template-prepend', true);
+				OC_Util::addScript('core', 'files_client', true);
+				OC_Util::addScript('core', 'files_fileinfo', true);
 			}
-			OC_Util::addScript('core', 'dist/main', true);
+			OC_Util::addScript('core', 'main', true);
 
 			self::$initTemplateEngineFirstRun = false;
 		}

+ 25 - 20
webpack.common.js

@@ -7,40 +7,45 @@ const ESLintPlugin = require('eslint-webpack-plugin')
 
 const modules = require('./webpack.modules.js')
 
+const formatOutputFromModules = (modules) => {
+	// merge all configs into one object, and use AppID to generate the fileNames
+	// with the following format:
+	// AppId-fileName: path/to/js-file.js
+	const moduleEntries = Object.keys(modules).map(moduleKey => {
+		const module = modules[moduleKey]
+
+		const entries = Object.keys(module).map(entryKey => {
+			const entry = module[entryKey]
+			return { [`${moduleKey}-${entryKey}`]: entry }
+		})
+
+		return Object.assign({}, ...Object.values(entries))
+	})
+	return Object.assign({}, ...Object.values(moduleEntries))
+}
+
 const modulesToBuild = () => {
 	const MODULE = process.env.MODULE
 	if (MODULE) {
 		if (!modules[MODULE]) {
 			throw new Error(`No module "${MODULE}" found`)
 		}
-		return modules[MODULE]
+		return formatOutputFromModules({
+			[MODULE]: modules[MODULE]
+		})
 	}
-	// merge all configs into one object
-	return Object.assign({}, ...Object.values(modules))
+
+	return formatOutputFromModules(modules)
 }
 
 module.exports = {
 	entry: modulesToBuild(),
 	output: {
 		// Step away from the src folder and extract to the js folder
-		path: path.join(__dirname),
+		path: path.join(__dirname, 'dist'),
 		publicPath: '/dist/',
-		filename: (chunkData) => {
-			// Get relative path of the src folder
-			let srcPath = chunkData.chunk.entryModule.context
-			if (srcPath === null) {
-				srcPath = chunkData.chunk.entryModule.rootModule.context
-			}
-			const relativePath = path.relative(__dirname, srcPath)
-
-			// If this is a core source, output in core dist folder
-			if (relativePath.indexOf('core/src') > -1) {
-				return path.join('core/js/dist/', '[name].js?v=[contenthash]')
-			}
-			// Get out of the shared dist folder and output inside apps js folder
-			return path.join(relativePath, '..', 'js') + '/[name].js?v=[contenthash]'
-		},
-		chunkFilename: 'dist/[name]-[id].js?v=[contenthash]',
+		filename: '[name].js?v=[contenthash]',
+		chunkFilename: '[name]-[id].js?v=[contenthash]',
 	},
 
 	module: {

+ 1 - 0
webpack.modules.js

@@ -52,6 +52,7 @@ module.exports = {
 		sidebar: path.join(__dirname, 'apps/files/src', 'sidebar.js'),
 		templates: path.join(__dirname, 'apps/files/src', 'templates.js'),
 		'files-app-settings': path.join(__dirname, 'apps/files/src', 'files-app-settings.js'),
+		'legacy-filelist-search': path.join(__dirname, 'apps/files/src', 'legacy/filelistSearch.js'),
 		'personal-settings': path.join(__dirname, 'apps/files/src', 'main-personal-settings.js'),
 	},
 	files_sharing: {