Skip to content

Commit 9bca98c

Browse files
author
Viktor Tymchynskyi
committed
Merge remote-tracking branch 'origin/MAGETWO-43646' into MPI-BUGFIXES
2 parents d37da65 + b2ca24c commit 9bca98c

File tree

42 files changed

+1976
-950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1976
-950
lines changed

app/code/Magento/Deploy/Model/Deployer.php

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Deploy\Model;
88

9+
use Magento\Framework\View\Asset\PreProcessor\AlternativeSourceInterface;
910
use Magento\Framework\App\ObjectManagerFactory;
1011
use Magento\Framework\App\View\Deployment\Version;
1112
use Magento\Framework\App\View\Asset\Publisher;
@@ -19,6 +20,7 @@
1920
* A service for deploying Magento static view files for production mode
2021
*
2122
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
2224
*/
2325
class Deployer
2426
{
@@ -66,17 +68,26 @@ class Deployer
6668
protected $jsTranslationConfig;
6769

6870
/**
71+
* @var AlternativeSourceInterface[]
72+
*/
73+
private $alternativeSources;
74+
75+
/**
76+
* Constructor
77+
*
6978
* @param Files $filesUtil
7079
* @param OutputInterface $output
7180
* @param Version\StorageInterface $versionStorage
7281
* @param JsTranslationConfig $jsTranslationConfig
82+
* @param AlternativeSourceInterface[] $alternativeSources
7383
* @param bool $isDryRun
7484
*/
7585
public function __construct(
7686
Files $filesUtil,
7787
OutputInterface $output,
7888
Version\StorageInterface $versionStorage,
7989
JsTranslationConfig $jsTranslationConfig,
90+
array $alternativeSources,
8091
$isDryRun = false
8192
) {
8293
$this->filesUtil = $filesUtil;
@@ -85,6 +96,13 @@ public function __construct(
8596
$this->isDryRun = $isDryRun;
8697
$this->jsTranslationConfig = $jsTranslationConfig;
8798
$this->parentTheme = [];
99+
100+
array_map(
101+
function (AlternativeSourceInterface $alternative) {
102+
},
103+
$alternativeSources
104+
);
105+
$this->alternativeSources = $alternativeSources;
88106
}
89107

90108
/**
@@ -124,6 +142,7 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales)
124142
'design' => $design,
125143
]
126144
);
145+
/** @var \Magento\RequireJs\Model\FileManager $fileManager */
127146
$fileManager = $this->objectManager->create(
128147
'Magento\RequireJs\Model\FileManager',
129148
[
@@ -148,11 +167,17 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales)
148167
$this->findAncestors($area . Theme::THEME_PATH_SEPARATOR . $themePath)
149168
))
150169
) {
151-
$this->deployFile($filePath, $area, $themePath, $locale, $module);
170+
$compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, $module);
171+
if ($compiledFile !== '') {
172+
$this->deployFile($compiledFile, $area, $themePath, $locale, $module);
173+
}
152174
}
153175
}
154176
foreach ($libFiles as $filePath) {
155-
$this->deployFile($filePath, $area, $themePath, $locale, null);
177+
$compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, null);
178+
if ($compiledFile !== '') {
179+
$this->deployFile($compiledFile, $area, $themePath, $locale, null);
180+
}
156181
}
157182
if ($this->jsTranslationConfig->dictionaryEnabled()) {
158183
$this->deployFile(
@@ -169,7 +194,7 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales)
169194
}
170195
}
171196
}
172-
$this->output->writeln("=== Minify templates ===");
197+
$this->output->writeln('=== Minify templates ===');
173198
$this->count = 0;
174199
foreach ($this->filesUtil->getPhtmlFiles(false, false) as $template) {
175200
$this->htmlMinifier->minify($template);
@@ -268,15 +293,25 @@ protected function emulateApplicationLocale($locale, $area)
268293
* @param string $themePath
269294
* @param string $locale
270295
* @param string $module
271-
* @return void
296+
* @return string
297+
* @throws \InvalidArgumentException
298+
*
272299
* @SuppressWarnings(PHPMD.NPathComplexity)
273300
*/
274301
private function deployFile($filePath, $area, $themePath, $locale, $module)
275302
{
276-
$requestedPath = $filePath;
277-
if (substr($filePath, -5) == '.less') {
278-
$requestedPath = preg_replace('/.less$/', '.css', $filePath);
303+
$compiledFile = '';
304+
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
305+
306+
foreach ($this->alternativeSources as $name => $alternative) {
307+
if (in_array($extension, $alternative->getAlternativesExtensionsNames(), true)
308+
&& strpos(basename($filePath), '_') !== 0
309+
) {
310+
$compiledFile = substr($filePath, 0, strlen($filePath) - strlen($extension) - 1);
311+
$compiledFile = $compiledFile . '.' . $name;
312+
}
279313
}
314+
280315
$logMessage = "Processing file '$filePath' for area '$area', theme '$themePath', locale '$locale'";
281316
if ($module) {
282317
$logMessage .= ", module '$module'";
@@ -288,7 +323,7 @@ private function deployFile($filePath, $area, $themePath, $locale, $module)
288323

289324
try {
290325
$asset = $this->assetRepo->createAsset(
291-
$requestedPath,
326+
$filePath,
292327
['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]
293328
);
294329
if ($this->output->isVeryVerbose()) {
@@ -303,18 +338,13 @@ private function deployFile($filePath, $area, $themePath, $locale, $module)
303338
$this->bundleManager->addAsset($asset);
304339
}
305340
$this->count++;
306-
} catch (\Less_Exception_Compiler $e) {
307-
$this->verboseLog(
308-
"\tNotice: Could not parse LESS file '$filePath'. "
309-
. "This may indicate that the file is incomplete, but this is acceptable. "
310-
. "The file '$filePath' will be combined with another LESS file."
311-
);
312-
$this->verboseLog("\tCompiler error: " . $e->getMessage());
313341
} catch (\Exception $e) {
314-
$this->output->writeln($e->getMessage() . " ($logMessage)");
342+
$this->output->write('.');
315343
$this->verboseLog($e->getTraceAsString());
316344
$this->errorCount++;
317345
}
346+
347+
return $compiledFile;
318348
}
319349

320350
/**

app/code/Magento/Deploy/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Deploy\Model\Deployer">
10+
<arguments>
11+
<argument name="alternativeSources" xsi:type="array">
12+
<item name="css" xsi:type="object">AlternativeSourceProcessors</item>
13+
</argument>
14+
</arguments>
15+
</type>
916
<type name="Magento\Framework\Console\CommandList">
1017
<arguments>
1118
<argument name="commands" xsi:type="array">

app/code/Magento/Developer/Console/Command/CssDeployCommand.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Developer\Console\Command;
88

9+
use Magento\Framework\View\Asset\PreProcessor\Pool;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputArgument;
1112
use Symfony\Component\Console\Input\InputOption;
@@ -17,7 +18,6 @@
1718
use Magento\Framework\View\Asset\Repository;
1819
use Magento\Framework\ObjectManagerInterface;
1920
use Magento\Framework\App\ObjectManager\ConfigLoader;
20-
use Magento\Framework\View\Asset\SourceFileGeneratorPool;
2121
use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface;
2222
use Magento\Framework\App\Filesystem\DirectoryList;
2323
use Magento\Framework\Validator\Locale;
@@ -73,11 +73,6 @@ class CssDeployCommand extends Command
7373
*/
7474
private $state;
7575

76-
/**
77-
* @var SourceFileGeneratorPool
78-
*/
79-
private $sourceFileGeneratorPool;
80-
8176
/**
8277
* @var Source
8378
*/
@@ -98,6 +93,11 @@ class CssDeployCommand extends Command
9893
*/
9994
private $validator;
10095

96+
/**
97+
* @var Pool
98+
*/
99+
private $pool;
100+
101101
/**
102102
* Inject dependencies
103103
*
@@ -106,33 +106,33 @@ class CssDeployCommand extends Command
106106
* @param ConfigLoader $configLoader
107107
* @param State $state
108108
* @param Source $assetSource
109-
* @param SourceFileGeneratorPool $sourceFileGeneratorPoll
110109
* @param ChainFactoryInterface $chainFactory
111110
* @param Filesystem $filesystem
112111
* @param Locale $validator
112+
* @param Pool $pool
113113
*/
114114
public function __construct(
115115
ObjectManagerInterface $objectManager,
116116
Repository $assetRepo,
117117
ConfigLoader $configLoader,
118118
State $state,
119119
Source $assetSource,
120-
SourceFileGeneratorPool $sourceFileGeneratorPoll,
121120
ChainFactoryInterface $chainFactory,
122121
Filesystem $filesystem,
123-
Locale $validator
122+
Locale $validator,
123+
Pool $pool
124124
) {
125125
$this->state = $state;
126126
$this->objectManager = $objectManager;
127127
$this->configLoader = $configLoader;
128128
$this->assetRepo = $assetRepo;
129-
$this->sourceFileGeneratorPool = $sourceFileGeneratorPoll;
130129
$this->assetSource = $assetSource;
131130
$this->chainFactory = $chainFactory;
132131
$this->filesystem = $filesystem;
133132
$this->validator = $validator;
134133

135134
parent::__construct();
135+
$this->pool = $pool;
136136
}
137137

138138
/**
@@ -203,8 +203,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
203203
$this->state->setAreaCode($area);
204204
$this->objectManager->configure($this->configLoader->load($area));
205205

206-
$sourceFileGenerator = $this->sourceFileGeneratorPool->create($type);
207-
208206
foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) {
209207
$file .= '.' . $type;
210208

@@ -233,14 +231,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
233231
]
234232
);
235233

236-
$processedCoreFile = $sourceFileGenerator->generateFileTree($chain);
237-
234+
$this->pool->process($chain);
238235
$targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
239-
$source = $rootDir->getRelativePath($processedCoreFile);
240-
$destination = $asset->getPath();
241-
$rootDir->copyFile($source, $destination, $targetDir);
236+
$targetDir->writeFile($chain->getAsset()->getPath(), $chain->getContent());
242237

243-
$output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>");
238+
$output->writeln('<info>Successfully processed dynamic stylesheet into CSS</info>');
244239
}
245240
}
246241
}

app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
namespace Magento\Developer\Test\Unit\Console\Command;
88

99
use Magento\Framework\Filesystem;
10+
use Magento\Framework\View\Asset\PreProcessor\Pool;
1011
use Magento\Framework\View\Asset\Source;
1112
use Magento\Framework\App\State;
1213
use Magento\Framework\View\Asset\Repository;
1314
use Magento\Framework\ObjectManagerInterface;
1415
use Magento\Framework\App\ObjectManager\ConfigLoader;
15-
use Magento\Framework\View\Asset\SourceFileGeneratorPool;
1616
use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface;
1717
use Magento\Developer\Console\Command\CssDeployCommand;
1818
use Symfony\Component\Console\Tester\CommandTester;
1919
use Magento\Framework\Validator\Locale;
2020

21+
/**
22+
* Class CssDeployCommandTest
23+
*/
2124
class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
2225
{
2326
/**
@@ -45,11 +48,6 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
4548
*/
4649
private $state;
4750

48-
/**
49-
* @var SourceFileGeneratorPool|\PHPUnit_Framework_MockObject_MockObject
50-
*/
51-
private $sourceFileGeneratorPool;
52-
5351
/**
5452
* @var Source|\PHPUnit_Framework_MockObject_MockObject
5553
*/
@@ -70,36 +68,37 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase
7068
*/
7169
private $validator;
7270

71+
/**
72+
* @var Pool|\PHPUnit_Framework_MockObject_MockObject
73+
*/
74+
private $poolMock;
75+
7376
public function setUp()
7477
{
7578
$this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface');
7679
$this->assetRepo = $this->getMock('Magento\Framework\View\Asset\Repository', [], [], '', false);
7780
$this->configLoader = $this->getMock('Magento\Framework\App\ObjectManager\ConfigLoader', [], [], '', false);
7881
$this->state = $this->getMock('Magento\Framework\App\State', [], [], '', false);
7982
$this->assetSource = $this->getMock('Magento\Framework\View\Asset\Source', [], [], '', false);
80-
$this->sourceFileGeneratorPool = $this->getMock(
81-
'Magento\Framework\View\Asset\SourceFileGeneratorPool',
82-
[],
83-
[],
84-
'',
85-
false
86-
);
8783
$this->chainFactory = $this->getMockForAbstractClass(
8884
'Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface'
8985
);
9086
$this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
9187
$this->validator = $this->getMock('Magento\Framework\Validator\Locale', [], [], '', false);
88+
$this->poolMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Pool')
89+
->disableOriginalConstructor()
90+
->getMock();
9291

9392
$this->command = new CssDeployCommand(
9493
$this->objectManager,
9594
$this->assetRepo,
9695
$this->configLoader,
9796
$this->state,
9897
$this->assetSource,
99-
$this->sourceFileGeneratorPool,
10098
$this->chainFactory,
10199
$this->filesystem,
102-
$this->validator
100+
$this->validator,
101+
$this->poolMock
103102
);
104103
}
105104

@@ -109,10 +108,6 @@ public function testExecute()
109108

110109
$this->configLoader->expects($this->once())->method('load')->with('frontend')->willReturn([]);
111110
$this->objectManager->expects($this->once())->method('configure');
112-
$this->sourceFileGeneratorPool->expects($this->once())
113-
->method('create')
114-
->with('less')
115-
->willReturn($this->getMock('Magento\Framework\View\Asset\SourceFileGeneratorInterface'));
116111
$asset = $this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface');
117112
$asset->expects($this->once())->method('getContentType')->willReturn('type');
118113
$this->assetRepo->expects($this->once())
@@ -128,6 +123,10 @@ public function testExecute()
128123
->willReturn($asset);
129124
$this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null');
130125

126+
$chainMock = $this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false);
127+
$assetMock = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface')
128+
->getMockForAbstractClass();
129+
131130
$this->chainFactory->expects($this->once())
132131
->method('create')
133132
->with(
@@ -137,8 +136,11 @@ public function testExecute()
137136
'origContentType' => 'type',
138137
'origAssetPath' => 'relative/path',
139138
]
140-
)
141-
->willReturn($this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false));
139+
)->willReturn($chainMock);
140+
141+
$chainMock->expects(self::once())
142+
->method('getAsset')
143+
->willReturn($assetMock);
142144

143145
$rootDir = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteInterface', [], [], '', false);
144146
$this->filesystem->expects($this->at(0))->method('getDirectoryWrite')->willReturn($rootDir);

0 commit comments

Comments
 (0)