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

resources.ToCSS produces "stdin" in sourcemap sources if no "@include" is present in SCSS file #8174

Closed
stlufi opened this issue Jan 24, 2021 · 1 comment · Fixed by #10249

Comments

@stlufi
Copy link

stlufi commented Jan 24, 2021

What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.80.0/extended linux/amd64 BuildDate: unknown

Does this issue reproduce with the latest release?

yes

Bug Description

When using Hugo pipe for SASS/SCSS with option "enableSourceMap" true in a theme's template the resulting sourcemap shows the following behavior:

  • style.scss without @import
    body {
      margin: 0;
    }
    results in soucemap style.css.map
    {
      "version": 3,
      "file": "style.css",
      "sourceRoot": "/www/my-hugo-page",
      "sources": [
        "stdin"
      ],
      "sourcesContent": [
        "<the content of style.scss>"
      ],
      "names": [],
      "mappings": "<the mappings>"
    }
  • style.scss with @import pointing to an empty file
    body {
      margin: 0;
    }
    
    @import "dummy/empty"
    results in soucemap style.css.map
    {
      "version": 3,
      "file": "style.css",
      "sourceRoot": "/www/my-hugo-page",
      "sources": [
        "themes/my-hugo-theme/assets/css/style.scss",
        "themes/my-hugo-theme/assets/css/dummy/_empty.scss"
      ],
      "sourcesContent": [
        "<the content of style.scss>",
        ""
      ],
      "names": [],
      "mappings": "<the mappings>"
    }

The resulting source map contains the expected value if the sources array contains more than one item, otherwise it simply contains stdin. This makes debugging CSS via browser tooling very hard, especially when using more than one SCSS style sheet on the same page.

The respective Hugo pipe was called like this in themes/my-hugo-theme/layout/_default/baseof.html:

{{ $style := resources.Get "css/style.scss" | resources.ToCSS (dict "enableSourceMap" true) }}
<link href="{{ $style.RelPermalink }}" rel="stylesheet" type="text/css"/>

I believe the issue is caused by this piece of code in the Hugo sources: resources/resource_transformers/tocss/scss/tocss.go line 156
To me it looks like it expects to find stdin",, but this is not the case for a SCSS file without an @import, because there is simply no , after the "stdin" in this case (there is only one item in the array and a trailing comma is not needed).

@bep bep added the Bug label Jan 24, 2021
@bep bep added this to the v0.81 milestone Jan 24, 2021
@bep bep modified the milestones: v0.81, v0.82 Feb 19, 2021
@bep bep modified the milestones: v0.82, v0.83 Mar 21, 2021
@bep bep modified the milestones: v0.83, v0.84 May 1, 2021
@bep bep modified the milestones: v0.84, v0.85 Jun 18, 2021
@bep bep modified the milestones: v0.85, v0.86 Jul 5, 2021
@bep bep modified the milestones: v0.86, v0.87, v0.88 Jul 26, 2021
@bep bep modified the milestones: v0.88, v0.89 Sep 2, 2021
@bep bep modified the milestones: v0.89, v0.90 Nov 2, 2021
@bep bep modified the milestones: v0.90, v0.91.0 Dec 13, 2021
@bep bep modified the milestones: v0.91.0, v0.92.0 Dec 22, 2021
@bep bep modified the milestones: v0.92.0, v0.93.0 Jan 12, 2022
@bep bep modified the milestones: v0.93.0, v0.94.0 Mar 1, 2022
@bep bep modified the milestones: v0.94.0, v0.95.0 Mar 9, 2022
@bep bep modified the milestones: v0.95.0, v0.96.0 Mar 15, 2022
@bep bep modified the milestones: v0.96.0, v0.97.0 Mar 24, 2022
@bep bep modified the milestones: v0.97.0, v0.98.0 Apr 13, 2022
@bep bep modified the milestones: v0.98.0, v0.99.0 Apr 28, 2022
@bep bep modified the milestones: v0.99.0, v0.100.0 May 24, 2022
@bep bep modified the milestones: v0.100.0, v0.101.0 May 31, 2022
@bep bep modified the milestones: v0.101.0, v0.102.0 Jun 16, 2022
@bep bep modified the milestones: v0.102.0, v0.103.0 Aug 28, 2022
toothrot added a commit to toothrot/hugo that referenced this issue Sep 5, 2022
Simple sites may only have one css file. Update the replace directive to
correctly match single-file sourcemaps and multi-file sourcemaps.

Fixes gohugoio#8174
toothrot added a commit to toothrot/hugo that referenced this issue Sep 5, 2022
Simple sites may only have one css file. Update the replace directive to
correctly match single-file sourcemaps and multi-file sourcemaps.

Verified locally with and without SASS and CSS imports.

Fixes gohugoio#8174
toothrot added a commit to toothrot/hugo that referenced this issue Sep 5, 2022
Simple sites may only have one css file. Update the replace directive to
correctly match single-file sourcemaps and multi-file sourcemaps.

Verified locally with and without SASS and CSS imports.

Fixes gohugoio#8174
@bep bep closed this as completed in #10249 Sep 6, 2022
bep pushed a commit that referenced this issue Sep 6, 2022
Simple sites may only have one css file. Update the replace directive to
correctly match single-file sourcemaps and multi-file sourcemaps.

Verified locally with and without SASS and CSS imports.

Fixes #8174
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants