Skip to content

Commit f82915f

Browse files
committed
resolve paths after configuration processing
1 parent aa47da8 commit f82915f

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

config/services.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
->args([
3636
abstract_arg('path to scss files'),
3737
abstract_arg('path to css output directory'),
38-
param('kernel.project_dir'),
3938
service('sass.builder'),
4039
])
4140

src/AssetMapper/SassCssCompiler.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,21 @@
1212
use Symfony\Component\AssetMapper\AssetMapperInterface;
1313
use Symfony\Component\AssetMapper\Compiler\AssetCompilerInterface;
1414
use Symfony\Component\AssetMapper\MappedAsset;
15-
use Symfony\Component\Filesystem\Path;
1615
use Symfonycasts\SassBundle\SassBuilder;
1716

1817
class SassCssCompiler implements AssetCompilerInterface
1918
{
2019
public function __construct(
2120
private array $scssPaths,
2221
private string $cssPathDirectory,
23-
private string $projectDir,
2422
private readonly SassBuilder $sassBuilder
2523
) {
2624
}
2725

2826
public function supports(MappedAsset $asset): bool
2927
{
3028
foreach ($this->scssPaths as $path) {
31-
$absolutePath = Path::isAbsolute($path) ? $path : Path::makeAbsolute($path, $this->projectDir);
32-
33-
if (realpath($asset->sourcePath) === realpath($absolutePath)) {
29+
if (realpath($asset->sourcePath) === realpath($path)) {
3430
return true;
3531
}
3632
}

src/DependencyInjection/SymfonycastsSassExtension.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Extension\Extension;
1818
use Symfony\Component\DependencyInjection\Loader;
19+
use Symfony\Component\Filesystem\Path;
1920

2021
class SymfonycastsSassExtension extends Extension implements ConfigurationInterface
2122
{
@@ -27,6 +28,16 @@ public function load(array $configs, ContainerBuilder $container): void
2728
$configuration = $this->getConfiguration($configs, $container);
2829
$config = $this->processConfiguration($configuration, $configs);
2930

31+
// Ensure paths are absolute
32+
$normalizeRootSassPath = function ($path) use ($container) {
33+
return Path::isAbsolute($container->getParameterBag()->resolveValue($path))
34+
? $path
35+
: '%kernel.project_dir%/'.$path
36+
;
37+
};
38+
39+
$config['root_sass'] = array_map($normalizeRootSassPath, $config['root_sass']);
40+
3041
// BC Layer with SassBundle < 0.4
3142
if (isset($config['embed_sourcemap'])) {
3243
$config['sass_options']['embed_source_map'] = $config['embed_sourcemap'];

tests/AssetMapper/SassCssCompilerTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,13 @@ public function testSupports()
2222

2323
$asset = new MappedAsset('assets/app.scss', __DIR__.'/../fixtures/assets/app.scss');
2424

25-
$compilerAbsolutePath = new SassCssCompiler(
25+
$compiler = new SassCssCompiler(
2626
[__DIR__.'/../fixtures/assets/app.scss'],
2727
__DIR__.'/../fixtures/var/sass',
2828
__DIR__.'/../fixtures',
2929
$builder
3030
);
3131

32-
$this->assertTrue($compilerAbsolutePath->supports($asset), 'Supports absolute paths');
33-
34-
$compilerRelativePath = new SassCssCompiler(
35-
['assets/app.scss'],
36-
__DIR__.'/../fixtures/var/sass',
37-
__DIR__.'/../fixtures',
38-
$builder
39-
);
40-
41-
$this->assertTrue($compilerRelativePath->supports($asset), 'Supportes relative paths');
32+
$this->assertTrue($compiler->supports($asset));
4233
}
4334
}

0 commit comments

Comments
 (0)