@mauroandre/velojs 0.0.16 → 0.0.18

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.
@@ -1,6 +1,6 @@
1
1
  import { jsx as o, jsxs as p, Fragment as $ } from "preact/jsx-runtime";
2
- import { useRouter as v, Link as E } from "wouter-preact";
3
- import { __veloUpdatePending as y } from "./hooks.js";
2
+ import { useRouter as C, Link as S } from "wouter-preact";
3
+ import { __veloUpdatePending as E } 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" : "");
@@ -11,10 +11,10 @@ function O({ basePath: e, favicon: t = "/favicon.ico" } = {}) {
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 = typeof __VELO_CLIENT_JS__ < "u" ? __VELO_CLIENT_JS__ : "client.js";
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
15
  return /* @__PURE__ */ p($, { children: [
16
16
  i,
17
- /* @__PURE__ */ o("link", { rel: "stylesheet", href: `${e}/${typeof __VELO_CLIENT_CSS__ < "u" ? __VELO_CLIENT_CSS__ : "client.css"}` }),
17
+ /* @__PURE__ */ o("link", { rel: "stylesheet", href: `${e}/${c}` }),
18
18
  /* @__PURE__ */ o("script", { type: "module", src: `${e}/${r}` })
19
19
  ] });
20
20
  }
@@ -25,29 +25,29 @@ function h(e, t) {
25
25
  return n;
26
26
  }
27
27
  function j({ to: e, params: t, search: n, absolute: i, ...r }) {
28
- const c = typeof e != "string", u = v(), _ = c ? (i ? e.metadata?.fullPath : e.metadata?.path) ?? "/" : e, l = t ? h(_, t) : _, L = c && i ? `~${l}` : l, a = n ? `?${new URLSearchParams(n).toString()}` : "", m = `${L}${a}`;
29
- if (typeof window < "u" && y.value) {
30
- let f;
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
31
  if (c) {
32
- const s = e.metadata?.fullPath ?? _;
33
- f = `${t ? h(s, t) : s}${a}`;
32
+ const s = e.metadata?.fullPath ?? f;
33
+ _ = `${t ? h(s, t) : s}${a}`;
34
34
  } else {
35
35
  const s = l.replace(/^~/, "");
36
- f = `${!l.startsWith("~") && u.base ? u.base : ""}${s}${a}`;
36
+ _ = `${!l.startsWith("~") && u.base ? u.base : ""}${s}${a}`;
37
37
  }
38
- const { onClick: d, ...S } = r;
38
+ const { onClick: d, ...m } = r;
39
39
  return /* @__PURE__ */ o(
40
40
  "a",
41
41
  {
42
- href: f,
42
+ href: _,
43
43
  onClick: (s) => {
44
- d && d(s), s.defaultPrevented || (s.preventDefault(), window.location.href = f);
44
+ d && d(s), s.defaultPrevented || (s.preventDefault(), window.location.href = _);
45
45
  },
46
- ...S
46
+ ...m
47
47
  }
48
48
  );
49
49
  }
50
- return /* @__PURE__ */ o(E, { to: m, ...r });
50
+ return /* @__PURE__ */ o(S, { to: L, ...r });
51
51
  }
52
52
  export {
53
53
  j as Link,
package/dist/server.js CHANGED
@@ -1,15 +1,15 @@
1
- import { jsx as h } from "preact/jsx-runtime";
2
- import { Hono as P } from "hono";
3
- import { logger as T } from "hono/logger";
4
- import { trimTrailingSlash as D } from "hono/trailing-slash";
5
- import { render as O } from "preact-render-to-string";
6
- import { Router as b } from "wouter-preact";
7
- import { AsyncLocalStorage as I } from "node:async_hooks";
8
- const v = new I();
1
+ import { jsx as m } from "preact/jsx-runtime";
2
+ import { Hono as T } from "hono";
3
+ import { logger as A } from "hono/logger";
4
+ import { trimTrailingSlash as b } from "hono/trailing-slash";
5
+ import { render as D } from "preact-render-to-string";
6
+ import { Router as R } from "wouter-preact";
7
+ import { AsyncLocalStorage as C } from "node:async_hooks";
8
+ const v = new C();
9
9
  globalThis.__veloServerData = v;
10
10
  const _ = [];
11
11
  let p = null;
12
- function M(t) {
12
+ function L(t) {
13
13
  if (p) {
14
14
  t(p);
15
15
  return;
@@ -21,18 +21,18 @@ function y(t) {
21
21
  for (const e of _) e(t);
22
22
  _.length = 0;
23
23
  }
24
- const S = [];
25
- function G(t) {
26
- S.push(t);
24
+ const w = [];
25
+ function U(t) {
26
+ w.push(t);
27
27
  }
28
- const R = (t, e, o) => {
28
+ const N = (t, e, o) => {
29
29
  if (t.req.query("_data") === "1") {
30
- const c = typeof __VELO_BUILD_HASH__ < "u" ? __VELO_BUILD_HASH__ : void 0, r = o ? { ...o, __buildHash: c } : { __buildHash: c };
30
+ const c = globalThis.__veloBuildHash || void 0, r = o ? { ...o, __buildHash: c } : { __buildHash: c };
31
31
  return t.json(r);
32
32
  }
33
33
  const s = t.req.path, n = v.run(
34
34
  o ?? {},
35
- () => O(/* @__PURE__ */ h(b, { ssrPath: s, children: e }))
35
+ () => D(/* @__PURE__ */ m(R, { ssrPath: s, children: e }))
36
36
  );
37
37
  if (t.header("Cache-Control", "no-cache"), !o)
38
38
  return t.html(n);
@@ -40,7 +40,7 @@ const R = (t, e, o) => {
40
40
  o
41
41
  )}<\/script>`;
42
42
  return t.html(n.replace("</head>", `${a}</head>`));
43
- }, C = async (t, e) => {
43
+ }, O = async (t, e) => {
44
44
  const o = e.req.param(), s = e.req.query(), n = { params: o, query: s, c: e }, a = await Promise.all(
45
45
  t.map(async (r) => {
46
46
  if (!r.loader) return null;
@@ -58,24 +58,24 @@ const R = (t, e, o) => {
58
58
  components: t.map((r) => r.Component),
59
59
  data: c
60
60
  };
61
- }, N = (t) => {
61
+ }, j = (t) => {
62
62
  if (t.length === 0) return null;
63
63
  const e = t.filter(Boolean);
64
64
  if (e.length === 0) return null;
65
65
  if (e.length === 1) {
66
66
  const n = e[0];
67
- return /* @__PURE__ */ h(n, {});
67
+ return /* @__PURE__ */ m(n, {});
68
68
  }
69
69
  const o = e[e.length - 1];
70
- return e.slice(0, -1).reduceRight((n, a) => /* @__PURE__ */ h(a, { children: n }), /* @__PURE__ */ h(o, {}));
71
- }, w = (t, e, o = [], s = []) => {
70
+ return e.slice(0, -1).reduceRight((n, a) => /* @__PURE__ */ m(a, { children: n }), /* @__PURE__ */ m(o, {}));
71
+ }, S = (t, e, o = [], s = []) => {
72
72
  for (const n of e) {
73
73
  const a = [...o, n.module], c = [
74
74
  ...s,
75
75
  ...n.middlewares || []
76
76
  ];
77
77
  if (n.children)
78
- w(
78
+ S(
79
79
  t,
80
80
  n.children,
81
81
  a,
@@ -90,13 +90,13 @@ const R = (t, e, o) => {
90
90
  continue;
91
91
  }
92
92
  const u = async (i) => {
93
- const { components: d, data: f } = await C(a, i), l = N(d);
94
- return R(i, l, f);
93
+ const { components: d, data: f } = await O(a, i), l = j(d);
94
+ return N(i, l, f);
95
95
  };
96
96
  c.length > 0 ? t.on(["GET"], [r], ...c, u) : t.on(["GET"], [r], u);
97
97
  }
98
98
  }
99
- }, E = (t, e, o = []) => {
99
+ }, q = (t, e, o = []) => {
100
100
  for (const s of e) {
101
101
  const n = s.module.metadata?.moduleId, a = [
102
102
  ...o,
@@ -115,18 +115,18 @@ const R = (t, e, o) => {
115
115
  g = await l.req.json();
116
116
  } catch {
117
117
  }
118
- const q = {
118
+ const E = {
119
119
  body: g,
120
120
  params: l.req.param(),
121
121
  query: l.req.query(),
122
122
  c: l
123
123
  };
124
124
  try {
125
- const m = await i(q);
126
- return l.json(m ?? { ok: !0 });
127
- } catch (m) {
128
- const A = m instanceof Error ? m.message : "Action failed";
129
- return l.json({ error: A }, 500);
125
+ const h = await i(E);
126
+ return l.json(h ?? { ok: !0 });
127
+ } catch (h) {
128
+ const P = h instanceof Error ? h.message : "Action failed";
129
+ return l.json({ error: P }, 500);
130
130
  }
131
131
  };
132
132
  a.length > 0 ? t.on(
@@ -138,20 +138,20 @@ const R = (t, e, o) => {
138
138
  }
139
139
  }
140
140
  }
141
- s.children && E(t, s.children, a);
141
+ s.children && q(t, s.children, a);
142
142
  }
143
- }, j = async (t) => {
144
- const e = new P();
145
- e.use(D()), process.env.NODE_ENV !== "production" && e.use("*", T());
146
- for (const o of S)
143
+ }, I = async (t) => {
144
+ const e = new T();
145
+ e.use(b()), process.env.NODE_ENV !== "production" && e.use("*", A());
146
+ for (const o of w)
147
147
  await o(e);
148
- if (w(e, t), E(e, t), process.env.NODE_ENV !== "production" && !p) {
148
+ if (S(e, t), q(e, t), process.env.NODE_ENV !== "production" && !p) {
149
149
  const o = globalThis.__veloDevServer;
150
150
  o && y(o);
151
151
  }
152
152
  return e;
153
153
  }, x = async (t) => {
154
- const { routes: e, port: o = Number(process.env.SERVER_PORT) || 3e3 } = t, s = await j(e);
154
+ const { routes: e, port: o = Number(process.env.SERVER_PORT) || 3e3 } = t, s = await I(e);
155
155
  if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
156
156
  const { serve: n } = await import("@hono/node-server"), { serveStatic: a } = await import("@hono/node-server/serve-static"), { join: c } = await import("node:path"), r = c(process.cwd(), "dist/client");
157
157
  (process.env.STATIC_BASE_URL || "").startsWith("http") || s.use("/*", a({ root: r })), console.log(`Server running on http://localhost:${o}`);
@@ -161,10 +161,10 @@ const R = (t, e, o) => {
161
161
  return s;
162
162
  };
163
163
  export {
164
- G as addRoutes,
165
- j as createApp,
166
- j as default,
167
- M as onServer,
164
+ U as addRoutes,
165
+ I as createApp,
166
+ I as default,
167
+ L as onServer,
168
168
  v as serverDataStorage,
169
169
  x as startServer
170
170
  };
package/dist/vite.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import d from "node:path";
2
2
  import L from "node:fs";
3
- import C from "@preact/preset-vite";
3
+ import D from "@preact/preset-vite";
4
4
  import F from "@hono/vite-dev-server";
5
5
  import { parse as v } from "@babel/parser";
6
- import b from "@babel/traverse";
7
- import j from "@babel/generator";
6
+ import E from "@babel/traverse";
7
+ import b from "@babel/generator";
8
8
  import * as e from "@babel/types";
9
- const m = typeof b == "function" ? b : b.default, S = typeof j == "function" ? j : j.default;
10
- function w(u, c, r, l) {
11
- const i = v(u, {
9
+ const m = typeof E == "function" ? E : E.default, S = typeof b == "function" ? b : b.default;
10
+ function w(u, l, r, c) {
11
+ const n = v(u, {
12
12
  sourceType: "module",
13
13
  plugins: ["typescript", "jsx"]
14
14
  });
15
15
  let t = !1;
16
- if (m(i, {
16
+ if (m(n, {
17
17
  // Procura: export const metadata = { ... }
18
18
  ExportNamedDeclaration(s) {
19
19
  const o = s.node.declaration;
@@ -21,23 +21,23 @@ function w(u, c, r, l) {
21
21
  const a = o.declarations[0];
22
22
  if (a && e.isIdentifier(a.id, { name: "metadata" }) && e.isObjectExpression(a.init)) {
23
23
  t = !0;
24
- const f = a.init.properties.filter((y) => e.isObjectProperty(y) && e.isIdentifier(y.key) ? y.key.name !== "moduleId" && y.key.name !== "fullPath" && y.key.name !== "path" : !0), h = [
24
+ const f = a.init.properties.filter((y) => e.isObjectProperty(y) && e.isIdentifier(y.key) ? y.key.name !== "moduleId" && y.key.name !== "fullPath" && y.key.name !== "path" : !0), _ = [
25
25
  e.objectProperty(
26
26
  e.identifier("moduleId"),
27
- e.stringLiteral(c)
27
+ e.stringLiteral(l)
28
28
  )
29
29
  ];
30
- r !== void 0 && h.push(
30
+ r !== void 0 && _.push(
31
31
  e.objectProperty(
32
32
  e.identifier("fullPath"),
33
33
  e.stringLiteral(r)
34
34
  )
35
- ), l !== void 0 && h.push(
35
+ ), c !== void 0 && _.push(
36
36
  e.objectProperty(
37
37
  e.identifier("path"),
38
- e.stringLiteral(l)
38
+ e.stringLiteral(c)
39
39
  )
40
- ), a.init.properties = [...h, ...f];
40
+ ), a.init.properties = [..._, ...f];
41
41
  }
42
42
  }
43
43
  }
@@ -45,7 +45,7 @@ function w(u, c, r, l) {
45
45
  const s = [
46
46
  e.objectProperty(
47
47
  e.identifier("moduleId"),
48
- e.stringLiteral(c)
48
+ e.stringLiteral(l)
49
49
  )
50
50
  ];
51
51
  r !== void 0 && s.push(
@@ -53,10 +53,10 @@ function w(u, c, r, l) {
53
53
  e.identifier("fullPath"),
54
54
  e.stringLiteral(r)
55
55
  )
56
- ), l !== void 0 && s.push(
56
+ ), c !== void 0 && s.push(
57
57
  e.objectProperty(
58
58
  e.identifier("path"),
59
- e.stringLiteral(l)
59
+ e.stringLiteral(c)
60
60
  )
61
61
  );
62
62
  const o = e.exportNamedDeclaration(
@@ -67,50 +67,50 @@ function w(u, c, r, l) {
67
67
  )
68
68
  ])
69
69
  );
70
- i.program.body.unshift(o);
70
+ n.program.body.unshift(o);
71
71
  }
72
- return S(i, { retainLines: !0 }).code;
72
+ return S(n, { retainLines: !0 }).code;
73
73
  }
74
- function R(u, c) {
74
+ function V(u, l) {
75
75
  const r = v(u, {
76
76
  sourceType: "module",
77
77
  plugins: ["typescript", "jsx"]
78
78
  });
79
79
  return m(r, {
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 o = i.node.arguments, a = e.stringLiteral(c), p = o[0];
84
- e.isStringLiteral(p) && p.value.includes("/") || (i.node.arguments = [a, ...o]);
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 o = n.node.arguments, a = e.stringLiteral(l), p = o[0];
84
+ e.isStringLiteral(p) && p.value.includes("/") || (n.node.arguments = [a, ...o]);
85
85
  }
86
86
  }), S(r, { retainLines: !0 }).code;
87
87
  }
88
- function V(u, c) {
88
+ function R(u, l) {
89
89
  const r = v(u, {
90
90
  sourceType: "module",
91
91
  plugins: ["typescript", "jsx"]
92
92
  });
93
93
  return m(r, {
94
- ExportNamedDeclaration(i) {
95
- const t = i.node.declaration;
94
+ ExportNamedDeclaration(n) {
95
+ const t = n.node.declaration;
96
96
  if (!e.isVariableDeclaration(t)) return;
97
- const n = t.declarations[0];
98
- if (!n || !e.isIdentifier(n.id)) return;
99
- const s = n.id.name;
97
+ const i = t.declarations[0];
98
+ if (!i || !e.isIdentifier(i.id)) return;
99
+ const s = i.id.name;
100
100
  if (!s.startsWith("action_")) return;
101
- const o = s.replace("action_", ""), a = n.init;
101
+ const o = s.replace("action_", ""), a = i.init;
102
102
  if (!e.isArrowFunctionExpression(a) || !a.async) return;
103
- const p = a.params, f = U(c, o, p);
103
+ const p = a.params, f = U(l, o, p);
104
104
  a.body = e.blockStatement([e.returnStatement(f)]), W(a, p);
105
105
  }
106
106
  }), S(r, { retainLines: !0 }).code;
107
107
  }
108
- function U(u, c, r) {
109
- const l = `/_action/${u}/${c}`;
108
+ function U(u, l, r) {
109
+ const c = `/_action/${u}/${l}`;
110
110
  return r.length === 0 ? e.callExpression(
111
111
  e.memberExpression(
112
112
  e.callExpression(e.identifier("fetch"), [
113
- e.stringLiteral(l),
113
+ e.stringLiteral(c),
114
114
  e.objectExpression([
115
115
  e.objectProperty(
116
116
  e.identifier("method"),
@@ -135,7 +135,7 @@ function U(u, c, r) {
135
135
  ) : e.callExpression(
136
136
  e.memberExpression(
137
137
  e.callExpression(e.identifier("fetch"), [
138
- e.stringLiteral(l),
138
+ e.stringLiteral(c),
139
139
  e.objectExpression([
140
140
  e.objectProperty(
141
141
  e.identifier("method"),
@@ -175,163 +175,166 @@ function U(u, c, r) {
175
175
  ]
176
176
  );
177
177
  }
178
- function W(u, c) {
179
- if (c.length === 0) return;
180
- const r = c[0];
178
+ function W(u, l) {
179
+ if (l.length === 0) return;
180
+ const r = l[0];
181
181
  if (e.isObjectPattern(r)) {
182
- let l = null;
182
+ let c = null;
183
183
  if (e.isTSTypeAnnotation(r.typeAnnotation) && e.isTSTypeReference(r.typeAnnotation.typeAnnotation)) {
184
- const n = r.typeAnnotation.typeAnnotation;
185
- e.isIdentifier(n.typeName, { name: "ActionArgs" }) && n.typeParameters?.params[0] && (l = n.typeParameters.params[0]);
184
+ const i = r.typeAnnotation.typeAnnotation;
185
+ e.isIdentifier(i.typeName, { name: "ActionArgs" }) && i.typeParameters?.params[0] && (c = i.typeParameters.params[0]);
186
186
  }
187
- const i = e.objectProperty(
187
+ const n = e.objectProperty(
188
188
  e.identifier("body"),
189
189
  e.identifier("body"),
190
190
  !1,
191
191
  !0
192
192
  // shorthand
193
- ), t = e.objectPattern([i]);
194
- l && (t.typeAnnotation = e.tsTypeAnnotation(
193
+ ), t = e.objectPattern([n]);
194
+ c && (t.typeAnnotation = e.tsTypeAnnotation(
195
195
  e.tsTypeLiteral([
196
196
  e.tsPropertySignature(
197
197
  e.identifier("body"),
198
- e.tsTypeAnnotation(l)
198
+ e.tsTypeAnnotation(c)
199
199
  )
200
200
  ])
201
201
  )), u.params = [t];
202
202
  }
203
203
  }
204
204
  function $(u) {
205
- const c = v(u, {
205
+ const l = v(u, {
206
206
  sourceType: "module",
207
207
  plugins: ["typescript", "jsx"]
208
208
  });
209
- return m(c, {
210
- ExportNamedDeclaration(l) {
211
- const i = l.node.declaration;
212
- if (!e.isVariableDeclaration(i)) return;
213
- const t = i.declarations[0];
214
- !t || !e.isIdentifier(t.id) || t.id.name === "loader" && l.remove();
209
+ return m(l, {
210
+ ExportNamedDeclaration(c) {
211
+ const n = c.node.declaration;
212
+ if (!e.isVariableDeclaration(n)) return;
213
+ const t = n.declarations[0];
214
+ !t || !e.isIdentifier(t.id) || t.id.name === "loader" && c.remove();
215
215
  }
216
- }), S(c, { retainLines: !0 }).code;
216
+ }), S(l, { retainLines: !0 }).code;
217
217
  }
218
- function k(u) {
219
- const c = v(u, {
218
+ function J(u) {
219
+ const l = v(u, {
220
220
  sourceType: "module",
221
221
  plugins: ["typescript", "jsx"]
222
222
  }), r = /* @__PURE__ */ new Set();
223
- return m(c, {
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)
223
+ return m(l, {
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)
227
227
  e.isIdentifier(t) && r.add(t.name);
228
- i.remove();
228
+ n.remove();
229
229
  }
230
230
  }
231
- }), r.size === 0 ? u : (m(c, {
232
- ImportDeclaration(i) {
233
- const t = i.node.specifiers, n = t.filter((s) => {
231
+ }), r.size === 0 ? u : (m(l, {
232
+ ImportDeclaration(n) {
233
+ const t = n.node.specifiers, i = t.filter((s) => {
234
234
  if (e.isImportSpecifier(s)) {
235
235
  const o = s.local.name;
236
236
  return !r.has(o);
237
237
  }
238
238
  return !0;
239
239
  });
240
- n.length === 0 ? i.remove() : n.length !== t.length && (i.node.specifiers = n);
240
+ i.length === 0 ? n.remove() : i.length !== t.length && (n.node.specifiers = i);
241
241
  }
242
- }), S(c, { retainLines: !0 }).code);
242
+ }), S(l, { retainLines: !0 }).code);
243
243
  }
244
- function _(u) {
245
- const c = v(u, {
244
+ function j(u) {
245
+ const l = v(u, {
246
246
  sourceType: "module",
247
247
  plugins: ["typescript", "jsx"]
248
248
  }), r = /* @__PURE__ */ new Map();
249
- m(c, {
249
+ m(l, {
250
250
  ImportDeclaration(t) {
251
- const n = t.node.source.value;
251
+ const i = t.node.source.value;
252
252
  for (const s of t.node.specifiers)
253
- e.isImportNamespaceSpecifier(s) && r.set(s.local.name, n);
253
+ e.isImportNamespaceSpecifier(s) && r.set(s.local.name, i);
254
254
  }
255
255
  });
256
- const l = /* @__PURE__ */ new Map();
257
- m(c, {
256
+ const c = /* @__PURE__ */ new Map();
257
+ m(l, {
258
258
  ExportDefaultDeclaration(t) {
259
- const n = t.node.declaration;
259
+ const i = t.node.declaration;
260
260
  let s = null;
261
- e.isArrayExpression(n) ? s = n : e.isTSSatisfiesExpression(n) && e.isArrayExpression(n.expression) && (s = n.expression), s && A(s.elements, "", l);
261
+ e.isArrayExpression(i) ? s = i : e.isTSSatisfiesExpression(i) && e.isArrayExpression(i.expression) && (s = i.expression), s && P(s.elements, "", c);
262
262
  }
263
263
  });
264
- const i = /* @__PURE__ */ new Map();
265
- for (const [t, n] of l) {
264
+ const n = /* @__PURE__ */ new Map();
265
+ for (const [t, i] of c) {
266
266
  const s = r.get(t);
267
267
  if (s) {
268
268
  const o = s.replace(/^\.\//, "").replace(/\.(tsx?|jsx?|js)$/, "");
269
- i.set(o, n);
269
+ n.set(o, i);
270
270
  }
271
271
  }
272
- return i;
272
+ return n;
273
273
  }
274
- function A(u, c, r) {
275
- for (const l of u) {
276
- if (!e.isObjectExpression(l)) continue;
277
- let i = "", t = c, n = null, s = null;
278
- for (const o of l.properties) {
274
+ function P(u, l, r) {
275
+ for (const c of u) {
276
+ if (!e.isObjectExpression(c)) continue;
277
+ let n = "", t = l, i = null, s = null;
278
+ for (const o of c.properties) {
279
279
  if (!e.isObjectProperty(o)) continue;
280
280
  const a = o.key, p = e.isIdentifier(a) ? a.name : null;
281
- p === "path" && e.isStringLiteral(o.value) && (i = o.value.value, i && !i.startsWith("/") ? t = c + "/" + i : t = c + i), p === "module" && e.isIdentifier(o.value) && (n = o.value.name), p === "children" && e.isArrayExpression(o.value) && (s = o.value);
281
+ p === "path" && e.isStringLiteral(o.value) && (n = o.value.value, n && !n.startsWith("/") ? t = l + "/" + n : t = l + n), p === "module" && e.isIdentifier(o.value) && (i = o.value.name), p === "children" && e.isArrayExpression(o.value) && (s = o.value);
282
282
  }
283
- if (n) {
284
- const a = !s && i === "/" ? c || "/" : t;
285
- r.set(n, {
283
+ if (i) {
284
+ const a = !s && n === "/" ? l || "/" : t;
285
+ r.set(i, {
286
286
  fullPath: a,
287
- path: i
287
+ path: n
288
288
  });
289
289
  }
290
- s && A(s.elements, t, r);
290
+ s && P(s.elements, t, r);
291
291
  }
292
292
  }
293
- const g = "virtual:velo/server-entry", x = "virtual:velo/client-entry", T = "\0" + g, P = "\0" + x;
294
- function J(u, c) {
295
- let r = d.resolve(process.cwd(), c);
296
- const l = u.routesFile ?? "routes.tsx", i = /* @__PURE__ */ new Map();
293
+ const h = "virtual:velo/server-entry", g = "virtual:velo/client-entry", T = "\0" + h, N = "\0" + g;
294
+ function k(u, l) {
295
+ let r = d.resolve(process.cwd(), l);
296
+ const c = u.routesFile ?? "routes.tsx", n = /* @__PURE__ */ new Map();
297
297
  return {
298
298
  name: "velo:transform",
299
299
  enforce: "pre",
300
300
  configResolved(t) {
301
- r = d.resolve(t.root, c);
301
+ r = d.resolve(t.root, l);
302
302
  },
303
303
  buildStart() {
304
- const t = d.join(r, l);
304
+ const t = d.join(r, c);
305
305
  if (L.existsSync(t)) {
306
- const n = L.readFileSync(t, "utf-8"), s = _(n);
307
- i.clear();
306
+ const i = L.readFileSync(t, "utf-8"), s = j(i);
307
+ n.clear();
308
308
  for (const [o, a] of s)
309
- i.set(o, a);
309
+ n.set(o, a);
310
310
  }
311
311
  },
312
- handleHotUpdate({ file: t, server: n }) {
313
- const s = d.join(r, l);
312
+ handleHotUpdate({ file: t, server: i }) {
313
+ const s = d.join(r, c);
314
314
  if (t === s) {
315
- const o = L.readFileSync(s, "utf-8"), a = _(o);
316
- i.clear();
315
+ const o = L.readFileSync(s, "utf-8"), a = j(o);
316
+ n.clear();
317
317
  for (const [p, f] of a)
318
- i.set(p, f);
319
- return n.ws.send({ type: "full-reload" }), [];
318
+ n.set(p, f);
319
+ return i.ws.send({ type: "full-reload" }), [];
320
320
  }
321
321
  },
322
322
  resolveId(t) {
323
- return t === g || t.endsWith(g) ? T : t === x || t.endsWith(x) || t === "/__velo_client.js" ? P : null;
323
+ return t === h || t.endsWith(h) ? T : t === g || t.endsWith(g) || t === "/__velo_client.js" ? N : null;
324
324
  },
325
325
  load(t) {
326
- const n = u.routesFile ?? "routes.tsx", s = u.serverInit ?? "server.tsx", o = u.clientInit ?? "client.tsx", a = d.join(r, n).replace(/\.tsx?$/, ".js"), p = d.join(r, s).replace(/\.tsx?$/, ".js"), f = d.join(r, o).replace(/\.tsx?$/, ".js");
326
+ const i = u.routesFile ?? "routes.tsx", s = u.serverInit ?? "server.tsx", o = u.clientInit ?? "client.tsx", a = d.join(r, i).replace(/\.tsx?$/, ".js"), p = d.join(r, s).replace(/\.tsx?$/, ".js"), f = d.join(r, o).replace(/\.tsx?$/, ".js");
327
327
  return t === T ? `
328
+ globalThis.__veloBuildHash = __VELO_BUILD_HASH__;
329
+ globalThis.__veloClientJs = __VELO_CLIENT_JS__;
330
+ globalThis.__veloClientCss = __VELO_CLIENT_CSS__;
328
331
  import "${p}";
329
332
  import routes from "${a}";
330
333
  import { startServer } from "@mauroandre/velojs/server";
331
334
 
332
335
  export { routes };
333
336
  export default await startServer({ routes });
334
- ` : t === P ? `
337
+ ` : t === N ? `
335
338
  import "${f}";
336
339
  import routes from "${a}";
337
340
  import { startClient } from "@mauroandre/velojs/client";
@@ -339,18 +342,18 @@ import { startClient } from "@mauroandre/velojs/client";
339
342
  startClient({ routes });
340
343
  ` : null;
341
344
  },
342
- transform(t, n, s) {
345
+ transform(t, i, s) {
343
346
  const o = s?.ssr === !0;
344
- if (n.startsWith("\0") || n.includes("/.velojs/") || !n.endsWith(".tsx") && !n.endsWith(".ts") || !n.startsWith(r)) return null;
347
+ if (i.startsWith("\0") || i.includes("/.velojs/") || !i.endsWith(".tsx") && !i.endsWith(".ts") || !i.startsWith(r)) return null;
345
348
  let a = t, p = !1;
346
- const f = /middlewares:\s*\[/.test(t), h = /export\s+(const|function)\s+Component/.test(
349
+ const f = /middlewares:\s*\[/.test(t), _ = /export\s+(const|function)\s+Component/.test(
347
350
  t
348
- ), y = /export\s+(const|function)\s+loader/.test(t), N = /export\s+const\s+action_\w+/.test(t), O = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), D = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t);
349
- if (!o && f && (a = k(a), p = !0), h || y || N || O || D) {
350
- const E = d.relative(r, n).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), I = i.get(E);
351
- a = w(a, E, I?.fullPath, I?.path), a = R(a, E), o || (a = V(
351
+ ), y = /export\s+(const|function)\s+loader/.test(t), A = /export\s+const\s+action_\w+/.test(t), O = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), C = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t);
352
+ if (!o && f && (a = J(a), p = !0), _ || y || A || O || C) {
353
+ const x = d.relative(r, i).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), I = n.get(x);
354
+ a = w(a, x, I?.fullPath, I?.path), a = V(a, x), o || (a = R(
352
355
  a,
353
- E
356
+ x
354
357
  )), o || (a = $(a)), p = !0;
355
358
  }
356
359
  return p ? {
@@ -360,26 +363,26 @@ startClient({ routes });
360
363
  }
361
364
  };
362
365
  }
363
- function M() {
366
+ function B() {
364
367
  return {
365
368
  name: "velo:config",
366
- config(u, { mode: c }) {
367
- const r = c === "server", l = c === "development", i = !!process.env.VELO_STATIC;
368
- let t = "client.js", n = "client.css";
369
+ config(u, { mode: l }) {
370
+ const r = l === "server", c = l === "development", n = !!process.env.VELO_STATIC;
371
+ let t = "client.js", i = "client.css";
369
372
  if (r)
370
373
  try {
371
- const o = d.resolve(process.cwd(), "dist/client/.vite/manifest.json"), p = JSON.parse(L.readFileSync(o, "utf-8"))[x];
372
- p && (t = p.file || t, p.css?.[0] && (n = p.css[0]));
374
+ const o = d.resolve(process.cwd(), "dist/client/.vite/manifest.json"), p = JSON.parse(L.readFileSync(o, "utf-8"))[g];
375
+ p && (t = p.file || t, p.css?.[0] && (i = p.css[0]));
373
376
  } catch {
374
377
  }
375
378
  const s = {
376
379
  define: {
377
- "process.env.NODE_ENV": JSON.stringify(l ? "development" : "production"),
378
- "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (i ? "/client" : "")),
379
- __VELO_STATIC__: JSON.stringify(i),
380
+ "process.env.NODE_ENV": JSON.stringify(c ? "development" : "production"),
381
+ "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (n ? "/client" : "")),
382
+ __VELO_STATIC__: JSON.stringify(n),
380
383
  __VELO_BUILD_HASH__: JSON.stringify(process.env.VELO_BUILD_HASH || Date.now().toString(36)),
381
384
  __VELO_CLIENT_JS__: JSON.stringify(t),
382
- __VELO_CLIENT_CSS__: JSON.stringify(n)
385
+ __VELO_CLIENT_CSS__: JSON.stringify(i)
383
386
  },
384
387
  resolve: {
385
388
  alias: {
@@ -389,7 +392,7 @@ function M() {
389
392
  }
390
393
  };
391
394
  return r ? s.build = {
392
- ssr: g,
395
+ ssr: h,
393
396
  outDir: "dist",
394
397
  emptyOutDir: !1,
395
398
  copyPublicDir: !1,
@@ -398,11 +401,11 @@ function M() {
398
401
  entryFileNames: "server.js"
399
402
  }
400
403
  }
401
- } : l || (s.build = {
404
+ } : c || (s.build = {
402
405
  manifest: !0,
403
406
  outDir: "dist/client",
404
407
  rollupOptions: {
405
- input: x,
408
+ input: g,
406
409
  output: {
407
410
  entryFileNames: "client.[hash].js",
408
411
  assetFileNames: (o) => o.names?.[0]?.endsWith(".css") ? "client.[hash].css" : "[name].[hash][extname]"
@@ -412,16 +415,16 @@ function M() {
412
415
  }
413
416
  };
414
417
  }
415
- function B() {
418
+ function M() {
416
419
  return {
417
420
  name: "velo:static-url",
418
421
  apply: "build",
419
422
  enforce: "post",
420
- generateBundle(u, c) {
423
+ generateBundle(u, l) {
421
424
  const r = process.env.STATIC_BASE_URL || "";
422
425
  if (r)
423
- for (const l of Object.values(c))
424
- l.type === "asset" && typeof l.source == "string" && l.fileName.endsWith(".css") && (l.source = l.source.replace(
426
+ for (const c of Object.values(l))
427
+ c.type === "asset" && typeof c.source == "string" && c.fileName.endsWith(".css") && (c.source = c.source.replace(
425
428
  /url\(\s*(['"]?)\/(?!\/)/g,
426
429
  `url($1${r}/`
427
430
  ));
@@ -429,14 +432,14 @@ function B() {
429
432
  };
430
433
  }
431
434
  function Z(u) {
432
- const c = u ?? {}, r = c.appDirectory ?? "./app";
435
+ const l = u ?? {}, r = l.appDirectory ?? "./app";
433
436
  return [
434
- M(),
435
- J(c, r),
436
437
  B(),
437
- C(),
438
+ k(l, r),
439
+ M(),
440
+ D(),
438
441
  F({
439
- entry: g
442
+ entry: h
440
443
  }),
441
444
  H()
442
445
  ];
@@ -450,12 +453,12 @@ function H() {
450
453
  };
451
454
  }
452
455
  export {
453
- _ as buildFullPathMap,
454
- A as collectFullPaths,
456
+ j as buildFullPathMap,
457
+ P as collectFullPaths,
455
458
  w as injectMetadata,
456
459
  $ as removeLoaders,
457
- k as removeMiddlewares,
458
- V as transformActionsForClient,
459
- R as transformLoaderFunctions,
460
+ J as removeMiddlewares,
461
+ R as transformActionsForClient,
462
+ V as transformLoaderFunctions,
460
463
  Z as veloPlugin
461
464
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mauroandre/velojs",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "type": "module",
5
5
  "description": "Fullstack web framework built on Hono + Preact with Vite-powered AST transforms",
6
6
  "keywords": [