Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed May 8, 2020
1 parent e912543 commit 6daaea9
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions source/hosts-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const fileOptions = {
const whitespaceRegExp = /\s+/g;

class HostsResolver {
constructor({watching, customHostsPath}) {
constructor({watching, customHostsPath = hostsPath}) {
this._hostsPath = customHostsPath;
this._error = null;
this._watcher = null;
this._watching = Boolean(watching);
this._watching = watching;
this._hosts = {};

this._init();
Expand Down Expand Up @@ -135,23 +135,22 @@ class HostsResolver {

const resolvers = {};

const getResolver = (options = {
watching: false,
customHostsPath: hostsPath
}) => {
if (typeof options.customHostsPath !== 'string') {
options.customHostsPath = false;
const getResolver = ({customHostsPath, watching}) => {
if (customHostsPath !== undefined && typeof customHostsPath !== 'string') {
customHostsPath = false;
}

const id = `${options.customHostsPath}:${Boolean(options.watching)}`;
watching = Boolean(watching);

const id = `${customHostsPath}:${watching}`;

let resolver = resolvers[id];

if (resolver) {
return resolver;
}

resolver = new HostsResolver(options);
resolver = new HostsResolver({customHostsPath, watching});
resolvers[id] = resolver;

return resolver;
Expand Down

0 comments on commit 6daaea9

Please sign in to comment.