litestar-vite 0.13.1__py3-none-any.whl → 0.14.0__py3-none-any.whl

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.

litestar_vite/cli.py CHANGED
@@ -168,7 +168,6 @@ def vite_init(
168
168
  )
169
169
  install_dir = os.environ.get("VIRTUAL_ENV", sys.prefix)
170
170
  console.rule("[yellow]Starting Nodeenv installation process[/]", align="left")
171
- console.print(f"Installing Node environment into {install_dir}")
172
171
  execute_command(command_to_run=[nodeenv_command, install_dir, "--force", "--quiet"], cwd=root_path)
173
172
 
174
173
  console.rule("[yellow]Starting package installation process[/]", align="left")
@@ -206,7 +205,6 @@ def vite_install(app: "Litestar", verbose: "bool") -> None:
206
205
  )
207
206
  install_dir = os.environ.get("VIRTUAL_ENV", sys.prefix)
208
207
  console.rule("[yellow]Starting Nodeenv installation process[/]", align="left")
209
- console.print("Installing Node environment to %s:", install_dir)
210
208
  execute_command(command_to_run=[nodeenv_command, install_dir, "--force", "--quiet"], cwd=plugin.config.root_dir)
211
209
 
212
210
  console.rule("[yellow]Starting package installation process[/]", align="left")
litestar_vite/commands.py CHANGED
@@ -4,21 +4,25 @@ from collections.abc import MutableMapping
4
4
  from pathlib import Path
5
5
  from typing import TYPE_CHECKING, Any, Optional, Union
6
6
 
7
+ from litestar_vite.config import JINJA_INSTALLED
8
+ from litestar_vite.exceptions import MissingDependencyError
9
+
7
10
  if TYPE_CHECKING:
8
11
  from collections.abc import MutableMapping
9
12
 
10
13
  from jinja2 import Environment, Template
11
14
  from litestar import Litestar
12
15
 
16
+
13
17
  VITE_INIT_TEMPLATES: "set[str]" = {"package.json.j2", "tsconfig.json.j2", "vite.config.ts.j2"}
14
18
  DEFAULT_RESOURCES: "set[str]" = {"styles.css.j2", "main.ts.j2"}
15
19
  DEFAULT_DEV_DEPENDENCIES: "dict[str, str]" = {
16
- "typescript": "^5.7.2",
17
- "vite": "^6.0.6",
18
- "litestar-vite-plugin": "^0.13.1",
19
- "@types/node": "^22.10.2",
20
+ "typescript": "^5.8.3",
21
+ "vite": "^6.3.5",
22
+ "litestar-vite-plugin": "^0.14.0",
23
+ "@types/node": "^22.15.3",
20
24
  }
21
- DEFAULT_DEPENDENCIES: "dict[str, str]" = {"axios": "^1.7.9"}
25
+ DEFAULT_DEPENDENCIES: "dict[str, str]" = {"axios": "^1.9.0"}
22
26
 
23
27
 
24
28
  def to_json(value: "Any") -> str:
@@ -60,11 +64,17 @@ def init_vite(
60
64
  vite_port: Port for Vite dev server.
61
65
  hot_file: Path to hot reload manifest.
62
66
  litestar_port: Port for Litestar server.
67
+
68
+ Raises:
69
+ MissingDependencyError: If required dependencies are not installed.
63
70
  """
64
- from jinja2 import Environment, FileSystemLoader, select_autoescape
65
71
  from litestar.cli._utils import console # pyright: ignore[reportPrivateImportUsage]
66
72
  from litestar.utils import module_loader
67
73
 
74
+ if not JINJA_INSTALLED:
75
+ raise MissingDependencyError(package="jinja2", install_package="jinja")
76
+ from jinja2 import Environment, FileSystemLoader, select_autoescape
77
+
68
78
  template_path = module_loader.module_to_os_path("litestar_vite.templates")
69
79
  vite_template_env = Environment(
70
80
  loader=FileSystemLoader([template_path]),
@@ -128,6 +138,23 @@ def get_template(
128
138
  parent: "Optional[str]" = None,
129
139
  globals: "Optional[MutableMapping[str, Any]]" = None, # noqa: A002
130
140
  ) -> "Template":
141
+ """Get a template from the Jinja environment.
142
+
143
+ Args:
144
+ environment: The Jinja :class:`jinja2.Environment`.
145
+ name: Template name or :class:`jinja2.Template` object.
146
+ parent: Parent template name.
147
+ globals: Global variables for the template.
148
+
149
+ Returns:
150
+ The :class:`jinja2.Template` object.
151
+
152
+ Raises:
153
+ MissingDependencyError: If Jinja2 is not available.
154
+ """
155
+ if not JINJA_INSTALLED:
156
+ raise MissingDependencyError(package="jinja2", install_package="jinja")
157
+
131
158
  return environment.get_template(name=name, parent=parent, globals=globals)
132
159
 
133
160
 
litestar_vite/config.py CHANGED
@@ -1,10 +1,13 @@
1
1
  import os
2
2
  from dataclasses import dataclass, field
3
+ from importlib.util import find_spec
3
4
  from pathlib import Path
4
5
  from typing import Union
5
6
 
6
- __all__ = ("ViteConfig",)
7
+ __all__ = ("JINJA_INSTALLED", "ViteConfig")
8
+
7
9
  TRUE_VALUES = {"True", "true", "1", "yes", "Y", "T"}
10
+ JINJA_INSTALLED = bool(find_spec("jinja2"))
8
11
 
9
12
 
10
13
  @dataclass
@@ -0,0 +1,26 @@
1
+ """Litestar-Vite exception classes."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __all__ = ["LitestarViteError", "MissingDependencyError"]
6
+
7
+
8
+ class LitestarViteError(Exception):
9
+ """Base exception for Litestar-Vite related errors."""
10
+
11
+
12
+ class MissingDependencyError(LitestarViteError, ImportError):
13
+ """Raised when a package is not installed but required."""
14
+
15
+ def __init__(self, package: str, install_package: str | None = None) -> None:
16
+ """Initialize the exception.
17
+
18
+ Args:
19
+ package: The name of the missing package.
20
+ install_package: Optional alternative package name for installation.
21
+ """
22
+ super().__init__(
23
+ f"Package {package!r} is not installed but required. You can install it by running "
24
+ f"'pip install litestar-vite[{install_package or package}]' to install litestar-vite with the required extra "
25
+ f"or 'pip install {install_package or package}' to install the package separately"
26
+ )
@@ -21,7 +21,7 @@ class InertiaConfig:
21
21
  """Optionally supply a path where unauthorized requests should redirect."""
22
22
  redirect_404: "Optional[str]" = None
23
23
  """Optionally supply a path where 404 requests should redirect."""
24
- extra_static_page_props: "dict[str, Any]" = field(default_factory=dict)
24
+ extra_static_page_props: "dict[str, Any]" = field(default_factory=dict) # pyright: ignore
25
25
  """A dictionary of values to automatically add in to page props on every response."""
26
- extra_session_page_props: "set[str]" = field(default_factory=set)
26
+ extra_session_page_props: "set[str]" = field(default_factory=set) # pyright: ignore
27
27
  """A set of session keys for which the value automatically be added (if it exists) to the response."""
litestar_vite/loader.py CHANGED
@@ -104,7 +104,9 @@ class ViteAssetLoader(metaclass=SingletonMeta):
104
104
  Returns:
105
105
  The manifest loader.
106
106
  """
107
- return cls(config=config)
107
+ loader = cls(config=config)
108
+ loader.parse_manifest()
109
+ return loader
108
110
 
109
111
  @cached_property
110
112
  def version_id(self) -> str:
litestar_vite/plugin.py CHANGED
@@ -9,10 +9,11 @@ from pathlib import Path
9
9
  from typing import TYPE_CHECKING, Any, Optional, Union
10
10
 
11
11
  from litestar.cli._utils import console # pyright: ignore[reportPrivateImportUsage]
12
- from litestar.contrib.jinja import JinjaTemplateEngine
13
12
  from litestar.plugins import CLIPlugin, InitPluginProtocol
14
13
  from litestar.static_files import create_static_files_router # pyright: ignore[reportUnknownVariableType]
15
14
 
15
+ from litestar_vite.config import JINJA_INSTALLED
16
+
16
17
  if TYPE_CHECKING:
17
18
  from collections.abc import Iterator, Sequence
18
19
 
@@ -78,7 +79,6 @@ class ViteProcess:
78
79
  if self.process and self.process.poll() is None: # pyright: ignore[reportUnknownMemberType]
79
80
  return
80
81
 
81
- console.print(f"Starting Vite process with command: {command}")
82
82
  self.process = subprocess.Popen(
83
83
  command,
84
84
  cwd=cwd,
@@ -104,7 +104,6 @@ class ViteProcess:
104
104
  if hasattr(signal, "SIGKILL"):
105
105
  self.process.kill() # pyright: ignore[reportUnknownMemberType]
106
106
  self.process.wait(timeout=1.0) # pyright: ignore[reportUnknownMemberType]
107
- console.print("Stopping Vite process")
108
107
  except Exception as e:
109
108
  console.print(f"[red]Failed to stop Vite process: {e!s}[/]")
110
109
  raise
@@ -165,15 +164,21 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
165
164
  """
166
165
  from litestar_vite.loader import render_asset_tag, render_hmr_client
167
166
 
168
- if app_config.template_config and isinstance(app_config.template_config.engine_instance, JinjaTemplateEngine): # pyright: ignore[reportUnknownMemberType]
169
- app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
170
- key="vite_hmr",
171
- template_callable=render_hmr_client,
172
- )
173
- app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
174
- key="vite",
175
- template_callable=render_asset_tag,
176
- )
167
+ if JINJA_INSTALLED:
168
+ from litestar.contrib.jinja import JinjaTemplateEngine
169
+
170
+ if (
171
+ app_config.template_config # pyright: ignore[reportUnknownMemberType]
172
+ and isinstance(app_config.template_config.engine_instance, JinjaTemplateEngine) # pyright: ignore[reportUnknownMemberType]
173
+ ):
174
+ app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
175
+ key="vite_hmr",
176
+ template_callable=render_hmr_client,
177
+ )
178
+ app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
179
+ key="vite",
180
+ template_callable=render_asset_tag,
181
+ )
177
182
  if self._config.set_static_folders:
178
183
  static_dirs = [Path(self._config.bundle_dir), Path(self._config.resource_dir)]
179
184
  if Path(self._config.public_dir).exists() and self._config.public_dir != self._config.bundle_dir:
@@ -200,7 +205,8 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
200
205
  Yields:
201
206
  An iterator of None.
202
207
  """
203
-
208
+ if self._config.set_environment:
209
+ set_environment(config=self._config)
204
210
  if self._config.use_server_lifespan and self._config.dev_mode:
205
211
  command_to_run = self._config.run_command if self._config.hot_reload else self._config.build_watch_command
206
212
 
@@ -209,9 +215,6 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
209
215
  else:
210
216
  console.rule("[yellow]Starting Vite watch and build process[/]", align="left")
211
217
 
212
- if self._config.set_environment:
213
- set_environment(config=self._config)
214
-
215
218
  try:
216
219
  self._vite_process.start(command_to_run, self._config.root_dir)
217
220
  yield
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: litestar-vite
3
- Version: 0.13.1
3
+ Version: 0.14.0
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
@@ -29,7 +29,9 @@ Classifier: Topic :: Database :: Database Engines/Servers
29
29
  Classifier: Topic :: Software Development
30
30
  Classifier: Typing :: Typed
31
31
  Requires-Python: >=3.9
32
- Requires-Dist: litestar[jinja]>=2.7.0
32
+ Requires-Dist: litestar>=2.7.0
33
+ Provides-Extra: jinja
34
+ Requires-Dist: jinja2; extra == 'jinja'
33
35
  Provides-Extra: nodeenv
34
36
  Requires-Dist: nodeenv; extra == 'nodeenv'
35
37
  Description-Content-Type: text/markdown
@@ -73,7 +75,7 @@ app = Litestar(plugins=[vite], template_config=template_config, route_handlers=[
73
75
 
74
76
  ```
75
77
 
76
- Create a template to serve the application in `./templates/index.html.h2`:
78
+ Create a template to serve the application in `./templates/index.html.j2`:
77
79
 
78
80
  ```html
79
81
  <!DOCTYPE html>
@@ -1,14 +1,15 @@
1
1
  litestar_vite/__init__.py,sha256=QykOZjCNHyDZJNIF84fa-6ze-lajDAGcoi18LxeV-0E,241
2
2
  litestar_vite/__metadata__.py,sha256=dMGIPS6M11LcmiEfnMJJrbSPH8Lf00pU8crIIUsIBPw,478
3
- litestar_vite/cli.py,sha256=_BlglaeRbRf2zja0uCg51FpCier7hPVrte5XHJYDDR4,11208
4
- litestar_vite/commands.py,sha256=O4B6-C7r45NJfEl6xuHL4rSCz7JjITMN3UnsB_94dgs,5385
5
- litestar_vite/config.py,sha256=K3C3uhfcllINGAkOUS4tTah-mhhx74GYwNF4ME92eOA,4592
6
- litestar_vite/loader.py,sha256=gHhLUb4GgJF8zxEl-5xirNX_cU1ZyMz4ZT9f8WCg8XY,11746
7
- litestar_vite/plugin.py,sha256=_4ZWdfUBzF93hT5qG9fiPW54LaSFJvYsRmavUcAgQQI,9277
3
+ litestar_vite/cli.py,sha256=W3bpXZSt_ne0pdDZQCGi_naMEakp7MA-oD_r1BJI0cQ,11058
4
+ litestar_vite/commands.py,sha256=aHubdOrSim0RFtJX5zg9UkfXyQN53Q_PB058quGlUfw,6218
5
+ litestar_vite/config.py,sha256=gWnXhWw4XggC82bWQEa2BtqxzR_AdhqZeRuLYvYy3N4,4692
6
+ litestar_vite/exceptions.py,sha256=E37ficSm9V8iMYTPThtLX0Dm0gsK80rV8a0IT8I0MGo,991
7
+ litestar_vite/loader.py,sha256=opF-YJh0fnu1cpH2uJ4aLmK9PZpsREa4yEEajYV9yVs,11802
8
+ litestar_vite/plugin.py,sha256=4b3I9yc73YAZcnnT_1jvCzN_5s-jFlzS0tHBZwLHyHg,9351
8
9
  litestar_vite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
10
  litestar_vite/inertia/__init__.py,sha256=KGvxCZhnOw06Pqx5_qjUxj0WWsCR3BR0cVnuNMT7sKQ,1136
10
11
  litestar_vite/inertia/_utils.py,sha256=HZOedWduCu3fCMniuFvstEcXzP2FA1IBwPZ3E2XNBEo,2529
11
- litestar_vite/inertia/config.py,sha256=M8YStJKvUGSWc4LOzkbIuj8_q70vDNHsUyy3dtBHvNY,1220
12
+ litestar_vite/inertia/config.py,sha256=i_Ji1SnWVt2hNClpAvIVTw-vb3L8TLPW_1f27QG5OEc,1258
12
13
  litestar_vite/inertia/exception_handler.py,sha256=FfaPp7eiU_yo6sNU6WVRpKTkn6Npti7lFp1Rg-94Tqs,5576
13
14
  litestar_vite/inertia/helpers.py,sha256=rk8P7Gh705JPaKLh9LONr-hDHrMBOEdUn-89NMEu_Bg,10876
14
15
  litestar_vite/inertia/middleware.py,sha256=gyKZIOtsQmEq0nPjr2CJ-_qddZ1JsepROLO-CDSNEZM,1621
@@ -24,7 +25,7 @@ litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYu
24
25
  litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
26
  litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
26
27
  litestar_vite/templates/vite.config.ts.j2,sha256=bF5kOPFafYMkhhV0VkIwetN-_zoVMGVM1jEMX_wKoNc,1037
27
- litestar_vite-0.13.1.dist-info/METADATA,sha256=X9oK-Oj6UfzsBoposYyD0Q6CatC5FpXGQMZkoDeZiqY,6245
28
- litestar_vite-0.13.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
- litestar_vite-0.13.1.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
30
- litestar_vite-0.13.1.dist-info/RECORD,,
28
+ litestar_vite-0.14.0.dist-info/METADATA,sha256=nuE0TkAISpQ4HgWkAR44A--wBbRsNwSO9-7l_DjkxgA,6300
29
+ litestar_vite-0.14.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
30
+ litestar_vite-0.14.0.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
31
+ litestar_vite-0.14.0.dist-info/RECORD,,