Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Console/Commands/SetupCpVite.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function handle(): void

private function installDependencies(): self
{
spin(
$result = spin(
callback: function () {
$packageJsonPath = base_path('package.json');
$contents = File::json($packageJsonPath);
Expand All @@ -63,13 +63,18 @@ private function installDependencies(): self

File::put($packageJsonPath, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

Process::path(base_path())->run('npm install', function (string $type, string $buffer) {
echo $buffer;
});
return Process::path(base_path())->run('npm install');
},
message: 'Installing dependencies...'
);

if ($result->failed()) {
$this->line($result->errorOutput() ?: $result->output());
$this->components->error('Failed to install dependencies. You need to run "npm install" manually.');

return $this;
}

$this->components->info('Installed dependencies');

return $this;
Expand Down
18 changes: 18 additions & 0 deletions tests/Console/Commands/SetupCpViteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,24 @@ public function boot(): void
PHP, $this->files->get(app_path('Providers/AppServiceProvider.php')));
}

#[Test]
public function it_shows_error_when_npm_install_fails_but_continues()
{
Process::fake([
'*' => Process::result(
output: '',
errorOutput: 'npm ERR! code ERESOLVE',
exitCode: 1,
),
]);

$this
->artisan('statamic:setup-cp-vite')
->expectsOutputToContain('Failed to install dependencies')
->expectsOutputToContain('npm ERR! code ERESOLVE')
->expectsOutputToContain('Added cp:dev and cp:build scripts to package.json');
}

private function makeNecessaryFiles(): void
{
$this->files->put(app_path('Providers/AppServiceProvider.php'), <<<'PHP'
Expand Down