@cloudwerk/vite-plugin 0.1.1 → 0.1.2
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.
- package/dist/index.js +13 -6
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ function generateServerEntry(manifest, scanResult, options) {
|
|
|
43
43
|
for (const middlewarePath of route.middleware) {
|
|
44
44
|
if (!importedModules.has(middlewarePath)) {
|
|
45
45
|
const varName = `middleware_${middlewareIndex++}`;
|
|
46
|
-
middlewareImports.push(`import ${varName} from '${middlewarePath}'`);
|
|
46
|
+
middlewareImports.push(`import { middleware as ${varName} } from '${middlewarePath}'`);
|
|
47
47
|
middlewareModules.set(middlewarePath, varName);
|
|
48
48
|
importedModules.add(middlewarePath);
|
|
49
49
|
}
|
|
@@ -63,6 +63,13 @@ function generateServerEntry(manifest, scanResult, options) {
|
|
|
63
63
|
imports.push(`import * as ${varName} from '${route.absolutePath}'`);
|
|
64
64
|
const layoutChain = route.layouts.map((p) => layoutModules.get(p)).join(", ");
|
|
65
65
|
const middlewareChain = route.middleware.map((p) => middlewareModules.get(p)).join(", ");
|
|
66
|
+
const hasOptionalCatchAll = route.segments.some((s) => s.type === "optionalCatchAll");
|
|
67
|
+
if (hasOptionalCatchAll) {
|
|
68
|
+
const basePath = route.urlPattern.replace(/\/:[^/]+\{\.\*\}$/, "") || "/";
|
|
69
|
+
pageRegistrations.push(
|
|
70
|
+
` registerPage(app, '${basePath}', ${varName}, [${layoutChain}], [${middlewareChain}])`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
66
73
|
pageRegistrations.push(
|
|
67
74
|
` registerPage(app, '${route.urlPattern}', ${varName}, [${layoutChain}], [${middlewareChain}])`
|
|
68
75
|
);
|
|
@@ -82,7 +89,7 @@ function generateServerEntry(manifest, scanResult, options) {
|
|
|
82
89
|
*/
|
|
83
90
|
|
|
84
91
|
import { Hono } from 'hono'
|
|
85
|
-
import { contextMiddleware, createHandlerAdapter, setRouteConfig } from '@cloudwerk/core/runtime'
|
|
92
|
+
import { contextMiddleware, createHandlerAdapter, createMiddlewareAdapter, setRouteConfig } from '@cloudwerk/core/runtime'
|
|
86
93
|
import { setActiveRenderer } from '@cloudwerk/ui'
|
|
87
94
|
|
|
88
95
|
// Page and Route Imports
|
|
@@ -101,9 +108,9 @@ ${middlewareImports.join("\n")}
|
|
|
101
108
|
const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD']
|
|
102
109
|
|
|
103
110
|
function registerPage(app, pattern, pageModule, layoutModules, middlewareModules) {
|
|
104
|
-
// Apply middleware
|
|
111
|
+
// Apply middleware (wrap with adapter to convert Cloudwerk middleware to Hono middleware)
|
|
105
112
|
for (const mw of middlewareModules) {
|
|
106
|
-
app.use(pattern, mw)
|
|
113
|
+
app.use(pattern, createMiddlewareAdapter(mw))
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
// Apply config middleware if present
|
|
@@ -184,9 +191,9 @@ function renderWithHydration(element) {
|
|
|
184
191
|
}
|
|
185
192
|
|
|
186
193
|
function registerRoute(app, pattern, routeModule, middlewareModules) {
|
|
187
|
-
// Apply middleware
|
|
194
|
+
// Apply middleware (wrap with adapter to convert Cloudwerk middleware to Hono middleware)
|
|
188
195
|
for (const mw of middlewareModules) {
|
|
189
|
-
app.use(pattern, mw)
|
|
196
|
+
app.use(pattern, createMiddlewareAdapter(mw))
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
// Apply config middleware if present
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudwerk/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Vite plugin for Cloudwerk file-based routing with virtual entry generation",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@swc/core": "^1.3.100",
|
|
22
|
-
"@cloudwerk/core": "^0.7.
|
|
23
|
-
"@cloudwerk/ui": "^0.7.
|
|
22
|
+
"@cloudwerk/core": "^0.7.1",
|
|
23
|
+
"@cloudwerk/ui": "^0.7.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"vite": "^5.0.0 || ^6.0.0",
|