Skip to content

Commit

Permalink
fix(downloads): filter out scoped packages
Browse files Browse the repository at this point in the history
These aren't supported in the npm downloads API (never were), but now it returns a 400.

Fixes #36
  • Loading branch information
Haroenv committed Apr 16, 2017
1 parent 6251664 commit 76f571a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion npm.js
Expand Up @@ -20,7 +20,10 @@ export function info() {
export function getDownloads(pkgs) {
// npm has a weird API to get downloads via GET params, so we split pkgs into chunks
// and do multiple requests to avoid weird cases when concurrency is high
const encodedPackageNames = pkgs.map(pkg => encodeURIComponent(pkg.name));
const encodedPackageNames = pkgs
.map(pkg => pkg.name)
.filter(name => name[0] !== '@' /*downloads for scoped packages fails */)
.map(name => encodeURIComponent(name));
// why do we do this? see https://github.com/npm/registry/issues/104
encodedPackageNames.unshift('');
const pkgsNamesChunks = chunk(encodedPackageNames, 100).map(names =>
Expand Down

3 comments on commit 76f571a

@vvo
Copy link
Contributor

@vvo vvo commented on 76f571a Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Npm announced scoped package downloads were now available. What do we need to do to support it?

@Haroenv
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the endpoint the same as before, in that case we can remove this workaround again (funnily enough just after they broke it)

@vvo
Copy link
Contributor

@vvo vvo commented on 76f571a Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Youll have to dig into their blogpost and npms changes to see what to change

Please sign in to comment.