Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix other options are forbidden when --no-source-map #59

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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