I am having problems overriding the path to the Node.js binary used by the UglifyCSS filter in Assetic. Supposedly one can set the path in the /app/config/config.yml (Symfony docs, SO question), but it does not seem to have any effect, no matter where I put the overridden value.
To debug this, I changed line 37-39 in vendor/kriswallsmith/assetic/src/Assetic/Filter/UglifyCssFilter.php to output the value:
/**
* @param string $uglifycssBin Absolute path to the uglifycss executable
* @param string $nodeBin Absolute path to the folder containg node.js executable
*/
public function __construct($uglifycssBin = '/usr/bin/uglifycss', $nodeBin = null)
{
throw new \RuntimeException('Path to node executable '. $nodeBin . ' Uglify executable '. $uglifycssBin . "\n\$PATH: ". getenv('PATH'));
Here is the result
$ ../bin/console assetic:dump --env=prod
[RuntimeException]
Path to node executable /usr/local/bin/node Uglify executable /home/myuser/dev/ptflow-api/app/../node_modules/.bin/uglifycss
$PATH: /home/myuser/.sdkman/candidates/java/current/bin:/home/myuser/go/bin:/home/myuser/.local/bin:/home/myuser/bin/Telegram:/home/myuser/.yarn/bin:/home/carleri
k/.config/yarn/global/node_modules/.bin:/home/myuser/bin:/home/myuser/.yarn/bin:/home/myuser/.config/yarn/global/node_modules/.bin:/home/myuser/go/bin:/home/carleri
k/.go/bin:/home/myuser/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
This shows that $nodeBin always has the value /usr/local/bin/node. This is actually the right path on my system, but I need to be able to set it manually for it to work in a Docker container that does not find the right executable.
The example configs I have seen so far differ in whether to use the parameter path assetic.node or assetic.node.bin, but I have set both, in addition to assetic.filters.uglifycss.node:
assetic:
node: /not/a/path/config.yml/node
bin: '/usr/bin/node'
I also found a file that seemed to give some insight:
$ cat ./vendor/symfony/assetic-bundle/Resources/config/filters/uglifycss.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="assetic.filter.uglifycss.class">Assetic\Filter\UglifyCssFilter</parameter>
<parameter key="assetic.filter.uglifycss.bin">/usr/bin/uglifycss</parameter>
<parameter key="assetic.filter.uglifycss.node">%assetic.node.bin%</parameter>
<parameter key="assetic.filter.uglifycss.timeout">null</parameter>
<parameter key="assetic.filter.uglifycss.node_paths">%assetic.node.paths%</parameter>
<parameter key="assetic.filter.uglifycss.expand_vars">false</parameter>
<parameter key="assetic.filter.uglifycss.ugly_comments">false</parameter>
<parameter key="assetic.filter.uglifycss.cute_comments">false</parameter>
</parameters>
<services>
<service id="assetic.filter.uglifycss" class="%assetic.filter.uglifycss.class%">
<tag name="assetic.filter" alias="uglifycss" />
<argument>%assetic.filter.uglifycss.bin%</argument>
<argument>%assetic.filter.uglifycss.node%</argument>
<call method="setTimeout"><argument>%assetic.filter.uglifycss.timeout%</argument></call>
<call method="setNodePaths"><argument>%assetic.filter.uglifycss.node_paths%</argument></call>
<call method="setExpandVars"><argument>%assetic.filter.uglifycss.expand_vars%</argument></call>
<call method="setUglyComments"><argument>%assetic.filter.uglifycss.ugly_comments%</argument></call>
<call method="setCuteComments"><argument>%assetic.filter.uglifycss.cute_comments%</argument></call>
</service>
</services>
</container>
This seems to indicate that setting either assetic.filter.uglifycss.node or assetic.node.bin both should work. Neither does... The XML file seems to describe how to call the filter using reflection. I am not that well versed in PHP development (NodeJS, Java, .NET background), so I am not sure which code will use this further up the stack.
I am using Symfony 3.3 and the Assetic 2.8 bundle.
OMG, I hate this non-intuitive setup. It seems that not only build artifact are cached, so are config values! I found out by grepping the entire project for
/usr/local, finding it references in/var/cache.I had to delete the cache for the changes to take place:
The actual config paths in the Symfony config was not
assetic.node.bin, butassetic.node. Same for the filter.