Skip to content

Commit

Permalink
Minor refactor of isRequestToRegistry logic for readability (#5321)
Browse files Browse the repository at this point in the history
  • Loading branch information
KidkArolis authored and bestander committed Feb 10, 2018
1 parent 6dc0d23 commit 9cd66df
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/registries/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,13 @@ export default class NpmRegistry extends Registry {
const registry = urlParts(registryUrl);
const customHostSuffix = this.getRegistryOrGlobalOption(registryUrl, 'custom-host-suffix');

const requestToRegistryHost = () => request.host === registry.host;
const requestToYarn = () => YARN_REGISTRY.includes(request.host) && DEFAULT_REGISTRY.includes(registry.host);
const requestToRegistryHost = request.host === registry.host;
const requestToYarn = YARN_REGISTRY.includes(request.host) && DEFAULT_REGISTRY.includes(registry.host);
const requestToRegistryPath = request.path.startsWith(registry.path);
// For some registries, the package path does not prefix with the registry path
const customHostSuffixInUse = typeof customHostSuffix === 'string' && request.host.endsWith(customHostSuffix);

return (
(requestToRegistryHost() || requestToYarn()) &&
(request.path.startsWith(registry.path) ||
// For some registries, the package path does not prefix with the registry path
(typeof customHostSuffix === 'string' && request.host.endsWith(customHostSuffix)))
);
return (requestToRegistryHost || requestToYarn) && (requestToRegistryPath || customHostSuffixInUse);
}

request(pathname: string, opts?: RegistryRequestOptions = {}, packageName: ?string): Promise<*> {
Expand Down

0 comments on commit 9cd66df

Please sign in to comment.