hugo/hugolib
Paul Gottschling e03f82eef2
Pass minification errors to the user
Previously, *minifyTransformation.Transform suppressed the
error returned by t.m.Minify. This meant that when minification
returned an error, the error would not reach the user. Instead,
minification would silently fail. For example, if a JavaScript
file included a call to the Date constructor with:

new Date(2020, 04, 02)

The package that the minification library uses to parse JS files,
github.com/tdewolff/parse would return an error, since "04" would
be parsed as a legacy octal. However, the JS file would remain
un-minified with no error.

Fixing this is not as simple as replacing "_" with an "err" in
*minifyTransformation.Transform, however (though this is
necessary). If we only returned this error from Transform,
then hugolib.TestResourceMinifyDisabled would fail. Instead of
being a no-op, as TestResourceMinifyDisabled expects, using the
"minify" template function with a "disableXML=true" config
setting instead returns the error, "minifier does not exist for
mimetype."

The "minifier does not exist" error is returned because of the
way minifiers.New works. If the user's config disables
minification for a particular MIME type, minifiers.New does
not add it to the resulting Client's *minify.M. However, this
also means that when the "minify" template function is executed,
 a *resourceAdapter's transformations still add a minification.
When it comes time to call the minify.Minifier for a specific
MIME type via *M.MinifyMimetype, the github.com/tdewolff/minify
library throws the "does not exist" error for the missing MIME
type.

The solution was to change minifiers.New so, instead of skipping
a minifier for each disabled MIME type, it adds  a NoOpMinifier,
which simply copies the source to the destination without
minification. This means that when the "minify" template
function is used for a particular resource, and that resource's
MIME type has minification disabled, minification is genuinely
skipped, and does not result in an error.

In order to add this, I've fixed a possibly unwanted interaction
between minifiers.TestConfigureMinify and
hugolib.TestResourceMinifyDisabled. The latter disables
minification and expects minification to be a no-op. The former
disables minification and expects it to result in an error. The
only reason hugolib.TestResourceMinifyDisabled passes in the
original code is that the "does not exist" error is suppressed.
However, we shouldn't suppress minification errors, since they
can leave users perplexed. I've changed the test assertion in
minifiers.TestConfigureMinify to expect no errors and a no-op
if minification is disabled for a particular MIME type.

Fixes #8954
2021-09-22 20:54:40 +02:00
..
assets/images
filesystems hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
paths Misc config loading fixes 2021-06-14 17:00:32 +02:00
testdata
testsite
404_test.go
alias.go tpl/fmt: Add erroridf template func 2021-06-07 19:11:03 +02:00
alias_test.go
breaking_changes_test.go
cascade_test.go Add config.cascade 2021-07-10 11:13:41 +02:00
case_insensitive_test.go
collections.go tpl/fmt: Add erroridf template func 2021-06-07 19:11:03 +02:00
collections_test.go
config.go Avoid failing with "module not found" for hugo mod init and similar 2021-08-31 12:08:11 +02:00
config_test.go Fix it so disableKinds etc. does not get merged in from theme 2021-08-22 13:25:20 +02:00
configdir_test.go Switch to go-toml v2 2021-07-28 11:51:13 +02:00
content_map.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
content_map_page.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
content_map_test.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
content_render_hooks_test.go markup/goldmark: Support auto links in render hook 2021-07-15 10:14:52 +02:00
datafiles_test.go
dates_test.go Fix error handling for the time func alias 2021-08-01 13:39:30 +02:00
disableKinds_test.go
embedded_shortcodes_test.go highlight: Remove some pygments references 2021-08-21 15:50:49 +02:00
embedded_templates_test.go Fix tab selection of disabled items in internal pagination template 2021-07-05 10:30:59 +02:00
fileInfo.go
fileInfo_test.go
gitinfo.go
hugo_modules_test.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
hugo_sites.go commands: Don't fail on template errors on go mod graph etc. 2021-08-31 22:16:12 +02:00
hugo_sites_build.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
hugo_sites_build_errors_test.go Misc config loading fixes 2021-06-14 17:00:32 +02:00
hugo_sites_build_test.go
hugo_sites_multihost_test.go
hugo_sites_rebuild_test.go
hugo_smoke_test.go
image_test.go Misc config loading fixes 2021-06-14 17:00:32 +02:00
js_test.go deps: Update github.com/evanw/esbuild v0.11.16 => v0.12.16 2021-07-26 20:23:00 +02:00
language_content_dir_test.go
language_test.go Reduce binary size vs locale, update to CLDR v36.1 2021-08-02 19:40:32 +02:00
menu_test.go Improve handling of <nil> Params 2021-07-30 21:07:52 +02:00
minify_publisher_test.go Misc config loading fixes 2021-06-14 17:00:32 +02:00
multilingual.go
openapi_test.go
page.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
page__common.go
page__content.go
page__data.go
page__menus.go Simplify "active menu" logic for section menus 2021-07-20 17:50:59 +02:00
page__meta.go Add timezone support for front matter dates without one 2021-07-27 19:02:48 +02:00
page__new.go tpl/fmt: Add erroridf template func 2021-06-07 19:11:03 +02:00
page__output.go
page__paginator.go
page__paths.go
page__per_output.go
page__position.go
page__ref.go
page__tree.go
page_kinds.go
page_permalink_test.go
page_test.go markup: Add tabindex="0" to default <pre> wrapper 2021-07-15 16:48:39 +02:00
page_unwrap.go
page_unwrap_test.go
pagebundler_test.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
pagecollections.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
pagecollections_test.go
pages_capture.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
pages_capture_test.go
pages_language_merge_test.go
pages_process.go hugofs: Make FileMeta a struct 2021-07-15 17:14:26 +02:00
pages_test.go Add a benchmark 2021-05-04 17:59:04 +02:00
paginator_test.go
permalinker.go
prune_resources.go
resource_chain_babel_test.go Misc config loading fixes 2021-06-14 17:00:32 +02:00
resource_chain_test.go Pass minification errors to the user 2021-09-22 20:54:40 +02:00
robotstxt_test.go Misc config loading fixes 2021-06-14 17:00:32 +02:00
rss_test.go
shortcode.go Catch incomplete shortcode error 2021-05-24 14:59:02 +02:00
shortcode_page.go
shortcode_test.go highlight: Remove some pygments references 2021-08-21 15:50:49 +02:00
site.go Improve handling of <nil> Params 2021-07-30 21:07:52 +02:00
site_benchmark_new_test.go Add a TOML front matter benchmark 2021-07-27 19:27:54 +02:00
site_output.go
site_output_test.go Misc config loading fixes 2021-06-14 17:00:32 +02:00
site_render.go tpl/fmt: Add erroridf template func 2021-06-07 19:11:03 +02:00
site_sections.go
site_sections_test.go
site_stats_test.go
site_test.go Misc config loading fixes 2021-06-14 17:00:32 +02:00
site_url_test.go
siteJSONEncode_test.go
sitemap_test.go
taxonomy.go
taxonomy_test.go
template_test.go Misc config loading fixes 2021-06-14 17:00:32 +02:00
testhelpers_test.go Adjust a test helper 2021-07-14 21:47:26 +02:00
translations.go