# conditional-dependencies

> A "meta" package that adds support for conditional dependencies in package.json

Latest version **0.1.4** (published 2022-07-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install conditional-dependencies
pnpm add conditional-dependencies
yarn add conditional-dependencies
bun add conditional-dependencies
```

Provides the command `install`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2022-07-26 |
| First published | 2022-07-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Christian Fritz |
| Maintainers | chfritz |
| Keywords | conditional, dependencies |

## Links

- npm: https://www.npmjs.com/package/conditional-dependencies
- Repository: https://github.com/transitive/npm-conditional-dependencies
- Homepage: https://github.com/transitive/npm-conditional-dependencies#readme
- Issues: https://github.com/transitive/npm-conditional-dependencies/issues
- npm.io page: https://npm.io/package/conditional-dependencies

## Recent versions

- 0.1.4 (latest) — 2022-07-26
- 0.1.3 — 2022-07-26
- 0.1.2 — 2022-07-26
- 0.1.1 — 2022-07-26
- 0.1.0 — 2022-07-25

## README

# Conditional Dependencies

This is an npm "meta" package that adds support for conditional dependencies to `package.json` files.

## Usage

1. Add this package as a dependency to your project.
2. add to your `package.json` file a `conditionalDependencies` section with subsections for each environment you want to specify conditional dependencies for, e.g.:
   ```
   "conditionalDependencies": {
     "cloud": {
       "esbuild": "^0.14.27"
     },
     "device": {
       "rosnodejs": "^3.1.0"
     }
   }
   ```
3. Set the environment variable `conditionalDependencies` to the environment you want to pull in dependencies for before calling `npm install` or `npm update`, e.g.:
   ```
   conditionalDependencies=cloud npm install
   ```
4. Add `npx condition-dependencies` to your `postinstall` script, e.g.:
   ```
   "scripts": {
     "postinstall": "node -r conditional-dependencies -e ''"
   }
   ```

This will pull in those dependencies on-the-fly during the `npm install` process -- during the postinstall step to be precise. The package does that by merging the regular dependencies with the conditional ones and calling `npm install --ignore-scripts` once more temporarily using the merged result.

If the `conditionalDependencies` env var is blank or states an unspecified environment, the package does nothing.

## Status

This is a brand new package and has not yet been tested much at all. So please use with caution and report bugs on Github if you find them. Thanks!

Inspired by [this answer](https://stackoverflow.com/a/40812665/1087119).

🇺🇦

---
_Source: https://npm.io/package/conditional-dependencies · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
