litestar-vite 0.10.0__py3-none-any.whl → 0.11.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 +1 -1
- litestar_vite/commands.py +1 -1
- litestar_vite/plugin.py +73 -19
- {litestar_vite-0.10.0.dist-info → litestar_vite-0.11.0.dist-info}/METADATA +1 -1
- {litestar_vite-0.10.0.dist-info → litestar_vite-0.11.0.dist-info}/RECORD +7 -7
- {litestar_vite-0.10.0.dist-info → litestar_vite-0.11.0.dist-info}/WHEEL +0 -0
- {litestar_vite-0.10.0.dist-info → litestar_vite-0.11.0.dist-info}/licenses/LICENSE +0 -0
litestar_vite/cli.py
CHANGED
|
@@ -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()
|
litestar_vite/commands.py
CHANGED
|
@@ -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.
|
|
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"}
|
litestar_vite/plugin.py
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
185
|
+
self._vite_process.start(command_to_run, self._config.root_dir)
|
|
130
186
|
yield
|
|
131
187
|
finally:
|
|
132
|
-
|
|
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():
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
litestar_vite/__init__.py,sha256=OioNGhH88mdivQlFz9JlbJV8R6wyjSYE3c8C-RIM4Ls,277
|
|
2
2
|
litestar_vite/__metadata__.py,sha256=_Wo-vNQuj5co9J4FwJAB2rRafbFo8ztTHrXmEPrYrV8,514
|
|
3
|
-
litestar_vite/cli.py,sha256=
|
|
4
|
-
litestar_vite/commands.py,sha256=
|
|
3
|
+
litestar_vite/cli.py,sha256=CBSRohDLU9cDeKMAfSbFiw1x8OE_b15ZlUaxji9Rdw8,10749
|
|
4
|
+
litestar_vite/commands.py,sha256=aGpSmrRfArSg4hkpL6GTuKZPRyZm1y-qhon0P5mUoEQ,5228
|
|
5
5
|
litestar_vite/config.py,sha256=cZWIwTwNnBYScCty8OxxPaOL8cELx57dm7JQeV8og3Y,4565
|
|
6
6
|
litestar_vite/loader.py,sha256=nrXL2txXoBZEsdLZnysgBYZSreMXQ7ckLuNcu7MqnSM,10277
|
|
7
|
-
litestar_vite/plugin.py,sha256=
|
|
7
|
+
litestar_vite/plugin.py,sha256=XZ1RxyRS9aX3coJis02Uv2AMB2frI2eqKSlK_zZWwSY,8091
|
|
8
8
|
litestar_vite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
litestar_vite/inertia/__init__.py,sha256=Fab61KXbBnyub2Nx-2AHYv2U6QiYUIrqhEZia_f9xik,863
|
|
10
10
|
litestar_vite/inertia/_utils.py,sha256=ijO9Lgka7ZPIAHkby9szbTGoSg0nDShC2bqWT9cDxi0,1956
|
|
@@ -23,7 +23,7 @@ litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYu
|
|
|
23
23
|
litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
|
|
25
25
|
litestar_vite/templates/vite.config.ts.j2,sha256=bF5kOPFafYMkhhV0VkIwetN-_zoVMGVM1jEMX_wKoNc,1037
|
|
26
|
-
litestar_vite-0.
|
|
27
|
-
litestar_vite-0.
|
|
28
|
-
litestar_vite-0.
|
|
29
|
-
litestar_vite-0.
|
|
26
|
+
litestar_vite-0.11.0.dist-info/METADATA,sha256=vwSng0cRQYYu4oWOP7a0auIl2p7kLiaxUCOS3TT5fAA,6222
|
|
27
|
+
litestar_vite-0.11.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
28
|
+
litestar_vite-0.11.0.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
|
|
29
|
+
litestar_vite-0.11.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|