@teamvelix/velix 5.1.7 → 5.2.1

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 (40) hide show
  1. package/dist/build/index.js +3 -2
  2. package/dist/chunk-4S5YQJHB.js +11 -0
  3. package/dist/chunk-4S5YQJHB.js.map +1 -0
  4. package/dist/{chunk-CFDPNOWM.js → chunk-DTF3KTLR.js} +82 -31
  5. package/dist/chunk-DTF3KTLR.js.map +1 -0
  6. package/dist/{chunk-OIZNYND3.js → chunk-JI2HJFUT.js} +2 -2
  7. package/dist/chunk-JI2HJFUT.js.map +1 -0
  8. package/dist/{chunk-X2EZAAQS.js → chunk-QIPVMOXL.js} +4 -4
  9. package/dist/chunk-QIPVMOXL.js.map +1 -0
  10. package/dist/{chunk-INOZP2VD.js → chunk-QLFG6PW3.js} +3 -2
  11. package/dist/chunk-QLFG6PW3.js.map +1 -0
  12. package/dist/{chunk-SB5DCDTH.js → chunk-XXPHGRLC.js} +3 -3
  13. package/dist/{chunk-SB5DCDTH.js.map → chunk-XXPHGRLC.js.map} +1 -1
  14. package/dist/client/index.d.ts +2 -1
  15. package/dist/client/index.js +2 -1
  16. package/dist/config.js +1 -0
  17. package/dist/{image-optimizer-I6TWWH6W.js → image-optimizer-KPRXE5VI.js} +3 -3
  18. package/dist/image-optimizer-KPRXE5VI.js.map +1 -0
  19. package/dist/index-8CqitL9K.d.ts +300 -0
  20. package/dist/{index-C4udNtpZ.d.ts → index-ChyKLf1W.d.ts} +18 -3
  21. package/dist/index.d.ts +53 -176
  22. package/dist/index.js +12 -6
  23. package/dist/index.js.map +1 -1
  24. package/dist/islands/index.d.ts +22 -10
  25. package/dist/islands/index.js +2 -1
  26. package/dist/runtime/start-build.js +2 -2
  27. package/dist/runtime/start-build.js.map +1 -1
  28. package/dist/runtime/start-dev.js +81 -22
  29. package/dist/runtime/start-dev.js.map +1 -1
  30. package/dist/runtime/start-prod.js +81 -22
  31. package/dist/runtime/start-prod.js.map +1 -1
  32. package/dist/server/index.d.ts +3 -1
  33. package/dist/server/index.js +4 -3
  34. package/package.json +60 -58
  35. package/dist/chunk-CFDPNOWM.js.map +0 -1
  36. package/dist/chunk-INOZP2VD.js.map +0 -1
  37. package/dist/chunk-OIZNYND3.js.map +0 -1
  38. package/dist/chunk-X2EZAAQS.js.map +0 -1
  39. package/dist/image-optimizer-I6TWWH6W.js.map +0 -1
  40. package/dist/index-DYgxL3mE.d.ts +0 -107
@@ -11,9 +11,13 @@ var __export = (target, all) => {
11
11
  // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postc_36112cdf9ab6125b194fc7941daee874/node_modules/tsup/assets/esm_shims.js
12
12
  import path from "path";
13
13
  import { fileURLToPath } from "url";
14
+ var getFilename, getDirname, __dirname;
14
15
  var init_esm_shims = __esm({
15
16
  "../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postc_36112cdf9ab6125b194fc7941daee874/node_modules/tsup/assets/esm_shims.js"() {
16
17
  "use strict";
18
+ getFilename = () => fileURLToPath(import.meta.url);
19
+ getDirname = () => path.dirname(getFilename());
20
+ __dirname = /* @__PURE__ */ getDirname();
17
21
  }
18
22
  });
19
23
 
@@ -273,7 +277,7 @@ function buildRouteTree(appDir) {
273
277
  pages: [],
274
278
  api: [],
275
279
  layouts: /* @__PURE__ */ new Map(),
276
- tree: {},
280
+ tree: { children: {}, routes: [] },
277
281
  appRoutes: []
278
282
  };
279
283
  if (fs3.existsSync(appDir)) {
@@ -468,7 +472,8 @@ async function loadMiddleware(projectRoot) {
468
472
  break;
469
473
  }
470
474
  } catch (err) {
471
- console.warn(`\u26A0 Failed to load proxy ${file}: ${err.message}`);
475
+ const error = err;
476
+ console.warn(`\u26A0 Failed to load proxy ${file}: ${error.message}`);
472
477
  }
473
478
  }
474
479
  return fns;
@@ -645,11 +650,12 @@ async function loadPlugins(projectRoot, config) {
645
650
  console.warn(`\u26A0 Plugin not found: ${entry}`);
646
651
  }
647
652
  }
648
- } else if (typeof entry === "object" && entry.name) {
653
+ } else if (typeof entry === "object" && entry !== null && "name" in entry) {
649
654
  pluginManager.register(entry);
650
655
  }
651
656
  } catch (err) {
652
- console.warn(`\u26A0 Failed to load plugin: ${err.message}`);
657
+ const error = err;
658
+ console.warn(`\u26A0 Failed to load plugin: ${error?.message || String(error)}`);
653
659
  }
654
660
  }
655
661
  }
@@ -664,10 +670,11 @@ var builtinPlugins = {
664
670
  name: "velix:security",
665
671
  hooks: {
666
672
  [PluginHooks.RESPONSE]: (_req, res) => {
667
- if (!res.headersSent) {
668
- res.setHeader("X-Content-Type-Options", "nosniff");
669
- res.setHeader("X-Frame-Options", "DENY");
670
- res.setHeader("X-XSS-Protection", "1; mode=block");
673
+ const response = res;
674
+ if (!response.headersSent) {
675
+ response.setHeader("X-Content-Type-Options", "nosniff");
676
+ response.setHeader("X-Frame-Options", "DENY");
677
+ response.setHeader("X-XSS-Protection", "1; mode=block");
671
678
  }
672
679
  }
673
680
  }
@@ -679,7 +686,8 @@ var builtinPlugins = {
679
686
  name: "velix:logger",
680
687
  hooks: {
681
688
  [PluginHooks.RESPONSE]: (req, _res, duration) => {
682
- console.log(` ${req.method} ${req.url} ${duration}ms`);
689
+ const request = req;
690
+ console.log(` ${request.method} ${request.url} ${duration}ms`);
683
691
  }
684
692
  }
685
693
  })
@@ -693,7 +701,7 @@ init_esm_shims();
693
701
 
694
702
  // version.ts
695
703
  init_esm_shims();
696
- var VERSION = "5.1.6";
704
+ var VERSION = "5.1.7";
697
705
 
698
706
  // logger.ts
699
707
  var colors = {
@@ -1222,7 +1230,8 @@ async function executeAction(actionId, args, context) {
1222
1230
  try {
1223
1231
  const result = await action(...args);
1224
1232
  return { success: true, data: result };
1225
- } catch (error) {
1233
+ } catch (err) {
1234
+ const error = err;
1226
1235
  if (error instanceof RedirectError) return { success: true, redirect: error.url };
1227
1236
  if (error instanceof NotFoundError) return { success: false, error: "Not found" };
1228
1237
  return { success: false, error: error.message || "Action failed" };
@@ -2118,6 +2127,14 @@ function generate500Page(options) {
2118
2127
  }
2119
2128
 
2120
2129
  // server/index.ts
2130
+ import {
2131
+ defineRoute,
2132
+ VelixHttpError,
2133
+ defineLoader,
2134
+ serverAction,
2135
+ buildApiManifest,
2136
+ handleApiRequest
2137
+ } from "@teamvelix/velix-core";
2121
2138
  function getProjectVersion(dep, projectRoot) {
2122
2139
  try {
2123
2140
  const projectRequire = createRequire(pathToFileURL3(path7.join(projectRoot, "package.json")).href);
@@ -2228,14 +2245,15 @@ async function createServer(options = {}) {
2228
2245
  res.end(generate404Page(pathname));
2229
2246
  if (isDev) logger_default.request(req.method || "GET", pathname, 404, Date.now() - requestStart);
2230
2247
  } catch (error) {
2248
+ const err = error;
2231
2249
  console.error("Server error:", error);
2232
2250
  if (!res.headersSent) {
2233
2251
  res.writeHead(500, { "Content-Type": "text/html; charset=utf-8" });
2234
2252
  res.end(generate500Page({
2235
2253
  statusCode: 500,
2236
2254
  title: "Server Error",
2237
- message: error.message || "An unexpected error occurred",
2238
- stack: isDev ? error.stack : void 0,
2255
+ message: err.message || "An unexpected error occurred",
2256
+ stack: isDev ? err.stack : void 0,
2239
2257
  isDev,
2240
2258
  pathname
2241
2259
  }));
@@ -2392,8 +2410,9 @@ async function handleApiRoute(route, req, res, url) {
2392
2410
  res.end(String(response));
2393
2411
  }
2394
2412
  } catch (err) {
2413
+ const error = err;
2395
2414
  res.writeHead(500, { "Content-Type": "application/json" });
2396
- res.end(JSON.stringify({ error: err.message }));
2415
+ res.end(JSON.stringify({ error: error.message }));
2397
2416
  }
2398
2417
  }
2399
2418
  async function handleServerAction(req, res) {
@@ -2409,8 +2428,9 @@ async function handleServerAction(req, res) {
2409
2428
  res.writeHead(200, { "Content-Type": "application/json" });
2410
2429
  res.end(JSON.stringify(result));
2411
2430
  } catch (err) {
2431
+ const error = err;
2412
2432
  res.writeHead(500, { "Content-Type": "application/json" });
2413
- res.end(JSON.stringify({ success: false, error: err.message }));
2433
+ res.end(JSON.stringify({ success: false, error: error.message }));
2414
2434
  }
2415
2435
  }
2416
2436
  async function handlePageRoute(route, routes, req, res, url, config, isDev, projectRoot) {
@@ -2475,9 +2495,14 @@ async function handlePageRoute(route, routes, req, res, url, config, isDev, proj
2475
2495
  const headInjectionsHtml = `
2476
2496
  ${headInjections}
2477
2497
  `;
2498
+ const hmrScript = isDev ? `
2499
+ <script type="module">
2500
+ import { initHMRClient, VelixDevOverlay } from '/__velix/hmr-client.js';
2501
+ initHMRClient();
2502
+ </script>` : "";
2478
2503
  const bodyInjectionsHtml = `
2479
2504
  <div id="__velix-islands"></div>
2480
- ${hydrationScript}${devToolsHtml}
2505
+ ${hydrationScript}${devToolsHtml}${hmrScript}
2481
2506
  `;
2482
2507
  if (finalHtml.includes("<html")) {
2483
2508
  const headEnd = finalHtml.lastIndexOf("</head>");
@@ -2513,13 +2538,14 @@ async function handlePageRoute(route, routes, req, res, url, config, isDev, proj
2513
2538
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
2514
2539
  res.end(finalHtml);
2515
2540
  } catch (err) {
2516
- logger_default.error(`Render error: ${route.path}`, err);
2541
+ const error = err;
2542
+ logger_default.error(`Render error: ${route.path}`, error);
2517
2543
  res.writeHead(500, { "Content-Type": "text/html; charset=utf-8" });
2518
2544
  res.end(generate500Page({
2519
2545
  statusCode: 500,
2520
2546
  title: "Render Error",
2521
- message: err.message || "Failed to render page",
2522
- stack: isDev ? err.stack : void 0,
2547
+ message: error.message || "Failed to render page",
2548
+ stack: isDev ? error.stack : void 0,
2523
2549
  isDev,
2524
2550
  pathname: route.path
2525
2551
  }));
@@ -2562,6 +2588,38 @@ async function serveVelixInternal(pathname, req, res, projectRoot) {
2562
2588
  }
2563
2589
  return;
2564
2590
  }
2591
+ if (pathname === "/__velix/hmr-client.js") {
2592
+ try {
2593
+ const candidates = [
2594
+ path7.join(process.cwd(), "packages", "velix-react", "src", "hmr", "hmr-client.ts"),
2595
+ path7.join(process.cwd(), "node_modules", "@teamvelix", "velix-react", "src", "hmr", "hmr-client.ts"),
2596
+ path7.join(__dirname, "..", "..", "velix-react", "src", "hmr", "hmr-client.ts")
2597
+ ];
2598
+ const hmrClientSrc = candidates.find((p) => fs7.existsSync(p));
2599
+ if (!hmrClientSrc) {
2600
+ res.writeHead(404);
2601
+ res.end();
2602
+ return;
2603
+ }
2604
+ const result = await esbuild.build({
2605
+ entryPoints: [hmrClientSrc],
2606
+ bundle: true,
2607
+ format: "esm",
2608
+ platform: "browser",
2609
+ target: ["es2022"],
2610
+ minify: true,
2611
+ write: false
2612
+ });
2613
+ res.writeHead(200, { "Content-Type": "application/javascript", "Cache-Control": "no-cache" });
2614
+ res.end(result.outputFiles[0].text);
2615
+ return;
2616
+ } catch (err) {
2617
+ console.error("HMR Client build failed", err);
2618
+ res.writeHead(500);
2619
+ res.end();
2620
+ return;
2621
+ }
2622
+ }
2565
2623
  if (pathname.startsWith("/__velix/islands/") && pathname.endsWith(".js")) {
2566
2624
  const componentName = pathname.replace("/__velix/islands/", "").replace(".js", "");
2567
2625
  try {
@@ -2602,9 +2660,10 @@ async function serveVelixInternal(pathname, req, res, projectRoot) {
2602
2660
  res.end(result.outputFiles[0].text);
2603
2661
  return;
2604
2662
  } catch (err) {
2605
- logger_default.error(`Island bundling failed: ${componentName}`, err);
2663
+ const error = err;
2664
+ logger_default.error(`Island bundling failed: ${componentName}`, error);
2606
2665
  res.writeHead(500);
2607
- res.end(`console.error("Island bundling failed: ${err.message}");`);
2666
+ res.end(`console.error("Island bundling failed: ${error.message}");`);
2608
2667
  return;
2609
2668
  }
2610
2669
  }
@@ -2629,7 +2688,7 @@ async function serveVelixInternal(pathname, req, res, projectRoot) {
2629
2688
  return;
2630
2689
  }
2631
2690
  }
2632
- res.writeHead(404);
2691
+ res.writeHead(404, { "Content-Type": "text/plain" });
2633
2692
  res.end("Not found");
2634
2693
  }
2635
2694
  function parseRequestBody(req) {