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

soft-add-dependencies

v2.0.0

Published

Add dependencies to your package.json without installing them.

Downloads

5

Readme

soft-add-dependencies

⚡️ Add dependencies to your package.json without installing them.

sort-add-dependencies is a small package to add dependencies without installing them. It has a powerful yet easy JavaScript and TypeScript API, with chainable methods, promise support, and strong typings, but it also has a CLI to add packages from your terminal!

Table of Contents

Usage

CLI

Explanations

soft-add-dependencies works great in the cli. You first need to install it:

$ npm i soft-add-dependencies [-g]

And then run it with npx if it is installed locally, or simply by calling soft-add-dependencies:

$ npx soft-add-dependencies
$ soft-add-dependencies

You first have to put the path to the package json. If it is not set, it will default to ./package.json. If no such file exist, it will create one. Then you have to enter all the dependencies you want to add, separated by a space.

You can also add flags and options:

  • If you add the --overwrite flag, it will overwrite the version of the package if already installed.
  • You can specify the package type with --save-mode <dep/dev/peer/optional>.

Examples

$ soft-add-dependencies ./project/package.json eslint eslint-plugin-foo -m dev
$ soft-add-dependencies zlib-sync sodium --overwrite --mode optional

Code

API

enum SaveMode
  • Normal: 'dependencies'
  • Dev: 'devDependencies'
  • Peer: 'peerDependencies'
  • Optional: 'optionalDependencies'
class SoftAddDependencies(optionsOrDestination)

Parameters:

  • An object with the following fields:
    • destination (mandatory) (string): The destination path
    • overwrite (optional) (boolean): If it should overwrite the version if the package is already present
    • packages (optional) (string[]): List of packages to install
    • saveMode (optional) (SaveMode): The mode to save the dependencies
  • A string, which is the destination path

NOTE: If the provided destination is absolute, then it will be used. Otherwise, it will be used relatively to the current working directory (process.cwd())

SoftAddDependencies#overwrite()
  • Parameters: None
  • Returns: this
  • Set the overwrite property to true
SoftAddDependencies#add(...dependencies)
  • Parameters: ...dependencies (string[]): The dependencies to add
  • Returns: this
  • Add the given dependencies to the list
SoftAddDependencies#as(mode)
  • Parameters: mode (SaveMode): The mode to save the dependencies
  • Returns: this
  • Set the saveMode property to the mode given in the parameter
SoftAddDependencies#run()
  • Parameters: None
  • Returns: Promise<void>
  • Run the installation process.

Examples

You can also use soft-add-dependencies directly inside your JavaScript/TypeScript code.

import SoftAddDependencies, { SaveMode } from 'soft-add-dependencies';

// Using options in the constructor:
await new SoftAddDependencies({
  destination: './project/package.json',
  packages: ['@babel/core', '@babel/node', '@babel/preset-env'],
  overwrite: true,
  saveMode: SaveMode.Dev,
}).run();

// Or using the chainable API:
await new SoftAddDependencies('./project/package.json')
  .add('@babel/core', '@babel/node', '@babel/preset-env')
  .overwrite()
  .as(SaveMode.Optional)
  .run();

License

Copyright © 2020 Elliot 'noftaly' Maisl. Licensed under the MIT license, see the license.