Skip to content

Commit

Permalink
tailwindcss: Write to a temp file as a workaround for upstream bug
Browse files Browse the repository at this point in the history
As a workaround for what seems to be a bug in  tailwindcss 4.0.0-alpha.25.

See gohugoio#12880
  • Loading branch information
bep committed Sep 26, 2024
1 parent 0ea796d commit af00412
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

*.test
imports.*
imports.*
debug.log
28 changes: 21 additions & 7 deletions resources/resource_transformers/cssjs/tailwindcss.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cssjs
import (
"bytes"
"io"
"os"
"regexp"
"strings"

Expand Down Expand Up @@ -115,12 +116,11 @@ func (t *tailwindcssTransformation) Transform(ctx *resources.ResourceTransformat
return err
}

stdin, err := cmd.StdinPipe()
// See https://github.com/gohugoio/hugo/issues/12880
/*stdin, err := cmd.StdinPipe()
if err != nil {
return err
}

src := ctx.From
}*/

imp := newImportResolver(
ctx.From,
Expand All @@ -129,15 +129,29 @@ func (t *tailwindcssTransformation) Transform(ctx *resources.ResourceTransformat
t.rs.Assets.Fs, t.rs.Logger, ctx.DependencyManager,
)

src, err = imp.resolve()
src, err := imp.resolve()
if err != nil {
return err
}

tmpFile, err := os.CreateTemp("", "hugo-tailwindcss-*")
if err != nil {
return err
}
defer func() {
tmpFile.Close()
os.Remove(tmpFile.Name())
}()

_, err = io.Copy(tmpFile, src)
if err != nil {
return err
}

go func() {
/*go func() {
defer stdin.Close()
io.Copy(stdin, src)
}()
}()*/

err = cmd.Run()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func TestTailwindV4Basic(t *testing.T) {
"url": "https://github.com/bep/hugo-starter-tailwind-basic.git"
},
"devDependencies": {
"@tailwindcss/cli": "^4.0.0-alpha.16",
"tailwindcss": "^4.0.0-alpha.16"
"@tailwindcss/cli": "^4.0.0-alpha.25",
"tailwindcss": "^4.0.0-alpha.25"
},
"name": "hugo-starter-tailwind-basic",
"version": "0.1.0"
Expand Down

0 comments on commit af00412

Please sign in to comment.