Skip to content

Commit e854be9

Browse files
committed
fix: remove cjs deps
Swaps `receptacle` for `quick-lru` and `debug` for `weald` to be able to produce an 100% ESM bundle.
1 parent ff0a161 commit e854be9

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,10 @@
135135
"docs": "aegir docs"
136136
},
137137
"dependencies": {
138-
"debug": "^4.3.4",
139-
"receptacle": "^1.3.2"
138+
"quick-lru": "^7.0.0",
139+
"weald": "^1.0.2"
140140
},
141141
"devDependencies": {
142-
"@types/debug": "^4.1.7",
143142
"@types/sinon": "^17.0.3",
144143
"aegir": "^44.0.0",
145144
"sinon": "^18.0.0"

src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import debug from 'debug'
2-
import Receptacle from 'receptacle'
1+
import QuickLRU from 'quick-lru'
2+
import debug from 'weald'
33
import * as utils from './utils.js'
44
import type { DNSJSON } from './utils'
55

@@ -19,8 +19,8 @@ interface ResolverOptions {
1919
* Uses a list of servers to resolve DNS records with HTTP requests.
2020
*/
2121
class Resolver {
22-
private readonly _cache: Receptacle<string[]>
23-
private readonly _TXTcache: Receptacle<string[][]>
22+
private readonly _cache: QuickLRU<string, string[]>
23+
private readonly _TXTcache: QuickLRU<string, string[][]>
2424
private _servers: string[]
2525
private readonly _request: Request
2626
private _abortControllers: AbortController[]
@@ -32,8 +32,8 @@ class Resolver {
3232
* @param {Request} [options.request] - function to return DNSJSON
3333
*/
3434
constructor (options: ResolverOptions = {}) {
35-
this._cache = new Receptacle({ max: options?.maxCache ?? 100 })
36-
this._TXTcache = new Receptacle({ max: options?.maxCache ?? 100 })
35+
this._cache = new QuickLRU({ maxSize: options?.maxCache ?? 100 })
36+
this._TXTcache = new QuickLRU({ maxSize: options?.maxCache ?? 100 })
3737
this._servers = [
3838
'https://cloudflare-dns.com/dns-query',
3939
'https://dns.google/resolve'
@@ -133,7 +133,7 @@ class Resolver {
133133
const data = response.Answer.map(a => a.data)
134134
const ttl = Math.min(...response.Answer.map(a => a.TTL))
135135

136-
this._cache.set(utils.getCacheKey(hostname, recordType), data, { ttl })
136+
this._cache.set(utils.getCacheKey(hostname, recordType), data, { maxAge: ttl })
137137

138138
return data
139139
} catch (err) {
@@ -183,7 +183,7 @@ class Resolver {
183183
const data = response.Answer.map(a => a.data)
184184
const ttl = Math.min(...response.Answer.map(a => a.TTL))
185185

186-
this._cache.set(utils.getCacheKey(hostname, recordType), data, { ttl })
186+
this._cache.set(utils.getCacheKey(hostname, recordType), data, { maxAge: ttl })
187187

188188
return data
189189
} catch (err) {
@@ -233,7 +233,7 @@ class Resolver {
233233
const data = response.Answer.map(a => [a.data.replace(/['"]+/g, '')])
234234
const ttl = Math.min(...response.Answer.map(a => a.TTL))
235235

236-
this._TXTcache.set(utils.getCacheKey(hostname, recordType), data, { ttl })
236+
this._TXTcache.set(utils.getCacheKey(hostname, recordType), data, { maxAge: ttl })
237237

238238
return data
239239
} catch (err) {

0 commit comments

Comments
 (0)