Skip to content

Commit

Permalink
Merge pull request #15 from hotwired-laravel/fix-windows-manifest
Browse files Browse the repository at this point in the history
Fix Manifest Generation on Windows
  • Loading branch information
tonysm authored Aug 31, 2023
2 parents a605e47 + ff81a2b commit 60367c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion config/stimulus-laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use HotwiredLaravel\StimulusLaravel\Features;

return [
'controllers_path' => resource_path('js/controllers'),
'controllers_path' => resource_path(implode(DIRECTORY_SEPARATOR, ['js', 'controllers'])),
'features' => [
Features::directives(),
],
Expand Down
8 changes: 4 additions & 4 deletions src/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public function generateFrom(string $controllersPath): Collection
->values()
->map(function (SplFileInfo $file) use ($controllersPath) {
$controllerPath = $this->relativePathFrom($file->getRealPath(), $controllersPath);
$modulePath = Str::before($controllerPath, '.');
$modulePath = Str::of($controllerPath)->before('.')->replace(DIRECTORY_SEPARATOR, '/')->toString();
$controllerClassName = Str::of($modulePath)
->explode(DIRECTORY_SEPARATOR)
->explode('/')
->map(fn ($piece) => Str::studly($piece))
->join('__');
$tagName = Str::of($modulePath)->before('_controller')->replace('_', '-')->replace(DIRECTORY_SEPARATOR, '--')->toString();
$tagName = Str::of($modulePath)->before('_controller')->replace('_', '-')->replace('/', '--')->toString();

$join = function ($paths) {
return implode(DIRECTORY_SEPARATOR, $paths);
return implode('/', $paths);
};

return <<<JS
Expand Down
25 changes: 11 additions & 14 deletions tests/ManifestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,52 @@ class ManifestTest extends TestCase
/** @test */
public function generates_controllers_imports_given_a_path()
{
$join = function ($paths) {
return implode(DIRECTORY_SEPARATOR, $paths);
};
$manifest = (new Manifest)->generateFrom($join([
$manifest = (new Manifest)->generateFrom(implode(DIRECTORY_SEPARATOR, [
__DIR__,
'stubs',
'controllers',
]).DIRECTORY_SEPARATOR)->join(PHP_EOL);

$this->assertStringContainsString(
<<<JS
<<<'JS'
import HelloController from '{$join(['.', 'hello_controller'])}'
import HelloController from './hello_controller'
application.register('hello', HelloController)
JS,
$manifest,
);

$this->assertStringContainsString(
<<<JS
<<<'JS'
import Nested__DeepController from '{$join(['.', 'nested', 'deep_controller'])}'
import Nested__DeepController from './nested/deep_controller'
application.register('nested--deep', Nested__DeepController)
JS,
$manifest,
);

$this->assertStringContainsString(
<<<JS
<<<'JS'
import CoffeeController from '{$join(['.', 'coffee_controller'])}'
import CoffeeController from './coffee_controller'
application.register('coffee', CoffeeController)
JS,
$manifest,
);

$this->assertStringContainsString(
<<<JS
<<<'JS'
import TypeScriptController from '{$join(['.', 'type_script_controller'])}'
import TypeScriptController from './type_script_controller'
application.register('type-script', TypeScriptController)
JS,
$manifest,
);

$this->assertStringNotContainsString(
<<<JS
<<<'JS'
import Index from '{$join(['.', 'index'])}'
import Index from './index'
application.register('index', Index)
JS,
$manifest,
Expand Down

0 comments on commit 60367c7

Please sign in to comment.