@@ -38,8 +38,10 @@ func TestProcessCSSRunsStandaloneCommand(t *testing.T) {
3838 t .Fatal (err )
3939 }
4040 argsFile := filepath .Join (root , "args.txt" )
41+ cwdFile := filepath .Join (root , "cwd.txt" )
4142 inputCopy := filepath .Join (root , "generated-input.css" )
4243 t .Setenv ("TAILWIND_ARGS_FILE" , argsFile )
44+ t .Setenv ("TAILWIND_CWD_FILE" , cwdFile )
4345 t .Setenv ("TAILWIND_INPUT_COPY" , inputCopy )
4446
4547 result , err := Addon (Options {
@@ -66,6 +68,17 @@ func TestProcessCSSRunsStandaloneCommand(t *testing.T) {
6668 if len (result .Stylesheets ) != 1 || result .Stylesheets [0 ].Href != "/assets/site.css" {
6769 t .Fatalf ("unexpected stylesheets: %#v" , result .Stylesheets )
6870 }
71+ wantCWD , err := os .Getwd ()
72+ if err != nil {
73+ t .Fatal (err )
74+ }
75+ cwd , err := os .ReadFile (cwdFile )
76+ if err != nil {
77+ t .Fatal (err )
78+ }
79+ if strings .TrimSpace (string (cwd )) != wantCWD {
80+ t .Fatalf ("expected tailwind command to run in %q, got %q" , wantCWD , cwd )
81+ }
6982
7083 args , err := os .ReadFile (argsFile )
7184 if err != nil {
@@ -89,6 +102,63 @@ func TestProcessCSSRunsStandaloneCommand(t *testing.T) {
89102 }
90103}
91104
105+ func TestProcessCSSResolvesRelativePathsFromContextWorkingDir (t * testing.T ) {
106+ root := t .TempDir ()
107+ if err := os .Mkdir (filepath .Join (root , "styles" ), 0o755 ); err != nil {
108+ t .Fatal (err )
109+ }
110+ input := filepath .Join (root , "styles" , "app.css" )
111+ if err := os .WriteFile (input , []byte (`@import "tailwindcss";` ), 0o644 ); err != nil {
112+ t .Fatal (err )
113+ }
114+ argsFile := filepath .Join (root , "args.txt" )
115+ cwdFile := filepath .Join (root , "cwd.txt" )
116+ inputCopy := filepath .Join (root , "generated-input.css" )
117+ t .Setenv ("TAILWIND_ARGS_FILE" , argsFile )
118+ t .Setenv ("TAILWIND_CWD_FILE" , cwdFile )
119+ t .Setenv ("TAILWIND_INPUT_COPY" , inputCopy )
120+
121+ other := t .TempDir ()
122+ previous , err := os .Getwd ()
123+ if err != nil {
124+ t .Fatal (err )
125+ }
126+ if err := os .Chdir (other ); err != nil {
127+ t .Fatal (err )
128+ }
129+ t .Cleanup (func () {
130+ if err := os .Chdir (previous ); err != nil {
131+ t .Fatal (err )
132+ }
133+ })
134+
135+ _ , err = Addon (Options {
136+ Input : "styles/app.css" ,
137+ Command : fakeTailwindCommand (t ),
138+ }).ProcessCSS (gowdk.CSSContext {
139+ WorkingDir : root ,
140+ Sources : []gowdk.CSSSource {{Path : "site.page.gwdk" }},
141+ })
142+ if err != nil {
143+ t .Fatal (err )
144+ }
145+ cwd , err := os .ReadFile (cwdFile )
146+ if err != nil {
147+ t .Fatal (err )
148+ }
149+ if strings .TrimSpace (string (cwd )) != root {
150+ t .Fatalf ("expected tailwind command to run in %q, got %q" , root , cwd )
151+ }
152+ generatedInput , err := os .ReadFile (inputCopy )
153+ if err != nil {
154+ t .Fatal (err )
155+ }
156+ generated := string (generatedInput )
157+ if ! strings .Contains (generated , `styles/app.css` ) {
158+ t .Fatalf ("expected generated input to reference context-relative input, got:\n %s" , generated )
159+ }
160+ }
161+
92162func TestProcessCSSReportsMissingExecutable (t * testing.T ) {
93163 input := filepath .Join (t .TempDir (), "app.css" )
94164 if err := os .WriteFile (input , []byte (`@import "tailwindcss";` ), 0o644 ); err != nil {
@@ -195,6 +265,9 @@ func fakeTailwindCommand(t *testing.T) string {
195265
196266const fakeTailwindScript = `#!/bin/sh
197267set -eu
268+ if [ "${TAILWIND_CWD_FILE:-}" != "" ]; then
269+ pwd > "$TAILWIND_CWD_FILE"
270+ fi
198271printf '%s\n' "$@" > "$TAILWIND_ARGS_FILE"
199272out=""
200273in=""
0 commit comments