• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14322727335

07 Apr 2025 03:10PM UTC coverage: 81.259% (+0.4%) from 80.906%
14322727335

push

github

web-flow
fix(support): non-dev bun dependencies installation (#1124)

0 of 12 new or added lines in 1 file covered. (0.0%)

25 existing lines in 6 files now uncovered.

11434 of 14071 relevant lines covered (81.26%)

105.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.06
/src/Tempest/Support/src/JavaScript/DependencyInstaller.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Support\JavaScript;
6

7
use Symfony\Component\Process\Process;
8
use Tempest\Console\Console;
9
use Tempest\Validation\Rules\Enum;
10

11
use function Tempest\Support\Arr\wrap;
12

13
/**
14
 * Helps with installing JavaScript dependencies in a directory.
15
 */
16
final readonly class DependencyInstaller
17
{
18
    public function __construct(
6✔
19
        private Console $console,
20
    ) {}
6✔
21

22
    /**
23
     * Installs the specified JavaScript dependencies.
24
     * The package manager will be detected from the lockfile present in `$cwd`. If none found, it will be prompted to the user.
25
     */
26
    public function installDependencies(string $cwd, string|array $dependencies, bool $dev = false): void
×
27
    {
28
        /** @var PackageManager */
29
        $packageManager = PackageManager::detect($cwd) ?? $this->console->ask(
×
30
            question: 'Which package manager do you wish to use?',
×
31
            options: PackageManager::class,
×
32
            default: PackageManager::BUN,
×
33
            validation: [
×
34
                new Enum(PackageManager::class),
×
35
            ],
×
36
        );
×
37

38
        $this->console->task('Installing dependencies', $this->getInstallProcess($packageManager, $cwd, $dependencies, $dev));
×
39
    }
40

41
    /**
42
     * Installs dependencies without interacting with the console.
43
     */
44
    public function silentlyInstallDependencies(string $cwd, string|array $dependencies, bool $dev = false, ?PackageManager $defaultPackageManager = null): void
×
45
    {
46
        $install = $this->getInstallProcess(
×
47
            packageManager: PackageManager::detect($cwd) ?? $defaultPackageManager,
×
48
            cwd: $cwd,
×
49
            dependencies: $dependencies,
×
50
            dev: $dev,
×
51
        );
×
52

53
        $install->mustRun();
×
54
    }
55

56
    /**
57
     * Gets the `Process` instance that will install the specified dependencies.
58
     */
59
    private function getInstallProcess(PackageManager $packageManager, string $cwd, string|array $dependencies, bool $dev = false): Process
×
60
    {
NEW
61
        return new Process(
×
NEW
62
            array_filter(
×
NEW
63
                [
×
NEW
64
                    $packageManager->getBinaryName(),
×
NEW
65
                    $packageManager->getInstallCommand(),
×
NEW
66
                    $dev ? '-D' : null,
×
NEW
67
                    ...wrap($dependencies),
×
NEW
68
                ],
×
NEW
69
                fn (?string $arg): bool => $arg !== null,
×
NEW
70
            ),
×
NEW
71
            $cwd,
×
NEW
72
        );
×
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc