@@ -146,6 +146,13 @@ def compile_tailwind(
146146 return output_path , code
147147
148148
149+ def _index_of_element_that_startswith (lines : list [str ], prefix : str ) -> int | None :
150+ return next (
151+ (i for i , line in enumerate (lines ) if line .strip ().startswith (prefix )),
152+ None ,
153+ )
154+
155+
149156def add_tailwind_to_postcss_config ():
150157 """Add tailwind to the postcss config."""
151158 from reflex .constants import Dirs
@@ -161,16 +168,11 @@ def add_tailwind_to_postcss_config():
161168
162169 postcss_file_lines = postcss_file .read_text ().splitlines ()
163170
164- if any ( line . strip (). startswith ( "tailwindcss" ) for line in postcss_file_lines ) :
171+ if _index_of_element_that_startswith ( postcss_file_lines , "tailwindcss" ) is not None :
165172 return
166173
167- line_with_postcss_plugins = next (
168- (
169- i
170- for i , line in enumerate (postcss_file_lines )
171- if line .strip ().startswith ("plugins" )
172- ),
173- None ,
174+ line_with_postcss_plugins = _index_of_element_that_startswith (
175+ postcss_file_lines , "plugins"
174176 )
175177 if not line_with_postcss_plugins :
176178 print ( # noqa: T201
@@ -179,15 +181,9 @@ def add_tailwind_to_postcss_config():
179181 )
180182 return
181183
182- postcss_import_line = next (
183- (
184- i
185- for i , line in enumerate (postcss_file_lines )
186- if line .strip ().startswith ('"postcss-import"' )
187- ),
188- None ,
184+ postcss_import_line = _index_of_element_that_startswith (
185+ postcss_file_lines , '"postcss-import"'
189186 )
190-
191187 postcss_file_lines .insert (
192188 (postcss_import_line or line_with_postcss_plugins ) + 1 , "tailwindcss: {},"
193189 )
0 commit comments