@mauroandre/velojs 0.0.14 → 0.0.15

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,15 +1,19 @@
1
1
  import { spawnSync as c } from "node:child_process";
2
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, {
3
+ const o = process.argv.slice(2), r = o[0], l = (e, t = []) => {
4
+ const s = c(e, t, {
5
5
  stdio: "inherit",
6
6
  cwd: process.cwd()
7
7
  });
8
- process.exit(o.status ?? 0);
8
+ process.exit(s.status ?? 0);
9
9
  }, p = () => {
10
- l("npx", ["vite", ...t.slice(1)]);
11
- }, v = (e) => {
12
- const s = e ? { ...process.env, VELO_STATIC: "1" } : process.env;
10
+ l("npx", ["vite", ...o.slice(1)]);
11
+ }, u = (e) => {
12
+ const t = Date.now().toString(36), s = {
13
+ ...process.env,
14
+ VELO_BUILD_HASH: t,
15
+ ...e ? { VELO_STATIC: "1" } : {}
16
+ };
13
17
  console.log("Building client..."), c("npx", ["vite", "build"], {
14
18
  stdio: "inherit",
15
19
  cwd: process.cwd(),
@@ -18,13 +22,13 @@ const t = process.argv.slice(2), r = t[0], l = (e, s = []) => {
18
22
  stdio: "inherit",
19
23
  cwd: process.cwd(),
20
24
  env: s
21
- }), console.log("Build complete!"), e && u();
22
- }, u = async () => {
25
+ }), console.log("Build complete!"), e && v();
26
+ }, v = async () => {
23
27
  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));
28
+ const t = await import(a(process.cwd(), "dist/server.js")), s = t.default, i = t.routes;
29
+ (!s || !i) && (console.error("Failed to load app or routes from dist/server.js"), process.exit(1));
26
30
  const { generateStatic: d } = await import("./static.js");
27
- await d(o, i);
31
+ await d(s, i);
28
32
  }, m = () => {
29
33
  process.env.NODE_ENV = "production";
30
34
  const e = a(process.cwd(), "dist/server.js");
@@ -54,15 +58,15 @@ Examples:
54
58
  switch (r) {
55
59
  case "init": {
56
60
  const { runInit: e } = await import("./init.js");
57
- await e(t[1]);
61
+ await e(o[1]);
58
62
  break;
59
63
  }
60
64
  case "dev":
61
65
  p();
62
66
  break;
63
67
  case "build": {
64
- const e = t.includes("--static");
65
- v(e);
68
+ const e = o.includes("--static");
69
+ u(e);
66
70
  break;
67
71
  }
68
72
  case "start":
@@ -1,48 +1,48 @@
1
- import { jsx as r, jsxs as u, Fragment as a } from "preact/jsx-runtime";
2
- import { Link as S } from "wouter-preact";
3
- import { __veloUpdatePending as v } from "./hooks.js";
4
- function C({ basePath: e, favicon: n = "/favicon.ico" } = {}) {
5
- const t = process.env.NODE_ENV !== "production";
1
+ import { jsx as o, jsxs as p, Fragment as L } from "preact/jsx-runtime";
2
+ import { Link as v } from "wouter-preact";
3
+ import { __veloUpdatePending as E } from "./hooks.js";
4
+ function k({ basePath: e, favicon: t = "/favicon.ico" } = {}) {
5
+ const n = process.env.NODE_ENV !== "production";
6
6
  e = e || process.env.STATIC_BASE_URL || (process.env.VELO_STATIC ? "/client" : "");
7
- const i = n !== !1 && /* @__PURE__ */ r("link", { rel: "icon", href: `${e}${n}`, type: "image/x-icon" });
8
- if (t)
9
- return /* @__PURE__ */ u(a, { children: [
7
+ const i = t !== !1 && /* @__PURE__ */ o("link", { rel: "icon", href: `${e}${t}`, type: "image/x-icon" });
8
+ if (n)
9
+ return /* @__PURE__ */ p(L, { children: [
10
10
  i,
11
- /* @__PURE__ */ r("script", { type: "module", src: "/@vite/client" }),
12
- /* @__PURE__ */ r("script", { type: "module", src: "/__velo_client.js" })
11
+ /* @__PURE__ */ o("script", { type: "module", src: "/@vite/client" }),
12
+ /* @__PURE__ */ o("script", { type: "module", src: "/__velo_client.js" })
13
13
  ] });
14
- const o = typeof __VELO_CLIENT_JS__ < "u" ? __VELO_CLIENT_JS__ : "client.js";
15
- return /* @__PURE__ */ u(a, { children: [
14
+ const r = typeof __VELO_CLIENT_JS__ < "u" ? __VELO_CLIENT_JS__ : "client.js";
15
+ return /* @__PURE__ */ p(L, { children: [
16
16
  i,
17
- /* @__PURE__ */ r("link", { rel: "stylesheet", href: `${e}/${typeof __VELO_CLIENT_CSS__ < "u" ? __VELO_CLIENT_CSS__ : "client.css"}` }),
18
- /* @__PURE__ */ r("script", { type: "module", src: `${e}/${o}` })
17
+ /* @__PURE__ */ o("link", { rel: "stylesheet", href: `${e}/${typeof __VELO_CLIENT_CSS__ < "u" ? __VELO_CLIENT_CSS__ : "client.css"}` }),
18
+ /* @__PURE__ */ o("script", { type: "module", src: `${e}/${r}` })
19
19
  ] });
20
20
  }
21
- function E(e, n) {
22
- let t = e;
23
- for (const [i, o] of Object.entries(n))
24
- t = t.replace(`:${i}`, o);
25
- return t;
21
+ function $(e, t) {
22
+ let n = e;
23
+ for (const [i, r] of Object.entries(t))
24
+ n = n.replace(`:${i}`, r);
25
+ return n;
26
26
  }
27
- function T({ to: e, params: n, search: t, absolute: i, ...o }) {
28
- const c = typeof e != "string", _ = c ? (i ? e.metadata?.fullPath : e.metadata?.path) ?? "/" : e, f = n ? E(_, n) : _, d = c && i ? `~${f}` : f, m = t ? `?${new URLSearchParams(t).toString()}` : "", s = `${d}${m}`;
29
- if (typeof window < "u" && v.value) {
30
- const { onClick: p, ...L } = o;
31
- return /* @__PURE__ */ r(
27
+ function g({ to: e, params: t, search: n, absolute: i, ...r }) {
28
+ const c = typeof e != "string", s = c ? (i ? e.metadata?.fullPath : e.metadata?.path) ?? "/" : e, f = t ? $(s, t) : s, m = c && i ? `~${f}` : f, _ = n ? `?${new URLSearchParams(n).toString()}` : "", S = `${m}${_}`;
29
+ if (typeof window < "u" && E.value) {
30
+ const u = c ? e.metadata?.fullPath ?? s : s, a = `${t ? $(u, t) : u}${_}`, { onClick: d, ...h } = r;
31
+ return /* @__PURE__ */ o(
32
32
  "a",
33
33
  {
34
- href: s.replace(/^~/, ""),
34
+ href: a,
35
35
  onClick: (l) => {
36
- p && p(l), l.defaultPrevented || (l.preventDefault(), window.location.href = s.replace(/^~/, ""));
36
+ d && d(l), l.defaultPrevented || (l.preventDefault(), window.location.href = a);
37
37
  },
38
- ...L
38
+ ...h
39
39
  }
40
40
  );
41
41
  }
42
- return /* @__PURE__ */ r(S, { to: s, ...o });
42
+ return /* @__PURE__ */ o(v, { to: S, ...r });
43
43
  }
44
44
  export {
45
- T as Link,
46
- C as Scripts,
47
- E as substituteParams
45
+ g as Link,
46
+ k as Scripts,
47
+ $ as substituteParams
48
48
  };
package/dist/vite.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import d from "node:path";
2
- import b from "node:fs";
2
+ import L 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 L from "@babel/traverse";
6
+ import b from "@babel/traverse";
7
7
  import j from "@babel/generator";
8
8
  import * as e from "@babel/types";
9
- const m = typeof L == "function" ? L : L.default, S = typeof j == "function" ? j : j.default;
9
+ const m = typeof b == "function" ? b : b.default, S = typeof j == "function" ? j : j.default;
10
10
  function w(u, c, r, l) {
11
11
  const i = v(u, {
12
12
  sourceType: "module",
@@ -21,7 +21,7 @@ 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 p = 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), h = [
25
25
  e.objectProperty(
26
26
  e.identifier("moduleId"),
27
27
  e.stringLiteral(c)
@@ -37,7 +37,7 @@ function w(u, c, r, l) {
37
37
  e.identifier("path"),
38
38
  e.stringLiteral(l)
39
39
  )
40
- ), a.init.properties = [...h, ...p];
40
+ ), a.init.properties = [...h, ...f];
41
41
  }
42
42
  }
43
43
  }
@@ -80,8 +80,8 @@ function R(u, c) {
80
80
  CallExpression(i) {
81
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
82
  if (!n && !s) return;
83
- const o = i.node.arguments, a = e.stringLiteral(c), f = o[0];
84
- e.isStringLiteral(f) && f.value.includes("/") || (i.node.arguments = [a, ...o]);
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]);
85
85
  }
86
86
  }), S(r, { retainLines: !0 }).code;
87
87
  }
@@ -100,12 +100,12 @@ function V(u, c) {
100
100
  if (!s.startsWith("action_")) return;
101
101
  const o = s.replace("action_", ""), a = n.init;
102
102
  if (!e.isArrowFunctionExpression(a) || !a.async) return;
103
- const f = a.params, p = W(c, o, f);
104
- a.body = e.blockStatement([e.returnStatement(p)]), $(a, f);
103
+ const p = a.params, f = U(c, o, p);
104
+ a.body = e.blockStatement([e.returnStatement(f)]), W(a, p);
105
105
  }
106
106
  }), S(r, { retainLines: !0 }).code;
107
107
  }
108
- function W(u, c, r) {
108
+ function U(u, c, r) {
109
109
  const l = `/_action/${u}/${c}`;
110
110
  return r.length === 0 ? e.callExpression(
111
111
  e.memberExpression(
@@ -175,7 +175,7 @@ function W(u, c, r) {
175
175
  ]
176
176
  );
177
177
  }
178
- function $(u, c) {
178
+ function W(u, c) {
179
179
  if (c.length === 0) return;
180
180
  const r = c[0];
181
181
  if (e.isObjectPattern(r)) {
@@ -201,7 +201,7 @@ function $(u, c) {
201
201
  )), u.params = [t];
202
202
  }
203
203
  }
204
- function U(u) {
204
+ function $(u) {
205
205
  const c = v(u, {
206
206
  sourceType: "module",
207
207
  plugins: ["typescript", "jsx"]
@@ -258,7 +258,7 @@ function _(u) {
258
258
  ExportDefaultDeclaration(t) {
259
259
  const n = 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 && 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
264
  const i = /* @__PURE__ */ new Map();
@@ -271,14 +271,14 @@ function _(u) {
271
271
  }
272
272
  return i;
273
273
  }
274
- function N(u, c, r) {
274
+ function A(u, c, r) {
275
275
  for (const l of u) {
276
276
  if (!e.isObjectExpression(l)) continue;
277
277
  let i = "", t = c, n = null, s = null;
278
278
  for (const o of l.properties) {
279
279
  if (!e.isObjectProperty(o)) continue;
280
- const a = o.key, f = e.isIdentifier(a) ? a.name : null;
281
- f === "path" && e.isStringLiteral(o.value) && (i = o.value.value, i && !i.startsWith("/") ? t = c + "/" + i : t = c + i), f === "module" && e.isIdentifier(o.value) && (n = o.value.name), f === "children" && e.isArrayExpression(o.value) && (s = o.value);
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);
282
282
  }
283
283
  if (n) {
284
284
  const a = !s && i === "/" ? c || "/" : t;
@@ -287,7 +287,7 @@ function N(u, c, r) {
287
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
293
  const g = "virtual:velo/server-entry", x = "virtual:velo/client-entry", T = "\0" + g, P = "\0" + x;
@@ -302,8 +302,8 @@ function J(u, c) {
302
302
  },
303
303
  buildStart() {
304
304
  const t = d.join(r, l);
305
- if (b.existsSync(t)) {
306
- const n = b.readFileSync(t, "utf-8"), s = _(n);
305
+ if (L.existsSync(t)) {
306
+ const n = L.readFileSync(t, "utf-8"), s = _(n);
307
307
  i.clear();
308
308
  for (const [o, a] of s)
309
309
  i.set(o, a);
@@ -312,10 +312,10 @@ 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 = b.readFileSync(s, "utf-8"), a = _(o);
315
+ const o = L.readFileSync(s, "utf-8"), a = _(o);
316
316
  i.clear();
317
- for (const [f, p] of a)
318
- i.set(f, p);
317
+ for (const [p, f] of a)
318
+ i.set(p, f);
319
319
  return n.ws.send({ type: "full-reload" }), [];
320
320
  }
321
321
  },
@@ -323,16 +323,16 @@ function J(u, c) {
323
323
  return t === g || t.endsWith(g) ? T : t === x || t.endsWith(x) || t === "/__velo_client.js" ? P : 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"), f = d.join(r, s).replace(/\.tsx?$/, ".js"), p = d.join(r, o).replace(/\.tsx?$/, ".js");
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
- import "${f}";
328
+ import "${p}";
329
329
  import routes from "${a}";
330
330
  import { startServer } from "@mauroandre/velojs/server";
331
331
 
332
332
  export { routes };
333
333
  export default await startServer({ routes });
334
334
  ` : t === P ? `
335
- import "${p}";
335
+ import "${f}";
336
336
  import routes from "${a}";
337
337
  import { startClient } from "@mauroandre/velojs/client";
338
338
 
@@ -342,18 +342,18 @@ startClient({ routes });
342
342
  transform(t, n, s) {
343
343
  const o = s?.ssr === !0;
344
344
  if (n.startsWith("\0") || n.includes("/.velojs/") || !n.endsWith(".tsx") && !n.endsWith(".ts") || !n.startsWith(r)) return null;
345
- let a = t, f = !1;
346
- const p = /middlewares:\s*\[/.test(t), h = /export\s+(const|function)\s+Component/.test(
345
+ let a = t, p = !1;
346
+ const f = /middlewares:\s*\[/.test(t), h = /export\s+(const|function)\s+Component/.test(
347
347
  t
348
- ), 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), D = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t);
349
- if (!o && p && (a = k(a), f = !0), h || y || A || O || D) {
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
350
  const E = d.relative(r, n).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), I = i.get(E);
351
351
  a = w(a, E, I?.fullPath, I?.path), a = R(a, E), o || (a = V(
352
352
  a,
353
353
  E
354
- )), o || (a = U(a)), f = !0;
354
+ )), o || (a = $(a)), p = !0;
355
355
  }
356
- return f ? {
356
+ return p ? {
357
357
  code: a,
358
358
  map: null
359
359
  } : null;
@@ -368,8 +368,8 @@ function M() {
368
368
  let t = "client.js", n = "client.css";
369
369
  if (r)
370
370
  try {
371
- const o = d.resolve(process.cwd(), "dist/client/.vite/manifest.json"), f = JSON.parse(b.readFileSync(o, "utf-8"))[x];
372
- f && (t = f.file || t, f.css?.[0] && (n = f.css[0]));
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]));
373
373
  } catch {
374
374
  }
375
375
  const s = {
@@ -377,7 +377,7 @@ function M() {
377
377
  "process.env.NODE_ENV": JSON.stringify(l ? "development" : "production"),
378
378
  "process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (i ? "/client" : "")),
379
379
  __VELO_STATIC__: JSON.stringify(i),
380
- __VELO_BUILD_HASH__: JSON.stringify(Date.now().toString(36)),
380
+ __VELO_BUILD_HASH__: JSON.stringify(process.env.VELO_BUILD_HASH || Date.now().toString(36)),
381
381
  __VELO_CLIENT_JS__: JSON.stringify(t),
382
382
  __VELO_CLIENT_CSS__: JSON.stringify(n)
383
383
  },
@@ -451,9 +451,9 @@ function H() {
451
451
  }
452
452
  export {
453
453
  _ as buildFullPathMap,
454
- N as collectFullPaths,
454
+ A as collectFullPaths,
455
455
  w as injectMetadata,
456
- U as removeLoaders,
456
+ $ as removeLoaders,
457
457
  k as removeMiddlewares,
458
458
  V as transformActionsForClient,
459
459
  R as transformLoaderFunctions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mauroandre/velojs",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "type": "module",
5
5
  "description": "Fullstack web framework built on Hono + Preact with Vite-powered AST transforms",
6
6
  "keywords": [