@mauroandre/velojs 0.0.6 → 0.0.8

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,20 +1,35 @@
1
- import { spawnSync as o } from "node:child_process";
2
- import { resolve as l } from "node:path";
3
- const r = process.argv.slice(2), s = r[0], c = (e, n = []) => {
4
- const i = o(e, n, {
1
+ import { spawnSync as c } from "node:child_process";
2
+ import { resolve as a } from "node:path";
3
+ const t = process.argv.slice(2), r = t[0], l = (e, s = []) => {
4
+ const o = c(e, s, {
5
5
  stdio: "inherit",
6
6
  cwd: process.cwd()
7
7
  });
8
- process.exit(i.status ?? 0);
9
- }, a = () => {
10
- c("npx", ["vite", ...r.slice(1)]);
11
- }, d = () => {
12
- console.log("Building client..."), o("npx", ["vite", "build"], { stdio: "inherit", cwd: process.cwd() }), console.log("Building server..."), o("npx", ["vite", "build", "--mode", "server"], { stdio: "inherit", cwd: process.cwd() }), console.log("Build complete!");
8
+ process.exit(o.status ?? 0);
13
9
  }, p = () => {
10
+ l("npx", ["vite", ...t.slice(1)]);
11
+ }, v = (e) => {
12
+ const s = e ? { ...process.env, VELO_STATIC: "1" } : process.env;
13
+ console.log("Building client..."), c("npx", ["vite", "build"], {
14
+ stdio: "inherit",
15
+ cwd: process.cwd(),
16
+ env: s
17
+ }), console.log("Building server..."), c("npx", ["vite", "build", "--mode", "server"], {
18
+ stdio: "inherit",
19
+ cwd: process.cwd(),
20
+ env: s
21
+ }), console.log("Build complete!"), e && u();
22
+ }, u = async () => {
23
+ process.env.NODE_ENV = "production", process.env.VELO_STATIC = "1";
24
+ const s = await import(a(process.cwd(), "dist/server.js")), o = s.default, i = s.routes;
25
+ (!o || !i) && (console.error("Failed to load app or routes from dist/server.js"), process.exit(1));
26
+ const { generateStatic: d } = await import("./static.js");
27
+ await d(o, i);
28
+ }, m = () => {
14
29
  process.env.NODE_ENV = "production";
15
- const e = l(process.cwd(), "dist/server.js");
16
- c("node", [e]);
17
- }, t = () => {
30
+ const e = a(process.cwd(), "dist/server.js");
31
+ l("node", [e]);
32
+ }, n = () => {
18
33
  console.log(`
19
34
  VeloJS CLI
20
35
 
@@ -22,38 +37,42 @@ Usage:
22
37
  velojs <command>
23
38
 
24
39
  Commands:
25
- init Create a new VeloJS project
26
- dev Start development server
27
- build Build for production (client + server)
28
- start Start production server
40
+ init Create a new VeloJS project
41
+ dev Start development server
42
+ build Build for production (client + server)
43
+ build --static Build as static site (HTML + JSON)
44
+ start Start production server
29
45
 
30
46
  Examples:
31
47
  velojs init my-app
32
48
  velojs dev
33
49
  velojs build
50
+ velojs build --static
34
51
  velojs start
35
52
  `);
36
53
  };
37
- switch (s) {
54
+ switch (r) {
38
55
  case "init": {
39
56
  const { runInit: e } = await import("./init.js");
40
- await e(r[1]);
57
+ await e(t[1]);
41
58
  break;
42
59
  }
43
60
  case "dev":
44
- a();
61
+ p();
45
62
  break;
46
- case "build":
47
- d();
63
+ case "build": {
64
+ const e = t.includes("--static");
65
+ v(e);
48
66
  break;
67
+ }
49
68
  case "start":
50
- p();
69
+ m();
51
70
  break;
52
71
  case "help":
53
72
  case "--help":
54
73
  case "-h":
55
- t();
74
+ n();
56
75
  break;
57
76
  default:
58
- s && console.error(`Unknown command: ${s}`), t(), process.exit(1);
77
+ r && console.error(`Unknown command: ${r}`), n(), process.exit(1);
59
78
  }
package/dist/hooks.js CHANGED
@@ -1,72 +1,77 @@
1
1
  import { signal as f, useSignal as _ } from "@preact/signals";
2
- import { useEffect as v } from "preact/hooks";
3
- import { useLocation as d, useParams as w } from "wouter-preact";
4
- function p(e) {
2
+ import { useEffect as w } from "preact/hooks";
3
+ import { useLocation as d, useParams as g } from "wouter-preact";
4
+ function S(e) {
5
5
  e.value !== null && typeof e.value == "object" && (e.value = { ...e.value });
6
6
  }
7
7
  function y(e) {
8
- const t = f(!1);
8
+ const a = f(!1);
9
9
  if (typeof window > "u")
10
10
  return { data: {
11
11
  get value() {
12
12
  return e ? globalThis.__veloServerData?.getStore?.()?.[e] ?? null : null;
13
13
  }
14
- }, loading: t };
15
- const a = window.__PAGE_DATA__, r = e && a?.[e] ? a[e] : null;
16
- return { data: f(r), loading: t };
14
+ }, loading: a };
15
+ const t = window.__PAGE_DATA__, r = e && t?.[e] ? t[e] : null;
16
+ return { data: f(r), loading: a };
17
17
  }
18
- function S(e, t) {
19
- let a, r;
20
- Array.isArray(e) ? r = e : (a = e, r = t);
18
+ function m(e, a) {
19
+ let t, r;
20
+ Array.isArray(e) ? r = e : (t = e, r = a);
21
21
  let n = null;
22
- if (typeof window > "u" && a) {
23
- const i = globalThis.__veloServerData?.getStore?.();
24
- i?.[a] && (n = i[a]);
22
+ if (typeof window > "u" && t) {
23
+ const c = globalThis.__veloServerData?.getStore?.();
24
+ c?.[t] && (n = c[t]);
25
25
  }
26
- if (typeof window < "u" && a) {
26
+ if (typeof window < "u" && t) {
27
27
  const o = window.__PAGE_DATA__;
28
- o?.[a] && (n = o[a], delete o[a]);
28
+ o?.[t] && (n = o[t], delete o[t]);
29
29
  }
30
- const c = _(n), s = _(!1), l = () => {
31
- if (typeof window > "u" || !a) return;
32
- const o = window.location.pathname, i = new URLSearchParams(window.location.search);
33
- i.set("_data", "1"), s.value = !0, fetch(`${o}?${i.toString()}`).then((u) => u.json()).then((u) => {
34
- c.value = u[a], s.value = !1;
35
- }).catch((u) => {
36
- console.error("Erro ao carregar dados:", u), s.value = !1;
30
+ const u = _(n), i = _(!1), l = () => {
31
+ if (typeof window > "u" || !t) return;
32
+ const o = window.location.pathname;
33
+ i.value = !0;
34
+ const v = typeof __VELO_STATIC__ < "u" && __VELO_STATIC__ ? `${o === "/" ? "" : o}/index.json` : (() => {
35
+ const s = new URLSearchParams(window.location.search);
36
+ return s.set("_data", "1"), `${o}?${s.toString()}`;
37
+ })();
38
+ fetch(v).then((s) => s.json()).then((s) => {
39
+ u.value = s[t], i.value = !1;
40
+ }).catch((s) => {
41
+ console.error("Erro ao carregar dados:", s), i.value = !1;
37
42
  });
38
43
  };
39
- return v(() => {
44
+ return w(() => {
40
45
  n === null && l();
41
- }, r ?? []), { data: c, loading: s, refetch: l };
46
+ }, r ?? []), { data: u, loading: i, refetch: l };
42
47
  }
43
- function m() {
48
+ function A() {
44
49
  const [, e] = d();
45
50
  return e;
46
51
  }
47
52
  function P() {
48
- return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : w();
53
+ return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : g();
49
54
  }
50
- function A() {
55
+ function T() {
51
56
  if (typeof window > "u")
52
57
  return globalThis.__veloServerData?.getStore?.()?.__query ?? {};
53
58
  const e = window.__PAGE_DATA__;
54
59
  if (e?.__query)
55
60
  return e.__query;
56
- const t = new URLSearchParams(window.location.search), a = {};
57
- return t.forEach((r, n) => {
58
- a[n] = r;
59
- }), a;
61
+ const a = new URLSearchParams(window.location.search), t = {};
62
+ return a.forEach((r, n) => {
63
+ t[n] = r;
64
+ }), t;
60
65
  }
61
- function T() {
66
+ function E() {
62
67
  return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (d(), window.location.pathname);
63
68
  }
64
69
  export {
65
70
  y as Loader,
66
- p as touch,
67
- S as useLoader,
68
- m as useNavigate,
71
+ S as touch,
72
+ m as useLoader,
73
+ A as useNavigate,
69
74
  P as useParams,
70
- T as usePathname,
71
- A as useQuery
75
+ E as usePathname,
76
+ T as useQuery
72
77
  };
package/dist/server.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { jsx as h } from "preact/jsx-runtime";
2
2
  import { Hono as T } from "hono";
3
3
  import { logger as A } from "hono/logger";
4
- import { trimTrailingSlash as R } from "hono/trailing-slash";
5
- import { render as D } from "preact-render-to-string";
4
+ import { trimTrailingSlash as D } from "hono/trailing-slash";
5
+ import { render as R } from "preact-render-to-string";
6
6
  import { Router as N } from "wouter-preact";
7
7
  import { AsyncLocalStorage as O } from "node:async_hooks";
8
8
  const v = new O();
@@ -25,12 +25,12 @@ const w = [];
25
25
  function B(t) {
26
26
  w.push(t);
27
27
  }
28
- const b = (t, e, o) => {
28
+ const I = (t, e, o) => {
29
29
  if (t.req.query("_data") === "1")
30
30
  return t.json(o ?? null);
31
31
  const s = t.req.path, r = v.run(
32
32
  o ?? {},
33
- () => D(/* @__PURE__ */ h(N, { ssrPath: s, children: e }))
33
+ () => R(/* @__PURE__ */ h(N, { ssrPath: s, children: e }))
34
34
  );
35
35
  if (!o)
36
36
  return t.html(r);
@@ -38,7 +38,7 @@ const b = (t, e, o) => {
38
38
  o
39
39
  )}<\/script>`;
40
40
  return t.html(r.replace("</head>", `${a}</head>`));
41
- }, j = async (t, e) => {
41
+ }, b = async (t, e) => {
42
42
  const o = e.req.param(), s = e.req.query(), r = { params: o, query: s, c: e }, a = await Promise.all(
43
43
  t.map(async (n) => {
44
44
  if (!n.loader) return null;
@@ -56,7 +56,7 @@ const b = (t, e, o) => {
56
56
  components: t.map((n) => n.Component),
57
57
  data: c
58
58
  };
59
- }, I = (t) => {
59
+ }, j = (t) => {
60
60
  if (t.length === 0) return null;
61
61
  const e = t.filter(Boolean);
62
62
  if (e.length === 0) return null;
@@ -88,13 +88,13 @@ const b = (t, e, o) => {
88
88
  continue;
89
89
  }
90
90
  const u = async (i) => {
91
- const { components: d, data: f } = await j(a, i), l = I(d);
92
- return b(i, l, f);
91
+ const { components: d, data: f } = await b(a, i), l = j(d);
92
+ return I(i, l, f);
93
93
  };
94
94
  c.length > 0 ? t.on(["GET"], [n], ...c, u) : t.on(["GET"], [n], u);
95
95
  }
96
96
  }
97
- }, P = (t, e, o = []) => {
97
+ }, q = (t, e, o = []) => {
98
98
  for (const s of e) {
99
99
  const r = s.module.metadata?.moduleId, a = [
100
100
  ...o,
@@ -113,18 +113,18 @@ const b = (t, e, o) => {
113
113
  _ = await l.req.json();
114
114
  } catch {
115
115
  }
116
- const q = {
116
+ const E = {
117
117
  body: _,
118
118
  params: l.req.param(),
119
119
  query: l.req.query(),
120
120
  c: l
121
121
  };
122
122
  try {
123
- const m = await i(q);
123
+ const m = await i(E);
124
124
  return l.json(m ?? { ok: !0 });
125
125
  } catch (m) {
126
- const E = m instanceof Error ? m.message : "Action failed";
127
- return l.json({ error: E }, 500);
126
+ const P = m instanceof Error ? m.message : "Action failed";
127
+ return l.json({ error: P }, 500);
128
128
  }
129
129
  };
130
130
  a.length > 0 ? t.on(
@@ -136,25 +136,25 @@ const b = (t, e, o) => {
136
136
  }
137
137
  }
138
138
  }
139
- s.children && P(t, s.children, a);
139
+ s.children && q(t, s.children, a);
140
140
  }
141
141
  }, C = async (t) => {
142
142
  const e = new T();
143
- e.use(R()), process.env.NODE_ENV !== "production" && e.use("*", A());
143
+ e.use(D()), process.env.NODE_ENV !== "production" && e.use("*", A());
144
144
  for (const o of w)
145
145
  await o(e);
146
- if (S(e, t), P(e, t), process.env.NODE_ENV !== "production" && !p) {
146
+ if (S(e, t), q(e, t), process.env.NODE_ENV !== "production" && !p) {
147
147
  const o = globalThis.__veloDevServer;
148
148
  o && y(o);
149
149
  }
150
150
  return e;
151
151
  }, K = async (t) => {
152
152
  const { routes: e, port: o = Number(process.env.SERVER_PORT) || 3e3 } = t, s = await C(e);
153
- if (process.env.NODE_ENV === "production") {
154
- const { serve: r } = await import("@hono/node-server"), { serveStatic: a } = await import("@hono/node-server/serve-static"), { dirname: c, join: n } = await import("node:path"), { fileURLToPath: u } = await import("node:url"), i = c(u(import.meta.url)), d = n(i, "client");
155
- (process.env.STATIC_BASE_URL || "").startsWith("http") || s.use("/*", a({ root: d })), console.log(`Server running on http://localhost:${o}`);
156
- const l = r({ fetch: s.fetch, port: o });
157
- y(l);
153
+ if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
154
+ const { serve: r } = await import("@hono/node-server"), { serveStatic: a } = await import("@hono/node-server/serve-static"), { join: c } = await import("node:path"), n = c(process.cwd(), "dist/client");
155
+ (process.env.STATIC_BASE_URL || "").startsWith("http") || s.use("/*", a({ root: n })), console.log(`Server running on http://localhost:${o}`);
156
+ const i = r({ fetch: s.fetch, port: o });
157
+ y(i);
158
158
  }
159
159
  return s;
160
160
  };
@@ -0,0 +1,7 @@
1
+ import type { Hono } from "hono";
2
+ import type { AppRoutes } from "./types.js";
3
+ /**
4
+ * Generates a fully static site from a VeloJS app.
5
+ * Called by `velojs build --static` after the normal build.
6
+ */
7
+ export declare function generateStatic(app: Hono, routes: AppRoutes): Promise<void>;
package/dist/static.js ADDED
@@ -0,0 +1,62 @@
1
+ import f from "node:fs";
2
+ import r from "node:path";
3
+ async function h(a, n = "") {
4
+ const o = [];
5
+ for (const t of a) {
6
+ const s = t.module.metadata?.fullPath ?? "";
7
+ if (t.children) {
8
+ const e = await h(t.children, s);
9
+ o.push(...e);
10
+ } else {
11
+ const e = t.module.metadata?.fullPath;
12
+ if (!e) continue;
13
+ const l = Object.keys(t.module).filter((c) => c.startsWith("action_"));
14
+ if (l.length > 0 && console.warn(
15
+ `⚠ Route ${e} has actions (${l.join(", ")}) — they won't work in static mode`
16
+ ), e.includes(":")) {
17
+ const c = t.module.staticPaths;
18
+ if (typeof c == "function") {
19
+ const i = await c();
20
+ for (const d of i) {
21
+ let u = e;
22
+ for (const [m, p] of Object.entries(d))
23
+ u = u.replace(`:${m}`, p);
24
+ o.push({ fullPath: u, module: t.module });
25
+ }
26
+ } else
27
+ console.warn(
28
+ `Skipping ${e} — dynamic route without staticPaths export`
29
+ );
30
+ } else
31
+ o.push({ fullPath: e, module: t.module });
32
+ }
33
+ }
34
+ return o;
35
+ }
36
+ async function w(a, n, o) {
37
+ const t = "http://localhost", s = await a.fetch(new Request(`${t}${n}`));
38
+ if (s.status !== 200) {
39
+ console.warn(`Skipping ${n} — got status ${s.status}`);
40
+ return;
41
+ }
42
+ const e = await s.text(), c = await (await a.fetch(
43
+ new Request(`${t}${n}?_data=1`)
44
+ )).text(), i = n === "/" ? o : r.join(o, n);
45
+ f.mkdirSync(i, { recursive: !0 }), f.writeFileSync(r.join(i, "index.html"), e), f.writeFileSync(r.join(i, "index.json"), c);
46
+ }
47
+ async function $(a, n) {
48
+ const o = r.resolve(process.cwd(), "dist");
49
+ console.log("Generating static pages...");
50
+ const t = await h(n);
51
+ if (t.length === 0) {
52
+ console.warn("No routes found for static generation.");
53
+ return;
54
+ }
55
+ for (const s of t)
56
+ await w(a, s.fullPath, o), console.log(` ✓ ${s.fullPath}`);
57
+ console.log(`
58
+ Generated ${t.length} static pages.`);
59
+ }
60
+ export {
61
+ $ as generateStatic
62
+ };
package/dist/types.d.ts CHANGED
@@ -20,6 +20,7 @@ export interface Metadata {
20
20
  export interface RouteModule {
21
21
  Component: ComponentType<any>;
22
22
  loader?: (args: LoaderArgs) => Promise<any>;
23
+ staticPaths?: () => Promise<Record<string, string>[]>;
23
24
  metadata?: Metadata;
24
25
  [key: `action_${string}`]: (args: ActionArgs<any>) => Promise<any>;
25
26
  }
package/dist/vite.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import d from "node:path";
2
- import E from "node:fs";
3
- import w from "@preact/preset-vite";
4
- import C from "@hono/vite-dev-server";
2
+ import j from "node:fs";
3
+ import C from "@preact/preset-vite";
4
+ import O from "@hono/vite-dev-server";
5
5
  import { parse as v } from "@babel/parser";
6
6
  import L from "@babel/traverse";
7
- import I from "@babel/generator";
7
+ import S from "@babel/generator";
8
8
  import * as e from "@babel/types";
9
- const m = typeof L == "function" ? L : L.default, h = typeof I == "function" ? I : I.default;
10
- function R(u, o, r, l) {
11
- const n = v(u, {
9
+ const m = typeof L == "function" ? L : L.default, h = typeof S == "function" ? S : S.default;
10
+ function w(u, o, r, l) {
11
+ const i = v(u, {
12
12
  sourceType: "module",
13
13
  plugins: ["typescript", "jsx"]
14
14
  });
15
15
  let t = !1;
16
- if (m(n, {
16
+ if (m(i, {
17
17
  // Procura: export const metadata = { ... }
18
18
  ExportNamedDeclaration(s) {
19
19
  const c = s.node.declaration;
@@ -67,45 +67,45 @@ function R(u, o, r, l) {
67
67
  )
68
68
  ])
69
69
  );
70
- n.program.body.unshift(c);
70
+ i.program.body.unshift(c);
71
71
  }
72
- return h(n, { retainLines: !0 }).code;
72
+ return h(i, { retainLines: !0 }).code;
73
73
  }
74
- function O(u, o) {
74
+ function R(u, o) {
75
75
  const r = v(u, {
76
76
  sourceType: "module",
77
77
  plugins: ["typescript", "jsx"]
78
78
  });
79
79
  return m(r, {
80
- CallExpression(n) {
81
- const t = n.node.callee, i = e.isIdentifier(t, { name: "Loader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "Loader" }), s = e.isIdentifier(t, { name: "useLoader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "useLoader" });
82
- if (!i && !s) return;
83
- const c = n.node.arguments, a = e.stringLiteral(o), p = c[0];
84
- e.isStringLiteral(p) && p.value.includes("/") || (n.node.arguments = [a, ...c]);
80
+ CallExpression(i) {
81
+ const t = i.node.callee, n = e.isIdentifier(t, { name: "Loader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "Loader" }), s = e.isIdentifier(t, { name: "useLoader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "useLoader" });
82
+ if (!n && !s) return;
83
+ const c = i.node.arguments, a = e.stringLiteral(o), p = c[0];
84
+ e.isStringLiteral(p) && p.value.includes("/") || (i.node.arguments = [a, ...c]);
85
85
  }
86
86
  }), h(r, { retainLines: !0 }).code;
87
87
  }
88
- function W(u, o) {
88
+ function V(u, o) {
89
89
  const r = v(u, {
90
90
  sourceType: "module",
91
91
  plugins: ["typescript", "jsx"]
92
92
  });
93
93
  return m(r, {
94
- ExportNamedDeclaration(n) {
95
- const t = n.node.declaration;
94
+ ExportNamedDeclaration(i) {
95
+ const t = i.node.declaration;
96
96
  if (!e.isVariableDeclaration(t)) return;
97
- const i = t.declarations[0];
98
- if (!i || !e.isIdentifier(i.id)) return;
99
- const s = i.id.name;
97
+ const n = t.declarations[0];
98
+ if (!n || !e.isIdentifier(n.id)) return;
99
+ const s = n.id.name;
100
100
  if (!s.startsWith("action_")) return;
101
- const c = s.replace("action_", ""), a = i.init;
101
+ const c = s.replace("action_", ""), a = n.init;
102
102
  if (!e.isArrowFunctionExpression(a) || !a.async) return;
103
- const p = a.params, f = $(o, c, p);
104
- a.body = e.blockStatement([e.returnStatement(f)]), V(a, p);
103
+ const p = a.params, f = W(o, c, p);
104
+ a.body = e.blockStatement([e.returnStatement(f)]), $(a, p);
105
105
  }
106
106
  }), h(r, { retainLines: !0 }).code;
107
107
  }
108
- function $(u, o, r) {
108
+ function W(u, o, r) {
109
109
  const l = `/_action/${u}/${o}`;
110
110
  return r.length === 0 ? e.callExpression(
111
111
  e.memberExpression(
@@ -175,22 +175,22 @@ function $(u, o, r) {
175
175
  ]
176
176
  );
177
177
  }
178
- function V(u, o) {
178
+ function $(u, o) {
179
179
  if (o.length === 0) return;
180
180
  const r = o[0];
181
181
  if (e.isObjectPattern(r)) {
182
182
  let l = null;
183
183
  if (e.isTSTypeAnnotation(r.typeAnnotation) && e.isTSTypeReference(r.typeAnnotation.typeAnnotation)) {
184
- const i = r.typeAnnotation.typeAnnotation;
185
- e.isIdentifier(i.typeName, { name: "ActionArgs" }) && i.typeParameters?.params[0] && (l = i.typeParameters.params[0]);
184
+ const n = r.typeAnnotation.typeAnnotation;
185
+ e.isIdentifier(n.typeName, { name: "ActionArgs" }) && n.typeParameters?.params[0] && (l = n.typeParameters.params[0]);
186
186
  }
187
- const n = e.objectProperty(
187
+ const i = 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([n]);
193
+ ), t = e.objectPattern([i]);
194
194
  l && (t.typeAnnotation = e.tsTypeAnnotation(
195
195
  e.tsTypeLiteral([
196
196
  e.tsPropertySignature(
@@ -208,9 +208,9 @@ function U(u) {
208
208
  });
209
209
  return m(o, {
210
210
  ExportNamedDeclaration(l) {
211
- const n = l.node.declaration;
212
- if (!e.isVariableDeclaration(n)) return;
213
- const t = n.declarations[0];
211
+ const i = l.node.declaration;
212
+ if (!e.isVariableDeclaration(i)) return;
213
+ const t = i.declarations[0];
214
214
  !t || !e.isIdentifier(t.id) || t.id.name === "loader" && l.remove();
215
215
  }
216
216
  }), h(o, { retainLines: !0 }).code;
@@ -221,23 +221,23 @@ function k(u) {
221
221
  plugins: ["typescript", "jsx"]
222
222
  }), r = /* @__PURE__ */ new Set();
223
223
  return m(o, {
224
- ObjectProperty(n) {
225
- if (e.isIdentifier(n.node.key, { name: "middlewares" }) && e.isArrayExpression(n.node.value)) {
226
- for (const t of n.node.value.elements)
224
+ ObjectProperty(i) {
225
+ if (e.isIdentifier(i.node.key, { name: "middlewares" }) && e.isArrayExpression(i.node.value)) {
226
+ for (const t of i.node.value.elements)
227
227
  e.isIdentifier(t) && r.add(t.name);
228
- n.remove();
228
+ i.remove();
229
229
  }
230
230
  }
231
231
  }), r.size === 0 ? u : (m(o, {
232
- ImportDeclaration(n) {
233
- const t = n.node.specifiers, i = t.filter((s) => {
232
+ ImportDeclaration(i) {
233
+ const t = i.node.specifiers, n = t.filter((s) => {
234
234
  if (e.isImportSpecifier(s)) {
235
235
  const c = s.local.name;
236
236
  return !r.has(c);
237
237
  }
238
238
  return !0;
239
239
  });
240
- i.length === 0 ? n.remove() : i.length !== t.length && (n.node.specifiers = i);
240
+ n.length === 0 ? i.remove() : n.length !== t.length && (i.node.specifiers = n);
241
241
  }
242
242
  }), h(o, { retainLines: !0 }).code);
243
243
  }
@@ -248,52 +248,52 @@ function T(u) {
248
248
  }), r = /* @__PURE__ */ new Map();
249
249
  m(o, {
250
250
  ImportDeclaration(t) {
251
- const i = t.node.source.value;
251
+ const n = t.node.source.value;
252
252
  for (const s of t.node.specifiers)
253
- e.isImportNamespaceSpecifier(s) && r.set(s.local.name, i);
253
+ e.isImportNamespaceSpecifier(s) && r.set(s.local.name, n);
254
254
  }
255
255
  });
256
256
  const l = /* @__PURE__ */ new Map();
257
257
  m(o, {
258
258
  ExportDefaultDeclaration(t) {
259
- const i = t.node.declaration;
259
+ const n = t.node.declaration;
260
260
  let s = null;
261
- e.isArrayExpression(i) ? s = i : e.isTSSatisfiesExpression(i) && e.isArrayExpression(i.expression) && (s = i.expression), s && N(s.elements, "", l);
261
+ e.isArrayExpression(n) ? s = n : e.isTSSatisfiesExpression(n) && e.isArrayExpression(n.expression) && (s = n.expression), s && A(s.elements, "", l);
262
262
  }
263
263
  });
264
- const n = /* @__PURE__ */ new Map();
265
- for (const [t, i] of l) {
264
+ const i = /* @__PURE__ */ new Map();
265
+ for (const [t, n] of l) {
266
266
  const s = r.get(t);
267
267
  if (s) {
268
268
  const c = s.replace(/^\.\//, "").replace(/\.(tsx?|jsx?|js)$/, "");
269
- n.set(c, i);
269
+ i.set(c, n);
270
270
  }
271
271
  }
272
- return n;
272
+ return i;
273
273
  }
274
- function N(u, o, r) {
274
+ function A(u, o, r) {
275
275
  for (const l of u) {
276
276
  if (!e.isObjectExpression(l)) continue;
277
- let n = "", t = o, i = null, s = null;
277
+ let i = "", t = o, n = null, s = null;
278
278
  for (const c of l.properties) {
279
279
  if (!e.isObjectProperty(c)) continue;
280
280
  const a = c.key, p = e.isIdentifier(a) ? a.name : null;
281
- p === "path" && e.isStringLiteral(c.value) && (n = c.value.value, n && !n.startsWith("/") ? t = o + "/" + n : t = o + n), p === "module" && e.isIdentifier(c.value) && (i = c.value.name), p === "children" && e.isArrayExpression(c.value) && (s = c.value);
281
+ p === "path" && e.isStringLiteral(c.value) && (i = c.value.value, i && !i.startsWith("/") ? t = o + "/" + i : t = o + i), p === "module" && e.isIdentifier(c.value) && (n = c.value.name), p === "children" && e.isArrayExpression(c.value) && (s = c.value);
282
282
  }
283
- if (i) {
284
- const a = !s && n === "/" ? o || "/" : t;
285
- r.set(i, {
283
+ if (n) {
284
+ const a = !s && i === "/" ? o || "/" : t;
285
+ r.set(n, {
286
286
  fullPath: a,
287
- path: n
287
+ path: i
288
288
  });
289
289
  }
290
- s && N(s.elements, t, r);
290
+ s && A(s.elements, t, r);
291
291
  }
292
292
  }
293
- const g = "virtual:velo/server-entry", j = "virtual:velo/client-entry", P = "\0" + g, A = "\0" + j;
293
+ const g = "virtual:velo/server-entry", E = "virtual:velo/client-entry", P = "\0" + g, _ = "\0" + E;
294
294
  function M(u, o) {
295
295
  let r = d.resolve(process.cwd(), o);
296
- const l = u.routesFile ?? "routes.tsx", n = /* @__PURE__ */ new Map();
296
+ const l = u.routesFile ?? "routes.tsx", i = /* @__PURE__ */ new Map();
297
297
  return {
298
298
  name: "velo:transform",
299
299
  enforce: "pre",
@@ -302,35 +302,36 @@ function M(u, o) {
302
302
  },
303
303
  buildStart() {
304
304
  const t = d.join(r, l);
305
- if (E.existsSync(t)) {
306
- const i = E.readFileSync(t, "utf-8"), s = T(i);
307
- n.clear();
305
+ if (j.existsSync(t)) {
306
+ const n = j.readFileSync(t, "utf-8"), s = T(n);
307
+ i.clear();
308
308
  for (const [c, a] of s)
309
- n.set(c, a);
309
+ i.set(c, a);
310
310
  }
311
311
  },
312
- handleHotUpdate({ file: t, server: i }) {
312
+ handleHotUpdate({ file: t, server: n }) {
313
313
  const s = d.join(r, l);
314
314
  if (t === s) {
315
- const c = E.readFileSync(s, "utf-8"), a = T(c);
316
- n.clear();
315
+ const c = j.readFileSync(s, "utf-8"), a = T(c);
316
+ i.clear();
317
317
  for (const [p, f] of a)
318
- n.set(p, f);
319
- return i.ws.send({ type: "full-reload" }), [];
318
+ i.set(p, f);
319
+ return n.ws.send({ type: "full-reload" }), [];
320
320
  }
321
321
  },
322
322
  resolveId(t) {
323
- return t === g || t.endsWith(g) ? P : t === j || t.endsWith(j) || t === "/__velo_client.js" ? A : null;
323
+ return t === g || t.endsWith(g) ? P : t === E || t.endsWith(E) || t === "/__velo_client.js" ? _ : null;
324
324
  },
325
325
  load(t) {
326
- const i = u.routesFile ?? "routes.tsx", s = u.serverInit ?? "server.tsx", c = u.clientInit ?? "client.tsx", a = d.join(r, i).replace(/\.tsx?$/, ".js"), p = d.join(r, s).replace(/\.tsx?$/, ".js"), f = d.join(r, c).replace(/\.tsx?$/, ".js");
326
+ const n = u.routesFile ?? "routes.tsx", s = u.serverInit ?? "server.tsx", c = u.clientInit ?? "client.tsx", a = d.join(r, n).replace(/\.tsx?$/, ".js"), p = d.join(r, s).replace(/\.tsx?$/, ".js"), f = d.join(r, c).replace(/\.tsx?$/, ".js");
327
327
  return t === P ? `
328
328
  import "${p}";
329
329
  import routes from "${a}";
330
330
  import { startServer } from "@mauroandre/velojs/server";
331
331
 
332
+ export { routes };
332
333
  export default await startServer({ routes });
333
- ` : t === A ? `
334
+ ` : t === _ ? `
334
335
  import "${f}";
335
336
  import routes from "${a}";
336
337
  import { startClient } from "@mauroandre/velojs/client";
@@ -338,16 +339,16 @@ import { startClient } from "@mauroandre/velojs/client";
338
339
  startClient({ routes });
339
340
  ` : null;
340
341
  },
341
- transform(t, i, s) {
342
+ transform(t, n, s) {
342
343
  const c = s?.ssr === !0;
343
- if (i.startsWith("\0") || i.includes("/.velojs/") || !i.endsWith(".tsx") && !i.endsWith(".ts") || !i.startsWith(r)) return null;
344
+ if (n.startsWith("\0") || n.includes("/.velojs/") || !n.endsWith(".tsx") && !n.endsWith(".ts") || !n.startsWith(r)) return null;
344
345
  let a = t, p = !1;
345
346
  const f = /middlewares:\s*\[/.test(t), x = /export\s+(const|function)\s+Component/.test(
346
347
  t
347
- ), y = /export\s+(const|function)\s+loader/.test(t), _ = /export\s+const\s+action_\w+/.test(t), D = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), F = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t);
348
- if (!c && f && (a = k(a), p = !0), x || y || _ || D || F) {
349
- const b = d.relative(r, i).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), S = n.get(b);
350
- a = R(a, b, S?.fullPath, S?.path), a = O(a, b), c || (a = W(
348
+ ), y = /export\s+(const|function)\s+loader/.test(t), N = /export\s+const\s+action_\w+/.test(t), D = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), F = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t);
349
+ if (!c && f && (a = k(a), p = !0), x || y || N || D || F) {
350
+ const b = d.relative(r, n).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), I = i.get(b);
351
+ a = w(a, b, I?.fullPath, I?.path), a = R(a, b), c || (a = V(
351
352
  a,
352
353
  b
353
354
  )), c || (a = U(a)), p = !0;
@@ -363,10 +364,11 @@ function B() {
363
364
  return {
364
365
  name: "velo:config",
365
366
  config(u, { mode: o }) {
366
- const r = o === "server", l = o === "development", n = {
367
+ const r = o === "server", l = o === "development", i = !!process.env.VELO_STATIC, t = {
367
368
  define: {
368
369
  "process.env.NODE_ENV": JSON.stringify(l ? "development" : "production"),
369
- "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || "")
370
+ "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (i ? "/client" : "")),
371
+ __VELO_STATIC__: JSON.stringify(i)
370
372
  },
371
373
  resolve: {
372
374
  alias: {
@@ -375,7 +377,7 @@ function B() {
375
377
  }
376
378
  }
377
379
  };
378
- return r ? n.build = {
380
+ return r ? t.build = {
379
381
  ssr: g,
380
382
  outDir: "dist",
381
383
  emptyOutDir: !1,
@@ -385,17 +387,17 @@ function B() {
385
387
  entryFileNames: "server.js"
386
388
  }
387
389
  }
388
- } : l || (n.build = {
390
+ } : l || (t.build = {
389
391
  manifest: !0,
390
392
  outDir: "dist/client",
391
393
  rollupOptions: {
392
- input: j,
394
+ input: E,
393
395
  output: {
394
396
  entryFileNames: "client.js",
395
- assetFileNames: (t) => t.names?.[0]?.endsWith(".css") ? "client.css" : "[name][extname]"
397
+ assetFileNames: (n) => n.names?.[0]?.endsWith(".css") ? "client.css" : "[name][extname]"
396
398
  }
397
399
  }
398
- }), n;
400
+ }), t;
399
401
  }
400
402
  };
401
403
  }
@@ -421,8 +423,8 @@ function Z(u) {
421
423
  B(),
422
424
  M(o, r),
423
425
  J(),
424
- w(),
425
- C({
426
+ C(),
427
+ O({
426
428
  entry: g
427
429
  }),
428
430
  Y()
@@ -438,11 +440,11 @@ function Y() {
438
440
  }
439
441
  export {
440
442
  T as buildFullPathMap,
441
- N as collectFullPaths,
442
- R as injectMetadata,
443
+ A as collectFullPaths,
444
+ w as injectMetadata,
443
445
  U as removeLoaders,
444
446
  k as removeMiddlewares,
445
- W as transformActionsForClient,
446
- O as transformLoaderFunctions,
447
+ V as transformActionsForClient,
448
+ R as transformLoaderFunctions,
447
449
  Z as veloPlugin
448
450
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mauroandre/velojs",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "description": "Fullstack web framework built on Hono + Preact with Vite-powered AST transforms",
6
6
  "keywords": [