Skip to content

Commit a5fd85c

Browse files
authored
chore(vite): show proper run command depending on package manager (#1004)
1 parent fd63ec0 commit a5fd85c

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/Tempest/Support/src/JavaScript/PackageManager.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ public function getBinaryName(): string
3535
};
3636
}
3737

38+
public function getRunCommand(string $script): string
39+
{
40+
return (
41+
$this->getBinaryName() .
42+
' ' .
43+
match ($this) {
44+
self::BUN => $script,
45+
self::NPM => "run {$script}",
46+
self::YARN => $script,
47+
self::PNPM => $script,
48+
}
49+
);
50+
}
51+
3852
public function getInstallCommand(): string
3953
{
4054
return match ($this) {

src/Tempest/Support/tests/JavaScript/PackageManagerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,18 @@ public function test_can_detect_package_manager(string $fixture, ?PackageManager
2727
actual: PackageManager::detect(cwd: __DIR__ . "/Fixtures/{$fixture}"),
2828
);
2929
}
30+
#[TestWith(['bun-lock', 'bun dev'])]
31+
#[TestWith(['bun-lockb', 'bun dev'])]
32+
#[TestWith(['npm', 'npm run dev'])]
33+
#[TestWith(['yarn', 'yarn dev'])]
34+
#[TestWith(['pnpm', 'pnpm dev'])]
35+
#[TestWith(['multiple', 'bun dev'])]
36+
#[TestWith(['empty', null])]
37+
public function test_print_run_command(string $fixture, ?string $expectedCommand): void
38+
{
39+
$this->assertSame(
40+
expected: $expectedCommand,
41+
actual: PackageManager::detect(cwd: __DIR__ . "/Fixtures/{$fixture}")?->getRunCommand('dev'),
42+
);
43+
}
3044
}

src/Tempest/Vite/src/Installer/ViteInstaller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function install(): void
110110
json_encode(array_filter([$mainCss, $mainTs]), JSON_UNESCAPED_SLASHES),
111111
)
112112
: 'Create a file and include it in your template with <code><x-vite-tags entrypoint="./path/to/file.ts" /></code>',
113-
"Run <code>{$packageManager->getBinaryName()} dev</code> to start the <strong>development server</strong>",
113+
"Run <code>{$packageManager->getRunCommand('dev')}</code> to start the <strong>development server</strong>",
114114
PHP_EOL,
115115
// '<style="fg-green">→</style> Read the <href="https://tempestphp.com/ocs/framework/vite">documentation</href>', // TODO: update when we have Vite docs
116116
'<style="fg-green">→</style> Join the <href="https://tempestphp.com/discord">Discord server</href>',

0 commit comments

Comments
 (0)