diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2022-04-05 04:12:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-05 04:12:14 +0300 |
commit | 925b2ae1de42e33bd37487384bf8e71e68280fbc (patch) | |
tree | b8130624d7878f1f321223a48bdf9b06b1a7ce90 | |
parent | 63252ee0c4430c10ba79d87307f8f88bcf9dfddd (diff) |
retry vue:build if we notice a typescript compiler race condition occurs (#19046)
-rw-r--r-- | plugins/CoreVue/Commands/Build.php | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/plugins/CoreVue/Commands/Build.php b/plugins/CoreVue/Commands/Build.php index 48f68e8dbd..93c24af457 100644 --- a/plugins/CoreVue/Commands/Build.php +++ b/plugins/CoreVue/Commands/Build.php @@ -22,6 +22,7 @@ class Build extends ConsoleCommand { const RECOMMENDED_NODE_VERSION = '16.0.0'; const RECOMMENDED_NPM_VERSION = '7.0.0'; + const RETRY_COUNT = 2; protected function configure() { @@ -144,13 +145,25 @@ class Build extends ConsoleCommand if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { passthru($command); } else { - exec($command, $cmdOutput, $returnCode); - if ($returnCode != 0 - || stripos(implode("\n", $cmdOutput), 'warning') !== false - ) { - $output->writeln("<error>Failed:</error>\n"); - $output->writeln($cmdOutput); - $output->writeln(""); + $attempts = 0; + while ($attempts < self::RETRY_COUNT) { + exec($command, $cmdOutput, $returnCode); + + $concattedOutput = implode("\n", $cmdOutput); + if ($this->isTypeScriptRaceConditionInOutput($plugin, $concattedOutput)) { + $output->writeln("<comment>The TypeScript compiler encountered a race condition when compiling " + . "files (files that exist were not found), retrying.</comment>"); + } + + if ($returnCode != 0 + || stripos($concattedOutput, 'warning') !== false + ) { + $output->writeln("<error>Failed:</error>\n"); + $output->writeln($cmdOutput); + $output->writeln(""); + } + + ++$attempts; } } @@ -252,4 +265,16 @@ class Build extends ConsoleCommand self::RECOMMENDED_NPM_VERSION, $npmVersion, 'npm install -g npm@latest')); } } + + private function isTypeScriptRaceConditionInOutput($plugin, $concattedOutput) + { + if (!preg_match('/^TS2307: Cannot find module \'([^\']+)\' or its corresponding type declarations./', $concattedOutput, $matches)) { + return false; + } + + $file = $matches[1]; + $filePath = PIWIK_INCLUDE_PATH . '/plugins/' . $plugin . '/vue/src/' . $file; + $isTypeScriptCompilerBug = file_exists($filePath); + return $isTypeScriptCompilerBug; + } } |