From dea0b4712b6dbdabe58cc3792294c8a288fa1f45 Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Mon, 7 Oct 2019 15:47:51 +0300 Subject: [PATCH 1/7] Static Content Deploy - Add command line argument to disable JS Bundles There were no way to disable JS bundles even if you don't use them. Disabling generation of JS bundles improves speed of Static Content Deploy and makes build package smaller. --- .../Magento/Deploy/Console/DeployStaticOptions.php | 11 +++++++++++ .../Magento/Deploy/Service/DeployStaticContent.php | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Deploy/Console/DeployStaticOptions.php b/app/code/Magento/Deploy/Console/DeployStaticOptions.php index 1c02d24f7e99c..1e9f6a1b91f71 100644 --- a/app/code/Magento/Deploy/Console/DeployStaticOptions.php +++ b/app/code/Magento/Deploy/Console/DeployStaticOptions.php @@ -78,6 +78,11 @@ class DeployStaticOptions */ const NO_JAVASCRIPT = 'no-javascript'; + /** + * Key for js-bundle option + */ + const NO_JS_BUNLDE = 'no-js-bundle'; + /** * Key for css option */ @@ -275,6 +280,12 @@ private function getSkipOptions() InputOption::VALUE_NONE, 'Do not deploy JavaScript files.' ), + new InputOption( + self::NO_JS_BUNLDE, + null, + InputOption::VALUE_NONE, + 'Do not deploy JavaScript bundle files.' + ), new InputOption( self::NO_CSS, null, diff --git a/app/code/Magento/Deploy/Service/DeployStaticContent.php b/app/code/Magento/Deploy/Service/DeployStaticContent.php index 8903997159914..6e65807bbc2a1 100644 --- a/app/code/Magento/Deploy/Service/DeployStaticContent.php +++ b/app/code/Magento/Deploy/Service/DeployStaticContent.php @@ -120,13 +120,20 @@ public function deploy(array $options) $deployI18n = $this->objectManager->create(DeployTranslationsDictionary::class, [ 'logger' => $this->logger ]); + foreach ($packages as $package) { + if (!$package->isVirtual()) { + $deployRjsConfig->deploy($package->getArea(), $package->getTheme(), $package->getLocale()); + $deployI18n->deploy($package->getArea(), $package->getTheme(), $package->getLocale()); + } + } + } + + if ($options[Options::NO_JAVASCRIPT] !== true && $options[Options::NO_JS_BUNLDE] !== true ) { $deployBundle = $this->objectManager->create(Bundle::class, [ 'logger' => $this->logger ]); foreach ($packages as $package) { if (!$package->isVirtual()) { - $deployRjsConfig->deploy($package->getArea(), $package->getTheme(), $package->getLocale()); - $deployI18n->deploy($package->getArea(), $package->getTheme(), $package->getLocale()); $deployBundle->deploy($package->getArea(), $package->getTheme(), $package->getLocale()); } } From b0296e8ffe3c6a8a22da38fcfff8d6b62cf2f1c0 Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Mon, 7 Oct 2019 20:36:42 +0300 Subject: [PATCH 2/7] Fix code style --- app/code/Magento/Deploy/Service/DeployStaticContent.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Deploy/Service/DeployStaticContent.php b/app/code/Magento/Deploy/Service/DeployStaticContent.php index 6e65807bbc2a1..590b58a06b5c5 100644 --- a/app/code/Magento/Deploy/Service/DeployStaticContent.php +++ b/app/code/Magento/Deploy/Service/DeployStaticContent.php @@ -5,9 +5,9 @@ */ namespace Magento\Deploy\Service; -use Magento\Deploy\Strategy\DeployStrategyFactory; -use Magento\Deploy\Process\QueueFactory; use Magento\Deploy\Console\DeployStaticOptions as Options; +use Magento\Deploy\Process\QueueFactory; +use Magento\Deploy\Strategy\DeployStrategyFactory; use Magento\Framework\App\View\Deployment\Version\StorageInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\ObjectManagerInterface; @@ -128,7 +128,7 @@ public function deploy(array $options) } } - if ($options[Options::NO_JAVASCRIPT] !== true && $options[Options::NO_JS_BUNLDE] !== true ) { + if ($options[Options::NO_JAVASCRIPT] !== true && $options[Options::NO_JS_BUNLDE] !== true) { $deployBundle = $this->objectManager->create(Bundle::class, [ 'logger' => $this->logger ]); From ad13021d733cdd9ada5159d09877efbaf2bc6b28 Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Mon, 7 Oct 2019 20:49:17 +0300 Subject: [PATCH 3/7] Fix unit tests --- .../Deploy/Test/Unit/Service/DeployStaticContentTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php index 396381960e544..5e956a6f32894 100644 --- a/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php +++ b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php @@ -103,7 +103,7 @@ public function testDeploy($options, $expectedContentVersion) $package->expects($this->never())->method('getTheme'); $package->expects($this->never())->method('getLocale'); } else { - $package->expects($this->exactly(1))->method('isVirtual')->willReturn(false); + $package->expects($this->exactly(2))->method('isVirtual')->willReturn(false); $package->expects($this->exactly(3))->method('getArea')->willReturn('area'); $package->expects($this->exactly(3))->method('getTheme')->willReturn('theme'); $package->expects($this->exactly(3))->method('getLocale')->willReturn('locale'); @@ -198,6 +198,7 @@ public function deployDataProvider() [ 'strategy' => 'compact', 'no-javascript' => false, + 'no-js-bundle' => false, 'no-html-minify' => false, 'refresh-content-version-only' => false, ], @@ -207,6 +208,7 @@ public function deployDataProvider() [ 'strategy' => 'compact', 'no-javascript' => false, + 'no-js-bundle' => false, 'no-html-minify' => false, 'refresh-content-version-only' => false, 'content-version' => '123456', @@ -231,6 +233,7 @@ public function testMaxExecutionTimeOptionPassed() DeployStaticOptions::JOBS_AMOUNT => 3, DeployStaticOptions::STRATEGY => 'compact', DeployStaticOptions::NO_JAVASCRIPT => true, + DeployStaticOptions::NO_JS_BUNLDE => true, DeployStaticOptions::NO_HTML_MINIFY => true, ]; From c4d4768a27d788ac262da1b5bc51ff423f09e76c Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Mon, 7 Oct 2019 20:52:33 +0300 Subject: [PATCH 4/7] Fix typo in constant name --- .../Magento/Deploy/Console/DeployStaticOptions.php | 4 ++-- .../Magento/Deploy/Service/DeployStaticContent.php | 2 +- .../Test/Unit/Service/DeployStaticContentTest.php | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Deploy/Console/DeployStaticOptions.php b/app/code/Magento/Deploy/Console/DeployStaticOptions.php index 1e9f6a1b91f71..5326ba79b959a 100644 --- a/app/code/Magento/Deploy/Console/DeployStaticOptions.php +++ b/app/code/Magento/Deploy/Console/DeployStaticOptions.php @@ -81,7 +81,7 @@ class DeployStaticOptions /** * Key for js-bundle option */ - const NO_JS_BUNLDE = 'no-js-bundle'; + const NO_JS_BUNDLE = 'no-js-bundle'; /** * Key for css option @@ -281,7 +281,7 @@ private function getSkipOptions() 'Do not deploy JavaScript files.' ), new InputOption( - self::NO_JS_BUNLDE, + self::NO_JS_BUNDLE, null, InputOption::VALUE_NONE, 'Do not deploy JavaScript bundle files.' diff --git a/app/code/Magento/Deploy/Service/DeployStaticContent.php b/app/code/Magento/Deploy/Service/DeployStaticContent.php index 590b58a06b5c5..ba367b5283aa3 100644 --- a/app/code/Magento/Deploy/Service/DeployStaticContent.php +++ b/app/code/Magento/Deploy/Service/DeployStaticContent.php @@ -128,7 +128,7 @@ public function deploy(array $options) } } - if ($options[Options::NO_JAVASCRIPT] !== true && $options[Options::NO_JS_BUNLDE] !== true) { + if ($options[Options::NO_JAVASCRIPT] !== true && $options[Options::NO_JS_BUNDLE] !== true) { $deployBundle = $this->objectManager->create(Bundle::class, [ 'logger' => $this->logger ]); diff --git a/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php index 5e956a6f32894..4c6d0e4dd5f53 100644 --- a/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php +++ b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php @@ -228,13 +228,13 @@ public function deployDataProvider() public function testMaxExecutionTimeOptionPassed() { $options = [ - DeployStaticOptions::MAX_EXECUTION_TIME => 100, + DeployStaticOptions::MAX_EXECUTION_TIME => 100, DeployStaticOptions::REFRESH_CONTENT_VERSION_ONLY => false, - DeployStaticOptions::JOBS_AMOUNT => 3, - DeployStaticOptions::STRATEGY => 'compact', - DeployStaticOptions::NO_JAVASCRIPT => true, - DeployStaticOptions::NO_JS_BUNLDE => true, - DeployStaticOptions::NO_HTML_MINIFY => true, + DeployStaticOptions::JOBS_AMOUNT => 3, + DeployStaticOptions::STRATEGY => 'compact', + DeployStaticOptions::NO_JAVASCRIPT => true, + DeployStaticOptions::NO_JS_BUNDLE => true, + DeployStaticOptions::NO_HTML_MINIFY => true, ]; $queueMock = $this->createMock(Queue::class); From e9f309c121e9debc4b971823a67afd8fbf4099b7 Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Mon, 7 Oct 2019 21:30:44 +0300 Subject: [PATCH 5/7] Refactor code --- .../Deploy/Console/DeployStaticOptions.php | 3 -- .../Deploy/Service/DeployStaticContent.php | 28 +++++++++++-------- .../Unit/Service/DeployStaticContentTest.php | 16 ++++++----- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/Deploy/Console/DeployStaticOptions.php b/app/code/Magento/Deploy/Console/DeployStaticOptions.php index 5326ba79b959a..06887fc0206fc 100644 --- a/app/code/Magento/Deploy/Console/DeployStaticOptions.php +++ b/app/code/Magento/Deploy/Console/DeployStaticOptions.php @@ -127,9 +127,6 @@ class DeployStaticOptions */ const NO_LESS = 'no-less'; - /** - * Default jobs amount - */ const DEFAULT_JOBS_AMOUNT = 0; /** diff --git a/app/code/Magento/Deploy/Service/DeployStaticContent.php b/app/code/Magento/Deploy/Service/DeployStaticContent.php index ba367b5283aa3..b6333d6fec71e 100644 --- a/app/code/Magento/Deploy/Service/DeployStaticContent.php +++ b/app/code/Magento/Deploy/Service/DeployStaticContent.php @@ -75,6 +75,9 @@ public function __construct( * @param array $options * @throws LocalizedException * @return void + * + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) */ public function deploy(array $options) { @@ -106,20 +109,20 @@ public function deploy(array $options) $deployStrategy = $this->deployStrategyFactory->create( $options[Options::STRATEGY], - [ - 'queue' => $this->queueFactory->create($queueOptions) - ] + ['queue' => $this->queueFactory->create($queueOptions)] ); $packages = $deployStrategy->deploy($options); if ($options[Options::NO_JAVASCRIPT] !== true) { - $deployRjsConfig = $this->objectManager->create(DeployRequireJsConfig::class, [ - 'logger' => $this->logger - ]); - $deployI18n = $this->objectManager->create(DeployTranslationsDictionary::class, [ - 'logger' => $this->logger - ]); + $deployRjsConfig = $this->objectManager->create( + DeployRequireJsConfig::class, + ['logger' => $this->logger] + ); + $deployI18n = $this->objectManager->create( + DeployTranslationsDictionary::class, + ['logger' => $this->logger] + ); foreach ($packages as $package) { if (!$package->isVirtual()) { $deployRjsConfig->deploy($package->getArea(), $package->getTheme(), $package->getLocale()); @@ -129,9 +132,10 @@ public function deploy(array $options) } if ($options[Options::NO_JAVASCRIPT] !== true && $options[Options::NO_JS_BUNDLE] !== true) { - $deployBundle = $this->objectManager->create(Bundle::class, [ - 'logger' => $this->logger - ]); + $deployBundle = $this->objectManager->create( + Bundle::class, + ['logger' => $this->logger] + ); foreach ($packages as $package) { if (!$package->isVirtual()) { $deployBundle->deploy($package->getArea(), $package->getTheme(), $package->getLocale()); diff --git a/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php index 4c6d0e4dd5f53..fcc02476bb858 100644 --- a/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php +++ b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php @@ -241,13 +241,15 @@ public function testMaxExecutionTimeOptionPassed() $strategyMock = $this->createMock(CompactDeploy::class); $this->queueFactory->expects($this->once()) ->method('create') - ->with([ - 'logger' => $this->logger, - 'maxExecTime' => 100, - 'maxProcesses' => 3, - 'options' => $options, - 'deployPackageService' => null - ]) + ->with( + [ + 'logger' => $this->logger, + 'maxExecTime' => 100, + 'maxProcesses' => 3, + 'options' => $options, + 'deployPackageService' => null + ] + ) ->willReturn($queueMock); $this->deployStrategyFactory->expects($this->once()) ->method('create') From 9d1c128d0cb03cb2f3ab21ecd45ef07ebc7c1fd1 Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Tue, 8 Oct 2019 10:53:41 +0300 Subject: [PATCH 6/7] Fix integration tests --- dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php b/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php index ea155894d7299..f00938c64dfc3 100644 --- a/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php +++ b/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php @@ -71,6 +71,7 @@ class DeployTest extends \PHPUnit\Framework\TestCase private $options = [ Options::DRY_RUN => false, Options::NO_JAVASCRIPT => false, + Options::NO_JS_BUNDLE => false, Options::NO_CSS => false, Options::NO_LESS => false, Options::NO_IMAGES => false, From 7e8defedc4fdf98bfc115fcca179a6368ab0f752 Mon Sep 17 00:00:00 2001 From: Andrey Legayev Date: Tue, 8 Oct 2019 11:18:30 +0300 Subject: [PATCH 7/7] Fix code style in integration tests --- .../integration/testsuite/Magento/Deploy/DeployTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php b/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php index f00938c64dfc3..a9591f1968ef7 100644 --- a/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php +++ b/dev/tests/integration/testsuite/Magento/Deploy/DeployTest.php @@ -101,9 +101,10 @@ protected function setUp() $this->rootDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT); $logger = $objectManager->get(\Psr\Log\LoggerInterface::class); - $this->deployService = $objectManager->create(DeployStaticContent::class, [ - 'logger' => $logger - ]); + $this->deployService = $objectManager->create( + DeployStaticContent::class, + ['logger' => $logger] + ); $this->bundleConfig = $objectManager->create(BundleConfig::class); $this->config = $objectManager->create(View::class);