diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d316189..121028e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## 3.1.0 +- Added: Search for Node executable additionally in paths of `PATH` environment variable +- Improved: Provide directory search path in error message if executable cannot be found + ## 3.0.0 - Release stable version for Matomo 5 - Fixed: CORS template issue diff --git a/ExecutableFinder.php b/ExecutableFinder.php index fe3e9cd6..655a2dd5 100644 --- a/ExecutableFinder.php +++ b/ExecutableFinder.php @@ -4,6 +4,8 @@ require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php'; +use Piwik\Container\StaticContainer; +use Piwik\Log\Logger; use Piwik\Plugins\PerformanceAudit\Exceptions\DependencyMissingException; use Symfony\Component\Process\ExecutableFinder as BaseExecutableFinder; @@ -28,6 +30,9 @@ public static function search($name) [__DIR__ . DIRECTORY_SEPARATOR . 'node_modules' . DIRECTORY_SEPARATOR . '.bin'], explode(PATH_SEPARATOR, self::getDefaultPath()) ); + StaticContainer::get(Logger::class)->debug('Searching for executable in directories.', + ['executable' => $name, 'directories' => $extraDirs]); + $executablePath = (new parent())->find($name, false, $extraDirs); if (!$executablePath) { throw new DependencyMissingException($name, $extraDirs); @@ -42,28 +47,45 @@ public static function search($name) * @return string */ public static function getDefaultPath() { - return ExecutableFinder::isRunningOnWindows() ? - implode(";", [ - '%SystemRoot%\system32', - '%SystemRoot%', - '%SystemRoot%\System32\Wbem' - ]) : - implode(":", [ - '/usr/local/sbin', - '/usr/local/bin', - '/usr/sbin', - '/usr/bin', - '/sbin', - '/bin', - '/opt/plesk/node/24/bin', - '/opt/plesk/node/22/bin', - '/opt/plesk/node/20/bin', - '/opt/plesk/node/18/bin', - '/opt/plesk/node/16/bin', - '/opt/plesk/node/14/bin', - '/opt/plesk/node/12/bin', - '/opt/plesk/node/10/bin' - ]); + $searchPaths = ExecutableFinder::isRunningOnWindows() ? [ + '%SystemRoot%\system32', + '%SystemRoot%', + '%SystemRoot%\System32\Wbem' + ] : [ + '/usr/local/sbin', + '/usr/local/bin', + '/usr/sbin', + '/usr/bin', + '/sbin', + '/bin', + '/opt/plesk/node/24/bin', + '/opt/plesk/node/22/bin', + '/opt/plesk/node/20/bin', + '/opt/plesk/node/18/bin', + '/opt/plesk/node/16/bin', + '/opt/plesk/node/14/bin', + '/opt/plesk/node/12/bin', + '/opt/plesk/node/10/bin' + ]; + $additionalSearchPaths = ExecutableFinder::getPathsFromEnvironmentVariablePath(); + $finalSearchPaths = array_unique(array_merge($searchPaths, $additionalSearchPaths)); + + return implode(PATH_SEPARATOR, $finalSearchPaths); + } + + /** + * Return paths as array if `PATH` environment variable is set, + * empty array otherwise. + * + * @return array + */ + private static function getPathsFromEnvironmentVariablePath() { + $envPath = getenv('PATH'); + if (!is_string($envPath)) { + return []; + } + + return explode(PATH_SEPARATOR, $envPath); } /** diff --git a/plugin.json b/plugin.json index 5ae5d415..fc850b4f 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "name": "PerformanceAudit", "description": "Daily performance audits of all your sites in Matomo.", - "version": "3.0.0", + "version": "3.1.0", "theme": false, "require": { "php": ">=7.2.5",