@frixaco/hbench 0.1.0 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frixaco/hbench",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "hbench": "./bin/hbench.js"
@@ -10,19 +10,15 @@
10
10
  },
11
11
  "files": [
12
12
  "bin",
13
- "server",
14
- "ui",
15
- "lib",
16
- "bun-env.d.ts",
17
- "tsconfig.json",
18
- "tsconfig.base.json",
13
+ "dist",
19
14
  "README.md",
20
15
  "LICENSE*"
21
16
  ],
22
17
  "scripts": {
23
18
  "dev": "bun --hot server/index.ts",
24
- "start": "NODE_ENV=production bun server/index.ts",
19
+ "start": "NODE_ENV=production bun --cwd dist index.js",
25
20
  "build": "bun run server/build.ts",
21
+ "prepack": "bun run build",
26
22
  "format": "prettier --write .",
27
23
  "lint": "eslint",
28
24
  "lint-fix": "eslint --fix",
package/bun-env.d.ts DELETED
@@ -1,17 +0,0 @@
1
- // Generated by `bun init`
2
-
3
- declare module "*.svg" {
4
- /**
5
- * A path to the SVG file
6
- */
7
- const path: `${string}.svg`;
8
- export = path;
9
- }
10
-
11
- declare module "*.module.css" {
12
- /**
13
- * A record of class names to their corresponding CSS module classes
14
- */
15
- const classes: { readonly [key: string]: string };
16
- export = classes;
17
- }
package/lib/.gitkeep DELETED
File without changes
package/server/build.ts DELETED
@@ -1,172 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- if (process.argv.includes("--help") || process.argv.includes("-h")) {
4
- console.log(`
5
- šŸ—ļø Bun Build Script
6
-
7
- Usage: bun run server/build.ts [options]
8
-
9
- Common Options:
10
- --outdir <path> Output directory (default: "dist")
11
- --minify Enable minification (or --minify.whitespace, --minify.syntax, etc)
12
- --sourcemap <type> Sourcemap type: none|linked|inline|external
13
- --target <target> Build target: browser|bun|node
14
- --format <format> Output format: esm|cjs|iife
15
- --splitting Enable code splitting
16
- --packages <type> Package handling: bundle|external
17
- --public-path <path> Public path for assets
18
- --env <mode> Environment handling: inline|disable|prefix*
19
- --conditions <list> Package.json export conditions (comma separated)
20
- --external <list> External packages (comma separated)
21
- --banner <text> Add banner text to output
22
- --footer <text> Add footer text to output
23
- --define <obj> Define global constants (e.g. --define.VERSION=1.0.0)
24
- --help, -h Show this help message
25
-
26
- Example:
27
- bun run server/build.ts --outdir=dist --minify --sourcemap=linked --external=react,react-dom
28
- `);
29
- process.exit(0);
30
- }
31
-
32
- const toCamelCase = (str: string): string =>
33
- str.replace(/-([a-z])/g, (_, letter: string) => letter.toUpperCase());
34
-
35
- const parseValue = (value: string): string | boolean | number | string[] => {
36
- if (value === "true") return true;
37
- if (value === "false") return false;
38
-
39
- if (/^\d+$/.test(value)) return parseInt(value, 10);
40
- if (/^\d*\.\d+$/.test(value)) return parseFloat(value);
41
-
42
- if (value.includes(",")) return value.split(",").map((v) => v.trim());
43
-
44
- return value;
45
- };
46
-
47
- function parseArgs(): Partial<Bun.BuildConfig> {
48
- const config: Record<string, unknown> = {};
49
- const args = process.argv.slice(2);
50
-
51
- for (let i = 0; i < args.length; i++) {
52
- const arg = args[i];
53
- if (arg === undefined) continue;
54
- if (!arg.startsWith("--")) continue;
55
-
56
- if (arg.startsWith("--no-")) {
57
- const key = toCamelCase(arg.slice(5));
58
- config[key] = false;
59
- continue;
60
- }
61
-
62
- if (
63
- !arg.includes("=") &&
64
- (i === args.length - 1 || args[i + 1]?.startsWith("--"))
65
- ) {
66
- const key = toCamelCase(arg.slice(2));
67
- config[key] = true;
68
- continue;
69
- }
70
-
71
- let key: string;
72
- let value: string;
73
-
74
- if (arg.includes("=")) {
75
- [key, value] = arg.slice(2).split("=", 2) as [string, string];
76
- } else {
77
- key = arg.slice(2);
78
- value = args[++i] ?? "";
79
- }
80
-
81
- key = toCamelCase(key);
82
-
83
- if (key.includes(".")) {
84
- const parts = key.split(".");
85
- if (parts.length > 2) {
86
- console.warn(
87
- `Warning: Deeply nested option "${key}" is not supported. Only single-level nesting (e.g., --minify.whitespace) is allowed.`,
88
- );
89
- continue;
90
- }
91
- const parentKey = parts[0]!;
92
- const childKey = parts[1]!;
93
- const existing = config[parentKey];
94
- if (
95
- typeof existing !== "object" ||
96
- existing === null ||
97
- Array.isArray(existing)
98
- ) {
99
- config[parentKey] = {};
100
- }
101
- (config[parentKey] as Record<string, unknown>)[childKey] =
102
- parseValue(value);
103
- } else {
104
- config[key] = parseValue(value);
105
- }
106
- }
107
-
108
- return config as Partial<Bun.BuildConfig>;
109
- }
110
-
111
- const formatFileSize = (bytes: number): string => {
112
- const units = ["B", "KB", "MB", "GB"];
113
- let size = bytes;
114
- let unitIndex = 0;
115
-
116
- while (size >= 1024 && unitIndex < units.length - 1) {
117
- size /= 1024;
118
- unitIndex++;
119
- }
120
-
121
- return `${size.toFixed(2)} ${units[unitIndex]}`;
122
- };
123
-
124
- console.log("\nšŸš€ Starting build process...\n");
125
-
126
- const cliConfig = parseArgs();
127
- const outdir = cliConfig.outdir || path.join(process.cwd(), "dist");
128
-
129
- if (existsSync(outdir)) {
130
- console.log(`šŸ—‘ļø Cleaning previous build at ${outdir}`);
131
- await rm(outdir, { recursive: true, force: true });
132
- }
133
-
134
- const start = performance.now();
135
-
136
- const entrypoints = [...new Bun.Glob("**.html").scanSync("ui")]
137
- .map((a) => path.resolve("ui", a))
138
- .filter((dir) => !dir.includes("node_modules"));
139
- console.log(
140
- `šŸ“„ Found ${entrypoints.length} HTML ${entrypoints.length === 1 ? "file" : "files"} to process\n`,
141
- );
142
-
143
- const result = await Bun.build({
144
- entrypoints,
145
- outdir,
146
- plugins: [plugin],
147
- minify: true,
148
- target: "browser",
149
- sourcemap: "linked",
150
- define: {
151
- "process.env.NODE_ENV": JSON.stringify("production"),
152
- },
153
- ...cliConfig,
154
- });
155
-
156
- const end = performance.now();
157
-
158
- const outputTable = result.outputs.map((output) => ({
159
- File: path.relative(process.cwd(), output.path),
160
- Type: output.kind,
161
- Size: formatFileSize(output.size),
162
- }));
163
-
164
- console.table(outputTable);
165
- const buildTime = (end - start).toFixed(2);
166
-
167
- console.log(`\nāœ… Build completed in ${buildTime}ms\n`);
168
-
169
- import plugin from "bun-plugin-tailwind";
170
- import { existsSync } from "fs";
171
- import { rm } from "fs/promises";
172
- import path from "path";