Skip to content

😎 try to install an optional development dependency, YOLO if you can't.

License

Notifications You must be signed in to change notification settings

bcoe/optional-dev-dependency

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

optional-dev-dependency

Build Status Coverage Status NPM version js-standard-style

For when you want to try to install a module, but want to keep on truckin' if you are unable to. I found this useful for simulating optional-dev-dependencies.

optional-dev-dependency lodash [email protected] fffffffgggggg

All different npm install styles are supported besides the git remote url

Command Line

optional-dev-dependency package [options]

Options:
  -s, --silent   should the `npm install` output be shown?
                                                      [boolean] [default: false]
  -S, --save     try to install the specified packages, and save them to
                 optionalDevDependencies in package.json
                                                      [boolean] [default: false]
  -t, --tag      only try to load dependencies with this tag
  -V, --verbose  output NPM commands before running them
                                                      [boolean] [default: false]
  -h, --help     Show help                                             [boolean]
  -v, --version  Show version number                                   [boolean]

Examples:
  ../bin/odd.js lodash hiredis  try to install 'lodash' and 'hiredis', it's okay
                                if an install fails.
  ../bin/odd.js -t travis       try to install optionalDevDependencies for the
                                'travis' tag from package.json, it's okay if an
                                install fails.

Examples

Here's an example from node_redis:

{
  "name": "redis",
  "scripts": {
    "pretest": "optional-dev-dependency hiredis"
  }
}

You can also save optionalDevDependencies in your package.json file for ease of installation later. For example, let's say you want most developers who download your package and play with it to run basic tests, but when you run your code on your continuous integration server, you need a few extra dependencies. You can use a package.json file like this:

{
  "name": "sample",
  "scripts": {
    "test": "mocha",
    "precoverage": "optional-dev-dependency",
    "coverage": "nyc npm test",
    "preci": "optional-dev-dependency -t ci",
    "ci": "nyc report --reporter=text-lcov | coveralls"
  },
  "optionalDevDependencies": {
    "nyc": "^8.3.1",
    "coveralls": [
      "^2.11.14",
      "ci"
    ]
  }
}

When you do npm run coverage, the precoverage script will ensure that all optionalDevDependencies without a tag are installed (in this case, nyc).

When you do npm run ci on your CI server, the preci script will ensure that all optionalDevDependencies with the ci tag are installed (in this case, coveralls).

You can load optionalDevDependencies into your package.json with the --save/-S flag. This will install the latest lodash, save that version in your package.json, and will only install it later if the foo or bar tag is specified:

optional-dev-dependency --save lodash -t foo -t bar

License

ISC

About

😎 try to install an optional development dependency, YOLO if you can't.

Resources

License

Stars

Watchers

Forks

Packages

No packages published