@mauroandre/velojs 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +18 -14
- package/dist/components.js +31 -31
- package/dist/vite.js +36 -36
- package/package.json +1 -1
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,48 +1,48 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { Link as
|
|
3
|
-
import { __veloUpdatePending as
|
|
4
|
-
function
|
|
5
|
-
const
|
|
1
|
+
import { jsx as o, jsxs as p, Fragment as L } from "preact/jsx-runtime";
|
|
2
|
+
import { Link as v } from "wouter-preact";
|
|
3
|
+
import { __veloUpdatePending as E } from "./hooks.js";
|
|
4
|
+
function k({ basePath: e, favicon: t = "/favicon.ico" } = {}) {
|
|
5
|
+
const n = process.env.NODE_ENV !== "production";
|
|
6
6
|
e = e || process.env.STATIC_BASE_URL || (process.env.VELO_STATIC ? "/client" : "");
|
|
7
|
-
const i =
|
|
8
|
-
if (
|
|
9
|
-
return /* @__PURE__ */
|
|
7
|
+
const i = t !== !1 && /* @__PURE__ */ o("link", { rel: "icon", href: `${e}${t}`, type: "image/x-icon" });
|
|
8
|
+
if (n)
|
|
9
|
+
return /* @__PURE__ */ p(L, { children: [
|
|
10
10
|
i,
|
|
11
|
-
/* @__PURE__ */
|
|
12
|
-
/* @__PURE__ */
|
|
11
|
+
/* @__PURE__ */ o("script", { type: "module", src: "/@vite/client" }),
|
|
12
|
+
/* @__PURE__ */ o("script", { type: "module", src: "/__velo_client.js" })
|
|
13
13
|
] });
|
|
14
|
-
const
|
|
15
|
-
return /* @__PURE__ */
|
|
14
|
+
const r = typeof __VELO_CLIENT_JS__ < "u" ? __VELO_CLIENT_JS__ : "client.js";
|
|
15
|
+
return /* @__PURE__ */ p(L, { children: [
|
|
16
16
|
i,
|
|
17
|
-
/* @__PURE__ */
|
|
18
|
-
/* @__PURE__ */
|
|
17
|
+
/* @__PURE__ */ o("link", { rel: "stylesheet", href: `${e}/${typeof __VELO_CLIENT_CSS__ < "u" ? __VELO_CLIENT_CSS__ : "client.css"}` }),
|
|
18
|
+
/* @__PURE__ */ o("script", { type: "module", src: `${e}/${r}` })
|
|
19
19
|
] });
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
let
|
|
23
|
-
for (const [i,
|
|
24
|
-
|
|
25
|
-
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;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const c = typeof e != "string",
|
|
29
|
-
if (typeof window < "u" &&
|
|
30
|
-
const { onClick:
|
|
31
|
-
return /* @__PURE__ */
|
|
27
|
+
function g({ to: e, params: t, search: n, absolute: i, ...r }) {
|
|
28
|
+
const c = typeof e != "string", s = c ? (i ? e.metadata?.fullPath : e.metadata?.path) ?? "/" : e, f = t ? $(s, t) : s, m = c && i ? `~${f}` : f, _ = n ? `?${new URLSearchParams(n).toString()}` : "", S = `${m}${_}`;
|
|
29
|
+
if (typeof window < "u" && E.value) {
|
|
30
|
+
const u = c ? e.metadata?.fullPath ?? s : s, a = `${t ? $(u, t) : u}${_}`, { onClick: d, ...h } = r;
|
|
31
|
+
return /* @__PURE__ */ o(
|
|
32
32
|
"a",
|
|
33
33
|
{
|
|
34
|
-
href:
|
|
34
|
+
href: a,
|
|
35
35
|
onClick: (l) => {
|
|
36
|
-
|
|
36
|
+
d && d(l), l.defaultPrevented || (l.preventDefault(), window.location.href = a);
|
|
37
37
|
},
|
|
38
|
-
...
|
|
38
|
+
...h
|
|
39
39
|
}
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
|
-
return /* @__PURE__ */
|
|
42
|
+
return /* @__PURE__ */ o(v, { to: S, ...r });
|
|
43
43
|
}
|
|
44
44
|
export {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
g as Link,
|
|
46
|
+
k as Scripts,
|
|
47
|
+
$ as substituteParams
|
|
48
48
|
};
|
package/dist/vite.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import d from "node:path";
|
|
2
|
-
import
|
|
2
|
+
import L from "node:fs";
|
|
3
3
|
import C from "@preact/preset-vite";
|
|
4
4
|
import F from "@hono/vite-dev-server";
|
|
5
5
|
import { parse as v } from "@babel/parser";
|
|
6
|
-
import
|
|
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
|
|
9
|
+
const m = typeof b == "function" ? b : b.default, S = typeof j == "function" ? j : j.default;
|
|
10
10
|
function w(u, c, r, l) {
|
|
11
11
|
const i = v(u, {
|
|
12
12
|
sourceType: "module",
|
|
@@ -21,7 +21,7 @@ function w(u, c, r, l) {
|
|
|
21
21
|
const a = o.declarations[0];
|
|
22
22
|
if (a && e.isIdentifier(a.id, { name: "metadata" }) && e.isObjectExpression(a.init)) {
|
|
23
23
|
t = !0;
|
|
24
|
-
const
|
|
24
|
+
const f = a.init.properties.filter((y) => e.isObjectProperty(y) && e.isIdentifier(y.key) ? y.key.name !== "moduleId" && y.key.name !== "fullPath" && y.key.name !== "path" : !0), h = [
|
|
25
25
|
e.objectProperty(
|
|
26
26
|
e.identifier("moduleId"),
|
|
27
27
|
e.stringLiteral(c)
|
|
@@ -37,7 +37,7 @@ function w(u, c, r, l) {
|
|
|
37
37
|
e.identifier("path"),
|
|
38
38
|
e.stringLiteral(l)
|
|
39
39
|
)
|
|
40
|
-
), a.init.properties = [...h, ...
|
|
40
|
+
), a.init.properties = [...h, ...f];
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -80,8 +80,8 @@ function R(u, c) {
|
|
|
80
80
|
CallExpression(i) {
|
|
81
81
|
const t = i.node.callee, n = e.isIdentifier(t, { name: "Loader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "Loader" }), s = e.isIdentifier(t, { name: "useLoader" }) || e.isTSInstantiationExpression(t) && e.isIdentifier(t.expression, { name: "useLoader" });
|
|
82
82
|
if (!n && !s) return;
|
|
83
|
-
const o = i.node.arguments, a = e.stringLiteral(c),
|
|
84
|
-
e.isStringLiteral(
|
|
83
|
+
const o = i.node.arguments, a = e.stringLiteral(c), p = o[0];
|
|
84
|
+
e.isStringLiteral(p) && p.value.includes("/") || (i.node.arguments = [a, ...o]);
|
|
85
85
|
}
|
|
86
86
|
}), S(r, { retainLines: !0 }).code;
|
|
87
87
|
}
|
|
@@ -100,12 +100,12 @@ function V(u, c) {
|
|
|
100
100
|
if (!s.startsWith("action_")) return;
|
|
101
101
|
const o = s.replace("action_", ""), a = n.init;
|
|
102
102
|
if (!e.isArrowFunctionExpression(a) || !a.async) return;
|
|
103
|
-
const
|
|
104
|
-
a.body = e.blockStatement([e.returnStatement(
|
|
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
|
|
108
|
+
function U(u, c, r) {
|
|
109
109
|
const l = `/_action/${u}/${c}`;
|
|
110
110
|
return r.length === 0 ? e.callExpression(
|
|
111
111
|
e.memberExpression(
|
|
@@ -175,7 +175,7 @@ function W(u, c, r) {
|
|
|
175
175
|
]
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function W(u, c) {
|
|
179
179
|
if (c.length === 0) return;
|
|
180
180
|
const r = c[0];
|
|
181
181
|
if (e.isObjectPattern(r)) {
|
|
@@ -201,7 +201,7 @@ function $(u, c) {
|
|
|
201
201
|
)), u.params = [t];
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
function
|
|
204
|
+
function $(u) {
|
|
205
205
|
const c = v(u, {
|
|
206
206
|
sourceType: "module",
|
|
207
207
|
plugins: ["typescript", "jsx"]
|
|
@@ -258,7 +258,7 @@ function _(u) {
|
|
|
258
258
|
ExportDefaultDeclaration(t) {
|
|
259
259
|
const n = t.node.declaration;
|
|
260
260
|
let s = null;
|
|
261
|
-
e.isArrayExpression(n) ? s = n : e.isTSSatisfiesExpression(n) && e.isArrayExpression(n.expression) && (s = n.expression), s &&
|
|
261
|
+
e.isArrayExpression(n) ? s = n : e.isTSSatisfiesExpression(n) && e.isArrayExpression(n.expression) && (s = n.expression), s && A(s.elements, "", l);
|
|
262
262
|
}
|
|
263
263
|
});
|
|
264
264
|
const i = /* @__PURE__ */ new Map();
|
|
@@ -271,14 +271,14 @@ function _(u) {
|
|
|
271
271
|
}
|
|
272
272
|
return i;
|
|
273
273
|
}
|
|
274
|
-
function
|
|
274
|
+
function A(u, c, r) {
|
|
275
275
|
for (const l of u) {
|
|
276
276
|
if (!e.isObjectExpression(l)) continue;
|
|
277
277
|
let i = "", t = c, n = null, s = null;
|
|
278
278
|
for (const o of l.properties) {
|
|
279
279
|
if (!e.isObjectProperty(o)) continue;
|
|
280
|
-
const a = o.key,
|
|
281
|
-
|
|
280
|
+
const a = o.key, p = e.isIdentifier(a) ? a.name : null;
|
|
281
|
+
p === "path" && e.isStringLiteral(o.value) && (i = o.value.value, i && !i.startsWith("/") ? t = c + "/" + i : t = c + i), p === "module" && e.isIdentifier(o.value) && (n = o.value.name), p === "children" && e.isArrayExpression(o.value) && (s = o.value);
|
|
282
282
|
}
|
|
283
283
|
if (n) {
|
|
284
284
|
const a = !s && i === "/" ? c || "/" : t;
|
|
@@ -287,7 +287,7 @@ function N(u, c, r) {
|
|
|
287
287
|
path: i
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
|
-
s &&
|
|
290
|
+
s && A(s.elements, t, r);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
const g = "virtual:velo/server-entry", x = "virtual:velo/client-entry", T = "\0" + g, P = "\0" + x;
|
|
@@ -302,8 +302,8 @@ function J(u, c) {
|
|
|
302
302
|
},
|
|
303
303
|
buildStart() {
|
|
304
304
|
const t = d.join(r, l);
|
|
305
|
-
if (
|
|
306
|
-
const n =
|
|
305
|
+
if (L.existsSync(t)) {
|
|
306
|
+
const n = L.readFileSync(t, "utf-8"), s = _(n);
|
|
307
307
|
i.clear();
|
|
308
308
|
for (const [o, a] of s)
|
|
309
309
|
i.set(o, a);
|
|
@@ -312,10 +312,10 @@ function J(u, c) {
|
|
|
312
312
|
handleHotUpdate({ file: t, server: n }) {
|
|
313
313
|
const s = d.join(r, l);
|
|
314
314
|
if (t === s) {
|
|
315
|
-
const o =
|
|
315
|
+
const o = L.readFileSync(s, "utf-8"), a = _(o);
|
|
316
316
|
i.clear();
|
|
317
|
-
for (const [
|
|
318
|
-
i.set(
|
|
317
|
+
for (const [p, f] of a)
|
|
318
|
+
i.set(p, f);
|
|
319
319
|
return n.ws.send({ type: "full-reload" }), [];
|
|
320
320
|
}
|
|
321
321
|
},
|
|
@@ -323,16 +323,16 @@ function J(u, c) {
|
|
|
323
323
|
return t === g || t.endsWith(g) ? T : t === x || t.endsWith(x) || t === "/__velo_client.js" ? P : null;
|
|
324
324
|
},
|
|
325
325
|
load(t) {
|
|
326
|
-
const n = u.routesFile ?? "routes.tsx", s = u.serverInit ?? "server.tsx", o = u.clientInit ?? "client.tsx", a = d.join(r, n).replace(/\.tsx?$/, ".js"),
|
|
326
|
+
const n = u.routesFile ?? "routes.tsx", s = u.serverInit ?? "server.tsx", o = u.clientInit ?? "client.tsx", a = d.join(r, n).replace(/\.tsx?$/, ".js"), p = d.join(r, s).replace(/\.tsx?$/, ".js"), f = d.join(r, o).replace(/\.tsx?$/, ".js");
|
|
327
327
|
return t === T ? `
|
|
328
|
-
import "${
|
|
328
|
+
import "${p}";
|
|
329
329
|
import routes from "${a}";
|
|
330
330
|
import { startServer } from "@mauroandre/velojs/server";
|
|
331
331
|
|
|
332
332
|
export { routes };
|
|
333
333
|
export default await startServer({ routes });
|
|
334
334
|
` : t === P ? `
|
|
335
|
-
import "${
|
|
335
|
+
import "${f}";
|
|
336
336
|
import routes from "${a}";
|
|
337
337
|
import { startClient } from "@mauroandre/velojs/client";
|
|
338
338
|
|
|
@@ -342,18 +342,18 @@ startClient({ routes });
|
|
|
342
342
|
transform(t, n, s) {
|
|
343
343
|
const o = s?.ssr === !0;
|
|
344
344
|
if (n.startsWith("\0") || n.includes("/.velojs/") || !n.endsWith(".tsx") && !n.endsWith(".ts") || !n.startsWith(r)) return null;
|
|
345
|
-
let a = t,
|
|
346
|
-
const
|
|
345
|
+
let a = t, p = !1;
|
|
346
|
+
const f = /middlewares:\s*\[/.test(t), h = /export\s+(const|function)\s+Component/.test(
|
|
347
347
|
t
|
|
348
|
-
), y = /export\s+(const|function)\s+loader/.test(t),
|
|
349
|
-
if (!o &&
|
|
348
|
+
), y = /export\s+(const|function)\s+loader/.test(t), N = /export\s+const\s+action_\w+/.test(t), O = /\bLoader\s*</.test(t) || /\bLoader\s*\(/.test(t), D = /\buseLoader\s*</.test(t) || /\buseLoader\s*\(/.test(t);
|
|
349
|
+
if (!o && f && (a = k(a), p = !0), h || y || N || O || D) {
|
|
350
350
|
const E = d.relative(r, n).replace(/\.(tsx?|jsx?)$/, "").replace(/\\/g, "/"), I = i.get(E);
|
|
351
351
|
a = w(a, E, I?.fullPath, I?.path), a = R(a, E), o || (a = V(
|
|
352
352
|
a,
|
|
353
353
|
E
|
|
354
|
-
)), o || (a =
|
|
354
|
+
)), o || (a = $(a)), p = !0;
|
|
355
355
|
}
|
|
356
|
-
return
|
|
356
|
+
return p ? {
|
|
357
357
|
code: a,
|
|
358
358
|
map: null
|
|
359
359
|
} : null;
|
|
@@ -368,8 +368,8 @@ function M() {
|
|
|
368
368
|
let t = "client.js", n = "client.css";
|
|
369
369
|
if (r)
|
|
370
370
|
try {
|
|
371
|
-
const o = d.resolve(process.cwd(), "dist/client/.vite/manifest.json"),
|
|
372
|
-
|
|
371
|
+
const o = d.resolve(process.cwd(), "dist/client/.vite/manifest.json"), p = JSON.parse(L.readFileSync(o, "utf-8"))[x];
|
|
372
|
+
p && (t = p.file || t, p.css?.[0] && (n = p.css[0]));
|
|
373
373
|
} catch {
|
|
374
374
|
}
|
|
375
375
|
const s = {
|
|
@@ -377,7 +377,7 @@ function M() {
|
|
|
377
377
|
"process.env.NODE_ENV": JSON.stringify(l ? "development" : "production"),
|
|
378
378
|
"process.env.STATIC_BASE_URL": JSON.stringify(process.env.STATIC_BASE_URL || (i ? "/client" : "")),
|
|
379
379
|
__VELO_STATIC__: JSON.stringify(i),
|
|
380
|
-
__VELO_BUILD_HASH__: JSON.stringify(Date.now().toString(36)),
|
|
380
|
+
__VELO_BUILD_HASH__: JSON.stringify(process.env.VELO_BUILD_HASH || Date.now().toString(36)),
|
|
381
381
|
__VELO_CLIENT_JS__: JSON.stringify(t),
|
|
382
382
|
__VELO_CLIENT_CSS__: JSON.stringify(n)
|
|
383
383
|
},
|
|
@@ -451,9 +451,9 @@ function H() {
|
|
|
451
451
|
}
|
|
452
452
|
export {
|
|
453
453
|
_ as buildFullPathMap,
|
|
454
|
-
|
|
454
|
+
A as collectFullPaths,
|
|
455
455
|
w as injectMetadata,
|
|
456
|
-
|
|
456
|
+
$ as removeLoaders,
|
|
457
457
|
k as removeMiddlewares,
|
|
458
458
|
V as transformActionsForClient,
|
|
459
459
|
R as transformLoaderFunctions,
|