Skip to content

Commit 4e7bd54

Browse files
guo-yuclaude
andcommitted
perf: reduce subprocess count from 8 to 4 on setup
- Remove redundant backend.isAvailable() pre-check before server start - Merge gh --version + gh auth status into single gh auth status call - Merge wrangler --version + wrangler whoami into single wrangler whoami call - Add idleTimeout: 120s to Bun.serve to prevent request timeouts - Bump shipkey to 0.3.6 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 829940e commit 4e7bd54

4 files changed

Lines changed: 23 additions & 42 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shipkey",
3-
"version": "0.3.5",
3+
"version": "0.3.6",
44
"type": "module",
55
"workspaces": ["packages/*"],
66
"repository": {

src/commands/setup.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ function startServer(
479479

480480
return Bun.serve({
481481
port: port ?? 0,
482+
idleTimeout: 120,
482483
async fetch(req) {
483484
const url = new URL(req.url);
484485

@@ -631,12 +632,6 @@ export const setupCommand = new Command("setup")
631632
}
632633

633634
const backend = getBackend(config.backend);
634-
if (!(await backend.isAvailable())) {
635-
console.warn(
636-
` Warning: ${backend.name} CLI not available. Store/read operations will fail.\n` +
637-
` Run the setup wizard for installation instructions.\n`
638-
);
639-
}
640635

641636
const configPath = join(projectRoot, "shipkey.json");
642637
const port = opts.port ? parseInt(opts.port, 10) : undefined;

src/targets/cloudflare.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,23 @@ export class CloudflareTarget implements SyncTarget {
55

66
async checkStatus(): Promise<TargetStatus> {
77
try {
8-
const versionProc = Bun.spawn(["wrangler", "--version"], {
8+
// Single call: wrangler whoami checks both installation and authentication
9+
const proc = Bun.spawn(["wrangler", "whoami"], {
910
stdout: "pipe",
1011
stderr: "pipe",
1112
});
12-
await versionProc.exited;
13-
if (versionProc.exitCode !== 0) return "not_installed";
14-
} catch {
15-
return "not_installed";
16-
}
17-
18-
try {
19-
const whoamiProc = Bun.spawn(["wrangler", "whoami"], {
20-
stdout: "pipe",
21-
stderr: "pipe",
22-
});
23-
const stderr = await new Response(whoamiProc.stderr).text();
24-
await whoamiProc.exited;
25-
if (whoamiProc.exitCode !== 0 || stderr.includes("not authenticated")) {
26-
return "not_authenticated";
13+
const stderr = await new Response(proc.stderr).text();
14+
await proc.exited;
15+
if (proc.exitCode !== 0) {
16+
if (stderr.includes("not authenticated") || stderr.includes("not logged")) {
17+
return "not_authenticated";
18+
}
19+
return "not_installed";
2720
}
21+
return "ready";
2822
} catch {
29-
return "not_authenticated";
23+
return "not_installed";
3024
}
31-
32-
return "ready";
3325
}
3426

3527
async isAvailable(): Promise<boolean> {

src/targets/github.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,22 @@ export class GitHubTarget implements SyncTarget {
55

66
async checkStatus(): Promise<TargetStatus> {
77
try {
8-
const versionProc = Bun.spawn(["gh", "--version"], {
8+
// Single call: gh auth status checks both installation and authentication
9+
const proc = Bun.spawn(["gh", "auth", "status"], {
910
stdout: "pipe",
1011
stderr: "pipe",
1112
});
12-
await versionProc.exited;
13-
if (versionProc.exitCode !== 0) return "not_installed";
13+
const stderr = await new Response(proc.stderr).text();
14+
await proc.exited;
15+
if (proc.exitCode !== 0) {
16+
return stderr.includes("not logged") || stderr.includes("no accounts")
17+
? "not_authenticated"
18+
: "not_installed";
19+
}
20+
return "ready";
1421
} catch {
1522
return "not_installed";
1623
}
17-
18-
try {
19-
const authProc = Bun.spawn(["gh", "auth", "status"], {
20-
stdout: "pipe",
21-
stderr: "pipe",
22-
});
23-
await authProc.exited;
24-
if (authProc.exitCode !== 0) return "not_authenticated";
25-
} catch {
26-
return "not_authenticated";
27-
}
28-
29-
return "ready";
3024
}
3125

3226
async isAvailable(): Promise<boolean> {

0 commit comments

Comments
 (0)