github-search-cli 9.8.1 → 9.8.2

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/src/user.ts CHANGED
@@ -212,20 +212,21 @@ export async function fetchUserProfile(
212
212
  if (userPayload.public_repos > 0) {
213
213
  const perPage = Math.min(limit, 100);
214
214
  const maxPages = Math.ceil(limit / perPage);
215
- for (let page = 1; page <= maxPages; page++) {
216
- const url =
217
- `https://api.github.com/users/${encodeURIComponent(name)}/repos` +
218
- `?per_page=${perPage}&sort=pushed&page=${page}`;
219
- const res = await fetch(url, { headers: apiHeaders(token) });
220
- if (!res.ok) {
221
- // User metadata succeeded; degraded summary beats a hard failure.
222
- break;
223
- }
224
- const items = (await res.json()) as GitHubRepoPayload[];
225
- if (!Array.isArray(items)) break; // unexpected shape — degrade gracefully
226
- repos.push(...items);
227
- if (repos.length >= limit || items.length < perPage) break;
228
- }
215
+ const pages = await Promise.all(
216
+ Array.from({ length: maxPages }, (_, i) => i + 1).map(async (page) => {
217
+ const url =
218
+ `https://api.github.com/users/${encodeURIComponent(name)}/repos` +
219
+ `?per_page=${perPage}&sort=pushed&page=${page}`;
220
+ const res = await fetch(url, { headers: apiHeaders(token) });
221
+ if (!res.ok) {
222
+ // User metadata succeeded; degraded summary beats a hard failure.
223
+ return [];
224
+ }
225
+ const items = (await res.json()) as GitHubRepoPayload[];
226
+ return Array.isArray(items) ? items : []; // unexpected shape — skip
227
+ }),
228
+ );
229
+ repos.push(...pages.flat());
229
230
  }
230
231
 
231
232
  return normalizeUser(userPayload, repos.slice(0, limit));
@@ -1,59 +0,0 @@
1
- // src/config.ts
2
- import { homedir } from "os";
3
- import { join } from "path";
4
- import { mkdirSync, readFileSync, writeFileSync } from "fs";
5
- function stateDir() {
6
- const xdg = process.env.XDG_STATE_HOME;
7
- const base = xdg ? join(xdg, "ghfind") : join(homedir(), ".local", "share", "ghfind");
8
- return base;
9
- }
10
- function cacheDir() {
11
- const xdg = process.env.XDG_CACHE_HOME;
12
- const base = xdg ? join(xdg, "ghfind") : join(homedir(), ".cache", "ghfind");
13
- return base;
14
- }
15
- var DEFAULTS = {
16
- defaultSort: "best-match",
17
- defaultLimit: 50,
18
- theme: "tokyo-night",
19
- cacheTtlSeconds: 300,
20
- defaultTab: "search"
21
- };
22
- function configPath() {
23
- const envPath = process.env.GHFIND_CONFIG;
24
- if (envPath) return envPath;
25
- const xdg = process.env.XDG_CONFIG_HOME;
26
- const base = xdg ? join(xdg, "ghfind") : join(homedir(), ".config", "ghfind");
27
- return join(base, "config.json");
28
- }
29
- function loadConfig() {
30
- const path = configPath();
31
- try {
32
- const raw = readFileSync(path, "utf-8");
33
- const parsed = JSON.parse(raw);
34
- return mergeWithEnv({ ...DEFAULTS, ...parsed });
35
- } catch {
36
- return mergeWithEnv({ ...DEFAULTS });
37
- }
38
- }
39
- function saveConfig(config) {
40
- const path = configPath();
41
- const dir = path.slice(
42
- 0,
43
- Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"))
44
- );
45
- mkdirSync(dir, { recursive: true });
46
- writeFileSync(path, JSON.stringify(config, null, 2));
47
- }
48
- function mergeWithEnv(config) {
49
- if (process.env.GITHUB_TOKEN) config.githubToken = process.env.GITHUB_TOKEN;
50
- return config;
51
- }
52
-
53
- export {
54
- stateDir,
55
- cacheDir,
56
- configPath,
57
- loadConfig,
58
- saveConfig
59
- };
@@ -1,14 +0,0 @@
1
- import {
2
- cacheDir,
3
- configPath,
4
- loadConfig,
5
- saveConfig,
6
- stateDir
7
- } from "./chunk-GYIL4S5X.js";
8
- export {
9
- cacheDir,
10
- configPath,
11
- loadConfig,
12
- saveConfig,
13
- stateDir
14
- };