litestar-vite 0.8.3__tar.gz → 0.10.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.
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/PKG-INFO +6 -4
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/README.md +5 -3
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/pyproject.toml +4 -2
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/src/index.ts +41 -5
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/src/inertia-helpers/index.ts +2 -1
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/tests/index.test.ts +221 -144
- litestar_vite-0.10.0/src/py/litestar_vite/__init__.py +8 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/commands.py +1 -1
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/config.py +1 -67
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/middleware.py +1 -2
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/response.py +8 -9
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/loader.py +66 -3
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/plugin.py +29 -23
- litestar_vite-0.10.0/src/py/tests/conftest.py +39 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/app.py +8 -2
- litestar_vite-0.10.0/src/py/tests/test_asset_loader.py +153 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_cli/test_init.py +16 -7
- litestar_vite-0.10.0/src/py/tests/test_inertia/conftest.py +33 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_inertia/test_inertia_request.py +27 -7
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_inertia/test_inertia_response.py +33 -9
- litestar_vite-0.8.3/src/py/litestar_vite/__init__.py +0 -9
- litestar_vite-0.8.3/src/py/litestar_vite/template_engine.py +0 -103
- litestar_vite-0.8.3/src/py/tests/conftest.py +0 -27
- litestar_vite-0.8.3/src/py/tests/test_inertia/conftest.py +0 -30
- litestar_vite-0.8.3/src/py/tests/test_template_engine.py +0 -148
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/.gitignore +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/LICENSE +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/LICENSE +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/Makefile +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/NOTICE +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/README.md +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/src/dev-server-index.html +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/tests/__data__/dummy.ts +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/tsconfig.inertia-helpers.json +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/tsconfig.json +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/vitest.config.ts +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/js/vitest.workspace.ts +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/__metadata__.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/cli.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/__init__.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/_utils.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/config.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/exception_handler.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/plugin.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/request.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/routes.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/inertia/types.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/py.typed +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/templates/__init__.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/templates/index.html.j2 +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/templates/main.ts.j2 +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/templates/package.json.j2 +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/templates/styles.css.j2 +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/templates/tsconfig.json.j2 +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/litestar_vite/templates/vite.config.ts.j2 +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/__init__.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/templates/__init__.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/templates/index.html.j2 +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/__init__.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/__init__.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/public/.gitkeep +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/public/assets/main-l0sNRNKZ.js +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/public/assets/styles-l0sNRNKZ.js +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/public/manifest.json +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/resources/.gitkeep +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/resources/main.ts +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/resources/styles.css +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/templates/.gitkeep +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_app/web/templates/index.html +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_cli/__init__.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_cli/conftest.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_commands.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_config.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_inertia/__init__.py +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.0}/src/py/tests/test_inertia/templates/index.html.j2 +0 -0
- {litestar_vite-0.8.3 → litestar_vite-0.10.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.
|
|
3
|
+
Version: 0.10.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
|
|
@@ -53,6 +53,8 @@ from pathlib import Path
|
|
|
53
53
|
from litestar import Controller, get, Litestar
|
|
54
54
|
from litestar.response import Template
|
|
55
55
|
from litestar.status_codes import HTTP_200_OK
|
|
56
|
+
from litestar.template.config import TemplateConfig
|
|
57
|
+
from litestar.contrib.jinja import JinjaTemplateEngine
|
|
56
58
|
from litestar_vite import ViteConfig, VitePlugin
|
|
57
59
|
|
|
58
60
|
class WebController(Controller):
|
|
@@ -64,9 +66,9 @@ class WebController(Controller):
|
|
|
64
66
|
async def index(self) -> Template:
|
|
65
67
|
return Template(template_name="index.html.j2")
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
vite = VitePlugin(config=ViteConfig(
|
|
69
|
-
app = Litestar(plugins=[vite], route_handlers=[WebController])
|
|
69
|
+
template_config = TemplateConfig(engine=JinjaTemplateEngine(directory='templates/'))
|
|
70
|
+
vite = VitePlugin(config=ViteConfig())
|
|
71
|
+
app = Litestar(plugins=[vite], template_config=template_config, route_handlers=[WebController])
|
|
70
72
|
|
|
71
73
|
```
|
|
72
74
|
|
|
@@ -18,6 +18,8 @@ from pathlib import Path
|
|
|
18
18
|
from litestar import Controller, get, Litestar
|
|
19
19
|
from litestar.response import Template
|
|
20
20
|
from litestar.status_codes import HTTP_200_OK
|
|
21
|
+
from litestar.template.config import TemplateConfig
|
|
22
|
+
from litestar.contrib.jinja import JinjaTemplateEngine
|
|
21
23
|
from litestar_vite import ViteConfig, VitePlugin
|
|
22
24
|
|
|
23
25
|
class WebController(Controller):
|
|
@@ -29,9 +31,9 @@ class WebController(Controller):
|
|
|
29
31
|
async def index(self) -> Template:
|
|
30
32
|
return Template(template_name="index.html.j2")
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
vite = VitePlugin(config=ViteConfig(
|
|
34
|
-
app = Litestar(plugins=[vite], route_handlers=[WebController])
|
|
34
|
+
template_config = TemplateConfig(engine=JinjaTemplateEngine(directory='templates/'))
|
|
35
|
+
vite = VitePlugin(config=ViteConfig())
|
|
36
|
+
app = Litestar(plugins=[vite], template_config=template_config, route_handlers=[WebController])
|
|
35
37
|
|
|
36
38
|
```
|
|
37
39
|
|
|
@@ -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.
|
|
28
|
+
version = "0.10.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.
|
|
88
|
+
current_version = "0.10.0"
|
|
89
89
|
ignore_missing_files = false
|
|
90
90
|
ignore_missing_version = false
|
|
91
91
|
message = "chore(release): bump to v{new_version}"
|
|
@@ -267,6 +267,8 @@ lint.select = ["ALL"]
|
|
|
267
267
|
lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
|
268
268
|
src = ["src/py/litestar_vite", "src/py/tests"]
|
|
269
269
|
target-version = "py38"
|
|
270
|
+
unsafe-fixes = true
|
|
271
|
+
|
|
270
272
|
|
|
271
273
|
[tool.ruff.lint.pydocstyle]
|
|
272
274
|
convention = "google"
|
|
@@ -63,6 +63,12 @@ interface PluginConfig {
|
|
|
63
63
|
* @default null
|
|
64
64
|
*/
|
|
65
65
|
detectTls?: string | boolean | null
|
|
66
|
+
/**
|
|
67
|
+
* Automatically detect the index.html file.
|
|
68
|
+
*
|
|
69
|
+
* @default true
|
|
70
|
+
*/
|
|
71
|
+
autoDetectIndex?: boolean
|
|
66
72
|
/**
|
|
67
73
|
* Transform the code while serving.
|
|
68
74
|
*/
|
|
@@ -82,7 +88,7 @@ type DevServerUrl = `${"http" | "https"}://${string}:${number}`
|
|
|
82
88
|
|
|
83
89
|
let exitHandlersBound = false
|
|
84
90
|
|
|
85
|
-
export const refreshPaths = ["
|
|
91
|
+
export const refreshPaths = ["src/**", "resources/**", "assets/**"].filter((path) => fs.existsSync(path.replace(/\*\*$/, "")))
|
|
86
92
|
|
|
87
93
|
/**
|
|
88
94
|
* Litestar plugin for Vite.
|
|
@@ -184,10 +190,30 @@ function resolveLitestarPlugin(pluginConfig: Required<PluginConfig>): LitestarPl
|
|
|
184
190
|
}
|
|
185
191
|
return undefined
|
|
186
192
|
},
|
|
187
|
-
configureServer(server) {
|
|
193
|
+
async configureServer(server) {
|
|
188
194
|
const envDir = resolvedConfig.envDir || process.cwd()
|
|
189
195
|
const appUrl = loadEnv(resolvedConfig.mode, envDir, "APP_URL").APP_URL ?? "undefined"
|
|
190
196
|
|
|
197
|
+
// Check if we should serve SPA directly
|
|
198
|
+
const shouldServeIndex = () => {
|
|
199
|
+
if (!pluginConfig.autoDetectIndex) return false
|
|
200
|
+
|
|
201
|
+
// Check various common locations for index.html
|
|
202
|
+
const possiblePaths = [
|
|
203
|
+
path.join(server.config.root, "index.html"),
|
|
204
|
+
path.join(server.config.root, pluginConfig.resourceDirectory, "index.html"),
|
|
205
|
+
path.join(server.config.root, "public", "index.html"),
|
|
206
|
+
]
|
|
207
|
+
|
|
208
|
+
for (const indexPath of possiblePaths) {
|
|
209
|
+
try {
|
|
210
|
+
fs.accessSync(indexPath)
|
|
211
|
+
return true
|
|
212
|
+
} catch {}
|
|
213
|
+
}
|
|
214
|
+
return false
|
|
215
|
+
}
|
|
216
|
+
|
|
191
217
|
server.httpServer?.once("listening", () => {
|
|
192
218
|
const address = server.httpServer?.address()
|
|
193
219
|
|
|
@@ -197,14 +223,23 @@ function resolveLitestarPlugin(pluginConfig: Required<PluginConfig>): LitestarPl
|
|
|
197
223
|
fs.mkdirSync(path.dirname(pluginConfig.hotFile), { recursive: true })
|
|
198
224
|
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl)
|
|
199
225
|
|
|
226
|
+
const hasIndex = shouldServeIndex()
|
|
227
|
+
|
|
200
228
|
setTimeout(() => {
|
|
201
229
|
server.config.logger.info(`\n ${colors.red(`${colors.bold("LITESTAR")} ${litestarVersion()}`)} ${colors.dim("plugin")} ${colors.bold(`v${pluginVersion()}`)}`)
|
|
202
230
|
server.config.logger.info("")
|
|
203
|
-
|
|
231
|
+
if (hasIndex) {
|
|
232
|
+
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("Serve Index")}: Serving application index with Vite`)
|
|
233
|
+
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("DEV URL")}: ${colors.cyan(viteDevServerUrl)}`)
|
|
234
|
+
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("APP_URL")}: ${colors.cyan(appUrl.replace(/:(\d+)/, (_, port) => `:${colors.bold(port)}`))}`)
|
|
235
|
+
} else {
|
|
236
|
+
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("Serve Index")}: Serving Litestar index with Vite`)
|
|
237
|
+
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("DEV URL")}: ${colors.cyan(viteDevServerUrl)}`)
|
|
238
|
+
server.config.logger.info(` ${colors.green("➜")} ${colors.bold("APP_URL")}: ${colors.cyan(appUrl.replace(/:(\d+)/, (_, port) => `:${colors.bold(port)}`))}`)
|
|
239
|
+
}
|
|
204
240
|
}, 100)
|
|
205
241
|
}
|
|
206
242
|
})
|
|
207
|
-
|
|
208
243
|
if (!exitHandlersBound) {
|
|
209
244
|
const clean = () => {
|
|
210
245
|
if (fs.existsSync(pluginConfig.hotFile)) {
|
|
@@ -222,7 +257,7 @@ function resolveLitestarPlugin(pluginConfig: Required<PluginConfig>): LitestarPl
|
|
|
222
257
|
|
|
223
258
|
return () =>
|
|
224
259
|
server.middlewares.use((req, res, next) => {
|
|
225
|
-
if (req.url === "/index.html") {
|
|
260
|
+
if (!shouldServeIndex() && req.url === "/index.html") {
|
|
226
261
|
res.statusCode = 404
|
|
227
262
|
|
|
228
263
|
res.end(
|
|
@@ -325,6 +360,7 @@ function resolvePluginConfig(config: string | string[] | PluginConfig): Required
|
|
|
325
360
|
refresh: resolvedConfig.refresh ?? false,
|
|
326
361
|
hotFile: resolvedConfig.hotFile ?? path.join(resolvedConfig.bundleDirectory ?? "public", "hot"),
|
|
327
362
|
detectTls: resolvedConfig.detectTls ?? false,
|
|
363
|
+
autoDetectIndex: resolvedConfig.autoDetectIndex ?? true,
|
|
328
364
|
transformOnServe: resolvedConfig.transformOnServe ?? ((code) => code),
|
|
329
365
|
}
|
|
330
366
|
}
|
|
@@ -125,8 +125,9 @@ export function isRoute(url: string, routeName: string): boolean {
|
|
|
125
125
|
const regexPattern = routePattern.replace(/\//g, "\\/").replace(/\{([^}]+):([^}]+)\}/g, (match, paramName, paramType) => {
|
|
126
126
|
switch (paramType) {
|
|
127
127
|
case "str":
|
|
128
|
-
case "path":
|
|
129
128
|
return "([^/]+)"
|
|
129
|
+
case "path":
|
|
130
|
+
return "(.*)"
|
|
130
131
|
case "uuid":
|
|
131
132
|
return "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
|
132
133
|
default:
|