فهرست منبع

copy styles to the correct dir (#5024)

Masen Furer 1 ماه پیش
والد
کامیت
5b6afb1eb8
2فایلهای تغییر یافته به همراه23 افزوده شده و 9 حذف شده
  1. 1 2
      reflex/compiler/compiler.py
  2. 22 7
      tests/units/compiler/test_compiler.py

+ 1 - 2
reflex/compiler/compiler.py

@@ -224,8 +224,7 @@ def _compile_root_stylesheet(stylesheets: list[str]) -> str:
                 in constants.Reflex.STYLESHEETS_SUPPORTED
                 in constants.Reflex.STYLESHEETS_SUPPORTED
             ):
             ):
                 target = (
                 target = (
-                    Path.cwd()
-                    / constants.Dirs.WEB
+                    get_web_dir()
                     / constants.Dirs.STYLES
                     / constants.Dirs.STYLES
                     / (stylesheet.rsplit(".", 1)[0].strip("/") + ".css")
                     / (stylesheet.rsplit(".", 1)[0].strip("/") + ".css")
                 )
                 )

+ 22 - 7
tests/units/compiler/test_compiler.py

@@ -4,6 +4,7 @@ from pathlib import Path
 
 
 import pytest
 import pytest
 
 
+from reflex import constants
 from reflex.compiler import compiler, utils
 from reflex.compiler import compiler, utils
 from reflex.utils.imports import ImportVar, ParsedImportDict
 from reflex.utils.imports import ImportVar, ParsedImportDict
 
 
@@ -124,6 +125,13 @@ def test_compile_stylesheets(tmp_path: Path, mocker):
         "button.rt-Button {\n\tborder-radius:unset !important;\n}"
         "button.rt-Button {\n\tborder-radius:unset !important;\n}"
     )
     )
     mocker.patch("reflex.compiler.compiler.Path.cwd", return_value=project)
     mocker.patch("reflex.compiler.compiler.Path.cwd", return_value=project)
+    mocker.patch(
+        "reflex.compiler.compiler.get_web_dir",
+        return_value=project / constants.Dirs.WEB,
+    )
+    mocker.patch(
+        "reflex.compiler.utils.get_web_dir", return_value=project / constants.Dirs.WEB
+    )
 
 
     stylesheets = [
     stylesheets = [
         "https://fonts.googleapis.com/css?family=Sofia&effect=neon|outline|emboss|shadow-multiple",
         "https://fonts.googleapis.com/css?family=Sofia&effect=neon|outline|emboss|shadow-multiple",
@@ -133,7 +141,7 @@ def test_compile_stylesheets(tmp_path: Path, mocker):
     ]
     ]
 
 
     assert compiler.compile_root_stylesheet(stylesheets) == (
     assert compiler.compile_root_stylesheet(stylesheets) == (
-        str(Path(".web") / "styles" / "styles.css"),
+        str(project / constants.Dirs.WEB / "styles" / "styles.css"),
         "@import url('./tailwind.css'); \n"
         "@import url('./tailwind.css'); \n"
         "@import url('https://fonts.googleapis.com/css?family=Sofia&effect=neon|outline|emboss|shadow-multiple'); \n"
         "@import url('https://fonts.googleapis.com/css?family=Sofia&effect=neon|outline|emboss|shadow-multiple'); \n"
         "@import url('https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css'); \n"
         "@import url('https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css'); \n"
@@ -141,7 +149,7 @@ def test_compile_stylesheets(tmp_path: Path, mocker):
         "@import url('https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css'); \n",
         "@import url('https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css'); \n",
     )
     )
 
 
-    assert (project / ".web" / "styles" / "styles.css").read_text() == (
+    assert (project / constants.Dirs.WEB / "styles" / "styles.css").read_text() == (
         assets_dir / "styles.css"
         assets_dir / "styles.css"
     ).read_text()
     ).read_text()
 
 
@@ -173,6 +181,13 @@ def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker):
         "button.rt-Button {\n\tborder-radius:unset !important;\n}"
         "button.rt-Button {\n\tborder-radius:unset !important;\n}"
     )
     )
     mocker.patch("reflex.compiler.compiler.Path.cwd", return_value=project)
     mocker.patch("reflex.compiler.compiler.Path.cwd", return_value=project)
+    mocker.patch(
+        "reflex.compiler.compiler.get_web_dir",
+        return_value=project / constants.Dirs.WEB,
+    )
+    mocker.patch(
+        "reflex.compiler.utils.get_web_dir", return_value=project / constants.Dirs.WEB
+    )
 
 
     stylesheets = [
     stylesheets = [
         "/styles.css",
         "/styles.css",
@@ -181,7 +196,7 @@ def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker):
     ]
     ]
 
 
     assert compiler.compile_root_stylesheet(stylesheets) == (
     assert compiler.compile_root_stylesheet(stylesheets) == (
-        str(Path(".web") / "styles" / "styles.css"),
+        str(project / constants.Dirs.WEB / "styles" / "styles.css"),
         "@import url('./tailwind.css'); \n"
         "@import url('./tailwind.css'); \n"
         "@import url('./styles.css'); \n"
         "@import url('./styles.css'); \n"
         f"@import url('./{Path('preprocess') / Path('styles_a.css')!s}'); \n"
         f"@import url('./{Path('preprocess') / Path('styles_a.css')!s}'); \n"
@@ -194,23 +209,23 @@ def test_compile_stylesheets_scss_sass(tmp_path: Path, mocker):
     ]
     ]
 
 
     assert compiler.compile_root_stylesheet(stylesheets) == (
     assert compiler.compile_root_stylesheet(stylesheets) == (
-        str(Path(".web") / "styles" / "styles.css"),
+        str(project / constants.Dirs.WEB / "styles" / "styles.css"),
         "@import url('./tailwind.css'); \n"
         "@import url('./tailwind.css'); \n"
         "@import url('./styles.css'); \n"
         "@import url('./styles.css'); \n"
         f"@import url('./{Path('preprocess') / Path('styles_b.css')!s}'); \n"
         f"@import url('./{Path('preprocess') / Path('styles_b.css')!s}'); \n"
         f"@import url('./{Path('preprocess') / Path('styles_a.css')!s}'); \n",
         f"@import url('./{Path('preprocess') / Path('styles_a.css')!s}'); \n",
     )
     )
 
 
-    assert (project / ".web" / "styles" / "styles.css").read_text() == (
+    assert (project / constants.Dirs.WEB / "styles" / "styles.css").read_text() == (
         assets_dir / "styles.css"
         assets_dir / "styles.css"
     ).read_text()
     ).read_text()
 
 
     expected_result = "button.rt-Button{border-radius:unset !important}\n"
     expected_result = "button.rt-Button{border-radius:unset !important}\n"
     assert (
     assert (
-        project / ".web" / "styles" / "preprocess" / "styles_a.css"
+        project / constants.Dirs.WEB / "styles" / "preprocess" / "styles_a.css"
     ).read_text() == expected_result
     ).read_text() == expected_result
     assert (
     assert (
-        project / ".web" / "styles" / "preprocess" / "styles_b.css"
+        project / constants.Dirs.WEB / "styles" / "preprocess" / "styles_b.css"
     ).read_text() == expected_result
     ).read_text() == expected_result