Skip to content

Commit 48f1e30

Browse files
committed
feat: add telemetry for performance metrics and opt-out option
1 parent c89aac3 commit 48f1e30

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ bun run benchmark
104104

105105
> Results may vary based on your app size and system. The test app includes 4 routes with images, fonts, and interactivity.
106106
107+
## Telemetry
108+
109+
Anonymized telemetry is collected to help improve the tool. **No IP addresses are tracked.** All we collect is time taken and RAM used.
110+
111+
To disable telemetry:
112+
113+
```bash
114+
NEXT_SINGLE_FILE_NO_TELEMETRY=1 bunx next-single-file --input out
115+
```
116+
117+
Telemetry is sent by default. Set the above env var to opt out.
118+
107119
## Development
108120

109121
```bash

index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { parseNextOutput } from "./src/parser";
33
import { inlineAssets } from "./src/inliner";
44
import { generateRouterShim } from "./src/router";
55
import { bundleToSingleHtml } from "./src/bundler";
6+
import { sendTelemetry, getMemoryUsage } from "./src/telemetry";
67
import { $ } from "bun";
78

89
function parseArgs() {
@@ -30,6 +31,8 @@ function parseArgs() {
3031

3132
const { inputDir, outputFile } = parseArgs();
3233

34+
const startTime = Date.now();
35+
3336
console.log(`📖 Parsing Next.js output from: ${inputDir}`);
3437
const parsed = await parseNextOutput(inputDir);
3538

@@ -50,7 +53,16 @@ const html = bundleToSingleHtml(inlined, routerShim);
5053
await $`mkdir -p ${outputFile.split("/").slice(0, -1).join("/") || "."}`.quiet();
5154
await Bun.write(outputFile, html);
5255

56+
const endTime = Date.now();
57+
const memoryUsed = getMemoryUsage();
58+
5359
console.log(`✅ Done! Output: ${outputFile}`);
5460
console.log(` Size: ${(html.length / 1024).toFixed(1)} KB`);
61+
console.log(` Time: ${(endTime - startTime)} ms`);
62+
console.log(` Memory: ${memoryUsed} MB`);
5563
console.log("Star us: https://github.com/simples-tools/next-single-file");
56-
console.log("Report bugs: https://github.com/simples-tools/next-single-file/issues");
64+
console.log("Report bugs: https://github.com/simples-tools/next-single-file/issues");
65+
66+
if (process.env.NEXT_SINGLE_FILE_NO_TELEMETRY !== "1") {
67+
await sendTelemetry(endTime - startTime, memoryUsed);
68+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-single-file",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Convert Next.js static export to a single HTML file with hash routing",
55
"bin": {
66
"next-single-file": "dist/cli.js"

src/telemetry.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export async function sendTelemetry(time: number, ram: number): Promise<void> {
2+
const endpoint = "https://next-single-file-backend.vercel.app/";
3+
4+
try {
5+
const response = await fetch(endpoint, {
6+
method: "POST",
7+
headers: { "Content-Type": "application/json" },
8+
body: JSON.stringify({ time, ram }),
9+
});
10+
11+
if (!response.ok) {
12+
console.error("Telemetry failed:", response.statusText);
13+
return;
14+
}
15+
16+
} catch (error) {
17+
console.error("Telemetry error:", error);
18+
}
19+
}
20+
21+
export function getMemoryUsage(): number {
22+
const usage = process.memoryUsage();
23+
return Math.round(usage.heapTotal / 1024 / 1024);
24+
}

0 commit comments

Comments
 (0)