Skip to content

Commit 60367c7

Browse files
authored
Merge pull request #15 from hotwired-laravel/fix-windows-manifest
Fix Manifest Generation on Windows
2 parents a605e47 + ff81a2b commit 60367c7

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

config/stimulus-laravel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use HotwiredLaravel\StimulusLaravel\Features;
44

55
return [
6-
'controllers_path' => resource_path('js/controllers'),
6+
'controllers_path' => resource_path(implode(DIRECTORY_SEPARATOR, ['js', 'controllers'])),
77
'features' => [
88
Features::directives(),
99
],

src/Manifest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public function generateFrom(string $controllersPath): Collection
1616
->values()
1717
->map(function (SplFileInfo $file) use ($controllersPath) {
1818
$controllerPath = $this->relativePathFrom($file->getRealPath(), $controllersPath);
19-
$modulePath = Str::before($controllerPath, '.');
19+
$modulePath = Str::of($controllerPath)->before('.')->replace(DIRECTORY_SEPARATOR, '/')->toString();
2020
$controllerClassName = Str::of($modulePath)
21-
->explode(DIRECTORY_SEPARATOR)
21+
->explode('/')
2222
->map(fn ($piece) => Str::studly($piece))
2323
->join('__');
24-
$tagName = Str::of($modulePath)->before('_controller')->replace('_', '-')->replace(DIRECTORY_SEPARATOR, '--')->toString();
24+
$tagName = Str::of($modulePath)->before('_controller')->replace('_', '-')->replace('/', '--')->toString();
2525

2626
$join = function ($paths) {
27-
return implode(DIRECTORY_SEPARATOR, $paths);
27+
return implode('/', $paths);
2828
};
2929

3030
return <<<JS

tests/ManifestTest.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,52 @@ class ManifestTest extends TestCase
99
/** @test */
1010
public function generates_controllers_imports_given_a_path()
1111
{
12-
$join = function ($paths) {
13-
return implode(DIRECTORY_SEPARATOR, $paths);
14-
};
15-
$manifest = (new Manifest)->generateFrom($join([
12+
$manifest = (new Manifest)->generateFrom(implode(DIRECTORY_SEPARATOR, [
1613
__DIR__,
1714
'stubs',
1815
'controllers',
1916
]).DIRECTORY_SEPARATOR)->join(PHP_EOL);
2017

2118
$this->assertStringContainsString(
22-
<<<JS
19+
<<<'JS'
2320
24-
import HelloController from '{$join(['.', 'hello_controller'])}'
21+
import HelloController from './hello_controller'
2522
application.register('hello', HelloController)
2623
JS,
2724
$manifest,
2825
);
2926

3027
$this->assertStringContainsString(
31-
<<<JS
28+
<<<'JS'
3229
33-
import Nested__DeepController from '{$join(['.', 'nested', 'deep_controller'])}'
30+
import Nested__DeepController from './nested/deep_controller'
3431
application.register('nested--deep', Nested__DeepController)
3532
JS,
3633
$manifest,
3734
);
3835

3936
$this->assertStringContainsString(
40-
<<<JS
37+
<<<'JS'
4138
42-
import CoffeeController from '{$join(['.', 'coffee_controller'])}'
39+
import CoffeeController from './coffee_controller'
4340
application.register('coffee', CoffeeController)
4441
JS,
4542
$manifest,
4643
);
4744

4845
$this->assertStringContainsString(
49-
<<<JS
46+
<<<'JS'
5047
51-
import TypeScriptController from '{$join(['.', 'type_script_controller'])}'
48+
import TypeScriptController from './type_script_controller'
5249
application.register('type-script', TypeScriptController)
5350
JS,
5451
$manifest,
5552
);
5653

5754
$this->assertStringNotContainsString(
58-
<<<JS
55+
<<<'JS'
5956
60-
import Index from '{$join(['.', 'index'])}'
57+
import Index from './index'
6158
application.register('index', Index)
6259
JS,
6360
$manifest,

0 commit comments

Comments
 (0)