@mauroandre/velojs 0.0.29 → 0.0.31

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/cli.js CHANGED
@@ -1,39 +1,43 @@
1
- import { spawnSync as c } from "node:child_process";
2
- import { resolve as a } from "node:path";
3
- const o = process.argv.slice(2), r = o[0], l = (e, t = []) => {
4
- const s = c(e, t, {
1
+ import { spawnSync as n } from "node:child_process";
2
+ import { resolve as l } from "node:path";
3
+ const i = process.argv.slice(2), c = i[0], d = (e, t = []) => {
4
+ const s = n(e, t, {
5
5
  stdio: "inherit",
6
6
  cwd: process.cwd()
7
7
  });
8
8
  process.exit(s.status ?? 0);
9
9
  }, p = () => {
10
- l("npx", ["vite", ...o.slice(1)]);
10
+ d("npx", ["vite", ...i.slice(1)]);
11
11
  }, u = (e) => {
12
12
  const t = Date.now().toString(36), s = {
13
13
  ...process.env,
14
14
  VELO_BUILD_HASH: t,
15
15
  ...e ? { VELO_STATIC: "1" } : {}
16
16
  };
17
- console.log("Building client..."), c("npx", ["vite", "build"], {
17
+ console.log("Building client...");
18
+ const o = n("npx", ["vite", "build"], {
18
19
  stdio: "inherit",
19
20
  cwd: process.cwd(),
20
21
  env: s
21
- }), console.log("Building server..."), c("npx", ["vite", "build", "--mode", "server"], {
22
+ });
23
+ o.status !== 0 && (console.error("Client build failed. Aborting."), process.exit(o.status ?? 1)), console.log("Building server...");
24
+ const r = n("npx", ["vite", "build", "--mode", "server"], {
22
25
  stdio: "inherit",
23
26
  cwd: process.cwd(),
24
27
  env: s
25
- }), console.log("Build complete!"), e && v();
28
+ });
29
+ r.status !== 0 && (console.error("Server build failed. Aborting."), process.exit(r.status ?? 1)), console.log("Build complete!"), e && v();
26
30
  }, v = async () => {
27
31
  process.env.NODE_ENV = "production", process.env.VELO_STATIC = "1";
28
- const t = await import(a(process.cwd(), "dist/server.js")), s = t.default, i = t.routes;
29
- (!s || !i) && (console.error("Failed to load app or routes from dist/server.js"), process.exit(1));
30
- const { generateStatic: d } = await import("./static.js");
31
- await d(s, i);
32
+ const t = await import(l(process.cwd(), "dist/server.js")), s = t.default, o = t.routes;
33
+ (!s || !o) && (console.error("Failed to load app or routes from dist/server.js"), process.exit(1));
34
+ const { generateStatic: r } = await import("./static.js");
35
+ await r(s, o);
32
36
  }, m = () => {
33
37
  process.env.NODE_ENV = "production";
34
- const e = a(process.cwd(), "dist/server.js");
35
- l("node", [e]);
36
- }, n = () => {
38
+ const e = l(process.cwd(), "dist/server.js");
39
+ d("node", [e]);
40
+ }, a = () => {
37
41
  console.log(`
38
42
  VeloJS CLI
39
43
 
@@ -55,17 +59,17 @@ Examples:
55
59
  velojs start
56
60
  `);
57
61
  };
58
- switch (r) {
62
+ switch (c) {
59
63
  case "init": {
60
64
  const { runInit: e } = await import("./init.js");
61
- await e(o[1]);
65
+ await e(i[1]);
62
66
  break;
63
67
  }
64
68
  case "dev":
65
69
  p();
66
70
  break;
67
71
  case "build": {
68
- const e = o.includes("--static");
72
+ const e = i.includes("--static");
69
73
  u(e);
70
74
  break;
71
75
  }
@@ -75,8 +79,8 @@ switch (r) {
75
79
  case "help":
76
80
  case "--help":
77
81
  case "-h":
78
- n();
82
+ a();
79
83
  break;
80
84
  default:
81
- r && console.error(`Unknown command: ${r}`), n(), process.exit(1);
85
+ c && console.error(`Unknown command: ${c}`), a(), process.exit(1);
82
86
  }
@@ -1,56 +1,56 @@
1
- import { jsx as o, jsxs as p, Fragment as $ } from "preact/jsx-runtime";
2
- import { useRouter as C, Link as S } from "wouter-preact";
3
- import { __veloUpdatePending as E } from "./hooks.js";
1
+ import { jsx as o, jsxs as p, Fragment as h } from "preact/jsx-runtime";
2
+ import { useRouter as L, Link as C } from "wouter-preact";
3
+ import { __veloUpdatePending as S } from "./hooks.js";
4
4
  function O({ basePath: e, favicon: t = "/favicon.ico" } = {}) {
5
5
  const n = process.env.NODE_ENV !== "production";
6
6
  e = e || process.env.STATIC_BASE_URL || (process.env.VELO_STATIC ? "/client" : "");
7
- const i = t !== !1 && /* @__PURE__ */ o("link", { rel: "icon", href: `${e}${t}`, type: "image/x-icon" });
7
+ const r = t === !1 ? void 0 : t.endsWith(".svg") ? "image/svg+xml" : t.endsWith(".png") ? "image/png" : "image/x-icon", i = t !== !1 && /* @__PURE__ */ o("link", { rel: "icon", href: `${e}${t}`, type: r });
8
8
  if (n)
9
- return /* @__PURE__ */ p($, { children: [
9
+ return /* @__PURE__ */ p(h, { children: [
10
10
  i,
11
11
  /* @__PURE__ */ o("script", { type: "module", src: "/@vite/client" }),
12
12
  /* @__PURE__ */ o("script", { type: "module", src: "/__velo_client.js" })
13
13
  ] });
14
- const r = globalThis.__veloClientJs || (typeof __VELO_CLIENT_JS__ < "u" ? __VELO_CLIENT_JS__ : "client.js"), c = globalThis.__veloClientCss || (typeof __VELO_CLIENT_CSS__ < "u" ? __VELO_CLIENT_CSS__ : "client.css");
15
- return /* @__PURE__ */ p($, { children: [
14
+ const l = globalThis.__veloClientJs || (typeof __VELO_CLIENT_JS__ < "u" ? __VELO_CLIENT_JS__ : "client.js"), c = globalThis.__veloClientCss || (typeof __VELO_CLIENT_CSS__ < "u" ? __VELO_CLIENT_CSS__ : "client.css");
15
+ return /* @__PURE__ */ p(h, { children: [
16
16
  i,
17
17
  /* @__PURE__ */ o("link", { rel: "stylesheet", href: `${e}/${c}` }),
18
- /* @__PURE__ */ o("script", { type: "module", src: `${e}/${r}` })
18
+ /* @__PURE__ */ o("script", { type: "module", src: `${e}/${l}` })
19
19
  ] });
20
20
  }
21
- function h(e, t) {
21
+ function $(e, t) {
22
22
  let n = e;
23
- for (const [i, r] of Object.entries(t))
24
- n = n.replace(`:${i}`, r);
23
+ for (const [r, i] of Object.entries(t))
24
+ n = n.replace(`:${r}`, i);
25
25
  return n;
26
26
  }
27
- function j({ to: e, params: t, search: n, absolute: i, ...r }) {
28
- const c = typeof e != "string", u = C(), f = c ? (i ? e.metadata?.fullPath : e.metadata?.path) ?? "/" : e, l = t ? h(f, t) : f, v = c && i ? `~${l}` : l, a = n ? `?${new URLSearchParams(n).toString()}` : "", L = `${v}${a}`;
29
- if (typeof window < "u" && E.value) {
30
- let _;
31
- if (c) {
27
+ function j({ to: e, params: t, search: n, absolute: r, ...i }) {
28
+ const l = typeof e != "string", c = L(), f = l ? (r ? e.metadata?.fullPath : e.metadata?.path) ?? "/" : e, _ = t ? $(f, t) : f, m = l && r ? `~${_}` : _, u = n ? `?${new URLSearchParams(n).toString()}` : "", g = `${m}${u}`;
29
+ if (typeof window < "u" && S.value) {
30
+ let a;
31
+ if (l) {
32
32
  const s = e.metadata?.fullPath ?? f;
33
- _ = `${t ? h(s, t) : s}${a}`;
33
+ a = `${t ? $(s, t) : s}${u}`;
34
34
  } else {
35
- const s = l.replace(/^~/, "");
36
- _ = `${!l.startsWith("~") && u.base ? u.base : ""}${s}${a}`;
35
+ const s = _.replace(/^~/, "");
36
+ a = `${!_.startsWith("~") && c.base ? c.base : ""}${s}${u}`;
37
37
  }
38
- const { onClick: d, ...m } = r;
38
+ const { onClick: d, ...v } = i;
39
39
  return /* @__PURE__ */ o(
40
40
  "a",
41
41
  {
42
- href: _,
42
+ href: a,
43
43
  onClick: (s) => {
44
- d && d(s), s.defaultPrevented || (s.preventDefault(), window.location.href = _);
44
+ d && d(s), s.defaultPrevented || (s.preventDefault(), window.location.href = a);
45
45
  },
46
- ...m
46
+ ...v
47
47
  }
48
48
  );
49
49
  }
50
- return /* @__PURE__ */ o(S, { to: L, ...r });
50
+ return /* @__PURE__ */ o(C, { to: g, ...i });
51
51
  }
52
52
  export {
53
53
  j as Link,
54
54
  O as Scripts,
55
- h as substituteParams
55
+ $ as substituteParams
56
56
  };
package/dist/vite.d.ts CHANGED
@@ -21,6 +21,27 @@ export declare function transformStreamsForClient(code: string, moduleId: string
21
21
  */
22
22
  export declare function transformSocketsForClient(code: string, moduleId: string): string;
23
23
  export declare function removeLoaders(code: string): string;
24
+ /**
25
+ * Removes import specifiers whose local binding is no longer referenced
26
+ * anywhere in the module after the client-only strips above (actions →
27
+ * fetch stubs, streams/sockets → stubs, loaders removed). Runs LAST so it
28
+ * sees the fully transformed AST.
29
+ *
30
+ * Why this is needed: under Rollup (vite 7) these orphaned imports were
31
+ * tree-shaken for free, keeping server-only code out of the client graph.
32
+ * Under Rolldown (vite 8) they survive — so a server-only helper imported
33
+ * top-level (e.g. an SSE `channel` resolver referenced only inside a now-
34
+ * stubbed `createEventStream({...})`) drags its entire service, and native
35
+ * `.node` deps, into the browser bundle and breaks the build. We replicate
36
+ * the tree-shake deterministically, inside our control.
37
+ *
38
+ * Safety:
39
+ * - Side-effect imports (`import "./x.css"`, no specifiers) are preserved.
40
+ * - `collectReferencedIdentifiers` counts value, type, and JSX positions,
41
+ * so a component used only in `<Foo />` is never dropped.
42
+ * - Only specifiers with zero remaining references are removed.
43
+ */
44
+ export declare function pruneClientOnlyImports(code: string): string;
24
45
  export declare function removeMiddlewares(code: string): string;
25
46
  /**
26
47
  * On client builds, strip EndpointRoute objects from the default-export array
package/dist/vite.js CHANGED
@@ -3,41 +3,41 @@ import S from "node:fs";
3
3
  import R from "@preact/preset-vite";
4
4
  import $ from "@hono/vite-dev-server";
5
5
  import { parse as _ } from "@babel/parser";
6
- import g from "@babel/traverse";
6
+ import b from "@babel/traverse";
7
7
  import j from "@babel/generator";
8
8
  import * as e from "@babel/types";
9
- const d = typeof g == "function" ? g : g.default, h = typeof j == "function" ? j : j.default;
10
- function U(p, c, i, n) {
11
- const o = _(p, {
9
+ const d = typeof b == "function" ? b : b.default, h = typeof j == "function" ? j : j.default;
10
+ function U(p, o, n, r) {
11
+ const c = _(p, {
12
12
  sourceType: "module",
13
13
  plugins: ["typescript", "jsx"]
14
14
  });
15
15
  let t = !1;
16
- if (d(o, {
16
+ if (d(c, {
17
17
  // Procura: export const metadata = { ... }
18
18
  ExportNamedDeclaration(l) {
19
19
  const a = l.node.declaration;
20
20
  if (e.isVariableDeclaration(a) && a.declarations.length === 1) {
21
- const r = a.declarations[0];
22
- if (r && e.isIdentifier(r.id, { name: "metadata" }) && e.isObjectExpression(r.init)) {
21
+ const i = a.declarations[0];
22
+ if (i && e.isIdentifier(i.id, { name: "metadata" }) && e.isObjectExpression(i.init)) {
23
23
  t = !0;
24
- const f = r.init.properties.filter((v) => e.isObjectProperty(v) && e.isIdentifier(v.key) ? v.key.name !== "moduleId" && v.key.name !== "fullPath" && v.key.name !== "path" : !0), m = [
24
+ const f = i.init.properties.filter((v) => e.isObjectProperty(v) && e.isIdentifier(v.key) ? v.key.name !== "moduleId" && v.key.name !== "fullPath" && v.key.name !== "path" : !0), m = [
25
25
  e.objectProperty(
26
26
  e.identifier("moduleId"),
27
- e.stringLiteral(c)
27
+ e.stringLiteral(o)
28
28
  )
29
29
  ];
30
- i !== void 0 && m.push(
30
+ n !== void 0 && m.push(
31
31
  e.objectProperty(
32
32
  e.identifier("fullPath"),
33
- e.stringLiteral(i)
33
+ e.stringLiteral(n)
34
34
  )
35
- ), n !== void 0 && m.push(
35
+ ), r !== void 0 && m.push(
36
36
  e.objectProperty(
37
37
  e.identifier("path"),
38
- e.stringLiteral(n)
38
+ e.stringLiteral(r)
39
39
  )
40
- ), r.init.properties = [...m, ...f];
40
+ ), i.init.properties = [...m, ...f];
41
41
  }
42
42
  }
43
43
  }
@@ -45,18 +45,18 @@ function U(p, c, i, n) {
45
45
  const l = [
46
46
  e.objectProperty(
47
47
  e.identifier("moduleId"),
48
- e.stringLiteral(c)
48
+ e.stringLiteral(o)
49
49
  )
50
50
  ];
51
- i !== void 0 && l.push(
51
+ n !== void 0 && l.push(
52
52
  e.objectProperty(
53
53
  e.identifier("fullPath"),
54
- e.stringLiteral(i)
54
+ e.stringLiteral(n)
55
55
  )
56
- ), n !== void 0 && l.push(
56
+ ), r !== void 0 && l.push(
57
57
  e.objectProperty(
58
58
  e.identifier("path"),
59
- e.stringLiteral(n)
59
+ e.stringLiteral(r)
60
60
  )
61
61
  );
62
62
  const a = e.exportNamedDeclaration(
@@ -67,50 +67,50 @@ function U(p, c, i, n) {
67
67
  )
68
68
  ])
69
69
  );
70
- o.program.body.unshift(a);
70
+ c.program.body.unshift(a);
71
71
  }
72
- return h(o, { retainLines: !0 }).code;
72
+ return h(c, { retainLines: !0 }).code;
73
73
  }
74
- function W(p, c) {
75
- const i = _(p, {
74
+ function W(p, o) {
75
+ const n = _(p, {
76
76
  sourceType: "module",
77
77
  plugins: ["typescript", "jsx"]
78
78
  });
79
- return d(i, {
80
- CallExpression(o) {
81
- const t = o.node.callee, s = e.isIdentifier(t, { name: "Loader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "Loader" }), l = e.isIdentifier(t, { name: "useLoader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "useLoader" });
79
+ return d(n, {
80
+ CallExpression(c) {
81
+ const t = c.node.callee, s = e.isIdentifier(t, { name: "Loader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "Loader" }), l = e.isIdentifier(t, { name: "useLoader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "useLoader" });
82
82
  if (!s && !l) return;
83
- const a = o.node.arguments, r = e.stringLiteral(c), u = a[0];
84
- e.isStringLiteral(u) && u.value.includes("/") || (o.node.arguments = [r, ...a]);
83
+ const a = c.node.arguments, i = e.stringLiteral(o), u = a[0];
84
+ e.isStringLiteral(u) && u.value.includes("/") || (c.node.arguments = [i, ...a]);
85
85
  }
86
- }), h(i, { retainLines: !0 }).code;
86
+ }), h(n, { retainLines: !0 }).code;
87
87
  }
88
- function J(p, c) {
89
- const i = _(p, {
88
+ function J(p, o) {
89
+ const n = _(p, {
90
90
  sourceType: "module",
91
91
  plugins: ["typescript", "jsx"]
92
92
  });
93
- return d(i, {
94
- ExportNamedDeclaration(o) {
95
- const t = o.node.declaration;
93
+ return d(n, {
94
+ ExportNamedDeclaration(c) {
95
+ const t = c.node.declaration;
96
96
  if (!e.isVariableDeclaration(t)) return;
97
97
  const s = t.declarations[0];
98
98
  if (!s || !e.isIdentifier(s.id)) return;
99
99
  const l = s.id.name;
100
100
  if (!l.startsWith("action_")) return;
101
- const a = l.replace("action_", ""), r = s.init;
102
- if (!e.isArrowFunctionExpression(r) || !r.async) return;
103
- const u = r.params, f = M(c, a, u);
104
- r.body = e.blockStatement([e.returnStatement(f)]), B(r, u);
101
+ const a = l.replace("action_", ""), i = s.init;
102
+ if (!e.isArrowFunctionExpression(i) || !i.async) return;
103
+ const u = i.params, f = M(o, a, u);
104
+ i.body = e.blockStatement([e.returnStatement(f)]), B(i, u);
105
105
  }
106
- }), h(i, { retainLines: !0 }).code;
106
+ }), h(n, { retainLines: !0 }).code;
107
107
  }
108
- function M(p, c, i) {
109
- const n = `/_action/${p}/${c}`;
110
- return i.length === 0 ? e.callExpression(
108
+ function M(p, o, n) {
109
+ const r = `/_action/${p}/${o}`;
110
+ return n.length === 0 ? e.callExpression(
111
111
  e.memberExpression(
112
112
  e.callExpression(e.identifier("fetch"), [
113
- e.stringLiteral(n),
113
+ e.stringLiteral(r),
114
114
  e.objectExpression([
115
115
  e.objectProperty(
116
116
  e.identifier("method"),
@@ -135,7 +135,7 @@ function M(p, c, i) {
135
135
  ) : e.callExpression(
136
136
  e.memberExpression(
137
137
  e.callExpression(e.identifier("fetch"), [
138
- e.stringLiteral(n),
138
+ e.stringLiteral(r),
139
139
  e.objectExpression([
140
140
  e.objectProperty(
141
141
  e.identifier("method"),
@@ -175,46 +175,46 @@ function M(p, c, i) {
175
175
  ]
176
176
  );
177
177
  }
178
- function B(p, c) {
179
- if (c.length === 0) return;
180
- const i = c[0];
181
- if (e.isObjectPattern(i)) {
182
- let n = null;
183
- if (e.isTSTypeAnnotation(i.typeAnnotation) && e.isTSTypeReference(i.typeAnnotation.typeAnnotation)) {
184
- const s = i.typeAnnotation.typeAnnotation;
185
- e.isIdentifier(s.typeName, { name: "ActionArgs" }) && s.typeParameters?.params[0] && (n = s.typeParameters.params[0]);
178
+ function B(p, o) {
179
+ if (o.length === 0) return;
180
+ const n = o[0];
181
+ if (e.isObjectPattern(n)) {
182
+ let r = null;
183
+ if (e.isTSTypeAnnotation(n.typeAnnotation) && e.isTSTypeReference(n.typeAnnotation.typeAnnotation)) {
184
+ const s = n.typeAnnotation.typeAnnotation;
185
+ e.isIdentifier(s.typeName, { name: "ActionArgs" }) && s.typeParameters?.params[0] && (r = s.typeParameters.params[0]);
186
186
  }
187
- const o = e.objectProperty(
187
+ const c = e.objectProperty(
188
188
  e.identifier("body"),
189
189
  e.identifier("body"),
190
190
  !1,
191
191
  !0
192
192
  // shorthand
193
- ), t = e.objectPattern([o]);
194
- n && (t.typeAnnotation = e.tsTypeAnnotation(
193
+ ), t = e.objectPattern([c]);
194
+ r && (t.typeAnnotation = e.tsTypeAnnotation(
195
195
  e.tsTypeLiteral([
196
196
  e.tsPropertySignature(
197
197
  e.identifier("body"),
198
- e.tsTypeAnnotation(n)
198
+ e.tsTypeAnnotation(r)
199
199
  )
200
200
  ])
201
201
  )), p.params = [t];
202
202
  }
203
203
  }
204
- function H(p, c) {
205
- const i = _(p, {
204
+ function H(p, o) {
205
+ const n = _(p, {
206
206
  sourceType: "module",
207
207
  plugins: ["typescript", "jsx"]
208
208
  });
209
- return d(i, {
210
- ExportNamedDeclaration(o) {
211
- const t = o.node.declaration;
209
+ return d(n, {
210
+ ExportNamedDeclaration(c) {
211
+ const t = c.node.declaration;
212
212
  if (!e.isVariableDeclaration(t)) return;
213
213
  const s = t.declarations[0];
214
214
  if (!s || !e.isIdentifier(s.id)) return;
215
215
  const l = s.id.name;
216
216
  if (!l.startsWith("stream_")) return;
217
- const a = l.replace("stream_", ""), r = `/_event/${c}/${a}`;
217
+ const a = l.replace("stream_", ""), i = `/_event/${o}/${a}`;
218
218
  s.init = e.objectExpression([
219
219
  e.objectProperty(
220
220
  e.identifier("__isVeloEventStream"),
@@ -222,26 +222,26 @@ function H(p, c) {
222
222
  ),
223
223
  e.objectProperty(
224
224
  e.identifier("__path"),
225
- e.stringLiteral(r)
225
+ e.stringLiteral(i)
226
226
  )
227
227
  ]), s.id.typeAnnotation = null;
228
228
  }
229
- }), h(i, { retainLines: !0 }).code;
229
+ }), h(n, { retainLines: !0 }).code;
230
230
  }
231
- function z(p, c) {
232
- const i = _(p, {
231
+ function z(p, o) {
232
+ const n = _(p, {
233
233
  sourceType: "module",
234
234
  plugins: ["typescript", "jsx"]
235
235
  });
236
- return d(i, {
237
- ExportNamedDeclaration(o) {
238
- const t = o.node.declaration;
236
+ return d(n, {
237
+ ExportNamedDeclaration(c) {
238
+ const t = c.node.declaration;
239
239
  if (!e.isVariableDeclaration(t)) return;
240
240
  const s = t.declarations[0];
241
241
  if (!s || !e.isIdentifier(s.id)) return;
242
242
  const l = s.id.name;
243
243
  if (!l.startsWith("socket_")) return;
244
- const a = l.replace("socket_", ""), r = `/_socket/${c}/${a}`;
244
+ const a = l.replace("socket_", ""), i = `/_socket/${o}/${a}`;
245
245
  s.init = e.objectExpression([
246
246
  e.objectProperty(
247
247
  e.identifier("__isVeloSocket"),
@@ -249,224 +249,244 @@ function z(p, c) {
249
249
  ),
250
250
  e.objectProperty(
251
251
  e.identifier("__path"),
252
- e.stringLiteral(r)
252
+ e.stringLiteral(i)
253
253
  )
254
254
  ]), s.id.typeAnnotation = null;
255
255
  }
256
- }), h(i, { retainLines: !0 }).code;
256
+ }), h(n, { retainLines: !0 }).code;
257
257
  }
258
258
  function G(p) {
259
- const c = _(p, {
259
+ const o = _(p, {
260
260
  sourceType: "module",
261
261
  plugins: ["typescript", "jsx"]
262
262
  });
263
- return d(c, {
264
- ExportNamedDeclaration(n) {
265
- const o = n.node.declaration;
266
- if (!e.isVariableDeclaration(o)) return;
267
- const t = o.declarations[0];
268
- !t || !e.isIdentifier(t.id) || t.id.name === "loader" && n.remove();
263
+ return d(o, {
264
+ ExportNamedDeclaration(r) {
265
+ const c = r.node.declaration;
266
+ if (!e.isVariableDeclaration(c)) return;
267
+ const t = c.declarations[0];
268
+ !t || !e.isIdentifier(t.id) || t.id.name === "loader" && r.remove();
269
269
  }
270
- }), h(c, { retainLines: !0 }).code;
270
+ }), h(o, { retainLines: !0 }).code;
271
271
  }
272
272
  function Y(p) {
273
- const c = _(p, {
273
+ const o = _(p, {
274
+ sourceType: "module",
275
+ plugins: ["typescript", "jsx"]
276
+ }), n = /* @__PURE__ */ new Set();
277
+ L(o.program, n);
278
+ let r = !1;
279
+ return d(o, {
280
+ ImportDeclaration(t) {
281
+ const s = t.node.specifiers;
282
+ if (s.length === 0) return;
283
+ const l = s.filter((a) => n.has(a.local.name));
284
+ l.length !== s.length && (r = !0, l.length === 0 ? t.remove() : t.node.specifiers = l);
285
+ }
286
+ }), r ? h(o, { retainLines: !0 }).code : p;
287
+ }
288
+ function X(p) {
289
+ const o = _(p, {
274
290
  sourceType: "module",
275
291
  plugins: ["typescript", "jsx"]
276
- }), i = /* @__PURE__ */ new Set();
277
- return d(c, {
278
- ObjectProperty(o) {
279
- if (e.isIdentifier(o.node.key, { name: "middlewares" }) && e.isArrayExpression(o.node.value)) {
280
- for (const t of o.node.value.elements)
281
- e.isIdentifier(t) && i.add(t.name);
282
- o.remove();
292
+ }), n = /* @__PURE__ */ new Set();
293
+ return d(o, {
294
+ ObjectProperty(c) {
295
+ if (e.isIdentifier(c.node.key, { name: "middlewares" }) && e.isArrayExpression(c.node.value)) {
296
+ for (const t of c.node.value.elements)
297
+ e.isIdentifier(t) && n.add(t.name);
298
+ c.remove();
283
299
  }
284
300
  }
285
- }), i.size === 0 ? p : (d(c, {
286
- ImportDeclaration(o) {
287
- const t = o.node.specifiers, s = t.filter((l) => {
301
+ }), n.size === 0 ? p : (d(o, {
302
+ ImportDeclaration(c) {
303
+ const t = c.node.specifiers, s = t.filter((l) => {
288
304
  if (e.isImportSpecifier(l)) {
289
305
  const a = l.local.name;
290
- return !i.has(a);
306
+ return !n.has(a);
291
307
  }
292
308
  return !0;
293
309
  });
294
- s.length === 0 ? o.remove() : s.length !== t.length && (o.node.specifiers = s);
310
+ s.length === 0 ? c.remove() : s.length !== t.length && (c.node.specifiers = s);
295
311
  }
296
- }), h(c, { retainLines: !0 }).code);
312
+ }), h(o, { retainLines: !0 }).code);
297
313
  }
298
- function O(p, c) {
299
- const i = (n) => {
300
- if (!(!n || typeof n != "object")) {
301
- if (Array.isArray(n)) {
302
- for (const o of n) i(o);
314
+ function L(p, o) {
315
+ const n = (r) => {
316
+ if (!(!r || typeof r != "object")) {
317
+ if (Array.isArray(r)) {
318
+ for (const c of r) n(c);
319
+ return;
320
+ }
321
+ if (r.type === "Identifier") {
322
+ o.add(r.name), r.typeAnnotation && n(r.typeAnnotation);
303
323
  return;
304
324
  }
305
- if (n.type === "Identifier") {
306
- c.add(n.name);
325
+ if (r.type === "JSXIdentifier") {
326
+ o.add(r.name);
307
327
  return;
308
328
  }
309
- if (n.type === "MemberExpression") {
310
- i(n.object), n.computed && i(n.property);
329
+ if (r.type === "MemberExpression") {
330
+ n(r.object), r.computed && n(r.property);
311
331
  return;
312
332
  }
313
- if ((n.type === "ObjectProperty" || n.type === "ObjectMethod") && !n.computed) {
314
- n.type === "ObjectProperty" ? i(n.value) : i(n.body);
333
+ if ((r.type === "ObjectProperty" || r.type === "ObjectMethod") && !r.computed) {
334
+ r.type === "ObjectProperty" ? n(r.value) : n(r.body);
315
335
  return;
316
336
  }
317
- if (!(n.type === "ImportSpecifier" || n.type === "ImportDefaultSpecifier" || n.type === "ImportNamespaceSpecifier"))
318
- for (const o of Object.keys(n))
319
- o === "loc" || o === "start" || o === "end" || o === "leadingComments" || o === "trailingComments" || o === "innerComments" || i(n[o]);
337
+ if (!(r.type === "ImportSpecifier" || r.type === "ImportDefaultSpecifier" || r.type === "ImportNamespaceSpecifier"))
338
+ for (const c of Object.keys(r))
339
+ c === "loc" || c === "start" || c === "end" || c === "leadingComments" || c === "trailingComments" || c === "innerComments" || n(r[c]);
320
340
  }
321
341
  };
322
- i(p);
342
+ n(p);
323
343
  }
324
344
  function q(p) {
325
- for (const c of p.properties)
326
- if (e.isObjectProperty(c) && e.isIdentifier(c.key) && c.key.name === "handler")
345
+ for (const o of p.properties)
346
+ if (e.isObjectProperty(o) && e.isIdentifier(o.key) && o.key.name === "handler")
327
347
  return !0;
328
348
  return !1;
329
349
  }
330
350
  function K(p) {
331
- for (const c of p.properties)
332
- if (e.isObjectProperty(c) && e.isIdentifier(c.key) && c.key.name === "children" && e.isArrayExpression(c.value))
333
- return c.value;
351
+ for (const o of p.properties)
352
+ if (e.isObjectProperty(o) && e.isIdentifier(o.key) && o.key.name === "children" && e.isArrayExpression(o.value))
353
+ return o.value;
334
354
  return null;
335
355
  }
336
356
  function Q(p) {
337
- const c = _(p, {
357
+ const o = _(p, {
338
358
  sourceType: "module",
339
359
  plugins: ["typescript", "jsx"]
340
- }), i = [], n = (a) => {
341
- for (let r = a.elements.length - 1; r >= 0; r--) {
342
- const u = a.elements[r];
360
+ }), n = [], r = (a) => {
361
+ for (let i = a.elements.length - 1; i >= 0; i--) {
362
+ const u = a.elements[i];
343
363
  if (!e.isObjectExpression(u)) continue;
344
364
  if (q(u)) {
345
- i.push(u), a.elements.splice(r, 1);
365
+ n.push(u), a.elements.splice(i, 1);
346
366
  continue;
347
367
  }
348
368
  const f = K(u);
349
- f && n(f);
369
+ f && r(f);
350
370
  }
351
371
  };
352
- if (d(c, {
372
+ if (d(o, {
353
373
  ExportDefaultDeclaration(a) {
354
- const r = a.node.declaration;
374
+ const i = a.node.declaration;
355
375
  let u = null;
356
- e.isArrayExpression(r) ? u = r : (e.isTSSatisfiesExpression(r) && e.isArrayExpression(r.expression) || e.isTSAsExpression(r) && e.isArrayExpression(r.expression)) && (u = r.expression), u && n(u);
376
+ e.isArrayExpression(i) ? u = i : (e.isTSSatisfiesExpression(i) && e.isArrayExpression(i.expression) || e.isTSAsExpression(i) && e.isArrayExpression(i.expression)) && (u = i.expression), u && r(u);
357
377
  }
358
- }), i.length === 0) return p;
359
- const o = /* @__PURE__ */ new Set();
360
- for (const a of i)
361
- O(a, o);
378
+ }), n.length === 0) return p;
379
+ const c = /* @__PURE__ */ new Set();
380
+ for (const a of n)
381
+ L(a, c);
362
382
  const t = /* @__PURE__ */ new Set();
363
- O(c.program, t);
383
+ L(o.program, t);
364
384
  const s = /* @__PURE__ */ new Set();
365
- for (const a of o)
385
+ for (const a of c)
366
386
  t.has(a) || s.add(a);
367
- return s.size > 0 && d(c, {
387
+ return s.size > 0 && d(o, {
368
388
  ImportDeclaration(a) {
369
- const r = a.node.specifiers, u = r.filter((f) => !s.has(f.local.name));
370
- u.length === 0 ? a.remove() : u.length !== r.length && (a.node.specifiers = u);
389
+ const i = a.node.specifiers, u = i.filter((f) => !s.has(f.local.name));
390
+ u.length === 0 ? a.remove() : u.length !== i.length && (a.node.specifiers = u);
371
391
  }
372
- }), h(c, { retainLines: !0 }).code;
392
+ }), h(o, { retainLines: !0 }).code;
373
393
  }
374
394
  function A(p) {
375
- const c = _(p, {
395
+ const o = _(p, {
376
396
  sourceType: "module",
377
397
  plugins: ["typescript", "jsx"]
378
- }), i = /* @__PURE__ */ new Map();
379
- d(c, {
398
+ }), n = /* @__PURE__ */ new Map();
399
+ d(o, {
380
400
  ImportDeclaration(t) {
381
401
  const s = t.node.source.value;
382
402
  for (const l of t.node.specifiers)
383
- e.isImportNamespaceSpecifier(l) && i.set(l.local.name, s);
403
+ e.isImportNamespaceSpecifier(l) && n.set(l.local.name, s);
384
404
  }
385
405
  });
386
- const n = /* @__PURE__ */ new Map();
387
- d(c, {
406
+ const r = /* @__PURE__ */ new Map();
407
+ d(o, {
388
408
  ExportDefaultDeclaration(t) {
389
409
  const s = t.node.declaration;
390
410
  let l = null;
391
- e.isArrayExpression(s) ? l = s : e.isTSSatisfiesExpression(s) && e.isArrayExpression(s.expression) && (l = s.expression), l && C(l.elements, "", n);
411
+ e.isArrayExpression(s) ? l = s : e.isTSSatisfiesExpression(s) && e.isArrayExpression(s.expression) && (l = s.expression), l && C(l.elements, "", r);
392
412
  }
393
413
  });
394
- const o = /* @__PURE__ */ new Map();
395
- for (const [t, s] of n) {
396
- const l = i.get(t);
414
+ const c = /* @__PURE__ */ new Map();
415
+ for (const [t, s] of r) {
416
+ const l = n.get(t);
397
417
  if (l) {
398
418
  const a = l.replace(/^\.\//, "").replace(/\.(tsx?|jsx?|js)$/, "");
399
- o.set(a, s);
419
+ c.set(a, s);
400
420
  }
401
421
  }
402
- return o;
422
+ return c;
403
423
  }
404
- function C(p, c, i) {
405
- for (const n of p) {
406
- if (!e.isObjectExpression(n)) continue;
407
- let o = "", t = c, s = null, l = null;
408
- for (const a of n.properties) {
424
+ function C(p, o, n) {
425
+ for (const r of p) {
426
+ if (!e.isObjectExpression(r)) continue;
427
+ let c = "", t = o, s = null, l = null;
428
+ for (const a of r.properties) {
409
429
  if (!e.isObjectProperty(a)) continue;
410
- const r = a.key, u = e.isIdentifier(r) ? r.name : null;
411
- u === "path" && e.isStringLiteral(a.value) && (o = a.value.value, o && !o.startsWith("/") ? t = c + "/" + o : t = c + o), u === "module" && e.isIdentifier(a.value) && (s = a.value.name), u === "children" && e.isArrayExpression(a.value) && (l = a.value);
430
+ const i = a.key, u = e.isIdentifier(i) ? i.name : null;
431
+ u === "path" && e.isStringLiteral(a.value) && (c = a.value.value, c && !c.startsWith("/") ? t = o + "/" + c : t = o + c), u === "module" && e.isIdentifier(a.value) && (s = a.value.name), u === "children" && e.isArrayExpression(a.value) && (l = a.value);
412
432
  }
413
433
  if (s) {
414
- const r = !l && o === "/" ? c || "/" : t;
415
- i.set(s, {
416
- fullPath: r,
417
- path: o
434
+ const i = !l && c === "/" ? o || "/" : t;
435
+ n.set(s, {
436
+ fullPath: i,
437
+ path: c
418
438
  });
419
439
  }
420
- l && C(l.elements, t, i);
440
+ l && C(l.elements, t, n);
421
441
  }
422
442
  }
423
- const E = "virtual:velo/server-entry", b = "virtual:velo/client-entry", P = "\0" + E, N = "\0" + b;
424
- function X(p, c) {
425
- let i = y.resolve(process.cwd(), c);
426
- const n = p.routesFile ?? "routes.tsx", o = /* @__PURE__ */ new Map();
443
+ const g = "virtual:velo/server-entry", E = "virtual:velo/client-entry", N = "\0" + g, P = "\0" + E;
444
+ function Z(p, o) {
445
+ let n = y.resolve(process.cwd(), o);
446
+ const r = p.routesFile ?? "routes.tsx", c = /* @__PURE__ */ new Map();
427
447
  return {
428
448
  name: "velo:transform",
429
449
  enforce: "pre",
430
450
  configResolved(t) {
431
- i = y.resolve(t.root, c);
451
+ n = y.resolve(t.root, o);
432
452
  },
433
453
  buildStart() {
434
- const t = y.join(i, n);
454
+ const t = y.join(n, r);
435
455
  if (S.existsSync(t)) {
436
456
  const s = S.readFileSync(t, "utf-8"), l = A(s);
437
- o.clear();
438
- for (const [a, r] of l)
439
- o.set(a, r);
457
+ c.clear();
458
+ for (const [a, i] of l)
459
+ c.set(a, i);
440
460
  }
441
461
  },
442
462
  handleHotUpdate({ file: t, server: s }) {
443
- const l = y.join(i, n);
463
+ const l = y.join(n, r);
444
464
  if (t === l) {
445
- const a = S.readFileSync(l, "utf-8"), r = A(a);
446
- o.clear();
447
- for (const [u, f] of r)
448
- o.set(u, f);
465
+ const a = S.readFileSync(l, "utf-8"), i = A(a);
466
+ c.clear();
467
+ for (const [u, f] of i)
468
+ c.set(u, f);
449
469
  return s.ws.send({ type: "full-reload" }), [];
450
470
  }
451
471
  },
452
472
  resolveId(t) {
453
- return t === E || t.endsWith(E) ? P : t === b || t.endsWith(b) || t === "/__velo_client.js" ? N : null;
473
+ return t === g || t.endsWith(g) ? N : t === E || t.endsWith(E) || t === "/__velo_client.js" ? P : null;
454
474
  },
455
475
  load(t) {
456
- const s = p.routesFile ?? "routes.tsx", l = p.serverInit ?? "server.tsx", a = p.clientInit ?? "client.tsx", r = y.join(i, s).replace(/\.tsx?$/, ".js"), u = y.join(i, l).replace(/\.tsx?$/, ".js"), f = y.join(i, a).replace(/\.tsx?$/, ".js");
457
- return t === P ? `
476
+ const s = p.routesFile ?? "routes.tsx", l = p.serverInit ?? "server.tsx", a = p.clientInit ?? "client.tsx", i = y.join(n, s).replace(/\.tsx?$/, ".js"), u = y.join(n, l).replace(/\.tsx?$/, ".js"), f = y.join(n, a).replace(/\.tsx?$/, ".js");
477
+ return t === N ? `
458
478
  globalThis.__veloBuildHash = __VELO_BUILD_HASH__;
459
479
  globalThis.__veloClientJs = __VELO_CLIENT_JS__;
460
480
  globalThis.__veloClientCss = __VELO_CLIENT_CSS__;
461
481
  import "${u}";
462
- import routes from "${r}";
482
+ import routes from "${i}";
463
483
  import { startServer } from "@mauroandre/velojs/server";
464
484
 
465
485
  export { routes };
466
486
  export default await startServer({ routes, port: __VELO_CONFIG_PORT__ });
467
- ` : t === N ? `
487
+ ` : t === P ? `
468
488
  import "${f}";
469
- import routes from "${r}";
489
+ import routes from "${i}";
470
490
  import { startClient } from "@mauroandre/velojs/client";
471
491
 
472
492
  startClient({ routes });
@@ -474,46 +494,46 @@ startClient({ routes });
474
494
  },
475
495
  transform(t, s, l) {
476
496
  const a = l?.ssr === !0;
477
- if (s.startsWith("\0") || s.includes("/.velojs/") || !s.endsWith(".tsx") && !s.endsWith(".ts") || !s.startsWith(i)) return null;
478
- let r = t, u = !1;
497
+ if (s.startsWith("\0") || s.includes("/.velojs/") || !s.endsWith(".tsx") && !s.endsWith(".ts") || !s.startsWith(n)) return null;
498
+ let i = t, u = !1;
479
499
  const f = /middlewares:\s*\[/.test(t), m = /export\s+(const|function)\s+Component/.test(
480
500
  t
481
- ), v = /export\s+(const|function)\s+loader/.test(t), D = /export\s+const\s+action_\w+/.test(t), L = /export\s+const\s+stream_\w+/.test(t), I = /export\s+const\s+socket_\w+/.test(t), w = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), F = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t), k = /\bhandler\s*:/.test(t), V = y.join(i, n);
482
- if (!a && f && (r = Y(r), u = !0), !a && k && s === V && (r = Q(r), u = !0), m || v || D || L || I || w || F) {
483
- const x = y.relative(i, s).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), T = o.get(x);
484
- r = U(r, x, T?.fullPath, T?.path), r = W(r, x), a || (r = J(
485
- r,
501
+ ), v = /export\s+(const|function)\s+loader/.test(t), D = /export\s+const\s+action_\w+/.test(t), I = /export\s+const\s+stream_\w+/.test(t), T = /export\s+const\s+socket_\w+/.test(t), w = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), k = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t), F = /\bhandler\s*:/.test(t), V = y.join(n, r);
502
+ if (!a && f && (i = X(i), u = !0), !a && F && s === V && (i = Q(i), u = !0), m || v || D || I || T || w || k) {
503
+ const x = y.relative(n, s).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), O = c.get(x);
504
+ i = U(i, x, O?.fullPath, O?.path), i = W(i, x), a || (i = J(
505
+ i,
486
506
  x
487
- )), !a && L && (r = H(
488
- r,
507
+ )), !a && I && (i = H(
508
+ i,
489
509
  x
490
- )), !a && I && (r = z(
491
- r,
510
+ )), !a && T && (i = z(
511
+ i,
492
512
  x
493
- )), a || (r = G(r)), u = !0;
513
+ )), a || (i = G(i)), a || (i = Y(i)), u = !0;
494
514
  }
495
515
  return u ? {
496
- code: r,
516
+ code: i,
497
517
  map: null
498
518
  } : null;
499
519
  }
500
520
  };
501
521
  }
502
- function Z(p) {
522
+ function ee(p) {
503
523
  return {
504
524
  name: "velo:config",
505
- config(c, { mode: i }) {
506
- const n = i === "server", o = i === "development", t = !!process.env.VELO_STATIC, s = Number(process.env.PORT) || p.port || 3e3;
525
+ config(o, { mode: n }) {
526
+ const r = n === "server", c = n === "development", t = !!process.env.VELO_STATIC, s = Number(process.env.PORT) || p.port || 3e3;
507
527
  let l = "client.js", a = "client.css";
508
- if (n)
528
+ if (r)
509
529
  try {
510
- const u = y.resolve(process.cwd(), "dist/client/.vite/manifest.json"), m = JSON.parse(S.readFileSync(u, "utf-8"))[b];
530
+ const u = y.resolve(process.cwd(), "dist/client/.vite/manifest.json"), m = JSON.parse(S.readFileSync(u, "utf-8"))[E];
511
531
  m && (l = m.file || l, m.css?.[0] && (a = m.css[0]));
512
532
  } catch {
513
533
  }
514
- const r = {
534
+ const i = {
515
535
  define: {
516
- "process.env.NODE_ENV": JSON.stringify(o ? "development" : "production"),
536
+ "process.env.NODE_ENV": JSON.stringify(c ? "development" : "production"),
517
537
  "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (t ? "/client" : "")),
518
538
  __VELO_STATIC__: JSON.stringify(t),
519
539
  __VELO_BUILD_HASH__: JSON.stringify(process.env.VELO_BUILD_HASH || Date.now().toString(36)),
@@ -533,8 +553,8 @@ function Z(p) {
533
553
  port: s
534
554
  }
535
555
  };
536
- return n ? r.build = {
537
- ssr: E,
556
+ return r ? i.build = {
557
+ ssr: g,
538
558
  outDir: "dist",
539
559
  emptyOutDir: !1,
540
560
  copyPublicDir: !1,
@@ -543,50 +563,50 @@ function Z(p) {
543
563
  entryFileNames: "server.js"
544
564
  }
545
565
  }
546
- } : o || (r.build = {
566
+ } : c || (i.build = {
547
567
  manifest: !0,
548
568
  outDir: "dist/client",
549
569
  rollupOptions: {
550
- input: b,
570
+ input: E,
551
571
  output: {
552
572
  entryFileNames: "client.[hash].js",
553
573
  assetFileNames: (u) => u.names?.[0]?.endsWith(".css") ? "client.[hash].css" : "[name].[hash][extname]"
554
574
  }
555
575
  }
556
- }), r;
576
+ }), i;
557
577
  }
558
578
  };
559
579
  }
560
- function ee() {
580
+ function te() {
561
581
  return {
562
582
  name: "velo:static-url",
563
583
  apply: "build",
564
584
  enforce: "post",
565
- generateBundle(p, c) {
566
- const i = process.env.STATIC_BASE_URL || "";
567
- if (i)
568
- for (const n of Object.values(c))
569
- n.type === "asset" && typeof n.source == "string" && n.fileName.endsWith(".css") && (n.source = n.source.replace(
585
+ generateBundle(p, o) {
586
+ const n = process.env.STATIC_BASE_URL || "";
587
+ if (n)
588
+ for (const r of Object.values(o))
589
+ r.type === "asset" && typeof r.source == "string" && r.fileName.endsWith(".css") && (r.source = r.source.replace(
570
590
  /url\(\s*(['"]?)\/(?!\/)/g,
571
- `url($1${i}/`
591
+ `url($1${n}/`
572
592
  ));
573
593
  }
574
594
  };
575
595
  }
576
- function le(p) {
577
- const c = p ?? {}, i = c.appDirectory ?? "./app";
596
+ function pe(p) {
597
+ const o = p ?? {}, n = o.appDirectory ?? "./app";
578
598
  return [
579
- Z(c),
580
- X(c, i),
581
- ee(),
599
+ ee(o),
600
+ Z(o, n),
601
+ te(),
582
602
  R(),
583
603
  $({
584
- entry: E
604
+ entry: g
585
605
  }),
586
- te()
606
+ re()
587
607
  ];
588
608
  }
589
- function te() {
609
+ function re() {
590
610
  return {
591
611
  name: "velo:ws-bridge",
592
612
  configureServer(p) {
@@ -598,12 +618,13 @@ export {
598
618
  A as buildFullPathMap,
599
619
  C as collectFullPaths,
600
620
  U as injectMetadata,
621
+ Y as pruneClientOnlyImports,
601
622
  Q as removeEndpointRoutes,
602
623
  G as removeLoaders,
603
- Y as removeMiddlewares,
624
+ X as removeMiddlewares,
604
625
  J as transformActionsForClient,
605
626
  W as transformLoaderFunctions,
606
627
  z as transformSocketsForClient,
607
628
  H as transformStreamsForClient,
608
- le as veloPlugin
629
+ pe as veloPlugin
609
630
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mauroandre/velojs",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "type": "module",
5
5
  "description": "Fullstack web framework built on Hono + Preact with Vite-powered AST transforms",
6
6
  "keywords": [
@@ -95,7 +95,7 @@
95
95
  "hono": "^4.12.0",
96
96
  "preact": "^10.29.0",
97
97
  "preact-render-to-string": "^6.6.0",
98
- "vite": "^7.3.0",
98
+ "vite": "^7.3.0 || ^8.0.0",
99
99
  "wouter-preact": "^3.9.0"
100
100
  },
101
101
  "devDependencies": {