@mauroandre/velojs 0.0.25 → 0.0.27
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 +121 -1
- package/dist/client.js +43 -16
- package/dist/events.d.ts +58 -3
- package/dist/events.js +174 -135
- package/dist/hooks.d.ts +56 -0
- package/dist/hooks.js +128 -68
- package/dist/index.d.ts +3 -2
- package/dist/server.js +180 -122
- package/dist/sockets.d.ts +94 -0
- package/dist/sockets.js +182 -0
- package/dist/static.js +9 -8
- package/dist/testing/index.js +453 -290
- package/dist/testing/socketSession.d.ts +13 -0
- package/dist/testing/types.d.ts +36 -0
- package/dist/types.d.ts +10 -1
- package/dist/vite.d.ts +18 -0
- package/dist/vite.js +339 -231
- package/package.json +6 -1
package/dist/vite.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { parse as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
1
|
+
import m from "node:path";
|
|
2
|
+
import S from "node:fs";
|
|
3
|
+
import R from "@preact/preset-vite";
|
|
4
|
+
import $ from "@hono/vite-dev-server";
|
|
5
|
+
import { parse as y } from "@babel/parser";
|
|
6
|
+
import g from "@babel/traverse";
|
|
7
|
+
import j from "@babel/generator";
|
|
8
8
|
import * as e from "@babel/types";
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
const
|
|
9
|
+
const d = typeof g == "function" ? g : g.default, h = typeof j == "function" ? j : j.default;
|
|
10
|
+
function U(p, c, i, n) {
|
|
11
|
+
const o = y(p, {
|
|
12
12
|
sourceType: "module",
|
|
13
13
|
plugins: ["typescript", "jsx"]
|
|
14
14
|
});
|
|
15
15
|
let t = !1;
|
|
16
|
-
if (
|
|
16
|
+
if (d(o, {
|
|
17
17
|
// Procura: export const metadata = { ... }
|
|
18
|
-
ExportNamedDeclaration(
|
|
19
|
-
const a =
|
|
18
|
+
ExportNamedDeclaration(l) {
|
|
19
|
+
const a = l.node.declaration;
|
|
20
20
|
if (e.isVariableDeclaration(a) && a.declarations.length === 1) {
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
21
|
+
const r = a.declarations[0];
|
|
22
|
+
if (r && e.isIdentifier(r.id, { name: "metadata" }) && e.isObjectExpression(r.init)) {
|
|
23
23
|
t = !0;
|
|
24
|
-
const f =
|
|
24
|
+
const f = r.init.properties.filter((_) => e.isObjectProperty(_) && e.isIdentifier(_.key) ? _.key.name !== "moduleId" && _.key.name !== "fullPath" && _.key.name !== "path" : !0), x = [
|
|
25
25
|
e.objectProperty(
|
|
26
26
|
e.identifier("moduleId"),
|
|
27
|
-
e.stringLiteral(
|
|
27
|
+
e.stringLiteral(c)
|
|
28
28
|
)
|
|
29
29
|
];
|
|
30
|
-
|
|
30
|
+
i !== void 0 && x.push(
|
|
31
31
|
e.objectProperty(
|
|
32
32
|
e.identifier("fullPath"),
|
|
33
|
-
e.stringLiteral(
|
|
33
|
+
e.stringLiteral(i)
|
|
34
34
|
)
|
|
35
|
-
),
|
|
35
|
+
), n !== void 0 && x.push(
|
|
36
36
|
e.objectProperty(
|
|
37
37
|
e.identifier("path"),
|
|
38
|
-
e.stringLiteral(
|
|
38
|
+
e.stringLiteral(n)
|
|
39
39
|
)
|
|
40
|
-
),
|
|
40
|
+
), r.init.properties = [...x, ...f];
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}), !t) {
|
|
45
|
-
const
|
|
45
|
+
const l = [
|
|
46
46
|
e.objectProperty(
|
|
47
47
|
e.identifier("moduleId"),
|
|
48
|
-
e.stringLiteral(
|
|
48
|
+
e.stringLiteral(c)
|
|
49
49
|
)
|
|
50
50
|
];
|
|
51
|
-
|
|
51
|
+
i !== void 0 && l.push(
|
|
52
52
|
e.objectProperty(
|
|
53
53
|
e.identifier("fullPath"),
|
|
54
|
-
e.stringLiteral(
|
|
54
|
+
e.stringLiteral(i)
|
|
55
55
|
)
|
|
56
|
-
),
|
|
56
|
+
), n !== void 0 && l.push(
|
|
57
57
|
e.objectProperty(
|
|
58
58
|
e.identifier("path"),
|
|
59
|
-
e.stringLiteral(
|
|
59
|
+
e.stringLiteral(n)
|
|
60
60
|
)
|
|
61
61
|
);
|
|
62
62
|
const a = e.exportNamedDeclaration(
|
|
63
63
|
e.variableDeclaration("const", [
|
|
64
64
|
e.variableDeclarator(
|
|
65
65
|
e.identifier("metadata"),
|
|
66
|
-
e.objectExpression(
|
|
66
|
+
e.objectExpression(l)
|
|
67
67
|
)
|
|
68
68
|
])
|
|
69
69
|
);
|
|
70
|
-
|
|
70
|
+
o.program.body.unshift(a);
|
|
71
71
|
}
|
|
72
|
-
return
|
|
72
|
+
return h(o, { retainLines: !0 }).code;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
const
|
|
74
|
+
function W(p, c) {
|
|
75
|
+
const i = y(p, {
|
|
76
76
|
sourceType: "module",
|
|
77
77
|
plugins: ["typescript", "jsx"]
|
|
78
78
|
});
|
|
79
|
-
return
|
|
80
|
-
CallExpression(
|
|
81
|
-
const t =
|
|
82
|
-
if (!
|
|
83
|
-
const a =
|
|
84
|
-
e.isStringLiteral(
|
|
79
|
+
return d(i, {
|
|
80
|
+
CallExpression(o) {
|
|
81
|
+
const t = o.node.callee, s = e.isIdentifier(t, { name: "Loader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "Loader" }), l = e.isIdentifier(t, { name: "useLoader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "useLoader" });
|
|
82
|
+
if (!s && !l) return;
|
|
83
|
+
const a = o.node.arguments, r = e.stringLiteral(c), u = a[0];
|
|
84
|
+
e.isStringLiteral(u) && u.value.includes("/") || (o.node.arguments = [r, ...a]);
|
|
85
85
|
}
|
|
86
|
-
}),
|
|
86
|
+
}), h(i, { retainLines: !0 }).code;
|
|
87
87
|
}
|
|
88
|
-
function
|
|
89
|
-
const
|
|
88
|
+
function J(p, c) {
|
|
89
|
+
const i = y(p, {
|
|
90
90
|
sourceType: "module",
|
|
91
91
|
plugins: ["typescript", "jsx"]
|
|
92
92
|
});
|
|
93
|
-
return
|
|
94
|
-
ExportNamedDeclaration(
|
|
95
|
-
const t =
|
|
93
|
+
return d(i, {
|
|
94
|
+
ExportNamedDeclaration(o) {
|
|
95
|
+
const t = o.node.declaration;
|
|
96
96
|
if (!e.isVariableDeclaration(t)) return;
|
|
97
|
-
const
|
|
98
|
-
if (!
|
|
99
|
-
const
|
|
100
|
-
if (!
|
|
101
|
-
const a =
|
|
102
|
-
if (!e.isArrowFunctionExpression(
|
|
103
|
-
const
|
|
104
|
-
|
|
97
|
+
const s = t.declarations[0];
|
|
98
|
+
if (!s || !e.isIdentifier(s.id)) return;
|
|
99
|
+
const l = s.id.name;
|
|
100
|
+
if (!l.startsWith("action_")) return;
|
|
101
|
+
const a = l.replace("action_", ""), r = s.init;
|
|
102
|
+
if (!e.isArrowFunctionExpression(r) || !r.async) return;
|
|
103
|
+
const u = r.params, f = M(c, a, u);
|
|
104
|
+
r.body = e.blockStatement([e.returnStatement(f)]), B(r, u);
|
|
105
105
|
}
|
|
106
|
-
}),
|
|
106
|
+
}), h(i, { retainLines: !0 }).code;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
return
|
|
108
|
+
function M(p, c, i) {
|
|
109
|
+
const n = `/_action/${p}/${c}`;
|
|
110
|
+
return i.length === 0 ? e.callExpression(
|
|
111
111
|
e.memberExpression(
|
|
112
112
|
e.callExpression(e.identifier("fetch"), [
|
|
113
|
-
e.stringLiteral(
|
|
113
|
+
e.stringLiteral(n),
|
|
114
114
|
e.objectExpression([
|
|
115
115
|
e.objectProperty(
|
|
116
116
|
e.identifier("method"),
|
|
@@ -135,7 +135,7 @@ function U(u, l, n) {
|
|
|
135
135
|
) : e.callExpression(
|
|
136
136
|
e.memberExpression(
|
|
137
137
|
e.callExpression(e.identifier("fetch"), [
|
|
138
|
-
e.stringLiteral(
|
|
138
|
+
e.stringLiteral(n),
|
|
139
139
|
e.objectExpression([
|
|
140
140
|
e.objectProperty(
|
|
141
141
|
e.identifier("method"),
|
|
@@ -175,244 +175,350 @@ function U(u, l, n) {
|
|
|
175
175
|
]
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
179
|
-
if (
|
|
180
|
-
const
|
|
181
|
-
if (e.isObjectPattern(
|
|
182
|
-
let
|
|
183
|
-
if (e.isTSTypeAnnotation(
|
|
184
|
-
const
|
|
185
|
-
e.isIdentifier(
|
|
178
|
+
function B(p, c) {
|
|
179
|
+
if (c.length === 0) return;
|
|
180
|
+
const i = c[0];
|
|
181
|
+
if (e.isObjectPattern(i)) {
|
|
182
|
+
let n = null;
|
|
183
|
+
if (e.isTSTypeAnnotation(i.typeAnnotation) && e.isTSTypeReference(i.typeAnnotation.typeAnnotation)) {
|
|
184
|
+
const s = i.typeAnnotation.typeAnnotation;
|
|
185
|
+
e.isIdentifier(s.typeName, { name: "ActionArgs" }) && s.typeParameters?.params[0] && (n = s.typeParameters.params[0]);
|
|
186
186
|
}
|
|
187
|
-
const
|
|
187
|
+
const o = e.objectProperty(
|
|
188
188
|
e.identifier("body"),
|
|
189
189
|
e.identifier("body"),
|
|
190
190
|
!1,
|
|
191
191
|
!0
|
|
192
192
|
// shorthand
|
|
193
|
-
), t = e.objectPattern([
|
|
194
|
-
|
|
193
|
+
), t = e.objectPattern([o]);
|
|
194
|
+
n && (t.typeAnnotation = e.tsTypeAnnotation(
|
|
195
195
|
e.tsTypeLiteral([
|
|
196
196
|
e.tsPropertySignature(
|
|
197
197
|
e.identifier("body"),
|
|
198
|
-
e.tsTypeAnnotation(
|
|
198
|
+
e.tsTypeAnnotation(n)
|
|
199
199
|
)
|
|
200
200
|
])
|
|
201
|
-
)),
|
|
201
|
+
)), p.params = [t];
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
function
|
|
205
|
-
const
|
|
204
|
+
function H(p, c) {
|
|
205
|
+
const i = y(p, {
|
|
206
206
|
sourceType: "module",
|
|
207
207
|
plugins: ["typescript", "jsx"]
|
|
208
208
|
});
|
|
209
|
-
return
|
|
210
|
-
ExportNamedDeclaration(
|
|
211
|
-
const t =
|
|
209
|
+
return d(i, {
|
|
210
|
+
ExportNamedDeclaration(o) {
|
|
211
|
+
const t = o.node.declaration;
|
|
212
212
|
if (!e.isVariableDeclaration(t)) return;
|
|
213
|
-
const
|
|
214
|
-
if (!
|
|
215
|
-
const
|
|
216
|
-
if (!
|
|
217
|
-
const a =
|
|
218
|
-
|
|
213
|
+
const s = t.declarations[0];
|
|
214
|
+
if (!s || !e.isIdentifier(s.id)) return;
|
|
215
|
+
const l = s.id.name;
|
|
216
|
+
if (!l.startsWith("stream_")) return;
|
|
217
|
+
const a = l.replace("stream_", ""), r = `/_event/${c}/${a}`;
|
|
218
|
+
s.init = e.objectExpression([
|
|
219
219
|
e.objectProperty(
|
|
220
220
|
e.identifier("__isVeloEventStream"),
|
|
221
221
|
e.booleanLiteral(!0)
|
|
222
222
|
),
|
|
223
223
|
e.objectProperty(
|
|
224
224
|
e.identifier("__path"),
|
|
225
|
-
e.stringLiteral(
|
|
225
|
+
e.stringLiteral(r)
|
|
226
|
+
)
|
|
227
|
+
]), s.id.typeAnnotation = null;
|
|
228
|
+
}
|
|
229
|
+
}), h(i, { retainLines: !0 }).code;
|
|
230
|
+
}
|
|
231
|
+
function z(p, c) {
|
|
232
|
+
const i = y(p, {
|
|
233
|
+
sourceType: "module",
|
|
234
|
+
plugins: ["typescript", "jsx"]
|
|
235
|
+
});
|
|
236
|
+
return d(i, {
|
|
237
|
+
ExportNamedDeclaration(o) {
|
|
238
|
+
const t = o.node.declaration;
|
|
239
|
+
if (!e.isVariableDeclaration(t)) return;
|
|
240
|
+
const s = t.declarations[0];
|
|
241
|
+
if (!s || !e.isIdentifier(s.id)) return;
|
|
242
|
+
const l = s.id.name;
|
|
243
|
+
if (!l.startsWith("socket_")) return;
|
|
244
|
+
const a = l.replace("socket_", ""), r = `/_socket/${c}/${a}`;
|
|
245
|
+
s.init = e.objectExpression([
|
|
246
|
+
e.objectProperty(
|
|
247
|
+
e.identifier("__isVeloSocket"),
|
|
248
|
+
e.booleanLiteral(!0)
|
|
249
|
+
),
|
|
250
|
+
e.objectProperty(
|
|
251
|
+
e.identifier("__path"),
|
|
252
|
+
e.stringLiteral(r)
|
|
226
253
|
)
|
|
227
|
-
]),
|
|
254
|
+
]), s.id.typeAnnotation = null;
|
|
228
255
|
}
|
|
229
|
-
}),
|
|
256
|
+
}), h(i, { retainLines: !0 }).code;
|
|
230
257
|
}
|
|
231
|
-
function
|
|
232
|
-
const
|
|
258
|
+
function Y(p) {
|
|
259
|
+
const c = y(p, {
|
|
233
260
|
sourceType: "module",
|
|
234
261
|
plugins: ["typescript", "jsx"]
|
|
235
262
|
});
|
|
236
|
-
return
|
|
237
|
-
ExportNamedDeclaration(
|
|
238
|
-
const
|
|
239
|
-
if (!e.isVariableDeclaration(
|
|
240
|
-
const t =
|
|
241
|
-
!t || !e.isIdentifier(t.id) || t.id.name === "loader" &&
|
|
263
|
+
return d(c, {
|
|
264
|
+
ExportNamedDeclaration(n) {
|
|
265
|
+
const o = n.node.declaration;
|
|
266
|
+
if (!e.isVariableDeclaration(o)) return;
|
|
267
|
+
const t = o.declarations[0];
|
|
268
|
+
!t || !e.isIdentifier(t.id) || t.id.name === "loader" && n.remove();
|
|
242
269
|
}
|
|
243
|
-
}),
|
|
270
|
+
}), h(c, { retainLines: !0 }).code;
|
|
244
271
|
}
|
|
245
|
-
function
|
|
246
|
-
const
|
|
272
|
+
function q(p) {
|
|
273
|
+
const c = y(p, {
|
|
247
274
|
sourceType: "module",
|
|
248
275
|
plugins: ["typescript", "jsx"]
|
|
249
|
-
}),
|
|
250
|
-
return
|
|
251
|
-
ObjectProperty(
|
|
252
|
-
if (e.isIdentifier(
|
|
253
|
-
for (const t of
|
|
254
|
-
e.isIdentifier(t) &&
|
|
255
|
-
|
|
276
|
+
}), i = /* @__PURE__ */ new Set();
|
|
277
|
+
return d(c, {
|
|
278
|
+
ObjectProperty(o) {
|
|
279
|
+
if (e.isIdentifier(o.node.key, { name: "middlewares" }) && e.isArrayExpression(o.node.value)) {
|
|
280
|
+
for (const t of o.node.value.elements)
|
|
281
|
+
e.isIdentifier(t) && i.add(t.name);
|
|
282
|
+
o.remove();
|
|
256
283
|
}
|
|
257
284
|
}
|
|
258
|
-
}),
|
|
259
|
-
ImportDeclaration(
|
|
260
|
-
const t =
|
|
261
|
-
if (e.isImportSpecifier(
|
|
262
|
-
const a =
|
|
263
|
-
return !
|
|
285
|
+
}), i.size === 0 ? p : (d(c, {
|
|
286
|
+
ImportDeclaration(o) {
|
|
287
|
+
const t = o.node.specifiers, s = t.filter((l) => {
|
|
288
|
+
if (e.isImportSpecifier(l)) {
|
|
289
|
+
const a = l.local.name;
|
|
290
|
+
return !i.has(a);
|
|
264
291
|
}
|
|
265
292
|
return !0;
|
|
266
293
|
});
|
|
267
|
-
|
|
294
|
+
s.length === 0 ? o.remove() : s.length !== t.length && (o.node.specifiers = s);
|
|
268
295
|
}
|
|
269
|
-
}),
|
|
296
|
+
}), h(c, { retainLines: !0 }).code);
|
|
270
297
|
}
|
|
271
|
-
function
|
|
272
|
-
const
|
|
298
|
+
function A(p, c) {
|
|
299
|
+
const i = (n) => {
|
|
300
|
+
if (!(!n || typeof n != "object")) {
|
|
301
|
+
if (Array.isArray(n)) {
|
|
302
|
+
for (const o of n) i(o);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (n.type === "Identifier") {
|
|
306
|
+
c.add(n.name);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (n.type === "MemberExpression") {
|
|
310
|
+
i(n.object), n.computed && i(n.property);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if ((n.type === "ObjectProperty" || n.type === "ObjectMethod") && !n.computed) {
|
|
314
|
+
n.type === "ObjectProperty" ? i(n.value) : i(n.body);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (!(n.type === "ImportSpecifier" || n.type === "ImportDefaultSpecifier" || n.type === "ImportNamespaceSpecifier"))
|
|
318
|
+
for (const o of Object.keys(n))
|
|
319
|
+
o === "loc" || o === "start" || o === "end" || o === "leadingComments" || o === "trailingComments" || o === "innerComments" || i(n[o]);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
i(p);
|
|
323
|
+
}
|
|
324
|
+
function G(p) {
|
|
325
|
+
for (const c of p.properties)
|
|
326
|
+
if (e.isObjectProperty(c) && e.isIdentifier(c.key) && c.key.name === "handler")
|
|
327
|
+
return !0;
|
|
328
|
+
return !1;
|
|
329
|
+
}
|
|
330
|
+
function K(p) {
|
|
331
|
+
for (const c of p.properties)
|
|
332
|
+
if (e.isObjectProperty(c) && e.isIdentifier(c.key) && c.key.name === "children" && e.isArrayExpression(c.value))
|
|
333
|
+
return c.value;
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
function Q(p) {
|
|
337
|
+
const c = y(p, {
|
|
273
338
|
sourceType: "module",
|
|
274
339
|
plugins: ["typescript", "jsx"]
|
|
275
|
-
}),
|
|
276
|
-
|
|
340
|
+
}), i = [], n = (a) => {
|
|
341
|
+
for (let r = a.elements.length - 1; r >= 0; r--) {
|
|
342
|
+
const u = a.elements[r];
|
|
343
|
+
if (!e.isObjectExpression(u)) continue;
|
|
344
|
+
if (G(u)) {
|
|
345
|
+
i.push(u), a.elements.splice(r, 1);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const f = K(u);
|
|
349
|
+
f && n(f);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
if (d(c, {
|
|
353
|
+
ExportDefaultDeclaration(a) {
|
|
354
|
+
const r = a.node.declaration;
|
|
355
|
+
let u = null;
|
|
356
|
+
e.isArrayExpression(r) ? u = r : (e.isTSSatisfiesExpression(r) && e.isArrayExpression(r.expression) || e.isTSAsExpression(r) && e.isArrayExpression(r.expression)) && (u = r.expression), u && n(u);
|
|
357
|
+
}
|
|
358
|
+
}), i.length === 0) return p;
|
|
359
|
+
const o = /* @__PURE__ */ new Set();
|
|
360
|
+
for (const a of i)
|
|
361
|
+
A(a, o);
|
|
362
|
+
const t = /* @__PURE__ */ new Set();
|
|
363
|
+
A(c.program, t);
|
|
364
|
+
const s = /* @__PURE__ */ new Set();
|
|
365
|
+
for (const a of o)
|
|
366
|
+
t.has(a) || s.add(a);
|
|
367
|
+
return s.size > 0 && d(c, {
|
|
368
|
+
ImportDeclaration(a) {
|
|
369
|
+
const r = a.node.specifiers, u = r.filter((f) => !s.has(f.local.name));
|
|
370
|
+
u.length === 0 ? a.remove() : u.length !== r.length && (a.node.specifiers = u);
|
|
371
|
+
}
|
|
372
|
+
}), h(c, { retainLines: !0 }).code;
|
|
373
|
+
}
|
|
374
|
+
function P(p) {
|
|
375
|
+
const c = y(p, {
|
|
376
|
+
sourceType: "module",
|
|
377
|
+
plugins: ["typescript", "jsx"]
|
|
378
|
+
}), i = /* @__PURE__ */ new Map();
|
|
379
|
+
d(c, {
|
|
277
380
|
ImportDeclaration(t) {
|
|
278
|
-
const
|
|
279
|
-
for (const
|
|
280
|
-
e.isImportNamespaceSpecifier(
|
|
381
|
+
const s = t.node.source.value;
|
|
382
|
+
for (const l of t.node.specifiers)
|
|
383
|
+
e.isImportNamespaceSpecifier(l) && i.set(l.local.name, s);
|
|
281
384
|
}
|
|
282
385
|
});
|
|
283
|
-
const
|
|
284
|
-
|
|
386
|
+
const n = /* @__PURE__ */ new Map();
|
|
387
|
+
d(c, {
|
|
285
388
|
ExportDefaultDeclaration(t) {
|
|
286
|
-
const
|
|
287
|
-
let
|
|
288
|
-
e.isArrayExpression(
|
|
389
|
+
const s = t.node.declaration;
|
|
390
|
+
let l = null;
|
|
391
|
+
e.isArrayExpression(s) ? l = s : e.isTSSatisfiesExpression(s) && e.isArrayExpression(s.expression) && (l = s.expression), l && C(l.elements, "", n);
|
|
289
392
|
}
|
|
290
393
|
});
|
|
291
|
-
const
|
|
292
|
-
for (const [t,
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
295
|
-
const a =
|
|
296
|
-
|
|
394
|
+
const o = /* @__PURE__ */ new Map();
|
|
395
|
+
for (const [t, s] of n) {
|
|
396
|
+
const l = i.get(t);
|
|
397
|
+
if (l) {
|
|
398
|
+
const a = l.replace(/^\.\//, "").replace(/\.(tsx?|jsx?|js)$/, "");
|
|
399
|
+
o.set(a, s);
|
|
297
400
|
}
|
|
298
401
|
}
|
|
299
|
-
return
|
|
402
|
+
return o;
|
|
300
403
|
}
|
|
301
|
-
function
|
|
302
|
-
for (const
|
|
303
|
-
if (!e.isObjectExpression(
|
|
304
|
-
let
|
|
305
|
-
for (const a of
|
|
404
|
+
function C(p, c, i) {
|
|
405
|
+
for (const n of p) {
|
|
406
|
+
if (!e.isObjectExpression(n)) continue;
|
|
407
|
+
let o = "", t = c, s = null, l = null;
|
|
408
|
+
for (const a of n.properties) {
|
|
306
409
|
if (!e.isObjectProperty(a)) continue;
|
|
307
|
-
const
|
|
308
|
-
|
|
410
|
+
const r = a.key, u = e.isIdentifier(r) ? r.name : null;
|
|
411
|
+
u === "path" && e.isStringLiteral(a.value) && (o = a.value.value, o && !o.startsWith("/") ? t = c + "/" + o : t = c + o), u === "module" && e.isIdentifier(a.value) && (s = a.value.name), u === "children" && e.isArrayExpression(a.value) && (l = a.value);
|
|
309
412
|
}
|
|
310
|
-
if (
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
fullPath:
|
|
314
|
-
path:
|
|
413
|
+
if (s) {
|
|
414
|
+
const r = !l && o === "/" ? c || "/" : t;
|
|
415
|
+
i.set(s, {
|
|
416
|
+
fullPath: r,
|
|
417
|
+
path: o
|
|
315
418
|
});
|
|
316
419
|
}
|
|
317
|
-
|
|
420
|
+
l && C(l.elements, t, i);
|
|
318
421
|
}
|
|
319
422
|
}
|
|
320
|
-
const
|
|
321
|
-
function
|
|
322
|
-
let
|
|
323
|
-
const
|
|
423
|
+
const b = "virtual:velo/server-entry", E = "virtual:velo/client-entry", N = "\0" + b, O = "\0" + E;
|
|
424
|
+
function X(p, c) {
|
|
425
|
+
let i = m.resolve(process.cwd(), c);
|
|
426
|
+
const n = p.routesFile ?? "routes.tsx", o = /* @__PURE__ */ new Map();
|
|
324
427
|
return {
|
|
325
428
|
name: "velo:transform",
|
|
326
429
|
enforce: "pre",
|
|
327
430
|
configResolved(t) {
|
|
328
|
-
|
|
431
|
+
i = m.resolve(t.root, c);
|
|
329
432
|
},
|
|
330
433
|
buildStart() {
|
|
331
|
-
const t =
|
|
332
|
-
if (
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
for (const [a,
|
|
336
|
-
|
|
434
|
+
const t = m.join(i, n);
|
|
435
|
+
if (S.existsSync(t)) {
|
|
436
|
+
const s = S.readFileSync(t, "utf-8"), l = P(s);
|
|
437
|
+
o.clear();
|
|
438
|
+
for (const [a, r] of l)
|
|
439
|
+
o.set(a, r);
|
|
337
440
|
}
|
|
338
441
|
},
|
|
339
|
-
handleHotUpdate({ file: t, server:
|
|
340
|
-
const
|
|
341
|
-
if (t ===
|
|
342
|
-
const a =
|
|
343
|
-
|
|
344
|
-
for (const [
|
|
345
|
-
|
|
346
|
-
return
|
|
442
|
+
handleHotUpdate({ file: t, server: s }) {
|
|
443
|
+
const l = m.join(i, n);
|
|
444
|
+
if (t === l) {
|
|
445
|
+
const a = S.readFileSync(l, "utf-8"), r = P(a);
|
|
446
|
+
o.clear();
|
|
447
|
+
for (const [u, f] of r)
|
|
448
|
+
o.set(u, f);
|
|
449
|
+
return s.ws.send({ type: "full-reload" }), [];
|
|
347
450
|
}
|
|
348
451
|
},
|
|
349
452
|
resolveId(t) {
|
|
350
|
-
return t ===
|
|
453
|
+
return t === b || t.endsWith(b) ? N : t === E || t.endsWith(E) || t === "/__velo_client.js" ? O : null;
|
|
351
454
|
},
|
|
352
455
|
load(t) {
|
|
353
|
-
const
|
|
456
|
+
const s = p.routesFile ?? "routes.tsx", l = p.serverInit ?? "server.tsx", a = p.clientInit ?? "client.tsx", r = m.join(i, s).replace(/\.tsx?$/, ".js"), u = m.join(i, l).replace(/\.tsx?$/, ".js"), f = m.join(i, a).replace(/\.tsx?$/, ".js");
|
|
354
457
|
return t === N ? `
|
|
355
458
|
globalThis.__veloBuildHash = __VELO_BUILD_HASH__;
|
|
356
459
|
globalThis.__veloClientJs = __VELO_CLIENT_JS__;
|
|
357
460
|
globalThis.__veloClientCss = __VELO_CLIENT_CSS__;
|
|
358
|
-
import "${
|
|
359
|
-
import routes from "${
|
|
461
|
+
import "${u}";
|
|
462
|
+
import routes from "${r}";
|
|
360
463
|
import { startServer } from "@mauroandre/velojs/server";
|
|
361
464
|
|
|
362
465
|
export { routes };
|
|
363
466
|
export default await startServer({ routes });
|
|
364
|
-
` : t ===
|
|
467
|
+
` : t === O ? `
|
|
365
468
|
import "${f}";
|
|
366
|
-
import routes from "${
|
|
469
|
+
import routes from "${r}";
|
|
367
470
|
import { startClient } from "@mauroandre/velojs/client";
|
|
368
471
|
|
|
369
472
|
startClient({ routes });
|
|
370
473
|
` : null;
|
|
371
474
|
},
|
|
372
|
-
transform(t,
|
|
373
|
-
const a =
|
|
374
|
-
if (
|
|
375
|
-
let
|
|
376
|
-
const f = /middlewares:\s*\[/.test(t),
|
|
475
|
+
transform(t, s, l) {
|
|
476
|
+
const a = l?.ssr === !0;
|
|
477
|
+
if (s.startsWith("\0") || s.includes("/.velojs/") || !s.endsWith(".tsx") && !s.endsWith(".ts") || !s.startsWith(i)) return null;
|
|
478
|
+
let r = t, u = !1;
|
|
479
|
+
const f = /middlewares:\s*\[/.test(t), x = /export\s+(const|function)\s+Component/.test(
|
|
377
480
|
t
|
|
378
|
-
),
|
|
379
|
-
if (!a && f && (
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
)), !a &&
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
)), a
|
|
481
|
+
), _ = /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), k = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t), F = /\bhandler\s*:/.test(t), V = m.join(i, n);
|
|
482
|
+
if (!a && f && (r = q(r), u = !0), !a && F && s === V && (r = Q(r), u = !0), x || _ || D || L || I || w || k) {
|
|
483
|
+
const v = m.relative(i, s).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), T = o.get(v);
|
|
484
|
+
r = U(r, v, T?.fullPath, T?.path), r = W(r, v), a || (r = J(
|
|
485
|
+
r,
|
|
486
|
+
v
|
|
487
|
+
)), !a && L && (r = H(
|
|
488
|
+
r,
|
|
489
|
+
v
|
|
490
|
+
)), !a && I && (r = z(
|
|
491
|
+
r,
|
|
492
|
+
v
|
|
493
|
+
)), a || (r = Y(r)), u = !0;
|
|
388
494
|
}
|
|
389
|
-
return
|
|
390
|
-
code:
|
|
495
|
+
return u ? {
|
|
496
|
+
code: r,
|
|
391
497
|
map: null
|
|
392
498
|
} : null;
|
|
393
499
|
}
|
|
394
500
|
};
|
|
395
501
|
}
|
|
396
|
-
function
|
|
502
|
+
function Z() {
|
|
397
503
|
return {
|
|
398
504
|
name: "velo:config",
|
|
399
|
-
config(
|
|
400
|
-
const
|
|
401
|
-
let t = "client.js",
|
|
402
|
-
if (
|
|
505
|
+
config(p, { mode: c }) {
|
|
506
|
+
const i = c === "server", n = c === "development", o = !!process.env.VELO_STATIC;
|
|
507
|
+
let t = "client.js", s = "client.css";
|
|
508
|
+
if (i)
|
|
403
509
|
try {
|
|
404
|
-
const a =
|
|
405
|
-
|
|
510
|
+
const a = m.resolve(process.cwd(), "dist/client/.vite/manifest.json"), u = JSON.parse(S.readFileSync(a, "utf-8"))[E];
|
|
511
|
+
u && (t = u.file || t, u.css?.[0] && (s = u.css[0]));
|
|
406
512
|
} catch {
|
|
407
513
|
}
|
|
408
|
-
const
|
|
514
|
+
const l = {
|
|
409
515
|
define: {
|
|
410
|
-
"process.env.NODE_ENV": JSON.stringify(
|
|
411
|
-
"process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (
|
|
412
|
-
__VELO_STATIC__: JSON.stringify(
|
|
516
|
+
"process.env.NODE_ENV": JSON.stringify(n ? "development" : "production"),
|
|
517
|
+
"process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (o ? "/client" : "")),
|
|
518
|
+
__VELO_STATIC__: JSON.stringify(o),
|
|
413
519
|
__VELO_BUILD_HASH__: JSON.stringify(process.env.VELO_BUILD_HASH || Date.now().toString(36)),
|
|
414
520
|
__VELO_CLIENT_JS__: JSON.stringify(t),
|
|
415
|
-
__VELO_CLIENT_CSS__: JSON.stringify(
|
|
521
|
+
__VELO_CLIENT_CSS__: JSON.stringify(s)
|
|
416
522
|
},
|
|
417
523
|
resolve: {
|
|
418
524
|
alias: {
|
|
@@ -421,8 +527,8 @@ function H() {
|
|
|
421
527
|
}
|
|
422
528
|
}
|
|
423
529
|
};
|
|
424
|
-
return
|
|
425
|
-
ssr:
|
|
530
|
+
return i ? l.build = {
|
|
531
|
+
ssr: b,
|
|
426
532
|
outDir: "dist",
|
|
427
533
|
emptyOutDir: !1,
|
|
428
534
|
copyPublicDir: !1,
|
|
@@ -431,65 +537,67 @@ function H() {
|
|
|
431
537
|
entryFileNames: "server.js"
|
|
432
538
|
}
|
|
433
539
|
}
|
|
434
|
-
} :
|
|
540
|
+
} : n || (l.build = {
|
|
435
541
|
manifest: !0,
|
|
436
542
|
outDir: "dist/client",
|
|
437
543
|
rollupOptions: {
|
|
438
|
-
input:
|
|
544
|
+
input: E,
|
|
439
545
|
output: {
|
|
440
546
|
entryFileNames: "client.[hash].js",
|
|
441
547
|
assetFileNames: (a) => a.names?.[0]?.endsWith(".css") ? "client.[hash].css" : "[name].[hash][extname]"
|
|
442
548
|
}
|
|
443
549
|
}
|
|
444
|
-
}),
|
|
550
|
+
}), l;
|
|
445
551
|
}
|
|
446
552
|
};
|
|
447
553
|
}
|
|
448
|
-
function
|
|
554
|
+
function ee() {
|
|
449
555
|
return {
|
|
450
556
|
name: "velo:static-url",
|
|
451
557
|
apply: "build",
|
|
452
558
|
enforce: "post",
|
|
453
|
-
generateBundle(
|
|
454
|
-
const
|
|
455
|
-
if (
|
|
456
|
-
for (const
|
|
457
|
-
|
|
559
|
+
generateBundle(p, c) {
|
|
560
|
+
const i = process.env.STATIC_BASE_URL || "";
|
|
561
|
+
if (i)
|
|
562
|
+
for (const n of Object.values(c))
|
|
563
|
+
n.type === "asset" && typeof n.source == "string" && n.fileName.endsWith(".css") && (n.source = n.source.replace(
|
|
458
564
|
/url\(\s*(['"]?)\/(?!\/)/g,
|
|
459
|
-
`url($1${
|
|
565
|
+
`url($1${i}/`
|
|
460
566
|
));
|
|
461
567
|
}
|
|
462
568
|
};
|
|
463
569
|
}
|
|
464
|
-
function
|
|
465
|
-
const
|
|
570
|
+
function le(p) {
|
|
571
|
+
const c = p ?? {}, i = c.appDirectory ?? "./app";
|
|
466
572
|
return [
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
entry:
|
|
573
|
+
Z(),
|
|
574
|
+
X(c, i),
|
|
575
|
+
ee(),
|
|
576
|
+
R(),
|
|
577
|
+
$({
|
|
578
|
+
entry: b
|
|
473
579
|
}),
|
|
474
|
-
|
|
580
|
+
te()
|
|
475
581
|
];
|
|
476
582
|
}
|
|
477
|
-
function
|
|
583
|
+
function te() {
|
|
478
584
|
return {
|
|
479
585
|
name: "velo:ws-bridge",
|
|
480
|
-
configureServer(
|
|
481
|
-
globalThis.__veloDevServer =
|
|
586
|
+
configureServer(p) {
|
|
587
|
+
globalThis.__veloDevServer = p.httpServer;
|
|
482
588
|
}
|
|
483
589
|
};
|
|
484
590
|
}
|
|
485
591
|
export {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
592
|
+
P as buildFullPathMap,
|
|
593
|
+
C as collectFullPaths,
|
|
594
|
+
U as injectMetadata,
|
|
595
|
+
Q as removeEndpointRoutes,
|
|
596
|
+
Y as removeLoaders,
|
|
597
|
+
q as removeMiddlewares,
|
|
598
|
+
J as transformActionsForClient,
|
|
599
|
+
W as transformLoaderFunctions,
|
|
600
|
+
z as transformSocketsForClient,
|
|
601
|
+
H as transformStreamsForClient,
|
|
602
|
+
le as veloPlugin
|
|
495
603
|
};
|