diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2022-03-24 18:29:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-24 18:29:45 +0300 |
commit | 1c5769b5770397f85a3e3f644f295f47ebc9b6aa (patch) | |
tree | 45af7dd011280b8b221931f098c234b8076273b5 | |
parent | 1713349b9ef31cad5a27f74304220958dea790c2 (diff) |
Build plugin module dependencies if type output does not exist locally, otherwise build will fail. (#18994)
-rw-r--r-- | core/AssetManager/UIAssetFetcher/PluginUmdAssetFetcher.php | 33 | ||||
-rw-r--r-- | plugins/CoreVue/Commands/Build.php | 21 |
2 files changed, 45 insertions, 9 deletions
diff --git a/core/AssetManager/UIAssetFetcher/PluginUmdAssetFetcher.php b/core/AssetManager/UIAssetFetcher/PluginUmdAssetFetcher.php index f86f7f5102..9ac1edaec7 100644 --- a/core/AssetManager/UIAssetFetcher/PluginUmdAssetFetcher.php +++ b/core/AssetManager/UIAssetFetcher/PluginUmdAssetFetcher.php @@ -10,6 +10,7 @@ namespace Piwik\AssetManager\UIAssetFetcher; use Piwik\AssetManager\UIAssetFetcher; +use Piwik\Cache; use Piwik\Config; use Piwik\Development; use Piwik\Plugin\Manager; @@ -214,6 +215,26 @@ class PluginUmdAssetFetcher extends UIAssetFetcher return $result; } + public static function getPluginDependencies($plugin) + { + $pluginDir = self::getPluginDirectory($plugin); + $umdMetadata = "$pluginDir/vue/dist/umd.metadata.json"; + + $cache = Cache::getTransientCache(); + $cacheKey = 'PluginUmdAssetFetcher.pluginDependencies.' . $plugin; + + $pluginDependencies = $cache->fetch($cacheKey); + if (!is_array($pluginDependencies)) { + $pluginDependencies = []; + if (is_file($umdMetadata)) { + $pluginDependencies = json_decode(file_get_contents($umdMetadata), true); + $pluginDependencies = $pluginDependencies['dependsOn'] ?? []; + } + $cache->save($cacheKey, $pluginDependencies); + } + return $cache->fetch($cacheKey); + } + private static function visitPlugin($plugin, $keepUnresolved, &$plugins, &$result) { // remove the plugin from the array of plugins to visit @@ -225,17 +246,11 @@ class PluginUmdAssetFetcher extends UIAssetFetcher } // read the plugin dependencies, if any - $pluginDir = self::getPluginDirectory($plugin); - $umdMetadata = "$pluginDir/vue/dist/umd.metadata.json"; - - $pluginDependencies = []; - if (is_file($umdMetadata)) { - $pluginDependencies = json_decode(file_get_contents($umdMetadata), true); - } + $pluginDependencies = self::getPluginDependencies($plugin); - if (!empty($pluginDependencies['dependsOn'])) { + if (!empty($pluginDependencies)) { // visit each plugin this one depends on first, so it is loaded first - foreach ($pluginDependencies['dependsOn'] as $pluginDependency) { + foreach ($pluginDependencies as $pluginDependency) { // check if dependency is not activated if (!in_array($pluginDependency, $plugins) && !in_array($pluginDependency, $result) diff --git a/plugins/CoreVue/Commands/Build.php b/plugins/CoreVue/Commands/Build.php index a021f0de69..5242c97d8b 100644 --- a/plugins/CoreVue/Commands/Build.php +++ b/plugins/CoreVue/Commands/Build.php @@ -62,6 +62,7 @@ class Build extends ConsoleCommand } } + $plugins = $this->ensureUntranspiledPluginDependenciesArePresent($plugins); $plugins = PluginUmdAssetFetcher::orderPluginsByPluginDependencies($plugins); // remove webpack cache since it can result in strange builds if present @@ -71,6 +72,26 @@ class Build extends ConsoleCommand return $failed; } + private function ensureUntranspiledPluginDependenciesArePresent($plugins) + { + $pluginDependenciesToAdd = []; + foreach ($plugins as $plugin) { + $dependencies = PluginUmdAssetFetcher::getPluginDependencies($plugin); + foreach ($dependencies as $dependency) { + if (!$this->isTypeOutputPresent($dependency)) { + $pluginDependenciesToAdd[] = $dependency; + } + } + } + return array_unique(array_merge($plugins, $pluginDependenciesToAdd)); + } + + private function isTypeOutputPresent($dependency) + { + $typeDirectory = PIWIK_INCLUDE_PATH . '/@types/' . $dependency . '/index.d.ts'; + return is_file($typeDirectory); + } + private function build(OutputInterface $output, $plugins, $printBuildCommand, $watch = false) { if ($watch) { |