Skip to content

Commit df1d6f6

Browse files
authored
fix: remove cjs deps (#116)
Swaps `receptacle` for `quick-lru` and `debug` for `weald` to be able to produce an 100% ESM bundle.
1 parent ff0a161 commit df1d6f6

File tree

7 files changed

+70
-14
lines changed

7 files changed

+70
-14
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ updates:
55
schedule:
66
interval: daily
77
time: "10:00"
8-
open-pull-requests-limit: 10
8+
open-pull-requests-limit: 20
99
commit-message:
1010
prefix: "deps"
1111
prefix-development: "deps(dev)"

.github/pull_request_template.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Title
2+
3+
<!---
4+
The title of the PR will be the commit message of the merge commit, so please make sure it is descriptive enough.
5+
We utilize the Conventional Commits specification for our commit messages. See <https://www.conventionalcommits.org/en/v1.0.0/#specification> for more information.
6+
The commit tag types can be of one of the following: feat, fix, deps, refactor, chore, docs. See <https://github.com/ipfs/helia/blob/main/.github/workflows/main.yml#L184-L192>
7+
The title must also be fewer than 72 characters long or it will fail the Semantic PR check. See <https://github.com/ipfs/helia/blob/main/.github/workflows/semantic-pull-request.yml>
8+
--->
9+
10+
## Description
11+
12+
<!--
13+
Please write a summary of your changes and why you made them.
14+
Please include any relevant issues in here, for example:
15+
Related https://github.com/ipfs/helia/issues/ABCD.
16+
Fixes https://github.com/ipfs/helia/issues/XYZ.
17+
-->
18+
19+
## Notes & open questions
20+
21+
<!--
22+
Any notes, remarks or open questions you have to make about the PR which don't need to go into the final commit message.
23+
-->
24+
25+
## Change checklist
26+
27+
- [ ] I have performed a self-review of my own code
28+
- [ ] I have made corresponding changes to the documentation if necessary (this includes comments as well)
29+
- [ ] I have added tests that prove my fix is effective or that my feature works

.github/workflows/js-test-and-release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ on:
99

1010
permissions:
1111
contents: write
12+
id-token: write
1213
packages: write
14+
pull-requests: write
1315

1416
concurrency:
1517
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }}
1618
cancel-in-progress: true
1719

1820
jobs:
1921
js-test-and-release:
20-
uses: pl-strflt/uci/.github/workflows/js-test-and-release.yml@v0.0
22+
uses: ipdxco/unified-github-workflows/.github/workflows/js-test-and-release.yml@v1.0
2123
secrets:
2224
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
2325
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
2426
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2527
UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }}
28+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Semantic PR
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
main:
12+
uses: pl-strflt/.github/.github/workflows/[email protected]

.github/workflows/stale.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Close and mark stale issue
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
7+
permissions:
8+
issues: write
9+
pull-requests: write
10+
11+
jobs:
12+
stale:
13+
uses: pl-strflt/.github/.github/workflows/[email protected]

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)