Skip to content

Commit da7006f

Browse files
authored
fix(support): non-dev bun dependencies installation (#1124)
1 parent 13f48c2 commit da7006f

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/Tempest/Support/src/JavaScript/DependencyInstaller.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ public function silentlyInstallDependencies(string $cwd, string|array $dependenc
5858
*/
5959
private function getInstallProcess(PackageManager $packageManager, string $cwd, string|array $dependencies, bool $dev = false): Process
6060
{
61-
return new Process([
62-
$packageManager->getBinaryName(),
63-
$packageManager->getInstallCommand(),
64-
$dev ? '-D' : '',
65-
...wrap($dependencies),
66-
], $cwd);
61+
return new Process(
62+
array_filter(
63+
[
64+
$packageManager->getBinaryName(),
65+
$packageManager->getInstallCommand(),
66+
$dev ? '-D' : null,
67+
...wrap($dependencies),
68+
],
69+
fn (?string $arg): bool => $arg !== null,
70+
),
71+
$cwd,
72+
);
6773
}
6874
}

tests/Integration/Support/DependencyInstallerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ public function test_asks_for_package_manager(): void
5858
});
5959
}
6060

61+
#[TestWith(['bun.lock'])]
62+
#[TestWith(['package-lock.json'])]
63+
public function test_can_install_non_dev_dependencies(string $lockfile): void
64+
{
65+
$this->callInTemporaryDirectory(function (string $directory) use ($lockfile): void {
66+
file_put_contents("{$directory}/package.json", data: '{}');
67+
file_put_contents("{$directory}/{$lockfile}", data: null);
68+
69+
$installer = $this->container->get(DependencyInstaller::class);
70+
$installer->silentlyInstallDependencies($directory, 'vite-plugin-tempest', dev: false);
71+
72+
$this->assertTrue(is_dir($directory . '/node_modules'), message: 'Dependencies were not installed.');
73+
$this->assertNotNull(json_decode(file_get_contents($directory . '/package.json'), associative: true)['dependencies']['vite-plugin-tempest']);
74+
});
75+
}
76+
6177
private function callInTemporaryDirectory(Closure $callback): void
6278
{
6379
$directory = __DIR__ . '/Fixtures/tmp';

0 commit comments

Comments
 (0)