Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/Service/NodePackageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,22 @@ public function installPackageVersions(
*/
public function checkOutdatedPackages(string $path, SymfonyStyle $io): void
{
try {
$outdated = $this->shell->execute('cd %s && npm outdated --json', [$path]);
if ($outdated) {
$io->warning('Outdated packages found:');
$io->writeln($outdated);
}
} catch (\Exception $e) {
$outdated = $this->getOutdatedPackages($path);

if ($outdated === null) {
if ($io->isVerbose()) {
$io->warning('Failed to check outdated packages: ' . $e->getMessage());
$io->warning('Failed to check outdated packages.');
}
return;
}

if ($outdated === []) {
return;
}

$io->warning('Outdated packages found:');
foreach ($outdated as $package) {
$io->writeln(sprintf(' %s: %s -> %s', $package['name'], $package['current'], $package['latest']));
}
}

Expand Down
23 changes: 1 addition & 22 deletions src/Service/ThemeBuilder/MagentoStandard/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function autoRepair(string $themePath, SymfonyStyle $io, OutputInterface

// Check for outdated packages
if ($isVerbose) {
$this->checkOutdatedPackages($io);
$this->nodePackageManager->checkOutdatedPackages($rootPath, $io);
}

return true;
Expand Down Expand Up @@ -214,27 +214,6 @@ private function installGruntIfMissing(SymfonyStyle $io, bool $isVerbose): bool
}
}

/**
* Check for outdated packages and report them
*
* @param SymfonyStyle $io
* @return void
*/
private function checkOutdatedPackages(SymfonyStyle $io): void
{
try {
$outdated = $this->shell->execute('npm outdated --json');
if ($outdated) {
$io->warning('Outdated packages found:');
$io->writeln($outdated);
}
} catch (\Exception $e) {
if ($io->isVerbose()) {
$io->warning('Failed to check outdated packages: ' . $e->getMessage());
}
}
}

/**
* Run watch mode for Magento standard theme assets.
*
Expand Down
29 changes: 17 additions & 12 deletions tests/Unit/Service/NodePackageManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,23 @@ public function testWarnsAboutOutdatedPackages(): void
$shell
->expects($this->once())
->method('execute')
->with('cd %s && npm outdated --json', ['/theme'])
->willReturn('{"tailwindcss": {"current": "3.0.0", "latest": "4.0.0"}}');
->with('cd %s && npm outdated --json --long 2>/dev/null; true', ['/theme'])
->willReturn('{"tailwindcss": {"current": "3.0.0", "wanted": "3.4.0", "latest": "4.0.0"}}');
$io = $this->createMock(SymfonyStyle::class);
$io->expects($this->once())->method('warning')->with('Outdated packages found:');
$io
->expects($this->once())
->method('writeln')
->with('{"tailwindcss": {"current": "3.0.0", "latest": "4.0.0"}}');
$io->expects($this->once())->method('writeln')->with(' tailwindcss: 3.0.0 -> 4.0.0');

$packageManager = $this->createPackageManager(shell: $shell);

$packageManager->checkOutdatedPackages('/theme', $io);
}

public function testStaysSilentWhenEverythingIsUpToDate(): void
public function testStaysSilentWhenNpmReportsEmptyObject(): void
{
$this->shell->method('execute')->willReturn('');
$this->shell->method('execute')->willReturn('{}');
$io = $this->createMock(SymfonyStyle::class);
$io->expects($this->never())->method('warning');
$io->expects($this->never())->method('writeln');

$this->packageManager->checkOutdatedPackages('/theme', $io);
}
Expand All @@ -235,10 +233,17 @@ public function testReportsCheckFailureOnlyInVerboseMode(): void
$this->shell->method('execute')->willThrowException(new \RuntimeException('registry unreachable'));
$io = $this->createMock(SymfonyStyle::class);
$io->method('isVerbose')->willReturn(true);
$io
->expects($this->once())
->method('warning')
->with('Failed to check outdated packages: registry unreachable');
$io->expects($this->once())->method('warning')->with('Failed to check outdated packages.');

$this->packageManager->checkOutdatedPackages('/theme', $io);
}

public function testStaysSilentOnCheckFailureWhenNotVerbose(): void
{
$this->shell->method('execute')->willThrowException(new \RuntimeException('registry unreachable'));
$io = $this->createMock(SymfonyStyle::class);
$io->method('isVerbose')->willReturn(false);
$io->expects($this->never())->method('warning');

$this->packageManager->checkOutdatedPackages('/theme', $io);
}
Expand Down
17 changes: 6 additions & 11 deletions tests/Unit/Service/ThemeBuilder/MagentoStandard/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,18 +593,13 @@ public function testAutoRepairSkipsInstallAndOutdatedCheckWhenQuietAndInSync():

public function testAutoRepairChecksOutdatedPackagesInVerboseMode(): void
{
$this->nodePackageManager->method('isNodeModulesInSync')->willReturn(true);

$executedCommands = [];
$this->shell
->method('execute')
->willReturnCallback(function (string $command) use (&$executedCommands): string {
$executedCommands[] = $command;
return '';
});
$nodePackageManager = $this->createMock(NodePackageManager::class);
$nodePackageManager->method('isNodeModulesInSync')->willReturn(true);
$nodePackageManager->expects($this->once())->method('checkOutdatedPackages')->with('/magento-root', $this->io);
$this->shell->method('execute')->willReturn('');
$builder = $this->createBuilder(nodePackageManager: $nodePackageManager);

$this->assertTrue($this->builder->autoRepair($this->themePath, $this->io, $this->output, true));
$this->assertSame(['which grunt', 'npm outdated --json'], $executedCommands);
$this->assertTrue($builder->autoRepair($this->themePath, $this->io, $this->output, true));
}

public function testInstallsGruntWithExactMessagesWhenMissing(): void
Expand Down
Loading