gitprotocolsnpm-installaws-ssonpm-cli

Is there a way to have NPM CLI use custom protocols?


Is there a way to have npm CLI to use custom protocols?

...
"dependencies": {
    ...
    "common-resource-1": "git+codecommit::us-east-1://common-resource-1#develop",
    "common-resource-2": "git+codecommit://common-resource-1#develop",
   ...
}
...

Any of the two would suffice.

This is for use with AWS SSO, codecommit and repos cloned using GRC links. For more info see this question: AWS SSO, Codecommit (GRC git clone link) and npm install

To be clear this is not a git issue as part of the AWS SSO setup is installing a python package called git-remote-codecommit that allows git to recognize the codecommit protocol. However, npm cli does not recognize codecommit protocol as a valid protocol to use when trying to retrieve dependencies.

Running the command npm install fails with the following error:

npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "git+codecommit:": git+codecommit::us-east-1://some-repo

or

npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "git+codecommit:": git+codecommit://some-repo

Any help would be greatly appreciated.


Solution

  • If on a mac:

    1. Remove any keychains entries that may pertain to the domain and/or repository in question. This was my main problem.
    2. Use the git credential-helper with aws command as followings:
      [credential "https://git-codecommit.us-east-1.amazonaws.com"]
           UseHttpPath = true
           helper = !aws codecommit credential-helper $@
      

    Note: if on mac and it still does not work, may have to add dummy value for the username attribute.

    [credential "https://git-codecommit.us-east-1.amazonaws.com"]
         UseHttpPath = true
         helper = !aws codecommit credential-helper $@
         username = "dummy"