Skip to content

Commit

Permalink
fix: remove cjs deps (#116)
Browse files Browse the repository at this point in the history
Swaps `receptacle` for `quick-lru` and `debug` for `weald` to be
able to produce an 100% ESM bundle.
  • Loading branch information
achingbrain authored Aug 2, 2024
1 parent ff0a161 commit df1d6f6
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ updates:
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10
open-pull-requests-limit: 20
commit-message:
prefix: "deps"
prefix-development: "deps(dev)"
29 changes: 29 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Title

<!---
The title of the PR will be the commit message of the merge commit, so please make sure it is descriptive enough.
We utilize the Conventional Commits specification for our commit messages. See <https://www.conventionalcommits.org/en/v1.0.0/#specification> for more information.
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>
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>
--->

## Description

<!--
Please write a summary of your changes and why you made them.
Please include any relevant issues in here, for example:
Related https://github.com/ipfs/helia/issues/ABCD.
Fixes https://github.com/ipfs/helia/issues/XYZ.
-->

## Notes & open questions

<!--
Any notes, remarks or open questions you have to make about the PR which don't need to go into the final commit message.
-->

## Change checklist

- [ ] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation if necessary (this includes comments as well)
- [ ] I have added tests that prove my fix is effective or that my feature works
5 changes: 4 additions & 1 deletion .github/workflows/js-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ on:

permissions:
contents: write
id-token: write
packages: write
pull-requests: write

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

jobs:
js-test-and-release:
uses: pl-strflt/uci/.github/workflows/js-test-and-release.yml@v0.0
uses: ipdxco/unified-github-workflows/.github/workflows/js-test-and-release.yml@v1.0
secrets:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
UCI_GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
12 changes: 12 additions & 0 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Semantic PR

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
uses: pl-strflt/.github/.github/workflows/[email protected]
13 changes: 13 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Close and mark stale issue

on:
schedule:
- cron: '0 0 * * *'

permissions:
issues: write
pull-requests: write

jobs:
stale:
uses: pl-strflt/.github/.github/workflows/[email protected]
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@
"docs": "aegir docs"
},
"dependencies": {
"debug": "^4.3.4",
"receptacle": "^1.3.2"
"quick-lru": "^7.0.0",
"weald": "^1.0.2"
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/sinon": "^17.0.3",
"aegir": "^44.0.0",
"sinon": "^18.0.0"
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import debug from 'debug'
import Receptacle from 'receptacle'
import QuickLRU from 'quick-lru'
import debug from 'weald'
import * as utils from './utils.js'
import type { DNSJSON } from './utils'

Expand All @@ -19,8 +19,8 @@ interface ResolverOptions {
* Uses a list of servers to resolve DNS records with HTTP requests.
*/
class Resolver {
private readonly _cache: Receptacle<string[]>
private readonly _TXTcache: Receptacle<string[][]>
private readonly _cache: QuickLRU<string, string[]>
private readonly _TXTcache: QuickLRU<string, string[][]>
private _servers: string[]
private readonly _request: Request
private _abortControllers: AbortController[]
Expand All @@ -32,8 +32,8 @@ class Resolver {
* @param {Request} [options.request] - function to return DNSJSON
*/
constructor (options: ResolverOptions = {}) {
this._cache = new Receptacle({ max: options?.maxCache ?? 100 })
this._TXTcache = new Receptacle({ max: options?.maxCache ?? 100 })
this._cache = new QuickLRU({ maxSize: options?.maxCache ?? 100 })
this._TXTcache = new QuickLRU({ maxSize: options?.maxCache ?? 100 })
this._servers = [
'https://cloudflare-dns.com/dns-query',
'https://dns.google/resolve'
Expand Down Expand Up @@ -133,7 +133,7 @@ class Resolver {
const data = response.Answer.map(a => a.data)
const ttl = Math.min(...response.Answer.map(a => a.TTL))

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

return data
} catch (err) {
Expand Down Expand Up @@ -183,7 +183,7 @@ class Resolver {
const data = response.Answer.map(a => a.data)
const ttl = Math.min(...response.Answer.map(a => a.TTL))

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

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

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

return data
} catch (err) {
Expand Down

0 comments on commit df1d6f6

Please sign in to comment.