@skarab/detect-package-manager
Version:
Detects which package manager (bun, pnpm, yarn, npm) is used based on the current working directory.
60 lines (59 loc) • 2.58 kB
TypeScript
export declare const agents: readonly ["bun", "pnpm", "yarn", "npm"];
export declare type AgentName = typeof agents[number];
export declare type AgentVersion = string | undefined;
export interface Agent {
name: AgentName;
version: AgentVersion;
}
export declare type AgentMap = Map<AgentName, Agent>;
/**
* Detects all (known) agents installed on the system.
*/
export declare function detectInstalledAgents(): Promise<AgentMap>;
/**
* Try to find the used agent from a directory with the following rules:
*
* - Try to find the agent in `packageManager` field from `package.json`.
* - If not found, try to find the agent from lock file name.
* - If not found, stats again in parent directory.
*
* @param directory If no directory is provided, the current working directory will be used.
*/
export declare function detectAgent(directory?: string): Promise<Agent | undefined>;
/**
* Try to find the used agent defined in `packageManager` field from `package.json`.
*
* @param directory If no directory is provided, the current working directory will be used.
*/
export declare function detectAgentFromPackageJSON(directory?: string): Promise<Agent | undefined>;
export declare const lockFiles: readonly ["pnpm-lock.yaml", "yarn.lock", "package-lock.json", "bun.lockb", "shrinkwrap.yaml", "npm-shrinkwrap.json"];
export declare type LockFileName = typeof lockFiles[number];
export declare function detectNPMVersionFromLockFile(path: string): Agent;
export declare const pnpmLockFileVersionToVersion: {
readonly '5.4': ">=7.0.0";
readonly '5.3': ">=6.0.0";
readonly '5.2': ">=5.10.0";
readonly '5.1': ">=3.5.0";
readonly '5.0': ">=3.0.0";
readonly '4.0': ">=2.17.0";
readonly '3.9': ">=2.13.3";
readonly '3.8': ">=2.8.0";
readonly '3.7': ">=2.0.0";
readonly '3.6': ">=1.43.0";
readonly '3.5': ">=1.40.0";
readonly '3.4': ">=1.23.0";
readonly '3.3': ">=1.22.0";
readonly '3.2': ">=1.18.1";
readonly '3.1': "1.17 - 1.18.0";
readonly '3': "1 - 1.16";
readonly '2': "0.62 - 0";
};
export declare type PNPMLockFileVersion = keyof typeof pnpmLockFileVersionToVersion;
export declare function detectPNPMVersionFromLockFile(path: string): Agent;
export declare const lockFileVersionDetector: Record<LockFileName, (path: string) => Agent>;
/**
* Try to find the used agent from lock file name and/or content.
*
* @param directory If no directory is provided, the current working directory will be used.
*/
export declare function detectAgentFromLockFile(directory?: string): Promise<Agent | undefined>;