bun-ui-tests 1.0.8 → 1.0.9

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 +45 -8
  2. package/package.json +1 -1
package/cli.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
3
  import { spawn } from "node:child_process";
4
- import { readFile, access } from "node:fs/promises";
4
+ import { readdir, readFile, access } from "node:fs/promises";
5
5
  import { join, dirname, resolve } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
+ import { homedir } from "node:os";
7
8
 
8
9
  // Função robusta para determinar o diretório raiz do pacote
9
10
  function getPackageRoot() {
@@ -28,11 +29,9 @@ function getPackageRoot() {
28
29
  }
29
30
 
30
31
  // Se é um executável, procura node_modules ou cache
31
- // bunx instala em: ~/.bun/install/cache/bun-ui-tests@version/
32
32
  const parts = argvPath.split('/');
33
33
  const cacheIndex = parts.findIndex(p => p === 'cache' || p === '.bun' || p === 'node_modules');
34
34
  if (cacheIndex !== -1 && cacheIndex + 1 < parts.length) {
35
- // Pega até o nome do pacote (ex: bun-ui-tests@1.0.5)
36
35
  const packagePath = parts.slice(0, cacheIndex + 2).join('/');
37
36
  return packagePath;
38
37
  }
@@ -45,8 +44,6 @@ function getPackageRoot() {
45
44
  return process.cwd();
46
45
  }
47
46
 
48
- const packageRoot = getPackageRoot();
49
-
50
47
  // Cores ANSI suaves
51
48
  const colors = {
52
49
  reset: "\x1b[0m",
@@ -64,6 +61,38 @@ const COMMANDS = {
64
61
  help: "Show this help message"
65
62
  };
66
63
 
64
+ async function findGlobalPackageRoot(): Promise<string | null> {
65
+ try {
66
+ const home = homedir();
67
+ const cacheDir = join(home, ".bun", "install", "cache");
68
+
69
+ // Check if cache dir exists
70
+ if (!await Bun.file(cacheDir).exists() && !await Bun.file(join(cacheDir, "..")).exists()) {
71
+ return null;
72
+ }
73
+
74
+ // Read directory entries of cacheDir
75
+ const entries = await readdir(cacheDir);
76
+ const myPackages = entries.filter(e => e.startsWith("bun-ui-tests@"));
77
+
78
+ // Sort by version (simple string sort for now, assuming standard format)
79
+ myPackages.sort().reverse();
80
+
81
+ for (const pkgName of myPackages) {
82
+ const candidate = join(cacheDir, pkgName);
83
+ const runnerPath = join(candidate, "ui-runner.ts");
84
+ const distPath = join(candidate, "app", "dist", "index.html");
85
+
86
+ if (await Bun.file(runnerPath).exists() && await Bun.file(distPath).exists()) {
87
+ return candidate;
88
+ }
89
+ }
90
+ } catch (e) {
91
+ return null;
92
+ }
93
+ return null;
94
+ }
95
+
67
96
  async function findVerifiedRoot(): Promise<string> {
68
97
  const possibleRoots = [
69
98
  getPackageRoot(),
@@ -81,12 +110,20 @@ async function findVerifiedRoot(): Promise<string> {
81
110
  }
82
111
  }
83
112
 
84
- // Se não achou, tenta procurar subindo diretórios
113
+ // Fallback: search in global cache
114
+ const globalRoot = await findGlobalPackageRoot();
115
+ if (globalRoot) return globalRoot;
116
+
117
+ // Se não achou, tenta procurar subindo diretórios (mas verifica ambos os arquivos)
85
118
  try {
86
119
  let current = getPackageRoot();
87
- for (let i = 0; i < 3; i++) {
120
+ for (let i = 0; i < 4; i++) {
88
121
  const runnerPath = join(current, "ui-runner.ts");
89
- if (await Bun.file(runnerPath).exists()) return current;
122
+ const distPath = join(current, "app", "dist", "index.html");
123
+
124
+ if (await Bun.file(runnerPath).exists() && await Bun.file(distPath).exists()) {
125
+ return current;
126
+ }
90
127
  current = dirname(current);
91
128
  }
92
129
  } catch (e) {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-ui-tests",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "A beautiful UI for running Bun tests",
5
5
  "type": "module",
6
6
  "bin": {