Skip to content

Commit

Permalink
Fix other options are forbidden when --no-source-map (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
smnandre authored Jan 18, 2024
1 parent 2f2fd8b commit ab60d02
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
56 changes: 33 additions & 23 deletions src/SassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@

class SassBuilder
{
private ?SymfonyStyle $output = null;

/**
* @var array<string, bool|string>
*/
private array $sassOptions;

/**
* Run "sass --help" to see all options.
*
Expand All @@ -44,6 +37,13 @@ class SassBuilder
'--[no-]trace' => null, // Print full Dart stack traces for exceptions.
];

private ?SymfonyStyle $output = null;

/**
* @var array<string, bool|string>
*/
private array $sassOptions;

/**
* @param array<string> $sassPaths
* @param array<string, bool|string> $sassOptions
Expand All @@ -66,6 +66,16 @@ public function __construct(
$this->setOptions($sassOptions);
}

/**
* @internal
*/
public static function guessCssNameFromSassFile(string $sassFile, string $outputDirectory): string
{
$fileName = basename($sassFile, '.scss');

return $outputDirectory.'/'.$fileName.'.output.css';
}

public function runBuild(bool $watch): Process
{
$binary = $this->createBinary();
Expand Down Expand Up @@ -95,11 +105,6 @@ public function runBuild(bool $watch): Process
return $process;
}

private function createBinary(): SassBinary
{
return new SassBinary($this->projectRootDir.'/var', $this->binaryPath, $this->output);
}

/**
* @return array<string>
*/
Expand All @@ -117,16 +122,6 @@ public function getScssCssTargets(): array
return $targets;
}

/**
* @internal
*/
public static function guessCssNameFromSassFile(string $sassFile, string $outputDirectory): string
{
$fileName = basename($sassFile, '.scss');

return $outputDirectory.'/'.$fileName.'.output.css';
}

/**
* @param array<string, bool|string> $options
*
Expand Down Expand Up @@ -159,14 +154,29 @@ public function getBuildOptions(array $options = []): array
}
}

return $buildOptions;
// Filter forbidden associations of options.
if (\in_array('--no-source-map', $buildOptions, true)) {
$buildOptions = array_diff($buildOptions, [
'--embed-sources',
'--embed-source-map',
'--no-embed-sources',
'--no-embed-source-map',
]);
}

return array_values($buildOptions);
}

public function setOutput(SymfonyStyle $output): void
{
$this->output = $output;
}

private function createBinary(): SassBinary
{
return new SassBinary($this->projectRootDir.'/var', $this->binaryPath, $this->output);
}

/**
* Save the Sass options for the build.
*
Expand Down
2 changes: 0 additions & 2 deletions tests/SassBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ public static function provideSassPhpOptions()
'--no-charset',
'--no-error-css',
'--no-source-map',
'--no-embed-sources',
'--no-embed-source-map',
'--no-quiet',
'--no-quiet-deps',
'--no-stop-on-error',
Expand Down

0 comments on commit ab60d02

Please sign in to comment.