Fix npm cache permissions for web upgrades

This commit is contained in:
root
2026-02-01 01:16:30 +02:00
parent 8b1acbfa13
commit 029947c0b2

View File

@@ -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}");