diff --git a/src/Installer/VendorInstaller.php b/src/Installer/VendorInstaller.php index 3f1fb3bc..e7575312 100644 --- a/src/Installer/VendorInstaller.php +++ b/src/Installer/VendorInstaller.php @@ -16,6 +16,7 @@ use MoodlePluginCI\Bridge\MoodlePlugin; use MoodlePluginCI\Process\Execute; use Symfony\Component\Process\Process; +use Symfony\Component\Filesystem\Filesystem; /** * Vendor installer. @@ -119,9 +120,17 @@ public function installNode(): void file_put_contents($this->moodle->directory . '/.nvmrc', $reqversion); } - $nvmDir = getenv('NVM_DIR'); - $cmd = ". $nvmDir/nvm.sh && nvm install && nvm use && echo \"NVM_BIN=\$NVM_BIN\""; + $nvmDir = "{$this->moodle->directory}/.nvm"; + (new Filesystem())->mkdir($nvmDir); + $cmd = "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | NVM_DIR=\"{$nvmDir}\" bash"; + $process = $this->execute->passThroughProcess( + Process::fromShellCommandline($cmd, $this->moodle->directory, null, null, null) + ); + if (!$process->isSuccessful()) { + throw new \RuntimeException('nvm installation failed.'); + } + $cmd = ". {$nvmDir}/nvm.sh && nvm install && nvm use && echo \"NVM_BIN=\$NVM_BIN\""; $process = $this->execute->passThroughProcess( Process::fromShellCommandline($cmd, $this->moodle->directory, null, null, null) );