-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[npm node] support for custom npm registry #1277
[npm node] support for custom npm registry #1277
Conversation
extend routes to optionally match protocol (http or https) and host. utilise ./lib/npm-provider::getNpmRegistryUrl to construct custom npm registry urls or fallback to standard one.
Thanks for this! I appreciate that you're modeling it the Jenkins badge. Since #1186 it's possible to pass arbitrary parameters through the query string. I'd like to use this for exception / rarely used options, long options, or options which require munging to fit into the URL. This seems like a good place for it. Basically, something like The benefit is a more consistent and understandable URL pattern. The resultant URL isn't quite as pretty and takes a bit of effort to encode, but it's also not going to be used by many people, and after #701 it should be really easy to encode one of these through the UI. You can see a few examples in queryParams: ['uri', 'query', 'prefix', 'suffix'], |
lib/all-badge-examples.js
Outdated
}, | ||
{ | ||
title: 'custom registry :: npm (scoped with tag)', | ||
previewUri: '/npm/https/registry.npm.taobao.org/v/@cycle/core/canary.svg', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about choosing one of these four and removing the others? The title should be something like npm (scoped with tag, custom registry). Same with the node badges. I feel like people will understand the pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like this now, hope its okay
lib/npm-provider.js
Outdated
@@ -36,6 +36,15 @@ function mapNpmDownloads(camp, urlComponent, apiUriComponent) { | |||
})); | |||
} | |||
|
|||
// npm registry url | |||
function getNpmRegistryUrl(maybeProtocol, maybeHost) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the query string should make this a little simpler. If you still need this function it should go in a new file npm-badge-helpers.js
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the difference between npm-provider
and npm-badge-helpers
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the badge providers are in server.js
, though a few, like npm, are pulled out. We use -provider
to refer to the function which implements the badge.
The -badge-helpers
are service-specific utility functions which are invoked by the providers.
Yea, in a couple cases the line is gray. Though this one seems to be a utility function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and i got rid off of helper function, now i only use default npm registry uri as a constant to share
server.js
Outdated
} else { | ||
// e.g. https://registry.npmjs.org/@cedx%2Fgulp-david | ||
// because https://registry.npmjs.org/@cedx%2Fgulp-david/latest does not work | ||
const path = encodeURIComponent(`${scope}/${packageName}`); | ||
apiUrl = `https://registry.npmjs.org/@${path}`; | ||
apiUrl = `${registryUrl}/@${path}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I wrote tests for the current Node and NPM badges. Could you add tests of the new routes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
no problems. i'll change stuff. just to be on the same page. here this is the list to change/add:
if im not right, pls correct me |
and thanks for the feedback |
Yup, that's it. And if you keep the helper function, please move it to a different file. Thanks! |
b5cc1f1
to
733c65b
Compare
only tests left |
done |
efe8a76
to
6c71b35
Compare
because of added queryParams and following added indentation to handler diff looks messy. to make things simpler to review use diff url without whitespace diff https://github.com/badges/shields/pull/1277/files?w=1 |
tests are ok, its just ping to chinese registry is very long/big and mocha is timing out. what do you think? |
Excellent! Thanks for the diff; it's easy enough to read. This looks great. Only one thing I'd ask for, is tests of the license badge. It seems think we have any now. The reason it seems important is that all that code was in flight. You could just pick a package and hard-code the expected value. Is there another mirror that's faster to reach from the U.S.? Alternatively we could just leave the flaky test. I've solved the timeout issue in IcedFrisby; it's waiting to be shipped in 2.0. |
sure, i'll add tests for license service |
about registries |
its complicated. there used to be some semi-supported mirrors. Nowadays its only |
from this log default registry is
|
i'll use |
….npmjs.com in examples and tests
yay, |
done |
if nothing left to fix, this pull-request should be fine. @paulmelnikow thanks for your input, feedback and patience |
Thanks for all your work! |
hurray |
thanks |
will you release it to https://shields.io/ anytime soon? |
I can't; I don't have access. Deploys usually happen every 1–3 weeks. Thaddée, who has limited time on this project, is the only sysadmin. He's working on giving me access to deploy and logs, but doing so is complicated because the hosting account (and maybe the servers too) are shared with other services he runs. |
there are two types of custom npm registries:
affected endpoints:
/npm/https/registry.npm.taobao.org/v/express.svg
:/npm/https/registry.npm.taobao.org/l/express.svg
:/node/https/registry.npm.taobao.org/v/express.svg
:downloads related endpoints are not affected due to custom https://api.npmjs.org/ server, which complicates stuff. But apart from complexity, there are several reasons not to modify these endpoints:
P.S. inspiration for
/npm(/:protocol/:host)/…
is jenkins endpoint