Reputation: 54
I need to have my common npm module as git dependency and use it in many modules. I'm trying to use access token for authorize in git. Bit I don't want to store the token in package.json (at least, it's hard to change it in few modules if it change).
Can I do something like this:
package.json
...
"scripts": {
"preinstall": "read-credentials.sh"
}
...
"dependencies": {
...
"my-module": "git+https://$$$token-from-variable$$$:x-oauth-basic@some-repo-url"
...
}
I know about options with private npm modules or make ssh keys for git access, but it isn't a good fit for me. The main point of the question is to figure out if there is a way to set variables from some preinstall script (where I can have access to access tokens) and use them in package.json.
Upvotes: 1
Views: 2039
Reputation: 111434
You can have private modules on npm. It costs $7/month and is created for exactly the use case that you have here.
If you don't want to do that for some reason, then you can rely on git-specific environment variables to resolve your dependencies. For example if you use git+ssh://git@SERVER:USER/MODULE.git
as a dependency then npm will try to get it with git using the default credentials used by git (which in turn uses the credentials used by ssh). You can even change GIT_SSH
environment variable to completely control the SSH session however you want.
For more options see Install node module from own gitlab server.
Upvotes: 1
Reputation: 54
As I understood, there is no way to create such kind of variables. My solution for my problem:
Upvotes: 0