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