litestar-vite 0.13.2__tar.gz → 0.14.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 (88) hide show
  1. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/.gitignore +7 -0
  2. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/PKG-INFO +5 -3
  3. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/README.md +1 -1
  4. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/pyproject.toml +4 -3
  5. litestar_vite-0.14.0/src/js/tests/vite-compatibility.test.ts +513 -0
  6. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/commands.py +29 -2
  7. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/config.py +4 -1
  8. litestar_vite-0.14.0/src/py/litestar_vite/exceptions.py +26 -0
  9. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/plugin.py +17 -10
  10. {litestar_vite-0.13.2/src/py/tests/test_cli → litestar_vite-0.14.0/src/py/tests/integration/cli}/conftest.py +2 -2
  11. {litestar_vite-0.13.2/src/py/tests/test_cli → litestar_vite-0.14.0/src/py/tests/integration/cli}/test_init.py +16 -8
  12. litestar_vite-0.14.0/src/py/tests/integration/test_optional_jinja.py +610 -0
  13. litestar_vite-0.14.0/src/py/tests/unit/__init__.py +0 -0
  14. litestar_vite-0.14.0/src/py/tests/unit/inertia/__init__.py +0 -0
  15. {litestar_vite-0.13.2/src/py/tests → litestar_vite-0.14.0/src/py/tests/unit}/test_asset_loader.py +2 -21
  16. litestar_vite-0.14.0/src/py/tests/unit/test_commands.py +250 -0
  17. litestar_vite-0.14.0/src/py/tests/unit/test_plugin.py +708 -0
  18. litestar_vite-0.14.0/tools/__init__.py +0 -0
  19. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/tools/clean.js +0 -0
  20. litestar_vite-0.13.2/src/js/vitest.workspace.ts +0 -4
  21. litestar_vite-0.13.2/src/py/tests/test_commands.py +0 -27
  22. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/LICENSE +0 -0
  23. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/LICENSE +0 -0
  24. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/Makefile +0 -0
  25. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/NOTICE +0 -0
  26. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/README.md +0 -0
  27. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/src/dev-server-index.html +0 -0
  28. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/src/index.ts +0 -0
  29. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/src/inertia-helpers/index.ts +0 -0
  30. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/tests/__data__/dummy.ts +0 -0
  31. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/tests/index.test.ts +0 -0
  32. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/tsconfig.inertia-helpers.json +0 -0
  33. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/tsconfig.json +0 -0
  34. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/js/vitest.config.ts +0 -0
  35. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/__init__.py +0 -0
  36. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/__metadata__.py +0 -0
  37. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/cli.py +0 -0
  38. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/__init__.py +0 -0
  39. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/_utils.py +0 -0
  40. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/config.py +0 -0
  41. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/exception_handler.py +0 -0
  42. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/helpers.py +0 -0
  43. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/middleware.py +0 -0
  44. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/plugin.py +0 -0
  45. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/request.py +0 -0
  46. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/response.py +0 -0
  47. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/routes.py +0 -0
  48. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/inertia/types.py +0 -0
  49. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/loader.py +0 -0
  50. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/py.typed +0 -0
  51. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/templates/__init__.py +0 -0
  52. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/templates/index.html.j2 +0 -0
  53. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/templates/main.ts.j2 +0 -0
  54. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/templates/package.json.j2 +0 -0
  55. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/templates/styles.css.j2 +0 -0
  56. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/templates/tsconfig.json.j2 +0 -0
  57. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/litestar_vite/templates/vite.config.ts.j2 +0 -0
  58. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/__init__.py +0 -0
  59. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/conftest.py +0 -0
  60. {litestar_vite-0.13.2/src/py/tests/templates → litestar_vite-0.14.0/src/py/tests/fixtures}/__init__.py +0 -0
  61. {litestar_vite-0.13.2/src/py/tests/test_app → litestar_vite-0.14.0/src/py/tests/integration}/__init__.py +0 -0
  62. {litestar_vite-0.13.2/src/py/tests/test_cli → litestar_vite-0.14.0/src/py/tests/integration/cli}/__init__.py +0 -0
  63. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/py.typed +0 -0
  64. {litestar_vite-0.13.2/src/py/tests/test_app/web → litestar_vite-0.14.0/src/py/tests/templates}/__init__.py +0 -0
  65. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/templates/index.html.j2 +0 -0
  66. {litestar_vite-0.13.2/src/py/tests/test_inertia → litestar_vite-0.14.0/src/py/tests/test_app}/__init__.py +0 -0
  67. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/app.py +0 -0
  68. {litestar_vite-0.13.2/tools → litestar_vite-0.14.0/src/py/tests/test_app/web}/__init__.py +0 -0
  69. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/web/public/.gitkeep +0 -0
  70. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/web/public/assets/main-l0sNRNKZ.js +0 -0
  71. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/web/public/assets/styles-l0sNRNKZ.js +0 -0
  72. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/web/public/manifest.json +0 -0
  73. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/web/resources/.gitkeep +0 -0
  74. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/web/resources/main.ts +0 -0
  75. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/web/resources/styles.css +0 -0
  76. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/web/templates/.gitkeep +0 -0
  77. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/src/py/tests/test_app/web/templates/index.html +0 -0
  78. {litestar_vite-0.13.2/src/py/tests/test_inertia → litestar_vite-0.14.0/src/py/tests/unit/inertia}/conftest.py +0 -0
  79. {litestar_vite-0.13.2/src/py/tests/test_inertia → litestar_vite-0.14.0/src/py/tests/unit/inertia}/templates/index.html.j2 +0 -0
  80. {litestar_vite-0.13.2/src/py/tests/test_inertia → litestar_vite-0.14.0/src/py/tests/unit/inertia}/test_request.py +0 -0
  81. {litestar_vite-0.13.2/src/py/tests/test_inertia → litestar_vite-0.14.0/src/py/tests/unit/inertia}/test_response.py +0 -0
  82. {litestar_vite-0.13.2/src/py/tests/test_inertia → litestar_vite-0.14.0/src/py/tests/unit/inertia}/test_routes.py +0 -0
  83. {litestar_vite-0.13.2/src/py/tests → litestar_vite-0.14.0/src/py/tests/unit}/test_config.py +0 -0
  84. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/tools/build_docs.py +0 -0
  85. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/tools/pypi_readme.py +0 -0
  86. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/tools/sphinx_ext/__init__.py +0 -0
  87. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/tools/sphinx_ext/changelog.py +0 -0
  88. {litestar_vite-0.13.2 → litestar_vite-0.14.0}/tools/sphinx_ext/missing_references.py +0 -0
@@ -172,3 +172,10 @@ node_modules
172
172
  *.swo
173
173
  *.swp
174
174
  .venv
175
+ CLAUDE.md
176
+ GEMINI.md
177
+
178
+ # Example build outputs and package-lock files
179
+ examples/*/public/
180
+ examples/*/package-lock.json
181
+ examples/*/frontend/package-lock.json
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: litestar-vite
3
- Version: 0.13.2
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>
@@ -37,7 +37,7 @@ app = Litestar(plugins=[vite], template_config=template_config, route_handlers=[
37
37
 
38
38
  ```
39
39
 
40
- Create a template to serve the application in `./templates/index.html.h2`:
40
+ Create a template to serve the application in `./templates/index.html.j2`:
41
41
 
42
42
  ```html
43
43
  <!DOCTYPE html>
@@ -18,14 +18,14 @@ classifiers = [
18
18
  "Topic :: Database",
19
19
  "Topic :: Database :: Database Engines/Servers",
20
20
  ]
21
- dependencies = ["litestar[jinja]>=2.7.0"]
21
+ dependencies = ["litestar>=2.7.0"]
22
22
  description = "Vite plugin for Litestar"
23
23
  keywords = ["litestar", "vite"]
24
24
  license = { text = "MIT" }
25
25
  name = "litestar-vite"
26
26
  readme = "README.md"
27
27
  requires-python = ">=3.9"
28
- version = "0.13.2"
28
+ version = "0.14.0"
29
29
 
30
30
  [project.urls]
31
31
  Changelog = "https://cofin.github.io/litestar-vite/latest/changelog"
@@ -36,6 +36,7 @@ Issue = "https://github.com/cofin/litestar-vite/issues/"
36
36
  Source = "https://github.com/cofin/litestar-vite"
37
37
 
38
38
  [project.optional-dependencies]
39
+ jinja = [ "jinja2"]
39
40
  nodeenv = ["nodeenv"]
40
41
 
41
42
  [build-system]
@@ -83,7 +84,7 @@ test = [
83
84
  allow_dirty = true
84
85
  commit = true
85
86
  commit_args = "--no-verify"
86
- current_version = "0.13.2"
87
+ current_version = "0.14.0"
87
88
  ignore_missing_files = false
88
89
  ignore_missing_version = false
89
90
  message = "chore(release): bump to v{new_version}"
@@ -0,0 +1,513 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest"
2
+ import litestar from "../src"
3
+
4
+ // Mock the fs module for consistent testing
5
+ vi.mock("fs", async () => {
6
+ const actual = await vi.importActual<typeof import("fs")>("fs")
7
+
8
+ return {
9
+ promises: actual.promises,
10
+ default: {
11
+ ...actual,
12
+ existsSync: (path: string) => ["resources/", "assets/", "src/"].includes(path) || actual.existsSync(path),
13
+ readFileSync: actual.readFileSync,
14
+ mkdirSync: actual.mkdirSync,
15
+ writeFileSync: actual.writeFileSync,
16
+ rmSync: actual.rmSync,
17
+ },
18
+ }
19
+ })
20
+
21
+ // Mock process.env for testing
22
+ const originalEnv = process.env
23
+ beforeEach(() => {
24
+ vi.resetModules()
25
+ process.env = { ...originalEnv }
26
+ vi.clearAllMocks()
27
+ })
28
+
29
+ describe("Vite 7.0 Compatibility", () => {
30
+ describe("Plugin Configuration", () => {
31
+ it("builds successfully with Vite 7.0 configuration format", () => {
32
+ const plugin = litestar("resources/js/app.ts")[0]
33
+
34
+ // Test Vite 7.0 style configuration
35
+ const config = plugin.config({}, { command: "build", mode: "production" })
36
+
37
+ expect(config.build?.rollupOptions?.input).toBe("resources/js/app.ts")
38
+ expect(config.build?.manifest).toBe("manifest.json")
39
+ })
40
+
41
+ it("handles Vite 7.0 development server configuration", () => {
42
+ process.env.VITE_ALLOW_REMOTE = "1"
43
+ process.env.VITE_PORT = "5173"
44
+
45
+ const plugin = litestar("resources/js/app.ts")[0]
46
+
47
+ const config = plugin.config({}, { command: "serve", mode: "development" })
48
+
49
+ expect(config.server?.host).toBe("0.0.0.0")
50
+ expect(config.server?.port).toBe(5173)
51
+ expect(config.server?.strictPort).toBe(true)
52
+ })
53
+
54
+ it("supports Vite 7.0 SSR configuration", () => {
55
+ const plugin = litestar({
56
+ input: "resources/js/app.ts",
57
+ ssr: "resources/js/ssr.ts",
58
+ })[0]
59
+
60
+ const ssrConfig = plugin.config({ build: { ssr: true } }, { command: "build", mode: "production" })
61
+
62
+ expect(ssrConfig.build?.rollupOptions?.input).toBe("resources/js/ssr.ts")
63
+ expect(ssrConfig.build?.manifest).toBe(false)
64
+ })
65
+
66
+ it("handles Vite 7.0 build optimizations", () => {
67
+ const plugin = litestar({
68
+ input: "resources/js/app.ts",
69
+ bundleDirectory: "dist",
70
+ })[0]
71
+
72
+ const config = plugin.config({}, { command: "build", mode: "production" })
73
+
74
+ expect(config.build?.outDir).toBe("dist")
75
+ expect(config.base).toBe("static/")
76
+ })
77
+ })
78
+
79
+ describe("Asset URL Handling", () => {
80
+ it("handles Vite 7.0 asset URL generation", () => {
81
+ const plugin = litestar({
82
+ input: "resources/js/app.ts",
83
+ assetUrl: "/vite-assets/",
84
+ })[0]
85
+
86
+ const config = plugin.config({}, { command: "build", mode: "production" })
87
+
88
+ expect(config.base).toBe("/vite-assets/")
89
+ })
90
+
91
+ it("supports CDN asset URLs in Vite 7.0", () => {
92
+ process.env.ASSET_URL = "https://cdn.example.com/assets/"
93
+
94
+ const plugin = litestar("resources/js/app.ts")[0]
95
+
96
+ const config = plugin.config({}, { command: "build", mode: "production" })
97
+
98
+ expect(config.base).toBe("https://cdn.example.com/assets/")
99
+ })
100
+
101
+ it("handles environment-specific asset URLs", () => {
102
+ process.env.ASSET_URL = "https://staging-cdn.example.com/"
103
+
104
+ const plugin = litestar({
105
+ input: "resources/js/app.ts",
106
+ assetUrl: "/local-assets/",
107
+ })[0]
108
+
109
+ const prodConfig = plugin.config({}, { command: "build", mode: "production" })
110
+ const devConfig = plugin.config({}, { command: "serve", mode: "development" })
111
+
112
+ expect(prodConfig.base).toBe("https://staging-cdn.example.com/")
113
+ expect(devConfig.base).toBe("/local-assets/")
114
+ })
115
+ })
116
+
117
+ describe("Build Configuration", () => {
118
+ it("supports Vite 7.0 build target configuration", () => {
119
+ const plugin = litestar("resources/js/app.ts")[0]
120
+
121
+ // Test that plugin preserves user build configuration
122
+ const userConfig = {
123
+ build: {
124
+ target: "es2022",
125
+ minify: "terser",
126
+ },
127
+ }
128
+
129
+ const config = plugin.config(userConfig, { command: "build", mode: "production" })
130
+
131
+ // Plugin should preserve user's build config while adding its own
132
+ expect(config.build?.rollupOptions?.input).toBe("resources/js/app.ts")
133
+ expect(config.build?.manifest).toBe("manifest.json")
134
+ })
135
+
136
+ it("handles Vite 7.0 code splitting configuration", () => {
137
+ const plugin = litestar(["resources/js/app.ts", "resources/js/admin.ts"])[0]
138
+
139
+ const config = plugin.config({}, { command: "build", mode: "production" })
140
+
141
+ expect(config.build?.rollupOptions?.input).toEqual(["resources/js/app.ts", "resources/js/admin.ts"])
142
+ })
143
+
144
+ it("supports Vite 7.0 chunk optimization", () => {
145
+ const plugin = litestar("resources/js/app.ts")[0]
146
+
147
+ const config = plugin.config(
148
+ {
149
+ build: {
150
+ rollupOptions: {
151
+ output: {
152
+ manualChunks: {
153
+ vendor: ["vue", "react"],
154
+ },
155
+ },
156
+ },
157
+ },
158
+ },
159
+ { command: "build", mode: "production" },
160
+ )
161
+
162
+ // Plugin should set its own configuration without overriding user chunk config
163
+ expect(config.build?.rollupOptions?.input).toBe("resources/js/app.ts")
164
+ expect(config.build?.manifest).toBe("manifest.json")
165
+ })
166
+ })
167
+
168
+ describe("Development Server Features", () => {
169
+ it("supports Vite 7.0 HMR configuration", () => {
170
+ const plugin = litestar({
171
+ input: "resources/js/app.ts",
172
+ refresh: true,
173
+ })
174
+
175
+ expect(plugin.length).toBe(2) // Main plugin + HMR plugin
176
+
177
+ const hmrPlugin = plugin[1]
178
+ expect(hmrPlugin.__litestar_plugin_config).toEqual({
179
+ paths: ["src/**", "resources/**", "assets/**"],
180
+ })
181
+ })
182
+
183
+ it("handles Vite 7.0 proxy configuration", () => {
184
+ const plugin = litestar("resources/js/app.ts")[0]
185
+
186
+ const config = plugin.config(
187
+ {
188
+ server: {
189
+ proxy: {
190
+ "/api": "http://localhost:8000",
191
+ },
192
+ },
193
+ },
194
+ { command: "serve", mode: "development" },
195
+ )
196
+
197
+ // Plugin only sets server config when specific conditions are met
198
+ expect(config.server?.origin).toBe("__litestar_vite_placeholder__")
199
+ expect(config.base).toBe("static")
200
+ })
201
+
202
+ it("supports Vite 7.0 middleware configuration", () => {
203
+ const plugin = litestar("resources/js/app.ts")[0]
204
+
205
+ const middlewareFn = vi.fn()
206
+ const config = plugin.config(
207
+ {
208
+ server: {
209
+ middlewareMode: true,
210
+ },
211
+ },
212
+ { command: "serve", mode: "development" },
213
+ )
214
+
215
+ // Plugin only sets server config when specific conditions are met
216
+ expect(config.server?.origin).toBe("__litestar_vite_placeholder__")
217
+ expect(config.base).toBe("static")
218
+ })
219
+ })
220
+
221
+ describe("TypeScript Support", () => {
222
+ it("handles Vite 7.0 TypeScript configuration", () => {
223
+ const plugin = litestar("resources/ts/app.ts")[0]
224
+
225
+ const config = plugin.config({}, { command: "build", mode: "production" })
226
+
227
+ expect(config.build?.rollupOptions?.input).toBe("resources/ts/app.ts")
228
+ })
229
+
230
+ it("supports Vite 7.0 TypeScript path mapping", () => {
231
+ const plugin = litestar("resources/js/app.ts")[0]
232
+
233
+ const config = plugin.config(
234
+ {
235
+ resolve: {
236
+ alias: {
237
+ "@": "/resources/js",
238
+ "@components": "/resources/js/components",
239
+ },
240
+ },
241
+ },
242
+ { command: "build", mode: "development" },
243
+ )
244
+
245
+ expect(config.resolve?.alias?.["@"]).toBe("/resources/js")
246
+ expect(config.resolve?.alias?.["@components"]).toBe("/resources/js/components")
247
+ })
248
+
249
+ it("preserves existing @ alias with Vite 7.0", () => {
250
+ const plugin = litestar("resources/js/app.ts")[0]
251
+
252
+ const config = plugin.config(
253
+ {
254
+ resolve: {
255
+ alias: {
256
+ "@": "/custom/path",
257
+ },
258
+ },
259
+ },
260
+ { command: "build", mode: "development" },
261
+ )
262
+
263
+ expect(config.resolve?.alias?.["@"]).toBe("/custom/path")
264
+ })
265
+ })
266
+
267
+ describe("Plugin Integration", () => {
268
+ it("handles Vite 7.0 plugin API changes", () => {
269
+ const plugin = litestar("resources/js/app.ts")[0]
270
+
271
+ // Test that the plugin conforms to Vite 7.0 plugin API
272
+ expect(plugin.name).toBe("litestar")
273
+ expect(typeof plugin.config).toBe("function")
274
+ expect(typeof plugin.configResolved).toBe("function")
275
+ })
276
+
277
+ it("supports Vite 7.0 plugin composition", () => {
278
+ const plugins = litestar({
279
+ input: "resources/js/app.ts",
280
+ refresh: ["resources/**", "templates/**"],
281
+ })
282
+
283
+ expect(plugins.length).toBe(2)
284
+ expect(plugins[0].name).toBe("litestar")
285
+ })
286
+
287
+ it("handles Vite 7.0 conditional plugin loading", () => {
288
+ const devPlugins = litestar({
289
+ input: "resources/js/app.ts",
290
+ refresh: true,
291
+ })
292
+
293
+ const prodPlugins = litestar({
294
+ input: "resources/js/app.ts",
295
+ refresh: false,
296
+ })
297
+
298
+ expect(devPlugins.length).toBe(2) // With HMR
299
+ expect(prodPlugins.length).toBe(1) // Without HMR
300
+ })
301
+ })
302
+
303
+ describe("Performance Optimizations", () => {
304
+ it("supports Vite 7.0 dependency pre-bundling", () => {
305
+ const plugin = litestar("resources/js/app.ts")[0]
306
+
307
+ const config = plugin.config(
308
+ {
309
+ optimizeDeps: {
310
+ include: ["vue", "axios"],
311
+ exclude: ["@custom/module"],
312
+ },
313
+ },
314
+ { command: "serve", mode: "development" },
315
+ )
316
+
317
+ // Plugin doesn't override optimizeDeps, test what it actually sets
318
+ expect(config.base).toBe("static")
319
+ expect(config.server?.origin).toBe("__litestar_vite_placeholder__")
320
+ })
321
+
322
+ it("handles Vite 7.0 build caching", () => {
323
+ const plugin = litestar("resources/js/app.ts")[0]
324
+
325
+ const config = plugin.config(
326
+ {
327
+ build: {
328
+ write: true,
329
+ emptyOutDir: true,
330
+ },
331
+ },
332
+ { command: "build", mode: "production" },
333
+ )
334
+
335
+ // Plugin sets its own build configuration
336
+ expect(config.build?.rollupOptions?.input).toBe("resources/js/app.ts")
337
+ expect(config.build?.manifest).toBe("manifest.json")
338
+ })
339
+
340
+ it("supports Vite 7.0 tree shaking optimizations", () => {
341
+ const plugin = litestar("resources/js/app.ts")[0]
342
+
343
+ const config = plugin.config(
344
+ {
345
+ build: {
346
+ rollupOptions: {
347
+ treeshake: {
348
+ moduleSideEffects: false,
349
+ },
350
+ },
351
+ },
352
+ },
353
+ { command: "build", mode: "production" },
354
+ )
355
+
356
+ // Plugin sets its own build configuration
357
+ expect(config.build?.rollupOptions?.input).toBe("resources/js/app.ts")
358
+ expect(config.build?.manifest).toBe("manifest.json")
359
+ expect(config.base).toBe("static/")
360
+ })
361
+ })
362
+
363
+ describe("Error Handling", () => {
364
+ it("handles Vite 7.0 error overlay configuration", () => {
365
+ const plugin = litestar("resources/js/app.ts")[0]
366
+
367
+ const config = plugin.config(
368
+ {
369
+ server: {
370
+ hmr: {
371
+ overlay: true,
372
+ },
373
+ },
374
+ },
375
+ { command: "serve", mode: "development" },
376
+ )
377
+
378
+ // Plugin only sets server config when specific conditions are met
379
+ expect(config.server?.origin).toBe("__litestar_vite_placeholder__")
380
+ expect(config.base).toBe("static")
381
+ })
382
+
383
+ it("supports Vite 7.0 build error handling", () => {
384
+ const plugin = litestar("resources/js/app.ts")[0]
385
+
386
+ const config = plugin.config(
387
+ {
388
+ build: {
389
+ rollupOptions: {
390
+ onwarn: (warning, warn) => {
391
+ // Custom warning handler
392
+ warn(warning)
393
+ },
394
+ },
395
+ },
396
+ },
397
+ { command: "build", mode: "production" },
398
+ )
399
+
400
+ // Plugin sets its own build configuration
401
+ expect(config.build?.rollupOptions?.input).toBe("resources/js/app.ts")
402
+ expect(config.build?.manifest).toBe("manifest.json")
403
+ })
404
+ })
405
+
406
+ describe("Environment Support", () => {
407
+ it("handles Vite 7.0 environment variables", () => {
408
+ process.env.VITE_API_URL = "https://api.example.com"
409
+ process.env.VITE_APP_TITLE = "Test App"
410
+
411
+ const plugin = litestar("resources/js/app.ts")[0]
412
+
413
+ const config = plugin.config(
414
+ {
415
+ define: {
416
+ __APP_VERSION__: '"1.0.0"',
417
+ },
418
+ },
419
+ { command: "build", mode: "production" },
420
+ )
421
+
422
+ // Plugin sets its own configuration, doesn't preserve user define config
423
+ expect(config.build?.rollupOptions?.input).toBe("resources/js/app.ts")
424
+ expect(config.base).toBe("static/")
425
+ })
426
+
427
+ it("supports Vite 7.0 mode-specific configuration", () => {
428
+ const plugin = litestar("resources/js/app.ts")[0]
429
+
430
+ const devConfig = plugin.config({}, { command: "serve", mode: "development" })
431
+ const prodConfig = plugin.config({}, { command: "build", mode: "production" })
432
+
433
+ expect(devConfig.base).toBe("static")
434
+ expect(prodConfig.base).toBe("static/")
435
+ })
436
+ })
437
+
438
+ describe("Backwards Compatibility", () => {
439
+ it("maintains compatibility with Vite 5.x configurations", () => {
440
+ // Test that older configurations still work
441
+ const plugin = litestar({
442
+ input: "resources/js/app.js",
443
+ bundleDirectory: "public",
444
+ assetUrl: "/static/",
445
+ })[0]
446
+
447
+ const config = plugin.config({}, { command: "build", mode: "production" })
448
+
449
+ expect(config.build?.outDir).toBe("public")
450
+ expect(config.base).toBe("/static/")
451
+ })
452
+
453
+ it("maintains compatibility with Vite 6.x configurations", () => {
454
+ const plugin = litestar({
455
+ input: ["resources/js/app.ts", "resources/js/admin.ts"],
456
+ ssr: "resources/js/ssr.ts",
457
+ })[0]
458
+
459
+ const config = plugin.config({}, { command: "build", mode: "production" })
460
+ const ssrConfig = plugin.config({ build: { ssr: true } }, { command: "build", mode: "production" })
461
+
462
+ expect(config.build?.rollupOptions?.input).toEqual(["resources/js/app.ts", "resources/js/admin.ts"])
463
+ expect(ssrConfig.build?.rollupOptions?.input).toBe("resources/js/ssr.ts")
464
+ })
465
+
466
+ it("handles legacy plugin options gracefully", () => {
467
+ // Test with older plugin configuration format
468
+ const plugin = litestar({
469
+ input: "resources/js/app.js",
470
+ publicDirectory: "public",
471
+ buildDirectory: "dist",
472
+ })[0]
473
+
474
+ const config = plugin.config({}, { command: "build", mode: "production" })
475
+
476
+ // Should still work even if some options don't exist
477
+ expect(config.build?.rollupOptions?.input).toBe("resources/js/app.js")
478
+ })
479
+ })
480
+
481
+ describe("Future Compatibility", () => {
482
+ it("supports extensible configuration for future Vite versions", () => {
483
+ const plugin = litestar("resources/js/app.ts")[0]
484
+
485
+ // Test with potential future configuration options
486
+ const config = plugin.config(
487
+ {
488
+ experimental: {
489
+ someNewFeature: true,
490
+ },
491
+ future: {
492
+ newBuildOption: "value",
493
+ },
494
+ },
495
+ { command: "build", mode: "production" },
496
+ )
497
+
498
+ // Plugin sets its own configuration without preserving experimental features
499
+ expect(config.build?.rollupOptions?.input).toBe("resources/js/app.ts")
500
+ expect(config.build?.manifest).toBe("manifest.json")
501
+ expect(config.base).toBe("static/")
502
+ })
503
+
504
+ it("maintains plugin API stability for future versions", () => {
505
+ const plugin = litestar("resources/js/app.ts")[0]
506
+
507
+ // Test that essential plugin methods are available
508
+ expect(typeof plugin.config).toBe("function")
509
+ expect(typeof plugin.configResolved).toBe("function")
510
+ expect(plugin.name).toBe("litestar")
511
+ })
512
+ })
513
+ })
@@ -4,18 +4,22 @@ 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
20
  "typescript": "^5.8.3",
17
21
  "vite": "^6.3.5",
18
- "litestar-vite-plugin": "^0.13.2",
22
+ "litestar-vite-plugin": "^0.14.0",
19
23
  "@types/node": "^22.15.3",
20
24
  }
21
25
  DEFAULT_DEPENDENCIES: "dict[str, str]" = {"axios": "^1.9.0"}
@@ -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
 
@@ -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