@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.
- package/dist/components.js +15 -15
- package/dist/server.js +41 -41
- package/dist/vite.js +146 -143
- package/package.json +1 -1
package/dist/components.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as o, jsxs as p, Fragment as $ } from "preact/jsx-runtime";
|
|
2
|
-
import { useRouter as
|
|
3
|
-
import { __veloUpdatePending as
|
|
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}/${
|
|
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 =
|
|
29
|
-
if (typeof window < "u" &&
|
|
30
|
-
let
|
|
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
|
-
|
|
32
|
+
const s = e.metadata?.fullPath ?? f;
|
|
33
|
+
_ = `${t ? h(s, t) : s}${a}`;
|
|
34
34
|
} else {
|
|
35
35
|
const s = l.replace(/^~/, "");
|
|
36
|
-
|
|
36
|
+
_ = `${!l.startsWith("~") && u.base ? u.base : ""}${s}${a}`;
|
|
37
37
|
}
|
|
38
|
-
const { onClick: d, ...
|
|
38
|
+
const { onClick: d, ...m } = r;
|
|
39
39
|
return /* @__PURE__ */ o(
|
|
40
40
|
"a",
|
|
41
41
|
{
|
|
42
|
-
href:
|
|
42
|
+
href: _,
|
|
43
43
|
onClick: (s) => {
|
|
44
|
-
d && d(s), s.defaultPrevented || (s.preventDefault(), window.location.href =
|
|
44
|
+
d && d(s), s.defaultPrevented || (s.preventDefault(), window.location.href = _);
|
|
45
45
|
},
|
|
46
|
-
...
|
|
46
|
+
...m
|
|
47
47
|
}
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
|
-
return /* @__PURE__ */ o(
|
|
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
|
|
2
|
-
import { Hono as
|
|
3
|
-
import { logger as
|
|
4
|
-
import { trimTrailingSlash as
|
|
5
|
-
import { render as
|
|
6
|
-
import { Router as
|
|
7
|
-
import { AsyncLocalStorage as
|
|
8
|
-
const v = new
|
|
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
|
|
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
|
|
25
|
-
function
|
|
26
|
-
|
|
24
|
+
const w = [];
|
|
25
|
+
function U(t) {
|
|
26
|
+
w.push(t);
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const N = (t, e, o) => {
|
|
29
29
|
if (t.req.query("_data") === "1") {
|
|
30
|
-
const 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
|
-
() =>
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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__ */
|
|
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__ */
|
|
71
|
-
},
|
|
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
|
-
|
|
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
|
|
94
|
-
return
|
|
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
|
-
},
|
|
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
|
|
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
|
|
126
|
-
return l.json(
|
|
127
|
-
} catch (
|
|
128
|
-
const
|
|
129
|
-
return l.json({ error:
|
|
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 &&
|
|
141
|
+
s.children && q(t, s.children, a);
|
|
142
142
|
}
|
|
143
|
-
},
|
|
144
|
-
const e = new
|
|
145
|
-
e.use(
|
|
146
|
-
for (const o of
|
|
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 (
|
|
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
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
|
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
|
|
7
|
-
import
|
|
6
|
+
import E from "@babel/traverse";
|
|
7
|
+
import b from "@babel/generator";
|
|
8
8
|
import * as e from "@babel/types";
|
|
9
|
-
const m = typeof
|
|
10
|
-
function w(u,
|
|
11
|
-
const
|
|
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(
|
|
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),
|
|
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(
|
|
27
|
+
e.stringLiteral(l)
|
|
28
28
|
)
|
|
29
29
|
];
|
|
30
|
-
r !== void 0 &&
|
|
30
|
+
r !== void 0 && _.push(
|
|
31
31
|
e.objectProperty(
|
|
32
32
|
e.identifier("fullPath"),
|
|
33
33
|
e.stringLiteral(r)
|
|
34
34
|
)
|
|
35
|
-
),
|
|
35
|
+
), c !== void 0 && _.push(
|
|
36
36
|
e.objectProperty(
|
|
37
37
|
e.identifier("path"),
|
|
38
|
-
e.stringLiteral(
|
|
38
|
+
e.stringLiteral(c)
|
|
39
39
|
)
|
|
40
|
-
), a.init.properties = [...
|
|
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(
|
|
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
|
-
),
|
|
56
|
+
), c !== void 0 && s.push(
|
|
57
57
|
e.objectProperty(
|
|
58
58
|
e.identifier("path"),
|
|
59
|
-
e.stringLiteral(
|
|
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
|
-
|
|
70
|
+
n.program.body.unshift(o);
|
|
71
71
|
}
|
|
72
|
-
return S(
|
|
72
|
+
return S(n, { retainLines: !0 }).code;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
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(
|
|
81
|
-
const t =
|
|
82
|
-
if (!
|
|
83
|
-
const o =
|
|
84
|
-
e.isStringLiteral(p) && p.value.includes("/") || (
|
|
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
|
|
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(
|
|
95
|
-
const t =
|
|
94
|
+
ExportNamedDeclaration(n) {
|
|
95
|
+
const t = n.node.declaration;
|
|
96
96
|
if (!e.isVariableDeclaration(t)) return;
|
|
97
|
-
const
|
|
98
|
-
if (!
|
|
99
|
-
const s =
|
|
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 =
|
|
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(
|
|
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,
|
|
109
|
-
const
|
|
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(
|
|
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(
|
|
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,
|
|
179
|
-
if (
|
|
180
|
-
const r =
|
|
178
|
+
function W(u, l) {
|
|
179
|
+
if (l.length === 0) return;
|
|
180
|
+
const r = l[0];
|
|
181
181
|
if (e.isObjectPattern(r)) {
|
|
182
|
-
let
|
|
182
|
+
let c = null;
|
|
183
183
|
if (e.isTSTypeAnnotation(r.typeAnnotation) && e.isTSTypeReference(r.typeAnnotation.typeAnnotation)) {
|
|
184
|
-
const
|
|
185
|
-
e.isIdentifier(
|
|
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
|
|
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([
|
|
194
|
-
|
|
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(
|
|
198
|
+
e.tsTypeAnnotation(c)
|
|
199
199
|
)
|
|
200
200
|
])
|
|
201
201
|
)), u.params = [t];
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
function $(u) {
|
|
205
|
-
const
|
|
205
|
+
const l = v(u, {
|
|
206
206
|
sourceType: "module",
|
|
207
207
|
plugins: ["typescript", "jsx"]
|
|
208
208
|
});
|
|
209
|
-
return m(
|
|
210
|
-
ExportNamedDeclaration(
|
|
211
|
-
const
|
|
212
|
-
if (!e.isVariableDeclaration(
|
|
213
|
-
const t =
|
|
214
|
-
!t || !e.isIdentifier(t.id) || t.id.name === "loader" &&
|
|
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(
|
|
216
|
+
}), S(l, { retainLines: !0 }).code;
|
|
217
217
|
}
|
|
218
|
-
function
|
|
219
|
-
const
|
|
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(
|
|
224
|
-
ObjectProperty(
|
|
225
|
-
if (e.isIdentifier(
|
|
226
|
-
for (const t of
|
|
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
|
-
|
|
228
|
+
n.remove();
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
-
}), r.size === 0 ? u : (m(
|
|
232
|
-
ImportDeclaration(
|
|
233
|
-
const t =
|
|
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
|
-
|
|
240
|
+
i.length === 0 ? n.remove() : i.length !== t.length && (n.node.specifiers = i);
|
|
241
241
|
}
|
|
242
|
-
}), S(
|
|
242
|
+
}), S(l, { retainLines: !0 }).code);
|
|
243
243
|
}
|
|
244
|
-
function
|
|
245
|
-
const
|
|
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(
|
|
249
|
+
m(l, {
|
|
250
250
|
ImportDeclaration(t) {
|
|
251
|
-
const
|
|
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,
|
|
253
|
+
e.isImportNamespaceSpecifier(s) && r.set(s.local.name, i);
|
|
254
254
|
}
|
|
255
255
|
});
|
|
256
|
-
const
|
|
257
|
-
m(
|
|
256
|
+
const c = /* @__PURE__ */ new Map();
|
|
257
|
+
m(l, {
|
|
258
258
|
ExportDefaultDeclaration(t) {
|
|
259
|
-
const
|
|
259
|
+
const i = t.node.declaration;
|
|
260
260
|
let s = null;
|
|
261
|
-
e.isArrayExpression(
|
|
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
|
|
265
|
-
for (const [t,
|
|
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
|
-
|
|
269
|
+
n.set(o, i);
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
return
|
|
272
|
+
return n;
|
|
273
273
|
}
|
|
274
|
-
function
|
|
275
|
-
for (const
|
|
276
|
-
if (!e.isObjectExpression(
|
|
277
|
-
let
|
|
278
|
-
for (const o of
|
|
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) && (
|
|
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 (
|
|
284
|
-
const a = !s &&
|
|
285
|
-
r.set(
|
|
283
|
+
if (i) {
|
|
284
|
+
const a = !s && n === "/" ? l || "/" : t;
|
|
285
|
+
r.set(i, {
|
|
286
286
|
fullPath: a,
|
|
287
|
-
path:
|
|
287
|
+
path: n
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
|
-
s &&
|
|
290
|
+
s && P(s.elements, t, r);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
const
|
|
294
|
-
function
|
|
295
|
-
let r = d.resolve(process.cwd(),
|
|
296
|
-
const
|
|
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,
|
|
301
|
+
r = d.resolve(t.root, l);
|
|
302
302
|
},
|
|
303
303
|
buildStart() {
|
|
304
|
-
const t = d.join(r,
|
|
304
|
+
const t = d.join(r, c);
|
|
305
305
|
if (L.existsSync(t)) {
|
|
306
|
-
const
|
|
307
|
-
|
|
306
|
+
const i = L.readFileSync(t, "utf-8"), s = j(i);
|
|
307
|
+
n.clear();
|
|
308
308
|
for (const [o, a] of s)
|
|
309
|
-
|
|
309
|
+
n.set(o, a);
|
|
310
310
|
}
|
|
311
311
|
},
|
|
312
|
-
handleHotUpdate({ file: t, server:
|
|
313
|
-
const s = d.join(r,
|
|
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 =
|
|
316
|
-
|
|
315
|
+
const o = L.readFileSync(s, "utf-8"), a = j(o);
|
|
316
|
+
n.clear();
|
|
317
317
|
for (const [p, f] of a)
|
|
318
|
-
|
|
319
|
-
return
|
|
318
|
+
n.set(p, f);
|
|
319
|
+
return i.ws.send({ type: "full-reload" }), [];
|
|
320
320
|
}
|
|
321
321
|
},
|
|
322
322
|
resolveId(t) {
|
|
323
|
-
return t ===
|
|
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
|
|
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 ===
|
|
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,
|
|
345
|
+
transform(t, i, s) {
|
|
343
346
|
const o = s?.ssr === !0;
|
|
344
|
-
if (
|
|
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),
|
|
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),
|
|
349
|
-
if (!o && f && (a =
|
|
350
|
-
const
|
|
351
|
-
a = w(a,
|
|
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
|
-
|
|
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
|
|
366
|
+
function B() {
|
|
364
367
|
return {
|
|
365
368
|
name: "velo:config",
|
|
366
|
-
config(u, { mode:
|
|
367
|
-
const r =
|
|
368
|
-
let t = "client.js",
|
|
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"))[
|
|
372
|
-
p && (t = p.file || t, 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(
|
|
378
|
-
"process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (
|
|
379
|
-
__VELO_STATIC__: JSON.stringify(
|
|
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(
|
|
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:
|
|
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
|
-
} :
|
|
404
|
+
} : c || (s.build = {
|
|
402
405
|
manifest: !0,
|
|
403
406
|
outDir: "dist/client",
|
|
404
407
|
rollupOptions: {
|
|
405
|
-
input:
|
|
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
|
|
418
|
+
function M() {
|
|
416
419
|
return {
|
|
417
420
|
name: "velo:static-url",
|
|
418
421
|
apply: "build",
|
|
419
422
|
enforce: "post",
|
|
420
|
-
generateBundle(u,
|
|
423
|
+
generateBundle(u, l) {
|
|
421
424
|
const r = process.env.STATIC_BASE_URL || "";
|
|
422
425
|
if (r)
|
|
423
|
-
for (const
|
|
424
|
-
|
|
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
|
|
435
|
+
const l = u ?? {}, r = l.appDirectory ?? "./app";
|
|
433
436
|
return [
|
|
434
|
-
M(),
|
|
435
|
-
J(c, r),
|
|
436
437
|
B(),
|
|
437
|
-
|
|
438
|
+
k(l, r),
|
|
439
|
+
M(),
|
|
440
|
+
D(),
|
|
438
441
|
F({
|
|
439
|
-
entry:
|
|
442
|
+
entry: h
|
|
440
443
|
}),
|
|
441
444
|
H()
|
|
442
445
|
];
|
|
@@ -450,12 +453,12 @@ function H() {
|
|
|
450
453
|
};
|
|
451
454
|
}
|
|
452
455
|
export {
|
|
453
|
-
|
|
454
|
-
|
|
456
|
+
j as buildFullPathMap,
|
|
457
|
+
P as collectFullPaths,
|
|
455
458
|
w as injectMetadata,
|
|
456
459
|
$ as removeLoaders,
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
+
J as removeMiddlewares,
|
|
461
|
+
R as transformActionsForClient,
|
|
462
|
+
V as transformLoaderFunctions,
|
|
460
463
|
Z as veloPlugin
|
|
461
464
|
};
|