Fix npm build permissions for public assets

This commit is contained in:
root
2026-02-01 01:51:01 +02:00
parent cb845e88c2
commit a024093e8c
3 changed files with 30 additions and 1 deletions

View File

@@ -1 +1 @@
VERSION=0.9-rc36 VERSION=0.9-rc37

View File

@@ -186,6 +186,7 @@ class UpgradeCommand extends Command
$this->ensureCommandAvailable('npm'); $this->ensureCommandAvailable('npm');
$this->ensureNpmCacheDirectory(); $this->ensureNpmCacheDirectory();
$this->ensureNodeModulesPermissions(); $this->ensureNodeModulesPermissions();
$this->ensurePublicBuildPermissions();
if (! $this->isNodeModulesWritable()) { if (! $this->isNodeModulesWritable()) {
$this->warn('Skipping frontend build because node_modules is not writable by the current user.'); $this->warn('Skipping frontend build because node_modules is not writable by the current user.');
$this->warn('Run: sudo chown -R www-data:www-data '.$this->getNodeModulesPath()); $this->warn('Run: sudo chown -R www-data:www-data '.$this->getNodeModulesPath());
@@ -208,6 +209,7 @@ class UpgradeCommand extends Command
} }
$this->ensureNodeModulesPermissions(); $this->ensureNodeModulesPermissions();
$this->ensurePublicBuildPermissions();
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->error('Asset build failed: '.$e->getMessage()); $this->error('Asset build failed: '.$e->getMessage());
@@ -437,6 +439,7 @@ class UpgradeCommand extends Command
$this->basePath.'/database', $this->basePath.'/database',
$this->basePath.'/storage', $this->basePath.'/storage',
$this->getNodeModulesPath(), $this->getNodeModulesPath(),
$this->getPublicBuildPath(),
$this->getNpmCacheDir(), $this->getNpmCacheDir(),
$this->getPuppeteerCacheDir(), $this->getPuppeteerCacheDir(),
$this->getXdgCacheDir(), $this->getXdgCacheDir(),
@@ -494,6 +497,26 @@ class UpgradeCommand extends Command
$this->executeCommand('chmod -R u+rwX '.escapeshellarg($nodeModules)); $this->executeCommand('chmod -R u+rwX '.escapeshellarg($nodeModules));
} }
protected function ensurePublicBuildPermissions(): void
{
$buildPath = $this->getPublicBuildPath();
if (! File::exists($buildPath)) {
File::ensureDirectoryExists($buildPath);
}
if ($this->isRunningAsRoot() && $this->userExists('www-data')) {
$escaped = escapeshellarg($buildPath);
$this->executeCommand("chgrp -R www-data {$escaped}");
$this->executeCommand("chmod -R g+rwX {$escaped}");
$this->executeCommand("find {$escaped} -type d -exec chmod g+s {} +");
return;
}
$this->executeCommand('chmod -R u+rwX '.escapeshellarg($buildPath));
}
protected function isNodeModulesWritable(): bool protected function isNodeModulesWritable(): bool
{ {
$nodeModules = $this->getNodeModulesPath(); $nodeModules = $this->getNodeModulesPath();
@@ -524,6 +547,11 @@ class UpgradeCommand extends Command
return $this->basePath.'/node_modules'; return $this->basePath.'/node_modules';
} }
protected function getPublicBuildPath(): string
{
return $this->basePath.'/public/build';
}
protected function getPuppeteerCacheDir(): string protected function getPuppeteerCacheDir(): string
{ {
return $this->basePath.'/storage/puppeteer-cache'; return $this->basePath.'/storage/puppeteer-cache';

View File

@@ -133,6 +133,7 @@ class UpgradeCommandTest extends TestCase
base_path().'/database', base_path().'/database',
base_path().'/storage', base_path().'/storage',
base_path().'/node_modules', base_path().'/node_modules',
base_path().'/public/build',
base_path().'/storage/npm-cache', base_path().'/storage/npm-cache',
base_path().'/storage/puppeteer-cache', base_path().'/storage/puppeteer-cache',
base_path().'/storage/.cache', base_path().'/storage/.cache',