Skip to content

Commit

Permalink
Merge pull request #154 from baierjan/show_sass_failures
Browse files Browse the repository at this point in the history
Propagate errors from sass compiler
  • Loading branch information
kraih authored Dec 6, 2024
2 parents ed42ad0 + 031474f commit b74bdcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/Mojolicious/Plugin/AssetPack/Pipe/Sass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ sub process {
my @args = (qw(sass -s), map { ('-I', $_) } @{$opts{include_paths}});
push @args, '--scss' if $asset->format eq 'scss';
push @args, qw(-t compressed) if $attrs->{minified};
$self->run(\@args, \$content, \my $css, undef);
$self->run(\@args, \$content, \my $css, \my $err);
my $exit = $? > 0 ? $? >> 8 : $?;
if ($exit) {
die sprintf '[Pipe::Sass] Could not compile "%s" with opts=%s: %s', $asset->url, dumper(\%opts), $err;
}
$asset->content($store->save(\$css, $attrs))->FROM_JSON($attrs);
}
});
Expand Down
13 changes: 11 additions & 2 deletions t/sass-bin.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ $t->get_ok($html->at('link:nth-of-child(1)')->{href})->status_is(200)->content_l

$t->get_ok($html->at('link:nth-of-child(2)')->{href})->status_is(200)->content_like(qr{footer.*\#aaa.*body.*\#222}s);

# Processing invalid sass file should fail as it does with CSS::Sass
$t = t::Helper->t(pipes => [qw(Sass)]);
$t->app->asset->pipe('Sass')->{has_module} = ''; # make sure CSS::Sass is not used
ok((not eval { $t->app->asset->process('invalid.css' => 'sass-invalid.sass') }), 'compile invalid sass file');
like $@, qr/Undefined variable/, 'sass complains about undefined variable';

$ENV{MOJO_MODE} = 'Test_minify_from_here';
$t = t::Helper->t(pipes => [qw(Sass Css Combine)]);
$t->app->asset->pipe('Sass')->{has_module} = ''; # make sure CSS::Sass is not used
$t->app->asset->pipe('Sass')->{has_module} = ''; # make sure CSS::Sass is not used
$t->app->asset->process('app.css' => ('sass.sass', 'sass/sass-1.scss'));
$t->get_ok('/')->status_is(200);
$t->get_ok($t->tx->res->dom->at('link')->{href})->status_is(200)->content_unlike(qr/[ ]/)
; # No spaces in minified version
; # No spaces in minified version

done_testing;

Expand All @@ -33,3 +39,6 @@ __DATA__
$color: #aaa
.sass
color: $color
@@ sass-invalid.sass
.sass
color: $undefined

0 comments on commit b74bdcc

Please sign in to comment.