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
package/dist/vite/ssg.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ import { pathFromPageFile } from "../runtime/pageRoutes.js";
3
4
  import { replaceHtmlRootContents } from "../utils/html.js";
4
5
  import { log } from "../utils/logger.js";
5
- import { hasPageDirective, isPageFile, scanAppShell, scanServerExports } from "./scanner.js";
6
- import { generateClientModule } from "./virtualServerModule.js";
6
+ import { findLayoutPathsForPage, scanAppShell, scanPageManifest } from "./scanner.js";
7
+ import { generateServerClientModule, generateServerPrefetchModule, generateServerTransitionsModule } from "./serverClientAdapter.js";
8
+ export { findLayoutPathsForPage };
7
9
  /**
8
10
  * Remove string literals from content to avoid false positives when checking for patterns
9
11
  * This removes template literals, single-quoted strings, and double-quoted strings
@@ -62,53 +64,27 @@ export function validateSSGPage(filePath) {
62
64
  /**
63
65
  * Scan pages directory and find all pages with "use ssg" directive
64
66
  */
65
- export function scanSSGPages(root) {
66
- const pagesDir = path.join(root, "src", "pages");
67
- if (!fs.existsSync(pagesDir)) {
68
- return [];
69
- }
70
- const ssgPages = [];
71
- function walkDirectory(dir) {
72
- const items = fs.readdirSync(dir);
73
- for (const item of items) {
74
- const fullPath = path.join(dir, item);
75
- const stat = fs.statSync(fullPath);
76
- if (stat.isDirectory()) {
77
- walkDirectory(fullPath);
78
- }
79
- else if (isPageFile(item)) {
80
- const content = fs.readFileSync(fullPath, "utf-8");
81
- // Check for "use ssg"; directive at the top of the file
82
- if (hasPageDirective(content, "use ssg")) {
83
- const relativePath = path.relative(path.join(root, "src"), fullPath);
84
- const urlPath = filePathToUrlPath(relativePath);
85
- // Validate the page for SSG compatibility
86
- const validation = validateSSGPage(fullPath);
87
- const warnings = [...validation.warnings];
88
- // Also check all layouts for this page
89
- const layoutPaths = findLayoutPathsForPage(fullPath, root);
90
- for (const layoutPath of layoutPaths) {
91
- const layoutValidation = validateSSGPage(layoutPath);
92
- if (layoutValidation.warnings.length > 0) {
93
- const layoutRelative = path.relative(path.join(root, "src"), layoutPath);
94
- warnings.push(`Layout ${layoutRelative} has issues:`);
95
- for (const warning of layoutValidation.warnings) {
96
- warnings.push(` └─ ${warning}`);
97
- }
98
- }
99
- }
100
- ssgPages.push({
101
- filePath: fullPath,
102
- urlPath,
103
- relativePath,
104
- warnings,
105
- });
106
- }
67
+ export function scanSSGPages(root, manifest = scanPageManifest(root)) {
68
+ const srcDir = path.join(root, "src");
69
+ return manifest
70
+ .filter((route) => route.render === "ssg")
71
+ .map(({ file, pattern, layouts }) => {
72
+ const { warnings } = validateSSGPage(file);
73
+ for (const layout of layouts) {
74
+ const layoutWarnings = validateSSGPage(layout).warnings;
75
+ if (layoutWarnings.length) {
76
+ warnings.push(`Layout ${path.relative(srcDir, layout)} has issues:`);
77
+ warnings.push(...layoutWarnings.map((warning) => ` └─ ${warning}`));
107
78
  }
108
79
  }
109
- }
110
- walkDirectory(pagesDir);
111
- return ssgPages;
80
+ return {
81
+ filePath: file,
82
+ urlPath: pattern === "__404__" ? "/404" : pattern,
83
+ relativePath: path.relative(srcDir, file),
84
+ warnings,
85
+ layouts,
86
+ };
87
+ });
112
88
  }
113
89
  /**
114
90
  * Convert file path to URL path
@@ -120,27 +96,8 @@ export function scanSSGPages(root) {
120
96
  * @internal Exported for testing
121
97
  */
122
98
  export function filePathToUrlPath(relativePath) {
123
- // Remove 'pages/' prefix and file extension
124
- let urlPath = relativePath
125
- .replace(/\\/g, "/")
126
- .replace(/^pages\//, "")
127
- .replace(/\.(tsx|jsx|ts|js)$/, "");
128
- // Remove route groups (folders in parentheses)
129
- // E.g., (website)/contact -> /contact
130
- urlPath = urlPath.replace(/\([^)]+\)\//g, "");
131
- // Handle index files
132
- if (urlPath.endsWith("/index") || urlPath === "index") {
133
- urlPath = urlPath.replace(/\/index$/, "").replace(/^index$/, "");
134
- }
135
- // Ensure leading slash
136
- if (!urlPath.startsWith("/")) {
137
- urlPath = "/" + urlPath;
138
- }
139
- // Root path
140
- if (urlPath === "/") {
141
- return "/";
142
- }
143
- return urlPath;
99
+ const pattern = pathFromPageFile(relativePath.replace(/\\/g, "/").replace(/^pages\//, ""));
100
+ return pattern === "__404__" ? "/404" : pattern;
144
101
  }
145
102
  /**
146
103
  * Convert URL path to output file path
@@ -157,34 +114,11 @@ export function urlPathToOutputPath(urlPath) {
157
114
  const cleanPath = urlPath.replace(/^\//, "");
158
115
  return `${cleanPath}.html`;
159
116
  }
160
- /**
161
- * Find all layout file paths for a given page path (from root to leaf)
162
- * @internal Exported for testing
163
- */
164
- export function findLayoutPathsForPage(pagePath, root) {
165
- const pagesDir = path.join(root, "src", "pages");
166
- const relativePath = path.relative(pagesDir, pagePath);
167
- const pathParts = path
168
- .dirname(relativePath)
169
- .split(path.sep)
170
- .filter((p) => p !== ".");
171
- const layoutPaths = [];
172
- const layoutNames = ["_layout.tsx", "_layout.jsx", "_layout.ts", "_layout.js"];
173
- for (let i = 0; i <= pathParts.length; i++) {
174
- const dirPath = path.join(pagesDir, ...pathParts.slice(0, i));
175
- const layoutPath = layoutNames.map((name) => path.join(dirPath, name)).find((candidate) => fs.existsSync(candidate));
176
- if (layoutPath) {
177
- layoutPaths.push(layoutPath);
178
- }
179
- }
180
- return layoutPaths;
181
- }
182
117
  /**
183
118
  * Find all layout components for a given page path (from root to leaf)
184
119
  * Note: Layouts cannot use routing features during SSG since they're pre-rendered
185
120
  */
186
- async function findLayoutsForPage(pagePath, root, viteServer) {
187
- const layoutPaths = findLayoutPathsForPage(pagePath, root);
121
+ async function loadLayouts(layoutPaths, viteServer) {
188
122
  const layouts = [];
189
123
  for (const layoutPath of layoutPaths) {
190
124
  try {
@@ -223,7 +157,7 @@ export async function renderPageToHTML(page, root, htmlTemplate, viteServer, tim
223
157
  throw new Error(`No default export found in ${page.relativePath}`);
224
158
  }
225
159
  // Find all layouts (from root to leaf)
226
- const layouts = await findLayoutsForPage(page.filePath, root, viteServer);
160
+ const layouts = await loadLayouts(page.layouts ?? findLayoutPathsForPage(page.filePath, root), viteServer);
227
161
  // Build the component tree: layouts wrap the page, innermost to outermost
228
162
  const pageProps = { params: {}, searchParams: new URLSearchParams() };
229
163
  const WrappedPage = () => {
@@ -278,9 +212,9 @@ export async function renderPageToHTML(page, root, htmlTemplate, viteServer, tim
278
212
  /**
279
213
  * Generate static HTML files for all SSG pages
280
214
  */
281
- export async function generateStaticPages(context, root, htmlTemplate, distDir) {
215
+ export async function generateStaticPages(context, root, htmlTemplate, distDir, manifest) {
282
216
  // Scan for SSG pages
283
- const ssgPages = scanSSGPages(root);
217
+ const ssgPages = scanSSGPages(root, manifest);
284
218
  if (ssgPages.length === 0) {
285
219
  return;
286
220
  }
@@ -292,180 +226,17 @@ export async function generateStaticPages(context, root, htmlTemplate, distDir)
292
226
  }
293
227
  // Filter out dynamic routes
294
228
  const staticPages = ssgPages.filter((p) => !p.relativePath.includes("["));
295
- // Precompute RPC client stubs for SSG (mirrors helium Vite plugin)
296
- const { methods } = scanServerExports(root);
297
- const serverStubCode = `// Auto-generated SSG RPC stub\n${generateClientModule(methods)}\n`;
298
- // Create a stub for heliumts/client that provides mock Router and hooks
299
- const clientStubCode = `
300
- // Auto-generated SSG client stub
301
- import React from 'react';
302
-
303
- // Mock RouterContext
304
- export const RouterContext = React.createContext({
305
- path: '/',
306
- params: {},
307
- searchParams: new URLSearchParams(),
308
- push: () => {},
309
- replace: () => {},
310
- on: () => () => {},
311
- status: 200,
312
- isNavigating: false,
313
- isPending: false,
314
- });
315
-
316
- // Mock useRouter hook
317
- export function useRouter() {
318
- const ctx = React.useContext(RouterContext);
319
- if (!ctx) {
320
- console.warn('useRouter called outside RouterContext during SSG');
321
- return {
322
- path: '/',
323
- params: {},
324
- searchParams: new URLSearchParams(),
325
- push: () => {},
326
- replace: () => {},
327
- on: () => () => {},
328
- status: 200,
329
- isNavigating: false,
330
- isPending: false,
331
- };
332
- }
333
- return ctx;
334
- }
335
-
336
- // Mock AppRouter component (alias for Router)
337
- export function AppRouter({ children }) {
338
- return React.createElement(React.Fragment, null, children);
339
- }
340
-
341
- // Mock Router component
342
- export function Router({ children }) {
343
- return React.createElement(React.Fragment, null, children);
344
- }
345
-
346
- // Mock Link component
347
- export function Link({ href, children, prefetch, ...props }) {
348
- return React.createElement('a', { href, ...props }, children);
349
- }
350
-
351
- // Mock Redirect component
352
- export function Redirect({ to, replace }) {
353
- return null;
354
- }
355
-
356
- // Browser RPC calls may be referenced by handlers but cannot run during SSG.
357
- export async function callMethod() {
358
- throw new Error('callMethod is only available in the browser. Load server data with getServerSideProps instead.');
359
- }
360
-
361
- export function useStreaming() {
362
- return {
363
- chunks: [],
364
- text: '',
365
- isStreaming: false,
366
- error: null,
367
- stats: null,
368
- start: async () => {
369
- throw new Error('useStreaming.start is only available in the browser. Load server data with getServerSideProps instead.');
370
- },
371
- cancel: () => {},
372
- reset: () => {},
373
- };
374
- }
375
-
376
- export function useCall(serverFn) {
377
- return { call: async () => null, isCalling: false, error: null };
378
- }
379
-
380
- // Mock useFetch hook
381
- export function useFetch(serverFn, ...args) {
382
- console.warn('useFetch called during SSG - returning null');
383
- return { data: null, isLoading: false, error: null, refetch: async () => {} };
384
- }
385
-
386
- export function isSSR() { return true; }
387
- export function getPublicEnv() {
388
- return Object.fromEntries(Object.entries(process.env).filter(([key, value]) => key.startsWith('HELIUM_PUBLIC_') && typeof value === 'string'));
389
- }
390
- export function getPublicEnvValue(key) { return getPublicEnv()[key]; }
391
- export function isDevEnvironment() { return false; }
392
- export class RpcError extends Error {}
393
-
394
- // Re-export cache (mock)
395
- export const cache = {
396
- get: () => null,
397
- set: () => {},
398
- delete: () => {},
399
- clear: () => {},
400
- };
401
-
402
- // Mock PageTransition and useDeferredNavigation (also available from heliumts/client/transitions)
403
- export function useDeferredNavigation() {
404
- const { path } = useRouter();
405
- return {
406
- path,
407
- deferredPath: path,
408
- isStale: false,
409
- isPending: false,
410
- isTransitioning: false,
411
- };
412
- }
413
-
414
- export function PageTransition({ children, fallback = null }) {
415
- return React.createElement('div', { style: { opacity: 1, transition: 'opacity 150ms ease' } },
416
- React.createElement(React.Suspense, { fallback }, children));
417
- }
418
- `;
419
- // Create a stub for heliumts/client/transitions
420
- const transitionsStubCode = `
421
- // Auto-generated SSG transitions stub
422
- import React from 'react';
423
- import { useRouter } from 'heliumts/client';
424
-
425
- // Mock useDeferredNavigation hook - returns static values for SSG
426
- export function useDeferredNavigation() {
427
- const { path } = useRouter();
428
- return {
429
- path,
430
- deferredPath: path,
431
- isStale: false,
432
- isPending: false,
433
- isTransitioning: false,
434
- };
435
- }
436
-
437
- // Mock PageTransition component - renders children without transition logic
438
- export function PageTransition({ children, fallback = null }) {
439
- return React.createElement('div', { style: { opacity: 1, transition: 'opacity 150ms ease' } },
440
- React.createElement(React.Suspense, { fallback }, children));
441
- }
442
-
443
- export default {
444
- useDeferredNavigation,
445
- PageTransition,
446
- };
447
- `;
448
- // Create a stub for heliumts/client/prefetch
449
- const prefetchStubCode = `
450
- // Auto-generated SSG prefetch stub
451
- export function prefetchRoute() {
452
- // No-op during SSG
453
- }
454
-
455
- export function clearPrefetchCache() {
456
- // No-op during SSG
457
- }
458
- `;
229
+ const clientStubCode = generateServerClientModule("ssg");
230
+ const transitionsStubCode = generateServerTransitionsModule("ssg");
231
+ const prefetchStubCode = generateServerPrefetchModule();
459
232
  // Write stub files to node_modules/.heliumts
460
233
  const heliumInternalDir = path.join(root, "node_modules", ".heliumts");
461
234
  if (!fs.existsSync(heliumInternalDir)) {
462
235
  fs.mkdirSync(heliumInternalDir, { recursive: true });
463
236
  }
464
- const ssgServerStubPath = path.join(heliumInternalDir, "ssg-server-stub.mjs");
465
237
  const ssgClientStubPath = path.join(heliumInternalDir, "ssg-client-stub.mjs");
466
238
  const ssgTransitionsStubPath = path.join(heliumInternalDir, "ssg-transitions-stub.mjs");
467
239
  const ssgPrefetchStubPath = path.join(heliumInternalDir, "ssg-prefetch-stub.mjs");
468
- fs.writeFileSync(ssgServerStubPath, serverStubCode, "utf-8");
469
240
  fs.writeFileSync(ssgClientStubPath, clientStubCode, "utf-8");
470
241
  fs.writeFileSync(ssgTransitionsStubPath, transitionsStubCode, "utf-8");
471
242
  fs.writeFileSync(ssgPrefetchStubPath, prefetchStubCode, "utf-8");
@@ -484,9 +255,7 @@ export function clearPrefetchCache() {
484
255
  // Most specific aliases first - heliumts/client/transitions and heliumts/client/prefetch
485
256
  { find: /^heliumts\/client\/transitions$/, replacement: ssgTransitionsStubPath },
486
257
  { find: /^heliumts\/client\/prefetch$/, replacement: ssgPrefetchStubPath },
487
- // Then heliumts/client and heliumts/server
488
258
  { find: /^heliumts\/client$/, replacement: ssgClientStubPath },
489
- { find: /^heliumts\/server$/, replacement: ssgServerStubPath },
490
259
  ],
491
260
  },
492
261
  ssr: {
@@ -1 +1 @@
1
- {"version":3,"file":"ssg.js","sourceRoot":"","sources":["../../src/vite/ssg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAuBhE;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IAC/C,0EAA0E;IAC1E,IAAI,MAAM,GAAG,OAAO,CAAC;IAErB,2GAA2G;IAC3G,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAEpD,+BAA+B;IAC/B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAEpD,+BAA+B;IAC/B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAEpD,0EAA0E;IAC1E,mDAAmD;IACnD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAE5C,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC5C,MAAM,UAAU,GAAG,EAAE,CAAC,YA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/C,CAAC;YAED,gDAAgD;YAChD,MAAM,cAAc,GAAG,uBAAuB,CAAC,YAAY,EAAE,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;YACrH,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;YAErD,GAAG,CAAC,MAAM,EAAE,KAAK,gBAAgB,CAAC,MAAM,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;YAC3E,GAAG,CAAC,MAAM,EAAE,KAAK,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAC;QAChF,CAAC;QAED,UAAU;QACV,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACnB,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YAChB,GAAG,CAAC,MAAM,EAAE,sBAAsB,YAAY,oBAAoB,YAAY,cAAc,CAAC,CAAC;QAClG,CAAC;IACL,CAAC;YAAS,CAAC;QACP,yDAAyD;QACzD,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;AACL,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport { replaceHtmlRootContents } from \"../utils/html.js\";\nimport { log } from \"../utils/logger.js\";\nimport { hasPageDirective, isPageFile, scanAppShell, scanServerExports } from \"./scanner.js\";\nimport { generateClientModule } from \"./virtualServerModule.js\";\n\n/**\n * SSG (Static Site Generation) implementation for Helium\n *\n * Scans pages directory for files with \"use ssg\"; directive and generates\n * static HTML for them at build time.\n */\n\ninterface SSGPage {\n filePath: string;\n urlPath: string;\n relativePath: string;\n warnings: string[];\n}\n\ninterface SSGValidation {\n hasHooks: boolean;\n hasClientImports: boolean;\n hasServerImports: boolean;\n warnings: string[];\n}\n\n/**\n * Remove string literals from content to avoid false positives when checking for patterns\n * This removes template literals, single-quoted strings, and double-quoted strings\n * @internal Exported for testing\n */\nexport function stripStringLiterals(content: string): string {\n // Remove template literals (backtick strings) - handle nested expressions\n let result = content;\n\n // Remove template literals with their content (simplified - doesn't handle all edge cases but good enough)\n result = result.replace(/`(?:[^`\\\\]|\\\\.)*`/g, '\"\"');\n\n // Remove double-quoted strings\n result = result.replace(/\"(?:[^\"\\\\]|\\\\.)*\"/g, '\"\"');\n\n // Remove single-quoted strings\n result = result.replace(/'(?:[^'\\\\]|\\\\.)*'/g, \"''\");\n\n // Also remove JSX text content between tags (but not the tags themselves)\n // This helps with cases like <code>useState</code>\n result = result.replace(/>([^<]+)</g, \"><\");\n\n return result;\n}\n\n/**\n * Validate if a page file can be truly statically generated\n * Checks for React hooks and helium imports that would prevent static generation\n * @internal Exported for testing\n */\nexport function validateSSGPage(filePath: string): SSGValidation {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const warnings: string[] = [];\n\n // Strip string literals and JSX text to avoid false positives\n const content = stripStringLiterals(rawContent);\n\n // Check for React hooks (common ones)\n const hookPatterns = [\n /\\buse(State|Effect|Context|Reducer|Callback|Memo|Ref|ImperativeHandle|LayoutEffect|DebugValue)\\s*\\(/,\n /\\buse[A-Z]\\w+\\s*\\(/, // Custom hooks (useXxx) - must be followed by ( to be a call\n ];\n\n const hasHooks = hookPatterns.some((pattern) => pattern.test(content));\n if (hasHooks) {\n warnings.push(\"Page uses React hooks which may cause hydration issues\");\n }\n\n // Check for heliumts/client imports - use raw content since imports should be at top level\n const hasClientImports = /^import\\s+.*from\\s+['\"]heliumts\\/client['\"]/m.test(rawContent);\n if (hasClientImports) {\n warnings.push(\"Page imports from 'heliumts/client' which requires client-side execution\");\n }\n\n // Check for heliumts/server imports - use raw content since imports should be at top level\n const hasServerImports = /^import\\s+.*from\\s+['\"]heliumts\\/server['\"]/m.test(rawContent);\n if (hasServerImports) {\n warnings.push(\"Page imports from 'heliumts/server' which may cause runtime issues\");\n }\n\n return {\n hasHooks,\n hasClientImports,\n hasServerImports,\n warnings,\n };\n}\n\n/**\n * Scan pages directory and find all pages with \"use ssg\" directive\n */\nexport function scanSSGPages(root: string): SSGPage[] {\n const pagesDir = path.join(root, \"src\", \"pages\");\n\n if (!fs.existsSync(pagesDir)) {\n return [];\n }\n\n const ssgPages: SSGPage[] = [];\n\n function walkDirectory(dir: string) {\n const items = fs.readdirSync(dir);\n\n for (const item of items) {\n const fullPath = path.join(dir, item);\n const stat = fs.statSync(fullPath);\n\n if (stat.isDirectory()) {\n walkDirectory(fullPath);\n } else if (isPageFile(item)) {\n const content = fs.readFileSync(fullPath, \"utf-8\");\n\n // Check for \"use ssg\"; directive at the top of the file\n if (hasPageDirective(content, \"use ssg\")) {\n const relativePath = path.relative(path.join(root, \"src\"), fullPath);\n const urlPath = filePathToUrlPath(relativePath);\n\n // Validate the page for SSG compatibility\n const validation = validateSSGPage(fullPath);\n const warnings = [...validation.warnings];\n\n // Also check all layouts for this page\n const layoutPaths = findLayoutPathsForPage(fullPath, root);\n for (const layoutPath of layoutPaths) {\n const layoutValidation = validateSSGPage(layoutPath);\n if (layoutValidation.warnings.length > 0) {\n const layoutRelative = path.relative(path.join(root, \"src\"), layoutPath);\n warnings.push(`Layout ${layoutRelative} has issues:`);\n for (const warning of layoutValidation.warnings) {\n warnings.push(` └─ ${warning}`);\n }\n }\n }\n\n ssgPages.push({\n filePath: fullPath,\n urlPath,\n relativePath,\n warnings,\n });\n }\n }\n }\n }\n\n walkDirectory(pagesDir);\n return ssgPages;\n}\n\n/**\n * Convert file path to URL path\n * pages/index.tsx -> /\n * pages/about.tsx -> /about\n * pages/blog/post.tsx -> /blog/post\n * pages/(website)/contact.tsx -> /contact\n * pages/(portal)/dashboard.tsx -> /dashboard\n * @internal Exported for testing\n */\nexport function filePathToUrlPath(relativePath: string): string {\n // Remove 'pages/' prefix and file extension\n let urlPath = relativePath\n .replace(/\\\\/g, \"/\")\n .replace(/^pages\\//, \"\")\n .replace(/\\.(tsx|jsx|ts|js)$/, \"\");\n\n // Remove route groups (folders in parentheses)\n // E.g., (website)/contact -> /contact\n urlPath = urlPath.replace(/\\([^)]+\\)\\//g, \"\");\n\n // Handle index files\n if (urlPath.endsWith(\"/index\") || urlPath === \"index\") {\n urlPath = urlPath.replace(/\\/index$/, \"\").replace(/^index$/, \"\");\n }\n\n // Ensure leading slash\n if (!urlPath.startsWith(\"/\")) {\n urlPath = \"/\" + urlPath;\n }\n\n // Root path\n if (urlPath === \"/\") {\n return \"/\";\n }\n\n return urlPath;\n}\n\n/**\n * Convert URL path to output file path\n * / -> __index.html (special case - renamed later to prevent conflicts)\n * /about -> about.html\n * /blog/post -> blog/post.html\n * @internal Exported for testing\n */\nexport function urlPathToOutputPath(urlPath: string): string {\n if (urlPath === \"/\") {\n return \"__index.html\";\n }\n\n // Remove leading slash and add .html extension\n const cleanPath = urlPath.replace(/^\\//, \"\");\n return `${cleanPath}.html`;\n}\n\n/**\n * Find all layout file paths for a given page path (from root to leaf)\n * @internal Exported for testing\n */\nexport function findLayoutPathsForPage(pagePath: string, root: string): string[] {\n const pagesDir = path.join(root, \"src\", \"pages\");\n const relativePath = path.relative(pagesDir, pagePath);\n const pathParts = path\n .dirname(relativePath)\n .split(path.sep)\n .filter((p) => p !== \".\");\n\n const layoutPaths: string[] = [];\n\n const layoutNames = [\"_layout.tsx\", \"_layout.jsx\", \"_layout.ts\", \"_layout.js\"];\n for (let i = 0; i <= pathParts.length; i++) {\n const dirPath = path.join(pagesDir, ...pathParts.slice(0, i));\n const layoutPath = layoutNames.map((name) => path.join(dirPath, name)).find((candidate) => fs.existsSync(candidate));\n if (layoutPath) {\n layoutPaths.push(layoutPath);\n }\n }\n\n return layoutPaths;\n}\n\n/**\n * Find all layout components for a given page path (from root to leaf)\n * Note: Layouts cannot use routing features during SSG since they're pre-rendered\n */\nasync function findLayoutsForPage(pagePath: string, root: string, viteServer: any): Promise<any[]> {\n const layoutPaths = findLayoutPathsForPage(pagePath, root);\n const layouts = [];\n\n for (const layoutPath of layoutPaths) {\n try {\n const layoutModule = await viteServer.ssrLoadModule(layoutPath);\n if (layoutModule.default) {\n layouts.push(layoutModule.default);\n }\n } catch (error) {\n log(\"warn\", `Could not load layout at ${layoutPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n return layouts;\n}\n\n/**\n * Render a page component to static HTML using Vite SSR with timeout\n */\nexport async function renderPageToHTML(page: SSGPage, root: string, htmlTemplate: string, viteServer: any, timeout: number = 10000): Promise<string> {\n // Create timeout promise\n let timeoutId: ReturnType<typeof setTimeout>;\n const timeoutPromise = new Promise<string>((_, reject) => {\n timeoutId = setTimeout(() => {\n reject(new Error(`Rendering timeout after ${timeout}ms - page may contain hooks or async operations`));\n }, timeout);\n });\n\n // Create render promise\n const renderPromise = (async () => {\n try {\n // Dynamically import React and ReactDOMServer\n const React = (await import(\"react\")).default;\n const ReactDOMServer = await import(\"react-dom/server\");\n\n // Use Vite's SSR loader to load the page component\n const pageModule = await viteServer.ssrLoadModule(page.filePath);\n const PageComponent = pageModule.default;\n\n if (!PageComponent) {\n throw new Error(`No default export found in ${page.relativePath}`);\n }\n\n // Find all layouts (from root to leaf)\n const layouts = await findLayoutsForPage(page.filePath, root, viteServer);\n\n // Build the component tree: layouts wrap the page, innermost to outermost\n const pageProps = { params: {}, searchParams: new URLSearchParams() };\n const WrappedPage = () => {\n let content: any = React.createElement(PageComponent, pageProps);\n for (let i = layouts.length - 1; i >= 0; i--) {\n content = React.createElement(layouts[i], { children: content });\n }\n return content;\n };\n const appShellPath = scanAppShell(root);\n const appShellModule = appShellPath ? await viteServer.ssrLoadModule(appShellPath) : null;\n const AppShell = appShellModule ? (appShellModule.default ?? appShellModule.App ?? appShellModule.app) : null;\n let element: any = AppShell\n ? React.createElement(AppShell, { Component: WrappedPage, pageProps, children: React.createElement(WrappedPage) })\n : React.createElement(WrappedPage);\n\n // Load RouterContext from our stub\n const heliumClient = await viteServer.ssrLoadModule(\"heliumts/client\");\n const RouterContext = heliumClient.RouterContext;\n\n // Mock Router Context with the page's URL\n const routerValue = {\n path: page.urlPath,\n params: {},\n searchParams: new URLSearchParams(),\n push: () => {},\n replace: () => {},\n on: () => () => {},\n status: 200,\n };\n\n // Wrap with RouterContext\n if (RouterContext) {\n element = React.createElement(RouterContext.Provider, { value: routerValue }, element);\n }\n\n // Render to static HTML\n const markup = ReactDOMServer.renderToString(element);\n\n // Inject the markup into the HTML template with the SSG marker\n const finalHtml = replaceHtmlRootContents(htmlTemplate, markup, { \"data-ssg-page\": page.urlPath, \"data-ssg-failed\": null });\n\n return finalHtml;\n } catch (error) {\n log(\"error\", `Failed to render ${page.relativePath}:`, error);\n throw error; // Don't fallback, let the caller handle the error\n }\n })();\n\n // Race between timeout and render\n try {\n return await Promise.race([renderPromise, timeoutPromise]);\n } finally {\n clearTimeout(timeoutId!);\n }\n}\n\n/**\n * Generate static HTML files for all SSG pages\n */\nexport async function generateStaticPages(context: any, root: string, htmlTemplate: string, distDir: string) {\n // Scan for SSG pages\n const ssgPages = scanSSGPages(root);\n\n if (ssgPages.length === 0) {\n return;\n }\n\n log(\"info\", `Generating ${ssgPages.length} static page(s) for SSG...`);\n\n // Check for dynamic routes (not supported yet)\n const dynamicPages = ssgPages.filter((p) => p.relativePath.includes(\"[\"));\n if (dynamicPages.length > 0) {\n log(\"warn\", `Skipping ${dynamicPages.length} dynamic route(s) - not yet supported:\\n` + dynamicPages.map((p) => ` - ${p.relativePath}`).join(\"\\n\"));\n }\n\n // Filter out dynamic routes\n const staticPages = ssgPages.filter((p) => !p.relativePath.includes(\"[\"));\n\n // Precompute RPC client stubs for SSG (mirrors helium Vite plugin)\n const { methods } = scanServerExports(root);\n const serverStubCode = `// Auto-generated SSG RPC stub\\n${generateClientModule(methods)}\\n`;\n\n // Create a stub for heliumts/client that provides mock Router and hooks\n const clientStubCode = `\n// Auto-generated SSG client stub\nimport React from 'react';\n\n// Mock RouterContext\nexport const RouterContext = React.createContext({\n path: '/',\n params: {},\n searchParams: new URLSearchParams(),\n push: () => {},\n replace: () => {},\n on: () => () => {},\n status: 200,\n isNavigating: false,\n isPending: false,\n});\n\n// Mock useRouter hook\nexport function useRouter() {\n const ctx = React.useContext(RouterContext);\n if (!ctx) {\n console.warn('useRouter called outside RouterContext during SSG');\n return {\n path: '/',\n params: {},\n searchParams: new URLSearchParams(),\n push: () => {},\n replace: () => {},\n on: () => () => {},\n status: 200,\n isNavigating: false,\n isPending: false,\n };\n }\n return ctx;\n}\n\n// Mock AppRouter component (alias for Router)\nexport function AppRouter({ children }) {\n return React.createElement(React.Fragment, null, children);\n}\n\n// Mock Router component\nexport function Router({ children }) {\n return React.createElement(React.Fragment, null, children);\n}\n\n// Mock Link component\nexport function Link({ href, children, prefetch, ...props }) {\n return React.createElement('a', { href, ...props }, children);\n}\n\n// Mock Redirect component\nexport function Redirect({ to, replace }) {\n return null;\n}\n\n// Browser RPC calls may be referenced by handlers but cannot run during SSG.\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(serverFn) {\n return { call: async () => null, isCalling: false, error: null };\n}\n\n// Mock useFetch hook\nexport function useFetch(serverFn, ...args) {\n console.warn('useFetch called during SSG - returning null');\n return { data: null, isLoading: false, error: null, refetch: async () => {} };\n}\n\nexport function isSSR() { return true; }\nexport function getPublicEnv() {\n return Object.fromEntries(Object.entries(process.env).filter(([key, value]) => key.startsWith('HELIUM_PUBLIC_') && typeof value === 'string'));\n}\nexport function getPublicEnvValue(key) { return getPublicEnv()[key]; }\nexport function isDevEnvironment() { return false; }\nexport class RpcError extends Error {}\n\n// Re-export cache (mock)\nexport const cache = {\n get: () => null,\n set: () => {},\n delete: () => {},\n clear: () => {},\n};\n\n// Mock PageTransition and useDeferredNavigation (also available from heliumts/client/transitions)\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 // Create a stub for heliumts/client/transitions\n const transitionsStubCode = `\n// Auto-generated SSG transitions stub\nimport React from 'react';\nimport { useRouter } from 'heliumts/client';\n\n// Mock useDeferredNavigation hook - returns static values for SSG\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\n// Mock PageTransition component - renders children without transition logic\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\nexport default {\n useDeferredNavigation,\n PageTransition,\n};\n`;\n\n // Create a stub for heliumts/client/prefetch\n const prefetchStubCode = `\n// Auto-generated SSG prefetch stub\nexport function prefetchRoute() {\n // No-op during SSG\n}\n\nexport function clearPrefetchCache() {\n // No-op during SSG\n}\n`;\n\n // Write stub files to node_modules/.heliumts\n const heliumInternalDir = path.join(root, \"node_modules\", \".heliumts\");\n if (!fs.existsSync(heliumInternalDir)) {\n fs.mkdirSync(heliumInternalDir, { recursive: true });\n }\n const ssgServerStubPath = path.join(heliumInternalDir, \"ssg-server-stub.mjs\");\n const ssgClientStubPath = path.join(heliumInternalDir, \"ssg-client-stub.mjs\");\n const ssgTransitionsStubPath = path.join(heliumInternalDir, \"ssg-transitions-stub.mjs\");\n const ssgPrefetchStubPath = path.join(heliumInternalDir, \"ssg-prefetch-stub.mjs\");\n fs.writeFileSync(ssgServerStubPath, serverStubCode, \"utf-8\");\n fs.writeFileSync(ssgClientStubPath, clientStubCode, \"utf-8\");\n fs.writeFileSync(ssgTransitionsStubPath, transitionsStubCode, \"utf-8\");\n fs.writeFileSync(ssgPrefetchStubPath, prefetchStubCode, \"utf-8\");\n\n // Create a temporary Vite server for SSR rendering\n const { createServer } = await import(\"vite\");\n const heliumPlugin = (await import(\"./heliumPlugin.js\")).default;\n\n const viteServer = await createServer({\n root,\n mode: \"production\",\n server: { middlewareMode: true },\n appType: \"custom\",\n logLevel: \"error\",\n plugins: [heliumPlugin()],\n resolve: {\n alias: [\n // Most specific aliases first - heliumts/client/transitions and heliumts/client/prefetch\n { find: /^heliumts\\/client\\/transitions$/, replacement: ssgTransitionsStubPath },\n { find: /^heliumts\\/client\\/prefetch$/, replacement: ssgPrefetchStubPath },\n // Then heliumts/client and heliumts/server\n { find: /^heliumts\\/client$/, replacement: ssgClientStubPath },\n { find: /^heliumts\\/server$/, replacement: ssgServerStubPath },\n ],\n },\n ssr: {\n external: [\"react\", \"react-dom\"],\n // Don't externalize heliumts packages - we want to use our stubs\n noExternal: [\"heliumts\"],\n },\n });\n\n try {\n // Generate HTML for each static page\n const zlib = await import(\"zlib\");\n let successCount = 0;\n let failureCount = 0;\n let hasIndexSSG = false;\n\n // Calculate max path length for proper alignment (min 35, max 80)\n const maxPathLength = Math.min(80, Math.max(35, ...staticPages.map((p) => urlPathToOutputPath(p.urlPath).length)));\n\n for (const page of staticPages) {\n try {\n // Render the page component to static HTML using Vite SSR with 10s timeout\n const html = await renderPageToHTML(page, root, htmlTemplate, viteServer, 10000);\n const outputPath = urlPathToOutputPath(page.urlPath);\n const fullOutputPath = path.join(distDir, outputPath);\n\n // Track if the root page (/) has SSG\n if (page.urlPath === \"/\") {\n hasIndexSSG = true;\n }\n\n // Ensure directory exists\n const outputDir = path.dirname(fullOutputPath);\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n // Write the HTML file\n fs.writeFileSync(fullOutputPath, html, \"utf-8\");\n\n // Calculate file size and gzipped size\n const size = Buffer.byteLength(html, \"utf-8\");\n const sizeKB = (size / 1024).toFixed(2);\n\n // Calculate gzipped size\n const gzipped = zlib.gzipSync(html);\n const gzipSizeKB = (gzipped.length / 1024).toFixed(2);\n\n log(\"info\", ` ${outputPath.padEnd(maxPathLength)} ${sizeKB.padStart(8)} kB │ gzip: ${gzipSizeKB.padStart(7)} kB`);\n successCount++;\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : String(error);\n if (errorMsg.includes(\"timeout\")) {\n log(\"error\", ` ✗ ${page.relativePath} - ${errorMsg}`);\n } else {\n log(\"error\", ` ✗ ${page.relativePath} - Failed to generate:`, error);\n }\n\n // Write a fallback HTML file with empty root div (client will hydrate)\n const outputPath = urlPathToOutputPath(page.urlPath);\n const fullOutputPath = path.join(distDir, outputPath);\n const outputDir = path.dirname(fullOutputPath);\n\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n const fallbackHtml = replaceHtmlRootContents(htmlTemplate, \"\", { \"data-ssg-page\": null, \"data-ssg-failed\": page.urlPath });\n fs.writeFileSync(fullOutputPath, fallbackHtml, \"utf-8\");\n\n failureCount++;\n }\n }\n\n // If index page has SSG, we need to handle it specially:\n // 1. Rename __index.html to index.ssg.html (the SSG version)\n // 2. Create a clean blank index.html as fallback for non-root routes\n if (hasIndexSSG) {\n const tempIndexPath = path.join(distDir, \"__index.html\");\n const ssgIndexPath = path.join(distDir, \"index.ssg.html\");\n const indexPath = path.join(distDir, \"index.html\");\n\n // Move __index.html to index.ssg.html\n if (fs.existsSync(tempIndexPath)) {\n fs.renameSync(tempIndexPath, ssgIndexPath);\n }\n\n // Create a blank index.html as the SPA fallback\n const blankIndexHtml = replaceHtmlRootContents(htmlTemplate, \"\", { \"data-ssg-page\": null, \"data-ssg-failed\": null });\n fs.writeFileSync(indexPath, blankIndexHtml, \"utf-8\");\n\n log(\"info\", ` ${\"index.ssg.html\".padEnd(maxPathLength)} (SSG root page)`);\n log(\"info\", ` ${\"index.html\".padEnd(maxPathLength)} (blank SPA fallback)`);\n }\n\n // Summary\n if (failureCount > 0) {\n log(\"warn\", \"\");\n log(\"warn\", `SSG completed with ${successCount} success(es) and ${failureCount} failure(s).`);\n }\n } finally {\n // Always close the Vite server, even if generation fails\n await viteServer.close();\n }\n}\n"]}
1
+ {"version":3,"file":"ssg.js","sourceRoot":"","sources":["../../src/vite/ssg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAA0B,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC9G,OAAO,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAC;AAErI,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAwBlC;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IAC/C,0EAA0E;IAC1E,IAAI,MAAM,GAAG,OAAO,CAAC;IAErB,2GAA2G;IAC3G,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAEpD,+BAA+B;IAC/B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAEpD,+BAA+B;IAC/B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAEpD,0EAA0E;IAC1E,mDAAmD;IACnD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAE5C,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC5C,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAA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ootContents } from \"../utils/html.js\";\nimport { log } from \"../utils/logger.js\";\nimport { findLayoutPathsForPage, type PageManifestEntry, scanAppShell, scanPageManifest } from \"./scanner.js\";\nimport { generateServerClientModule, generateServerPrefetchModule, generateServerTransitionsModule } from \"./serverClientAdapter.js\";\n\nexport { findLayoutPathsForPage };\n\n/**\n * SSG (Static Site Generation) implementation for Helium\n *\n * Scans pages directory for files with \"use ssg\"; directive and generates\n * static HTML for them at build time.\n */\n\ninterface SSGPage {\n filePath: string;\n urlPath: string;\n relativePath: string;\n warnings: string[];\n layouts?: readonly string[];\n}\n\ninterface SSGValidation {\n hasHooks: boolean;\n hasClientImports: boolean;\n hasServerImports: boolean;\n warnings: string[];\n}\n\n/**\n * Remove string literals from content to avoid false positives when checking for patterns\n * This removes template literals, single-quoted strings, and double-quoted strings\n * @internal Exported for testing\n */\nexport function stripStringLiterals(content: string): string {\n // Remove template literals (backtick strings) - handle nested expressions\n let result = content;\n\n // Remove template literals with their content (simplified - doesn't handle all edge cases but good enough)\n result = result.replace(/`(?:[^`\\\\]|\\\\.)*`/g, '\"\"');\n\n // Remove double-quoted strings\n result = result.replace(/\"(?:[^\"\\\\]|\\\\.)*\"/g, '\"\"');\n\n // Remove single-quoted strings\n result = result.replace(/'(?:[^'\\\\]|\\\\.)*'/g, \"''\");\n\n // Also remove JSX text content between tags (but not the tags themselves)\n // This helps with cases like <code>useState</code>\n result = result.replace(/>([^<]+)</g, \"><\");\n\n return result;\n}\n\n/**\n * Validate if a page file can be truly statically generated\n * Checks for React hooks and helium imports that would prevent static generation\n * @internal Exported for testing\n */\nexport function validateSSGPage(filePath: string): SSGValidation {\n const rawContent = fs.readFileSync(filePath, \"utf-8\");\n const warnings: string[] = [];\n\n // Strip string literals and JSX text to avoid false positives\n const content = stripStringLiterals(rawContent);\n\n // Check for React hooks (common ones)\n const hookPatterns = [\n /\\buse(State|Effect|Context|Reducer|Callback|Memo|Ref|ImperativeHandle|LayoutEffect|DebugValue)\\s*\\(/,\n /\\buse[A-Z]\\w+\\s*\\(/, // Custom hooks (useXxx) - must be followed by ( to be a call\n ];\n\n const hasHooks = hookPatterns.some((pattern) => pattern.test(content));\n if (hasHooks) {\n warnings.push(\"Page uses React hooks which may cause hydration issues\");\n }\n\n // Check for heliumts/client imports - use raw content since imports should be at top level\n const hasClientImports = /^import\\s+.*from\\s+['\"]heliumts\\/client['\"]/m.test(rawContent);\n if (hasClientImports) {\n warnings.push(\"Page imports from 'heliumts/client' which requires client-side execution\");\n }\n\n // Check for heliumts/server imports - use raw content since imports should be at top level\n const hasServerImports = /^import\\s+.*from\\s+['\"]heliumts\\/server['\"]/m.test(rawContent);\n if (hasServerImports) {\n warnings.push(\"Page imports from 'heliumts/server' which may cause runtime issues\");\n }\n\n return {\n hasHooks,\n hasClientImports,\n hasServerImports,\n warnings,\n };\n}\n\n/**\n * Scan pages directory and find all pages with \"use ssg\" directive\n */\nexport function scanSSGPages(root: string, manifest: readonly PageManifestEntry[] = scanPageManifest(root)): SSGPage[] {\n const srcDir = path.join(root, \"src\");\n return manifest\n .filter((route) => route.render === \"ssg\")\n .map(({ file, pattern, layouts }) => {\n const { warnings } = validateSSGPage(file);\n for (const layout of layouts) {\n const layoutWarnings = validateSSGPage(layout).warnings;\n if (layoutWarnings.length) {\n warnings.push(`Layout ${path.relative(srcDir, layout)} has issues:`);\n warnings.push(...layoutWarnings.map((warning) => ` └─ ${warning}`));\n }\n }\n return {\n filePath: file,\n urlPath: pattern === \"__404__\" ? \"/404\" : pattern,\n relativePath: path.relative(srcDir, file),\n warnings,\n layouts,\n };\n });\n}\n\n/**\n * Convert file path to URL path\n * pages/index.tsx -> /\n * pages/about.tsx -> /about\n * pages/blog/post.tsx -> /blog/post\n * pages/(website)/contact.tsx -> /contact\n * pages/(portal)/dashboard.tsx -> /dashboard\n * @internal Exported for testing\n */\nexport function filePathToUrlPath(relativePath: string): string {\n const pattern = pathFromPageFile(relativePath.replace(/\\\\/g, \"/\").replace(/^pages\\//, \"\"));\n return pattern === \"__404__\" ? \"/404\" : pattern;\n}\n\n/**\n * Convert URL path to output file path\n * / -> __index.html (special case - renamed later to prevent conflicts)\n * /about -> about.html\n * /blog/post -> blog/post.html\n * @internal Exported for testing\n */\nexport function urlPathToOutputPath(urlPath: string): string {\n if (urlPath === \"/\") {\n return \"__index.html\";\n }\n\n // Remove leading slash and add .html extension\n const cleanPath = urlPath.replace(/^\\//, \"\");\n return `${cleanPath}.html`;\n}\n\n/**\n * Find all layout components for a given page path (from root to leaf)\n * Note: Layouts cannot use routing features during SSG since they're pre-rendered\n */\nasync function loadLayouts(layoutPaths: readonly string[], viteServer: any): Promise<any[]> {\n const layouts = [];\n\n for (const layoutPath of layoutPaths) {\n try {\n const layoutModule = await viteServer.ssrLoadModule(layoutPath);\n if (layoutModule.default) {\n layouts.push(layoutModule.default);\n }\n } catch (error) {\n log(\"warn\", `Could not load layout at ${layoutPath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n return layouts;\n}\n\n/**\n * Render a page component to static HTML using Vite SSR with timeout\n */\nexport async function renderPageToHTML(page: SSGPage, root: string, htmlTemplate: string, viteServer: any, timeout: number = 10000): Promise<string> {\n // Create timeout promise\n let timeoutId: ReturnType<typeof setTimeout>;\n const timeoutPromise = new Promise<string>((_, reject) => {\n timeoutId = setTimeout(() => {\n reject(new Error(`Rendering timeout after ${timeout}ms - page may contain hooks or async operations`));\n }, timeout);\n });\n\n // Create render promise\n const renderPromise = (async () => {\n try {\n // Dynamically import React and ReactDOMServer\n const React = (await import(\"react\")).default;\n const ReactDOMServer = await import(\"react-dom/server\");\n\n // Use Vite's SSR loader to load the page component\n const pageModule = await viteServer.ssrLoadModule(page.filePath);\n const PageComponent = pageModule.default;\n\n if (!PageComponent) {\n throw new Error(`No default export found in ${page.relativePath}`);\n }\n\n // Find all layouts (from root to leaf)\n const layouts = await loadLayouts(page.layouts ?? findLayoutPathsForPage(page.filePath, root), viteServer);\n\n // Build the component tree: layouts wrap the page, innermost to outermost\n const pageProps = { params: {}, searchParams: new URLSearchParams() };\n const WrappedPage = () => {\n let content: any = React.createElement(PageComponent, pageProps);\n for (let i = layouts.length - 1; i >= 0; i--) {\n content = React.createElement(layouts[i], { children: content });\n }\n return content;\n };\n const appShellPath = scanAppShell(root);\n const appShellModule = appShellPath ? await viteServer.ssrLoadModule(appShellPath) : null;\n const AppShell = appShellModule ? (appShellModule.default ?? appShellModule.App ?? appShellModule.app) : null;\n let element: any = AppShell\n ? React.createElement(AppShell, { Component: WrappedPage, pageProps, children: React.createElement(WrappedPage) })\n : React.createElement(WrappedPage);\n\n // Load RouterContext from our stub\n const heliumClient = await viteServer.ssrLoadModule(\"heliumts/client\");\n const RouterContext = heliumClient.RouterContext;\n\n // Mock Router Context with the page's URL\n const routerValue = {\n path: page.urlPath,\n params: {},\n searchParams: new URLSearchParams(),\n push: () => {},\n replace: () => {},\n on: () => () => {},\n status: 200,\n };\n\n // Wrap with RouterContext\n if (RouterContext) {\n element = React.createElement(RouterContext.Provider, { value: routerValue }, element);\n }\n\n // Render to static HTML\n const markup = ReactDOMServer.renderToString(element);\n\n // Inject the markup into the HTML template with the SSG marker\n const finalHtml = replaceHtmlRootContents(htmlTemplate, markup, { \"data-ssg-page\": page.urlPath, \"data-ssg-failed\": null });\n\n return finalHtml;\n } catch (error) {\n log(\"error\", `Failed to render ${page.relativePath}:`, error);\n throw error; // Don't fallback, let the caller handle the error\n }\n })();\n\n // Race between timeout and render\n try {\n return await Promise.race([renderPromise, timeoutPromise]);\n } finally {\n clearTimeout(timeoutId!);\n }\n}\n\n/**\n * Generate static HTML files for all SSG pages\n */\nexport async function generateStaticPages(context: any, root: string, htmlTemplate: string, distDir: string, manifest?: readonly PageManifestEntry[]) {\n // Scan for SSG pages\n const ssgPages = scanSSGPages(root, manifest);\n\n if (ssgPages.length === 0) {\n return;\n }\n\n log(\"info\", `Generating ${ssgPages.length} static page(s) for SSG...`);\n\n // Check for dynamic routes (not supported yet)\n const dynamicPages = ssgPages.filter((p) => p.relativePath.includes(\"[\"));\n if (dynamicPages.length > 0) {\n log(\"warn\", `Skipping ${dynamicPages.length} dynamic route(s) - not yet supported:\\n` + dynamicPages.map((p) => ` - ${p.relativePath}`).join(\"\\n\"));\n }\n\n // Filter out dynamic routes\n const staticPages = ssgPages.filter((p) => !p.relativePath.includes(\"[\"));\n\n const clientStubCode = generateServerClientModule(\"ssg\");\n const transitionsStubCode = generateServerTransitionsModule(\"ssg\");\n const prefetchStubCode = generateServerPrefetchModule();\n\n // Write stub files to node_modules/.heliumts\n const heliumInternalDir = path.join(root, \"node_modules\", \".heliumts\");\n if (!fs.existsSync(heliumInternalDir)) {\n fs.mkdirSync(heliumInternalDir, { recursive: true });\n }\n const ssgClientStubPath = path.join(heliumInternalDir, \"ssg-client-stub.mjs\");\n const ssgTransitionsStubPath = path.join(heliumInternalDir, \"ssg-transitions-stub.mjs\");\n const ssgPrefetchStubPath = path.join(heliumInternalDir, \"ssg-prefetch-stub.mjs\");\n fs.writeFileSync(ssgClientStubPath, clientStubCode, \"utf-8\");\n fs.writeFileSync(ssgTransitionsStubPath, transitionsStubCode, \"utf-8\");\n fs.writeFileSync(ssgPrefetchStubPath, prefetchStubCode, \"utf-8\");\n\n // Create a temporary Vite server for SSR rendering\n const { createServer } = await import(\"vite\");\n const heliumPlugin = (await import(\"./heliumPlugin.js\")).default;\n\n const viteServer = await createServer({\n root,\n mode: \"production\",\n server: { middlewareMode: true },\n appType: \"custom\",\n logLevel: \"error\",\n plugins: [heliumPlugin()],\n resolve: {\n alias: [\n // Most specific aliases first - heliumts/client/transitions and heliumts/client/prefetch\n { find: /^heliumts\\/client\\/transitions$/, replacement: ssgTransitionsStubPath },\n { find: /^heliumts\\/client\\/prefetch$/, replacement: ssgPrefetchStubPath },\n { find: /^heliumts\\/client$/, replacement: ssgClientStubPath },\n ],\n },\n ssr: {\n external: [\"react\", \"react-dom\"],\n // Don't externalize heliumts packages - we want to use our stubs\n noExternal: [\"heliumts\"],\n },\n });\n\n try {\n // Generate HTML for each static page\n const zlib = await import(\"zlib\");\n let successCount = 0;\n let failureCount = 0;\n let hasIndexSSG = false;\n\n // Calculate max path length for proper alignment (min 35, max 80)\n const maxPathLength = Math.min(80, Math.max(35, ...staticPages.map((p) => urlPathToOutputPath(p.urlPath).length)));\n\n for (const page of staticPages) {\n try {\n // Render the page component to static HTML using Vite SSR with 10s timeout\n const html = await renderPageToHTML(page, root, htmlTemplate, viteServer, 10000);\n const outputPath = urlPathToOutputPath(page.urlPath);\n const fullOutputPath = path.join(distDir, outputPath);\n\n // Track if the root page (/) has SSG\n if (page.urlPath === \"/\") {\n hasIndexSSG = true;\n }\n\n // Ensure directory exists\n const outputDir = path.dirname(fullOutputPath);\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n // Write the HTML file\n fs.writeFileSync(fullOutputPath, html, \"utf-8\");\n\n // Calculate file size and gzipped size\n const size = Buffer.byteLength(html, \"utf-8\");\n const sizeKB = (size / 1024).toFixed(2);\n\n // Calculate gzipped size\n const gzipped = zlib.gzipSync(html);\n const gzipSizeKB = (gzipped.length / 1024).toFixed(2);\n\n log(\"info\", ` ${outputPath.padEnd(maxPathLength)} ${sizeKB.padStart(8)} kB │ gzip: ${gzipSizeKB.padStart(7)} kB`);\n successCount++;\n } catch (error) {\n const errorMsg = error instanceof Error ? error.message : String(error);\n if (errorMsg.includes(\"timeout\")) {\n log(\"error\", ` ✗ ${page.relativePath} - ${errorMsg}`);\n } else {\n log(\"error\", ` ✗ ${page.relativePath} - Failed to generate:`, error);\n }\n\n // Write a fallback HTML file with empty root div (client will hydrate)\n const outputPath = urlPathToOutputPath(page.urlPath);\n const fullOutputPath = path.join(distDir, outputPath);\n const outputDir = path.dirname(fullOutputPath);\n\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n const fallbackHtml = replaceHtmlRootContents(htmlTemplate, \"\", { \"data-ssg-page\": null, \"data-ssg-failed\": page.urlPath });\n fs.writeFileSync(fullOutputPath, fallbackHtml, \"utf-8\");\n\n failureCount++;\n }\n }\n\n // If index page has SSG, we need to handle it specially:\n // 1. Rename __index.html to index.ssg.html (the SSG version)\n // 2. Create a clean blank index.html as fallback for non-root routes\n if (hasIndexSSG) {\n const tempIndexPath = path.join(distDir, \"__index.html\");\n const ssgIndexPath = path.join(distDir, \"index.ssg.html\");\n const indexPath = path.join(distDir, \"index.html\");\n\n // Move __index.html to index.ssg.html\n if (fs.existsSync(tempIndexPath)) {\n fs.renameSync(tempIndexPath, ssgIndexPath);\n }\n\n // Create a blank index.html as the SPA fallback\n const blankIndexHtml = replaceHtmlRootContents(htmlTemplate, \"\", { \"data-ssg-page\": null, \"data-ssg-failed\": null });\n fs.writeFileSync(indexPath, blankIndexHtml, \"utf-8\");\n\n log(\"info\", ` ${\"index.ssg.html\".padEnd(maxPathLength)} (SSG root page)`);\n log(\"info\", ` ${\"index.html\".padEnd(maxPathLength)} (blank SPA fallback)`);\n }\n\n // Summary\n if (failureCount > 0) {\n log(\"warn\", \"\");\n log(\"warn\", `SSG completed with ${successCount} success(es) and ${failureCount} failure(s).`);\n }\n } finally {\n // Always close the Vite server, even if generation fails\n await viteServer.close();\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
- import { HTTPHandlerExport, MethodExport, MiddlewareExport, SEOMetadataExport, SSRPageExport, WorkerExport } from "./scanner.js";
2
- export declare function generateServerManifest(methods: MethodExport[], httpHandlers: HTTPHandlerExport[], seoMetadata?: SEOMetadataExport[], pageRoutePatterns?: string[], ssrPages?: SSRPageExport[], appShellFilePath?: string | null, middleware?: MiddlewareExport, workers?: WorkerExport[]): string;
3
- export declare function generateClientModule(methods: MethodExport[]): string;
4
- export declare function generateTypeDefinitions(methods: MethodExport[], root: string): string;
1
+ import type { PageRoute } from "../runtime/pageRoutes.js";
2
+ import { HTTPHandlerExport, MethodExport, MiddlewareExport, PageManifestEntry, SEOMetadataExport, SSRPageExport, WorkerExport } from "./scanner.js";
3
+ export declare function generateServerManifest(methods: MethodExport[], httpHandlers: HTTPHandlerExport[], seoMetadata?: SEOMetadataExport[], pageRoutePatterns?: string[], ssrPages?: SSRPageExport[], appShellFilePath?: string | null, middleware?: MiddlewareExport, workers?: WorkerExport[], pageRoutes?: readonly PageRoute[]): string;
4
+ export declare function generatePageModules(manifest: readonly PageManifestEntry[], root: string): string;
5
5
  export declare function generateEntryModule(appShellFilePath?: string | null): string;
6
6
  //# sourceMappingURL=virtualServerModule.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"virtualServerModule.d.ts","sourceRoot":"","sources":["../../src/vite/virtualServerModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAajI,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,YAAY,EAAE,EACvB,YAAY,EAAE,iBAAiB,EAAE,EACjC,WAAW,GAAE,iBAAiB,EAAO,EACrC,iBAAiB,GAAE,MAAM,EAAO,EAChC,QAAQ,GAAE,aAAa,EAAO,EAC9B,gBAAgB,GAAE,MAAM,GAAG,IAAW,EACtC,UAAU,CAAC,EAAE,gBAAgB,EAC7B,OAAO,GAAE,YAAY,EAAO,GAC7B,MAAM,CAqGR;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,CAIpE;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAiErF;AAED,wBAAgB,mBAAmB,CAAC,gBAAgB,GAAE,MAAM,GAAG,IAAiB,GAAG,MAAM,CAwBxF"}
1
+ {"version":3,"file":"virtualServerModule.d.ts","sourceRoot":"","sources":["../../src/vite/virtualServerModule.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,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