@mauroandre/velojs 0.0.13 → 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/README.md +92 -5
- package/dist/cli.js +18 -14
- package/dist/components.js +40 -23
- package/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +27 -25
- package/dist/server.js +79 -77
- package/dist/vite.js +106 -96
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,7 @@ export default defineConfig({
|
|
|
52
52
|
"scripts": {
|
|
53
53
|
"dev": "velojs dev",
|
|
54
54
|
"build": "velojs build",
|
|
55
|
+
"build:static": "velojs build --static",
|
|
55
56
|
"start": "velojs start"
|
|
56
57
|
}
|
|
57
58
|
}
|
|
@@ -619,10 +620,12 @@ export const Component = ({ children }) => (
|
|
|
619
620
|
**Production:**
|
|
620
621
|
```html
|
|
621
622
|
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
|
|
622
|
-
<link rel="stylesheet" href="/client.css" />
|
|
623
|
-
<script type="module" src="/client.js"></script>
|
|
623
|
+
<link rel="stylesheet" href="/client.a1b2c3.css" />
|
|
624
|
+
<script type="module" src="/client.x9y8z7.js"></script>
|
|
624
625
|
```
|
|
625
626
|
|
|
627
|
+
Asset filenames include a content hash for cache busting. The hash changes only when the file content changes.
|
|
628
|
+
|
|
626
629
|
---
|
|
627
630
|
|
|
628
631
|
## Middlewares
|
|
@@ -984,6 +987,87 @@ interface VeloConfig {
|
|
|
984
987
|
|
|
985
988
|
---
|
|
986
989
|
|
|
990
|
+
## Static Site Generation (SSG)
|
|
991
|
+
|
|
992
|
+
Build a fully static site with pre-rendered HTML and JSON files:
|
|
993
|
+
|
|
994
|
+
```bash
|
|
995
|
+
velojs build --static
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
### Output
|
|
999
|
+
|
|
1000
|
+
```
|
|
1001
|
+
dist/
|
|
1002
|
+
index.html # Pre-rendered HTML
|
|
1003
|
+
index.json # Loader data
|
|
1004
|
+
about/
|
|
1005
|
+
index.html
|
|
1006
|
+
index.json
|
|
1007
|
+
client/
|
|
1008
|
+
client.a1b2c3.js
|
|
1009
|
+
client.x9y8z7.css
|
|
1010
|
+
logos/ # Files from public/ are copied to dist/
|
|
1011
|
+
logo.svg
|
|
1012
|
+
```
|
|
1013
|
+
|
|
1014
|
+
### Public assets
|
|
1015
|
+
|
|
1016
|
+
Files in the `public/` folder are automatically copied to `dist/` root during static generation. Reference them with absolute paths:
|
|
1017
|
+
|
|
1018
|
+
```tsx
|
|
1019
|
+
<img src="/logos/logo.svg" />
|
|
1020
|
+
```
|
|
1021
|
+
|
|
1022
|
+
This works in both dev mode (Vite serves `public/` at root) and static builds (`public/` is copied to `dist/`).
|
|
1023
|
+
|
|
1024
|
+
### Dynamic routes
|
|
1025
|
+
|
|
1026
|
+
For routes with `:params`, export a `staticPaths` function that returns all possible parameter combinations:
|
|
1027
|
+
|
|
1028
|
+
```typescript
|
|
1029
|
+
// app/pages/UserDetail.tsx
|
|
1030
|
+
export const staticPaths = async () => {
|
|
1031
|
+
const { getUsers } = await import("./user.service.js");
|
|
1032
|
+
const users = await getUsers();
|
|
1033
|
+
return users.map((u) => ({ id: u.id }));
|
|
1034
|
+
};
|
|
1035
|
+
```
|
|
1036
|
+
|
|
1037
|
+
Routes without `staticPaths` are skipped with a warning.
|
|
1038
|
+
|
|
1039
|
+
### Deploying
|
|
1040
|
+
|
|
1041
|
+
The `dist/` folder is self-contained. Deploy to any static hosting (Nginx, Cloudflare Pages, S3, etc.). No server required.
|
|
1042
|
+
|
|
1043
|
+
---
|
|
1044
|
+
|
|
1045
|
+
## Cache Busting & Auto-Update Detection
|
|
1046
|
+
|
|
1047
|
+
VeloJS has built-in cache management for zero-downtime deployments:
|
|
1048
|
+
|
|
1049
|
+
### Content-hashed assets
|
|
1050
|
+
|
|
1051
|
+
JS and CSS files are generated with content hashes (`client.a1b2c3.js`). When the content changes, the hash changes, and browsers automatically fetch the new version. Unchanged assets stay cached indefinitely.
|
|
1052
|
+
|
|
1053
|
+
### HTML no-cache
|
|
1054
|
+
|
|
1055
|
+
HTML responses include `Cache-Control: no-cache`, so browsers always check for the latest version. Since HTML is small (a few KB), this has negligible performance impact.
|
|
1056
|
+
|
|
1057
|
+
### SPA deploy detection
|
|
1058
|
+
|
|
1059
|
+
When a user is navigating a SPA and a new deploy happens, VeloJS detects it automatically:
|
|
1060
|
+
|
|
1061
|
+
1. Each build generates a unique `__VELO_BUILD_HASH__`, embedded in the client JS
|
|
1062
|
+
2. JSON data responses (both SSR and SSG) include a `__buildHash` field
|
|
1063
|
+
3. On SPA navigation, `useLoader` compares the response hash with the client hash
|
|
1064
|
+
4. If they differ, an internal `__veloUpdatePending` flag is set
|
|
1065
|
+
5. On the next `<Link>` click, VeloJS does a full page navigation instead of SPA — loading the new HTML with updated asset references
|
|
1066
|
+
|
|
1067
|
+
This means users get the new version without needing `Ctrl+Shift+R`. The transition is seamless — from the user's perspective, it looks like a normal page navigation.
|
|
1068
|
+
|
|
1069
|
+
---
|
|
1070
|
+
|
|
987
1071
|
## Docker / Production Deploy
|
|
988
1072
|
|
|
989
1073
|
### Dockerfile
|
|
@@ -1014,12 +1098,15 @@ CMD ["npx", "velojs", "start"]
|
|
|
1014
1098
|
velojs build
|
|
1015
1099
|
# dist/
|
|
1016
1100
|
# client/ # Static assets (JS, CSS, images)
|
|
1017
|
-
# client.js
|
|
1018
|
-
# client.css
|
|
1101
|
+
# client.a1b2c3.js
|
|
1102
|
+
# client.x9y8z7.css
|
|
1103
|
+
# .vite/manifest.json
|
|
1019
1104
|
# server.js # SSR server entry (single file)
|
|
1020
1105
|
```
|
|
1021
1106
|
|
|
1022
|
-
|
|
1107
|
+
Asset filenames include content hashes for long-term browser caching. The server build reads the Vite manifest to inject the correct filenames into `<Scripts>`.
|
|
1108
|
+
|
|
1109
|
+
In production, `velojs start` sets `NODE_ENV=production` automatically and serves static files from `dist/client/`. HTML responses are served with `Cache-Control: no-cache` so browsers always fetch the latest HTML (which references the current hashed assets).
|
|
1023
1110
|
|
|
1024
1111
|
### Static assets on CDN
|
|
1025
1112
|
|
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
|
|
4
|
-
const
|
|
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(
|
|
8
|
+
process.exit(s.status ?? 0);
|
|
9
9
|
}, p = () => {
|
|
10
|
-
l("npx", ["vite", ...
|
|
11
|
-
},
|
|
12
|
-
const
|
|
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 &&
|
|
22
|
-
},
|
|
25
|
+
}), console.log("Build complete!"), e && v();
|
|
26
|
+
}, v = async () => {
|
|
23
27
|
process.env.NODE_ENV = "production", process.env.VELO_STATIC = "1";
|
|
24
|
-
const
|
|
25
|
-
(!
|
|
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(
|
|
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(
|
|
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 =
|
|
65
|
-
|
|
68
|
+
const e = o.includes("--static");
|
|
69
|
+
u(e);
|
|
66
70
|
break;
|
|
67
71
|
}
|
|
68
72
|
case "start":
|
package/dist/components.js
CHANGED
|
@@ -1,31 +1,48 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { Link as
|
|
3
|
-
|
|
4
|
-
|
|
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";
|
|
5
6
|
e = e || process.env.STATIC_BASE_URL || (process.env.VELO_STATIC ? "/client" : "");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
i,
|
|
11
|
+
/* @__PURE__ */ o("script", { type: "module", src: "/@vite/client" }),
|
|
12
|
+
/* @__PURE__ */ o("script", { type: "module", src: "/__velo_client.js" })
|
|
13
|
+
] });
|
|
14
|
+
const r = typeof __VELO_CLIENT_JS__ < "u" ? __VELO_CLIENT_JS__ : "client.js";
|
|
15
|
+
return /* @__PURE__ */ p(L, { children: [
|
|
16
|
+
i,
|
|
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}` })
|
|
15
19
|
] });
|
|
16
20
|
}
|
|
17
|
-
function $(e,
|
|
18
|
-
let
|
|
19
|
-
for (const [
|
|
20
|
-
|
|
21
|
-
return
|
|
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;
|
|
22
26
|
}
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
|
|
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
|
+
"a",
|
|
33
|
+
{
|
|
34
|
+
href: a,
|
|
35
|
+
onClick: (l) => {
|
|
36
|
+
d && d(l), l.defaultPrevented || (l.preventDefault(), window.location.href = a);
|
|
37
|
+
},
|
|
38
|
+
...h
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ o(v, { to: S, ...r });
|
|
26
43
|
}
|
|
27
44
|
export {
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
g as Link,
|
|
46
|
+
k as Scripts,
|
|
30
47
|
$ as substituteParams
|
|
31
48
|
};
|
package/dist/hooks.d.ts
CHANGED
package/dist/hooks.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { signal as
|
|
1
|
+
import { signal as c, useSignal as v } from "@preact/signals";
|
|
2
2
|
import { useRef as D, useEffect as p } from "preact/hooks";
|
|
3
3
|
import { useLocation as w, useParams as S } from "wouter-preact";
|
|
4
|
+
const y = c(!1);
|
|
4
5
|
function P(e) {
|
|
5
6
|
e.value !== null && typeof e.value == "object" && (e.value = { ...e.value });
|
|
6
7
|
}
|
|
7
8
|
function T(e) {
|
|
8
|
-
const a =
|
|
9
|
+
const a = c(!1);
|
|
9
10
|
if (typeof window > "u")
|
|
10
11
|
return { data: {
|
|
11
12
|
get value() {
|
|
@@ -13,50 +14,50 @@ function T(e) {
|
|
|
13
14
|
}
|
|
14
15
|
}, loading: a };
|
|
15
16
|
const t = window.__PAGE_DATA__, n = e && t?.[e] ? t[e] : null;
|
|
16
|
-
return { data:
|
|
17
|
+
return { data: c(n), loading: a };
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
+
function E(e, a) {
|
|
19
20
|
let t, n;
|
|
20
21
|
Array.isArray(e) ? n = e : (t = e, n = a);
|
|
21
22
|
let r = null;
|
|
22
23
|
if (typeof window > "u" && t) {
|
|
23
|
-
const
|
|
24
|
-
|
|
24
|
+
const u = globalThis.__veloServerData?.getStore?.();
|
|
25
|
+
u?.[t] && (r = u[t]);
|
|
25
26
|
}
|
|
26
27
|
if (typeof window < "u" && t) {
|
|
27
28
|
const o = window.__PAGE_DATA__;
|
|
28
29
|
o?.[t] && (r = o[t], delete o[t]);
|
|
29
30
|
}
|
|
30
|
-
const
|
|
31
|
+
const _ = v(r), i = v(!1), f = () => {
|
|
31
32
|
if (typeof window > "u" || !t) return;
|
|
32
33
|
const o = window.location.pathname;
|
|
33
34
|
i.value = !0;
|
|
34
|
-
const
|
|
35
|
+
const d = typeof __VELO_STATIC__ < "u" && __VELO_STATIC__ ? `${o === "/" ? "" : o}/index.json` : (() => {
|
|
35
36
|
const s = new URLSearchParams(window.location.search);
|
|
36
37
|
return s.set("_data", "1"), `${o}?${s.toString()}`;
|
|
37
|
-
})(), g =
|
|
38
|
-
fetch(`${
|
|
39
|
-
u.value = s[t], i.value = !1;
|
|
38
|
+
})(), g = d.includes("?") ? "&" : "?", h = typeof __VELO_BUILD_HASH__ < "u" ? `${g}v=${__VELO_BUILD_HASH__}` : "";
|
|
39
|
+
fetch(`${d}${h}`).then((s) => s.json()).then((s) => {
|
|
40
|
+
typeof __VELO_BUILD_HASH__ < "u" && s.__buildHash && s.__buildHash !== __VELO_BUILD_HASH__ && (y.value = !0), _.value = s[t], i.value = !1;
|
|
40
41
|
}).catch(() => {
|
|
41
42
|
i.value = !1;
|
|
42
43
|
});
|
|
43
|
-
},
|
|
44
|
+
}, l = D(r !== null);
|
|
44
45
|
return p(() => {
|
|
45
|
-
if (
|
|
46
|
-
|
|
46
|
+
if (l.current) {
|
|
47
|
+
l.current = !1;
|
|
47
48
|
return;
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
}, n ?? []), { data:
|
|
50
|
+
f();
|
|
51
|
+
}, n ?? []), { data: _, loading: i, refetch: f };
|
|
51
52
|
}
|
|
52
|
-
function
|
|
53
|
+
function H() {
|
|
53
54
|
const [, e] = w();
|
|
54
55
|
return e;
|
|
55
56
|
}
|
|
56
|
-
function
|
|
57
|
+
function b() {
|
|
57
58
|
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : S();
|
|
58
59
|
}
|
|
59
|
-
function
|
|
60
|
+
function U() {
|
|
60
61
|
if (typeof window > "u")
|
|
61
62
|
return globalThis.__veloServerData?.getStore?.()?.__query ?? {};
|
|
62
63
|
const e = window.__PAGE_DATA__;
|
|
@@ -67,15 +68,16 @@ function b() {
|
|
|
67
68
|
t[r] = n;
|
|
68
69
|
}), t;
|
|
69
70
|
}
|
|
70
|
-
function
|
|
71
|
+
function $() {
|
|
71
72
|
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (w(), window.location.pathname);
|
|
72
73
|
}
|
|
73
74
|
export {
|
|
74
75
|
T as Loader,
|
|
76
|
+
y as __veloUpdatePending,
|
|
75
77
|
P as touch,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
E as useLoader,
|
|
79
|
+
H as useNavigate,
|
|
80
|
+
b as useParams,
|
|
81
|
+
$ as usePathname,
|
|
82
|
+
U as useQuery
|
|
81
83
|
};
|
package/dist/server.js
CHANGED
|
@@ -1,48 +1,50 @@
|
|
|
1
1
|
import { jsx as h } from "preact/jsx-runtime";
|
|
2
|
-
import { Hono as
|
|
3
|
-
import { logger as
|
|
2
|
+
import { Hono as P } from "hono";
|
|
3
|
+
import { logger as T } from "hono/logger";
|
|
4
4
|
import { trimTrailingSlash as D } from "hono/trailing-slash";
|
|
5
|
-
import { render as
|
|
6
|
-
import { Router as
|
|
7
|
-
import { AsyncLocalStorage as
|
|
8
|
-
const v = new
|
|
5
|
+
import { render as O } from "preact-render-to-string";
|
|
6
|
+
import { Router as b } from "wouter-preact";
|
|
7
|
+
import { AsyncLocalStorage as I } from "node:async_hooks";
|
|
8
|
+
const v = new I();
|
|
9
9
|
globalThis.__veloServerData = v;
|
|
10
|
-
const
|
|
10
|
+
const _ = [];
|
|
11
11
|
let p = null;
|
|
12
|
-
function
|
|
12
|
+
function M(t) {
|
|
13
13
|
if (p) {
|
|
14
14
|
t(p);
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
_.push(t);
|
|
18
18
|
}
|
|
19
19
|
function y(t) {
|
|
20
20
|
p = t;
|
|
21
|
-
for (const e of
|
|
22
|
-
|
|
21
|
+
for (const e of _) e(t);
|
|
22
|
+
_.length = 0;
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
function
|
|
26
|
-
|
|
24
|
+
const S = [];
|
|
25
|
+
function G(t) {
|
|
26
|
+
S.push(t);
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
if (t.req.query("_data") === "1")
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const R = (t, e, o) => {
|
|
29
|
+
if (t.req.query("_data") === "1") {
|
|
30
|
+
const c = typeof __VELO_BUILD_HASH__ < "u" ? __VELO_BUILD_HASH__ : void 0, r = o ? { ...o, __buildHash: c } : { __buildHash: c };
|
|
31
|
+
return t.json(r);
|
|
32
|
+
}
|
|
33
|
+
const s = t.req.path, n = v.run(
|
|
32
34
|
o ?? {},
|
|
33
|
-
() =>
|
|
35
|
+
() => O(/* @__PURE__ */ h(b, { ssrPath: s, children: e }))
|
|
34
36
|
);
|
|
35
|
-
if (!o)
|
|
36
|
-
return t.html(
|
|
37
|
+
if (t.header("Cache-Control", "no-cache"), !o)
|
|
38
|
+
return t.html(n);
|
|
37
39
|
const a = `<script>window.__PAGE_DATA__=${JSON.stringify(
|
|
38
40
|
o
|
|
39
41
|
)}<\/script>`;
|
|
40
|
-
return t.html(
|
|
41
|
-
},
|
|
42
|
-
const o = e.req.param(), s = e.req.query(),
|
|
43
|
-
t.map(async (
|
|
44
|
-
if (!
|
|
45
|
-
const u = await
|
|
42
|
+
return t.html(n.replace("</head>", `${a}</head>`));
|
|
43
|
+
}, C = async (t, e) => {
|
|
44
|
+
const o = e.req.param(), s = e.req.query(), n = { params: o, query: s, c: e }, a = await Promise.all(
|
|
45
|
+
t.map(async (r) => {
|
|
46
|
+
if (!r.loader) return null;
|
|
47
|
+
const u = await r.loader(n), i = r.metadata?.moduleId;
|
|
46
48
|
return i ? { moduleId: i, loaderData: u } : null;
|
|
47
49
|
})
|
|
48
50
|
), c = {
|
|
@@ -50,81 +52,81 @@ const I = (t, e, o) => {
|
|
|
50
52
|
__query: s,
|
|
51
53
|
__pathname: e.req.path
|
|
52
54
|
};
|
|
53
|
-
for (const
|
|
54
|
-
|
|
55
|
+
for (const r of a)
|
|
56
|
+
r && (c[r.moduleId] = r.loaderData);
|
|
55
57
|
return {
|
|
56
|
-
components: t.map((
|
|
58
|
+
components: t.map((r) => r.Component),
|
|
57
59
|
data: c
|
|
58
60
|
};
|
|
59
|
-
},
|
|
61
|
+
}, N = (t) => {
|
|
60
62
|
if (t.length === 0) return null;
|
|
61
63
|
const e = t.filter(Boolean);
|
|
62
64
|
if (e.length === 0) return null;
|
|
63
65
|
if (e.length === 1) {
|
|
64
|
-
const
|
|
65
|
-
return /* @__PURE__ */ h(
|
|
66
|
+
const n = e[0];
|
|
67
|
+
return /* @__PURE__ */ h(n, {});
|
|
66
68
|
}
|
|
67
69
|
const o = e[e.length - 1];
|
|
68
|
-
return e.slice(0, -1).reduceRight((
|
|
69
|
-
},
|
|
70
|
-
for (const
|
|
71
|
-
const a = [...o,
|
|
70
|
+
return e.slice(0, -1).reduceRight((n, a) => /* @__PURE__ */ h(a, { children: n }), /* @__PURE__ */ h(o, {}));
|
|
71
|
+
}, w = (t, e, o = [], s = []) => {
|
|
72
|
+
for (const n of e) {
|
|
73
|
+
const a = [...o, n.module], c = [
|
|
72
74
|
...s,
|
|
73
|
-
...
|
|
75
|
+
...n.middlewares || []
|
|
74
76
|
];
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
+
if (n.children)
|
|
78
|
+
w(
|
|
77
79
|
t,
|
|
78
|
-
|
|
80
|
+
n.children,
|
|
79
81
|
a,
|
|
80
82
|
c
|
|
81
83
|
);
|
|
82
84
|
else {
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
85
|
+
const r = n.module.metadata?.fullPath;
|
|
86
|
+
if (!r) {
|
|
85
87
|
console.warn(
|
|
86
|
-
`Module ${
|
|
88
|
+
`Module ${n.module.metadata?.moduleId} has no fullPath`
|
|
87
89
|
);
|
|
88
90
|
continue;
|
|
89
91
|
}
|
|
90
92
|
const u = async (i) => {
|
|
91
|
-
const { components: d, data: f } = await
|
|
92
|
-
return
|
|
93
|
+
const { components: d, data: f } = await C(a, i), l = N(d);
|
|
94
|
+
return R(i, l, f);
|
|
93
95
|
};
|
|
94
|
-
c.length > 0 ? t.on(["GET"], [
|
|
96
|
+
c.length > 0 ? t.on(["GET"], [r], ...c, u) : t.on(["GET"], [r], u);
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
|
-
},
|
|
99
|
+
}, E = (t, e, o = []) => {
|
|
98
100
|
for (const s of e) {
|
|
99
|
-
const
|
|
101
|
+
const n = s.module.metadata?.moduleId, a = [
|
|
100
102
|
...o,
|
|
101
103
|
...s.middlewares || []
|
|
102
104
|
];
|
|
103
|
-
if (
|
|
105
|
+
if (n) {
|
|
104
106
|
const c = Object.keys(s.module).filter(
|
|
105
|
-
(
|
|
107
|
+
(r) => r.startsWith("action_")
|
|
106
108
|
);
|
|
107
|
-
for (const
|
|
108
|
-
const u =
|
|
109
|
+
for (const r of c) {
|
|
110
|
+
const u = r.replace("action_", ""), i = s.module[r];
|
|
109
111
|
if (typeof i == "function") {
|
|
110
|
-
const d = `/_action/${
|
|
111
|
-
let
|
|
112
|
+
const d = `/_action/${n}/${u}`, f = async (l) => {
|
|
113
|
+
let g = {};
|
|
112
114
|
try {
|
|
113
|
-
|
|
115
|
+
g = await l.req.json();
|
|
114
116
|
} catch {
|
|
115
117
|
}
|
|
116
|
-
const
|
|
117
|
-
body:
|
|
118
|
+
const q = {
|
|
119
|
+
body: g,
|
|
118
120
|
params: l.req.param(),
|
|
119
121
|
query: l.req.query(),
|
|
120
122
|
c: l
|
|
121
123
|
};
|
|
122
124
|
try {
|
|
123
|
-
const m = await i(
|
|
125
|
+
const m = await i(q);
|
|
124
126
|
return l.json(m ?? { ok: !0 });
|
|
125
127
|
} catch (m) {
|
|
126
|
-
const
|
|
127
|
-
return l.json({ error:
|
|
128
|
+
const A = m instanceof Error ? m.message : "Action failed";
|
|
129
|
+
return l.json({ error: A }, 500);
|
|
128
130
|
}
|
|
129
131
|
};
|
|
130
132
|
a.length > 0 ? t.on(
|
|
@@ -136,33 +138,33 @@ const I = (t, e, o) => {
|
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
|
-
s.children &&
|
|
141
|
+
s.children && E(t, s.children, a);
|
|
140
142
|
}
|
|
141
|
-
},
|
|
142
|
-
const e = new
|
|
143
|
-
e.use(D()), process.env.NODE_ENV !== "production" && e.use("*",
|
|
144
|
-
for (const o of
|
|
143
|
+
}, j = async (t) => {
|
|
144
|
+
const e = new P();
|
|
145
|
+
e.use(D()), process.env.NODE_ENV !== "production" && e.use("*", T());
|
|
146
|
+
for (const o of S)
|
|
145
147
|
await o(e);
|
|
146
|
-
if (
|
|
148
|
+
if (w(e, t), E(e, t), process.env.NODE_ENV !== "production" && !p) {
|
|
147
149
|
const o = globalThis.__veloDevServer;
|
|
148
150
|
o && y(o);
|
|
149
151
|
}
|
|
150
152
|
return e;
|
|
151
|
-
},
|
|
152
|
-
const { routes: e, port: o = Number(process.env.SERVER_PORT) || 3e3 } = t, s = await
|
|
153
|
+
}, x = async (t) => {
|
|
154
|
+
const { routes: e, port: o = Number(process.env.SERVER_PORT) || 3e3 } = t, s = await j(e);
|
|
153
155
|
if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
|
|
154
|
-
const { serve:
|
|
155
|
-
(process.env.STATIC_BASE_URL || "").startsWith("http") || s.use("/*", a({ root:
|
|
156
|
-
const i =
|
|
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
|
+
(process.env.STATIC_BASE_URL || "").startsWith("http") || s.use("/*", a({ root: r })), console.log(`Server running on http://localhost:${o}`);
|
|
158
|
+
const i = n({ fetch: s.fetch, port: o });
|
|
157
159
|
y(i);
|
|
158
160
|
}
|
|
159
161
|
return s;
|
|
160
162
|
};
|
|
161
163
|
export {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
G as addRoutes,
|
|
165
|
+
j as createApp,
|
|
166
|
+
j as default,
|
|
167
|
+
M as onServer,
|
|
166
168
|
v as serverDataStorage,
|
|
167
|
-
|
|
169
|
+
x as startServer
|
|
168
170
|
};
|
package/dist/vite.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import d from "node:path";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import L from "node:fs";
|
|
3
|
+
import C from "@preact/preset-vite";
|
|
4
|
+
import F from "@hono/vite-dev-server";
|
|
5
5
|
import { parse as v } from "@babel/parser";
|
|
6
|
-
import
|
|
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
|
|
10
|
-
function
|
|
9
|
+
const m = typeof b == "function" ? b : b.default, S = typeof j == "function" ? j : j.default;
|
|
10
|
+
function w(u, c, r, l) {
|
|
11
11
|
const i = v(u, {
|
|
12
12
|
sourceType: "module",
|
|
13
13
|
plugins: ["typescript", "jsx"]
|
|
@@ -16,28 +16,28 @@ function C(u, o, r, l) {
|
|
|
16
16
|
if (m(i, {
|
|
17
17
|
// Procura: export const metadata = { ... }
|
|
18
18
|
ExportNamedDeclaration(s) {
|
|
19
|
-
const
|
|
20
|
-
if (e.isVariableDeclaration(
|
|
21
|
-
const a =
|
|
19
|
+
const o = s.node.declaration;
|
|
20
|
+
if (e.isVariableDeclaration(o) && o.declarations.length === 1) {
|
|
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), h = [
|
|
25
25
|
e.objectProperty(
|
|
26
26
|
e.identifier("moduleId"),
|
|
27
|
-
e.stringLiteral(
|
|
27
|
+
e.stringLiteral(c)
|
|
28
28
|
)
|
|
29
29
|
];
|
|
30
|
-
r !== void 0 &&
|
|
30
|
+
r !== void 0 && h.push(
|
|
31
31
|
e.objectProperty(
|
|
32
32
|
e.identifier("fullPath"),
|
|
33
33
|
e.stringLiteral(r)
|
|
34
34
|
)
|
|
35
|
-
), l !== void 0 &&
|
|
35
|
+
), l !== void 0 && h.push(
|
|
36
36
|
e.objectProperty(
|
|
37
37
|
e.identifier("path"),
|
|
38
38
|
e.stringLiteral(l)
|
|
39
39
|
)
|
|
40
|
-
), a.init.properties = [...
|
|
40
|
+
), a.init.properties = [...h, ...f];
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -45,7 +45,7 @@ function C(u, o, r, l) {
|
|
|
45
45
|
const s = [
|
|
46
46
|
e.objectProperty(
|
|
47
47
|
e.identifier("moduleId"),
|
|
48
|
-
e.stringLiteral(
|
|
48
|
+
e.stringLiteral(c)
|
|
49
49
|
)
|
|
50
50
|
];
|
|
51
51
|
r !== void 0 && s.push(
|
|
@@ -59,7 +59,7 @@ function C(u, o, r, l) {
|
|
|
59
59
|
e.stringLiteral(l)
|
|
60
60
|
)
|
|
61
61
|
);
|
|
62
|
-
const
|
|
62
|
+
const o = e.exportNamedDeclaration(
|
|
63
63
|
e.variableDeclaration("const", [
|
|
64
64
|
e.variableDeclarator(
|
|
65
65
|
e.identifier("metadata"),
|
|
@@ -67,11 +67,11 @@ function C(u, o, r, l) {
|
|
|
67
67
|
)
|
|
68
68
|
])
|
|
69
69
|
);
|
|
70
|
-
i.program.body.unshift(
|
|
70
|
+
i.program.body.unshift(o);
|
|
71
71
|
}
|
|
72
|
-
return
|
|
72
|
+
return S(i, { retainLines: !0 }).code;
|
|
73
73
|
}
|
|
74
|
-
function R(u,
|
|
74
|
+
function R(u, c) {
|
|
75
75
|
const r = v(u, {
|
|
76
76
|
sourceType: "module",
|
|
77
77
|
plugins: ["typescript", "jsx"]
|
|
@@ -80,12 +80,12 @@ function R(u, o) {
|
|
|
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
|
|
84
|
-
e.isStringLiteral(p) && p.value.includes("/") || (i.node.arguments = [a, ...
|
|
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
|
}
|
|
88
|
-
function V(u,
|
|
88
|
+
function V(u, c) {
|
|
89
89
|
const r = v(u, {
|
|
90
90
|
sourceType: "module",
|
|
91
91
|
plugins: ["typescript", "jsx"]
|
|
@@ -98,15 +98,15 @@ function V(u, o) {
|
|
|
98
98
|
if (!n || !e.isIdentifier(n.id)) return;
|
|
99
99
|
const s = n.id.name;
|
|
100
100
|
if (!s.startsWith("action_")) return;
|
|
101
|
-
const
|
|
101
|
+
const o = 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 = 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
|
|
109
|
-
const l = `/_action/${u}/${
|
|
108
|
+
function U(u, c, r) {
|
|
109
|
+
const l = `/_action/${u}/${c}`;
|
|
110
110
|
return r.length === 0 ? e.callExpression(
|
|
111
111
|
e.memberExpression(
|
|
112
112
|
e.callExpression(e.identifier("fetch"), [
|
|
@@ -175,9 +175,9 @@ function W(u, o, r) {
|
|
|
175
175
|
]
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
179
|
-
if (
|
|
180
|
-
const r =
|
|
178
|
+
function W(u, c) {
|
|
179
|
+
if (c.length === 0) return;
|
|
180
|
+
const r = c[0];
|
|
181
181
|
if (e.isObjectPattern(r)) {
|
|
182
182
|
let l = null;
|
|
183
183
|
if (e.isTSTypeAnnotation(r.typeAnnotation) && e.isTSTypeReference(r.typeAnnotation.typeAnnotation)) {
|
|
@@ -201,26 +201,26 @@ function $(u, o) {
|
|
|
201
201
|
)), u.params = [t];
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
function
|
|
205
|
-
const
|
|
204
|
+
function $(u) {
|
|
205
|
+
const c = v(u, {
|
|
206
206
|
sourceType: "module",
|
|
207
207
|
plugins: ["typescript", "jsx"]
|
|
208
208
|
});
|
|
209
|
-
return m(
|
|
209
|
+
return m(c, {
|
|
210
210
|
ExportNamedDeclaration(l) {
|
|
211
211
|
const i = l.node.declaration;
|
|
212
212
|
if (!e.isVariableDeclaration(i)) return;
|
|
213
213
|
const t = i.declarations[0];
|
|
214
214
|
!t || !e.isIdentifier(t.id) || t.id.name === "loader" && l.remove();
|
|
215
215
|
}
|
|
216
|
-
}),
|
|
216
|
+
}), S(c, { retainLines: !0 }).code;
|
|
217
217
|
}
|
|
218
218
|
function k(u) {
|
|
219
|
-
const
|
|
219
|
+
const c = v(u, {
|
|
220
220
|
sourceType: "module",
|
|
221
221
|
plugins: ["typescript", "jsx"]
|
|
222
222
|
}), r = /* @__PURE__ */ new Set();
|
|
223
|
-
return m(
|
|
223
|
+
return m(c, {
|
|
224
224
|
ObjectProperty(i) {
|
|
225
225
|
if (e.isIdentifier(i.node.key, { name: "middlewares" }) && e.isArrayExpression(i.node.value)) {
|
|
226
226
|
for (const t of i.node.value.elements)
|
|
@@ -228,25 +228,25 @@ function k(u) {
|
|
|
228
228
|
i.remove();
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
-
}), r.size === 0 ? u : (m(
|
|
231
|
+
}), r.size === 0 ? u : (m(c, {
|
|
232
232
|
ImportDeclaration(i) {
|
|
233
233
|
const t = i.node.specifiers, n = t.filter((s) => {
|
|
234
234
|
if (e.isImportSpecifier(s)) {
|
|
235
|
-
const
|
|
236
|
-
return !r.has(
|
|
235
|
+
const o = s.local.name;
|
|
236
|
+
return !r.has(o);
|
|
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
|
+
}), S(c, { retainLines: !0 }).code);
|
|
243
243
|
}
|
|
244
|
-
function
|
|
245
|
-
const
|
|
244
|
+
function _(u) {
|
|
245
|
+
const c = v(u, {
|
|
246
246
|
sourceType: "module",
|
|
247
247
|
plugins: ["typescript", "jsx"]
|
|
248
248
|
}), r = /* @__PURE__ */ new Map();
|
|
249
|
-
m(
|
|
249
|
+
m(c, {
|
|
250
250
|
ImportDeclaration(t) {
|
|
251
251
|
const n = t.node.source.value;
|
|
252
252
|
for (const s of t.node.specifiers)
|
|
@@ -254,7 +254,7 @@ function T(u) {
|
|
|
254
254
|
}
|
|
255
255
|
});
|
|
256
256
|
const l = /* @__PURE__ */ new Map();
|
|
257
|
-
m(
|
|
257
|
+
m(c, {
|
|
258
258
|
ExportDefaultDeclaration(t) {
|
|
259
259
|
const n = t.node.declaration;
|
|
260
260
|
let s = null;
|
|
@@ -265,23 +265,23 @@ function T(u) {
|
|
|
265
265
|
for (const [t, n] of l) {
|
|
266
266
|
const s = r.get(t);
|
|
267
267
|
if (s) {
|
|
268
|
-
const
|
|
269
|
-
i.set(
|
|
268
|
+
const o = s.replace(/^\.\//, "").replace(/\.(tsx?|jsx?|js)$/, "");
|
|
269
|
+
i.set(o, n);
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
return i;
|
|
273
273
|
}
|
|
274
|
-
function A(u,
|
|
274
|
+
function A(u, c, r) {
|
|
275
275
|
for (const l of u) {
|
|
276
276
|
if (!e.isObjectExpression(l)) continue;
|
|
277
|
-
let i = "", t =
|
|
278
|
-
for (const
|
|
279
|
-
if (!e.isObjectProperty(
|
|
280
|
-
const a =
|
|
281
|
-
p === "path" && e.isStringLiteral(
|
|
277
|
+
let i = "", t = c, n = null, s = null;
|
|
278
|
+
for (const o of l.properties) {
|
|
279
|
+
if (!e.isObjectProperty(o)) continue;
|
|
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
|
-
const a = !s && i === "/" ?
|
|
284
|
+
const a = !s && i === "/" ? c || "/" : t;
|
|
285
285
|
r.set(n, {
|
|
286
286
|
fullPath: a,
|
|
287
287
|
path: i
|
|
@@ -290,29 +290,29 @@ function A(u, o, r) {
|
|
|
290
290
|
s && A(s.elements, t, r);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
const g = "virtual:velo/server-entry",
|
|
294
|
-
function
|
|
295
|
-
let r = d.resolve(process.cwd(),
|
|
293
|
+
const g = "virtual:velo/server-entry", x = "virtual:velo/client-entry", T = "\0" + g, P = "\0" + x;
|
|
294
|
+
function J(u, c) {
|
|
295
|
+
let r = d.resolve(process.cwd(), c);
|
|
296
296
|
const l = u.routesFile ?? "routes.tsx", i = /* @__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, c);
|
|
302
302
|
},
|
|
303
303
|
buildStart() {
|
|
304
304
|
const t = d.join(r, l);
|
|
305
|
-
if (
|
|
306
|
-
const n =
|
|
305
|
+
if (L.existsSync(t)) {
|
|
306
|
+
const n = L.readFileSync(t, "utf-8"), s = _(n);
|
|
307
307
|
i.clear();
|
|
308
|
-
for (const [
|
|
309
|
-
i.set(
|
|
308
|
+
for (const [o, a] of s)
|
|
309
|
+
i.set(o, a);
|
|
310
310
|
}
|
|
311
311
|
},
|
|
312
312
|
handleHotUpdate({ file: t, server: n }) {
|
|
313
313
|
const s = d.join(r, l);
|
|
314
314
|
if (t === s) {
|
|
315
|
-
const
|
|
315
|
+
const o = L.readFileSync(s, "utf-8"), a = _(o);
|
|
316
316
|
i.clear();
|
|
317
317
|
for (const [p, f] of a)
|
|
318
318
|
i.set(p, f);
|
|
@@ -320,11 +320,11 @@ function M(u, o) {
|
|
|
320
320
|
}
|
|
321
321
|
},
|
|
322
322
|
resolveId(t) {
|
|
323
|
-
return t === g || t.endsWith(g) ?
|
|
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",
|
|
327
|
-
return 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"), p = d.join(r, s).replace(/\.tsx?$/, ".js"), f = d.join(r, o).replace(/\.tsx?$/, ".js");
|
|
327
|
+
return t === T ? `
|
|
328
328
|
import "${p}";
|
|
329
329
|
import routes from "${a}";
|
|
330
330
|
import { startServer } from "@mauroandre/velojs/server";
|
|
@@ -340,18 +340,18 @@ startClient({ routes });
|
|
|
340
340
|
` : null;
|
|
341
341
|
},
|
|
342
342
|
transform(t, n, s) {
|
|
343
|
-
const
|
|
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
345
|
let a = t, p = !1;
|
|
346
|
-
const f = /middlewares:\s*\[/.test(t),
|
|
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), N = /export\s+const\s+action_\w+/.test(t),
|
|
349
|
-
if (!
|
|
350
|
-
const
|
|
351
|
-
a =
|
|
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
|
+
const E = d.relative(r, n).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), I = i.get(E);
|
|
351
|
+
a = w(a, E, I?.fullPath, I?.path), a = R(a, E), o || (a = V(
|
|
352
352
|
a,
|
|
353
|
-
|
|
354
|
-
)),
|
|
353
|
+
E
|
|
354
|
+
)), o || (a = $(a)), p = !0;
|
|
355
355
|
}
|
|
356
356
|
return p ? {
|
|
357
357
|
code: a,
|
|
@@ -360,16 +360,26 @@ startClient({ routes });
|
|
|
360
360
|
}
|
|
361
361
|
};
|
|
362
362
|
}
|
|
363
|
-
function
|
|
363
|
+
function M() {
|
|
364
364
|
return {
|
|
365
365
|
name: "velo:config",
|
|
366
|
-
config(u, { mode:
|
|
367
|
-
const r =
|
|
366
|
+
config(u, { mode: c }) {
|
|
367
|
+
const r = c === "server", l = c === "development", i = !!process.env.VELO_STATIC;
|
|
368
|
+
let t = "client.js", n = "client.css";
|
|
369
|
+
if (r)
|
|
370
|
+
try {
|
|
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
|
+
} catch {
|
|
374
|
+
}
|
|
375
|
+
const s = {
|
|
368
376
|
define: {
|
|
369
377
|
"process.env.NODE_ENV": JSON.stringify(l ? "development" : "production"),
|
|
370
378
|
"process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (i ? "/client" : "")),
|
|
371
379
|
__VELO_STATIC__: JSON.stringify(i),
|
|
372
|
-
__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
|
+
__VELO_CLIENT_JS__: JSON.stringify(t),
|
|
382
|
+
__VELO_CLIENT_CSS__: JSON.stringify(n)
|
|
373
383
|
},
|
|
374
384
|
resolve: {
|
|
375
385
|
alias: {
|
|
@@ -378,7 +388,7 @@ function B() {
|
|
|
378
388
|
}
|
|
379
389
|
}
|
|
380
390
|
};
|
|
381
|
-
return r ?
|
|
391
|
+
return r ? s.build = {
|
|
382
392
|
ssr: g,
|
|
383
393
|
outDir: "dist",
|
|
384
394
|
emptyOutDir: !1,
|
|
@@ -388,29 +398,29 @@ function B() {
|
|
|
388
398
|
entryFileNames: "server.js"
|
|
389
399
|
}
|
|
390
400
|
}
|
|
391
|
-
} : l || (
|
|
401
|
+
} : l || (s.build = {
|
|
392
402
|
manifest: !0,
|
|
393
403
|
outDir: "dist/client",
|
|
394
404
|
rollupOptions: {
|
|
395
|
-
input:
|
|
405
|
+
input: x,
|
|
396
406
|
output: {
|
|
397
|
-
entryFileNames: "client.js",
|
|
398
|
-
assetFileNames: (
|
|
407
|
+
entryFileNames: "client.[hash].js",
|
|
408
|
+
assetFileNames: (o) => o.names?.[0]?.endsWith(".css") ? "client.[hash].css" : "[name].[hash][extname]"
|
|
399
409
|
}
|
|
400
410
|
}
|
|
401
|
-
}),
|
|
411
|
+
}), s;
|
|
402
412
|
}
|
|
403
413
|
};
|
|
404
414
|
}
|
|
405
|
-
function
|
|
415
|
+
function B() {
|
|
406
416
|
return {
|
|
407
417
|
name: "velo:static-url",
|
|
408
418
|
apply: "build",
|
|
409
419
|
enforce: "post",
|
|
410
|
-
generateBundle(u,
|
|
420
|
+
generateBundle(u, c) {
|
|
411
421
|
const r = process.env.STATIC_BASE_URL || "";
|
|
412
422
|
if (r)
|
|
413
|
-
for (const l of Object.values(
|
|
423
|
+
for (const l of Object.values(c))
|
|
414
424
|
l.type === "asset" && typeof l.source == "string" && l.fileName.endsWith(".css") && (l.source = l.source.replace(
|
|
415
425
|
/url\(\s*(['"]?)\/(?!\/)/g,
|
|
416
426
|
`url($1${r}/`
|
|
@@ -419,13 +429,13 @@ function J() {
|
|
|
419
429
|
};
|
|
420
430
|
}
|
|
421
431
|
function Z(u) {
|
|
422
|
-
const
|
|
432
|
+
const c = u ?? {}, r = c.appDirectory ?? "./app";
|
|
423
433
|
return [
|
|
434
|
+
M(),
|
|
435
|
+
J(c, r),
|
|
424
436
|
B(),
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
F(),
|
|
428
|
-
w({
|
|
437
|
+
C(),
|
|
438
|
+
F({
|
|
429
439
|
entry: g
|
|
430
440
|
}),
|
|
431
441
|
H()
|
|
@@ -440,10 +450,10 @@ function H() {
|
|
|
440
450
|
};
|
|
441
451
|
}
|
|
442
452
|
export {
|
|
443
|
-
|
|
453
|
+
_ as buildFullPathMap,
|
|
444
454
|
A as collectFullPaths,
|
|
445
|
-
|
|
446
|
-
|
|
455
|
+
w as injectMetadata,
|
|
456
|
+
$ as removeLoaders,
|
|
447
457
|
k as removeMiddlewares,
|
|
448
458
|
V as transformActionsForClient,
|
|
449
459
|
R as transformLoaderFunctions,
|