op-pkg
Version:
operating package
45 lines (39 loc) • 1.74 kB
text/typescript
import * as tinyexec from 'tinyexec';
import { PackageJson } from 'pkg-types';
import { Agent } from 'package-manager-detector';
export { Agent } from 'package-manager-detector';
type PackageManager = 'pnpm' | 'yarn' | 'npm' | 'bun';
declare function detectPackageManager(cwd?: string): Promise<Agent | null>;
interface InstallPackageOptions {
cwd?: string;
dev?: boolean;
silent?: boolean;
packageManager?: string;
preferOffline?: boolean;
additionalArgs?: string[] | ((agent: string, detectedAgent: string) => string[] | undefined);
}
declare function installPackage(names: string | string[], options?: InstallPackageOptions): Promise<tinyexec.Output>;
/**
* copy from https://github.com/antfu/local-pkg
*/
interface PackageInfo {
name: string;
rootPath: string;
packageJsonPath: string;
version: string;
packageJson: PackageJson;
}
interface PackageResolvingOptions {
paths?: string[];
/**
* @default 'auto'
* Resolve path as posix or win32
*/
platform?: 'posix' | 'win32' | 'auto';
}
declare function resolveModule(name: string, options?: PackageResolvingOptions): string | undefined;
declare function importModule<T = any>(path: string): Promise<T>;
declare function isPackageExists(name: string, options?: PackageResolvingOptions): boolean;
declare function getPackageInfo(name: string, options?: PackageResolvingOptions): Promise<PackageInfo | undefined>;
declare function loadPackageJSON(cwd?: string): Promise<PackageJson | null>;
export { type InstallPackageOptions, type PackageInfo, type PackageManager, type PackageResolvingOptions, detectPackageManager, getPackageInfo, importModule, installPackage, isPackageExists, loadPackageJSON, resolveModule };