UNPKG

@dephub/package-install

Version:

Install packages with flexible scope support using your preferred package manager

90 lines (89 loc) 3.38 kB
import { PackageManager } from '@dephub/package-manager'; /** Supported installation scopes for package managers. */ export type InstallScope = 'global' | 'workspace' | 'dev' | 'production'; /** * Represents the result of a package installation attempt. */ export interface InstallResult { /** Whether the installation was successful */ success: boolean; /** The name of the package that was attempted to be installed */ name: string; /** The package manager used for installation, if any */ packageManager?: PackageManager; /** The installation scope that was used */ scope: InstallScope; /** Error message if the installation failed */ error?: string; /** Whether the installation was skipped by user confirmation */ skipped?: boolean; } /** * Configuration options for creating an InstallBuilder instance. */ export interface InstallOptions { /** The package manager to use for installation */ packageManager?: PackageManager; /** The name of the package to install */ name?: string; /** The installation scope */ scope?: InstallScope; } /** * Builder for installing packages using various package managers. * Supports chaining to set options before installation. */ export declare class InstallBuilder { #private; /** * Creates a new InstallBuilder instance. * @param options - Optional initial configuration for the builder. */ constructor(options?: InstallOptions); /** * Sets the package manager to use for installation. * @param packageManager - The package manager to use (npm, yarn, pnpm, bun) * @returns The InstallBuilder instance for method chaining. */ setPackageManager(packageManager: PackageManager): this; /** * Sets the name of the package to install. * @param name - The name of the package to install. * @returns The InstallBuilder instance for method chaining. */ setName(name: string): this; /** * Sets the installation scope. * @param scope - The installation scope (e.g., 'global', 'workspace', 'dev', 'production'). * @returns The InstallBuilder instance for method chaining. */ setScope(scope: InstallScope): this; /** * Automatically detects and sets the package manager from the environment. * @returns A promise that resolves when detection is complete. * @throws {Error} When no package manager is detected in the current environment */ detectPackageManager(): Promise<void>; /** * Installs the package using the configured settings. * @returns A promise resolving to installation result. * @throws {Error} If package name is not set * @throws {Error} If no package manager is set and automatic detection fails */ install(): Promise<InstallResult>; /** * Prompts the user for confirmation before installing the package. * @returns A promise resolving to installation result, including user cancellation. * @example * const result = await builder.askInstall(); * if (result.skipped) { * warn('User cancelled installation'); * } */ askInstall(): Promise<InstallResult>; } /** * Pre-configured InstallBuilder instance for immediate use. * Useful for CLI applications and quick installations. */ export declare const installer: InstallBuilder;