Skip to content

Commit 2684fe3

Browse files
committed
Merge remote-tracking branch 'ogresCE/MAGETWO-38010-warnings-static-view-files-deployment' into PR_Branch
2 parents 6013060 + f17f0d5 commit 2684fe3

File tree

6 files changed

+106
-35
lines changed

6 files changed

+106
-35
lines changed

lib/internal/Magento/Framework/Less/PreProcessor/Instruction/Import.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@ public function process(\Magento\Framework\View\Asset\PreProcessor\Chain $chain)
5050
$replaceCallback = function ($matchContent) use ($asset) {
5151
return $this->replace($matchContent, $asset);
5252
};
53-
$chain->setContent(preg_replace_callback(self::REPLACE_PATTERN, $replaceCallback, $chain->getContent()));
53+
$content = $this->removeComments($chain->getContent());
54+
$chain->setContent(preg_replace_callback(self::REPLACE_PATTERN, $replaceCallback, $content));
55+
}
56+
57+
/**
58+
* Returns the content without commented lines
59+
*
60+
* @param string $content
61+
* @return string
62+
*/
63+
private function removeComments($content)
64+
{
65+
return preg_replace("#(^\s*//.*$)|((^\s*/\*(?s).*?(\*/)(?!\*/))$)#m", '', $content);
5466
}
5567

5668
/**

lib/internal/Magento/Framework/Less/Test/Unit/PreProcessor/Instruction/ImportTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ public function processDataProvider()
9191
'Magento_Module/something.css',
9292
"@import (type) 'Magento_Module/something.css';",
9393
],
94+
'with single line comment' => [
95+
'@import (type) "some/file.css" media;' . PHP_EOL
96+
. '// @import (type) "unnecessary/file.css" media;',
97+
'some/file.css',
98+
'some/file.css',
99+
"@import (type) 'some/file.css' media;" . PHP_EOL,
100+
],
101+
'with multi line comment' => [
102+
'@import (type) "some/file.css" media;' . PHP_EOL
103+
. '/* @import (type) "unnecessary/file.css" media;' . PHP_EOL
104+
. '@import (type) "another/unnecessary/file.css" media; */',
105+
'some/file.css',
106+
'some/file.css',
107+
"@import (type) 'some/file.css' media;" . PHP_EOL,
108+
],
94109
];
95110
}
96111

lib/internal/Magento/Framework/View/Asset/File.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ public function getSourceFile()
143143
*/
144144
public function getContent()
145145
{
146-
return (string)$this->source->getContent($this);
146+
$content = $this->source->getContent($this);
147+
if (false === $content) {
148+
throw new File\NotFoundException("Unable to get content for '{$this->getPath()}'");
149+
}
150+
return $content;
147151
}
148152

149153
/**

lib/internal/Magento/Framework/View/Asset/Source.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,22 @@ public function getContent(LocalInterface $asset)
130130
private function preProcess(LocalInterface $asset)
131131
{
132132
$sourceFile = $this->findSourceFile($asset);
133-
$dirCode = DirectoryList::ROOT;
134-
$path = $this->rootDir->getRelativePath($sourceFile);
133+
if ($sourceFile !== false) {
134+
$path = $this->rootDir->getRelativePath($sourceFile);
135+
} else {
136+
// No original file, the resulting file may be generated by a pre-processor
137+
$path = false;
138+
}
135139
$cacheId = $path . ':' . $asset->getPath();
136140
$cached = $this->cache->load($cacheId);
137141
if ($cached) {
138142
return unserialize($cached);
139143
}
140144

141-
$origContent = $path ? $this->rootDir->readFile($path) : '';
142-
$origContentType = $this->getContentType($path) ?: $asset->getContentType();
143-
144-
$chain = $this->chainFactory->create(
145-
[
146-
'asset' => $asset,
147-
'origContent' => $origContent,
148-
'origContentType' => $origContentType,
149-
'origAssetPath' => $path
150-
]
151-
);
152-
145+
$chain = $this->createChain($asset, $path);
153146
$this->preProcessorPool->process($chain);
154147
$chain->assertValid();
148+
$dirCode = DirectoryList::ROOT;
155149
if ($chain->isChanged()) {
156150
$dirCode = DirectoryList::VAR_DIR;
157151
$path = DirectoryList::TMP_MATERIALIZATION_DIR . '/source/' . $chain->getTargetAssetPath();
@@ -252,4 +246,32 @@ public function findRelativeSourceFilePath(LocalInterface $asset)
252246
}
253247
return $this->rootDir->getRelativePath($sourceFile);
254248
}
249+
250+
/**
251+
* Creates a chain for pre-processing
252+
*
253+
* @param LocalInterface $asset
254+
* @param string|bool $path
255+
* @return PreProcessor\Chain
256+
*/
257+
private function createChain(LocalInterface $asset, $path)
258+
{
259+
if ($path) {
260+
$origContent = $this->rootDir->readFile($path);
261+
$origContentType = $this->getContentType($path);
262+
} else {
263+
$origContent = '';
264+
$origContentType = $asset->getContentType();
265+
}
266+
267+
$chain = $this->chainFactory->create(
268+
[
269+
'asset' => $asset,
270+
'origContent' => $origContent,
271+
'origContentType' => $origContentType,
272+
'origAssetPath' => $path
273+
]
274+
);
275+
return $chain;
276+
}
255277
}

lib/internal/Magento/Framework/View/Test/Unit/Asset/FileTest.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,40 @@ public function testGetSourceFileMissing()
9898
$this->object->getSourceFile();
9999
}
100100

101-
public function testGetContent()
101+
/**
102+
* @param string $content
103+
*
104+
* @dataProvider getContentDataProvider
105+
*/
106+
public function testGetContent($content)
102107
{
103108
$this->source->expects($this->exactly(2))
104109
->method('getContent')
105110
->with($this->object)
106-
->will($this->returnValue('content'));
107-
$this->assertEquals('content', $this->object->getContent());
108-
$this->assertEquals('content', $this->object->getContent()); // no in-memory caching for content
111+
->will($this->returnValue($content));
112+
$this->assertEquals($content, $this->object->getContent());
113+
$this->assertEquals($content, $this->object->getContent()); // no in-memory caching for content
114+
}
115+
116+
public function getContentDataProvider()
117+
{
118+
return [
119+
'normal content' => ['content'],
120+
'empty content' => [''],
121+
];
122+
}
123+
124+
/**
125+
* @expectedException \Magento\Framework\View\Asset\File\NotFoundException
126+
* @expectedExceptionMessage Unable to get content for 'Magento_Module/dir/file.css'
127+
*/
128+
public function testGetContentNotFound()
129+
{
130+
$this->source->expects($this->once())
131+
->method('getContent')
132+
->with($this->object)
133+
->will($this->returnValue(false));
134+
$this->object->getContent();
109135
}
110136

111137
public function testSimpleGetters()

setup/src/Magento/Setup/Model/Deployer.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ class Deployer
3434
/** @var Version\StorageInterface */
3535
private $versionStorage;
3636

37-
/** @var \Magento\Framework\Stdlib\DateTime */
38-
private $dateTime;
39-
4037
/** @var \Magento\Framework\View\Asset\Repository */
4138
private $assetRepo;
4239

@@ -75,7 +72,6 @@ class Deployer
7572
* @param Files $filesUtil
7673
* @param OutputInterface $output
7774
* @param Version\StorageInterface $versionStorage
78-
* @param \Magento\Framework\Stdlib\DateTime $dateTime
7975
* @param \Magento\Framework\View\Asset\MinifyService $minifyService
8076
* @param JsTranslationConfig $jsTranslationConfig
8177
* @param bool $isDryRun
@@ -84,15 +80,13 @@ public function __construct(
8480
Files $filesUtil,
8581
OutputInterface $output,
8682
Version\StorageInterface $versionStorage,
87-
\Magento\Framework\Stdlib\DateTime $dateTime,
8883
\Magento\Framework\View\Asset\MinifyService $minifyService,
8984
JsTranslationConfig $jsTranslationConfig,
9085
$isDryRun = false
9186
) {
9287
$this->filesUtil = $filesUtil;
9388
$this->output = $output;
9489
$this->versionStorage = $versionStorage;
95-
$this->dateTime = $dateTime;
9690
$this->isDryRun = $isDryRun;
9791
$this->minifyService = $minifyService;
9892
$this->jsTranslationConfig = $jsTranslationConfig;
@@ -159,7 +153,7 @@ public function deploy(ObjectManagerFactory $omFactory, array $locales)
159153
$this->count = 0;
160154
foreach ($this->filesUtil->getPhtmlFiles(false, false) as $template) {
161155
$this->htmlMinifier->minify($template);
162-
if ($this->output->isVerbose()) {
156+
if ($this->output->isVeryVerbose()) {
163157
$this->output->writeln($template . " minified\n");
164158
} else {
165159
$this->output->write('.');
@@ -272,15 +266,17 @@ private function deployFile($filePath, $area, $themePath, $locale, $module)
272266
$logMessage .= ", module '$module'";
273267
}
274268

275-
$this->verboseLog($logMessage);
269+
if ($this->output->isVeryVerbose()) {
270+
$this->output->writeln($logMessage);
271+
}
276272

277273
try {
278274
$asset = $this->assetRepo->createAsset(
279275
$requestedPath,
280276
['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]
281277
);
282278
$asset = $this->minifyService->getAssets([$asset], true)[0];
283-
if ($this->output->isVerbose()) {
279+
if ($this->output->isVeryVerbose()) {
284280
$this->output->writeln("\tDeploying the file to '{$asset->getPath()}'");
285281
} else {
286282
$this->output->write('.');
@@ -292,20 +288,16 @@ private function deployFile($filePath, $area, $themePath, $locale, $module)
292288
$this->bundleManager->addAsset($asset);
293289
}
294290
$this->count++;
295-
} catch (\Magento\Framework\View\Asset\File\NotFoundException $e) {
296-
// File was not found by Fallback (possibly because it's wrong context for it) - there is nothing to publish
297-
$this->verboseLog(
298-
"\tNotice: Could not find file '$filePath'. This file may not be relevant for the theme or area."
299-
);
300291
} catch (\Less_Exception_Compiler $e) {
301292
$this->verboseLog(
302293
"\tNotice: Could not parse LESS file '$filePath'. "
303294
. "This may indicate that the file is incomplete, but this is acceptable. "
304295
. "The file '$filePath' will be combined with another LESS file."
305296
);
297+
$this->verboseLog("\tCompiler error: " . $e->getMessage());
306298
} catch (\Exception $e) {
307299
$this->output->writeln($e->getMessage() . " ($logMessage)");
308-
$this->verboseLog((string)$e);
300+
$this->verboseLog($e->getTraceAsString());
309301
$this->errorCount++;
310302
}
311303
}

0 commit comments

Comments
 (0)