0.1.4 β€’ Published 2 years ago

conditional-dependencies v0.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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.

πŸ‡ΊπŸ‡¦