Skip to content

Commit

Permalink
Don't assume anything about the registry URL, read registries from co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
KidkArolis committed Nov 3, 2016
1 parent 35924ad commit ef7debc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/registries/base-registry.js
Expand Up @@ -64,6 +64,16 @@ export default class BaseRegistry {
return this.config[key];
}

getAvailableRegistries(): Array<string> {
let config = this.config
return Object.keys(config).reduce((registries, option) => {
if (option.split(':')[1] === 'registry') {
registries.push(config[option])
}
return registries
}, [])
}

loadConfig(): Promise<void> {
return Promise.resolve();
}
Expand Down
7 changes: 5 additions & 2 deletions src/registries/npm-registry.js
Expand Up @@ -141,8 +141,11 @@ export default class NpmRegistry extends Registry {
getRegistry(packageName: string): string {
// Try extracting registry from the url, then scoped registry, and default registry
if (packageName.match(/^https?:/)) {
const parts = url.parse(packageName);
return parts.protocol + '//' + parts.host + '/';
const availableRegistries = this.getAvailableRegistries()
const registry = availableRegistries.find(registry => packageName.startsWith(registry))
if (registry) {
return registry
}
}

for (const scope of [this.getScope(packageName), '']) {
Expand Down

0 comments on commit ef7debc

Please sign in to comment.