Skip to content

Conversation

@chazomaticus
Copy link

@chazomaticus chazomaticus commented Dec 1, 2017

This fixes a bug where attempting to clone public, scoped packages (e.g. @kgryte/noop) would error out.

There are two issues here: 1) npm-fetch seems not to handle scoped packages well, %-encoding just the @. This leads to errors like:

$ bin/clone-packages -t http://localhost:8123/ @kgryte/noop
cloning @kgryte/noop @ *...
Error: Not found : %40kgryte/noop
  1. when this module PUTs the module on the destination registry, it skips %-encoding the name, leading to 404s due to the scope being treated as a URL path.

I initially tried to update npm-fetch, but it hasn't been updated in a long time. The npm-registry-client it uses is ancient, but porting to a newer version isn't trivial since the API has changed, and I wasn't sure exactly how to update the callers to handle all cases properly.

So, I added a new alternative for npm-fetch, pacote, here instead. I make use of it conditionally, only for this case where npm-fetch fails. It'd clean things up to replace npm-fetch with pacote entirely, but I wasn't sure it covers all of the same use cases in the same way.

This also adds a test for the new functionality. Unfortunately, I couldn't get the tests to pass on master, and I don't have a lot of time to figure out why. So I blindly added a test for scoped clones, which I think should cover this case just fine.

Let me know if this passes muster, or if I'm barking up the wrong tree. Thanks!

This fixes a bug where attempting to clone public, scoped packages (e.g.
@kgryte/noop) would error out.

There are two issues here: 1) npm-fetch seems not to handle scoped
packages well, %-encoding just the @.  This leads to errors like:

    $ bin/clone-packages -t http://localhost:8123/ @kgryte/noop
    cloning @kgryte/noop @ *...
    Error: Not found : %40kgryte/noop

2) when this module PUTs the module on the destination registry, it
skips %-encoding the name, leading to 404s due to the scope being
treated as a URL path.

I initially tried to update npm-fetch, but it hasn't been updated in a
long time.  The npm-registry-client it uses is ancient, but porting to a
newer version isn't trivial since the API has changed, and I wasn't sure
exactly how to update the callers to handle all cases properly.

So, I added a new alternative for npm-fetch, pacote, here instead.  I
make use of it conditionally, only for this case where npm-fetch fails.
It'd clean things up to replace npm-fetch with pacote entirely, but I
wasn't sure it covers all of the same use cases in the same way.

This also adds a test for the new functionality.  Unfortunately, I
couldn't get the tests to pass on master, and I don't have a lot of time
to figure out why.  So I blindly added a test for scoped clones, which I
*think* should cover this case just fine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant