litestar-vite 0.13.0__py3-none-any.whl → 0.13.2__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/__init__.py +0 -2
- litestar_vite/__metadata__.py +0 -2
- litestar_vite/cli.py +33 -40
- litestar_vite/commands.py +48 -38
- litestar_vite/config.py +6 -7
- litestar_vite/inertia/_utils.py +53 -17
- litestar_vite/inertia/config.py +5 -7
- litestar_vite/inertia/exception_handler.py +22 -8
- litestar_vite/inertia/helpers.py +57 -61
- litestar_vite/inertia/middleware.py +4 -6
- litestar_vite/inertia/plugin.py +22 -9
- litestar_vite/inertia/request.py +58 -20
- litestar_vite/inertia/response.py +42 -40
- litestar_vite/inertia/routes.py +7 -9
- litestar_vite/inertia/types.py +6 -8
- litestar_vite/loader.py +95 -29
- litestar_vite/plugin.py +42 -38
- {litestar_vite-0.13.0.dist-info → litestar_vite-0.13.2.dist-info}/METADATA +3 -3
- litestar_vite-0.13.2.dist-info/RECORD +30 -0
- litestar_vite-0.13.0.dist-info/RECORD +0 -30
- {litestar_vite-0.13.0.dist-info → litestar_vite-0.13.2.dist-info}/WHEEL +0 -0
- {litestar_vite-0.13.0.dist-info → litestar_vite-0.13.2.dist-info}/licenses/LICENSE +0 -0
litestar_vite/inertia/routes.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
from dataclasses import dataclass
|
|
4
2
|
from functools import cached_property
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from typing import TYPE_CHECKING, Optional
|
|
6
4
|
|
|
7
5
|
from litestar.app import DEFAULT_OPENAPI_CONFIG
|
|
8
6
|
from litestar.cli._utils import (
|
|
9
|
-
remove_default_schema_routes,
|
|
10
|
-
remove_routes_with_patterns,
|
|
7
|
+
remove_default_schema_routes, # pyright: ignore[reportPrivateImportUsage]
|
|
8
|
+
remove_routes_with_patterns, # pyright: ignore[reportPrivateImportUsage]
|
|
11
9
|
)
|
|
12
10
|
from litestar.routes import ASGIRoute, WebSocketRoute
|
|
13
11
|
from litestar.serialization import encode_json
|
|
@@ -29,10 +27,10 @@ EXCLUDED_METHODS = {"HEAD", "OPTIONS", "TRACE"}
|
|
|
29
27
|
|
|
30
28
|
|
|
31
29
|
def generate_js_routes(
|
|
32
|
-
app: Litestar,
|
|
33
|
-
exclude: tuple[str, ...]
|
|
34
|
-
schema: bool = False,
|
|
35
|
-
) -> Routes:
|
|
30
|
+
app: "Litestar",
|
|
31
|
+
exclude: "Optional[tuple[str, ...]]" = None,
|
|
32
|
+
schema: "bool" = False,
|
|
33
|
+
) -> "Routes":
|
|
36
34
|
sorted_routes = sorted(app.routes, key=lambda r: r.path)
|
|
37
35
|
if not schema:
|
|
38
36
|
openapi_config = app.openapi_config or DEFAULT_OPENAPI_CONFIG
|
litestar_vite/inertia/types.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
from dataclasses import dataclass
|
|
4
|
-
from typing import Any, Generic, TypedDict, TypeVar
|
|
2
|
+
from typing import Any, Generic, Optional, TypedDict, TypeVar
|
|
5
3
|
|
|
6
4
|
__all__ = (
|
|
7
5
|
"InertiaHeaderType",
|
|
@@ -32,8 +30,8 @@ class InertiaProps(Generic[T]):
|
|
|
32
30
|
class InertiaHeaderType(TypedDict, total=False):
|
|
33
31
|
"""Type for inertia_headers parameter in get_headers()."""
|
|
34
32
|
|
|
35
|
-
enabled: bool
|
|
36
|
-
version: str
|
|
37
|
-
location: str
|
|
38
|
-
partial_data: str
|
|
39
|
-
partial_component: str
|
|
33
|
+
enabled: "Optional[bool]"
|
|
34
|
+
version: "Optional[str]"
|
|
35
|
+
location: "Optional[str]"
|
|
36
|
+
partial_data: "Optional[str]"
|
|
37
|
+
partial_component: "Optional[str]"
|
litestar_vite/loader.py
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
import json
|
|
4
2
|
from functools import cached_property
|
|
5
3
|
from pathlib import Path
|
|
6
4
|
from textwrap import dedent
|
|
7
|
-
from typing import TYPE_CHECKING, Any,
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
|
8
6
|
from urllib.parse import urljoin
|
|
9
7
|
|
|
10
8
|
import markupsafe
|
|
11
9
|
from litestar.exceptions import ImproperlyConfiguredException
|
|
12
10
|
|
|
13
11
|
if TYPE_CHECKING:
|
|
12
|
+
from collections.abc import Mapping
|
|
13
|
+
|
|
14
14
|
from litestar.connection import Request
|
|
15
15
|
|
|
16
16
|
from litestar_vite.config import ViteConfig
|
|
17
17
|
from litestar_vite.plugin import VitePlugin
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def _get_request_from_context(context: Mapping[str, Any]) -> Request[Any, Any, Any]:
|
|
20
|
+
def _get_request_from_context(context: "Mapping[str, Any]") -> "Request[Any, Any, Any]":
|
|
21
21
|
"""Get the request from the template context.
|
|
22
22
|
|
|
23
23
|
Args:
|
|
@@ -29,7 +29,7 @@ def _get_request_from_context(context: Mapping[str, Any]) -> Request[Any, Any, A
|
|
|
29
29
|
return cast("Request[Any, Any, Any]", context["request"])
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def render_hmr_client(context: Mapping[str, Any], /) -> markupsafe.Markup:
|
|
32
|
+
def render_hmr_client(context: "Mapping[str, Any]", /) -> "markupsafe.Markup":
|
|
33
33
|
"""Render the HMR client.
|
|
34
34
|
|
|
35
35
|
Args:
|
|
@@ -44,8 +44,8 @@ def render_hmr_client(context: Mapping[str, Any], /) -> markupsafe.Markup:
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def render_asset_tag(
|
|
47
|
-
context: Mapping[str, Any], /, path: str
|
|
48
|
-
) -> markupsafe.Markup:
|
|
47
|
+
context: "Mapping[str, Any]", /, path: "Union[str, list[str]]", scripts_attrs: "Optional[dict[str, str]]" = None
|
|
48
|
+
) -> "markupsafe.Markup":
|
|
49
49
|
"""Render an asset tag.
|
|
50
50
|
|
|
51
51
|
Args:
|
|
@@ -61,42 +61,86 @@ def render_asset_tag(
|
|
|
61
61
|
).asset_loader.render_asset_tag(path, scripts_attrs)
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
class
|
|
64
|
+
class SingletonMeta(type):
|
|
65
|
+
"""Singleton metaclass."""
|
|
66
|
+
|
|
67
|
+
_instances: "dict[type, Any]" = {}
|
|
68
|
+
|
|
69
|
+
def __call__(cls, *args: "Any", **kwargs: "Any") -> "Any":
|
|
70
|
+
if cls not in cls._instances: # pyright: ignore[reportUnnecessaryContains]
|
|
71
|
+
cls._instances[cls] = super().__call__(*args, **kwargs)
|
|
72
|
+
return cls._instances[cls]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ViteAssetLoader(metaclass=SingletonMeta):
|
|
65
76
|
"""Vite manifest loader.
|
|
66
77
|
|
|
67
78
|
Please see: https://vitejs.dev/guide/backend-integration.html
|
|
68
79
|
"""
|
|
69
80
|
|
|
70
|
-
|
|
81
|
+
_config: "ViteConfig"
|
|
82
|
+
_manifest: "dict[str, Any]"
|
|
83
|
+
_manifest_content: "str"
|
|
84
|
+
_vite_base_path: "Optional[str]"
|
|
85
|
+
|
|
86
|
+
def __init__(self, config: "ViteConfig") -> None:
|
|
87
|
+
"""Initialize the manifest loader.
|
|
71
88
|
|
|
72
|
-
|
|
89
|
+
Args:
|
|
90
|
+
config: The Vite configuration.
|
|
91
|
+
"""
|
|
73
92
|
self._config = config
|
|
74
|
-
self._manifest: dict[str, Any] = {}
|
|
75
|
-
self._manifest_content: str = ""
|
|
76
|
-
self._vite_base_path: str
|
|
93
|
+
self._manifest: "dict[str, Any]" = {}
|
|
94
|
+
self._manifest_content: "str" = ""
|
|
95
|
+
self._vite_base_path: "Optional[str]" = None
|
|
77
96
|
|
|
78
97
|
@classmethod
|
|
79
|
-
def initialize_loader(cls, config: ViteConfig) -> ViteAssetLoader:
|
|
80
|
-
"""
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
def initialize_loader(cls, config: "ViteConfig") -> "ViteAssetLoader":
|
|
99
|
+
"""Initialize the manifest loader.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
config: The Vite configuration.
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
The manifest loader.
|
|
106
|
+
"""
|
|
107
|
+
loader = cls(config=config)
|
|
108
|
+
loader.parse_manifest()
|
|
109
|
+
return loader
|
|
85
110
|
|
|
86
111
|
@cached_property
|
|
87
112
|
def version_id(self) -> str:
|
|
88
|
-
|
|
113
|
+
"""Get the version ID of the manifest.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
The version ID of the manifest.
|
|
117
|
+
"""
|
|
118
|
+
if self._manifest_content:
|
|
89
119
|
return str(hash(self.manifest_content))
|
|
90
120
|
return "1.0"
|
|
91
121
|
|
|
92
|
-
def render_hmr_client(self) -> markupsafe.Markup:
|
|
93
|
-
"""
|
|
122
|
+
def render_hmr_client(self) -> "markupsafe.Markup":
|
|
123
|
+
"""Render the HMR client.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
The HMR client.
|
|
127
|
+
"""
|
|
94
128
|
return markupsafe.Markup(
|
|
95
129
|
f"{self.generate_react_hmr_tags()}{self.generate_ws_client_tags()}",
|
|
96
130
|
)
|
|
97
131
|
|
|
98
|
-
def render_asset_tag(
|
|
99
|
-
|
|
132
|
+
def render_asset_tag(
|
|
133
|
+
self, path: "Union[str, list[str]]", scripts_attrs: "Optional[dict[str, str]]" = None
|
|
134
|
+
) -> "markupsafe.Markup":
|
|
135
|
+
"""Render an asset tag.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
path: The path to the asset.
|
|
139
|
+
scripts_attrs: The attributes for the script tag.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
The asset tag.
|
|
143
|
+
"""
|
|
100
144
|
path = [str(p) for p in path] if isinstance(path, list) else [str(path)]
|
|
101
145
|
return markupsafe.Markup(
|
|
102
146
|
"".join([self.generate_asset_tags(p, scripts_attrs=scripts_attrs) for p in path]),
|
|
@@ -131,6 +175,9 @@ class ViteAssetLoader:
|
|
|
131
175
|
}
|
|
132
176
|
|
|
133
177
|
The manifest is parsed and stored in memory for asset resolution during template rendering.
|
|
178
|
+
|
|
179
|
+
Raises:
|
|
180
|
+
RuntimeError: If the manifest file is not found or cannot be read.
|
|
134
181
|
"""
|
|
135
182
|
if self._config.hot_reload and self._config.dev_mode:
|
|
136
183
|
hot_file_path = Path(
|
|
@@ -191,9 +238,18 @@ class ViteAssetLoader:
|
|
|
191
238
|
""")
|
|
192
239
|
return ""
|
|
193
240
|
|
|
194
|
-
def generate_asset_tags(
|
|
241
|
+
def generate_asset_tags(
|
|
242
|
+
self, path: "Union[str, list[str]]", scripts_attrs: "Optional[dict[str, str]]" = None
|
|
243
|
+
) -> str:
|
|
195
244
|
"""Generate all assets include tags for the file in argument.
|
|
196
245
|
|
|
246
|
+
Args:
|
|
247
|
+
path: The path to the asset.
|
|
248
|
+
scripts_attrs: The attributes for the script tag.
|
|
249
|
+
|
|
250
|
+
Raises:
|
|
251
|
+
ImproperlyConfiguredException: If the manifest file is not found or cannot be read.
|
|
252
|
+
|
|
197
253
|
Returns:
|
|
198
254
|
str: All tags to import this asset in your HTML page.
|
|
199
255
|
"""
|
|
@@ -250,7 +306,7 @@ class ViteAssetLoader:
|
|
|
250
306
|
)
|
|
251
307
|
return "".join(tags)
|
|
252
308
|
|
|
253
|
-
def _vite_server_url(self, path: str
|
|
309
|
+
def _vite_server_url(self, path: "Optional[str]" = None) -> str:
|
|
254
310
|
"""Generate an URL to and asset served by the Vite development server.
|
|
255
311
|
|
|
256
312
|
Keyword Arguments:
|
|
@@ -265,14 +321,24 @@ class ViteAssetLoader:
|
|
|
265
321
|
urljoin(self._config.asset_url, path if path is not None else ""),
|
|
266
322
|
)
|
|
267
323
|
|
|
268
|
-
|
|
269
|
-
|
|
324
|
+
@staticmethod
|
|
325
|
+
def _script_tag(src: str, attrs: "Optional[dict[str, str]]" = None) -> str:
|
|
326
|
+
"""Generate an HTML script tag.
|
|
327
|
+
|
|
328
|
+
Args:
|
|
329
|
+
src: The source of the script.
|
|
330
|
+
attrs: The attributes for the script tag.
|
|
331
|
+
|
|
332
|
+
Returns:
|
|
333
|
+
str: The script tag.
|
|
334
|
+
"""
|
|
270
335
|
if attrs is None:
|
|
271
336
|
attrs = {}
|
|
272
337
|
attrs_str = " ".join([f'{key}="{value}"' for key, value in attrs.items()])
|
|
273
338
|
return f'<script {attrs_str} src="{src}"></script>'
|
|
274
339
|
|
|
275
|
-
|
|
340
|
+
@staticmethod
|
|
341
|
+
def _style_tag(href: str) -> str:
|
|
276
342
|
"""Generate and HTML <link> stylesheet tag for CSS.
|
|
277
343
|
|
|
278
344
|
Args:
|
litestar_vite/plugin.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
import os
|
|
4
2
|
import platform
|
|
5
3
|
import signal
|
|
@@ -8,14 +6,16 @@ import threading
|
|
|
8
6
|
from contextlib import contextmanager
|
|
9
7
|
from dataclasses import dataclass
|
|
10
8
|
from pathlib import Path
|
|
11
|
-
from typing import TYPE_CHECKING, Any,
|
|
9
|
+
from typing import TYPE_CHECKING, Any, Optional, Union
|
|
12
10
|
|
|
13
|
-
from litestar.cli._utils import console
|
|
11
|
+
from litestar.cli._utils import console # pyright: ignore[reportPrivateImportUsage]
|
|
14
12
|
from litestar.contrib.jinja import JinjaTemplateEngine
|
|
15
13
|
from litestar.plugins import CLIPlugin, InitPluginProtocol
|
|
16
14
|
from litestar.static_files import create_static_files_router # pyright: ignore[reportUnknownVariableType]
|
|
17
15
|
|
|
18
16
|
if TYPE_CHECKING:
|
|
17
|
+
from collections.abc import Iterator, Sequence
|
|
18
|
+
|
|
19
19
|
from click import Group
|
|
20
20
|
from litestar import Litestar
|
|
21
21
|
from litestar.config.app import AppConfig
|
|
@@ -34,40 +34,43 @@ if TYPE_CHECKING:
|
|
|
34
34
|
from litestar_vite.loader import ViteAssetLoader
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
def set_environment(config: ViteConfig) -> None:
|
|
37
|
+
def set_environment(config: "ViteConfig") -> None:
|
|
38
38
|
"""Configure environment for easier integration"""
|
|
39
|
+
from litestar import __version__ as litestar_version
|
|
40
|
+
|
|
39
41
|
os.environ.setdefault("ASSET_URL", config.asset_url)
|
|
40
42
|
os.environ.setdefault("VITE_ALLOW_REMOTE", str(True))
|
|
41
43
|
os.environ.setdefault("VITE_PORT", str(config.port))
|
|
42
44
|
os.environ.setdefault("VITE_HOST", config.host)
|
|
43
45
|
os.environ.setdefault("VITE_PROTOCOL", config.protocol)
|
|
44
|
-
os.environ.setdefault("
|
|
46
|
+
os.environ.setdefault("LITESTAR_VERSION", litestar_version.formatted())
|
|
47
|
+
os.environ.setdefault("APP_URL", f"http://localhost:{os.environ.get('LITESTAR_PORT', '8000')}")
|
|
45
48
|
if config.dev_mode:
|
|
46
49
|
os.environ.setdefault("VITE_DEV_MODE", str(config.dev_mode))
|
|
47
50
|
|
|
48
51
|
|
|
49
52
|
@dataclass
|
|
50
53
|
class StaticFilesConfig:
|
|
51
|
-
after_request: AfterRequestHookHandler
|
|
52
|
-
after_response: AfterResponseHookHandler
|
|
53
|
-
before_request: BeforeRequestHookHandler
|
|
54
|
-
cache_control: CacheControlHeader
|
|
55
|
-
exception_handlers: ExceptionHandlersMap
|
|
56
|
-
guards: list[Guard]
|
|
57
|
-
middleware: Sequence[Middleware]
|
|
58
|
-
opt: dict[str, Any]
|
|
59
|
-
security: Sequence[SecurityRequirement]
|
|
60
|
-
tags: Sequence[str]
|
|
54
|
+
after_request: "Optional[AfterRequestHookHandler]" = None
|
|
55
|
+
after_response: "Optional[AfterResponseHookHandler]" = None
|
|
56
|
+
before_request: "Optional[BeforeRequestHookHandler]" = None
|
|
57
|
+
cache_control: "Optional[CacheControlHeader]" = None
|
|
58
|
+
exception_handlers: "Optional[ExceptionHandlersMap]" = None
|
|
59
|
+
guards: "Optional[list[Guard]]" = None
|
|
60
|
+
middleware: "Optional[Sequence[Middleware]]" = None
|
|
61
|
+
opt: "Optional[dict[str, Any]]" = None
|
|
62
|
+
security: "Optional[Sequence[SecurityRequirement]]" = None
|
|
63
|
+
tags: "Optional[Sequence[str]]" = None
|
|
61
64
|
|
|
62
65
|
|
|
63
66
|
class ViteProcess:
|
|
64
67
|
"""Manages the Vite process."""
|
|
65
68
|
|
|
66
69
|
def __init__(self) -> None:
|
|
67
|
-
self.process: subprocess.Popen
|
|
70
|
+
self.process: "Optional[subprocess.Popen]" = None # pyright: ignore[reportUnknownMemberType,reportMissingTypeArgument]
|
|
68
71
|
self._lock = threading.Lock()
|
|
69
72
|
|
|
70
|
-
def start(self, command: list[str], cwd: Path
|
|
73
|
+
def start(self, command: "list[str]", cwd: "Union[Path, str, None]") -> None:
|
|
71
74
|
"""Start the Vite process."""
|
|
72
75
|
|
|
73
76
|
try:
|
|
@@ -75,7 +78,6 @@ class ViteProcess:
|
|
|
75
78
|
if self.process and self.process.poll() is None: # pyright: ignore[reportUnknownMemberType]
|
|
76
79
|
return
|
|
77
80
|
|
|
78
|
-
console.print(f"Starting Vite process with command: {command}")
|
|
79
81
|
self.process = subprocess.Popen(
|
|
80
82
|
command,
|
|
81
83
|
cwd=cwd,
|
|
@@ -101,7 +103,6 @@ class ViteProcess:
|
|
|
101
103
|
if hasattr(signal, "SIGKILL"):
|
|
102
104
|
self.process.kill() # pyright: ignore[reportUnknownMemberType]
|
|
103
105
|
self.process.wait(timeout=1.0) # pyright: ignore[reportUnknownMemberType]
|
|
104
|
-
console.print("Stopping Vite process")
|
|
105
106
|
except Exception as e:
|
|
106
107
|
console.print(f"[red]Failed to stop Vite process: {e!s}[/]")
|
|
107
108
|
raise
|
|
@@ -114,9 +115,9 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
|
|
|
114
115
|
|
|
115
116
|
def __init__(
|
|
116
117
|
self,
|
|
117
|
-
config: ViteConfig
|
|
118
|
-
asset_loader: ViteAssetLoader
|
|
119
|
-
static_files_config: StaticFilesConfig
|
|
118
|
+
config: "Optional[ViteConfig]" = None,
|
|
119
|
+
asset_loader: "Optional[ViteAssetLoader]" = None,
|
|
120
|
+
static_files_config: "Optional[StaticFilesConfig]" = None,
|
|
120
121
|
) -> None:
|
|
121
122
|
"""Initialize ``Vite``.
|
|
122
123
|
|
|
@@ -132,30 +133,33 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
|
|
|
132
133
|
self._config = config
|
|
133
134
|
self._asset_loader = asset_loader
|
|
134
135
|
self._vite_process = ViteProcess()
|
|
135
|
-
self._static_files_config: dict[str, Any] = static_files_config.__dict__ if static_files_config else {}
|
|
136
|
+
self._static_files_config: "dict[str, Any]" = static_files_config.__dict__ if static_files_config else {}
|
|
136
137
|
|
|
137
138
|
@property
|
|
138
|
-
def config(self) -> ViteConfig:
|
|
139
|
+
def config(self) -> "ViteConfig":
|
|
139
140
|
return self._config
|
|
140
141
|
|
|
141
142
|
@property
|
|
142
|
-
def asset_loader(self) -> ViteAssetLoader:
|
|
143
|
+
def asset_loader(self) -> "ViteAssetLoader":
|
|
143
144
|
from litestar_vite.loader import ViteAssetLoader
|
|
144
145
|
|
|
145
146
|
if self._asset_loader is None:
|
|
146
147
|
self._asset_loader = ViteAssetLoader.initialize_loader(config=self._config)
|
|
147
148
|
return self._asset_loader
|
|
148
149
|
|
|
149
|
-
def on_cli_init(self, cli: Group) -> None:
|
|
150
|
+
def on_cli_init(self, cli: "Group") -> None:
|
|
150
151
|
from litestar_vite.cli import vite_group
|
|
151
152
|
|
|
152
153
|
cli.add_command(vite_group)
|
|
153
154
|
|
|
154
|
-
def on_app_init(self, app_config: AppConfig) -> AppConfig:
|
|
155
|
+
def on_app_init(self, app_config: "AppConfig") -> "AppConfig":
|
|
155
156
|
"""Configure application for use with Vite.
|
|
156
157
|
|
|
157
158
|
Args:
|
|
158
159
|
app_config: The :class:`AppConfig <litestar.config.app.AppConfig>` instance.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
The :class:`AppConfig <litestar.config.app.AppConfig>` instance.
|
|
159
163
|
"""
|
|
160
164
|
from litestar_vite.loader import render_asset_tag, render_hmr_client
|
|
161
165
|
|
|
@@ -185,9 +189,17 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
|
|
|
185
189
|
return app_config
|
|
186
190
|
|
|
187
191
|
@contextmanager
|
|
188
|
-
def server_lifespan(self, app: Litestar) -> Iterator[None]:
|
|
189
|
-
"""Manage Vite server process lifecycle.
|
|
192
|
+
def server_lifespan(self, app: "Litestar") -> "Iterator[None]":
|
|
193
|
+
"""Manage Vite server process lifecycle.
|
|
190
194
|
|
|
195
|
+
Args:
|
|
196
|
+
app: The :class:`Litestar <litestar.app.Litestar>` instance.
|
|
197
|
+
|
|
198
|
+
Yields:
|
|
199
|
+
An iterator of None.
|
|
200
|
+
"""
|
|
201
|
+
if self._config.set_environment:
|
|
202
|
+
set_environment(config=self._config)
|
|
191
203
|
if self._config.use_server_lifespan and self._config.dev_mode:
|
|
192
204
|
command_to_run = self._config.run_command if self._config.hot_reload else self._config.build_watch_command
|
|
193
205
|
|
|
@@ -196,9 +208,6 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
|
|
|
196
208
|
else:
|
|
197
209
|
console.rule("[yellow]Starting Vite watch and build process[/]", align="left")
|
|
198
210
|
|
|
199
|
-
if self._config.set_environment:
|
|
200
|
-
set_environment(config=self._config)
|
|
201
|
-
|
|
202
211
|
try:
|
|
203
212
|
self._vite_process.start(command_to_run, self._config.root_dir)
|
|
204
213
|
yield
|
|
@@ -206,9 +215,4 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
|
|
|
206
215
|
self._vite_process.stop()
|
|
207
216
|
console.print("[yellow]Vite process stopped.[/]")
|
|
208
217
|
else:
|
|
209
|
-
manifest_path = Path(f"{self._config.bundle_dir}/{self._config.manifest_name}")
|
|
210
|
-
if manifest_path.exists():
|
|
211
|
-
console.rule(f"[yellow]Serving assets using manifest at `{manifest_path!s}`.[/]", align="left")
|
|
212
|
-
else:
|
|
213
|
-
console.rule(f"[yellow]Serving assets without manifest at `{manifest_path!s}`.[/]", align="left")
|
|
214
218
|
yield
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: litestar-vite
|
|
3
|
-
Version: 0.13.
|
|
3
|
+
Version: 0.13.2
|
|
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
|
|
@@ -19,16 +19,16 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
19
19
|
Classifier: Natural Language :: English
|
|
20
20
|
Classifier: Operating System :: OS Independent
|
|
21
21
|
Classifier: Programming Language :: Python
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.9
|
|
24
23
|
Classifier: Programming Language :: Python :: 3.10
|
|
25
24
|
Classifier: Programming Language :: Python :: 3.11
|
|
26
25
|
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
27
|
Classifier: Topic :: Database
|
|
28
28
|
Classifier: Topic :: Database :: Database Engines/Servers
|
|
29
29
|
Classifier: Topic :: Software Development
|
|
30
30
|
Classifier: Typing :: Typed
|
|
31
|
-
Requires-Python: >=3.
|
|
31
|
+
Requires-Python: >=3.9
|
|
32
32
|
Requires-Dist: litestar[jinja]>=2.7.0
|
|
33
33
|
Provides-Extra: nodeenv
|
|
34
34
|
Requires-Dist: nodeenv; extra == 'nodeenv'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
litestar_vite/__init__.py,sha256=QykOZjCNHyDZJNIF84fa-6ze-lajDAGcoi18LxeV-0E,241
|
|
2
|
+
litestar_vite/__metadata__.py,sha256=dMGIPS6M11LcmiEfnMJJrbSPH8Lf00pU8crIIUsIBPw,478
|
|
3
|
+
litestar_vite/cli.py,sha256=W3bpXZSt_ne0pdDZQCGi_naMEakp7MA-oD_r1BJI0cQ,11058
|
|
4
|
+
litestar_vite/commands.py,sha256=XrQ6vIbcJYEANrO1nJwawb3DYOXt-1GGVYfJYWsYc6c,5385
|
|
5
|
+
litestar_vite/config.py,sha256=K3C3uhfcllINGAkOUS4tTah-mhhx74GYwNF4ME92eOA,4592
|
|
6
|
+
litestar_vite/loader.py,sha256=opF-YJh0fnu1cpH2uJ4aLmK9PZpsREa4yEEajYV9yVs,11802
|
|
7
|
+
litestar_vite/plugin.py,sha256=uyGlJZBl46DpKoHmxkdkNUvZ2SyYI0Q3MXcDwYytweo,9132
|
|
8
|
+
litestar_vite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
litestar_vite/inertia/__init__.py,sha256=KGvxCZhnOw06Pqx5_qjUxj0WWsCR3BR0cVnuNMT7sKQ,1136
|
|
10
|
+
litestar_vite/inertia/_utils.py,sha256=HZOedWduCu3fCMniuFvstEcXzP2FA1IBwPZ3E2XNBEo,2529
|
|
11
|
+
litestar_vite/inertia/config.py,sha256=i_Ji1SnWVt2hNClpAvIVTw-vb3L8TLPW_1f27QG5OEc,1258
|
|
12
|
+
litestar_vite/inertia/exception_handler.py,sha256=FfaPp7eiU_yo6sNU6WVRpKTkn6Npti7lFp1Rg-94Tqs,5576
|
|
13
|
+
litestar_vite/inertia/helpers.py,sha256=rk8P7Gh705JPaKLh9LONr-hDHrMBOEdUn-89NMEu_Bg,10876
|
|
14
|
+
litestar_vite/inertia/middleware.py,sha256=gyKZIOtsQmEq0nPjr2CJ-_qddZ1JsepROLO-CDSNEZM,1621
|
|
15
|
+
litestar_vite/inertia/plugin.py,sha256=qRxJr8clCj52_B2y0y99lTvAhAXUMEqLBryDrpXZe44,4064
|
|
16
|
+
litestar_vite/inertia/request.py,sha256=VF74lzboSV_FdlaYT0LGac6RWDX00Cp_vR--OsKg9D4,4590
|
|
17
|
+
litestar_vite/inertia/response.py,sha256=W6SrNcqhVnrEz7ZAaKA12m8qDgoRy2IKHBYZ2AKD9y8,14060
|
|
18
|
+
litestar_vite/inertia/routes.py,sha256=JKeZtbRMSoI7dokrxgwb_9U4YZPsbzh67NKQgoGoj9M,1857
|
|
19
|
+
litestar_vite/inertia/types.py,sha256=qKkFBcc637nnQpbsOUI_aTf19vnY4Qo5c0jsMYsOqQk,701
|
|
20
|
+
litestar_vite/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
+
litestar_vite/templates/index.html.j2,sha256=Xue1cTl6piEOZkW3UG68SnW80NeL9PxaOp-Xr23kpr4,322
|
|
22
|
+
litestar_vite/templates/main.ts.j2,sha256=Nzr5m_hXMAjeDL_4yQNP3DMCf7Blh3dwg5m-67GJVbY,22
|
|
23
|
+
litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYuzBjXrziXNw,299
|
|
24
|
+
litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
|
+
litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
|
|
26
|
+
litestar_vite/templates/vite.config.ts.j2,sha256=bF5kOPFafYMkhhV0VkIwetN-_zoVMGVM1jEMX_wKoNc,1037
|
|
27
|
+
litestar_vite-0.13.2.dist-info/METADATA,sha256=jeyo7erxAdorX651z6CrIaFTF5xwRiCwvVM8Gx5HgjU,6245
|
|
28
|
+
litestar_vite-0.13.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
29
|
+
litestar_vite-0.13.2.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
|
|
30
|
+
litestar_vite-0.13.2.dist-info/RECORD,,
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
litestar_vite/__init__.py,sha256=OioNGhH88mdivQlFz9JlbJV8R6wyjSYE3c8C-RIM4Ls,277
|
|
2
|
-
litestar_vite/__metadata__.py,sha256=_Wo-vNQuj5co9J4FwJAB2rRafbFo8ztTHrXmEPrYrV8,514
|
|
3
|
-
litestar_vite/cli.py,sha256=CBSRohDLU9cDeKMAfSbFiw1x8OE_b15ZlUaxji9Rdw8,10749
|
|
4
|
-
litestar_vite/commands.py,sha256=NFRTA_VoeFuZVk6bOINJTdP9DGGSAIZRVsM-SlDykNk,5228
|
|
5
|
-
litestar_vite/config.py,sha256=cZWIwTwNnBYScCty8OxxPaOL8cELx57dm7JQeV8og3Y,4565
|
|
6
|
-
litestar_vite/loader.py,sha256=nrXL2txXoBZEsdLZnysgBYZSreMXQ7ckLuNcu7MqnSM,10277
|
|
7
|
-
litestar_vite/plugin.py,sha256=nglizc45_CBG1gqZRDxyGo8cc_KZ1yOJfAS0XiSadpg,9119
|
|
8
|
-
litestar_vite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
litestar_vite/inertia/__init__.py,sha256=KGvxCZhnOw06Pqx5_qjUxj0WWsCR3BR0cVnuNMT7sKQ,1136
|
|
10
|
-
litestar_vite/inertia/_utils.py,sha256=ijO9Lgka7ZPIAHkby9szbTGoSg0nDShC2bqWT9cDxi0,1956
|
|
11
|
-
litestar_vite/inertia/config.py,sha256=0Je9SLg0acv0eRvudk3aJLj5k1DjPxULoVOwAfpjnUc,1232
|
|
12
|
-
litestar_vite/inertia/exception_handler.py,sha256=BU7vOK7C2iW52_J5xGJZMjYX3EqIg1OpAF3PgbaLSZ4,5349
|
|
13
|
-
litestar_vite/inertia/helpers.py,sha256=9XVQUAqmiXOTUGVLgxPWPgftkRCx99jr6LXPiD35YJE,10571
|
|
14
|
-
litestar_vite/inertia/middleware.py,sha256=23HfQ8D2wNGXUXt_isuGfZ8AFKrr1d_498qGFLynocs,1650
|
|
15
|
-
litestar_vite/inertia/plugin.py,sha256=iVF1c8E7M6IdZK_S1nZW8ZTi7vfIllMAnIUX0pVdrFQ,3686
|
|
16
|
-
litestar_vite/inertia/request.py,sha256=Ogt_ikauWrsgKafaip7IL1YhbybwjdBAQ0PQS7cImoQ,3848
|
|
17
|
-
litestar_vite/inertia/response.py,sha256=YjfabkYkGxDwbuo-WLgbUAHcCi0jgZYM_qdnUbI6Pas,13767
|
|
18
|
-
litestar_vite/inertia/routes.py,sha256=QksJm2RUfL-WbuhOieYnPXXWO5GYnPtmsYEm6Ef8Yeo,1782
|
|
19
|
-
litestar_vite/inertia/types.py,sha256=tLp0pm1N__hcWC875khf6wH1nuFlKS9-VjDqgsRkXnw,702
|
|
20
|
-
litestar_vite/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
-
litestar_vite/templates/index.html.j2,sha256=Xue1cTl6piEOZkW3UG68SnW80NeL9PxaOp-Xr23kpr4,322
|
|
22
|
-
litestar_vite/templates/main.ts.j2,sha256=Nzr5m_hXMAjeDL_4yQNP3DMCf7Blh3dwg5m-67GJVbY,22
|
|
23
|
-
litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYuzBjXrziXNw,299
|
|
24
|
-
litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
|
-
litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
|
|
26
|
-
litestar_vite/templates/vite.config.ts.j2,sha256=bF5kOPFafYMkhhV0VkIwetN-_zoVMGVM1jEMX_wKoNc,1037
|
|
27
|
-
litestar_vite-0.13.0.dist-info/METADATA,sha256=qxVk_WT5C6YZaPsDHfPaoauTTXJQh9dL_6BUCVrUeCY,6244
|
|
28
|
-
litestar_vite-0.13.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
29
|
-
litestar_vite-0.13.0.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
|
|
30
|
-
litestar_vite-0.13.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|