@mauroandre/velojs 0.0.27 → 0.0.29
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/README.md +2 -2
- package/dist/config.d.ts +6 -0
- package/dist/hooks.d.ts +2 -2
- package/dist/server.js +11 -11
- package/dist/sockets.d.ts +16 -1
- package/dist/sockets.js +85 -71
- package/dist/vite.js +74 -68
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1247,7 +1247,7 @@ Callbacks queue until the server starts. If called after startup, executes immed
|
|
|
1247
1247
|
|
|
1248
1248
|
| Variable | Default | Description |
|
|
1249
1249
|
|----------|---------|-------------|
|
|
1250
|
-
| `
|
|
1250
|
+
| `PORT` | `3000` | Server port. Overrides the `port` set in `defineConfig` |
|
|
1251
1251
|
| `NODE_ENV` | — | Set automatically by `velojs start`. Enables static file serving |
|
|
1252
1252
|
| `STATIC_BASE_URL` | `""` | CDN/bucket prefix for static assets |
|
|
1253
1253
|
|
|
@@ -1528,7 +1528,7 @@ COPY package.json package-lock.json ./
|
|
|
1528
1528
|
RUN npm ci --omit=dev
|
|
1529
1529
|
COPY --from=builder /app/dist ./dist
|
|
1530
1530
|
|
|
1531
|
-
ENV
|
|
1531
|
+
ENV PORT=3000
|
|
1532
1532
|
EXPOSE 3000
|
|
1533
1533
|
CMD ["npx", "velojs", "start"]
|
|
1534
1534
|
```
|
package/dist/config.d.ts
CHANGED
|
@@ -19,5 +19,11 @@ export interface VeloConfig {
|
|
|
19
19
|
* @default "client.tsx"
|
|
20
20
|
*/
|
|
21
21
|
clientInit?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Porta usada tanto pelo dev server quanto pelo servidor de produção.
|
|
24
|
+
* A env `PORT` (injetada pela maioria dos hosts) sempre tem precedência.
|
|
25
|
+
* @default 3000
|
|
26
|
+
*/
|
|
27
|
+
port?: number;
|
|
22
28
|
}
|
|
23
29
|
export declare function defineConfig(config: VeloConfig): VeloConfig;
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Signal } from "@preact/signals";
|
|
2
2
|
import type { EventStream } from "./events.js";
|
|
3
|
-
import type { SocketStub } from "./sockets.js";
|
|
3
|
+
import type { SocketHandler, SocketStub } from "./sockets.js";
|
|
4
4
|
export declare const __veloUpdatePending: Signal<boolean>;
|
|
5
5
|
/**
|
|
6
6
|
* Força o signal a notificar mudanças após mutação de propriedades aninhadas
|
|
@@ -201,7 +201,7 @@ export interface UseSocketApi {
|
|
|
201
201
|
* send({ type: "resize", cols: 80, rows: 24 });
|
|
202
202
|
* ```
|
|
203
203
|
*/
|
|
204
|
-
export declare function useSocket(stub: SocketStub | {
|
|
204
|
+
export declare function useSocket(stub: SocketHandler | SocketStub | {
|
|
205
205
|
__path: string;
|
|
206
206
|
}, options?: UseSocketOptions): UseSocketApi;
|
|
207
207
|
export {};
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as g } from "preact/jsx-runtime";
|
|
2
|
-
import { Hono as
|
|
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
5
|
import { render as k } from "preact-render-to-string";
|
|
@@ -108,7 +108,7 @@ const N = (e, t, s) => {
|
|
|
108
108
|
} else
|
|
109
109
|
continue;
|
|
110
110
|
}
|
|
111
|
-
},
|
|
111
|
+
}, b = (e, t, s = []) => {
|
|
112
112
|
for (const a of t) {
|
|
113
113
|
const o = a.module?.metadata?.moduleId, n = [
|
|
114
114
|
...s,
|
|
@@ -137,8 +137,8 @@ const N = (e, t, s) => {
|
|
|
137
137
|
const p = await c(f);
|
|
138
138
|
return d.json(p ?? { ok: !0 });
|
|
139
139
|
} catch (p) {
|
|
140
|
-
const
|
|
141
|
-
return d.json({ error:
|
|
140
|
+
const E = p instanceof Error ? p.message : "Action failed";
|
|
141
|
+
return d.json({ error: E }, 500);
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
n.length > 0 ? e.on(
|
|
@@ -150,7 +150,7 @@ const N = (e, t, s) => {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
a.children &&
|
|
153
|
+
a.children && b(e, a.children, n);
|
|
154
154
|
}
|
|
155
155
|
}, H = async (e, t, s = []) => {
|
|
156
156
|
const a = (o, n) => {
|
|
@@ -191,7 +191,7 @@ const N = (e, t, s) => {
|
|
|
191
191
|
}
|
|
192
192
|
};
|
|
193
193
|
return s(e), t;
|
|
194
|
-
},
|
|
194
|
+
}, q = (e, t, s, a = "", o = []) => {
|
|
195
195
|
for (const n of t) {
|
|
196
196
|
const r = x(a, n.path), i = [
|
|
197
197
|
...o,
|
|
@@ -217,7 +217,7 @@ const N = (e, t, s) => {
|
|
|
217
217
|
});
|
|
218
218
|
i.length > 0 ? e.on([h], [r], ...i, m) : e.on([h], [r], m);
|
|
219
219
|
}
|
|
220
|
-
n.children &&
|
|
220
|
+
n.children && q(
|
|
221
221
|
e,
|
|
222
222
|
n.children,
|
|
223
223
|
s,
|
|
@@ -226,20 +226,20 @@ const N = (e, t, s) => {
|
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
}, W = async (e) => {
|
|
229
|
-
const t = new
|
|
229
|
+
const t = new R();
|
|
230
230
|
t.use(j()), process.env.NODE_ENV !== "production" && t.use("*", T());
|
|
231
231
|
const a = v().pendingRoutes.splice(0);
|
|
232
232
|
for (const n of a)
|
|
233
233
|
await n(t);
|
|
234
|
-
_(t, e),
|
|
234
|
+
_(t, e), b(t, e), await H(t, e);
|
|
235
235
|
const o = V(e);
|
|
236
|
-
if (
|
|
236
|
+
if (q(t, e, o), await I(t, e), $(t), process.env.NODE_ENV !== "production" && !w) {
|
|
237
237
|
const n = globalThis.__veloDevServer;
|
|
238
238
|
n && (P(n), await y(t, n));
|
|
239
239
|
}
|
|
240
240
|
return t;
|
|
241
241
|
}, ee = async (e) => {
|
|
242
|
-
const { routes: t,
|
|
242
|
+
const { routes: t } = e, s = Number(process.env.PORT) || e.port || 3e3, a = await W(t);
|
|
243
243
|
if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
|
|
244
244
|
const { serve: o } = await import("@hono/node-server"), { serveStatic: n } = await import("@hono/node-server/serve-static"), { join: r } = await import("node:path"), i = r(process.cwd(), "dist/client");
|
|
245
245
|
(process.env.STATIC_BASE_URL || "").startsWith("http") || a.use("/*", n({ root: i })), console.log(`Server running on http://localhost:${s}`);
|
package/dist/sockets.d.ts
CHANGED
|
@@ -52,7 +52,15 @@ export interface SocketHandlerArgs {
|
|
|
52
52
|
/** Query-string values. */
|
|
53
53
|
query: Record<string, string>;
|
|
54
54
|
}
|
|
55
|
-
export type SocketHandler = (args: SocketHandlerArgs) => void | Promise<void
|
|
55
|
+
export type SocketHandler = ((args: SocketHandlerArgs) => void | Promise<void>) & {
|
|
56
|
+
/**
|
|
57
|
+
* Populated at runtime by the socket registrar (and by the Vite plugin on the
|
|
58
|
+
* client bundle, where the function is replaced by a stub). Lets consumers
|
|
59
|
+
* pass the declared `socket_*` value straight into `useSocket(...)` without
|
|
60
|
+
* casting.
|
|
61
|
+
*/
|
|
62
|
+
readonly __path?: string;
|
|
63
|
+
};
|
|
56
64
|
/** Client-side stub shape — what the Vite plugin replaces `socket_*` with on the client bundle. */
|
|
57
65
|
export interface SocketStub {
|
|
58
66
|
readonly __isVeloSocket: true;
|
|
@@ -89,6 +97,13 @@ export declare function registerSocketRoutes(app: Hono, nodes: RouteNode[], pare
|
|
|
89
97
|
* returns (prod) or with Vite's dev http server (dev).
|
|
90
98
|
*
|
|
91
99
|
* No-op when no sockets are registered on `app`.
|
|
100
|
+
*
|
|
101
|
+
* The server is wrapped so that `upgrade` listeners registered by
|
|
102
|
+
* `@hono/node-ws` only fire for requests whose pathname matches a registered
|
|
103
|
+
* `socket_*` route. Without this, the adapter's listener treats every upgrade
|
|
104
|
+
* as a candidate and replies with an HTTP status, which corrupts the handshake
|
|
105
|
+
* for other listeners on the same server (notably Vite's HMR WebSocket in
|
|
106
|
+
* dev mode).
|
|
92
107
|
*/
|
|
93
108
|
export declare function injectWebSocketServer(app: Hono, server: any): Promise<void>;
|
|
94
109
|
export {};
|
package/dist/sockets.js
CHANGED
|
@@ -8,28 +8,28 @@ async function* W(e) {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
const
|
|
12
|
-
async function
|
|
13
|
-
let t =
|
|
11
|
+
const g = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
async function p(e) {
|
|
13
|
+
let t = g.get(e);
|
|
14
14
|
if (t) return t;
|
|
15
15
|
try {
|
|
16
|
-
return t = (await import("@hono/node-ws")).createNodeWebSocket({ app: e }),
|
|
16
|
+
return t = (await import("@hono/node-ws")).createNodeWebSocket({ app: e }), g.set(e, t), t;
|
|
17
17
|
} catch (n) {
|
|
18
18
|
return console.error("[velojs] failed to load @hono/node-ws:", n), null;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
function p(e, t) {
|
|
22
|
-
let n = k.get(e);
|
|
23
|
-
n || (n = /* @__PURE__ */ new Set(), k.set(e, n)), n.add(t);
|
|
24
|
-
}
|
|
25
21
|
function b(e, t) {
|
|
26
|
-
|
|
22
|
+
let n = S.get(e);
|
|
23
|
+
n || (n = /* @__PURE__ */ new Set(), S.set(e, n)), n.add(t);
|
|
24
|
+
}
|
|
25
|
+
function m(e, t) {
|
|
26
|
+
S.get(e)?.delete(t);
|
|
27
27
|
}
|
|
28
28
|
function _(e, t) {
|
|
29
|
-
return
|
|
29
|
+
return b(e, t), () => m(e, t);
|
|
30
30
|
}
|
|
31
31
|
function M(e) {
|
|
32
|
-
const t =
|
|
32
|
+
const t = S.get(e);
|
|
33
33
|
if (t) {
|
|
34
34
|
for (const n of t)
|
|
35
35
|
try {
|
|
@@ -39,64 +39,64 @@ function M(e) {
|
|
|
39
39
|
t.clear();
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
return
|
|
42
|
+
function x(e) {
|
|
43
|
+
return k.get(e) ?? /* @__PURE__ */ new Map();
|
|
44
44
|
}
|
|
45
45
|
function j(e, t, n) {
|
|
46
|
-
const
|
|
47
|
-
let
|
|
48
|
-
const
|
|
49
|
-
|
|
46
|
+
const i = [];
|
|
47
|
+
let r = null, s = !1, c = !1, o = null;
|
|
48
|
+
const l = new AbortController();
|
|
49
|
+
b(e, l);
|
|
50
50
|
const u = {
|
|
51
51
|
async *[Symbol.asyncIterator]() {
|
|
52
52
|
for (; ; ) {
|
|
53
|
-
for (;
|
|
54
|
-
yield
|
|
55
|
-
if (
|
|
56
|
-
await new Promise((
|
|
57
|
-
|
|
58
|
-
}),
|
|
53
|
+
for (; i.length > 0; )
|
|
54
|
+
yield i.shift();
|
|
55
|
+
if (s) return;
|
|
56
|
+
await new Promise((f) => {
|
|
57
|
+
r = f;
|
|
58
|
+
}), r = null;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
}, d = (
|
|
62
|
-
if (!(!o ||
|
|
61
|
+
}, d = (f) => {
|
|
62
|
+
if (!(!o || s))
|
|
63
63
|
try {
|
|
64
|
-
typeof
|
|
65
|
-
} catch (
|
|
66
|
-
console.error("[velojs] socket send failed:",
|
|
64
|
+
typeof f == "string" || f instanceof Uint8Array ? o.send(f) : o.send(JSON.stringify(f));
|
|
65
|
+
} catch (a) {
|
|
66
|
+
console.error("[velojs] socket send failed:", a);
|
|
67
67
|
}
|
|
68
|
-
},
|
|
68
|
+
}, w = (f, a) => {
|
|
69
69
|
if (o)
|
|
70
70
|
try {
|
|
71
|
-
o.close(
|
|
71
|
+
o.close(f, a);
|
|
72
72
|
} catch {
|
|
73
73
|
}
|
|
74
74
|
}, y = () => {
|
|
75
75
|
c = !0;
|
|
76
|
-
},
|
|
77
|
-
if (
|
|
76
|
+
}, h = () => {
|
|
77
|
+
if (s || (s = !0, r?.()), !l.signal.aborted)
|
|
78
78
|
try {
|
|
79
|
-
|
|
79
|
+
l.abort();
|
|
80
80
|
} catch {
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
m(e, l);
|
|
83
83
|
};
|
|
84
84
|
return {
|
|
85
85
|
events: {
|
|
86
|
-
onOpen(
|
|
87
|
-
o =
|
|
86
|
+
onOpen(f, a) {
|
|
87
|
+
o = a, Promise.resolve(
|
|
88
88
|
t({
|
|
89
89
|
incoming: u,
|
|
90
90
|
send: d,
|
|
91
|
-
close:
|
|
91
|
+
close: w,
|
|
92
92
|
keepOpen: y,
|
|
93
|
-
abortSignal:
|
|
93
|
+
abortSignal: l.signal,
|
|
94
94
|
c: n,
|
|
95
95
|
params: n.req.param(),
|
|
96
96
|
query: n.req.query()
|
|
97
97
|
})
|
|
98
98
|
).then(() => {
|
|
99
|
-
if (!c && o && !
|
|
99
|
+
if (!c && o && !s)
|
|
100
100
|
try {
|
|
101
101
|
o.close();
|
|
102
102
|
} catch {
|
|
@@ -109,33 +109,33 @@ function j(e, t, n) {
|
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
},
|
|
112
|
-
onMessage(
|
|
113
|
-
if (
|
|
114
|
-
const
|
|
115
|
-
typeof
|
|
112
|
+
onMessage(f) {
|
|
113
|
+
if (s) return;
|
|
114
|
+
const a = f.data;
|
|
115
|
+
typeof a == "string" ? i.push(a) : a instanceof ArrayBuffer ? i.push(new Uint8Array(a)) : a && typeof a == "object" && "buffer" in a && a.buffer instanceof ArrayBuffer && i.push(new Uint8Array(a.buffer)), r?.();
|
|
116
116
|
},
|
|
117
117
|
onClose() {
|
|
118
|
-
|
|
118
|
+
h();
|
|
119
119
|
},
|
|
120
120
|
onError() {
|
|
121
|
-
|
|
121
|
+
h();
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
|
-
cleanup:
|
|
124
|
+
cleanup: h
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
async function A(e, t, n,
|
|
128
|
-
let
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
if (!
|
|
132
|
-
const c =
|
|
133
|
-
|
|
127
|
+
async function A(e, t, n, i = []) {
|
|
128
|
+
let r = k.get(e);
|
|
129
|
+
r || (r = /* @__PURE__ */ new Map(), k.set(e, r)), r.set(t, { path: t, handler: n, middlewares: i });
|
|
130
|
+
const s = await p(e);
|
|
131
|
+
if (!s) return;
|
|
132
|
+
const c = s.upgradeWebSocket((o) => j(e, n, o).events);
|
|
133
|
+
i.length > 0 ? e.on(["GET"], [t], ...i, c) : e.on(["GET"], [t], c);
|
|
134
134
|
}
|
|
135
|
-
async function
|
|
136
|
-
const
|
|
137
|
-
for (const c of
|
|
138
|
-
const o = c.module?.metadata?.moduleId,
|
|
135
|
+
async function O(e, t, n = []) {
|
|
136
|
+
const i = async (r, s) => {
|
|
137
|
+
for (const c of r) {
|
|
138
|
+
const o = c.module?.metadata?.moduleId, l = [...s, ...c.middlewares ?? []];
|
|
139
139
|
if (c.module && o)
|
|
140
140
|
for (const u of Object.keys(c.module)) {
|
|
141
141
|
if (!u.startsWith("socket_")) continue;
|
|
@@ -146,7 +146,7 @@ async function q(e, t, n = []) {
|
|
|
146
146
|
);
|
|
147
147
|
continue;
|
|
148
148
|
}
|
|
149
|
-
const
|
|
149
|
+
const w = u.replace("socket_", ""), y = `/_socket/${o}/${w}`;
|
|
150
150
|
try {
|
|
151
151
|
d.__path = y;
|
|
152
152
|
} catch {
|
|
@@ -155,28 +155,42 @@ async function q(e, t, n = []) {
|
|
|
155
155
|
d.__isVeloSocket = !0;
|
|
156
156
|
} catch {
|
|
157
157
|
}
|
|
158
|
-
await A(e, y, d,
|
|
158
|
+
await A(e, y, d, l);
|
|
159
159
|
}
|
|
160
|
-
c.children && await
|
|
160
|
+
c.children && await i(c.children, l);
|
|
161
161
|
}
|
|
162
162
|
};
|
|
163
|
-
await
|
|
163
|
+
await i(t, n);
|
|
164
164
|
}
|
|
165
|
-
async function
|
|
166
|
-
const n =
|
|
167
|
-
if (n)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
165
|
+
async function J(e, t) {
|
|
166
|
+
const n = g.get(e);
|
|
167
|
+
if (!n) return;
|
|
168
|
+
const i = new Proxy(t, {
|
|
169
|
+
get(r, s, c) {
|
|
170
|
+
return s === "on" || s === "addListener" ? (o, l) => o !== "upgrade" ? r[s](o, l) : r[s]("upgrade", (u, d, w) => {
|
|
171
|
+
const y = u.headers?.host ?? "localhost";
|
|
172
|
+
let h;
|
|
173
|
+
try {
|
|
174
|
+
h = new URL(u.url ?? "/", `http://${y}`).pathname;
|
|
175
|
+
} catch {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
k.get(e)?.has(h) && l(u, d, w);
|
|
179
|
+
}) : Reflect.get(r, s, c);
|
|
172
180
|
}
|
|
181
|
+
});
|
|
182
|
+
try {
|
|
183
|
+
n.injectWebSocket(i);
|
|
184
|
+
} catch (r) {
|
|
185
|
+
console.error("[velojs] injectWebSocket failed:", r);
|
|
186
|
+
}
|
|
173
187
|
}
|
|
174
188
|
export {
|
|
175
189
|
M as abortAllSocketSessions,
|
|
176
|
-
|
|
177
|
-
|
|
190
|
+
x as getAppSockets,
|
|
191
|
+
J as injectWebSocketServer,
|
|
178
192
|
W as parseJson,
|
|
179
193
|
A as registerSocketHandler,
|
|
180
|
-
|
|
194
|
+
O as registerSocketRoutes,
|
|
181
195
|
_ as trackSocketSession
|
|
182
196
|
};
|
package/dist/vite.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import y from "node:path";
|
|
2
2
|
import S from "node:fs";
|
|
3
3
|
import R from "@preact/preset-vite";
|
|
4
4
|
import $ from "@hono/vite-dev-server";
|
|
5
|
-
import { parse as
|
|
5
|
+
import { parse as _ } from "@babel/parser";
|
|
6
6
|
import g from "@babel/traverse";
|
|
7
7
|
import j from "@babel/generator";
|
|
8
8
|
import * as e from "@babel/types";
|
|
9
9
|
const d = typeof g == "function" ? g : g.default, h = typeof j == "function" ? j : j.default;
|
|
10
10
|
function U(p, c, i, n) {
|
|
11
|
-
const o =
|
|
11
|
+
const o = _(p, {
|
|
12
12
|
sourceType: "module",
|
|
13
13
|
plugins: ["typescript", "jsx"]
|
|
14
14
|
});
|
|
@@ -21,23 +21,23 @@ function U(p, c, i, n) {
|
|
|
21
21
|
const r = a.declarations[0];
|
|
22
22
|
if (r && e.isIdentifier(r.id, { name: "metadata" }) && e.isObjectExpression(r.init)) {
|
|
23
23
|
t = !0;
|
|
24
|
-
const f = r.init.properties.filter((
|
|
24
|
+
const f = r.init.properties.filter((v) => e.isObjectProperty(v) && e.isIdentifier(v.key) ? v.key.name !== "moduleId" && v.key.name !== "fullPath" && v.key.name !== "path" : !0), m = [
|
|
25
25
|
e.objectProperty(
|
|
26
26
|
e.identifier("moduleId"),
|
|
27
27
|
e.stringLiteral(c)
|
|
28
28
|
)
|
|
29
29
|
];
|
|
30
|
-
i !== void 0 &&
|
|
30
|
+
i !== void 0 && m.push(
|
|
31
31
|
e.objectProperty(
|
|
32
32
|
e.identifier("fullPath"),
|
|
33
33
|
e.stringLiteral(i)
|
|
34
34
|
)
|
|
35
|
-
), n !== void 0 &&
|
|
35
|
+
), n !== void 0 && m.push(
|
|
36
36
|
e.objectProperty(
|
|
37
37
|
e.identifier("path"),
|
|
38
38
|
e.stringLiteral(n)
|
|
39
39
|
)
|
|
40
|
-
), r.init.properties = [...
|
|
40
|
+
), r.init.properties = [...m, ...f];
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -72,7 +72,7 @@ function U(p, c, i, n) {
|
|
|
72
72
|
return h(o, { retainLines: !0 }).code;
|
|
73
73
|
}
|
|
74
74
|
function W(p, c) {
|
|
75
|
-
const i =
|
|
75
|
+
const i = _(p, {
|
|
76
76
|
sourceType: "module",
|
|
77
77
|
plugins: ["typescript", "jsx"]
|
|
78
78
|
});
|
|
@@ -86,7 +86,7 @@ function W(p, c) {
|
|
|
86
86
|
}), h(i, { retainLines: !0 }).code;
|
|
87
87
|
}
|
|
88
88
|
function J(p, c) {
|
|
89
|
-
const i =
|
|
89
|
+
const i = _(p, {
|
|
90
90
|
sourceType: "module",
|
|
91
91
|
plugins: ["typescript", "jsx"]
|
|
92
92
|
});
|
|
@@ -202,7 +202,7 @@ function B(p, c) {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
function H(p, c) {
|
|
205
|
-
const i =
|
|
205
|
+
const i = _(p, {
|
|
206
206
|
sourceType: "module",
|
|
207
207
|
plugins: ["typescript", "jsx"]
|
|
208
208
|
});
|
|
@@ -229,7 +229,7 @@ function H(p, c) {
|
|
|
229
229
|
}), h(i, { retainLines: !0 }).code;
|
|
230
230
|
}
|
|
231
231
|
function z(p, c) {
|
|
232
|
-
const i =
|
|
232
|
+
const i = _(p, {
|
|
233
233
|
sourceType: "module",
|
|
234
234
|
plugins: ["typescript", "jsx"]
|
|
235
235
|
});
|
|
@@ -255,8 +255,8 @@ function z(p, c) {
|
|
|
255
255
|
}
|
|
256
256
|
}), h(i, { retainLines: !0 }).code;
|
|
257
257
|
}
|
|
258
|
-
function
|
|
259
|
-
const c =
|
|
258
|
+
function G(p) {
|
|
259
|
+
const c = _(p, {
|
|
260
260
|
sourceType: "module",
|
|
261
261
|
plugins: ["typescript", "jsx"]
|
|
262
262
|
});
|
|
@@ -269,8 +269,8 @@ function Y(p) {
|
|
|
269
269
|
}
|
|
270
270
|
}), h(c, { retainLines: !0 }).code;
|
|
271
271
|
}
|
|
272
|
-
function
|
|
273
|
-
const c =
|
|
272
|
+
function Y(p) {
|
|
273
|
+
const c = _(p, {
|
|
274
274
|
sourceType: "module",
|
|
275
275
|
plugins: ["typescript", "jsx"]
|
|
276
276
|
}), i = /* @__PURE__ */ new Set();
|
|
@@ -295,7 +295,7 @@ function q(p) {
|
|
|
295
295
|
}
|
|
296
296
|
}), h(c, { retainLines: !0 }).code);
|
|
297
297
|
}
|
|
298
|
-
function
|
|
298
|
+
function O(p, c) {
|
|
299
299
|
const i = (n) => {
|
|
300
300
|
if (!(!n || typeof n != "object")) {
|
|
301
301
|
if (Array.isArray(n)) {
|
|
@@ -321,7 +321,7 @@ function A(p, c) {
|
|
|
321
321
|
};
|
|
322
322
|
i(p);
|
|
323
323
|
}
|
|
324
|
-
function
|
|
324
|
+
function q(p) {
|
|
325
325
|
for (const c of p.properties)
|
|
326
326
|
if (e.isObjectProperty(c) && e.isIdentifier(c.key) && c.key.name === "handler")
|
|
327
327
|
return !0;
|
|
@@ -334,14 +334,14 @@ function K(p) {
|
|
|
334
334
|
return null;
|
|
335
335
|
}
|
|
336
336
|
function Q(p) {
|
|
337
|
-
const c =
|
|
337
|
+
const c = _(p, {
|
|
338
338
|
sourceType: "module",
|
|
339
339
|
plugins: ["typescript", "jsx"]
|
|
340
340
|
}), i = [], n = (a) => {
|
|
341
341
|
for (let r = a.elements.length - 1; r >= 0; r--) {
|
|
342
342
|
const u = a.elements[r];
|
|
343
343
|
if (!e.isObjectExpression(u)) continue;
|
|
344
|
-
if (
|
|
344
|
+
if (q(u)) {
|
|
345
345
|
i.push(u), a.elements.splice(r, 1);
|
|
346
346
|
continue;
|
|
347
347
|
}
|
|
@@ -358,9 +358,9 @@ function Q(p) {
|
|
|
358
358
|
}), i.length === 0) return p;
|
|
359
359
|
const o = /* @__PURE__ */ new Set();
|
|
360
360
|
for (const a of i)
|
|
361
|
-
|
|
361
|
+
O(a, o);
|
|
362
362
|
const t = /* @__PURE__ */ new Set();
|
|
363
|
-
|
|
363
|
+
O(c.program, t);
|
|
364
364
|
const s = /* @__PURE__ */ new Set();
|
|
365
365
|
for (const a of o)
|
|
366
366
|
t.has(a) || s.add(a);
|
|
@@ -371,8 +371,8 @@ function Q(p) {
|
|
|
371
371
|
}
|
|
372
372
|
}), h(c, { retainLines: !0 }).code;
|
|
373
373
|
}
|
|
374
|
-
function
|
|
375
|
-
const c =
|
|
374
|
+
function A(p) {
|
|
375
|
+
const c = _(p, {
|
|
376
376
|
sourceType: "module",
|
|
377
377
|
plugins: ["typescript", "jsx"]
|
|
378
378
|
}), i = /* @__PURE__ */ new Map();
|
|
@@ -420,29 +420,29 @@ function C(p, c, i) {
|
|
|
420
420
|
l && C(l.elements, t, i);
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
-
const
|
|
423
|
+
const E = "virtual:velo/server-entry", b = "virtual:velo/client-entry", P = "\0" + E, N = "\0" + b;
|
|
424
424
|
function X(p, c) {
|
|
425
|
-
let i =
|
|
425
|
+
let i = y.resolve(process.cwd(), c);
|
|
426
426
|
const n = p.routesFile ?? "routes.tsx", o = /* @__PURE__ */ new Map();
|
|
427
427
|
return {
|
|
428
428
|
name: "velo:transform",
|
|
429
429
|
enforce: "pre",
|
|
430
430
|
configResolved(t) {
|
|
431
|
-
i =
|
|
431
|
+
i = y.resolve(t.root, c);
|
|
432
432
|
},
|
|
433
433
|
buildStart() {
|
|
434
|
-
const t =
|
|
434
|
+
const t = y.join(i, n);
|
|
435
435
|
if (S.existsSync(t)) {
|
|
436
|
-
const s = S.readFileSync(t, "utf-8"), l =
|
|
436
|
+
const s = S.readFileSync(t, "utf-8"), l = A(s);
|
|
437
437
|
o.clear();
|
|
438
438
|
for (const [a, r] of l)
|
|
439
439
|
o.set(a, r);
|
|
440
440
|
}
|
|
441
441
|
},
|
|
442
442
|
handleHotUpdate({ file: t, server: s }) {
|
|
443
|
-
const l =
|
|
443
|
+
const l = y.join(i, n);
|
|
444
444
|
if (t === l) {
|
|
445
|
-
const a = S.readFileSync(l, "utf-8"), r =
|
|
445
|
+
const a = S.readFileSync(l, "utf-8"), r = A(a);
|
|
446
446
|
o.clear();
|
|
447
447
|
for (const [u, f] of r)
|
|
448
448
|
o.set(u, f);
|
|
@@ -450,11 +450,11 @@ function X(p, c) {
|
|
|
450
450
|
}
|
|
451
451
|
},
|
|
452
452
|
resolveId(t) {
|
|
453
|
-
return t ===
|
|
453
|
+
return t === E || t.endsWith(E) ? P : t === b || t.endsWith(b) || t === "/__velo_client.js" ? N : null;
|
|
454
454
|
},
|
|
455
455
|
load(t) {
|
|
456
|
-
const s = p.routesFile ?? "routes.tsx", l = p.serverInit ?? "server.tsx", a = p.clientInit ?? "client.tsx", r =
|
|
457
|
-
return t ===
|
|
456
|
+
const s = p.routesFile ?? "routes.tsx", l = p.serverInit ?? "server.tsx", a = p.clientInit ?? "client.tsx", r = y.join(i, s).replace(/\.tsx?$/, ".js"), u = y.join(i, l).replace(/\.tsx?$/, ".js"), f = y.join(i, a).replace(/\.tsx?$/, ".js");
|
|
457
|
+
return t === P ? `
|
|
458
458
|
globalThis.__veloBuildHash = __VELO_BUILD_HASH__;
|
|
459
459
|
globalThis.__veloClientJs = __VELO_CLIENT_JS__;
|
|
460
460
|
globalThis.__veloClientCss = __VELO_CLIENT_CSS__;
|
|
@@ -463,8 +463,8 @@ import routes from "${r}";
|
|
|
463
463
|
import { startServer } from "@mauroandre/velojs/server";
|
|
464
464
|
|
|
465
465
|
export { routes };
|
|
466
|
-
export default await startServer({ routes });
|
|
467
|
-
` : t ===
|
|
466
|
+
export default await startServer({ routes, port: __VELO_CONFIG_PORT__ });
|
|
467
|
+
` : t === N ? `
|
|
468
468
|
import "${f}";
|
|
469
469
|
import routes from "${r}";
|
|
470
470
|
import { startClient } from "@mauroandre/velojs/client";
|
|
@@ -476,21 +476,21 @@ startClient({ routes });
|
|
|
476
476
|
const a = l?.ssr === !0;
|
|
477
477
|
if (s.startsWith("\0") || s.includes("/.velojs/") || !s.endsWith(".tsx") && !s.endsWith(".ts") || !s.startsWith(i)) return null;
|
|
478
478
|
let r = t, u = !1;
|
|
479
|
-
const f = /middlewares:\s*\[/.test(t),
|
|
479
|
+
const f = /middlewares:\s*\[/.test(t), m = /export\s+(const|function)\s+Component/.test(
|
|
480
480
|
t
|
|
481
|
-
),
|
|
482
|
-
if (!a && f && (r =
|
|
483
|
-
const
|
|
484
|
-
r = U(r,
|
|
481
|
+
), v = /export\s+(const|function)\s+loader/.test(t), D = /export\s+const\s+action_\w+/.test(t), L = /export\s+const\s+stream_\w+/.test(t), I = /export\s+const\s+socket_\w+/.test(t), w = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), F = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t), k = /\bhandler\s*:/.test(t), V = y.join(i, n);
|
|
482
|
+
if (!a && f && (r = Y(r), u = !0), !a && k && s === V && (r = Q(r), u = !0), m || v || D || L || I || w || F) {
|
|
483
|
+
const x = y.relative(i, s).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), T = o.get(x);
|
|
484
|
+
r = U(r, x, T?.fullPath, T?.path), r = W(r, x), a || (r = J(
|
|
485
485
|
r,
|
|
486
|
-
|
|
486
|
+
x
|
|
487
487
|
)), !a && L && (r = H(
|
|
488
488
|
r,
|
|
489
|
-
|
|
489
|
+
x
|
|
490
490
|
)), !a && I && (r = z(
|
|
491
491
|
r,
|
|
492
|
-
|
|
493
|
-
)), a || (r =
|
|
492
|
+
x
|
|
493
|
+
)), a || (r = G(r)), u = !0;
|
|
494
494
|
}
|
|
495
495
|
return u ? {
|
|
496
496
|
code: r,
|
|
@@ -499,36 +499,42 @@ startClient({ routes });
|
|
|
499
499
|
}
|
|
500
500
|
};
|
|
501
501
|
}
|
|
502
|
-
function Z() {
|
|
502
|
+
function Z(p) {
|
|
503
503
|
return {
|
|
504
504
|
name: "velo:config",
|
|
505
|
-
config(
|
|
506
|
-
const
|
|
507
|
-
let
|
|
508
|
-
if (
|
|
505
|
+
config(c, { mode: i }) {
|
|
506
|
+
const n = i === "server", o = i === "development", t = !!process.env.VELO_STATIC, s = Number(process.env.PORT) || p.port || 3e3;
|
|
507
|
+
let l = "client.js", a = "client.css";
|
|
508
|
+
if (n)
|
|
509
509
|
try {
|
|
510
|
-
const
|
|
511
|
-
|
|
510
|
+
const u = y.resolve(process.cwd(), "dist/client/.vite/manifest.json"), m = JSON.parse(S.readFileSync(u, "utf-8"))[b];
|
|
511
|
+
m && (l = m.file || l, m.css?.[0] && (a = m.css[0]));
|
|
512
512
|
} catch {
|
|
513
513
|
}
|
|
514
|
-
const
|
|
514
|
+
const r = {
|
|
515
515
|
define: {
|
|
516
|
-
"process.env.NODE_ENV": JSON.stringify(
|
|
517
|
-
"process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (
|
|
518
|
-
__VELO_STATIC__: JSON.stringify(
|
|
516
|
+
"process.env.NODE_ENV": JSON.stringify(o ? "development" : "production"),
|
|
517
|
+
"process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (t ? "/client" : "")),
|
|
518
|
+
__VELO_STATIC__: JSON.stringify(t),
|
|
519
519
|
__VELO_BUILD_HASH__: JSON.stringify(process.env.VELO_BUILD_HASH || Date.now().toString(36)),
|
|
520
|
-
__VELO_CLIENT_JS__: JSON.stringify(
|
|
521
|
-
__VELO_CLIENT_CSS__: JSON.stringify(
|
|
520
|
+
__VELO_CLIENT_JS__: JSON.stringify(l),
|
|
521
|
+
__VELO_CLIENT_CSS__: JSON.stringify(a),
|
|
522
|
+
// Baked into the server bundle as startServer's port fallback.
|
|
523
|
+
// null when unset → startServer falls back to PORT env / 3000.
|
|
524
|
+
__VELO_CONFIG_PORT__: JSON.stringify(p.port ?? null)
|
|
522
525
|
},
|
|
523
526
|
resolve: {
|
|
524
527
|
alias: {
|
|
525
528
|
react: "preact/compat",
|
|
526
529
|
"react-dom": "preact/compat"
|
|
527
530
|
}
|
|
531
|
+
},
|
|
532
|
+
server: {
|
|
533
|
+
port: s
|
|
528
534
|
}
|
|
529
535
|
};
|
|
530
|
-
return
|
|
531
|
-
ssr:
|
|
536
|
+
return n ? r.build = {
|
|
537
|
+
ssr: E,
|
|
532
538
|
outDir: "dist",
|
|
533
539
|
emptyOutDir: !1,
|
|
534
540
|
copyPublicDir: !1,
|
|
@@ -537,17 +543,17 @@ function Z() {
|
|
|
537
543
|
entryFileNames: "server.js"
|
|
538
544
|
}
|
|
539
545
|
}
|
|
540
|
-
} :
|
|
546
|
+
} : o || (r.build = {
|
|
541
547
|
manifest: !0,
|
|
542
548
|
outDir: "dist/client",
|
|
543
549
|
rollupOptions: {
|
|
544
|
-
input:
|
|
550
|
+
input: b,
|
|
545
551
|
output: {
|
|
546
552
|
entryFileNames: "client.[hash].js",
|
|
547
|
-
assetFileNames: (
|
|
553
|
+
assetFileNames: (u) => u.names?.[0]?.endsWith(".css") ? "client.[hash].css" : "[name].[hash][extname]"
|
|
548
554
|
}
|
|
549
555
|
}
|
|
550
|
-
}),
|
|
556
|
+
}), r;
|
|
551
557
|
}
|
|
552
558
|
};
|
|
553
559
|
}
|
|
@@ -570,12 +576,12 @@ function ee() {
|
|
|
570
576
|
function le(p) {
|
|
571
577
|
const c = p ?? {}, i = c.appDirectory ?? "./app";
|
|
572
578
|
return [
|
|
573
|
-
Z(),
|
|
579
|
+
Z(c),
|
|
574
580
|
X(c, i),
|
|
575
581
|
ee(),
|
|
576
582
|
R(),
|
|
577
583
|
$({
|
|
578
|
-
entry:
|
|
584
|
+
entry: E
|
|
579
585
|
}),
|
|
580
586
|
te()
|
|
581
587
|
];
|
|
@@ -589,12 +595,12 @@ function te() {
|
|
|
589
595
|
};
|
|
590
596
|
}
|
|
591
597
|
export {
|
|
592
|
-
|
|
598
|
+
A as buildFullPathMap,
|
|
593
599
|
C as collectFullPaths,
|
|
594
600
|
U as injectMetadata,
|
|
595
601
|
Q as removeEndpointRoutes,
|
|
596
|
-
|
|
597
|
-
|
|
602
|
+
G as removeLoaders,
|
|
603
|
+
Y as removeMiddlewares,
|
|
598
604
|
J as transformActionsForClient,
|
|
599
605
|
W as transformLoaderFunctions,
|
|
600
606
|
z as transformSocketsForClient,
|