Install packages with flexible scope support using your preferred package manager
- π§ Multi-scope Installation - Install packages in local, workspace, global, or dev scope
- π― Smart Package Manager Detection - Automatically detects your package manager (npm, yarn, pnpm, bun)
- π Zero Dependencies - Only uses @dephub packages for core functionality
- π Type Safe - Full TypeScript support with strict types
- π» CLI & API - Use via command line or programmatically
- β Interactive Confirmation - Optional prompt before installation
# Using npm
npm install @dephub/package-install
# Using pnpm
pnpm add @dephub/package-install
# Using yarn
yarn add @dephub/package-install
# Using bun
bun add @dephub/package-install# Install a package (default: production dependency)
package-install eslint
# Install as development dependency
package-install --dev typescript
# Install globally
package-install --global esbuild
# Install into workspace (monorepo support)
package-install --workspace react--packageManager <manager>- Specify package manager: npm, yarn, pnpm, bun--global- Install the package globally--dev- Install as a development dependency--production- Install as a production dependency (default)--workspace- Install into the current workspace
# Install with specific package manager
package-install eslint --packageManager pnpm
# Install multiple scopes (the last one wins)
package-install typescript --dev --workspace
# Install globally with bun
package-install serve --global --packageManager bunimport {
install,
askInstall,
InstallBuilder,
installer,
} from '@dephub/package-install';
// Install a package without confirmation (production scope by default)
const result = await install('eslint');
console.log(result.success); // true or false
// Install with specific scope
const result2 = await install('typescript', 'dev');
// Interactive installation with confirmation
const result3 = await askInstall('react', 'workspace');
// Use the builder for advanced configuration
const builder = new InstallBuilder()
.setName('vue')
.setScope('global')
.setPackageManager('npm');
const result4 = await builder.install();
// Or use the pre-configured instance
installer.setName('prettier');
installer.setScope('dev');
const result5 = await installer.install();Install a package with the specified scope without user confirmation.
Parameters:
name(string) - Package name to installscope(InstallScope) - Installation scope: 'global', 'workspace', 'dev', 'production' (default: 'production')
Returns: Promise<InstallResult> - Installation result
Prompts the user for confirmation before installing the package.
Parameters:
name(string) - Package name to installscope(InstallScope) - Installation scope: 'global', 'workspace', 'dev', 'production' (default: 'production')
Returns: Promise<InstallResult> - Installation result with user confirmation
Builder class for installing packages with method chaining.
Creates a new InstallBuilder instance.
Parameters:
options(InstallOptions) - Optional initial configuration
Sets the package manager to use for installation.
Parameters:
packageManager(PackageManager) - The package manager to use (npm, yarn, pnpm, bun)
Returns: InstallBuilder
Sets the name of the package to install.
Parameters:
name(string) - The name of the package to install
Returns: InstallBuilder
Sets the installation scope.
Parameters:
scope(InstallScope) - The installation scope (global, workspace, dev, production)
Returns: InstallBuilder
Installs the package using the configured settings.
Returns: Promise<InstallResult>
Prompts the user for confirmation before installing the package.
Returns: Promise<InstallResult>
Automatically detects and sets the package manager from the environment.
Returns: Promise<void>
Pre-configured InstallBuilder instance for immediate use.
- production: Install as a production dependency (default)
- dev: Install as a development dependency
- global: Install globally
- workspace: Install into the current workspace (monorepo support)
// Install a production dependency
await install('lodash');
// Install a development dependency
await install('typescript', 'dev');
// Install globally
await install('esbuild', 'global');// Ask for confirmation before installing
const result = await askInstall('react', 'workspace');
if (result.skipped) {
console.log('Installation cancelled by user');
} else if (result.success) {
console.log('Package installed successfully');
} else {
console.log('Installation failed:', result.error);
}// Chain methods for fluent configuration
const result = await new InstallBuilder()
.setName('vue')
.setScope('dev')
.setPackageManager('pnpm')
.install();
// Use the pre-configured instance
installer.setName('eslint');
installer.setScope('dev');
const result2 = await installer.askInstall();try {
const result = await install('some-package');
if (!result.success) {
console.error('Installation failed:', result.error);
}
} catch (error) {
console.error('Unexpected error:', error);
}type InstallScope = 'global' | 'workspace' | 'dev' | 'production';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;
}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;
}type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';MIT License
Author: Estarlin R (estarlincito.com)