heliumts 0.9.5 → 0.9.6
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.
- package/README.md +5 -1
- package/dist/bin/helium.js +57 -53
- package/dist/bin/helium.js.map +1 -1
- package/dist/client/Router.d.ts +2 -2
- package/dist/client/Router.d.ts.map +1 -1
- package/dist/client/Router.js +32 -29
- package/dist/client/Router.js.map +1 -1
- package/dist/client/cache.d.ts.map +1 -1
- package/dist/client/cache.js +13 -13
- package/dist/client/cache.js.map +1 -1
- package/dist/client/env.js.map +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/routerManifest.d.ts.map +1 -1
- package/dist/client/routerManifest.js +18 -29
- package/dist/client/routerManifest.js.map +1 -1
- package/dist/client/rpcClient.d.ts.map +1 -1
- package/dist/client/rpcClient.js +71 -72
- package/dist/client/rpcClient.js.map +1 -1
- package/dist/client/transitions.d.ts +1 -1
- package/dist/client/transitions.d.ts.map +1 -1
- package/dist/client/useCall.d.ts.map +1 -1
- package/dist/client/useCall.js +4 -1
- package/dist/client/useCall.js.map +1 -1
- package/dist/client/useFetch.d.ts.map +1 -1
- package/dist/client/useFetch.js +48 -92
- package/dist/client/useFetch.js.map +1 -1
- package/dist/runtime/routeOrder.d.ts +3 -0
- package/dist/runtime/routeOrder.d.ts.map +1 -0
- package/dist/runtime/routeOrder.js +15 -0
- package/dist/runtime/routeOrder.js.map +1 -0
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/config.js +51 -26
- package/dist/server/config.js.map +1 -1
- package/dist/server/defineHTTPRequest.d.ts +1 -1
- package/dist/server/defineHTTPRequest.d.ts.map +1 -1
- package/dist/server/defineHTTPRequest.js.map +1 -1
- package/dist/server/defineWorker.d.ts.map +1 -1
- package/dist/server/defineWorker.js +68 -37
- package/dist/server/defineWorker.js.map +1 -1
- package/dist/server/devServer.d.ts.map +1 -1
- package/dist/server/devServer.js +62 -17
- package/dist/server/devServer.js.map +1 -1
- package/dist/server/httpRouter.d.ts.map +1 -1
- package/dist/server/httpRouter.js +138 -43
- package/dist/server/httpRouter.js.map +1 -1
- package/dist/server/meta.d.ts.map +1 -1
- package/dist/server/meta.js +23 -15
- package/dist/server/meta.js.map +1 -1
- package/dist/server/prodServer.d.ts.map +1 -1
- package/dist/server/prodServer.js +79 -23
- package/dist/server/prodServer.js.map +1 -1
- package/dist/server/rateLimiter.d.ts +9 -0
- package/dist/server/rateLimiter.d.ts.map +1 -1
- package/dist/server/rateLimiter.js +46 -0
- package/dist/server/rateLimiter.js.map +1 -1
- package/dist/server/requestHandler.d.ts +4 -0
- package/dist/server/requestHandler.d.ts.map +1 -0
- package/dist/server/requestHandler.js +20 -0
- package/dist/server/requestHandler.js.map +1 -0
- package/dist/server/rpcRegistry.d.ts.map +1 -1
- package/dist/server/rpcRegistry.js +46 -6
- package/dist/server/rpcRegistry.js.map +1 -1
- package/dist/server/security.d.ts.map +1 -1
- package/dist/server/security.js +3 -2
- package/dist/server/security.js.map +1 -1
- package/dist/server/serializer.js +11 -6
- package/dist/server/serializer.js.map +1 -1
- package/dist/server/ssr.d.ts +2 -1
- package/dist/server/ssr.d.ts.map +1 -1
- package/dist/server/ssr.js +29 -32
- package/dist/server/ssr.js.map +1 -1
- package/dist/utils/envLoader.js +1 -1
- package/dist/utils/envLoader.js.map +1 -1
- package/dist/utils/html.d.ts +7 -0
- package/dist/utils/html.d.ts.map +1 -0
- package/dist/utils/html.js +197 -0
- package/dist/utils/html.js.map +1 -0
- package/dist/utils/ipExtractor.d.ts +6 -52
- package/dist/utils/ipExtractor.d.ts.map +1 -1
- package/dist/utils/ipExtractor.js +21 -118
- package/dist/utils/ipExtractor.js.map +1 -1
- package/dist/vite/heliumPlugin.d.ts.map +1 -1
- package/dist/vite/heliumPlugin.js +71 -83
- package/dist/vite/heliumPlugin.js.map +1 -1
- package/dist/vite/scanner.d.ts +3 -0
- package/dist/vite/scanner.d.ts.map +1 -1
- package/dist/vite/scanner.js +89 -18
- package/dist/vite/scanner.js.map +1 -1
- package/dist/vite/ssg.d.ts +4 -0
- package/dist/vite/ssg.d.ts.map +1 -1
- package/dist/vite/ssg.js +62 -39
- package/dist/vite/ssg.js.map +1 -1
- package/dist/vite/virtualServerModule.d.ts +1 -1
- package/dist/vite/virtualServerModule.d.ts.map +1 -1
- package/dist/vite/virtualServerModule.js +28 -16
- package/dist/vite/virtualServerModule.js.map +1 -1
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -31,8 +31,12 @@ HeliumTS is a blazing fast 🚀 and opinionated full-stack React + Vite framewor
|
|
|
31
31
|
|
|
32
32
|
## 1. Getting Started
|
|
33
33
|
|
|
34
|
+
The current release is **0.9.6**. See the [changelog](./CHANGELOG.md) for fixes and upgrade notes.
|
|
35
|
+
|
|
34
36
|
### 1.1. Installation
|
|
35
37
|
|
|
38
|
+
Requires Node.js 20.19+ within Node 20, or Node.js 22.12+, and React 18 or 19.
|
|
39
|
+
|
|
36
40
|
The easiest way to get started with HeliumTS is by using the scaffolding tool:
|
|
37
41
|
|
|
38
42
|
```bash
|
|
@@ -419,7 +423,7 @@ See [SSR Documentation](./docs/ssr.md) for detailed information including sideca
|
|
|
419
423
|
- [HTTP Handlers & Webhooks](./docs/http-handlers.md) - Create custom HTTP endpoints for webhooks and REST APIs
|
|
420
424
|
- [Production Deployment](./docs/production-deployment.md) - Deploy to production platforms and platform compatibility
|
|
421
425
|
|
|
422
|
-
>
|
|
426
|
+
> **Hosting:** Full Helium functionality runs through its persistent Node.js server. Static-only hosting serves assets and SSG output, but does not execute SSR, RPC, HTTP handlers, or workers. See [Production Deployment](./docs/production-deployment.md).
|
|
423
427
|
|
|
424
428
|
## 6. Contributing
|
|
425
429
|
|
package/dist/bin/helium.js
CHANGED
|
@@ -4,18 +4,33 @@ import { spawn } from "child_process";
|
|
|
4
4
|
import { build as esbuild } from "esbuild";
|
|
5
5
|
import fs from "fs";
|
|
6
6
|
import path from "path";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
7
8
|
import { build as viteBuild } from "vite";
|
|
9
|
+
import { replaceHtmlRootContents } from "../utils/html.js";
|
|
8
10
|
import { log } from "../utils/logger.js";
|
|
9
11
|
import { scanAppShell, scanPageRoutePatterns, scanServerExports, scanSSRPages } from "../vite/scanner.js";
|
|
10
12
|
import { generateStaticPages } from "../vite/ssg.js";
|
|
11
13
|
import { generateClientModule, generateServerManifest, generateTypeDefinitions } from "../vite/virtualServerModule.js";
|
|
12
14
|
const cli = cac("helium");
|
|
13
15
|
const root = process.cwd();
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
function monitorChild(child) {
|
|
17
|
+
const onInterrupt = () => child.kill("SIGINT");
|
|
18
|
+
const onTerminate = () => child.kill("SIGTERM");
|
|
19
|
+
process.on("SIGINT", onInterrupt);
|
|
20
|
+
process.on("SIGTERM", onTerminate);
|
|
21
|
+
child.on("error", (error) => {
|
|
22
|
+
log("error", "Failed to start child process:", error);
|
|
23
|
+
process.exit(1);
|
|
18
24
|
});
|
|
25
|
+
child.on("close", (code, signal) => {
|
|
26
|
+
process.off("SIGINT", onInterrupt);
|
|
27
|
+
process.off("SIGTERM", onTerminate);
|
|
28
|
+
process.exit(code ?? (signal === "SIGINT" ? 130 : signal === "SIGTERM" ? 143 : 1));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
cli.command("dev", "Start development server").action(async () => {
|
|
32
|
+
const vitePackage = fileURLToPath(import.meta.resolve("vite/package.json"));
|
|
33
|
+
monitorChild(spawn(process.execPath, [path.join(path.dirname(vitePackage), "bin", "vite.js")], { stdio: "inherit" }));
|
|
19
34
|
});
|
|
20
35
|
cli.command("build", "Build for production").action(async () => {
|
|
21
36
|
// Generate type definitions before building so TypeScript can resolve
|
|
@@ -71,7 +86,7 @@ cli.command("build", "Build for production").action(async () => {
|
|
|
71
86
|
// 1. Remove the build-time HELIUM_CONNECTION_TOKEN (SSG pages don't need it)
|
|
72
87
|
htmlTemplate = htmlTemplate.replace(/<script>window\.HELIUM_CONNECTION_TOKEN = "build-time-placeholder";<\/script>/g, "");
|
|
73
88
|
// 2. Clear any existing content in root div from SPA build
|
|
74
|
-
htmlTemplate = htmlTemplate
|
|
89
|
+
htmlTemplate = replaceHtmlRootContents(htmlTemplate, "", { "data-ssg-page": null, "data-ssg-failed": null });
|
|
75
90
|
await generateStaticPages(null, root, htmlTemplate, distDir);
|
|
76
91
|
}
|
|
77
92
|
else {
|
|
@@ -126,11 +141,14 @@ export async function start() {
|
|
|
126
141
|
// Load environment variables FIRST, before any other imports
|
|
127
142
|
import './env-loader.js';
|
|
128
143
|
// Now import and start the server (this ensures handlers load after env)
|
|
129
|
-
|
|
144
|
+
const { start } = await import('./server-module.js');
|
|
130
145
|
await start();
|
|
131
146
|
`;
|
|
132
147
|
const envLoaderCode = `
|
|
133
148
|
import { loadEnvFiles, injectEnvToProcess, log } from 'heliumts/server';
|
|
149
|
+
import { fileURLToPath } from 'node:url';
|
|
150
|
+
process.env.HELIUM_CONFIG_DIR ??= fileURLToPath(new URL('.', import.meta.url));
|
|
151
|
+
process.env.NODE_ENV ??= 'production';
|
|
134
152
|
const envRoot = process.cwd();
|
|
135
153
|
log('info', \`Loading .env files from: \${envRoot}\`);
|
|
136
154
|
const envVars = loadEnvFiles({ mode: 'production' });
|
|
@@ -192,7 +210,7 @@ export function useRouter() {
|
|
|
192
210
|
}
|
|
193
211
|
|
|
194
212
|
export function Link(props: { href?: string; children?: React.ReactNode } & Record<string, unknown>) {
|
|
195
|
-
const { href = '#', children, ...rest } = props || {};
|
|
213
|
+
const { href = '#', children, prefetch: _prefetch, ...rest } = props || {};
|
|
196
214
|
return React.createElement('a', { href, ...rest }, children);
|
|
197
215
|
}
|
|
198
216
|
|
|
@@ -224,11 +242,15 @@ export function useFetch() {
|
|
|
224
242
|
export class RpcError extends Error {}
|
|
225
243
|
|
|
226
244
|
export function getPublicEnv() {
|
|
227
|
-
return
|
|
245
|
+
return Object.fromEntries(Object.entries(process.env).filter(([key, value]) => key.startsWith('HELIUM_PUBLIC_') && value !== undefined));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function getPublicEnvValue(key: string) {
|
|
249
|
+
return getPublicEnv()[key];
|
|
228
250
|
}
|
|
229
251
|
|
|
230
|
-
export function
|
|
231
|
-
return
|
|
252
|
+
export function isDevEnvironment() {
|
|
253
|
+
return false;
|
|
232
254
|
}
|
|
233
255
|
|
|
234
256
|
export function getRpcTransport() {
|
|
@@ -247,19 +269,22 @@ export function isSSR() {
|
|
|
247
269
|
`;
|
|
248
270
|
const ssrTransitionsStubCode = `
|
|
249
271
|
import React from 'react';
|
|
272
|
+
import { useRouter } from 'heliumts/client';
|
|
250
273
|
|
|
251
274
|
export function useDeferredNavigation() {
|
|
275
|
+
const { path } = useRouter();
|
|
252
276
|
return {
|
|
253
|
-
path
|
|
254
|
-
deferredPath:
|
|
277
|
+
path,
|
|
278
|
+
deferredPath: path,
|
|
255
279
|
isStale: false,
|
|
256
280
|
isPending: false,
|
|
257
281
|
isTransitioning: false,
|
|
258
282
|
};
|
|
259
283
|
}
|
|
260
284
|
|
|
261
|
-
export function PageTransition({ children }: { children?: React.ReactNode }) {
|
|
262
|
-
return React.createElement(
|
|
285
|
+
export function PageTransition({ children, fallback = null }: { children?: React.ReactNode; fallback?: React.ReactNode }) {
|
|
286
|
+
return React.createElement('div', { style: { opacity: 1, transition: 'opacity 150ms ease' } },
|
|
287
|
+
React.createElement(React.Suspense, { fallback }, children));
|
|
263
288
|
}
|
|
264
289
|
`;
|
|
265
290
|
const ssrPrefetchStubCode = `
|
|
@@ -274,7 +299,7 @@ export function clearPrefetchCache() {}
|
|
|
274
299
|
// user-defined methods from 'heliumts/server' resolve correctly during
|
|
275
300
|
// the esbuild server bundle (mirroring the Vite plugin's virtual module).
|
|
276
301
|
const rpcClientStubPath = path.join(heliumDir, "rpc-client-stub.ts");
|
|
277
|
-
const rpcClientStubCode = generateClientModule(serverExports.methods)
|
|
302
|
+
const rpcClientStubCode = `export * from 'heliumts/server';\n${generateClientModule(serverExports.methods)}`;
|
|
278
303
|
fs.writeFileSync(rpcClientStubPath, rpcClientStubCode);
|
|
279
304
|
fs.writeFileSync(ssrClientStubPath, ssrClientStubCode);
|
|
280
305
|
fs.writeFileSync(ssrTransitionsStubPath, ssrTransitionsStubCode);
|
|
@@ -322,6 +347,7 @@ export function clearPrefetchCache() {}
|
|
|
322
347
|
"sqlite3",
|
|
323
348
|
"better-sqlite3",
|
|
324
349
|
"redis",
|
|
350
|
+
"esbuild",
|
|
325
351
|
// Node.js built-ins are automatically external, but let's be explicit
|
|
326
352
|
"crypto",
|
|
327
353
|
"fs",
|
|
@@ -344,38 +370,19 @@ export function clearPrefetchCache() {}
|
|
|
344
370
|
const serverSizeKB = (serverStats.size / 1024).toFixed(2);
|
|
345
371
|
log("info", ` ${serverOutputPath.padEnd(35)} ${serverSizeKB.padStart(8)} kB`);
|
|
346
372
|
log("info", "Server build complete.");
|
|
347
|
-
//
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
log("info", "Config file transpiled to dist/helium.config.js");
|
|
361
|
-
}
|
|
362
|
-
catch (e) {
|
|
363
|
-
log("warn", "Failed to transpile config file:", e);
|
|
364
|
-
log("warn", "You may need to manually rename helium.config.ts to helium.config.js");
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
// Check if .js or .mjs config exists and copy it to dist
|
|
369
|
-
const configJsPath = path.join(root, "helium.config.js");
|
|
370
|
-
const configMjsPath = path.join(root, "helium.config.mjs");
|
|
371
|
-
if (fs.existsSync(configJsPath)) {
|
|
372
|
-
fs.copyFileSync(configJsPath, path.join(root, "dist", "helium.config.js"));
|
|
373
|
-
log("info", "Copied helium.config.js to dist/");
|
|
374
|
-
}
|
|
375
|
-
else if (fs.existsSync(configMjsPath)) {
|
|
376
|
-
fs.copyFileSync(configMjsPath, path.join(root, "dist", "helium.config.mjs"));
|
|
377
|
-
log("info", "Copied helium.config.mjs to dist/");
|
|
378
|
-
}
|
|
373
|
+
// Bundle config helpers so moving the config into dist preserves relative imports.
|
|
374
|
+
const configFile = ["helium.config.js", "helium.config.mjs", "helium.config.ts"].map((name) => path.join(root, name)).find((candidate) => fs.existsSync(candidate));
|
|
375
|
+
if (configFile) {
|
|
376
|
+
await esbuild({
|
|
377
|
+
entryPoints: [configFile],
|
|
378
|
+
outfile: path.join(root, "dist", "helium.config.js"),
|
|
379
|
+
bundle: true,
|
|
380
|
+
packages: "external",
|
|
381
|
+
platform: "node",
|
|
382
|
+
format: "esm",
|
|
383
|
+
target: "node20",
|
|
384
|
+
});
|
|
385
|
+
log("info", "Bundled Helium config to dist/helium.config.js");
|
|
379
386
|
}
|
|
380
387
|
log("info", "--------------------------------");
|
|
381
388
|
log("info", "✓ Build finished successfully.");
|
|
@@ -396,14 +403,11 @@ cli.command("start", "Start production server").action(async () => {
|
|
|
396
403
|
}
|
|
397
404
|
// When running in production, look for config in dist directory first
|
|
398
405
|
// This allows the transpiled config to be found
|
|
399
|
-
const server = spawn(
|
|
406
|
+
const server = spawn(process.execPath, [serverPath], {
|
|
400
407
|
stdio: "inherit",
|
|
401
|
-
|
|
402
|
-
env: { ...process.env, HELIUM_CONFIG_DIR: path.join(root, "dist") },
|
|
403
|
-
});
|
|
404
|
-
server.on("close", (code) => {
|
|
405
|
-
process.exit(code || 0);
|
|
408
|
+
env: { ...process.env, NODE_ENV: process.env.NODE_ENV || "production", HELIUM_CONFIG_DIR: path.join(root, "dist") },
|
|
406
409
|
});
|
|
410
|
+
monitorChild(server);
|
|
407
411
|
});
|
|
408
412
|
cli.help();
|
|
409
413
|
cli.parse();
|
package/dist/bin/helium.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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KAAK,IAAI,EAAE;IAC9D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACxD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,GAAG,CAAC,OAAO,EAAE,mDAAmD,CAAC,CAAC;QAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,sEAAsE;IACtE,gDAAgD;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE;QACvC,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,IAAI;QACX,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;KACtE,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QACxB,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,KAAK,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { cac } from \"cac\";\nimport { spawn } from \"child_process\";\nimport { build as esbuild } from \"esbuild\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { build as viteBuild } from \"vite\";\n\nimport { log } from \"../utils/logger.js\";\nimport { scanAppShell, scanPageRoutePatterns, scanServerExports, scanSSRPages } from \"../vite/scanner.js\";\nimport { generateStaticPages } from \"../vite/ssg.js\";\nimport { generateClientModule, generateServerManifest, generateTypeDefinitions } from \"../vite/virtualServerModule.js\";\n\nconst cli = cac(\"helium\");\nconst root = process.cwd();\n\ncli.command(\"dev\", \"Start development server\").action(async () => {\n const vite = spawn(\"vite\", [], { stdio: \"inherit\", shell: true });\n vite.on(\"close\", (code) => {\n process.exit(code || 0);\n });\n});\n\ncli.command(\"build\", \"Build for production\").action(async () => {\n // Generate type definitions before building so TypeScript can resolve\n // server method types even if the dev server was never started.\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 if (!fs.existsSync(typesDir)) {\n fs.mkdirSync(typesDir, { recursive: true });\n }\n\n if (!fs.existsSync(dtsPath) || fs.readFileSync(dtsPath, \"utf-8\") !== dts) {\n fs.writeFileSync(dtsPath, dts);\n log(\"info\", `Generated type definitions for ${methods.length} method(s)`);\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"Building client...\");\n\n try {\n const result = await viteBuild({\n root,\n logLevel: \"silent\",\n build: {\n outDir: \"dist\",\n },\n });\n\n // Display build output\n if (result && \"output\" in result) {\n const outputs = result.output;\n const zlib = await import(\"zlib\");\n\n for (const chunk of outputs) {\n if (chunk.type === \"asset\" || chunk.type === \"chunk\") {\n const fileName = chunk.fileName;\n const content = \"code\" in chunk ? chunk.code : chunk.source;\n const size = Buffer.byteLength(content, \"utf-8\");\n const sizeKB = (size / 1024).toFixed(2);\n\n // Calculate gzipped size\n const gzipped = zlib.gzipSync(content);\n const gzipSizeKB = (gzipped.length / 1024).toFixed(2);\n\n log(\"info\", ` ${fileName.padEnd(35)} ${sizeKB.padStart(8)} kB │ gzip: ${gzipSizeKB.padStart(7)} kB`);\n }\n }\n }\n\n log(\"info\", \"Client build complete.\");\n\n // Generate static pages for SSG\n log(\"info\", \"--------------------------------\");\n try {\n // Read the generated index.html as a template for SSG\n const distDir = path.join(root, \"dist\");\n const htmlPath = path.join(distDir, \"index.html\");\n\n if (fs.existsSync(htmlPath)) {\n let htmlTemplate = fs.readFileSync(htmlPath, \"utf-8\");\n\n // Clean up the template for SSG:\n // 1. Remove the build-time HELIUM_CONNECTION_TOKEN (SSG pages don't need it)\n htmlTemplate = htmlTemplate.replace(/<script>window\\.HELIUM_CONNECTION_TOKEN = \"build-time-placeholder\";<\\/script>/g, \"\");\n\n // 2. Clear any existing content in root div from SPA build\n htmlTemplate = htmlTemplate.replace(/<div\\s+id=\"root\"[^>]*>.*?<\\/div>/s, '<div id=\"root\"></div>');\n\n await generateStaticPages(null, root, htmlTemplate, distDir);\n } else {\n log(\"warn\", \"index.html not found in dist, skipping SSG\");\n }\n } catch (e) {\n log(\"warn\", \"SSG generation failed:\", e);\n // Don't fail the build if SSG fails\n }\n log(\"info\", \"--------------------------------\");\n } catch (e) {\n log(\"error\", \"Client build failed:\", e);\n process.exit(1);\n }\n\n log(\"info\", \"Building server...\");\n // Generate server entry\n const serverExports = scanServerExports(root);\n const pageRoutePatterns = scanPageRoutePatterns(root);\n const ssrPages = scanSSRPages(root);\n const appShell = scanAppShell(root);\n const manifestCode = generateServerManifest(\n serverExports.methods,\n serverExports.httpHandlers,\n serverExports.seoMetadata,\n pageRoutePatterns,\n ssrPages,\n appShell,\n serverExports.middleware,\n serverExports.workers\n );\n\n // Create the main server module that will be imported after env is loaded\n const serverModuleCode = `\nimport { startProdServer, loadConfig } from 'heliumts/server';\n${manifestCode}\n\nexport async function start() {\n const config = await loadConfig();\n\n startProdServer({\n config,\n registerHandlers: (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 ssrPages,\n appShell,\n workers\n });\n}\n`;\n\n // Create the entry loader that loads env first, then imports the server module\n const entryCode = `\n// Load environment variables FIRST, before any other imports\nimport './env-loader.js';\n// Now import and start the server (this ensures handlers load after env)\nimport { start } from './server-module.js';\nawait start();\n`;\n\n const envLoaderCode = `\nimport { loadEnvFiles, injectEnvToProcess, log } from 'heliumts/server';\nconst envRoot = process.cwd();\nlog('info', \\`Loading .env files from: \\${envRoot}\\`);\nconst envVars = loadEnvFiles({ mode: 'production' });\ninjectEnvToProcess(envVars);\nif (Object.keys(envVars).length > 0) {\n log('info', \\`Loaded \\${Object.keys(envVars).length} environment variable(s) from .env files\\`);\n} else {\n log('info', 'No .env files found (using platform environment variables if available)');\n}\n`;\n\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, \"server-entry.ts\");\n const envLoaderPath = path.join(heliumDir, \"env-loader.ts\");\n const serverModuleSrcPath = path.join(heliumDir, \"server-module.ts\");\n const ssrClientStubPath = path.join(heliumDir, \"ssr-client-stub.ts\");\n const ssrTransitionsStubPath = path.join(heliumDir, \"ssr-transitions-stub.ts\");\n const ssrPrefetchStubPath = path.join(heliumDir, \"ssr-prefetch-stub.ts\");\n\n const ssrClientStubCode = `\nimport React from 'react';\n\nexport const RouterContext = React.createContext(null);\n\nfunction getSSRRouterSnapshot() {\n const snapshot = globalThis.__HELIUM_SSR_ROUTER__ as\n | { path?: string; params?: Record<string, string | string[]>; search?: string }\n | undefined;\n\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: { href?: string; children?: React.ReactNode } & Record<string, unknown>) {\n const { href = '#', children, ...rest } = props || {};\n return React.createElement('a', { href, ...rest }, children);\n}\n\nexport function Redirect() {\n return null;\n}\n\nexport function AppRouter() {\n return null;\n}\n\nexport function useCall() {\n return {\n call: async () => null,\n isCalling: false,\n error: null,\n };\n}\n\nexport function useFetch() {\n return {\n data: null,\n isLoading: false,\n error: null,\n refetch: async () => undefined,\n };\n}\n\nexport class RpcError extends Error {}\n\nexport function getPublicEnv() {\n return {};\n}\n\nexport function getPublicEnvValue() {\n return undefined;\n}\n\nexport function getRpcTransport() {\n return 'websocket';\n}\n\nexport function isAutoHttpOnMobileEnabled() {\n return false;\n}\n\nexport function preconnect() {}\n\nexport function isSSR() {\n return true;\n}\n`;\n\n const ssrTransitionsStubCode = `\nimport React from 'react';\n\nexport function useDeferredNavigation() {\n return {\n path: '/',\n deferredPath: '/',\n isStale: false,\n isPending: false,\n isTransitioning: false,\n };\n}\n\nexport function PageTransition({ children }: { children?: React.ReactNode }) {\n return React.createElement(React.Fragment, null, children);\n}\n`;\n\n const ssrPrefetchStubCode = `\nexport function prefetchRoute() {}\nexport function clearPrefetchCache() {}\n`;\n\n fs.writeFileSync(entryPath, entryCode);\n fs.writeFileSync(envLoaderPath, envLoaderCode);\n fs.writeFileSync(serverModuleSrcPath, serverModuleCode);\n // Generate a client-side stub for heliumts/server that provides method stubs\n // (e.g. { __id: 'subscribeWaitlist' }) so client components that import\n // user-defined methods from 'heliumts/server' resolve correctly during\n // the esbuild server bundle (mirroring the Vite plugin's virtual module).\n const rpcClientStubPath = path.join(heliumDir, \"rpc-client-stub.ts\");\n const rpcClientStubCode = generateClientModule(serverExports.methods);\n fs.writeFileSync(rpcClientStubPath, rpcClientStubCode);\n\n fs.writeFileSync(ssrClientStubPath, ssrClientStubCode);\n fs.writeFileSync(ssrTransitionsStubPath, ssrTransitionsStubCode);\n fs.writeFileSync(ssrPrefetchStubPath, ssrPrefetchStubCode);\n\n // Bundle with esbuild\n try {\n await esbuild({\n entryPoints: [entryPath],\n outfile: path.join(root, \"dist\", \"server.js\"),\n bundle: true,\n platform: \"node\",\n format: \"esm\",\n jsx: \"automatic\",\n jsxImportSource: \"react\",\n plugins: [\n {\n name: \"helium-ssr-client-alias\",\n setup(build) {\n build.onResolve({ filter: /^heliumts\\/client$/ }, () => ({ path: ssrClientStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/transitions$/ }, () => ({ path: ssrTransitionsStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/prefetch$/ }, () => ({ path: ssrPrefetchStubPath }));\n // Intercept heliumts/server imports from client code\n // and redirect to the RPC stub module (method stubs).\n // Server-side files and generated server-module resolve normally.\n const serverDirAbs = path.join(root, \"src\", \"server\");\n build.onResolve({ filter: /^heliumts\\/server$/ }, (args) => {\n const importer = args.importer;\n // Allow the generated server-module and env-loader to\n // import the real heliumts/server framework exports.\n if (importer.startsWith(heliumDir) || importer.startsWith(serverDirAbs)) {\n return undefined; // let esbuild resolve normally\n }\n return { path: rpcClientStubPath };\n });\n },\n },\n ],\n external: [\n // External common database and heavy dependencies\n \"mongodb\",\n \"mongoose\",\n \"pg\",\n \"mysql\",\n \"mysql2\",\n \"sqlite3\",\n \"better-sqlite3\",\n \"redis\",\n // Node.js built-ins are automatically external, but let's be explicit\n \"crypto\",\n \"fs\",\n \"path\",\n \"http\",\n \"https\",\n \"stream\",\n \"zlib\",\n \"util\",\n ],\n target: \"node18\",\n metafile: true,\n banner: {\n js: \"import { createRequire } from 'module'; const require = createRequire(import.meta.url);\",\n },\n });\n\n // Display server build output\n const serverOutputPath = path.relative(root, path.join(root, \"dist\", \"server.js\"));\n const serverStats = fs.statSync(path.join(root, \"dist\", \"server.js\"));\n const serverSizeKB = (serverStats.size / 1024).toFixed(2);\n log(\"info\", ` ${serverOutputPath.padEnd(35)} ${serverSizeKB.padStart(8)} kB`);\n\n log(\"info\", \"Server build complete.\");\n\n // Transpile helium.config.ts to helium.config.js if it exists\n const configTsPath = path.join(root, \"helium.config.ts\");\n if (fs.existsSync(configTsPath)) {\n log(\"info\", \"Transpiling helium.config.ts...\");\n try {\n await esbuild({\n entryPoints: [configTsPath],\n outfile: path.join(root, \"dist\", \"helium.config.js\"),\n bundle: false,\n platform: \"node\",\n format: \"esm\",\n target: \"node18\",\n });\n log(\"info\", \"Config file transpiled to dist/helium.config.js\");\n } catch (e) {\n log(\"warn\", \"Failed to transpile config file:\", e);\n log(\"warn\", \"You may need to manually rename helium.config.ts to helium.config.js\");\n }\n } else {\n // Check if .js or .mjs config exists and copy it to dist\n const configJsPath = path.join(root, \"helium.config.js\");\n const configMjsPath = path.join(root, \"helium.config.mjs\");\n\n if (fs.existsSync(configJsPath)) {\n fs.copyFileSync(configJsPath, path.join(root, \"dist\", \"helium.config.js\"));\n log(\"info\", \"Copied helium.config.js to dist/\");\n } else if (fs.existsSync(configMjsPath)) {\n fs.copyFileSync(configMjsPath, path.join(root, \"dist\", \"helium.config.mjs\"));\n log(\"info\", \"Copied helium.config.mjs to dist/\");\n }\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"✓ Build finished successfully.\");\n log(\"info\", \"▶ Run 'helium start' to start the production server.\");\n\n // Exit cleanly after build completes\n process.exit(0);\n } catch (e) {\n log(\"error\", \"Server build failed:\", e);\n process.exit(1);\n }\n});\n\ncli.command(\"start\", \"Start production server\").action(async () => {\n const serverPath = path.join(root, \"dist\", \"server.js\");\n if (!fs.existsSync(serverPath)) {\n log(\"error\", 'Server build not found. Run \"helium build\" first.');\n process.exit(1);\n }\n\n // When running in production, look for config in dist directory first\n // This allows the transpiled config to be found\n const server = spawn(\"node\", [serverPath], {\n stdio: \"inherit\",\n shell: true,\n env: { ...process.env, HELIUM_CONFIG_DIR: path.join(root, \"dist\") },\n });\n server.on(\"close\", (code) => {\n process.exit(code || 0);\n });\n});\n\ncli.help();\ncli.parse();\n"]}
|
|
1
|
+
{"version":3,"file":"helium.js","sourceRoot":"","sources":["../../src/bin/helium.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAqB,K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C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,GAAG,CAAC,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE;IAC9D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACxD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,GAAG,CAAC,OAAO,EAAE,mDAAmD,CAAC,CAAC;QAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,sEAAsE;IACtE,gDAAgD;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,EAAE;QACjD,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,YAAY,EAAE,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;KACtH,CAAC,CAAC;IACH,YAAY,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,IAAI,EAAE,CAAC;AACX,GAAG,CAAC,KAAK,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { cac } from \"cac\";\nimport { type ChildProcess, spawn } from \"child_process\";\nimport { build as esbuild } from \"esbuild\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { build as viteBuild } from \"vite\";\n\nimport { replaceHtmlRootContents } from \"../utils/html.js\";\nimport { log } from \"../utils/logger.js\";\nimport { scanAppShell, scanPageRoutePatterns, scanServerExports, scanSSRPages } from \"../vite/scanner.js\";\nimport { generateStaticPages } from \"../vite/ssg.js\";\nimport { generateClientModule, generateServerManifest, generateTypeDefinitions } from \"../vite/virtualServerModule.js\";\n\nconst cli = cac(\"helium\");\nconst root = process.cwd();\n\nfunction monitorChild(child: ChildProcess) {\n const onInterrupt = () => child.kill(\"SIGINT\");\n const onTerminate = () => child.kill(\"SIGTERM\");\n process.on(\"SIGINT\", onInterrupt);\n process.on(\"SIGTERM\", onTerminate);\n child.on(\"error\", (error) => {\n log(\"error\", \"Failed to start child process:\", error);\n process.exit(1);\n });\n child.on(\"close\", (code, signal) => {\n process.off(\"SIGINT\", onInterrupt);\n process.off(\"SIGTERM\", onTerminate);\n process.exit(code ?? (signal === \"SIGINT\" ? 130 : signal === \"SIGTERM\" ? 143 : 1));\n });\n}\n\ncli.command(\"dev\", \"Start development server\").action(async () => {\n const vitePackage = fileURLToPath(import.meta.resolve(\"vite/package.json\"));\n monitorChild(spawn(process.execPath, [path.join(path.dirname(vitePackage), \"bin\", \"vite.js\")], { stdio: \"inherit\" }));\n});\n\ncli.command(\"build\", \"Build for production\").action(async () => {\n // Generate type definitions before building so TypeScript can resolve\n // server method types even if the dev server was never started.\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 if (!fs.existsSync(typesDir)) {\n fs.mkdirSync(typesDir, { recursive: true });\n }\n\n if (!fs.existsSync(dtsPath) || fs.readFileSync(dtsPath, \"utf-8\") !== dts) {\n fs.writeFileSync(dtsPath, dts);\n log(\"info\", `Generated type definitions for ${methods.length} method(s)`);\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"Building client...\");\n\n try {\n const result = await viteBuild({\n root,\n logLevel: \"silent\",\n build: {\n outDir: \"dist\",\n },\n });\n\n // Display build output\n if (result && \"output\" in result) {\n const outputs = result.output;\n const zlib = await import(\"zlib\");\n\n for (const chunk of outputs) {\n if (chunk.type === \"asset\" || chunk.type === \"chunk\") {\n const fileName = chunk.fileName;\n const content = \"code\" in chunk ? chunk.code : chunk.source;\n const size = Buffer.byteLength(content, \"utf-8\");\n const sizeKB = (size / 1024).toFixed(2);\n\n // Calculate gzipped size\n const gzipped = zlib.gzipSync(content);\n const gzipSizeKB = (gzipped.length / 1024).toFixed(2);\n\n log(\"info\", ` ${fileName.padEnd(35)} ${sizeKB.padStart(8)} kB │ gzip: ${gzipSizeKB.padStart(7)} kB`);\n }\n }\n }\n\n log(\"info\", \"Client build complete.\");\n\n // Generate static pages for SSG\n log(\"info\", \"--------------------------------\");\n try {\n // Read the generated index.html as a template for SSG\n const distDir = path.join(root, \"dist\");\n const htmlPath = path.join(distDir, \"index.html\");\n\n if (fs.existsSync(htmlPath)) {\n let htmlTemplate = fs.readFileSync(htmlPath, \"utf-8\");\n\n // Clean up the template for SSG:\n // 1. Remove the build-time HELIUM_CONNECTION_TOKEN (SSG pages don't need it)\n htmlTemplate = htmlTemplate.replace(/<script>window\\.HELIUM_CONNECTION_TOKEN = \"build-time-placeholder\";<\\/script>/g, \"\");\n\n // 2. Clear any existing content in root div from SPA build\n htmlTemplate = replaceHtmlRootContents(htmlTemplate, \"\", { \"data-ssg-page\": null, \"data-ssg-failed\": null });\n\n await generateStaticPages(null, root, htmlTemplate, distDir);\n } else {\n log(\"warn\", \"index.html not found in dist, skipping SSG\");\n }\n } catch (e) {\n log(\"warn\", \"SSG generation failed:\", e);\n // Don't fail the build if SSG fails\n }\n log(\"info\", \"--------------------------------\");\n } catch (e) {\n log(\"error\", \"Client build failed:\", e);\n process.exit(1);\n }\n\n log(\"info\", \"Building server...\");\n // Generate server entry\n const serverExports = scanServerExports(root);\n const pageRoutePatterns = scanPageRoutePatterns(root);\n const ssrPages = scanSSRPages(root);\n const appShell = scanAppShell(root);\n const manifestCode = generateServerManifest(\n serverExports.methods,\n serverExports.httpHandlers,\n serverExports.seoMetadata,\n pageRoutePatterns,\n ssrPages,\n appShell,\n serverExports.middleware,\n serverExports.workers\n );\n\n // Create the main server module that will be imported after env is loaded\n const serverModuleCode = `\nimport { startProdServer, loadConfig } from 'heliumts/server';\n${manifestCode}\n\nexport async function start() {\n const config = await loadConfig();\n\n startProdServer({\n config,\n registerHandlers: (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 ssrPages,\n appShell,\n workers\n });\n}\n`;\n\n // Create the entry loader that loads env first, then imports the server module\n const entryCode = `\n// Load environment variables FIRST, before any other imports\nimport './env-loader.js';\n// Now import and start the server (this ensures handlers load after env)\nconst { start } = await import('./server-module.js');\nawait start();\n`;\n\n const envLoaderCode = `\nimport { loadEnvFiles, injectEnvToProcess, log } from 'heliumts/server';\nimport { fileURLToPath } from 'node:url';\nprocess.env.HELIUM_CONFIG_DIR ??= fileURLToPath(new URL('.', import.meta.url));\nprocess.env.NODE_ENV ??= 'production';\nconst envRoot = process.cwd();\nlog('info', \\`Loading .env files from: \\${envRoot}\\`);\nconst envVars = loadEnvFiles({ mode: 'production' });\ninjectEnvToProcess(envVars);\nif (Object.keys(envVars).length > 0) {\n log('info', \\`Loaded \\${Object.keys(envVars).length} environment variable(s) from .env files\\`);\n} else {\n log('info', 'No .env files found (using platform environment variables if available)');\n}\n`;\n\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, \"server-entry.ts\");\n const envLoaderPath = path.join(heliumDir, \"env-loader.ts\");\n const serverModuleSrcPath = path.join(heliumDir, \"server-module.ts\");\n const ssrClientStubPath = path.join(heliumDir, \"ssr-client-stub.ts\");\n const ssrTransitionsStubPath = path.join(heliumDir, \"ssr-transitions-stub.ts\");\n const ssrPrefetchStubPath = path.join(heliumDir, \"ssr-prefetch-stub.ts\");\n\n const ssrClientStubCode = `\nimport React from 'react';\n\nexport const RouterContext = React.createContext(null);\n\nfunction getSSRRouterSnapshot() {\n const snapshot = globalThis.__HELIUM_SSR_ROUTER__ as\n | { path?: string; params?: Record<string, string | string[]>; search?: string }\n | undefined;\n\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: { href?: string; children?: React.ReactNode } & Record<string, unknown>) {\n const { href = '#', children, prefetch: _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 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_') && value !== undefined));\n}\n\nexport function getPublicEnvValue(key: string) {\n return getPublicEnv()[key];\n}\n\nexport function isDevEnvironment() {\n return false;\n}\n\nexport function getRpcTransport() {\n return 'websocket';\n}\n\nexport function isAutoHttpOnMobileEnabled() {\n return false;\n}\n\nexport function preconnect() {}\n\nexport function isSSR() {\n return true;\n}\n`;\n\n const ssrTransitionsStubCode = `\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 }: { children?: React.ReactNode; fallback?: React.ReactNode }) {\n return React.createElement('div', { style: { opacity: 1, transition: 'opacity 150ms ease' } },\n React.createElement(React.Suspense, { fallback }, children));\n}\n`;\n\n const ssrPrefetchStubCode = `\nexport function prefetchRoute() {}\nexport function clearPrefetchCache() {}\n`;\n\n fs.writeFileSync(entryPath, entryCode);\n fs.writeFileSync(envLoaderPath, envLoaderCode);\n fs.writeFileSync(serverModuleSrcPath, serverModuleCode);\n // Generate a client-side stub for heliumts/server that provides method stubs\n // (e.g. { __id: 'subscribeWaitlist' }) so client components that import\n // user-defined methods from 'heliumts/server' resolve correctly during\n // the esbuild server bundle (mirroring the Vite plugin's virtual module).\n const rpcClientStubPath = path.join(heliumDir, \"rpc-client-stub.ts\");\n const rpcClientStubCode = `export * from 'heliumts/server';\\n${generateClientModule(serverExports.methods)}`;\n fs.writeFileSync(rpcClientStubPath, rpcClientStubCode);\n\n fs.writeFileSync(ssrClientStubPath, ssrClientStubCode);\n fs.writeFileSync(ssrTransitionsStubPath, ssrTransitionsStubCode);\n fs.writeFileSync(ssrPrefetchStubPath, ssrPrefetchStubCode);\n\n // Bundle with esbuild\n try {\n await esbuild({\n entryPoints: [entryPath],\n outfile: path.join(root, \"dist\", \"server.js\"),\n bundle: true,\n platform: \"node\",\n format: \"esm\",\n jsx: \"automatic\",\n jsxImportSource: \"react\",\n plugins: [\n {\n name: \"helium-ssr-client-alias\",\n setup(build) {\n build.onResolve({ filter: /^heliumts\\/client$/ }, () => ({ path: ssrClientStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/transitions$/ }, () => ({ path: ssrTransitionsStubPath }));\n build.onResolve({ filter: /^heliumts\\/client\\/prefetch$/ }, () => ({ path: ssrPrefetchStubPath }));\n // Intercept heliumts/server imports from client code\n // and redirect to the RPC stub module (method stubs).\n // Server-side files and generated server-module resolve normally.\n const serverDirAbs = path.join(root, \"src\", \"server\");\n build.onResolve({ filter: /^heliumts\\/server$/ }, (args) => {\n const importer = args.importer;\n // Allow the generated server-module and env-loader to\n // import the real heliumts/server framework exports.\n if (importer.startsWith(heliumDir) || importer.startsWith(serverDirAbs)) {\n return undefined; // let esbuild resolve normally\n }\n return { path: rpcClientStubPath };\n });\n },\n },\n ],\n external: [\n // External common database and heavy dependencies\n \"mongodb\",\n \"mongoose\",\n \"pg\",\n \"mysql\",\n \"mysql2\",\n \"sqlite3\",\n \"better-sqlite3\",\n \"redis\",\n \"esbuild\",\n // Node.js built-ins are automatically external, but let's be explicit\n \"crypto\",\n \"fs\",\n \"path\",\n \"http\",\n \"https\",\n \"stream\",\n \"zlib\",\n \"util\",\n ],\n target: \"node18\",\n metafile: true,\n banner: {\n js: \"import { createRequire } from 'module'; const require = createRequire(import.meta.url);\",\n },\n });\n\n // Display server build output\n const serverOutputPath = path.relative(root, path.join(root, \"dist\", \"server.js\"));\n const serverStats = fs.statSync(path.join(root, \"dist\", \"server.js\"));\n const serverSizeKB = (serverStats.size / 1024).toFixed(2);\n log(\"info\", ` ${serverOutputPath.padEnd(35)} ${serverSizeKB.padStart(8)} kB`);\n\n log(\"info\", \"Server build complete.\");\n\n // Bundle config helpers so moving the config into dist preserves relative imports.\n const configFile = [\"helium.config.js\", \"helium.config.mjs\", \"helium.config.ts\"].map((name) => path.join(root, name)).find((candidate) => fs.existsSync(candidate));\n if (configFile) {\n await esbuild({\n entryPoints: [configFile],\n outfile: path.join(root, \"dist\", \"helium.config.js\"),\n bundle: true,\n packages: \"external\",\n platform: \"node\",\n format: \"esm\",\n target: \"node20\",\n });\n log(\"info\", \"Bundled Helium config to dist/helium.config.js\");\n }\n\n log(\"info\", \"--------------------------------\");\n log(\"info\", \"✓ Build finished successfully.\");\n log(\"info\", \"▶ Run 'helium start' to start the production server.\");\n\n // Exit cleanly after build completes\n process.exit(0);\n } catch (e) {\n log(\"error\", \"Server build failed:\", e);\n process.exit(1);\n }\n});\n\ncli.command(\"start\", \"Start production server\").action(async () => {\n const serverPath = path.join(root, \"dist\", \"server.js\");\n if (!fs.existsSync(serverPath)) {\n log(\"error\", 'Server build not found. Run \"helium build\" first.');\n process.exit(1);\n }\n\n // When running in production, look for config in dist directory first\n // This allows the transpiled config to be found\n const server = spawn(process.execPath, [serverPath], {\n stdio: \"inherit\",\n env: { ...process.env, NODE_ENV: process.env.NODE_ENV || \"production\", HELIUM_CONFIG_DIR: path.join(root, \"dist\") },\n });\n monitorChild(server);\n});\n\ncli.help();\ncli.parse();\n"]}
|
package/dist/client/Router.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export type LinkProps = React.PropsWithChildren<Omit<React.AnchorHTMLAttributes<
|
|
|
67
67
|
*
|
|
68
68
|
* Automatically prefetches page chunks on hover for faster navigation.
|
|
69
69
|
*/
|
|
70
|
-
export declare function Link(props: LinkProps):
|
|
70
|
+
export declare function Link(props: LinkProps): React.JSX.Element;
|
|
71
71
|
/**
|
|
72
72
|
* Props passed to an optional \`AppShell\` wrapper component used by <AppRouter />.
|
|
73
73
|
*
|
|
@@ -80,6 +80,6 @@ export type AppShellProps<TPageProps extends Record<string, unknown> = Record<st
|
|
|
80
80
|
};
|
|
81
81
|
export declare function AppRouter({ AppShell }: {
|
|
82
82
|
AppShell?: ComponentType<AppShellProps>;
|
|
83
|
-
}):
|
|
83
|
+
}): React.JSX.Element;
|
|
84
84
|
export {};
|
|
85
85
|
//# sourceMappingURL=Router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../src/client/Router.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EA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;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,EAAE,OAAe,EAAE,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,QAyBlF;AA6CD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,iBAAiB,CAC3C,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,GAAG;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qDAAqD;IACrD,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB,CACJ,CAAC;AA+BF;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,qBA4DpC;AAGD;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC9F,SAAS,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACrC,SAAS,EAAE,UAAU,CAAC;IACtB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B,CAAC;AAqBF,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;CAAE,qBAiLlF"}
|
package/dist/client/Router.js
CHANGED
|
@@ -367,6 +367,22 @@ export function Link(props) {
|
|
|
367
367
|
};
|
|
368
368
|
return (_jsx("a", { ...restProps, href: href, target: target, download: download, onClick: onClick, onMouseEnter: onMouseEnter, onFocus: onFocus, className: className, children: children }));
|
|
369
369
|
}
|
|
370
|
+
// Keep the component type and shared layout positions stable across router
|
|
371
|
+
// updates, so loading page props or navigating does not discard local state.
|
|
372
|
+
const PageRouteContext = React.createContext(null);
|
|
373
|
+
function RoutedPage(pageProps) {
|
|
374
|
+
const route = React.useContext(PageRouteContext);
|
|
375
|
+
if (!route) {
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
const Page = route.Component;
|
|
379
|
+
let content = _jsx(Page, { ...pageProps });
|
|
380
|
+
for (let i = route.layouts.length - 1; i >= 0; i--) {
|
|
381
|
+
const Layout = route.layouts[i];
|
|
382
|
+
content = _jsx(Layout, { children: content });
|
|
383
|
+
}
|
|
384
|
+
return content;
|
|
385
|
+
}
|
|
370
386
|
// Main router component
|
|
371
387
|
export function AppRouter({ AppShell }) {
|
|
372
388
|
// useTransition for concurrent rendering - allows React to keep UI responsive during navigation
|
|
@@ -394,17 +410,16 @@ export function AppRouter({ AppShell }) {
|
|
|
394
410
|
// Use useSyncExternalStore to subscribe to location changes
|
|
395
411
|
// This ensures synchronous updates when location changes
|
|
396
412
|
const state = useSyncExternalStore(subscribeToLocation, getLocationSnapshot, getServerSnapshot);
|
|
413
|
+
const targetPath = `${state.path}${typeof window !== "undefined" ? window.location.search : ""}`;
|
|
397
414
|
const [runtimeSSRProps, setRuntimeSSRProps] = React.useState(() => {
|
|
398
415
|
const payload = getInitialSSRBootstrap();
|
|
399
416
|
if (!payload) {
|
|
400
|
-
return {};
|
|
417
|
+
return { path: targetPath, props: {} };
|
|
401
418
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
return {};
|
|
419
|
+
const bootstrapPath = `${payload.path}${payload.search ?? window.location.search}`;
|
|
420
|
+
return { path: bootstrapPath, props: payload.props };
|
|
406
421
|
});
|
|
407
|
-
const
|
|
422
|
+
const hydrationDoneRef = React.useRef(false);
|
|
408
423
|
const match = useMemo(() => matchRoute(state.path, routes), [state.path, routes]);
|
|
409
424
|
// Use matched params, or fall back to re-extracting from path using global routes during HMR
|
|
410
425
|
const currentParams = match?.params ?? (isDevEnvironment() ? extractParamsFromPath(state.path) : {});
|
|
@@ -431,15 +446,14 @@ export function AppRouter({ AppShell }) {
|
|
|
431
446
|
isPending,
|
|
432
447
|
};
|
|
433
448
|
React.useEffect(() => {
|
|
434
|
-
|
|
435
|
-
//
|
|
436
|
-
if (!
|
|
449
|
+
// On first client render, keep the matching SSR payload. A ref avoids
|
|
450
|
+
// restarting this effect and remounting content just to mark hydration.
|
|
451
|
+
if (!hydrationDoneRef.current) {
|
|
452
|
+
hydrationDoneRef.current = true;
|
|
437
453
|
const bootstrap = getInitialSSRBootstrap();
|
|
438
|
-
if (bootstrap && bootstrap.path ===
|
|
439
|
-
setHydrationDone(true);
|
|
454
|
+
if (bootstrap && `${bootstrap.path}${bootstrap.search ?? window.location.search}` === targetPath) {
|
|
440
455
|
return;
|
|
441
456
|
}
|
|
442
|
-
setHydrationDone(true);
|
|
443
457
|
}
|
|
444
458
|
let cancelled = false;
|
|
445
459
|
const load = async () => {
|
|
@@ -460,16 +474,16 @@ export function AppRouter({ AppShell }) {
|
|
|
460
474
|
return;
|
|
461
475
|
}
|
|
462
476
|
if (ssrPayload.kind === "props") {
|
|
463
|
-
setRuntimeSSRProps(ssrPayload.props);
|
|
477
|
+
setRuntimeSSRProps({ path: targetPath, props: ssrPayload.props });
|
|
464
478
|
return;
|
|
465
479
|
}
|
|
466
|
-
setRuntimeSSRProps({});
|
|
480
|
+
setRuntimeSSRProps({ path: targetPath, props: {} });
|
|
467
481
|
};
|
|
468
482
|
void load();
|
|
469
483
|
return () => {
|
|
470
484
|
cancelled = true;
|
|
471
485
|
};
|
|
472
|
-
}, [
|
|
486
|
+
}, [targetPath]);
|
|
473
487
|
React.useEffect(() => {
|
|
474
488
|
const controller = new AbortController();
|
|
475
489
|
const targetPath = `${state.path}${window.location.search || ""}`;
|
|
@@ -500,24 +514,13 @@ export function AppRouter({ AppShell }) {
|
|
|
500
514
|
const content = _jsx(NotFoundComp, {});
|
|
501
515
|
return _jsx(RouterContext.Provider, { value: routerValue, children: AppShell ? _jsx(AppShell, { Component: NotFoundComp, pageProps: {} }) : content });
|
|
502
516
|
}
|
|
503
|
-
const Page = match.route.Component;
|
|
504
517
|
const pageProps = {
|
|
505
|
-
...runtimeSSRProps,
|
|
518
|
+
...(runtimeSSRProps.path === targetPath ? runtimeSSRProps.props : {}),
|
|
506
519
|
params: match.params,
|
|
507
520
|
searchParams: currentSearchParams,
|
|
508
521
|
};
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
let content = _jsx(Page, { ...pageProps });
|
|
512
|
-
// Wrap page with layouts (from outer to inner)
|
|
513
|
-
for (let i = match.route.layouts.length - 1; i >= 0; i--) {
|
|
514
|
-
const Layout = match.route.layouts[i];
|
|
515
|
-
content = _jsx(Layout, { children: content });
|
|
516
|
-
}
|
|
517
|
-
return content;
|
|
518
|
-
};
|
|
519
|
-
const finalContent = AppShell ? (_jsx(AppShell, { Component: WrappedPage, pageProps: pageProps, children: _jsx(WrappedPage, {}) })) : (_jsx(WrappedPage, {}));
|
|
520
|
-
return _jsx(RouterContext.Provider, { value: routerValue, children: finalContent });
|
|
522
|
+
const finalContent = AppShell ? (_jsx(AppShell, { Component: RoutedPage, pageProps: pageProps, children: _jsx(RoutedPage, { ...pageProps }) })) : (_jsx(RoutedPage, { ...pageProps }));
|
|
523
|
+
return (_jsx(RouterContext.Provider, { value: routerValue, children: _jsx(PageRouteContext.Provider, { value: match.route, children: finalContent }) }));
|
|
521
524
|
}
|
|
522
525
|
function applyRouteMetadata(meta) {
|
|
523
526
|
if (typeof document === "undefined") {
|