litestar-vite 0.1.19__tar.gz → 0.1.21__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of litestar-vite might be problematic. Click here for more details.

Files changed (62) hide show
  1. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/.github/workflows/ci.yaml +1 -1
  2. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/.pre-commit-config.yaml +2 -2
  3. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/PKG-INFO +3 -3
  4. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/cli.py +32 -13
  5. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/commands.py +11 -7
  6. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/config.py +10 -4
  7. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/plugin.py +13 -5
  8. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/templates/vite.config.ts.j2 +4 -1
  9. litestar_vite-0.1.21/package-lock.json +920 -0
  10. litestar_vite-0.1.21/package.json +11 -0
  11. litestar_vite-0.1.21/pdm.lock +1747 -0
  12. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/pyproject.toml +74 -27
  13. litestar_vite-0.1.21/tests/conftest.py +27 -0
  14. litestar_vite-0.1.21/tests/templates/index.html.j2 +18 -0
  15. litestar_vite-0.1.21/tests/test_cli/__init__.py +4 -0
  16. litestar_vite-0.1.21/tests/test_cli/conftest.py +155 -0
  17. litestar_vite-0.1.21/tests/test_cli/test_init.py +36 -0
  18. litestar_vite-0.1.21/tests/test_commands.py +13 -0
  19. litestar_vite-0.1.21/tests/test_config.py +12 -0
  20. litestar_vite-0.1.19/pdm.lock +0 -2026
  21. litestar_vite-0.1.19/tests/docker-compose.yml +0 -9
  22. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/.github/CODEOWNERS +0 -0
  23. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/.github/workflows/cd.yaml +0 -0
  24. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/.github/workflows/docs-preview.yaml +0 -0
  25. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/.github/workflows/docs.yaml +0 -0
  26. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/.github/workflows/pr-title.yaml +0 -0
  27. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/.github/workflows/publish.yaml +0 -0
  28. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/.gitignore +0 -0
  29. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/CONTRIBUTING.rst +0 -0
  30. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/LICENSE +0 -0
  31. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/Makefile +0 -0
  32. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/README.md +0 -0
  33. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/docs/Makefile +0 -0
  34. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/docs/conf.py +0 -0
  35. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/docs/contribution-guide.rst +0 -0
  36. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/docs/fix_missing_references.py +0 -0
  37. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/docs/index.rst +0 -0
  38. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/docs/reference/config.rst +0 -0
  39. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/docs/reference/plugin.rst +0 -0
  40. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/docs/usage/index.rst +0 -0
  41. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/docs/usage/placeholder.rst +0 -0
  42. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/__init__.py +0 -0
  43. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/vanilla/__init__.py +0 -0
  44. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/vanilla/app.py +0 -0
  45. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/vanilla/package-lock.json +0 -0
  46. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/vanilla/package.json +0 -0
  47. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/vanilla/resources/main.ts +0 -0
  48. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/vanilla/resources/styles.css +0 -0
  49. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/vanilla/templates/index.html.j2 +0 -0
  50. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/vanilla/tsconfig.json +0 -0
  51. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/examples/vanilla/vite.config.ts +0 -0
  52. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/__init__.py +0 -0
  53. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/__metadata__.py +0 -0
  54. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/loader.py +0 -0
  55. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/py.typed +0 -0
  56. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/template_engine.py +0 -0
  57. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/templates/__init__.py +0 -0
  58. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/templates/index.html.j2 +0 -0
  59. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/templates/main.css.j2 +0 -0
  60. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/templates/package.json.j2 +0 -0
  61. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/litestar_vite/templates/tsconfig.json.j2 +0 -0
  62. {litestar_vite-0.1.19 → litestar_vite-0.1.21}/tests/__init__.py +0 -0
@@ -52,7 +52,7 @@ jobs:
52
52
  run: pdm install
53
53
 
54
54
  - name: Test
55
- run: pdm run pytest -m "" -n auto
55
+ run: pdm run pytest -m ""
56
56
 
57
57
  build-docs:
58
58
  needs:
@@ -17,7 +17,7 @@ repos:
17
17
  - id: mixed-line-ending
18
18
  - id: trailing-whitespace
19
19
  - repo: https://github.com/charliermarsh/ruff-pre-commit
20
- rev: "v0.2.2"
20
+ rev: "v0.3.3"
21
21
  hooks:
22
22
  - id: ruff
23
23
  args: ["--fix"]
@@ -27,7 +27,7 @@ repos:
27
27
  hooks:
28
28
  - id: codespell
29
29
  - repo: https://github.com/pre-commit/mirrors-mypy
30
- rev: "v1.8.0"
30
+ rev: "v1.9.0"
31
31
  hooks:
32
32
  - id: mypy
33
33
  exclude: "docs"
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: litestar-vite
3
- Version: 0.1.19
3
+ Version: 0.1.21
4
4
  Summary: Vite plugin for Litestar
5
5
  Project-URL: Changelog, https://cofin.github.io/litestar-vite/latest/changelog
6
6
  Project-URL: Discord, https://discord.gg/X3FJqy8d2j
@@ -30,7 +30,7 @@ Classifier: Topic :: Database :: Database Engines/Servers
30
30
  Classifier: Topic :: Software Development
31
31
  Classifier: Typing :: Typed
32
32
  Requires-Python: >=3.8
33
- Requires-Dist: litestar[cli,jinja]>=2.4.0
33
+ Requires-Dist: litestar[jinja]>=2.4.0
34
34
  Provides-Extra: nodeenv
35
35
  Requires-Dist: nodeenv; extra == 'nodeenv'
36
36
  Description-Content-Type: text/markdown
@@ -19,10 +19,17 @@ def vite_group() -> None:
19
19
  """Manage Vite Tasks."""
20
20
 
21
21
 
22
- @vite_group.command( # type: ignore # noqa: PGH003
22
+ @vite_group.command(
23
23
  name="init",
24
24
  help="Initialize vite for your project.",
25
25
  )
26
+ @option(
27
+ "--root-path",
28
+ type=ClickPath(dir_okay=True, file_okay=False, path_type=Path),
29
+ help="The path for the initial the Vite application. This is the equivalent to the top-level folder in a normal Vue or React application..",
30
+ default=None,
31
+ required=False,
32
+ )
26
33
  @option(
27
34
  "--bundle-path",
28
35
  type=ClickPath(dir_okay=True, file_okay=False, path_type=Path),
@@ -37,6 +44,13 @@ def vite_group() -> None:
37
44
  default=None,
38
45
  required=False,
39
46
  )
47
+ @option(
48
+ "--public-path",
49
+ type=ClickPath(dir_okay=True, file_okay=False, path_type=Path),
50
+ help="The optional path to your public/static JS assets. If this were a standalone Vue or React app, this would point to your `public/` folder.",
51
+ default=None,
52
+ required=False,
53
+ )
40
54
  @option("--asset-url", type=str, help="Base url to serve assets from.", default=None, required=False)
41
55
  @option(
42
56
  "--vite-port",
@@ -79,8 +93,10 @@ def vite_init(
79
93
  vite_port: int | None,
80
94
  enable_ssr: bool | None,
81
95
  asset_url: str | None,
96
+ root_path: Path | None,
82
97
  bundle_path: Path | None,
83
98
  resource_path: Path | None,
99
+ public_path: Path | None,
84
100
  overwrite: bool,
85
101
  verbose: bool,
86
102
  no_prompt: bool,
@@ -106,16 +122,18 @@ def vite_init(
106
122
  ctx.obj.app.debug = True
107
123
  env: LitestarEnv = ctx.obj
108
124
  plugin = env.app.plugins.get(VitePlugin)
109
- config = plugin._config # noqa: SLF001
125
+ config = plugin._config
110
126
 
111
127
  console.rule("[yellow]Initializing Vite[/]", align="left")
112
128
  resource_path = Path(resource_path or config.resource_dir)
129
+ public_path = Path(public_path or config.public_dir)
113
130
  bundle_path = Path(bundle_path or config.bundle_dir)
114
131
  enable_ssr = enable_ssr or config.ssr_enabled
115
132
  asset_url = asset_url or config.asset_url
116
133
  vite_port = vite_port or config.port
117
134
  hot_file = Path(bundle_path / config.hot_file)
118
- root_path = resource_path.parent
135
+ root_path = Path(root_path or config.root_dir or resource_path.parent)
136
+
119
137
  if any(output_path.exists() for output_path in (bundle_path, resource_path)) and not any(
120
138
  [overwrite, no_prompt],
121
139
  ):
@@ -125,7 +143,7 @@ def vite_init(
125
143
  if not confirm_overwrite:
126
144
  console.print("Skipping Vite initialization")
127
145
  sys.exit(2)
128
- for output_path in (bundle_path, resource_path):
146
+ for output_path in (bundle_path, resource_path, root_path):
129
147
  output_path.mkdir(parents=True, exist_ok=True)
130
148
 
131
149
  enable_ssr = (
@@ -144,6 +162,7 @@ def vite_init(
144
162
  vite_port=vite_port,
145
163
  asset_url=asset_url,
146
164
  resource_path=resource_path,
165
+ public_path=public_path,
147
166
  bundle_path=bundle_path,
148
167
  hot_file=hot_file,
149
168
  litestar_port=env.port or 8000,
@@ -159,14 +178,14 @@ def vite_init(
159
178
  install_dir = os.environ.get("VIRTUAL_ENV", sys.prefix)
160
179
  console.rule("[yellow]Starting Nodeenv installation process[/]", align="left")
161
180
  console.print(f"Installing Node environment into {install_dir}")
162
- execute_command([nodeenv_command, install_dir, "--force", "--quiet"])
181
+ execute_command(command_to_run=[nodeenv_command, install_dir, "--force", "--quiet"], cwd=root_path)
163
182
 
164
183
  console.rule("[yellow]Starting package installation process[/]", align="left")
165
184
 
166
- execute_command(plugin.config.install_command)
185
+ execute_command(command_to_run=plugin.config.install_command, cwd=root_path)
167
186
 
168
187
 
169
- @vite_group.command( # type: ignore # noqa: PGH003
188
+ @vite_group.command(
170
189
  name="install",
171
190
  help="Install frontend packages.",
172
191
  )
@@ -197,14 +216,14 @@ def vite_install(app: Litestar, verbose: bool) -> None:
197
216
  install_dir = os.environ.get("VIRTUAL_ENV", sys.prefix)
198
217
  console.rule("[yellow]Starting Nodeenv installation process[/]", align="left")
199
218
  console.print("Installing Node environment to %s:", install_dir)
200
- execute_command([nodeenv_command, install_dir, "--force", "--quiet"])
219
+ execute_command(command_to_run=[nodeenv_command, install_dir, "--force", "--quiet"], cwd=plugin.config.root_dir)
201
220
 
202
221
  console.rule("[yellow]Starting package installation process[/]", align="left")
203
222
 
204
- execute_command(plugin.config.install_command)
223
+ execute_command(command_to_run=plugin.config.install_command, cwd=plugin.config.root_dir)
205
224
 
206
225
 
207
- @vite_group.command( # type: ignore # noqa: PGH003
226
+ @vite_group.command(
208
227
  name="build",
209
228
  help="Building frontend assets with Vite.",
210
229
  )
@@ -224,14 +243,14 @@ def vite_build(app: Litestar, verbose: bool) -> None:
224
243
  plugin = app.plugins.get(VitePlugin)
225
244
  if plugin.config.set_environment:
226
245
  set_environment(config=plugin.config)
227
- p = execute_command(plugin.config.build_command)
246
+ p = execute_command(command_to_run=plugin.config.build_command, cwd=plugin.config.root_dir)
228
247
  if p.returncode == 0:
229
248
  console.print("[bold green] Assets built.[/]")
230
249
  else:
231
250
  console.print("[bold red] There was an error building the assets.[/]")
232
251
 
233
252
 
234
- @vite_group.command( # type: ignore # noqa: PGH003
253
+ @vite_group.command(
235
254
  name="serve",
236
255
  help="Serving frontend assets with Vite.",
237
256
  )
@@ -256,5 +275,5 @@ def vite_serve(app: Litestar, verbose: bool) -> None:
256
275
  else:
257
276
  console.rule("[yellow]Starting Vite watch and build process[/]", align="left")
258
277
  command_to_run = plugin.config.run_command if plugin.config.hot_reload else plugin.config.build_watch_command
259
- execute_command(command_to_run)
278
+ execute_command(command_to_run=command_to_run, cwd=plugin.config.root_dir)
260
279
  console.print("[yellow]Vite process stopped.[/]")
@@ -5,9 +5,6 @@ import subprocess
5
5
  from pathlib import Path
6
6
  from typing import TYPE_CHECKING, Any, MutableMapping
7
7
 
8
- from jinja2 import select_autoescape
9
- from litestar.serialization import encode_json
10
-
11
8
  if TYPE_CHECKING:
12
9
  from jinja2 import Environment, Template
13
10
  from litestar import Litestar
@@ -33,14 +30,17 @@ def to_json(value: Any) -> str:
33
30
  Returns:
34
31
  JSON string.
35
32
  """
33
+ from litestar.serialization import encode_json
34
+
36
35
  return encode_json(value).decode("utf-8")
37
36
 
38
37
 
39
38
  def init_vite(
40
- app: Litestar, # noqa: ARG001
39
+ app: Litestar,
41
40
  root_path: Path,
42
41
  resource_path: Path,
43
42
  asset_url: str,
43
+ public_path: Path,
44
44
  bundle_path: Path,
45
45
  enable_ssr: bool,
46
46
  vite_port: int,
@@ -48,7 +48,7 @@ def init_vite(
48
48
  litestar_port: int,
49
49
  ) -> None:
50
50
  """Initialize a new vite project."""
51
- from jinja2 import Environment, FileSystemLoader
51
+ from jinja2 import Environment, FileSystemLoader, select_autoescape
52
52
  from litestar.cli._utils import console
53
53
 
54
54
  entry_point: list[str] = []
@@ -81,6 +81,7 @@ def init_vite(
81
81
  asset_url=asset_url,
82
82
  root_path=str(root_path.relative_to(Path.cwd().absolute())),
83
83
  resource_path=str(resource_path.relative_to(root_path)),
84
+ public_path=str(public_path.relative_to(root_path)),
84
85
  bundle_path=str(bundle_path.relative_to(root_path)),
85
86
  hot_file=str(hot_file.relative_to(Path.cwd().absolute())),
86
87
  vite_port=str(vite_port),
@@ -105,6 +106,9 @@ def get_template(
105
106
  return environment.get_template(name=name, parent=parent, globals=globals)
106
107
 
107
108
 
108
- def execute_command(command_to_run: list[str]) -> subprocess.CompletedProcess[bytes]:
109
+ def execute_command(command_to_run: list[str], cwd: str | Path | None = None) -> subprocess.CompletedProcess[bytes]:
109
110
  """Run Vite in a subprocess."""
110
- return subprocess.run(command_to_run, check=False, shell=platform.system() == "Windows") # noqa: S603
111
+ kwargs = {}
112
+ if cwd is not None:
113
+ kwargs["cwd"] = Path(cwd)
114
+ return subprocess.run(command_to_run, check=False, shell=platform.system() == "Windows", **kwargs) # type: ignore[call-overload]
@@ -43,7 +43,11 @@ class ViteConfig:
43
43
  In a standalone Vue or React application, this would be equivalent to the ``./src`` directory.
44
44
  """
45
45
  template_dir: Path | str | None = field(default=None)
46
- """Location of the Jinja2 template file.
46
+ """Location of the Jinja2 template file."""
47
+ public_dir: Path | str = field(default="public")
48
+ """The optional public directory Vite serves assets from.
49
+
50
+ In a standalone Vue or React application, this would be equivalent to the ``./public`` directory.
47
51
  """
48
52
  manifest_name: str = "manifest.json"
49
53
  """Name of the manifest file."""
@@ -63,12 +67,12 @@ class ViteConfig:
63
67
  root_dir: Path | str | None = None
64
68
  """The is the base path to your application.
65
69
 
66
- In a standalone Vue or React application, this would be equivalent to the ``./src`` directory.
70
+ In a standalone Vue or React application, this would be equivalent to the top-level project folder containing the ``./src`` directory.
67
71
 
68
72
  """
69
73
  is_react: bool = False
70
74
  """Enable React components."""
71
- asset_url: str =field(default_factory=lambda: os.getenv("ASSET_URL", "/static/"))
75
+ asset_url: str = field(default_factory=lambda: os.getenv("ASSET_URL", "/static/"))
72
76
  """Base URL to generate for static asset references.
73
77
 
74
78
  This URL will be prepended to anything generated from Vite.
@@ -91,7 +95,7 @@ class ViteConfig:
91
95
  default_factory=lambda: os.getenv("VITE_USE_SERVER_LIFESPAN", "False") in {"True", "1", "yes", "Y", "T"},
92
96
  )
93
97
  """Utilize the server lifespan hook to run Vite."""
94
- dev_mode: bool = field(
98
+ dev_mode: bool = field(
95
99
  default_factory=lambda: os.getenv("VITE_DEV_MODE", "False") in {"True", "1", "yes", "Y", "T"},
96
100
  )
97
101
  """When True, Vite will run with HMR or watch build"""
@@ -112,6 +116,8 @@ class ViteConfig:
112
116
  self.root_dir = Path(self.root_dir)
113
117
  if self.template_dir is not None and isinstance(self.template_dir, str):
114
118
  self.template_dir = Path(self.template_dir)
119
+ if self.public_dir is not None and isinstance(self.public_dir, str):
120
+ self.public_dir = Path(self.public_dir)
115
121
  if isinstance(self.resource_dir, str):
116
122
  self.resource_dir = Path(self.resource_dir)
117
123
  if isinstance(self.bundle_dir, str):
@@ -2,7 +2,8 @@ from __future__ import annotations
2
2
 
3
3
  import os
4
4
  from contextlib import contextmanager
5
- from typing import TYPE_CHECKING, Iterator
5
+ from pathlib import Path
6
+ from typing import TYPE_CHECKING, Iterator, cast
6
7
 
7
8
  from litestar.plugins import CLIPlugin, InitPluginProtocol
8
9
  from litestar.static_files import create_static_files_router
@@ -66,14 +67,19 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
66
67
  )
67
68
 
68
69
  if self._config.set_static_folders:
70
+ static_dirs = [Path(self._config.bundle_dir), Path(self._config.resource_dir)]
71
+ if Path(self._config.public_dir).exists() and self._config.public_dir != self._config.bundle_dir:
72
+ static_dirs.append(Path(self._config.public_dir))
69
73
  app_config.route_handlers.append(
70
74
  create_static_files_router(
71
- directories=[self._config.bundle_dir, self._config.resource_dir]
72
- if self._config.dev_mode
73
- else [self._config.bundle_dir],
75
+ directories=cast( # type: ignore[arg-type]
76
+ "list[Path]",
77
+ static_dirs if self._config.dev_mode else [Path(self._config.bundle_dir)],
78
+ ),
74
79
  path=self._config.asset_url,
75
80
  name="vite",
76
81
  html_mode=False,
82
+ include_in_schema=False,
77
83
  opt={"exclude_from_auth": True},
78
84
  ),
79
85
  )
@@ -96,8 +102,10 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
96
102
  if self._config.set_environment:
97
103
  set_environment(config=self._config)
98
104
  vite_thread = threading.Thread(
105
+ name="vite",
99
106
  target=execute_command,
100
- args=[command_to_run],
107
+ args=[],
108
+ kwargs={"command_to_run": command_to_run, "cwd": self._config.root_dir},
101
109
  )
102
110
  try:
103
111
  vite_thread.start()
@@ -10,9 +10,12 @@ export default defineConfig({
10
10
  base: `${ASSET_URL}`,
11
11
  {% if root_path and root_path != '.' %} root: "{{ root_path }}",{% endif %}
12
12
  server: {
13
- host: `${VITE_HOST}`,
13
+ host: "0.0.0.0",
14
14
  port: +`${VITE_PORT}`,
15
15
  cors: true,
16
+ hmr: {
17
+ host: `${VITE_HOST}`,
18
+ },
16
19
  },
17
20
  plugins: [
18
21
  {% if include_vue %}vue(),{% endif %}