@mauroandre/velojs 0.0.16 → 0.0.17

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/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,12 +1,12 @@
1
1
  import d from "node:path";
2
- import L from "node:fs";
2
+ import _ from "node:fs";
3
3
  import C 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;
9
+ const m = typeof E == "function" ? E : E.default, S = typeof b == "function" ? b : b.default;
10
10
  function w(u, c, r, l) {
11
11
  const i = v(u, {
12
12
  sourceType: "module",
@@ -241,7 +241,7 @@ function k(u) {
241
241
  }
242
242
  }), S(c, { retainLines: !0 }).code);
243
243
  }
244
- function _(u) {
244
+ function j(u) {
245
245
  const c = v(u, {
246
246
  sourceType: "module",
247
247
  plugins: ["typescript", "jsx"]
@@ -291,7 +291,7 @@ function A(u, c, r) {
291
291
  }
292
292
  }
293
293
  const g = "virtual:velo/server-entry", x = "virtual:velo/client-entry", T = "\0" + g, P = "\0" + x;
294
- function J(u, c) {
294
+ function B(u, c) {
295
295
  let r = d.resolve(process.cwd(), c);
296
296
  const l = u.routesFile ?? "routes.tsx", i = /* @__PURE__ */ new Map();
297
297
  return {
@@ -302,8 +302,8 @@ function J(u, c) {
302
302
  },
303
303
  buildStart() {
304
304
  const t = d.join(r, l);
305
- if (L.existsSync(t)) {
306
- const n = L.readFileSync(t, "utf-8"), s = _(n);
305
+ if (_.existsSync(t)) {
306
+ const n = _.readFileSync(t, "utf-8"), s = j(n);
307
307
  i.clear();
308
308
  for (const [o, a] of s)
309
309
  i.set(o, a);
@@ -312,7 +312,7 @@ function J(u, c) {
312
312
  handleHotUpdate({ file: t, server: n }) {
313
313
  const s = d.join(r, l);
314
314
  if (t === s) {
315
- const o = L.readFileSync(s, "utf-8"), a = _(o);
315
+ const o = _.readFileSync(s, "utf-8"), a = j(o);
316
316
  i.clear();
317
317
  for (const [p, f] of a)
318
318
  i.set(p, f);
@@ -325,6 +325,7 @@ function J(u, c) {
325
325
  load(t) {
326
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");
327
327
  return t === T ? `
328
+ globalThis.__veloBuildHash = __VELO_BUILD_HASH__;
328
329
  import "${p}";
329
330
  import routes from "${a}";
330
331
  import { startServer } from "@mauroandre/velojs/server";
@@ -347,10 +348,10 @@ startClient({ routes });
347
348
  t
348
349
  ), 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
350
  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
+ const L = d.relative(r, n).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), I = i.get(L);
352
+ a = w(a, L, I?.fullPath, I?.path), a = R(a, L), o || (a = V(
352
353
  a,
353
- E
354
+ L
354
355
  )), o || (a = $(a)), p = !0;
355
356
  }
356
357
  return p ? {
@@ -360,7 +361,7 @@ startClient({ routes });
360
361
  }
361
362
  };
362
363
  }
363
- function M() {
364
+ function J() {
364
365
  return {
365
366
  name: "velo:config",
366
367
  config(u, { mode: c }) {
@@ -368,7 +369,7 @@ function M() {
368
369
  let t = "client.js", n = "client.css";
369
370
  if (r)
370
371
  try {
371
- const o = d.resolve(process.cwd(), "dist/client/.vite/manifest.json"), p = JSON.parse(L.readFileSync(o, "utf-8"))[x];
372
+ const o = d.resolve(process.cwd(), "dist/client/.vite/manifest.json"), p = JSON.parse(_.readFileSync(o, "utf-8"))[x];
372
373
  p && (t = p.file || t, p.css?.[0] && (n = p.css[0]));
373
374
  } catch {
374
375
  }
@@ -412,7 +413,7 @@ function M() {
412
413
  }
413
414
  };
414
415
  }
415
- function B() {
416
+ function M() {
416
417
  return {
417
418
  name: "velo:static-url",
418
419
  apply: "build",
@@ -431,9 +432,9 @@ function B() {
431
432
  function Z(u) {
432
433
  const c = u ?? {}, r = c.appDirectory ?? "./app";
433
434
  return [
435
+ J(),
436
+ B(c, r),
434
437
  M(),
435
- J(c, r),
436
- B(),
437
438
  C(),
438
439
  F({
439
440
  entry: g
@@ -450,7 +451,7 @@ function H() {
450
451
  };
451
452
  }
452
453
  export {
453
- _ as buildFullPathMap,
454
+ j as buildFullPathMap,
454
455
  A as collectFullPaths,
455
456
  w as injectMetadata,
456
457
  $ as removeLoaders,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mauroandre/velojs",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "type": "module",
5
5
  "description": "Fullstack web framework built on Hono + Preact with Vite-powered AST transforms",
6
6
  "keywords": [