heliumts 0.10.2 → 0.11.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 (156) hide show
  1. package/README.md +45 -46
  2. package/dist/bin/helium.js +117 -172
  3. package/dist/bin/helium.js.map +1 -1
  4. package/dist/bin/projectCommands.d.ts +59 -0
  5. package/dist/bin/projectCommands.d.ts.map +1 -0
  6. package/dist/bin/projectCommands.js +103 -0
  7. package/dist/bin/projectCommands.js.map +1 -0
  8. package/dist/bin/publicApi.d.ts +30 -0
  9. package/dist/bin/publicApi.d.ts.map +1 -0
  10. package/dist/bin/publicApi.js +155 -0
  11. package/dist/bin/publicApi.js.map +1 -0
  12. package/dist/client/Router.d.ts.map +1 -1
  13. package/dist/client/Router.js +5 -1
  14. package/dist/client/Router.js.map +1 -1
  15. package/dist/client/callMethod.d.ts +2 -2
  16. package/dist/client/callMethod.d.ts.map +1 -1
  17. package/dist/client/callMethod.js +3 -2
  18. package/dist/client/callMethod.js.map +1 -1
  19. package/dist/client/index.d.ts +3 -1
  20. package/dist/client/index.d.ts.map +1 -1
  21. package/dist/client/index.js +1 -2
  22. package/dist/client/index.js.map +1 -1
  23. package/dist/client/pageModules.d.ts +18 -0
  24. package/dist/client/pageModules.d.ts.map +1 -0
  25. package/dist/client/pageModules.js +3 -0
  26. package/dist/client/pageModules.js.map +1 -0
  27. package/dist/client/routerManifest.d.ts +2 -11
  28. package/dist/client/routerManifest.d.ts.map +1 -1
  29. package/dist/client/routerManifest.js +15 -187
  30. package/dist/client/routerManifest.js.map +1 -1
  31. package/dist/client/types.d.ts +12 -12
  32. package/dist/client/types.d.ts.map +1 -1
  33. package/dist/client/types.js +8 -1
  34. package/dist/client/types.js.map +1 -1
  35. package/dist/client/useCall.d.ts +20 -9
  36. package/dist/client/useCall.d.ts.map +1 -1
  37. package/dist/client/useCall.js +21 -6
  38. package/dist/client/useCall.js.map +1 -1
  39. package/dist/client/useFetch.d.ts +3 -3
  40. package/dist/client/useFetch.d.ts.map +1 -1
  41. package/dist/client/useFetch.js +8 -5
  42. package/dist/client/useFetch.js.map +1 -1
  43. package/dist/client/useStreaming.d.ts +3 -3
  44. package/dist/client/useStreaming.d.ts.map +1 -1
  45. package/dist/client/useStreaming.js +9 -7
  46. package/dist/client/useStreaming.js.map +1 -1
  47. package/dist/internal/index.d.ts +4 -0
  48. package/dist/internal/index.d.ts.map +1 -0
  49. package/dist/internal/index.js +4 -0
  50. package/dist/internal/index.js.map +1 -0
  51. package/dist/runtime/pageRoutes.d.ts +11 -0
  52. package/dist/runtime/pageRoutes.d.ts.map +1 -0
  53. package/dist/runtime/pageRoutes.js +50 -0
  54. package/dist/runtime/pageRoutes.js.map +1 -0
  55. package/dist/server/defineMethod.d.ts +16 -2
  56. package/dist/server/defineMethod.d.ts.map +1 -1
  57. package/dist/server/defineMethod.js +27 -3
  58. package/dist/server/defineMethod.js.map +1 -1
  59. package/dist/server/defineWorker.d.ts.map +1 -1
  60. package/dist/server/defineWorker.js +4 -6
  61. package/dist/server/defineWorker.js.map +1 -1
  62. package/dist/server/devServer.d.ts +2 -1
  63. package/dist/server/devServer.d.ts.map +1 -1
  64. package/dist/server/devServer.js +6 -9
  65. package/dist/server/devServer.js.map +1 -1
  66. package/dist/server/index.d.ts +16 -9
  67. package/dist/server/index.d.ts.map +1 -1
  68. package/dist/server/index.js +9 -12
  69. package/dist/server/index.js.map +1 -1
  70. package/dist/server/prodServer.d.ts +2 -0
  71. package/dist/server/prodServer.d.ts.map +1 -1
  72. package/dist/server/prodServer.js +7 -5
  73. package/dist/server/prodServer.js.map +1 -1
  74. package/dist/server/ssr.d.ts +4 -1
  75. package/dist/server/ssr.d.ts.map +1 -1
  76. package/dist/server/ssr.js +27 -61
  77. package/dist/server/ssr.js.map +1 -1
  78. package/dist/vite/heliumPlugin.d.ts +0 -14
  79. package/dist/vite/heliumPlugin.d.ts.map +1 -1
  80. package/dist/vite/heliumPlugin.js +68 -294
  81. package/dist/vite/heliumPlugin.js.map +1 -1
  82. package/dist/vite/paths.d.ts +0 -2
  83. package/dist/vite/paths.d.ts.map +1 -1
  84. package/dist/vite/paths.js +0 -2
  85. package/dist/vite/paths.js.map +1 -1
  86. package/dist/vite/rpcDiscovery.d.ts +10 -0
  87. package/dist/vite/rpcDiscovery.d.ts.map +1 -0
  88. package/dist/vite/rpcDiscovery.js +237 -0
  89. package/dist/vite/rpcDiscovery.js.map +1 -0
  90. package/dist/vite/rpcModule.d.ts +4 -0
  91. package/dist/vite/rpcModule.d.ts.map +1 -0
  92. package/dist/vite/rpcModule.js +64 -0
  93. package/dist/vite/rpcModule.js.map +1 -0
  94. package/dist/vite/scanner.d.ts +14 -4
  95. package/dist/vite/scanner.d.ts.map +1 -1
  96. package/dist/vite/scanner.js +130 -236
  97. package/dist/vite/scanner.js.map +1 -1
  98. package/dist/vite/serverClientAdapter.d.ts +103 -0
  99. package/dist/vite/serverClientAdapter.d.ts.map +1 -0
  100. package/dist/vite/serverClientAdapter.js +139 -0
  101. package/dist/vite/serverClientAdapter.js.map +1 -0
  102. package/dist/vite/ssg.d.ts +5 -8
  103. package/dist/vite/ssg.d.ts.map +1 -1
  104. package/dist/vite/ssg.js +32 -263
  105. package/dist/vite/ssg.js.map +1 -1
  106. package/dist/vite/virtualServerModule.d.ts +4 -4
  107. package/dist/vite/virtualServerModule.d.ts.map +1 -1
  108. package/dist/vite/virtualServerModule.js +18 -62
  109. package/dist/vite/virtualServerModule.js.map +1 -1
  110. package/docs/agent/api-reference.md +45 -0
  111. package/docs/agent/editable-forms.md +37 -0
  112. package/docs/agent/guide-get.md +13 -0
  113. package/docs/agent/guide-index.md +15 -0
  114. package/docs/agent/http-handlers.md +9 -0
  115. package/docs/agent/imports.md +16 -0
  116. package/docs/agent/index.md +48 -0
  117. package/docs/agent/input-validation.md +9 -0
  118. package/docs/agent/measuring.md +7 -0
  119. package/docs/agent/mutations.md +11 -0
  120. package/docs/agent/operations.md +9 -0
  121. package/docs/agent/query-params.md +28 -0
  122. package/docs/agent/rendering.md +9 -0
  123. package/docs/agent/request-context.md +13 -0
  124. package/docs/agent/routing.md +11 -0
  125. package/docs/agent/scaffold.md +15 -0
  126. package/docs/agent/security.md +9 -0
  127. package/docs/agent/server-files.md +9 -0
  128. package/docs/agent/streaming.md +9 -0
  129. package/docs/agent/validation-page.md +21 -0
  130. package/docs/agent/validation.md +33 -0
  131. package/docs/agent/verify.md +19 -0
  132. package/docs/agent/workflow.md +11 -0
  133. package/docs/agent-guide.md +266 -0
  134. package/docs/agent-start.md +87 -0
  135. package/docs/migration-0.11.md +15 -0
  136. package/package.json +20 -5
  137. package/dist/server/handlerLoader.d.ts +0 -1
  138. package/dist/server/handlerLoader.d.ts.map +0 -1
  139. package/dist/server/handlerLoader.js +0 -2
  140. package/dist/server/handlerLoader.js.map +0 -1
  141. package/dist/server/ipExtractor.d.ts +0 -48
  142. package/dist/server/ipExtractor.d.ts.map +0 -1
  143. package/dist/server/ipExtractor.js +0 -96
  144. package/dist/server/ipExtractor.js.map +0 -1
  145. package/dist/server/requestRouting.d.ts +0 -4
  146. package/dist/server/requestRouting.d.ts.map +0 -1
  147. package/dist/server/requestRouting.js +0 -67
  148. package/dist/server/requestRouting.js.map +0 -1
  149. package/dist/utils/deepEqual.d.ts +0 -1
  150. package/dist/utils/deepEqual.d.ts.map +0 -1
  151. package/dist/utils/deepEqual.js +0 -2
  152. package/dist/utils/deepEqual.js.map +0 -1
  153. package/dist/utils/formatError.d.ts +0 -2
  154. package/dist/utils/formatError.d.ts.map +0 -1
  155. package/dist/utils/formatError.js +0 -18
  156. package/dist/utils/formatError.js.map +0 -1
@@ -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,YAAY,E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,EAAE,IAAY,EAAE,SAAiB;IACxF,IAAI,CAAC,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, 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 tags that inject the framework entry.\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 the client token lifetime and HTTP batching limit.\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_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 if (!server.httpServer) {\n // Middleware mode has no Vite-owned HTTP server to attach to.\n return;\n }\n\n const httpServer = server.httpServer;\n let initialized = false;\n let initialization: Promise<void> | undefined;\n const initialize = () => {\n initialization ??= (async () => {\n const config = await loadConfig(root);\n const mod = await server.ssrLoadModule(VIRTUAL_SERVER_MANIFEST_ID);\n attachToDevServer(\n httpServer,\n (registry, httpRouter, seoRouter) => {\n mod.registerAll(registry);\n httpRouter.registerRoutes(mod.httpHandlers || []);\n seoRouter.registerRoutes(mod.seoMetadataHandlers || []);\n seoRouter.setPageRoutePatterns(mod.pageRoutePatterns || []);\n if (mod.middlewareHandler) {\n registry.setMiddleware(mod.middlewareHandler);\n httpRouter.setMiddleware(mod.middlewareHandler);\n }\n },\n config,\n mod.workers || [],\n mod.ssrPages || [],\n mod.appShell || null\n );\n initialized = true;\n })();\n return initialization;\n };\n\n // Vite initializes plugin containers and dependency optimizers as it\n // starts listening. Do not load the SSR manifest before that work.\n // Requests accepted during loading must wait without reading bodies.\n server.middlewares.use((req, res, next) => {\n if (initialized) {\n next();\n return;\n }\n void initialize().then(\n () => {\n if (!res.destroyed && !res.writableEnded) {\n // The request entered Connect before Helium attached.\n // Dispatch it through the newly installed HTTP handler.\n // Its Connect fallback passes this gate immediately\n // because initialized is now true.\n httpServer.emit(\"request\", req, res);\n }\n },\n () => {\n if (!res.destroyed && !res.writableEnded) {\n res.writeHead(503, { \"Content-Type\": \"text/plain\", \"Cache-Control\": \"no-store\" });\n res.end(\"Helium server initialization failed\");\n }\n }\n );\n });\n\n // Native callers can start httpServer directly; the shared promise\n // protects those requests too. Public Vite listen() must not resolve\n // and advertise readiness until registration has completed.\n httpServer.once(\"listening\", () => {\n void initialize().catch((error) => log(\"error\", \"Failed to attach Helium RPC server\", error));\n });\n const listen = server.listen.bind(server);\n server.listen = async (...args) => {\n const listeningServer = await listen(...args);\n await initialize();\n return listeningServer;\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 useStreaming() {\n return {\n chunks: [],\n text: '',\n isStreaming: false,\n error: null,\n stats: null,\n start: async () => {\n throw new Error('useStreaming.start is only available in the browser. Load server data with getServerSideProps instead.');\n },\n cancel: () => {},\n reset: () => {},\n };\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 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"]}
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;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAGpC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACrG,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,EAAE,gCAAgC,EAAE,mCAAmC,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AA4B,EAAE,IAAY,EAAE,SAAiB;IACxF,IAAI,CAAC,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","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\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 { RESOLVED_VIRTUAL_ENTRY_MODULE_ID, RESOLVED_VIRTUAL_SERVER_MANIFEST_ID, SERVER_DIR, VIRTUAL_ENTRY_MODULE_ID, VIRTUAL_SERVER_MANIFEST_ID } from \"./paths.js\";\nimport { RPC_MODULE_PATH, writeRpcModule } from \"./rpcModule.js\";\nimport { checkRouteCollisions, type PageManifestEntry, scanAppShell, scanPageManifest, scanPageRoutePatterns, scanServerExports, scanSSRPages } from \"./scanner.js\";\nimport { generateServerClientModule, generateServerPrefetchModule, generateServerTransitionsModule } from \"./serverClientAdapter.js\";\nimport { generateEntryModule, generatePageModules, generateServerManifest } from \"./virtualServerModule.js\";\n\nexport default function helium(): Plugin {\n let root = process.cwd();\n let pageManifest: PageManifestEntry[] | undefined;\n const getPageManifest = () => (pageManifest ??= scanPageManifest(root));\n const generateProjectRpc = () => writeRpcModule(root, scanServerExports(root).methods);\n const serverDir = normalizeToPosix(SERVER_DIR);\n const RESOLVED_PAGE_MODULES_ID = \"\\0heliumts:page-modules\";\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 tags that inject the framework entry.\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 the client token lifetime and HTTP batching limit.\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_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 === \"./pageModules.js\" && importer && import.meta.url.startsWith(\"file:\")) {\n const importerFile = importer.split(\"?\")[0];\n if (fs.existsSync(importerFile)) {\n const pluginDir = path.dirname(fs.realpathSync(fileURLToPath(import.meta.url)));\n const routerManifest = normalizeToPosix(path.resolve(pluginDir, \"../client/routerManifest\"));\n const importerPath = normalizeToPosix(fs.realpathSync(importerFile));\n if (importerPath === `${routerManifest}.js` || importerPath === `${routerManifest}.ts`) {\n return RESOLVED_PAGE_MODULES_ID;\n }\n }\n }\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 (!options?.ssr && id === \"heliumts/server\") {\n throw new Error(\"heliumts/server is server-only. Import application RPC references from src/rpc.generated.ts.\");\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 application RPC references from src/rpc.generated.ts 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_PAGE_MODULES_ID) {\n return generatePageModules(getPageManifest(), root);\n }\n if (id === RESOLVED_VIRTUAL_SSR_CLIENT_MODULE_ID) {\n return generateServerClientModule(\"ssr\");\n }\n if (id === RESOLVED_VIRTUAL_SSR_TRANSITIONS_MODULE_ID) {\n return generateServerTransitionsModule(\"ssr\");\n }\n if (id === RESOLVED_VIRTUAL_SSR_PREFETCH_MODULE_ID) {\n return generateServerPrefetchModule();\n }\n if (id === RESOLVED_VIRTUAL_SERVER_MANIFEST_ID) {\n const { methods, httpHandlers, seoMetadata, middleware, workers } = scanServerExports(root);\n const pages = getPageManifest();\n const pageRoutePatterns = scanPageRoutePatterns(root, pages);\n const ssrPages = scanSSRPages(root, pages);\n const appShell = scanAppShell(root);\n return generateServerManifest(methods, httpHandlers, seoMetadata, pageRoutePatterns, ssrPages, appShell, middleware, workers, pages);\n }\n if (id === RESOLVED_VIRTUAL_ENTRY_MODULE_ID + \".tsx\") {\n return generateEntryModule(scanAppShell(root));\n }\n },\n buildStart() {\n generateProjectRpc();\n\n // Check for route collisions in pages directory\n pageManifest = undefined;\n checkRouteCollisions(root, getPageManifest());\n },\n configureServer(server) {\n // Vite's SPA fallback runs after static/public assets and preserves request URLs.\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 () => {\n try {\n if (generateProjectRpc()) {\n const generatedFile = normalizeToPosix(path.join(root, RPC_MODULE_PATH));\n for (const environment of [server.environments.client, server.environments.ssr]) {\n const graph = environment?.moduleGraph;\n for (const module of graph?.getModulesByFile(generatedFile) ?? []) {\n graph?.invalidateModule(module);\n }\n }\n }\n } catch (error) {\n log(\"error\", \"Failed to regenerate RPC imports\", error);\n }\n\n // Invalidate the virtual modules so they get regenerated\n pageManifest = undefined;\n const clientPages = server.environments.client?.moduleGraph.getModuleById(RESOLVED_PAGE_MODULES_ID);\n const serverModule = server.environments.ssr?.moduleGraph.getModuleById(RESOLVED_VIRTUAL_SERVER_MANIFEST_ID);\n if (clientPages) {\n server.environments.client?.moduleGraph.invalidateModule(clientPages);\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 mod.pageRoutes\n );\n }\n } catch (e) {\n log(\"error\", \"Failed to reload Helium server manifest\", e);\n }\n\n // Refresh the browser after the server manifest has reloaded.\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 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 const refreshManifest = (file: string) => {\n if (!affectsManifest(file)) {\n return;\n }\n if (debounceTimer) {\n clearTimeout(debounceTimer);\n }\n debounceTimer = setTimeout(() => {\n debounceTimer = null;\n void handleServerFileChange();\n }, DEBOUNCE_DELAY);\n };\n server.watcher.on(\"change\", refreshManifest);\n server.watcher.on(\"add\", refreshManifest);\n server.watcher.on(\"unlink\", refreshManifest);\n\n server.httpServer?.once(\"close\", () => {\n if (debounceTimer) {\n clearTimeout(debounceTimer);\n }\n });\n\n if (!server.httpServer) {\n // Middleware mode has no Vite-owned HTTP server to attach to.\n return;\n }\n\n const httpServer = server.httpServer;\n let initialized = false;\n let initialization: Promise<void> | undefined;\n const initialize = () => {\n initialization ??= (async () => {\n const config = await loadConfig(root);\n const mod = await server.ssrLoadModule(VIRTUAL_SERVER_MANIFEST_ID);\n attachToDevServer(\n httpServer,\n (registry, httpRouter, seoRouter) => {\n mod.registerAll(registry);\n httpRouter.registerRoutes(mod.httpHandlers || []);\n seoRouter.registerRoutes(mod.seoMetadataHandlers || []);\n seoRouter.setPageRoutePatterns(mod.pageRoutePatterns || []);\n if (mod.middlewareHandler) {\n registry.setMiddleware(mod.middlewareHandler);\n httpRouter.setMiddleware(mod.middlewareHandler);\n }\n },\n config,\n mod.workers || [],\n mod.ssrPages || [],\n mod.appShell || null,\n mod.pageRoutes\n );\n initialized = true;\n })();\n return initialization;\n };\n\n // Vite initializes plugin containers and dependency optimizers as it\n // starts listening. Do not load the SSR manifest before that work.\n // Requests accepted during loading must wait without reading bodies.\n server.middlewares.use((req, res, next) => {\n if (initialized) {\n next();\n return;\n }\n void initialize().then(\n () => {\n if (!res.destroyed && !res.writableEnded) {\n // The request entered Connect before Helium attached.\n // Dispatch it through the newly installed HTTP handler.\n // Its Connect fallback passes this gate immediately\n // because initialized is now true.\n httpServer.emit(\"request\", req, res);\n }\n },\n () => {\n if (!res.destroyed && !res.writableEnded) {\n res.writeHead(503, { \"Content-Type\": \"text/plain\", \"Cache-Control\": \"no-store\" });\n res.end(\"Helium server initialization failed\");\n }\n }\n );\n });\n\n // Native callers can start httpServer directly; the shared promise\n // protects those requests too. Public Vite listen() must not resolve\n // and advertise readiness until registration has completed.\n httpServer.once(\"listening\", () => {\n void initialize().catch((error) => log(\"error\", \"Failed to attach Helium RPC server\", error));\n });\n const listen = server.listen.bind(server);\n server.listen = async (...args) => {\n const listeningServer = await listen(...args);\n await initialize();\n return listeningServer;\n };\n },\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"]}
@@ -1,8 +1,6 @@
1
1
  export declare const SERVER_DIR = "src/server";
2
- export declare const VIRTUAL_CLIENT_MODULE_ID = "heliumts/server";
3
2
  export declare const VIRTUAL_SERVER_MANIFEST_ID = "heliumts/__serverManifest";
4
3
  export declare const VIRTUAL_ENTRY_MODULE_ID = "virtual:heliumts/entry";
5
- export declare const RESOLVED_VIRTUAL_CLIENT_MODULE_ID: string;
6
4
  export declare const RESOLVED_VIRTUAL_SERVER_MANIFEST_ID: string;
7
5
  export declare const RESOLVED_VIRTUAL_ENTRY_MODULE_ID: string;
8
6
  //# sourceMappingURL=paths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/vite/paths.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,wBAAwB,oBAAoB,CAAC;AAC1D,eAAO,MAAM,0BAA0B,8BAA8B,CAAC;AACtE,eAAO,MAAM,uBAAuB,2BAA2B,CAAC;AAEhE,eAAO,MAAM,iCAAiC,QAAkC,CAAC;AACjF,eAAO,MAAM,mCAAmC,QAAoC,CAAC;AACrF,eAAO,MAAM,gCAAgC,QAAiC,CAAC"}
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/vite/paths.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,0BAA0B,8BAA8B,CAAC;AACtE,eAAO,MAAM,uBAAuB,2BAA2B,CAAC;AAEhE,eAAO,MAAM,mCAAmC,QAAoC,CAAC;AACrF,eAAO,MAAM,gCAAgC,QAAiC,CAAC"}
@@ -1,8 +1,6 @@
1
1
  export const SERVER_DIR = "src/server";
2
- export const VIRTUAL_CLIENT_MODULE_ID = "heliumts/server";
3
2
  export const VIRTUAL_SERVER_MANIFEST_ID = "heliumts/__serverManifest";
4
3
  export const VIRTUAL_ENTRY_MODULE_ID = "virtual:heliumts/entry";
5
- export const RESOLVED_VIRTUAL_CLIENT_MODULE_ID = "\0" + VIRTUAL_CLIENT_MODULE_ID;
6
4
  export const RESOLVED_VIRTUAL_SERVER_MANIFEST_ID = "\0" + VIRTUAL_SERVER_MANIFEST_ID;
7
5
  export const RESOLVED_VIRTUAL_ENTRY_MODULE_ID = "\0" + VIRTUAL_ENTRY_MODULE_ID;
8
6
  //# sourceMappingURL=paths.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/vite/paths.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AACvC,MAAM,CAAC,MAAM,wBAAwB,GAAG,iBAAiB,CAAC;AAC1D,MAAM,CAAC,MAAM,0BAA0B,GAAG,2BAA2B,CAAC;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAEhE,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,GAAG,wBAAwB,CAAC;AACjF,MAAM,CAAC,MAAM,mCAAmC,GAAG,IAAI,GAAG,0BAA0B,CAAC;AACrF,MAAM,CAAC,MAAM,gCAAgC,GAAG,IAAI,GAAG,uBAAuB,CAAC","sourcesContent":["export const SERVER_DIR = \"src/server\";\nexport const VIRTUAL_CLIENT_MODULE_ID = \"heliumts/server\";\nexport const VIRTUAL_SERVER_MANIFEST_ID = \"heliumts/__serverManifest\";\nexport const VIRTUAL_ENTRY_MODULE_ID = \"virtual:heliumts/entry\";\n\nexport const RESOLVED_VIRTUAL_CLIENT_MODULE_ID = \"\\0\" + VIRTUAL_CLIENT_MODULE_ID;\nexport const RESOLVED_VIRTUAL_SERVER_MANIFEST_ID = \"\\0\" + VIRTUAL_SERVER_MANIFEST_ID;\nexport const RESOLVED_VIRTUAL_ENTRY_MODULE_ID = \"\\0\" + VIRTUAL_ENTRY_MODULE_ID;\n"]}
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/vite/paths.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AACvC,MAAM,CAAC,MAAM,0BAA0B,GAAG,2BAA2B,CAAC;AACtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAEhE,MAAM,CAAC,MAAM,mCAAmC,GAAG,IAAI,GAAG,0BAA0B,CAAC;AACrF,MAAM,CAAC,MAAM,gCAAgC,GAAG,IAAI,GAAG,uBAAuB,CAAC","sourcesContent":["export const SERVER_DIR = \"src/server\";\nexport const VIRTUAL_SERVER_MANIFEST_ID = \"heliumts/__serverManifest\";\nexport const VIRTUAL_ENTRY_MODULE_ID = \"virtual:heliumts/entry\";\n\nexport const RESOLVED_VIRTUAL_SERVER_MANIFEST_ID = \"\\0\" + VIRTUAL_SERVER_MANIFEST_ID;\nexport const RESOLVED_VIRTUAL_ENTRY_MODULE_ID = \"\\0\" + VIRTUAL_ENTRY_MODULE_ID;\n"]}
@@ -0,0 +1,10 @@
1
+ export interface DiscoveredExport {
2
+ name: string;
3
+ filePath: string;
4
+ factory: string;
5
+ origin: string;
6
+ location: string;
7
+ }
8
+ /** Parse declarations, never import or execute application modules. */
9
+ export declare function discoverExports(files: Map<string, string>): DiscoveredExport[];
10
+ //# sourceMappingURL=rpcDiscovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpcDiscovery.d.ts","sourceRoot":"","sources":["../../src/vite/rpcDiscovery.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAcD,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB,EAAE,CA2O9E"}
@@ -0,0 +1,237 @@
1
+ import path from "path";
2
+ import ts from "typescript";
3
+ const factories = new Set(["defineMethod", "defineHTTPRequest", "defineSEOMetadata", "defineWorker", "middleware", "defineMiddleware"]);
4
+ /** All bound identifiers matter for shadowing, even when they are not RPCs. */
5
+ function bindingNames(name) {
6
+ if (ts.isIdentifier(name)) {
7
+ return [name.text];
8
+ }
9
+ return name.elements.flatMap((element) => (ts.isOmittedExpression(element) ? [] : bindingNames(element.name)));
10
+ }
11
+ function declarationExportName(statement) {
12
+ return statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) ? "default" : statement.name?.text;
13
+ }
14
+ /** Parse declarations, never import or execute application modules. */
15
+ export function discoverExports(files) {
16
+ const modules = new Map([...files].map(([file, source]) => [file, ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true)]));
17
+ for (const [file, source] of modules) {
18
+ // The parser records syntax errors without resolving imports or evaluating code.
19
+ const diagnostics = source.parseDiagnostics;
20
+ if (diagnostics.length) {
21
+ const error = diagnostics[0];
22
+ const position = source.getLineAndCharacterOfPosition(error.start ?? 0);
23
+ throw new Error(`${file}:${position.line + 1}:${position.character + 1}: ${ts.flattenDiagnosticMessageText(error.messageText, "\n")}`);
24
+ }
25
+ }
26
+ const result = [];
27
+ const resolveFile = (from, specifier) => {
28
+ if (!specifier.startsWith(".")) {
29
+ return undefined;
30
+ }
31
+ const base = path.resolve(path.dirname(from), specifier);
32
+ return [base, ...[".ts", ".tsx", ".js", ".jsx", ".mts", ".mjs", "/index.ts", "/index.js"].map((ext) => base + ext), base.replace(/\.[cm]?js$/, ".ts")].find((file) => modules.has(file));
33
+ };
34
+ function resolve(file, name, exported, seen = new Set()) {
35
+ const key = `${file}:${exported}:${name}`;
36
+ if (seen.has(key)) {
37
+ return;
38
+ }
39
+ seen = new Set(seen).add(key);
40
+ const source = modules.get(file);
41
+ function expression(node) {
42
+ if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isTypeAssertionExpression(node)) {
43
+ return expression(node.expression);
44
+ }
45
+ if (ts.isIdentifier(node)) {
46
+ return resolve(file, node.text, false, seen);
47
+ }
48
+ if (!ts.isCallExpression(node)) {
49
+ return;
50
+ }
51
+ const callee = node.expression;
52
+ let factory;
53
+ if (ts.isIdentifier(callee)) {
54
+ for (const statement of source.statements) {
55
+ if (!ts.isImportDeclaration(statement) ||
56
+ !ts.isStringLiteral(statement.moduleSpecifier) ||
57
+ statement.moduleSpecifier.text !== "heliumts/server" ||
58
+ statement.importClause?.isTypeOnly) {
59
+ continue;
60
+ }
61
+ const bindings = statement.importClause?.namedBindings;
62
+ if (bindings && ts.isNamedImports(bindings)) {
63
+ const binding = bindings.elements.find((item) => !item.isTypeOnly && item.name.text === callee.text);
64
+ if (binding) {
65
+ factory = (binding.propertyName ?? binding.name).text;
66
+ }
67
+ }
68
+ }
69
+ // Preserve bare factory declarations used by generated sources, but never
70
+ // mistake an explicitly declared/imported unrelated function for Helium.
71
+ if (!factory &&
72
+ factories.has(callee.text) &&
73
+ !source.statements.some((statement) => ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) &&
74
+ statement.name?.text === callee.text) ||
75
+ (ts.isImportDeclaration(statement) && statement.importClause?.name?.text === callee.text) ||
76
+ (ts.isImportDeclaration(statement) &&
77
+ statement.importClause?.namedBindings &&
78
+ ts.isNamespaceImport(statement.importClause.namedBindings) &&
79
+ statement.importClause.namedBindings.name.text === callee.text) ||
80
+ (ts.isVariableStatement(statement) && statement.declarationList.declarations.some((d) => bindingNames(d.name).includes(callee.text))) ||
81
+ (ts.isImportDeclaration(statement) &&
82
+ statement.importClause?.namedBindings &&
83
+ ts.isNamedImports(statement.importClause.namedBindings) &&
84
+ statement.importClause.namedBindings.elements.some((b) => b.name.text === callee.text)))) {
85
+ factory = callee.text;
86
+ }
87
+ }
88
+ else if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) {
89
+ const namespace = callee.expression.text;
90
+ if (source.statements.some((statement) => ts.isImportDeclaration(statement) &&
91
+ ts.isStringLiteral(statement.moduleSpecifier) &&
92
+ statement.moduleSpecifier.text === "heliumts/server" &&
93
+ !statement.importClause?.isTypeOnly &&
94
+ statement.importClause?.namedBindings &&
95
+ ts.isNamespaceImport(statement.importClause.namedBindings) &&
96
+ statement.importClause.namedBindings.name.text === namespace)) {
97
+ factory = callee.name.text;
98
+ }
99
+ }
100
+ if (factory && factories.has(factory)) {
101
+ const position = source.getLineAndCharacterOfPosition(node.getStart(source));
102
+ return { factory, origin: `${file}:${node.pos}`, location: `${file}:${position.line + 1}:${position.character + 1}` };
103
+ }
104
+ }
105
+ for (const statement of source.statements) {
106
+ if (exported &&
107
+ (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) &&
108
+ declarationExportName(statement) === name &&
109
+ statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {
110
+ return; // Explicit non-RPC declarations also shadow star exports.
111
+ }
112
+ if (ts.isVariableStatement(statement) && (!exported || statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword))) {
113
+ for (const declaration of statement.declarationList.declarations) {
114
+ if (bindingNames(declaration.name).includes(name)) {
115
+ return ts.isIdentifier(declaration.name) && declaration.initializer ? expression(declaration.initializer) : undefined;
116
+ }
117
+ }
118
+ }
119
+ if (exported && name === "default" && ts.isExportAssignment(statement) && !statement.isExportEquals) {
120
+ return expression(statement.expression);
121
+ }
122
+ if (exported && ts.isExportDeclaration(statement) && !statement.isTypeOnly) {
123
+ const target = statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier) ? resolveFile(file, statement.moduleSpecifier.text) : undefined;
124
+ if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {
125
+ const binding = statement.exportClause.elements.find((item) => !item.isTypeOnly && item.name.text === name);
126
+ if (binding) {
127
+ if (statement.moduleSpecifier && !target) {
128
+ return;
129
+ }
130
+ return resolve(target ?? file, (binding.propertyName ?? binding.name).text, !!target, seen);
131
+ }
132
+ }
133
+ else if (statement.exportClause && ts.isNamespaceExport(statement.exportClause) && statement.exportClause.name.text === name) {
134
+ return; // An explicit namespace export shadows any star export.
135
+ }
136
+ }
137
+ if (!exported && ts.isImportDeclaration(statement) && !statement.importClause?.isTypeOnly && ts.isStringLiteral(statement.moduleSpecifier)) {
138
+ const target = resolveFile(file, statement.moduleSpecifier.text);
139
+ if (target && statement.importClause?.name?.text === name) {
140
+ return resolve(target, "default", true, seen);
141
+ }
142
+ const bindings = statement.importClause?.namedBindings;
143
+ if (target && bindings && ts.isNamedImports(bindings)) {
144
+ const binding = bindings.elements.find((item) => !item.isTypeOnly && item.name.text === name);
145
+ if (binding) {
146
+ return resolve(target, (binding.propertyName ?? binding.name).text, true, seen);
147
+ }
148
+ }
149
+ }
150
+ }
151
+ // ESM explicit exports win regardless of declaration order. Resolve stars only
152
+ // after checking all explicit exports, and omit ambiguous star bindings.
153
+ let candidate;
154
+ let matched = false;
155
+ if (exported && name !== "default") {
156
+ for (const statement of source.statements) {
157
+ if (!ts.isExportDeclaration(statement) ||
158
+ statement.isTypeOnly ||
159
+ statement.exportClause ||
160
+ !statement.moduleSpecifier ||
161
+ !ts.isStringLiteral(statement.moduleSpecifier)) {
162
+ continue;
163
+ }
164
+ const target = resolveFile(file, statement.moduleSpecifier.text);
165
+ if (!target || !names(target).has(name)) {
166
+ continue;
167
+ }
168
+ const found = resolve(target, name, true, seen);
169
+ if (matched && (!found || !candidate || found.origin !== candidate.origin)) {
170
+ return;
171
+ }
172
+ matched = true;
173
+ candidate = found;
174
+ }
175
+ }
176
+ return candidate;
177
+ }
178
+ function names(file, seen = new Set()) {
179
+ if (seen.has(file)) {
180
+ return new Set();
181
+ }
182
+ seen = new Set(seen).add(file);
183
+ const found = new Set();
184
+ for (const statement of modules.get(file).statements) {
185
+ if (ts.isVariableStatement(statement) && statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {
186
+ for (const d of statement.declarationList.declarations) {
187
+ for (const name of bindingNames(d.name)) {
188
+ found.add(name);
189
+ }
190
+ }
191
+ }
192
+ else if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) &&
193
+ statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
194
+ const name = declarationExportName(statement);
195
+ if (name) {
196
+ found.add(name);
197
+ }
198
+ }
199
+ else if (ts.isExportAssignment(statement)) {
200
+ found.add("default");
201
+ }
202
+ else if (ts.isExportDeclaration(statement) && !statement.isTypeOnly) {
203
+ if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {
204
+ for (const binding of statement.exportClause.elements) {
205
+ if (!binding.isTypeOnly) {
206
+ found.add(binding.name.text);
207
+ }
208
+ }
209
+ }
210
+ else if (statement.exportClause && ts.isNamespaceExport(statement.exportClause)) {
211
+ found.add(statement.exportClause.name.text);
212
+ }
213
+ else if (!statement.exportClause && statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier)) {
214
+ const target = resolveFile(file, statement.moduleSpecifier.text);
215
+ if (target) {
216
+ for (const name of names(target, seen)) {
217
+ if (name !== "default") {
218
+ found.add(name);
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+ return found;
226
+ }
227
+ for (const file of modules.keys()) {
228
+ for (const name of names(file)) {
229
+ const found = resolve(file, name, true);
230
+ if (found) {
231
+ result.push({ name, filePath: file, ...found });
232
+ }
233
+ }
234
+ }
235
+ return result;
236
+ }
237
+ //# sourceMappingURL=rpcDiscovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpcDiscovery.js","sourceRoot":"","sources":["../../src/vite/rpcDiscovery.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,CAAC,CAAC,CAAC;AASxI,+EAA+E;AAC/E,SAAS,YAAY,CAAC,IAAoB;IACtC,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACnH,CAAC;AAED,SAAS,qBAAqB,CAAC,SAA4E;IACvG,OAAO,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ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nconst factories = new Set([\"defineMethod\", \"defineHTTPRequest\", \"defineSEOMetadata\", \"defineWorker\", \"middleware\", \"defineMiddleware\"]);\nexport interface DiscoveredExport {\n name: string;\n filePath: string;\n factory: string;\n origin: string;\n location: string;\n}\n\n/** All bound identifiers matter for shadowing, even when they are not RPCs. */\nfunction bindingNames(name: ts.BindingName): string[] {\n if (ts.isIdentifier(name)) {\n return [name.text];\n }\n return name.elements.flatMap((element) => (ts.isOmittedExpression(element) ? [] : bindingNames(element.name)));\n}\n\nfunction declarationExportName(statement: ts.FunctionDeclaration | ts.ClassDeclaration | ts.EnumDeclaration): string | undefined {\n return statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) ? \"default\" : statement.name?.text;\n}\n\n/** Parse declarations, never import or execute application modules. */\nexport function discoverExports(files: Map<string, string>): DiscoveredExport[] {\n const modules = new Map([...files].map(([file, source]) => [file, ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true)]));\n for (const [file, source] of modules) {\n // The parser records syntax errors without resolving imports or evaluating code.\n const diagnostics = (source as ts.SourceFile & { parseDiagnostics: readonly ts.DiagnosticWithLocation[] }).parseDiagnostics;\n if (diagnostics.length) {\n const error = diagnostics[0];\n const position = source.getLineAndCharacterOfPosition(error.start ?? 0);\n throw new Error(`${file}:${position.line + 1}:${position.character + 1}: ${ts.flattenDiagnosticMessageText(error.messageText, \"\\n\")}`);\n }\n }\n const result: DiscoveredExport[] = [];\n const resolveFile = (from: string, specifier: string) => {\n if (!specifier.startsWith(\".\")) {\n return undefined;\n }\n const base = path.resolve(path.dirname(from), specifier);\n return [base, ...[\".ts\", \".tsx\", \".js\", \".jsx\", \".mts\", \".mjs\", \"/index.ts\", \"/index.js\"].map((ext) => base + ext), base.replace(/\\.[cm]?js$/, \".ts\")].find((file) =>\n modules.has(file)\n );\n };\n type Found = { factory: string; origin: string; location: string };\n function resolve(file: string, name: string, exported: boolean, seen = new Set<string>()): Found | undefined {\n const key = `${file}:${exported}:${name}`;\n if (seen.has(key)) {\n return;\n }\n seen = new Set(seen).add(key);\n const source = modules.get(file)!;\n function expression(node: ts.Expression): Found | undefined {\n if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isTypeAssertionExpression(node)) {\n return expression(node.expression);\n }\n if (ts.isIdentifier(node)) {\n return resolve(file, node.text, false, seen);\n }\n if (!ts.isCallExpression(node)) {\n return;\n }\n const callee = node.expression;\n let factory: string | undefined;\n if (ts.isIdentifier(callee)) {\n for (const statement of source.statements) {\n if (\n !ts.isImportDeclaration(statement) ||\n !ts.isStringLiteral(statement.moduleSpecifier) ||\n statement.moduleSpecifier.text !== \"heliumts/server\" ||\n statement.importClause?.isTypeOnly\n ) {\n continue;\n }\n const bindings = statement.importClause?.namedBindings;\n if (bindings && ts.isNamedImports(bindings)) {\n const binding = bindings.elements.find((item) => !item.isTypeOnly && item.name.text === callee.text);\n if (binding) {\n factory = (binding.propertyName ?? binding.name).text;\n }\n }\n }\n // Preserve bare factory declarations used by generated sources, but never\n // mistake an explicitly declared/imported unrelated function for Helium.\n if (\n !factory &&\n factories.has(callee.text) &&\n !source.statements.some(\n (statement) =>\n ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) &&\n statement.name?.text === callee.text) ||\n (ts.isImportDeclaration(statement) && statement.importClause?.name?.text === callee.text) ||\n (ts.isImportDeclaration(statement) &&\n statement.importClause?.namedBindings &&\n ts.isNamespaceImport(statement.importClause.namedBindings) &&\n statement.importClause.namedBindings.name.text === callee.text) ||\n (ts.isVariableStatement(statement) && statement.declarationList.declarations.some((d) => bindingNames(d.name).includes(callee.text))) ||\n (ts.isImportDeclaration(statement) &&\n statement.importClause?.namedBindings &&\n ts.isNamedImports(statement.importClause.namedBindings) &&\n statement.importClause.namedBindings.elements.some((b) => b.name.text === callee.text))\n )\n ) {\n factory = callee.text;\n }\n } else if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) {\n const namespace = callee.expression.text;\n if (\n source.statements.some(\n (statement) =>\n ts.isImportDeclaration(statement) &&\n ts.isStringLiteral(statement.moduleSpecifier) &&\n statement.moduleSpecifier.text === \"heliumts/server\" &&\n !statement.importClause?.isTypeOnly &&\n statement.importClause?.namedBindings &&\n ts.isNamespaceImport(statement.importClause.namedBindings) &&\n statement.importClause.namedBindings.name.text === namespace\n )\n ) {\n factory = callee.name.text;\n }\n }\n if (factory && factories.has(factory)) {\n const position = source.getLineAndCharacterOfPosition(node.getStart(source));\n return { factory, origin: `${file}:${node.pos}`, location: `${file}:${position.line + 1}:${position.character + 1}` };\n }\n }\n for (const statement of source.statements) {\n if (\n exported &&\n (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) &&\n declarationExportName(statement) === name &&\n statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)\n ) {\n return; // Explicit non-RPC declarations also shadow star exports.\n }\n if (ts.isVariableStatement(statement) && (!exported || statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword))) {\n for (const declaration of statement.declarationList.declarations) {\n if (bindingNames(declaration.name).includes(name)) {\n return ts.isIdentifier(declaration.name) && declaration.initializer ? expression(declaration.initializer) : undefined;\n }\n }\n }\n if (exported && name === \"default\" && ts.isExportAssignment(statement) && !statement.isExportEquals) {\n return expression(statement.expression);\n }\n if (exported && ts.isExportDeclaration(statement) && !statement.isTypeOnly) {\n const target = statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier) ? resolveFile(file, statement.moduleSpecifier.text) : undefined;\n if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {\n const binding = statement.exportClause.elements.find((item) => !item.isTypeOnly && item.name.text === name);\n if (binding) {\n if (statement.moduleSpecifier && !target) {\n return;\n }\n return resolve(target ?? file, (binding.propertyName ?? binding.name).text, !!target, seen);\n }\n } else if (statement.exportClause && ts.isNamespaceExport(statement.exportClause) && statement.exportClause.name.text === name) {\n return; // An explicit namespace export shadows any star export.\n }\n }\n if (!exported && ts.isImportDeclaration(statement) && !statement.importClause?.isTypeOnly && ts.isStringLiteral(statement.moduleSpecifier)) {\n const target = resolveFile(file, statement.moduleSpecifier.text);\n if (target && statement.importClause?.name?.text === name) {\n return resolve(target, \"default\", true, seen);\n }\n const bindings = statement.importClause?.namedBindings;\n if (target && bindings && ts.isNamedImports(bindings)) {\n const binding = bindings.elements.find((item) => !item.isTypeOnly && item.name.text === name);\n if (binding) {\n return resolve(target, (binding.propertyName ?? binding.name).text, true, seen);\n }\n }\n }\n }\n // ESM explicit exports win regardless of declaration order. Resolve stars only\n // after checking all explicit exports, and omit ambiguous star bindings.\n let candidate: Found | undefined;\n let matched = false;\n if (exported && name !== \"default\") {\n for (const statement of source.statements) {\n if (\n !ts.isExportDeclaration(statement) ||\n statement.isTypeOnly ||\n statement.exportClause ||\n !statement.moduleSpecifier ||\n !ts.isStringLiteral(statement.moduleSpecifier)\n ) {\n continue;\n }\n const target = resolveFile(file, statement.moduleSpecifier.text);\n if (!target || !names(target).has(name)) {\n continue;\n }\n const found = resolve(target, name, true, seen);\n if (matched && (!found || !candidate || found.origin !== candidate.origin)) {\n return;\n }\n matched = true;\n candidate = found;\n }\n }\n return candidate;\n }\n function names(file: string, seen = new Set<string>()): Set<string> {\n if (seen.has(file)) {\n return new Set();\n }\n seen = new Set(seen).add(file);\n const found = new Set<string>();\n for (const statement of modules.get(file)!.statements) {\n if (ts.isVariableStatement(statement) && statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {\n for (const d of statement.declarationList.declarations) {\n for (const name of bindingNames(d.name)) {\n found.add(name);\n }\n }\n } else if (\n (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) &&\n statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)\n ) {\n const name = declarationExportName(statement);\n if (name) {\n found.add(name);\n }\n } else if (ts.isExportAssignment(statement)) {\n found.add(\"default\");\n } else if (ts.isExportDeclaration(statement) && !statement.isTypeOnly) {\n if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {\n for (const binding of statement.exportClause.elements) {\n if (!binding.isTypeOnly) {\n found.add(binding.name.text);\n }\n }\n } else if (statement.exportClause && ts.isNamespaceExport(statement.exportClause)) {\n found.add(statement.exportClause.name.text);\n } else if (!statement.exportClause && statement.moduleSpecifier && ts.isStringLiteral(statement.moduleSpecifier)) {\n const target = resolveFile(file, statement.moduleSpecifier.text);\n if (target) {\n for (const name of names(target, seen)) {\n if (name !== \"default\") {\n found.add(name);\n }\n }\n }\n }\n }\n }\n return found;\n }\n for (const file of modules.keys()) {\n for (const name of names(file)) {\n const found = resolve(file, name, true);\n if (found) {\n result.push({ name, filePath: file, ...found });\n }\n }\n }\n return result;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { MethodExport } from "./scanner.js";
2
+ export declare const RPC_MODULE_PATH = "src/rpc.generated.ts";
3
+ export declare function writeRpcModule(root: string, methods: readonly MethodExport[]): boolean;
4
+ //# sourceMappingURL=rpcModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpcModule.d.ts","sourceRoot":"","sources":["../../src/vite/rpcModule.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,eAAO,MAAM,eAAe,yBAAyB,CAAC;AAkDtD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAatF"}
@@ -0,0 +1,64 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ export const RPC_MODULE_PATH = "src/rpc.generated.ts";
5
+ const RPC_MODULE_HEADER = "// Auto-generated by HeliumTS. Do not edit.";
6
+ function generateRpcModule(methods, root) {
7
+ if (!methods.length) {
8
+ return `${RPC_MODULE_HEADER}\nexport {};\n`;
9
+ }
10
+ const sorted = [...methods].sort((a, b) => a.name.localeCompare(b.name));
11
+ let prefix = "__helium_method_";
12
+ while (sorted.some(({ name }) => name.startsWith(prefix))) {
13
+ prefix = "_" + prefix;
14
+ }
15
+ const imports = [];
16
+ const references = [];
17
+ for (const [index, { name, filePath }] of sorted.entries()) {
18
+ const alias = `${prefix}${index}`;
19
+ const relativePath = path.relative(path.join(root, "src"), filePath).split(path.sep).join("/");
20
+ const specifier = JSON.stringify("./" + relativePath);
21
+ imports.push(`import type { ${name} as ${alias} } from ${specifier};`);
22
+ references.push(`export const ${name} = { __id: ${JSON.stringify(name)} } as unknown as import("heliumts/client").MethodReference<
23
+ Parameters<typeof ${alias}["handler"]>[0],
24
+ Awaited<ReturnType<typeof ${alias}["handler"]>>
25
+ >;`);
26
+ }
27
+ return `${RPC_MODULE_HEADER}\n/* eslint-disable */\n${imports.join("\n")}\n\n${references.join("\n\n")}\n`;
28
+ }
29
+ function readIfPresent(file) {
30
+ try {
31
+ return fs.readFileSync(file, "utf8");
32
+ }
33
+ catch (error) {
34
+ if (error.code !== "ENOENT") {
35
+ throw error;
36
+ }
37
+ }
38
+ }
39
+ function writeAtomically(file, content) {
40
+ const dir = path.dirname(file);
41
+ fs.mkdirSync(dir, { recursive: true });
42
+ const temporary = path.join(dir, `.${path.basename(file)}.${randomUUID()}.tmp`);
43
+ try {
44
+ fs.writeFileSync(temporary, content, { flag: "wx" });
45
+ fs.renameSync(temporary, file);
46
+ }
47
+ finally {
48
+ fs.rmSync(temporary, { force: true });
49
+ }
50
+ }
51
+ export function writeRpcModule(root, methods) {
52
+ const rpcPath = path.join(root, RPC_MODULE_PATH);
53
+ const existingRpc = readIfPresent(rpcPath);
54
+ if (existingRpc !== undefined && existingRpc.split(/\r?\n/, 1)[0] !== RPC_MODULE_HEADER) {
55
+ throw new Error(`Cannot generate RPC references: ${rpcPath} already exists and was not generated by HeliumTS. Move or rename that file.`);
56
+ }
57
+ const rpcModule = generateRpcModule(methods, root);
58
+ if (existingRpc === rpcModule) {
59
+ return false;
60
+ }
61
+ writeAtomically(rpcPath, rpcModule);
62
+ return true;
63
+ }
64
+ //# sourceMappingURL=rpcModule.js.map