Skip to content

Commit 59d2803

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

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/AssetMapper/SassCssCompiler.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
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
@@ -28,9 +27,7 @@ public function __construct(
2827
public function supports(MappedAsset $asset): bool
2928
{
3029
foreach ($this->scssPaths as $path) {
31-
$absolutePath = Path::isAbsolute($path) ? $path : Path::makeAbsolute($path, $this->projectDir);
32-
33-
if (realpath($asset->sourcePath) === realpath($absolutePath)) {
30+
if (realpath($asset->sourcePath) === realpath($path)) {
3431
return true;
3532
}
3633
}

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)