bun-ui-tests 1.0.5 → 1.0.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.
Files changed (2) hide show
  1. package/cli.ts +74 -56
  2. package/package.json +1 -1
package/cli.ts CHANGED
@@ -5,22 +5,42 @@ import { readFile, access } from "node:fs/promises";
5
5
  import { join, dirname, resolve } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
 
8
- // Robustly determine the package root directory
8
+ // Função robusta para determinar o diretório raiz do pacote
9
9
  function getPackageRoot() {
10
- // 1. Try to use process.argv[1] which often points to the real script path
11
- // when run via bunx or direct execution.
10
+ // 1. Tentar import.meta.dir (Bun específico)
11
+ if (import.meta.dir) {
12
+ return import.meta.dir;
13
+ }
14
+
15
+ // 2. Tentar process.argv[1] (caminho do script)
12
16
  try {
13
17
  const argvPath = process.argv[1];
14
- if (argvPath && argvPath.endsWith("cli.ts")) {
15
- return dirname(argvPath);
18
+ if (argvPath) {
19
+ // Se é um arquivo .ts, usa o diretório dele
20
+ if (argvPath.endsWith('.ts')) {
21
+ return dirname(argvPath);
22
+ }
23
+
24
+ // Se é um executável, procura node_modules
25
+ // bunx instala em: ~/.bun/install/cache/bun-ui-tests@version/
26
+ const parts = argvPath.split('/');
27
+ const cacheIndex = parts.findIndex(p => p === 'cache');
28
+ if (cacheIndex !== -1 && cacheIndex + 1 < parts.length) {
29
+ // Pega até o nome do pacote (ex: bun-ui-tests@1.0.5)
30
+ const packagePath = parts.slice(0, cacheIndex + 2).join('/');
31
+ return packagePath;
32
+ }
16
33
  }
17
- } catch (e) {}
34
+ } catch (e) {
35
+ console.error('Error resolving from argv[1]:', e);
36
+ }
18
37
 
19
- // 2. Fallback to import.meta.dir
20
- return import.meta.dir;
38
+ // 3. Fallback: usar diretório atual
39
+ console.warn('⚠️ Could not determine package root, using current directory');
40
+ return process.cwd();
21
41
  }
22
42
 
23
- const __dirname = getPackageRoot();
43
+ const packageRoot = getPackageRoot();
24
44
 
25
45
  const COMMANDS = {
26
46
  run: "Run the test UI (production mode)",
@@ -33,7 +53,7 @@ async function showHelp() {
33
53
  🧪 Bun Test UI - A beautiful UI for running Bun tests
34
54
 
35
55
  Usage:
36
- buntestui <command>
56
+ bunx bun-ui-tests <command>
37
57
 
38
58
  Commands:
39
59
  run Start the test UI (production mode)
@@ -41,50 +61,44 @@ Commands:
41
61
  help Show this help message
42
62
 
43
63
  Examples:
44
- buntestui run # Run in production mode
45
- buntestui dev # Run in development mode (for testing)
64
+ bunx bun-ui-tests run # Run in production mode
65
+ bunx bun-ui-tests dev # Run in development mode (for testing)
46
66
  `);
47
67
  }
48
68
 
49
- async function buildFrontend() {
50
- console.log("🏗️ Building frontend...\n");
69
+ async function checkBuildExists(): Promise<boolean> {
70
+ const distPath = join(packageRoot, "app", "dist", "index.html");
51
71
 
52
- const appDir = join(__dirname, "app");
72
+ console.log(`🔍 Debug Info:`);
73
+ console.log(` - process.argv[1]: ${process.argv[1]}`);
74
+ console.log(` - Resolved packageRoot: ${packageRoot}`);
75
+ console.log(` - Looking for: ${distPath}`);
53
76
 
54
- return new Promise<void>((resolve, reject) => {
55
- const proc = spawn("bun", ["run", "build"], {
56
- cwd: appDir,
57
- stdio: "inherit",
58
- shell: true
59
- });
60
-
61
- proc.on("close", (code) => {
62
- if (code === 0) {
63
- console.log("\n✅ Frontend built successfully!");
64
- resolve();
65
- } else {
66
- reject(new Error(`Frontend build failed with code ${code}`));
67
- }
68
- });
69
-
70
- proc.on("error", (err) => {
71
- reject(err);
72
- });
73
- });
74
- }
75
-
76
- async function checkBuildExists(): Promise<boolean> {
77
- const distPath = join(__dirname, "app", "dist", "index.html");
78
- console.error(`Debug: process.argv[1] is ${process.argv[1]}`);
79
- console.error(`Debug: Resolved __dirname is ${__dirname}`);
80
77
  try {
81
78
  const exists = await Bun.file(distPath).exists();
82
79
  if (!exists) {
83
- console.error(`Debug: Bun.file.exists failed for: ${distPath}`);
80
+ console.log(` - File exists: NO ❌`);
81
+
82
+ // Tentar procurar em locais alternativos
83
+ const alternatives = [
84
+ join(process.cwd(), "app", "dist", "index.html"),
85
+ join(dirname(process.argv[0]), "app", "dist", "index.html"),
86
+ ];
87
+
88
+ console.log(`\n🔍 Trying alternative paths:`);
89
+ for (const alt of alternatives) {
90
+ const altExists = await Bun.file(alt).exists();
91
+ console.log(` - ${alt}: ${altExists ? '✓' : '✗'}`);
92
+ if (altExists) {
93
+ return true;
94
+ }
95
+ }
96
+ } else {
97
+ console.log(` - File exists: YES ✓`);
84
98
  }
85
99
  return exists;
86
100
  } catch (err) {
87
- console.error(`Debug: Error checking path ${distPath}:`, err);
101
+ console.error(`❌ Error checking path:`, err);
88
102
  return false;
89
103
  }
90
104
  }
@@ -94,9 +108,19 @@ async function runTestUI() {
94
108
  const buildExists = await checkBuildExists();
95
109
 
96
110
  if (!buildExists) {
97
- console.log("⚠️ Frontend assets not found.\n");
98
- console.log("If you are running from source, please run: bun run build");
99
- console.log("If you installed via npm, this might be a packaging issue.\n");
111
+ console.log("\n⚠️ Frontend assets not found.\n");
112
+ console.log("This usually means one of:");
113
+ console.log(" 1. The package wasn't built before publishing (contact maintainer)");
114
+ console.log(" 2. You're running from source (run: bun run build first)");
115
+ console.log(" 3. Installation issue (try: npm cache clean --force)\n");
116
+
117
+ console.log("💡 Temporary workaround:");
118
+ console.log(" git clone https://github.com/KillDarkness/Bun-UI-Test.git");
119
+ console.log(" cd Bun-UI-Test");
120
+ console.log(" bun install");
121
+ console.log(" cd app && bun install && bun run build && cd ..");
122
+ console.log(" bun run ui-runner.ts\n");
123
+
100
124
  process.exit(1);
101
125
  }
102
126
 
@@ -106,11 +130,10 @@ async function runTestUI() {
106
130
  console.log("Press Ctrl+C to stop\n");
107
131
 
108
132
  // Roda o script do backend diretamente com Bun
109
- // O usuário OBRIGATORIAMENTE tem Bun instalado para usar esta ferramenta
110
- const runnerScript = join(__dirname, "ui-runner.ts");
133
+ const runnerScript = join(packageRoot, "ui-runner.ts");
111
134
 
112
135
  const proc = spawn("bun", ["run", runnerScript], {
113
- cwd: process.cwd(), // Roda no diretório atual do usuário
136
+ cwd: process.cwd(),
114
137
  stdio: "inherit",
115
138
  shell: false,
116
139
  env: { ...process.env, NODE_ENV: "production" }
@@ -142,8 +165,7 @@ async function runDevMode() {
142
165
  console.log("🌐 Frontend: http://localhost:5050 (with hot reload)\n");
143
166
  console.log("Press Ctrl+C to stop\n");
144
167
 
145
- // Inicia o backend (ui-runner.ts) com bun run e flag de dev mode
146
- const backendPath = join(__dirname, "ui-runner.ts");
168
+ const backendPath = join(packageRoot, "ui-runner.ts");
147
169
  const backendProc = spawn("bun", ["run", backendPath], {
148
170
  cwd: process.cwd(),
149
171
  stdio: "inherit",
@@ -151,18 +173,15 @@ async function runDevMode() {
151
173
  env: { ...process.env, BUN_TEST_UI_DEV: "true" }
152
174
  });
153
175
 
154
- // Aguarda um pouco para o backend iniciar
155
176
  await new Promise(resolve => setTimeout(resolve, 1000));
156
177
 
157
- // Inicia o frontend em modo dev
158
- const appDir = join(__dirname, "app");
178
+ const appDir = join(packageRoot, "app");
159
179
  const frontendProc = spawn("bun", ["run", "dev"], {
160
180
  cwd: appDir,
161
181
  stdio: "inherit",
162
182
  shell: true
163
183
  });
164
184
 
165
- // Handle Ctrl+C
166
185
  process.on("SIGINT", () => {
167
186
  console.log("\n\n👋 Stopping Bun Test UI...");
168
187
  backendProc.kill("SIGINT");
@@ -170,7 +189,6 @@ async function runDevMode() {
170
189
  process.exit(0);
171
190
  });
172
191
 
173
- // Se um processo terminar, termina o outro também
174
192
  backendProc.on("close", (code) => {
175
193
  console.log("\n❌ Backend stopped");
176
194
  frontendProc.kill("SIGINT");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-ui-tests",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "A beautiful UI for running Bun tests",
5
5
  "type": "module",
6
6
  "bin": {