From 6daaea92d4a9c66a2a37e8194d24f4718b605784 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Fri, 8 May 2020 11:42:43 +0200 Subject: [PATCH] Small fixes --- source/hosts-resolver.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/source/hosts-resolver.js b/source/hosts-resolver.js index 93700b7..58813e4 100644 --- a/source/hosts-resolver.js +++ b/source/hosts-resolver.js @@ -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(); @@ -135,15 +135,14 @@ 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]; @@ -151,7 +150,7 @@ const getResolver = (options = { return resolver; } - resolver = new HostsResolver(options); + resolver = new HostsResolver({customHostsPath, watching}); resolvers[id] = resolver; return resolver;