Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/skillkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ const IS_WIN = platform() === "win32";
const DB_PATH = join(HOME, ".skillkit", "analytics.db");
const BIN_NAMES = IS_WIN ? ["skillkit.cmd", "skillkit.exe", "skillkit"] : ["skillkit"];

export function getPackageManagerBinDirs(home = HOME): string[] {
return [
join(home, ".bun", "bin"), join(home, ".local", "share", "mise", "shims"),
join(home, ".local", "share", "pnpm"), join(home, ".volta", "bin"),
join(home, ".yarn", "bin"), join(home, ".config", "yarn", "global", "node_modules", ".bin"),
join(home, ".fnm", "aliases", "default", "bin"), join(home, ".asdf", "shims"),
join(home, ".proto", "bin"),
];
}

function buildPath(): string {
const extra: string[] = [];
if (IS_WIN) {
Expand Down Expand Up @@ -100,15 +110,7 @@ function findSkillkitBin(): string | null {
"/usr/local/bin",
"/opt/homebrew/bin",
join(HOME, ".local", "bin"),
join(HOME, ".bun", "bin"),
join(HOME, ".local", "share", "mise", "shims"),
join(HOME, ".local", "share", "pnpm"), // pnpm global bin
join(HOME, ".volta", "bin"), // Volta
join(HOME, ".yarn", "bin"), // Yarn classic
join(HOME, ".config", "yarn", "global", "node_modules", ".bin"), // Yarn modern
join(HOME, ".fnm", "aliases", "default", "bin"), // fnm
join(HOME, ".asdf", "shims"), // asdf
join(HOME, ".proto", "bin"), // proto
...getPackageManagerBinDirs(),
);
}
for (const dir of searchDirs) {
Expand Down
4 changes: 3 additions & 1 deletion src/tool-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { homedir, platform } from "os";
import { existsSync, readdirSync } from "fs";
import { join } from "path";
import type { ToolConfig } from "./types";
import { getPackageManagerBinDirs } from "./skillkit";

const HOME = homedir();
const IS_WIN = platform() === "win32";
Expand Down Expand Up @@ -36,7 +37,7 @@ function appExists(name: string): boolean {
);
}

function cliExists(name: string): boolean {
export function cliExists(name: string): boolean {
const names = IS_WIN ? [`${name}.cmd`, `${name}.exe`, name] : [name];
const dirs: string[] = [];
if (IS_WIN) {
Expand All @@ -51,6 +52,7 @@ function cliExists(name: string): boolean {
"/usr/local/bin",
"/opt/homebrew/bin",
join(HOME, ".local", "bin"),
...getPackageManagerBinDirs(),
);
}
for (const dir of dirs) {
Expand Down
18 changes: 18 additions & 0 deletions tests/tool-configs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect, mock, test } from "bun:test";
import { homedir } from "os";
import { join } from "path";

const existsSync = mock(() => false);
mock.module("fs", () => ({ existsSync, readdirSync: () => [] }));
const { cliExists } = await import("../src/tool-configs");

test("finds CLIs installed by supported package managers", () => {
for (const parts of [
[".local", "share", "pnpm"], [".volta", "bin"],
[".fnm", "aliases", "default", "bin"], [".asdf", "shims"], [".proto", "bin"],
]) {
const expected = join(homedir(), ...parts, "example-cli");
existsSync.mockImplementation((path) => path === expected);
expect(cliExists("example-cli")).toBe(true);
}
});