Skip to content

Commit b487f05

Browse files
committed
[cache] Cache unchanged files on --dry-run
1 parent 7a32610 commit b487f05

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Parallel\ValueObject;
6+
7+
use Rector\Core\ValueObject\Error\SystemError;
8+
use Rector\Core\ValueObject\Reporting\FileDiff;
9+
10+
final class ProcessFileResult
11+
{
12+
/**
13+
* @param array{system_errors: SystemError[], file_diffs: FileDiff[]} $errorAndFileDiffs
14+
*/
15+
public function __construct(
16+
private readonly bool $isFileChanged,
17+
private readonly array $errorAndFileDiffs
18+
) {
19+
}
20+
21+
public function isFileChanged(): bool
22+
{
23+
return $this->isFileChanged;
24+
}
25+
26+
/**
27+
* @return array{system_errors: SystemError[], file_diffs: FileDiff[]}
28+
*/
29+
public function getErrorAndFileDiffs(): array
30+
{
31+
return $this->errorAndFileDiffs;
32+
}
33+
}

packages/Parallel/WorkerRunner.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Rector\Core\ValueObject\Error\SystemError;
2121
use Rector\Core\ValueObject\Reporting\FileDiff;
2222
use Rector\Parallel\ValueObject\Bridge;
23+
use Rector\Parallel\ValueObject\ProcessFileResult;
2324
use Symplify\EasyParallel\Enum\Action;
2425
use Symplify\EasyParallel\Enum\ReactCommand;
2526
use Symplify\EasyParallel\Enum\ReactEvent;
@@ -93,11 +94,12 @@ public function run(Encoder $encoder, Decoder $decoder, Configuration $configura
9394
$file = new File($filePath, FileSystem::read($filePath));
9495
$this->currentFileProvider->setFile($file);
9596

96-
$errorAndFileDiffs = $this->processFile($file, $configuration, $errorAndFileDiffs);
97+
$processFileResult = $this->processFile($file, $configuration, $errorAndFileDiffs);
98+
$errorAndFileDiffs = $processFileResult->getErrorAndFileDiffs();
9799

98100
if ($errorAndFileDiffs[Bridge::SYSTEM_ERRORS] !== []) {
99101
$this->invalidateFile($file);
100-
} elseif (! $configuration->isDryRun()) {
102+
} elseif (! $configuration->isDryRun() || $processFileResult->isFileChanged()) {
101103
$this->changedFilesDetector->cacheFileWithDependencies($file->getFilePath());
102104
}
103105
} catch (Throwable $throwable) {
@@ -129,23 +131,24 @@ public function run(Encoder $encoder, Decoder $decoder, Configuration $configura
129131

130132
/**
131133
* @param array{system_errors: SystemError[], file_diffs: FileDiff[]}|mixed[] $errorAndFileDiffs
132-
* @return array{system_errors: SystemError[], file_diffs: FileDiff[]}
133134
*/
134-
private function processFile(File $file, Configuration $configuration, array $errorAndFileDiffs): array
135+
private function processFile(File $file, Configuration $configuration, array $errorAndFileDiffs): ProcessFileResult
135136
{
137+
$wasFileChanged = false;
136138
foreach ($this->fileProcessors as $fileProcessor) {
137139
if (! $fileProcessor->supports($file, $configuration)) {
138140
continue;
139141
}
140142

141143
$currentErrorsAndFileDiffs = $fileProcessor->process($file, $configuration);
144+
$wasFileChanged = $wasFileChanged || $currentErrorsAndFileDiffs[Bridge::FILE_DIFFS] !== [];
142145
$errorAndFileDiffs = $this->arrayParametersMerger->merge(
143146
$errorAndFileDiffs,
144147
$currentErrorsAndFileDiffs
145148
);
146149
}
147150

148-
return $errorAndFileDiffs;
151+
return new ProcessFileResult($wasFileChanged, $errorAndFileDiffs);
149152
}
150153

151154
/**

0 commit comments

Comments
 (0)