Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Request: allow npm install to accept path to json file describing dependencies #6661

Closed
devinivy opened this issue Nov 7, 2014 · 10 comments
Closed

Comments

@devinivy
Copy link

devinivy commented Nov 7, 2014

It would be very useful if npm install accepted a path to a file that included json formatted the same as package.json's dependencies value. My use-case is to programmatically configure a list of global packages on, say, a new box. I haven't found a good solution to arbitrarily translate
{"package-name": "version/uri"} (a la package.json) into something like npm install package-name@version.

@kenany
Copy link
Contributor

kenany commented Nov 7, 2014

Sounds to me like you might as well just have a package.json?

@devinivy
Copy link
Author

devinivy commented Nov 7, 2014

Dependencies in package.json are never installed in global mode. I'd like to programmatically configure global packages on a new box, which seems like a reasonable use-case. Also, there isn't really an associated package, so there wouldn't be a proper name or version.

(That said, I do understand why such a request sounds a little odd, given package.json's existence as a core component of npm. I just want a batch version of npm install <package>, which is not the same as listing dependencies in a package.json file then running npm install)

@kenany
Copy link
Contributor

kenany commented Nov 7, 2014

Dependencies in package.json are never installed in global mode

Ah, true. However, there's still a way to do this with a package.json. Global packages are installed to a node_modules folder just like any other package, so really all you need to do is write a package.json and place it in the same directory as that node_modules folder, which should be at {{prefix}}/lib/, where prefix is the prefix .npmrc config. Then running npm install in this directory will install the dependencies into the global node_modules folder.

@devinivy
Copy link
Author

devinivy commented Nov 7, 2014

Ah, thanks for the tip, @kenany ! That's a great solution for now. I'll close this.

@devinivy devinivy closed this as completed Nov 7, 2014
@kenany
Copy link
Contributor

kenany commented Nov 7, 2014

Hmm, actually I guess that wouldn't put them in {{prefix}}/bin/, which is where npm points PATH to for globally installed modules. I think you'd have to add {{prefix}}/node_modules/.bin/ to each box's PATH.

@devinivy
Copy link
Author

devinivy commented Nov 7, 2014

I was just realizing this. I'll figure it out- this is still a good start. I wonder if I ought to reopen this issue, to see if anyone else would voice for such a feature. I admit it's slightly awkward, but perhaps it would be useful. Perhaps there's yet a better solution!

Opening for two days of input, then I'll close it out.

@othiym23
Copy link
Contributor

I see the feature here, but I do think it's a pretty marginal use case, and would be curious to hear if there's enough desire for the feature to warrant making it a supported feature. It seems like it would be pretty trivial to write a small wrapper module that reads either a standalone file or a special stanza in a package.json file and then runs the correct npm -g command to install everything globally. Maybe try that first and see how it goes?

@devinivy
Copy link
Author

Sure! Is there a good starting-point to translate {"package-name": "semver/uri"} to npm install -g package@semver/uri? I saw the npa package, which appears to be somewhat related. I don't know how to best cover all of the cases, but I expect the npa package will be a good place to start looking.

@othiym23
Copy link
Contributor

npm-package-arg and realize-package-specifier are good places to look, and I think @iarna has a few more tricks in her toolbox. In general, anything you can put in a dependencies or devDependencies block will work as-is if passed to npm on the command line, so you can run things like npm install -g 'bower@^1.3.11' without worrying that npm will blow up.

@othiym23
Copy link
Contributor

The CLI team is triaging our feature requests, and have decided to close this issue. This sounds like something that would be useful as an external utility, but isn't something that makes sense for npm itself. Thanks for your time and the discussion!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants