Alternative to package.json, for npm (for public packages)

I have a standard package.json

file for a list of packages that my project uses.

I also need to install some global packages. Instead of doing it manually, I would like to list them in a config file global.json

so that I can:

npm install -g -f global.json

      

But the flag -f

doesn't seem to exist for npm? Is it possible to specify an alternative list of dependencies instead of the standard onepackage.json

+3


source to share


1 answer


The filename package.json

is actually hardcoded into the npm source and you cannot change it using a config option or command line flag.

While this is not a confirmed reason for developers, I suspect that the reason is not that it will lead to a dependency resolution violation. If package A renames its package package.json to myapp.json and package B specifies A as its dependency, then npm will be unable to read and install A's dependencies (or any meta information for that matter) due to the non-standard package. json name.

If you search npm repo , you will find multiple mentions both in the source and in tests that link directly to the package.json line.



PS. If your application requires an npm module to be installed globally, you must either

  • State this clearly in the README and detect its presence at runtime (and print an error message to the user if not present).
  • Invest time and effort in working with a local installation (subjectively preferred).
+4


source







All Articles