Skip to content

Commit d4fae67

Browse files
Fixed watch option not working on files in subfolders (#25)
1 parent 30b1a2c commit d4fae67

File tree

5 files changed

+8
-32
lines changed

5 files changed

+8
-32
lines changed

config/services.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<?php
2-
//
2+
33
use Sensiolabs\TypeScriptBundle\AssetMapper\TypeScriptCompiler;
44
use Sensiolabs\TypeScriptBundle\AssetMapper\TypeScriptPublicPathAssetPathResolver;
55
use Sensiolabs\TypeScriptBundle\Command\TypeScriptBuildCommand;
66
use Sensiolabs\TypeScriptBundle\EventListener\PreAssetsCompileListener;
77
use Sensiolabs\TypeScriptBundle\TypeScriptBuilder;
88
use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent;
99
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
10+
1011
use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
11-
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
1212
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
13+
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
1314

1415
return static function (ContainerConfigurator $container) {
1516
$container->services()
@@ -20,7 +21,6 @@
2021
param('kernel.project_dir'),
2122
abstract_arg('path to the binaries download directory'),
2223
abstract_arg('path to the swc binary'),
23-
abstract_arg('path to the watchexec binary'),
2424
])
2525
->set('sensiolabs_typescript.command.build', TypeScriptBuildCommand::class)
2626
->args([

src/DependencyInjection/SensiolabsTypeScriptExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public function load(array $configs, ContainerBuilder $container): void
3030
->replaceArgument(1, '%kernel.project_dir%/var/typescript')
3131
->replaceArgument(3, $config['binary_download_dir'])
3232
->replaceArgument(4, $config['swc_binary'])
33-
->replaceArgument(5, $config['watchexec_binary']);
34-
33+
;
3534
$container->findDefinition('sensiolabs_typescript.js_asset_compiler')
3635
->replaceArgument(0, $config['source_dir'])
3736
->replaceArgument(1, '%kernel.project_dir%/var/typescript')

src/Tools/WatcherBinary.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public function __construct(
1616
*/
1717
public function startWatch(string $watchPath, callable $callback, array $extensions = []): Process
1818
{
19+
if (!str_ends_with($watchPath, \DIRECTORY_SEPARATOR.'...')) {
20+
$watchPath = rtrim($watchPath, \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR.'...';
21+
}
1922
$process = new Process([$this->executablePath, $watchPath]);
2023

2124
$process->start(function ($type, $buffer) use ($callback, $extensions) {

src/TypeScriptBuilder.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public function __construct(
2222
private readonly string $projectRootDir,
2323
private readonly string $binaryDownloadDir,
2424
private readonly ?string $buildBinaryPath,
25-
private readonly ?string $watchexecBinaryPath,
2625
) {
2726
}
2827

@@ -58,31 +57,6 @@ private function createBuildProcess(string $path, bool $watch = false): Process
5857
}
5958

6059
return $this->getWatchexecBinary()->startWatch($relativePath, fn ($path, $operation) => $this->createBuildProcess($path), ['ts']);
61-
//
62-
// $watchProcess = $this->getWatchexecBinary()->createProcess($relativePath);
63-
// $watchProcess->setTimeout(null)->setIdleTimeout(null);
64-
// $this->output?->note(sprintf('Watching for changes in %s...', $relativePath));
65-
// if ($this->output?->isVerbose()) {
66-
// $this->output->writeln([
67-
// ' Command:',
68-
// ' '.$watchProcess->getCommandLine(),
69-
// ]);
70-
// }
71-
// $watchProcess->start(function ($type, $buffer) {
72-
// if ('err' === $type) {
73-
// throw new \RuntimeException($buffer);
74-
// }
75-
// $path = trim($buffer);
76-
// if ('/' === $path) {
77-
// return;
78-
// }
79-
// $newProcess = $this->createBuildProcess($path);
80-
// $newProcess->wait(function ($type, $buffer) {
81-
// $this->output?->write($buffer);
82-
// });
83-
// });
84-
//
85-
// return $watchProcess;
8660
}
8761

8862
public function setOutput(SymfonyStyle $output): void

tests/Tools/WatcherBinaryFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testGetBinaryFromServerSpecs()
1515
// Test that the binary exists and the process is created with the correct arguments
1616
$binary = (new WatcherBinaryFactory())->getBinaryFromServerSpecs('Linux');
1717
$process = $binary->startWatch($this->watchPath, fn ($path, $operation) => '');
18-
$this->assertEquals('\''.realpath($this->binaryDir).'/watcher-linux\' \''.$this->watchPath.'\'', $process->getCommandLine());
18+
$this->assertEquals('\''.realpath($this->binaryDir).'/watcher-linux\' \''.$this->watchPath.'/...\'', $process->getCommandLine());
1919

2020
// Test that an exception is thrown when the platform is not supported
2121
$this->expectException(\Exception::class);

0 commit comments

Comments
 (0)