@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/dist/vite.js CHANGED
@@ -1,116 +1,116 @@
1
- import d from "node:path";
2
- import L from "node:fs";
3
- import F from "@preact/preset-vite";
4
- import w from "@hono/vite-dev-server";
5
- import { parse as _ } from "@babel/parser";
6
- import E from "@babel/traverse";
7
- import b from "@babel/generator";
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 m = typeof E == "function" ? E : E.default, v = typeof b == "function" ? b : b.default;
10
- function V(u, l, n, c) {
11
- const i = _(u, {
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 (m(i, {
16
+ if (d(o, {
17
17
  // Procura: export const metadata = { ... }
18
- ExportNamedDeclaration(s) {
19
- const a = s.node.declaration;
18
+ ExportNamedDeclaration(l) {
19
+ const a = l.node.declaration;
20
20
  if (e.isVariableDeclaration(a) && a.declarations.length === 1) {
21
- const o = a.declarations[0];
22
- if (o && e.isIdentifier(o.id, { name: "metadata" }) && e.isObjectExpression(o.init)) {
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 = o.init.properties.filter((y) => e.isObjectProperty(y) && e.isIdentifier(y.key) ? y.key.name !== "moduleId" && y.key.name !== "fullPath" && y.key.name !== "path" : !0), h = [
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(l)
27
+ e.stringLiteral(c)
28
28
  )
29
29
  ];
30
- n !== void 0 && h.push(
30
+ i !== void 0 && x.push(
31
31
  e.objectProperty(
32
32
  e.identifier("fullPath"),
33
- e.stringLiteral(n)
33
+ e.stringLiteral(i)
34
34
  )
35
- ), c !== void 0 && h.push(
35
+ ), n !== void 0 && x.push(
36
36
  e.objectProperty(
37
37
  e.identifier("path"),
38
- e.stringLiteral(c)
38
+ e.stringLiteral(n)
39
39
  )
40
- ), o.init.properties = [...h, ...f];
40
+ ), r.init.properties = [...x, ...f];
41
41
  }
42
42
  }
43
43
  }
44
44
  }), !t) {
45
- const s = [
45
+ const l = [
46
46
  e.objectProperty(
47
47
  e.identifier("moduleId"),
48
- e.stringLiteral(l)
48
+ e.stringLiteral(c)
49
49
  )
50
50
  ];
51
- n !== void 0 && s.push(
51
+ i !== void 0 && l.push(
52
52
  e.objectProperty(
53
53
  e.identifier("fullPath"),
54
- e.stringLiteral(n)
54
+ e.stringLiteral(i)
55
55
  )
56
- ), c !== void 0 && s.push(
56
+ ), n !== void 0 && l.push(
57
57
  e.objectProperty(
58
58
  e.identifier("path"),
59
- e.stringLiteral(c)
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(s)
66
+ e.objectExpression(l)
67
67
  )
68
68
  ])
69
69
  );
70
- i.program.body.unshift(a);
70
+ o.program.body.unshift(a);
71
71
  }
72
- return v(i, { retainLines: !0 }).code;
72
+ return h(o, { retainLines: !0 }).code;
73
73
  }
74
- function R(u, l) {
75
- const n = _(u, {
74
+ function W(p, c) {
75
+ const i = y(p, {
76
76
  sourceType: "module",
77
77
  plugins: ["typescript", "jsx"]
78
78
  });
79
- return m(n, {
80
- CallExpression(i) {
81
- const t = i.node.callee, r = e.isIdentifier(t, { name: "Loader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "Loader" }), s = e.isIdentifier(t, { name: "useLoader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "useLoader" });
82
- if (!r && !s) return;
83
- const a = i.node.arguments, o = e.stringLiteral(l), p = a[0];
84
- e.isStringLiteral(p) && p.value.includes("/") || (i.node.arguments = [o, ...a]);
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
- }), v(n, { retainLines: !0 }).code;
86
+ }), h(i, { retainLines: !0 }).code;
87
87
  }
88
- function $(u, l) {
89
- const n = _(u, {
88
+ function J(p, c) {
89
+ const i = y(p, {
90
90
  sourceType: "module",
91
91
  plugins: ["typescript", "jsx"]
92
92
  });
93
- return m(n, {
94
- ExportNamedDeclaration(i) {
95
- const t = i.node.declaration;
93
+ return d(i, {
94
+ ExportNamedDeclaration(o) {
95
+ const t = o.node.declaration;
96
96
  if (!e.isVariableDeclaration(t)) return;
97
- const r = t.declarations[0];
98
- if (!r || !e.isIdentifier(r.id)) return;
99
- const s = r.id.name;
100
- if (!s.startsWith("action_")) return;
101
- const a = s.replace("action_", ""), o = r.init;
102
- if (!e.isArrowFunctionExpression(o) || !o.async) return;
103
- const p = o.params, f = U(l, a, p);
104
- o.body = e.blockStatement([e.returnStatement(f)]), W(o, p);
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
- }), v(n, { retainLines: !0 }).code;
106
+ }), h(i, { retainLines: !0 }).code;
107
107
  }
108
- function U(u, l, n) {
109
- const c = `/_action/${u}/${l}`;
110
- return n.length === 0 ? e.callExpression(
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(c),
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(c),
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 W(u, l) {
179
- if (l.length === 0) return;
180
- const n = l[0];
181
- if (e.isObjectPattern(n)) {
182
- let c = null;
183
- if (e.isTSTypeAnnotation(n.typeAnnotation) && e.isTSTypeReference(n.typeAnnotation.typeAnnotation)) {
184
- const r = n.typeAnnotation.typeAnnotation;
185
- e.isIdentifier(r.typeName, { name: "ActionArgs" }) && r.typeParameters?.params[0] && (c = r.typeParameters.params[0]);
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 i = e.objectProperty(
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([i]);
194
- c && (t.typeAnnotation = e.tsTypeAnnotation(
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(c)
198
+ e.tsTypeAnnotation(n)
199
199
  )
200
200
  ])
201
- )), u.params = [t];
201
+ )), p.params = [t];
202
202
  }
203
203
  }
204
- function J(u, l) {
205
- const n = _(u, {
204
+ function H(p, c) {
205
+ const i = y(p, {
206
206
  sourceType: "module",
207
207
  plugins: ["typescript", "jsx"]
208
208
  });
209
- return m(n, {
210
- ExportNamedDeclaration(i) {
211
- const t = i.node.declaration;
209
+ return d(i, {
210
+ ExportNamedDeclaration(o) {
211
+ const t = o.node.declaration;
212
212
  if (!e.isVariableDeclaration(t)) return;
213
- const r = t.declarations[0];
214
- if (!r || !e.isIdentifier(r.id)) return;
215
- const s = r.id.name;
216
- if (!s.startsWith("stream_")) return;
217
- const a = s.replace("stream_", ""), o = `/_event/${l}/${a}`;
218
- r.init = e.objectExpression([
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(o)
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
- ]), r.id.typeAnnotation = null;
254
+ ]), s.id.typeAnnotation = null;
228
255
  }
229
- }), v(n, { retainLines: !0 }).code;
256
+ }), h(i, { retainLines: !0 }).code;
230
257
  }
231
- function k(u) {
232
- const l = _(u, {
258
+ function Y(p) {
259
+ const c = y(p, {
233
260
  sourceType: "module",
234
261
  plugins: ["typescript", "jsx"]
235
262
  });
236
- return m(l, {
237
- ExportNamedDeclaration(c) {
238
- const i = c.node.declaration;
239
- if (!e.isVariableDeclaration(i)) return;
240
- const t = i.declarations[0];
241
- !t || !e.isIdentifier(t.id) || t.id.name === "loader" && c.remove();
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
- }), v(l, { retainLines: !0 }).code;
270
+ }), h(c, { retainLines: !0 }).code;
244
271
  }
245
- function B(u) {
246
- const l = _(u, {
272
+ function q(p) {
273
+ const c = y(p, {
247
274
  sourceType: "module",
248
275
  plugins: ["typescript", "jsx"]
249
- }), n = /* @__PURE__ */ new Set();
250
- return m(l, {
251
- ObjectProperty(i) {
252
- if (e.isIdentifier(i.node.key, { name: "middlewares" }) && e.isArrayExpression(i.node.value)) {
253
- for (const t of i.node.value.elements)
254
- e.isIdentifier(t) && n.add(t.name);
255
- i.remove();
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
- }), n.size === 0 ? u : (m(l, {
259
- ImportDeclaration(i) {
260
- const t = i.node.specifiers, r = t.filter((s) => {
261
- if (e.isImportSpecifier(s)) {
262
- const a = s.local.name;
263
- return !n.has(a);
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
- r.length === 0 ? i.remove() : r.length !== t.length && (i.node.specifiers = r);
294
+ s.length === 0 ? o.remove() : s.length !== t.length && (o.node.specifiers = s);
268
295
  }
269
- }), v(l, { retainLines: !0 }).code);
296
+ }), h(c, { retainLines: !0 }).code);
270
297
  }
271
- function T(u) {
272
- const l = _(u, {
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
- }), n = /* @__PURE__ */ new Map();
276
- m(l, {
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 r = t.node.source.value;
279
- for (const s of t.node.specifiers)
280
- e.isImportNamespaceSpecifier(s) && n.set(s.local.name, r);
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 c = /* @__PURE__ */ new Map();
284
- m(l, {
386
+ const n = /* @__PURE__ */ new Map();
387
+ d(c, {
285
388
  ExportDefaultDeclaration(t) {
286
- const r = t.node.declaration;
287
- let s = null;
288
- e.isArrayExpression(r) ? s = r : e.isTSSatisfiesExpression(r) && e.isArrayExpression(r.expression) && (s = r.expression), s && A(s.elements, "", c);
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 i = /* @__PURE__ */ new Map();
292
- for (const [t, r] of c) {
293
- const s = n.get(t);
294
- if (s) {
295
- const a = s.replace(/^\.\//, "").replace(/\.(tsx?|jsx?|js)$/, "");
296
- i.set(a, r);
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 i;
402
+ return o;
300
403
  }
301
- function A(u, l, n) {
302
- for (const c of u) {
303
- if (!e.isObjectExpression(c)) continue;
304
- let i = "", t = l, r = null, s = null;
305
- for (const a of c.properties) {
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 o = a.key, p = e.isIdentifier(o) ? o.name : null;
308
- p === "path" && e.isStringLiteral(a.value) && (i = a.value.value, i && !i.startsWith("/") ? t = l + "/" + i : t = l + i), p === "module" && e.isIdentifier(a.value) && (r = a.value.name), p === "children" && e.isArrayExpression(a.value) && (s = a.value);
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 (r) {
311
- const o = !s && i === "/" ? l || "/" : t;
312
- n.set(r, {
313
- fullPath: o,
314
- path: i
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
- s && A(s.elements, t, n);
420
+ l && C(l.elements, t, i);
318
421
  }
319
422
  }
320
- const x = "virtual:velo/server-entry", S = "virtual:velo/client-entry", N = "\0" + x, P = "\0" + S;
321
- function M(u, l) {
322
- let n = d.resolve(process.cwd(), l);
323
- const c = u.routesFile ?? "routes.tsx", i = /* @__PURE__ */ new Map();
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
- n = d.resolve(t.root, l);
431
+ i = m.resolve(t.root, c);
329
432
  },
330
433
  buildStart() {
331
- const t = d.join(n, c);
332
- if (L.existsSync(t)) {
333
- const r = L.readFileSync(t, "utf-8"), s = T(r);
334
- i.clear();
335
- for (const [a, o] of s)
336
- i.set(a, o);
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: r }) {
340
- const s = d.join(n, c);
341
- if (t === s) {
342
- const a = L.readFileSync(s, "utf-8"), o = T(a);
343
- i.clear();
344
- for (const [p, f] of o)
345
- i.set(p, f);
346
- return r.ws.send({ type: "full-reload" }), [];
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 === x || t.endsWith(x) ? N : t === S || t.endsWith(S) || t === "/__velo_client.js" ? P : null;
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 r = u.routesFile ?? "routes.tsx", s = u.serverInit ?? "server.tsx", a = u.clientInit ?? "client.tsx", o = d.join(n, r).replace(/\.tsx?$/, ".js"), p = d.join(n, s).replace(/\.tsx?$/, ".js"), f = d.join(n, a).replace(/\.tsx?$/, ".js");
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 "${p}";
359
- import routes from "${o}";
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 === P ? `
467
+ ` : t === O ? `
365
468
  import "${f}";
366
- import routes from "${o}";
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, r, s) {
373
- const a = s?.ssr === !0;
374
- if (r.startsWith("\0") || r.includes("/.velojs/") || !r.endsWith(".tsx") && !r.endsWith(".ts") || !r.startsWith(n)) return null;
375
- let o = t, p = !1;
376
- const f = /middlewares:\s*\[/.test(t), h = /export\s+(const|function)\s+Component/.test(
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
- ), y = /export\s+(const|function)\s+loader/.test(t), C = /export\s+const\s+action_\w+/.test(t), j = /export\s+const\s+stream_\w+/.test(t), O = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), D = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t);
379
- if (!a && f && (o = B(o), p = !0), h || y || C || j || O || D) {
380
- const g = d.relative(n, r).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), I = i.get(g);
381
- o = V(o, g, I?.fullPath, I?.path), o = R(o, g), a || (o = $(
382
- o,
383
- g
384
- )), !a && j && (o = J(
385
- o,
386
- g
387
- )), a || (o = k(o)), p = !0;
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 p ? {
390
- code: o,
495
+ return u ? {
496
+ code: r,
391
497
  map: null
392
498
  } : null;
393
499
  }
394
500
  };
395
501
  }
396
- function H() {
502
+ function Z() {
397
503
  return {
398
504
  name: "velo:config",
399
- config(u, { mode: l }) {
400
- const n = l === "server", c = l === "development", i = !!process.env.VELO_STATIC;
401
- let t = "client.js", r = "client.css";
402
- if (n)
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 = d.resolve(process.cwd(), "dist/client/.vite/manifest.json"), p = JSON.parse(L.readFileSync(a, "utf-8"))[S];
405
- p && (t = p.file || t, p.css?.[0] && (r = p.css[0]));
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 s = {
514
+ const l = {
409
515
  define: {
410
- "process.env.NODE_ENV": JSON.stringify(c ? "development" : "production"),
411
- "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (i ? "/client" : "")),
412
- __VELO_STATIC__: JSON.stringify(i),
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(r)
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 n ? s.build = {
425
- ssr: x,
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
- } : c || (s.build = {
540
+ } : n || (l.build = {
435
541
  manifest: !0,
436
542
  outDir: "dist/client",
437
543
  rollupOptions: {
438
- input: S,
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
- }), s;
550
+ }), l;
445
551
  }
446
552
  };
447
553
  }
448
- function Y() {
554
+ function ee() {
449
555
  return {
450
556
  name: "velo:static-url",
451
557
  apply: "build",
452
558
  enforce: "post",
453
- generateBundle(u, l) {
454
- const n = process.env.STATIC_BASE_URL || "";
455
- if (n)
456
- for (const c of Object.values(l))
457
- c.type === "asset" && typeof c.source == "string" && c.fileName.endsWith(".css") && (c.source = c.source.replace(
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${n}/`
565
+ `url($1${i}/`
460
566
  ));
461
567
  }
462
568
  };
463
569
  }
464
- function te(u) {
465
- const l = u ?? {}, n = l.appDirectory ?? "./app";
570
+ function le(p) {
571
+ const c = p ?? {}, i = c.appDirectory ?? "./app";
466
572
  return [
467
- H(),
468
- M(l, n),
469
- Y(),
470
- F(),
471
- w({
472
- entry: x
573
+ Z(),
574
+ X(c, i),
575
+ ee(),
576
+ R(),
577
+ $({
578
+ entry: b
473
579
  }),
474
- z()
580
+ te()
475
581
  ];
476
582
  }
477
- function z() {
583
+ function te() {
478
584
  return {
479
585
  name: "velo:ws-bridge",
480
- configureServer(u) {
481
- globalThis.__veloDevServer = u.httpServer;
586
+ configureServer(p) {
587
+ globalThis.__veloDevServer = p.httpServer;
482
588
  }
483
589
  };
484
590
  }
485
591
  export {
486
- T as buildFullPathMap,
487
- A as collectFullPaths,
488
- V as injectMetadata,
489
- k as removeLoaders,
490
- B as removeMiddlewares,
491
- $ as transformActionsForClient,
492
- R as transformLoaderFunctions,
493
- J as transformStreamsForClient,
494
- te as veloPlugin
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
  };