mirror of
https://github.com/pestphp/pest.git
synced 2026-06-05 02:52:12 +02:00
wip
This commit is contained in:
@ -630,10 +630,6 @@ final class Tia implements AddsOutput, HandlesArguments, Terminable
|
|||||||
$this->state->write(self::KEY_COVERAGE_MARKER, '');
|
$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)) {
|
if ($this->piggybackCoverage && ! $this->state->exists(self::KEY_COVERAGE_CACHE)) {
|
||||||
return $this->enterRecordMode($arguments);
|
return $this->enterRecordMode($arguments);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Plugins\Tia;
|
namespace Pest\Plugins\Tia;
|
||||||
|
|
||||||
use Pest\Support\Cpu;
|
|
||||||
use Symfony\Component\Process\ExecutableFinder;
|
use Symfony\Component\Process\ExecutableFinder;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
@ -17,49 +16,6 @@ final class JsModuleGraph
|
|||||||
|
|
||||||
private const string CACHE_FILE = 'js-module-graph.cache.json';
|
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<string, list<string>>
|
* @return array<string, list<string>>
|
||||||
*/
|
*/
|
||||||
@ -104,33 +60,17 @@ final class JsModuleGraph
|
|||||||
$cached = self::readCache($projectRoot, $fingerprint);
|
$cached = self::readCache($projectRoot, $fingerprint);
|
||||||
|
|
||||||
if ($cached !== null) {
|
if ($cached !== null) {
|
||||||
self::reapWarmer();
|
|
||||||
|
|
||||||
return $cached;
|
return $cached;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::$warmerCacheHit && $fingerprint !== null) {
|
$process = self::buildNodeProcess($projectRoot);
|
||||||
$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;
|
|
||||||
|
|
||||||
if (! $process instanceof Process) {
|
if (! $process instanceof Process) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$process->wait();
|
$process->run();
|
||||||
|
|
||||||
if (! $process->isSuccessful()) {
|
if (! $process->isSuccessful()) {
|
||||||
return null;
|
return null;
|
||||||
@ -167,16 +107,7 @@ final class JsModuleGraph
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$env = ['TIA_VITE_CONCURRENCY' => (string) max(4, min(32, Cpu::cores() * 2))];
|
$process = new Process([$nodeBinary, $helperPath, $projectRoot], $projectRoot);
|
||||||
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->setTimeout(self::NODE_TIMEOUT_SECONDS);
|
$process->setTimeout(self::NODE_TIMEOUT_SECONDS);
|
||||||
|
|
||||||
return $process;
|
return $process;
|
||||||
@ -222,27 +153,6 @@ final class JsModuleGraph
|
|||||||
return $out;
|
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
|
private static function fingerprint(string $projectRoot): ?string
|
||||||
{
|
{
|
||||||
if (! self::hasViteConfig($projectRoot)) {
|
if (! self::hasViteConfig($projectRoot)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user