From fe4376debf631f520d6344e2fc467e71fccd1102 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Thu, 9 Nov 2023 16:30:14 +0100 Subject: [PATCH 01/15] Add support for file name for converted files in paths --- src/SassBuilder.php | 10 +++++---- tests/SassBuilderTest.php | 33 ++++++++++++++++++++++++++-- tests/fixtures/assets/admin/app.scss | 5 +++++ 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/assets/admin/app.scss diff --git a/src/SassBuilder.php b/src/SassBuilder.php index c200a9c..60578a5 100644 --- a/src/SassBuilder.php +++ b/src/SassBuilder.php @@ -71,12 +71,12 @@ public function runBuild(bool $watch): Process public function getScssCssTargets(): array { $targets = []; - foreach ($this->sassPaths as $sassPath) { + foreach ($this->sassPaths as $fileName => $sassPath) { if (!is_file($sassPath)) { throw new \Exception(sprintf('Could not find Sass file: "%s"', $sassPath)); } - $targets[] = $sassPath.':'.$this->guessCssNameFromSassFile($sassPath, $this->cssPath); + $targets[] = $sassPath.':'. self::guessCssNameFromSassFile($sassPath, $fileName, $this->cssPath); } return $targets; @@ -90,9 +90,11 @@ public function setOutput(SymfonyStyle $output): void /** * @internal */ - public static function guessCssNameFromSassFile(string $sassFile, string $outputDirectory): string + public static function guessCssNameFromSassFile(string $sassFile, string|int $fileName, string $outputDirectory): string { - $fileName = basename($sassFile, '.scss'); + if (is_int($fileName)) { + $fileName = basename($sassFile, '.scss'); + } return $outputDirectory.'/'.$fileName.'.output.css'; } diff --git a/tests/SassBuilderTest.php b/tests/SassBuilderTest.php index a651d96..6191cf0 100644 --- a/tests/SassBuilderTest.php +++ b/tests/SassBuilderTest.php @@ -16,8 +16,14 @@ class SassBuilderTest extends TestCase { protected function tearDown(): void { - unlink(__DIR__.'/fixtures/assets/app.output.css'); - unlink(__DIR__.'/fixtures/assets/app.output.css.map'); + @unlink(__DIR__.'/fixtures/assets/app.output.css'); + @unlink(__DIR__.'/fixtures/assets/app.output.css.map'); + + @unlink(__DIR__.'/fixtures/assets/foo.output.css'); + @unlink(__DIR__.'/fixtures/assets/foo.output.css.map'); + + @unlink(__DIR__.'/fixtures/assets/bar.output.css'); + @unlink(__DIR__.'/fixtures/assets/bar.output.css.map'); } public function testIntegration(): void @@ -37,4 +43,27 @@ public function testIntegration(): void $this->assertFileExists(__DIR__.'/fixtures/assets/app.output.css'); $this->assertStringContainsString('color: red;', file_get_contents(__DIR__.'/fixtures/assets/app.output.css')); } + + public function testPathsConfigWithKeys(): void + { + $builder = new SassBuilder( + [ + 'foo' => __DIR__.'/fixtures/assets/app.scss', + 'bar' => __DIR__.'/fixtures/assets/admin/app.scss' + ], + __DIR__.'/fixtures/assets', + __DIR__.'/fixtures', + null, + false + ); + + $process = $builder->runBuild(false); + $process->wait(); + + $this->assertTrue($process->isSuccessful()); + $this->assertFileExists(__DIR__.'/fixtures/assets/foo.output.css'); + $this->assertFileExists(__DIR__.'/fixtures/assets/bar.output.css'); + $this->assertStringContainsString('color: red;', file_get_contents(__DIR__.'/fixtures/assets/foo.output.css')); + $this->assertStringContainsString('color: blue;', file_get_contents(__DIR__.'/fixtures/assets/bar.output.css')); + } } diff --git a/tests/fixtures/assets/admin/app.scss b/tests/fixtures/assets/admin/app.scss new file mode 100644 index 0000000..6b583f9 --- /dev/null +++ b/tests/fixtures/assets/admin/app.scss @@ -0,0 +1,5 @@ +$color: blue; + +p { + color: $color; +} From f1574a77f7cd67f967bf31c8d68aea434b8d1877 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Thu, 9 Nov 2023 16:50:01 +0100 Subject: [PATCH 02/15] Fixed PHP CS fixer errors --- src/SassBuilder.php | 4 ++-- tests/SassBuilderTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SassBuilder.php b/src/SassBuilder.php index 60578a5..02a29f6 100644 --- a/src/SassBuilder.php +++ b/src/SassBuilder.php @@ -76,7 +76,7 @@ public function getScssCssTargets(): array throw new \Exception(sprintf('Could not find Sass file: "%s"', $sassPath)); } - $targets[] = $sassPath.':'. self::guessCssNameFromSassFile($sassPath, $fileName, $this->cssPath); + $targets[] = $sassPath.':'.self::guessCssNameFromSassFile($sassPath, $fileName, $this->cssPath); } return $targets; @@ -92,7 +92,7 @@ public function setOutput(SymfonyStyle $output): void */ public static function guessCssNameFromSassFile(string $sassFile, string|int $fileName, string $outputDirectory): string { - if (is_int($fileName)) { + if (\is_int($fileName)) { $fileName = basename($sassFile, '.scss'); } diff --git a/tests/SassBuilderTest.php b/tests/SassBuilderTest.php index 6191cf0..ac86fa3 100644 --- a/tests/SassBuilderTest.php +++ b/tests/SassBuilderTest.php @@ -49,7 +49,7 @@ public function testPathsConfigWithKeys(): void $builder = new SassBuilder( [ 'foo' => __DIR__.'/fixtures/assets/app.scss', - 'bar' => __DIR__.'/fixtures/assets/admin/app.scss' + 'bar' => __DIR__.'/fixtures/assets/admin/app.scss', ], __DIR__.'/fixtures/assets', __DIR__.'/fixtures', From 3b7ae99723ece7287645cd698b8d86796ca46048 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Thu, 9 Nov 2023 16:52:31 +0100 Subject: [PATCH 03/15] Fixed PHPStan errors --- src/AssetMapper/SassCssCompiler.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/AssetMapper/SassCssCompiler.php b/src/AssetMapper/SassCssCompiler.php index 8270e82..21ce71f 100644 --- a/src/AssetMapper/SassCssCompiler.php +++ b/src/AssetMapper/SassCssCompiler.php @@ -18,8 +18,7 @@ class SassCssCompiler implements AssetCompilerInterface { public function __construct( private array $scssPaths, - private string $cssPathDirectory, - private readonly SassBuilder $sassBuilder + private string $cssPathDirectory ) { } @@ -36,7 +35,7 @@ public function supports(MappedAsset $asset): bool public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string { - $cssFile = $this->sassBuilder->guessCssNameFromSassFile($asset->sourcePath, $this->cssPathDirectory); + $cssFile = SassBuilder::guessCssNameFromSassFile($asset->sourcePath, 0, $this->cssPathDirectory); $asset->addFileDependency($cssFile); From a6808a8952588d07c5013ed3dc80aa099da04c31 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Mon, 13 Nov 2023 13:57:54 +0100 Subject: [PATCH 04/15] Changed order of method arguments --- src/AssetMapper/SassCssCompiler.php | 2 +- src/SassBuilder.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AssetMapper/SassCssCompiler.php b/src/AssetMapper/SassCssCompiler.php index 21ce71f..341dae5 100644 --- a/src/AssetMapper/SassCssCompiler.php +++ b/src/AssetMapper/SassCssCompiler.php @@ -35,7 +35,7 @@ public function supports(MappedAsset $asset): bool public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string { - $cssFile = SassBuilder::guessCssNameFromSassFile($asset->sourcePath, 0, $this->cssPathDirectory); + $cssFile = SassBuilder::guessCssNameFromSassFile($asset->sourcePath, $this->cssPathDirectory); $asset->addFileDependency($cssFile); diff --git a/src/SassBuilder.php b/src/SassBuilder.php index 02a29f6..eef12f5 100644 --- a/src/SassBuilder.php +++ b/src/SassBuilder.php @@ -76,7 +76,7 @@ public function getScssCssTargets(): array throw new \Exception(sprintf('Could not find Sass file: "%s"', $sassPath)); } - $targets[] = $sassPath.':'.self::guessCssNameFromSassFile($sassPath, $fileName, $this->cssPath); + $targets[] = $sassPath.':'.self::guessCssNameFromSassFile($sassPath, $this->cssPath, $fileName); } return $targets; @@ -90,9 +90,9 @@ public function setOutput(SymfonyStyle $output): void /** * @internal */ - public static function guessCssNameFromSassFile(string $sassFile, string|int $fileName, string $outputDirectory): string + public static function guessCssNameFromSassFile(string $sassFile, string $outputDirectory, string|int $fileName = null): string { - if (\is_int($fileName)) { + if (\is_null($fileName) || \is_int($fileName)) { $fileName = basename($sassFile, '.scss'); } From 3d13b79bb1a27ddb4f19f1b5fa7265c354d2c3c7 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Wed, 15 Nov 2023 11:21:15 +0100 Subject: [PATCH 05/15] Reverted removal of SassBuilder constructor injection to prevent BC-break --- src/AssetMapper/SassCssCompiler.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/AssetMapper/SassCssCompiler.php b/src/AssetMapper/SassCssCompiler.php index 341dae5..8270e82 100644 --- a/src/AssetMapper/SassCssCompiler.php +++ b/src/AssetMapper/SassCssCompiler.php @@ -18,7 +18,8 @@ class SassCssCompiler implements AssetCompilerInterface { public function __construct( private array $scssPaths, - private string $cssPathDirectory + private string $cssPathDirectory, + private readonly SassBuilder $sassBuilder ) { } @@ -35,7 +36,7 @@ public function supports(MappedAsset $asset): bool public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string { - $cssFile = SassBuilder::guessCssNameFromSassFile($asset->sourcePath, $this->cssPathDirectory); + $cssFile = $this->sassBuilder->guessCssNameFromSassFile($asset->sourcePath, $this->cssPathDirectory); $asset->addFileDependency($cssFile); From 9c0afd4e05e53bf2dfed2b6191bbab14cb4ec03c Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Wed, 15 Nov 2023 15:48:47 +0100 Subject: [PATCH 06/15] Add support for custom filename in compile function --- src/AssetMapper/SassCssCompiler.php | 4 +++- src/SassBuilder.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/AssetMapper/SassCssCompiler.php b/src/AssetMapper/SassCssCompiler.php index 8270e82..fcc520a 100644 --- a/src/AssetMapper/SassCssCompiler.php +++ b/src/AssetMapper/SassCssCompiler.php @@ -36,7 +36,9 @@ public function supports(MappedAsset $asset): bool public function compile(string $content, MappedAsset $asset, AssetMapperInterface $assetMapper): string { - $cssFile = $this->sassBuilder->guessCssNameFromSassFile($asset->sourcePath, $this->cssPathDirectory); + $fileName = $this->sassBuilder->getIdentifierByLogicalPath($asset->logicalPath); + + $cssFile = SassBuilder::guessCssNameFromSassFile($asset->sourcePath, $this->cssPathDirectory, $fileName); $asset->addFileDependency($cssFile); diff --git a/src/SassBuilder.php b/src/SassBuilder.php index eef12f5..90fc4d8 100644 --- a/src/SassBuilder.php +++ b/src/SassBuilder.php @@ -99,6 +99,24 @@ public static function guessCssNameFromSassFile(string $sassFile, string $output return $outputDirectory.'/'.$fileName.'.output.css'; } + public function getIdentifierByLogicalPath(string $path): ?string + { + if (array_is_list($this->sassPaths)) { + return null; + } + + foreach ($this->sassPaths as $identifier => $configuredSassPath) { + // as the configured paths include the project dir, we need to subtract it to be able to compare the paths + $logicalPath = str_replace($this->projectRootDir.'/assets/', '', $configuredSassPath); + + if ($path === $logicalPath) { + return $identifier; + } + } + + return null; + } + private function createBinary(): SassBinary { return new SassBinary($this->projectRootDir.'/var', $this->binaryPath, $this->output); From 3c8497e63c0117007bca24f61826575c756baa00 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Wed, 15 Nov 2023 16:21:13 +0100 Subject: [PATCH 07/15] Fix php-cs-fixer --- src/SassBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SassBuilder.php b/src/SassBuilder.php index 90fc4d8..ac57d1f 100644 --- a/src/SassBuilder.php +++ b/src/SassBuilder.php @@ -92,7 +92,7 @@ public function setOutput(SymfonyStyle $output): void */ public static function guessCssNameFromSassFile(string $sassFile, string $outputDirectory, string|int $fileName = null): string { - if (\is_null($fileName) || \is_int($fileName)) { + if (null === $fileName || \is_int($fileName)) { $fileName = basename($sassFile, '.scss'); } From 04f0769afb0b0c0e48ff0927d9d9f3f9fde572e0 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Thu, 16 Nov 2023 11:07:14 +0100 Subject: [PATCH 08/15] Added SassCssCompilerTest --- tests/AssetMapper/SassCssCompilerTest.php | 114 ++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tests/AssetMapper/SassCssCompilerTest.php diff --git a/tests/AssetMapper/SassCssCompilerTest.php b/tests/AssetMapper/SassCssCompilerTest.php new file mode 100644 index 0000000..0585a00 --- /dev/null +++ b/tests/AssetMapper/SassCssCompilerTest.php @@ -0,0 +1,114 @@ +createSassBuilder($scssPaths, self::CSS_DIR) + ); + + $mappedAsset = new MappedAsset( + 'app.scss', + $scssFile, + 'app.css' + ); + + file_put_contents($cssFile, <<compile( + file_get_contents($scssFile), + $mappedAsset, + $this->createMock(AssetMapperInterface::class) + ); + + $this->assertStringEqualsFile( + $cssFile, + $compiledContent + ); + } + + public function testCompileNamedSassPath() + { + $scssFile = __DIR__.'/../fixtures/assets/admin/app.scss'; + $scssPaths = [ + 'admin' => $scssFile + ]; + $cssFile = self::CSS_DIR.'/admin.output.css'; + + $compiler = new SassCssCompiler( + $scssPaths, + self::CSS_DIR, + $this->createSassBuilder($scssPaths, self::CSS_DIR) + ); + + $mappedAsset = new MappedAsset( + 'admin/app.scss', + $scssFile, + 'admin.css' + ); + + file_put_contents($cssFile, <<compile( + file_get_contents($scssFile), + $mappedAsset, + $this->createMock(AssetMapperInterface::class) + ); + + $this->assertStringEqualsFile( + $cssFile, + $compiledContent + ); + } + + private function createSassBuilder(array $sassPaths, string $cssPath): SassBuilder + { + return new SassBuilder( + $sassPaths, + $cssPath, + __DIR__.'/../fixtures', + null, + false + ); + } +} From c5e3f3ada95734749a407fcf65b3ecc3afbe3d05 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Thu, 16 Nov 2023 11:14:13 +0100 Subject: [PATCH 09/15] Fix php-cs-fixer --- tests/AssetMapper/SassCssCompilerTest.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/AssetMapper/SassCssCompilerTest.php b/tests/AssetMapper/SassCssCompilerTest.php index 0585a00..ef37961 100644 --- a/tests/AssetMapper/SassCssCompilerTest.php +++ b/tests/AssetMapper/SassCssCompilerTest.php @@ -2,6 +2,13 @@ declare(strict_types=1); +/* + * This file is part of the SymfonyCasts SassBundle package. + * Copyright (c) SymfonyCasts + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfonycasts\SassBundle\Tests\AssetMapper; use PHPUnit\Framework\TestCase; @@ -10,13 +17,11 @@ use Symfonycasts\SassBundle\AssetMapper\SassCssCompiler; use Symfonycasts\SassBundle\SassBuilder; -use function file_put_contents; - final class SassCssCompilerTest extends TestCase { private const CSS_DIR = __DIR__.'/../fixtures/var/sass'; - public function setUp(): void + protected function setUp(): void { if (!is_dir(self::CSS_DIR)) { mkdir(self::CSS_DIR); @@ -27,7 +32,7 @@ public function testCompileSingleSassPath(): void { $scssFile = __DIR__.'/../fixtures/assets/app.scss'; $scssPaths = [ - $scssFile + $scssFile, ]; $cssFile = self::CSS_DIR.'/app.output.css'; @@ -43,7 +48,7 @@ public function testCompileSingleSassPath(): void 'app.css' ); - file_put_contents($cssFile, << $scssFile + 'admin' => $scssFile, ]; $cssFile = self::CSS_DIR.'/admin.output.css'; @@ -82,7 +87,7 @@ public function testCompileNamedSassPath() 'admin.css' ); - file_put_contents($cssFile, << Date: Thu, 16 Nov 2023 11:16:08 +0100 Subject: [PATCH 10/15] Fix testsuite --- tests/AssetMapper/SassCssCompilerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AssetMapper/SassCssCompilerTest.php b/tests/AssetMapper/SassCssCompilerTest.php index ef37961..8c5ff39 100644 --- a/tests/AssetMapper/SassCssCompilerTest.php +++ b/tests/AssetMapper/SassCssCompilerTest.php @@ -24,7 +24,7 @@ final class SassCssCompilerTest extends TestCase protected function setUp(): void { if (!is_dir(self::CSS_DIR)) { - mkdir(self::CSS_DIR); + mkdir(self::CSS_DIR, 0777, true); } } From b94223226f6db4bc72019b064a865831655b26df Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Thu, 16 Nov 2023 11:18:19 +0100 Subject: [PATCH 11/15] Fix php-cs-fixer --- tests/AssetMapper/SassCssCompilerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/AssetMapper/SassCssCompilerTest.php b/tests/AssetMapper/SassCssCompilerTest.php index 8c5ff39..01903de 100644 --- a/tests/AssetMapper/SassCssCompilerTest.php +++ b/tests/AssetMapper/SassCssCompilerTest.php @@ -48,7 +48,7 @@ public function testCompileSingleSassPath(): void 'app.css' ); - \file_put_contents($cssFile, << Date: Fri, 17 Nov 2023 11:36:39 +0100 Subject: [PATCH 12/15] Fix config validation is keys are used defining the "root_sass" paths --- .../SymfonycastsSassExtension.php | 2 +- tests/ConfigurationTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/DependencyInjection/SymfonycastsSassExtension.php b/src/DependencyInjection/SymfonycastsSassExtension.php index c07d9a4..9439207 100644 --- a/src/DependencyInjection/SymfonycastsSassExtension.php +++ b/src/DependencyInjection/SymfonycastsSassExtension.php @@ -61,7 +61,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ->validate() ->ifTrue(static function (array $paths): bool { - if (1 === \count($paths)) { + if (1 === \count($paths) || !array_is_list($paths)) { return false; } diff --git a/tests/ConfigurationTest.php b/tests/ConfigurationTest.php index f1b724e..0ca35fb 100644 --- a/tests/ConfigurationTest.php +++ b/tests/ConfigurationTest.php @@ -47,6 +47,18 @@ public function testMultipleSassRootPaths(): void ]); } + public function testMultipleSassRootPathsWithIdentifier(): void + { + $this->assertConfigurationIsValid([ + 'symfonycasts_sass' => [ + 'root_sass' => [ + 'website' => '%kernel.project_dir%/assets/scss/app.scss', + 'admin' => '%kernel.project_dir%/assets/admin/scss/app.scss', + ], + ], + ]); + } + public function testMultipleSassRootPathsWithSameFilename(): void { $this->assertConfigurationIsInvalid([ From 145df5b7cc47ce9bcc466b9e76a4fc8dcc9d4503 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Fri, 24 Nov 2023 14:53:20 +0100 Subject: [PATCH 13/15] Moved Configuration test to logical namespace path --- tests/{ => DependencyInjection}/ConfigurationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{ => DependencyInjection}/ConfigurationTest.php (97%) diff --git a/tests/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php similarity index 97% rename from tests/ConfigurationTest.php rename to tests/DependencyInjection/ConfigurationTest.php index 0ca35fb..6575a3e 100644 --- a/tests/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfonycasts\SassBundle\Tests; +namespace Symfonycasts\SassBundle\Tests\DependencyInjection; use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; use PHPUnit\Framework\TestCase; From 669fa0a1d1a4aca3c42248baaffcb0002b484f16 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Fri, 24 Nov 2023 15:17:45 +0100 Subject: [PATCH 14/15] Minor cleanup in test --- tests/AssetMapper/SassCssCompilerTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/AssetMapper/SassCssCompilerTest.php b/tests/AssetMapper/SassCssCompilerTest.php index 01903de..3a4ead8 100644 --- a/tests/AssetMapper/SassCssCompilerTest.php +++ b/tests/AssetMapper/SassCssCompilerTest.php @@ -39,7 +39,7 @@ public function testCompileSingleSassPath(): void $compiler = new SassCssCompiler( $scssPaths, self::CSS_DIR, - $this->createSassBuilder($scssPaths, self::CSS_DIR) + $this->createSassBuilder($scssPaths) ); $mappedAsset = new MappedAsset( @@ -70,6 +70,7 @@ public function testCompileSingleSassPath(): void public function testCompileNamedSassPath() { $scssFile = __DIR__.'/../fixtures/assets/admin/app.scss'; + $scssPaths = [ 'admin' => $scssFile, ]; @@ -78,7 +79,7 @@ public function testCompileNamedSassPath() $compiler = new SassCssCompiler( $scssPaths, self::CSS_DIR, - $this->createSassBuilder($scssPaths, self::CSS_DIR) + $this->createSassBuilder($scssPaths) ); $mappedAsset = new MappedAsset( @@ -106,11 +107,11 @@ public function testCompileNamedSassPath() ); } - private function createSassBuilder(array $sassPaths, string $cssPath): SassBuilder + private function createSassBuilder(array $sassPaths): SassBuilder { return new SassBuilder( $sassPaths, - $cssPath, + self::CSS_DIR, __DIR__.'/../fixtures', null, false From 15a9f6eea8823cf883217c41111efbe378ce29fe Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Fri, 24 Nov 2023 15:27:00 +0100 Subject: [PATCH 15/15] Use substr in stead of str_replace --- src/SassBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SassBuilder.php b/src/SassBuilder.php index ac57d1f..0becd01 100644 --- a/src/SassBuilder.php +++ b/src/SassBuilder.php @@ -107,7 +107,8 @@ public function getIdentifierByLogicalPath(string $path): ?string foreach ($this->sassPaths as $identifier => $configuredSassPath) { // as the configured paths include the project dir, we need to subtract it to be able to compare the paths - $logicalPath = str_replace($this->projectRootDir.'/assets/', '', $configuredSassPath); + $pathPrefix = $this->projectRootDir.'/assets/'; + $logicalPath = substr($configuredSassPath, \strlen($pathPrefix)); if ($path === $logicalPath) { return $identifier;