litestar-vite 0.10.0__tar.gz → 0.11.0__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 (71) hide show
  1. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/PKG-INFO +1 -1
  2. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/pyproject.toml +2 -2
  3. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/cli.py +1 -1
  4. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/commands.py +1 -1
  5. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/plugin.py +73 -19
  6. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/.gitignore +0 -0
  7. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/LICENSE +0 -0
  8. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/README.md +0 -0
  9. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/LICENSE +0 -0
  10. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/Makefile +0 -0
  11. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/NOTICE +0 -0
  12. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/README.md +0 -0
  13. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/src/dev-server-index.html +0 -0
  14. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/src/index.ts +0 -0
  15. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/src/inertia-helpers/index.ts +0 -0
  16. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/tests/__data__/dummy.ts +0 -0
  17. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/tests/index.test.ts +0 -0
  18. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/tsconfig.inertia-helpers.json +0 -0
  19. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/tsconfig.json +0 -0
  20. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/vitest.config.ts +0 -0
  21. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/js/vitest.workspace.ts +0 -0
  22. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/__init__.py +0 -0
  23. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/__metadata__.py +0 -0
  24. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/config.py +0 -0
  25. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/__init__.py +0 -0
  26. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/_utils.py +0 -0
  27. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/config.py +0 -0
  28. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/exception_handler.py +0 -0
  29. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/middleware.py +0 -0
  30. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/plugin.py +0 -0
  31. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/request.py +0 -0
  32. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/response.py +0 -0
  33. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/routes.py +0 -0
  34. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/inertia/types.py +0 -0
  35. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/loader.py +0 -0
  36. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/py.typed +0 -0
  37. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/templates/__init__.py +0 -0
  38. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/templates/index.html.j2 +0 -0
  39. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/templates/main.ts.j2 +0 -0
  40. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/templates/package.json.j2 +0 -0
  41. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/templates/styles.css.j2 +0 -0
  42. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/templates/tsconfig.json.j2 +0 -0
  43. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/litestar_vite/templates/vite.config.ts.j2 +0 -0
  44. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/__init__.py +0 -0
  45. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/conftest.py +0 -0
  46. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/templates/__init__.py +0 -0
  47. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/templates/index.html.j2 +0 -0
  48. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/__init__.py +0 -0
  49. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/app.py +0 -0
  50. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/__init__.py +0 -0
  51. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/public/.gitkeep +0 -0
  52. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/public/assets/main-l0sNRNKZ.js +0 -0
  53. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/public/assets/styles-l0sNRNKZ.js +0 -0
  54. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/public/manifest.json +0 -0
  55. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/resources/.gitkeep +0 -0
  56. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/resources/main.ts +0 -0
  57. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/resources/styles.css +0 -0
  58. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/templates/.gitkeep +0 -0
  59. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_app/web/templates/index.html +0 -0
  60. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_asset_loader.py +0 -0
  61. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_cli/__init__.py +0 -0
  62. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_cli/conftest.py +0 -0
  63. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_cli/test_init.py +0 -0
  64. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_commands.py +0 -0
  65. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_config.py +0 -0
  66. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_inertia/__init__.py +0 -0
  67. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_inertia/conftest.py +0 -0
  68. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_inertia/templates/index.html.j2 +0 -0
  69. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_inertia/test_inertia_request.py +0 -0
  70. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_inertia/test_inertia_response.py +0 -0
  71. {litestar_vite-0.10.0 → litestar_vite-0.11.0}/src/py/tests/test_inertia/test_routes.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: litestar-vite
3
- Version: 0.10.0
3
+ Version: 0.11.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
@@ -25,7 +25,7 @@ license = { text = "MIT" }
25
25
  name = "litestar-vite"
26
26
  readme = "README.md"
27
27
  requires-python = ">=3.8"
28
- version = "0.10.0"
28
+ version = "0.11.0"
29
29
 
30
30
  [project.urls]
31
31
  Changelog = "https://cofin.github.io/litestar-vite/latest/changelog"
@@ -85,7 +85,7 @@ test = [
85
85
  allow_dirty = true
86
86
  commit = true
87
87
  commit_args = "--no-verify"
88
- current_version = "0.10.0"
88
+ current_version = "0.11.0"
89
89
  ignore_missing_files = false
90
90
  ignore_missing_version = false
91
91
  message = "chore(release): bump to v{new_version}"
@@ -113,8 +113,8 @@ def vite_init(
113
113
  )
114
114
  from rich.prompt import Confirm
115
115
 
116
+ from litestar_vite import VitePlugin
116
117
  from litestar_vite.commands import execute_command, init_vite
117
- from litestar_vite.plugin import VitePlugin
118
118
 
119
119
  if callable(ctx.obj):
120
120
  ctx.obj = ctx.obj()
@@ -14,7 +14,7 @@ DEFAULT_RESOURCES: set[str] = {"styles.css.j2", "main.ts.j2"}
14
14
  DEFAULT_DEV_DEPENDENCIES: dict[str, str] = {
15
15
  "typescript": "^5.7.2",
16
16
  "vite": "^6.0.3",
17
- "litestar-vite-plugin": "^0.10.0",
17
+ "litestar-vite-plugin": "^0.11.0",
18
18
  "@types/node": "^22.10.1",
19
19
  }
20
20
  DEFAULT_DEPENDENCIES: dict[str, str] = {"axios": "^1.7.2"}
@@ -1,6 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
+ import signal
5
+ import threading
4
6
  from contextlib import contextmanager
5
7
  from pathlib import Path
6
8
  from typing import TYPE_CHECKING, Iterator, cast
@@ -10,14 +12,14 @@ from litestar.exceptions import ImproperlyConfiguredException
10
12
  from litestar.plugins import CLIPlugin, InitPluginProtocol
11
13
  from litestar.static_files import create_static_files_router # pyright: ignore[reportUnknownVariableType]
12
14
 
13
- from litestar_vite.config import ViteConfig
14
- from litestar_vite.loader import ViteAssetLoader, render_asset_tag, render_hmr_client
15
-
16
15
  if TYPE_CHECKING:
17
16
  from click import Group
18
17
  from litestar import Litestar
19
18
  from litestar.config.app import AppConfig
20
19
 
20
+ from litestar_vite.config import ViteConfig
21
+ from litestar_vite.loader import ViteAssetLoader
22
+
21
23
 
22
24
  def set_environment(config: ViteConfig) -> None:
23
25
  """Configure environment for easier integration"""
@@ -31,11 +33,64 @@ def set_environment(config: ViteConfig) -> None:
31
33
  os.environ.setdefault("VITE_DEV_MODE", str(config.dev_mode))
32
34
 
33
35
 
36
+ class ViteProcess:
37
+ """Manages the Vite process."""
38
+
39
+ def __init__(self) -> None:
40
+ self.process: threading.Thread | None = None
41
+ self._lock = threading.Lock()
42
+
43
+ def start(self, command: list[str], cwd: Path | str | None) -> None:
44
+ """Start the Vite process."""
45
+ from litestar.cli._utils import console
46
+
47
+ from litestar_vite.commands import execute_command
48
+
49
+ try:
50
+ with self._lock:
51
+ if self.process and self.process.is_alive():
52
+ return
53
+
54
+ self.process = threading.Thread(
55
+ name="vite",
56
+ target=execute_command,
57
+ args=[],
58
+ kwargs={"command_to_run": command, "cwd": cwd},
59
+ daemon=True, # Make thread daemon so it exits when main thread exits
60
+ )
61
+ console.print(f"Starting Vite process with command: {command}")
62
+ self.process.start()
63
+ except Exception as e:
64
+ console.print(f"[red]Failed to start Vite process: {e!s}[/]")
65
+ raise
66
+
67
+ def stop(self, timeout: float = 5.0) -> None:
68
+ """Stop the Vite process."""
69
+ from litestar.cli._utils import console
70
+
71
+ try:
72
+ with self._lock:
73
+ if self.process and self.process.is_alive():
74
+ # Send SIGTERM to child process
75
+ if hasattr(signal, "SIGTERM") and self.process.ident is not None:
76
+ os.kill(self.process.ident, signal.SIGTERM)
77
+ self.process.join(timeout=timeout)
78
+
79
+ # Force kill if still alive
80
+ if self.process.is_alive():
81
+ if hasattr(signal, "SIGKILL") and self.process.ident is not None:
82
+ os.kill(self.process.ident, signal.SIGKILL)
83
+ self.process.join(timeout=1.0)
84
+ console.print("Stopping Vite process")
85
+ except Exception as e:
86
+ console.print(f"[red]Failed to stop Vite process: {e!s}[/]")
87
+ raise
88
+
89
+
34
90
  class VitePlugin(InitPluginProtocol, CLIPlugin):
35
91
  """Vite plugin."""
36
92
 
37
- __slots__ = ("_asset_loader", "_config")
38
- _asset_loader: ViteAssetLoader | None
93
+ __slots__ = ("_asset_loader", "_config", "_vite_process")
39
94
 
40
95
  def __init__(self, config: ViteConfig | None = None, asset_loader: ViteAssetLoader | None = None) -> None:
41
96
  """Initialize ``Vite``.
@@ -44,10 +99,13 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
44
99
  config: configuration to use for starting Vite. The default configuration will be used if it is not provided.
45
100
  asset_loader: an initialized asset loader to use for rendering asset tags.
46
101
  """
102
+ from litestar_vite.config import ViteConfig
103
+
47
104
  if config is None:
48
105
  config = ViteConfig()
49
106
  self._config = config
50
107
  self._asset_loader = asset_loader
108
+ self._vite_process = ViteProcess()
51
109
 
52
110
  @property
53
111
  def config(self) -> ViteConfig:
@@ -55,6 +113,8 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
55
113
 
56
114
  @property
57
115
  def asset_loader(self) -> ViteAssetLoader:
116
+ from litestar_vite.loader import ViteAssetLoader
117
+
58
118
  if self._asset_loader is None:
59
119
  self._asset_loader = ViteAssetLoader.initialize_loader(config=self._config)
60
120
  return self._asset_loader
@@ -70,6 +130,8 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
70
130
  Args:
71
131
  app_config: The :class:`AppConfig <litestar.config.app.AppConfig>` instance.
72
132
  """
133
+ from litestar_vite.loader import render_asset_tag, render_hmr_client
134
+
73
135
  if app_config.template_config is None: # pyright: ignore[reportUnknownMemberType]
74
136
  msg = "A template configuration is required for Vite."
75
137
  raise ImproperlyConfiguredException(msg)
@@ -105,34 +167,26 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
105
167
 
106
168
  @contextmanager
107
169
  def server_lifespan(self, app: Litestar) -> Iterator[None]:
108
- import threading
109
-
170
+ """Manage Vite server process lifecycle."""
110
171
  from litestar.cli._utils import console
111
172
 
112
- from litestar_vite.commands import execute_command
113
-
114
173
  if self._config.use_server_lifespan and self._config.dev_mode:
115
174
  command_to_run = self._config.run_command if self._config.hot_reload else self._config.build_watch_command
175
+
116
176
  if self.config.hot_reload:
117
177
  console.rule("[yellow]Starting Vite process with HMR Enabled[/]", align="left")
118
178
  else:
119
179
  console.rule("[yellow]Starting Vite watch and build process[/]", align="left")
180
+
120
181
  if self._config.set_environment:
121
182
  set_environment(config=self._config)
122
- vite_thread = threading.Thread(
123
- name="vite",
124
- target=execute_command,
125
- args=[],
126
- kwargs={"command_to_run": command_to_run, "cwd": self._config.root_dir},
127
- )
183
+
128
184
  try:
129
- vite_thread.start()
185
+ self._vite_process.start(command_to_run, self._config.root_dir)
130
186
  yield
131
187
  finally:
132
- if vite_thread.is_alive():
133
- vite_thread.join(timeout=5)
188
+ self._vite_process.stop()
134
189
  console.print("[yellow]Vite process stopped.[/]")
135
-
136
190
  else:
137
191
  manifest_path = Path(f"{self._config.bundle_dir}/{self._config.manifest_name}")
138
192
  if manifest_path.exists():
File without changes
File without changes