I'm working on an npm package, let's call it foo, that has a few external dependencies. One such dependency, bar requires a build flag in order to work with my project. If I were to manually install the dependencies I would say:
npm install bar --bar-option=1
... # other deps
npm install foo
node script_that_uses_foo.js
I would like the dependencies of foo to be installed automatically with npm install foo. So I have a section in my package.json file that looks like this:
"dependencies" : {
"bar": "file:../../bar-0.1.0.tgz",
"baz": "*"
}
This works fine, except that bar is installed without --bar-option=1. How can I tell npm to pass this argument to the install script of bar? I've looked through the npm documentation and haven't found what I'm looking for.
Thanks for your help.
To declare an optional dependency, add the <optional/> tag to the declared dependency in the plugin pom. xml . If any of the classes in the unavailable optional dependencies are used in the plugin a NoClassDefFoundError will be thrown.
Execute npm install someDependency --save-optional to install a package as an optional dependency. The installed package will be put into optionalDependencies . When you want to avoid installing optional dependencies, you can execute npm ci --no-optional (e.g. on CI tools like GitLab CI).
To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.
I know this is really old, but I believe that in this case, you can
npm install foo --bar-option=1
npm will pass bar-option through to all dependencies, e.g. "bar" when installing them.
alternatively, inside of foo's package.json, you could define a preinstall script that does "npm install bar --bar-option=1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With