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
9 changes: 9 additions & 0 deletions src/Actions/GetNodeVersionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ private function resolveVersion(): ?string

protected function resolveVersionFromBinary(): ?string
{
if (! $this->canUseShellExec()) {
return null;
}

$output = shell_exec('node --version 2>/dev/null');

if (blank($output)) {
Expand All @@ -59,4 +63,9 @@ protected function resolveVersionFromBinary(): ?string

return preg_match('/^\d+\.\d+/', $version) ? $version : null;
}

protected function canUseShellExec(): bool
{
return function_exists('shell_exec');
}
}
21 changes: 21 additions & 0 deletions tests/GetNodeVersionActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ protected function resolveVersionFromBinary(): ?string
rmdir($dir);
});

test('reads version from .nvmrc when shell_exec is disabled', function () {
$dir = sys_get_temp_dir().'/kite-sdk-test-'.uniqid();
mkdir($dir);
file_put_contents($dir.'/.nvmrc', '20.11.0');

$action = new class($dir) extends GetNodeVersionAction
{
protected function canUseShellExec(): bool
{
return false;
}
};

$result = $action->handle(new Collection, fn ($data) => $data);

expect($result[0]['value'])->toBe('20.11.0');

unlink($dir.'/.nvmrc');
rmdir($dir);
});

test('strips leading v from .nvmrc version', function () {
$dir = sys_get_temp_dir().'/kite-sdk-test-'.uniqid();
mkdir($dir);
Expand Down
Loading