conditional-dependencies
v0.1.4
Published
A "meta" package that adds support for conditional dependencies in package.json
Downloads
0
Readme
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.json
file aconditionalDependencies
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" } }
- Set the environment variable
conditionalDependencies
to the environment you want to pull in dependencies for before callingnpm install
ornpm update
, e.g.:conditionalDependencies=cloud npm install
- Add
npx condition-dependencies
to yourpostinstall
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.
🇺🇦