Skip to content

Commit e0a5af6

Browse files
authored
Merge pull request #1142 from vever001/issue-1141
Trigger composer task also when composer.lock changes.
2 parents 0106169 + 3d53d2c commit e0a5af6

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Task/Composer.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ public function canRunInContext(ContextInterface $context): bool
6767
public function run(ContextInterface $context): TaskResultInterface
6868
{
6969
$config = $this->getConfig()->getOptions();
70+
$composerDir = pathinfo($config['file'], PATHINFO_DIRNAME);
71+
$composerFile = pathinfo($config['file'], PATHINFO_BASENAME);
72+
$composerLockFile = $this->getLockFile($composerFile);
7073
$files = $context->getFiles()
71-
->path(pathinfo($config['file'], PATHINFO_DIRNAME))
72-
->name(pathinfo($config['file'], PATHINFO_BASENAME));
74+
->path($composerDir)
75+
->names([$composerFile, $composerLockFile]);
7376
if (0 === \count($files)) {
7477
return TaskResult::createSkipped($this, $context);
7578
}
@@ -116,4 +119,14 @@ private function hasLocalRepository(SplFileInfo $composerFile): bool
116119

117120
return false;
118121
}
122+
123+
/**
124+
* Verbatim copy from \Composer\Factory::getLockFile.
125+
*/
126+
private static function getLockFile(string $composerFile): string
127+
{
128+
return 'json' === pathinfo($composerFile, PATHINFO_EXTENSION)
129+
? substr($composerFile, 0, -4) . 'lock'
130+
: $composerFile . '.lock';
131+
}
119132
}

test/Unit/Task/ComposerTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ public function provideExternalTaskRuns(): iterable
195195
'./composer.json',
196196
]
197197
];
198+
yield 'lock-only' => [
199+
[],
200+
$this->mockContext(RunContext::class, ['composer.lock']),
201+
'composer',
202+
[
203+
'validate',
204+
'./composer.json',
205+
]
206+
];
198207
yield 'no-check-all' => [
199208
[
200209
'no_check_all' => true,

0 commit comments

Comments
 (0)