heliumts 0.9.5 → 0.9.7

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 (110) hide show
  1. package/README.md +7 -3
  2. package/dist/bin/helium.js +61 -53
  3. package/dist/bin/helium.js.map +1 -1
  4. package/dist/client/Router.d.ts +2 -2
  5. package/dist/client/Router.d.ts.map +1 -1
  6. package/dist/client/Router.js +32 -29
  7. package/dist/client/Router.js.map +1 -1
  8. package/dist/client/cache.d.ts.map +1 -1
  9. package/dist/client/cache.js +13 -13
  10. package/dist/client/cache.js.map +1 -1
  11. package/dist/client/callMethod.d.ts +13 -0
  12. package/dist/client/callMethod.d.ts.map +1 -0
  13. package/dist/client/callMethod.js +10 -0
  14. package/dist/client/callMethod.js.map +1 -0
  15. package/dist/client/env.js.map +1 -1
  16. package/dist/client/index.d.ts +2 -1
  17. package/dist/client/index.d.ts.map +1 -1
  18. package/dist/client/index.js +1 -0
  19. package/dist/client/index.js.map +1 -1
  20. package/dist/client/routerManifest.d.ts.map +1 -1
  21. package/dist/client/routerManifest.js +18 -29
  22. package/dist/client/routerManifest.js.map +1 -1
  23. package/dist/client/rpcClient.d.ts +7 -3
  24. package/dist/client/rpcClient.d.ts.map +1 -1
  25. package/dist/client/rpcClient.js +80 -78
  26. package/dist/client/rpcClient.js.map +1 -1
  27. package/dist/client/transitions.d.ts +1 -1
  28. package/dist/client/transitions.d.ts.map +1 -1
  29. package/dist/client/useCall.d.ts.map +1 -1
  30. package/dist/client/useCall.js +4 -1
  31. package/dist/client/useCall.js.map +1 -1
  32. package/dist/client/useFetch.d.ts.map +1 -1
  33. package/dist/client/useFetch.js +48 -92
  34. package/dist/client/useFetch.js.map +1 -1
  35. package/dist/runtime/routeOrder.d.ts +3 -0
  36. package/dist/runtime/routeOrder.d.ts.map +1 -0
  37. package/dist/runtime/routeOrder.js +15 -0
  38. package/dist/runtime/routeOrder.js.map +1 -0
  39. package/dist/server/config.d.ts.map +1 -1
  40. package/dist/server/config.js +51 -26
  41. package/dist/server/config.js.map +1 -1
  42. package/dist/server/defineHTTPRequest.d.ts +1 -1
  43. package/dist/server/defineHTTPRequest.d.ts.map +1 -1
  44. package/dist/server/defineHTTPRequest.js.map +1 -1
  45. package/dist/server/defineWorker.d.ts.map +1 -1
  46. package/dist/server/defineWorker.js +68 -37
  47. package/dist/server/defineWorker.js.map +1 -1
  48. package/dist/server/devServer.d.ts.map +1 -1
  49. package/dist/server/devServer.js +70 -40
  50. package/dist/server/devServer.js.map +1 -1
  51. package/dist/server/httpCompression.d.ts +8 -0
  52. package/dist/server/httpCompression.d.ts.map +1 -0
  53. package/dist/server/httpCompression.js +58 -0
  54. package/dist/server/httpCompression.js.map +1 -0
  55. package/dist/server/httpRouter.d.ts.map +1 -1
  56. package/dist/server/httpRouter.js +138 -43
  57. package/dist/server/httpRouter.js.map +1 -1
  58. package/dist/server/meta.d.ts.map +1 -1
  59. package/dist/server/meta.js +23 -15
  60. package/dist/server/meta.js.map +1 -1
  61. package/dist/server/prodServer.d.ts.map +1 -1
  62. package/dist/server/prodServer.js +87 -46
  63. package/dist/server/prodServer.js.map +1 -1
  64. package/dist/server/rateLimiter.d.ts +9 -0
  65. package/dist/server/rateLimiter.d.ts.map +1 -1
  66. package/dist/server/rateLimiter.js +46 -0
  67. package/dist/server/rateLimiter.js.map +1 -1
  68. package/dist/server/requestHandler.d.ts +4 -0
  69. package/dist/server/requestHandler.d.ts.map +1 -0
  70. package/dist/server/requestHandler.js +20 -0
  71. package/dist/server/requestHandler.js.map +1 -0
  72. package/dist/server/rpcRegistry.d.ts +4 -0
  73. package/dist/server/rpcRegistry.d.ts.map +1 -1
  74. package/dist/server/rpcRegistry.js +60 -15
  75. package/dist/server/rpcRegistry.js.map +1 -1
  76. package/dist/server/security.d.ts.map +1 -1
  77. package/dist/server/security.js +3 -2
  78. package/dist/server/security.js.map +1 -1
  79. package/dist/server/serializer.js +17 -6
  80. package/dist/server/serializer.js.map +1 -1
  81. package/dist/server/ssr.d.ts +2 -1
  82. package/dist/server/ssr.d.ts.map +1 -1
  83. package/dist/server/ssr.js +29 -32
  84. package/dist/server/ssr.js.map +1 -1
  85. package/dist/utils/envLoader.js +1 -1
  86. package/dist/utils/envLoader.js.map +1 -1
  87. package/dist/utils/html.d.ts +7 -0
  88. package/dist/utils/html.d.ts.map +1 -0
  89. package/dist/utils/html.js +197 -0
  90. package/dist/utils/html.js.map +1 -0
  91. package/dist/utils/ipExtractor.d.ts +6 -52
  92. package/dist/utils/ipExtractor.d.ts.map +1 -1
  93. package/dist/utils/ipExtractor.js +21 -118
  94. package/dist/utils/ipExtractor.js.map +1 -1
  95. package/dist/vite/heliumPlugin.d.ts.map +1 -1
  96. package/dist/vite/heliumPlugin.js +75 -83
  97. package/dist/vite/heliumPlugin.js.map +1 -1
  98. package/dist/vite/scanner.d.ts +3 -0
  99. package/dist/vite/scanner.d.ts.map +1 -1
  100. package/dist/vite/scanner.js +89 -18
  101. package/dist/vite/scanner.js.map +1 -1
  102. package/dist/vite/ssg.d.ts +4 -0
  103. package/dist/vite/ssg.d.ts.map +1 -1
  104. package/dist/vite/ssg.js +66 -39
  105. package/dist/vite/ssg.js.map +1 -1
  106. package/dist/vite/virtualServerModule.d.ts +1 -1
  107. package/dist/vite/virtualServerModule.d.ts.map +1 -1
  108. package/dist/vite/virtualServerModule.js +28 -16
  109. package/dist/vite/virtualServerModule.js.map +1 -1
  110. package/package.json +12 -7
@@ -1 +1 @@
1
- {"version":3,"file":"ipExtractor.js","sourceRoot":"","sources":["../../src/utils/ipExtractor.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,eAAe,CAAC,GAAyB,EAAE,kBAA0B,CAAC;IAClF,+DAA+D;IAC/D,IAAI,eAAe,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,SAAS,CAAC;IACjD,C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tE,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED,kDAAkD;IAClD,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpD,IAAI,YAAY,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;aACrF,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;aACtB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAEnC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,0EAA0E;YAC1E,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,MAAM,GAAG,eAAe,GAAG,CAAC,CAAC,CAAC;YAC7E,OAAO,YAAY,CAAC,aAAa,CAAC,CAAC;QACvC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,SAAS,CAAC;AACjD,CAAC","sourcesContent":["import type http from \"http\";\n\n/**\n * Extracts the client IP address from an HTTP request, checking multiple headers\n * and taking into account proxy configurations.\n *\n * Checks headers in order of reliability:\n * 1. CF-Connecting-IP (Cloudflare)\n * 2. True-Client-IP (Cloudflare Enterprise, Akamai)\n * 3. X-Real-IP (Nginx, other proxies)\n * 4. X-Forwarded-For (Standard, but can be spoofed)\n * 5. req.socket.remoteAddress (Direct connection)\n *\n * When behind proxies, the X-Forwarded-For header contains a chain of IP addresses.\n * Format: \"client, proxy1, proxy2, ...\"\n *\n * @param req - The HTTP request object\n * @param trustProxyDepth - Number of proxy levels to trust\n * - 0: Only use req.socket.remoteAddress (no proxy trust)\n * - 1: Trust 1 proxy level (recommended for Vercel, Netlify, Railway)\n * - 2+: Trust multiple proxy levels (for complex setups)\n *\n * Examples:\n * - trustProxyDepth=0: Direct connection, no proxies\n * All proxy headers ignored\n * Result: req.socket.remoteAddress\n *\n * - trustProxyDepth=1: Behind one proxy (e.g., Vercel, Netlify)\n * X-Forwarded-For: \"203.0.113.1, 198.51.100.1\"\n * Result: \"203.0.113.1\" (client IP)\n *\n * - trustProxyDepth=2: Behind two proxies (e.g., Cloudflare -> Load Balancer)\n * X-Forwarded-For: \"203.0.113.1, 198.51.100.1, 192.0.2.1\"\n * Result: \"203.0.113.1\" (client IP)\n *\n * Common configurations:\n * - Vercel/Netlify/Railway: trustProxyDepth=1\n * - Cloudflare -> Origin: trustProxyDepth=1 (use CF-Connecting-IP)\n * - AWS ALB -> EC2: trustProxyDepth=1\n * - Nginx -> Node: trustProxyDepth=1 (use X-Real-IP)\n * - Cloudflare -> Nginx -> Node: trustProxyDepth=2\n */\nexport function extractClientIP(req: http.IncomingMessage, trustProxyDepth: number = 0): string {\n // If not trusting any proxies, return the direct connection IP\n if (trustProxyDepth === 0) {\n return req.socket.remoteAddress || \"unknown\";\n }\n\n // Security: When trustProxyDepth >= 1, extract IP using X-Forwarded-For first.\n // Single-value headers (CF-Connecting-IP, True-Client-IP, X-Real-IP) are only\n // checked as a fallback since they can be spoofed by direct clients when no\n // trusted proxy IP allowlist is configured.\n\n // 1. Check X-Forwarded-For (Standard, most reliable with depth-based extraction)\n const forwardedFor = req.headers[\"x-forwarded-for\"];\n if (forwardedFor) {\n const forwardedIPs = (Array.isArray(forwardedFor) ? forwardedFor.join(\",\") : forwardedFor)\n .split(\",\")\n .map((ip) => ip.trim())\n .filter((ip) => ip.length > 0);\n\n if (forwardedIPs.length > 0) {\n // Verify we have enough IPs in the chain for the trust depth\n if (forwardedIPs.length >= trustProxyDepth) {\n // Return the client IP (first in the chain)\n return forwardedIPs[0];\n }\n }\n }\n\n // 2. Fallback: Check CF-Connecting-IP (Cloudflare)\n const cfConnectingIP = req.headers[\"cf-connecting-ip\"];\n if (cfConnectingIP && typeof cfConnectingIP === \"string\" && cfConnectingIP.trim().length > 0) {\n return cfConnectingIP.trim();\n }\n\n // 3. Fallback: Check True-Client-IP (Cloudflare Enterprise, Akamai)\n const trueClientIP = req.headers[\"true-client-ip\"];\n if (trueClientIP && typeof trueClientIP === \"string\" && trueClientIP.trim().length > 0) {\n return trueClientIP.trim();\n }\n\n // 4. Fallback: Check X-Real-IP (Nginx, other proxies)\n const xRealIP = req.headers[\"x-real-ip\"];\n if (xRealIP && typeof xRealIP === \"string\" && xRealIP.trim().length > 0) {\n return xRealIP.trim();\n }\n\n // 5. Fall back to direct connection\n return req.socket.remoteAddress || \"unknown\";\n}\n\n/**\n * Alternative extraction method that works from the right (trusts the rightmost IPs).\n * This is useful when you want to trust the last N proxies in the chain.\n *\n * Note: This only applies to X-Forwarded-For parsing. Single-value headers like\n * CF-Connecting-IP are still checked first.\n *\n * @param req - The HTTP request object\n * @param trustProxyDepth - Number of proxy levels to trust from the right\n *\n * Example:\n * X-Forwarded-For: \"203.0.113.1, 198.51.100.1, 192.0.2.1\"\n * trustProxyDepth=1: Result is \"198.51.100.1\" (skip the last trusted proxy)\n * trustProxyDepth=2: Result is \"203.0.113.1\" (skip the last 2 trusted proxies)\n */\nexport function extractClientIPFromRight(req: http.IncomingMessage, trustProxyDepth: number = 0): string {\n if (trustProxyDepth === 0) {\n return req.socket.remoteAddress || \"unknown\";\n }\n\n // Check single-value headers first (same as extractClientIP)\n const cfConnectingIP = req.headers[\"cf-connecting-ip\"];\n if (cfConnectingIP && typeof cfConnectingIP === \"string\" && cfConnectingIP.trim().length > 0) {\n return cfConnectingIP.trim();\n }\n\n const trueClientIP = req.headers[\"true-client-ip\"];\n if (trueClientIP && typeof trueClientIP === \"string\" && trueClientIP.trim().length > 0) {\n return trueClientIP.trim();\n }\n\n const xRealIP = req.headers[\"x-real-ip\"];\n if (xRealIP && typeof xRealIP === \"string\" && xRealIP.trim().length > 0) {\n return xRealIP.trim();\n }\n\n // For X-Forwarded-For, use right-based extraction\n const forwardedFor = req.headers[\"x-forwarded-for\"];\n if (forwardedFor) {\n const forwardedIPs = (Array.isArray(forwardedFor) ? forwardedFor.join(\",\") : forwardedFor)\n .split(\",\")\n .map((ip) => ip.trim())\n .filter((ip) => ip.length > 0);\n\n if (forwardedIPs.length > 0) {\n // Calculate which IP to trust by skipping the rightmost N trusted proxies\n const clientIPIndex = Math.max(0, forwardedIPs.length - trustProxyDepth - 1);\n return forwardedIPs[clientIPIndex];\n }\n }\n\n return req.socket.remoteAddress || \"unknown\";\n}\n"]}
1
+ {"version":3,"file":"ipExtractor.js","sourceRoot":"","sources":["../../src/utils/ipExtractor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,GAAyB,EAAE,kBAA0B,CAAC;IAClF,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,aAAa,IAAI,SAAS,CAAC;IACxD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,eAAe,IAAI,CAAC,EAAE,CAAC;QAC7D,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7H,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,eAAe,CAAC,CAAC;QACrE,OAAO,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC5D,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,CAAC,kBAAkB,EAAE,gBAAgB,EAAE,WAAW,CAAC,EAAE,CAAC;QACrE,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YAClD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;QACxB,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,wBAAwB,CAAC,GAAyB,EAAE,kBAA0B,CAAC;IAC3F,OAAO,eAAe,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import type http from \"http\";\nimport { isIP } from \"net\";\n\n/**\n * Extract the client IP by trusting exactly `trustProxyDepth` hops, including\n * the direct peer. For one trusted proxy, use the rightmost X-Forwarded-For\n * entry; for two, use the next entry to its left. Untrusted prefixes are ignored.\n *\n * With no forwarded chain, provider-specific headers are accepted only when\n * proxy trust is enabled. The trusted proxy must overwrite those headers.\n */\nexport function extractClientIP(req: http.IncomingMessage, trustProxyDepth: number = 0): string {\n const directIP = req.socket?.remoteAddress || \"unknown\";\n if (!Number.isInteger(trustProxyDepth) || trustProxyDepth <= 0) {\n return directIP;\n }\n\n const forwardedFor = req.headers[\"x-forwarded-for\"];\n if (forwardedFor !== undefined) {\n const forwardedIPs = (Array.isArray(forwardedFor) ? forwardedFor.join(\",\") : forwardedFor).split(\",\").map((ip) => ip.trim());\n const clientIP = forwardedIPs[forwardedIPs.length - trustProxyDepth];\n return clientIP && isIP(clientIP) ? clientIP : directIP;\n }\n\n for (const name of [\"cf-connecting-ip\", \"true-client-ip\", \"x-real-ip\"]) {\n const value = req.headers[name];\n if (typeof value === \"string\" && isIP(value.trim())) {\n return value.trim();\n }\n }\n return directIP;\n}\n\n/** Uses the same depth-based extraction as extractClientIP. */\nexport function extractClientIPFromRight(req: http.IncomingMessage, trustProxyDepth: number = 0): string {\n return extractClientIP(req, trustProxyDepth);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"heliumPlugin.d.ts","sourceRoot":"","sources":["../../src/vite/heliumPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAkBnC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,MAAM,CA+cvC;AA2HD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAiBrG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAUhD"}
1
+ {"version":3,"file":"heliumPlugin.d.ts","sourceRoot":"","sources":["../../src/vite/heliumPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAkBnC,MAAM,CAAC,OAAO,UAAU,MAAM,IAAI,MAAM,CAwbvC;AAsID;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAiBrG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAUhD"}
@@ -1,6 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { clearConfigCache, getRpcClientConfig, loadConfig } from "../server/config.js";
3
+ import { clearConfigCache, getRpcClientConfig, getRpcConfig, loadConfig } from "../server/config.js";
4
4
  import { attachToDevServer } from "../server/devServer.js";
5
5
  import { injectEnvToProcess, loadEnvFiles } from "../utils/envLoader.js";
6
6
  import { log } from "../utils/logger.js";
@@ -10,6 +10,7 @@ import { generateClientModule, generateEntryModule, generateServerManifest, gene
10
10
  export default function helium() {
11
11
  let root = process.cwd();
12
12
  const serverDir = normalizeToPosix(SERVER_DIR);
13
+ const RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID = "\0heliumts:ssr-server";
13
14
  const RESOLVED_VIRTUAL_SSR_CLIENT_MODULE_ID = "\0heliumts:ssr-client";
14
15
  const RESOLVED_VIRTUAL_SSR_TRANSITIONS_MODULE_ID = "\0heliumts:ssr-transitions";
15
16
  const RESOLVED_VIRTUAL_SSR_PREFETCH_MODULE_ID = "\0heliumts:ssr-prefetch";
@@ -23,13 +24,13 @@ export default function helium() {
23
24
  order: "pre",
24
25
  handler(html, _ctx) {
25
26
  // Check if HTML already has a script tag for entry
26
- if (html.includes("src/main.tsx") || html.includes("src/main.ts")) {
27
+ if (/<script\b[^>]*\bsrc\s*=\s*["'][^"']*src\/main\.[jt]sx?(?:[?#][^"']*)?["']/i.test(html)) {
27
28
  return html; // User has their own entry, don't modify
28
29
  }
29
30
  // Ensure root div exists
30
31
  let modifiedHtml = html;
31
- if (!modifiedHtml.includes('id="root"')) {
32
- modifiedHtml = modifiedHtml.replace("<body>", '<body>\n <div id="root"></div>');
32
+ if (!/<[a-z][^>]*\sid\s*=\s*["']root["']/i.test(modifiedHtml)) {
33
+ modifiedHtml = modifiedHtml.replace(/<body\b[^>]*>/i, (body) => `${body}\n <div id="root"></div>`);
33
34
  }
34
35
  // Generate physical entry file
35
36
  const heliumDir = path.join(root, "node_modules", ".heliumts");
@@ -37,23 +38,27 @@ export default function helium() {
37
38
  fs.mkdirSync(heliumDir, { recursive: true });
38
39
  }
39
40
  const entryPath = path.join(heliumDir, "entry.tsx");
40
- fs.writeFileSync(entryPath, generateEntryModule());
41
+ fs.writeFileSync(entryPath, generateEntryModule(scanAppShell(root)));
41
42
  // Return with tags to inject the entry (runtime config is fetched by the client)
42
- return [
43
- {
44
- tag: "script",
45
- attrs: {
46
- type: "module",
47
- src: "/node_modules/.heliumts/entry.tsx",
43
+ return {
44
+ html: modifiedHtml,
45
+ tags: [
46
+ {
47
+ tag: "script",
48
+ attrs: {
49
+ type: "module",
50
+ src: "/node_modules/.heliumts/entry.tsx",
51
+ },
52
+ injectTo: "body",
48
53
  },
49
- injectTo: "body",
50
- },
51
- ];
54
+ ],
55
+ };
52
56
  },
53
57
  },
54
- async config(config) {
55
- // Load environment variables before config is finalized
56
- const mode = config.mode || "development";
58
+ async config(config, env) {
59
+ // configResolved runs after this hook; honor an explicit Vite root now.
60
+ root = path.resolve(config.root || process.cwd());
61
+ const mode = env.mode;
57
62
  const envVars = loadEnvFiles({ root, mode });
58
63
  // Inject env vars into process.env so server-side code can access them
59
64
  // consistently in both development and production.
@@ -63,7 +68,7 @@ export default function helium() {
63
68
  const rpcClientConfig = getRpcClientConfig(heliumConfig);
64
69
  // Provide default index.html if none exists
65
70
  return {
66
- appType: "spa",
71
+ appType: config.appType ?? "spa",
67
72
  optimizeDeps: {
68
73
  include: ["react-dom/client"],
69
74
  // Exclude helium from pre-bundling since it's the framework itself
@@ -102,10 +107,11 @@ export default function helium() {
102
107
  },
103
108
  },
104
109
  define: {
105
- __HELIUM_DEV__: JSON.stringify(mode !== "production"),
110
+ __HELIUM_DEV__: JSON.stringify(env.command === "serve"),
106
111
  __HELIUM_RPC_TRANSPORT__: JSON.stringify(rpcClientConfig.transport),
107
112
  __HELIUM_RPC_AUTO_HTTP_ON_MOBILE__: JSON.stringify(rpcClientConfig.autoHttpOnMobile),
108
113
  __HELIUM_RPC_TOKEN_VALIDITY_MS__: JSON.stringify(rpcClientConfig.tokenValidityMs),
114
+ __HELIUM_RPC_MAX_BATCH_SIZE__: JSON.stringify(getRpcConfig(heliumConfig).maxBatchSize),
109
115
  },
110
116
  };
111
117
  },
@@ -120,10 +126,10 @@ export default function helium() {
120
126
  return RESOLVED_VIRTUAL_SSR_PREFETCH_MODULE_ID;
121
127
  }
122
128
  if (id === VIRTUAL_CLIENT_MODULE_ID) {
123
- if (isServerModule(importer, root, serverDir)) {
129
+ if (importer === RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID || isServerModule(importer, root, serverDir) || /\.server\.[cm]?[jt]sx?(?:\?|$)/.test(importer || "")) {
124
130
  return null;
125
131
  }
126
- return RESOLVED_VIRTUAL_CLIENT_MODULE_ID;
132
+ return options?.ssr ? RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID : RESOLVED_VIRTUAL_CLIENT_MODULE_ID;
127
133
  }
128
134
  if (id === VIRTUAL_SERVER_MANIFEST_ID) {
129
135
  return RESOLVED_VIRTUAL_SERVER_MANIFEST_ID;
@@ -132,25 +138,23 @@ export default function helium() {
132
138
  // Add .tsx extension so Vite knows it contains JSX
133
139
  return RESOLVED_VIRTUAL_ENTRY_MODULE_ID + ".tsx";
134
140
  }
135
- // Intercept heliumts/server imports from client code
136
- if (id === "heliumts/server") {
137
- // If imported from server code, let it resolve normally
138
- if (isServerModule(importer, root, serverDir)) {
139
- return null;
140
- }
141
- // For client code, redirect to virtual client module
142
- return RESOLVED_VIRTUAL_CLIENT_MODULE_ID;
143
- }
144
141
  return null;
145
142
  },
146
143
  transform(code, id, options) {
144
+ if (!options?.ssr && isServerModule(id, root, serverDir)) {
145
+ throw new Error(`Server-only module cannot be imported by client code: ${id}. Import RPC method stubs from 'heliumts/server' instead.`);
146
+ }
147
147
  // Prevent .server.ts/.server.js sidecar files from being bundled in client code.
148
148
  // These files contain server-only logic (e.g. DB queries) and must never run in the browser.
149
- if (!options?.ssr && /\.server\.(ts|js|tsx|jsx|mts|mjs)$/.test(id)) {
149
+ if (!options?.ssr && /\.server\.(ts|js|tsx|jsx|mts|mjs)$/.test(id.split("?")[0])) {
150
150
  return { code: "export default null;", map: null };
151
151
  }
152
152
  },
153
153
  load(id) {
154
+ if (id === RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID) {
155
+ const { methods } = scanServerExports(root);
156
+ return `export * from 'heliumts/server';\n${generateClientModule(methods)}`;
157
+ }
154
158
  if (id === RESOLVED_VIRTUAL_SSR_CLIENT_MODULE_ID) {
155
159
  return generateSSRClientStubModule();
156
160
  }
@@ -172,7 +176,7 @@ export default function helium() {
172
176
  return generateServerManifest(methods, httpHandlers, seoMetadata, pageRoutePatterns, ssrPages, appShell, middleware, workers);
173
177
  }
174
178
  if (id === RESOLVED_VIRTUAL_ENTRY_MODULE_ID + ".tsx") {
175
- return generateEntryModule();
179
+ return generateEntryModule(scanAppShell(root));
176
180
  }
177
181
  },
178
182
  buildStart() {
@@ -194,28 +198,7 @@ export default function helium() {
194
198
  checkRouteCollisions(root);
195
199
  },
196
200
  configureServer(server) {
197
- // Add middleware to handle HTML fallback for nested routes
198
- // This ensures that routes like /docs/guides/auth properly serve index.html
199
- // so the client-side router can handle them
200
- server.middlewares.use((req, res, next) => {
201
- const url = req.url || "";
202
- const cleanUrl = url.split("?")[0];
203
- // Skip if:
204
- // - Has file extension (asset request)
205
- // - Is an API/special endpoint
206
- // - Is a dev server endpoint
207
- if (path.extname(cleanUrl) !== "" ||
208
- cleanUrl.startsWith("/api") ||
209
- cleanUrl.startsWith("/webhooks") ||
210
- cleanUrl.startsWith("/@") ||
211
- cleanUrl.startsWith("/__helium__")) {
212
- return next();
213
- }
214
- // For all other routes (including nested paths like /docs/guides/auth),
215
- // rewrite to index.html so Vite serves it and the client-side router handles routing
216
- req.url = "/index.html";
217
- next();
218
- });
201
+ // Vite's SPA fallback runs after static/public assets and preserves request URLs.
219
202
  /**
220
203
  * Write type definitions only if content has changed.
221
204
  * This prevents unnecessary TypeScript recompilation.
@@ -277,12 +260,16 @@ export default function helium() {
277
260
  // Invalidate the virtual modules so they get regenerated
278
261
  const clientModule = server.environments.client?.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CLIENT_MODULE_ID);
279
262
  const serverModule = server.environments.ssr?.moduleGraph.getModuleById(RESOLVED_VIRTUAL_SERVER_MANIFEST_ID);
263
+ const ssrRpcModule = server.environments.ssr?.moduleGraph.getModuleById(RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID);
280
264
  if (clientModule) {
281
265
  server.environments.client?.moduleGraph.invalidateModule(clientModule);
282
266
  }
283
267
  if (serverModule) {
284
268
  server.environments.ssr?.moduleGraph.invalidateModule(serverModule);
285
269
  }
270
+ if (ssrRpcModule) {
271
+ server.environments.ssr?.moduleGraph.invalidateModule(ssrRpcModule);
272
+ }
286
273
  // Reload the server manifest and re-register methods
287
274
  try {
288
275
  // Clear config cache to ensure fresh config is loaded
@@ -320,9 +307,8 @@ export default function helium() {
320
307
  path: "*",
321
308
  });
322
309
  };
323
- // Watch server directory for changes
324
- const serverPath = path.join(root, serverDir);
325
- server.watcher.add(serverPath);
310
+ // Watch server and page directories: new SSR pages and sidecars change the manifest too.
311
+ server.watcher.add([path.join(root, serverDir), path.join(root, "src", "pages")]);
326
312
  // Watch config files for changes
327
313
  const configFiles = ["helium.config.ts", "helium.config.js", "helium.config.mjs"];
328
314
  for (const configFile of configFiles) {
@@ -353,35 +339,30 @@ export default function helium() {
353
339
  handleServerFileChange(shouldAllowFewer);
354
340
  }, DEBOUNCE_DELAY);
355
341
  };
342
+ const affectsManifest = (file) => {
343
+ const normalized = normalizeToPosix(path.relative(root, file));
344
+ return (normalized.startsWith(`${serverDir}/`) || normalized.startsWith("src/pages/") || /^src\/[Aa]pp\.[jt]sx?$/.test(normalized) || configFiles.includes(normalized));
345
+ };
356
346
  server.watcher.on("change", (file) => {
357
- const relative = path.relative(root, file);
358
- const normalized = normalizeToPosix(relative);
359
- // If a server file changed, regenerate everything
360
- if (normalized.startsWith(`${serverDir}/`)) {
361
- debouncedHandleServerFileChange();
362
- }
363
- // If config file changed, reload config and regenerate
364
- if (configFiles.some((cf) => normalized === cf)) {
365
- log("info", `Config file changed: ${normalized}`);
366
- debouncedHandleServerFileChange();
347
+ if (affectsManifest(file)) {
348
+ debouncedHandleServerFileChange(true);
367
349
  }
368
350
  });
369
351
  server.watcher.on("add", (file) => {
370
- const relative = path.relative(root, file);
371
- const normalized = normalizeToPosix(relative);
372
- // If a server file was added, regenerate everything
373
- if (normalized.startsWith(`${serverDir}/`)) {
352
+ if (affectsManifest(file)) {
374
353
  debouncedHandleServerFileChange();
375
354
  }
376
355
  });
377
356
  server.watcher.on("unlink", (file) => {
378
- const relative = path.relative(root, file);
379
- const normalized = normalizeToPosix(relative);
380
- // If a server file was removed, regenerate (allow fewer methods)
381
- if (normalized.startsWith(`${serverDir}/`)) {
357
+ if (affectsManifest(file)) {
382
358
  debouncedHandleServerFileChange(true);
383
359
  }
384
360
  });
361
+ server.httpServer?.once("close", () => {
362
+ if (debounceTimer) {
363
+ clearTimeout(debounceTimer);
364
+ }
365
+ });
385
366
  // We hook into the server start to attach our RPC server
386
367
  server.httpServer?.on("listening", async () => {
387
368
  try {
@@ -457,7 +438,7 @@ export function useRouter() {
457
438
  }
458
439
 
459
440
  export function Link(props) {
460
- const { href = '#', children, ...rest } = props || {};
441
+ const { href = '#', children, prefetch, ...rest } = props || {};
461
442
  return React.createElement('a', { href, ...rest }, children);
462
443
  }
463
444
 
@@ -469,6 +450,10 @@ export function AppRouter() {
469
450
  return null;
470
451
  }
471
452
 
453
+ export async function callMethod() {
454
+ throw new Error('callMethod is only available in the browser. Load server data with getServerSideProps instead.');
455
+ }
456
+
472
457
  export function useCall() {
473
458
  return {
474
459
  call: async () => null,
@@ -489,11 +474,15 @@ export function useFetch() {
489
474
  export class RpcError extends Error {}
490
475
 
491
476
  export function getPublicEnv() {
492
- return {};
477
+ return Object.fromEntries(Object.entries(process.env).filter(([key, value]) => key.startsWith('HELIUM_PUBLIC_') && typeof value === 'string'));
493
478
  }
494
479
 
495
- export function getPublicEnvValue() {
496
- return undefined;
480
+ export function getPublicEnvValue(key) {
481
+ return getPublicEnv()[key];
482
+ }
483
+
484
+ export function isDevEnvironment() {
485
+ return false;
497
486
  }
498
487
 
499
488
  export function getRpcTransport() {
@@ -514,19 +503,22 @@ export function isSSR() {
514
503
  function generateSSRTransitionsStubModule() {
515
504
  return `
516
505
  import React from 'react';
506
+ import { useRouter } from 'heliumts/client';
517
507
 
518
508
  export function useDeferredNavigation() {
509
+ const { path } = useRouter();
519
510
  return {
520
- path: '/',
521
- deferredPath: '/',
511
+ path,
512
+ deferredPath: path,
522
513
  isStale: false,
523
514
  isPending: false,
524
515
  isTransitioning: false,
525
516
  };
526
517
  }
527
518
 
528
- export function PageTransition({ children }) {
529
- return React.createElement(React.Fragment, null, children);
519
+ export function PageTransition({ children, fallback = null }) {
520
+ return React.createElement('div', { style: { opacity: 1, transition: 'opacity 150ms ease' } },
521
+ React.createElement(React.Suspense, { fallback }, children));
530
522
  }
531
523
  `;
532
524
  }
@@ -1 +1 @@
1
- {"version":3,"file":"heliumPlugin.js","sourceRoot":"","sources":["../../src/vite/heliumPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EACH,iCAAiC,EACjC,gCAAgC,EAChC,mCAAmC,EACnC,UAAU,EACV,w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C,QAAQ,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACnD,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC9C,OAAO,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACtC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACtD,IAAI,CAAC;QACD,IAAI,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC9B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,EAAE,CAAC,UAAU,CAAC,YAAY,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAC1C,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACL,6EAA6E;IACjF,CAAC;AACL,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport type { Plugin } from \"vite\";\n\nimport { clearConfigCache, getRpcClientConfig, loadConfig } from \"../server/config.js\";\nimport { attachToDevServer } from \"../server/devServer.js\";\nimport { injectEnvToProcess, loadEnvFiles } from \"../utils/envLoader.js\";\nimport { log } from \"../utils/logger.js\";\nimport {\n RESOLVED_VIRTUAL_CLIENT_MODULE_ID,\n RESOLVED_VIRTUAL_ENTRY_MODULE_ID,\n RESOLVED_VIRTUAL_SERVER_MANIFEST_ID,\n SERVER_DIR,\n VIRTUAL_CLIENT_MODULE_ID,\n VIRTUAL_ENTRY_MODULE_ID,\n VIRTUAL_SERVER_MANIFEST_ID,\n} from \"./paths.js\";\nimport { checkRouteCollisions, scanAppShell, scanPageRoutePatterns, scanServerExports, scanSSRPages } from \"./scanner.js\";\nimport { generateClientModule, generateEntryModule, generateServerManifest, generateTypeDefinitions } from \"./virtualServerModule.js\";\n\nexport default function helium(): Plugin {\n let root = process.cwd();\n const serverDir = normalizeToPosix(SERVER_DIR);\n const RESOLVED_VIRTUAL_SSR_CLIENT_MODULE_ID = \"\\0heliumts:ssr-client\";\n const RESOLVED_VIRTUAL_SSR_TRANSITIONS_MODULE_ID = \"\\0heliumts:ssr-transitions\";\n const RESOLVED_VIRTUAL_SSR_PREFETCH_MODULE_ID = \"\\0heliumts:ssr-prefetch\";\n\n return {\n name: \"vite-plugin-helium\",\n enforce: \"pre\",\n configResolved(config) {\n root = config.root;\n },\n transformIndexHtml: {\n order: \"pre\",\n handler(html, _ctx) {\n // Check if HTML already has a script tag for entry\n if (html.includes(\"src/main.tsx\") || html.includes(\"src/main.ts\")) {\n return html; // User has their own entry, don't modify\n }\n\n // Ensure root div exists\n let modifiedHtml = html;\n if (!modifiedHtml.includes('id=\"root\"')) {\n modifiedHtml = modifiedHtml.replace(\"<body>\", '<body>\\n <div id=\"root\"></div>');\n }\n\n // Generate physical entry file\n const heliumDir = path.join(root, \"node_modules\", \".heliumts\");\n if (!fs.existsSync(heliumDir)) {\n fs.mkdirSync(heliumDir, { recursive: true });\n }\n const entryPath = path.join(heliumDir, \"entry.tsx\");\n fs.writeFileSync(entryPath, generateEntryModule());\n\n // Return with tags to inject the entry (runtime config is fetched by the client)\n return [\n {\n tag: \"script\",\n attrs: {\n type: \"module\",\n src: \"/node_modules/.heliumts/entry.tsx\",\n },\n injectTo: \"body\",\n },\n ];\n },\n },\n async config(config) {\n // Load environment variables before config is finalized\n const mode = config.mode || \"development\";\n const envVars = loadEnvFiles({ root, mode });\n\n // Inject env vars into process.env so server-side code can access them\n // consistently in both development and production.\n injectEnvToProcess(envVars);\n\n // Load helium config to get client-side RPC transport settings\n const heliumConfig = await loadConfig(root);\n const rpcClientConfig = getRpcClientConfig(heliumConfig);\n\n // Provide default index.html if none exists\n return {\n appType: \"spa\",\n optimizeDeps: {\n include: [\"react-dom/client\"],\n // Exclude helium from pre-bundling since it's the framework itself\n // This ensures changes to helium are picked up immediately\n exclude: [\"heliumts\", \"heliumts/client\", \"heliumts/server\", \"heliumts/vite\"],\n },\n // SSR configuration to properly isolate server-only code\n ssr: {\n // Externalize Node.js built-in modules - these should never be bundled\n external: [\"util\", \"zlib\", \"http\", \"https\", \"http2\", \"fs\", \"path\", \"crypto\", \"stream\", \"os\", \"url\", \"net\", \"tls\", \"child_process\", \"worker_threads\"],\n // Don't externalize heliumts - let the plugin handle the client/server split\n noExternal: [\"heliumts\"],\n },\n // Ensure Node.js built-ins are not bundled for client\n build: {\n rollupOptions: {\n external: [\n // Node.js built-in modules should never be in client bundle\n /^node:/,\n \"util\",\n \"zlib\",\n \"http\",\n \"https\",\n \"http2\",\n \"fs\",\n \"path\",\n \"crypto\",\n \"stream\",\n \"os\",\n \"url\",\n \"net\",\n \"tls\",\n \"child_process\",\n \"worker_threads\",\n ],\n },\n },\n define: {\n __HELIUM_DEV__: JSON.stringify(mode !== \"production\"),\n __HELIUM_RPC_TRANSPORT__: JSON.stringify(rpcClientConfig.transport),\n __HELIUM_RPC_AUTO_HTTP_ON_MOBILE__: JSON.stringify(rpcClientConfig.autoHttpOnMobile),\n __HELIUM_RPC_TOKEN_VALIDITY_MS__: JSON.stringify(rpcClientConfig.tokenValidityMs),\n },\n };\n },\n resolveId(id, importer, options) {\n if (options?.ssr && id === \"heliumts/client\") {\n return RESOLVED_VIRTUAL_SSR_CLIENT_MODULE_ID;\n }\n if (options?.ssr && id === \"heliumts/client/transitions\") {\n return RESOLVED_VIRTUAL_SSR_TRANSITIONS_MODULE_ID;\n }\n if (options?.ssr && id === \"heliumts/client/prefetch\") {\n return RESOLVED_VIRTUAL_SSR_PREFETCH_MODULE_ID;\n }\n if (id === VIRTUAL_CLIENT_MODULE_ID) {\n if (isServerModule(importer, root, serverDir)) {\n return null;\n }\n return RESOLVED_VIRTUAL_CLIENT_MODULE_ID;\n }\n if (id === VIRTUAL_SERVER_MANIFEST_ID) {\n return RESOLVED_VIRTUAL_SERVER_MANIFEST_ID;\n }\n if (id === VIRTUAL_ENTRY_MODULE_ID) {\n // Add .tsx extension so Vite knows it contains JSX\n return RESOLVED_VIRTUAL_ENTRY_MODULE_ID + \".tsx\";\n }\n // Intercept heliumts/server imports from client code\n if (id === \"heliumts/server\") {\n // If imported from server code, let it resolve normally\n if (isServerModule(importer, root, serverDir)) {\n return null;\n }\n // For client code, redirect to virtual client module\n return RESOLVED_VIRTUAL_CLIENT_MODULE_ID;\n }\n return null;\n },\n transform(code, id, options) {\n // Prevent .server.ts/.server.js sidecar files from being bundled in client code.\n // These files contain server-only logic (e.g. DB queries) and must never run in the browser.\n if (!options?.ssr && /\\.server\\.(ts|js|tsx|jsx|mts|mjs)$/.test(id)) {\n return { code: \"export default null;\", map: null };\n }\n },\n load(id) {\n if (id === RESOLVED_VIRTUAL_SSR_CLIENT_MODULE_ID) {\n return generateSSRClientStubModule();\n }\n if (id === RESOLVED_VIRTUAL_SSR_TRANSITIONS_MODULE_ID) {\n return generateSSRTransitionsStubModule();\n }\n if (id === RESOLVED_VIRTUAL_SSR_PREFETCH_MODULE_ID) {\n return generateSSRPrefetchStubModule();\n }\n if (id === RESOLVED_VIRTUAL_CLIENT_MODULE_ID) {\n const { methods } = scanServerExports(root);\n return generateClientModule(methods);\n }\n if (id === RESOLVED_VIRTUAL_SERVER_MANIFEST_ID) {\n const { methods, httpHandlers, seoMetadata, middleware, workers } = scanServerExports(root);\n const pageRoutePatterns = scanPageRoutePatterns(root);\n const ssrPages = scanSSRPages(root);\n const appShell = scanAppShell(root);\n return generateServerManifest(methods, httpHandlers, seoMetadata, pageRoutePatterns, ssrPages, appShell, middleware, workers);\n }\n if (id === RESOLVED_VIRTUAL_ENTRY_MODULE_ID + \".tsx\") {\n return generateEntryModule();\n }\n },\n buildStart() {\n const { methods } = scanServerExports(root);\n const dts = generateTypeDefinitions(methods, root);\n const typesDir = path.join(root, \"src\", \"types\");\n const dtsPath = path.join(typesDir, \"heliumts-server.d.ts\");\n\n // Ensure src/types exists\n if (!fs.existsSync(typesDir)) {\n fs.mkdirSync(typesDir, { recursive: true });\n }\n\n // At build start we always allow writing the canonical set.\n // Only skip if content is identical to avoid needless TS invalidation.\n if (!fs.existsSync(dtsPath) || fs.readFileSync(dtsPath, \"utf-8\") !== dts) {\n fs.writeFileSync(dtsPath, dts);\n touchTsConfig(root);\n }\n\n // Check for route collisions in pages directory\n checkRouteCollisions(root);\n },\n configureServer(server) {\n // Add middleware to handle HTML fallback for nested routes\n // This ensures that routes like /docs/guides/auth properly serve index.html\n // so the client-side router can handle them\n server.middlewares.use((req, res, next) => {\n const url = req.url || \"\";\n const cleanUrl = url.split(\"?\")[0];\n\n // Skip if:\n // - Has file extension (asset request)\n // - Is an API/special endpoint\n // - Is a dev server endpoint\n if (\n path.extname(cleanUrl) !== \"\" ||\n cleanUrl.startsWith(\"/api\") ||\n cleanUrl.startsWith(\"/webhooks\") ||\n cleanUrl.startsWith(\"/@\") ||\n cleanUrl.startsWith(\"/__helium__\")\n ) {\n return next();\n }\n\n // For all other routes (including nested paths like /docs/guides/auth),\n // rewrite to index.html so Vite serves it and the client-side router handles routing\n req.url = \"/index.html\";\n next();\n });\n\n /**\n * Write type definitions only if content has changed.\n * This prevents unnecessary TypeScript recompilation.\n *\n * When `allowFewer` is false (default) the file will NOT be\n * overwritten if the new content has fewer method declarations\n * than the existing file — this guards against writing a\n * degraded .d.ts while the user's file is only partially saved.\n */\n const writeTypesIfChanged = (dts: string, allowFewer = false): boolean => {\n const typesDir = path.join(root, \"src\", \"types\");\n const dtsPath = path.join(typesDir, \"heliumts-server.d.ts\");\n\n if (!fs.existsSync(typesDir)) {\n fs.mkdirSync(typesDir, { recursive: true });\n }\n\n // Check if file exists and content is the same\n if (fs.existsSync(dtsPath)) {\n const existing = fs.readFileSync(dtsPath, \"utf-8\");\n if (existing === dts) {\n return false; // No change needed\n }\n\n // Guard: don't overwrite with fewer methods unless explicitly allowed\n // (e.g. on unlink). This prevents losing types during partial saves.\n if (!allowFewer) {\n const countExports = (s: string) => (s.match(/export const \\w+:/g) || []).length;\n const existingCount = countExports(existing);\n const newCount = countExports(dts);\n if (newCount < existingCount) {\n log(\"info\", `Skipping type generation: found ${newCount} methods, existing has ${existingCount} (likely partial save)`);\n return false;\n }\n }\n }\n\n fs.writeFileSync(dtsPath, dts);\n\n // Touch tsconfig.json to force the TypeScript language server\n // to reload the project. Without this, TS may cache stale\n // module augmentations and autocomplete won't reflect the\n // new methods until a manual restart.\n touchTsConfig(root);\n\n return true; // File was written\n };\n\n const regenerateTypes = (allowFewer = false): boolean => {\n try {\n const { methods } = scanServerExports(root);\n const dts = generateTypeDefinitions(methods, root);\n return writeTypesIfChanged(dts, allowFewer);\n } catch (e) {\n log(\"error\", \"Failed to regenerate types\", e);\n return false;\n }\n };\n\n // Debounce timer for file changes\n let debounceTimer: ReturnType<typeof setTimeout> | null = null;\n const DEBOUNCE_DELAY = 300; // ms — long enough for format-on-save to finish\n\n const handleServerFileChange = async (allowFewer = false) => {\n // Regenerate type definitions\n regenerateTypes(allowFewer);\n\n // Invalidate the virtual modules so they get regenerated\n const clientModule = server.environments.client?.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CLIENT_MODULE_ID);\n const serverModule = server.environments.ssr?.moduleGraph.getModuleById(RESOLVED_VIRTUAL_SERVER_MANIFEST_ID);\n\n if (clientModule) {\n server.environments.client?.moduleGraph.invalidateModule(clientModule);\n }\n if (serverModule) {\n server.environments.ssr?.moduleGraph.invalidateModule(serverModule);\n }\n\n // Reload the server manifest and re-register methods\n try {\n // Clear config cache to ensure fresh config is loaded\n clearConfigCache();\n const config = await loadConfig(root);\n const mod = await server.ssrLoadModule(VIRTUAL_SERVER_MANIFEST_ID);\n const registerAll = mod.registerAll;\n const httpHandlers = mod.httpHandlers || [];\n const seoMetadataHandlers = mod.seoMetadataHandlers || [];\n const pageRoutePatterns = mod.pageRoutePatterns || [];\n const middlewareHandler = mod.middlewareHandler || null;\n const workers = mod.workers || [];\n const ssrPages = mod.ssrPages || [];\n const appShell = mod.appShell || null;\n\n // Update the dev server registry with new methods and HTTP handlers\n if (server.httpServer) {\n attachToDevServer(\n server.httpServer,\n (registry, httpRouter, seoRouter) => {\n registerAll(registry);\n httpRouter.registerRoutes(httpHandlers);\n seoRouter.registerRoutes(seoMetadataHandlers);\n seoRouter.setPageRoutePatterns(pageRoutePatterns);\n if (middlewareHandler) {\n registry.setMiddleware(middlewareHandler);\n httpRouter.setMiddleware(middlewareHandler);\n }\n },\n config,\n workers,\n ssrPages,\n appShell\n );\n }\n } catch (e) {\n log(\"error\", \"Failed to reload Helium server manifest\", e);\n }\n\n // Trigger HMR for any client code that imports heliumts/server\n server.ws.send({\n type: \"full-reload\",\n path: \"*\",\n });\n };\n\n // Watch server directory for changes\n const serverPath = path.join(root, serverDir);\n server.watcher.add(serverPath);\n\n // Watch config files for changes\n const configFiles = [\"helium.config.ts\", \"helium.config.js\", \"helium.config.mjs\"];\n for (const configFile of configFiles) {\n const configPath = path.join(root, configFile);\n if (fs.existsSync(configPath)) {\n server.watcher.add(configPath);\n }\n }\n\n /**\n * Debounced handler for server file changes.\n * This prevents multiple rapid regenerations during file saves.\n * @param allowFewer - pass true when files are deleted, so the\n * method count is allowed to decrease.\n */\n let pendingAllowFewer = false;\n const debouncedHandleServerFileChange = (allowFewer = false) => {\n // If any event in the batch is an unlink, honour it\n if (allowFewer) {\n pendingAllowFewer = true;\n }\n if (debounceTimer) {\n clearTimeout(debounceTimer);\n }\n debounceTimer = setTimeout(() => {\n debounceTimer = null;\n const shouldAllowFewer = pendingAllowFewer;\n pendingAllowFewer = false;\n handleServerFileChange(shouldAllowFewer);\n }, DEBOUNCE_DELAY);\n };\n\n server.watcher.on(\"change\", (file) => {\n const relative = path.relative(root, file);\n const normalized = normalizeToPosix(relative);\n\n // If a server file changed, regenerate everything\n if (normalized.startsWith(`${serverDir}/`)) {\n debouncedHandleServerFileChange();\n }\n\n // If config file changed, reload config and regenerate\n if (configFiles.some((cf) => normalized === cf)) {\n log(\"info\", `Config file changed: ${normalized}`);\n debouncedHandleServerFileChange();\n }\n });\n\n server.watcher.on(\"add\", (file) => {\n const relative = path.relative(root, file);\n const normalized = normalizeToPosix(relative);\n\n // If a server file was added, regenerate everything\n if (normalized.startsWith(`${serverDir}/`)) {\n debouncedHandleServerFileChange();\n }\n });\n\n server.watcher.on(\"unlink\", (file) => {\n const relative = path.relative(root, file);\n const normalized = normalizeToPosix(relative);\n\n // If a server file was removed, regenerate (allow fewer methods)\n if (normalized.startsWith(`${serverDir}/`)) {\n debouncedHandleServerFileChange(true);\n }\n });\n\n // We hook into the server start to attach our RPC server\n server.httpServer?.on(\"listening\", async () => {\n try {\n // Load config\n const config = await loadConfig(root);\n\n // Load the manifest using Vite's SSR loader\n // This allows us to load TS files directly and handle dependencies\n const mod = await server.ssrLoadModule(VIRTUAL_SERVER_MANIFEST_ID);\n const registerAll = mod.registerAll;\n const httpHandlers = mod.httpHandlers || [];\n const seoMetadataHandlers = mod.seoMetadataHandlers || [];\n const pageRoutePatterns = mod.pageRoutePatterns || [];\n const middlewareHandler = mod.middlewareHandler || null;\n const workers = mod.workers || [];\n const ssrPages = mod.ssrPages || [];\n const appShell = mod.appShell || null;\n\n if (server.httpServer) {\n attachToDevServer(\n server.httpServer,\n (registry, httpRouter, seoRouter) => {\n registerAll(registry);\n httpRouter.registerRoutes(httpHandlers);\n seoRouter.registerRoutes(seoMetadataHandlers);\n seoRouter.setPageRoutePatterns(pageRoutePatterns);\n if (middlewareHandler) {\n registry.setMiddleware(middlewareHandler);\n httpRouter.setMiddleware(middlewareHandler);\n }\n },\n config,\n workers,\n ssrPages,\n appShell\n );\n }\n } catch (e) {\n log(\"error\", \"Failed to attach Helium RPC server\", e);\n }\n });\n },\n };\n}\n\nfunction generateSSRClientStubModule(): string {\n return `\nimport React from 'react';\n\nexport const RouterContext = React.createContext(null);\n\nfunction getSSRRouterSnapshot() {\n const snapshot = globalThis.__HELIUM_SSR_ROUTER__;\n if (!snapshot || typeof snapshot !== 'object') {\n return {\n path: '/',\n params: {},\n search: '',\n };\n }\n\n return {\n path: typeof snapshot.path === 'string' ? snapshot.path : '/',\n params: snapshot.params && typeof snapshot.params === 'object' ? snapshot.params : {},\n search: typeof snapshot.search === 'string' ? snapshot.search : '',\n };\n}\n\nexport function useRouter() {\n const snapshot = getSSRRouterSnapshot();\n return {\n path: snapshot.path,\n params: snapshot.params,\n searchParams: new URLSearchParams(snapshot.search),\n push: () => {},\n replace: () => {},\n on: () => () => {},\n status: 200,\n isNavigating: false,\n isPending: false,\n };\n}\n\nexport function Link(props) {\n const { href = '#', children, ...rest } = props || {};\n return React.createElement('a', { href, ...rest }, children);\n}\n\nexport function Redirect() {\n return null;\n}\n\nexport function AppRouter() {\n return null;\n}\n\nexport function useCall() {\n return {\n call: async () => null,\n isCalling: false,\n error: null,\n };\n}\n\nexport function useFetch() {\n return {\n data: null,\n isLoading: false,\n error: null,\n refetch: async () => undefined,\n };\n}\n\nexport class RpcError extends Error {}\n\nexport function getPublicEnv() {\n return {};\n}\n\nexport function getPublicEnvValue() {\n return undefined;\n}\n\nexport function getRpcTransport() {\n return 'websocket';\n}\n\nexport function isAutoHttpOnMobileEnabled() {\n return false;\n}\n\nexport function preconnect() {}\n\nexport function isSSR() {\n return true;\n}\n`;\n}\n\nfunction generateSSRTransitionsStubModule(): string {\n return `\nimport React from 'react';\n\nexport function useDeferredNavigation() {\n return {\n path: '/',\n deferredPath: '/',\n isStale: false,\n isPending: false,\n isTransitioning: false,\n };\n}\n\nexport function PageTransition({ children }) {\n return React.createElement(React.Fragment, null, children);\n}\n`;\n}\n\nfunction generateSSRPrefetchStubModule(): string {\n return `\nexport function prefetchRoute() {}\nexport function clearPrefetchCache() {}\n`;\n}\n\n/**\n * Convert file path to POSIX format\n * @internal Exported for testing\n */\nexport function normalizeToPosix(filePath: string): string {\n return filePath.split(path.sep).join(\"/\");\n}\n\n/**\n * Check if an importer is a server module\n * @internal Exported for testing\n */\nexport function isServerModule(importer: string | undefined, root: string, serverDir: string): boolean {\n if (!importer || importer.startsWith(\"\\0\")) {\n return false;\n }\n\n const [importerPath] = importer.split(\"?\");\n if (!importerPath) {\n return false;\n }\n\n const relative = path.relative(root, importerPath);\n if (!relative || relative.startsWith(\"..\")) {\n return false;\n }\n\n const normalized = normalizeToPosix(relative);\n return normalized === serverDir || normalized.startsWith(`${serverDir}/`);\n}\n\n/**\n * Touch the project's tsconfig.json to force the TypeScript language server\n * to reload the project and pick up changed module augmentations.\n *\n * TS language server watches tsconfig.json for changes. When a `.d.ts` file\n * with `declare module` augmentations is regenerated, TS doesn't always\n * detect the new content — leading to stale autocomplete. By updating\n * tsconfig.json's mtime we trigger a full project reload.\n *\n * The file content is NOT modified; only the filesystem timestamp changes.\n *\n * @internal Exported for testing\n */\nexport function touchTsConfig(root: string): void {\n const tsconfigPath = path.join(root, \"tsconfig.json\");\n try {\n if (fs.existsSync(tsconfigPath)) {\n const now = new Date();\n fs.utimesSync(tsconfigPath, now, now);\n }\n } catch {\n // Non-critical: if we can't touch the file, TS may just need a manual reload\n }\n}\n"]}
1
+ {"version":3,"file":"heliumPlugin.js","sourceRoot":"","sources":["../../src/vite/heliumPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,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,YAAY,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAC1C,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACL,6EAA6E;IACjF,CAAC;AACL,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport type { Plugin } from \"vite\";\n\nimport { clearConfigCache, getRpcClientConfig, getRpcConfig, loadConfig } from \"../server/config.js\";\nimport { attachToDevServer } from \"../server/devServer.js\";\nimport { injectEnvToProcess, loadEnvFiles } from \"../utils/envLoader.js\";\nimport { log } from \"../utils/logger.js\";\nimport {\n RESOLVED_VIRTUAL_CLIENT_MODULE_ID,\n RESOLVED_VIRTUAL_ENTRY_MODULE_ID,\n RESOLVED_VIRTUAL_SERVER_MANIFEST_ID,\n SERVER_DIR,\n VIRTUAL_CLIENT_MODULE_ID,\n VIRTUAL_ENTRY_MODULE_ID,\n VIRTUAL_SERVER_MANIFEST_ID,\n} from \"./paths.js\";\nimport { checkRouteCollisions, scanAppShell, scanPageRoutePatterns, scanServerExports, scanSSRPages } from \"./scanner.js\";\nimport { generateClientModule, generateEntryModule, generateServerManifest, generateTypeDefinitions } from \"./virtualServerModule.js\";\n\nexport default function helium(): Plugin {\n let root = process.cwd();\n const serverDir = normalizeToPosix(SERVER_DIR);\n const RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID = \"\\0heliumts:ssr-server\";\n const RESOLVED_VIRTUAL_SSR_CLIENT_MODULE_ID = \"\\0heliumts:ssr-client\";\n const RESOLVED_VIRTUAL_SSR_TRANSITIONS_MODULE_ID = \"\\0heliumts:ssr-transitions\";\n const RESOLVED_VIRTUAL_SSR_PREFETCH_MODULE_ID = \"\\0heliumts:ssr-prefetch\";\n\n return {\n name: \"vite-plugin-helium\",\n enforce: \"pre\",\n configResolved(config) {\n root = config.root;\n },\n transformIndexHtml: {\n order: \"pre\",\n handler(html, _ctx) {\n // Check if HTML already has a script tag for entry\n if (/<script\\b[^>]*\\bsrc\\s*=\\s*[\"'][^\"']*src\\/main\\.[jt]sx?(?:[?#][^\"']*)?[\"']/i.test(html)) {\n return html; // User has their own entry, don't modify\n }\n\n // Ensure root div exists\n let modifiedHtml = html;\n if (!/<[a-z][^>]*\\sid\\s*=\\s*[\"']root[\"']/i.test(modifiedHtml)) {\n modifiedHtml = modifiedHtml.replace(/<body\\b[^>]*>/i, (body) => `${body}\\n <div id=\"root\"></div>`);\n }\n\n // Generate physical entry file\n const heliumDir = path.join(root, \"node_modules\", \".heliumts\");\n if (!fs.existsSync(heliumDir)) {\n fs.mkdirSync(heliumDir, { recursive: true });\n }\n const entryPath = path.join(heliumDir, \"entry.tsx\");\n fs.writeFileSync(entryPath, generateEntryModule(scanAppShell(root)));\n\n // Return with tags to inject the entry (runtime config is fetched by the client)\n return {\n html: modifiedHtml,\n tags: [\n {\n tag: \"script\",\n attrs: {\n type: \"module\",\n src: \"/node_modules/.heliumts/entry.tsx\",\n },\n injectTo: \"body\",\n },\n ],\n };\n },\n },\n async config(config, env) {\n // configResolved runs after this hook; honor an explicit Vite root now.\n root = path.resolve(config.root || process.cwd());\n const mode = env.mode;\n const envVars = loadEnvFiles({ root, mode });\n\n // Inject env vars into process.env so server-side code can access them\n // consistently in both development and production.\n injectEnvToProcess(envVars);\n\n // Load helium config to get client-side RPC transport settings\n const heliumConfig = await loadConfig(root);\n const rpcClientConfig = getRpcClientConfig(heliumConfig);\n\n // Provide default index.html if none exists\n return {\n appType: config.appType ?? \"spa\",\n optimizeDeps: {\n include: [\"react-dom/client\"],\n // Exclude helium from pre-bundling since it's the framework itself\n // This ensures changes to helium are picked up immediately\n exclude: [\"heliumts\", \"heliumts/client\", \"heliumts/server\", \"heliumts/vite\"],\n },\n // SSR configuration to properly isolate server-only code\n ssr: {\n // Externalize Node.js built-in modules - these should never be bundled\n external: [\"util\", \"zlib\", \"http\", \"https\", \"http2\", \"fs\", \"path\", \"crypto\", \"stream\", \"os\", \"url\", \"net\", \"tls\", \"child_process\", \"worker_threads\"],\n // Don't externalize heliumts - let the plugin handle the client/server split\n noExternal: [\"heliumts\"],\n },\n // Ensure Node.js built-ins are not bundled for client\n build: {\n rollupOptions: {\n external: [\n // Node.js built-in modules should never be in client bundle\n /^node:/,\n \"util\",\n \"zlib\",\n \"http\",\n \"https\",\n \"http2\",\n \"fs\",\n \"path\",\n \"crypto\",\n \"stream\",\n \"os\",\n \"url\",\n \"net\",\n \"tls\",\n \"child_process\",\n \"worker_threads\",\n ],\n },\n },\n define: {\n __HELIUM_DEV__: JSON.stringify(env.command === \"serve\"),\n __HELIUM_RPC_TRANSPORT__: JSON.stringify(rpcClientConfig.transport),\n __HELIUM_RPC_AUTO_HTTP_ON_MOBILE__: JSON.stringify(rpcClientConfig.autoHttpOnMobile),\n __HELIUM_RPC_TOKEN_VALIDITY_MS__: JSON.stringify(rpcClientConfig.tokenValidityMs),\n __HELIUM_RPC_MAX_BATCH_SIZE__: JSON.stringify(getRpcConfig(heliumConfig).maxBatchSize),\n },\n };\n },\n resolveId(id, importer, options) {\n if (options?.ssr && id === \"heliumts/client\") {\n return RESOLVED_VIRTUAL_SSR_CLIENT_MODULE_ID;\n }\n if (options?.ssr && id === \"heliumts/client/transitions\") {\n return RESOLVED_VIRTUAL_SSR_TRANSITIONS_MODULE_ID;\n }\n if (options?.ssr && id === \"heliumts/client/prefetch\") {\n return RESOLVED_VIRTUAL_SSR_PREFETCH_MODULE_ID;\n }\n if (id === VIRTUAL_CLIENT_MODULE_ID) {\n if (importer === RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID || isServerModule(importer, root, serverDir) || /\\.server\\.[cm]?[jt]sx?(?:\\?|$)/.test(importer || \"\")) {\n return null;\n }\n return options?.ssr ? RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID : RESOLVED_VIRTUAL_CLIENT_MODULE_ID;\n }\n if (id === VIRTUAL_SERVER_MANIFEST_ID) {\n return RESOLVED_VIRTUAL_SERVER_MANIFEST_ID;\n }\n if (id === VIRTUAL_ENTRY_MODULE_ID) {\n // Add .tsx extension so Vite knows it contains JSX\n return RESOLVED_VIRTUAL_ENTRY_MODULE_ID + \".tsx\";\n }\n return null;\n },\n transform(code, id, options) {\n if (!options?.ssr && isServerModule(id, root, serverDir)) {\n throw new Error(`Server-only module cannot be imported by client code: ${id}. Import RPC method stubs from 'heliumts/server' instead.`);\n }\n // Prevent .server.ts/.server.js sidecar files from being bundled in client code.\n // These files contain server-only logic (e.g. DB queries) and must never run in the browser.\n if (!options?.ssr && /\\.server\\.(ts|js|tsx|jsx|mts|mjs)$/.test(id.split(\"?\")[0])) {\n return { code: \"export default null;\", map: null };\n }\n },\n load(id) {\n if (id === RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID) {\n const { methods } = scanServerExports(root);\n return `export * from 'heliumts/server';\\n${generateClientModule(methods)}`;\n }\n if (id === RESOLVED_VIRTUAL_SSR_CLIENT_MODULE_ID) {\n return generateSSRClientStubModule();\n }\n if (id === RESOLVED_VIRTUAL_SSR_TRANSITIONS_MODULE_ID) {\n return generateSSRTransitionsStubModule();\n }\n if (id === RESOLVED_VIRTUAL_SSR_PREFETCH_MODULE_ID) {\n return generateSSRPrefetchStubModule();\n }\n if (id === RESOLVED_VIRTUAL_CLIENT_MODULE_ID) {\n const { methods } = scanServerExports(root);\n return generateClientModule(methods);\n }\n if (id === RESOLVED_VIRTUAL_SERVER_MANIFEST_ID) {\n const { methods, httpHandlers, seoMetadata, middleware, workers } = scanServerExports(root);\n const pageRoutePatterns = scanPageRoutePatterns(root);\n const ssrPages = scanSSRPages(root);\n const appShell = scanAppShell(root);\n return generateServerManifest(methods, httpHandlers, seoMetadata, pageRoutePatterns, ssrPages, appShell, middleware, workers);\n }\n if (id === RESOLVED_VIRTUAL_ENTRY_MODULE_ID + \".tsx\") {\n return generateEntryModule(scanAppShell(root));\n }\n },\n buildStart() {\n const { methods } = scanServerExports(root);\n const dts = generateTypeDefinitions(methods, root);\n const typesDir = path.join(root, \"src\", \"types\");\n const dtsPath = path.join(typesDir, \"heliumts-server.d.ts\");\n\n // Ensure src/types exists\n if (!fs.existsSync(typesDir)) {\n fs.mkdirSync(typesDir, { recursive: true });\n }\n\n // At build start we always allow writing the canonical set.\n // Only skip if content is identical to avoid needless TS invalidation.\n if (!fs.existsSync(dtsPath) || fs.readFileSync(dtsPath, \"utf-8\") !== dts) {\n fs.writeFileSync(dtsPath, dts);\n touchTsConfig(root);\n }\n\n // Check for route collisions in pages directory\n checkRouteCollisions(root);\n },\n configureServer(server) {\n // Vite's SPA fallback runs after static/public assets and preserves request URLs.\n /**\n * Write type definitions only if content has changed.\n * This prevents unnecessary TypeScript recompilation.\n *\n * When `allowFewer` is false (default) the file will NOT be\n * overwritten if the new content has fewer method declarations\n * than the existing file — this guards against writing a\n * degraded .d.ts while the user's file is only partially saved.\n */\n const writeTypesIfChanged = (dts: string, allowFewer = false): boolean => {\n const typesDir = path.join(root, \"src\", \"types\");\n const dtsPath = path.join(typesDir, \"heliumts-server.d.ts\");\n\n if (!fs.existsSync(typesDir)) {\n fs.mkdirSync(typesDir, { recursive: true });\n }\n\n // Check if file exists and content is the same\n if (fs.existsSync(dtsPath)) {\n const existing = fs.readFileSync(dtsPath, \"utf-8\");\n if (existing === dts) {\n return false; // No change needed\n }\n\n // Guard: don't overwrite with fewer methods unless explicitly allowed\n // (e.g. on unlink). This prevents losing types during partial saves.\n if (!allowFewer) {\n const countExports = (s: string) => (s.match(/export const \\w+:/g) || []).length;\n const existingCount = countExports(existing);\n const newCount = countExports(dts);\n if (newCount < existingCount) {\n log(\"info\", `Skipping type generation: found ${newCount} methods, existing has ${existingCount} (likely partial save)`);\n return false;\n }\n }\n }\n\n fs.writeFileSync(dtsPath, dts);\n\n // Touch tsconfig.json to force the TypeScript language server\n // to reload the project. Without this, TS may cache stale\n // module augmentations and autocomplete won't reflect the\n // new methods until a manual restart.\n touchTsConfig(root);\n\n return true; // File was written\n };\n\n const regenerateTypes = (allowFewer = false): boolean => {\n try {\n const { methods } = scanServerExports(root);\n const dts = generateTypeDefinitions(methods, root);\n return writeTypesIfChanged(dts, allowFewer);\n } catch (e) {\n log(\"error\", \"Failed to regenerate types\", e);\n return false;\n }\n };\n\n // Debounce timer for file changes\n let debounceTimer: ReturnType<typeof setTimeout> | null = null;\n const DEBOUNCE_DELAY = 300; // ms — long enough for format-on-save to finish\n\n const handleServerFileChange = async (allowFewer = false) => {\n // Regenerate type definitions\n regenerateTypes(allowFewer);\n\n // Invalidate the virtual modules so they get regenerated\n const clientModule = server.environments.client?.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CLIENT_MODULE_ID);\n const serverModule = server.environments.ssr?.moduleGraph.getModuleById(RESOLVED_VIRTUAL_SERVER_MANIFEST_ID);\n const ssrRpcModule = server.environments.ssr?.moduleGraph.getModuleById(RESOLVED_VIRTUAL_SSR_SERVER_MODULE_ID);\n\n if (clientModule) {\n server.environments.client?.moduleGraph.invalidateModule(clientModule);\n }\n if (serverModule) {\n server.environments.ssr?.moduleGraph.invalidateModule(serverModule);\n }\n\n if (ssrRpcModule) {\n server.environments.ssr?.moduleGraph.invalidateModule(ssrRpcModule);\n }\n\n // Reload the server manifest and re-register methods\n try {\n // Clear config cache to ensure fresh config is loaded\n clearConfigCache();\n const config = await loadConfig(root);\n const mod = await server.ssrLoadModule(VIRTUAL_SERVER_MANIFEST_ID);\n const registerAll = mod.registerAll;\n const httpHandlers = mod.httpHandlers || [];\n const seoMetadataHandlers = mod.seoMetadataHandlers || [];\n const pageRoutePatterns = mod.pageRoutePatterns || [];\n const middlewareHandler = mod.middlewareHandler || null;\n const workers = mod.workers || [];\n const ssrPages = mod.ssrPages || [];\n const appShell = mod.appShell || null;\n\n // Update the dev server registry with new methods and HTTP handlers\n if (server.httpServer) {\n attachToDevServer(\n server.httpServer,\n (registry, httpRouter, seoRouter) => {\n registerAll(registry);\n httpRouter.registerRoutes(httpHandlers);\n seoRouter.registerRoutes(seoMetadataHandlers);\n seoRouter.setPageRoutePatterns(pageRoutePatterns);\n if (middlewareHandler) {\n registry.setMiddleware(middlewareHandler);\n httpRouter.setMiddleware(middlewareHandler);\n }\n },\n config,\n workers,\n ssrPages,\n appShell\n );\n }\n } catch (e) {\n log(\"error\", \"Failed to reload Helium server manifest\", e);\n }\n\n // Trigger HMR for any client code that imports heliumts/server\n server.ws.send({\n type: \"full-reload\",\n path: \"*\",\n });\n };\n\n // Watch server and page directories: new SSR pages and sidecars change the manifest too.\n server.watcher.add([path.join(root, serverDir), path.join(root, \"src\", \"pages\")]);\n\n // Watch config files for changes\n const configFiles = [\"helium.config.ts\", \"helium.config.js\", \"helium.config.mjs\"];\n for (const configFile of configFiles) {\n const configPath = path.join(root, configFile);\n if (fs.existsSync(configPath)) {\n server.watcher.add(configPath);\n }\n }\n\n /**\n * Debounced handler for server file changes.\n * This prevents multiple rapid regenerations during file saves.\n * @param allowFewer - pass true when files are deleted, so the\n * method count is allowed to decrease.\n */\n let pendingAllowFewer = false;\n const debouncedHandleServerFileChange = (allowFewer = false) => {\n // If any event in the batch is an unlink, honour it\n if (allowFewer) {\n pendingAllowFewer = true;\n }\n if (debounceTimer) {\n clearTimeout(debounceTimer);\n }\n debounceTimer = setTimeout(() => {\n debounceTimer = null;\n const shouldAllowFewer = pendingAllowFewer;\n pendingAllowFewer = false;\n handleServerFileChange(shouldAllowFewer);\n }, DEBOUNCE_DELAY);\n };\n\n const affectsManifest = (file: string): boolean => {\n const normalized = normalizeToPosix(path.relative(root, file));\n return (\n normalized.startsWith(`${serverDir}/`) || normalized.startsWith(\"src/pages/\") || /^src\\/[Aa]pp\\.[jt]sx?$/.test(normalized) || configFiles.includes(normalized)\n );\n };\n\n server.watcher.on(\"change\", (file) => {\n if (affectsManifest(file)) {\n debouncedHandleServerFileChange(true);\n }\n });\n\n server.watcher.on(\"add\", (file) => {\n if (affectsManifest(file)) {\n debouncedHandleServerFileChange();\n }\n });\n\n server.watcher.on(\"unlink\", (file) => {\n if (affectsManifest(file)) {\n debouncedHandleServerFileChange(true);\n }\n });\n\n server.httpServer?.once(\"close\", () => {\n if (debounceTimer) {\n clearTimeout(debounceTimer);\n }\n });\n\n // We hook into the server start to attach our RPC server\n server.httpServer?.on(\"listening\", async () => {\n try {\n // Load config\n const config = await loadConfig(root);\n\n // Load the manifest using Vite's SSR loader\n // This allows us to load TS files directly and handle dependencies\n const mod = await server.ssrLoadModule(VIRTUAL_SERVER_MANIFEST_ID);\n const registerAll = mod.registerAll;\n const httpHandlers = mod.httpHandlers || [];\n const seoMetadataHandlers = mod.seoMetadataHandlers || [];\n const pageRoutePatterns = mod.pageRoutePatterns || [];\n const middlewareHandler = mod.middlewareHandler || null;\n const workers = mod.workers || [];\n const ssrPages = mod.ssrPages || [];\n const appShell = mod.appShell || null;\n\n if (server.httpServer) {\n attachToDevServer(\n server.httpServer,\n (registry, httpRouter, seoRouter) => {\n registerAll(registry);\n httpRouter.registerRoutes(httpHandlers);\n seoRouter.registerRoutes(seoMetadataHandlers);\n seoRouter.setPageRoutePatterns(pageRoutePatterns);\n if (middlewareHandler) {\n registry.setMiddleware(middlewareHandler);\n httpRouter.setMiddleware(middlewareHandler);\n }\n },\n config,\n workers,\n ssrPages,\n appShell\n );\n }\n } catch (e) {\n log(\"error\", \"Failed to attach Helium RPC server\", e);\n }\n });\n },\n };\n}\n\nfunction generateSSRClientStubModule(): string {\n return `\nimport React from 'react';\n\nexport const RouterContext = React.createContext(null);\n\nfunction getSSRRouterSnapshot() {\n const snapshot = globalThis.__HELIUM_SSR_ROUTER__;\n if (!snapshot || typeof snapshot !== 'object') {\n return {\n path: '/',\n params: {},\n search: '',\n };\n }\n\n return {\n path: typeof snapshot.path === 'string' ? snapshot.path : '/',\n params: snapshot.params && typeof snapshot.params === 'object' ? snapshot.params : {},\n search: typeof snapshot.search === 'string' ? snapshot.search : '',\n };\n}\n\nexport function useRouter() {\n const snapshot = getSSRRouterSnapshot();\n return {\n path: snapshot.path,\n params: snapshot.params,\n searchParams: new URLSearchParams(snapshot.search),\n push: () => {},\n replace: () => {},\n on: () => () => {},\n status: 200,\n isNavigating: false,\n isPending: false,\n };\n}\n\nexport function Link(props) {\n const { href = '#', children, prefetch, ...rest } = props || {};\n return React.createElement('a', { href, ...rest }, children);\n}\n\nexport function Redirect() {\n return null;\n}\n\nexport function AppRouter() {\n return null;\n}\n\nexport async function callMethod() {\n throw new Error('callMethod is only available in the browser. Load server data with getServerSideProps instead.');\n}\n\nexport function useCall() {\n return {\n call: async () => null,\n isCalling: false,\n error: null,\n };\n}\n\nexport function useFetch() {\n return {\n data: null,\n isLoading: false,\n error: null,\n refetch: async () => undefined,\n };\n}\n\nexport class RpcError extends Error {}\n\nexport function getPublicEnv() {\n return Object.fromEntries(Object.entries(process.env).filter(([key, value]) => key.startsWith('HELIUM_PUBLIC_') && typeof value === 'string'));\n}\n\nexport function getPublicEnvValue(key) {\n return getPublicEnv()[key];\n}\n\nexport function isDevEnvironment() {\n return false;\n}\n\nexport function getRpcTransport() {\n return 'websocket';\n}\n\nexport function isAutoHttpOnMobileEnabled() {\n return false;\n}\n\nexport function preconnect() {}\n\nexport function isSSR() {\n return true;\n}\n`;\n}\n\nfunction generateSSRTransitionsStubModule(): string {\n return `\nimport React from 'react';\nimport { useRouter } from 'heliumts/client';\n\nexport function useDeferredNavigation() {\n const { path } = useRouter();\n return {\n path,\n deferredPath: path,\n isStale: false,\n isPending: false,\n isTransitioning: false,\n };\n}\n\nexport function PageTransition({ children, fallback = null }) {\n return React.createElement('div', { style: { opacity: 1, transition: 'opacity 150ms ease' } },\n React.createElement(React.Suspense, { fallback }, children));\n}\n`;\n}\n\nfunction generateSSRPrefetchStubModule(): string {\n return `\nexport function prefetchRoute() {}\nexport function clearPrefetchCache() {}\n`;\n}\n\n/**\n * Convert file path to POSIX format\n * @internal Exported for testing\n */\nexport function normalizeToPosix(filePath: string): string {\n return filePath.split(path.sep).join(\"/\");\n}\n\n/**\n * Check if an importer is a server module\n * @internal Exported for testing\n */\nexport function isServerModule(importer: string | undefined, root: string, serverDir: string): boolean {\n if (!importer || importer.startsWith(\"\\0\")) {\n return false;\n }\n\n const [importerPath] = importer.split(\"?\");\n if (!importerPath) {\n return false;\n }\n\n const relative = path.relative(root, importerPath);\n if (!relative || relative.startsWith(\"..\")) {\n return false;\n }\n\n const normalized = normalizeToPosix(relative);\n return normalized === serverDir || normalized.startsWith(`${serverDir}/`);\n}\n\n/**\n * Touch the project's tsconfig.json to force the TypeScript language server\n * to reload the project and pick up changed module augmentations.\n *\n * TS language server watches tsconfig.json for changes. When a `.d.ts` file\n * with `declare module` augmentations is regenerated, TS doesn't always\n * detect the new content — leading to stale autocomplete. By updating\n * tsconfig.json's mtime we trigger a full project reload.\n *\n * The file content is NOT modified; only the filesystem timestamp changes.\n *\n * @internal Exported for testing\n */\nexport function touchTsConfig(root: string): void {\n const tsconfigPath = path.join(root, \"tsconfig.json\");\n try {\n if (fs.existsSync(tsconfigPath)) {\n const now = new Date();\n fs.utimesSync(tsconfigPath, now, now);\n }\n } catch {\n // Non-critical: if we can't touch the file, TS may just need a manual reload\n }\n}\n"]}
@@ -34,6 +34,9 @@ export interface SSRPageExport {
34
34
  export declare function scanAppShell(root: string): string | null;
35
35
  export declare function scanServerMethods(root: string): MethodExport[];
36
36
  export declare function scanServerExports(root: string): ServerExports;
37
+ export declare function isPageFile(fileName: string): boolean;
38
+ /** Read directives only from the module prologue, never from comments or examples. */
39
+ export declare function hasPageDirective(source: string, directive: "use ssr" | "use ssg"): boolean;
37
40
  export declare function scanSSRPages(root: string): SSRPageExport[];
38
41
  export interface RouteCollision {
39
42
  pattern: string;
@@ -1 +1 @@
1
- {"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../src/vite/scanner.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;I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