Skip to content

Commit

Permalink
fix: build task once per execution, not once per file (#148)
Browse files Browse the repository at this point in the history
closes #147
  • Loading branch information
g105b committed Sep 30, 2021
1 parent 2c99952 commit 09ac7fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Build.php
Expand Up @@ -45,12 +45,12 @@ public function check(array &$errors = null):int {
*/
public function build(array &$errors = null):array {
$updatedTasks = [];
foreach($this->taskList as $pathMatch => $task) {
foreach($this->taskList as $task) {
if($task->build($errors)) {
$updatedTasks []= $task;
}
}

return $updatedTasks;
}
}
}
11 changes: 7 additions & 4 deletions src/Task.php
Expand Up @@ -57,20 +57,23 @@ public function check(array &$errors = null):void {
}

public function build(array &$errors = null):bool {
$changes = false;
$hashMiss = false;

foreach(Glob::glob($this->absolutePath) as $matchedPath) {
$hash = filemtime($matchedPath);
$existingHash = $this->fileHashList[$matchedPath] ?? null;

if($hash !== $existingHash) {
$changes = $this->execute($errors);
$hashMiss = true;
}

$this->fileHashList[$matchedPath] = $hash;
}

return $changes;
if($hashMiss) {
return $this->execute($errors);
}
return false;
}

public function requirementFromRequireBlockItem(
Expand Down Expand Up @@ -160,4 +163,4 @@ protected function isAbsolutePath(string $path):bool {
// Windows:
|| preg_match('~\A[A-Z]:(?![^/\\\\])~i',$path) > 0;
}
}
}

0 comments on commit 09ac7fc

Please sign in to comment.