11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2015 Adobe
4+ * All Rights Reserved .
55 */
66namespace Magento \Framework \Css \PreProcessor \Adapter \Less ;
77
8+ use Magento \Framework \App \Filesystem \DirectoryList ;
9+ use Magento \Framework \App \ObjectManager ;
810use Magento \Framework \App \State ;
911use Magento \Framework \Css \PreProcessor \File \Temporary ;
1012use Magento \Framework \Phrase ;
1618
1719/**
1820 * Class Processor
21+ *
22+ * Process LESS files into CSS
1923 */
2024class Processor implements ContentProcessorInterface
2125{
@@ -39,24 +43,32 @@ class Processor implements ContentProcessorInterface
3943 */
4044 private $ temporaryFile ;
4145
46+ /**
47+ * @var DirectoryList
48+ */
49+ private DirectoryList $ directoryList ;
50+
4251 /**
4352 * Constructor
4453 *
4554 * @param LoggerInterface $logger
4655 * @param State $appState
4756 * @param Source $assetSource
4857 * @param Temporary $temporaryFile
58+ * @param ?DirectoryList $directoryList
4959 */
5060 public function __construct (
5161 LoggerInterface $ logger ,
5262 State $ appState ,
5363 Source $ assetSource ,
54- Temporary $ temporaryFile
64+ Temporary $ temporaryFile ,
65+ ?DirectoryList $ directoryList = null ,
5566 ) {
5667 $ this ->logger = $ logger ;
5768 $ this ->appState = $ appState ;
5869 $ this ->assetSource = $ assetSource ;
5970 $ this ->temporaryFile = $ temporaryFile ;
71+ $ this ->directoryList = $ directoryList ?: ObjectManager::getInstance ()->get (DirectoryList::class);
6072 }
6173
6274 /**
@@ -66,10 +78,19 @@ public function processContent(File $asset)
6678 {
6779 $ path = $ asset ->getPath ();
6880 try {
81+ $ mode = $ this ->appState ->getMode ();
82+ $ sourceMapBasePath = sprintf (
83+ '%s/pub/ ' ,
84+ $ this ->directoryList ->getPath (DirectoryList::TEMPLATE_MINIFICATION_DIR ),
85+ );
86+
6987 $ parser = new \Less_Parser (
7088 [
7189 'relativeUrls ' => false ,
72- 'compress ' => $ this ->appState ->getMode () !== State::MODE_DEVELOPER
90+ 'compress ' => $ mode !== State::MODE_DEVELOPER ,
91+ 'sourceMap ' => $ mode === State::MODE_DEVELOPER ,
92+ 'sourceMapRootpath ' => '/ ' ,
93+ 'sourceMapBasepath ' => $ sourceMapBasePath ,
7394 ]
7495 );
7596
0 commit comments