@mauroandre/velojs 0.0.7 → 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 +43 -24
- package/dist/hooks.js +42 -37
- package/dist/server.js +20 -20
- package/dist/static.d.ts +7 -0
- package/dist/static.js +62 -0
- package/dist/types.d.ts +1 -0
- package/dist/vite.js +92 -90
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,20 +1,35 @@
|
|
|
1
|
-
import { spawnSync as
|
|
2
|
-
import { resolve as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
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(
|
|
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 =
|
|
16
|
-
|
|
17
|
-
},
|
|
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
|
|
26
|
-
dev
|
|
27
|
-
build
|
|
28
|
-
|
|
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 (
|
|
54
|
+
switch (r) {
|
|
38
55
|
case "init": {
|
|
39
56
|
const { runInit: e } = await import("./init.js");
|
|
40
|
-
await e(
|
|
57
|
+
await e(t[1]);
|
|
41
58
|
break;
|
|
42
59
|
}
|
|
43
60
|
case "dev":
|
|
44
|
-
|
|
61
|
+
p();
|
|
45
62
|
break;
|
|
46
|
-
case "build":
|
|
47
|
-
|
|
63
|
+
case "build": {
|
|
64
|
+
const e = t.includes("--static");
|
|
65
|
+
v(e);
|
|
48
66
|
break;
|
|
67
|
+
}
|
|
49
68
|
case "start":
|
|
50
|
-
|
|
69
|
+
m();
|
|
51
70
|
break;
|
|
52
71
|
case "help":
|
|
53
72
|
case "--help":
|
|
54
73
|
case "-h":
|
|
55
|
-
|
|
74
|
+
n();
|
|
56
75
|
break;
|
|
57
76
|
default:
|
|
58
|
-
|
|
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
|
|
3
|
-
import { useLocation as d, useParams as
|
|
4
|
-
function
|
|
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
|
|
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:
|
|
15
|
-
const
|
|
16
|
-
return { data: f(r), loading:
|
|
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
|
|
19
|
-
let
|
|
20
|
-
Array.isArray(e) ? r = e : (
|
|
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" &&
|
|
23
|
-
const
|
|
24
|
-
|
|
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" &&
|
|
26
|
+
if (typeof window < "u" && t) {
|
|
27
27
|
const o = window.__PAGE_DATA__;
|
|
28
|
-
o?.[
|
|
28
|
+
o?.[t] && (n = o[t], delete o[t]);
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
if (typeof window > "u" || !
|
|
32
|
-
const o = window.location.pathname
|
|
33
|
-
i.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
44
|
+
return w(() => {
|
|
40
45
|
n === null && l();
|
|
41
|
-
}, r ?? []), { data:
|
|
46
|
+
}, r ?? []), { data: u, loading: i, refetch: l };
|
|
42
47
|
}
|
|
43
|
-
function
|
|
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 ?? {} :
|
|
53
|
+
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : g();
|
|
49
54
|
}
|
|
50
|
-
function
|
|
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
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
}),
|
|
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
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
S as touch,
|
|
72
|
+
m as useLoader,
|
|
73
|
+
A as useNavigate,
|
|
69
74
|
P as useParams,
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
E as usePathname,
|
|
76
|
+
T as useQuery
|
|
72
77
|
};
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as h } from "preact/jsx-runtime";
|
|
2
|
-
import { Hono as
|
|
3
|
-
import { logger as
|
|
2
|
+
import { Hono as T } from "hono";
|
|
3
|
+
import { logger as A } from "hono/logger";
|
|
4
4
|
import { trimTrailingSlash as D } from "hono/trailing-slash";
|
|
5
5
|
import { render as R } from "preact-render-to-string";
|
|
6
6
|
import { Router as N } from "wouter-preact";
|
|
@@ -9,7 +9,7 @@ const v = new O();
|
|
|
9
9
|
globalThis.__veloServerData = v;
|
|
10
10
|
const g = [];
|
|
11
11
|
let p = null;
|
|
12
|
-
function
|
|
12
|
+
function x(t) {
|
|
13
13
|
if (p) {
|
|
14
14
|
t(p);
|
|
15
15
|
return;
|
|
@@ -22,10 +22,10 @@ function y(t) {
|
|
|
22
22
|
g.length = 0;
|
|
23
23
|
}
|
|
24
24
|
const w = [];
|
|
25
|
-
function
|
|
25
|
+
function B(t) {
|
|
26
26
|
w.push(t);
|
|
27
27
|
}
|
|
28
|
-
const
|
|
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(
|
|
@@ -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
|
-
},
|
|
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
|
-
},
|
|
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,8 +88,8 @@ const b = (t, e, o) => {
|
|
|
88
88
|
continue;
|
|
89
89
|
}
|
|
90
90
|
const u = async (i) => {
|
|
91
|
-
const { components: d, data: f } = await
|
|
92
|
-
return
|
|
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
|
}
|
|
@@ -113,18 +113,18 @@ const b = (t, e, o) => {
|
|
|
113
113
|
_ = await l.req.json();
|
|
114
114
|
} catch {
|
|
115
115
|
}
|
|
116
|
-
const
|
|
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(
|
|
123
|
+
const m = await i(E);
|
|
124
124
|
return l.json(m ?? { ok: !0 });
|
|
125
125
|
} catch (m) {
|
|
126
|
-
const
|
|
127
|
-
return l.json({ error:
|
|
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(
|
|
@@ -139,8 +139,8 @@ const b = (t, e, o) => {
|
|
|
139
139
|
s.children && q(t, s.children, a);
|
|
140
140
|
}
|
|
141
141
|
}, C = async (t) => {
|
|
142
|
-
const e = new
|
|
143
|
-
e.use(D()), process.env.NODE_ENV !== "production" && e.use("*",
|
|
142
|
+
const e = new T();
|
|
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
146
|
if (S(e, t), q(e, t), process.env.NODE_ENV !== "production" && !p) {
|
|
@@ -148,9 +148,9 @@ const b = (t, e, o) => {
|
|
|
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") {
|
|
153
|
+
if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
|
|
154
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
155
|
(process.env.STATIC_BASE_URL || "").startsWith("http") || s.use("/*", a({ root: n })), console.log(`Server running on http://localhost:${o}`);
|
|
156
156
|
const i = r({ fetch: s.fetch, port: o });
|
|
@@ -159,10 +159,10 @@ const b = (t, e, o) => {
|
|
|
159
159
|
return s;
|
|
160
160
|
};
|
|
161
161
|
export {
|
|
162
|
-
|
|
162
|
+
B as addRoutes,
|
|
163
163
|
C as createApp,
|
|
164
164
|
C as default,
|
|
165
|
-
|
|
165
|
+
x as onServer,
|
|
166
166
|
v as serverDataStorage,
|
|
167
|
-
|
|
167
|
+
K as startServer
|
|
168
168
|
};
|
package/dist/static.d.ts
ADDED
|
@@ -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
|
|
3
|
-
import
|
|
4
|
-
import
|
|
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
|
|
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
|
|
10
|
-
function
|
|
11
|
-
const
|
|
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(
|
|
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
|
-
|
|
70
|
+
i.program.body.unshift(c);
|
|
71
71
|
}
|
|
72
|
-
return h(
|
|
72
|
+
return h(i, { retainLines: !0 }).code;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
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(
|
|
81
|
-
const t =
|
|
82
|
-
if (!
|
|
83
|
-
const c =
|
|
84
|
-
e.isStringLiteral(p) && p.value.includes("/") || (
|
|
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
|
|
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(
|
|
95
|
-
const t =
|
|
94
|
+
ExportNamedDeclaration(i) {
|
|
95
|
+
const t = i.node.declaration;
|
|
96
96
|
if (!e.isVariableDeclaration(t)) return;
|
|
97
|
-
const
|
|
98
|
-
if (!
|
|
99
|
-
const s =
|
|
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 =
|
|
101
|
+
const c = s.replace("action_", ""), a = n.init;
|
|
102
102
|
if (!e.isArrowFunctionExpression(a) || !a.async) return;
|
|
103
|
-
const p = a.params, f =
|
|
104
|
-
a.body = e.blockStatement([e.returnStatement(f)]),
|
|
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
|
|
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
|
|
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
|
|
185
|
-
e.isIdentifier(
|
|
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
|
|
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([
|
|
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
|
|
212
|
-
if (!e.isVariableDeclaration(
|
|
213
|
-
const t =
|
|
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(
|
|
225
|
-
if (e.isIdentifier(
|
|
226
|
-
for (const t of
|
|
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
|
-
|
|
228
|
+
i.remove();
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
}), r.size === 0 ? u : (m(o, {
|
|
232
|
-
ImportDeclaration(
|
|
233
|
-
const t =
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
|
259
|
+
const n = t.node.declaration;
|
|
260
260
|
let s = null;
|
|
261
|
-
e.isArrayExpression(
|
|
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
|
|
265
|
-
for (const [t,
|
|
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
|
-
|
|
269
|
+
i.set(c, n);
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
return
|
|
272
|
+
return i;
|
|
273
273
|
}
|
|
274
|
-
function
|
|
274
|
+
function A(u, o, r) {
|
|
275
275
|
for (const l of u) {
|
|
276
276
|
if (!e.isObjectExpression(l)) continue;
|
|
277
|
-
let
|
|
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) && (
|
|
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 (
|
|
284
|
-
const a = !s &&
|
|
285
|
-
r.set(
|
|
283
|
+
if (n) {
|
|
284
|
+
const a = !s && i === "/" ? o || "/" : t;
|
|
285
|
+
r.set(n, {
|
|
286
286
|
fullPath: a,
|
|
287
|
-
path:
|
|
287
|
+
path: i
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
|
-
s &&
|
|
290
|
+
s && A(s.elements, t, r);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
const g = "virtual:velo/server-entry",
|
|
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",
|
|
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 (
|
|
306
|
-
const
|
|
307
|
-
|
|
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
|
-
|
|
309
|
+
i.set(c, a);
|
|
310
310
|
}
|
|
311
311
|
},
|
|
312
|
-
handleHotUpdate({ file: t, server:
|
|
312
|
+
handleHotUpdate({ file: t, server: n }) {
|
|
313
313
|
const s = d.join(r, l);
|
|
314
314
|
if (t === s) {
|
|
315
|
-
const c =
|
|
316
|
-
|
|
315
|
+
const c = j.readFileSync(s, "utf-8"), a = T(c);
|
|
316
|
+
i.clear();
|
|
317
317
|
for (const [p, f] of a)
|
|
318
|
-
|
|
319
|
-
return
|
|
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 ===
|
|
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
|
|
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 ===
|
|
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,
|
|
342
|
+
transform(t, n, s) {
|
|
342
343
|
const c = s?.ssr === !0;
|
|
343
|
-
if (
|
|
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),
|
|
348
|
-
if (!c && f && (a = k(a), p = !0), x || y ||
|
|
349
|
-
const b = d.relative(r,
|
|
350
|
-
a =
|
|
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",
|
|
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 ?
|
|
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 || (
|
|
390
|
+
} : l || (t.build = {
|
|
389
391
|
manifest: !0,
|
|
390
392
|
outDir: "dist/client",
|
|
391
393
|
rollupOptions: {
|
|
392
|
-
input:
|
|
394
|
+
input: E,
|
|
393
395
|
output: {
|
|
394
396
|
entryFileNames: "client.js",
|
|
395
|
-
assetFileNames: (
|
|
397
|
+
assetFileNames: (n) => n.names?.[0]?.endsWith(".css") ? "client.css" : "[name][extname]"
|
|
396
398
|
}
|
|
397
399
|
}
|
|
398
|
-
}),
|
|
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
|
-
|
|
425
|
-
|
|
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
|
-
|
|
442
|
-
|
|
443
|
+
A as collectFullPaths,
|
|
444
|
+
w as injectMetadata,
|
|
443
445
|
U as removeLoaders,
|
|
444
446
|
k as removeMiddlewares,
|
|
445
|
-
|
|
446
|
-
|
|
447
|
+
V as transformActionsForClient,
|
|
448
|
+
R as transformLoaderFunctions,
|
|
447
449
|
Z as veloPlugin
|
|
448
450
|
};
|