npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

better-install

v0.1.0

Published

Automatically install typescript types when installing or adding dependencies.

Downloads

7

Readme

TypeScript NPM Build Status

Better Install

Automatically install TypeScript @types.

Inspired by @yarnpkg/plugin-typescript but works with yarn@1, yarn@2, pnpm and npm.

Install

yarn

yarn add -D better-install

pnpm

pnpm add -D better-install

npm

npm install -D better-install

Configure

package.json

{
  "scripts": {
    "bi": "better-install"
  }
}

:star: When running better-install as an npm script, it will use the package manager that invokes the script to run all commands, e.g., yarn bi lodash uses yarn to install lodash and @types/lodash.

Add Packages

The format for installing packages is

<PACKAGE_MANAGER> bi [PACKAGES...] [OPTIONS]

yarn

yarn bi lodash yargs-parser minimist-options argville

Install lodash, yargs-parser and minimist-options as a prod dependencies and corresponding @types/ as a devDependencies using yarn.

:fire: better-install installs @types/ packages if the dependency does not contain a types or typings field in package.json or an index.d.ts file in the package root. minimist-options includes a default declaration file, index.d.ts, in the package root but does not specify a types or a typings field within the package.json file. This is enough for better-install to know that minimist-options comes bundled with types and therefore will skip installing @types/minimist-options. better-install checks for types, typings and index.d.ts the same as TypeScript.

Like minimist-options, argville comes bundled with types and therfore better-install skips installing @types/argville.

:star: better-install supports both yarn@1 and yarn@2.

:thumbsup: better-install also supports locating and installing @types/ for scoped packages.

pnpm

pnpm bi -- lodash yargs-parser minimist-options argville

npm

npm run bi -- lodash yargs-parser minimist-options argville

Install All Packages

Run better-install without any args to install all packages listed in package.json and corresponding @types/.

# with yarn
yarn bi
# OR pnpm
pnpm bi
# OR npm
npm run bi

Add devDependency

better-install passes all unknown cli flags to the underlying package manager. To install dev dependencies simply pass the dev flag for the appropriate package manager.

# with yarn
yarn bi -D lodash
# OR pnpm
pnpm bi -D lodash
# OR npm
npm run bi --save-dev lodash

Installs lodash and @types/lodash as devDependencies.

CLI Options

Run yarn bi --help (or with pnpm or npm) to view a full list of options.

:warning: better-install passes unknown flags to the underlying package manager. For example, bi lodash -D sends the -D flag to the package manager and therfore installs lodash and @types/lodash as devDependencies (@types are always installed as devDependencies).

As a Global Bin

May also install better-install globally

# with yarn
yarn add better-install -g
# OR pnpm
pnpm add better-install -g
# OR npm
npm add better-install -g

Exposes two bins, better-install and, for convenience, bi.

Install All Packages

bi

Installs all packages listed in <CWD>/package.json.

Select a Package Manager

As a global bin, better-install uses npm by default. Override this using the --pm option.

# install all package.json dependencies and @types with yarn
bi --pm yarn
# add lodash and @types/lodash with pnpm
bi lodash --pm pnpm
# add lodash and @types/lodash as devDependencies with npm
bi lodash -D --pm npm
# Same as
bi lodash -D

Project or User Config

better-install loads configuration from project level .npmrc config files, /path/to/project/.npmrc, and user level .npmrc config files, ~/.npmrc. Instead of always passing --pm to better-install, one can define the pm key once within an .npmrc file.

# /path/to/project/.npmrc
pm=yarn

Now bi commands within /path/to/project will use yarn instead of npm. Can still override this using the --pm flag.

MonoRepo Projects

better-install supports yarn workspaces and pnpm workspaces.

yarn

// package.json
{
  "private": true,
  "workspaces": ["packages/*"]
}

Then use the -f,--filter flag to glob

yarn bi lodash --filter packages/sub-pkg
# Or with globbing
yarn bi lodash -f packages/*

The -f,--filter flag also supports globbing for the package name.

yarn bi lodash -f @pkg-name/sub-pkg
# Or with globbing
yarn bi lodash -f @pkg-name/*

pnpm

# pnpm-workspace.yaml
packages:
  - packages/*
pnpm bi lodash -f @pkg-name/*