@mauroandre/velojs 0.0.30 → 0.0.32
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/cli.js +24 -20
- package/dist/init.js +18 -5
- package/dist/server.js +66 -66
- package/dist/static.js +45 -33
- package/dist/types.d.ts +7 -0
- package/dist/vite.d.ts +21 -0
- package/dist/vite.js +240 -219
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
import { spawnSync as
|
|
2
|
-
import { resolve as
|
|
3
|
-
const
|
|
4
|
-
const s =
|
|
1
|
+
import { spawnSync as n } from "node:child_process";
|
|
2
|
+
import { resolve as l } from "node:path";
|
|
3
|
+
const i = process.argv.slice(2), c = i[0], d = (e, t = []) => {
|
|
4
|
+
const s = n(e, t, {
|
|
5
5
|
stdio: "inherit",
|
|
6
6
|
cwd: process.cwd()
|
|
7
7
|
});
|
|
8
8
|
process.exit(s.status ?? 0);
|
|
9
9
|
}, p = () => {
|
|
10
|
-
|
|
10
|
+
d("npx", ["vite", ...i.slice(1)]);
|
|
11
11
|
}, u = (e) => {
|
|
12
12
|
const t = Date.now().toString(36), s = {
|
|
13
13
|
...process.env,
|
|
14
14
|
VELO_BUILD_HASH: t,
|
|
15
15
|
...e ? { VELO_STATIC: "1" } : {}
|
|
16
16
|
};
|
|
17
|
-
console.log("Building client...")
|
|
17
|
+
console.log("Building client...");
|
|
18
|
+
const o = n("npx", ["vite", "build"], {
|
|
18
19
|
stdio: "inherit",
|
|
19
20
|
cwd: process.cwd(),
|
|
20
21
|
env: s
|
|
21
|
-
})
|
|
22
|
+
});
|
|
23
|
+
o.status !== 0 && (console.error("Client build failed. Aborting."), process.exit(o.status ?? 1)), console.log("Building server...");
|
|
24
|
+
const r = n("npx", ["vite", "build", "--mode", "server"], {
|
|
22
25
|
stdio: "inherit",
|
|
23
26
|
cwd: process.cwd(),
|
|
24
27
|
env: s
|
|
25
|
-
})
|
|
28
|
+
});
|
|
29
|
+
r.status !== 0 && (console.error("Server build failed. Aborting."), process.exit(r.status ?? 1)), console.log("Build complete!"), e && v();
|
|
26
30
|
}, v = async () => {
|
|
27
31
|
process.env.NODE_ENV = "production", process.env.VELO_STATIC = "1";
|
|
28
|
-
const t = await import(
|
|
29
|
-
(!s || !
|
|
30
|
-
const { generateStatic:
|
|
31
|
-
await
|
|
32
|
+
const t = await import(l(process.cwd(), "dist/server.js")), s = t.default, o = t.routes;
|
|
33
|
+
(!s || !o) && (console.error("Failed to load app or routes from dist/server.js"), process.exit(1));
|
|
34
|
+
const { generateStatic: r } = await import("./static.js");
|
|
35
|
+
await r(s, o);
|
|
32
36
|
}, m = () => {
|
|
33
37
|
process.env.NODE_ENV = "production";
|
|
34
|
-
const e =
|
|
35
|
-
|
|
36
|
-
},
|
|
38
|
+
const e = l(process.cwd(), "dist/server.js");
|
|
39
|
+
d("node", [e]);
|
|
40
|
+
}, a = () => {
|
|
37
41
|
console.log(`
|
|
38
42
|
VeloJS CLI
|
|
39
43
|
|
|
@@ -55,17 +59,17 @@ Examples:
|
|
|
55
59
|
velojs start
|
|
56
60
|
`);
|
|
57
61
|
};
|
|
58
|
-
switch (
|
|
62
|
+
switch (c) {
|
|
59
63
|
case "init": {
|
|
60
64
|
const { runInit: e } = await import("./init.js");
|
|
61
|
-
await e(
|
|
65
|
+
await e(i[1]);
|
|
62
66
|
break;
|
|
63
67
|
}
|
|
64
68
|
case "dev":
|
|
65
69
|
p();
|
|
66
70
|
break;
|
|
67
71
|
case "build": {
|
|
68
|
-
const e =
|
|
72
|
+
const e = i.includes("--static");
|
|
69
73
|
u(e);
|
|
70
74
|
break;
|
|
71
75
|
}
|
|
@@ -75,8 +79,8 @@ switch (r) {
|
|
|
75
79
|
case "help":
|
|
76
80
|
case "--help":
|
|
77
81
|
case "-h":
|
|
78
|
-
|
|
82
|
+
a();
|
|
79
83
|
break;
|
|
80
84
|
default:
|
|
81
|
-
|
|
85
|
+
c && console.error(`Unknown command: ${c}`), a(), process.exit(1);
|
|
82
86
|
}
|
package/dist/init.js
CHANGED
|
@@ -54,6 +54,7 @@ export default { plugins: [veloPlugin()] };
|
|
|
54
54
|
|
|
55
55
|
import * as Root from "./client-root.js";
|
|
56
56
|
import * as Home from "./pages/Home.js";
|
|
57
|
+
import * as NotFound from "./pages/NotFound.js";
|
|
57
58
|
|
|
58
59
|
export default [
|
|
59
60
|
{
|
|
@@ -61,6 +62,8 @@ export default [
|
|
|
61
62
|
isRoot: true,
|
|
62
63
|
children: [
|
|
63
64
|
{ path: "/", module: Home },
|
|
65
|
+
// Catch-all 404 — keep last. Served via notFound (SSR) / 404.html (SSG).
|
|
66
|
+
{ path: "*", module: NotFound, statusCode: 404 },
|
|
64
67
|
],
|
|
65
68
|
},
|
|
66
69
|
] satisfies AppRoutes;
|
|
@@ -123,9 +126,19 @@ a:hover {
|
|
|
123
126
|
</main>
|
|
124
127
|
);
|
|
125
128
|
};
|
|
129
|
+
`,
|
|
130
|
+
"app/pages/NotFound.tsx": `export const Component = () => {
|
|
131
|
+
return (
|
|
132
|
+
<main style={{ maxWidth: 640, margin: "80px auto", padding: "0 20px" }}>
|
|
133
|
+
<h1>404</h1>
|
|
134
|
+
<p>Page not found.</p>
|
|
135
|
+
<a href="/">Go home</a>
|
|
136
|
+
</main>
|
|
137
|
+
);
|
|
138
|
+
};
|
|
126
139
|
`
|
|
127
140
|
};
|
|
128
|
-
async function
|
|
141
|
+
async function x(o) {
|
|
129
142
|
const e = o ? s.resolve(process.cwd(), o) : process.cwd(), r = s.basename(e);
|
|
130
143
|
t.existsSync(e) ? t.readdirSync(e).filter(
|
|
131
144
|
(n) => !n.startsWith(".") && n !== "node_modules"
|
|
@@ -133,10 +146,10 @@ async function v(o) {
|
|
|
133
146
|
`Error: Directory "${r}" is not empty. Use an empty directory.`
|
|
134
147
|
), process.exit(1)) : t.mkdirSync(e, { recursive: !0 });
|
|
135
148
|
for (const [a, n] of Object.entries(u)) {
|
|
136
|
-
const
|
|
149
|
+
const p = s.join(e, a), l = s.dirname(p);
|
|
137
150
|
t.existsSync(l) || t.mkdirSync(l, { recursive: !0 });
|
|
138
|
-
const
|
|
139
|
-
t.writeFileSync(
|
|
151
|
+
const c = a === "package.json" ? n.replace("my-velojs-app", r) : n;
|
|
152
|
+
t.writeFileSync(p, c);
|
|
140
153
|
}
|
|
141
154
|
console.log(`
|
|
142
155
|
Project created in ${o ? r : "current directory"}!
|
|
@@ -145,5 +158,5 @@ Project created in ${o ? r : "current directory"}!
|
|
|
145
158
|
`);
|
|
146
159
|
}
|
|
147
160
|
export {
|
|
148
|
-
|
|
161
|
+
x as runInit
|
|
149
162
|
};
|
package/dist/server.js
CHANGED
|
@@ -2,13 +2,13 @@ import { jsx as g } from "preact/jsx-runtime";
|
|
|
2
2
|
import { Hono as R } from "hono";
|
|
3
3
|
import { logger as T } from "hono/logger";
|
|
4
4
|
import { trimTrailingSlash as j } from "hono/trailing-slash";
|
|
5
|
-
import { render as
|
|
6
|
-
import { Router as
|
|
7
|
-
import { AsyncLocalStorage as
|
|
5
|
+
import { render as A } from "preact-render-to-string";
|
|
6
|
+
import { Router as C } from "wouter-preact";
|
|
7
|
+
import { AsyncLocalStorage as k } from "node:async_hooks";
|
|
8
8
|
import { getAppContext as v } from "./app-context.js";
|
|
9
9
|
import { flushPendingStreamRoutes as $, registerStreamHandler as D } from "./events.js";
|
|
10
10
|
import { registerSocketRoutes as I, injectWebSocketServer as y } from "./sockets.js";
|
|
11
|
-
const S = new
|
|
11
|
+
const S = new k();
|
|
12
12
|
globalThis.__veloServerData = S;
|
|
13
13
|
let w = null;
|
|
14
14
|
function Y(e) {
|
|
@@ -27,38 +27,38 @@ function P(e) {
|
|
|
27
27
|
function Z(e) {
|
|
28
28
|
v().pendingRoutes.push(e);
|
|
29
29
|
}
|
|
30
|
-
const N = (e, t, s) => {
|
|
31
|
-
if (e.req.query("_data") === "1") {
|
|
32
|
-
const
|
|
33
|
-
return e.json(
|
|
30
|
+
const N = (e, t, s, r) => {
|
|
31
|
+
if (r && r !== 200 && e.status(r), e.req.query("_data") === "1") {
|
|
32
|
+
const i = globalThis.__veloBuildHash || void 0, l = s ? { ...s, __buildHash: i } : { __buildHash: i };
|
|
33
|
+
return e.json(l);
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const o = e.req.path, n = S.run(
|
|
36
36
|
s ?? {},
|
|
37
|
-
() =>
|
|
37
|
+
() => A(/* @__PURE__ */ g(C, { ssrPath: o, children: t }))
|
|
38
38
|
);
|
|
39
39
|
if (e.header("Cache-Control", "no-cache"), !s)
|
|
40
|
-
return e.html(
|
|
41
|
-
const
|
|
40
|
+
return e.html(n);
|
|
41
|
+
const a = `<script>window.__PAGE_DATA__=${JSON.stringify(
|
|
42
42
|
s
|
|
43
43
|
)}<\/script>`;
|
|
44
|
-
return e.html(
|
|
44
|
+
return e.html(n.replace("</head>", `${a}</head>`));
|
|
45
45
|
}, O = async (e, t) => {
|
|
46
|
-
const s = t.req.param(),
|
|
46
|
+
const s = t.req.param(), r = t.req.query(), o = { params: s, query: r, c: t }, n = await Promise.all(
|
|
47
47
|
e.map(async (i) => {
|
|
48
48
|
if (!i.loader) return null;
|
|
49
49
|
const l = await i.loader(o), c = i.metadata?.moduleId;
|
|
50
50
|
return c ? { moduleId: c, loaderData: l } : null;
|
|
51
51
|
})
|
|
52
|
-
),
|
|
52
|
+
), a = {
|
|
53
53
|
__params: s,
|
|
54
|
-
__query:
|
|
54
|
+
__query: r,
|
|
55
55
|
__pathname: t.req.path
|
|
56
56
|
};
|
|
57
57
|
for (const i of n)
|
|
58
|
-
i && (
|
|
58
|
+
i && (a[i.moduleId] = i.loaderData);
|
|
59
59
|
return {
|
|
60
60
|
components: e.map((i) => i.Component),
|
|
61
|
-
data:
|
|
61
|
+
data: a
|
|
62
62
|
};
|
|
63
63
|
}, G = (e) => {
|
|
64
64
|
if (e.length === 0) return null;
|
|
@@ -70,19 +70,19 @@ const N = (e, t, s) => {
|
|
|
70
70
|
}
|
|
71
71
|
const s = t[t.length - 1];
|
|
72
72
|
return t.slice(0, -1).reduceRight((o, n) => /* @__PURE__ */ g(n, { children: o }), /* @__PURE__ */ g(s, {}));
|
|
73
|
-
}, _ = (e, t, s = [],
|
|
73
|
+
}, _ = (e, t, s = [], r = []) => {
|
|
74
74
|
for (const o of t) {
|
|
75
75
|
if (o.handler && !o.module) {
|
|
76
76
|
o.children && _(
|
|
77
77
|
e,
|
|
78
78
|
o.children,
|
|
79
79
|
s,
|
|
80
|
-
[...
|
|
80
|
+
[...r, ...o.middlewares || []]
|
|
81
81
|
);
|
|
82
82
|
continue;
|
|
83
83
|
}
|
|
84
|
-
const n = o.module ? [...s, o.module] : s,
|
|
85
|
-
...
|
|
84
|
+
const n = o.module ? [...s, o.module] : s, a = [
|
|
85
|
+
...r,
|
|
86
86
|
...o.middlewares || []
|
|
87
87
|
];
|
|
88
88
|
if (o.children)
|
|
@@ -90,36 +90,36 @@ const N = (e, t, s) => {
|
|
|
90
90
|
e,
|
|
91
91
|
o.children,
|
|
92
92
|
n,
|
|
93
|
-
|
|
93
|
+
a
|
|
94
94
|
);
|
|
95
95
|
else if (o.module) {
|
|
96
|
-
const i = o.module.metadata?.fullPath;
|
|
97
|
-
if (!i) {
|
|
96
|
+
const i = o.path === "*", l = o.statusCode ?? (i ? 404 : void 0), c = o.module.metadata?.fullPath;
|
|
97
|
+
if (!c && !i) {
|
|
98
98
|
console.warn(
|
|
99
99
|
`Module ${o.module.metadata?.moduleId} has no fullPath`
|
|
100
100
|
);
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
|
-
const
|
|
104
|
-
const { components:
|
|
105
|
-
return N(
|
|
103
|
+
const u = async (h) => {
|
|
104
|
+
const { components: d, data: m } = await O(n, h), f = G(d);
|
|
105
|
+
return N(h, f, m, l);
|
|
106
106
|
};
|
|
107
|
-
|
|
107
|
+
i ? e.notFound(u) : a.length > 0 ? e.on(["GET"], [c], ...a, u) : e.on(["GET"], [c], u);
|
|
108
108
|
} else
|
|
109
109
|
continue;
|
|
110
110
|
}
|
|
111
111
|
}, b = (e, t, s = []) => {
|
|
112
|
-
for (const
|
|
113
|
-
const o =
|
|
112
|
+
for (const r of t) {
|
|
113
|
+
const o = r.module?.metadata?.moduleId, n = [
|
|
114
114
|
...s,
|
|
115
|
-
...
|
|
115
|
+
...r.middlewares || []
|
|
116
116
|
];
|
|
117
|
-
if (
|
|
118
|
-
const
|
|
117
|
+
if (r.module && o) {
|
|
118
|
+
const a = Object.keys(r.module).filter(
|
|
119
119
|
(i) => i.startsWith("action_")
|
|
120
120
|
);
|
|
121
|
-
for (const i of
|
|
122
|
-
const l = i.replace("action_", ""), c =
|
|
121
|
+
for (const i of a) {
|
|
122
|
+
const l = i.replace("action_", ""), c = r.module[i];
|
|
123
123
|
if (typeof c == "function") {
|
|
124
124
|
const u = `/_action/${o}/${l}`, h = async (d) => {
|
|
125
125
|
let m = {};
|
|
@@ -150,21 +150,21 @@ const N = (e, t, s) => {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
|
|
153
|
+
r.children && b(e, r.children, n);
|
|
154
154
|
}
|
|
155
155
|
}, H = async (e, t, s = []) => {
|
|
156
|
-
const
|
|
157
|
-
for (const
|
|
158
|
-
const i =
|
|
156
|
+
const r = (o, n) => {
|
|
157
|
+
for (const a of o) {
|
|
158
|
+
const i = a.module?.metadata?.moduleId, l = [
|
|
159
159
|
...n,
|
|
160
|
-
...
|
|
160
|
+
...a.middlewares || []
|
|
161
161
|
];
|
|
162
|
-
if (
|
|
163
|
-
const c = Object.keys(
|
|
162
|
+
if (a.module && i) {
|
|
163
|
+
const c = Object.keys(a.module).filter(
|
|
164
164
|
(u) => u.startsWith("stream_")
|
|
165
165
|
);
|
|
166
166
|
for (const u of c) {
|
|
167
|
-
const h = u.replace("stream_", ""), d =
|
|
167
|
+
const h = u.replace("stream_", ""), d = a.module[u];
|
|
168
168
|
if (d?.__isVeloEventStream) {
|
|
169
169
|
const m = `/_event/${i}/${h}`;
|
|
170
170
|
d.__path = m, D(
|
|
@@ -176,13 +176,13 @@ const N = (e, t, s) => {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
a.children && r(a.children, l);
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
|
-
|
|
182
|
+
r(t, s);
|
|
183
183
|
}, x = (e, t) => t ? t.startsWith("/") ? e + t : e ? e + "/" + t : "/" + t : e || "", V = (e) => {
|
|
184
|
-
const t = /* @__PURE__ */ new Set(), s = (
|
|
185
|
-
for (const o of
|
|
184
|
+
const t = /* @__PURE__ */ new Set(), s = (r) => {
|
|
185
|
+
for (const o of r) {
|
|
186
186
|
if (o.module && !o.children) {
|
|
187
187
|
const n = o.module.metadata?.fullPath;
|
|
188
188
|
n && t.add(n);
|
|
@@ -191,45 +191,45 @@ const N = (e, t, s) => {
|
|
|
191
191
|
}
|
|
192
192
|
};
|
|
193
193
|
return s(e), t;
|
|
194
|
-
}, q = (e, t, s,
|
|
194
|
+
}, q = (e, t, s, r = "", o = []) => {
|
|
195
195
|
for (const n of t) {
|
|
196
|
-
const
|
|
196
|
+
const a = x(r, n.path), i = [
|
|
197
197
|
...o,
|
|
198
198
|
...n.middlewares || []
|
|
199
199
|
], l = !!n.handler, c = !!n.method;
|
|
200
200
|
if (l && !c ? console.warn(
|
|
201
|
-
`[velojs] invalid route at "${
|
|
201
|
+
`[velojs] invalid route at "${a || "/"}" — "handler" set without "method"; endpoint skipped`
|
|
202
202
|
) : c && !l ? console.warn(
|
|
203
|
-
`[velojs] invalid route at "${
|
|
203
|
+
`[velojs] invalid route at "${a || "/"}" — "method" set without "handler"; endpoint skipped`
|
|
204
204
|
) : l && n.module ? console.warn(
|
|
205
|
-
`[velojs] ambiguous route at "${
|
|
205
|
+
`[velojs] ambiguous route at "${a || "/"}" — both "module" and "handler" set; endpoint ignored, page kept`
|
|
206
206
|
) : l && n.isRoot && console.warn(
|
|
207
|
-
`[velojs] "isRoot" has no effect on endpoint at "${
|
|
207
|
+
`[velojs] "isRoot" has no effect on endpoint at "${a || "/"}"; ignored`
|
|
208
208
|
), l && c && !n.module) {
|
|
209
209
|
const h = n.method;
|
|
210
|
-
h === "GET" && s.has(
|
|
211
|
-
`[velojs] path "${
|
|
210
|
+
h === "GET" && s.has(a) && console.warn(
|
|
211
|
+
`[velojs] path "${a}" has both a page GET and an endpoint GET; endpoint will win. Consider renaming one.`
|
|
212
212
|
);
|
|
213
213
|
const d = n.handler, m = async (f) => await d({
|
|
214
214
|
c: f,
|
|
215
215
|
params: f.req.param(),
|
|
216
216
|
query: f.req.query()
|
|
217
217
|
});
|
|
218
|
-
i.length > 0 ? e.on([h], [
|
|
218
|
+
i.length > 0 ? e.on([h], [a], ...i, m) : e.on([h], [a], m);
|
|
219
219
|
}
|
|
220
220
|
n.children && q(
|
|
221
221
|
e,
|
|
222
222
|
n.children,
|
|
223
223
|
s,
|
|
224
|
-
|
|
224
|
+
a,
|
|
225
225
|
i
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
}, W = async (e) => {
|
|
229
229
|
const t = new R();
|
|
230
230
|
t.use(j()), process.env.NODE_ENV !== "production" && t.use("*", T());
|
|
231
|
-
const
|
|
232
|
-
for (const n of
|
|
231
|
+
const r = v().pendingRoutes.splice(0);
|
|
232
|
+
for (const n of r)
|
|
233
233
|
await n(t);
|
|
234
234
|
_(t, e), b(t, e), await H(t, e);
|
|
235
235
|
const o = V(e);
|
|
@@ -239,14 +239,14 @@ const N = (e, t, s) => {
|
|
|
239
239
|
}
|
|
240
240
|
return t;
|
|
241
241
|
}, ee = async (e) => {
|
|
242
|
-
const { routes: t } = e, s = Number(process.env.PORT) || e.port || 3e3,
|
|
242
|
+
const { routes: t } = e, s = Number(process.env.PORT) || e.port || 3e3, r = await W(t);
|
|
243
243
|
if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
|
|
244
|
-
const { serve: o } = await import("@hono/node-server"), { serveStatic: n } = await import("@hono/node-server/serve-static"), { join:
|
|
245
|
-
(process.env.STATIC_BASE_URL || "").startsWith("http") ||
|
|
246
|
-
const c = o({ fetch:
|
|
247
|
-
await y(
|
|
244
|
+
const { serve: o } = await import("@hono/node-server"), { serveStatic: n } = await import("@hono/node-server/serve-static"), { join: a } = await import("node:path"), i = a(process.cwd(), "dist/client");
|
|
245
|
+
(process.env.STATIC_BASE_URL || "").startsWith("http") || r.use("/*", n({ root: i })), console.log(`Server running on http://localhost:${s}`);
|
|
246
|
+
const c = o({ fetch: r.fetch, port: s });
|
|
247
|
+
await y(r, c), P(c);
|
|
248
248
|
}
|
|
249
|
-
return
|
|
249
|
+
return r;
|
|
250
250
|
};
|
|
251
251
|
export {
|
|
252
252
|
Z as addRoutes,
|
package/dist/static.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import i from "node:fs";
|
|
2
2
|
import a from "node:path";
|
|
3
|
-
async function
|
|
4
|
-
const
|
|
3
|
+
async function h(c, e = "") {
|
|
4
|
+
const o = [];
|
|
5
5
|
for (const t of c) {
|
|
6
|
-
|
|
6
|
+
if (t.path === "*") continue;
|
|
7
|
+
const n = t.module?.metadata?.fullPath ?? "";
|
|
7
8
|
if (t.children) {
|
|
8
|
-
const s = await
|
|
9
|
-
|
|
9
|
+
const s = await h(t.children, n);
|
|
10
|
+
o.push(...s);
|
|
10
11
|
} else if (t.module) {
|
|
11
12
|
const s = t.module.metadata?.fullPath;
|
|
12
13
|
if (!s) continue;
|
|
@@ -17,60 +18,71 @@ async function d(c, n = "") {
|
|
|
17
18
|
const l = t.module.staticPaths;
|
|
18
19
|
if (typeof l == "function") {
|
|
19
20
|
const u = await l();
|
|
20
|
-
for (const
|
|
21
|
+
for (const p of u) {
|
|
21
22
|
let f = s;
|
|
22
|
-
for (const [
|
|
23
|
-
f = f.replace(`:${
|
|
24
|
-
|
|
23
|
+
for (const [m, w] of Object.entries(p))
|
|
24
|
+
f = f.replace(`:${m}`, w);
|
|
25
|
+
o.push({ fullPath: f, module: t.module });
|
|
25
26
|
}
|
|
26
27
|
} else
|
|
27
28
|
console.warn(
|
|
28
29
|
`Skipping ${s} — dynamic route without staticPaths export`
|
|
29
30
|
);
|
|
30
31
|
} else
|
|
31
|
-
|
|
32
|
+
o.push({ fullPath: s, module: t.module });
|
|
32
33
|
} else
|
|
33
34
|
continue;
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return o;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
function d(c) {
|
|
39
|
+
for (const e of c)
|
|
40
|
+
if (e.path === "*" && e.module || e.children && d(e.children)) return !0;
|
|
41
|
+
return !1;
|
|
42
|
+
}
|
|
43
|
+
async function y(c, e, o) {
|
|
44
|
+
const t = "http://localhost", n = await c.fetch(new Request(`${t}${e}`));
|
|
45
|
+
if (n.status !== 200) {
|
|
46
|
+
console.warn(`Skipping ${e} — got status ${n.status}`);
|
|
41
47
|
return;
|
|
42
48
|
}
|
|
43
|
-
const s = await
|
|
44
|
-
new Request(`${t}${
|
|
45
|
-
)).text(), u =
|
|
49
|
+
const s = await n.text(), l = await (await c.fetch(
|
|
50
|
+
new Request(`${t}${e}?_data=1`)
|
|
51
|
+
)).text(), u = e === "/" ? o : a.join(o, e);
|
|
46
52
|
i.mkdirSync(u, { recursive: !0 }), i.writeFileSync(a.join(u, "index.html"), s), i.writeFileSync(a.join(u, "index.json"), l);
|
|
47
53
|
}
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
if (!i.existsSync(
|
|
51
|
-
const
|
|
54
|
+
function g(c) {
|
|
55
|
+
const e = a.resolve(process.cwd(), "public");
|
|
56
|
+
if (!i.existsSync(e)) return;
|
|
57
|
+
const o = (t, n) => {
|
|
52
58
|
if (i.statSync(t).isDirectory()) {
|
|
53
|
-
i.mkdirSync(
|
|
59
|
+
i.mkdirSync(n, { recursive: !0 });
|
|
54
60
|
for (const r of i.readdirSync(t))
|
|
55
|
-
|
|
61
|
+
o(a.join(t, r), a.join(n, r));
|
|
56
62
|
} else
|
|
57
|
-
i.copyFileSync(t,
|
|
63
|
+
i.copyFileSync(t, n);
|
|
58
64
|
};
|
|
59
|
-
e
|
|
65
|
+
o(e, c);
|
|
60
66
|
}
|
|
61
|
-
async function
|
|
62
|
-
const
|
|
67
|
+
async function R(c, e) {
|
|
68
|
+
const o = a.resolve(process.cwd(), "dist");
|
|
63
69
|
console.log("Generating static pages...");
|
|
64
|
-
const t = await
|
|
70
|
+
const t = await h(e);
|
|
65
71
|
if (t.length === 0) {
|
|
66
72
|
console.warn("No routes found for static generation.");
|
|
67
73
|
return;
|
|
68
74
|
}
|
|
69
|
-
for (const
|
|
70
|
-
await y(c,
|
|
71
|
-
|
|
75
|
+
for (const n of t)
|
|
76
|
+
await y(c, n.fullPath, o), console.log(` ✓ ${n.fullPath}`);
|
|
77
|
+
if (d(e)) {
|
|
78
|
+
const s = await (await c.fetch(
|
|
79
|
+
new Request("http://localhost/__velojs_not_found__")
|
|
80
|
+
)).text();
|
|
81
|
+
i.writeFileSync(a.join(o, "404.html"), s), console.log(" ✓ /404.html");
|
|
82
|
+
}
|
|
83
|
+
g(o), console.log(`
|
|
72
84
|
Generated ${t.length} static pages.`);
|
|
73
85
|
}
|
|
74
86
|
export {
|
|
75
|
-
|
|
87
|
+
R as generateStatic
|
|
76
88
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -39,5 +39,12 @@ export interface RouteNode {
|
|
|
39
39
|
children?: RouteNode[];
|
|
40
40
|
middlewares?: MiddlewareHandler[];
|
|
41
41
|
isRoot?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* HTTP status code for the rendered page (default 200). Lets a route
|
|
44
|
+
* respond with e.g. 404/410/503. The bare catch-all (`path: "*"`) defaults
|
|
45
|
+
* to 404 and is served via Hono's notFound hook. For conditional status
|
|
46
|
+
* (resource missing inside a valid route), call `c.status()` in the loader.
|
|
47
|
+
*/
|
|
48
|
+
statusCode?: number;
|
|
42
49
|
}
|
|
43
50
|
export type AppRoutes = RouteNode[];
|
package/dist/vite.d.ts
CHANGED
|
@@ -21,6 +21,27 @@ export declare function transformStreamsForClient(code: string, moduleId: string
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function transformSocketsForClient(code: string, moduleId: string): string;
|
|
23
23
|
export declare function removeLoaders(code: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Removes import specifiers whose local binding is no longer referenced
|
|
26
|
+
* anywhere in the module after the client-only strips above (actions →
|
|
27
|
+
* fetch stubs, streams/sockets → stubs, loaders removed). Runs LAST so it
|
|
28
|
+
* sees the fully transformed AST.
|
|
29
|
+
*
|
|
30
|
+
* Why this is needed: under Rollup (vite 7) these orphaned imports were
|
|
31
|
+
* tree-shaken for free, keeping server-only code out of the client graph.
|
|
32
|
+
* Under Rolldown (vite 8) they survive — so a server-only helper imported
|
|
33
|
+
* top-level (e.g. an SSE `channel` resolver referenced only inside a now-
|
|
34
|
+
* stubbed `createEventStream({...})`) drags its entire service, and native
|
|
35
|
+
* `.node` deps, into the browser bundle and breaks the build. We replicate
|
|
36
|
+
* the tree-shake deterministically, inside our control.
|
|
37
|
+
*
|
|
38
|
+
* Safety:
|
|
39
|
+
* - Side-effect imports (`import "./x.css"`, no specifiers) are preserved.
|
|
40
|
+
* - `collectReferencedIdentifiers` counts value, type, and JSX positions,
|
|
41
|
+
* so a component used only in `<Foo />` is never dropped.
|
|
42
|
+
* - Only specifiers with zero remaining references are removed.
|
|
43
|
+
*/
|
|
44
|
+
export declare function pruneClientOnlyImports(code: string): string;
|
|
24
45
|
export declare function removeMiddlewares(code: string): string;
|
|
25
46
|
/**
|
|
26
47
|
* On client builds, strip EndpointRoute objects from the default-export array
|