Is it possible to have two package.json
files for a single NodeJS project?
In a project I'm working on, there is an optional and experimental feature which requires some node packages of its own. For every day development, I do not want to force all developers to install those packages.
What I'd like, essentially, is a file which just lists npm dependencies in the a similar format as package.json
, and then use npm install
to install all of them.
eg:
// package.json:
{
"dependencies": {
"underscore": "1.1.7",
"connect": "1.7.0"
}
}
// alt.json
{
"dependencies": {
"experimental_package": "0.0.1",
"and_another_one": "1.33.7"
}
}
And then, something like:
$ npm install
// install the regular package.json stuff
$ npm install alt.json
// install the other ones
Please note that this is not the same as devDependencies
If the nested dependency (with vulnerability) is already fixed but the main dependency isn't, you can use overrides field of package. json as explained in StackOverflow answer. You'll need a recently new version of npm cli v8. 3.0 (2021-12-09) which comes with Node.
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.
You could make a small script (even in Node.js) so that it executes 'npm install .' twice: one for the original package.json and then for alt.json (package.json gets renamed to _package.json and alt.json gets renamed to package.json; after that's finished rename the files as they were).
I'm not sure about this I've never tried, but I think it could work.
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