Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it ok to have more than one package.json in a project?

Is it ok to have more than one package.json in a project? I'm working in a .NET MVC solution and it has a package.json at the root level. I need to integrate Jasmine/Karma into the solution and this is my first time doing this type of integration. I found a sample project for Jasmine/Karma on the web and I was able to get this running locally. This project has it's own package.json.

It seems like it would be useful to maintain the package.json file for the sample Jasmine/Karma sample project separately from the package.json at the root level of the solution to provide more flexibility and to allow the same properties to be used differently based on context.

Would this be valid or generally considered an ok practice? Or do I need to figure out how to merge the contents of package.json from the sample project into the package.json at the root level of the .NET MVC solution?

like image 676
user8334943 Avatar asked Jul 24 '17 19:07

user8334943


People also ask

Can we have 2 package json?

If you use the two-package. json project structure, you'll only have your devDependencies in your development package. json and your dependencies in your app package.

Is package json necessary?

If you're not publishing your project to the NPM registry or otherwise making it publicly available to others, your package. json is still essential to the development flow. Your project also must include a package. json before any packages can be installed from NPM.

What is one purpose of a package json file?

A package. json is a JSON file that exists at the root of a Javascript/Node project. It holds metadata relevant to the project and it is used for managing the project's dependencies, scripts, version and a whole lot more.


1 Answers

In terms of keeping things simple, it is easier to only have to maintain a single package.json file, but there is nothing inherently wrong with multiple package.json files within a repo. Some companies do use mono-repos, for which it would make total sense to have multiple package.json files.

Multiple package.json files give you a lot of flexibility to run different/incompatible versions of dependencies. As a practical example, on one of the projects that I work on we have 2 package.json files, one for the main application code and then another one for our BDD tests. We use chimp for our BDD tests and had issues with running that on the latest node version, whereas we don't want to keep the rest of the app from upgrading just because of this. We also found that the single package.json file got very messy when it was combined at first.

like image 188
jpunk11 Avatar answered Sep 18 '22 13:09

jpunk11