@mauroandre/velojs 0.0.59 → 0.0.61

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,115 +1,128 @@
1
- import { loadEnv as G } from "vite";
1
+ import b from "node:fs";
2
2
  import m from "node:path";
3
- import x from "node:fs";
4
- import z from "@preact/preset-vite";
5
- import Y, { defaultOptions as X } from "@hono/vite-dev-server";
6
- import { parse as v } from "@babel/parser";
7
- import P from "@babel/traverse";
8
- import D from "@babel/generator";
3
+ import { builtinModules as se } from "node:module";
4
+ import { parse as O } from "@babel/parser";
5
+ import N from "@babel/traverse";
9
6
  import * as e from "@babel/types";
10
- import { buildGraph as q } from "./graph.js";
11
- const h = typeof P == "function" ? P : P.default, g = typeof D == "function" ? D : D.default;
12
- function K(p, n, r, s) {
13
- const c = v(p, {
7
+ import { loadEnv as ie } from "vite";
8
+ import oe from "@preact/preset-vite";
9
+ import ae, { defaultOptions as ce } from "@hono/vite-dev-server";
10
+ import R from "@babel/generator";
11
+ import { buildGraph as le } from "./graph.js";
12
+ const w = typeof N == "function" ? N : N.default, A = typeof R == "function" ? R : R.default;
13
+ function ue(r, n, t, s) {
14
+ const o = O(r, {
14
15
  sourceType: "module",
15
16
  plugins: ["typescript", "jsx"]
16
17
  });
17
- let a = !1;
18
- if (h(c, {
18
+ let c = !1;
19
+ if (w(o, {
19
20
  // Procura: export const metadata = { ... }
20
- ExportNamedDeclaration(i) {
21
- const t = i.node.declaration;
22
- if (e.isVariableDeclaration(t) && t.declarations.length === 1) {
23
- const l = t.declarations[0];
21
+ ExportNamedDeclaration(a) {
22
+ const u = a.node.declaration;
23
+ if (e.isVariableDeclaration(u) && u.declarations.length === 1) {
24
+ const l = u.declarations[0];
24
25
  if (l && e.isIdentifier(l.id, { name: "metadata" }) && e.isObjectExpression(l.init)) {
25
- a = !0;
26
- const d = l.init.properties.filter((y) => e.isObjectProperty(y) && e.isIdentifier(y.key) ? y.key.name !== "moduleId" && y.key.name !== "fullPath" && y.key.name !== "path" : !0), f = [
26
+ c = !0;
27
+ const d = l.init.properties.filter((h) => e.isObjectProperty(h) && e.isIdentifier(h.key) ? h.key.name !== "moduleId" && h.key.name !== "fullPath" && h.key.name !== "path" : !0), y = [
27
28
  e.objectProperty(
28
29
  e.identifier("moduleId"),
29
30
  e.stringLiteral(n)
30
31
  )
31
32
  ];
32
- r !== void 0 && f.push(
33
+ t !== void 0 && y.push(
33
34
  e.objectProperty(
34
35
  e.identifier("fullPath"),
35
- e.stringLiteral(r)
36
+ e.stringLiteral(t)
36
37
  )
37
- ), s !== void 0 && f.push(
38
+ ), s !== void 0 && y.push(
38
39
  e.objectProperty(
39
40
  e.identifier("path"),
40
41
  e.stringLiteral(s)
41
42
  )
42
- ), l.init.properties = [...f, ...d];
43
+ ), l.init.properties = [...y, ...d];
43
44
  }
44
45
  }
45
46
  }
46
- }), !a) {
47
- const i = [
47
+ }), !c) {
48
+ const a = [
48
49
  e.objectProperty(
49
50
  e.identifier("moduleId"),
50
51
  e.stringLiteral(n)
51
52
  )
52
53
  ];
53
- r !== void 0 && i.push(
54
+ t !== void 0 && a.push(
54
55
  e.objectProperty(
55
56
  e.identifier("fullPath"),
56
- e.stringLiteral(r)
57
+ e.stringLiteral(t)
57
58
  )
58
- ), s !== void 0 && i.push(
59
+ ), s !== void 0 && a.push(
59
60
  e.objectProperty(
60
61
  e.identifier("path"),
61
62
  e.stringLiteral(s)
62
63
  )
63
64
  );
64
- const t = e.exportNamedDeclaration(
65
+ const u = e.exportNamedDeclaration(
65
66
  e.variableDeclaration("const", [
66
67
  e.variableDeclarator(
67
68
  e.identifier("metadata"),
68
- e.objectExpression(i)
69
+ e.objectExpression(a)
69
70
  )
70
71
  ])
71
72
  );
72
- c.program.body.unshift(t);
73
+ o.program.body.unshift(u);
73
74
  }
74
- return g(c, { retainLines: !0 }).code;
75
+ return A(o, { retainLines: !0 }).code;
75
76
  }
76
- function Q(p, n) {
77
- const r = v(p, {
77
+ function pe(r, n) {
78
+ const t = O(r, {
78
79
  sourceType: "module",
79
80
  plugins: ["typescript", "jsx"]
80
81
  });
81
- return h(r, {
82
- CallExpression(c) {
83
- const a = c.node.callee, o = e.isIdentifier(a, { name: "Loader" }) || e.isTSInstantiationExpression(a) && e.isIdentifier(a.expression, { name: "Loader" }), i = e.isIdentifier(a, { name: "useLoader" }) || e.isTSInstantiationExpression(a) && e.isIdentifier(a.expression, { name: "useLoader" });
84
- if (!o && !i) return;
85
- const t = c.node.arguments, l = e.stringLiteral(n), u = t[0];
86
- e.isStringLiteral(u) && u.value.includes("/") || (c.node.arguments = [l, ...t]);
82
+ return w(t, {
83
+ CallExpression(o) {
84
+ const c = o.node.callee, i = e.isIdentifier(c, { name: "Loader" }) || e.isTSInstantiationExpression(c) && e.isIdentifier(c.expression, { name: "Loader" }), a = e.isIdentifier(c, { name: "useLoader" }) || e.isTSInstantiationExpression(c) && e.isIdentifier(c.expression, { name: "useLoader" });
85
+ if (!i && !a) return;
86
+ const u = o.node.arguments, l = e.stringLiteral(n), p = u[0];
87
+ e.isStringLiteral(p) && p.value.includes("/") || (o.node.arguments = [l, ...u]);
87
88
  }
88
- }), g(r, { retainLines: !0 }).code;
89
+ }), A(t, { retainLines: !0 }).code;
89
90
  }
90
- function Z(p, n) {
91
- const r = v(p, {
91
+ function fe(r, n, t) {
92
+ const s = O(r, {
92
93
  sourceType: "module",
93
94
  plugins: ["typescript", "jsx"]
94
95
  });
95
- return h(r, {
96
+ return w(s, {
96
97
  ExportNamedDeclaration(c) {
97
- const a = c.node.declaration;
98
- if (!e.isVariableDeclaration(a)) return;
99
- const o = a.declarations[0];
100
- if (!o || !e.isIdentifier(o.id)) return;
101
- const i = o.id.name;
102
- if (!i.startsWith("action_")) return;
103
- const t = i.replace("action_", ""), l = o.init;
104
- if (!e.isArrowFunctionExpression(l) || !l.async) return;
105
- const u = l.params, d = ee(n, t, u);
106
- l.body = e.blockStatement([e.returnStatement(d)]), te(l, u);
107
- }
108
- }), g(r, { retainLines: !0 }).code;
109
- }
110
- function ee(p, n, r) {
111
- const s = `/_action/${p}/${n}`;
112
- return r.length === 0 ? e.callExpression(
98
+ const i = c.node.declaration;
99
+ if (!e.isVariableDeclaration(i)) return;
100
+ const a = i.declarations[0];
101
+ if (!a || !e.isIdentifier(a.id)) return;
102
+ const u = a.id.name;
103
+ if (!u.startsWith("action_")) return;
104
+ const l = u.replace("action_", ""), p = a.init;
105
+ if (!e.isArrowFunctionExpression(p) || !p.async) return;
106
+ const d = p.params, y = de(n, l, d);
107
+ p.body = e.blockStatement([e.returnStatement(y)]), me(p, d), t?.has(l) && (a.init = e.callExpression(e.identifier("Object.assign"), [
108
+ p,
109
+ e.objectExpression([
110
+ e.objectProperty(
111
+ e.identifier("__isVeloLiveAction"),
112
+ e.booleanLiteral(!0)
113
+ ),
114
+ e.objectProperty(
115
+ e.identifier("__path"),
116
+ e.stringLiteral(`/_live/${n}/${l}`)
117
+ )
118
+ ])
119
+ ]), a.id.typeAnnotation = null);
120
+ }
121
+ }), A(s, { retainLines: !0 }).code;
122
+ }
123
+ function de(r, n, t) {
124
+ const s = `/_action/${r}/${n}`;
125
+ return t.length === 0 ? e.callExpression(
113
126
  e.memberExpression(
114
127
  e.callExpression(e.identifier("fetch"), [
115
128
  e.stringLiteral(s),
@@ -177,47 +190,47 @@ function ee(p, n, r) {
177
190
  ]
178
191
  );
179
192
  }
180
- function te(p, n) {
193
+ function me(r, n) {
181
194
  if (n.length === 0) return;
182
- const r = n[0];
183
- if (e.isObjectPattern(r)) {
195
+ const t = n[0];
196
+ if (e.isObjectPattern(t)) {
184
197
  let s = null;
185
- if (e.isTSTypeAnnotation(r.typeAnnotation) && e.isTSTypeReference(r.typeAnnotation.typeAnnotation)) {
186
- const o = r.typeAnnotation.typeAnnotation;
187
- e.isIdentifier(o.typeName, { name: "ActionArgs" }) && o.typeParameters?.params[0] && (s = o.typeParameters.params[0]);
198
+ if (e.isTSTypeAnnotation(t.typeAnnotation) && e.isTSTypeReference(t.typeAnnotation.typeAnnotation)) {
199
+ const i = t.typeAnnotation.typeAnnotation;
200
+ e.isIdentifier(i.typeName, { name: "ActionArgs" }) && i.typeParameters?.params[0] && (s = i.typeParameters.params[0]);
188
201
  }
189
- const c = e.objectProperty(
202
+ const o = e.objectProperty(
190
203
  e.identifier("body"),
191
204
  e.identifier("body"),
192
205
  !1,
193
206
  !0
194
207
  // shorthand
195
- ), a = e.objectPattern([c]);
196
- s && (a.typeAnnotation = e.tsTypeAnnotation(
208
+ ), c = e.objectPattern([o]);
209
+ s && (c.typeAnnotation = e.tsTypeAnnotation(
197
210
  e.tsTypeLiteral([
198
211
  e.tsPropertySignature(
199
212
  e.identifier("body"),
200
213
  e.tsTypeAnnotation(s)
201
214
  )
202
215
  ])
203
- )), p.params = [a];
216
+ )), r.params = [c];
204
217
  }
205
218
  }
206
- function re(p, n) {
207
- const r = v(p, {
219
+ function he(r, n) {
220
+ const t = O(r, {
208
221
  sourceType: "module",
209
222
  plugins: ["typescript", "jsx"]
210
223
  });
211
- return h(r, {
212
- ExportNamedDeclaration(c) {
213
- const a = c.node.declaration;
214
- if (!e.isVariableDeclaration(a)) return;
215
- const o = a.declarations[0];
216
- if (!o || !e.isIdentifier(o.id)) return;
217
- const i = o.id.name;
218
- if (!i.startsWith("stream_")) return;
219
- const t = i.replace("stream_", ""), l = `/_event/${n}/${t}`;
220
- o.init = e.objectExpression([
224
+ return w(t, {
225
+ ExportNamedDeclaration(o) {
226
+ const c = o.node.declaration;
227
+ if (!e.isVariableDeclaration(c)) return;
228
+ const i = c.declarations[0];
229
+ if (!i || !e.isIdentifier(i.id)) return;
230
+ const a = i.id.name;
231
+ if (!a.startsWith("stream_")) return;
232
+ const u = a.replace("stream_", ""), l = `/_event/${n}/${u}`;
233
+ i.init = e.objectExpression([
221
234
  e.objectProperty(
222
235
  e.identifier("__isVeloEventStream"),
223
236
  e.booleanLiteral(!0)
@@ -226,25 +239,25 @@ function re(p, n) {
226
239
  e.identifier("__path"),
227
240
  e.stringLiteral(l)
228
241
  )
229
- ]), o.id.typeAnnotation = null;
242
+ ]), i.id.typeAnnotation = null;
230
243
  }
231
- }), g(r, { retainLines: !0 }).code;
244
+ }), A(t, { retainLines: !0 }).code;
232
245
  }
233
- function ne(p, n) {
234
- const r = v(p, {
246
+ function ye(r, n) {
247
+ const t = O(r, {
235
248
  sourceType: "module",
236
249
  plugins: ["typescript", "jsx"]
237
250
  });
238
- return h(r, {
239
- ExportNamedDeclaration(c) {
240
- const a = c.node.declaration;
241
- if (!e.isVariableDeclaration(a)) return;
242
- const o = a.declarations[0];
243
- if (!o || !e.isIdentifier(o.id)) return;
244
- const i = o.id.name;
245
- if (!i.startsWith("socket_")) return;
246
- const t = i.replace("socket_", ""), l = `/_socket/${n}/${t}`;
247
- o.init = e.objectExpression([
251
+ return w(t, {
252
+ ExportNamedDeclaration(o) {
253
+ const c = o.node.declaration;
254
+ if (!e.isVariableDeclaration(c)) return;
255
+ const i = c.declarations[0];
256
+ if (!i || !e.isIdentifier(i.id)) return;
257
+ const a = i.id.name;
258
+ if (!a.startsWith("socket_")) return;
259
+ const u = a.replace("socket_", ""), l = `/_socket/${n}/${u}`;
260
+ i.init = e.objectExpression([
248
261
  e.objectProperty(
249
262
  e.identifier("__isVeloSocket"),
250
263
  e.booleanLiteral(!0)
@@ -253,74 +266,74 @@ function ne(p, n) {
253
266
  e.identifier("__path"),
254
267
  e.stringLiteral(l)
255
268
  )
256
- ]), o.id.typeAnnotation = null;
269
+ ]), i.id.typeAnnotation = null;
257
270
  }
258
- }), g(r, { retainLines: !0 }).code;
271
+ }), A(t, { retainLines: !0 }).code;
259
272
  }
260
- function se(p) {
261
- const n = v(p, {
273
+ function ge(r) {
274
+ const n = O(r, {
262
275
  sourceType: "module",
263
276
  plugins: ["typescript", "jsx"]
264
277
  });
265
- return h(n, {
278
+ return w(n, {
266
279
  ExportNamedDeclaration(s) {
267
- const c = s.node.declaration;
268
- if (!e.isVariableDeclaration(c)) return;
269
- const a = c.declarations[0];
270
- !a || !e.isIdentifier(a.id) || a.id.name === "loader" && s.remove();
280
+ const o = s.node.declaration;
281
+ if (!e.isVariableDeclaration(o)) return;
282
+ const c = o.declarations[0];
283
+ !c || !e.isIdentifier(c.id) || c.id.name === "loader" && s.remove();
271
284
  }
272
- }), g(n, { retainLines: !0 }).code;
285
+ }), A(n, { retainLines: !0 }).code;
273
286
  }
274
- function ie(p) {
275
- const n = v(p, {
287
+ function ve(r) {
288
+ const n = O(r, {
276
289
  sourceType: "module",
277
290
  plugins: ["typescript", "jsx"]
278
- }), r = /* @__PURE__ */ new Set();
279
- T(n.program, r);
291
+ }), t = /* @__PURE__ */ new Set();
292
+ D(n.program, t);
280
293
  let s = !1;
281
- return h(n, {
282
- ImportDeclaration(a) {
283
- const o = a.node.specifiers;
284
- if (o.length === 0) return;
285
- const i = o.filter((t) => r.has(t.local.name));
286
- i.length !== o.length && (s = !0, i.length === 0 ? a.remove() : a.node.specifiers = i);
294
+ return w(n, {
295
+ ImportDeclaration(c) {
296
+ const i = c.node.specifiers;
297
+ if (i.length === 0) return;
298
+ const a = i.filter((u) => t.has(u.local.name));
299
+ a.length !== i.length && (s = !0, a.length === 0 ? c.remove() : c.node.specifiers = a);
287
300
  }
288
- }), s ? g(n, { retainLines: !0 }).code : p;
301
+ }), s ? A(n, { retainLines: !0 }).code : r;
289
302
  }
290
- function oe(p) {
291
- const n = v(p, {
303
+ function xe(r) {
304
+ const n = O(r, {
292
305
  sourceType: "module",
293
306
  plugins: ["typescript", "jsx"]
294
- }), r = [];
295
- if (h(n, {
296
- ObjectProperty(i) {
297
- e.isIdentifier(i.node.key, { name: "middlewares" }) && (r.push(i.node.value), i.remove());
307
+ }), t = [];
308
+ if (w(n, {
309
+ ObjectProperty(a) {
310
+ e.isIdentifier(a.node.key, { name: "middlewares" }) && (t.push(a.node.value), a.remove());
298
311
  }
299
- }), r.length === 0) return p;
312
+ }), t.length === 0) return r;
300
313
  const s = /* @__PURE__ */ new Set();
301
- for (const i of r)
302
- T(i, s);
314
+ for (const a of t)
315
+ D(a, s);
316
+ const o = /* @__PURE__ */ new Set();
317
+ D(n.program, o);
303
318
  const c = /* @__PURE__ */ new Set();
304
- T(n.program, c);
305
- const a = /* @__PURE__ */ new Set();
306
- for (const i of s)
307
- c.has(i) || a.add(i);
308
- return a.size > 0 && h(n, {
309
- ImportDeclaration(i) {
310
- const t = i.node.specifiers, l = t.filter((u) => !a.has(u.local.name));
311
- l.length === 0 ? i.remove() : l.length !== t.length && (i.node.specifiers = l);
312
- }
313
- }), g(n, { retainLines: !0 }).code;
314
- }
315
- function T(p, n) {
316
- const r = (s) => {
319
+ for (const a of s)
320
+ o.has(a) || c.add(a);
321
+ return c.size > 0 && w(n, {
322
+ ImportDeclaration(a) {
323
+ const u = a.node.specifiers, l = u.filter((p) => !c.has(p.local.name));
324
+ l.length === 0 ? a.remove() : l.length !== u.length && (a.node.specifiers = l);
325
+ }
326
+ }), A(n, { retainLines: !0 }).code;
327
+ }
328
+ function D(r, n) {
329
+ const t = (s) => {
317
330
  if (!(!s || typeof s != "object")) {
318
331
  if (Array.isArray(s)) {
319
- for (const c of s) r(c);
332
+ for (const o of s) t(o);
320
333
  return;
321
334
  }
322
335
  if (s.type === "Identifier") {
323
- n.add(s.name), s.typeAnnotation && r(s.typeAnnotation);
336
+ n.add(s.name), s.typeAnnotation && t(s.typeAnnotation);
324
337
  return;
325
338
  }
326
339
  if (s.type === "JSXIdentifier") {
@@ -328,315 +341,389 @@ function T(p, n) {
328
341
  return;
329
342
  }
330
343
  if (s.type === "MemberExpression") {
331
- r(s.object), s.computed && r(s.property);
344
+ t(s.object), s.computed && t(s.property);
332
345
  return;
333
346
  }
334
347
  if ((s.type === "ObjectProperty" || s.type === "ObjectMethod") && !s.computed) {
335
- s.type === "ObjectProperty" ? r(s.value) : r(s.body);
348
+ s.type === "ObjectProperty" ? t(s.value) : t(s.body);
336
349
  return;
337
350
  }
338
351
  if (!(s.type === "ImportSpecifier" || s.type === "ImportDefaultSpecifier" || s.type === "ImportNamespaceSpecifier"))
339
- for (const c of Object.keys(s))
340
- c === "loc" || c === "start" || c === "end" || c === "leadingComments" || c === "trailingComments" || c === "innerComments" || r(s[c]);
352
+ for (const o of Object.keys(s))
353
+ o === "loc" || o === "start" || o === "end" || o === "leadingComments" || o === "trailingComments" || o === "innerComments" || t(s[o]);
341
354
  }
342
355
  };
343
- r(p);
356
+ t(r);
344
357
  }
345
- function ae(p) {
346
- for (const n of p.properties)
358
+ function Se(r) {
359
+ for (const n of r.properties)
347
360
  if (e.isObjectProperty(n) && e.isIdentifier(n.key) && n.key.name === "handler")
348
361
  return !0;
349
362
  return !1;
350
363
  }
351
- function ce(p) {
352
- for (const n of p.properties)
364
+ function _e(r) {
365
+ for (const n of r.properties)
353
366
  if (e.isObjectProperty(n) && e.isIdentifier(n.key) && n.key.name === "children" && e.isArrayExpression(n.value))
354
367
  return n.value;
355
368
  return null;
356
369
  }
357
- function le(p) {
358
- const n = v(p, {
370
+ function je(r) {
371
+ const n = O(r, {
359
372
  sourceType: "module",
360
373
  plugins: ["typescript", "jsx"]
361
- }), r = [], s = (t) => {
362
- for (let l = t.elements.length - 1; l >= 0; l--) {
363
- const u = t.elements[l];
364
- if (!e.isObjectExpression(u)) continue;
365
- if (ae(u)) {
366
- r.push(u), t.elements.splice(l, 1);
374
+ }), t = [], s = (u) => {
375
+ for (let l = u.elements.length - 1; l >= 0; l--) {
376
+ const p = u.elements[l];
377
+ if (!e.isObjectExpression(p)) continue;
378
+ if (Se(p)) {
379
+ t.push(p), u.elements.splice(l, 1);
367
380
  continue;
368
381
  }
369
- const d = ce(u);
382
+ const d = _e(p);
370
383
  d && s(d);
371
384
  }
372
385
  };
373
- if (h(n, {
374
- ExportDefaultDeclaration(t) {
375
- const l = t.node.declaration;
376
- let u = null;
377
- e.isArrayExpression(l) ? u = l : (e.isTSSatisfiesExpression(l) && e.isArrayExpression(l.expression) || e.isTSAsExpression(l) && e.isArrayExpression(l.expression)) && (u = l.expression), u && s(u);
386
+ if (w(n, {
387
+ ExportDefaultDeclaration(u) {
388
+ const l = u.node.declaration;
389
+ let p = null;
390
+ e.isArrayExpression(l) ? p = l : (e.isTSSatisfiesExpression(l) && e.isArrayExpression(l.expression) || e.isTSAsExpression(l) && e.isArrayExpression(l.expression)) && (p = l.expression), p && s(p);
378
391
  }
379
- }), r.length === 0) return p;
380
- const c = /* @__PURE__ */ new Set();
381
- for (const t of r)
382
- T(t, c);
383
- const a = /* @__PURE__ */ new Set();
384
- T(n.program, a);
392
+ }), t.length === 0) return r;
385
393
  const o = /* @__PURE__ */ new Set();
386
- for (const t of c)
387
- a.has(t) || o.add(t);
388
- return o.size > 0 && h(n, {
389
- ImportDeclaration(t) {
390
- const l = t.node.specifiers, u = l.filter((d) => !o.has(d.local.name));
391
- u.length === 0 ? t.remove() : u.length !== l.length && (t.node.specifiers = u);
394
+ for (const u of t)
395
+ D(u, o);
396
+ const c = /* @__PURE__ */ new Set();
397
+ D(n.program, c);
398
+ const i = /* @__PURE__ */ new Set();
399
+ for (const u of o)
400
+ c.has(u) || i.add(u);
401
+ return i.size > 0 && w(n, {
402
+ ImportDeclaration(u) {
403
+ const l = u.node.specifiers, p = l.filter((d) => !i.has(d.local.name));
404
+ p.length === 0 ? u.remove() : p.length !== l.length && (u.node.specifiers = p);
392
405
  }
393
- }), g(n, { retainLines: !0 }).code;
406
+ }), A(n, { retainLines: !0 }).code;
394
407
  }
395
- function F(p) {
396
- const n = v(p, {
408
+ function B(r) {
409
+ const n = O(r, {
397
410
  sourceType: "module",
398
411
  plugins: ["typescript", "jsx"]
399
- }), r = /* @__PURE__ */ new Map();
400
- h(n, {
401
- ImportDeclaration(a) {
402
- const o = a.node.source.value;
403
- for (const i of a.node.specifiers)
404
- e.isImportNamespaceSpecifier(i) && r.set(i.local.name, o);
412
+ }), t = /* @__PURE__ */ new Map();
413
+ w(n, {
414
+ ImportDeclaration(c) {
415
+ const i = c.node.source.value;
416
+ for (const a of c.node.specifiers)
417
+ e.isImportNamespaceSpecifier(a) && t.set(a.local.name, i);
405
418
  }
406
419
  });
407
420
  const s = /* @__PURE__ */ new Map();
408
- h(n, {
409
- ExportDefaultDeclaration(a) {
410
- const o = a.node.declaration;
411
- let i = null;
412
- e.isArrayExpression(o) ? i = o : (e.isTSSatisfiesExpression(o) || e.isTSAsExpression(o)) && e.isArrayExpression(o.expression) && (i = o.expression), i && R(i.elements, "", s);
421
+ w(n, {
422
+ ExportDefaultDeclaration(c) {
423
+ const i = c.node.declaration;
424
+ let a = null;
425
+ e.isArrayExpression(i) ? a = i : (e.isTSSatisfiesExpression(i) || e.isTSAsExpression(i)) && e.isArrayExpression(i.expression) && (a = i.expression), a && X(a.elements, "", s);
413
426
  }
414
427
  });
415
- const c = /* @__PURE__ */ new Map();
416
- for (const [a, o] of s) {
417
- const i = r.get(a);
418
- if (i) {
419
- const t = i.replace(/^\.\//, "").replace(/\.(tsx?|jsx?|js)$/, "");
420
- c.set(t, o);
428
+ const o = /* @__PURE__ */ new Map();
429
+ for (const [c, i] of s) {
430
+ const a = t.get(c);
431
+ if (a) {
432
+ const u = a.replace(/^\.\//, "").replace(/\.(tsx?|jsx?|js)$/, "");
433
+ o.set(u, i);
421
434
  }
422
435
  }
423
- return c;
436
+ return o;
424
437
  }
425
- function R(p, n, r) {
426
- for (const s of p) {
438
+ function X(r, n, t) {
439
+ for (const s of r) {
427
440
  if (!e.isObjectExpression(s)) continue;
428
- let c = "", a = n, o = null, i = null;
429
- for (const t of s.properties) {
430
- if (!e.isObjectProperty(t)) continue;
431
- const l = t.key, u = e.isIdentifier(l) ? l.name : null;
432
- u === "path" && e.isStringLiteral(t.value) && (c = t.value.value, c && !c.startsWith("/") ? a = n + "/" + c : a = n + c), u === "module" && e.isIdentifier(t.value) && (o = t.value.name), u === "children" && e.isArrayExpression(t.value) && (i = t.value);
433
- }
434
- if (o) {
435
- const l = !i && c === "/" ? n || "/" : a;
436
- r.set(o, {
441
+ let o = "", c = n, i = null, a = null;
442
+ for (const u of s.properties) {
443
+ if (!e.isObjectProperty(u)) continue;
444
+ const l = u.key, p = e.isIdentifier(l) ? l.name : null;
445
+ p === "path" && e.isStringLiteral(u.value) && (o = u.value.value, o && !o.startsWith("/") ? c = n + "/" + o : c = n + o), p === "module" && e.isIdentifier(u.value) && (i = u.value.name), p === "children" && e.isArrayExpression(u.value) && (a = u.value);
446
+ }
447
+ if (i) {
448
+ const l = !a && o === "/" ? n || "/" : c;
449
+ t.set(i, {
437
450
  fullPath: l,
438
- path: c
451
+ path: o
439
452
  });
440
453
  }
441
- i && R(i.elements, a, r);
454
+ a && X(a.elements, c, t);
442
455
  }
443
456
  }
444
- function pe(p) {
445
- const n = v(p, {
457
+ function Ee(r) {
458
+ const n = O(r, {
446
459
  sourceType: "module",
447
460
  plugins: ["typescript", "jsx"]
448
461
  });
449
- let r = null;
450
- return h(n, {
462
+ let t = null;
463
+ return w(n, {
451
464
  ExportNamedDeclaration(s) {
452
- if (r) return;
453
- const c = s.node.declaration;
454
- if (e.isVariableDeclaration(c))
455
- for (const a of c.declarations) {
456
- if (!e.isIdentifier(a.id, { name: "channels" })) continue;
457
- let o = a.init;
458
- if (o && (e.isTSSatisfiesExpression(o) || e.isTSAsExpression(o)) && (o = o.expression), !e.isArrayExpression(o)) continue;
459
- const i = [];
460
- for (const t of o.elements)
461
- e.isStringLiteral(t) && i.push(t.value);
462
- r = i;
465
+ if (t) return;
466
+ const o = s.node.declaration;
467
+ if (e.isVariableDeclaration(o))
468
+ for (const c of o.declarations) {
469
+ if (!e.isIdentifier(c.id, { name: "channels" })) continue;
470
+ let i = c.init;
471
+ if (i && (e.isTSSatisfiesExpression(i) || e.isTSAsExpression(i)) && (i = i.expression), !e.isArrayExpression(i)) continue;
472
+ const a = [];
473
+ for (const u of i.elements)
474
+ e.isStringLiteral(u) && a.push(u.value);
475
+ t = a;
463
476
  }
464
477
  }
465
- }), r;
478
+ }), t;
466
479
  }
467
- function ue(p) {
480
+ function be(r) {
468
481
  const n = /* @__PURE__ */ new Set();
469
- if (!x.existsSync(p)) return n;
470
- let r;
482
+ if (!b.existsSync(r)) return n;
483
+ let t;
471
484
  try {
472
- r = v(x.readFileSync(p, "utf-8"), {
485
+ t = O(b.readFileSync(r, "utf-8"), {
473
486
  sourceType: "module",
474
487
  plugins: ["typescript", "jsx"]
475
488
  });
476
489
  } catch {
477
490
  return n;
478
491
  }
479
- return h(r, {
492
+ return w(t, {
480
493
  ExportNamedDeclaration(s) {
481
- const c = s.node.declaration;
482
- if (e.isVariableDeclaration(c))
483
- for (const a of c.declarations) {
484
- if (!e.isIdentifier(a.id, { name: "channels" })) continue;
485
- let o = a.init;
486
- if (o && (e.isTSSatisfiesExpression(o) || e.isTSAsExpression(o)) && (o = o.expression), !!e.isObjectExpression(o))
487
- for (const i of o.properties)
488
- e.isObjectProperty(i) && (e.isIdentifier(i.key) ? n.add(i.key.name) : e.isStringLiteral(i.key) && n.add(i.key.value));
494
+ const o = s.node.declaration;
495
+ if (e.isVariableDeclaration(o))
496
+ for (const c of o.declarations) {
497
+ if (!e.isIdentifier(c.id, { name: "channels" })) continue;
498
+ let i = c.init;
499
+ if (i && (e.isTSSatisfiesExpression(i) || e.isTSAsExpression(i)) && (i = i.expression), !!e.isObjectExpression(i))
500
+ for (const a of i.properties)
501
+ e.isObjectProperty(a) && (e.isIdentifier(a.key) ? n.add(a.key.name) : e.isStringLiteral(a.key) && n.add(a.key.value));
489
502
  }
490
503
  }
491
504
  }), n;
492
505
  }
493
- function C(p) {
494
- return [m.join(p, "channels.ts"), m.join(p, "channels.tsx")];
495
- }
496
- const O = "virtual:velo/server-entry", N = "virtual:velo/client-entry", V = "\0" + O, $ = "\0" + N;
497
- function fe(p, n) {
498
- let r = m.resolve(process.cwd(), n);
499
- const s = p.routesFile ?? "routes.tsx", c = /* @__PURE__ */ new Map();
500
- let a = null;
501
- const o = () => {
502
- if (!a) {
503
- const t = C(r).find((l) => x.existsSync(l));
504
- a = t ? ue(t) : /* @__PURE__ */ new Set();
505
- }
506
- return a;
507
- }, i = /* @__PURE__ */ new Set();
506
+ function M(r) {
507
+ return [m.join(r, "channels.ts"), m.join(r, "channels.tsx")];
508
+ }
509
+ function Y(r) {
510
+ const n = O(r, {
511
+ sourceType: "module",
512
+ plugins: ["typescript", "jsx"]
513
+ });
514
+ let t = null;
515
+ return w(n, {
516
+ ExportNamedDeclaration(s) {
517
+ if (t) return;
518
+ const o = s.node.declaration;
519
+ if (e.isVariableDeclaration(o))
520
+ for (const c of o.declarations) {
521
+ if (!e.isIdentifier(c.id, { name: "liveActions" })) continue;
522
+ let i = c.init;
523
+ if (i && (e.isTSSatisfiesExpression(i) || e.isTSAsExpression(i)) && (i = i.expression), !e.isObjectExpression(i)) continue;
524
+ const a = {};
525
+ for (const u of i.properties) {
526
+ if (!e.isObjectProperty(u) || u.computed) continue;
527
+ const l = e.isIdentifier(u.key) ? u.key.name : e.isStringLiteral(u.key) ? u.key.value : null;
528
+ if (l === null) continue;
529
+ let p = u.value;
530
+ if (p && (e.isTSSatisfiesExpression(p) || e.isTSAsExpression(p)) && (p = p.expression), !e.isArrayExpression(p)) continue;
531
+ const d = [];
532
+ for (const y of p.elements)
533
+ e.isStringLiteral(y) && d.push(y.value);
534
+ a[l] = d;
535
+ }
536
+ t = a;
537
+ }
538
+ }
539
+ }), t;
540
+ }
541
+ const P = "virtual:velo/server-entry", F = "virtual:velo/client-entry", H = "\0" + P, G = "\0" + F, Ie = "@mauroandre/velojs/client";
542
+ function Q(r, n) {
543
+ return m.relative(r, n).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/");
544
+ }
545
+ function Z(r, n) {
546
+ const { id: t, appDir: s, isSSR: o } = n, c = n.routesFile ?? "routes.tsx";
547
+ if (t.startsWith("\0") || t.includes("/.velojs/") || !t.endsWith(".tsx") && !t.endsWith(".ts") || !t.startsWith(s)) return null;
548
+ let i = r, a = !1;
549
+ const u = /middlewares:\s*\[/.test(r), l = /export\s+(const|function)\s+Component/.test(
550
+ r
551
+ ), p = /export\s+(const|function)\s+loader/.test(r), d = /export\s+const\s+action_\w+/.test(r), y = /export\s+const\s+stream_\w+/.test(r), h = /export\s+const\s+socket_\w+/.test(r), _ = /\bLoader\s*</.test(r) || /\bLoader\s*\(/.test(r), v = /\buseLoader\s*</.test(r) || /\buseLoader\s*\(/.test(r), T = /\bhandler\s*:/.test(r), S = Q(s, t), I = n.pathInfo, j = /export\s+(const|let|var)\s+liveActions\b/.test(r) ? Y(r) : null, E = j ? new Set(Object.keys(j)) : void 0, k = m.join(s, c);
552
+ return !o && u && (i = xe(i), a = !0), !o && T && t === k && (i = je(i), a = !0), (l || p || d || y || h || _ || v) && (i = ue(i, S, I?.fullPath, I?.path), i = pe(i, S), o || (i = fe(
553
+ i,
554
+ S,
555
+ E
556
+ )), !o && y && (i = he(
557
+ i,
558
+ S
559
+ )), !o && h && (i = ye(
560
+ i,
561
+ S
562
+ )), o || (i = ge(i)), o || (i = ve(i)), a = !0), a ? { code: i, moduleId: S } : null;
563
+ }
564
+ function ee(r, n) {
565
+ const t = n.routesFile ?? "routes.tsx", s = n.clientInit ?? "client.tsx";
566
+ return {
567
+ clientInit: m.join(r, s).replace(/\.tsx?$/, ".js"),
568
+ routes: m.join(r, t).replace(/\.tsx?$/, ".js"),
569
+ framework: Ie
570
+ };
571
+ }
572
+ function Le(r, n) {
573
+ let t = m.resolve(process.cwd(), n);
574
+ const s = r.routesFile ?? "routes.tsx", o = /* @__PURE__ */ new Map();
575
+ let c = null;
576
+ const i = () => {
577
+ if (!c) {
578
+ const l = M(t).find((p) => b.existsSync(p));
579
+ c = l ? be(l) : /* @__PURE__ */ new Set();
580
+ }
581
+ return c;
582
+ }, a = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
508
583
  return {
509
584
  name: "velo:transform",
510
585
  enforce: "pre",
511
- configResolved(t) {
512
- r = m.resolve(t.root, n), a = null;
586
+ configResolved(l) {
587
+ t = m.resolve(l.root, n), c = null;
513
588
  },
514
589
  buildStart() {
515
- a = null;
516
- const t = m.join(r, s);
517
- if (x.existsSync(t)) {
518
- const l = x.readFileSync(t, "utf-8"), u = F(l);
519
- c.clear();
520
- for (const [d, f] of u)
521
- c.set(d, f);
590
+ c = null;
591
+ const l = m.join(t, s);
592
+ if (b.existsSync(l)) {
593
+ const p = b.readFileSync(l, "utf-8"), d = B(p);
594
+ o.clear();
595
+ for (const [y, h] of d)
596
+ o.set(y, h);
522
597
  }
523
598
  },
524
- handleHotUpdate({ file: t, server: l }) {
525
- if (C(r).includes(t))
526
- return a = null, l.ws.send({ type: "full-reload" }), [];
527
- const u = m.join(r, s);
528
- if (t === u) {
529
- const d = x.readFileSync(u, "utf-8"), f = F(d);
530
- c.clear();
531
- for (const [y, E] of f)
532
- c.set(y, E);
533
- return l.ws.send({ type: "full-reload" }), [];
599
+ handleHotUpdate({ file: l, server: p }) {
600
+ if (M(t).includes(l))
601
+ return c = null, p.ws.send({ type: "full-reload" }), [];
602
+ const d = m.join(t, s);
603
+ if (l === d) {
604
+ const y = b.readFileSync(d, "utf-8"), h = B(y);
605
+ o.clear();
606
+ for (const [_, v] of h)
607
+ o.set(_, v);
608
+ return p.ws.send({ type: "full-reload" }), [];
534
609
  }
535
610
  },
536
- resolveId(t) {
537
- return t === O || t.endsWith(O) ? V : t === N || t.endsWith(N) || t === "/__velo_client.js" ? $ : null;
611
+ resolveId(l) {
612
+ return l === P || l.endsWith(P) ? H : l === F || l.endsWith(F) || l === "/__velo_client.js" ? G : null;
538
613
  },
539
- load(t) {
540
- const l = p.routesFile ?? "routes.tsx", u = p.serverInit ?? "server.tsx", d = p.clientInit ?? "client.tsx", f = m.join(r, l).replace(/\.tsx?$/, ".js"), y = m.join(r, u).replace(/\.tsx?$/, ".js"), E = m.join(r, d).replace(/\.tsx?$/, ".js");
541
- if (t === V) {
542
- const b = C(r).find((j) => x.existsSync(j)), _ = b ? b.replace(/\.tsx?$/, ".js") : null;
614
+ load(l) {
615
+ const p = r.routesFile ?? "routes.tsx", d = r.serverInit ?? "server.tsx", y = m.join(t, p).replace(/\.tsx?$/, ".js"), h = m.join(t, d).replace(/\.tsx?$/, ".js");
616
+ if (l === H) {
617
+ const _ = M(t).find((T) => b.existsSync(T)), v = _ ? _.replace(/\.tsx?$/, ".js") : null;
543
618
  return `
544
619
  globalThis.__veloBuildHash = __VELO_BUILD_HASH__;
545
620
  globalThis.__veloClientJs = __VELO_CLIENT_JS__;
546
621
  globalThis.__veloClientCss = __VELO_CLIENT_CSS__;
547
- import "${y}";
548
- import routes from "${f}";
549
- import { startServer${_ ? ", registerChannels" : ""} } from "@mauroandre/velojs/server";
550
- ${_ ? `import { channels as __veloChannelMap } from "${_}";` : ""}
551
- ${_ ? "registerChannels(__veloChannelMap);" : ""}
622
+ import "${h}";
623
+ import routes from "${y}";
624
+ import { startServer${v ? ", registerChannels" : ""} } from "@mauroandre/velojs/server";
625
+ ${v ? `import { channels as __veloChannelMap } from "${v}";` : ""}
626
+ ${v ? "registerChannels(__veloChannelMap);" : ""}
552
627
 
553
628
  export { routes };
554
629
  export default await startServer({ routes, port: __VELO_CONFIG_PORT__, hostname: __VELO_CONFIG_HOSTNAME__ });
555
630
  `;
556
631
  }
557
- return t === $ ? `
558
- import "${E}";
559
- import routes from "${f}";
560
- import { startClient } from "@mauroandre/velojs/client";
632
+ if (l === G) {
633
+ const _ = ee(t, r);
634
+ return `
635
+ import "${_.clientInit}";
636
+ import routes from "${_.routes}";
637
+ import { startClient } from "${_.framework}";
561
638
 
562
639
  startClient({ routes });
563
- ` : null;
640
+ `;
641
+ }
642
+ return null;
564
643
  },
565
- transform(t, l, u) {
566
- const d = u?.ssr === !0;
567
- if (l.startsWith("\0") || l.includes("/.velojs/") || !l.endsWith(".tsx") && !l.endsWith(".ts") || !l.startsWith(r)) return null;
568
- let f = t, y = !1;
569
- const E = /middlewares:\s*\[/.test(t), b = /export\s+(const|function)\s+Component/.test(
570
- t
571
- ), _ = /export\s+(const|function)\s+loader/.test(t), j = /export\s+const\s+action_\w+/.test(t), A = /export\s+const\s+stream_\w+/.test(t), L = /export\s+const\s+socket_\w+/.test(t), M = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), H = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t), J = /\bhandler\s*:/.test(t), U = /export\s+(const|let|var)\s+channels\b/.test(t), S = m.relative(r, l).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/");
572
- if (U) {
573
- const I = pe(t);
574
- if (I) {
575
- if (!_)
644
+ transform(l, p, d) {
645
+ const y = d?.ssr === !0;
646
+ if (p.startsWith("\0") || p.includes("/.velojs/") || !p.endsWith(".tsx") && !p.endsWith(".ts") || !p.startsWith(t)) return null;
647
+ const h = /export\s+(const|function)\s+loader/.test(l), _ = /export\s+(const|let|var)\s+channels\b/.test(l), v = Q(t, p);
648
+ if (_) {
649
+ const S = Ee(l);
650
+ if (S) {
651
+ if (!h)
576
652
  throw new Error(
577
- `[velojs] "${S}" declares \`channels\` without a \`loader\` — there is nothing to synchronize. Add a loader or remove the export.`
653
+ `[velojs] "${v}" declares \`channels\` without a \`loader\` — there is nothing to synchronize. Add a loader or remove the export.`
578
654
  );
579
- const B = o(), k = I.filter((w) => !B.has(w));
580
- if (k.length > 0)
655
+ const I = i(), j = S.filter((E) => !I.has(E));
656
+ if (j.length > 0)
581
657
  throw new Error(
582
- `[velojs] "${S}" declares channel(s) ${k.map((w) => `"${w}"`).join(", ")} with no entry in app/channels.ts — add the partition resolver for each name (a typo or a rename would otherwise be a silent no-op).`
658
+ `[velojs] "${v}" declares channel(s) ${j.map((E) => `"${E}"`).join(", ")} with no entry in app/channels.ts — add the partition resolver for each name (a typo or a rename would otherwise be a silent no-op).`
583
659
  );
584
- process.env.VELO_STATIC && !i.has(S) && (i.add(S), console.warn(
585
- `[velojs] "${S}" declares channels (${I.join(
660
+ process.env.VELO_STATIC && !a.has(v) && (a.add(v), console.warn(
661
+ `[velojs] "${v}" declares channels (${S.join(
586
662
  ", "
587
663
  )}) — inert in a static build: there is no SSE server, so no connection is opened and freshness stays "live".`
588
664
  ));
589
665
  }
590
666
  }
591
- const W = m.join(r, s);
592
- if (!d && E && (f = oe(f), y = !0), !d && J && l === W && (f = le(f), y = !0), b || _ || j || A || L || M || H) {
593
- const I = c.get(S);
594
- f = K(f, S, I?.fullPath, I?.path), f = Q(f, S), d || (f = Z(
595
- f,
596
- S
597
- )), !d && A && (f = re(
598
- f,
599
- S
600
- )), !d && L && (f = ne(
601
- f,
602
- S
603
- )), d || (f = se(f)), d || (f = ie(f)), y = !0;
667
+ if (/export\s+(const|let|var)\s+liveActions\b/.test(l)) {
668
+ const S = Y(l);
669
+ if (S)
670
+ for (const [I, j] of Object.entries(S)) {
671
+ if (!new RegExp(`export\\s+const\\s+action_${I}\\b`).test(l))
672
+ throw new Error(
673
+ `[velojs] "${v}" declares liveActions.${I} but the module has no \`export const action_${I}\` — there is nothing to synchronize. Add the action or remove the entry.`
674
+ );
675
+ const E = i(), k = j.filter(($) => !E.has($));
676
+ if (k.length > 0)
677
+ throw new Error(
678
+ `[velojs] "${v}" liveActions.${I} declares channel(s) ${k.map(($) => `"${$}"`).join(", ")} with no entry in app/channels.ts — add the partition resolver for each name (a typo or a rename would otherwise be a silent no-op).`
679
+ );
680
+ if (process.env.VELO_STATIC) {
681
+ const $ = `${v}#${I}`;
682
+ u.has($) || (u.add($), console.warn(
683
+ `[velojs] "${v}" liveActions.${I} (channels: ${j.join(", ")}) — inert in a static build: there is no SSE server, the hook opens no connection and returns data undefined with freshness "error" (the load really failed — the contrast with a channel, which stays "live", is deliberate).`
684
+ ));
685
+ }
686
+ }
604
687
  }
605
- return y ? {
606
- code: f,
607
- map: null
608
- } : null;
688
+ const T = Z(l, {
689
+ id: p,
690
+ appDir: t,
691
+ isSSR: y,
692
+ routesFile: s,
693
+ pathInfo: o.get(v)
694
+ });
695
+ return T ? { code: T.code, map: null } : null;
609
696
  }
610
697
  };
611
698
  }
612
- function de(p) {
699
+ function Te(r) {
613
700
  return {
614
701
  name: "velo:config",
615
- config(n, { mode: r }) {
616
- const s = r === "server", c = r === "development", a = !!process.env.VELO_STATIC, o = n.server?.port ?? (Number(process.env.PORT) || p.port || 3e3), i = m.resolve(
702
+ config(n, { mode: t }) {
703
+ const s = t === "server", o = t === "development", c = !!process.env.VELO_STATIC, i = n.server?.port ?? (Number(process.env.PORT) || r.port || 3e3), a = m.resolve(
617
704
  process.cwd(),
618
705
  n.root ?? "."
619
- ), t = n.envDir ? m.resolve(i, n.envDir) : i, l = G(r, t, ""), u = process.env.HOST?.trim() || l.HOST?.trim() || void 0, d = n.server?.host ?? u ?? p.hostname, f = d === !0 || d === "0.0.0.0" || d === "::", y = n.server?.allowedHosts ?? (f ? !0 : void 0);
620
- let E = "client.js", b = "client.css";
706
+ ), u = n.envDir ? m.resolve(a, n.envDir) : a, l = ie(t, u, ""), p = process.env.HOST?.trim() || l.HOST?.trim() || void 0, d = n.server?.host ?? p ?? r.hostname, y = d === !0 || d === "0.0.0.0" || d === "::", h = n.server?.allowedHosts ?? (y ? !0 : void 0);
707
+ let _ = "client.js", v = "client.css";
621
708
  if (s)
622
709
  try {
623
- const j = m.resolve(process.cwd(), "dist/client/.vite/manifest.json"), L = JSON.parse(x.readFileSync(j, "utf-8"))[N];
624
- L && (E = L.file || E, L.css?.[0] && (b = L.css[0]));
710
+ const S = m.resolve(process.cwd(), "dist/client/.vite/manifest.json"), j = JSON.parse(b.readFileSync(S, "utf-8"))[F];
711
+ j && (_ = j.file || _, j.css?.[0] && (v = j.css[0]));
625
712
  } catch {
626
713
  }
627
- const _ = {
714
+ const T = {
628
715
  define: {
629
- "process.env.NODE_ENV": JSON.stringify(c ? "development" : "production"),
630
- "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (a ? "/client" : "")),
631
- __VELO_STATIC__: JSON.stringify(a),
716
+ "process.env.NODE_ENV": JSON.stringify(o ? "development" : "production"),
717
+ "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (c ? "/client" : "")),
718
+ __VELO_STATIC__: JSON.stringify(c),
632
719
  __VELO_BUILD_HASH__: JSON.stringify(process.env.VELO_BUILD_HASH || Date.now().toString(36)),
633
- __VELO_CLIENT_JS__: JSON.stringify(E),
634
- __VELO_CLIENT_CSS__: JSON.stringify(b),
720
+ __VELO_CLIENT_JS__: JSON.stringify(_),
721
+ __VELO_CLIENT_CSS__: JSON.stringify(v),
635
722
  // Baked into the server bundle as startServer's port fallback.
636
723
  // null when unset → startServer falls back to PORT env / 3000.
637
- __VELO_CONFIG_PORT__: JSON.stringify(p.port ?? null),
724
+ __VELO_CONFIG_PORT__: JSON.stringify(r.port ?? null),
638
725
  // Same for the bind interface: null → HOST env / Node default.
639
- __VELO_CONFIG_HOSTNAME__: JSON.stringify(p.hostname ?? null)
726
+ __VELO_CONFIG_HOSTNAME__: JSON.stringify(r.hostname ?? null)
640
727
  },
641
728
  resolve: {
642
729
  alias: {
@@ -645,15 +732,15 @@ function de(p) {
645
732
  }
646
733
  },
647
734
  server: {
648
- port: o,
735
+ port: i,
649
736
  // Host and allowedHosts only shape the dev server; in build
650
737
  // they are inert, so we keep them out of the build config.
651
- ...c && d !== void 0 ? { host: d } : {},
652
- ...c && y !== void 0 ? { allowedHosts: y } : {}
738
+ ...o && d !== void 0 ? { host: d } : {},
739
+ ...o && h !== void 0 ? { allowedHosts: h } : {}
653
740
  }
654
741
  };
655
- return s ? _.build = {
656
- ssr: O,
742
+ return s ? T.build = {
743
+ ssr: P,
657
744
  outDir: "dist",
658
745
  emptyOutDir: !1,
659
746
  copyPublicDir: !1,
@@ -662,109 +749,490 @@ function de(p) {
662
749
  entryFileNames: "server.js"
663
750
  }
664
751
  }
665
- } : c || (_.build = {
752
+ } : o || (T.build = {
666
753
  manifest: !0,
667
754
  outDir: "dist/client",
668
755
  rollupOptions: {
669
- input: N,
756
+ input: F,
670
757
  output: {
671
758
  entryFileNames: "client.[hash].js",
672
- assetFileNames: (j) => j.names?.[0]?.endsWith(".css") ? "client.[hash].css" : "[name].[hash][extname]"
759
+ assetFileNames: (S) => S.names?.[0]?.endsWith(".css") ? "client.[hash].css" : "[name].[hash][extname]"
673
760
  }
674
761
  }
675
- }), _;
762
+ }), T;
676
763
  }
677
764
  };
678
765
  }
679
- function me() {
766
+ function we() {
680
767
  return {
681
768
  name: "velo:static-url",
682
769
  apply: "build",
683
770
  enforce: "post",
684
- generateBundle(p, n) {
685
- const r = process.env.STATIC_BASE_URL || "";
686
- if (r)
771
+ generateBundle(r, n) {
772
+ const t = process.env.STATIC_BASE_URL || "";
773
+ if (t)
687
774
  for (const s of Object.values(n))
688
775
  s.type === "asset" && typeof s.source == "string" && s.fileName.endsWith(".css") && (s.source = s.source.replace(
689
776
  /url\(\s*(['"]?)\/(?!\/)/g,
690
- `url($1${r}/`
777
+ `url($1${t}/`
691
778
  ));
692
779
  }
693
780
  };
694
781
  }
695
- function ye(p, n) {
696
- let r = "", s = "", c = !1, a = null;
697
- function o() {
698
- if (!r) return;
699
- const i = m.resolve(r, n);
700
- if (!x.existsSync(i)) return;
701
- const t = q(i), l = m.join(r, ".velojs");
702
- x.mkdirSync(l, { recursive: !0 }), x.writeFileSync(
782
+ function Oe(r, n) {
783
+ let t = "", s = "", o = !1, c = null;
784
+ function i() {
785
+ if (!t) return;
786
+ const a = m.resolve(t, n);
787
+ if (!b.existsSync(a)) return;
788
+ const u = le(a), l = m.join(t, ".velojs");
789
+ b.mkdirSync(l, { recursive: !0 }), b.writeFileSync(
703
790
  m.join(l, "graph.json"),
704
- JSON.stringify(t)
791
+ JSON.stringify(u)
705
792
  );
706
793
  }
707
794
  return {
708
795
  name: "velo:graph",
709
- configResolved(i) {
710
- r = i.root, s = i.mode;
796
+ configResolved(a) {
797
+ t = a.root, s = a.mode;
711
798
  },
712
799
  writeBundle() {
713
- s !== "server" && o();
800
+ s !== "server" && i();
714
801
  },
715
- configureServer(i) {
716
- o(), c = !0;
717
- const t = m.resolve(r, n);
718
- i.watcher.on("all", (l, u) => {
719
- c && u.startsWith(t) && (a && clearTimeout(a), a = setTimeout(() => o(), 500));
802
+ configureServer(a) {
803
+ i(), o = !0;
804
+ const u = m.resolve(t, n);
805
+ a.watcher.on("all", (l, p) => {
806
+ o && p.startsWith(u) && (c && clearTimeout(c), c = setTimeout(() => i(), 500));
720
807
  });
721
808
  }
722
809
  };
723
810
  }
724
- function he(p) {
811
+ function $e(r) {
725
812
  return [
726
- ...X.exclude,
813
+ ...ce.exclude,
727
814
  /.*\.mjs$/,
728
- ...p.devServerExclude ?? []
815
+ ...r.devServerExclude ?? []
729
816
  ];
730
817
  }
731
- function Te(p) {
732
- const n = p ?? {}, r = n.appDirectory ?? "./app";
818
+ function Ae(r, n) {
819
+ let t = "", s = "", o = "", c = null, i = null;
820
+ const a = /* @__PURE__ */ new Map();
821
+ function u() {
822
+ const l = ee(o, r);
823
+ return Ue({
824
+ rootDir: t,
825
+ appDir: o,
826
+ routesFile: r.routesFile,
827
+ entrySpecs: [l.clientInit, l.routes, l.framework],
828
+ serverOnly: r.serverOnly,
829
+ cache: a
830
+ });
831
+ }
832
+ return {
833
+ name: "velo:leak-diagnostic",
834
+ configResolved(l) {
835
+ t = l.root, s = l.mode, o = m.resolve(t, n);
836
+ },
837
+ closeBundle() {
838
+ s !== "server" && console.log(W(u()));
839
+ },
840
+ configureServer(l) {
841
+ const p = u();
842
+ c = p.signature, console.log(W(p)), l.watcher.on("all", (d, y) => {
843
+ i && clearTimeout(i), i = setTimeout(() => {
844
+ const h = u();
845
+ h.signature !== c && (c = h.signature, console.log(W(h)));
846
+ }, 500);
847
+ });
848
+ }
849
+ };
850
+ }
851
+ function tt(r) {
852
+ const n = r ?? {}, t = n.appDirectory ?? "./app";
733
853
  return [
734
- de(n),
735
- fe(n, r),
736
- me(),
737
- ye(n, r),
738
- z(),
739
- Y({
740
- entry: O,
741
- exclude: he(n)
854
+ Te(n),
855
+ Le(n, t),
856
+ we(),
857
+ Oe(n, t),
858
+ Ae(n, t),
859
+ oe(),
860
+ ae({
861
+ entry: P,
862
+ exclude: $e(n)
742
863
  }),
743
- ve()
864
+ ke()
744
865
  ];
745
866
  }
746
- function ve() {
867
+ function ke() {
747
868
  return {
748
869
  name: "velo:ws-bridge",
749
- configureServer(p) {
750
- globalThis.__veloDevServer = p.httpServer;
870
+ configureServer(r) {
871
+ globalThis.__veloDevServer = r.httpServer;
872
+ }
873
+ };
874
+ }
875
+ const Ne = typeof N == "function" ? N : N.default, K = new Set(se);
876
+ function te(r) {
877
+ if (r.startsWith("node:") || K.has(r)) return !0;
878
+ const n = r.indexOf("/");
879
+ return !!(n > 0 && K.has(r.slice(0, n)));
880
+ }
881
+ function De(r) {
882
+ let n = "";
883
+ for (let t = 0; t < r.length; t++) {
884
+ const s = r[t];
885
+ s === "*" ? r[t + 1] === "*" ? (n += ".*", t++) : n += "[^/]*" : s === "?" ? n += "[^/]" : n += s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
886
+ }
887
+ return new RegExp(`^${n}$`);
888
+ }
889
+ const Pe = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mjs"]);
890
+ function V(r) {
891
+ const n = [
892
+ r,
893
+ `${r}.ts`,
894
+ `${r}.tsx`,
895
+ `${r}.js`,
896
+ `${r}.jsx`,
897
+ `${r}.mjs`,
898
+ // TS-style extension completion: "./x.js" can stand for "./x.ts".
899
+ r.replace(/\.js$/, ".ts"),
900
+ r.replace(/\.js$/, ".tsx"),
901
+ r.replace(/\.jsx$/, ".tsx"),
902
+ ...["index.ts", "index.tsx", "index.js", "index.jsx", "index.mjs"].map(
903
+ (t) => m.join(r, t)
904
+ )
905
+ ];
906
+ for (const t of n)
907
+ if (!t.endsWith(".d.ts"))
908
+ try {
909
+ if (b.existsSync(t) && b.statSync(t).isFile())
910
+ return t;
911
+ } catch {
912
+ }
913
+ return null;
914
+ }
915
+ function Fe(r, n) {
916
+ let t = {};
917
+ try {
918
+ t = JSON.parse(b.readFileSync(m.join(r, "package.json"), "utf-8"));
919
+ } catch {
920
+ t = {};
921
+ }
922
+ const s = (c) => {
923
+ if (typeof c == "string") return c;
924
+ if (c && typeof c == "object") {
925
+ const i = c;
926
+ for (const a of ["browser", "import", "module", "default", "require", "node"]) {
927
+ const u = s(i[a]);
928
+ if (u) return u;
929
+ }
930
+ }
931
+ return null;
932
+ }, o = t.exports;
933
+ if (typeof o == "string") {
934
+ if (n === ".") return o;
935
+ } else if (o && typeof o == "object") {
936
+ const c = o;
937
+ if (Object.prototype.hasOwnProperty.call(c, n))
938
+ return s(c[n]);
939
+ for (const i of Object.keys(c)) {
940
+ const a = i.indexOf("*");
941
+ if (a < 0) continue;
942
+ const u = i.slice(0, a), l = i.slice(a + 1);
943
+ if (n.startsWith(u) && n.endsWith(l)) {
944
+ const p = n.slice(u.length, n.length - l.length), d = s(c[i]);
945
+ if (d) return d.replace("*", p);
946
+ }
947
+ }
948
+ return null;
949
+ }
950
+ if (n === ".")
951
+ for (const c of ["module", "main"]) {
952
+ const i = t[c];
953
+ if (typeof i == "string") return i;
954
+ }
955
+ return null;
956
+ }
957
+ function Ce(r, n) {
958
+ const t = r.split("?")[0];
959
+ if (!t || t.startsWith("\0") || t.startsWith("virtual:") || t.startsWith("data:") || t.startsWith("http:") || t.startsWith("https:"))
960
+ return null;
961
+ if (t.startsWith(".") || m.isAbsolute(t))
962
+ return V(m.resolve(m.dirname(n), t));
963
+ const o = (t.startsWith("@") ? t.split("/").slice(0, 2) : t.split("/").slice(0, 1)).join("/"), c = t.length > o.length ? `.${t.slice(o.length)}` : ".";
964
+ let i = m.dirname(n);
965
+ for (; ; ) {
966
+ const a = m.join(i, "node_modules", o);
967
+ if (b.existsSync(m.join(a, "package.json"))) {
968
+ const l = Fe(a, c);
969
+ if (l) {
970
+ const p = V(m.resolve(a, l));
971
+ if (p) return p;
972
+ }
973
+ return V(
974
+ m.resolve(a, c === "." ? "index" : c.slice(2))
975
+ );
976
+ }
977
+ const u = m.dirname(i);
978
+ if (u === i) return null;
979
+ i = u;
980
+ }
981
+ }
982
+ function z(r) {
983
+ return O(r, {
984
+ sourceType: "module",
985
+ plugins: ["typescript", "jsx"]
986
+ });
987
+ }
988
+ function q(r) {
989
+ const n = [], t = (s, o, c, i) => {
990
+ const a = [];
991
+ for (const u of i)
992
+ (e.isImportSpecifier(u) || e.isImportDefaultSpecifier(u) || e.isImportNamespaceSpecifier(u) || e.isExportSpecifier(u)) && a.push(u.local.name);
993
+ n.push({
994
+ spec: s,
995
+ line: o.loc?.start.line ?? 0,
996
+ kind: c,
997
+ locals: a
998
+ });
999
+ };
1000
+ return Ne(r, {
1001
+ ImportDeclaration(s) {
1002
+ s.node.importKind !== "type" && t(s.node.source.value, s.node, "static", s.node.specifiers);
1003
+ },
1004
+ ExportNamedDeclaration(s) {
1005
+ s.node.source && s.node.exportKind !== "type" && t(s.node.source.value, s.node, "static", s.node.specifiers);
1006
+ },
1007
+ ExportAllDeclaration(s) {
1008
+ s.node.exportKind !== "type" && t(s.node.source.value, s.node, "static", []);
1009
+ },
1010
+ CallExpression(s) {
1011
+ if (!e.isImport(s.node.callee)) return;
1012
+ const o = s.node.arguments[0];
1013
+ e.isStringLiteral(o) && t(o.value, s.node, "dynamic", []);
1014
+ },
1015
+ ImportExpression(s) {
1016
+ const o = s.node.source;
1017
+ e.isStringLiteral(o) && t(o.value, s.node, "dynamic", []);
1018
+ }
1019
+ }), n;
1020
+ }
1021
+ function Re(r, n) {
1022
+ const t = /* @__PURE__ */ new Set(), s = [];
1023
+ for (const o of r) {
1024
+ let c = -1;
1025
+ for (let i = 0; i < n.length; i++) {
1026
+ if (t.has(i)) continue;
1027
+ const a = n[i];
1028
+ if (a.spec === o.spec && a.kind === o.kind && !(o.locals.length > 0 && a.locals.length > 0 && !o.locals.some((l) => a.locals.includes(l)))) {
1029
+ c = i;
1030
+ break;
1031
+ }
1032
+ }
1033
+ s.push(c >= 0 ? n[c] : o), c >= 0 && t.add(c);
1034
+ }
1035
+ return s.sort((o, c) => o.line - c.line);
1036
+ }
1037
+ function Me(r, n) {
1038
+ return m.relative(r, n).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/");
1039
+ }
1040
+ function Ve(r, n, t, s, o) {
1041
+ const { rootDir: c, appDir: i } = n, a = m.relative(c, r).split(m.sep).join("/") || r;
1042
+ let u = 0;
1043
+ try {
1044
+ u = b.statSync(r).mtimeMs;
1045
+ } catch {
1046
+ }
1047
+ const l = o.get(r);
1048
+ if (l && l.info && l.mtimeMs === u) return l.info;
1049
+ const p = s.filter((E) => E.regex.test(a)).map((E) => E.glob), d = m.extname(r);
1050
+ if (!Pe.has(d)) {
1051
+ const E = { file: r, display: a, edges: [], builtins: [], patterns: p };
1052
+ return o.set(r, { mtimeMs: u, info: E }), E;
1053
+ }
1054
+ let y = "";
1055
+ try {
1056
+ y = b.readFileSync(r, "utf-8");
1057
+ } catch {
1058
+ y = "";
1059
+ }
1060
+ let h = [];
1061
+ try {
1062
+ h = q(z(y));
1063
+ } catch {
1064
+ h = [];
1065
+ }
1066
+ const _ = Z(y, {
1067
+ id: r,
1068
+ appDir: i,
1069
+ isSSR: !1,
1070
+ routesFile: n.routesFile,
1071
+ pathInfo: t.get(Me(i, r))
1072
+ }), v = _ ? _.code : y;
1073
+ let T;
1074
+ try {
1075
+ T = q(z(v));
1076
+ } catch {
1077
+ T = h;
1078
+ }
1079
+ const S = Re(T, h), I = [
1080
+ ...new Set(S.filter((E) => te(E.spec)).map((E) => E.spec))
1081
+ ].sort(), j = { file: r, display: a, edges: S, builtins: I, patterns: p };
1082
+ return o.set(r, { mtimeMs: u, info: j }), j;
1083
+ }
1084
+ const We = 8, Be = 100, Je = 2e4;
1085
+ function Ue(r) {
1086
+ const { rootDir: n, entrySpecs: t } = r, s = r.resolve ?? Ce, o = r.cache ?? /* @__PURE__ */ new Map(), c = (r.serverOnly ?? []).map((f) => ({
1087
+ glob: f,
1088
+ regex: De(f)
1089
+ })), i = /* @__PURE__ */ new Map(), a = m.join(r.appDir, r.routesFile ?? "routes.tsx");
1090
+ try {
1091
+ const f = b.readFileSync(a, "utf-8");
1092
+ for (const [g, x] of B(f))
1093
+ i.set(g, x);
1094
+ } catch {
1095
+ }
1096
+ const u = /* @__PURE__ */ new Map(), l = "virtual:velo/client-entry", p = m.join(r.appDir, "__velo_client_entry__.js"), d = (f, g) => {
1097
+ if (te(f)) return `builtin:${f}`;
1098
+ try {
1099
+ return s(f, g);
1100
+ } catch {
1101
+ return null;
1102
+ }
1103
+ }, y = (f) => {
1104
+ const g = u.get(f);
1105
+ if (g) return g;
1106
+ const x = Ve(f, r, i, c, o), L = {
1107
+ file: f,
1108
+ display: x.display,
1109
+ edges: [],
1110
+ builtins: x.builtins,
1111
+ patterns: x.patterns
1112
+ };
1113
+ u.set(f, L);
1114
+ for (const U of x.edges)
1115
+ L.edges.push({ ...U, target: d(U.spec, f) });
1116
+ return L;
1117
+ }, h = {
1118
+ file: null,
1119
+ display: l,
1120
+ edges: []
1121
+ };
1122
+ for (const f of t)
1123
+ h.edges.push({
1124
+ spec: f,
1125
+ line: 0,
1126
+ kind: "static",
1127
+ locals: [],
1128
+ target: d(f, p)
1129
+ });
1130
+ const _ = (f) => f.builtins.length > 0 || f.patterns.length > 0, v = (f) => {
1131
+ const g = [];
1132
+ if (f.builtins.length > 0) {
1133
+ const x = f.builtins.map((L) => `"${L}"`).join(", ");
1134
+ g.push(
1135
+ f.builtins.length === 1 ? `imports Node builtin ${x}` : `imports Node builtins ${x}`
1136
+ );
1137
+ }
1138
+ if (f.patterns.length > 0) {
1139
+ const x = f.patterns.map((L) => `"${L}"`).join(", ");
1140
+ g.push(
1141
+ f.patterns.length === 1 ? `matches serverOnly pattern ${x}` : `matches serverOnly patterns ${x}`
1142
+ );
1143
+ }
1144
+ return g;
1145
+ }, T = (f, g) => {
1146
+ let x = g.findIndex((L) => L.server);
1147
+ return x < 0 && (x = g.length - 1), {
1148
+ target: f.display,
1149
+ qualifiers: v(f),
1150
+ chain: g.map((L) => ({ from: L.from, line: L.line, to: L.to })),
1151
+ entryIndex: x
1152
+ };
1153
+ }, S = [], I = /* @__PURE__ */ new Map();
1154
+ let j = !1, E = Je;
1155
+ const k = [], $ = /* @__PURE__ */ new Set(), ne = (f, g) => {
1156
+ const x = I.get(f.display) ?? 0;
1157
+ if (x >= We || S.length >= Be) {
1158
+ j = !0;
1159
+ return;
1160
+ }
1161
+ I.set(f.display, x + 1), S.push(T(f, g));
1162
+ }, J = (f) => {
1163
+ for (const g of f.edges) {
1164
+ if (E-- <= 0) {
1165
+ j = !0;
1166
+ return;
1167
+ }
1168
+ if (!g.target || g.target.startsWith("builtin:")) continue;
1169
+ const x = y(g.target), L = {
1170
+ from: f.display,
1171
+ line: f.file === null ? null : g.line,
1172
+ to: x.display,
1173
+ server: _(x),
1174
+ targetNode: x
1175
+ };
1176
+ L.server && ne(x, [...k, L]), $.has(g.target) || ($.add(g.target), k.push(L), J(x), k.pop(), $.delete(g.target));
751
1177
  }
752
1178
  };
1179
+ J(h);
1180
+ const C = [];
1181
+ for (const f of u.values())
1182
+ for (const g of f.edges)
1183
+ C.push(
1184
+ `${f.display}|${g.line}|${g.kind}|${g.spec}|${g.target ?? ""}`
1185
+ );
1186
+ C.sort();
1187
+ const re = JSON.stringify({
1188
+ modules: [...u.values()].map((f) => f.display).sort(),
1189
+ edges: C
1190
+ });
1191
+ return {
1192
+ leaks: S,
1193
+ truncated: j,
1194
+ signature: re,
1195
+ moduleCount: u.size + 1
1196
+ };
1197
+ }
1198
+ function W(r) {
1199
+ const n = [];
1200
+ return r.leaks.length === 0 ? (n.push(
1201
+ "[velojs] server->client leak analysis: 0 leaks — what ships to the client is clean."
1202
+ ), n.join(`
1203
+ `)) : (n.push(
1204
+ `[velojs] server->client leak analysis: ${r.leaks.length} leak(s) in what ships to the client.`
1205
+ ), r.leaks.forEach((t, s) => {
1206
+ n.push(""), n.push(`${s + 1}) ${t.target}`), n.push(` server because: ${t.qualifiers.join("; ")}`), n.push(" import chain from the client entry:"), t.chain.forEach((o, c) => {
1207
+ const i = o.line === null ? `${o.from} (generated)` : `${o.from}:${o.line}`, a = c === t.entryIndex ? " <- entry point (cut here)" : "";
1208
+ n.push(` ${i} -> ${o.to}${a}`);
1209
+ });
1210
+ }), r.truncated && (n.push(""), n.push("... report truncated at its safety budget — more paths exist.")), n.push(""), n.push("The report is read-only: nothing is blocked or rewritten; the cut is yours."), n.join(`
1211
+ `));
753
1212
  }
754
1213
  export {
755
- F as buildFullPathMap,
756
- R as collectFullPaths,
757
- pe as declaredChannelNames,
758
- he as devServerExcludeFor,
759
- K as injectMetadata,
760
- ie as pruneClientOnlyImports,
761
- ue as readChannelMapNames,
762
- le as removeEndpointRoutes,
763
- se as removeLoaders,
764
- oe as removeMiddlewares,
765
- Z as transformActionsForClient,
766
- Q as transformLoaderFunctions,
767
- ne as transformSocketsForClient,
768
- re as transformStreamsForClient,
769
- Te as veloPlugin
1214
+ Ue as a,
1215
+ B as buildFullPathMap,
1216
+ ee as clientEntryModulePaths,
1217
+ X as collectFullPaths,
1218
+ Ce as d,
1219
+ Ee as declaredChannelNames,
1220
+ Y as declaredLiveActions,
1221
+ $e as devServerExcludeFor,
1222
+ W as f,
1223
+ De as g,
1224
+ te as i,
1225
+ ue as injectMetadata,
1226
+ Q as moduleIdFor,
1227
+ ve as pruneClientOnlyImports,
1228
+ be as readChannelMapNames,
1229
+ je as removeEndpointRoutes,
1230
+ ge as removeLoaders,
1231
+ xe as removeMiddlewares,
1232
+ fe as transformActionsForClient,
1233
+ pe as transformLoaderFunctions,
1234
+ Z as transformModuleCode,
1235
+ ye as transformSocketsForClient,
1236
+ he as transformStreamsForClient,
1237
+ tt as veloPlugin
770
1238
  };