0.1.4 β’ Published 3 years ago
conditional-dependencies v0.1.4
Conditional Dependencies
This is an npm "meta" package that adds support for conditional dependencies to package.json files.
Usage
- Add this package as a dependency to your project.
- add to your
package.jsonfile aconditionalDependenciessection 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" } } - Set the environment variable
conditionalDependenciesto the environment you want to pull in dependencies for before callingnpm installornpm update, e.g.:conditionalDependencies=cloud npm install - Add
npx condition-dependenciesto yourpostinstallscript, 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.
πΊπ¦