What is @antfu/install-pkg?
@antfu/install-pkg is a utility for programmatically installing npm packages. It simplifies the process of adding dependencies to your project by providing a straightforward API to install packages without needing to manually run npm or yarn commands.
What are @antfu/install-pkg's main functionalities?
Install a single package
This feature allows you to install a single npm package programmatically. In this example, the 'lodash' package is installed, and a message is logged upon successful installation.
const { install } = require('@antfu/install-pkg');
install('lodash').then(() => {
console.log('Lodash installed');
});
Install multiple packages
This feature allows you to install multiple npm packages at once. In this example, both 'express' and 'mongoose' packages are installed, and a message is logged upon successful installation.
const { install } = require('@antfu/install-pkg');
install(['express', 'mongoose']).then(() => {
console.log('Express and Mongoose installed');
});
Specify package version
This feature allows you to specify the version of the package you want to install. In this example, version 17.0.2 of the 'react' package is installed, and a message is logged upon successful installation.
const { install } = require('@antfu/install-pkg');
install('react@17.0.2').then(() => {
console.log('React 17.0.2 installed');
});
Install devDependencies
This feature allows you to install a package as a dev dependency. In this example, the 'typescript' package is installed as a dev dependency, and a message is logged upon successful installation.
const { install } = require('@antfu/install-pkg');
install('typescript', { dev: true }).then(() => {
console.log('TypeScript installed as a dev dependency');
});
Other packages similar to @antfu/install-pkg
npm-install-package
npm-install-package is a utility for installing npm packages programmatically. It provides a simple API to install packages and can be used as an alternative to @antfu/install-pkg. However, it may not offer as many features or as clean an API as @antfu/install-pkg.
yarn-install
yarn-install is a utility for programmatically installing packages using Yarn. It is similar to @antfu/install-pkg but specifically designed for Yarn users. It provides a straightforward API for adding dependencies to your project using Yarn.
npmi
npmi is a simple utility for installing npm packages programmatically. It offers basic functionality for adding dependencies to your project and can be used as an alternative to @antfu/install-pkg. However, it may lack some of the advanced features provided by @antfu/install-pkg.
install-pkg
Install package programmatically. Detect package managers automatically (npm
, yarn
, bun
and pnpm
).
npm i @antfu/install-pkg
import { installPackage } from '@antfu/install-pkg'
await installPackage('vite', { silent: true })
License
MIT License © 2021 Anthony Fu