diff --git a/src/Installer/VendorInstaller.php b/src/Installer/VendorInstaller.php index dc89d994..3daf18af 100644 --- a/src/Installer/VendorInstaller.php +++ b/src/Installer/VendorInstaller.php @@ -112,16 +112,19 @@ public function canInstallNvm(): bool */ public function installNvm(): void { - $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"; + $cmd = "curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash"; $process = $this->execute->passThroughProcess( Process::fromShellCommandline($cmd, $this->moodle->directory, null, null, null) ); if (!$process->isSuccessful()) { throw new \RuntimeException('nvm installation failed.'); } - putenv('NVM_DIR=' . $nvmDir); + preg_match('/^export NVM_DIR=(.+)$/m', trim($process->getOutput()), $matches); + if (isset($matches[1]) && is_dir($matches[1])) { + putenv('NVM_DIR=' . $matches[1]); + } else { + $this->getOutput()->debug('Can\'t retrieve NVM_DIR content from the command output.'); + } } /** @@ -155,7 +158,7 @@ public function installNode(): void } $nvmDir = getenv('NVM_DIR'); - $cmd = ". $nvmDir/nvm.sh && nvm install && nvm use && echo \"NVM_BIN=\$NVM_BIN\""; + $cmd = ". {$nvmDir}/nvm.sh && nvm --version"; $process = $this->execute->passThroughProcess( Process::fromShellCommandline($cmd, $this->moodle->directory, null, null, null)