@mauroandre/velojs 0.0.28 → 0.0.29

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/README.md CHANGED
@@ -1247,7 +1247,7 @@ Callbacks queue until the server starts. If called after startup, executes immed
1247
1247
 
1248
1248
  | Variable | Default | Description |
1249
1249
  |----------|---------|-------------|
1250
- | `SERVER_PORT` | `3000` | Server port |
1250
+ | `PORT` | `3000` | Server port. Overrides the `port` set in `defineConfig` |
1251
1251
  | `NODE_ENV` | — | Set automatically by `velojs start`. Enables static file serving |
1252
1252
  | `STATIC_BASE_URL` | `""` | CDN/bucket prefix for static assets |
1253
1253
 
@@ -1528,7 +1528,7 @@ COPY package.json package-lock.json ./
1528
1528
  RUN npm ci --omit=dev
1529
1529
  COPY --from=builder /app/dist ./dist
1530
1530
 
1531
- ENV SERVER_PORT=3000
1531
+ ENV PORT=3000
1532
1532
  EXPOSE 3000
1533
1533
  CMD ["npx", "velojs", "start"]
1534
1534
  ```
package/dist/config.d.ts CHANGED
@@ -19,5 +19,11 @@ export interface VeloConfig {
19
19
  * @default "client.tsx"
20
20
  */
21
21
  clientInit?: string;
22
+ /**
23
+ * Porta usada tanto pelo dev server quanto pelo servidor de produção.
24
+ * A env `PORT` (injetada pela maioria dos hosts) sempre tem precedência.
25
+ * @default 3000
26
+ */
27
+ port?: number;
22
28
  }
23
29
  export declare function defineConfig(config: VeloConfig): VeloConfig;
package/dist/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as g } from "preact/jsx-runtime";
2
- import { Hono as q } from "hono";
2
+ import { Hono as R } from "hono";
3
3
  import { logger as T } from "hono/logger";
4
4
  import { trimTrailingSlash as j } from "hono/trailing-slash";
5
5
  import { render as k } from "preact-render-to-string";
@@ -108,7 +108,7 @@ const N = (e, t, s) => {
108
108
  } else
109
109
  continue;
110
110
  }
111
- }, E = (e, t, s = []) => {
111
+ }, b = (e, t, s = []) => {
112
112
  for (const a of t) {
113
113
  const o = a.module?.metadata?.moduleId, n = [
114
114
  ...s,
@@ -137,8 +137,8 @@ const N = (e, t, s) => {
137
137
  const p = await c(f);
138
138
  return d.json(p ?? { ok: !0 });
139
139
  } catch (p) {
140
- const b = p instanceof Error ? p.message : "Action failed";
141
- return d.json({ error: b }, 500);
140
+ const E = p instanceof Error ? p.message : "Action failed";
141
+ return d.json({ error: E }, 500);
142
142
  }
143
143
  };
144
144
  n.length > 0 ? e.on(
@@ -150,7 +150,7 @@ const N = (e, t, s) => {
150
150
  }
151
151
  }
152
152
  }
153
- a.children && E(e, a.children, n);
153
+ a.children && b(e, a.children, n);
154
154
  }
155
155
  }, H = async (e, t, s = []) => {
156
156
  const a = (o, n) => {
@@ -191,7 +191,7 @@ const N = (e, t, s) => {
191
191
  }
192
192
  };
193
193
  return s(e), t;
194
- }, R = (e, t, s, a = "", o = []) => {
194
+ }, q = (e, t, s, a = "", o = []) => {
195
195
  for (const n of t) {
196
196
  const r = x(a, n.path), i = [
197
197
  ...o,
@@ -217,7 +217,7 @@ const N = (e, t, s) => {
217
217
  });
218
218
  i.length > 0 ? e.on([h], [r], ...i, m) : e.on([h], [r], m);
219
219
  }
220
- n.children && R(
220
+ n.children && q(
221
221
  e,
222
222
  n.children,
223
223
  s,
@@ -226,20 +226,20 @@ const N = (e, t, s) => {
226
226
  );
227
227
  }
228
228
  }, W = async (e) => {
229
- const t = new q();
229
+ const t = new R();
230
230
  t.use(j()), process.env.NODE_ENV !== "production" && t.use("*", T());
231
231
  const a = v().pendingRoutes.splice(0);
232
232
  for (const n of a)
233
233
  await n(t);
234
- _(t, e), E(t, e), await H(t, e);
234
+ _(t, e), b(t, e), await H(t, e);
235
235
  const o = V(e);
236
- if (R(t, e, o), await I(t, e), $(t), process.env.NODE_ENV !== "production" && !w) {
236
+ if (q(t, e, o), await I(t, e), $(t), process.env.NODE_ENV !== "production" && !w) {
237
237
  const n = globalThis.__veloDevServer;
238
238
  n && (P(n), await y(t, n));
239
239
  }
240
240
  return t;
241
241
  }, ee = async (e) => {
242
- const { routes: t, port: s = Number(process.env.SERVER_PORT) || 3e3 } = e, a = await W(t);
242
+ const { routes: t } = e, s = Number(process.env.PORT) || e.port || 3e3, a = await W(t);
243
243
  if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
244
244
  const { serve: o } = await import("@hono/node-server"), { serveStatic: n } = await import("@hono/node-server/serve-static"), { join: r } = await import("node:path"), i = r(process.cwd(), "dist/client");
245
245
  (process.env.STATIC_BASE_URL || "").startsWith("http") || a.use("/*", n({ root: i })), console.log(`Server running on http://localhost:${s}`);
package/dist/vite.js CHANGED
@@ -1,14 +1,14 @@
1
- import m from "node:path";
1
+ import y from "node:path";
2
2
  import S from "node:fs";
3
3
  import R from "@preact/preset-vite";
4
4
  import $ from "@hono/vite-dev-server";
5
- import { parse as y } from "@babel/parser";
5
+ import { parse as _ } from "@babel/parser";
6
6
  import g from "@babel/traverse";
7
7
  import j from "@babel/generator";
8
8
  import * as e from "@babel/types";
9
9
  const d = typeof g == "function" ? g : g.default, h = typeof j == "function" ? j : j.default;
10
10
  function U(p, c, i, n) {
11
- const o = y(p, {
11
+ const o = _(p, {
12
12
  sourceType: "module",
13
13
  plugins: ["typescript", "jsx"]
14
14
  });
@@ -21,23 +21,23 @@ function U(p, c, i, n) {
21
21
  const r = a.declarations[0];
22
22
  if (r && e.isIdentifier(r.id, { name: "metadata" }) && e.isObjectExpression(r.init)) {
23
23
  t = !0;
24
- const f = r.init.properties.filter((_) => e.isObjectProperty(_) && e.isIdentifier(_.key) ? _.key.name !== "moduleId" && _.key.name !== "fullPath" && _.key.name !== "path" : !0), x = [
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 = [
25
25
  e.objectProperty(
26
26
  e.identifier("moduleId"),
27
27
  e.stringLiteral(c)
28
28
  )
29
29
  ];
30
- i !== void 0 && x.push(
30
+ i !== void 0 && m.push(
31
31
  e.objectProperty(
32
32
  e.identifier("fullPath"),
33
33
  e.stringLiteral(i)
34
34
  )
35
- ), n !== void 0 && x.push(
35
+ ), n !== void 0 && m.push(
36
36
  e.objectProperty(
37
37
  e.identifier("path"),
38
38
  e.stringLiteral(n)
39
39
  )
40
- ), r.init.properties = [...x, ...f];
40
+ ), r.init.properties = [...m, ...f];
41
41
  }
42
42
  }
43
43
  }
@@ -72,7 +72,7 @@ function U(p, c, i, n) {
72
72
  return h(o, { retainLines: !0 }).code;
73
73
  }
74
74
  function W(p, c) {
75
- const i = y(p, {
75
+ const i = _(p, {
76
76
  sourceType: "module",
77
77
  plugins: ["typescript", "jsx"]
78
78
  });
@@ -86,7 +86,7 @@ function W(p, c) {
86
86
  }), h(i, { retainLines: !0 }).code;
87
87
  }
88
88
  function J(p, c) {
89
- const i = y(p, {
89
+ const i = _(p, {
90
90
  sourceType: "module",
91
91
  plugins: ["typescript", "jsx"]
92
92
  });
@@ -202,7 +202,7 @@ function B(p, c) {
202
202
  }
203
203
  }
204
204
  function H(p, c) {
205
- const i = y(p, {
205
+ const i = _(p, {
206
206
  sourceType: "module",
207
207
  plugins: ["typescript", "jsx"]
208
208
  });
@@ -229,7 +229,7 @@ function H(p, c) {
229
229
  }), h(i, { retainLines: !0 }).code;
230
230
  }
231
231
  function z(p, c) {
232
- const i = y(p, {
232
+ const i = _(p, {
233
233
  sourceType: "module",
234
234
  plugins: ["typescript", "jsx"]
235
235
  });
@@ -255,8 +255,8 @@ function z(p, c) {
255
255
  }
256
256
  }), h(i, { retainLines: !0 }).code;
257
257
  }
258
- function Y(p) {
259
- const c = y(p, {
258
+ function G(p) {
259
+ const c = _(p, {
260
260
  sourceType: "module",
261
261
  plugins: ["typescript", "jsx"]
262
262
  });
@@ -269,8 +269,8 @@ function Y(p) {
269
269
  }
270
270
  }), h(c, { retainLines: !0 }).code;
271
271
  }
272
- function q(p) {
273
- const c = y(p, {
272
+ function Y(p) {
273
+ const c = _(p, {
274
274
  sourceType: "module",
275
275
  plugins: ["typescript", "jsx"]
276
276
  }), i = /* @__PURE__ */ new Set();
@@ -295,7 +295,7 @@ function q(p) {
295
295
  }
296
296
  }), h(c, { retainLines: !0 }).code);
297
297
  }
298
- function A(p, c) {
298
+ function O(p, c) {
299
299
  const i = (n) => {
300
300
  if (!(!n || typeof n != "object")) {
301
301
  if (Array.isArray(n)) {
@@ -321,7 +321,7 @@ function A(p, c) {
321
321
  };
322
322
  i(p);
323
323
  }
324
- function G(p) {
324
+ function q(p) {
325
325
  for (const c of p.properties)
326
326
  if (e.isObjectProperty(c) && e.isIdentifier(c.key) && c.key.name === "handler")
327
327
  return !0;
@@ -334,14 +334,14 @@ function K(p) {
334
334
  return null;
335
335
  }
336
336
  function Q(p) {
337
- const c = y(p, {
337
+ const c = _(p, {
338
338
  sourceType: "module",
339
339
  plugins: ["typescript", "jsx"]
340
340
  }), i = [], n = (a) => {
341
341
  for (let r = a.elements.length - 1; r >= 0; r--) {
342
342
  const u = a.elements[r];
343
343
  if (!e.isObjectExpression(u)) continue;
344
- if (G(u)) {
344
+ if (q(u)) {
345
345
  i.push(u), a.elements.splice(r, 1);
346
346
  continue;
347
347
  }
@@ -358,9 +358,9 @@ function Q(p) {
358
358
  }), i.length === 0) return p;
359
359
  const o = /* @__PURE__ */ new Set();
360
360
  for (const a of i)
361
- A(a, o);
361
+ O(a, o);
362
362
  const t = /* @__PURE__ */ new Set();
363
- A(c.program, t);
363
+ O(c.program, t);
364
364
  const s = /* @__PURE__ */ new Set();
365
365
  for (const a of o)
366
366
  t.has(a) || s.add(a);
@@ -371,8 +371,8 @@ function Q(p) {
371
371
  }
372
372
  }), h(c, { retainLines: !0 }).code;
373
373
  }
374
- function P(p) {
375
- const c = y(p, {
374
+ function A(p) {
375
+ const c = _(p, {
376
376
  sourceType: "module",
377
377
  plugins: ["typescript", "jsx"]
378
378
  }), i = /* @__PURE__ */ new Map();
@@ -420,29 +420,29 @@ function C(p, c, i) {
420
420
  l && C(l.elements, t, i);
421
421
  }
422
422
  }
423
- const b = "virtual:velo/server-entry", E = "virtual:velo/client-entry", N = "\0" + b, O = "\0" + E;
423
+ const E = "virtual:velo/server-entry", b = "virtual:velo/client-entry", P = "\0" + E, N = "\0" + b;
424
424
  function X(p, c) {
425
- let i = m.resolve(process.cwd(), c);
425
+ let i = y.resolve(process.cwd(), c);
426
426
  const n = p.routesFile ?? "routes.tsx", o = /* @__PURE__ */ new Map();
427
427
  return {
428
428
  name: "velo:transform",
429
429
  enforce: "pre",
430
430
  configResolved(t) {
431
- i = m.resolve(t.root, c);
431
+ i = y.resolve(t.root, c);
432
432
  },
433
433
  buildStart() {
434
- const t = m.join(i, n);
434
+ const t = y.join(i, n);
435
435
  if (S.existsSync(t)) {
436
- const s = S.readFileSync(t, "utf-8"), l = P(s);
436
+ const s = S.readFileSync(t, "utf-8"), l = A(s);
437
437
  o.clear();
438
438
  for (const [a, r] of l)
439
439
  o.set(a, r);
440
440
  }
441
441
  },
442
442
  handleHotUpdate({ file: t, server: s }) {
443
- const l = m.join(i, n);
443
+ const l = y.join(i, n);
444
444
  if (t === l) {
445
- const a = S.readFileSync(l, "utf-8"), r = P(a);
445
+ const a = S.readFileSync(l, "utf-8"), r = A(a);
446
446
  o.clear();
447
447
  for (const [u, f] of r)
448
448
  o.set(u, f);
@@ -450,11 +450,11 @@ function X(p, c) {
450
450
  }
451
451
  },
452
452
  resolveId(t) {
453
- return t === b || t.endsWith(b) ? N : t === E || t.endsWith(E) || t === "/__velo_client.js" ? O : null;
453
+ return t === E || t.endsWith(E) ? P : t === b || t.endsWith(b) || t === "/__velo_client.js" ? N : null;
454
454
  },
455
455
  load(t) {
456
- const s = p.routesFile ?? "routes.tsx", l = p.serverInit ?? "server.tsx", a = p.clientInit ?? "client.tsx", r = m.join(i, s).replace(/\.tsx?$/, ".js"), u = m.join(i, l).replace(/\.tsx?$/, ".js"), f = m.join(i, a).replace(/\.tsx?$/, ".js");
457
- return t === N ? `
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 ? `
458
458
  globalThis.__veloBuildHash = __VELO_BUILD_HASH__;
459
459
  globalThis.__veloClientJs = __VELO_CLIENT_JS__;
460
460
  globalThis.__veloClientCss = __VELO_CLIENT_CSS__;
@@ -463,8 +463,8 @@ import routes from "${r}";
463
463
  import { startServer } from "@mauroandre/velojs/server";
464
464
 
465
465
  export { routes };
466
- export default await startServer({ routes });
467
- ` : t === O ? `
466
+ export default await startServer({ routes, port: __VELO_CONFIG_PORT__ });
467
+ ` : t === N ? `
468
468
  import "${f}";
469
469
  import routes from "${r}";
470
470
  import { startClient } from "@mauroandre/velojs/client";
@@ -476,21 +476,21 @@ startClient({ routes });
476
476
  const a = l?.ssr === !0;
477
477
  if (s.startsWith("\0") || s.includes("/.velojs/") || !s.endsWith(".tsx") && !s.endsWith(".ts") || !s.startsWith(i)) return null;
478
478
  let r = t, u = !1;
479
- const f = /middlewares:\s*\[/.test(t), x = /export\s+(const|function)\s+Component/.test(
479
+ const f = /middlewares:\s*\[/.test(t), m = /export\s+(const|function)\s+Component/.test(
480
480
  t
481
- ), _ = /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), k = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t), F = /\bhandler\s*:/.test(t), V = m.join(i, n);
482
- if (!a && f && (r = q(r), u = !0), !a && F && s === V && (r = Q(r), u = !0), x || _ || D || L || I || w || k) {
483
- const v = m.relative(i, s).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), T = o.get(v);
484
- r = U(r, v, T?.fullPath, T?.path), r = W(r, v), a || (r = J(
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
485
  r,
486
- v
486
+ x
487
487
  )), !a && L && (r = H(
488
488
  r,
489
- v
489
+ x
490
490
  )), !a && I && (r = z(
491
491
  r,
492
- v
493
- )), a || (r = Y(r)), u = !0;
492
+ x
493
+ )), a || (r = G(r)), u = !0;
494
494
  }
495
495
  return u ? {
496
496
  code: r,
@@ -499,36 +499,42 @@ startClient({ routes });
499
499
  }
500
500
  };
501
501
  }
502
- function Z() {
502
+ function Z(p) {
503
503
  return {
504
504
  name: "velo:config",
505
- config(p, { mode: c }) {
506
- const i = c === "server", n = c === "development", o = !!process.env.VELO_STATIC;
507
- let t = "client.js", s = "client.css";
508
- if (i)
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;
507
+ let l = "client.js", a = "client.css";
508
+ if (n)
509
509
  try {
510
- const a = m.resolve(process.cwd(), "dist/client/.vite/manifest.json"), u = JSON.parse(S.readFileSync(a, "utf-8"))[E];
511
- u && (t = u.file || t, u.css?.[0] && (s = u.css[0]));
510
+ const u = y.resolve(process.cwd(), "dist/client/.vite/manifest.json"), m = JSON.parse(S.readFileSync(u, "utf-8"))[b];
511
+ m && (l = m.file || l, m.css?.[0] && (a = m.css[0]));
512
512
  } catch {
513
513
  }
514
- const l = {
514
+ const r = {
515
515
  define: {
516
- "process.env.NODE_ENV": JSON.stringify(n ? "development" : "production"),
517
- "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (o ? "/client" : "")),
518
- __VELO_STATIC__: JSON.stringify(o),
516
+ "process.env.NODE_ENV": JSON.stringify(o ? "development" : "production"),
517
+ "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (t ? "/client" : "")),
518
+ __VELO_STATIC__: JSON.stringify(t),
519
519
  __VELO_BUILD_HASH__: JSON.stringify(process.env.VELO_BUILD_HASH || Date.now().toString(36)),
520
- __VELO_CLIENT_JS__: JSON.stringify(t),
521
- __VELO_CLIENT_CSS__: JSON.stringify(s)
520
+ __VELO_CLIENT_JS__: JSON.stringify(l),
521
+ __VELO_CLIENT_CSS__: JSON.stringify(a),
522
+ // Baked into the server bundle as startServer's port fallback.
523
+ // null when unset → startServer falls back to PORT env / 3000.
524
+ __VELO_CONFIG_PORT__: JSON.stringify(p.port ?? null)
522
525
  },
523
526
  resolve: {
524
527
  alias: {
525
528
  react: "preact/compat",
526
529
  "react-dom": "preact/compat"
527
530
  }
531
+ },
532
+ server: {
533
+ port: s
528
534
  }
529
535
  };
530
- return i ? l.build = {
531
- ssr: b,
536
+ return n ? r.build = {
537
+ ssr: E,
532
538
  outDir: "dist",
533
539
  emptyOutDir: !1,
534
540
  copyPublicDir: !1,
@@ -537,17 +543,17 @@ function Z() {
537
543
  entryFileNames: "server.js"
538
544
  }
539
545
  }
540
- } : n || (l.build = {
546
+ } : o || (r.build = {
541
547
  manifest: !0,
542
548
  outDir: "dist/client",
543
549
  rollupOptions: {
544
- input: E,
550
+ input: b,
545
551
  output: {
546
552
  entryFileNames: "client.[hash].js",
547
- assetFileNames: (a) => a.names?.[0]?.endsWith(".css") ? "client.[hash].css" : "[name].[hash][extname]"
553
+ assetFileNames: (u) => u.names?.[0]?.endsWith(".css") ? "client.[hash].css" : "[name].[hash][extname]"
548
554
  }
549
555
  }
550
- }), l;
556
+ }), r;
551
557
  }
552
558
  };
553
559
  }
@@ -570,12 +576,12 @@ function ee() {
570
576
  function le(p) {
571
577
  const c = p ?? {}, i = c.appDirectory ?? "./app";
572
578
  return [
573
- Z(),
579
+ Z(c),
574
580
  X(c, i),
575
581
  ee(),
576
582
  R(),
577
583
  $({
578
- entry: b
584
+ entry: E
579
585
  }),
580
586
  te()
581
587
  ];
@@ -589,12 +595,12 @@ function te() {
589
595
  };
590
596
  }
591
597
  export {
592
- P as buildFullPathMap,
598
+ A as buildFullPathMap,
593
599
  C as collectFullPaths,
594
600
  U as injectMetadata,
595
601
  Q as removeEndpointRoutes,
596
- Y as removeLoaders,
597
- q as removeMiddlewares,
602
+ G as removeLoaders,
603
+ Y as removeMiddlewares,
598
604
  J as transformActionsForClient,
599
605
  W as transformLoaderFunctions,
600
606
  z as transformSocketsForClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mauroandre/velojs",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "type": "module",
5
5
  "description": "Fullstack web framework built on Hono + Preact with Vite-powered AST transforms",
6
6
  "keywords": [