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

Viewed 28

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.

1 Answers

For npm-cli (which is the same as what is run when using npm on commandline) in file node_modules/npm-package-arg/npa.js around line 232, add another case statement like:

case 'git+codecommit:':

And that is it.

There is an issue here though. The GRC links also user codecommit::us-east-1: protocol, where after the :: is the region where codecommit and the repo reside.

The current use of the case statements will not work for something like codecommit::us-east-1:. So to make it more robust, there will need to be better parsing of the "urls" in dependencies.

Related