From 6e1bf63f6a403ff7b59074fca067b9a734a4f197 Mon Sep 17 00:00:00 2001 From: nuno maduro Date: Sat, 2 May 2026 01:40:35 +0100 Subject: [PATCH] wip --- src/Plugins/Tia.php | 4 -- src/Plugins/Tia/JsModuleGraph.php | 96 +------------------------------ 2 files changed, 3 insertions(+), 97 deletions(-) diff --git a/src/Plugins/Tia.php b/src/Plugins/Tia.php index aa74b773..964cd4ae 100644 --- a/src/Plugins/Tia.php +++ b/src/Plugins/Tia.php @@ -630,10 +630,6 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable $this->state->write(self::KEY_COVERAGE_MARKER, ''); } - if (! Parallel::isWorker() && JsModuleGraph::isApplicable($projectRoot)) { - JsModuleGraph::warmInBackground($projectRoot); - } - if ($this->piggybackCoverage && ! $this->state->exists(self::KEY_COVERAGE_CACHE)) { return $this->enterRecordMode($arguments); } diff --git a/src/Plugins/Tia/JsModuleGraph.php b/src/Plugins/Tia/JsModuleGraph.php index f97e980c..53259482 100644 --- a/src/Plugins/Tia/JsModuleGraph.php +++ b/src/Plugins/Tia/JsModuleGraph.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Pest\Plugins\Tia; -use Pest\Support\Cpu; use Symfony\Component\Process\ExecutableFinder; use Symfony\Component\Process\Process; @@ -17,49 +16,6 @@ final class JsModuleGraph private const string CACHE_FILE = 'js-module-graph.cache.json'; - private static ?Process $warmer = null; - - private static ?string $warmerFingerprint = null; - - private static bool $warmerCacheHit = false; - - private static ?string $warmerProjectRoot = null; - - public static function warmInBackground(string $projectRoot): void - { - if (self::$warmer instanceof Process || self::$warmerCacheHit) { - return; - } - - if (! self::isApplicable($projectRoot)) { - return; - } - - $fingerprint = self::fingerprint($projectRoot); - - if ($fingerprint !== null && self::readCache($projectRoot, $fingerprint) !== null) { - self::$warmerCacheHit = true; - self::$warmerFingerprint = $fingerprint; - self::$warmerProjectRoot = $projectRoot; - - return; - } - - $process = self::buildNodeProcess($projectRoot); - - if (! $process instanceof Process) { - return; - } - - $process->start(); - - self::$warmer = $process; - self::$warmerFingerprint = $fingerprint; - self::$warmerProjectRoot = $projectRoot; - - register_shutdown_function(self::reapWarmer(...)); - } - /** * @return array> */ @@ -104,33 +60,17 @@ final class JsModuleGraph $cached = self::readCache($projectRoot, $fingerprint); if ($cached !== null) { - self::reapWarmer(); - return $cached; } } - if (self::$warmerCacheHit && $fingerprint !== null) { - $cached = self::readCache($projectRoot, $fingerprint); - self::$warmerCacheHit = false; - self::$warmerFingerprint = null; - self::$warmerProjectRoot = null; - - if ($cached !== null) { - return $cached; - } - } - - $process = self::$warmer; - self::$warmer = null; - self::$warmerFingerprint = null; - self::$warmerProjectRoot = null; + $process = self::buildNodeProcess($projectRoot); if (! $process instanceof Process) { return null; } - $process->wait(); + $process->run(); if (! $process->isSuccessful()) { return null; @@ -167,16 +107,7 @@ final class JsModuleGraph return null; } - $env = ['TIA_VITE_CONCURRENCY' => (string) max(4, min(32, Cpu::cores() * 2))]; - foreach (['resources/js/Pages', 'resources/js/pages'] as $candidate) { - if (is_dir($projectRoot.DIRECTORY_SEPARATOR.$candidate)) { - $env['TIA_VITE_PAGES_DIR'] = $candidate; - - break; - } - } - - $process = new Process([$nodeBinary, $helperPath, $projectRoot], $projectRoot, $env); + $process = new Process([$nodeBinary, $helperPath, $projectRoot], $projectRoot); $process->setTimeout(self::NODE_TIMEOUT_SECONDS); return $process; @@ -222,27 +153,6 @@ final class JsModuleGraph return $out; } - private static function reapWarmer(): void - { - $process = self::$warmer; - self::$warmer = null; - self::$warmerFingerprint = null; - self::$warmerProjectRoot = null; - self::$warmerCacheHit = false; - - if (! $process instanceof Process) { - return; - } - - try { - if ($process->isRunning()) { - $process->stop(0.5); - } - } catch (\Throwable) { - // - } - } - private static function fingerprint(string $projectRoot): ?string { if (! self::hasViteConfig($projectRoot)) {