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 16, 2016
1 parent 8dad18e commit f54d8b6
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export default class BaseRegistry {
return this.config[key];
}

getAvailableRegistries(): Array<string> {
const 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
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,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 f54d8b6

Please sign in to comment.