Fix npm cache permissions for web upgrades
This commit is contained in:
@@ -184,6 +184,7 @@ class UpgradeCommand extends Command
|
||||
if ($shouldRunNpm) {
|
||||
try {
|
||||
$this->ensureCommandAvailable('npm');
|
||||
$this->ensureNpmCacheDirectory();
|
||||
$npmInstall = File::exists($this->basePath.'/package-lock.json') ? 'npm ci' : 'npm install';
|
||||
$installResult = $this->executeCommand($npmInstall, 1200);
|
||||
if ($installResult['exitCode'] !== 0) {
|
||||
@@ -362,6 +363,7 @@ class UpgradeCommand extends Command
|
||||
return [
|
||||
'PATH' => $path,
|
||||
'COMPOSER_ALLOW_SUPERUSER' => '1',
|
||||
'NPM_CONFIG_CACHE' => $this->getNpmCacheDir(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -423,6 +425,7 @@ class UpgradeCommand extends Command
|
||||
$paths = [
|
||||
$this->basePath.'/database',
|
||||
$this->basePath.'/storage',
|
||||
$this->getNpmCacheDir(),
|
||||
$this->basePath.'/bootstrap/cache',
|
||||
];
|
||||
|
||||
@@ -436,6 +439,24 @@ class UpgradeCommand extends Command
|
||||
];
|
||||
}
|
||||
|
||||
protected function ensureNpmCacheDirectory(): void
|
||||
{
|
||||
$cacheDir = $this->getNpmCacheDir();
|
||||
if (! File::exists($cacheDir)) {
|
||||
File::ensureDirectoryExists($cacheDir);
|
||||
}
|
||||
|
||||
if ($this->isRunningAsRoot() && $this->userExists('www-data')) {
|
||||
$this->executeCommand('chgrp -R www-data '.escapeshellarg($cacheDir));
|
||||
$this->executeCommand('chmod -R g+rwX '.escapeshellarg($cacheDir));
|
||||
}
|
||||
}
|
||||
|
||||
protected function getNpmCacheDir(): string
|
||||
{
|
||||
return $this->basePath.'/storage/npm-cache';
|
||||
}
|
||||
|
||||
protected function commandExists(string $command): bool
|
||||
{
|
||||
$result = $this->executeCommand("command -v {$command}");
|
||||
|
||||
Reference in New Issue
Block a user