@cfdez11/vex 0.8.2 → 0.9.0

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.
Files changed (71) hide show
  1. package/dist/bin/vex.js +3 -0
  2. package/dist/client/services/cache.js +1 -0
  3. package/dist/client/services/hmr-client.js +1 -0
  4. package/dist/client/services/html.js +1 -0
  5. package/dist/client/services/hydrate-client-components.js +1 -0
  6. package/dist/client/services/hydrate.js +1 -0
  7. package/dist/client/services/index.js +1 -0
  8. package/dist/client/services/navigation/create-layouts.js +1 -0
  9. package/dist/client/services/navigation/create-navigation.js +1 -0
  10. package/dist/client/services/navigation/index.js +1 -0
  11. package/dist/client/services/navigation/link-interceptor.js +1 -0
  12. package/dist/client/services/navigation/metadata.js +1 -0
  13. package/dist/client/services/navigation/navigate.js +1 -0
  14. package/dist/client/services/navigation/prefetch.js +1 -0
  15. package/dist/client/services/navigation/render-page.js +1 -0
  16. package/dist/client/services/navigation/render-ssr.js +1 -0
  17. package/dist/client/services/navigation/router.js +1 -0
  18. package/dist/client/services/navigation/use-query-params.js +1 -0
  19. package/dist/client/services/navigation/use-route-params.js +1 -0
  20. package/dist/client/services/navigation.js +1 -0
  21. package/dist/client/services/reactive.js +1 -0
  22. package/dist/server/build-static.js +6 -0
  23. package/dist/server/index.js +4 -0
  24. package/dist/server/prebuild.js +1 -0
  25. package/dist/server/utils/cache.js +1 -0
  26. package/dist/server/utils/component-processor.js +68 -0
  27. package/dist/server/utils/data-cache.js +1 -0
  28. package/dist/server/utils/esbuild-plugin.js +1 -0
  29. package/dist/server/utils/files.js +28 -0
  30. package/dist/server/utils/hmr.js +1 -0
  31. package/dist/server/utils/router.js +11 -0
  32. package/dist/server/utils/streaming.js +1 -0
  33. package/dist/server/utils/template.js +1 -0
  34. package/package.json +8 -7
  35. package/bin/vex.js +0 -69
  36. package/client/favicon.ico +0 -0
  37. package/client/services/cache.js +0 -55
  38. package/client/services/hmr-client.js +0 -22
  39. package/client/services/html.js +0 -377
  40. package/client/services/hydrate-client-components.js +0 -97
  41. package/client/services/hydrate.js +0 -25
  42. package/client/services/index.js +0 -9
  43. package/client/services/navigation/create-layouts.js +0 -172
  44. package/client/services/navigation/create-navigation.js +0 -103
  45. package/client/services/navigation/index.js +0 -8
  46. package/client/services/navigation/link-interceptor.js +0 -39
  47. package/client/services/navigation/metadata.js +0 -23
  48. package/client/services/navigation/navigate.js +0 -64
  49. package/client/services/navigation/prefetch.js +0 -43
  50. package/client/services/navigation/render-page.js +0 -45
  51. package/client/services/navigation/render-ssr.js +0 -157
  52. package/client/services/navigation/router.js +0 -48
  53. package/client/services/navigation/use-query-params.js +0 -225
  54. package/client/services/navigation/use-route-params.js +0 -76
  55. package/client/services/navigation.js +0 -6
  56. package/client/services/reactive.js +0 -247
  57. package/server/build-static.js +0 -138
  58. package/server/index.js +0 -135
  59. package/server/prebuild.js +0 -13
  60. package/server/utils/cache.js +0 -89
  61. package/server/utils/component-processor.js +0 -1631
  62. package/server/utils/data-cache.js +0 -62
  63. package/server/utils/delay.js +0 -1
  64. package/server/utils/esbuild-plugin.js +0 -110
  65. package/server/utils/files.js +0 -845
  66. package/server/utils/hmr.js +0 -21
  67. package/server/utils/router.js +0 -375
  68. package/server/utils/streaming.js +0 -324
  69. package/server/utils/template.js +0 -274
  70. /package/{client → dist/client}/app.webmanifest +0 -0
  71. /package/{server → dist/server}/root.html +0 -0
package/server/index.js DELETED
@@ -1,135 +0,0 @@
1
- import "dotenv/config";
2
- import express from "express";
3
- import path from "path";
4
- import { pathToFileURL } from "url";
5
- import { handlePageRequest, revalidatePath } from "./utils/router.js";
6
- import { initializeDirectories, CLIENT_DIR, USER_GENERATED_DIR } from "./utils/files.js";
7
-
8
- await initializeDirectories();
9
-
10
- let serverRoutes;
11
-
12
- if (process.env.NODE_ENV === "production") {
13
- try {
14
- const routesPath = path.join(process.cwd(), ".vexjs", "_routes.js");
15
- const { routes } = await import(pathToFileURL(routesPath).href);
16
- serverRoutes = routes;
17
- console.log("Routes loaded.");
18
- } catch {
19
- console.error("ERROR: No build found. Run 'vex build' before starting in production.");
20
- process.exit(1);
21
- }
22
- } else {
23
- const { build } = await import("./utils/component-processor.js");
24
- const result = await build();
25
- console.log("Components and routes generated.");
26
- serverRoutes = result.serverRoutes;
27
- }
28
-
29
- const app = express();
30
-
31
- // Serve generated client component bundles at /_vexjs/_components/
32
- app.use(
33
- "/_vexjs/_components",
34
- express.static(path.join(process.cwd(), ".vexjs", "_components"), {
35
- setHeaders(res, filePath) {
36
- if (filePath.endsWith(".js")) {
37
- res.setHeader("Content-Type", "application/javascript");
38
- }
39
- },
40
- })
41
- );
42
-
43
- // Serve framework runtime JS + generated files (_routes.js) at /_vexjs/services/
44
- // initializeDirectories() pre-populates this dir with framework files; build()
45
- // adds generated files (_routes.js). Single source of truth for all /_vexjs/services/*.
46
- app.use(
47
- "/_vexjs/services",
48
- express.static(path.join(process.cwd(), ".vexjs", "services"), {
49
- setHeaders(res, filePath) {
50
- if (filePath.endsWith(".js")) {
51
- res.setHeader("Content-Type", "application/javascript");
52
- }
53
- },
54
- })
55
- );
56
-
57
- // Serve pre-bundled user JS utility files at /_vexjs/user/
58
- // Registered before the generic /_vexjs mount so requests don't fall through
59
- // to CLIENT_DIR unnecessarily. esbuild bundles each file with npm packages
60
- // inlined; vex/*, @/*, and relative user imports stay external (singletons).
61
- app.use(
62
- "/_vexjs/user",
63
- express.static(USER_GENERATED_DIR, {
64
- setHeaders(res, filePath) {
65
- if (filePath.endsWith(".js")) {
66
- res.setHeader("Content-Type", "application/javascript");
67
- }
68
- },
69
- })
70
- );
71
-
72
- // Serve static framework assets (favicon.ico, app.webmanifest) from CLIENT_DIR.
73
- // Runtime JS files (reactive.js, index.js, etc.) are already in .vexjs/services/
74
- // via initializeDirectories() and are served by the /_vexjs/services route above.
75
- app.use(
76
- "/_vexjs",
77
- express.static(CLIENT_DIR, {
78
- setHeaders(res, filePath) {
79
- if (filePath.endsWith(".js")) {
80
- res.setHeader("Content-Type", "application/javascript");
81
- }
82
- },
83
- })
84
- );
85
-
86
- // Serve user's public directory at /
87
- app.use("/", express.static(path.join(process.cwd(), "public")));
88
-
89
- app.get("/revalidate", revalidatePath);
90
-
91
- // HMR SSE endpoint — dev only
92
- if (process.env.NODE_ENV !== "production") {
93
- const { hmrEmitter } = await import("./utils/hmr.js");
94
-
95
- app.get("/_vexjs/hmr", (req, res) => {
96
- res.setHeader("Content-Type", "text/event-stream");
97
- res.setHeader("Cache-Control", "no-cache");
98
- res.setHeader("Connection", "keep-alive");
99
- res.flushHeaders();
100
-
101
- const onReload = (filename) => {
102
- res.write(`event: reload\ndata: ${filename}\n\n`);
103
- };
104
-
105
- hmrEmitter.on("reload", onReload);
106
- req.on("close", () => hmrEmitter.off("reload", onReload));
107
- });
108
- }
109
-
110
- const registerSSRRoutes = (app, routes) => {
111
- routes.forEach((route) => {
112
- app.get(
113
- route.serverPath,
114
- async (req, res) => await handlePageRequest(req, res, route)
115
- );
116
- });
117
- };
118
-
119
- registerSSRRoutes(app, serverRoutes);
120
-
121
- app.use(async (req, res) => {
122
- const notFoundRoute = serverRoutes.find((r) => r.isNotFound);
123
- if (notFoundRoute) {
124
- return handlePageRequest(req, res, notFoundRoute);
125
- }
126
-
127
- res.status(404).send("Page not found");
128
- });
129
-
130
- const PORT = process.env.VEX_PORT || process.env.PORT || 3001;
131
- app.listen(PORT, () => {
132
- console.log(`Server running on port ${PORT}`);
133
- });
134
-
135
- export default app;
@@ -1,13 +0,0 @@
1
- import "dotenv/config";
2
- import { build } from "./utils/component-processor.js";
3
- import { initializeDirectories } from "./utils/files.js";
4
-
5
- console.log("🔨 Starting prebuild...");
6
-
7
- console.log("📁 Creating directories...");
8
- await initializeDirectories();
9
-
10
- console.log("⚙️ Generating components and routes...");
11
- await build();
12
-
13
- console.log("✅ Prebuild complete!");
@@ -1,89 +0,0 @@
1
- import { getComponentHtmlDisk, markComponentHtmlStale, saveComponentHtmlDisk } from "./files.js";
2
-
3
- /**
4
- * Retrieves cached HTML for a component or page from disk and determines if it is stale.
5
- *
6
- * This function supports Incremental Static Regeneration (ISR) semantics:
7
- * - If the cache does not exist, `html` will be null.
8
- * - If the cache exists, `isStale` indicates whether the cached HTML should be regenerated.
9
- *
10
- * @async
11
- * @param {Object} options
12
- * @param {string} options.componentPath - Unique identifier or path of the component/page to retrieve.
13
- * @param {number} [options.revalidateSeconds=0] - Number of seconds before the cached HTML is considered stale.
14
- * - `-1` indicates the cache never becomes stale (always fresh).
15
- * - `0` indicates the cache is always stale (regenerate on every request).
16
- * @returns {Promise<{ html: string|null, isStale: boolean }>}
17
- * - `html`: The cached HTML content, or null if not cached.
18
- * - `isStale`: True if the cache is stale or explicitly invalidated, false otherwise.
19
- */
20
- export async function getCachedComponentHtml({ componentPath, revalidateSeconds = 0 }) {
21
- const { html, meta } = await getComponentHtmlDisk({ componentPath, revalidateSeconds });
22
-
23
- if (!html) {
24
- return { html: null };
25
- }
26
-
27
- let staleByTime = false;
28
- if (revalidateSeconds !== -1) {
29
- staleByTime = Date.now() - meta.generatedAt > revalidateSeconds * 1000;
30
- }
31
-
32
- const isStale = meta.isStale === true || staleByTime;
33
-
34
- return { html, isStale };
35
- }
36
-
37
- /**
38
- * Stores HTML content of a component/page on disk along with metadata.
39
- *
40
- * Metadata includes:
41
- * - `generatedAt`: Timestamp of when the HTML was generated
42
- * - `isStale`: Indicates if the cache is stale (always false when saving)
43
- *
44
- * @async
45
- * @param {Object} options
46
- * @param {string} options.componentPath - Unique identifier or path of the component/page to cache.
47
- * @param {string} options.html - The HTML content to store in the cache.
48
- * @returns {Promise<void>} Resolves when the HTML and metadata have been successfully saved.
49
- */
50
- export async function saveCachedComponentHtml({ componentPath, html }) {
51
- await saveComponentHtmlDisk({ componentPath, html });
52
- }
53
-
54
- /**
55
- * Marks a cached component as stale without regenerating it.
56
- *
57
- * This is useful for manual revalidation or triggering ISR.
58
- *
59
- * @async
60
- * @param {string} componentPath - Unique identifier or path of the component/page to invalidate.
61
- * @returns {Promise<void>} Resolves when the cache metadata has been updated.
62
- */
63
- export async function revalidateCachedComponentHtml(componentPath) {
64
- await markComponentHtmlStale({ componentPath });
65
- }
66
-
67
- /**
68
- * Converts a revalidation setting into seconds for ISR purposes.
69
- *
70
- * @param {number|boolean|string} revalidate - Revalidation setting.
71
- * - If a number, it represents the number of seconds before the cache becomes stale.
72
- * - If `true`, defaults to 60 seconds.
73
- * - If `0`, cache is always stale.
74
- * - If `false` or `"never"`, cache never becomes stale.
75
- * @returns {number} Number of seconds for revalidation, or -1 for no revalidation.
76
- */
77
- export function getRevalidateSeconds(revalidate) {
78
- if (typeof revalidate === "number") {
79
- return revalidate;
80
- } if (typeof revalidate === "string" && !Number.isNaN(Number(revalidate))) {
81
- return Number(revalidate);
82
- }else if (revalidate === true) {
83
- return 60; // default to 60 seconds
84
- } else if (revalidate === 'never' || revalidate === false) {
85
- return -1; // never revalidate
86
- } else {
87
- return 0; // always revalidate
88
- }
89
- }