Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { tryGetCommandVersion } from './version.js'; | ||
|
||
export const agents = ['bun', 'pnpm', 'yarn', 'npm'] as const; | ||
|
||
export type AgentName = typeof agents[number]; | ||
|
||
export interface Agent { | ||
name: AgentName; | ||
version: string | undefined; | ||
} | ||
|
||
export type AgentMap = Map<AgentName, Agent>; | ||
|
||
/** | ||
* Detects all (known) agents installed on the system. | ||
*/ | ||
export async function detectInstalledAgents(): Promise<AgentMap> { | ||
const agentsFound: AgentMap = new Map(); | ||
|
||
for (const name of agents) { | ||
const version = await tryGetCommandVersion(name); | ||
|
||
if (version) { | ||
agentsFound.set(name, { name, version }); | ||
} | ||
} | ||
|
||
return agentsFound; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './process.js'; | ||
export * from './version.js'; | ||
export * from './agent.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { expect, it } from 'vitest'; | ||
|
||
import * as api from '../src/index.js'; | ||
|
||
it('should find almost one agent (pnpm)', async () => { | ||
const agents = await api.detectInstalledAgents(); | ||
|
||
expect(agents.has('pnpm')).toBe(true); | ||
}); |