@mauroandre/velojs 0.0.58 → 0.0.60

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