Skip to content

Commit 3ccf199

Browse files
authored
Sync changes if executable path from main (#514)
Signed-off-by: Pushpak Chhajed <pushpak1300@gmail.com>
1 parent cbbdfb6 commit 3ccf199

File tree

6 files changed

+225
-42
lines changed

6 files changed

+225
-42
lines changed

config/boost.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,27 @@
2525
| The following option may be used to enable or disable the browser logs
2626
| watcher feature within Laravel Boost. The log watcher will read any
2727
| errors within the browser's console to give Boost better context.
28+
|
2829
*/
2930

3031
'browser_logs_watcher' => env('BOOST_BROWSER_LOGS_WATCHER', true),
3132

3233
/*
3334
|--------------------------------------------------------------------------
34-
| Boost Executables Config
35+
| Boost Executables Paths
3536
|--------------------------------------------------------------------------
3637
|
37-
| The following options allow you to configure custom paths for the PHP,
38-
| Composer, and npm executables used by Boost. Leave empty to use defaults.
39-
| When configured, these take precedence over automatic detection.
38+
| These options allow you to specify custom paths for the executables that
39+
| Boost uses. When configured, they take precedence over the automatic
40+
| discovery mechanism. Leave empty to use defaults from your $PATH.
4041
|
4142
*/
4243

43-
'executables' => [
44-
'php' => env('BOOST_PHP_EXECUTABLE'),
45-
'composer' => env('BOOST_COMPOSER_EXECUTABLE'),
46-
'npm' => env('BOOST_NPM_EXECUTABLE'),
47-
'vendor_bin' => env('BOOST_VENDOR_BIN_EXECUTABLE'),
44+
'executable_paths' => [
45+
'php' => env('BOOST_PHP_EXECUTABLE_PATH'),
46+
'composer' => env('BOOST_COMPOSER_EXECUTABLE_PATH'),
47+
'npm' => env('BOOST_NPM_EXECUTABLE_PATH'),
48+
'vendor_bin' => env('BOOST_VENDOR_BIN_EXECUTABLE_PATH'),
4849
],
4950

5051
];

src/Install/CodeEnvironment/CodeEnvironment.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function useAbsolutePathForMcp(): bool
4040

4141
public function getPhpPath(bool $forceAbsolutePath = false): string
4242
{
43-
$phpBinaryPath = config('boost.executables.php') ?? 'php';
43+
$phpBinaryPath = config('boost.executable_paths.php') ?? 'php';
4444

4545
if ($phpBinaryPath === 'php' && ($this->useAbsolutePathForMcp() || $forceAbsolutePath)) {
4646
return PHP_BINARY;
@@ -185,6 +185,8 @@ protected function installShellMcp(string $key, string $command, array $args = [
185185
return false;
186186
}
187187

188+
$normalized = $this->normalizeCommand($command, $args);
189+
188190
// Build environment string
189191
$envString = '';
190192
foreach ($env as $envKey => $value) {
@@ -200,8 +202,8 @@ protected function installShellMcp(string $key, string $command, array $args = [
200202
'{env}',
201203
], [
202204
$key,
203-
$command,
204-
implode(' ', array_map(fn (string $arg): string => '"'.$arg.'"', $args)),
205+
$normalized['command'],
206+
implode(' ', array_map(fn (string $arg): string => '"'.$arg.'"', $normalized['args'])),
205207
trim($envString),
206208
], $shellCommand);
207209

@@ -226,9 +228,27 @@ protected function installFileMcp(string $key, string $command, array $args = []
226228
return false;
227229
}
228230

231+
$normalized = $this->normalizeCommand($command, $args);
232+
229233
return (new FileWriter($path, $this->defaultMcpConfig()))
230234
->configKey($this->mcpConfigKey())
231-
->addServerConfig($key, $this->mcpServerConfig($command, $args, $env))
235+
->addServerConfig($key, $this->mcpServerConfig($normalized['command'], $normalized['args'], $env))
232236
->save();
233237
}
238+
239+
/**
240+
* Normalize command by splitting space-separated commands into command + args.
241+
*
242+
* @param array<int, string> $args
243+
* @return array{command: string, args: array<int, string>}
244+
*/
245+
protected function normalizeCommand(string $command, array $args = []): array
246+
{
247+
$parts = str($command)->explode(' ');
248+
249+
return [
250+
'command' => $parts->first(),
251+
'args' => $parts->skip(1)->values()->merge($args)->all(),
252+
];
253+
}
234254
}

src/Install/GuidelineAssist.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function detectedNodePackageManager(): string
177177

178178
public function nodePackageManagerCommand(string $command): string
179179
{
180-
$npmExecutable = config('boost.executables.npm');
180+
$npmExecutable = config('boost.executable_paths.npm');
181181

182182
if ($npmExecutable !== null) {
183183
return "{$npmExecutable} {$command}";
@@ -197,7 +197,7 @@ public function artisanCommand(string $command): string
197197

198198
public function composerCommand(string $command): string
199199
{
200-
$composerExecutable = config('boost.executables.composer');
200+
$composerExecutable = config('boost.executable_paths.composer');
201201

202202
if ($composerExecutable !== null) {
203203
return "{$composerExecutable} {$command}";
@@ -212,7 +212,7 @@ public function composerCommand(string $command): string
212212

213213
public function binCommand(string $command): string
214214
{
215-
$vendorBinPrefix = config('boost.executables.vendor_bin');
215+
$vendorBinPrefix = config('boost.executable_paths.vendor_bin');
216216

217217
if ($vendorBinPrefix !== null) {
218218
return "{$vendorBinPrefix}{$command}";
@@ -227,7 +227,7 @@ public function binCommand(string $command): string
227227

228228
public function artisan(): string
229229
{
230-
$phpExecutable = config('boost.executables.php');
230+
$phpExecutable = config('boost.executable_paths.php');
231231

232232
if ($phpExecutable !== null) {
233233
return "{$phpExecutable} artisan";

tests/Feature/Install/CodeEnvironment/CodeEnvironmentPathResolutionTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Laravel\Boost\Install\Detection\DetectionStrategyFactory;
88

99
test('PhpStorm returns absolute PHP_BINARY path', function (): void {
10-
config(['boost.executables.php' => null]);
10+
config(['boost.executable_paths.php' => null]);
1111
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
1212
$phpStorm = new PhpStorm($strategyFactory);
1313

@@ -26,15 +26,15 @@
2626
});
2727

2828
test('Cursor returns relative php string', function (): void {
29-
config(['boost.executables.php' => null]);
29+
config(['boost.executable_paths.php' => null]);
3030
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
3131
$cursor = new Cursor($strategyFactory);
3232

3333
expect($cursor->getPhpPath())->toBe('php');
3434
});
3535

3636
test('Cursor uses configured default_php_bin when not forcing absolute path', function (): void {
37-
config(['boost.executables.php' => '/custom/path/to/php']);
37+
config(['boost.executable_paths.php' => '/custom/path/to/php']);
3838

3939
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
4040
$cursor = new Cursor($strategyFactory);
@@ -43,7 +43,7 @@
4343
});
4444

4545
test('Cursor uses config even when forceAbsolutePath is true', function (): void {
46-
config(['boost.executables.php' => '/custom/path/to/php']);
46+
config(['boost.executable_paths.php' => '/custom/path/to/php']);
4747

4848
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
4949
$cursor = new Cursor($strategyFactory);
@@ -52,7 +52,7 @@
5252
});
5353

5454
test('Cursor uses PHP_BINARY when forceAbsolutePath is true and config is empty', function (): void {
55-
config(['boost.executables.php' => null]);
55+
config(['boost.executable_paths.php' => null]);
5656

5757
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
5858
$cursor = new Cursor($strategyFactory);
@@ -68,7 +68,7 @@
6868
});
6969

7070
test('CodeEnvironment returns absolute paths when forceAbsolutePath is true and config is empty', function (): void {
71-
config(['boost.executables.php' => null]);
71+
config(['boost.executable_paths.php' => null]);
7272
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
7373
$cursor = new Cursor($strategyFactory);
7474

@@ -78,7 +78,7 @@
7878
});
7979

8080
test('CodeEnvironment maintains relative paths when forceAbsolutePath is false and config is empty', function (): void {
81-
config(['boost.executables.php' => null]);
81+
config(['boost.executable_paths.php' => null]);
8282
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
8383
$cursor = new Cursor($strategyFactory);
8484

@@ -87,7 +87,7 @@
8787
});
8888

8989
test('PhpStorm paths remain absolute regardless of forceAbsolutePath parameter', function (): void {
90-
config(['boost.executables.php' => null]);
90+
config(['boost.executable_paths.php' => null]);
9191
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
9292
$phpStorm = new PhpStorm($strategyFactory);
9393

@@ -103,7 +103,7 @@
103103
});
104104

105105
test('PhpStorm uses config when configured', function (): void {
106-
config(['boost.executables.php' => '/custom/php']);
106+
config(['boost.executable_paths.php' => '/custom/php']);
107107
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
108108
$phpStorm = new PhpStorm($strategyFactory);
109109

0 commit comments

Comments
 (0)